[libvirt] [REPOST PATCHv2 1/2] qemu: Check for existing hostdev address for cold attach device

John Ferlan jferlan at redhat.com
Fri Jul 6 18:50:18 UTC 2018


Prior to the hostdev being inserted in the hostdevs list,
add a check during qemuDomainAttachDeviceConfig to determine
whether the new/incoming <hostdev ...> device is providing
the same <address> as some existing hostdev on the list
and if so fail the cold attach.

This cannot be done during virDomainHostdevDefPostParse
because that is called after virDomainDefParseXML would
have inserted a hostdev onto the hostdevs list and thus
would have a "conflict" with itself. Therefore, the post
parse processing can only compare if the current hostdev
address conflicts with a SCSI <disk> address.

By comparison this is similar to the validation phase
checks in virDomainDefCheckDuplicateDriveAddresses that
occur during define/startup processing but are not run
during config attach of a live guest.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/qemu/qemu_driver.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9a35e04a85..ef1abe3f68 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -8007,6 +8007,12 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef,
                            _("device is already in the domain configuration"));
             return -1;
         }
+        if (dev->data.hostdev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+            virDomainDefHasDeviceAddress(vmdef, dev->data.hostdev->info)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("a device with the same address already exists "));
+            return -1;
+        }
         if (virDomainHostdevInsert(vmdef, hostdev))
             return -1;
         dev->data.hostdev = NULL;
-- 
2.14.4




More information about the libvir-list mailing list