]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: validate: Move qemu-specific LUN disk validation to global validation
authorPeter Krempa <pkrempa@redhat.com>
Tue, 7 Sep 2021 12:01:26 +0000 (14:01 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 9 Sep 2021 08:17:28 +0000 (10:17 +0200)
LUN disks are supported only by VMX and QEMU drivers and the VMX
implementation is a subset of qemu's implementation, thus we can move
the qemu-specific validator to the global validation code providing that
we allow the format to be 'none' (qemu driver always sets 'raw' if it's
not set) and allow disk type 'volume' as a source (qemu always
translates the source, and VMX doesn't implement 'volume' at all).

Moving the code to the global validation allows us to stop calling it
from the qemu specific validation and also deduplicates the checks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/domain_validate.c
src/conf/domain_validate.h
src/libvirt_private.syms
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
src/qemu/qemu_driver.c
src/qemu/qemu_validate.c

index 60f7ccdddd2c7cb737213c9cfcfb92e2015006b8..dbabb953aff3c008ba2c83395b326218847f0510 100644 (file)
@@ -540,6 +540,57 @@ virDomainDiskDefValidateSource(const virStorageSource *src)
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16
 
+
+/**
+ * virDomainDiskDefSourceLUNValidate:
+ * @src: disk source struct
+ *
+ * Validate whether the disk source is valid for disk device='lun'.
+ *
+ * Returns 0 if the configuration is valid -1 and a libvirt error if the source
+ * is invalid.
+ */
+int
+virDomainDiskDefSourceLUNValidate(const virStorageSource *src)
+{
+    if (virStorageSourceGetActualType(src) == VIR_STORAGE_TYPE_NETWORK) {
+        if (src->protocol != VIR_STORAGE_NET_PROTOCOL_ISCSI) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("disk device='lun' is not supported for protocol='%s'"),
+                           virStorageNetProtocolTypeToString(src->protocol));
+            return -1;
+        }
+    } else if (!virStorageSourceIsBlockLocal(src) &&
+               src->type != VIR_STORAGE_TYPE_VOLUME) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("disk device='lun' is only valid for block type disk source"));
+        return -1;
+    }
+
+    if (src->format != VIR_STORAGE_FILE_RAW &&
+        src->format != VIR_STORAGE_FILE_NONE) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("disk device 'lun' must use 'raw' format"));
+        return -1;
+    }
+
+    if (src->sliceStorage) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("disk device 'lun' doesn't support storage slice"));
+        return -1;
+    }
+
+    if (src->encryption &&
+        src->encryption->format != VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("disk device 'lun' doesn't support encryption"));
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 virDomainDiskDefValidate(const virDomainDef *def,
                          const virDomainDiskDef *disk)
@@ -551,16 +602,8 @@ virDomainDiskDefValidate(const virDomainDef *def,
 
     /* Validate LUN configuration */
     if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
-        /* volumes haven't been translated at this point, so accept them */
-        if (!(disk->src->type == VIR_STORAGE_TYPE_BLOCK ||
-              disk->src->type == VIR_STORAGE_TYPE_VOLUME ||
-              (disk->src->type == VIR_STORAGE_TYPE_NETWORK &&
-               disk->src->protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI))) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("disk '%s' improperly configured for a "
-                             "device='lun'"), disk->dst);
+        if (virDomainDiskDefSourceLUNValidate(disk->src) < 0)
             return -1;
-        }
     } else {
         if (disk->src->pr) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
index 38a1abcc8f014da6c1362cb96a65435ab9baabee..430d61fd3c83c00134f215e5ec6687ed14d2ce01 100644 (file)
@@ -40,3 +40,5 @@ int virDomainDeviceDefValidate(const virDomainDeviceDef *dev,
                                void *parseOpaque);
 
 int virDomainDiskDefValidateSource(const virStorageSource *src);
+
+int virDomainDiskDefSourceLUNValidate(const virStorageSource *src);
index ab8a6c00c3bd435e365a91c799872fd7c296479a..2778fe7f8fb6278a006a1eb356bb7396409d19e5 100644 (file)
@@ -767,6 +767,7 @@ virDomainConfVMNWFilterTeardown;
 virDomainActualNetDefValidate;
 virDomainDefValidate;
 virDomainDeviceValidateAliasForHotplug;
+virDomainDiskDefSourceLUNValidate;
 
 
 # conf/interface_conf.h
index 7f7d6dcfcc5c5c50ff9a1da572946e825b39f76a..5de7461fb34fc334956a21069b4c651bc65320b2 100644 (file)
@@ -9825,54 +9825,6 @@ qemuDomainDiskByName(virDomainDef *def,
 }
 
 
-/**
- * qemuDomainDefValidateDiskLunSource:
- * @src: disk source struct
- *
- * Validate whether the disk source is valid for disk device='lun'.
- *
- * Returns 0 if the configuration is valid -1 and a libvirt error if the source
- * is invalid.
- */
-int
-qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
-{
-    if (virStorageSourceGetActualType(src) == VIR_STORAGE_TYPE_NETWORK) {
-        if (src->protocol != VIR_STORAGE_NET_PROTOCOL_ISCSI) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("disk device='lun' is not supported for protocol='%s'"),
-                           virStorageNetProtocolTypeToString(src->protocol));
-            return -1;
-        }
-    } else if (!virStorageSourceIsBlockLocal(src)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("disk device='lun' is only valid for block type disk source"));
-        return -1;
-    }
-
-    if (src->format != VIR_STORAGE_FILE_RAW) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("disk device 'lun' must use 'raw' format"));
-        return -1;
-    }
-
-    if (src->sliceStorage) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("disk device 'lun' doesn't support storage slice"));
-        return -1;
-    }
-
-    if (src->encryption &&
-        src->encryption->format != VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("disk device 'lun' doesn't support encryption"));
-        return -1;
-    }
-
-    return 0;
-}
-
-
 int
 qemuDomainPrepareChannel(virDomainChrDef *channel,
                          const char *domainChannelTargetDir)
index cb1cd968d53388df892f3dc295a579e5b3cda670..ae9d76ec4a3aea9a4d264359698f8b7e6bfd4dd3 100644 (file)
@@ -893,9 +893,6 @@ int qemuDomainSecretPrepare(virQEMUDriver *driver,
                             virDomainObj *vm)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
-int qemuDomainDefValidateDiskLunSource(const virStorageSource *src)
-    ATTRIBUTE_NONNULL(1);
-
 int qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk,
                                     virQEMUCaps *qemuCaps);
 
index db605183cf86ff9edb95c8444cd8cec15a20468f..bd41ddbc3c8819620d35da9fed33e48cf4f37268 100644 (file)
@@ -14856,7 +14856,7 @@ qemuDomainBlockCopyCommon(virDomainObj *vm,
         goto endjob;
 
     if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN &&
-        qemuDomainDefValidateDiskLunSource(mirror) < 0)
+        virDomainDiskDefSourceLUNValidate(mirror) < 0)
         goto endjob;
 
     if (!(flags & VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB) &&
index 1a470f1ff56b8e147bcb282367d968660bce67e2..d8f39b6bdd1cf9ea83ab4e59be493a641a12e87f 100644 (file)
@@ -2663,9 +2663,6 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk,
             return -1;
         }
 
-        if (qemuDomainDefValidateDiskLunSource(disk->src) < 0)
-            return -1;
-
         if (disk->wwn) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("Setting wwn is not supported for lun device"));