[pve-devel] [PATCH storage] Automatically round up to the next valid size when resizing a ZFS volume

Fabian Ebner f.ebner at proxmox.com
Thu Dec 5 11:47:25 CET 2019


so ZFS won't complain when we do things like 'qm resize 102 scsi1 +0.01G'

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 PVE/Storage/ZFSPoolPlugin.pm | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm
index 456fb40..9bc3fcf 100644
--- a/PVE/Storage/ZFSPoolPlugin.pm
+++ b/PVE/Storage/ZFSPoolPlugin.pm
@@ -662,6 +662,17 @@ sub volume_resize {
 
     my $attr = $format eq 'subvol' ? 'refquota' : 'volsize';
 
+    # for ZFS volumes, size has to be a multiple of the volume block size,
+    # so we round up to the next valid size
+    if ($format eq 'raw') {
+	my $volblocksize = int($class->zfs_get_properties($scfg, 'volblocksize', "$scfg->{pool}/$vname"));
+	if ($volblocksize >= 2048) {
+	    $volblocksize = int($volblocksize / 1024);
+	    my $remainder = $new_size % $volblocksize;
+	    $new_size = $new_size + $volblocksize - $remainder if $remainder;
+	}
+    }
+
     $class->zfs_request($scfg, undef, 'set', "$attr=${new_size}k", "$scfg->{pool}/$vname");
 
     return $new_size;
-- 
2.20.1




More information about the pve-devel mailing list