5
0
mirror of git://git.proxmox.com/git/pve-storage.git synced 2024-12-22 13:34:16 +03:00

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 <f.ebner@proxmox.com>
This commit is contained in:
Fiona Ebner 2024-12-06 17:25:26 +01:00 committed by Fabian Grünbichler
parent 6e22cae004
commit 9612844ff3

View File

@ -661,15 +661,26 @@ sub list_images {
if (!$ext) { # raw if (!$ext) { # raw
$volid .= '.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') { } elsif ($ext eq 'subvol') {
($used, $size) = (0, 0); ($used, $size) = (0, 0);
#($used, $size) = btrfs_subvol_quota($class, $fn); #($used, $size) = btrfs_subvol_quota($class, $fn);
$format = 'subvol'; $format = 'subvol';
} else { } 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) { if ($vollist) {
next if ! grep { $_ eq $volid } @$vollist; next if ! grep { $_ eq $volid } @$vollist;