[PATCH 4/6] storage:dir: .resizeVol callback for ploop volume

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

 



To change the size of ploop image file we use ploop resize cmd that takes
2 args: new size and path/to/DiskDescriptor.xml

Signed-off-by: Olga Krishtal <okrishtal@xxxxxxxxxxxxx>
---
 src/storage/storage_backend.c    | 33 +++++++++++++++++++++++++++++++++
 src/storage/storage_backend.h    |  3 +++
 src/storage/storage_backend_fs.c |  2 ++
 3 files changed, 38 insertions(+)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index ac44fdf..18d414c 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -875,6 +875,39 @@ int virStorageBackendDeletePloop(virStorageVolDefPtr vol)
     return virFileDeleteTree(vol->target.path);
 }
 
+int virStoragePloopResize(virStorageVolDefPtr vol,
+                          unsigned long long capacity)
+{
+    int ret = -1;
+    char *path = NULL;
+    char *size = NULL;
+    virCommandPtr cmd = NULL;
+    char *create_tool = NULL;
+
+    create_tool = virFindFileInPath("ploop");
+    if (!create_tool) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "%s", _("unable to find ploop, please install "
+                       "ploop tools"));
+        return -1;
+    }
+    if (virAsprintf(&path, "%s/DiskDescriptor.xml", vol->target.path) < 0)
+        return -1;
+
+    if (virAsprintf(&size, "%lluM", VIR_DIV_UP(capacity, (1024 * 1024))) < 0)
+        goto cleanup;
+
+    cmd = virCommandNewArgList(create_tool, "resize", "-s", size, path, NULL);
+
+    ret = virCommandRun(cmd, NULL);
+
+ cleanup:
+    virCommandFree(cmd);
+    VIR_FREE(path);
+    VIR_FREE(size);
+    return ret;
+}
+
 enum {
     QEMU_IMG_BACKING_FORMAT_NONE = 0,
     QEMU_IMG_BACKING_FORMAT_FLAG,
diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index 3529755..65e91dc 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -117,6 +117,9 @@ int virStorageBackendCreatePloop(virConnectPtr conn,
 
 int virStorageBackendDeletePloop(virStorageVolDefPtr vol);
 
+int virStoragePloopResize(virStorageVolDefPtr vol,
+                          unsigned long long capacity);
+
 virStorageBackendBuildVolFrom
 virStorageBackendGetBuildVolFromFunction(virStorageVolDefPtr vol,
                                          virStorageVolDefPtr inputvol);
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index f494fd2..abb6e47 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1378,6 +1378,8 @@ virStorageBackendFileSystemVolResize(virConnectPtr conn ATTRIBUTE_UNUSED,
     if (vol->target.format == VIR_STORAGE_FILE_RAW) {
         return virStorageFileResize(vol->target.path, capacity,
                                     vol->target.allocation, pre_allocate);
+    } else if (vol->target.format == VIR_STORAGE_FILE_PLOOP) {
+        return virStoragePloopResize(vol, capacity);
     } else {
         if (pre_allocate) {
             virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-- 
1.8.3.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]