[PATCH 15/18] conf: use disk source accessors in vmx/

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

 



Part of a series of cleanups to use new accessor methods.

* src/vmx/vmx.c (virVMXHandleLegacySCSIDiskDriverName)
(virVMXParseDisk, virVMXFormatDisk, virVMXFormatFloppy): Use
accessors.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 src/vmx/vmx.c | 113 ++++++++++++++++++++++++++++++++++------------------------
 1 file changed, 66 insertions(+), 47 deletions(-)

diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 1ebb0f9..341d1af 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1,7 +1,7 @@
 /*
  * vmx.c: VMware VMX parsing/formatting functions
  *
- * Copyright (C) 2010-2013 Red Hat, Inc.
+ * Copyright (C) 2010-2014 Red Hat, Inc.
  * Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte@xxxxxxxxxxxxxx>
  *
  * This library is free software; you can redistribute it and/or
@@ -1060,22 +1060,27 @@ virVMXHandleLegacySCSIDiskDriverName(virDomainDefPtr def,
     int model;
     size_t i;
     virDomainControllerDefPtr controller = NULL;
+    const char *driver = virDomainDiskGetDriver(disk);
+    char *copy;

-    if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI || disk->driverName == NULL) {
+    if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI || !driver) {
         return 0;
     }

-    tmp = disk->driverName;
+    if (VIR_STRDUP(copy, driver) < 0)
+        return -1;
+    tmp = copy;

     for (; *tmp != '\0'; ++tmp) {
         *tmp = c_tolower(*tmp);
     }

-    model = virDomainControllerModelSCSITypeFromString(disk->driverName);
+    model = virDomainControllerModelSCSITypeFromString(copy);
+    VIR_FREE(copy);

     if (model < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Unknown driver name '%s'"), disk->driverName);
+                       _("Unknown driver name '%s'"), driver);
         return -1;
     }

@@ -1098,7 +1103,7 @@ virVMXHandleLegacySCSIDiskDriverName(virDomainDefPtr def,
     } else if (controller->model != model) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Inconsistent SCSI controller model ('%s' is not '%s') "
-                         "for SCSI controller index %d"), disk->driverName,
+                         "for SCSI controller index %d"), driver,
                        virDomainControllerModelSCSITypeToString(controller->model),
                        controller->idx);
         return -1;
@@ -2179,15 +2184,18 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
                 }
             }

-            (*def)->type = VIR_DOMAIN_DISK_TYPE_FILE;
-            (*def)->src = ctx->parseFileName(fileName, ctx->opaque);
+            virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_FILE);
+            if (virDomainDiskSetSource(*def,
+                                       ctx->parseFileName(fileName,
+                                                          ctx->opaque)) < 0)
+                goto cleanup;
             (*def)->cachemode = writeThrough ? VIR_DOMAIN_DISK_CACHE_WRITETHRU
                                              : VIR_DOMAIN_DISK_CACHE_DEFAULT;
             if (mode)
                 (*def)->transient = STRCASEEQ(mode,
                                               "independent-nonpersistent");

-            if ((*def)->src == NULL) {
+            if (!virDomainDiskGetSource(*def)) {
                 goto cleanup;
             }
         } else if (virFileHasSuffix(fileName, ".iso") ||
@@ -2219,10 +2227,13 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
                 }
             }

-            (*def)->type = VIR_DOMAIN_DISK_TYPE_FILE;
-            (*def)->src = ctx->parseFileName(fileName, ctx->opaque);
+            virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_FILE);
+            if (virDomainDiskSetSource(*def,
+                                       ctx->parseFileName(fileName,
+                                                          ctx->opaque)) < 0)
+                goto cleanup;

-            if ((*def)->src == NULL) {
+            if (!virDomainDiskGetSource(*def)) {
                 goto cleanup;
             }
         } else if (virFileHasSuffix(fileName, ".vmdk")) {
@@ -2234,26 +2245,24 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
              */
             goto ignore;
         } else if (STRCASEEQ(deviceType, "atapi-cdrom")) {
-            (*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
+            virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_BLOCK);

             if (STRCASEEQ(fileName, "auto detect")) {
-                (*def)->src = NULL;
+                ignore_value(virDomainDiskSetSource(*def, NULL));
                 (*def)->startupPolicy = VIR_DOMAIN_STARTUP_POLICY_OPTIONAL;
-            } else {
-                (*def)->src = fileName;
-                fileName = NULL;
+            } else if (virDomainDiskSetSource(*def, fileName) < 0) {
+                goto cleanup;
             }
         } else if (STRCASEEQ(deviceType, "cdrom-raw")) {
             /* Raw access CD-ROMs actually are device='lun' */
             (*def)->device = VIR_DOMAIN_DISK_DEVICE_LUN;
-            (*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
+            virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_BLOCK);

             if (STRCASEEQ(fileName, "auto detect")) {
-                (*def)->src = NULL;
+                ignore_value(virDomainDiskSetSource(*def, NULL));
                 (*def)->startupPolicy = VIR_DOMAIN_STARTUP_POLICY_OPTIONAL;
-            } else {
-                (*def)->src = fileName;
-                fileName = NULL;
+            } else if (virDomainDiskSetSource(*def, fileName) < 0) {
+                goto cleanup;
             }
         } else {
             virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2265,13 +2274,15 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
         }
     } else if (device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
         if (fileType != NULL && STRCASEEQ(fileType, "device")) {
-            (*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
-            (*def)->src = fileName;
-
-            fileName = NULL;
+            virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_BLOCK);
+            if (virDomainDiskSetSource(*def, fileName) < 0)
+                goto cleanup;
         } else if (fileType != NULL && STRCASEEQ(fileType, "file")) {
-            (*def)->type = VIR_DOMAIN_DISK_TYPE_FILE;
-            (*def)->src = ctx->parseFileName(fileName, ctx->opaque);
+            virDomainDiskSetType(*def, VIR_DOMAIN_DISK_TYPE_FILE);
+            if (virDomainDiskSetSource(*def,
+                                       ctx->parseFileName(fileName,
+                                                          ctx->opaque)) < 0)
+                goto cleanup;
         } else {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Invalid or not yet handled value '%s' "
@@ -2288,7 +2299,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con

     if (virDomainDiskDefAssignAddress(xmlopt, *def) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Could not assign address to disk '%s'"), (*def)->src);
+                       _("Could not assign address to disk '%s'"),
+                       virDomainDiskGetSource(*def));
         goto cleanup;
     }

@@ -3395,11 +3407,12 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def,
     int controllerOrBus, unit;
     const char *vmxDeviceType = NULL;
     char *fileName = NULL;
+    int type = virDomainDiskGetType(def);

     /* Convert a handful of types to their string values */
     const char *busType = virDomainDiskBusTypeToString(def->bus);
     const char *deviceType = virDomainDeviceTypeToString(def->device);
-    const char *diskType = virDomainDeviceTypeToString(def->type);
+    const char *diskType = virDomainDeviceTypeToString(type);

     /* If we are dealing with a disk its a .vmdk, otherwise it must be
      * an ISO.
@@ -3417,8 +3430,8 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def,
     }

     /* We only support type='file' and type='block' */
-    if (def->type != VIR_DOMAIN_DISK_TYPE_FILE &&
-        def->type != VIR_DOMAIN_DISK_TYPE_BLOCK) {
+    if (type != VIR_DOMAIN_DISK_TYPE_FILE &&
+        type != VIR_DOMAIN_DISK_TYPE_BLOCK) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("%s %s '%s' has unsupported type '%s', expecting "
                          "'%s' or '%s'"), busType, deviceType, def->dst,
@@ -3446,11 +3459,11 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def,
     }

     if (def->device == VIR_DOMAIN_DISK_DEVICE_DISK &&
-        def->type == VIR_DOMAIN_DISK_TYPE_FILE) {
+        type == VIR_DOMAIN_DISK_TYPE_FILE) {
         vmxDeviceType = (def->bus == VIR_DOMAIN_DISK_BUS_SCSI) ?
             "scsi-hardDisk" : "ata-hardDisk";
     } else if (def->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
-        if (def->type == VIR_DOMAIN_DISK_TYPE_FILE)
+        if (type == VIR_DOMAIN_DISK_TYPE_FILE)
             vmxDeviceType = "cdrom-image";
         else
             vmxDeviceType = "atapi-cdrom";
@@ -3468,8 +3481,10 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def,
     virBufferAsprintf(buffer, "%s%d:%d.deviceType = \"%s\"\n",
                       busType, controllerOrBus, unit, vmxDeviceType);

-    if (def->type == VIR_DOMAIN_DISK_TYPE_FILE) {
-        if (def->src != NULL && ! virFileHasSuffix(def->src, fileExt)) {
+    if (type == VIR_DOMAIN_DISK_TYPE_FILE) {
+        const char *src = virDomainDiskGetSource(def);
+
+        if (src && ! virFileHasSuffix(src, fileExt)) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Image file for %s %s '%s' has "
                              "unsupported suffix, expecting '%s'"),
@@ -3477,7 +3492,7 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def,
                 return -1;
         }

-        fileName = ctx->formatFileName(def->src, ctx->opaque);
+        fileName = ctx->formatFileName(src, ctx->opaque);

         if (fileName == NULL) {
             return -1;
@@ -3487,8 +3502,10 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def,
                           busType, controllerOrBus, unit, fileName);

         VIR_FREE(fileName);
-    } else if (def->type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
-        if (!def->src &&
+    } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
+        const char *src = virDomainDiskGetSource(def);
+
+        if (!src &&
             def->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_OPTIONAL) {
             virBufferAsprintf(buffer, "%s%d:%d.autodetect = \"true\"\n",
                               busType, controllerOrBus, unit);
@@ -3496,7 +3513,7 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def,
                               busType, controllerOrBus, unit);
         } else {
             virBufferAsprintf(buffer, "%s%d:%d.fileName = \"%s\"\n",
-                              busType, controllerOrBus, unit, def->src);
+                              busType, controllerOrBus, unit, src);
         }
     }

