[PATCH] Storage: ZFS: implement `resizeVol` method to support native resize

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

 



From: George Melikov <mail@xxxxxxxxxxx>

ZFS doesn't have thick allocations, every allocation is
thin-provisioned, so resize operation is essentially
a zvol size limit change
(`zfs set volsize=X pool/zvol_name`).

Shrink is allowed too (which leads to data destruction),
but shrink restriction is already implemented in libvirt,
so this function doesn't need to check anything.

This patch is posted via PR too and has green test runs
https://gitlab.com/libvirt/libvirt/-/merge_requests/495

Signed-off-by: George Melikov <mail@xxxxxxxxxxx>
---
 src/storage/storage_backend_zfs.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backend_zfs.c
index 178b505e92..33434d0cac 100644
--- a/src/storage/storage_backend_zfs.c
+++ b/src/storage/storage_backend_zfs.c
@@ -439,6 +439,25 @@ virStorageBackendZFSDeletePool(virStoragePoolObj *pool,
     return virCommandRun(cmd, NULL);
 }
 
+static int
+virStorageBackendZFSResizeVol(virStoragePoolObj *pool,
+                              virStorageVolDef *vol,
+                              unsigned long long capacity,
+                              unsigned int flags)
+{
+    virStoragePoolDef *def = virStoragePoolObjGetDef(pool);
+    g_autoptr(virCommand) resize_cmd = NULL;
+
+    virCheckFlags(0, -1);
+
+    resize_cmd = virCommandNewArgList(ZFS, "set", NULL);
+    virCommandAddArgFormat(resize_cmd, "volsize=%llu", capacity);
+    virCommandAddArgFormat(resize_cmd, "%s/%s",
+                           def->source.name, vol->name);
+
+    return virCommandRun(resize_cmd, NULL);
+}
+
 virStorageBackend virStorageBackendZFS = {
     .type = VIR_STORAGE_POOL_ZFS,
 
@@ -450,6 +469,7 @@ virStorageBackend virStorageBackendZFS = {
     .deletePool = virStorageBackendZFSDeletePool,
     .uploadVol = virStorageBackendVolUploadLocal,
     .downloadVol = virStorageBackendVolDownloadLocal,
+    .resizeVol = virStorageBackendZFSResizeVol,
 };
 
 
-- 
2.47.2



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

  Powered by Linux