]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: domain: Refactor control flow in qemuDomainDetermineDiskChain
authorPeter Krempa <pkrempa@redhat.com>
Fri, 24 Nov 2017 11:09:53 +0000 (12:09 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 30 Nov 2017 21:40:23 +0000 (22:40 +0100)
Split out clearing of the backing chain prior to other code since it
will be required later and optimize few layers of nested conditions and
loops.

src/qemu/qemu_domain.c

index d1e391f4814d3bd5271f5e49676f2c5613583a20..5dc3d73f48fb0ae5cd7288c2dad7def3f9ba17c6 100644 (file)
@@ -6369,29 +6369,26 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
         goto cleanup;
     }
 
-    if (virStorageSourceHasBacking(src)) {
-        if (force_probe) {
-            virStorageSourceBackingStoreClear(src);
-        } else {
-            /* skip to the end of the chain */
-            while (virStorageSourceIsBacking(src)) {
-                if (report_broken &&
-                    virStorageFileSupportsAccess(src)) {
-
-                    if (qemuDomainStorageFileInit(driver, vm, src, disk->src) < 0)
-                        goto cleanup;
-
-                    if (virStorageFileAccess(src, F_OK) < 0) {
-                        virStorageFileReportBrokenChain(errno, src, disk->src);
-                        virStorageFileDeinit(src);
-                        goto cleanup;
-                    }
+    if (force_probe)
+        virStorageSourceBackingStoreClear(src);
 
-                    virStorageFileDeinit(src);
-                }
-                src = src->backingStore;
+    /* skip to the end of the chain if there is any */
+    while (virStorageSourceHasBacking(src)) {
+        if (report_broken &&
+            virStorageFileSupportsAccess(src)) {
+
+            if (qemuDomainStorageFileInit(driver, vm, src, disk->src) < 0)
+                goto cleanup;
+
+            if (virStorageFileAccess(src, F_OK) < 0) {
+                virStorageFileReportBrokenChain(errno, src, disk->src);
+                virStorageFileDeinit(src);
+                goto cleanup;
             }
+
+            virStorageFileDeinit(src);
         }
+        src = src->backingStore;
     }
 
     /* We skipped to the end of the chain. Skip detection if there's the