[sheepdog] [PATCH] tests: remove directory surely

MORITA Kazutaka morita.kazutaka at gmail.com
Wed May 8 18:07:10 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

rm -rf fails if new files are created before rm is completed.  This
patch renames the directory beforehand so that sheep cannot creates
new objects in it any more.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 tests/043       |    4 ++--
 tests/056       |    7 ++++---
 tests/common.rc |    9 +++++++++
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/tests/043 b/tests/043
index 59f6f74..ff6b7cc 100755
--- a/tests/043
+++ b/tests/043
@@ -35,7 +35,7 @@ for i in 0 1 2 3 4; do
 done
 
 # remove obj directory to occur EIO
-rm -rf $STORE/4/obj
+_safe_remove $STORE/4/obj
 
 for i in `seq 0 10`; do
     echo $(($i + 100)) | $COLLIE vdi write test $((i * 4 * 1024 * 1024)) 512
@@ -66,5 +66,5 @@ for i in 0 1 2 4; do
 done
 
 # check whether we can write to a gateway after EIO
-rm -rf $STORE/0/obj
+_safe_remove $STORE/0/obj
 echo hello | $COLLIE vdi write test 0 512
diff --git a/tests/056 b/tests/056
index 25dd22f..9a45187 100755
--- a/tests/056
+++ b/tests/056
@@ -24,7 +24,8 @@ sleep 1
 $COLLIE vdi create test 200M -P
 
 # node event after disk failure
-rm $STORE/0/d0 -rf
+_safe_remove $STORE/0/d0
+
 dd if=/dev/urandom | $COLLIE vdi write test &
 sleep 1
 _start_sheep 3
@@ -35,12 +36,12 @@ $COLLIE vdi check test
 $COLLIE cluster info | _filter_cluster_info
 
 # disk failures after node event
-rm $STORE/1/d0 -rf
+_safe_remove $STORE/1/d0
 dd if=/dev/zero | $COLLIE vdi write test &
 sleep 1
 _kill_sheep 2
 sleep 1
-rm $STORE/1/d1 -rf
+_safe_remove $STORE/1/d1
 _wait_for_sheep_recovery 0
 wait # collie
 $COLLIE vdi check test
diff --git a/tests/common.rc b/tests/common.rc
index a2de9de..e9c0af0 100644
--- a/tests/common.rc
+++ b/tests/common.rc
@@ -41,6 +41,15 @@ _need_to_be_root()
     fi
 }
 
+# To remove directory successfully always, we have to rename it first
+# so that new files are not created in the directory while we remove it.
+_safe_remove()
+{
+    local dir=$1
+    mv ${dir} ${dir}.tmp
+    rm -rf ${dir}.tmp
+}
+
 # Do a command, log it to $seq.full, optionally test return status
 # and die if command fails. If called with one argument _do executes the
 # command, logs it, and returns its exit status. With two arguments _do
-- 
1.7.9.5




More information about the sheepdog mailing list