]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
util: storage: Make virStorageFileChainLookup more network storage aware
authorPeter Krempa <pkrempa@redhat.com>
Wed, 25 Jun 2014 11:45:54 +0000 (13:45 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 9 Jul 2014 09:35:16 +0000 (11:35 +0200)
Add a few checks and avoid resolving relative links on networked
storage.

src/util/virstoragefile.c

index 505b652169ae70d7d6d0f058846cb2483f322e8a..4dd76a7521af91dd74bf663145e60a3d41acabbc 100644 (file)
@@ -1333,13 +1333,12 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
     const char *tmp;
     char *parentDir = NULL;
     bool nameIsFile = virStorageIsFile(name);
-    size_t i;
+    size_t i = 0;
 
     if (!parent)
         parent = &tmp;
     *parent = NULL;
 
-    i = 0;
     if (startFrom) {
         while (chain && chain != startFrom->backingStore) {
             chain = chain->backingStore;
@@ -1360,24 +1359,26 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
             if (STREQ_NULLABLE(name, chain->relPath) ||
                 STREQ(name, chain->path))
                 break;
-            if (nameIsFile && (chain->type == VIR_STORAGE_TYPE_FILE ||
-                               chain->type == VIR_STORAGE_TYPE_BLOCK)) {
-                if (prev) {
-                    if (!(parentDir = mdir_name(prev->path))) {
-                        virReportOOMError();
-                        goto error;
-                    }
-                } else {
-                    if (VIR_STRDUP(parentDir, ".") < 0)
-                        goto error;
+
+            if (nameIsFile && virStorageSourceIsLocalStorage(chain)) {
+                if (prev && virStorageSourceIsLocalStorage(prev))
+                    parentDir = mdir_name(prev->path);
+                else
+                    ignore_value(VIR_STRDUP_QUIET(parentDir, "."));
+
+                if (!parentDir) {
+                    virReportOOMError();
+                    goto error;
                 }
 
                 int result = virFileRelLinkPointsTo(parentDir, name,
                                                     chain->path);
 
                 VIR_FREE(parentDir);
+
                 if (result < 0)
                     goto error;
+
                 if (result > 0)
                     break;
             }
@@ -1390,6 +1391,7 @@ virStorageFileChainLookup(virStorageSourcePtr chain,
 
     if (!chain)
         goto error;
+
     return chain;
 
  error: