Whamcloud - gitweb
LU-6943 clio: get rid of cl_req
[fs/lustre-release.git] / lustre / ptlrpc / nrs_tbf.c
index 50ddbf4..7fb0f4e 100644 (file)
@@ -22,6 +22,7 @@
 /*
  * Copyright (C) 2013 DataDirect Networks, Inc.
  *
+ * Copyright (c) 2014, Intel Corporation.
  */
 /*
  * lustre/ptlrpc/nrs_tbf.c
@@ -38,9 +39,6 @@
  */
 
 #define DEBUG_SUBSYSTEM S_RPC
-#ifndef __KERNEL__
-#include <liblustre.h>
-#endif
 #include <obd_support.h>
 #include <obd_class.h>
 #include <libcfs/libcfs.h>
 
 #define NRS_POL_NAME_TBF       "tbf"
 
-int tbf_jobid_cache_size = 8192;
+static int tbf_jobid_cache_size = 8192;
 CFS_MODULE_PARM(tbf_jobid_cache_size, "i", int, 0644,
                "The size of jobid cache");
 
-int tbf_rate = 10000;
+static int tbf_rate = 10000;
 CFS_MODULE_PARM(tbf_rate, "i", int, 0644,
                "Default rate limit in RPCs/s");
 
-int tbf_depth = 3;
+static int tbf_depth = 3;
 CFS_MODULE_PARM(tbf_depth, "i", int, 0644,
                "How many tokens that a client can save up");
 
@@ -442,7 +440,7 @@ static cfs_binheap_ops_t nrs_tbf_heap_ops = {
        .hop_compare    = tbf_cli_compare,
 };
 
-static unsigned nrs_tbf_jobid_hop_hash(cfs_hash_t *hs, const void *key,
+static unsigned nrs_tbf_jobid_hop_hash(struct cfs_hash *hs, const void *key,
                                  unsigned mask)
 {
        return cfs_hash_djb2_hash(key, strlen(key), mask);
@@ -471,7 +469,7 @@ static void *nrs_tbf_jobid_hop_object(struct hlist_node *hnode)
        return hlist_entry(hnode, struct nrs_tbf_client, tc_hnode);
 }
 
-static void nrs_tbf_jobid_hop_get(cfs_hash_t *hs, struct hlist_node *hnode)
+static void nrs_tbf_jobid_hop_get(struct cfs_hash *hs, struct hlist_node *hnode)
 {
        struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
@@ -480,7 +478,7 @@ static void nrs_tbf_jobid_hop_get(cfs_hash_t *hs, struct hlist_node *hnode)
        atomic_inc(&cli->tc_ref);
 }
 
-static void nrs_tbf_jobid_hop_put(cfs_hash_t *hs, struct hlist_node *hnode)
+static void nrs_tbf_jobid_hop_put(struct cfs_hash *hs, struct hlist_node *hnode)
 {
        struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
@@ -489,18 +487,19 @@ static void nrs_tbf_jobid_hop_put(cfs_hash_t *hs, struct hlist_node *hnode)
        atomic_dec(&cli->tc_ref);
 }
 
-static void nrs_tbf_jobid_hop_exit(cfs_hash_t *hs, struct hlist_node *hnode)
+static void
+nrs_tbf_jobid_hop_exit(struct cfs_hash *hs, struct hlist_node *hnode)
 
 {
        struct nrs_tbf_client *cli = hlist_entry(hnode,
-                                                    struct nrs_tbf_client,
-                                                    tc_hnode);
+                                                struct nrs_tbf_client,
+                                                tc_hnode);
 
        LASSERT(atomic_read(&cli->tc_ref) == 0);
        nrs_tbf_cli_fini(cli);
 }
 
