]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Allow relative path for qemu backing file
authorJesse Cook <code.crashenx@gmail.com>
Mon, 28 Mar 2011 01:30:14 +0000 (20:30 -0500)
committerEric Blake <eblake@redhat.com>
Mon, 4 Apr 2011 22:37:58 +0000 (16:37 -0600)
This patch enables the relative backing file path support provided by
qemu-img create.

If a relative path is specified for the backing file, it is converted
to an absolute path using the storage pool path. The absolute path is
used to verify that the backing file exists. If the backing file exists,
the relative path is allowed and will be provided to qemu-img create.

AUTHORS
src/storage/storage_backend.c

diff --git a/AUTHORS b/AUTHORS
index 19abaf1158b4c8372662d862fcbf8e9556cdf3bb..821cd396166ad359918d95f47f4a8eb1fd83edca 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -164,6 +164,7 @@ Patches have also been contributed by:
   Tiziano Mueller      <dev-zero@gentoo.org>
   Thibault VINCENT     <thibault.vincent@smartjog.com>
   Naoya Horiguchi      <n-horiguchi@ah.jp.nec.com>
+  Jesse Cook           <code.crashenx@gmail.com>
 
   [....send patches to get your name here....]
 
index 9b7bcc46b69e1cbf818f872563a6a2abf547b339..8af2878bed72de5ab9b71b8af2e655aa89c568b8 100644 (file)
@@ -692,6 +692,8 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
     }
 
     if (vol->backingStore.path) {
+        int accessRetCode = -1;
+        char *absolutePath = NULL;
 
         /* XXX: Not strictly required: qemu-img has an option a different
          * backing store, not really sure what use it serves though, and it
@@ -712,7 +714,20 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
                                   vol->backingStore.format);
             return -1;
         }
-        if (access(vol->backingStore.path, R_OK) != 0) {
+
+        /* Convert relative backing store paths to absolute paths for access
+         * validation.
+         */
+        if ('/' != *(vol->backingStore.path) &&
+            virAsprintf(&absolutePath, "%s/%s", pool->def->target.path,
+                        vol->backingStore.path) < 0) {
+            virReportOOMError();
+            return -1;
+        }
+        accessRetCode = access(absolutePath ? absolutePath
+                               : vol->backingStore.path, R_OK);
+        VIR_FREE(absolutePath);
+        if (accessRetCode != 0) {
             virReportSystemError(errno,
                                  _("inaccessible backing store volume %s"),
                                  vol->backingStore.path);