Whamcloud - gitweb
LU-4131 mdd: Changelog not logging file truncate. 23/9723/2
authorrahul.deshmukh <rahul_deshmukh@xyratex.com>
Wed, 19 Mar 2014 05:37:15 +0000 (11:07 +0530)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 19 Apr 2014 06:22:25 +0000 (06:22 +0000)
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 <rahul_deshmukh@xyratex.com>
Change-Id: I6621e726a82a8105a959b77b4f505f42990f5d64
Reviewed-on: http://review.whamcloud.com/9723
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Reviewed-by: Fan Yong <fan.yong@intel.com>
Reviewed-by: Mike Pershin <mike.pershin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/mdd/mdd_object.c
lustre/tests/sanity.sh

index b44f6f1..e62e798 100644 (file)
@@ -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,
index 5715d67..7a430d0 100644 (file)
@@ -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