apache / apache/cloudstack

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

未關閉 適合新手
#13,771 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
component:kvm component:managed-storage Severity:Minor type:bug
主要語言
Java
星號
3.1k
分支
1.4k
平均合併
7 天 14 小時
30 天內合併 PR
31

描述

## 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:

```java
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= diskpath= networkid= ...
```

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

貢獻指南

開啟貢獻指南

研究方向

從 server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java 開始,檢查共用/本機 KVM 匯入方法,尤其是傳遞給 importKVMSharedDisk 和 importKVMLocalDisk 的 deviceId。比較 external/VMware 和 staged 匯入路徑,然後驗證匯入的 ROOT 磁碟區回報 deviceid 0,同時現有的匯入行為保持不變。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
java
領域
infrastructure
Issue 類型
缺陷
難度
1/5
預估耗時
1-3 小時
活躍度
活躍
描述清晰度
描述清楚
新手友好度
86/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。