apache / apache/cloudstack

[KVM] Restored backup volume not attached to running VM via libvirt - only database updated

未關閉
#12,405 3 則留言 3 個 reaction 已指派 0 人 在 GitHub 檢視
status:needs-reproducing
主要語言
Java
星號
3.1k
分支
1.4k
平均合併
6 天 19 小時
30 天內合併 PR
32

描述

### problem

## Description
When restoring a volume from backup and attaching it to a **running** KVM VM, the volume is only attached at the **database level** but not actually hot-attached to the running VM via libvirt. This means:
1. The volume appears in CloudStack UI as "attached"
2. The volume does NOT appear in `virsh domblklist `
3. The volume is NOT visible inside the guest OS
4. User must reboot(forced) the VM to see the restored volume
## Root Cause
In `KVMGuru.attachRestoredVolumeToVirtualMachine()` (line 380-400), the method only:
- Updates the volume state in the database via `_volumeDao.attachVolume()`
- Sets volume state to `Ready`
It does **NOT**:
- Check if VM is running
- Send an `AttachCommand` to the KVM agent to hot-attach the disk via libvirt
## Expected Behavior
When attaching a restored volume to a **running** VM:
1. CloudStack should detect the VM state
2. If VM is [Running](cci:1://file:///root/new_merge/olympos-cloud-platform/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java:5982:4-5991:5), send a libvirt attach command to hot-attach the disk
3. Volume should immediately appear in `virsh domblklist` and inside guest OS
4. No reboot should be required

### versions

CloudStack: 4.21.0
Hypervisor: KVM
Host OS: Rocky Linux 9
Guest OS: Rocky Linux 9 / Windows 10 - 2022 Server

### The steps to reproduce the bug

## Steps to Reproduce
1. Create a VM with a data disk
2. Create a backup of the VM
3. Start the VM (ensure it's running)
4. Restore the backed-up volume and attach to the running VM via API:
`restoreVolumeFromBackupAndAttachToVM`
5. Check `virsh domblklist ` on the KVM host
6. **Observe:** The restored volume is NOT listed
7. Check inside guest OS
8. **Observe:** The disk is NOT visible
9. Reboot(forced) the VM
10. **Observe:** After reboot(forced), the disk appears

### What to do about it?

Either:
A) Add hot-attach logic to `KVMGuru.attachRestoredVolumeToVirtualMachine()` to send `AttachCommand` when VM is running
B) Or document this as expected behavior and require users to stop VM before restoring volumes
Option A is preferred as it aligns with how regular [attachVolume](cci:1://file:///root/new_merge/olympos-cloud-platform/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java:2479:4-2483:5) API works for running VMs.

貢獻指南

開啟貢獻指南

研究方向

從 KVMGuru.attachRestoredVolumeToVirtualMachine() 開始,特別查看引用的行,並將其資料庫附加操作與一般的 attachVolume API 路徑進行比較。閱讀 LibvirtComputingResource 中對執行中狀態的處理以及 AttachCommand 的流程。在執行中的 VM 上重現 restoreVolumeFromBackupAndAttachToVM,然後確認還原的磁碟會在 virsh domblklist 和 guest 中出現,且無需重新啟動。

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

評估

技術堆疊
java
領域
backend, infrastructure
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
45/100

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

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