Whamcloud - gitweb
LU-6939 nrs: add lock to protect TBF rule linkage
[fs/lustre-release.git] / lustre / ptlrpc / nrs_tbf.c
index 2dedef3..7f92e10 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");
 
@@ -75,9 +73,7 @@ static enum hrtimer_restart nrs_tbf_timer_cb(struct hrtimer *timer)
        struct ptlrpc_nrs   *nrs = head->th_res.res_policy->pol_nrs;
        struct ptlrpc_service_part *svcpt = nrs->nrs_svcpt;
 
-       spin_lock(&nrs->nrs_lock);
        nrs->nrs_throttling = 0;
-       spin_unlock(&nrs->nrs_lock);
        wake_up(&svcpt->scp_waitq);
 
        return HRTIMER_NORESTART;
@@ -118,9 +114,11 @@ static inline void nrs_tbf_rule_get(struct nrs_tbf_rule *rule)
 static void
 nrs_tbf_cli_rule_put(struct nrs_tbf_client *cli)
 {
-       LASSERT(!cfs_list_empty(&cli->tc_linkage));
+       LASSERT(!list_empty(&cli->tc_linkage));
        LASSERT(cli->tc_rule);
-       cfs_list_del_init(&cli->tc_linkage);
+       spin_lock(&cli->tc_rule->tr_rule_lock);
+       list_del_init(&cli->tc_linkage);
+       spin_unlock(&cli->tc_rule->tr_rule_lock);
        nrs_tbf_rule_put(cli->tc_rule);
        cli->tc_rule = NULL;
 }
