From: George Melikov Date: Thu, 24 Jul 2025 14:34:03 +0000 (+0300) Subject: Storage: ZFS: implement `resizeVol` method to support native resize X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=thirdparty%2Flibvirt.git Storage: ZFS: implement `resizeVol` method to support native resize 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é Signed-off-by: George Melikov --- 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, };