void mdc_close_pack(struct ptlrpc_request *req, struct md_op_data *op_data)
{
- struct mdt_ioepoch *epoch;
- struct mdt_rec_setattr *rec;
+ struct mdt_ioepoch *epoch;
+ struct mdt_rec_setattr *rec;
- epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH);
- rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
+ epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH);
+ rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
- mdc_setattr_pack_rec(rec, op_data);
- mdc_ioepoch_pack(epoch, op_data);
+ mdc_setattr_pack_rec(rec, op_data);
+ /*
+ * The client will zero out local timestamps when losing the IBITS lock
+ * so any new RPC timestamps will update the client inode's timestamps.
+ * There was a defect on the server side which allowed the atime to be
+ * overwritten by a zeroed-out atime packed into the close RPC.
+ *
+ * Proactively clear the MDS_ATTR_ATIME flag in the RPC in this case
+ * to avoid zeroing the atime on old unpatched servers. See LU-8041.
+ */
+ if (rec->sa_atime == 0)
+ rec->sa_valid &= ~MDS_ATTR_ATIME;
+
+ mdc_ioepoch_pack(epoch, op_data);
mdc_intent_close_pack(req, op_data);
}
}
if (la->la_valid == LA_ATIME) {
- /* This is atime only set for read atime update on close. */
- if (la->la_atime >= oattr->la_atime &&
- la->la_atime < (oattr->la_atime +
+ /* This is an atime-only attribute update for close RPCs. */
+ if (la->la_atime < (oattr->la_atime +
mdd_obj2mdd_dev(obj)->mdd_atime_diff))
la->la_valid &= ~LA_ATIME;
RETURN(0);
# test setting directory atime to future
touch -a -d @$TEST_39_ATIME $DIR/$tdir
local atime=$(stat -c %X $DIR/$tdir)
- [ "$atime" = $TEST_39_ATIME ] || \
+ [ "$atime" = $TEST_39_ATIME ] ||
error "atime is not set to future: $atime, $TEST_39_ATIME"
# test setting directory atime from future to now
- local d1=$(date +%s)
- ls $DIR/$tdir
- local d2=$(date +%s)
+ local now=$(date +%s)
+ touch -a -d @$now $DIR/$tdir
- cancel_lru_locks mdc
atime=$(stat -c %X $DIR/$tdir)
- [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
- error "atime is not updated from future: $atime, $d1<atime<$d2"
+ [ "$atime" -eq "$now" ] ||
+ error "atime is not updated from future: $atime, $now"
do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=2
sleep 3
# test setting directory atime when now > dir atime + atime_diff
- d1=$(date +%s)
+ local d1=$(date +%s)
ls $DIR/$tdir
- d2=$(date +%s)
+ local d2=$(date +%s)
cancel_lru_locks mdc
atime=$(stat -c %X $DIR/$tdir)
- [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
+ [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
error "atime is not updated : $atime, should be $d2"
do_facet $SINGLEMDS lctl set_param -n mdd.*MDT0000*.atime_diff=60
ls $DIR/$tdir
cancel_lru_locks mdc
atime=$(stat -c %X $DIR/$tdir)
- [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] || \
+ [ "$atime" -ge "$d1" -a "$atime" -le "$d2" ] ||
error "atime is updated to $atime, should remain $d1<atime<$d2"
do_facet $SINGLEMDS \
run_test 39p "remote directory cached attributes updated after create ========"
+test_39p() { # LU-8041
+ local testdir=$DIR/$tdir
+ mkdir -p $testdir
+ multiop_bg_pause $testdir D_c || error "multiop failed"
+ local multipid=$!
+ cancel_lru_locks mdc
+ kill -USR1 $multipid
+ local atime=$(stat -c %X $testdir)
+ [ "$atime" -ne 0 ] || error "atime is zero"
+}
+run_test 39p "close won't zero out atime"
+
test_40() {
dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
$RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&