From c2db0cb7d58d4ad2d80a5c403c136bca623c95bf Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval Date: Wed, 19 Feb 2025 12:17:36 +0100 Subject: [PATCH] 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 --- src/PVE/Storage/BTRFSPlugin.pm | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/PVE/Storage/BTRFSPlugin.pm b/src/PVE/Storage/BTRFSPlugin.pm index 8f4691b..7dec6e8 100644 --- a/src/PVE/Storage/BTRFSPlugin.pm +++ b/src/PVE/Storage/BTRFSPlugin.pm @@ -450,19 +450,16 @@ sub free_image { $subvol = raw_file_to_subvol($path); } - my $dir = dirname($subvol); - my $basename = basename($subvol); my @snapshot_vols; - foreach_subvol($dir, sub { - my ($volume, $name, $snapshot) = @_; - return if $name ne $basename; - return if !defined $snapshot; - push @snapshot_vols, "$dir/$volume"; + foreach_snapshot_of_subvol($subvol, sub { + my ($snap_name) = @_; + push @snapshot_vols, "$subvol\@$snap_name"; }); $class->btrfs_cmd(['subvolume', 'delete', '--', @snapshot_vols, $subvol]); # try to cleanup directory to not clutter storage with empty $vmid dirs if # all images from a guest got deleted + my $dir = dirname($subvol); rmdir($dir); return undef;