[libvirt] [PATCH] Access qemu backing_file with relative pool path

Jesse Cook code.crashenx at gmail.com
Fri Mar 4 03:06:25 UTC 2011


This patch enables the relative backing file path support provided by
qemu-img create.

If the storage pool is not found with the specified path, check if the
file exists relative to the pool where the new image will be created by
prepending the storage pool path.
---
 src/storage/storage_backend.c |   32 ++++++++++++++++++++++++++++----
 1 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 2eede74..bb49f22 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -687,10 +687,34 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
             return -1;
         }
         if (access(vol->backingStore.path, R_OK) != 0) {
-            virReportSystemError(errno,
-                                 _("inaccessible backing store volume %s"),
-                                 vol->backingStore.path);
-            return -1;
+            /* If the backing store image is not found with the specified path,
+             * check for the file relative to the pool path. */
+            int accessRetCode = -1;
+
+            char *absolutePath = NULL;
+
+            virBuffer absPathBuf = VIR_BUFFER_INITIALIZER;
+
+            virBufferVSprintf(&absPathBuf,
+                              "%s/%s",
+                              pool->def->target.path,
+                              vol->backingStore.path);
+
+            if (virBufferError(&absPathBuf)) {
+                virBufferFreeAndReset(&absPathBuf);
+                virReportOOMError();
+                return -1;
+            }
+
+            absolutePath = virBufferContentAndReset(&absPathBuf);
+            accessRetCode = access(absolutePath, R_OK);
+            VIR_FREE(absolutePath);
+            if (accessRetCode != 0) {
+                virReportSystemError(errno,
+                                     _("inaccessible backing store volume %s"),
+                                     vol->backingStore.path);
+                return -1;
+            }
         }
     }
 
-- 
1.7.4.1




More information about the libvir-list mailing list