Whamcloud - gitweb
LU-13296 obd: make statfs cache working again 53/37753/3
authorAlexey Lyashkov <c17817@cray.com>
Thu, 27 Feb 2020 14:48:48 +0000 (17:48 +0300)
committerOleg Drokin <green@whamcloud.com>
Thu, 5 Mar 2020 22:35:09 +0000 (22:35 +0000)
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 <c17817@cray.com>
Change-Id: I268782875c30c078f239c194f69cdf7506d66169
Reviewed-on: https://review.whamcloud.com/37753
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
lustre/include/obd_class.h
lustre/tests/sanity.sh

index 9cc8a4c..320914e 100644 (file)
@@ -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,
index 7f042ff..29d5033 100755 (executable)
@@ -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) ]] &&