From 6e22cae004ef5d4e9ebe66670b640241c038072f Mon Sep 17 00:00:00 2001 From: Fiona Ebner Date: Fri, 6 Dec 2024 17:25:25 +0100 Subject: [PATCH] plugin: 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/Plugin.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 493c0e0..1f9156f 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -1282,11 +1282,19 @@ sub list_images { my $owner = $2; my $name = $3; + my $format = $4; next if !$vollist && defined($vmid) && ($owner ne $vmid); - my ($size, $format, $used, $parent, $ctime) = file_size_info($fn); - next if !($format && defined($size)); + my ($size, undef, $used, $parent, $ctime) = eval { + 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) = file_size_info($fn, undef, 'raw'); + } + next if !defined($size); my $volid; if ($parent && $parent =~ m!^../(\d+)/([^/]+\.($fmts))$!) {