-static cfs_hash_ops_t nrs_tbf_jobid_hash_ops = {
+static struct cfs_hash_ops nrs_tbf_jobid_hash_ops = {
        .hs_hash        = nrs_tbf_jobid_hop_hash,
        .hs_keycmp      = nrs_tbf_jobid_hop_keycmp,
        .hs_key         = nrs_tbf_jobid_hop_key,
@@ -516,8 +515,8 @@ static cfs_hash_ops_t nrs_tbf_jobid_hash_ops = {
                                  CFS_HASH_DEPTH)
 
 static struct nrs_tbf_client *
-nrs_tbf_jobid_hash_lookup(cfs_hash_t *hs,
-                         cfs_hash_bd_t *bd,
+nrs_tbf_jobid_hash_lookup(struct cfs_hash *hs,
+                         struct cfs_hash_bd *bd,
                          const char *jobid)
 {
        struct hlist_node *hnode;
@@ -544,8 +543,8 @@ nrs_tbf_jobid_cli_find(struct nrs_tbf_head *head,
 {
        const char              *jobid;
        struct nrs_tbf_client   *cli;
-       cfs_hash_t              *hs = head->th_cli_hash;
-       cfs_hash_bd_t            bd;
+       struct cfs_hash         *hs = head->th_cli_hash;
+       struct cfs_hash_bd               bd;
 
        jobid = lustre_msg_get_jobid(req->rq_reqmsg);
        if (jobid == NULL)
@@ -563,8 +562,8 @@ nrs_tbf_jobid_cli_findadd(struct nrs_tbf_head *head,
 {
        const char              *jobid;
        struct nrs_tbf_client   *ret;
-       cfs_hash_t              *hs = head->th_cli_hash;
-       cfs_hash_bd_t            bd;
+       struct cfs_hash         *hs = head->th_cli_hash;
+       struct cfs_hash_bd               bd;
 
        jobid = cli->tc_jobid;
        cfs_hash_bd_get_and_lock(hs, (void *)jobid, &bd, 1);
@@ -582,8 +581,8 @@ static void
 nrs_tbf_jobid_cli_put(struct nrs_tbf_head *head,
                      struct nrs_tbf_client *cli)
 {
-       cfs_hash_bd_t            bd;
-       cfs_hash_t              *hs = head->th_cli_hash;
+       struct cfs_hash_bd               bd;
+       struct cfs_hash         *hs = head->th_cli_hash;
        struct nrs_tbf_bucket   *bkt;
        int                      hw;
        struct list_head        zombies;
@@ -629,7 +628,7 @@ nrs_tbf_jobid_cli_init(struct nrs_tbf_client *cli,
 
        if (jobid == NULL)
                jobid = NRS_TBF_JOBID_NULL;
-       LASSERT(strlen(jobid) < JOBSTATS_JOBID_SIZE);
+       LASSERT(strlen(jobid) < LUSTRE_JOBID_SIZE);
        INIT_LIST_HEAD(&cli->tc_lru);
        memcpy(cli->tc_jobid, jobid, strlen(jobid));
 }
@@ -655,7 +654,7 @@ nrs_tbf_jobid_startup(struct ptlrpc_nrs_policy *policy,
        int                      bits;
        int                      i;
        int                      rc;
-       cfs_hash_bd_t            bd;
+       struct cfs_hash_bd       bd;
 
        bits = nrs_tbf_jobid_hash_order();
        if (bits < NRS_TBF_JOBID_BKT_BITS)
@@ -844,7 +843,7 @@ static void nrs_tbf_jobid_rule_fini(struct nrs_tbf_rule *rule)
        OBD_FREE(rule->tr_jobids_str, strlen(rule->tr_jobids_str) + 1);
 }
 
-struct nrs_tbf_ops nrs_tbf_jobid_ops = {
+static struct nrs_tbf_ops nrs_tbf_jobid_ops = {
        .o_name = NRS_TBF_TYPE_JOBID,
        .o_startup = nrs_tbf_jobid_startup,
        .o_cli_find = nrs_tbf_jobid_cli_find,
@@ -866,7 +865,7 @@ struct nrs_tbf_ops nrs_tbf_jobid_ops = {
 #define NRS_TBF_NID_BKT_BITS    8
 #define NRS_TBF_NID_BITS        16
 
-static unsigned nrs_tbf_nid_hop_hash(cfs_hash_t *hs, const void *key,
+static unsigned nrs_tbf_nid_hop_hash(struct cfs_hash *hs, const void *key,
                                  unsigned mask)
 {
        return cfs_hash_djb2_hash(key, sizeof(lnet_nid_t), mask);
@@ -896,7 +895,7 @@ static void *nrs_tbf_nid_hop_object(struct hlist_node *hnode)
        return hlist_entry(hnode, struct nrs_tbf_client, tc_hnode);
 }
 
-static void nrs_tbf_nid_hop_get(cfs_hash_t *hs, struct hlist_node *hnode)
+static void nrs_tbf_nid_hop_get(struct cfs_hash *hs, struct hlist_node *hnode)
 {
        struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
@@ -905,7 +904,7 @@ static void nrs_tbf_nid_hop_get(cfs_hash_t *hs, struct hlist_node *hnode)
        atomic_inc(&cli->tc_ref);
 }
 
-static void nrs_tbf_nid_hop_put(cfs_hash_t *hs, struct hlist_node *hnode)
+static void nrs_tbf_nid_hop_put(struct cfs_hash *hs, struct hlist_node *hnode)
 {
        struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
@@ -914,7 +913,7 @@ static void nrs_tbf_nid_hop_put(cfs_hash_t *hs, struct hlist_node *hnode)
        atomic_dec(&cli->tc_ref);
 }
 
-static void nrs_tbf_nid_hop_exit(cfs_hash_t *hs, struct hlist_node *hnode)
+static void nrs_tbf_nid_hop_exit(struct cfs_hash *hs, struct hlist_node *hnode)
 {
        struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
@@ -927,7 +926,7 @@ static void nrs_tbf_nid_hop_exit(cfs_hash_t *hs, struct hlist_node *hnode)
        nrs_tbf_cli_fini(cli);
 }
 
-static cfs_hash_ops_t nrs_tbf_nid_hash_ops = {
+static struct cfs_hash_ops nrs_tbf_nid_hash_ops = {
        .hs_hash        = nrs_tbf_nid_hop_hash,
        .hs_keycmp      = nrs_tbf_nid_hop_keycmp,
        .hs_key         = nrs_tbf_nid_hop_key,
@@ -1076,7 +1075,7 @@ static int nrs_tbf_nid_parse(struct nrs_tbf_cmd *cmd, const char *id)
        return 0;
 }
 
-struct nrs_tbf_ops nrs_tbf_nid_ops = {
+static struct nrs_tbf_ops nrs_tbf_nid_ops = {
        .o_name = NRS_TBF_TYPE_NID,
        .o_startup = nrs_tbf_nid_startup,
        .o_cli_find = nrs_tbf_nid_cli_find,
@@ -1205,8 +1204,9 @@ static void nrs_tbf_stop(struct ptlrpc_nrs_policy *policy)
  * \retval 0   operation carried out successfully
  * \retval -ve error
  */
-int nrs_tbf_ctl(struct ptlrpc_nrs_policy *policy, enum ptlrpc_nrs_ctl opc,
-               void *arg)
+static int nrs_tbf_ctl(struct ptlrpc_nrs_policy *policy,
+                      enum ptlrpc_nrs_ctl opc,
+                      void *arg)
 {
        int rc = 0;
        ENTRY;
@@ -1550,7 +1550,7 @@ static void nrs_tbf_req_stop(struct ptlrpc_nrs_policy *policy,
               nrq->nr_u.tbf.tr_sequence);
 }
 
-#ifdef LPROCFS
+#ifdef CONFIG_PROC_FS
 
 /**
  * lprocfs interface
@@ -1579,6 +1579,14 @@ ptlrpc_lprocfs_nrs_tbf_rule_seq_show(struct seq_file *m, void *data)
                                       false, m);
        if (rc == 0) {
                /**
+                * -ENOSPC means buf in the parameter m is overflow, return 0
+                * here to let upper layer function seq_read alloc a larger
+                * memory area and do this process again.
+                */
+       } else if (rc == -ENOSPC) {
+               return 0;
+
+               /**
                 * Ignore -ENODEV as the regular NRS head's policy may be in the
                 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state.
                 */
@@ -1596,11 +1604,12 @@ ptlrpc_lprocfs_nrs_tbf_rule_seq_show(struct seq_file *m, void *data)
                                       false, m);
        if (rc == 0) {
                /**
-                * Ignore -ENODEV as the high priority NRS head's policy may be
-                * in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state.
+                * -ENOSPC means buf in the parameter m is overflow, return 0
+                * here to let upper layer function seq_read alloc a larger
+                * memory area and do this process again.
                 */
-       } else if (rc != -ENODEV) {
-               return rc;
+       } else if (rc == -ENOSPC) {
+               return 0;
        }
 
 no_hp:
@@ -1817,9 +1826,9 @@ LPROC_SEQ_FOPS(ptlrpc_lprocfs_nrs_tbf_rule);
  * \retval 0   success
  * \retval != 0        error
  */
-int nrs_tbf_lprocfs_init(struct ptlrpc_service *svc)
+static int nrs_tbf_lprocfs_init(struct ptlrpc_service *svc)
 {
-       struct lprocfs_seq_vars nrs_tbf_lprocfs_vars[] = {
+       struct lprocfs_vars nrs_tbf_lprocfs_vars[] = {
                { .name         = "nrs_tbf_rule",
                  .fops         = &ptlrpc_lprocfs_nrs_tbf_rule_fops,
                  .data = svc },
@@ -1829,8 +1838,7 @@ int nrs_tbf_lprocfs_init(struct ptlrpc_service *svc)
        if (svc->srv_procroot == NULL)
                return 0;
 
-       return lprocfs_seq_add_vars(svc->srv_procroot, nrs_tbf_lprocfs_vars,
-                                   NULL);
+       return lprocfs_add_vars(svc->srv_procroot, nrs_tbf_lprocfs_vars, NULL);
 }
 
 /**
@@ -1838,7 +1846,7 @@ int nrs_tbf_lprocfs_init(struct ptlrpc_service *svc)
  *
  * \param[in] svc the service
  */
-void nrs_tbf_lprocfs_fini(struct ptlrpc_service *svc)
+static void nrs_tbf_lprocfs_fini(struct ptlrpc_service *svc)
 {
        if (svc->srv_procroot == NULL)
                return;
@@ -1846,7 +1854,7 @@ void nrs_tbf_lprocfs_fini(struct ptlrpc_service *svc)
        lprocfs_remove_proc_entry("nrs_tbf_rule", svc->srv_procroot);
 }
 
-#endif /* LPROCFS */
+#endif /* CONFIG_PROC_FS */
 
 /**
  * TBF policy operations
@@ -1861,7 +1869,7 @@ static const struct ptlrpc_nrs_pol_ops nrs_tbf_ops = {
        .op_req_enqueue         = nrs_tbf_req_add,
        .op_req_dequeue         = nrs_tbf_req_del,
        .op_req_stop            = nrs_tbf_req_stop,
-#ifdef LPROCFS
+#ifdef CONFIG_PROC_FS
        .op_lprocfs_init        = nrs_tbf_lprocfs_init,
        .op_lprocfs_fini        = nrs_tbf_lprocfs_fini,
 #endif