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] [RFC qemu-server] backup: always die early when volume size or format cannot be determined
Date: Mon,  5 Aug 2024 14:14:21 +0200	[thread overview]
Message-ID: <20240805121421.736820-1-f.ebner@proxmox.com> (raw)

There are cases where volume_size_info() will return undef, and not
set $@. In particular, the default implementation will do so when stat
on the file fails or the output of 'qemu-img info' cannot be parsed as
JSON.

While the size is only strictly needed for fleecing, the
volume_size_info() call serves as an early sanity check otherwise.

This can break backup without fleecing in certain scenarios. Using
definedness checks would slightly reduce potential for breakage. To
minimize that potential, doing the check only for fleecing would be
the way to go. However, having a stricter check seems desirable for
future-proofing to abort early when something is amiss.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 PVE/VZDump/QemuServer.pm | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/PVE/VZDump/QemuServer.pm b/PVE/VZDump/QemuServer.pm
index 012c9210..9291a232 100644
--- a/PVE/VZDump/QemuServer.pm
+++ b/PVE/VZDump/QemuServer.pm
@@ -122,7 +122,11 @@ sub prepare {
 	if ($storeid) {
 	    # The call in list context can be expensive for certain plugins like RBD, just get size
 	    $size = eval { PVE::Storage::volume_size_info($self->{storecfg}, $volid, 5) };
-	    die "cannot determine size of volume '$volid' - $@\n" if $@;
+	    if ($@ || !$size) {
+		my $err = "cannot determine size of volume '$volid'";
+		$err .= " - $@" if $@;
+		die "$err\n";
+	    }
 
 	    my $scfg = PVE::Storage::storage_config($self->{storecfg}, $storeid);
 	    $format = PVE::QemuServer::qemu_img_format($scfg, $volname);
@@ -130,7 +134,11 @@ sub prepare {
 	    ($size, $format) = eval {
 		PVE::Storage::volume_size_info($self->{storecfg}, $volid, 5);
 	    };
-	    die "cannot determine size and format of volume '$volid' - $@\n" if $@;
+	    if ($@ || !$size || !$format) {
+		my $err = "cannot determine size and format of volume '$volid'";
+		$err .= " - $@" if $@;
+		die "$err\n";
+	    }
 	}
 
 	my $diskinfo = {
-- 
2.39.2



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


                 reply	other threads:[~2024-08-05 12:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240805121421.736820-1-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