public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v6 23/37] image convert: collect options in hash argument
Date: Mon, 31 Mar 2025 15:20:06 +0200	[thread overview]
Message-ID: <20250331132020.105324-24-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250331132020.105324-1-f.ebner@proxmox.com>

In preparation to add another option and to improve style for the
callers.

One of the test cases that specified $is_zero_initialized is for a
non-existent storage, so the option was not added there.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

New in v6.

 PVE/QemuServer.pm                  | 19 +++++++---
 PVE/QemuServer/ImportDisk.pm       |  3 +-
 test/run_qemu_img_convert_tests.pl | 58 ++++++++++++++++++++----------
 3 files changed, 56 insertions(+), 24 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index ffd5d56b..5c6cb94a 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -7787,8 +7787,14 @@ sub convert_iscsi_path {
     die "cannot convert iscsi path '$path', unknown format\n";
 }
 
+# The possible options are:
+# bwlimit - The bandwidth limit in KiB/s.
+# is-zero-initialized - If the destination image is zero-initialized.
+# snapname - Use this snapshot of the source image.
 sub qemu_img_convert {
-    my ($src_volid, $dst_volid, $size, $snapname, $is_zero_initialized, $bwlimit) = @_;
+    my ($src_volid, $dst_volid, $size, $opts) = @_;
+
+    my ($bwlimit, $snapname) = $opts->@{qw(bwlimit snapname)};
 
     my $storecfg = PVE::Storage::config();
     my ($src_storeid) = PVE::Storage::parse_volume_id($src_volid, 1);
@@ -7846,7 +7852,7 @@ sub qemu_img_convert {
 
     push @$cmd, $src_path;
 
-    if (!$dst_is_iscsi && $is_zero_initialized) {
+    if (!$dst_is_iscsi && $opts->{'is-zero-initialized'}) {
 	push @$cmd, "zeroinit:$dst_path";
     } else {
 	push @$cmd, $dst_path;
@@ -8307,7 +8313,12 @@ sub clone_disk {
 		push $cmd->@*, "bs=$bs", "osize=$size", "if=$src_path", "of=$dst_path";
 		run_command($cmd);
 	    } else {
-		qemu_img_convert($drive->{file}, $newvolid, $size, $snapname, $sparseinit, $bwlimit);
+		my $opts = {
+		    bwlimit => $bwlimit,
+		    'is-zero-initialized' => $sparseinit,
+		    snapname => $snapname,
+		};
+		qemu_img_convert($drive->{file}, $newvolid, $size, $opts);
 	    }
 	}
     }
@@ -8391,7 +8402,7 @@ sub create_efidisk($$$$$$$) {
     my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $vars_size);
     PVE::Storage::activate_volumes($storecfg, [$volid]);
 
-    qemu_img_convert($ovmf_vars, $volid, $vars_size_b, undef, 0);
+    qemu_img_convert($ovmf_vars, $volid, $vars_size_b);
     my $size = PVE::Storage::volume_size_info($storecfg, $volid, 3);
 
     return ($volid, $size/1024);
diff --git a/PVE/QemuServer/ImportDisk.pm b/PVE/QemuServer/ImportDisk.pm
index 30d56bae..75b5e0de 100755
--- a/PVE/QemuServer/ImportDisk.pm
+++ b/PVE/QemuServer/ImportDisk.pm
@@ -70,7 +70,8 @@ sub do_import {
 	    local $SIG{PIPE} = sub { die "interrupted by signal $!\n"; };
 
 	PVE::Storage::activate_volumes($storecfg, [$dst_volid]);
-	PVE::QemuServer::qemu_img_convert($src_path, $dst_volid, $src_size, undef, $zeroinit);
+	PVE::QemuServer::qemu_img_convert(
+	    $src_path, $dst_volid, $src_size, { 'is-zero-initialized' => $zeroinit });
 	PVE::Storage::deactivate_volumes($storecfg, [$dst_volid]);
 	PVE::QemuConfig->lock_config($vmid, $create_drive) if !$params->{'skip-config-update'};
     };
diff --git a/test/run_qemu_img_convert_tests.pl b/test/run_qemu_img_convert_tests.pl
index 29c188d8..652e61f2 100755
--- a/test/run_qemu_img_convert_tests.pl
+++ b/test/run_qemu_img_convert_tests.pl
@@ -55,7 +55,7 @@ my $storage_config = {
 my $tests = [
     {
 	name => 'qcow2raw',
-	parameters => [ "local:$vmid/vm-$vmid-disk-0.qcow2", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10, undef, 0, undef ],
+	parameters => [ "local:$vmid/vm-$vmid-disk-0.qcow2", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10 ],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-f", "qcow2", "-O", "raw",
 	    "/var/lib/vz/images/$vmid/vm-$vmid-disk-0.qcow2", "/var/lib/vz/images/$vmid/vm-$vmid-disk-0.raw"
@@ -63,7 +63,7 @@ my $tests = [
     },
     {
 	name => "raw2qcow2",
-	parameters => [ "local:$vmid/vm-$vmid-disk-0.raw", "local:$vmid/vm-$vmid-disk-0.qcow2", 1024*10, undef, 0, undef ],
+	parameters => [ "local:$vmid/vm-$vmid-disk-0.raw", "local:$vmid/vm-$vmid-disk-0.qcow2", 1024*10 ],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-f", "raw", "-O", "qcow2",
 	    "/var/lib/vz/images/$vmid/vm-$vmid-disk-0.raw", "/var/lib/vz/images/$vmid/vm-$vmid-disk-0.qcow2"
@@ -71,7 +71,7 @@ my $tests = [
     },
     {
 	name => "local2rbd",
-	parameters => [ "local:$vmid/vm-$vmid-disk-0.raw", "rbd-store:vm-$vmid-disk-0", 1024*10, undef, 0, undef ],
+	parameters => [ "local:$vmid/vm-$vmid-disk-0.raw", "rbd-store:vm-$vmid-disk-0", 1024*10 ],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-f", "raw", "-O", "raw",
 	    "/var/lib/vz/images/$vmid/vm-$vmid-disk-0.raw", "rbd:cpool/vm-$vmid-disk-0:mon_host=127.0.0.42;127.0.0.21;[\\:\\:1]:auth_supported=none"
@@ -79,7 +79,7 @@ my $tests = [
     },
     {
 	name => "rbd2local",
-	parameters => [ "rbd-store:vm-$vmid-disk-0", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10, undef, 0, undef ],
+	parameters => [ "rbd-store:vm-$vmid-disk-0", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10 ],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-f", "raw", "-O", "raw",
 	    "rbd:cpool/vm-$vmid-disk-0:mon_host=127.0.0.42;127.0.0.21;[\\:\\:1]:auth_supported=none", "/var/lib/vz/images/$vmid/vm-$vmid-disk-0.raw"
@@ -87,7 +87,7 @@ my $tests = [
     },
     {
 	name => "local2zos",
-	parameters => [ "local:$vmid/vm-$vmid-disk-0.raw", "zfs-over-iscsi:vm-$vmid-disk-0", 1024*10, undef, 0, undef ],
+	parameters => [ "local:$vmid/vm-$vmid-disk-0.raw", "zfs-over-iscsi:vm-$vmid-disk-0", 1024*10 ],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-f", "raw", "--target-image-opts",
 	    "/var/lib/vz/images/$vmid/vm-$vmid-disk-0.raw",
@@ -96,7 +96,7 @@ my $tests = [
     },
     {
 	name => "zos2local",
-	parameters => [ "zfs-over-iscsi:vm-$vmid-disk-0", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10, undef, 0, undef ],
+	parameters => [ "zfs-over-iscsi:vm-$vmid-disk-0", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10 ],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "--image-opts", "-O", "raw",
 	    "file.driver=iscsi,file.transport=tcp,file.initiator-name=foobar,file.portal=127.0.0.1,file.target=iqn.2019-10.org.test:foobar,file.lun=1,driver=raw",
@@ -105,7 +105,7 @@ my $tests = [
     },
     {
 	name => "zos2rbd",
-	parameters => [ "zfs-over-iscsi:vm-$vmid-disk-0", "rbd-store:vm-$vmid-disk-0", 1024*10, undef, 0, undef ],
+	parameters => [ "zfs-over-iscsi:vm-$vmid-disk-0", "rbd-store:vm-$vmid-disk-0", 1024*10 ],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "--image-opts", "-O", "raw",
 	    "file.driver=iscsi,file.transport=tcp,file.initiator-name=foobar,file.portal=127.0.0.1,file.target=iqn.2019-10.org.test:foobar,file.lun=1,driver=raw",
@@ -114,7 +114,7 @@ my $tests = [
     },
     {
 	name => "rbd2zos",
-	parameters => [ "rbd-store:vm-$vmid-disk-0", "zfs-over-iscsi:vm-$vmid-disk-0", 1024*10, undef, 0, undef ],
+	parameters => [ "rbd-store:vm-$vmid-disk-0", "zfs-over-iscsi:vm-$vmid-disk-0", 1024*10 ],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-f", "raw", "--target-image-opts",
 	    "rbd:cpool/vm-$vmid-disk-0:mon_host=127.0.0.42;127.0.0.21;[\\:\\:1]:auth_supported=none",
@@ -123,7 +123,7 @@ my $tests = [
     },
     {
 	name => "local2lvmthin",
-	parameters => [ "local:$vmid/vm-$vmid-disk-0.raw", "local-lvm:vm-$vmid-disk-0", 1024*10, undef, 0, undef ],
+	parameters => [ "local:$vmid/vm-$vmid-disk-0.raw", "local-lvm:vm-$vmid-disk-0", 1024*10 ],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-f", "raw", "-O", "raw",
 	    "/var/lib/vz/images/$vmid/vm-$vmid-disk-0.raw",
@@ -132,7 +132,7 @@ my $tests = [
     },
     {
 	name => "lvmthin2local",
-	parameters => [ "local-lvm:vm-$vmid-disk-0", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10, undef, 0, undef ],
+	parameters => [ "local-lvm:vm-$vmid-disk-0", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10 ],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-f", "raw", "-O", "raw",
 	    "/dev/pve/vm-$vmid-disk-0",
@@ -141,7 +141,12 @@ my $tests = [
     },
     {
 	name => "zeroinit",
-	parameters => [ "local-lvm:vm-$vmid-disk-0", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10, undef, 1, undef ],
+	parameters => [
+	    "local-lvm:vm-$vmid-disk-0",
+	    "local:$vmid/vm-$vmid-disk-0.raw",
+	    1024*10,
+	    { 'is-zero-initialized' => 1 },
+	],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-f", "raw", "-O", "raw",
 	    "/dev/pve/vm-$vmid-disk-0",
@@ -150,12 +155,12 @@ my $tests = [
     },
     {
 	name => "notexistingstorage",
-	parameters => [ "local-lvm:vm-$vmid-disk-0", "not-existing:$vmid/vm-$vmid-disk-0.raw", 1024*10, undef, 1, undef ],
+	parameters => [ "local-lvm:vm-$vmid-disk-0", "not-existing:$vmid/vm-$vmid-disk-0.raw", 1024*10 ],
 	expected => "storage 'not-existing' does not exist\n",
     },
     {
 	name => "vmdkfile",
-	parameters => [ "./test.vmdk", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10, undef, 0, undef ],
+	parameters => [ "./test.vmdk", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10 ],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-f", "vmdk", "-O", "raw",
 	    "./test.vmdk",
@@ -164,12 +169,12 @@ my $tests = [
     },
     {
 	name => "notexistingfile",
-	parameters => [ "/foo/bar", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10, undef, 0, undef ],
+	parameters => [ "/foo/bar", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10 ],
 	expected => "source '/foo/bar' is not a valid volid nor path for qemu-img convert\n",
     },
     {
 	name => "efidisk",
-	parameters => [ "/usr/share/kvm/OVMF_VARS-pure-efi.fd", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10, undef, 0, undef ],
+	parameters => [ "/usr/share/kvm/OVMF_VARS-pure-efi.fd", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10 ],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-O", "raw",
 	    "/usr/share/kvm/OVMF_VARS-pure-efi.fd",
@@ -178,7 +183,7 @@ my $tests = [
     },
     {
 	name => "efi2zos",
-	parameters => [ "/usr/share/kvm/OVMF_VARS-pure-efi.fd", "zfs-over-iscsi:vm-$vmid-disk-0", 1024*10, undef, 0, undef ],
+	parameters => [ "/usr/share/kvm/OVMF_VARS-pure-efi.fd", "zfs-over-iscsi:vm-$vmid-disk-0", 1024*10 ],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "--target-image-opts",
 	    "/usr/share/kvm/OVMF_VARS-pure-efi.fd",
@@ -187,7 +192,12 @@ my $tests = [
     },
     {
 	name => "bwlimit",
-	parameters => [ "local-lvm:vm-$vmid-disk-0", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10, undef, 0, 1024 ],
+	parameters => [
+	    "local-lvm:vm-$vmid-disk-0",
+	    "local:$vmid/vm-$vmid-disk-0.raw",
+	    1024*10,
+	    { bwlimit => 1024 },
+	],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-r", "1024K", "-f", "raw", "-O", "raw",
 	    "/dev/pve/vm-$vmid-disk-0",
@@ -196,7 +206,12 @@ my $tests = [
     },
     {
 	name => "lvmsnapshot",
-	parameters => [ "local-lvm:vm-$vmid-disk-0", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10, 'foo', 0, undef ],
+	parameters => [
+	    "local-lvm:vm-$vmid-disk-0",
+	    "local:$vmid/vm-$vmid-disk-0.raw",
+	    1024*10,
+	    { snapname => 'foo'},
+	],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-f", "raw", "-O", "raw",
 	    "/dev/pve/snap_vm-$vmid-disk-0_foo",
@@ -205,7 +220,12 @@ my $tests = [
     },
     {
 	name => "qcow2snapshot",
-	parameters => [ "local:$vmid/vm-$vmid-disk-0.qcow2", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10, 'snap', 0, undef ],
+	parameters => [
+	    "local:$vmid/vm-$vmid-disk-0.qcow2",
+	    "local:$vmid/vm-$vmid-disk-0.raw",
+	    1024*10,
+	    { snapname => 'snap' },
+	],
 	expected => [
 	    "/usr/bin/qemu-img", "convert", "-p", "-n", "-l", "snapshot.name=snap", "-f", "qcow2", "-O", "raw",
 	    "/var/lib/vz/images/$vmid/vm-$vmid-disk-0.qcow2",
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2025-03-31 13:24 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-31 13:19 [pve-devel] [PATCH-SERIES qemu/common/storage/qemu-server/container/manager v6 00/37] backup provider API Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH qemu v6 01/37] PVE backup: clean up directly in setup_snapshot_access() when it fails Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH qemu v6 02/37] PVE backup: factor out helper to clear backup state's bitmap list Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH qemu v6 03/37] PVE backup: factor out helper to initialize backup state stat struct Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH qemu v6 04/37] PVE backup: add target ID in backup state Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH qemu v6 05/37] PVE backup: get device info: allow caller to specify filter for which devices use fleecing Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH qemu v6 06/37] PVE backup: implement backup access setup and teardown API for external providers Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH qemu v6 07/37] PVE backup: implement bitmap support for external backup access Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH qemu v6 08/37] PVE backup: backup-access api: indicate situation where a bitmap was recreated Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH common v6 09/37] syscall: expose fallocate syscall Fiona Ebner
2025-03-31 14:34   ` [pve-devel] applied: " Thomas Lamprecht
2025-03-31 13:19 ` [pve-devel] [PATCH storage v6 10/37] add storage_has_feature() helper function Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH storage v6 11/37] common: add deallocate " Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH storage v6 12/37] plugin: introduce new_backup_provider() method Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH storage v6 13/37] config api/plugins: let plugins define sensitive properties themselves Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH storage v6 14/37] plugin api: bump api version and age Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [PATCH storage v6 15/37] extract backup config: delegate to backup provider for storages that support it Fiona Ebner
2025-03-31 13:19 ` [pve-devel] [POC storage v6 16/37] add backup provider example Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [POC storage v6 17/37] Borg example plugin Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH qemu-server v6 18/37] backup: keep track of block-node size for fleecing Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH qemu-server v6 19/37] backup: fleecing: use exact size when allocating non-raw fleecing images Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH qemu-server v6 20/37] backup: allow adding fleecing images also for EFI and TPM Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH qemu-server v6 21/37] backup: implement backup for external providers Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH qemu-server v6 22/37] test: qemu img convert: add test cases for snapshots Fiona Ebner
2025-03-31 13:20 ` Fiona Ebner [this message]
2025-03-31 13:20 ` [pve-devel] [PATCH qemu-server v6 24/37] image convert: allow caller to specify the format of the source path Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH qemu-server v6 25/37] backup: implement restore for external providers Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH qemu-server v6 26/37] backup: future-proof checks for QEMU feature support Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH qemu-server v6 27/37] backup: support 'missing-recreated' bitmap action Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH qemu-server v6 28/37] backup: bitmap action to human: lie about TPM state Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH container v6 29/37] add LXC::Namespaces module Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH container v6 30/37] backup: implement backup for external providers Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH container v6 31/37] backup: implement restore " Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH container v6 32/37] external restore: don't use 'one-file-system' tar flag when restoring from a directory Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH container v6 33/37] create: factor out compression option helper Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH container v6 34/37] restore tar archive: check potentially untrusted archive Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH container v6 35/37] api: add early check against restoring privileged container from external source Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH manager v6 36/37] ui: backup: also check for backup subtype to classify archive Fiona Ebner
2025-03-31 13:20 ` [pve-devel] [PATCH manager v6 37/37] backup: implement backup for external providers Fiona Ebner
2025-04-01  8:15 ` [pve-devel] [PATCH-SERIES qemu/common/storage/qemu-server/container/manager v6 00/37] backup provider API Fiona Ebner
2025-04-01  8:26 ` [pve-devel] [FOLLOWUP storage] backup provider: base: document limitation of backup_container() method Fiona Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250331132020.105324-24-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal