From 9612844ff3a53f0e9ece5d9c7c1767e6883405aa Mon Sep 17 00:00:00 2001 From: Fiona Ebner Date: Fri, 6 Dec 2024 17:25:26 +0100 Subject: [PATCH] btrfs: list images: specify format when querying file info This avoids auto-detection by qemu-img and so the information will be correct with respect to the actual image format on the storage layer. Should the image not be in the correct format, warn and try again querying as raw, so the image is still listed. The image is present, so it is better if it is listed and for some backwards compatibility. The format is still returned as the matched format in such a case, because that is how the image is treated, even if corrupt. Signed-off-by: Fiona Ebner --- src/PVE/Storage/BTRFSPlugin.pm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/PVE/Storage/BTRFSPlugin.pm b/src/PVE/Storage/BTRFSPlugin.pm index 81e5acb..555ed9d 100644 --- a/src/PVE/Storage/BTRFSPlugin.pm +++ b/src/PVE/Storage/BTRFSPlugin.pm @@ -661,15 +661,26 @@ sub list_images { if (!$ext) { # raw $volid .= '.raw'; - ($size, $format, $used, $parent, $ctime) = PVE::Storage::Plugin::file_size_info("$fn/disk.raw"); + $format = 'raw'; + ($size, undef, $used, $parent, $ctime) = + PVE::Storage::Plugin::file_size_info("$fn/disk.raw", undef, $format); } elsif ($ext eq 'subvol') { ($used, $size) = (0, 0); #($used, $size) = btrfs_subvol_quota($class, $fn); $format = 'subvol'; } else { - ($size, $format, $used, $parent, $ctime) = PVE::Storage::Plugin::file_size_info($fn); + $format = $ext; + ($size, undef, $used, $parent, $ctime) = eval { + PVE::Storage::Plugin::file_size_info($fn, undef, $format); + }; + if (my $err = $@) { + die $err if $err !~ m/Image is not in \S+ format$/; + warn "image '$fn' is not in expected format '$format', querying as raw\n"; + ($size, undef, $used, $parent, $ctime) = + PVE::Storage::Plugin::file_size_info($fn, undef, 'raw'); + } } - next if !($format && defined($size)); + next if !defined($size); if ($vollist) { next if ! grep { $_ eq $volid } @$vollist;