Whamcloud - gitweb
LU-9019 libcfs: remove cfs_time_XXX_64 wrappers
[fs/lustre-release.git] / lustre / target / tgt_grant.c
index 62da5c9..659afb3 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2016, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * lustre/target/tgt_grant.c
@@ -138,11 +138,6 @@ static int tgt_check_export_grants(struct obd_export *exp, u64 *dirty,
        struct tg_export_data *ted = &exp->exp_target_data;
        int level = D_CACHE;
 
-       if (exp->exp_obd->obd_self_export == exp)
-               CDEBUG(D_CACHE, "%s: processing self export: %ld %ld "
-                      "%ld\n", exp->exp_obd->obd_name, ted->ted_grant,
-                      ted->ted_pending, ted->ted_dirty);
-
        if (ted->ted_grant < 0 || ted->ted_pending < 0 || ted->ted_dirty < 0)
                level = D_ERROR;
        CDEBUG_LIMIT(level, "%s: cli %s/%p dirty %ld pend %ld grant %ld\n",
@@ -188,6 +183,7 @@ void tgt_grant_sanity_check(struct obd_device *obd, const char *func)
        struct lu_target *lut = obd->u.obt.obt_lut;
        struct tg_grants_data *tgd = &lut->lut_tgd;
        struct obd_export *exp;
+       struct tg_export_data *ted;
        u64                maxsize;
        u64                tot_dirty = 0;
        u64                tot_pending = 0;
@@ -209,6 +205,15 @@ void tgt_grant_sanity_check(struct obd_device *obd, const char *func)
 
        spin_lock(&obd->obd_dev_lock);
        spin_lock(&tgd->tgd_grant_lock);
+       exp = obd->obd_self_export;
+       ted = &exp->exp_target_data;
+       CDEBUG(D_CACHE, "%s: processing self export: %ld %ld "
+              "%ld\n", obd->obd_name, ted->ted_grant,
+              ted->ted_pending, ted->ted_dirty);
+       tot_granted += ted->ted_grant + ted->ted_pending;
+       tot_pending += ted->ted_pending;
+       tot_dirty += ted->ted_dirty;
+
        list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
                error = tgt_check_export_grants(exp, &tot_dirty, &tot_pending,
                                                &tot_granted, maxsize);
@@ -275,14 +280,14 @@ EXPORT_SYMBOL(tgt_grant_sanity_check);
  * \retval             negative value on error
  */
 int tgt_statfs_internal(const struct lu_env *env, struct lu_target *lut,
-                       struct obd_statfs *osfs, __u64 max_age, int *from_cache)
+                       struct obd_statfs *osfs, time64_t max_age, int *from_cache)
 {
        struct tg_grants_data *tgd = &lut->lut_tgd;
        int rc = 0;
        ENTRY;
 
        spin_lock(&tgd->tgd_osfs_lock);
-       if (cfs_time_before_64(tgd->tgd_osfs_age, max_age) || max_age == 0) {
+       if (tgd->tgd_osfs_age < max_age || max_age == 0) {
                u64 unstable;
 
                /* statfs data are too old, get up-to-date one.
@@ -339,7 +344,7 @@ int tgt_statfs_internal(const struct lu_env *env, struct lu_target *lut,
 
                /* finally udpate cached statfs data */
                tgd->tgd_osfs = *osfs;
-               tgd->tgd_osfs_age = cfs_time_current_64();
+               tgd->tgd_osfs_age = ktime_get_seconds();
 
                tgd->tgd_statfs_inflight--; /* stop tracking */
                if (tgd->tgd_statfs_inflight == 0)
@@ -385,13 +390,13 @@ static void tgt_grant_statfs(const struct lu_env *env, struct obd_export *exp,
        struct tg_grants_data   *tgd = &lut->lut_tgd;
        struct tgt_thread_info  *tti;
        struct obd_statfs       *osfs;
-       __u64                    max_age;
-       int                      rc;
+       time64_t max_age;
+       int rc;
 
        if (force)
                max_age = 0; /* get fresh statfs data */
        else
-               max_age = cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS);
+               max_age = ktime_get_seconds() - OBD_STATFS_CACHE_SECONDS;
 
        tti = tgt_th_info(env);
        osfs = &tti->tti_u.osfs;
@@ -926,6 +931,14 @@ static long tgt_grant_alloc(struct obd_export *exp, u64 curgrant,
        if ((grant > chunk) && conservative)
                grant = chunk;
 
+       /*
+        * Limit grant so that export' grant does not exceed what the
+        * client would like to have by more than grants for 2 full
+        * RPCs
+        */
+       if (ted->ted_grant + grant > want + chunk)
+               grant = want + chunk - ted->ted_grant;
+
        tgd->tgd_tot_granted += grant;
        ted->ted_grant += grant;