]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: domain: don't loop through images in qemuDomainPrepareDiskSourceChain
authorPeter Krempa <pkrempa@redhat.com>
Tue, 29 May 2018 15:05:05 +0000 (17:05 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 5 Jun 2018 06:13:58 +0000 (08:13 +0200)
Convert the function to just prepare data for the disk. Callers need to
do the looping since there's more to do than just copy the data around.

The code path in qemuDomainPrepareDiskSource doesn't need to loop over
the chain yet, since there currently is no chain at this point. This
will be addressed later in the blockdev series where we will setup much
more stuff.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
tests/qemublocktest.c

index 5f2c99d6519c7e4473e828b5b79749270a6f6ab8..91e5e2875917e01efa778523972dbd9be2fa6496 100644 (file)
@@ -8034,6 +8034,7 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
 {
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     virStorageSourcePtr src = disk->src;
+    virStorageSourcePtr n;
     qemuDomainObjPrivatePtr priv = vm->privateData;
     int ret = -1;
     uid_t uid;
@@ -8116,9 +8117,10 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
                                   report_broken) < 0)
         goto cleanup;
 
-    /* fill in data for the rest of the chain */
-    if (qemuDomainPrepareDiskSourceChain(disk, src, cfg, priv->qemuCaps) < 0)
-        goto cleanup;
+    for (n = src; virStorageSourceIsBacking(n); n = n->backingStore) {
+        if (qemuDomainPrepareDiskSourceData(disk, n, cfg, priv->qemuCaps) < 0)
+            goto cleanup;
+    }
 
     ret = 0;
 
@@ -12399,51 +12401,44 @@ qemuDomainCheckCCWS390AddressSupport(const virDomainDef *def,
 
 
 /**
- * qemuDomainPrepareDiskSourceChain:
+ * qemuDomainPrepareDiskSourceData:
  *
  * @disk: Disk config object
  * @src: source to start from
  * @cfg: qemu driver config object
  *
- * Prepares various aspects of the disk source and it's backing chain. This
- * function should be also called for detected backing chains. If @src is NULL
- * the root source is used.
+ * Prepares various aspects of a storage source belonging to a disk backing
+ * chain. This function should be also called for detected backing chain
+ * members.
  */
 int
-qemuDomainPrepareDiskSourceChain(virDomainDiskDefPtr disk,
-                                 virStorageSourcePtr src,
-                                 virQEMUDriverConfigPtr cfg,
-                                 virQEMUCapsPtr qemuCaps)
+qemuDomainPrepareDiskSourceData(virDomainDiskDefPtr disk,
+                                virStorageSourcePtr src,
+                                virQEMUDriverConfigPtr cfg,
+                                virQEMUCapsPtr qemuCaps)
 {
-    virStorageSourcePtr n;
-
-    if (!src)
-        src = disk->src;
-
     /* transfer properties valid only for the top level image */
     if (src == disk->src)
         src->detect_zeroes = disk->detect_zeroes;
 
-    for (n = src; virStorageSourceIsBacking(n); n = n->backingStore) {
-        if (cfg &&
-            n->type == VIR_STORAGE_TYPE_NETWORK &&
-            n->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER &&
-            virQEMUCapsGet(qemuCaps, QEMU_CAPS_GLUSTER_DEBUG_LEVEL)) {
-            n->debug = true;
-            n->debugLevel = cfg->glusterDebugLevel;
-        }
+    if (cfg &&
+        src->type == VIR_STORAGE_TYPE_NETWORK &&
+        src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER &&
+        virQEMUCapsGet(qemuCaps, QEMU_CAPS_GLUSTER_DEBUG_LEVEL)) {
+        src->debug = true;
+        src->debugLevel = cfg->glusterDebugLevel;
+    }
 
-        if (qemuDomainValidateStorageSource(n, qemuCaps) < 0)
-            return -1;
+    if (qemuDomainValidateStorageSource(src, qemuCaps) < 0)
+        return -1;
 
-        /* transfer properties valid for the full chain */
-        n->iomode = disk->iomode;
-        n->cachemode = disk->cachemode;
-        n->discard = disk->discard;
+    /* transfer properties valid for the full chain */
+    src->iomode = disk->iomode;
+    src->cachemode = disk->cachemode;
+    src->discard = disk->discard;
 
-        if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
-            n->floppyimg = true;
-    }
+    if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
+        src->floppyimg = true;
 
     return 0;
 }
@@ -12493,7 +12488,7 @@ qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk,
     if (qemuDomainSecretDiskPrepare(priv, disk) < 0)
         return -1;
 
-    if (qemuDomainPrepareDiskSourceChain(disk, NULL, cfg, priv->qemuCaps) < 0)
+    if (qemuDomainPrepareDiskSourceData(disk, disk->src, cfg, priv->qemuCaps) < 0)
         return -1;
 
     if (qemuDomainPrepareStorageSourcePR(disk->src, priv, disk->info.alias) < 0)
index 3e139e0c57f9469b9d056240d140dc1a1f2768ee..36b000be6031e8557d33b461b4b854d89c5f2282 100644 (file)
@@ -1003,10 +1003,10 @@ bool qemuDomainCheckCCWS390AddressSupport(const virDomainDef *def,
                                     const char *devicename);
 
 int
-qemuDomainPrepareDiskSourceChain(virDomainDiskDefPtr disk,
-                                 virStorageSourcePtr src,
-                                 virQEMUDriverConfigPtr cfg,
-                                 virQEMUCapsPtr qemuCaps)
+qemuDomainPrepareDiskSourceData(virDomainDiskDefPtr disk,
+                                virStorageSourcePtr src,
+                                virQEMUDriverConfigPtr cfg,
+                                virQEMUCapsPtr qemuCaps)
     ATTRIBUTE_RETURN_CHECK;
 
 int
index d671505969e4f436a247e0143922da6f4633ff20..7f39f6101885ec85bccbef908a14e0d43f2ea6e1 100644 (file)
@@ -215,13 +215,13 @@ testQemuDiskXMLToProps(const void *opaque)
         goto cleanup;
     }
 
-    if (qemuDomainPrepareDiskSourceChain(disk, NULL, NULL, data->qemuCaps) < 0)
-        goto cleanup;
-
     for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
         if (testQemuDiskXMLToJSONFakeSecrets(n) < 0)
             goto cleanup;
 
+        if (qemuDomainPrepareDiskSourceData(disk, n, NULL, data->qemuCaps) < 0)
+            goto cleanup;
+
         if (!(formatProps = qemuBlockStorageSourceGetBlockdevProps(n)) ||
             !(storageProps = qemuBlockStorageSourceGetBackendProps(n, false))) {
             if (!data->fail) {