X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fptlrpc%2Fnrs_tbf.c;h=af7d696d0f28fc5ea480dcbe577d4cabfc446c59;hb=0ad4f8a4227ed7dd93fec99d33c6bb25056473fc;hp=5d37c527dff0b292c806cd8cf9b6e6550aa22be4;hpb=004095a99b472b13984eabca412b9c1fc002fb81;p=fs%2Flustre-release.git diff --git a/lustre/ptlrpc/nrs_tbf.c b/lustre/ptlrpc/nrs_tbf.c index 5d37c52..af7d696 100644 --- a/lustre/ptlrpc/nrs_tbf.c +++ b/lustre/ptlrpc/nrs_tbf.c @@ -38,9 +38,6 @@ */ #define DEBUG_SUBSYSTEM S_RPC -#ifndef __KERNEL__ -#include -#endif #include #include #include @@ -87,9 +84,9 @@ static enum hrtimer_restart nrs_tbf_timer_cb(struct hrtimer *timer) static void nrs_tbf_rule_fini(struct nrs_tbf_rule *rule) { - LASSERT(cfs_atomic_read(&rule->tr_ref) == 0); - LASSERT(cfs_list_empty(&rule->tr_cli_list)); - LASSERT(cfs_list_empty(&rule->tr_linkage)); + LASSERT(atomic_read(&rule->tr_ref) == 0); + LASSERT(list_empty(&rule->tr_cli_list)); + LASSERT(list_empty(&rule->tr_linkage)); rule->tr_head->th_ops->o_rule_fini(rule); OBD_FREE_PTR(rule); @@ -103,7 +100,7 @@ static void nrs_tbf_rule_fini(struct nrs_tbf_rule *rule) */ static void nrs_tbf_rule_put(struct nrs_tbf_rule *rule) { - if (cfs_atomic_dec_and_test(&rule->tr_ref)) + if (atomic_dec_and_test(&rule->tr_ref)) nrs_tbf_rule_fini(rule); } @@ -112,15 +109,15 @@ static void nrs_tbf_rule_put(struct nrs_tbf_rule *rule) */ static inline void nrs_tbf_rule_get(struct nrs_tbf_rule *rule) { - cfs_atomic_inc(&rule->tr_ref); + atomic_inc(&rule->tr_ref); } 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); + list_del_init(&cli->tc_linkage); nrs_tbf_rule_put(cli->tc_rule); cli->tc_rule = NULL; } @@ -137,7 +134,7 @@ nrs_tbf_cli_reset_value(struct nrs_tbf_head *head, cli->tc_depth = rule->tr_depth; cli->tc_ntoken = rule->tr_depth; cli->tc_check_time = ktime_to_ns(ktime_get()); - cli->tc_rule_sequence = cfs_atomic_read(&head->th_rule_sequence); + cli->tc_rule_sequence = atomic_read(&head->th_rule_sequence); cli->tc_rule_generation = rule->tr_generation; if (cli->tc_in_heap) @@ -150,26 +147,26 @@ nrs_tbf_cli_reset(struct nrs_tbf_head *head, struct nrs_tbf_rule *rule, struct nrs_tbf_client *cli) { - if (!cfs_list_empty(&cli->tc_linkage)) { + if (!list_empty(&cli->tc_linkage)) { LASSERT(rule != cli->tc_rule); nrs_tbf_cli_rule_put(cli); } LASSERT(cli->tc_rule == NULL); - LASSERT(cfs_list_empty(&cli->tc_linkage)); + LASSERT(list_empty(&cli->tc_linkage)); /* Rule's ref is added before called */ cli->tc_rule = rule; - cfs_list_add_tail(&cli->tc_linkage, &rule->tr_cli_list); + list_add_tail(&cli->tc_linkage, &rule->tr_cli_list); nrs_tbf_cli_reset_value(head, cli); } static int -nrs_tbf_rule_dump(struct nrs_tbf_rule *rule, char *buff, int length) +nrs_tbf_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m) { - return rule->tr_head->th_ops->o_rule_dump(rule, buff, length); + return rule->tr_head->th_ops->o_rule_dump(rule, m); } static int -nrs_tbf_rule_dump_all(struct nrs_tbf_head *head, char *buff, int length) +nrs_tbf_rule_dump_all(struct nrs_tbf_head *head, struct seq_file *m) { struct nrs_tbf_rule *rule; int rc = 0; @@ -177,9 +174,13 @@ nrs_tbf_rule_dump_all(struct nrs_tbf_head *head, char *buff, int length) LASSERT(head != NULL); spin_lock(&head->th_rule_lock); /* List the rules from newest to oldest */ - 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); - rc += nrs_tbf_rule_dump(rule, buff + rc, length - rc); + rc = nrs_tbf_rule_dump(rule, m); + if (rc) { + rc = -ENOSPC; + break; + } } spin_unlock(&head->th_rule_lock); @@ -193,7 +194,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); @@ -225,7 +226,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; @@ -250,9 +251,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); - cfs_atomic_set(&cli->tc_ref, 1); + INIT_LIST_HEAD(&cli->tc_list); + INIT_LIST_HEAD(&cli->tc_linkage); + atomic_set(&cli->tc_ref, 1); rule = nrs_tbf_rule_match(head, cli); nrs_tbf_cli_reset(head, rule, cli); } @@ -260,9 +261,9 @@ 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(cfs_atomic_read(&cli->tc_ref) == 0); + LASSERT(atomic_read(&cli->tc_ref) == 0); nrs_tbf_cli_rule_put(cli); OBD_FREE_PTR(cli); } @@ -289,9 +290,9 @@ nrs_tbf_rule_start(struct ptlrpc_nrs_policy *policy, rule->tr_rpc_rate = start->tc_rpc_rate; rule->tr_nsecs = NSEC_PER_SEC / rule->tr_rpc_rate; rule->tr_depth = tbf_depth; - cfs_atomic_set(&rule->tr_ref, 1); - CFS_INIT_LIST_HEAD(&rule->tr_cli_list); - CFS_INIT_LIST_HEAD(&rule->tr_nids); + atomic_set(&rule->tr_ref, 1); + INIT_LIST_HEAD(&rule->tr_cli_list); + INIT_LIST_HEAD(&rule->tr_nids); rc = head->th_ops->o_rule_init(policy, rule, start); if (rc) { @@ -303,14 +304,15 @@ 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); + list_add(&rule->tr_linkage, &head->th_list); rule->tr_head = head; spin_unlock(&head->th_rule_lock); - cfs_atomic_inc(&head->th_rule_sequence); + atomic_inc(&head->th_rule_sequence); if (start->tc_rule_flags & NTRS_DEFAULT) { rule->tr_flags |= NTRS_DEFAULT; LASSERT(head->th_rule == NULL); @@ -327,7 +329,7 @@ nrs_tbf_rule_change(struct ptlrpc_nrs_policy *policy, { struct nrs_tbf_rule *rule; - LASSERT(spin_is_locked(&policy->pol_nrs->nrs_lock)); + assert_spin_locked(&policy->pol_nrs->nrs_lock); rule = nrs_tbf_rule_find(head, change->tc_name); if (rule == NULL) @@ -348,7 +350,7 @@ nrs_tbf_rule_stop(struct ptlrpc_nrs_policy *policy, { struct nrs_tbf_rule *rule; - LASSERT(spin_is_locked(&policy->pol_nrs->nrs_lock)); + assert_spin_locked(&policy->pol_nrs->nrs_lock); if (strcmp(stop->tc_name, NRS_TBF_DEFAULT_RULE) == 0) return -EPERM; @@ -357,7 +359,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); @@ -372,7 +374,7 @@ nrs_tbf_command(struct ptlrpc_nrs_policy *policy, { int rc; - LASSERT(spin_is_locked(&policy->pol_nrs->nrs_lock)); + assert_spin_locked(&policy->pol_nrs->nrs_lock); switch (cmd->tc_cmd) { case NRS_CTL_TBF_START_RULE: @@ -443,55 +445,55 @@ static unsigned nrs_tbf_jobid_hop_hash(cfs_hash_t *hs, const void *key, 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(cfs_hash_t *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); - cfs_atomic_inc(&cli->tc_ref); + 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(cfs_hash_t *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); - cfs_atomic_dec(&cli->tc_ref); + 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(cfs_hash_t *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); - LASSERT(cfs_atomic_read(&cli->tc_ref) == 0); + LASSERT(atomic_read(&cli->tc_ref) == 0); nrs_tbf_cli_fini(cli); } @@ -515,7 +517,7 @@ nrs_tbf_jobid_hash_lookup(cfs_hash_t *hs, cfs_hash_bd_t *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 @@ -526,8 +528,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; } @@ -581,14 +583,15 @@ nrs_tbf_jobid_cli_put(struct nrs_tbf_head *head, cfs_hash_t *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. @@ -596,21 +599,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(cfs_atomic_read(&cli->tc_ref) == 0); + 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); } } @@ -623,8 +626,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)); } @@ -668,7 +671,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)); @@ -677,7 +680,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; @@ -688,19 +691,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; @@ -715,16 +718,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; } @@ -732,7 +735,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; @@ -741,7 +744,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) { @@ -759,7 +762,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); @@ -801,8 +804,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); @@ -816,13 +819,11 @@ static int nrs_tbf_jobid_rule_init(struct ptlrpc_nrs_policy *policy, } static int -nrs_tbf_jobid_rule_dump(struct nrs_tbf_rule *rule, char *buff, int length) +nrs_tbf_jobid_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m) { - return snprintf(buff, length, "%s {%s} %llu, ref %d\n", - rule->tr_name, - rule->tr_jobids_str, - rule->tr_rpc_rate, - cfs_atomic_read(&rule->tr_ref) - 1); + return seq_printf(m, "%s {%s} %llu, ref %d\n", rule->tr_name, + rule->tr_jobids_str, rule->tr_rpc_rate, + atomic_read(&rule->tr_ref) - 1); } static int @@ -834,7 +835,7 @@ 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); @@ -868,57 +869,57 @@ static unsigned nrs_tbf_nid_hop_hash(cfs_hash_t *hs, const void *key, 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(cfs_hash_t *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); - cfs_atomic_inc(&cli->tc_ref); + 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(cfs_hash_t *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); - cfs_atomic_dec(&cli->tc_ref); + 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(cfs_hash_t *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); - LASSERTF(cfs_atomic_read(&cli->tc_ref) == 0, + LASSERTF(atomic_read(&cli->tc_ref) == 0, "Busy TBF object from client with NID %s, with %d refs\n", - libcfs_nid2str(cli->tc_nid), cfs_atomic_read(&cli->tc_ref)); + libcfs_nid2str(cli->tc_nid), atomic_read(&cli->tc_ref)); nrs_tbf_cli_fini(cli); } @@ -980,7 +981,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; @@ -1007,8 +1008,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) { @@ -1023,13 +1024,11 @@ static int nrs_tbf_nid_rule_init(struct ptlrpc_nrs_policy *policy, } static int -nrs_tbf_nid_rule_dump(struct nrs_tbf_rule *rule, char *buff, int length) +nrs_tbf_nid_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m) { - return snprintf(buff, length, "%s {%s} %llu, ref %d\n", - rule->tr_name, - rule->tr_nids_str, - rule->tr_rpc_rate, - cfs_atomic_read(&rule->tr_ref) - 1); + return seq_printf(m, "%s {%s} %llu, ref %d\n", rule->tr_name, + rule->tr_nids_str, rule->tr_rpc_rate, + atomic_read(&rule->tr_ref) - 1); } static int @@ -1041,7 +1040,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 +1048,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); @@ -1135,9 +1134,9 @@ static int nrs_tbf_start(struct ptlrpc_nrs_policy *policy, char *arg) if (head->th_binheap == NULL) GOTO(out_free_head, rc = -ENOMEM); - cfs_atomic_set(&head->th_rule_sequence, 0); + 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,11 +1173,11 @@ 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); @@ -1197,8 +1196,8 @@ static void nrs_tbf_stop(struct ptlrpc_nrs_policy *policy) * \param[in] opc the opcode * \param[in,out] arg used for passing parameters and information * - * \pre spin_is_locked(&policy->pol_nrs->->nrs_lock) - * \post spin_is_locked(&policy->pol_nrs->->nrs_lock) + * \pre assert_spin_locked(&policy->pol_nrs->->nrs_lock) + * \post assert_spin_locked(&policy->pol_nrs->->nrs_lock) * * \retval 0 operation carried out successfully * \retval -ve error @@ -1209,7 +1208,7 @@ int nrs_tbf_ctl(struct ptlrpc_nrs_policy *policy, enum ptlrpc_nrs_ctl opc, int rc = 0; ENTRY; - LASSERT(spin_is_locked(&policy->pol_nrs->nrs_lock)); + assert_spin_locked(&policy->pol_nrs->nrs_lock); switch ((enum nrs_ctl_tbf)opc) { default: @@ -1220,26 +1219,13 @@ int nrs_tbf_ctl(struct ptlrpc_nrs_policy *policy, enum ptlrpc_nrs_ctl opc, */ case NRS_CTL_TBF_RD_RULE: { struct nrs_tbf_head *head = policy->pol_private; + struct seq_file *m = (struct seq_file *) arg; struct ptlrpc_service_part *svcpt; - struct nrs_tbf_dump *dump; - int length; - - dump = (struct nrs_tbf_dump *)arg; svcpt = policy->pol_nrs->nrs_svcpt; - length = snprintf(dump->td_buff, dump->td_size, - "CPT %d:\n", - svcpt->scp_cpt); - dump->td_length += length; - dump->td_buff += length; - dump->td_size -= length; - - length = nrs_tbf_rule_dump_all(head, - dump->td_buff, - dump->td_size); - dump->td_length += length; - dump->td_buff += length; - dump->td_size -= length; + seq_printf(m, "CPT %d:\n", svcpt->scp_cpt); + + rc = nrs_tbf_rule_dump_all(head, m); } break; @@ -1297,7 +1283,7 @@ static int nrs_tbf_res_get(struct ptlrpc_nrs_policy *policy, spin_lock(&policy->pol_nrs->nrs_svcpt->scp_req_lock); LASSERT(cli->tc_rule); if (cli->tc_rule_sequence != - cfs_atomic_read(&head->th_rule_sequence) || + atomic_read(&head->th_rule_sequence) || cli->tc_rule->tr_flags & NTRS_STOPPING) { struct nrs_tbf_rule *rule; @@ -1321,7 +1307,7 @@ static int nrs_tbf_res_get(struct ptlrpc_nrs_policy *policy, nrs_tbf_cli_init(head, cli, req); tmp = head->th_ops->o_cli_findadd(head, cli); if (tmp != cli) { - cfs_atomic_dec(&cli->tc_ref); + atomic_dec(&cli->tc_ref); nrs_tbf_cli_fini(cli); cli = tmp; } @@ -1382,7 +1368,7 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy, struct nrs_tbf_client *cli; cfs_binheap_node_t *node; - LASSERT(spin_is_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock)); + assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock); if (!peek && policy->pol_nrs->nrs_throttling) return NULL; @@ -1394,7 +1380,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 { @@ -1413,7 +1399,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, @@ -1422,8 +1408,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; @@ -1469,19 +1455,19 @@ static int nrs_tbf_req_add(struct ptlrpc_nrs_policy *policy, struct nrs_tbf_client *cli; int rc = 0; - LASSERT(spin_is_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock)); + assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock); cli = container_of(nrs_request_resource(nrq), 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 + @@ -1501,7 +1487,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; @@ -1519,16 +1505,16 @@ static void nrs_tbf_req_del(struct ptlrpc_nrs_policy *policy, struct nrs_tbf_head *head; struct nrs_tbf_client *cli; - LASSERT(spin_is_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock)); + assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock); cli = container_of(nrs_request_resource(nrq), struct nrs_tbf_client, tc_res); 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; @@ -1554,7 +1540,7 @@ static void nrs_tbf_req_stop(struct ptlrpc_nrs_policy *policy, struct ptlrpc_request *req = container_of(nrq, struct ptlrpc_request, rq_nrq); - LASSERT(spin_is_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock)); + assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock); CDEBUG(D_RPCTRACE, "NRS stop %s request from %s, seq: "LPU64"\n", policy->pol_desc->pd_name, libcfs_id2str(req->rq_peer), @@ -1572,31 +1558,31 @@ static void nrs_tbf_req_stop(struct ptlrpc_nrs_policy *policy, */ #define LPROCFS_NRS_RATE_MAX 65535 -static int ptlrpc_lprocfs_rd_nrs_tbf_rule(char *page, char **start, - off_t off, int count, int *eof, - void *data) +static int +ptlrpc_lprocfs_nrs_tbf_rule_seq_show(struct seq_file *m, void *data) { - struct ptlrpc_service *svc = data; + struct ptlrpc_service *svc = m->private; int rc; - int rc2; - struct nrs_tbf_dump dump; - rc2 = snprintf(page, count, "regular_requests:\n"); + seq_printf(m, "regular_requests:\n"); /** * Perform two separate calls to this as only one of the NRS heads' * policies may be in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED or * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING state. */ - dump.td_length = 0; - dump.td_buff = page + rc2; - dump.td_size = count - rc2; rc = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_REG, NRS_POL_NAME_TBF, NRS_CTL_TBF_RD_RULE, - false, &dump); + false, m); if (rc == 0) { - *eof = 1; - rc2 += dump.td_length; + /** + * -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. @@ -1608,28 +1594,24 @@ static int ptlrpc_lprocfs_rd_nrs_tbf_rule(char *page, char **start, if (!nrs_svc_has_hp(svc)) goto no_hp; - rc2 += snprintf(page + rc2, count - rc2, "high_priority_requests:\n"); - dump.td_length = 0; - dump.td_buff = page + rc2; - dump.td_size = count - rc2; + seq_printf(m, "high_priority_requests:\n"); rc = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_HP, NRS_POL_NAME_TBF, NRS_CTL_TBF_RD_RULE, - false, &dump); + false, m); if (rc == 0) { - *eof = 1; - rc2 += dump.td_length; /** - * 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: - return rc2 ? : rc; + return rc; } static int nrs_tbf_id_parse(struct nrs_tbf_cmd *cmd, char **val) @@ -1762,11 +1744,12 @@ out: extern struct nrs_core nrs_core; #define LPROCFS_WR_NRS_TBF_MAX_CMD (4096) -static int ptlrpc_lprocfs_wr_nrs_tbf_rule(struct file *file, - const char *buffer, - unsigned long count, void *data) +static ssize_t +ptlrpc_lprocfs_nrs_tbf_rule_seq_write(struct file *file, const char *buffer, + size_t count, loff_t *off) { - struct ptlrpc_service *svc = data; + struct seq_file *m = file->private_data; + struct ptlrpc_service *svc = m->private; char *kernbuf; char *val; int rc; @@ -1830,7 +1813,7 @@ out_free_kernbuff: out: return rc ? rc : count; } - +LPROC_SEQ_FOPS(ptlrpc_lprocfs_nrs_tbf_rule); /** * Initializes a TBF policy's lprocfs interface for service \a svc @@ -1842,11 +1825,9 @@ out: */ int nrs_tbf_lprocfs_init(struct ptlrpc_service *svc) { - int rc; struct lprocfs_vars nrs_tbf_lprocfs_vars[] = { { .name = "nrs_tbf_rule", - .read_fptr = ptlrpc_lprocfs_rd_nrs_tbf_rule, - .write_fptr = ptlrpc_lprocfs_wr_nrs_tbf_rule, + .fops = &ptlrpc_lprocfs_nrs_tbf_rule_fops, .data = svc }, { NULL } }; @@ -1854,9 +1835,7 @@ int nrs_tbf_lprocfs_init(struct ptlrpc_service *svc) if (svc->srv_procroot == NULL) return 0; - rc = lprocfs_add_vars(svc->srv_procroot, nrs_tbf_lprocfs_vars, NULL); - - return rc; + return lprocfs_add_vars(svc->srv_procroot, nrs_tbf_lprocfs_vars, NULL); } /** @@ -1869,7 +1848,7 @@ void nrs_tbf_lprocfs_fini(struct ptlrpc_service *svc) if (svc->srv_procroot == NULL) return; - lprocfs_remove_proc_entry("nrs_tbf_quantum", svc->srv_procroot); + lprocfs_remove_proc_entry("nrs_tbf_rule", svc->srv_procroot); } #endif /* LPROCFS */