Skip to content

server: Avoid device id collision between config drive ISO and data volumes on KVM - #14073

Open
weizhouapache wants to merge 1 commit into
apache:4.22from
shapeblue:4.22-fix-13484
Open

server: Avoid device id collision between config drive ISO and data volumes on KVM#14073
weizhouapache wants to merge 1 commit into
apache:4.22from
shapeblue:4.22-fix-13484

Conversation

@weizhouapache

Copy link
Copy Markdown
Member

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

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

…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.
@weizhouapache

weizhouapache commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

Tested with

  • Ubuntu 24.04 cloud image
  • machine type is q35
  • UEFI=SECURE
  • rootdiskcontroller = scsi
  • datadiskcontroller = scsi
image

Note: still got error org.libvirt.LibvirtException: internal error: No more available PCI slots if disk controllers are virtio

image

@weizhouapache
weizhouapache requested a lite review from Copilot September 7, 2026 14:13
@weizhouapache weizhouapache added this to the 4.22.2 milestone Sep 7, 2026
@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 9.09091% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.82%. Comparing base (2b3cca6) to head (826ea7a).

Files with missing lines Patch % Lines
...er/src/main/java/com/cloud/hypervisor/KVMGuru.java 0.00% 5 Missing ⚠️
...n/java/com/cloud/storage/VolumeApiServiceImpl.java 0.00% 5 Missing ⚠️
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              
Flag Coverage Δ
uitests 3.82% <ø> (ø)
unittests 18.90% <9.09%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_LOCATION and skip device id CONFIGDRIVEDISKSEQ during device-id allocation.
  • Expose CONFIGDRIVEDISKSEQ publicly 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.

Comment on lines 110 to +113
devIds.remove("3");
if (_vmInstanceDetailsDao.findDetail(vmId, VmDetailConstants.CONFIG_DRIVE_LOCATION) != null) {
devIds.remove(ConfigDriveNetworkElement.CONFIGDRIVEDISKSEQ.toString());
}
Comment on lines 5043 to 5047
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConfigDrive: duplicated target for disk sources with Q35 machine type

3 participants