From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <t.lamprecht@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id F26098A63
 for <pve-devel@lists.proxmox.com>; Wed, 16 Nov 2022 13:40:02 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id D6BE91EF28
 for <pve-devel@lists.proxmox.com>; Wed, 16 Nov 2022 13:39:32 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pve-devel@lists.proxmox.com>; Wed, 16 Nov 2022 13:39:31 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 42B6044CEB
 for <pve-devel@lists.proxmox.com>; Wed, 16 Nov 2022 13:39:31 +0100 (CET)
Message-ID: <16fbd4f9-dd57-ea2b-53df-d8d82eb7045a@proxmox.com>
Date: Wed, 16 Nov 2022 13:39:30 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:107.0) Gecko/20100101
 Thunderbird/107.0
Content-Language: en-GB
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Leo Nunner <l.nunner@proxmox.com>
References: <20220916114741.107577-1-l.nunner@proxmox.com>
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
In-Reply-To: <20220916114741.107577-1-l.nunner@proxmox.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-SPAM-LEVEL: Spam detection results: =?UTF-8?Q?0=0A=09?=AWL -0.031 Adjusted
 score from AWL reputation of From: =?UTF-8?Q?address=0A=09?=BAYES_00 -1.9
 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict
 =?UTF-8?Q?Alignment=0A=09?=NICE_REPLY_A -0.001 Looks like a legit reply (A)
 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF
 =?UTF-8?Q?Record=0A=09?=SPF_PASS -0.001 SPF: sender matches SPF
 =?UTF-8?Q?record=0A=09?=URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query
 to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [qemuserver.pm, importdisk.pm]
Subject: Re: [pve-devel] [PATCH qemu-server] fix #4249: make
 qemu_img_convert respect bwlimit
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 16 Nov 2022 12:40:03 -0000

Am 16/09/2022 um 13:47 schrieb Leo Nunner:
> Previously, cloning a stopped VM didn't respect bwlimit. Passing the -r
> (ratelimit) parameter to qemu-img convert fixes this issue.

looks mostly OK

> Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
> ---
> With qemu_img_convert getting a parameter for bwlimit, would it maybe
> also make sense to apply the migration limit inside ImportDisk? I'm not
> quite sure if this falls under that category though.
> 
>  PVE/QemuServer.pm                  |  7 ++++---
>  PVE/QemuServer/ImportDisk.pm       |  2 +-
>  test/run_qemu_img_convert_tests.pl | 32 +++++++++++++++---------------
>  3 files changed, 21 insertions(+), 20 deletions(-)
> 
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index c706653..0be906e 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -7357,7 +7357,7 @@ sub convert_iscsi_path {
>  }
>  
>  sub qemu_img_convert {
> -    my ($src_volid, $dst_volid, $size, $snapname, $is_zero_initialized) = @_;
> +    my ($src_volid, $dst_volid, $size, $snapname, $is_zero_initialized, $bwlimit) = @_;
>  
>      my $storecfg = PVE::Storage::config();
>      my ($src_storeid, $src_volname) = PVE::Storage::parse_volume_id($src_volid, 1);
> @@ -7397,6 +7397,7 @@ sub qemu_img_convert {
>  	if $snapname && $src_format && $src_format eq "qcow2";
>      push @$cmd, '-t', 'none' if $dst_scfg->{type} eq 'zfspool';
>      push @$cmd, '-T', $cachemode if defined($cachemode);
> +    push @$cmd, '-r', "${bwlimit}K" if defined($bwlimit);
>  
>      if ($src_is_iscsi) {
>  	push @$cmd, '--image-opts';
> @@ -7777,7 +7778,7 @@ 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);
> +		qemu_img_convert($drive->{file}, $newvolid, $size, $snapname, $sparseinit, $bwlimit);
>  	    }
>  	}
>      }
> @@ -7863,7 +7864,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, undef, 0, undef);

fyi, you don't need to add undef explicitly, every parameter not passed along will be
undef anyway.

>      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 3e0474b..1c0851d 100755
> --- a/PVE/QemuServer/ImportDisk.pm
> +++ b/PVE/QemuServer/ImportDisk.pm
> @@ -71,7 +71,7 @@ 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, undef, $zeroinit, undef);

same here

>  	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 5e78d1b..f4ce369 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 ],
> +	parameters => [ "local:$vmid/vm-$vmid-disk-0.qcow2", "local:$vmid/vm-$vmid-disk-0.raw", 1024*10, undef, 0, undef ],
>  	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"

why isn't there a new test with $bwlimit set added here?