]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Storage: ZFS: implement `resizeVol` method to support native resize
authorGeorge Melikov <mail@gmelikov.ru>
Thu, 24 Jul 2025 14:34:03 +0000 (17:34 +0300)
committerDaniel P. Berrangé <berrange@redhat.com>
Tue, 5 Aug 2025 10:31:58 +0000 (11:31 +0100)
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.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: George Melikov <mail@gmelikov.ru>
src/storage/storage_backend_zfs.c

index 178b505e92a0bfd3d6b06bc9208621c7d3ef6198..33434d0cacf883ca4217019c6b80525cfd72029e 100644 (file)
@@ -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,
 };