Whamcloud - gitweb
LU-1304 mdt: cache statfs in mdt_device
[fs/lustre-release.git] / lustre / mdt / mdt_handler.c
index 9d9c84d..11c7a76 100644 (file)
@@ -383,12 +383,30 @@ static int mdt_statfs(struct mdt_thread_info *info)
         if (rc)
                 RETURN(err_serious(rc));
 
-        if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
-                rc = err_serious(-ENOMEM);
-        } else {
-                osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
-                rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
-        }
+       if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK))
+               RETURN(err_serious(-ENOMEM));
+
+       osfs = req_capsule_server_get(info->mti_pill, &RMF_OBD_STATFS);
+       if (!osfs)
+               RETURN(-EPROTO);
+
+       /** statfs information are cached in the mdt_device */
+       if (cfs_time_before_64(info->mti_mdt->mdt_osfs_age,
+                              cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS))) {
+               /** statfs data is too old, get up-to-date one */
+               rc = next->md_ops->mdo_statfs(info->mti_env, next, osfs);
+               if (rc)
+                       RETURN(rc);
+               cfs_spin_lock(&info->mti_mdt->mdt_osfs_lock);
+               info->mti_mdt->mdt_osfs = *osfs;
+               info->mti_mdt->mdt_osfs_age = cfs_time_current_64();
+               cfs_spin_unlock(&info->mti_mdt->mdt_osfs_lock);
+       } else {
+               /** use cached statfs data */
+               cfs_spin_lock(&info->mti_mdt->mdt_osfs_lock);
+               *osfs = info->mti_mdt->mdt_osfs;
+               cfs_spin_unlock(&info->mti_mdt->mdt_osfs_lock);
+       }
 
         if (rc == 0)
                mdt_counter_incr(req, LPROC_MDT_STATFS);