]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: Check duplicate WWNs also for hotplugged disks
authorPeter Krempa <pkrempa@redhat.com>
Wed, 8 Jul 2015 14:10:05 +0000 (16:10 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 10 Jul 2015 07:13:22 +0000 (09:13 +0200)
In commit 714b38cb232bcbbd7487af4c058fa6d0999b3326 I tried to avoid
having two disks with the same WWN in a VM. I forgot to check the
hotplug paths though which make it possible bypass that check. Reinforce
the fix by checking the wwn when attaching the disk.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1208009

src/conf/domain_conf.c

index 1f7862b00463f429d8bee5edad493d0d27e1d548..5a9a88d633b88298d2827d09ea65fb7be5f9e489 100644 (file)
@@ -22135,6 +22135,34 @@ virDomainDeviceInfoCheckBootIndex(virDomainDefPtr def ATTRIBUTE_UNUSED,
     return 0;
 }
 
+
+/**
+ * virDomainDefGetDiskByWWN:
+ * @def: domain definition
+ * @wwn: wwn of a disk to find
+ *
+ * Returns a disk definition pointer corresponding to the given WWN identifier
+ * or NULL either if @wwn was NULL or if disk with given WWN is not present in
+ * the domain definition.
+ */
+static virDomainDiskDefPtr
+virDomainDefGetDiskByWWN(virDomainDefPtr def,
+                         const char *wwn)
+{
+    size_t i;
+
+    if (!wwn)
+        return NULL;
+
+    for (i = 0; i < def->ndisks; i++) {
+        if (STREQ_NULLABLE(def->disks[i]->wwn, wwn))
+            return def->disks[i];
+    }
+
+    return NULL;
+}
+
+
 int
 virDomainDefCompatibleDevice(virDomainDefPtr def,
                              virDomainDeviceDefPtr dev,
@@ -22178,6 +22206,15 @@ virDomainDefCompatibleDevice(virDomainDefPtr def,
         }
     }
 
+    if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
+        if (!!virDomainDefGetDiskByWWN(def, dev->data.disk->wwn)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("Domain already has a disk with wwn '%s'"),
+                           dev->data.disk->wwn);
+            return -1;
+        }
+    }
+
     return 0;
 }