Whamcloud - gitweb
LU-7734 lnet: set primary NID in ptlrpc_connection_get()
[fs/lustre-release.git] / lustre / quota / qmt_pool.c
index c3215c9..3217127 100644 (file)
@@ -21,7 +21,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2012, 2013, Intel Corporation.
+ * Copyright (c) 2012, 2016, Intel Corporation.
  * Use is subject to license terms.
  *
  * Author: Johann Lombardi <johann.lombardi@intel.com>
@@ -86,7 +86,8 @@ static inline void qpi_putref_locked(struct qmt_pool_info *pool)
  * Hash functions for qmt_pool_info management
  */
 
-static unsigned qpi_hash_hash(cfs_hash_t *hs, const void *key, unsigned mask)
+static unsigned
+qpi_hash_hash(struct cfs_hash *hs, const void *key, unsigned mask)
 {
        return cfs_hash_u32_hash(*((__u32 *)key), mask);
 }
@@ -110,27 +111,27 @@ static void *qpi_hash_object(struct hlist_node *hnode)
        return hlist_entry(hnode, struct qmt_pool_info, qpi_hash);
 }
 
-static void qpi_hash_get(cfs_hash_t *hs, struct hlist_node *hnode)
+static void qpi_hash_get(struct cfs_hash *hs, struct hlist_node *hnode)
 {
        struct qmt_pool_info *pool;
        pool = hlist_entry(hnode, struct qmt_pool_info, qpi_hash);
        qpi_getref(pool);
 }
 
-static void qpi_hash_put_locked(cfs_hash_t *hs, struct hlist_node *hnode)
+static void qpi_hash_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
 {
        struct qmt_pool_info *pool;
        pool = hlist_entry(hnode, struct qmt_pool_info, qpi_hash);
        qpi_putref_locked(pool);
 }
 
-static void qpi_hash_exit(cfs_hash_t *hs, struct hlist_node *hnode)
+static void qpi_hash_exit(struct cfs_hash *hs, struct hlist_node *hnode)
 {
        CERROR("Should not have any item left!\n");
 }
 
 /* vector of hash operations */
