]> git.proxmox.com Git - pve-storage.git/commitdiff
fix #3580: plugins: make preallocation mode selectable for qcow2 and raw images
authorLorenz Stechauner <l.stechauner@proxmox.com>
Tue, 12 Oct 2021 12:32:32 +0000 (14:32 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 14 Oct 2021 09:00:23 +0000 (11:00 +0200)
the plugins for file based storages
 * BTRFS
 * CIFS
 * Dir
 * Glusterfs
 * NFS
now allow the option 'preallocation'.

'preallocation' can have four values:
 * default
 * off
 * metadata
 * falloc
 * full
see man pages for `qemu-img` for what these mean exactly. [0]

the defualt value was chosen to be
 * qcow2: metadata (as previously)
 * raw: off

when using 'metadata' as preallocation mode, for raw images 'off'
is used.

[0] https://qemu.readthedocs.io/en/latest/system/images.html#disk-image-file-formats

Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
Reviewed-by: Fabian Ebner <f.ebner@proxmox.com>
Tested-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/Storage/BTRFSPlugin.pm
PVE/Storage/CIFSPlugin.pm
PVE/Storage/DirPlugin.pm
PVE/Storage/GlusterfsPlugin.pm
PVE/Storage/NFSPlugin.pm
PVE/Storage/Plugin.pm

index 1407f443f1f5e83964345b4b1f926da4ee8664f9..63d307df6e8f4b5fa6cbb9239cb8481a4e9cc735 100644 (file)
@@ -73,6 +73,7 @@ sub options {
        is_mountpoint => { optional => 1 },
        nocow => { optional => 1 },
        mkdir => { optional => 1 },
+       preallocation => { optional => 1 },
        # TODO: The new variant of mkdir with  `populate` vs `create`...
     };
 }
index c5f38942979aafeb4dcfb28bbd892c83910e6c20..3a7e638c25407f84655a025957dc6791c05d29b1 100644 (file)
@@ -142,6 +142,7 @@ sub options {
        smbversion => { optional => 1},
        mkdir => { optional => 1 },
        bwlimit => { optional => 1 },
+       preallocation => { optional => 1 },
     };
 }
 
index 2267f117c963e3e7a05a00f4a563149c5aca8163..3eeec9813f448f19a20e4884fc00ff49ab9b75df 100644 (file)
@@ -59,6 +59,7 @@ sub options {
        mkdir => { optional => 1 },
        is_mountpoint => { optional => 1 },
        bwlimit => { optional => 1 },
+       preallocation => { optional => 1 },
    };
 }
 
index ea4df82a9682f949c74ac4445632d8256c9d60b1..d8d2b88f613b612a4da221dcfb283f2a91f3a7a3 100644 (file)
@@ -137,6 +137,7 @@ sub options {
        format => { optional => 1 },
        mkdir => { optional => 1 },
        bwlimit => { optional => 1 },
+       preallocation => { optional => 1 },
     };
 }
 
@@ -260,7 +261,8 @@ sub alloc_image {
 
     my $cmd = ['/usr/bin/qemu-img', 'create'];
 
-    push @$cmd, '-o', 'preallocation=metadata' if $fmt eq 'qcow2';
+    my $prealloc_opt = PVE::Storage::Plugin::preallocation_cmd_option($scfg, $fmt);
+    push @$cmd, '-o', $prealloc_opt if defined($prealloc_opt);
 
     push @$cmd, '-f', $fmt, $volumepath, "${size}K";
 
index 39bf15a2b164ca7d284ab05ec7d8d5e5ea6b7c31..21b288a239f3c3a50c5301c2bd51c9329703a7dd 100644 (file)
@@ -90,6 +90,7 @@ sub options {
        format => { optional => 1 },
        mkdir => { optional => 1 },
        bwlimit => { optional => 1 },
+       preallocation => { optional => 1 },
     };
 }
 
index fab231642c366dabf51a8d90723fc0c865c69514..aeb4fff3eb67c81b175b81e59ad2e6993523d742 100644 (file)
@@ -41,6 +41,19 @@ our @SHARED_STORAGE = (
     'pbs',
 );
 
+our $QCOW2_PREALLOCATION = {
+    off => 1,
+    metadata => 1,
+    falloc => 1,
+    full => 1,
+};
+
+our $RAW_PREALLOCATION = {
+    off => 1,
+    falloc => 1,
+    full => 1,
+};
+
 our $MAX_VOLUMES_PER_GUEST = 1024;
 
 cfs_register_file ('storage.cfg',
@@ -152,6 +165,13 @@ my $defaultData = {
            type => 'string', format => 'pve-storage-format',
            optional => 1,
        },
+       preallocation => {
+           description => "Preallocation mode for raw and qcow2 images. " .
+               "Using 'metadata' on raw images results in preallocation=off.",
+           type => 'string', enum => ['off', 'metadata', 'falloc', 'full'],
+           default => 'metadata',
+           optional => 1,
+       },
     },
 };
 
@@ -444,6 +464,31 @@ sub parse_config {
     return $cfg;
 }
 
+sub preallocation_cmd_option {
+    my ($scfg, $fmt) = @_;
+
+    my $prealloc = $scfg->{preallocation};
+
+    if ($fmt eq 'qcow2') {
+       $prealloc = $prealloc // 'metadata';
+
+       die "preallocation mode '$prealloc' not supported by format '$fmt'\n"
+           if !$QCOW2_PREALLOCATION->{$prealloc};
+
+       return "preallocation=$prealloc";
+    } elsif ($fmt eq 'raw') {
+       $prealloc = $prealloc // 'off';
+       $prealloc = 'off' if $prealloc eq 'metadata';
+
+       die "preallocation mode '$prealloc' not supported by format '$fmt'\n"
+           if !$RAW_PREALLOCATION->{$prealloc};
+
+       return "preallocation=$prealloc";
+    }
+
+    return;
+}
+
 # Storage implementation
 
 # called during addition of storage (before the new storage config got written)
@@ -764,7 +809,8 @@ sub alloc_image {
     } else {
        my $cmd = ['/usr/bin/qemu-img', 'create'];
 
-       push @$cmd, '-o', 'preallocation=metadata' if $fmt eq 'qcow2';
+       my $prealloc_opt = preallocation_cmd_option($scfg, $fmt);
+       push @$cmd, '-o', $prealloc_opt if defined($prealloc_opt);
 
        push @$cmd, '-f', $fmt, $path, "${size}K";