[PATCH] Allow relative path for qemu backing file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

This patch takes the place of a previous patch:
  http://www.redhat.com/archives/libvir-list/2011-March/msg00179.html
---
 src/storage/storage_backend.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 2eede74..abdc2dd 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -666,6 +666,9 @@ 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
@@ -686,7 +689,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);
+
+        } else {
+            virAsprintf(&absolutePath, "%s", vol->backingStore.path);
+        }
+        accessRetCode = access(absolutePath, R_OK);
+        VIR_FREE(absolutePath);
+        if (accessRetCode != 0) {
             virReportSystemError(errno,
                                  _("inaccessible backing store volume %s"),
                                  vol->backingStore.path);
-- 
1.7.4.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]