From dfd8433e6f6376bf5f7a50020bb484adfe48ce2c Mon Sep 17 00:00:00 2001 From: Manoj Joseph Date: Thu, 22 Apr 2010 12:15:28 -0700 Subject: [PATCH] b=22507 rm -rf not replicated Support replication of recursive directory removal. i=nathan.rutman i=robert.read --- lustre/tests/lustre-rsync-test.sh | 23 +++++++++++++++++++++++ lustre/utils/lustre_rsync.c | 16 ++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lustre/tests/lustre-rsync-test.sh b/lustre/tests/lustre-rsync-test.sh index 953b396..6566850 100644 --- a/lustre/tests/lustre-rsync-test.sh +++ b/lustre/tests/lustre-rsync-test.sh @@ -562,6 +562,29 @@ test_8() { } run_test 8 "Replicate multiple file/directory moves" +test_9() { + init_src + init_changelog + + mkdir $DIR/$tdir/foo + touch $DIR/$tdir/foo/a1 + + $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG + + check_diff ${DIR}/$tdir $TGT/$tdir + + rm -rf $DIR/$tdir/foo + + $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG + + check_diff ${DIR}/$tdir $TGT/$tdir + + fini_changelog + cleanup_src_tgt + return 0 +} +run_test 9 "Replicate recursive directory removal" + log "cleanup: ======================================================" cd $ORIG_PWD check_and_cleanup_lustre diff --git a/lustre/utils/lustre_rsync.c b/lustre/utils/lustre_rsync.c index 0f3d6de..ffe297f 100644 --- a/lustre/utils/lustre_rsync.c +++ b/lustre/utils/lustre_rsync.c @@ -708,6 +708,19 @@ int lr_rmfile(struct lr_info *info) return rc; } +/* Recursively remove directory and its contents */ +int lr_rm_recursive(struct lr_info *info) +{ + int rc; + + snprintf(info->cmd, PATH_MAX, "rm -rf %s", info->dest); + rc = system(info->cmd); + if (rc == -1) + rc = -errno; + + return rc; +} + /* Remove a file under SPECIAL_DIR with its tfid as its name. */ int lr_rm_special(struct lr_info *info) { @@ -825,6 +838,9 @@ int lr_remove(struct lr_info *info) rc1 = lr_rmfile(info); lr_debug(DINFO, "remove: %s; rc1=%d, errno=%d\n", info->dest, rc1, errno); + if (rc1 == -ENOTEMPTY) + rc1 = lr_rm_recursive(info); + if (rc1) { rc = rc1; continue; -- 1.8.3.1