Whamcloud - gitweb
LU-12635 build: Support for gcc -Wimplicit-fallthrough
[fs/lustre-release.git] / lustre / target / tgt_grant.c
index 659afb3..e863581 100644 (file)
@@ -71,7 +71,7 @@
  * Author: Johann Lombardi <johann.lombardi@intel.com>
  */
 
-#define DEBUG_SUBSYSTEM S_FILTER
+#define DEBUG_SUBSYSTEM S_CLASS
 
 #include <obd.h>
 #include <obd_class.h>
@@ -499,8 +499,7 @@ static void tgt_grant_incoming(const struct lu_env *env, struct obd_export *exp,
        struct tg_export_data   *ted = &exp->exp_target_data;
        struct obd_device       *obd = exp->exp_obd;
        struct tg_grants_data   *tgd = &obd->u.obt.obt_lut->lut_tgd;
-       long                     dirty;
-       long                     dropped;
+       long long                dirty, dropped;
        ENTRY;
 
        assert_spin_locked(&tgd->tgd_grant_lock);
@@ -524,10 +523,19 @@ static void tgt_grant_incoming(const struct lu_env *env, struct obd_export *exp,
 
        /* inflate grant counters if required */
        if (!exp_grant_param_supp(exp)) {
+               u64 tmp;
                oa->o_grant     = tgt_grant_inflate(tgd, oa->o_grant);
                oa->o_dirty     = tgt_grant_inflate(tgd, oa->o_dirty);
-               oa->o_dropped   = tgt_grant_inflate(tgd, (u64)oa->o_dropped);
-               oa->o_undirty   = tgt_grant_inflate(tgd, oa->o_undirty);
+               /* inflation can bump client's wish to >4GB which doesn't fit
+                * 32bit o_undirty, limit that ..  */
+               tmp = tgt_grant_inflate(tgd, oa->o_undirty);
+               if (tmp >= OBD_MAX_GRANT)
+                       tmp = OBD_MAX_GRANT & ~(1ULL << tgd->tgd_blockbits);
+               oa->o_undirty = tmp;
+               tmp = tgt_grant_inflate(tgd, oa->o_dropped);
+               if (tmp >= OBD_MAX_GRANT)
+                       tmp = OBD_MAX_GRANT & ~(1ULL << tgd->tgd_blockbits);
+               oa->o_dropped = tmp;
        }
 
        dirty = oa->o_dirty;
@@ -542,13 +550,13 @@ static void tgt_grant_incoming(const struct lu_env *env, struct obd_export *exp,
        tgd->tgd_tot_dirty += dirty - ted->ted_dirty;
        if (ted->ted_grant < dropped) {
                CDEBUG(D_CACHE,
-                      "%s: cli %s/%p reports %lu dropped > grant %lu\n",
+                      "%s: cli %s/%p reports %llu dropped > grant %lu\n",
                       obd->obd_name, exp->exp_client_uuid.uuid, exp, dropped,
                       ted->ted_grant);
                dropped = 0;
        }
        if (tgd->tgd_tot_granted < dropped) {
-               CERROR("%s: cli %s/%p reports %lu dropped > tot_grant %llu\n",
+               CERROR("%s: cli %s/%p reports %llu dropped > tot_grant %llu\n",
                       obd->obd_name, exp->exp_client_uuid.uuid, exp,
                       dropped, tgd->tgd_tot_granted);
                dropped = 0;
@@ -597,6 +605,14 @@ static void tgt_grant_shrink(struct obd_export *exp, struct obdo *oa,
 
        grant_shrink = oa->o_grant;
 
+       if (ted->ted_grant < grant_shrink) {
+               CDEBUG(D_CACHE,
+                      "%s: cli %s/%p wants %lu shrinked > grant %lu\n",
+                      obd->obd_name, exp->exp_client_uuid.uuid, exp,
+                      grant_shrink, ted->ted_grant);
+               grant_shrink = ted->ted_grant;
+       }
+
        ted->ted_grant -= grant_shrink;
        tgd->tgd_tot_granted -= grant_shrink;
 
@@ -894,9 +910,10 @@ static long tgt_grant_alloc(struct obd_export *exp, u64 curgrant,
             tgd->tgd_grant_compat_disable) || left == 0 || exp->exp_failed)
                RETURN(0);
 
-       if (want > 0x7fffffff) {
-               CERROR("%s: client %s/%p requesting > 2GB grant %llu\n",
-                      obd->obd_name, exp->exp_client_uuid.uuid, exp, want);
+       if (want > OBD_MAX_GRANT) {
+               CERROR("%s: client %s/%p requesting > max (%lu), %llu\n",
+                      obd->obd_name, exp->exp_client_uuid.uuid, exp,
+                      OBD_MAX_GRANT, want);
                RETURN(0);
        }
 
@@ -936,6 +953,8 @@ static long tgt_grant_alloc(struct obd_export *exp, u64 curgrant,
         * client would like to have by more than grants for 2 full
         * RPCs
         */
+       if (want + chunk <= ted->ted_grant)
+               RETURN(0);
        if (ted->ted_grant + grant > want + chunk)
                grant = want + chunk - ted->ted_grant;
 
@@ -1061,9 +1080,14 @@ EXPORT_SYMBOL(tgt_grant_connect);
 void tgt_grant_discard(struct obd_export *exp)
 {
        struct obd_device       *obd = exp->exp_obd;
-       struct tg_grants_data   *tgd = &obd->u.obt.obt_lut->lut_tgd;
+       struct lu_target        *lut = class_exp2tgt(exp);
        struct tg_export_data   *ted = &exp->exp_target_data;
+       struct tg_grants_data   *tgd;
+
+       if (!lut)
+               return;
 
+       tgd = &lut->lut_tgd;
        spin_lock(&tgd->tgd_grant_lock);
        LASSERTF(tgd->tgd_tot_granted >= ted->ted_grant,
                 "%s: tot_granted %llu cli %s/%p ted_grant %ld\n",
@@ -1521,65 +1545,68 @@ EXPORT_SYMBOL(tgt_grant_commit_cb_add);
 /**
  * Show estimate of total amount of dirty data on clients.
  *
- * \param[in] m                seq_file handle
- * \param[in] data     unused for single entry
+ * @kobj               kobject embedded in obd_device
+ * @attr               unused
+ * @buf                        buf used by sysfs to print out data
  *
- * \retval             0 on success
- * \retval             negative value on error
+ * Return:             0 on success
+ *                     negative value on error
  */
-int tgt_tot_dirty_seq_show(struct seq_file *m, void *data)
+ssize_t tot_dirty_show(struct kobject *kobj, struct attribute *attr,
+                      char *buf)
 {
-       struct obd_device *obd = m->private;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
        struct tg_grants_data *tgd;
 
-       LASSERT(obd != NULL);
        tgd = &obd->u.obt.obt_lut->lut_tgd;
-       seq_printf(m, "%llu\n", tgd->tgd_tot_dirty);
-       return 0;
+       return scnprintf(buf, PAGE_SIZE, "%llu\n", tgd->tgd_tot_dirty);
 }
-EXPORT_SYMBOL(tgt_tot_dirty_seq_show);
+EXPORT_SYMBOL(tot_dirty_show);
 
 /**
  * Show total amount of space granted to clients.
  *
- * \param[in] m                seq_file handle
- * \param[in] data     unused for single entry
+ * @kobj               kobject embedded in obd_device
+ * @attr               unused
+ * @buf                        buf used by sysfs to print out data
  *
- * \retval             0 on success
- * \retval             negative value on error
+ * Return:             0 on success
+ *                     negative value on error
  */
-int tgt_tot_granted_seq_show(struct seq_file *m, void *data)
+ssize_t tot_granted_show(struct kobject *kobj, struct attribute *attr,
+                        char *buf)
 {
-       struct obd_device *obd = m->private;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
        struct tg_grants_data *tgd;
 
-       LASSERT(obd != NULL);
        tgd = &obd->u.obt.obt_lut->lut_tgd;
-       seq_printf(m, "%llu\n", tgd->tgd_tot_granted);
-       return 0;
+       return scnprintf(buf, PAGE_SIZE, "%llu\n", tgd->tgd_tot_granted);
 }
-EXPORT_SYMBOL(tgt_tot_granted_seq_show);
+EXPORT_SYMBOL(tot_granted_show);
 
 /**
  * Show total amount of space used by IO in progress.
  *
- * \param[in] m                seq_file handle
- * \param[in] data     unused for single entry
+ * @kobj               kobject embedded in obd_device
+ * @attr               unused
+ * @buf                        buf used by sysfs to print out data
  *
- * \retval             0 on success
- * \retval             negative value on error
+ * Return:             0 on success
+ *                     negative value on error
  */
-int tgt_tot_pending_seq_show(struct seq_file *m, void *data)
+ssize_t tot_pending_show(struct kobject *kobj, struct attribute *attr,
+                        char *buf)
 {
-       struct obd_device *obd = m->private;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
        struct tg_grants_data *tgd;
 
-       LASSERT(obd != NULL);
        tgd = &obd->u.obt.obt_lut->lut_tgd;
-       seq_printf(m, "%llu\n", tgd->tgd_tot_pending);
-       return 0;
+       return scnprintf(buf, PAGE_SIZE, "%llu\n", tgd->tgd_tot_pending);
 }
-EXPORT_SYMBOL(tgt_tot_pending_seq_show);
+EXPORT_SYMBOL(tot_pending_show);
 
 /**
  * Show if grants compatibility mode is disabled.
@@ -1590,21 +1617,22 @@ EXPORT_SYMBOL(tgt_tot_pending_seq_show);
  * block, (i.e. typically 4kB units), but underlaying file system might have
  * block size bigger than page size, e.g. ZFS. See LU-2049 for details.
  *
- * \param[in] m                seq_file handle
- * \param[in] data     unused for single entry
+ * @kobj               kobject embedded in obd_device
+ * @attr               unused
+ * @buf                        buf used by sysfs to print out data
  *
- * \retval             0 on success
- * \retval             negative value on error
+ * Return:             string length of @buf output on success
  */
-int tgt_grant_compat_disable_seq_show(struct seq_file *m, void *data)
+ssize_t grant_compat_disable_show(struct kobject *kobj, struct attribute *attr,
+                                 char *buf)
 {
-       struct obd_device *obd = m->private;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
        struct tg_grants_data *tgd = &obd->u.obt.obt_lut->lut_tgd;
 
-       seq_printf(m, "%u\n", tgd->tgd_grant_compat_disable);
-       return 0;
+       return scnprintf(buf, PAGE_SIZE, "%u\n", tgd->tgd_grant_compat_disable);
 }
-EXPORT_SYMBOL(tgt_grant_compat_disable_seq_show);
+EXPORT_SYMBOL(grant_compat_disable_show);
 
 /**
  * Change grant compatibility mode.
@@ -1612,35 +1640,32 @@ EXPORT_SYMBOL(tgt_grant_compat_disable_seq_show);
  * Setting tgd_grant_compat_disable prohibit any space granting to clients
  * not supporting OBD_CONNECT_GRANT_PARAM. See details above.
  *
- * \param[in] file     proc file
- * \param[in] buffer   string which represents mode
- *                     1: disable compatibility mode
- *                     0: enable compatibility mode
- * \param[in] count    \a buffer length
- * \param[in] off      unused for single entry
+ * @kobj       kobject embedded in obd_device
+ * @attr       unused
+ * @buffer     string which represents mode
+ *             1: disable compatibility mode
+ *             0: enable compatibility mode
+ * @count      @buffer length
  *
- * \retval             \a count on success
- * \retval             negative number on error
+ * Return:     @count on success
+ *             negative number on error
  */
-ssize_t tgt_grant_compat_disable_seq_write(struct file *file,
-                                          const char __user *buffer,
-                                          size_t count, loff_t *off)
+ssize_t grant_compat_disable_store(struct kobject *kobj,
+                                  struct attribute *attr,
+                                  const char *buffer, size_t count)
 {
-       struct seq_file *m = file->private_data;
-       struct obd_device *obd = m->private;
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
        struct tg_grants_data *tgd = &obd->u.obt.obt_lut->lut_tgd;
-       __s64 val;
+       bool val;
        int rc;
 
-       rc = lprocfs_str_to_s64(buffer, count, &val);
+       rc = kstrtobool(buffer, &val);
        if (rc)
                return rc;
 
-       if (val < 0)
-               return -EINVAL;
-
-       tgd->tgd_grant_compat_disable = !!val;
+       tgd->tgd_grant_compat_disable = val;
 
        return count;
 }
-EXPORT_SYMBOL(tgt_grant_compat_disable_seq_write);
+EXPORT_SYMBOL(grant_compat_disable_store);