[PATCH 2/2] qemu: Enforce WWN to be unique among VM's disks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Operating systems use the identifier to name the disks. As the name
suggests the ID should be unique.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1208009
---
 docs/formatdomain.html.in |  3 ++-
 src/conf/domain_conf.c    | 25 +++++++++++++++++++++++++
 src/conf/domain_conf.h    |  3 +++
 src/libvirt_private.syms  |  1 +
 src/qemu/qemu_process.c   |  3 +++
 5 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 1b496c3..c808cb9 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2452,7 +2452,8 @@
       <dt><code>wwn</code></dt>
       <dd>If present, this element specifies the WWN (World Wide Name)
         of a virtual hard disk or CD-ROM drive. It must be composed
-        of 16 hexadecimal digits.
+        of 16 hexadecimal digits and must be unique (at least among
+        disks of a single domain)
         <span class='since'>Since 0.10.1</span>
       </dd>
       <dt><code>vendor</code></dt>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 27f29eb..52b4c63 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -23132,3 +23132,28 @@ virDomainDefNeedsPlacementAdvice(virDomainDefPtr def)

     return false;
 }
+
+
+int
+virDomainDefCheckDuplicateDiskWWN(virDomainDefPtr def)
+{
+    size_t i;
+    size_t j;
+
+    for (i = 0; i < def->ndisks; i++) {
+        if (def->disks[i]->wwn) {
+            for (j = i + 1; j < def->ndisks; j++) {
+                if (STREQ_NULLABLE(def->disks[i]->wwn,
+                                   def->disks[j]->wwn)) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                   _("Disks '%s' and '%s' have identical WWN"),
+                                   def->disks[i]->dst,
+                                   def->disks[j]->dst);
+                    return -1;
+                }
+            }
+        }
+    }
+
+    return 0;
+}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 0b2f1c9..edeece2 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3078,4 +3078,7 @@ virDomainParseMemory(const char *xpath,
 bool virDomainDefNeedsPlacementAdvice(virDomainDefPtr def)
     ATTRIBUTE_NONNULL(1);

+int virDomainDefCheckDuplicateDiskWWN(virDomainDefPtr def)
+    ATTRIBUTE_NONNULL(1);
+
 #endif /* __DOMAIN_CONF_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 9f82926..cf5002f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -198,6 +198,7 @@ virDomainCpuPlacementModeTypeFromString;
 virDomainCpuPlacementModeTypeToString;
 virDomainDefAddImplicitControllers;
 virDomainDefCheckABIStability;
+virDomainDefCheckDuplicateDiskWWN;
 virDomainDefCheckUnsupportedMemoryHotplug;
 virDomainDefClearCCWAddresses;
 virDomainDefClearDeviceAliases;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index ed8f65a..523c95f 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4558,6 +4558,9 @@ int qemuProcessStart(virConnectPtr conn,
             goto cleanup;
     }

+    if (virDomainDefCheckDuplicateDiskWWN(vm->def) < 0)
+        goto cleanup;
+
     /* "volume" type disk's source must be translated before
      * cgroup and security setting.
      */
-- 
2.2.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]