From 267d00fba3812198936d641a40f040a8937af33c Mon Sep 17 00:00:00 2001 From: Bobi Jam Date: Wed, 24 Jul 2013 00:47:23 +0800 Subject: [PATCH] LU-3620 mdd: missing CLF_RENAME_LAST flag in CL_RENME record mdd_rename() should use target's attribute to determine add CLF_RENAME_LAST flag in changelog record. Signed-off-by: Bobi Jam Change-Id: Id9a738f1c98f0c893b125d49965354f44c257e08 Reviewed-on: http://review.whamcloud.com/7095 Tested-by: Hudson Reviewed-by: Dmitry Eremin Tested-by: Maloo Reviewed-by: Fan Yong Reviewed-by: Oleg Drokin --- lustre/mdd/mdd_dir.c | 2 +- lustre/tests/sanity.sh | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index d607bba..b75ba34 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -2663,7 +2663,7 @@ static int mdd_rename(const struct lu_env *env, ma->ma_attr = *tg_attr; ma->ma_valid |= MA_INODE; - if (so_attr->la_nlink == 0) + if (tg_attr->la_nlink == 0) cl_flags |= CLF_RENAME_LAST; } diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index fdf7e76..b15303e 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -9477,6 +9477,85 @@ test_161b() { } run_test 161b "link ea sanity under remote directory" +test_161c() { + [ $PARALLEL == "yes" ] && skip "skip parallel run" && return + + # define CLF_RENAME_LAST 0x0001 + # rename overwrite a target having nlink = 1 (changelog flag 0x1) + local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \ + changelog_register -n) + mkdir -p $DIR/$tdir + touch $DIR/$tdir/foo_161c + touch $DIR/$tdir/bar_161c + mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c + local flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | \ + cut -f5 -d' ') + $LFS changelog_clear $MDT0 $USER 0 + if [ x$flags != "x0x1" ]; then + do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \ + $USER + error "flag $flags is not 0x1" + fi + echo "rename overwrite a target having nlink = 1," \ + "changelog record has flags of $flags" + + # rename overwrite a target having nlink > 1 (changelog flag 0x0) + touch $DIR/$tdir/foo_161c + touch $DIR/$tdir/bar_161c + ln $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c + mv -f $DIR/$tdir/foo_161c $DIR/$tdir/bar_161c + flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ') + $LFS changelog_clear $MDT0 $USER 0 + if [ x$flags != "x0x0" ]; then + do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \ + $USER + error "flag $flags is not 0x0" + fi + echo "rename overwrite a target having nlink > 1," \ + "changelog record has flags of $flags" + + # rename doesn't overwrite a target (changelog flag 0x0) + touch $DIR/$tdir/foo_161c + mv -f $DIR/$tdir/foo_161c $DIR/$tdir/foo2_161c + flags=$($LFS changelog $MDT0 | grep RENME | tail -1 | cut -f5 -d' ') + $LFS changelog_clear $MDT0 $USER 0 + if [ x$flags != "x0x0" ]; then + do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \ + $USER + error "flag $flags is not 0x0" + fi + echo "rename doesn't overwrite a target," \ + "changelog record has flags of $flags" + + # define CLF_UNLINK_LAST 0x0001 + # unlink a file having nlink = 1 (changelog flag 0x1) + rm -f $DIR/$tdir/foo2_161c + flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ') + $LFS changelog_clear $MDT0 $USER 0 + if [ x$flags != "x0x1" ]; then + do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \ + $USER + error "flag $flags is not 0x1" + fi + echo "unlink a file having nlink = 1," \ + "changelog record has flags of $flags" + + # unlink a file having nlink > 1 (changelog flag 0x0) + ln -f $DIR/$tdir/bar_161c $DIR/$tdir/foobar_161c + rm -f $DIR/$tdir/foobar_161c + flags=$($LFS changelog $MDT0 | grep UNLNK | tail -1 | cut -f5 -d' ') + $LFS changelog_clear $MDT0 $USER 0 + if [ x$flags != "x0x0" ]; then + do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister \ + $USER + error "flag $flags is not 0x0" + fi + echo "unlink a file having nlink > 1," \ + "changelog record has flags of $flags" + do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER +} +run_test 161c "check CL_RENME[UNLINK] changelog record flags" + check_path() { local expected=$1 shift -- 1.8.3.1