While running a make check on a btrfs system, many subvolumes are let at the end
of the build. It's pretty common to have several hundreds of those.
btrfs is pretty sensible to the path when requesting a subvolume removal.
The current code was misleading the path and didn't deleted the remaining
volumes.
This patch list the current subvolumes, filter thoses created by the
test process and ajust the path because brtfs reports
erwan/chroot/ceph/src/testdir/test-7202/dev/osd1/snap_439
while regarding the current working directory we want to delete :
testdir/test-7202/dev/osd1/snap_439
Signed-off-by: Erwan Velu <erwan@redhat.com>
local btrfs_base_dir=$1
btrfs_dirs=`ls -l $btrfs_base_dir | egrep '^d' | awk '{print $9}'`
- for btrfs_dir in $btrfs_dirs
- do
- btrfs_subdirs=`ls -l $btrfs_base_dir/$btrfs_dir | egrep '^d' | awk '{print $9}'`
- for btrfs_subdir in $btrfs_subdirs
- do
- btrfs subvolume delete $btrfs_base_dir/$btrfs_dir/$btrfs_subdir
- done
+ current_path=`pwd`
+ # extracting the current existing subvolumes
+ for subvolume in $(cd $btrfs_base_dir; btrfs subvolume list . -t |egrep '^[0-9]' | awk '{print $4}' |grep "$btrfs_base_dir/$btrfs_dir"); do
+ # Compute the relative path by removing the local path
+ # Like "erwan/chroot/ceph/src/testdir/test-7202/dev/osd1/snap_439" while we want "testdir/test-7202/dev/osd1/snap_439"
+ local_subvolume=$(echo $subvolume | sed -e "s|.*$current_path/||"g)
+ btrfs subvolume delete $local_subvolume
done
}