@@ -3526,6 +3543,8 @@ virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def,
 {
     int unit;
     char *fileName = NULL;
+    int type = virDomainDiskGetType(def);
+    const char *src = virDomainDiskGetSource(def);

     if (def->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
@@ -3540,11 +3559,11 @@ virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def,

     virBufferAsprintf(buffer, "floppy%d.present = \"true\"\n", unit);

-    if (def->type == VIR_DOMAIN_DISK_TYPE_FILE) {
+    if (type == VIR_DOMAIN_DISK_TYPE_FILE) {
         virBufferAsprintf(buffer, "floppy%d.fileType = \"file\"\n", unit);

-        if (def->src != NULL) {
-            fileName = ctx->formatFileName(def->src, ctx->opaque);
+        if (src) {
+            fileName = ctx->formatFileName(src, ctx->opaque);

             if (fileName == NULL) {
                 return -1;
@@ -3555,18 +3574,18 @@ virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def,

             VIR_FREE(fileName);
         }
-    } else if (def->type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
+    } else if (type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
         virBufferAsprintf(buffer, "floppy%d.fileType = \"device\"\n", unit);

-        if (def->src != NULL) {
+        if (src) {
             virBufferAsprintf(buffer, "floppy%d.fileName = \"%s\"\n",
-                              unit, def->src);
+                              unit, src);
         }
     } else {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Floppy '%s' has unsupported type '%s', expecting '%s' "
                          "or '%s'"), def->dst,
-                       virDomainDiskTypeToString(def->type),
+                       virDomainDiskTypeToString(type),
                        virDomainDiskTypeToString(VIR_DOMAIN_DISK_TYPE_FILE),
                        virDomainDiskTypeToString(VIR_DOMAIN_DISK_TYPE_BLOCK));
         return -1;
-- 
1.8.5.3

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