Whamcloud - gitweb
LU-7310 clio: sync write should update mtime 63/21063/6
authorNiu Yawei <yawei.niu@intel.com>
Wed, 29 Jun 2016 12:57:22 +0000 (08:57 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 13 Sep 2016 20:03:48 +0000 (20:03 +0000)
Sync write should update m/ctime promptly, otherwise, stale m/ctime
could be updated on the OST object by the sync write RPC.

Added sanityn test_39d to verify this.

Signed-off-by: Niu Yawei <yawei.niu@intel.com>
Change-Id: I9c7e1d75f610a3104c163df9d68c33442d8fe3f4
Reviewed-on: http://review.whamcloud.com/21063
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/osc/osc_io.c
lustre/tests/sanityn.sh

index 05ef75b..49e1d51 100644 (file)
@@ -214,6 +214,17 @@ static int osc_io_submit(const struct lu_env *env,
        if (queued > 0)
                result = osc_queue_sync_pages(env, osc, &list, cmd, brw_flags);
 
+       /* Update c/mtime for sync write. LU-7310 */
+       if (qout->pl_nr > 0 && result == 0) {
+               struct cl_object *obj   = ios->cis_obj;
+               struct cl_attr *attr = &osc_env_info(env)->oti_attr;
+
+               cl_object_attr_lock(obj);
+               attr->cat_mtime = attr->cat_ctime = LTIME_S(CURRENT_TIME);
+               cl_object_attr_update(env, obj, attr, CAT_MTIME | CAT_CTIME);
+               cl_object_attr_unlock(obj);
+       }
+
        CDEBUG(D_INFO, "%d/%d %d\n", qin->pl_nr, qout->pl_nr, result);
        return qout->pl_nr > 0 ? 0 : result;
 }
index 8c332a4..3d67e99 100755 (executable)
@@ -1351,6 +1351,32 @@ test_39c() {
 }
 run_test 39c "check truncate mtime update ======================"
 
+test_39d() { # LU-7310
+       touch $DIR1/$tfile
+       touch -m -d @$TEST_39_MTIME $DIR1/$tfile
+
+       local mtime1=$(stat -c %Y $DIR2/$tfile)
+       [ "$mtime1" = $TEST_39_MTIME ] ||
+               error "mtime: $mtime1, should be $TEST_39_MTIME"
+
+       # force sync write
+       # define OBD_FAIL_OSC_NO_GRANT 0x411
+       $LCTL set_param fail_loc=0x411
+
+       local d1=$(date +%s)
+       echo hello >> $DIR1/$tfile
+       local d2=$(date +%s)
+
+       $LCTL set_param fail_loc=0
+
+       cancel_lru_locks osc
+
+       local mtime2=$(stat -c %Y $DIR2/$tfile)
+       [ "$mtime2" -ge "$d1" ] && [ "$mtime2" -le "$d2" ] ||
+               error "mtime is not updated on write: $d1 <= $mtime2 <= $d2"
+}
+run_test 39d "sync write should update mtime"
+
 # check that pid exists hence second operation wasn't blocked by first one
 # if it is so then there is no conflict, return 0
 # else second operation is conflicting with first one, return 1