From: Niu Yawei Date: Wed, 29 Jun 2016 12:57:22 +0000 (-0400) Subject: LU-7310 clio: sync write should update mtime X-Git-Tag: 2.8.58~6 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=e130c75827b2f40d89cb69ac5c64bb94d67c520c LU-7310 clio: sync write should update mtime 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 Change-Id: I9c7e1d75f610a3104c163df9d68c33442d8fe3f4 Reviewed-on: http://review.whamcloud.com/21063 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Bobi Jam Reviewed-by: Oleg Drokin --- diff --git a/lustre/osc/osc_io.c b/lustre/osc/osc_io.c index 05ef75b..49e1d51 100644 --- a/lustre/osc/osc_io.c +++ b/lustre/osc/osc_io.c @@ -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; } diff --git a/lustre/tests/sanityn.sh b/lustre/tests/sanityn.sh index 8c332a4..3d67e99 100755 --- a/lustre/tests/sanityn.sh +++ b/lustre/tests/sanityn.sh @@ -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