@@ -150,7 +148,8 @@ nrs_tbf_cli_reset(struct nrs_tbf_head *head,
                  struct nrs_tbf_rule *rule,
                  struct nrs_tbf_client *cli)
 {
-       if (!list_empty(&cli->tc_linkage)) {
+       spin_lock(&cli->tc_rule_lock);
+       if (cli->tc_rule != NULL && !list_empty(&cli->tc_linkage)) {
                LASSERT(rule != cli->tc_rule);
                nrs_tbf_cli_rule_put(cli);
        }
@@ -158,7 +157,10 @@ nrs_tbf_cli_reset(struct nrs_tbf_head *head,
        LASSERT(list_empty(&cli->tc_linkage));
        /* Rule's ref is added before called */
        cli->tc_rule = rule;
+       spin_lock(&rule->tr_rule_lock);
        list_add_tail(&cli->tc_linkage, &rule->tr_cli_list);
+       spin_unlock(&rule->tr_rule_lock);
+       spin_unlock(&cli->tc_rule_lock);
        nrs_tbf_cli_reset_value(head, cli);
 }
 
@@ -197,7 +199,7 @@ nrs_tbf_rule_find_nolock(struct nrs_tbf_head *head,
        struct nrs_tbf_rule *rule;
 
        LASSERT(head != NULL);
-       cfs_list_for_each_entry(rule, &head->th_list, tr_linkage) {
+       list_for_each_entry(rule, &head->th_list, tr_linkage) {
                LASSERT((rule->tr_flags & NTRS_STOPPING) == 0);
                if (strcmp(rule->tr_name, name) == 0) {
                        nrs_tbf_rule_get(rule);
@@ -229,7 +231,7 @@ nrs_tbf_rule_match(struct nrs_tbf_head *head,
 
        spin_lock(&head->th_rule_lock);
        /* Match the newest rule in the list */
-       cfs_list_for_each_entry(tmp_rule, &head->th_list, tr_linkage) {
+       list_for_each_entry(tmp_rule, &head->th_list, tr_linkage) {
                LASSERT((tmp_rule->tr_flags & NTRS_STOPPING) == 0);
                if (head->th_ops->o_rule_match(tmp_rule, cli)) {
                        rule = tmp_rule;
@@ -254,8 +256,9 @@ nrs_tbf_cli_init(struct nrs_tbf_head *head,
 
        cli->tc_in_heap = false;
        head->th_ops->o_cli_init(cli, req);
-       CFS_INIT_LIST_HEAD(&cli->tc_list);
-       CFS_INIT_LIST_HEAD(&cli->tc_linkage);
+       INIT_LIST_HEAD(&cli->tc_list);
+       INIT_LIST_HEAD(&cli->tc_linkage);
+       spin_lock_init(&cli->tc_rule_lock);
        atomic_set(&cli->tc_ref, 1);
        rule = nrs_tbf_rule_match(head, cli);
        nrs_tbf_cli_reset(head, rule, cli);
@@ -264,10 +267,12 @@ nrs_tbf_cli_init(struct nrs_tbf_head *head,
 static void
 nrs_tbf_cli_fini(struct nrs_tbf_client *cli)
 {
-       LASSERT(cfs_list_empty(&cli->tc_list));
+       LASSERT(list_empty(&cli->tc_list));
        LASSERT(!cli->tc_in_heap);
        LASSERT(atomic_read(&cli->tc_ref) == 0);
+       spin_lock(&cli->tc_rule_lock);
        nrs_tbf_cli_rule_put(cli);
+       spin_unlock(&cli->tc_rule_lock);
        OBD_FREE_PTR(cli);
 }
 
@@ -294,8 +299,11 @@ nrs_tbf_rule_start(struct ptlrpc_nrs_policy *policy,
        rule->tr_nsecs = NSEC_PER_SEC / rule->tr_rpc_rate;
        rule->tr_depth = tbf_depth;
        atomic_set(&rule->tr_ref, 1);
-       CFS_INIT_LIST_HEAD(&rule->tr_cli_list);
-       CFS_INIT_LIST_HEAD(&rule->tr_nids);
+       INIT_LIST_HEAD(&rule->tr_cli_list);
+       INIT_LIST_HEAD(&rule->tr_nids);
+       INIT_LIST_HEAD(&rule->tr_linkage);
+       spin_lock_init(&rule->tr_rule_lock);
+       rule->tr_head = head;
 
        rc = head->th_ops->o_rule_init(policy, rule, start);
        if (rc) {
@@ -307,12 +315,12 @@ nrs_tbf_rule_start(struct ptlrpc_nrs_policy *policy,
        spin_lock(&head->th_rule_lock);
        tmp_rule = nrs_tbf_rule_find_nolock(head, start->tc_name);
        if (tmp_rule) {
+               spin_unlock(&head->th_rule_lock);
                nrs_tbf_rule_put(tmp_rule);
                nrs_tbf_rule_put(rule);
                return -EEXIST;
        }
-       cfs_list_add(&rule->tr_linkage, &head->th_list);
-       rule->tr_head = head;
+       list_add(&rule->tr_linkage, &head->th_list);
        spin_unlock(&head->th_rule_lock);
        atomic_inc(&head->th_rule_sequence);
        if (start->tc_rule_flags & NTRS_DEFAULT) {
@@ -361,7 +369,7 @@ nrs_tbf_rule_stop(struct ptlrpc_nrs_policy *policy,
        if (rule == NULL)
                return -ENOENT;
 
-       cfs_list_del_init(&rule->tr_linkage);
+       list_del_init(&rule->tr_linkage);
        rule->tr_flags |= NTRS_STOPPING;
        nrs_tbf_rule_put(rule);
        nrs_tbf_rule_put(rule);
@@ -441,65 +449,66 @@ 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);
 }
 
-static int nrs_tbf_jobid_hop_keycmp(const void *key, cfs_hlist_node_t *hnode)
+static int nrs_tbf_jobid_hop_keycmp(const void *key, struct hlist_node *hnode)
 {
-       struct nrs_tbf_client *cli = cfs_hlist_entry(hnode,
+       struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
                                                     tc_hnode);
 
        return (strcmp(cli->tc_jobid, key) == 0);
 }
 
-static void *nrs_tbf_jobid_hop_key(cfs_hlist_node_t *hnode)
+static void *nrs_tbf_jobid_hop_key(struct hlist_node *hnode)
 {
-       struct nrs_tbf_client *cli = cfs_hlist_entry(hnode,
+       struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
                                                     tc_hnode);
 
        return cli->tc_jobid;
 }
 
-static void *nrs_tbf_jobid_hop_object(cfs_hlist_node_t *hnode)
+static void *nrs_tbf_jobid_hop_object(struct hlist_node *hnode)
 {
-       return cfs_hlist_entry(hnode, struct nrs_tbf_client, tc_hnode);
+       return hlist_entry(hnode, struct nrs_tbf_client, tc_hnode);
 }
 
-static void nrs_tbf_jobid_hop_get(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
+static void nrs_tbf_jobid_hop_get(struct cfs_hash *hs, struct hlist_node *hnode)
 {
-       struct nrs_tbf_client *cli = cfs_hlist_entry(hnode,
+       struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
                                                     tc_hnode);
 
        atomic_inc(&cli->tc_ref);
 }
 
-static void nrs_tbf_jobid_hop_put(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
+static void nrs_tbf_jobid_hop_put(struct cfs_hash *hs, struct hlist_node *hnode)
 {
-       struct nrs_tbf_client *cli = cfs_hlist_entry(hnode,
+       struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
                                                     tc_hnode);
 
        atomic_dec(&cli->tc_ref);
 }
 
-static void nrs_tbf_jobid_hop_exit(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
+static void
+nrs_tbf_jobid_hop_exit(struct cfs_hash *hs, struct hlist_node *hnode)
 
 {
-       struct nrs_tbf_client *cli = cfs_hlist_entry(hnode,
-                                                    struct nrs_tbf_client,
-                                                    tc_hnode);
+       struct nrs_tbf_client *cli = hlist_entry(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,
@@ -515,11 +524,11 @@ 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)
 {
-       cfs_hlist_node_t *hnode;
+       struct hlist_node *hnode;
        struct nrs_tbf_client *cli;
 
        /* cfs_hash_bd_peek_locked is a somehow "internal" function
@@ -530,8 +539,8 @@ nrs_tbf_jobid_hash_lookup(cfs_hash_t *hs,
 
        cfs_hash_get(hs, hnode);
        cli = container_of0(hnode, struct nrs_tbf_client, tc_hnode);
-       if (!cfs_list_empty(&cli->tc_lru))
-               cfs_list_del_init(&cli->tc_lru);
+       if (!list_empty(&cli->tc_lru))
+               list_del_init(&cli->tc_lru);
        return cli;
 }
 
@@ -543,8 +552,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)
@@ -562,8 +571,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);
@@ -581,18 +590,19 @@ 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;
-       CFS_LIST_HEAD            (zombies);
+       struct list_head        zombies;
 
+       INIT_LIST_HEAD(&zombies);
        cfs_hash_bd_get(hs, &cli->tc_jobid, &bd);
        bkt = cfs_hash_bd_extra_get(hs, &bd);
        if (!cfs_hash_bd_dec_and_lock(hs, &bd, &cli->tc_ref))
                return;
-       LASSERT(cfs_list_empty(&cli->tc_lru));
-       cfs_list_add_tail(&cli->tc_lru, &bkt->ntb_lru);
+       LASSERT(list_empty(&cli->tc_lru));
+       list_add_tail(&cli->tc_lru, &bkt->ntb_lru);
 
        /*
         * Check and purge the LRU, there is at least one client in the LRU.
@@ -600,21 +610,21 @@ nrs_tbf_jobid_cli_put(struct nrs_tbf_head *head,
        hw = tbf_jobid_cache_size >>
             (hs->hs_cur_bits - hs->hs_bkt_bits);
        while (cfs_hash_bd_count_get(&bd) > hw) {
-               if (unlikely(cfs_list_empty(&bkt->ntb_lru)))
+               if (unlikely(list_empty(&bkt->ntb_lru)))
                        break;
-               cli = cfs_list_entry(bkt->ntb_lru.next,
+               cli = list_entry(bkt->ntb_lru.next,
                                     struct nrs_tbf_client,
                                     tc_lru);
                LASSERT(atomic_read(&cli->tc_ref) == 0);
                cfs_hash_bd_del_locked(hs, &bd, &cli->tc_hnode);
-               cfs_list_move(&cli->tc_lru, &zombies);
+               list_move(&cli->tc_lru, &zombies);
        }
        cfs_hash_bd_unlock(head->th_cli_hash, &bd, 1);
 
-       while (!cfs_list_empty(&zombies)) {
+       while (!list_empty(&zombies)) {
                cli = container_of0(zombies.next,
                                    struct nrs_tbf_client, tc_lru);
-               cfs_list_del_init(&cli->tc_lru);
+               list_del_init(&cli->tc_lru);
                nrs_tbf_cli_fini(cli);
        }
 }
@@ -627,8 +637,8 @@ nrs_tbf_jobid_cli_init(struct nrs_tbf_client *cli,
 
        if (jobid == NULL)
                jobid = NRS_TBF_JOBID_NULL;
-       LASSERT(strlen(jobid) < JOBSTATS_JOBID_SIZE);
-       CFS_INIT_LIST_HEAD(&cli->tc_lru);
+       LASSERT(strlen(jobid) < LUSTRE_JOBID_SIZE);
+       INIT_LIST_HEAD(&cli->tc_lru);
        memcpy(cli->tc_jobid, jobid, strlen(jobid));
 }
 
@@ -653,7 +663,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)
@@ -672,7 +682,7 @@ nrs_tbf_jobid_startup(struct ptlrpc_nrs_policy *policy,
 
        cfs_hash_for_each_bucket(head->th_cli_hash, &bd, i) {
                bkt = cfs_hash_bd_extra_get(head->th_cli_hash, &bd);
-               CFS_INIT_LIST_HEAD(&bkt->ntb_lru);
+               INIT_LIST_HEAD(&bkt->ntb_lru);
        }
 
        memset(&start, 0, sizeof(start));
@@ -681,7 +691,7 @@ nrs_tbf_jobid_startup(struct ptlrpc_nrs_policy *policy,
        start.tc_rpc_rate = tbf_rate;
        start.tc_rule_flags = NTRS_DEFAULT;
        start.tc_name = NRS_TBF_DEFAULT_RULE;
-       CFS_INIT_LIST_HEAD(&start.tc_jobids);
+       INIT_LIST_HEAD(&start.tc_jobids);
        rc = nrs_tbf_rule_start(policy, head, &start);
 
        return rc;
@@ -692,19 +702,19 @@ nrs_tbf_jobid_startup(struct ptlrpc_nrs_policy *policy,
  *
  */
 static void
-nrs_tbf_jobid_list_free(cfs_list_t *jobid_list)
+nrs_tbf_jobid_list_free(struct list_head *jobid_list)
 {
        struct nrs_tbf_jobid *jobid, *n;
 
-       cfs_list_for_each_entry_safe(jobid, n, jobid_list, tj_linkage) {
+       list_for_each_entry_safe(jobid, n, jobid_list, tj_linkage) {
                OBD_FREE(jobid->tj_id, strlen(jobid->tj_id) + 1);
-               cfs_list_del(&jobid->tj_linkage);
+               list_del(&jobid->tj_linkage);
                OBD_FREE(jobid, sizeof(struct nrs_tbf_jobid));
        }
 }
 
 static int
-nrs_tbf_jobid_list_add(const struct cfs_lstr *id, cfs_list_t *jobid_list)
+nrs_tbf_jobid_list_add(const struct cfs_lstr *id, struct list_head *jobid_list)
 {
        struct nrs_tbf_jobid *jobid;
 
@@ -719,16 +729,16 @@ nrs_tbf_jobid_list_add(const struct cfs_lstr *id, cfs_list_t *jobid_list)
        }
 
        memcpy(jobid->tj_id, id->ls_str, id->ls_len);
-       cfs_list_add_tail(&jobid->tj_linkage, jobid_list);
+       list_add_tail(&jobid->tj_linkage, jobid_list);
        return 0;
 }
 
 static int
-nrs_tbf_jobid_list_match(cfs_list_t *jobid_list, char *id)
+nrs_tbf_jobid_list_match(struct list_head *jobid_list, char *id)
 {
        struct nrs_tbf_jobid *jobid;
 
-       cfs_list_for_each_entry(jobid, jobid_list, tj_linkage) {
+       list_for_each_entry(jobid, jobid_list, tj_linkage) {
                if (strcmp(id, jobid->tj_id) == 0)
                        return 1;
        }
@@ -736,7 +746,7 @@ nrs_tbf_jobid_list_match(cfs_list_t *jobid_list, char *id)
 }
 
 static int
-nrs_tbf_jobid_list_parse(char *str, int len, cfs_list_t *jobid_list)
+nrs_tbf_jobid_list_parse(char *str, int len, struct list_head *jobid_list)
 {
        struct cfs_lstr src;
        struct cfs_lstr res;
@@ -745,7 +755,7 @@ nrs_tbf_jobid_list_parse(char *str, int len, cfs_list_t *jobid_list)
 
        src.ls_str = str;
        src.ls_len = len;
-       CFS_INIT_LIST_HEAD(jobid_list);
+       INIT_LIST_HEAD(jobid_list);
        while (src.ls_str) {
                rc = cfs_gettok(&src, ' ', &res);
                if (rc == 0) {
@@ -763,7 +773,7 @@ nrs_tbf_jobid_list_parse(char *str, int len, cfs_list_t *jobid_list)
 
 static void nrs_tbf_jobid_cmd_fini(struct nrs_tbf_cmd *cmd)
 {
-       if (!cfs_list_empty(&cmd->tc_jobids))
+       if (!list_empty(&cmd->tc_jobids))
                nrs_tbf_jobid_list_free(&cmd->tc_jobids);
        if (cmd->tc_jobids_str)
                OBD_FREE(cmd->tc_jobids_str, strlen(cmd->tc_jobids_str) + 1);
@@ -805,8 +815,8 @@ static int nrs_tbf_jobid_rule_init(struct ptlrpc_nrs_policy *policy,
               start->tc_jobids_str,
               strlen(start->tc_jobids_str));
 
-       CFS_INIT_LIST_HEAD(&rule->tr_jobids);
-       if (!cfs_list_empty(&start->tc_jobids)) {
+       INIT_LIST_HEAD(&rule->tr_jobids);
+       if (!list_empty(&start->tc_jobids)) {
                rc = nrs_tbf_jobid_list_parse(rule->tr_jobids_str,
                                              strlen(rule->tr_jobids_str),
                                              &rule->tr_jobids);
@@ -836,13 +846,13 @@ nrs_tbf_jobid_rule_match(struct nrs_tbf_rule *rule,
 
 static void nrs_tbf_jobid_rule_fini(struct nrs_tbf_rule *rule)
 {
-       if (!cfs_list_empty(&rule->tr_jobids))
+       if (!list_empty(&rule->tr_jobids))
                nrs_tbf_jobid_list_free(&rule->tr_jobids);
        LASSERT(rule->tr_jobids_str != NULL);
        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,
@@ -864,57 +874,57 @@ 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);
 }
 
-static int nrs_tbf_nid_hop_keycmp(const void *key, cfs_hlist_node_t *hnode)
+static int nrs_tbf_nid_hop_keycmp(const void *key, struct hlist_node *hnode)
 {
        lnet_nid_t            *nid = (lnet_nid_t *)key;
-       struct nrs_tbf_client *cli = cfs_hlist_entry(hnode,
+       struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
                                                     tc_hnode);
 
        return *nid == cli->tc_nid;
 }
 
-static void *nrs_tbf_nid_hop_key(cfs_hlist_node_t *hnode)
+static void *nrs_tbf_nid_hop_key(struct hlist_node *hnode)
 {
-       struct nrs_tbf_client *cli = cfs_hlist_entry(hnode,
+       struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
                                                     tc_hnode);
 
        return &cli->tc_nid;
 }
 
-static void *nrs_tbf_nid_hop_object(cfs_hlist_node_t *hnode)
+static void *nrs_tbf_nid_hop_object(struct hlist_node *hnode)
 {
-       return cfs_hlist_entry(hnode, struct nrs_tbf_client, tc_hnode);
+       return hlist_entry(hnode, struct nrs_tbf_client, tc_hnode);
 }
 
-static void nrs_tbf_nid_hop_get(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
+static void nrs_tbf_nid_hop_get(struct cfs_hash *hs, struct hlist_node *hnode)
 {
-       struct nrs_tbf_client *cli = cfs_hlist_entry(hnode,
+       struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
                                                     tc_hnode);
 
        atomic_inc(&cli->tc_ref);
 }
 
-static void nrs_tbf_nid_hop_put(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
+static void nrs_tbf_nid_hop_put(struct cfs_hash *hs, struct hlist_node *hnode)
 {
-       struct nrs_tbf_client *cli = cfs_hlist_entry(hnode,
+       struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
                                                     tc_hnode);
 
        atomic_dec(&cli->tc_ref);
 }
 
-static void nrs_tbf_nid_hop_exit(cfs_hash_t *hs, cfs_hlist_node_t *hnode)
+static void nrs_tbf_nid_hop_exit(struct cfs_hash *hs, struct hlist_node *hnode)
 {
-       struct nrs_tbf_client *cli = cfs_hlist_entry(hnode,
+       struct nrs_tbf_client *cli = hlist_entry(hnode,
                                                     struct nrs_tbf_client,
                                                     tc_hnode);
 
@@ -925,7 +935,7 @@ static void nrs_tbf_nid_hop_exit(cfs_hash_t *hs, cfs_hlist_node_t *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,
@@ -982,7 +992,7 @@ nrs_tbf_nid_startup(struct ptlrpc_nrs_policy *policy,
        start.tc_rpc_rate = tbf_rate;
        start.tc_rule_flags = NTRS_DEFAULT;
        start.tc_name = NRS_TBF_DEFAULT_RULE;
-       CFS_INIT_LIST_HEAD(&start.tc_nids);
+       INIT_LIST_HEAD(&start.tc_nids);
        rc = nrs_tbf_rule_start(policy, head, &start);
 
        return rc;
@@ -1009,8 +1019,8 @@ static int nrs_tbf_nid_rule_init(struct ptlrpc_nrs_policy *policy,
               start->tc_nids_str,
               strlen(start->tc_nids_str));
 
-       CFS_INIT_LIST_HEAD(&rule->tr_nids);
-       if (!cfs_list_empty(&start->tc_nids)) {
+       INIT_LIST_HEAD(&rule->tr_nids);
+       if (!list_empty(&start->tc_nids)) {
                if (cfs_parse_nidlist(rule->tr_nids_str,
                                      strlen(rule->tr_nids_str),
                                      &rule->tr_nids) <= 0) {
@@ -1041,7 +1051,7 @@ nrs_tbf_nid_rule_match(struct nrs_tbf_rule *rule,
 
 static void nrs_tbf_nid_rule_fini(struct nrs_tbf_rule *rule)
 {
-       if (!cfs_list_empty(&rule->tr_nids))
+       if (!list_empty(&rule->tr_nids))
                cfs_free_nidlist(&rule->tr_nids);
        LASSERT(rule->tr_nids_str != NULL);
        OBD_FREE(rule->tr_nids_str, strlen(rule->tr_nids_str) + 1);
@@ -1049,7 +1059,7 @@ static void nrs_tbf_nid_rule_fini(struct nrs_tbf_rule *rule)
 
 static void nrs_tbf_nid_cmd_fini(struct nrs_tbf_cmd *cmd)
 {
-       if (!cfs_list_empty(&cmd->tc_nids))
+       if (!list_empty(&cmd->tc_nids))
                cfs_free_nidlist(&cmd->tc_nids);
        if (cmd->tc_nids_str)
                OBD_FREE(cmd->tc_nids_str, strlen(cmd->tc_nids_str) + 1);
@@ -1074,7 +1084,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,
@@ -1137,7 +1147,7 @@ static int nrs_tbf_start(struct ptlrpc_nrs_policy *policy, char *arg)
 
        atomic_set(&head->th_rule_sequence, 0);
        spin_lock_init(&head->th_rule_lock);
-       CFS_INIT_LIST_HEAD(&head->th_list);
+       INIT_LIST_HEAD(&head->th_list);
        hrtimer_init(&head->th_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
        head->th_timer.function = nrs_tbf_timer_cb;
        rc = head->th_ops->o_startup(policy, head);
@@ -1174,18 +1184,16 @@ static void nrs_tbf_stop(struct ptlrpc_nrs_policy *policy)
        hrtimer_cancel(&head->th_timer);
        /* Should cleanup hash first before free rules */
        cfs_hash_putref(head->th_cli_hash);
-       cfs_list_for_each_entry_safe(rule, n, &head->th_list, tr_linkage) {
-               cfs_list_del_init(&rule->tr_linkage);
+       list_for_each_entry_safe(rule, n, &head->th_list, tr_linkage) {
+               list_del_init(&rule->tr_linkage);
                nrs_tbf_rule_put(rule);
        }
-       LASSERT(cfs_list_empty(&head->th_list));
+       LASSERT(list_empty(&head->th_list));
        LASSERT(head->th_binheap != NULL);
        LASSERT(cfs_binheap_is_empty(head->th_binheap));
        cfs_binheap_destroy(head->th_binheap);
        OBD_FREE_PTR(head);
-       spin_lock(&nrs->nrs_lock);
        nrs->nrs_throttling = 0;
-       spin_unlock(&nrs->nrs_lock);
        wake_up(&policy->pol_nrs->nrs_svcpt->scp_waitq);
 }
 
@@ -1203,8 +1211,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;
@@ -1381,7 +1390,7 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
        cli = container_of(node, struct nrs_tbf_client, tc_node);
        LASSERT(cli->tc_in_heap);
        if (peek) {
-               nrq = cfs_list_entry(cli->tc_list.next,
+               nrq = list_entry(cli->tc_list.next,
                                     struct ptlrpc_nrs_request,
                                     nr_u.tbf.tr_list);
        } else {
@@ -1400,7 +1409,7 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
                        ntoken = cli->tc_depth;
                if (ntoken > 0) {
                        struct ptlrpc_request *req;
-                       nrq = cfs_list_entry(cli->tc_list.next,
+                       nrq = list_entry(cli->tc_list.next,
                                             struct ptlrpc_nrs_request,
                                             nr_u.tbf.tr_list);
                        req = container_of(nrq,
@@ -1409,8 +1418,8 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
                        ntoken--;
                        cli->tc_ntoken = ntoken;
                        cli->tc_check_time = now;
-                       cfs_list_del_init(&nrq->nr_u.tbf.tr_list);
-                       if (cfs_list_empty(&cli->tc_list)) {
+                       list_del_init(&nrq->nr_u.tbf.tr_list);
+                       if (list_empty(&cli->tc_list)) {
                                cfs_binheap_remove(head->th_binheap,
                                                   &cli->tc_node);
                                cli->tc_in_heap = false;
@@ -1427,9 +1436,7 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
                } else {
                        ktime_t time;
 
-                       spin_lock(&policy->pol_nrs->nrs_lock);
                        policy->pol_nrs->nrs_throttling = 1;
-                       spin_unlock(&policy->pol_nrs->nrs_lock);
                        head->th_deadline = deadline;
                        time = ktime_set(0, 0);
                        time = ktime_add_ns(time, deadline);
@@ -1462,13 +1469,13 @@ static int nrs_tbf_req_add(struct ptlrpc_nrs_policy *policy,
                           struct nrs_tbf_client, tc_res);
        head = container_of(nrs_request_resource(nrq)->res_parent,
                            struct nrs_tbf_head, th_res);
-       if (cfs_list_empty(&cli->tc_list)) {
+       if (list_empty(&cli->tc_list)) {
                LASSERT(!cli->tc_in_heap);
                rc = cfs_binheap_insert(head->th_binheap, &cli->tc_node);
                if (rc == 0) {
                        cli->tc_in_heap = true;
                        nrq->nr_u.tbf.tr_sequence = head->th_sequence++;
-                       cfs_list_add_tail(&nrq->nr_u.tbf.tr_list,
+                       list_add_tail(&nrq->nr_u.tbf.tr_list,
                                          &cli->tc_list);
                        if (policy->pol_nrs->nrs_throttling) {
                                __u64 deadline = cli->tc_check_time +
@@ -1488,7 +1495,7 @@ static int nrs_tbf_req_add(struct ptlrpc_nrs_policy *policy,
        } else {
                LASSERT(cli->tc_in_heap);
                nrq->nr_u.tbf.tr_sequence = head->th_sequence++;
-               cfs_list_add_tail(&nrq->nr_u.tbf.tr_list,
+               list_add_tail(&nrq->nr_u.tbf.tr_list,
                                  &cli->tc_list);
        }
        return rc;
@@ -1513,9 +1520,9 @@ static void nrs_tbf_req_del(struct ptlrpc_nrs_policy *policy,
        head = container_of(nrs_request_resource(nrq)->res_parent,
                            struct nrs_tbf_head, th_res);
 
-       LASSERT(!cfs_list_empty(&nrq->nr_u.tbf.tr_list));
-       cfs_list_del_init(&nrq->nr_u.tbf.tr_list);
-       if (cfs_list_empty(&cli->tc_list)) {
+       LASSERT(!list_empty(&nrq->nr_u.tbf.tr_list));
+       list_del_init(&nrq->nr_u.tbf.tr_list);
+       if (list_empty(&cli->tc_list)) {
                cfs_binheap_remove(head->th_binheap,
                                   &cli->tc_node);
                cli->tc_in_heap = false;
@@ -1548,7 +1555,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
@@ -1577,6 +1584,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.
                 */
@@ -1594,11 +1609,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:
@@ -1737,7 +1753,8 @@ out:
 extern struct nrs_core nrs_core;
 #define LPROCFS_WR_NRS_TBF_MAX_CMD (4096)
 static ssize_t
-ptlrpc_lprocfs_nrs_tbf_rule_seq_write(struct file *file, const char *buffer,
+ptlrpc_lprocfs_nrs_tbf_rule_seq_write(struct file *file,
+                                     const char __user *buffer,
                                      size_t count, loff_t *off)
 {
        struct seq_file           *m = file->private_data;
@@ -1815,9 +1832,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 },
@@ -1827,8 +1844,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);
 }
 
 /**
@@ -1836,7 +1852,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;
@@ -1844,7 +1860,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
@@ -1859,7 +1875,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