-static cfs_hash_ops_t qpi_hash_ops = {
+static struct cfs_hash_ops qpi_hash_ops = {
        .hs_hash        = qpi_hash_hash,
        .hs_key         = qpi_hash_key,
        .hs_keycmp      = qpi_hash_keycmp,
@@ -158,7 +159,7 @@ static int qpi_state_seq_show(struct seq_file *m, void *data)
                   atomic_read(&pool->qpi_ref),
                   pool->qpi_least_qunit);
 
-       for (type = 0; type < MAXQUOTAS; type++)
+       for (type = 0; type < LL_MAXQUOTAS; type++)
                seq_printf(m, "    %s:\n"
                           "        #slv: %d\n"
                           "        #lqe: %d\n",
@@ -170,9 +171,53 @@ static int qpi_state_seq_show(struct seq_file *m, void *data)
 }
 LPROC_SEQ_FOPS_RO(qpi_state);
 
-static struct lprocfs_seq_vars lprocfs_quota_qpi_vars[] = {
+static int qpi_soft_least_qunit_seq_show(struct seq_file *m, void *data)
+{
+       struct qmt_pool_info    *pool = m->private;
+       LASSERT(pool != NULL);
+
+       seq_printf(m, "%lu\n", pool->qpi_soft_least_qunit);
+       return 0;
+}
+
+static ssize_t
+qpi_soft_least_qunit_seq_write(struct file *file, const char __user *buffer,
+                              size_t count, loff_t *off)
+{
+       struct qmt_pool_info    *pool;
+       int     qunit, rc;
+       s64     least_qunit;
+
+       pool = ((struct seq_file *)file->private_data)->private;
+       LASSERT(pool != NULL);
+
+       /* Not tuneable for inode limit */
+       if (pool->qpi_key >> 16 != LQUOTA_RES_DT)
+               return -EINVAL;
+
+       rc = lprocfs_str_to_s64(buffer, count, &least_qunit);
+       if (rc)
+               return rc;
+
+       /* Miminal qpi_soft_least_qunit */
+       qunit = pool->qpi_least_qunit << 2;
+       /* The value must be power of miminal qpi_soft_least_qunit, see
+        * how the qunit is adjusted in qmt_adjust_qunit(). */
+       while (qunit > 0 && qunit < least_qunit)
+               qunit <<= 2;
+       if (qunit <= 0)
+               qunit = INT_MAX & ~3;
+
+       pool->qpi_soft_least_qunit = qunit;
+       return count;
+}
+LPROC_SEQ_FOPS(qpi_soft_least_qunit);
+
+static struct lprocfs_vars lprocfs_quota_qpi_vars[] = {
        { .name =       "info",
          .fops =       &qpi_state_fops },
+       { .name =       "soft_least_qunit",
+         .fops =       &qpi_soft_least_qunit_fops },
        { NULL }
 };
 
@@ -210,11 +255,15 @@ static int qmt_pool_alloc(const struct lu_env *env, struct qmt_device *qmt,
 
        /* set up least qunit size to use for this pool */
        pool->qpi_least_qunit = LQUOTA_LEAST_QUNIT(pool_type);
+       if (pool_type == LQUOTA_RES_DT)
+               pool->qpi_soft_least_qunit = pool->qpi_least_qunit << 2;
+       else
+               pool->qpi_soft_least_qunit = pool->qpi_least_qunit;
 
        /* create pool proc directory */
        sprintf(qti->qti_buf, "%s-0x%x", RES_NAME(pool_type), pool_id);
-       pool->qpi_proc = lprocfs_seq_register(qti->qti_buf, qmt->qmt_proc,
-                                               lprocfs_quota_qpi_vars, pool);
+       pool->qpi_proc = lprocfs_register(qti->qti_buf, qmt->qmt_proc,
+                                         lprocfs_quota_qpi_vars, pool);
        if (IS_ERR(pool->qpi_proc)) {
                rc = PTR_ERR(pool->qpi_proc);
                CERROR("%s: failed to create proc entry for pool %s (%d)\n",
@@ -266,7 +315,7 @@ static void qmt_pool_free(const struct lu_env *env, struct qmt_pool_info *pool)
 
        /* release per-quota type site used to manage quota entries as well as
         * references to global index files */
-       for (qtype = 0; qtype < MAXQUOTAS; qtype++) {
+       for (qtype = 0; qtype < LL_MAXQUOTAS; qtype++) {
                /* release lqe storing grace time */
                if (pool->qpi_grace_lqe[qtype] != NULL)
                        lqe_putref(pool->qpi_grace_lqe[qtype]);
@@ -378,7 +427,7 @@ void qmt_pool_fini(const struct lu_env *env, struct qmt_device *qmt)
  * pool which are instantiated in this function.
  *
  * \param env - is the environment passed by the caller
- * \param qmt - is the quota master target for which we have to initializa the
+ * \param qmt - is the quota master target for which we have to initialize the
  *              pool configuration
  *
  * \retval - 0 on success, appropriate error on failure
@@ -437,7 +486,7 @@ static int qmt_slv_cnt(const struct lu_env *env, struct lu_fid *glb_fid,
  * Set up on-disk index files associated with each pool.
  *
  * \param env - is the environment passed by the caller
- * \param qmt - is the quota master target for which we have to initializa the
+ * \param qmt - is the quota master target for which we have to initialize the
  *              pool configuration
  * \param qmt_root - is the on-disk directory created for the QMT.
  *
@@ -480,7 +529,7 @@ int qmt_pool_prepare(const struct lu_env *env, struct qmt_device *qmt,
                        RETURN(PTR_ERR(obj));
                pool->qpi_root = obj;
 
-               for (qtype = 0; qtype < MAXQUOTAS; qtype++) {
+               for (qtype = 0; qtype < LL_MAXQUOTAS; qtype++) {
                        /* Generating FID of global index in charge of storing
                         * settings for this quota type */
                        lquota_generate_fid(&qti->qti_fid, pool_id, pool_type,
@@ -649,7 +698,7 @@ out:
  * Look-up a lquota_entry in the pool hash and allocate it if not found.
  *
  * \param env - is the environment passed by the caller
- * \param qmt - is the quota master target for which we have to initializa the
+ * \param qmt - is the quota master target for which we have to initialize the
  *              pool configuration
  * \param pool_id   - is the 16-bit identifier of the pool
  * \param pool_type - is the pool type, either LQUOTA_RES_MD or LQUOTA_RES_DT.