public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [RFC qemu-server] backup: always die early when volume size or format cannot be determined
@ 2024-08-05 12:14 Fiona Ebner
  0 siblings, 0 replies; only message in thread
From: Fiona Ebner @ 2024-08-05 12:14 UTC (permalink / raw)
  To: pve-devel

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-08-05 12:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-05 12:14 [pve-devel] [RFC qemu-server] backup: always die early when volume size or format cannot be determined Fiona Ebner

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