From 5f23ef1673ffd00f0b95478f4daa8735156a059d Mon Sep 17 00:00:00 2001 From: zhanghc Date: Wed, 8 Feb 2006 07:54:50 +0000 Subject: [PATCH] Land b1_4_atime_update on b_release_1_4_6 BUG: 5972 DESCRIPTION: Liblustre read not setting st_atime Modified Files: Tag: b_release_1_4_6 include/linux/lustre_compat25.h liblustre/rw.c liblustre/tests/sanity.c llite/file.c llite/llite_lib.c lov/lov_merge.c obdfilter/filter_io.c tests/replay-single.sh tests/sanityN.sh --- lustre/include/linux/lustre_compat25.h | 9 +++++++ lustre/liblustre/rw.c | 4 ++++ lustre/liblustre/tests/sanity.c | 43 ++++++++++++++++++++++++++++++++++ lustre/llite/file.c | 2 ++ lustre/llite/llite_lib.c | 3 ++- lustre/obdfilter/filter_io.c | 12 ++++++++++ lustre/tests/sanityN.sh | 26 ++++++++++++++++++++ 7 files changed, 98 insertions(+), 1 deletion(-) diff --git a/lustre/include/linux/lustre_compat25.h b/lustre/include/linux/lustre_compat25.h index a853f42..2eb9780 100644 --- a/lustre/include/linux/lustre_compat25.h +++ b/lustre/include/linux/lustre_compat25.h @@ -314,6 +314,15 @@ static inline int page_mapped(struct page *page) } #endif /* !HAVE_PAGE_MAPPED */ +static inline void file_accessed(struct file *file) +{ +#ifdef O_NOATIME + if (file->f_flags & O_NOATIME) + return; +#endif + update_atime(file->f_dentry->d_inode); +} + #endif /* end of 2.4 compat macros */ #ifdef HAVE_PAGE_LIST diff --git a/lustre/liblustre/rw.c b/lustre/liblustre/rw.c index f556c74..1f60bd5 100644 --- a/lustre/liblustre/rw.c +++ b/lustre/liblustre/rw.c @@ -787,6 +787,10 @@ static int llu_file_rwx(struct inode *ino, int llu_iop_read(struct inode *ino, struct ioctx *ioctx) { + /* BUG: 5972 */ + struct intnl_stat *st = llu_i2stat(ino); + st->st_atime = CURRENT_TIME; + return llu_file_rwx(ino, ioctx, 1); } diff --git a/lustre/liblustre/tests/sanity.c b/lustre/liblustre/tests/sanity.c index fa98f39..48c795d 100644 --- a/lustre/liblustre/tests/sanity.c +++ b/lustre/liblustre/tests/sanity.c @@ -1035,6 +1035,48 @@ int t51(char *name) printf("\n"); LEAVE(); } +/* + * check atime update during read + */ +int t52(char *name) +{ + char file[MAX_PATH_LENGTH] = ""; + char buf[16]; + struct stat statbuf; + time_t atime; + time_t diff; + int fd, i; + + ENTRY("atime should be updated during read"); + snprintf(file, MAX_PATH_LENGTH, "%s/test_t52_file", lustre_path); + + t_echo_create(file, "check atime update during read"); + fd = open(file, O_RDONLY); + if (fd < 0) { + printf("\nerror open file: %s\n", strerror(errno)); + return(-1); + } + stat(file, &statbuf); + printf("st_atime=%s", ctime(&statbuf.st_atime)); + atime = statbuf.st_atime; + for (i = 0; i < 3; i++) { + sleep(2); + read(fd, buf, sizeof(buf)); + stat(file, &statbuf); + printf("st_atime=%s", ctime(&statbuf.st_atime)); + diff = statbuf.st_atime - atime; + if (diff <= 0) { + printf("atime doesn't updated! failed!\n"); + close(fd); + t_unlink(file); + return -1; + } + atime = statbuf.st_atime; + } + close(fd); + t_unlink(file); + LEAVE(); +} extern void __liblustre_setup_(void); extern void __liblustre_cleanup_(void); @@ -1079,6 +1121,7 @@ struct testlist { { t50, "50" }, { t50b, "50b" }, { t51, "51" }, + { t52, "52" }, { NULL, NULL } }; diff --git a/lustre/llite/file.c b/lustre/llite/file.c index bef7220..41848b3 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -908,6 +908,8 @@ static ssize_t ll_file_read(struct file *file, char *buf, size_t count, bead.lrr_start = *ppos >> CFS_PAGE_SHIFT; bead.lrr_count = (count + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT; ll_ra_read_in(file, &bead); + /* BUG: 5972 */ + file_accessed(file); retval = generic_file_read(file, buf, count, ppos); ll_ra_read_ex(file, &bead); diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index eef3717..6aa56bd 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -1448,7 +1448,8 @@ void ll_update_inode(struct inode *inode, struct lustre_md *md) if (body->valid & OBD_MD_FLID) inode->i_ino = body->ino; - if (body->valid & OBD_MD_FLATIME) + if (body->valid & OBD_MD_FLATIME && + body->atime > LTIME_S(inode->i_atime)) LTIME_S(inode->i_atime) = body->atime; if (body->valid & OBD_MD_FLMTIME && body->mtime > LTIME_S(inode->i_mtime)) { diff --git a/lustre/obdfilter/filter_io.c b/lustre/obdfilter/filter_io.c index a0b494c..5d2cd2f 100644 --- a/lustre/obdfilter/filter_io.c +++ b/lustre/obdfilter/filter_io.c @@ -698,7 +698,19 @@ static int filter_commitrw_read(struct obd_export *exp, struct obdo *oa, struct obd_trans_info *oti, int rc) { struct inode *inode = NULL; + struct ldlm_res_id res_id = { .name = { obj->ioo_id } }; + struct ldlm_resource *resource = NULL; + struct ldlm_namespace *ns = exp->exp_obd->obd_namespace; ENTRY; + /* If oa != NULL then filter_preprw_read updated the inode atime + * and we should update the lvb so that other glimpses will also + * get the updated value. bug 5972 */ + if (ns && oa) { + resource = ldlm_resource_get(ns, NULL, res_id, LDLM_EXTENT, 0); + if (resource && ns->ns_lvbo && ns->ns_lvbo->lvbo_update) + ns->ns_lvbo->lvbo_update(resource, NULL, 0, 1); + ldlm_resource_putref(resource); + } if (res->dentry != NULL) inode = res->dentry->d_inode; diff --git a/lustre/tests/sanityN.sh b/lustre/tests/sanityN.sh index 9b753a3..2ea854a 100644 --- a/lustre/tests/sanityN.sh +++ b/lustre/tests/sanityN.sh @@ -464,6 +464,32 @@ test_22() { # Bug 9926 } run_test 22 " After joining in one dir, open/close unlink file in anther dir" +test_23() { # Bug 5972 + echo "others should see updated atime while another read" > $DIR1/f23 + + # clear the lock(mode: LCK_PW) gotten from creating operation + cancel_lru_locks OSC + + time1=`date +%s` + sleep 2 + + multiop $DIR1/f23 or20_c & + MULTIPID=$! + + sleep 2 + time2=`stat -c "%X" $DIR2/f23` + + if (( $time2 <= $time1 )); then + kill -USR1 $MULTIPID + error "atime doesn't update among nodes" + fi + + kill -USR1 $MULTIPID || return 1 + rm -f $DIR1/f23 || error "rm -f $DIR1/f23 failed" + true +} +run_test 23 " others should see updated atime while another read====" + log "cleanup: ======================================================" rm -rf $DIR1/[df][0-9]* $DIR1/lnk || true -- 1.8.3.1