[PATCH 06/18] vz: move disks checks to device post parse

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

 



And reformat so that we don't have lengthy lines. Also simplify
some checks.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx>
---
 src/vz/vz_sdk.c   | 47 --------------------------------------
 src/vz/vz_utils.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 47 deletions(-)

diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 7e36cb0..5a83586 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -3127,7 +3127,6 @@ static int prlsdkConfigureDisk(vzDriverPtr driver,
     virDomainDeviceDriveAddressPtr drive;
     PRL_DEVICE_TYPE devType;
     PRL_CLUSTERED_DEVICE_SUBTYPE scsiModel;
-    char *dst = NULL;
     const char *path = disk->src->path ? : "";
 
     if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK)
@@ -3165,54 +3164,19 @@ static int prlsdkConfigureDisk(vzDriverPtr driver,
     prlsdkCheckRetGoto(pret, cleanup);
 
     drive = &disk->info.addr.drive;
-    if (drive->controller > 0) {
-        /* We have only one controller of each type */
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid drive "
-                                                     "address of disk %s, vz driver supports "
-                                                     "only one controller."), disk->dst);
-        goto cleanup;
-    }
-
-    if (drive->target > 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid drive "
-                                                     "address of disk %s, vz driver supports "
-                                                     "only target 0."), disk->dst);
-        goto cleanup;
-    }
 
     switch (disk->bus) {
     case VIR_DOMAIN_DISK_BUS_IDE:
-        if (drive->unit > 1) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid drive "
-                                                         "address of disk %s, vz driver supports "
-                                                         "only units 0-1 for IDE bus."), disk->dst);
-            goto cleanup;
-        }
         sdkbus = PMS_IDE_DEVICE;
         idx = 2 * drive->bus + drive->unit;
-        dst = virIndexToDiskName(idx, "hd");
         break;
     case VIR_DOMAIN_DISK_BUS_SCSI:
-        if (drive->bus > 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid drive "
-                                                         "address of disk %s, vz driver supports "
-                                                         "only bus 0 for SCSI bus."), disk->dst);
-            goto cleanup;
-        }
         sdkbus = PMS_SCSI_DEVICE;
         idx = drive->unit;
-        dst = virIndexToDiskName(idx, "sd");
         break;
     case VIR_DOMAIN_DISK_BUS_SATA:
-        if (drive->bus > 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid drive "
-                                                         "address of disk %s, vz driver supports "
-                                                         "only bus 0 for SATA bus."), disk->dst);
-            goto cleanup;
-        }
         sdkbus = PMS_SATA_DEVICE;
         idx = drive->unit;
-        dst = virIndexToDiskName(idx, "sd");
         break;
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -3221,16 +3185,6 @@ static int prlsdkConfigureDisk(vzDriverPtr driver,
         goto cleanup;
     }
 
-    if (!dst)
-        goto cleanup;
-
-    if (STRNEQ(dst, disk->dst)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid drive "
-                                                     "address of disk %s, vz driver supports "
-                                                     "only defaults address to logical device name."), disk->dst);
-        goto cleanup;
-    }
-
     if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
         if (vzGetDefaultSCSIModel(driver, &scsiModel) < 0)
             goto cleanup;
@@ -3247,7 +3201,6 @@ static int prlsdkConfigureDisk(vzDriverPtr driver,
     return 0;
  cleanup:
     PrlHandle_Free(sdkdisk);
-    VIR_FREE(dst);
     return ret;
 }
 
diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c
index db0ad82..5c53e79 100644
--- a/src/vz/vz_utils.c
+++ b/src/vz/vz_utils.c
@@ -265,6 +265,71 @@ vzInitVersion(vzDriverPtr driver)
 }
 
 static int
+vzCheckDiskAddressDriveUnsupportedParams(virDomainDiskDefPtr disk)
+{
+    virDomainDeviceDriveAddressPtr drive = &disk->info.addr.drive;
+    int devIdx, busIdx;
+
+    if (drive->controller > 0) {
+        /* We have only one controller of each type */
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Invalid drive address of disk %s, vz driver "
+                         "supports only one controller."), disk->dst);
+        return -1;
+    }
+
+    if (drive->target > 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Invalid drive address of disk %s, vz driver "
+                         "supports only target 0."), disk->dst);
+        return -1;
+    }
+
+    switch (disk->bus) {
+    case VIR_DOMAIN_DISK_BUS_IDE:
+        if (drive->unit > 1) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("Invalid drive address of disk %s, vz driver "
+                             "supports only units 0-1 for IDE bus."),
+                           disk->dst);
+            return -1;
+        }
+        break;
+    case VIR_DOMAIN_DISK_BUS_SCSI:
+    case VIR_DOMAIN_DISK_BUS_SATA:
+        if (drive->bus > 0) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("Invalid drive address of disk %s, vz driver "
+                             "supports only bus 0 for SATA and SCSI bus."),
+                           disk->dst);
+            return -1;
+        }
+        break;
+    default:
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Specified disk bus is not supported by vz driver."));
+        return -1;
+    }
+
+    if (virDiskNameToBusDeviceIndex(disk, &busIdx, &devIdx) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("cannot convert disk '%s' to bus/device index"),
+                       disk->dst);
+        return -1;
+    }
+
+    if (busIdx != drive->bus || devIdx != drive->unit) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Invalid drive address of disk %s, vz driver "
+                         "does not support non default name mappings."),
+                       disk->dst);
+        return -1;
+    }
+
+    return 0;
+}
+
+static int
 vzCheckDiskUnsupportedParams(virDomainDiskDefPtr disk)
 {
     if (disk->device != VIR_DOMAIN_DISK_DEVICE_DISK &&
@@ -383,6 +448,9 @@ vzCheckDiskUnsupportedParams(virDomainDiskDefPtr disk)
 
     }
 
+    if (vzCheckDiskAddressDriveUnsupportedParams(disk) < 0)
+        return -1;
+
     return 0;
 }
 
-- 
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]