[pve-devel] [PATCH storage v3 3/4] btrfs: use foreach_snapshot_of_subvol helper in free_image

Maximiliano Sandoval m.sandoval at proxmox.com
Wed Feb 19 10:58:47 CET 2025


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 at proxmox.com>
---
 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 1a877f7..e554894 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;
-- 
2.39.5





More information about the pve-devel mailing list