From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id E37F91FF0E2 for ; Thu, 30 Jul 2026 15:17:57 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 46AF8214CE; Thu, 30 Jul 2026 15:17:52 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server 4/8] block job: monitor: factor out job status printing Date: Thu, 30 Jul 2026 15:15:53 +0200 Message-ID: <20260730131613.157722-5-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260730131613.157722-1-f.ebner@proxmox.com> References: <20260730131613.157722-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1785417458228 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.161 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: WGIKE6YTVP7WZPGTZUSPLMT5G6ORVTIT X-Message-ID-Hash: WGIKE6YTVP7WZPGTZUSPLMT5G6ORVTIT X-MailFrom: f.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The validity/presence of $job->{ready} does not depend on $job->{len} in any way, so does not need to be part of the if block. No functional change intended. Signed-off-by: Fiona Ebner --- src/PVE/QemuServer/BlockJob.pm | 57 +++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/src/PVE/QemuServer/BlockJob.pm b/src/PVE/QemuServer/BlockJob.pm index 3c8de3e4..14d814ee 100644 --- a/src/PVE/QemuServer/BlockJob.pm +++ b/src/PVE/QemuServer/BlockJob.pm @@ -79,6 +79,35 @@ sub qemu_blockjobs_cancel { } } +my sub print_job_status { + my ($job_id, $job, $duration) = @_; + + if (my $total = $job->{len}) { + my $transferred = $job->{offset} || 0; + my $remaining = $total - $transferred; + my $percent = sprintf "%.2f", ($transferred * 100 / $total); + + my $total_h = render_bytes($total, 1); + my $transferred_h = render_bytes($transferred, 1); + + my $status = sprintf( + "transferred $transferred_h of $total_h ($percent%%) in %s", + render_duration($duration), + ); + + if ($job->{ready}) { + if ($job->{busy}) { + $status .= ", still busy"; # shouldn't even happen? but mirror is weird + } else { + $status .= ", ready"; + } + } + print "$job_id: $status\n"; + } + + return; +} + # $completion can be either # 'complete': wait until all jobs are ready, job-complete them (default) # 'cancel': wait until all jobs are ready, block-job-cancel them @@ -130,32 +159,10 @@ sub monitor { qemu_handle_concluded_blockjob($qmp_peer, $job_id, $job, $jobs->{$job_id}); } - my $busy = $job->{busy}; - my $ready = $job->{ready}; - if (my $total = $job->{len}) { - my $transferred = $job->{offset} || 0; - my $remaining = $total - $transferred; - my $percent = sprintf "%.2f", ($transferred * 100 / $total); - - my $duration = $ctime - $starttime; - my $total_h = render_bytes($total, 1); - my $transferred_h = render_bytes($transferred, 1); - - my $status = sprintf( - "transferred $transferred_h of $total_h ($percent%%) in %s", - render_duration($duration), - ); - - if ($ready) { - if ($busy) { - $status .= ", still busy"; # shouldn't even happen? but mirror is weird - } else { - $status .= ", ready"; - } - } - print "$job_id: $status\n" if !$jobs->{$job_id}->{ready}; - $jobs->{$job_id}->{ready} = $ready; + if (!$jobs->{$job_id}->{ready}) { + print_job_status($job_id, $job, $ctime - $starttime); } + $jobs->{$job_id}->{ready} = $job->{ready}; $readycounter++ if $job->{ready}; } -- 2.47.3