btrfs: use foreach_snapshot_of_subvol helper in free_image

Replaces the current use without changes. The `$dir` variable is not
used anymore at that moment so it is defined later.

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
This commit is contained in:
Maximiliano Sandoval
2025-02-19 12:17:36 +01:00
committed by Fiona Ebner
parent c05ef0dbce
commit c2db0cb7d5

View File

@ -450,19 +450,16 @@ sub free_image {
$subvol = raw_file_to_subvol($path); $subvol = raw_file_to_subvol($path);
} }
my $dir = dirname($subvol);
my $basename = basename($subvol);
my @snapshot_vols; my @snapshot_vols;
foreach_subvol($dir, sub { foreach_snapshot_of_subvol($subvol, sub {
my ($volume, $name, $snapshot) = @_; my ($snap_name) = @_;
return if $name ne $basename; push @snapshot_vols, "$subvol\@$snap_name";
return if !defined $snapshot;
push @snapshot_vols, "$dir/$volume";
}); });
$class->btrfs_cmd(['subvolume', 'delete', '--', @snapshot_vols, $subvol]); $class->btrfs_cmd(['subvolume', 'delete', '--', @snapshot_vols, $subvol]);
# try to cleanup directory to not clutter storage with empty $vmid dirs if # try to cleanup directory to not clutter storage with empty $vmid dirs if
# all images from a guest got deleted # all images from a guest got deleted
my $dir = dirname($subvol);
rmdir($dir); rmdir($dir);
return undef; return undef;