render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
7a3408
From 7bf87a91878c0a2830be2534430f98527e361cd5 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <7bf87a91878c0a2830be2534430f98527e361cd5@dist-git>
7a3408
From: Peter Krempa <pkrempa@redhat.com>
7a3408
Date: Fri, 10 Jul 2015 09:20:32 +0200
7a3408
Subject: [PATCH] qemu: Check duplicate WWNs also for hotplugged disks
7a3408
7a3408
In commit 714b38cb232bcbbd7487af4c058fa6d0999b3326 I tried to avoid
7a3408
having two disks with the same WWN in a VM. I forgot to check the
7a3408
hotplug paths though which make it possible bypass that check. Reinforce
7a3408
the fix by checking the wwn when attaching the disk.
7a3408
7a3408
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1208009
7a3408
(cherry picked from commit 780fe4e4baf7e2f10f65ba1a34f9274fc547cad2)
7a3408
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/conf/domain_conf.c | 37 +++++++++++++++++++++++++++++++++++++
7a3408
 1 file changed, 37 insertions(+)
7a3408
7a3408
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
7a3408
index f3416cf..535701e 100644
7a3408
--- a/src/conf/domain_conf.c
7a3408
+++ b/src/conf/domain_conf.c
7a3408
@@ -22130,6 +22130,34 @@ virDomainDeviceInfoCheckBootIndex(virDomainDefPtr def ATTRIBUTE_UNUSED,
7a3408
     return 0;
7a3408
 }
7a3408
 
7a3408
+
7a3408
+/**
7a3408
+ * virDomainDefGetDiskByWWN:
7a3408
+ * @def: domain definition
7a3408
+ * @wwn: wwn of a disk to find
7a3408
+ *
7a3408
+ * Returns a disk definition pointer corresponding to the given WWN identifier
7a3408
+ * or NULL either if @wwn was NULL or if disk with given WWN is not present in
7a3408
+ * the domain definition.
7a3408
+ */
7a3408
+static virDomainDiskDefPtr
7a3408
+virDomainDefGetDiskByWWN(virDomainDefPtr def,
7a3408
+                         const char *wwn)
7a3408
+{
7a3408
+    size_t i;
7a3408
+
7a3408
+    if (!wwn)
7a3408
+        return NULL;
7a3408
+
7a3408
+    for (i = 0; i < def->ndisks; i++) {
7a3408
+        if (STREQ_NULLABLE(def->disks[i]->wwn, wwn))
7a3408
+            return def->disks[i];
7a3408
+    }
7a3408
+
7a3408
+    return NULL;
7a3408
+}
7a3408
+
7a3408
+
7a3408
 int
7a3408
 virDomainDefCompatibleDevice(virDomainDefPtr def,
7a3408
                              virDomainDeviceDefPtr dev,
7a3408
@@ -22173,6 +22201,15 @@ virDomainDefCompatibleDevice(virDomainDefPtr def,
7a3408
         }
7a3408
     }
7a3408
 
7a3408
+    if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
7a3408
+        if (!!virDomainDefGetDiskByWWN(def, dev->data.disk->wwn)) {
7a3408
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
7a3408
+                           _("Domain already has a disk with wwn '%s'"),
7a3408
+                           dev->data.disk->wwn);
7a3408
+            return -1;
7a3408
+        }
7a3408
+    }
7a3408
+
7a3408
     return 0;
7a3408
 }
7a3408
 
7a3408
-- 
7a3408
2.4.5
7a3408