importVm (shared/local storage adoption): ROOT volume always gets deviceId 1, not 0

Open Beginner friendly
#13,771 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
1-3 hours
Newbie friendliness
86/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java

Research direction

Start in server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java and inspect the shared/local KVM import method, especially the deviceId passed to importKVMSharedDisk and importKVMLocalDisk. Compare the external/VMware and staged import paths, then verify that an imported ROOT volume reports deviceid 0 while the existing import behavior remains unchanged.

Written by the indexing model from the issue text.

Description

component:kvm component:managed-storage Severity:Minor type:bug

Description

When adopting an existing disk with importVm importsource=shared or importsource=local, the ROOT
volume ends up with deviceid=1 instead of 0. This happens no matter which storage backend is used —
I saw it with RBD, Linstor, and plain qcow2 on NFS, all the same way.

It doesn't stop the VM from working. It boots fine, the disk is correct, everything else is normal. But
deviceid=1 for a ROOT volume is unexpected, and any code (or person reading listVolumes output) that
assumes ROOT = device 0 will get confused here.

Where it comes from

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java, in the method that handles
the shared/local KVM import:

long deviceId = 1L;
if (ImportSource.SHARED == importSource) {
    diskProfileStoragePoolList.add(importKVMSharedDisk(userVm, diskOffering, Volume.Type.ROOT,
            template, deviceId, poolId, diskPath, diskProfile));
} else if (ImportSource.LOCAL == importSource) {
    diskProfileStoragePoolList.add(importKVMLocalDisk(userVm, diskOffering, Volume.Type.ROOT,
            template, deviceId, hostId, diskPath, diskProfile));
}

deviceId = 1L is passed straight into the ROOT volume's own import call.

Compare this to the other two import paths in the same file (external/VMware import and staged import).
Both of those do it the right way: ROOT is imported with deviceId=null (which defaults to 0), and only
the loop that comes after, for data disks, starts counting at deviceId = 1L.

In the shared/local path there is no data-disk loop at all right now (data disks aren't imported this
way yet), so it looks like the 1L that was meant for "first disk after ROOT" ended up being used for
ROOT itself by mistake.

History

This is not new. git log -S "importKVMSharedDisk" traces it back to the original "KVM Ingestion -
Import Instance" PR (#7976), so it's been there since shared/local KVM import was first added.

Suggested fix

Pass null (or 0) as the deviceId for the ROOT volume in importKVMSharedDisk /
importKVMLocalDisk, the same way the external/VMware import path already does it.

Reproduce

importVm importsource=shared hypervisor=KVM storageid=<pool> diskpath=<existing file> networkid=<net> ...

Then check listVolumes for the resulting VM — ROOT shows deviceid: 1.

Dominant language
Java
Stars
3.1k
Forks
1.4k
Avg merge
6d 20h
Merged PRs (30d)
27

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/cloudstack

All issues in apache/cloudstack

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.