[PATCH 09/15] qemu: move qemuDomainDeviceDefValidateDisk() to qemu_validate.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This function will remain public due to its usage in qemublocktest.c
even after moving qemuDomainDeviceDefValidate(). The position of its
header in qemu_validate.h is no accident.

Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/qemu/qemu_domain.c   | 100 +--------------------------------------
 src/qemu/qemu_validate.c |  99 ++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_validate.h |   2 +
 tests/qemublocktest.c    |   3 +-
 4 files changed, 104 insertions(+), 100 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 6fa2326edc..2b3dea9d3f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5421,104 +5421,6 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src,
 }
 
 
-int
-qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk,
-                                virQEMUCapsPtr qemuCaps)
-{
-    const char *driverName = virDomainDiskGetDriver(disk);
-    virStorageSourcePtr n;
-    int idx;
-    int partition;
-
-    if (disk->src->shared && !disk->src->readonly &&
-        !qemuBlockStorageSourceSupportsConcurrentAccess(disk->src)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("shared access for disk '%s' requires use of "
-                         "supported storage format"), disk->dst);
-        return -1;
-    }
-
-    if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON) {
-        if (disk->src->readonly) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("copy_on_read is not compatible with read-only disk '%s'"),
-                           disk->dst);
-            return -1;
-        }
-
-        if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM ||
-            disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("copy_on_read is not supported with removable disk '%s'"),
-                           disk->dst);
-            return -1;
-        }
-    }
-
-    if (disk->geometry.cylinders > 0 &&
-        disk->geometry.heads > 0 &&
-        disk->geometry.sectors > 0) {
-        if (disk->bus == VIR_DOMAIN_DISK_BUS_USB ||
-            disk->bus == VIR_DOMAIN_DISK_BUS_SD) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("CHS geometry can not be set for '%s' bus"),
-                           virDomainDiskBusTypeToString(disk->bus));
-            return -1;
-        }
-
-        if (disk->geometry.trans != VIR_DOMAIN_DISK_TRANS_DEFAULT &&
-            disk->bus != VIR_DOMAIN_DISK_BUS_IDE) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("CHS translation mode can only be set for 'ide' bus not '%s'"),
-                           virDomainDiskBusTypeToString(disk->bus));
-            return -1;
-        }
-    }
-
-    if (disk->serial && disk->bus == VIR_DOMAIN_DISK_BUS_SD) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Serial property not supported for drive bus '%s'"),
-                       virDomainDiskBusTypeToString(disk->bus));
-        return -1;
-    }
-
-    if (driverName && STRNEQ(driverName, "qemu")) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unsupported driver name '%s' for disk '%s'"),
-                       driverName, disk->dst);
-        return -1;
-    }
-
-    if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
-        disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("disk type 'virtio' of '%s' does not support ejectable media"),
-                       disk->dst);
-        return -1;
-    }
-
-    if (virDiskNameParse(disk->dst, &idx, &partition) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("invalid disk target '%s'"), disk->dst);
-        return -1;
-    }
-
-    if (partition != 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("invalid disk target '%s', partitions can't appear in disk targets"),
-                       disk->dst);
-        return -1;
-    }
-
-    for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
-        if (qemuDomainValidateStorageSource(n, qemuCaps) < 0)
-            return -1;
-    }
-
-    return 0;
-}
-
-
 static int
 qemuDomainDeviceDefValidateControllerAttributes(const virDomainControllerDef *controller)
 {
@@ -6981,7 +6883,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
         break;
 
     case VIR_DOMAIN_DEVICE_DISK:
-        ret = qemuDomainDeviceDefValidateDisk(dev->data.disk, qemuCaps);
+        ret = qemuValidateDomainDeviceDefDisk(dev->data.disk, qemuCaps);
         break;
 
     case VIR_DOMAIN_DEVICE_CONTROLLER:
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 0caec1fce3..0f267b4abe 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -21,6 +21,7 @@
 #include <config.h>
 
 #include "qemu_validate.h"
+#include "qemu_block.h"
 #include "qemu_domain.h"
 #include "virlog.h"
 #include "virutil.h"
@@ -1815,3 +1816,101 @@ qemuValidateDomainDeviceDefVideo(const virDomainVideoDef *video,
 
     return 0;
 }
+
+
+int
+qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk,
+                                virQEMUCapsPtr qemuCaps)
+{
+    const char *driverName = virDomainDiskGetDriver(disk);
+    virStorageSourcePtr n;
+    int idx;
+    int partition;
+
+    if (disk->src->shared && !disk->src->readonly &&
+        !qemuBlockStorageSourceSupportsConcurrentAccess(disk->src)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("shared access for disk '%s' requires use of "
+                         "supported storage format"), disk->dst);
+        return -1;
+    }
+
+    if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON) {
+        if (disk->src->readonly) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("copy_on_read is not compatible with read-only disk '%s'"),
+                           disk->dst);
+            return -1;
+        }
+
+        if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM ||
+            disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("copy_on_read is not supported with removable disk '%s'"),
+                           disk->dst);
+            return -1;
+        }
+    }
+
+    if (disk->geometry.cylinders > 0 &&
+        disk->geometry.heads > 0 &&
+        disk->geometry.sectors > 0) {
+        if (disk->bus == VIR_DOMAIN_DISK_BUS_USB ||
+            disk->bus == VIR_DOMAIN_DISK_BUS_SD) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("CHS geometry can not be set for '%s' bus"),
+                           virDomainDiskBusTypeToString(disk->bus));
+            return -1;
+        }
+
+        if (disk->geometry.trans != VIR_DOMAIN_DISK_TRANS_DEFAULT &&
+            disk->bus != VIR_DOMAIN_DISK_BUS_IDE) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("CHS translation mode can only be set for 'ide' bus not '%s'"),
+                           virDomainDiskBusTypeToString(disk->bus));
+            return -1;
+        }
+    }
+
+    if (disk->serial && disk->bus == VIR_DOMAIN_DISK_BUS_SD) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Serial property not supported for drive bus '%s'"),
+                       virDomainDiskBusTypeToString(disk->bus));
+        return -1;
+    }
+
+    if (driverName && STRNEQ(driverName, "qemu")) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unsupported driver name '%s' for disk '%s'"),
+                       driverName, disk->dst);
+        return -1;
+    }
+
+    if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
+        disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("disk type 'virtio' of '%s' does not support ejectable media"),
+                       disk->dst);
+        return -1;
+    }
+
+    if (virDiskNameParse(disk->dst, &idx, &partition) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("invalid disk target '%s'"), disk->dst);
+        return -1;
+    }
+
+    if (partition != 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("invalid disk target '%s', partitions can't appear in disk targets"),
+                       disk->dst);
+        return -1;
+    }
+
+    for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
+        if (qemuDomainValidateStorageSource(n, qemuCaps) < 0)
+            return -1;
+    }
+
+    return 0;
+}
diff --git a/src/qemu/qemu_validate.h b/src/qemu/qemu_validate.h
index 387c6ce556..ba732d05d8 100644
--- a/src/qemu/qemu_validate.h
+++ b/src/qemu/qemu_validate.h
@@ -26,6 +26,8 @@
 #include "qemu_capabilities.h"
 
 int qemuValidateDomainDef(const virDomainDef *def, void *opaque);
+int qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk,
+                                    virQEMUCapsPtr qemuCaps);
 int qemuValidateDomainDeviceDefAddress(const virDomainDeviceDef *dev,
                                        virQEMUCapsPtr qemuCaps);
 int qemuValidateDomainDeviceDefNetwork(const virDomainNetDef *net,
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
index 124eaea752..f9fbfc98f2 100644
--- a/tests/qemublocktest.c
+++ b/tests/qemublocktest.c
@@ -28,6 +28,7 @@
 #include "qemu/qemu_monitor_json.h"
 #include "qemu/qemu_backup.h"
 #include "qemu/qemu_checkpoint.h"
+#include "qemu/qemu_validate.h"
 
 #include "qemu/qemu_command.h"
 
@@ -283,7 +284,7 @@ testQemuDiskXMLToProps(const void *opaque)
         return -1;
 
     if (qemuCheckDiskConfig(disk, vmdef, data->qemuCaps) < 0 ||
-        qemuDomainDeviceDefValidateDisk(disk, data->qemuCaps) < 0) {
+        qemuValidateDomainDeviceDefDisk(disk, data->qemuCaps) < 0) {
         VIR_TEST_VERBOSE("invalid configuration for disk");
         return -1;
     }
-- 
2.25.1






[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux