From 818c4c5542d38d01996bc8566aa8fd5766887195 Mon Sep 17 00:00:00 2001 From: Suresh Kumar Anaparti Date: Wed, 2 Dec 2026 15:33:31 +0530 Subject: [PATCH] KVM: let libvirt place the hot-plugged NIC on q35 guests --- .../wrapper/LibvirtPlugNicCommandWrapper.java | 30 +++++++++++++- .../LibvirtPlugNicCommandWrapperTest.java | 40 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java index acf95edeb954..c86f8c466f26 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapper.java @@ -129,7 +129,7 @@ public Answer execute(final PlugNicCommand command, final LibvirtComputingResour * controllers, balloon), in which case the next free slot above them is used. * * @return the slot to assign, or {@code null} to let libvirt auto-assign (domain XML unavailable - * or unparseable, or no free slot left). + * or unparseable, PCI Express root complex (q35), or no free slot left). */ protected Integer findNextAvailablePciSlot(final Domain vm, final List pluggedNics) { try { @@ -139,6 +139,12 @@ protected Integer findNextAvailablePciSlot(final Domain vm, final List usedSlots = getUsedPciSlots(domXml); if (usedSlots == null) { return null; @@ -154,6 +160,28 @@ protected Integer findNextAvailablePciSlot(final Domain vm, final List} element in the domain XML, * whichever device or bus they belong to. Returns {@code null} if the XML cannot be parsed. diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapperTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapperTest.java index 979ffda2f279..1bdee6bbe042 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapperTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPlugNicCommandWrapperTest.java @@ -18,7 +18,9 @@ package com.cloud.hypervisor.kvm.resource.wrapper; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; import java.util.Arrays; @@ -81,6 +83,30 @@ public class LibvirtPlugNicCommandWrapperTest { + " \n" + "\n"; + /** + * q35 layout as libvirt reports it: NICs sit in slot 0 behind pcie-root-port controllers on bus 0. + */ + private static final String Q35_DOMAIN_XML = + "\n" + + " i-2-43-VM\n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + "