]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Fix domain disk path iterator to work with networked storage
authorPeter Krempa <pkrempa@redhat.com>
Sat, 26 Apr 2014 09:38:29 +0000 (11:38 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 23 May 2014 07:25:52 +0000 (09:25 +0200)
Skip networked storage but continue iteration through backing chain to
iterate through all the local paths in the backing chain.

src/conf/domain_conf.c

index 01505cbf3d2af438ed7c39be70e6f9b4e71daca8..d6a1fc92af594e4f4dfa26b5a3ca7b80788c3e23 100644 (file)
@@ -18686,34 +18686,37 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
     int ret = -1;
     size_t depth = 0;
     virStorageSourcePtr tmp;
-    const char *path = virDomainDiskGetSource(disk);
-    int type = virDomainDiskGetType(disk);
+    char *brokenRaw = NULL;
 
-    if (!path || type == VIR_STORAGE_TYPE_NETWORK ||
-        (type == VIR_STORAGE_TYPE_VOLUME &&
-         disk->src.srcpool &&
-         disk->src.srcpool->mode == VIR_STORAGE_SOURCE_POOL_MODE_DIRECT))
-        return 0;
-
-    if (iter(disk, path, 0, opaque) < 0)
-        goto cleanup;
+    if (!ignoreOpenFailure) {
+        if (virStorageFileChainGetBroken(&disk->src, &brokenRaw) < 0)
+            goto cleanup;
 
-    tmp = disk->src.backingStore;
-    while (tmp && virStorageIsFile(tmp->path)) {
-        if (!ignoreOpenFailure && tmp->backingStoreRaw && !tmp->backingStore) {
+        if (brokenRaw) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unable to visit backing chain file %s"),
-                           tmp->backingStoreRaw);
+                           brokenRaw);
             goto cleanup;
         }
-        if (iter(disk, tmp->path, ++depth, opaque) < 0)
-            goto cleanup;
-        tmp = tmp->backingStore;
+    }
+
+    for (tmp = &disk->src; tmp; tmp = tmp->backingStore) {
+        int actualType = virStorageSourceGetActualType(tmp);
+        /* execute the callback only for local storage */
+        if (actualType != VIR_STORAGE_TYPE_NETWORK &&
+            actualType != VIR_STORAGE_TYPE_VOLUME &&
+            tmp->path) {
+            if (iter(disk, tmp->path, depth, opaque) < 0)
+                goto cleanup;
+        }
+
+        depth++;
     }
 
     ret = 0;
 
  cleanup:
+    VIR_FREE(brokenRaw);
     return ret;
 }