]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-helpers.sh: Deleting forgoten btrfs subvolumes
authorErwan Velu <erwan@redhat.com>
Thu, 25 Feb 2016 13:08:10 +0000 (14:08 +0100)
committerErwan Velu <erwan@redhat.com>
Thu, 25 Feb 2016 14:33:10 +0000 (15:33 +0100)
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>
qa/workunits/ceph-helpers.sh

index 157888864972f5094c6d977560549e5e4be212dc..d53837edb97cd7ba1750ea785e897e17b60bc5b0 100755 (executable)
@@ -126,13 +126,13 @@ function __teardown_btrfs() {
     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
 }