From 0081e53f5609b6064ffaf8fcb160da5bab540512 Mon Sep 17 00:00:00 2001 From: "rahul.deshmukh" Date: Wed, 19 Mar 2014 11:07:15 +0530 Subject: [PATCH] LU-4131 mdd: Changelog not logging file truncate. Use of truncate(2) does not produce any change log entries, and the action is invisible. This patch introduces CL_TRUNC event and adds the corresponding changelog record when the size has changed. Signed-off-by: Rahul Deshmukh Change-Id: I6621e726a82a8105a959b77b4f505f42990f5d64 Reviewed-on: http://review.whamcloud.com/9723 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Nathaniel Clark Reviewed-by: Fan Yong Reviewed-by: Mike Pershin Reviewed-by: Oleg Drokin --- lustre/mdd/mdd_object.c | 10 +++++----- lustre/tests/sanity.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index b44f6f1..e62e798 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -752,19 +752,19 @@ static int mdd_attr_set_changelog(const struct lu_env *env, struct mdd_device *mdd = mdo2mdd(obj); int bits, type = 0; - bits = (valid & ~(LA_CTIME|LA_MTIME|LA_ATIME)) ? 1 << CL_SETATTR : 0; + bits = (valid & LA_SIZE) ? 1 << CL_TRUNC : 0; + bits |= (valid & ~(LA_CTIME|LA_MTIME|LA_ATIME)) ? 1 << CL_SETATTR : 0; bits |= (valid & LA_MTIME) ? 1 << CL_MTIME : 0; bits |= (valid & LA_CTIME) ? 1 << CL_CTIME : 0; bits |= (valid & LA_ATIME) ? 1 << CL_ATIME : 0; bits = bits & mdd->mdd_cl.mc_mask; + /* This is an implementation limit rather than a protocol limit */ + CLASSERT(CL_LAST <= sizeof(int) * 8); if (bits == 0) return 0; /* The record type is the lowest non-masked set bit */ - while (bits && ((bits & 1) == 0)) { - bits = bits >> 1; - type++; - } + type = __ffs(bits); /* FYI we only store the first CLF_FLAGMASK bits of la_valid */ return mdd_changelog_data_store(env, mdd, type, (int)valid, diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 5715d67..7a430d0 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -9779,6 +9779,32 @@ test_160b() { # LU-3587 } run_test 160b "Verify that very long rename doesn't crash in changelog" +test_160c() { + local rc=0 + [ $PARALLEL == "yes" ] && skip "skip parallel run" && return + + # Registration step + local USER=$(do_facet $SINGLEMDS $LCTL --device $MDT0 \ + changelog_register -n) + + rm -rf $DIR/$tdir + mkdir -p $DIR/$tdir + $MCREATE $DIR/$tdir/foo_160c + changelog_chmask "TRUNC" + $TRUNCATE $DIR/$tdir/foo_160c 200 + changelog_chmask "TRUNC" + $TRUNCATE $DIR/$tdir/foo_160c 199 + $LFS changelog $MDT0 + TRUNCS=$($LFS changelog $MDT0 | tail -5 | grep -c "TRUNC") + [ $TRUNCS -eq 1 ] || err17935 "TRUNC changelog mask count $TRUNCS != 1" + $LFS changelog_clear $MDT0 $USER 0 + + # Deregistration step + echo "deregistering $USER" + do_facet $SINGLEMDS $LCTL --device $MDT0 changelog_deregister $USER +} +run_test 160c "verify that changelog log catch the truncate event" + test_161a() { [ $PARALLEL == "yes" ] && skip "skip parallel run" && return test_mkdir -p -c1 $DIR/$tdir -- 1.8.3.1