From: Alexey Lyashkov Date: Thu, 27 Feb 2020 14:48:48 +0000 (+0300) Subject: LU-13296 obd: make statfs cache working again X-Git-Tag: 2.13.53~140 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=7281635521a823548d497bce2f19acfa3318dfe9;p=fs%2Flustre-release.git LU-13296 obd: make statfs cache working again Once statfs raced on mutex, lets read a cached data instead of trash. Test-Parameters: testlist=sanity envdefinitions=ONLY=423,ONLY_REPEAT=500 Fixes: 1c41a6ac390b ("LU-12368 obdclass: don't send multiple statfs RPCs") Signed-off-by: Alexey Lyashkov Change-Id: I268782875c30c078f239c194f69cdf7506d66169 Reviewed-on: https://review.whamcloud.com/37753 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Alex Zhuravlev --- diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h index 9cc8a4c..320914e 100644 --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -1058,7 +1058,6 @@ static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp, if (obd->obd_osfs_age < max_age || ((obd->obd_osfs.os_state & OS_STATE_SUM) && !(flags & OBD_STATFS_SUM))) { - bool update_age = false; /* the RPC will block anyway, so avoid sending many at once */ rc = mutex_lock_interruptible(&obd->obd_dev_mutex); if (rc) @@ -1067,23 +1066,25 @@ static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp, ((obd->obd_osfs.os_state & OS_STATE_SUM) && !(flags & OBD_STATFS_SUM))) { rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags); - update_age = true; } else { - CDEBUG(D_SUPER, - "%s: new %p cache blocks %llu/%llu objects %llu/%llu\n", - obd->obd_name, &obd->obd_osfs, - obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks, - obd->obd_osfs.os_ffree, obd->obd_osfs.os_files); + mutex_unlock(&obd->obd_dev_mutex); + GOTO(cached, rc = 0); } if (rc == 0) { + CDEBUG(D_SUPER, + "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n", + obd->obd_name, &obd->obd_osfs, + osfs->os_bavail, osfs->os_blocks, + osfs->os_ffree, osfs->os_files); + spin_lock(&obd->obd_osfs_lock); memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs)); - if (update_age) - obd->obd_osfs_age = ktime_get_seconds(); + obd->obd_osfs_age = ktime_get_seconds(); spin_unlock(&obd->obd_osfs_lock); } mutex_unlock(&obd->obd_dev_mutex); } else { +cached: CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n", obd->obd_name, &obd->obd_osfs, diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 7f042ff..29d5033 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -21912,6 +21912,27 @@ test_422() { } run_test 422 "kill a process with RPC in progress" +stat_test() { + df -h $MOUNT & + df -h $MOUNT & + df -h $MOUNT & + df -h $MOUNT & + df -h $MOUNT & + df -h $MOUNT & +} + +test_423() { + local _stats + # ensure statfs cache is expired + sleep 2; + + _stats=$(stat_test | grep $MOUNT | sort -u | wc -l) + [[ ${_stats} -ne 1 ]] && error "statfs wrong" + + return 0 +} +run_test 423 "statfs should return a right data" + prep_801() { [[ $MDS1_VERSION -lt $(version_code 2.9.55) ]] || [[ $OST1_VERSION -lt $(version_code 2.9.55) ]] &&