]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: domain: Move checks from virDomainDiskDefParseXML to virDomainDiskDefValidate
authorPeter Krempa <pkrempa@redhat.com>
Thu, 15 Apr 2021 15:27:01 +0000 (17:27 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 19 Apr 2021 12:43:59 +0000 (14:43 +0200)
Move the rest of the validations to the vaidation code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_conf.c
src/conf/domain_validate.c

index 867d74f31fb3e3290ea44e1654c5b1fee425f726..ff408188d52634e66d0c8fabe8333c56a2bec21d 100644 (file)
@@ -9440,8 +9440,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
             if (!(wwn = virXMLNodeContentString(cur)))
                 return NULL;
 
-            if (!virValidateWWN(wwn))
-                return NULL;
         } else if (!vendor &&
                    virXMLNodeNameEqual(cur, "vendor")) {
             if (!(vendor = virXMLNodeContentString(cur)))
@@ -9462,48 +9460,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
         }
     }
 
-    /* Only CDROM and Floppy devices are allowed missing source path
-     * to indicate no media present. LUN is for raw access CD-ROMs
-     * that are not attached to a physical device presently */
-    if (virStorageSourceIsEmpty(def->src) &&
-        def->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
-        virReportError(VIR_ERR_NO_SOURCE,
-                       target ? "%s" : NULL, target);
-        return NULL;
-    }
-
-    if (!target) {
-        if (def->src->srcpool) {
-            tmp = g_strdup_printf("pool = '%s', volume = '%s'",
-                                  def->src->srcpool->pool, def->src->srcpool->volume);
-
-            virReportError(VIR_ERR_NO_TARGET, "%s", tmp);
-            VIR_FREE(tmp);
-        } else {
-            virReportError(VIR_ERR_NO_TARGET, def->src->path ? "%s" : NULL, def->src->path);
-        }
-        return NULL;
-    }
-
-    if (def->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
-        !STRPREFIX(target, "fd")) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Invalid floppy device name: %s"), target);
-        return NULL;
-    }
-
-    if ((def->device == VIR_DOMAIN_DISK_DEVICE_DISK ||
-         def->device == VIR_DOMAIN_DISK_DEVICE_LUN) &&
-        !STRPREFIX((const char *)target, "hd") &&
-        !STRPREFIX((const char *)target, "sd") &&
-        !STRPREFIX((const char *)target, "vd") &&
-        !STRPREFIX((const char *)target, "xvd") &&
-        !STRPREFIX((const char *)target, "ubd")) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Invalid harddisk device name: %s"), target);
-        return NULL;
-    }
-
     if (snapshot) {
         def->snapshot = virDomainSnapshotLocationTypeFromString(snapshot);
         if (def->snapshot <= 0) {
index 1073da3bfab62a776394ad6a79f64fad941bd4d8..686b9e8d169bbaec6754f9fcc3624de988c948a7 100644 (file)
@@ -699,6 +699,50 @@ virDomainDiskDefValidate(const virDomainDef *def,
         }
     }
 
+    if (disk->wwn && !virValidateWWN(disk->wwn))
+        return -1;
+
+    if (!disk->dst) {
+        if (disk->src->srcpool) {
+            virReportError(VIR_ERR_NO_TARGET, _("pool = '%s', volume = '%s'"),
+                           disk->src->srcpool->pool,
+                           disk->src->srcpool->volume);
+        } else {
+            virReportError(VIR_ERR_NO_TARGET,
+                           disk->src->path ? "%s" : NULL, disk->src->path);
+        }
+
+        return -1;
+    }
+
+    if ((disk->device == VIR_DOMAIN_DISK_DEVICE_DISK ||
+         disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) &&
+        !STRPREFIX(disk->dst, "hd") &&
+        !STRPREFIX(disk->dst, "sd") &&
+        !STRPREFIX(disk->dst, "vd") &&
+        !STRPREFIX(disk->dst, "xvd") &&
+        !STRPREFIX(disk->dst, "ubd")) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Invalid harddisk device name: %s"), disk->dst);
+        return -1;
+    }
+
+    if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY &&
+        !STRPREFIX(disk->dst, "fd")) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Invalid floppy device name: %s"), disk->dst);
+        return -1;
+    }
+
+    /* Only CDROM and Floppy devices are allowed missing source path to
+     * indicate no media present. LUN is for raw access CD-ROMs that are not
+     * attached to a physical device presently */
+    if (virStorageSourceIsEmpty(disk->src) &&
+        disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
+        virReportError(VIR_ERR_NO_SOURCE, "%s", disk->dst);
+        return -1;
+    }
+
     return 0;
 }