From c05ef0dbce1ca5d3c537e2d609bb136b556ddda2 Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval Date: Wed, 19 Feb 2025 12:17:35 +0100 Subject: [PATCH] fix #3873: btrfs: use foreach_snapshot_of_subvol helper in volume_export Suppose we are taking a snapshot of VM 100's disk-0. The dir_glob_foreach runs over $path=/subvolume/images/100, lists all snapshot names and appends their names to the path of the disk, e.g. /subvolume/images/vm-100-disk-0@SNAP_NAME, but the original directory $path might contain a second disk `vm-100-disk-1` which is also listed by the dir_glib_foreach. By using the helper we only iterate over the snapshots of the guest. Signed-off-by: Maximiliano Sandoval --- src/PVE/Storage/BTRFSPlugin.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PVE/Storage/BTRFSPlugin.pm b/src/PVE/Storage/BTRFSPlugin.pm index e5c3e08..8f4691b 100644 --- a/src/PVE/Storage/BTRFSPlugin.pm +++ b/src/PVE/Storage/BTRFSPlugin.pm @@ -796,8 +796,9 @@ sub volume_export { if (ref($with_snapshots) eq 'ARRAY') { push @$cmd, (map { "$path\@$_" } ($with_snapshots // [])->@*), $path; } else { - dir_glob_foreach(dirname($path), $BTRFS_VOL_REGEX, sub { - push @$cmd, "$path\@$_[2]" if !(defined($snapshot) && $_[2] eq $snapshot); + foreach_snapshot_of_subvol($path, sub { + my ($snap_name) = @_; + push @$cmd, "$path\@$snap_name" if !(defined($snapshot) && $snap_name eq $snapshot); }); } $path .= "\@$snapshot" if defined($snapshot);