]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: domain: Split out source validation part from virDomainDiskDefParseValidate
authorPeter Krempa <pkrempa@redhat.com>
Thu, 15 Apr 2021 13:20:28 +0000 (15:20 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 19 Apr 2021 12:43:59 +0000 (14:43 +0200)
Separate the validation of the source so that it can be reused once we
split up the XML parser too.

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

index f59d17930bfd30064a345f0ad7050efb19ede25a..0eec4c9356c401a72cfc2bec1a5b5b74e8c2828d 100644 (file)
@@ -9045,29 +9045,55 @@ virDomainDiskDefGeometryParse(virDomainDiskDef *def,
 
 
 static int
-virDomainDiskSourceDefParseAuthValidate(const virStorageSource *src)
+virDomainDiskDefParseValidateSourceChainOne(const virStorageSource *src)
 {
-    virStorageAuthDef *authdef = src->auth;
-    int actUsage;
+    if (src->type == VIR_STORAGE_TYPE_NETWORK && src->auth) {
+        virStorageAuthDef *authdef = src->auth;
+        int actUsage;
 
-    if (src->type != VIR_STORAGE_TYPE_NETWORK || !authdef)
-        return 0;
+        if ((actUsage = virSecretUsageTypeFromString(authdef->secrettype)) < 0) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("unknown secret type '%s'"),
+                           NULLSTR(authdef->secrettype));
+            return -1;
+        }
 
-    if ((actUsage = virSecretUsageTypeFromString(authdef->secrettype)) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown secret type '%s'"),
-                       NULLSTR(authdef->secrettype));
-        return -1;
+        if ((src->protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI &&
+             actUsage != VIR_SECRET_USAGE_TYPE_ISCSI) ||
+            (src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD &&
+             actUsage != VIR_SECRET_USAGE_TYPE_CEPH)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("invalid secret type '%s'"),
+                           virSecretUsageTypeToString(actUsage));
+            return -1;
+        }
     }
 
-    if ((src->protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI &&
-         actUsage != VIR_SECRET_USAGE_TYPE_ISCSI) ||
-        (src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD &&
-         actUsage != VIR_SECRET_USAGE_TYPE_CEPH)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("invalid secret type '%s'"),
-                       virSecretUsageTypeToString(actUsage));
-        return -1;
+    if (src->encryption) {
+        virStorageEncryption *encryption = src->encryption;
+
+        if (encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS &&
+            encryption->encinfo.cipher_name) {
+
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("supplying <cipher> for domain disk definition "
+                             "is unnecessary"));
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+
+static int
+virDomainDiskDefParseValidateSource(const virStorageSource *src)
+{
+    const virStorageSource *next;
+
+    for (next = src; next; next = next->backingStore) {
+        if (virDomainDiskDefParseValidateSourceChainOne(next) < 0)
+            return -1;
     }
 
     return 0;
@@ -9078,7 +9104,8 @@ static int
 virDomainDiskDefParseValidate(const virDomainDiskDef *def)
 
 {
-    virStorageSource *next;
+    if (virDomainDiskDefParseValidateSource(def->src) < 0)
+        return -1;
 
     if (def->bus != VIR_DOMAIN_DISK_BUS_VIRTIO) {
         if (def->event_idx != VIR_TRISTATE_SWITCH_ABSENT) {
@@ -9150,23 +9177,6 @@ virDomainDiskDefParseValidate(const virDomainDiskDef *def)
         }
     }
 
-    for (next = def->src; next; next = next->backingStore) {
-        if (virDomainDiskSourceDefParseAuthValidate(next) < 0)
-            return -1;
-
-        if (next->encryption) {
-            virStorageEncryption *encryption = next->encryption;
-
-            if (encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS &&
-                encryption->encinfo.cipher_name) {
-
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("supplying <cipher> for domain disk definition "
-                                 "is unnecessary"));
-                return -1;
-            }
-        }
-    }
 
     return 0;
 }