]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Extract code that checks disk serial/wwn conflict
authorPeter Krempa <pkrempa@redhat.com>
Thu, 4 Feb 2016 11:17:50 +0000 (12:17 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 8 Feb 2016 08:08:38 +0000 (09:08 +0100)
Put it into a separate function that can be called on two disk def
pointers.

src/conf/domain_conf.c

index 2d7a4c76ab0fcd1c30f7ad7788ec27628c2e1c90..8f74ac5c023adb2671927621908f436efd87ff72 100644 (file)
@@ -23988,6 +23988,28 @@ virDomainDefNeedsPlacementAdvice(virDomainDefPtr def)
 }
 
 
+static int
+virDomainDiskDefCheckDuplicateInfo(virDomainDiskDefPtr a,
+                                   virDomainDiskDefPtr b)
+{
+    if (a->wwn && b->wwn && STREQ(a->wwn, b->wwn)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Disks '%s' and '%s' have identical WWN"),
+                       a->dst, b->dst);
+        return -1;
+    }
+
+    if (a->serial && b->serial && STREQ(a->serial, b->serial)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Disks '%s' and '%s' have identical serial"),
+                       a->dst, b->dst);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 int
 virDomainDefCheckDuplicateDiskInfo(virDomainDefPtr def)
 {
@@ -23997,25 +24019,9 @@ virDomainDefCheckDuplicateDiskInfo(virDomainDefPtr def)
     for (i = 0; i < def->ndisks; i++) {
         if (def->disks[i]->wwn || def->disks[i]->serial) {
             for (j = i + 1; j < def->ndisks; j++) {
-                if (def->disks[i]->wwn &&
-                    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);
+                if (virDomainDiskDefCheckDuplicateInfo(def->disks[i],
+                                                       def->disks[j]) < 0)
                     return -1;
-                }
-
-                if (def->disks[i]->serial &&
-                    STREQ_NULLABLE(def->disks[i]->serial,
-                                   def->disks[j]->serial)) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("Disks '%s' and '%s' have identical serial"),
-                                   def->disks[i]->dst,
-                                   def->disks[j]->dst);
-                    return -1;
-                }
             }
         }
     }