[pve-devel] [RFC qemu-server] backup: always die early when volume size or format cannot be determined
Fiona Ebner
f.ebner at proxmox.com
Mon Aug 5 14:14:21 CEST 2024
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 at 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
More information about the pve-devel
mailing list