[libvirt] [PATCH v2 4/7] vz: move prlsdkCheckDiskUnsupportedParams to vz_utils.c

Maxim Nestratov mnestratov at virtuozzo.com
Wed Mar 16 14:21:07 UTC 2016


As long as we have another function checking disk parameters correctness,
let's have them in one place. Here we change prefix of the moved function and
start to call it from vzCheckUnsupportedDisks rather than add disk.

Signed-off-by: Maxim Nestratov <mnestratov at virtuozzo.com>
---
 src/vz/vz_sdk.c   | 123 -----------------------------------------------------
 src/vz/vz_utils.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 125 insertions(+), 123 deletions(-)

diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index bac8feb..d11e29f 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -2410,126 +2410,6 @@ static int prlsdkCheckNetUnsupportedParams(virDomainNetDefPtr net)
     return 0;
 }
 
-static int prlsdkCheckDiskUnsupportedParams(virDomainDiskDefPtr disk)
-{
-    if (disk->device != VIR_DOMAIN_DISK_DEVICE_DISK &&
-        disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
-
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Only hard disks and cdroms are supported "
-                         "by vz driver."));
-        return -1;
-    }
-
-    if (disk->blockio.logical_block_size ||
-        disk->blockio.physical_block_size) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Setting disk block sizes is not "
-                         "supported by vz driver."));
-        return -1;
-    }
-
-    if (disk->blkdeviotune.total_bytes_sec ||
-        disk->blkdeviotune.read_bytes_sec ||
-        disk->blkdeviotune.write_bytes_sec ||
-        disk->blkdeviotune.total_iops_sec ||
-        disk->blkdeviotune.read_iops_sec ||
-        disk->blkdeviotune.write_iops_sec) {
-
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Setting disk io limits is not "
-                         "supported by vz driver yet."));
-        return -1;
-    }
-
-    if (disk->serial) {
-        VIR_INFO("%s", _("Setting disk serial number is not "
-                         "supported by vz driver."));
-    }
-
-    if (disk->wwn) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Setting disk wwn id is not "
-                         "supported by vz driver."));
-        return -1;
-    }
-
-    if (disk->vendor) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Setting disk vendor is not "
-                         "supported by vz driver."));
-        return -1;
-    }
-
-    if (disk->product) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Setting disk product id is not "
-                         "supported by vz driver."));
-        return -1;
-    }
-
-    if (disk->error_policy != VIR_DOMAIN_DISK_ERROR_POLICY_DEFAULT) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Setting disk error policy is not "
-                         "supported by vz driver."));
-        return -1;
-    }
-
-    if (disk->iomode) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Setting disk io mode is not "
-                         "supported by vz driver."));
-        return -1;
-    }
-
-    if (disk->copy_on_read) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Disk copy_on_read is not "
-                         "supported by vz driver."));
-        return -1;
-    }
-
-    if (disk->startupPolicy != VIR_DOMAIN_STARTUP_POLICY_DEFAULT) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Setting up disk startup policy is not "
-                         "supported by vz driver."));
-        return -1;
-    }
-
-    if (disk->transient) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Transient disks are not "
-                         "supported by vz driver."));
-        return -1;
-    }
-
-    if (disk->discard) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Setting up disk discard parameter is not "
-                         "supported by vz driver."));
-        return -1;
-    }
-
-    if (disk->iothread) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Setting up disk io thread # is not "
-                         "supported by vz driver."));
-        return -1;
-    }
-
-    if (disk->src->type != VIR_STORAGE_TYPE_FILE &&
-        disk->src->type != VIR_STORAGE_TYPE_BLOCK) {
-
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Only disk and block storage types are "
-                         "supported by vz driver."));
-        return -1;
-
-    }
-
-    return 0;
-}
-
 static int prlsdkCheckFSUnsupportedParams(virDomainFSDefPtr fs)
 {
     if (fs->type != VIR_DOMAIN_FS_TYPE_FILE) {
@@ -3120,9 +3000,6 @@ static int prlsdkAddDisk(PRL_HANDLE sdkdom,
     PRL_DEVICE_TYPE devType;
     char *dst = NULL;
 
-    if (prlsdkCheckDiskUnsupportedParams(disk) < 0)
-        return -1;
-
     if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK)
         devType = PDE_HARD_DISK;
     else
diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c
index f949887..b616103 100644
--- a/src/vz/vz_utils.c
+++ b/src/vz/vz_utils.c
@@ -250,6 +250,127 @@ vzInitVersion(vzConnPtr privconn)
     return ret;
 }
 
+static int
+vzCheckDiskUnsupportedParams(virDomainDiskDefPtr disk)
+{
+    if (disk->device != VIR_DOMAIN_DISK_DEVICE_DISK &&
+        disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
+
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Only hard disks and cdroms are supported "
+                         "by vz driver."));
+        return -1;
+    }
+
+    if (disk->blockio.logical_block_size ||
+        disk->blockio.physical_block_size) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Setting disk block sizes is not "
+                         "supported by vz driver."));
+        return -1;
+    }
+
+    if (disk->blkdeviotune.total_bytes_sec ||
+        disk->blkdeviotune.read_bytes_sec ||
+        disk->blkdeviotune.write_bytes_sec ||
+        disk->blkdeviotune.total_iops_sec ||
+        disk->blkdeviotune.read_iops_sec ||
+        disk->blkdeviotune.write_iops_sec) {
+
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Setting disk io limits is not "
+                         "supported by vz driver yet."));
+        return -1;
+    }
+
+    if (disk->serial) {
+        VIR_INFO("%s", _("Setting disk serial number is not "
+                         "supported by vz driver."));
+    }
+
+    if (disk->wwn) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Setting disk wwn id is not "
+                         "supported by vz driver."));
+        return -1;
+    }
+
+    if (disk->vendor) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Setting disk vendor is not "
+                         "supported by vz driver."));
+        return -1;
+    }
+
+    if (disk->product) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Setting disk product id is not "
+                         "supported by vz driver."));
+        return -1;
+    }
+
+    if (disk->error_policy != VIR_DOMAIN_DISK_ERROR_POLICY_DEFAULT) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Setting disk error policy is not "
+                         "supported by vz driver."));
+        return -1;
+    }
+
+    if (disk->iomode) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Setting disk io mode is not "
+                         "supported by vz driver."));
+        return -1;
+    }
+
+    if (disk->copy_on_read) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Disk copy_on_read is not "
+                         "supported by vz driver."));
+        return -1;
+    }
+
+    if (disk->startupPolicy != VIR_DOMAIN_STARTUP_POLICY_DEFAULT) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Setting up disk startup policy is not "
+                         "supported by vz driver."));
+        return -1;
+    }
+
+    if (disk->transient) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Transient disks are not "
+                         "supported by vz driver."));
+        return -1;
+    }
+
+    if (disk->discard) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Setting up disk discard parameter is not "
+                         "supported by vz driver."));
+        return -1;
+    }
+
+    if (disk->iothread) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Setting up disk io thread # is not "
+                         "supported by vz driver."));
+        return -1;
+    }
+
+    if (disk->src->type != VIR_STORAGE_TYPE_FILE &&
+        disk->src->type != VIR_STORAGE_TYPE_BLOCK) {
+
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Only disk and block storage types are "
+                         "supported by vz driver."));
+        return -1;
+
+    }
+
+    return 0;
+}
+
 int
 vzCheckUnsupportedDisks(virDomainDefPtr def, vzCapabilitiesPtr vzCaps)
 {
@@ -260,6 +381,10 @@ vzCheckUnsupportedDisks(virDomainDefPtr def, vzCapabilitiesPtr vzCaps)
 
     for (i = 0; i < def->ndisks; i++) {
         disk = def->disks[i];
+
+        if (vzCheckDiskUnsupportedParams(disk) < 0)
+            return -1;
+
         diskFormat = virDomainDiskGetFormat(disk);
         supported = true;
         if (disk->src->type == VIR_STORAGE_TYPE_FILE) {
-- 
2.4.3




More information about the libvir-list mailing list