jmsperu opened a new pull request, #12826: URL: https://github.com/apache/cloudstack/pull/12826
## Description Fixes #12825 When hot-plugging a NIC to a running KVM VM, libvirt auto-assigns the next free PCI slot. Since non-NIC PCI devices (virtio-serial controller, virtio-disk, memballoon, watchdog) occupy slots immediately after existing NICs (slots 0x05-0x08), the hot-plugged NIC gets a much higher slot number (e.g., 0x09), causing the guest to see `ens9` instead of the expected sequential `ens5`. The NIC shows as DOWN with no IP. ## Changes Modified `LibvirtPlugNicCommandWrapper.java` to explicitly assign a PCI slot when hot-plugging: 1. Query the domain XML to find all PCI slots currently in use 2. Find the highest PCI slot used by existing NICs 3. Assign the next free slot after the last NIC slot This matches the approach already used by `LibvirtReplugNicCommandWrapper` which preserves PCI slots during re-plug operations (line 70: `interfaceDef.setSlot(oldPluggedNic.getSlot())`). Falls back gracefully to libvirt auto-assignment if: - No free PCI slots are available (slots 0x01-0x1f exhausted) - Domain XML cannot be read ## Evidence **Before fix** — hot-plugged NIC at non-sequential PCI slot 0x09: ``` Guest interfaces: ens3 (slot 3), ens4 (slot 4), ens9 (slot 9) ← non-sequential NIC state: DOWN, no IP assigned ``` **After relocating non-NIC devices to high slots (proving the concept):** ``` Guest interfaces: ens3 (slot 3), ens4 (slot 4) ← sequential ``` **Note:** For complete sequential naming on existing VMs, a follow-up change is needed to assign non-NIC PCI devices to higher slot numbers during VM creation in `createDevicesDef()`. ## Test plan - [ ] Hot-plug a NIC to a running KVM VM and verify the new NIC gets the next PCI slot after existing NICs - [ ] Verify guest OS sees sequential interface naming (e.g., ens5 after ens3, ens4) - [ ] Verify fallback to libvirt auto-assignment when domain XML cannot be read - [ ] Verify re-plug (ReplugNicCommand) still works correctly - [ ] Verify VM with maximum NICs still works (PCI slot exhaustion graceful handling) 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
