server: Avoid device id collision between config drive ISO and data volumes on KVM - #14073
server: Avoid device id collision between config drive ISO and data volumes on KVM#14073weizhouapache wants to merge 1 commit into
Conversation
…olumes on KVM ConfigDriveNetworkElement hardcodes disk sequence 4 (CONFIGDRIVEDISKSEQ) for the config drive ISO, but the volume device-id allocators (VolumeApiServiceImpl.getDeviceId, KVMGuru.getNextAvailableDeviceId) only look at persisted VolumeVO rows and have no knowledge that slot 4 is reserved by the config drive. When a VM using ConfigDrive already has data disks on device ids 1 and 2, attaching a 3rd data disk gets assigned device id 4 as well, producing two disks with the same libvirt target device (e.g. "sde") once both end up on the same bus namespace, as happens with Q35/UEFI machine types. Both allocators now skip CONFIGDRIVEDISKSEQ when the VM has a config drive (detected via the existing CONFIG_DRIVE_LOCATION vm detail), the same way they already permanently reserve device id 3 for the CD-ROM slot.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.22 #14073 +/- ##
============================================
- Coverage 17.83% 17.82% -0.01%
+ Complexity 16023 16022 -1
============================================
Files 5928 5928
Lines 534404 534410 +6
Branches 65399 65403 +4
============================================
- Hits 95290 95284 -6
- Misses 428296 428308 +12
Partials 10818 10818
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Reserving an additional device-id for ConfigDrive without expanding the computed max device-id range can reduce the maximum attachable data volumes and cause avoidable allocation failures.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR addresses KVM/libvirt disk target collisions when ConfigDrive is enabled by ensuring the device-id allocators avoid using the ConfigDrive ISO’s reserved disk sequence (4), preventing duplicate target devices on Q35/UEFI machine types.
Changes:
- Detect ConfigDrive presence via
VmDetailConstants.CONFIG_DRIVE_LOCATIONand skip device idCONFIGDRIVEDISKSEQduring device-id allocation. - Expose
CONFIGDRIVEDISKSEQpublicly so allocators can reference the reserved slot. - Update KVM import/restore volume attach path to use the updated allocator logic.
File summaries
| File | Description |
|---|---|
| server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java | Skip ConfigDrive’s reserved device id during device-id validation/allocation for volume attach. |
| server/src/main/java/com/cloud/network/element/ConfigDriveNetworkElement.java | Make ConfigDrive disk sequence constant publicly accessible. |
| server/src/main/java/com/cloud/hypervisor/KVMGuru.java | Skip ConfigDrive’s reserved device id when selecting the next available device id during VM restore/import flows. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| devIds.remove("3"); | ||
| if (_vmInstanceDetailsDao.findDetail(vmId, VmDetailConstants.CONFIG_DRIVE_LOCATION) != null) { | ||
| devIds.remove(ConfigDriveNetworkElement.CONFIGDRIVEDISKSEQ.toString()); | ||
| } |
| int maxDevices = getMaxDataVolumesSupported(vm) + 2; // add 2 to consider devices root volume and cdrom | ||
| int maxDeviceId = maxDevices - 1; | ||
| List<VolumeVO> vols = _volsDao.findByInstance(vm.getId()); | ||
| boolean vmHasConfigDrive = vmInstanceDetailsDao.findDetail(vm.getId(), VmDetailConstants.CONFIG_DRIVE_LOCATION) != null; | ||
| if (deviceId != null) { |
| private HypervisorGuruManager _hvGuruMgr; | ||
|
|
||
| private final static Integer CONFIGDRIVEDISKSEQ = 4; | ||
| public final static Integer CONFIGDRIVEDISKSEQ = 4; |


Description
This PR fixes #13484
ConfigDriveNetworkElement hardcodes disk sequence 4 (CONFIGDRIVEDISKSEQ) for the config drive ISO, but the volume device-id allocators (VolumeApiServiceImpl.getDeviceId, KVMGuru.getNextAvailableDeviceId) only look at persisted VolumeVO rows and have no knowledge that slot 4 is reserved by the config drive. When a VM using ConfigDrive already has data disks on device ids 1 and 2, attaching a 3rd data disk gets assigned device id 4 as well, producing two disks with the same libvirt target device (e.g. "sde") once both end up on the same bus namespace, as happens with Q35/UEFI machine types.
Both allocators now skip CONFIGDRIVEDISKSEQ when the VM has a config drive (detected via the existing CONFIG_DRIVE_LOCATION vm detail), the same way they already permanently reserve device id 3 for the CD-ROM slot.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?