]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virDomainDiskDefValidate: Move validation of disk target
authorPeter Krempa <pkrempa@redhat.com>
Tue, 7 Sep 2021 08:01:39 +0000 (10:01 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 9 Sep 2021 08:17:28 +0000 (10:17 +0200)
The disk target is mandatory and used as a designator in error messages
of other validation steps, so we must validate it first.

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

index 9069b60e374f927eb2e2c52e0fd12b6163f771e8..1bc62c364dc721c604bc09d07ebbae16563cd2fc 100644 (file)
@@ -597,6 +597,20 @@ virDomainDiskDefValidate(const virDomainDef *def,
 {
     virStorageSource *next;
 
+    /* disk target is used widely in other code so it must be validated first */
+    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 (virDomainDiskDefValidateSource(disk->src) < 0)
         return -1;
 
@@ -776,19 +790,6 @@ 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") &&