[PATCH 05/18] vz: leverage disks parameters check on disks updates too

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

 



This is as easy as moving disks checks from domain post
parse callback to device post parse callback.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx>
---
 src/vz/vz_driver.c | 14 +++++-------
 src/vz/vz_utils.c  | 66 ++++++++++++++++++++++++++----------------------------
 src/vz/vz_utils.h  |  5 +++--
 3 files changed, 40 insertions(+), 45 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 2778a9a..b007ad2 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -234,9 +234,6 @@ vzDomainDefPostParse(virDomainDefPtr def ATTRIBUTE_UNUSED,
                      unsigned int parseFlags ATTRIBUTE_UNUSED,
                      void *opaque)
 {
-    if (vzCheckUnsupportedDisks(def, opaque) < 0)
-        return -1;
-
     if (vzCheckUnsupportedControllers(def, opaque) < 0)
         return -1;
 
@@ -250,19 +247,18 @@ vzDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
                            unsigned int parseFlags ATTRIBUTE_UNUSED,
                            void *opaque ATTRIBUTE_UNUSED)
 {
-    int ret = -1;
-
     if (dev->type == VIR_DOMAIN_DEVICE_NET &&
         (dev->data.net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
          dev->data.net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) &&
         !dev->data.net->model &&
         def->os.type == VIR_DOMAIN_OSTYPE_HVM &&
         VIR_STRDUP(dev->data.net->model, "e1000") < 0)
-        goto cleanup;
+        return -1;
 
-    ret = 0;
- cleanup:
-    return ret;
+    if (dev->type == VIR_DOMAIN_DEVICE_DISK)
+        return vzCheckUnsupportedDisk(def, dev->data.disk, opaque);
+
+    return 0;
 }
 
 
diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c
index d9da1e7..db0ad82 100644
--- a/src/vz/vz_utils.c
+++ b/src/vz/vz_utils.c
@@ -387,51 +387,49 @@ vzCheckDiskUnsupportedParams(virDomainDiskDefPtr disk)
 }
 
 int
-vzCheckUnsupportedDisks(virDomainDefPtr def, vzCapabilitiesPtr vzCaps)
+vzCheckUnsupportedDisk(const virDomainDef *def,
+                       virDomainDiskDefPtr disk,
+                       vzCapabilitiesPtr vzCaps)
 {
-    size_t i, j;
-    virDomainDiskDefPtr disk;
+    size_t i;
     virStorageFileFormat diskFormat;
 
-    for (i = 0; i < def->ndisks; i++) {
-        disk = def->disks[i];
+    if (vzCheckDiskUnsupportedParams(disk) < 0)
+        return -1;
 
-        if (vzCheckDiskUnsupportedParams(disk) < 0)
-            return -1;
-
-        if (disk->src->type == VIR_STORAGE_TYPE_FILE) {
-            if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
-                if (IS_CT(def))
-                    diskFormat = vzCaps->ctDiskFormat;
-                else
-                    diskFormat = vzCaps->vmDiskFormat;
-            } else {
-                diskFormat = VIR_STORAGE_FILE_RAW;
-            }
+    if (disk->src->type == VIR_STORAGE_TYPE_FILE) {
+        if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
+            if (IS_CT(def))
+                diskFormat = vzCaps->ctDiskFormat;
+            else
+                diskFormat = vzCaps->vmDiskFormat;
         } else {
             diskFormat = VIR_STORAGE_FILE_RAW;
         }
+    } else {
+        diskFormat = VIR_STORAGE_FILE_RAW;
+    }
 
-        if (virDomainDiskGetFormat(disk) != VIR_STORAGE_FILE_NONE &&
-            virDomainDiskGetFormat(disk) != diskFormat) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("Unsupported format of disk %s"),
-                           disk->src->path);
-            return -1;
-        }
+    if (virDomainDiskGetFormat(disk) != VIR_STORAGE_FILE_NONE &&
+        virDomainDiskGetFormat(disk) != diskFormat) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Unsupported format of disk %s"),
+                       disk->src->path);
+        return -1;
+    }
 
-        for (j = 0; vzCaps->diskBuses[j] != VIR_DOMAIN_DISK_BUS_LAST; j++) {
-            if (disk->bus == vzCaps->diskBuses[j])
-                break;
-        }
+    for (i = 0; vzCaps->diskBuses[i] != VIR_DOMAIN_DISK_BUS_LAST; i++) {
+        if (disk->bus == vzCaps->diskBuses[i])
+            break;
+    }
 
-        if (vzCaps->diskBuses[j] == VIR_DOMAIN_DISK_BUS_LAST) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("Unsupported disk bus type %s"),
-                           virDomainDiskBusTypeToString(disk->bus));
-            return -1;
-        }
+    if (vzCaps->diskBuses[i] == VIR_DOMAIN_DISK_BUS_LAST) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Unsupported disk bus type %s"),
+                       virDomainDiskBusTypeToString(disk->bus));
+        return -1;
     }
+
     return 0;
 }
 
diff --git a/src/vz/vz_utils.h b/src/vz/vz_utils.h
index ee843d8..fc5f695 100644
--- a/src/vz/vz_utils.h
+++ b/src/vz/vz_utils.h
@@ -128,8 +128,9 @@ vzNewDomain(vzDriverPtr driver,
 int
 vzInitVersion(vzDriverPtr driver);
 int
-vzCheckUnsupportedDisks(virDomainDefPtr def,
-                        vzCapabilitiesPtr vzCaps);
+vzCheckUnsupportedDisk(const virDomainDef *def,
+                       virDomainDiskDefPtr disk,
+                       vzCapabilitiesPtr vzCaps);
 int
 vzCheckUnsupportedControllers(virDomainDefPtr def,
                               vzCapabilitiesPtr vzCaps);
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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]