Re: [PATCH 4/7] storage:dir: adapts .uploadVol .dowloadVol for ploop volume

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

 





On 05.02.2016 19:23, Olga Krishtal wrote:
In case of ploop volume, target path of the volume is the path to the
directory that contains image file named root.hds and DiskDescriptor.xml.
While using uploadVol and downloadVol callbacks we need to open root.hds
itself. To accomplish this goal we must change path from
path/to/ploop directory to path/to/ploop/root.hds

Signed-off-by: Olga Krishtal <okrishtal@xxxxxxxxxxxxx>
---
  src/storage/storage_backend.c | 27 ++++++++++++++++++++++++---
  1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 1b4ffbc..2afcc7c 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -2016,12 +2016,23 @@ virStorageBackendVolUploadLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
                                  unsigned long long len,
                                  unsigned int flags)
  {
+    char *path = NULL;
+    char *target_path = vol->target.path;
+    int ret;
+
      virCheckFlags(0, -1);
+    if (vol->type == VIR_STORAGE_VOL_PLOOP) {
+        if (virAsprintf(&path, "%s/%s", vol->target.path, "root.hds") < 0)
+            return -1;
+        target_path = path;
+    }
/* Not using O_CREAT because the file is required to already exist at
       * this point */
-    return virFDStreamOpenBlockDevice(stream, vol->target.path,
+    ret =  virFDStreamOpenBlockDevice(stream, target_path,
Delete one space after "="
                                        offset, len, O_WRONLY);
+    VIR_FREE(path);
+    return ret;
  }
int
@@ -2033,10 +2044,20 @@ virStorageBackendVolDownloadLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
                                    unsigned long long len,
                                    unsigned int flags)
  {
-    virCheckFlags(0, -1);
+    char *path = NULL;
+    char *target_path = vol->target.path;
+    int ret;
+    if (vol->type == VIR_STORAGE_VOL_PLOOP) {
+        if (virAsprintf(&path, "%s/%s", vol->target.path, "root.hds") < 0)
+            return -1;
+        target_path = path;
+    }
- return virFDStreamOpenBlockDevice(stream, vol->target.path,
+    virCheckFlags(0, -1);
+    ret = virFDStreamOpenBlockDevice(stream, target_path,
                                        offset, len, O_RDONLY);
+    VIR_FREE(path);
+    return ret;
  }
Memory leak.
If virCheckFlags fails than we do not free "path" memory

--
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]