[libvirt] [PATCH 5/7] storage:dir: .resizeVol callback for ploop volume

Olga Krishtal okrishtal at virtuozzo.com
Mon Feb 8 13:04:48 UTC 2016


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 at virtuozzo.com>
---
 src/storage/storage_backend.c    | 28 ++++++++++++++++++++++++++++
 src/storage/storage_backend.h    |  5 +++++
 src/storage/storage_backend_fs.c |  3 +++
 3 files changed, 36 insertions(+)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index f67953a..38ea601 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -867,6 +867,34 @@ int virStorageBackendDeletePloop(virConnectPtr conn ATTRIBUTE_UNUSED,
     return virFileDeleteTree(vol->target.path);
 }
 
+int virStoragePloopResize(virConnectPtr conn ATTRIBUTE_UNUSED,
+                          virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
+                          virStorageVolDefPtr vol,
+                          unsigned long long capacity)
+{
+    int ret;
+    char *path = NULL;
+    char *size = NULL;
+    virCommandPtr cmd = NULL;
+
+    if (virAsprintf(&path, "%s/%s", vol->target.path, "DiskDescriptor.xml") < 0)
+        return -1;
+
+    if (virAsprintf(&size, "%lluM", VIR_DIV_UP(capacity, 512)) < 0) {
+        ret = -1;
+        goto cleanup;
+    }
+    cmd = virCommandNewArgList("ploop", "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 7d354c5..1de8dfe 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -118,6 +118,11 @@ int virStorageBackendCreatePloop(virConnectPtr conn,
 int virStorageBackendDeletePloop(virConnectPtr conn,
                                  virStorageVolDefPtr vol);
 
+int virStoragePloopResize(virConnectPtr conn,
+                          virStoragePoolObjPtr pool,
+                          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 0df1880..2ec828b 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1379,6 +1379,9 @@ virStorageBackendFileSystemVolResize(virConnectPtr conn ATTRIBUTE_UNUSED,
     if (vol->target.format == VIR_STORAGE_FILE_RAW) {
         return virStorageFileResize(vol->target.path, capacity,
                                     vol->target.allocation, pre_allocate);
+    }
+    if (vol->target.format == VIR_STORAGE_FILE_PLOOP) {
+        return virStoragePloopResize(conn, pool, vol, capacity);
     } else {
         if (pre_allocate) {
             virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-- 
1.8.3.1




More information about the libvir-list mailing list