[PATCH 10/18] conf: use disk source accessors in qemu/

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

 



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

* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuAddSharedDevice, qemuRemoveSharedDevice, qemuSetUnprivSGIO):
Use accessors.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainObjCheckDiskTaint, qemuDomainSnapshotForEachQcow2Raw)
(qemuDomainCheckRemoveOptionalDisk, qemuDomainCheckDiskPresence)
(qemuDiskChainCheckBroken, qemuDomainDetermineDiskChain):
Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia)
(qemuDomainCheckEjectableMedia)
(qemuDomainAttachVirtioDiskDevice, qemuDomainAttachSCSIDisk)
(qemuDomainAttachUSBMassstorageDevice)
(qemuDomainAttachDeviceDiskLive, qemuDomainRemoveDiskDevice)
(qemuDomainDetachVirtioDiskDevice, qemuDomainDetachDiskDevice):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationStartNBDServer)
(qemuMigrationDriveMirror, qemuMigrationCancelDriveMirror)
(qemuMigrationIsSafe): Likewise.
* src/qemu/qemu_process.c (qemuProcessGetVolumeQcowPassphrase)
(qemuProcessHandleIOError, qemuProcessHandleBlockJob)
(qemuProcessInitPasswords): Likewise.
* src/qemu/qemu_driver.c (qemuDomainChangeDiskMediaLive)
(qemuDomainGetBlockInfo, qemuDiskPathToAlias): Likewise.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 src/qemu/qemu_conf.c      |  22 +++++----
 src/qemu/qemu_domain.c    |  60 +++++++++++++-----------
 src/qemu/qemu_driver.c    |  18 +++----
 src/qemu/qemu_hotplug.c   | 116 ++++++++++++++++++++++++++--------------------
 src/qemu/qemu_migration.c |  17 +++----
 src/qemu/qemu_process.c   |  11 +++--
 6 files changed, 135 insertions(+), 109 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 91c5e3a..d280c2c 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1,7 +1,7 @@
 /*
  * qemu_conf.c: QEMU configuration management
  *
- * Copyright (C) 2006-2013 Red Hat, Inc.
+ * Copyright (C) 2006-2014 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -744,6 +744,7 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
     char *key = NULL;
     int val;
     int ret = 0;
+    const char *src;

     if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
         disk = dev->data.disk;
@@ -757,7 +758,8 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
         return 0;
     }

-    if (!(sysfs_path = virGetUnprivSGIOSysfsPath(disk->src, NULL))) {
+    src = virDomainDiskGetSource(disk);
+    if (!(sysfs_path = virGetUnprivSGIOSysfsPath(src, NULL))) {
         ret = -1;
         goto cleanup;
     }
@@ -768,7 +770,7 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
     if (!virFileExists(sysfs_path))
         goto cleanup;

-    if (!(key = qemuGetSharedDeviceKey(disk->src))) {
+    if (!(key = qemuGetSharedDeviceKey(src))) {
         ret = -1;
         goto cleanup;
     }
@@ -779,7 +781,7 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
     if (!(virHashLookup(sharedDevices, key)))
         goto cleanup;

-    if (virGetDeviceUnprivSGIO(disk->src, NULL, &val) < 0) {
+    if (virGetDeviceUnprivSGIO(src, NULL, &val) < 0) {
         ret = -1;
         goto cleanup;
     }
@@ -791,7 +793,7 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
          disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))
         goto cleanup;

-    if (disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME) {
+    if (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_VOLUME) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        _("sgio of shared disk 'pool=%s' 'volume=%s' conflicts "
                          "with other active domains"),
@@ -800,7 +802,7 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
     } else {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        _("sgio of shared disk '%s' conflicts with other "
-                         "active domains"), disk->src);
+                         "active domains"), src);
     }

     ret = -1;
@@ -917,7 +919,7 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
         goto cleanup;

     if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
-        if (!(key = qemuGetSharedDeviceKey(disk->src)))
+        if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk))))
             goto cleanup;
     } else {
         if (!(dev_name = virSCSIDeviceGetDevName(NULL,
@@ -1022,7 +1024,7 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver,
     qemuDriverLock(driver);

     if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
-        if (!(key = qemuGetSharedDeviceKey(disk->src)))
+        if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk))))
             goto cleanup;
     } else {
         if (!(dev_name = virSCSIDeviceGetDevName(NULL,
@@ -1079,7 +1081,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
     virDomainDiskDefPtr disk = NULL;
     virDomainHostdevDefPtr hostdev = NULL;
     char *sysfs_path = NULL;
-    char *path = NULL;
+    const char *path = NULL;
     int val = -1;
     int ret = 0;

@@ -1093,7 +1095,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
             !virDomainDiskSourceIsBlockType(disk))
             return 0;

-        path = disk->src;
+        path = virDomainDiskGetSource(disk);
     } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
         hostdev = dev->data.hostdev;

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 7d375e5..d417387 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -872,10 +872,10 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
             /* assign default storage format and driver according to config */
             if (cfg->allowDiskFormatProbing) {
                 /* default disk format for drives */
-                if (disk->format == VIR_STORAGE_FILE_NONE &&
-                    (disk->type == VIR_DOMAIN_DISK_TYPE_FILE ||
-                     disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK))
-                    disk->format = VIR_STORAGE_FILE_AUTO;
+                if (virDomainDiskGetFormat(disk) == VIR_STORAGE_FILE_NONE &&
+                    (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_FILE ||
+                     virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_BLOCK))
+                    virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_AUTO);

                  /* default disk format for mirrored drive */
                 if (disk->mirror &&
@@ -883,15 +883,15 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
                     disk->mirrorFormat = VIR_STORAGE_FILE_AUTO;
             } else {
                 /* default driver if probing is forbidden */
-                if (!disk->driverName &&
-                    VIR_STRDUP(disk->driverName, "qemu") < 0)
+                if (!virDomainDiskGetDriver(disk) &&
+                    virDomainDiskSetDriver(disk, "qemu") < 0)
                         goto cleanup;

                 /* default disk format for drives */
-                if (disk->format == VIR_STORAGE_FILE_NONE &&
-                    (disk->type == VIR_DOMAIN_DISK_TYPE_FILE ||
-                     disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK))
-                    disk->format = VIR_STORAGE_FILE_RAW;
+                if (virDomainDiskGetFormat(disk) == VIR_STORAGE_FILE_NONE &&
+                    (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_FILE ||
+                     virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_BLOCK))
+                    virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW);

                  /* default disk format for mirrored drive */
                 if (disk->mirror &&
@@ -1697,8 +1697,9 @@ void qemuDomainObjCheckDiskTaint(virQEMUDriverPtr driver,
                                  int logFD)
 {
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    int format = virDomainDiskGetFormat(disk);

-    if ((!disk->format || disk->format == VIR_STORAGE_FILE_AUTO) &&
+    if ((!format || format == VIR_STORAGE_FILE_AUTO) &&
         cfg->allowDiskFormatProbing)
         qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_DISK_PROBING, logFD);

@@ -1939,8 +1940,9 @@ qemuDomainSnapshotForEachQcow2Raw(virQEMUDriverPtr driver,
     for (i = 0; i < ndisks; i++) {
         /* FIXME: we also need to handle LVM here */
         if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
-            if (def->disks[i]->format > 0 &&
-                def->disks[i]->format != VIR_STORAGE_FILE_QCOW2) {
+            int format = virDomainDiskGetFormat(def->disks[i]);
+
+            if (format > 0 && format != VIR_STORAGE_FILE_QCOW2) {
                 if (try_all) {
                     /* Continue on even in the face of error, since other
                      * disks in this VM may have the same snapshot name.
@@ -1962,7 +1964,7 @@ qemuDomainSnapshotForEachQcow2Raw(virQEMUDriverPtr driver,
                 return -1;
             }

-            qemuimgarg[4] = def->disks[i]->src;
+            qemuimgarg[4] = virDomainDiskGetSource(def->disks[i]);

             if (virRun(qemuimgarg, NULL) < 0) {
                 if (try_all) {
@@ -2160,28 +2162,29 @@ qemuDomainCheckRemoveOptionalDisk(virQEMUDriverPtr driver,
     char uuid[VIR_UUID_STRING_BUFLEN];
     virObjectEventPtr event = NULL;
     virDomainDiskDefPtr del_disk = NULL;
+    const char *src = virDomainDiskGetSource(disk);

     virUUIDFormat(vm->def->uuid, uuid);

     VIR_DEBUG("Dropping disk '%s' on domain '%s' (UUID '%s') "
               "due to inaccessible source '%s'",
-              disk->dst, vm->def->name, uuid, disk->src);
+              disk->dst, vm->def->name, uuid, src);

     if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM ||
         disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {

-        event = virDomainEventDiskChangeNewFromObj(vm, disk->src, NULL,
+        event = virDomainEventDiskChangeNewFromObj(vm, src, NULL,
                                                    disk->info.alias,
                                                    VIR_DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START);
-        VIR_FREE(disk->src);
+        ignore_value(virDomainDiskSetSource(disk, NULL));
     } else {
-        event = virDomainEventDiskChangeNewFromObj(vm, disk->src, NULL,
+        event = virDomainEventDiskChangeNewFromObj(vm, src, NULL,
                                                    disk->info.alias,
                                                    VIR_DOMAIN_EVENT_DISK_DROP_MISSING_ON_START);

-        if (!(del_disk = virDomainDiskRemoveByName(vm->def, disk->src))) {
+        if (!(del_disk = virDomainDiskRemoveByName(vm->def, src))) {
             virReportError(VIR_ERR_INVALID_ARG,
-                           _("no source device %s"), disk->src);
+                           _("no source device %s"), src);
             return -1;
         }
         virDomainDiskDefFree(del_disk);
@@ -2244,7 +2247,7 @@ qemuDomainCheckDiskPresence(virQEMUDriverPtr driver,
     for (i = vm->def->ndisks; i > 0; i--) {
         disk = vm->def->disks[i - 1];

-        if (!disk->src)
+        if (!virDomainDiskGetSource(disk))
             continue;

         if (qemuDomainDetermineDiskChain(driver, vm, disk, false) >= 0 &&
@@ -2339,7 +2342,7 @@ qemuDiskChainCheckBroken(virDomainDiskDefPtr disk)
 {
     char *brokenFile = NULL;

-    if (!disk->src || !disk->backingChain)
+    if (!virDomainDiskGetSource(disk) || !disk->backingChain)
         return 0;

     if (virStorageFileChainGetBroken(disk->backingChain, &brokenFile) < 0)
@@ -2348,7 +2351,7 @@ qemuDiskChainCheckBroken(virDomainDiskDefPtr disk)
     if (brokenFile) {
         virReportError(VIR_ERR_INVALID_ARG,
                        _("Backing file '%s' of image '%s' is missing."),
-                       brokenFile, disk->src);
+                       brokenFile, virDomainDiskGetSource(disk));
         VIR_FREE(brokenFile);
         return -1;
     }
@@ -2396,10 +2399,12 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
     int ret = 0;
     uid_t uid;
     gid_t gid;
+    const char *src = virDomainDiskGetSource(disk);
+    int type = virDomainDiskGetType(disk);

-    if (!disk->src ||
-        disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK ||
-        disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME)
+    if (!src ||
+        type == VIR_DOMAIN_DISK_TYPE_NETWORK ||
+        type == VIR_DOMAIN_DISK_TYPE_VOLUME)
         goto cleanup;

     if (disk->backingChain) {
@@ -2413,7 +2418,8 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,

     qemuDomainGetImageIds(cfg, vm, disk, &uid, &gid);

-    disk->backingChain = virStorageFileGetMetadata(disk->src, disk->format,
+    disk->backingChain = virStorageFileGetMetadata(src,
+                                                   virDomainDiskGetFormat(disk),
                                                    uid, gid,
                                                    cfg->allowDiskFormatProbing);
     if (!disk->backingChain)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2707bec..3b82c5a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6520,7 +6520,7 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
     if (ret != 0 &&
         qemuTeardownDiskCgroup(vm, disk) < 0)
         VIR_WARN("Failed to teardown cgroup for disk path %s",
-                 NULLSTR(disk->src));
+                 NULLSTR(virDomainDiskGetSource(disk)));

 end:
     virObjectUnref(caps);
@@ -10265,13 +10265,13 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
         goto cleanup;
     }
     disk = vm->def->disks[idx];
-    if (!disk->src) {
+    path = virDomainDiskGetSource(disk);
+    if (!path) {
         virReportError(VIR_ERR_INVALID_ARG,
                        _("disk %s does not currently have a source assigned"),
                        path);
         goto cleanup;
     }
-    path = disk->src;

     /* The path is correct, now try to open it and get its size. */
     fd = qemuOpenFile(driver, vm, path, O_RDONLY, NULL, NULL);
@@ -10279,18 +10279,18 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
         goto cleanup;

     /* Probe for magic formats */
-    if (disk->format) {
-        format = disk->format;
+    if (virDomainDiskGetFormat(disk)) {
+        format = virDomainDiskGetFormat(disk);
     } else {
         if (cfg->allowDiskFormatProbing) {
-            if ((format = virStorageFileProbeFormat(disk->src,
+            if ((format = virStorageFileProbeFormat(path,
                                                     cfg->user,
                                                     cfg->group)) < 0)
                 goto cleanup;
         } else {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("no disk format for %s and probing is disabled"),
-                           disk->src);
+                           path);
             goto cleanup;
         }
     }
@@ -10341,7 +10341,7 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
     /* ..but if guest is not using raw disk format and on a block device,
      * then query highest allocated extent from QEMU
      */
-    if (disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK &&
+    if (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_BLOCK &&
         format != VIR_STORAGE_FILE_RAW &&
         S_ISBLK(sb.st_mode)) {
         qemuDomainObjPrivatePtr priv = vm->privateData;
@@ -14620,7 +14620,7 @@ qemuDiskPathToAlias(virDomainObjPtr vm, const char *path, int *idxret)
     if (idxret)
         *idxret = idx;

-    if (disk->src) {
+    if (virDomainDiskGetSource(disk)) {
         if (virAsprintf(&ret, "drive-%s", disk->info.alias) < 0)
             return NULL;
     }
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index bf4f160..b948f2c 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -71,6 +71,7 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
     qemuDomainObjPrivatePtr priv = vm->privateData;
     int retries = CHANGE_MEDIA_RETRIES;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    const char *src = NULL;

     if (!origdisk->info.alias) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -93,7 +94,8 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
     if (virSecurityManagerSetImageLabel(driver->securityManager,
                                         vm->def, disk) < 0) {
         if (virDomainLockDiskDetach(driver->lockManager, vm, disk) < 0)
-            VIR_WARN("Unable to release lock on %s", disk->src);
+            VIR_WARN("Unable to release lock on %s",
+                     virDomainDiskGetSource(disk));
         goto cleanup;
     }

@@ -128,41 +130,49 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
     }
     ret = 0;

-    if (disk->src) {
+    src = virDomainDiskGetSource(disk);
+    if (src) {
         /* deliberately don't depend on 'ret' as 'eject' may have failed the
          * first time and we are going to check the drive state anyway */
         const char *format = NULL;
+        int type = virDomainDiskGetType(disk);
+        int diskFormat = virDomainDiskGetFormat(disk);

-        if (disk->type != VIR_DOMAIN_DISK_TYPE_DIR) {
-            if (disk->format > 0)
-                format = virStorageFileFormatTypeToString(disk->format);
-            else if (origdisk->format > 0)
-                format = virStorageFileFormatTypeToString(origdisk->format);
+        if (type != VIR_DOMAIN_DISK_TYPE_DIR) {
+            if (diskFormat > 0) {
+                format = virStorageFileFormatTypeToString(diskFormat);
+            } else {
+                diskFormat = virDomainDiskGetFormat(origdisk);
+                if (diskFormat > 0)
+                    format = virStorageFileFormatTypeToString(diskFormat);
+            }
         }
         qemuDomainObjEnterMonitor(driver, vm);
         ret = qemuMonitorChangeMedia(priv->mon,
                                      driveAlias,
-                                     disk->src, format);
+                                     src, format);
         qemuDomainObjExitMonitor(driver, vm);
     }
 audit:
-    virDomainAuditDisk(vm, origdisk->src, disk->src, "update", ret >= 0);
+    if (src)
+        virDomainAuditDisk(vm, virDomainDiskGetSource(origdisk),
+                           src, "update", ret >= 0);

     if (ret < 0)
         goto error;

     if (virSecurityManagerRestoreImageLabel(driver->securityManager,
                                             vm->def, origdisk) < 0)
-        VIR_WARN("Unable to restore security label on ejected image %s", origdisk->src);
+        VIR_WARN("Unable to restore security label on ejected image %s",
+                 virDomainDiskGetSource(origdisk));

     if (virDomainLockDiskDetach(driver->lockManager, vm, origdisk) < 0)
-        VIR_WARN("Unable to release lock on disk %s", origdisk->src);
-
-    VIR_FREE(origdisk->src);
-    origdisk->src = disk->src;
-    disk->src = NULL;
-    origdisk->type = disk->type;
+        VIR_WARN("Unable to release lock on disk %s",
+                 virDomainDiskGetSource(origdisk));

+    if (virDomainDiskSetSource(origdisk, src) < 0)
+        goto error;
+    virDomainDiskSetType(origdisk, virDomainDiskGetType(disk));

     virDomainDiskDefFree(disk);

@@ -174,10 +184,10 @@ cleanup:
 error:
     if (virSecurityManagerRestoreImageLabel(driver->securityManager,
                                             vm->def, disk) < 0)
-        VIR_WARN("Unable to restore security label on new media %s", disk->src);
+        VIR_WARN("Unable to restore security label on new media %s", src);

     if (virDomainLockDiskDetach(driver->lockManager, vm, disk) < 0)
-        VIR_WARN("Unable to release lock on %s", disk->src);
+        VIR_WARN("Unable to release lock on %s", src);

     goto cleanup;
 }
@@ -213,8 +223,8 @@ qemuDomainCheckEjectableMedia(virQEMUDriverPtr driver,
         if (!info)
             goto cleanup;

-        if (info->tray_open && disk->src)
-            VIR_FREE(disk->src);
+        if (info->tray_open && virDomainDiskGetSource(disk))
+            ignore_value(virDomainDiskSetSource(disk, NULL));
     }

     ret = 0;
@@ -238,6 +248,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
     char *drivestr = NULL;
     bool releaseaddr = false;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    const char *src = virDomainDiskGetSource(disk);

     if (!disk->info.type) {
         if (STREQLEN(vm->def->os.machine, "s390-ccw", 8) &&
@@ -262,7 +273,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
     if (virSecurityManagerSetImageLabel(driver->securityManager,
                                         vm->def, disk) < 0) {
         if (virDomainLockDiskDetach(driver->lockManager, vm, disk) < 0)
-            VIR_WARN("Unable to release lock on %s", disk->src);
+            VIR_WARN("Unable to release lock on %s", src);
         goto cleanup;
     }

@@ -311,10 +322,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
     } else if (!disk->info.type ||
                 disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
         virDevicePCIAddress guestAddr = disk->info.addr.pci;
-        ret = qemuMonitorAddPCIDisk(priv->mon,
-                                    disk->src,
-                                    type,
-                                    &guestAddr);
+        ret = qemuMonitorAddPCIDisk(priv->mon, src, type, &guestAddr);
         if (ret == 0) {
             disk->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
             memcpy(&disk->info.addr.pci, &guestAddr, sizeof(guestAddr));
@@ -322,7 +330,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
     }
     qemuDomainObjExitMonitor(driver, vm);

-    virDomainAuditDisk(vm, NULL, disk->src, "attach", ret >= 0);
+    virDomainAuditDisk(vm, NULL, src, "attach", ret >= 0);

     if (ret < 0)
         goto error;
@@ -337,14 +345,14 @@ cleanup:

 error:
     if (releaseaddr)
-        qemuDomainReleaseDeviceAddress(vm, &disk->info, disk->src);
+        qemuDomainReleaseDeviceAddress(vm, &disk->info, src);

     if (virSecurityManagerRestoreImageLabel(driver->securityManager,
                                             vm->def, disk) < 0)
-        VIR_WARN("Unable to restore security label on %s", disk->src);
+        VIR_WARN("Unable to restore security label on %s", src);

     if (virDomainLockDiskDetach(driver->lockManager, vm, disk) < 0)
-        VIR_WARN("Unable to release lock on %s", disk->src);
+        VIR_WARN("Unable to release lock on %s", src);

     goto cleanup;
 }
@@ -487,6 +495,7 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
     char *devstr = NULL;
     int ret = -1;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    const char *src = virDomainDiskGetSource(disk);

     for (i = 0; i < vm->def->ndisks; i++) {
         if (STREQ(vm->def->disks[i]->dst, disk->dst)) {
@@ -503,7 +512,7 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
     if (virSecurityManagerSetImageLabel(driver->securityManager,
                                         vm->def, disk) < 0) {
         if (virDomainLockDiskDetach(driver->lockManager, vm, disk) < 0)
-            VIR_WARN("Unable to release lock on %s", disk->src);
+            VIR_WARN("Unable to release lock on %s", src);
         goto cleanup;
     }

@@ -574,7 +583,7 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
     }
     qemuDomainObjExitMonitor(driver, vm);

-    virDomainAuditDisk(vm, NULL, disk->src, "attach", ret >= 0);
+    virDomainAuditDisk(vm, NULL, src, "attach", ret >= 0);

     if (ret < 0)
         goto error;
@@ -590,10 +599,10 @@ cleanup:
 error:
     if (virSecurityManagerRestoreImageLabel(driver->securityManager,
                                             vm->def, disk) < 0)
-        VIR_WARN("Unable to restore security label on %s", disk->src);
+        VIR_WARN("Unable to restore security label on %s", src);

     if (virDomainLockDiskDetach(driver->lockManager, vm, disk) < 0)
-        VIR_WARN("Unable to release lock on %s", disk->src);
+        VIR_WARN("Unable to release lock on %s", src);

     goto cleanup;
 }
@@ -611,6 +620,7 @@ qemuDomainAttachUSBMassstorageDevice(virConnectPtr conn,
     char *drivestr = NULL;
     char *devstr = NULL;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    const char *src = virDomainDiskGetSource(disk);

     for (i = 0; i < vm->def->ndisks; i++) {
         if (STREQ(vm->def->disks[i]->dst, disk->dst)) {
@@ -627,12 +637,12 @@ qemuDomainAttachUSBMassstorageDevice(virConnectPtr conn,
     if (virSecurityManagerSetImageLabel(driver->securityManager,
                                         vm->def, disk) < 0) {
         if (virDomainLockDiskDetach(driver->lockManager, vm, disk) < 0)
-            VIR_WARN("Unable to release lock on %s", disk->src);
+            VIR_WARN("Unable to release lock on %s", src);
         goto cleanup;
     }

     /* XXX not correct once we allow attaching a USB CDROM */
-    if (!disk->src) {
+    if (!src) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("disk source path is missing"));
         goto error;
@@ -663,11 +673,11 @@ qemuDomainAttachUSBMassstorageDevice(virConnectPtr conn,
             }
         }
     } else {
-        ret = qemuMonitorAddUSBDisk(priv->mon, disk->src);
+        ret = qemuMonitorAddUSBDisk(priv->mon, src);
     }
     qemuDomainObjExitMonitor(driver, vm);

-    virDomainAuditDisk(vm, NULL, disk->src, "attach", ret >= 0);
+    virDomainAuditDisk(vm, NULL, src, "attach", ret >= 0);

     if (ret < 0)
         goto error;
@@ -683,10 +693,10 @@ cleanup:
 error:
     if (virSecurityManagerRestoreImageLabel(driver->securityManager,
                                             vm->def, disk) < 0)
-        VIR_WARN("Unable to restore security label on %s", disk->src);
+        VIR_WARN("Unable to restore security label on %s", src);

     if (virDomainLockDiskDetach(driver->lockManager, vm, disk) < 0)
-        VIR_WARN("Unable to release lock on %s", disk->src);
+        VIR_WARN("Unable to release lock on %s", src);

     goto cleanup;
 }
@@ -704,11 +714,13 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
     virDomainDiskDefPtr tmp = NULL;
     virCapsPtr caps = NULL;
     int ret = -1;
+    const char *driverName = virDomainDiskGetDriver(disk);
+    const char *src = virDomainDiskGetSource(disk);

-    if (disk->driverName != NULL && !STREQ(disk->driverName, "qemu")) {
+    if (driverName && !STREQ(driverName, "qemu")) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("unsupported driver name '%s' for disk '%s'"),
-                       disk->driverName, disk->src);
+                       driverName, src);
         goto end;
     }

@@ -794,7 +806,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
     if (ret != 0 &&
         qemuTeardownDiskCgroup(vm, disk) < 0) {
         VIR_WARN("Failed to teardown cgroup for disk path %s",
-                 NULLSTR(disk->src));
+                 NULLSTR(src));
     }

 end:
@@ -2460,11 +2472,12 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
     virDomainDeviceDef dev;
     virObjectEventPtr event;
     size_t i;
+    const char *src = virDomainDiskGetSource(disk);

     VIR_DEBUG("Removing disk %s from domain %p %s",
               disk->info.alias, vm, vm->def->name);

-    virDomainAuditDisk(vm, disk->src, NULL, "detach", true);
+    virDomainAuditDisk(vm, src, NULL, "detach", true);

     event = virDomainEventDeviceRemovedNewFromObj(vm, disk->info.alias);
     if (event)
@@ -2477,17 +2490,17 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
         }
     }

-    qemuDomainReleaseDeviceAddress(vm, &disk->info, disk->src);
+    qemuDomainReleaseDeviceAddress(vm, &disk->info, src);

     if (virSecurityManagerRestoreImageLabel(driver->securityManager,
                                             vm->def, disk) < 0)
-        VIR_WARN("Unable to restore security label on %s", disk->src);
+        VIR_WARN("Unable to restore security label on %s", src);

     if (qemuTeardownDiskCgroup(vm, disk) < 0)
-        VIR_WARN("Failed to tear down cgroup for disk path %s", disk->src);
+        VIR_WARN("Failed to tear down cgroup for disk path %s", src);

     if (virDomainLockDiskDetach(driver->lockManager, vm, disk) < 0)
-        VIR_WARN("Unable to release lock on %s", disk->src);
+        VIR_WARN("Unable to release lock on %s", src);

     dev.type = VIR_DOMAIN_DEVICE_DISK;
     dev.data.disk = disk;
@@ -2858,14 +2871,16 @@ qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver,
     if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
         if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) {
             qemuDomainObjExitMonitor(driver, vm);
-            virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
+            virDomainAuditDisk(vm, virDomainDiskGetSource(detach),
+                               NULL, "detach", false);
             goto cleanup;
         }
     } else {
         if (qemuMonitorRemovePCIDevice(priv->mon,
                                        &detach->info.addr.pci) < 0) {
             qemuDomainObjExitMonitor(driver, vm);
-            virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
+            virDomainAuditDisk(vm, virDomainDiskGetSource(detach),
+                               NULL, "detach", false);
             goto cleanup;
         }
     }
@@ -2919,7 +2934,8 @@ qemuDomainDetachDiskDevice(virQEMUDriverPtr driver,
     qemuDomainObjEnterMonitor(driver, vm);
     if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) {
         qemuDomainObjExitMonitor(driver, vm);
-        virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
+        virDomainAuditDisk(vm, virDomainDiskGetSource(detach),
+                           NULL, "detach", false);
         goto cleanup;
     }

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 26ac99b..0a243c8 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1159,7 +1159,7 @@ qemuMigrationStartNBDServer(virQEMUDriverPtr driver,
         virDomainDiskDefPtr disk = vm->def->disks[i];

         /* skip shared, RO and source-less disks */
-        if (disk->shared || disk->readonly || !disk->src)
+        if (disk->shared || disk->readonly || !virDomainDiskGetSource(disk))
             continue;

         VIR_FREE(diskAlias);
@@ -1265,7 +1265,7 @@ qemuMigrationDriveMirror(virQEMUDriverPtr driver,
         virDomainBlockJobInfo info;

         /* skip shared, RO and source-less disks */
-        if (disk->shared || disk->readonly || !disk->src)
+        if (disk->shared || disk->readonly || !virDomainDiskGetSource(disk))
             continue;

         VIR_FREE(diskAlias);
@@ -1351,7 +1351,7 @@ error:
         virDomainDiskDefPtr disk = vm->def->disks[--lastGood];

         /* skip shared, RO disks */
-        if (disk->shared || disk->readonly || !disk->src)
+        if (disk->shared || disk->readonly || !virDomainDiskGetSource(disk))
             continue;

         VIR_FREE(diskAlias);
@@ -1414,7 +1414,7 @@ qemuMigrationCancelDriveMirror(qemuMigrationCookiePtr mig,
         virDomainDiskDefPtr disk = vm->def->disks[i];

         /* skip shared, RO and source-less disks */
-        if (disk->shared || disk->readonly || !disk->src)
+        if (disk->shared || disk->readonly || !virDomainDiskGetSource(disk))
             continue;

         VIR_FREE(diskAlias);
@@ -1523,21 +1523,22 @@ qemuMigrationIsSafe(virDomainDefPtr def)

     for (i = 0; i < def->ndisks; i++) {
         virDomainDiskDefPtr disk = def->disks[i];
+        const char *src = virDomainDiskGetSource(disk);

         /* Our code elsewhere guarantees shared disks are either readonly (in
          * which case cache mode doesn't matter) or used with cache=none */
-        if (disk->src &&
+        if (src &&
             !disk->shared &&
             !disk->readonly &&
             disk->cachemode != VIR_DOMAIN_DISK_CACHE_DISABLE) {
             int rc;

-            if (disk->type == VIR_DOMAIN_DISK_TYPE_FILE) {
-                if ((rc = virStorageFileIsSharedFS(disk->src)) < 0)
+            if (virDomainDiskGetType(disk) == VIR_DOMAIN_DISK_TYPE_FILE) {
+                if ((rc = virStorageFileIsSharedFS(src)) < 0)
                     return false;
                 else if (rc == 0)
                     continue;
-                if ((rc = virStorageFileIsClusterFS(disk->src)) < 0)
+                if ((rc = virStorageFileIsClusterFS(src)) < 0)
                     return false;
                 else if (rc == 1)
                     continue;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 6c4543f..978e7b4 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -448,7 +448,8 @@ qemuProcessGetVolumeQcowPassphrase(virConnectPtr conn,
         enc->secrets[0]->type !=
         VIR_STORAGE_ENCRYPTION_SECRET_TYPE_PASSPHRASE) {
         virReportError(VIR_ERR_XML_ERROR,
-                       _("invalid <encryption> for volume %s"), disk->src);
+                       _("invalid <encryption> for volume %s"),
+                       virDomainDiskGetSource(disk));
         goto cleanup;
     }

@@ -467,7 +468,7 @@ qemuProcessGetVolumeQcowPassphrase(virConnectPtr conn,
         VIR_FREE(data);
         virReportError(VIR_ERR_XML_ERROR,
                        _("format='qcow' passphrase for %s must not contain a "
-                         "'\\0'"), disk->src);
+                         "'\\0'"), virDomainDiskGetSource(disk));
         goto cleanup;
     }

@@ -930,7 +931,7 @@ qemuProcessHandleIOError(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
     disk = qemuProcessFindDomainDiskByAlias(vm, diskAlias);

     if (disk) {
-        srcPath = disk->src;
+        srcPath = virDomainDiskGetSource(disk);
         devAlias = disk->info.alias;
     } else {
         srcPath = "";
@@ -987,7 +988,7 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
     disk = qemuProcessFindDomainDiskByAlias(vm, diskAlias);

     if (disk) {
-        path = disk->src;
+        path = virDomainDiskGetSource(disk);
         event = virDomainEventBlockJobNewFromObj(vm, path, type, status);
         /* XXX If we completed a block pull or commit, then recompute
          * the cached backing chain to match.  Better would be storing
@@ -2193,7 +2194,7 @@ qemuProcessInitPasswords(virConnectPtr conn,
             const char *alias;

             if (!vm->def->disks[i]->encryption ||
-                !vm->def->disks[i]->src)
+                !virDomainDiskGetSource(vm->def->disks[i]))
                 continue;

             if (qemuProcessGetVolumeQcowPassphrase(conn,
-- 
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]