4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright (C) 2013 DataDirect Networks, Inc.
25 * Copyright (c) 2014, 2016, Intel Corporation.
28 * lustre/ptlrpc/nrs_tbf.c
30 * Network Request Scheduler (NRS) Token Bucket Filter(TBF) policy
34 #ifdef HAVE_SERVER_SUPPORT
41 #define DEBUG_SUBSYSTEM S_RPC
42 #include <obd_support.h>
43 #include <obd_class.h>
44 #include <libcfs/libcfs.h>
45 #include "ptlrpc_internal.h"
50 * Token Bucket Filter over client NIDs
55 #define NRS_POL_NAME_TBF "tbf"
57 static int tbf_jobid_cache_size = 8192;
58 module_param(tbf_jobid_cache_size, int, 0644);
59 MODULE_PARM_DESC(tbf_jobid_cache_size, "The size of jobid cache");
61 static int tbf_rate = 10000;
62 module_param(tbf_rate, int, 0644);
63 MODULE_PARM_DESC(tbf_rate, "Default rate limit in RPCs/s");
65 static int tbf_depth = 3;
66 module_param(tbf_depth, int, 0644);
67 MODULE_PARM_DESC(tbf_depth, "How many tokens that a client can save up");
69 static enum hrtimer_restart nrs_tbf_timer_cb(struct hrtimer *timer)
71 struct nrs_tbf_head *head = container_of(timer, struct nrs_tbf_head,
73 struct ptlrpc_nrs *nrs = head->th_res.res_policy->pol_nrs;
74 struct ptlrpc_service_part *svcpt = nrs->nrs_svcpt;
76 nrs->nrs_throttling = 0;
77 wake_up(&svcpt->scp_waitq);
79 return HRTIMER_NORESTART;
82 #define NRS_TBF_DEFAULT_RULE "default"
84 static void nrs_tbf_rule_fini(struct nrs_tbf_rule *rule)
86 LASSERT(atomic_read(&rule->tr_ref) == 0);
87 LASSERT(list_empty(&rule->tr_cli_list));
88 LASSERT(list_empty(&rule->tr_linkage));
90 rule->tr_head->th_ops->o_rule_fini(rule);
95 * Decreases the rule's usage reference count, and stops the rule in case it
96 * was already stopping and have no more outstanding usage references (which
97 * indicates it has no more queued or started requests, and can be safely
100 static void nrs_tbf_rule_put(struct nrs_tbf_rule *rule)
102 if (atomic_dec_and_test(&rule->tr_ref))
103 nrs_tbf_rule_fini(rule);
107 * Increases the rule's usage reference count.
109 static inline void nrs_tbf_rule_get(struct nrs_tbf_rule *rule)
111 atomic_inc(&rule->tr_ref);
115 nrs_tbf_cli_rule_put(struct nrs_tbf_client *cli)
117 LASSERT(!list_empty(&cli->tc_linkage));
118 LASSERT(cli->tc_rule);
119 spin_lock(&cli->tc_rule->tr_rule_lock);
120 list_del_init(&cli->tc_linkage);
121 spin_unlock(&cli->tc_rule->tr_rule_lock);
122 nrs_tbf_rule_put(cli->tc_rule);
127 nrs_tbf_cli_reset_value(struct nrs_tbf_head *head,
128 struct nrs_tbf_client *cli)
131 struct nrs_tbf_rule *rule = cli->tc_rule;
133 cli->tc_rpc_rate = rule->tr_rpc_rate;
134 cli->tc_nsecs = rule->tr_nsecs;
135 cli->tc_depth = rule->tr_depth;
136 cli->tc_ntoken = rule->tr_depth;
137 cli->tc_check_time = ktime_to_ns(ktime_get());
138 cli->tc_rule_sequence = atomic_read(&head->th_rule_sequence);
139 cli->tc_rule_generation = rule->tr_generation;
142 cfs_binheap_relocate(head->th_binheap,
147 nrs_tbf_cli_reset(struct nrs_tbf_head *head,
148 struct nrs_tbf_rule *rule,
149 struct nrs_tbf_client *cli)
151 spin_lock(&cli->tc_rule_lock);
152 if (cli->tc_rule != NULL && !list_empty(&cli->tc_linkage)) {
153 LASSERT(rule != cli->tc_rule);
154 nrs_tbf_cli_rule_put(cli);
156 LASSERT(cli->tc_rule == NULL);
157 LASSERT(list_empty(&cli->tc_linkage));
158 /* Rule's ref is added before called */
160 spin_lock(&rule->tr_rule_lock);
161 list_add_tail(&cli->tc_linkage, &rule->tr_cli_list);
162 spin_unlock(&rule->tr_rule_lock);
163 spin_unlock(&cli->tc_rule_lock);
164 nrs_tbf_cli_reset_value(head, cli);
168 nrs_tbf_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
170 return rule->tr_head->th_ops->o_rule_dump(rule, m);
174 nrs_tbf_rule_dump_all(struct nrs_tbf_head *head, struct seq_file *m)
176 struct nrs_tbf_rule *rule;
179 LASSERT(head != NULL);
180 spin_lock(&head->th_rule_lock);
181 /* List the rules from newest to oldest */
182 list_for_each_entry(rule, &head->th_list, tr_linkage) {
183 LASSERT((rule->tr_flags & NTRS_STOPPING) == 0);
184 rc = nrs_tbf_rule_dump(rule, m);
190 spin_unlock(&head->th_rule_lock);
195 static struct nrs_tbf_rule *
196 nrs_tbf_rule_find_nolock(struct nrs_tbf_head *head,
199 struct nrs_tbf_rule *rule;
201 LASSERT(head != NULL);
202 list_for_each_entry(rule, &head->th_list, tr_linkage) {
203 LASSERT((rule->tr_flags & NTRS_STOPPING) == 0);
204 if (strcmp(rule->tr_name, name) == 0) {
205 nrs_tbf_rule_get(rule);
212 static struct nrs_tbf_rule *
213 nrs_tbf_rule_find(struct nrs_tbf_head *head,
216 struct nrs_tbf_rule *rule;
218 LASSERT(head != NULL);
219 spin_lock(&head->th_rule_lock);
220 rule = nrs_tbf_rule_find_nolock(head, name);
221 spin_unlock(&head->th_rule_lock);
225 static struct nrs_tbf_rule *
226 nrs_tbf_rule_match(struct nrs_tbf_head *head,
227 struct nrs_tbf_client *cli)
229 struct nrs_tbf_rule *rule = NULL;
230 struct nrs_tbf_rule *tmp_rule;
232 spin_lock(&head->th_rule_lock);
233 /* Match the newest rule in the list */
234 list_for_each_entry(tmp_rule, &head->th_list, tr_linkage) {
235 LASSERT((tmp_rule->tr_flags & NTRS_STOPPING) == 0);
236 if (head->th_ops->o_rule_match(tmp_rule, cli)) {
243 rule = head->th_rule;
245 nrs_tbf_rule_get(rule);
246 spin_unlock(&head->th_rule_lock);
251 nrs_tbf_cli_init(struct nrs_tbf_head *head,
252 struct nrs_tbf_client *cli,
253 struct ptlrpc_request *req)
255 struct nrs_tbf_rule *rule;
257 memset(cli, 0, sizeof(*cli));
258 cli->tc_in_heap = false;
259 head->th_ops->o_cli_init(cli, req);
260 INIT_LIST_HEAD(&cli->tc_list);
261 INIT_LIST_HEAD(&cli->tc_linkage);
262 spin_lock_init(&cli->tc_rule_lock);
263 atomic_set(&cli->tc_ref, 1);
264 rule = nrs_tbf_rule_match(head, cli);
265 nrs_tbf_cli_reset(head, rule, cli);
269 nrs_tbf_cli_fini(struct nrs_tbf_client *cli)
271 LASSERT(list_empty(&cli->tc_list));
272 LASSERT(!cli->tc_in_heap);
273 LASSERT(atomic_read(&cli->tc_ref) == 0);
274 spin_lock(&cli->tc_rule_lock);
275 nrs_tbf_cli_rule_put(cli);
276 spin_unlock(&cli->tc_rule_lock);
281 nrs_tbf_rule_start(struct ptlrpc_nrs_policy *policy,
282 struct nrs_tbf_head *head,
283 struct nrs_tbf_cmd *start)
285 struct nrs_tbf_rule *rule;
286 struct nrs_tbf_rule *tmp_rule;
287 struct nrs_tbf_rule *next_rule;
288 char *next_name = start->u.tc_start.ts_next_name;
291 rule = nrs_tbf_rule_find(head, start->tc_name);
293 nrs_tbf_rule_put(rule);
297 OBD_CPT_ALLOC_PTR(rule, nrs_pol2cptab(policy), nrs_pol2cptid(policy));
301 memcpy(rule->tr_name, start->tc_name, strlen(start->tc_name));
302 rule->tr_rpc_rate = start->u.tc_start.ts_rpc_rate;
303 rule->tr_nsecs = NSEC_PER_SEC;
304 do_div(rule->tr_nsecs, rule->tr_rpc_rate);
305 rule->tr_depth = tbf_depth;
306 atomic_set(&rule->tr_ref, 1);
307 INIT_LIST_HEAD(&rule->tr_cli_list);
308 INIT_LIST_HEAD(&rule->tr_nids);
309 INIT_LIST_HEAD(&rule->tr_linkage);
310 spin_lock_init(&rule->tr_rule_lock);
311 rule->tr_head = head;
313 rc = head->th_ops->o_rule_init(policy, rule, start);
319 /* Add as the newest rule */
320 spin_lock(&head->th_rule_lock);
321 tmp_rule = nrs_tbf_rule_find_nolock(head, start->tc_name);
323 spin_unlock(&head->th_rule_lock);
324 nrs_tbf_rule_put(tmp_rule);
325 nrs_tbf_rule_put(rule);
330 next_rule = nrs_tbf_rule_find_nolock(head, next_name);
332 spin_unlock(&head->th_rule_lock);
333 nrs_tbf_rule_put(rule);
337 list_add(&rule->tr_linkage, next_rule->tr_linkage.prev);
338 nrs_tbf_rule_put(next_rule);
340 /* Add on the top of the rule list */
341 list_add(&rule->tr_linkage, &head->th_list);
343 spin_unlock(&head->th_rule_lock);
344 atomic_inc(&head->th_rule_sequence);
345 if (start->u.tc_start.ts_rule_flags & NTRS_DEFAULT) {
346 rule->tr_flags |= NTRS_DEFAULT;
347 LASSERT(head->th_rule == NULL);
348 head->th_rule = rule;
351 CDEBUG(D_RPCTRACE, "TBF starts rule@%p rate %llu gen %llu\n",
352 rule, rule->tr_rpc_rate, rule->tr_generation);
358 * Change the rank of a rule in the rule list
360 * The matched rule will be moved to the position right before another
363 * \param[in] policy the policy instance
364 * \param[in] head the TBF policy instance
365 * \param[in] name the rule name to be moved
366 * \param[in] next_name the rule name before which the matched rule will be
371 nrs_tbf_rule_change_rank(struct ptlrpc_nrs_policy *policy,
372 struct nrs_tbf_head *head,
376 struct nrs_tbf_rule *rule = NULL;
377 struct nrs_tbf_rule *next_rule = NULL;
380 LASSERT(head != NULL);
382 spin_lock(&head->th_rule_lock);
383 rule = nrs_tbf_rule_find_nolock(head, name);
385 GOTO(out, rc = -ENOENT);
387 if (strcmp(name, next_name) == 0)
390 next_rule = nrs_tbf_rule_find_nolock(head, next_name);
392 GOTO(out_put, rc = -ENOENT);
394 list_move(&rule->tr_linkage, next_rule->tr_linkage.prev);
395 nrs_tbf_rule_put(next_rule);
397 nrs_tbf_rule_put(rule);
399 spin_unlock(&head->th_rule_lock);
404 nrs_tbf_rule_change_rate(struct ptlrpc_nrs_policy *policy,
405 struct nrs_tbf_head *head,
409 struct nrs_tbf_rule *rule;
411 assert_spin_locked(&policy->pol_nrs->nrs_lock);
413 rule = nrs_tbf_rule_find(head, name);
417 rule->tr_rpc_rate = rate;
418 rule->tr_nsecs = NSEC_PER_SEC;
419 do_div(rule->tr_nsecs, rule->tr_rpc_rate);
420 rule->tr_generation++;
421 nrs_tbf_rule_put(rule);
427 nrs_tbf_rule_change(struct ptlrpc_nrs_policy *policy,
428 struct nrs_tbf_head *head,
429 struct nrs_tbf_cmd *change)
431 __u64 rate = change->u.tc_change.tc_rpc_rate;
432 char *next_name = change->u.tc_change.tc_next_name;
436 rc = nrs_tbf_rule_change_rate(policy, head, change->tc_name,
443 rc = nrs_tbf_rule_change_rank(policy, head, change->tc_name,
453 nrs_tbf_rule_stop(struct ptlrpc_nrs_policy *policy,
454 struct nrs_tbf_head *head,
455 struct nrs_tbf_cmd *stop)
457 struct nrs_tbf_rule *rule;
459 assert_spin_locked(&policy->pol_nrs->nrs_lock);
461 if (strcmp(stop->tc_name, NRS_TBF_DEFAULT_RULE) == 0)
464 rule = nrs_tbf_rule_find(head, stop->tc_name);
468 list_del_init(&rule->tr_linkage);
469 rule->tr_flags |= NTRS_STOPPING;
470 nrs_tbf_rule_put(rule);
471 nrs_tbf_rule_put(rule);
477 nrs_tbf_command(struct ptlrpc_nrs_policy *policy,
478 struct nrs_tbf_head *head,
479 struct nrs_tbf_cmd *cmd)
483 assert_spin_locked(&policy->pol_nrs->nrs_lock);
485 switch (cmd->tc_cmd) {
486 case NRS_CTL_TBF_START_RULE:
487 if (cmd->u.tc_start.ts_valid_type != head->th_type_flag)
490 spin_unlock(&policy->pol_nrs->nrs_lock);
491 rc = nrs_tbf_rule_start(policy, head, cmd);
492 spin_lock(&policy->pol_nrs->nrs_lock);
494 case NRS_CTL_TBF_CHANGE_RULE:
495 rc = nrs_tbf_rule_change(policy, head, cmd);
497 case NRS_CTL_TBF_STOP_RULE:
498 rc = nrs_tbf_rule_stop(policy, head, cmd);
499 /* Take it as a success, if not exists at all */
500 return rc == -ENOENT ? 0 : rc;
507 * Binary heap predicate.
509 * \param[in] e1 the first binheap node to compare
510 * \param[in] e2 the second binheap node to compare
516 tbf_cli_compare(struct cfs_binheap_node *e1, struct cfs_binheap_node *e2)
518 struct nrs_tbf_client *cli1;
519 struct nrs_tbf_client *cli2;
521 cli1 = container_of(e1, struct nrs_tbf_client, tc_node);
522 cli2 = container_of(e2, struct nrs_tbf_client, tc_node);
524 if (cli1->tc_check_time + cli1->tc_nsecs <
525 cli2->tc_check_time + cli2->tc_nsecs)
527 else if (cli1->tc_check_time + cli1->tc_nsecs >
528 cli2->tc_check_time + cli2->tc_nsecs)
531 if (cli1->tc_check_time < cli2->tc_check_time)
533 else if (cli1->tc_check_time > cli2->tc_check_time)
536 /* Maybe need more comparasion, e.g. request number in the rules */
541 * TBF binary heap operations
543 static struct cfs_binheap_ops nrs_tbf_heap_ops = {
546 .hop_compare = tbf_cli_compare,
549 static unsigned nrs_tbf_jobid_hop_hash(struct cfs_hash *hs, const void *key,
552 return cfs_hash_djb2_hash(key, strlen(key), mask);
555 static int nrs_tbf_jobid_hop_keycmp(const void *key, struct hlist_node *hnode)
557 struct nrs_tbf_client *cli = hlist_entry(hnode,
558 struct nrs_tbf_client,
561 return (strcmp(cli->tc_jobid, key) == 0);
564 static void *nrs_tbf_jobid_hop_key(struct hlist_node *hnode)
566 struct nrs_tbf_client *cli = hlist_entry(hnode,
567 struct nrs_tbf_client,
570 return cli->tc_jobid;
573 static void *nrs_tbf_jobid_hop_object(struct hlist_node *hnode)
575 return hlist_entry(hnode, struct nrs_tbf_client, tc_hnode);
578 static void nrs_tbf_jobid_hop_get(struct cfs_hash *hs, struct hlist_node *hnode)
580 struct nrs_tbf_client *cli = hlist_entry(hnode,
581 struct nrs_tbf_client,
584 atomic_inc(&cli->tc_ref);
587 static void nrs_tbf_jobid_hop_put(struct cfs_hash *hs, struct hlist_node *hnode)
589 struct nrs_tbf_client *cli = hlist_entry(hnode,
590 struct nrs_tbf_client,
593 atomic_dec(&cli->tc_ref);
597 nrs_tbf_jobid_hop_exit(struct cfs_hash *hs, struct hlist_node *hnode)
600 struct nrs_tbf_client *cli = hlist_entry(hnode,
601 struct nrs_tbf_client,
604 LASSERT(atomic_read(&cli->tc_ref) == 0);
605 nrs_tbf_cli_fini(cli);
608 static struct cfs_hash_ops nrs_tbf_jobid_hash_ops = {
609 .hs_hash = nrs_tbf_jobid_hop_hash,
610 .hs_keycmp = nrs_tbf_jobid_hop_keycmp,
611 .hs_key = nrs_tbf_jobid_hop_key,
612 .hs_object = nrs_tbf_jobid_hop_object,
613 .hs_get = nrs_tbf_jobid_hop_get,
614 .hs_put = nrs_tbf_jobid_hop_put,
615 .hs_put_locked = nrs_tbf_jobid_hop_put,
616 .hs_exit = nrs_tbf_jobid_hop_exit,
619 #define NRS_TBF_JOBID_HASH_FLAGS (CFS_HASH_SPIN_BKTLOCK | \
620 CFS_HASH_NO_ITEMREF | \
623 static struct nrs_tbf_client *
624 nrs_tbf_jobid_hash_lookup(struct cfs_hash *hs,
625 struct cfs_hash_bd *bd,
628 struct hlist_node *hnode;
629 struct nrs_tbf_client *cli;
631 hnode = cfs_hash_bd_lookup_locked(hs, bd, (void *)jobid);
635 cli = container_of0(hnode, struct nrs_tbf_client, tc_hnode);
636 if (!list_empty(&cli->tc_lru))
637 list_del_init(&cli->tc_lru);
641 #define NRS_TBF_JOBID_NULL ""
643 static struct nrs_tbf_client *
644 nrs_tbf_jobid_cli_find(struct nrs_tbf_head *head,
645 struct ptlrpc_request *req)
648 struct nrs_tbf_client *cli;
649 struct cfs_hash *hs = head->th_cli_hash;
650 struct cfs_hash_bd bd;
652 jobid = lustre_msg_get_jobid(req->rq_reqmsg);
654 jobid = NRS_TBF_JOBID_NULL;
655 cfs_hash_bd_get_and_lock(hs, (void *)jobid, &bd, 1);
656 cli = nrs_tbf_jobid_hash_lookup(hs, &bd, jobid);
657 cfs_hash_bd_unlock(hs, &bd, 1);
662 static struct nrs_tbf_client *
663 nrs_tbf_jobid_cli_findadd(struct nrs_tbf_head *head,
664 struct nrs_tbf_client *cli)
667 struct nrs_tbf_client *ret;
668 struct cfs_hash *hs = head->th_cli_hash;
669 struct cfs_hash_bd bd;
671 jobid = cli->tc_jobid;
672 cfs_hash_bd_get_and_lock(hs, (void *)jobid, &bd, 1);
673 ret = nrs_tbf_jobid_hash_lookup(hs, &bd, jobid);
675 cfs_hash_bd_add_locked(hs, &bd, &cli->tc_hnode);
678 cfs_hash_bd_unlock(hs, &bd, 1);
684 nrs_tbf_jobid_cli_put(struct nrs_tbf_head *head,
685 struct nrs_tbf_client *cli)
687 struct cfs_hash_bd bd;
688 struct cfs_hash *hs = head->th_cli_hash;
689 struct nrs_tbf_bucket *bkt;
691 struct list_head zombies;
693 INIT_LIST_HEAD(&zombies);
694 cfs_hash_bd_get(hs, &cli->tc_jobid, &bd);
695 bkt = cfs_hash_bd_extra_get(hs, &bd);
696 if (!cfs_hash_bd_dec_and_lock(hs, &bd, &cli->tc_ref))
698 LASSERT(list_empty(&cli->tc_lru));
699 list_add_tail(&cli->tc_lru, &bkt->ntb_lru);
702 * Check and purge the LRU, there is at least one client in the LRU.
704 hw = tbf_jobid_cache_size >>
705 (hs->hs_cur_bits - hs->hs_bkt_bits);
706 while (cfs_hash_bd_count_get(&bd) > hw) {
707 if (unlikely(list_empty(&bkt->ntb_lru)))
709 cli = list_entry(bkt->ntb_lru.next,
710 struct nrs_tbf_client,
712 LASSERT(atomic_read(&cli->tc_ref) == 0);
713 cfs_hash_bd_del_locked(hs, &bd, &cli->tc_hnode);
714 list_move(&cli->tc_lru, &zombies);
716 cfs_hash_bd_unlock(head->th_cli_hash, &bd, 1);
718 while (!list_empty(&zombies)) {
719 cli = container_of0(zombies.next,
720 struct nrs_tbf_client, tc_lru);
721 list_del_init(&cli->tc_lru);
722 nrs_tbf_cli_fini(cli);
727 nrs_tbf_jobid_cli_init(struct nrs_tbf_client *cli,
728 struct ptlrpc_request *req)
730 char *jobid = lustre_msg_get_jobid(req->rq_reqmsg);
733 jobid = NRS_TBF_JOBID_NULL;
734 LASSERT(strlen(jobid) < LUSTRE_JOBID_SIZE);
735 INIT_LIST_HEAD(&cli->tc_lru);
736 memcpy(cli->tc_jobid, jobid, strlen(jobid));
739 static int nrs_tbf_jobid_hash_order(void)
743 for (bits = 1; (1 << bits) < tbf_jobid_cache_size; ++bits)
749 #define NRS_TBF_JOBID_BKT_BITS 10
752 nrs_tbf_jobid_startup(struct ptlrpc_nrs_policy *policy,
753 struct nrs_tbf_head *head)
755 struct nrs_tbf_cmd start;
756 struct nrs_tbf_bucket *bkt;
760 struct cfs_hash_bd bd;
762 bits = nrs_tbf_jobid_hash_order();
763 if (bits < NRS_TBF_JOBID_BKT_BITS)
764 bits = NRS_TBF_JOBID_BKT_BITS;
765 head->th_cli_hash = cfs_hash_create("nrs_tbf_hash",
768 NRS_TBF_JOBID_BKT_BITS,
772 &nrs_tbf_jobid_hash_ops,
773 NRS_TBF_JOBID_HASH_FLAGS);
774 if (head->th_cli_hash == NULL)
777 cfs_hash_for_each_bucket(head->th_cli_hash, &bd, i) {
778 bkt = cfs_hash_bd_extra_get(head->th_cli_hash, &bd);
779 INIT_LIST_HEAD(&bkt->ntb_lru);
782 memset(&start, 0, sizeof(start));
783 start.u.tc_start.ts_jobids_str = "*";
785 start.u.tc_start.ts_rpc_rate = tbf_rate;
786 start.u.tc_start.ts_rule_flags = NTRS_DEFAULT;
787 start.tc_name = NRS_TBF_DEFAULT_RULE;
788 INIT_LIST_HEAD(&start.u.tc_start.ts_jobids);
789 rc = nrs_tbf_rule_start(policy, head, &start);
791 cfs_hash_putref(head->th_cli_hash);
792 head->th_cli_hash = NULL;
799 * Frees jobid of \a list.
803 nrs_tbf_jobid_list_free(struct list_head *jobid_list)
805 struct nrs_tbf_jobid *jobid, *n;
807 list_for_each_entry_safe(jobid, n, jobid_list, tj_linkage) {
808 OBD_FREE(jobid->tj_id, strlen(jobid->tj_id) + 1);
809 list_del(&jobid->tj_linkage);
810 OBD_FREE(jobid, sizeof(struct nrs_tbf_jobid));
815 nrs_tbf_jobid_list_add(struct cfs_lstr *id, struct list_head *jobid_list)
817 struct nrs_tbf_jobid *jobid;
821 OBD_ALLOC(jobid, sizeof(struct nrs_tbf_jobid));
825 OBD_ALLOC(jobid->tj_id, id->ls_len + 1);
826 if (jobid->tj_id == NULL) {
827 OBD_FREE(jobid, sizeof(struct nrs_tbf_jobid));
831 memcpy(jobid->tj_id, id->ls_str, id->ls_len);
832 rc = cfs_gettok(id, '*', &res);
834 jobid->tj_match_flag = NRS_TBF_MATCH_FULL;
836 jobid->tj_match_flag = NRS_TBF_MATCH_WILDCARD;
838 list_add_tail(&jobid->tj_linkage, jobid_list);
843 cfs_match_wildcard(const char *pattern, const char *content)
845 if (*pattern == '\0' && *content == '\0')
848 if (*pattern == '*' && *(pattern + 1) != '\0' && *content == '\0')
851 while (*pattern == *content) {
854 if (*pattern == '\0' && *content == '\0')
857 if (*pattern == '*' && *(pattern + 1) != '\0' &&
863 return (cfs_match_wildcard(pattern + 1, content) ||
864 cfs_match_wildcard(pattern, content + 1));
870 nrs_tbf_jobid_match(const struct nrs_tbf_jobid *jobid, const char *id)
872 if (jobid->tj_match_flag == NRS_TBF_MATCH_FULL)
873 return strcmp(jobid->tj_id, id) == 0;
875 if (jobid->tj_match_flag == NRS_TBF_MATCH_WILDCARD)
876 return cfs_match_wildcard(jobid->tj_id, id);
882 nrs_tbf_jobid_list_match(struct list_head *jobid_list, char *id)
884 struct nrs_tbf_jobid *jobid;
886 list_for_each_entry(jobid, jobid_list, tj_linkage) {
887 if (nrs_tbf_jobid_match(jobid, id))
894 nrs_tbf_jobid_list_parse(char *str, int len, struct list_head *jobid_list)
903 INIT_LIST_HEAD(jobid_list);
905 rc = cfs_gettok(&src, ' ', &res);
910 rc = nrs_tbf_jobid_list_add(&res, jobid_list);
915 nrs_tbf_jobid_list_free(jobid_list);
919 static void nrs_tbf_jobid_cmd_fini(struct nrs_tbf_cmd *cmd)
921 if (!list_empty(&cmd->u.tc_start.ts_jobids))
922 nrs_tbf_jobid_list_free(&cmd->u.tc_start.ts_jobids);
923 if (cmd->u.tc_start.ts_jobids_str)
924 OBD_FREE(cmd->u.tc_start.ts_jobids_str,
925 strlen(cmd->u.tc_start.ts_jobids_str) + 1);
928 static int nrs_tbf_check_id_value(struct cfs_lstr *src, char *key)
931 int keylen = strlen(key);
934 rc = cfs_gettok(src, '=', &res);
935 if (rc == 0 || res.ls_len != keylen ||
936 strncmp(res.ls_str, key, keylen) != 0 ||
937 src->ls_len <= 2 || src->ls_str[0] != '{' ||
938 src->ls_str[src->ls_len - 1] != '}')
941 /* Skip '{' and '}' */
947 static int nrs_tbf_jobid_parse(struct nrs_tbf_cmd *cmd, char *id)
953 src.ls_len = strlen(id);
954 rc = nrs_tbf_check_id_value(&src, "jobid");
958 OBD_ALLOC(cmd->u.tc_start.ts_jobids_str, src.ls_len + 1);
959 if (cmd->u.tc_start.ts_jobids_str == NULL)
962 memcpy(cmd->u.tc_start.ts_jobids_str, src.ls_str, src.ls_len);
964 /* parse jobid list */
965 rc = nrs_tbf_jobid_list_parse(cmd->u.tc_start.ts_jobids_str,
966 strlen(cmd->u.tc_start.ts_jobids_str),
967 &cmd->u.tc_start.ts_jobids);
969 nrs_tbf_jobid_cmd_fini(cmd);
974 static int nrs_tbf_jobid_rule_init(struct ptlrpc_nrs_policy *policy,
975 struct nrs_tbf_rule *rule,
976 struct nrs_tbf_cmd *start)
980 LASSERT(start->u.tc_start.ts_jobids_str);
981 OBD_ALLOC(rule->tr_jobids_str,
982 strlen(start->u.tc_start.ts_jobids_str) + 1);
983 if (rule->tr_jobids_str == NULL)
986 memcpy(rule->tr_jobids_str,
987 start->u.tc_start.ts_jobids_str,
988 strlen(start->u.tc_start.ts_jobids_str));
990 INIT_LIST_HEAD(&rule->tr_jobids);
991 if (!list_empty(&start->u.tc_start.ts_jobids)) {
992 rc = nrs_tbf_jobid_list_parse(rule->tr_jobids_str,
993 strlen(rule->tr_jobids_str),
996 CERROR("jobids {%s} illegal\n", rule->tr_jobids_str);
999 OBD_FREE(rule->tr_jobids_str,
1000 strlen(start->u.tc_start.ts_jobids_str) + 1);
1005 nrs_tbf_jobid_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
1007 seq_printf(m, "%s {%s} %llu, ref %d\n", rule->tr_name,
1008 rule->tr_jobids_str, rule->tr_rpc_rate,
1009 atomic_read(&rule->tr_ref) - 1);
1014 nrs_tbf_jobid_rule_match(struct nrs_tbf_rule *rule,
1015 struct nrs_tbf_client *cli)
1017 return nrs_tbf_jobid_list_match(&rule->tr_jobids, cli->tc_jobid);
1020 static void nrs_tbf_jobid_rule_fini(struct nrs_tbf_rule *rule)
1022 if (!list_empty(&rule->tr_jobids))
1023 nrs_tbf_jobid_list_free(&rule->tr_jobids);
1024 LASSERT(rule->tr_jobids_str != NULL);
1025 OBD_FREE(rule->tr_jobids_str, strlen(rule->tr_jobids_str) + 1);
1028 static struct nrs_tbf_ops nrs_tbf_jobid_ops = {
1029 .o_name = NRS_TBF_TYPE_JOBID,
1030 .o_startup = nrs_tbf_jobid_startup,
1031 .o_cli_find = nrs_tbf_jobid_cli_find,
1032 .o_cli_findadd = nrs_tbf_jobid_cli_findadd,
1033 .o_cli_put = nrs_tbf_jobid_cli_put,
1034 .o_cli_init = nrs_tbf_jobid_cli_init,
1035 .o_rule_init = nrs_tbf_jobid_rule_init,
1036 .o_rule_dump = nrs_tbf_jobid_rule_dump,
1037 .o_rule_match = nrs_tbf_jobid_rule_match,
1038 .o_rule_fini = nrs_tbf_jobid_rule_fini,
1042 * libcfs_hash operations for nrs_tbf_net::cn_cli_hash
1044 * This uses ptlrpc_request::rq_peer.nid as its key, in order to hash
1045 * nrs_tbf_client objects.
1047 #define NRS_TBF_NID_BKT_BITS 8
1048 #define NRS_TBF_NID_BITS 16
1050 static unsigned nrs_tbf_nid_hop_hash(struct cfs_hash *hs, const void *key,
1053 return cfs_hash_djb2_hash(key, sizeof(lnet_nid_t), mask);
1056 static int nrs_tbf_nid_hop_keycmp(const void *key, struct hlist_node *hnode)
1058 lnet_nid_t *nid = (lnet_nid_t *)key;
1059 struct nrs_tbf_client *cli = hlist_entry(hnode,
1060 struct nrs_tbf_client,
1063 return *nid == cli->tc_nid;
1066 static void *nrs_tbf_nid_hop_key(struct hlist_node *hnode)
1068 struct nrs_tbf_client *cli = hlist_entry(hnode,
1069 struct nrs_tbf_client,
1072 return &cli->tc_nid;
1075 static void *nrs_tbf_nid_hop_object(struct hlist_node *hnode)
1077 return hlist_entry(hnode, struct nrs_tbf_client, tc_hnode);
1080 static void nrs_tbf_nid_hop_get(struct cfs_hash *hs, struct hlist_node *hnode)
1082 struct nrs_tbf_client *cli = hlist_entry(hnode,
1083 struct nrs_tbf_client,
1086 atomic_inc(&cli->tc_ref);
1089 static void nrs_tbf_nid_hop_put(struct cfs_hash *hs, struct hlist_node *hnode)
1091 struct nrs_tbf_client *cli = hlist_entry(hnode,
1092 struct nrs_tbf_client,
1095 atomic_dec(&cli->tc_ref);
1098 static void nrs_tbf_nid_hop_exit(struct cfs_hash *hs, struct hlist_node *hnode)
1100 struct nrs_tbf_client *cli = hlist_entry(hnode,
1101 struct nrs_tbf_client,
1104 LASSERTF(atomic_read(&cli->tc_ref) == 0,
1105 "Busy TBF object from client with NID %s, with %d refs\n",
1106 libcfs_nid2str(cli->tc_nid), atomic_read(&cli->tc_ref));
1108 nrs_tbf_cli_fini(cli);
1111 static struct cfs_hash_ops nrs_tbf_nid_hash_ops = {
1112 .hs_hash = nrs_tbf_nid_hop_hash,
1113 .hs_keycmp = nrs_tbf_nid_hop_keycmp,
1114 .hs_key = nrs_tbf_nid_hop_key,
1115 .hs_object = nrs_tbf_nid_hop_object,
1116 .hs_get = nrs_tbf_nid_hop_get,
1117 .hs_put = nrs_tbf_nid_hop_put,
1118 .hs_put_locked = nrs_tbf_nid_hop_put,
1119 .hs_exit = nrs_tbf_nid_hop_exit,
1122 static struct nrs_tbf_client *
1123 nrs_tbf_nid_cli_find(struct nrs_tbf_head *head,
1124 struct ptlrpc_request *req)
1126 return cfs_hash_lookup(head->th_cli_hash, &req->rq_peer.nid);
1129 static struct nrs_tbf_client *
1130 nrs_tbf_nid_cli_findadd(struct nrs_tbf_head *head,
1131 struct nrs_tbf_client *cli)
1133 return cfs_hash_findadd_unique(head->th_cli_hash, &cli->tc_nid,
1138 nrs_tbf_nid_cli_put(struct nrs_tbf_head *head,
1139 struct nrs_tbf_client *cli)
1141 cfs_hash_put(head->th_cli_hash, &cli->tc_hnode);
1145 nrs_tbf_nid_startup(struct ptlrpc_nrs_policy *policy,
1146 struct nrs_tbf_head *head)
1148 struct nrs_tbf_cmd start;
1151 head->th_cli_hash = cfs_hash_create("nrs_tbf_hash",
1154 NRS_TBF_NID_BKT_BITS, 0,
1157 &nrs_tbf_nid_hash_ops,
1158 CFS_HASH_RW_BKTLOCK);
1159 if (head->th_cli_hash == NULL)
1162 memset(&start, 0, sizeof(start));
1163 start.u.tc_start.ts_nids_str = "*";
1165 start.u.tc_start.ts_rpc_rate = tbf_rate;
1166 start.u.tc_start.ts_rule_flags = NTRS_DEFAULT;
1167 start.tc_name = NRS_TBF_DEFAULT_RULE;
1168 INIT_LIST_HEAD(&start.u.tc_start.ts_nids);
1169 rc = nrs_tbf_rule_start(policy, head, &start);
1171 cfs_hash_putref(head->th_cli_hash);
1172 head->th_cli_hash = NULL;
1179 nrs_tbf_nid_cli_init(struct nrs_tbf_client *cli,
1180 struct ptlrpc_request *req)
1182 cli->tc_nid = req->rq_peer.nid;
1185 static int nrs_tbf_nid_rule_init(struct ptlrpc_nrs_policy *policy,
1186 struct nrs_tbf_rule *rule,
1187 struct nrs_tbf_cmd *start)
1189 LASSERT(start->u.tc_start.ts_nids_str);
1190 OBD_ALLOC(rule->tr_nids_str,
1191 strlen(start->u.tc_start.ts_nids_str) + 1);
1192 if (rule->tr_nids_str == NULL)
1195 memcpy(rule->tr_nids_str,
1196 start->u.tc_start.ts_nids_str,
1197 strlen(start->u.tc_start.ts_nids_str));
1199 INIT_LIST_HEAD(&rule->tr_nids);
1200 if (!list_empty(&start->u.tc_start.ts_nids)) {
1201 if (cfs_parse_nidlist(rule->tr_nids_str,
1202 strlen(rule->tr_nids_str),
1203 &rule->tr_nids) <= 0) {
1204 CERROR("nids {%s} illegal\n",
1206 OBD_FREE(rule->tr_nids_str,
1207 strlen(start->u.tc_start.ts_nids_str) + 1);
1215 nrs_tbf_nid_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
1217 seq_printf(m, "%s {%s} %llu, ref %d\n", rule->tr_name,
1218 rule->tr_nids_str, rule->tr_rpc_rate,
1219 atomic_read(&rule->tr_ref) - 1);
1224 nrs_tbf_nid_rule_match(struct nrs_tbf_rule *rule,
1225 struct nrs_tbf_client *cli)
1227 return cfs_match_nid(cli->tc_nid, &rule->tr_nids);
1230 static void nrs_tbf_nid_rule_fini(struct nrs_tbf_rule *rule)
1232 if (!list_empty(&rule->tr_nids))
1233 cfs_free_nidlist(&rule->tr_nids);
1234 LASSERT(rule->tr_nids_str != NULL);
1235 OBD_FREE(rule->tr_nids_str, strlen(rule->tr_nids_str) + 1);
1238 static void nrs_tbf_nid_cmd_fini(struct nrs_tbf_cmd *cmd)
1240 if (!list_empty(&cmd->u.tc_start.ts_nids))
1241 cfs_free_nidlist(&cmd->u.tc_start.ts_nids);
1242 if (cmd->u.tc_start.ts_nids_str)
1243 OBD_FREE(cmd->u.tc_start.ts_nids_str,
1244 strlen(cmd->u.tc_start.ts_nids_str) + 1);
1247 static int nrs_tbf_nid_parse(struct nrs_tbf_cmd *cmd, char *id)
1249 struct cfs_lstr src;
1253 src.ls_len = strlen(id);
1254 rc = nrs_tbf_check_id_value(&src, "nid");
1258 OBD_ALLOC(cmd->u.tc_start.ts_nids_str, src.ls_len + 1);
1259 if (cmd->u.tc_start.ts_nids_str == NULL)
1262 memcpy(cmd->u.tc_start.ts_nids_str, src.ls_str, src.ls_len);
1264 /* parse NID list */
1265 if (cfs_parse_nidlist(cmd->u.tc_start.ts_nids_str,
1266 strlen(cmd->u.tc_start.ts_nids_str),
1267 &cmd->u.tc_start.ts_nids) <= 0) {
1268 nrs_tbf_nid_cmd_fini(cmd);
1275 static struct nrs_tbf_ops nrs_tbf_nid_ops = {
1276 .o_name = NRS_TBF_TYPE_NID,
1277 .o_startup = nrs_tbf_nid_startup,
1278 .o_cli_find = nrs_tbf_nid_cli_find,
1279 .o_cli_findadd = nrs_tbf_nid_cli_findadd,
1280 .o_cli_put = nrs_tbf_nid_cli_put,
1281 .o_cli_init = nrs_tbf_nid_cli_init,
1282 .o_rule_init = nrs_tbf_nid_rule_init,
1283 .o_rule_dump = nrs_tbf_nid_rule_dump,
1284 .o_rule_match = nrs_tbf_nid_rule_match,
1285 .o_rule_fini = nrs_tbf_nid_rule_fini,
1288 static unsigned nrs_tbf_hop_hash(struct cfs_hash *hs, const void *key,
1291 return cfs_hash_djb2_hash(key, strlen(key), mask);
1294 static int nrs_tbf_hop_keycmp(const void *key, struct hlist_node *hnode)
1296 struct nrs_tbf_client *cli = hlist_entry(hnode,
1297 struct nrs_tbf_client,
1300 return (strcmp(cli->tc_key, key) == 0);
1303 static void *nrs_tbf_hop_key(struct hlist_node *hnode)
1305 struct nrs_tbf_client *cli = hlist_entry(hnode,
1306 struct nrs_tbf_client,
1311 static void *nrs_tbf_hop_object(struct hlist_node *hnode)
1313 return hlist_entry(hnode, struct nrs_tbf_client, tc_hnode);
1316 static void nrs_tbf_hop_get(struct cfs_hash *hs, struct hlist_node *hnode)
1318 struct nrs_tbf_client *cli = hlist_entry(hnode,
1319 struct nrs_tbf_client,
1322 atomic_inc(&cli->tc_ref);
1325 static void nrs_tbf_hop_put(struct cfs_hash *hs, struct hlist_node *hnode)
1327 struct nrs_tbf_client *cli = hlist_entry(hnode,
1328 struct nrs_tbf_client,
1331 atomic_dec(&cli->tc_ref);
1334 static void nrs_tbf_hop_exit(struct cfs_hash *hs, struct hlist_node *hnode)
1337 struct nrs_tbf_client *cli = hlist_entry(hnode,
1338 struct nrs_tbf_client,
1341 LASSERT(atomic_read(&cli->tc_ref) == 0);
1342 nrs_tbf_cli_fini(cli);
1345 static struct cfs_hash_ops nrs_tbf_hash_ops = {
1346 .hs_hash = nrs_tbf_hop_hash,
1347 .hs_keycmp = nrs_tbf_hop_keycmp,
1348 .hs_key = nrs_tbf_hop_key,
1349 .hs_object = nrs_tbf_hop_object,
1350 .hs_get = nrs_tbf_hop_get,
1351 .hs_put = nrs_tbf_hop_put,
1352 .hs_put_locked = nrs_tbf_hop_put,
1353 .hs_exit = nrs_tbf_hop_exit,
1356 #define NRS_TBF_GENERIC_BKT_BITS 10
1357 #define NRS_TBF_GENERIC_HASH_FLAGS (CFS_HASH_SPIN_BKTLOCK | \
1358 CFS_HASH_NO_ITEMREF | \
1362 nrs_tbf_startup(struct ptlrpc_nrs_policy *policy, struct nrs_tbf_head *head)
1364 struct nrs_tbf_cmd start;
1365 struct nrs_tbf_bucket *bkt;
1369 struct cfs_hash_bd bd;
1371 bits = nrs_tbf_jobid_hash_order();
1372 if (bits < NRS_TBF_GENERIC_BKT_BITS)
1373 bits = NRS_TBF_GENERIC_BKT_BITS;
1374 head->th_cli_hash = cfs_hash_create("nrs_tbf_hash",
1376 NRS_TBF_GENERIC_BKT_BITS,
1379 NRS_TBF_GENERIC_HASH_FLAGS);
1380 if (head->th_cli_hash == NULL)
1383 cfs_hash_for_each_bucket(head->th_cli_hash, &bd, i) {
1384 bkt = cfs_hash_bd_extra_get(head->th_cli_hash, &bd);
1385 INIT_LIST_HEAD(&bkt->ntb_lru);
1388 memset(&start, 0, sizeof(start));
1389 start.u.tc_start.ts_conds_str = "*";
1391 start.u.tc_start.ts_rpc_rate = tbf_rate;
1392 start.u.tc_start.ts_rule_flags = NTRS_DEFAULT;
1393 start.tc_name = NRS_TBF_DEFAULT_RULE;
1394 INIT_LIST_HEAD(&start.u.tc_start.ts_conds);
1395 rc = nrs_tbf_rule_start(policy, head, &start);
1397 cfs_hash_putref(head->th_cli_hash);
1402 static struct nrs_tbf_client *
1403 nrs_tbf_cli_hash_lookup(struct cfs_hash *hs, struct cfs_hash_bd *bd,
1406 struct hlist_node *hnode;
1407 struct nrs_tbf_client *cli;
1409 hnode = cfs_hash_bd_lookup_locked(hs, bd, (void *)key);
1413 cli = container_of0(hnode, struct nrs_tbf_client, tc_hnode);
1414 if (!list_empty(&cli->tc_lru))
1415 list_del_init(&cli->tc_lru);
1419 static struct nrs_tbf_client *
1420 nrs_tbf_cli_find(struct nrs_tbf_head *head, struct ptlrpc_request *req)
1422 struct nrs_tbf_client *cli;
1423 struct cfs_hash *hs = head->th_cli_hash;
1424 struct cfs_hash_bd bd;
1425 char keystr[NRS_TBF_KEY_LEN] = { '\0' };
1429 jobid = lustre_msg_get_jobid(req->rq_reqmsg);
1431 jobid = NRS_TBF_JOBID_NULL;
1432 opc = lustre_msg_get_opc(req->rq_reqmsg);
1433 snprintf(keystr, sizeof(keystr), "%s_%s_%d", jobid,
1434 libcfs_nid2str(req->rq_peer.nid), opc);
1435 LASSERT(strlen(keystr) < NRS_TBF_KEY_LEN);
1436 cfs_hash_bd_get_and_lock(hs, (void *)keystr, &bd, 1);
1437 cli = nrs_tbf_cli_hash_lookup(hs, &bd, keystr);
1438 cfs_hash_bd_unlock(hs, &bd, 1);
1443 static struct nrs_tbf_client *
1444 nrs_tbf_cli_findadd(struct nrs_tbf_head *head,
1445 struct nrs_tbf_client *cli)
1448 struct nrs_tbf_client *ret;
1449 struct cfs_hash *hs = head->th_cli_hash;
1450 struct cfs_hash_bd bd;
1453 cfs_hash_bd_get_and_lock(hs, (void *)key, &bd, 1);
1454 ret = nrs_tbf_cli_hash_lookup(hs, &bd, key);
1456 cfs_hash_bd_add_locked(hs, &bd, &cli->tc_hnode);
1459 cfs_hash_bd_unlock(hs, &bd, 1);
1465 nrs_tbf_cli_put(struct nrs_tbf_head *head, struct nrs_tbf_client *cli)
1467 struct cfs_hash_bd bd;
1468 struct cfs_hash *hs = head->th_cli_hash;
1469 struct nrs_tbf_bucket *bkt;
1471 struct list_head zombies;
1473 INIT_LIST_HEAD(&zombies);
1474 cfs_hash_bd_get(hs, &cli->tc_key, &bd);
1475 bkt = cfs_hash_bd_extra_get(hs, &bd);
1476 if (!cfs_hash_bd_dec_and_lock(hs, &bd, &cli->tc_ref))
1478 LASSERT(list_empty(&cli->tc_lru));
1479 list_add_tail(&cli->tc_lru, &bkt->ntb_lru);
1482 * Check and purge the LRU, there is at least one client in the LRU.
1484 hw = tbf_jobid_cache_size >> (hs->hs_cur_bits - hs->hs_bkt_bits);
1485 while (cfs_hash_bd_count_get(&bd) > hw) {
1486 if (unlikely(list_empty(&bkt->ntb_lru)))
1488 cli = list_entry(bkt->ntb_lru.next,
1489 struct nrs_tbf_client,
1491 LASSERT(atomic_read(&cli->tc_ref) == 0);
1492 cfs_hash_bd_del_locked(hs, &bd, &cli->tc_hnode);
1493 list_move(&cli->tc_lru, &zombies);
1495 cfs_hash_bd_unlock(head->th_cli_hash, &bd, 1);
1497 while (!list_empty(&zombies)) {
1498 cli = container_of0(zombies.next,
1499 struct nrs_tbf_client, tc_lru);
1500 list_del_init(&cli->tc_lru);
1501 nrs_tbf_cli_fini(cli);
1506 nrs_tbf_generic_cli_init(struct nrs_tbf_client *cli,
1507 struct ptlrpc_request *req)
1509 char keystr[NRS_TBF_KEY_LEN];
1513 jobid = lustre_msg_get_jobid(req->rq_reqmsg);
1515 jobid = NRS_TBF_JOBID_NULL;
1516 opc = lustre_msg_get_opc(req->rq_reqmsg);
1517 snprintf(keystr, sizeof(keystr), "%s_%s_%d", jobid,
1518 libcfs_nid2str(req->rq_peer.nid), opc);
1520 LASSERT(strlen(keystr) < NRS_TBF_KEY_LEN);
1521 INIT_LIST_HEAD(&cli->tc_lru);
1522 memcpy(cli->tc_key, keystr, strlen(keystr));
1523 memcpy(cli->tc_jobid, jobid, strlen(jobid));
1524 cli->tc_nid = req->rq_peer.nid;
1525 cli->tc_opcode = opc;
1529 nrs_tbf_expression_free(struct nrs_tbf_expression *expr)
1531 LASSERT(expr->te_field >= NRS_TBF_FIELD_NID &&
1532 expr->te_field < NRS_TBF_FIELD_MAX);
1533 switch (expr->te_field) {
1534 case NRS_TBF_FIELD_NID:
1535 cfs_free_nidlist(&expr->te_cond);
1537 case NRS_TBF_FIELD_JOBID:
1538 nrs_tbf_jobid_list_free(&expr->te_cond);
1540 case NRS_TBF_FIELD_OPCODE:
1541 CFS_FREE_BITMAP(expr->te_opcodes);
1550 nrs_tbf_conjunction_free(struct nrs_tbf_conjunction *conjunction)
1552 struct nrs_tbf_expression *expression;
1553 struct nrs_tbf_expression *n;
1555 LASSERT(list_empty(&conjunction->tc_linkage));
1556 list_for_each_entry_safe(expression, n,
1557 &conjunction->tc_expressions,
1559 list_del_init(&expression->te_linkage);
1560 nrs_tbf_expression_free(expression);
1562 OBD_FREE_PTR(conjunction);
1566 nrs_tbf_conds_free(struct list_head *cond_list)
1568 struct nrs_tbf_conjunction *conjunction;
1569 struct nrs_tbf_conjunction *n;
1571 list_for_each_entry_safe(conjunction, n, cond_list, tc_linkage) {
1572 list_del_init(&conjunction->tc_linkage);
1573 nrs_tbf_conjunction_free(conjunction);
1578 nrs_tbf_generic_cmd_fini(struct nrs_tbf_cmd *cmd)
1580 if (!list_empty(&cmd->u.tc_start.ts_conds))
1581 nrs_tbf_conds_free(&cmd->u.tc_start.ts_conds);
1582 if (cmd->u.tc_start.ts_conds_str)
1583 OBD_FREE(cmd->u.tc_start.ts_conds_str,
1584 strlen(cmd->u.tc_start.ts_conds_str) + 1);
1587 #define NRS_TBF_DISJUNCTION_DELIM (',')
1588 #define NRS_TBF_CONJUNCTION_DELIM ('&')
1589 #define NRS_TBF_EXPRESSION_DELIM ('=')
1592 nrs_tbf_check_field(struct cfs_lstr *field, char *str)
1594 int len = strlen(str);
1596 return (field->ls_len == len &&
1597 strncmp(field->ls_str, str, len) == 0);
1601 nrs_tbf_opcode_list_parse(char *str, int len, struct cfs_bitmap **bitmaptr);
1604 nrs_tbf_expression_parse(struct cfs_lstr *src, struct list_head *cond_list)
1606 struct nrs_tbf_expression *expr;
1607 struct cfs_lstr field;
1610 OBD_ALLOC(expr, sizeof(struct nrs_tbf_expression));
1614 rc = cfs_gettok(src, NRS_TBF_EXPRESSION_DELIM, &field);
1615 if (rc == 0 || src->ls_len <= 2 || src->ls_str[0] != '{' ||
1616 src->ls_str[src->ls_len - 1] != '}')
1617 GOTO(out, rc = -EINVAL);
1619 /* Skip '{' and '}' */
1623 if (nrs_tbf_check_field(&field, "nid")) {
1624 if (cfs_parse_nidlist(src->ls_str,
1626 &expr->te_cond) <= 0)
1627 GOTO(out, rc = -EINVAL);
1628 expr->te_field = NRS_TBF_FIELD_NID;
1629 } else if (nrs_tbf_check_field(&field, "jobid")) {
1630 if (nrs_tbf_jobid_list_parse(src->ls_str,
1632 &expr->te_cond) < 0)
1633 GOTO(out, rc = -EINVAL);
1634 expr->te_field = NRS_TBF_FIELD_JOBID;
1635 } else if (nrs_tbf_check_field(&field, "opcode")) {
1636 if (nrs_tbf_opcode_list_parse(src->ls_str,
1638 &expr->te_opcodes) < 0)
1639 GOTO(out, rc = -EINVAL);
1640 expr->te_field = NRS_TBF_FIELD_OPCODE;
1642 GOTO(out, rc = -EINVAL);
1644 list_add_tail(&expr->te_linkage, cond_list);
1652 nrs_tbf_conjunction_parse(struct cfs_lstr *src, struct list_head *cond_list)
1654 struct nrs_tbf_conjunction *conjunction;
1655 struct cfs_lstr expr;
1658 OBD_ALLOC(conjunction, sizeof(struct nrs_tbf_conjunction));
1659 if (conjunction == NULL)
1662 INIT_LIST_HEAD(&conjunction->tc_expressions);
1663 list_add_tail(&conjunction->tc_linkage, cond_list);
1665 while (src->ls_str) {
1666 rc = cfs_gettok(src, NRS_TBF_CONJUNCTION_DELIM, &expr);
1671 rc = nrs_tbf_expression_parse(&expr,
1672 &conjunction->tc_expressions);
1680 nrs_tbf_conds_parse(char *str, int len, struct list_head *cond_list)
1682 struct cfs_lstr src;
1683 struct cfs_lstr res;
1688 INIT_LIST_HEAD(cond_list);
1689 while (src.ls_str) {
1690 rc = cfs_gettok(&src, NRS_TBF_DISJUNCTION_DELIM, &res);
1695 rc = nrs_tbf_conjunction_parse(&res, cond_list);
1703 nrs_tbf_generic_parse(struct nrs_tbf_cmd *cmd, const char *id)
1707 OBD_ALLOC(cmd->u.tc_start.ts_conds_str, strlen(id) + 1);
1708 if (cmd->u.tc_start.ts_conds_str == NULL)
1711 memcpy(cmd->u.tc_start.ts_conds_str, id, strlen(id));
1713 /* Parse hybird NID and JOBID conditions */
1714 rc = nrs_tbf_conds_parse(cmd->u.tc_start.ts_conds_str,
1715 strlen(cmd->u.tc_start.ts_conds_str),
1716 &cmd->u.tc_start.ts_conds);
1718 nrs_tbf_generic_cmd_fini(cmd);
1724 nrs_tbf_expression_match(struct nrs_tbf_expression *expr,
1725 struct nrs_tbf_rule *rule,
1726 struct nrs_tbf_client *cli)
1728 switch (expr->te_field) {
1729 case NRS_TBF_FIELD_NID:
1730 return cfs_match_nid(cli->tc_nid, &expr->te_cond);
1731 case NRS_TBF_FIELD_JOBID:
1732 return nrs_tbf_jobid_list_match(&expr->te_cond, cli->tc_jobid);
1733 case NRS_TBF_FIELD_OPCODE:
1734 return cfs_bitmap_check(expr->te_opcodes, cli->tc_opcode);
1741 nrs_tbf_conjunction_match(struct nrs_tbf_conjunction *conjunction,
1742 struct nrs_tbf_rule *rule,
1743 struct nrs_tbf_client *cli)
1745 struct nrs_tbf_expression *expr;
1748 list_for_each_entry(expr, &conjunction->tc_expressions, te_linkage) {
1749 matched = nrs_tbf_expression_match(expr, rule, cli);
1758 nrs_tbf_cond_match(struct nrs_tbf_rule *rule, struct nrs_tbf_client *cli)
1760 struct nrs_tbf_conjunction *conjunction;
1763 list_for_each_entry(conjunction, &rule->tr_conds, tc_linkage) {
1764 matched = nrs_tbf_conjunction_match(conjunction, rule, cli);
1773 nrs_tbf_generic_rule_fini(struct nrs_tbf_rule *rule)
1775 if (!list_empty(&rule->tr_conds))
1776 nrs_tbf_conds_free(&rule->tr_conds);
1777 LASSERT(rule->tr_conds_str != NULL);
1778 OBD_FREE(rule->tr_conds_str, strlen(rule->tr_conds_str) + 1);
1782 nrs_tbf_rule_init(struct ptlrpc_nrs_policy *policy,
1783 struct nrs_tbf_rule *rule, struct nrs_tbf_cmd *start)
1787 LASSERT(start->u.tc_start.ts_conds_str);
1788 OBD_ALLOC(rule->tr_conds_str,
1789 strlen(start->u.tc_start.ts_conds_str) + 1);
1790 if (rule->tr_conds_str == NULL)
1793 memcpy(rule->tr_conds_str,
1794 start->u.tc_start.ts_conds_str,
1795 strlen(start->u.tc_start.ts_conds_str));
1797 INIT_LIST_HEAD(&rule->tr_conds);
1798 if (!list_empty(&start->u.tc_start.ts_conds)) {
1799 rc = nrs_tbf_conds_parse(rule->tr_conds_str,
1800 strlen(rule->tr_conds_str),
1804 nrs_tbf_generic_rule_fini(rule);
1810 nrs_tbf_generic_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
1812 seq_printf(m, "%s %s %llu, ref %d\n", rule->tr_name,
1813 rule->tr_conds_str, rule->tr_rpc_rate,
1814 atomic_read(&rule->tr_ref) - 1);
1819 nrs_tbf_generic_rule_match(struct nrs_tbf_rule *rule,
1820 struct nrs_tbf_client *cli)
1822 return nrs_tbf_cond_match(rule, cli);
1825 static struct nrs_tbf_ops nrs_tbf_generic_ops = {
1826 .o_name = NRS_TBF_TYPE_GENERIC,
1827 .o_startup = nrs_tbf_startup,
1828 .o_cli_find = nrs_tbf_cli_find,
1829 .o_cli_findadd = nrs_tbf_cli_findadd,
1830 .o_cli_put = nrs_tbf_cli_put,
1831 .o_cli_init = nrs_tbf_generic_cli_init,
1832 .o_rule_init = nrs_tbf_rule_init,
1833 .o_rule_dump = nrs_tbf_generic_rule_dump,
1834 .o_rule_match = nrs_tbf_generic_rule_match,
1835 .o_rule_fini = nrs_tbf_generic_rule_fini,
1838 static void nrs_tbf_opcode_rule_fini(struct nrs_tbf_rule *rule)
1840 if (rule->tr_opcodes != NULL)
1841 CFS_FREE_BITMAP(rule->tr_opcodes);
1843 LASSERT(rule->tr_opcodes_str != NULL);
1844 OBD_FREE(rule->tr_opcodes_str, strlen(rule->tr_opcodes_str) + 1);
1847 static unsigned nrs_tbf_opcode_hop_hash(struct cfs_hash *hs, const void *key,
1850 return cfs_hash_djb2_hash(key, sizeof(__u32), mask);
1853 static int nrs_tbf_opcode_hop_keycmp(const void *key, struct hlist_node *hnode)
1855 const __u32 *opc = key;
1856 struct nrs_tbf_client *cli = hlist_entry(hnode,
1857 struct nrs_tbf_client,
1860 return *opc == cli->tc_opcode;
1863 static void *nrs_tbf_opcode_hop_key(struct hlist_node *hnode)
1865 struct nrs_tbf_client *cli = hlist_entry(hnode,
1866 struct nrs_tbf_client,
1869 return &cli->tc_opcode;
1872 static void *nrs_tbf_opcode_hop_object(struct hlist_node *hnode)
1874 return hlist_entry(hnode, struct nrs_tbf_client, tc_hnode);
1877 static void nrs_tbf_opcode_hop_get(struct cfs_hash *hs,
1878 struct hlist_node *hnode)
1880 struct nrs_tbf_client *cli = hlist_entry(hnode,
1881 struct nrs_tbf_client,
1884 atomic_inc(&cli->tc_ref);
1887 static void nrs_tbf_opcode_hop_put(struct cfs_hash *hs,
1888 struct hlist_node *hnode)
1890 struct nrs_tbf_client *cli = hlist_entry(hnode,
1891 struct nrs_tbf_client,
1894 atomic_dec(&cli->tc_ref);
1897 static void nrs_tbf_opcode_hop_exit(struct cfs_hash *hs,
1898 struct hlist_node *hnode)
1900 struct nrs_tbf_client *cli = hlist_entry(hnode,
1901 struct nrs_tbf_client,
1904 LASSERTF(atomic_read(&cli->tc_ref) == 0,
1905 "Busy TBF object from client with opcode %s, with %d refs\n",
1906 ll_opcode2str(cli->tc_opcode),
1907 atomic_read(&cli->tc_ref));
1909 nrs_tbf_cli_fini(cli);
1911 static struct cfs_hash_ops nrs_tbf_opcode_hash_ops = {
1912 .hs_hash = nrs_tbf_opcode_hop_hash,
1913 .hs_keycmp = nrs_tbf_opcode_hop_keycmp,
1914 .hs_key = nrs_tbf_opcode_hop_key,
1915 .hs_object = nrs_tbf_opcode_hop_object,
1916 .hs_get = nrs_tbf_opcode_hop_get,
1917 .hs_put = nrs_tbf_opcode_hop_put,
1918 .hs_put_locked = nrs_tbf_opcode_hop_put,
1919 .hs_exit = nrs_tbf_opcode_hop_exit,
1923 nrs_tbf_opcode_startup(struct ptlrpc_nrs_policy *policy,
1924 struct nrs_tbf_head *head)
1926 struct nrs_tbf_cmd start = { 0 };
1929 head->th_cli_hash = cfs_hash_create("nrs_tbf_hash",
1932 NRS_TBF_NID_BKT_BITS, 0,
1935 &nrs_tbf_opcode_hash_ops,
1936 CFS_HASH_RW_BKTLOCK);
1937 if (head->th_cli_hash == NULL)
1940 start.u.tc_start.ts_opcodes = NULL;
1941 start.u.tc_start.ts_opcodes_str = "*";
1943 start.u.tc_start.ts_rpc_rate = tbf_rate;
1944 start.u.tc_start.ts_rule_flags = NTRS_DEFAULT;
1945 start.tc_name = NRS_TBF_DEFAULT_RULE;
1946 rc = nrs_tbf_rule_start(policy, head, &start);
1951 static struct nrs_tbf_client *
1952 nrs_tbf_opcode_cli_find(struct nrs_tbf_head *head,
1953 struct ptlrpc_request *req)
1957 opc = lustre_msg_get_opc(req->rq_reqmsg);
1958 return cfs_hash_lookup(head->th_cli_hash, &opc);
1961 static struct nrs_tbf_client *
1962 nrs_tbf_opcode_cli_findadd(struct nrs_tbf_head *head,
1963 struct nrs_tbf_client *cli)
1965 return cfs_hash_findadd_unique(head->th_cli_hash, &cli->tc_opcode,
1970 nrs_tbf_opcode_cli_init(struct nrs_tbf_client *cli,
1971 struct ptlrpc_request *req)
1973 cli->tc_opcode = lustre_msg_get_opc(req->rq_reqmsg);
1976 #define MAX_OPCODE_LEN 32
1978 nrs_tbf_opcode_set_bit(const struct cfs_lstr *id, struct cfs_bitmap *opcodes)
1981 char opcode_str[MAX_OPCODE_LEN];
1983 if (id->ls_len + 1 > MAX_OPCODE_LEN)
1986 memcpy(opcode_str, id->ls_str, id->ls_len);
1987 opcode_str[id->ls_len] = '\0';
1989 op = ll_str2opcode(opcode_str);
1993 cfs_bitmap_set(opcodes, op);
1998 nrs_tbf_opcode_list_parse(char *str, int len, struct cfs_bitmap **bitmaptr)
2000 struct cfs_bitmap *opcodes;
2001 struct cfs_lstr src;
2002 struct cfs_lstr res;
2006 opcodes = CFS_ALLOCATE_BITMAP(LUSTRE_MAX_OPCODES);
2007 if (opcodes == NULL)
2012 while (src.ls_str) {
2013 rc = cfs_gettok(&src, ' ', &res);
2018 rc = nrs_tbf_opcode_set_bit(&res, opcodes);
2024 *bitmaptr = opcodes;
2026 CFS_FREE_BITMAP(opcodes);
2031 static void nrs_tbf_opcode_cmd_fini(struct nrs_tbf_cmd *cmd)
2033 if (cmd->u.tc_start.ts_opcodes)
2034 CFS_FREE_BITMAP(cmd->u.tc_start.ts_opcodes);
2036 if (cmd->u.tc_start.ts_opcodes_str)
2037 OBD_FREE(cmd->u.tc_start.ts_opcodes_str,
2038 strlen(cmd->u.tc_start.ts_opcodes_str) + 1);
2042 static int nrs_tbf_opcode_parse(struct nrs_tbf_cmd *cmd, char *id)
2044 struct cfs_lstr src;
2048 src.ls_len = strlen(id);
2049 rc = nrs_tbf_check_id_value(&src, "opcode");
2053 OBD_ALLOC(cmd->u.tc_start.ts_opcodes_str, src.ls_len + 1);
2054 if (cmd->u.tc_start.ts_opcodes_str == NULL)
2057 memcpy(cmd->u.tc_start.ts_opcodes_str, src.ls_str, src.ls_len);
2059 /* parse opcode list */
2060 rc = nrs_tbf_opcode_list_parse(cmd->u.tc_start.ts_opcodes_str,
2061 strlen(cmd->u.tc_start.ts_opcodes_str),
2062 &cmd->u.tc_start.ts_opcodes);
2064 nrs_tbf_opcode_cmd_fini(cmd);
2070 nrs_tbf_opcode_rule_match(struct nrs_tbf_rule *rule,
2071 struct nrs_tbf_client *cli)
2073 if (rule->tr_opcodes == NULL)
2076 return cfs_bitmap_check(rule->tr_opcodes, cli->tc_opcode);
2079 static int nrs_tbf_opcode_rule_init(struct ptlrpc_nrs_policy *policy,
2080 struct nrs_tbf_rule *rule,
2081 struct nrs_tbf_cmd *start)
2085 LASSERT(start->u.tc_start.ts_opcodes_str != NULL);
2086 OBD_ALLOC(rule->tr_opcodes_str,
2087 strlen(start->u.tc_start.ts_opcodes_str) + 1);
2088 if (rule->tr_opcodes_str == NULL)
2091 strncpy(rule->tr_opcodes_str, start->u.tc_start.ts_opcodes_str,
2092 strlen(start->u.tc_start.ts_opcodes_str) + 1);
2094 /* Default rule '*' */
2095 if (start->u.tc_start.ts_opcodes == NULL)
2098 rc = nrs_tbf_opcode_list_parse(rule->tr_opcodes_str,
2099 strlen(rule->tr_opcodes_str),
2102 OBD_FREE(rule->tr_opcodes_str,
2103 strlen(start->u.tc_start.ts_opcodes_str) + 1);
2109 nrs_tbf_opcode_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
2111 seq_printf(m, "%s {%s} %llu, ref %d\n", rule->tr_name,
2112 rule->tr_opcodes_str, rule->tr_rpc_rate,
2113 atomic_read(&rule->tr_ref) - 1);
2118 struct nrs_tbf_ops nrs_tbf_opcode_ops = {
2119 .o_name = NRS_TBF_TYPE_OPCODE,
2120 .o_startup = nrs_tbf_opcode_startup,
2121 .o_cli_find = nrs_tbf_opcode_cli_find,
2122 .o_cli_findadd = nrs_tbf_opcode_cli_findadd,
2123 .o_cli_put = nrs_tbf_nid_cli_put,
2124 .o_cli_init = nrs_tbf_opcode_cli_init,
2125 .o_rule_init = nrs_tbf_opcode_rule_init,
2126 .o_rule_dump = nrs_tbf_opcode_rule_dump,
2127 .o_rule_match = nrs_tbf_opcode_rule_match,
2128 .o_rule_fini = nrs_tbf_opcode_rule_fini,
2131 static struct nrs_tbf_type nrs_tbf_types[] = {
2133 .ntt_name = NRS_TBF_TYPE_JOBID,
2134 .ntt_flag = NRS_TBF_FLAG_JOBID,
2135 .ntt_ops = &nrs_tbf_jobid_ops,
2138 .ntt_name = NRS_TBF_TYPE_NID,
2139 .ntt_flag = NRS_TBF_FLAG_NID,
2140 .ntt_ops = &nrs_tbf_nid_ops,
2143 .ntt_name = NRS_TBF_TYPE_OPCODE,
2144 .ntt_flag = NRS_TBF_FLAG_OPCODE,
2145 .ntt_ops = &nrs_tbf_opcode_ops,
2148 .ntt_name = NRS_TBF_TYPE_GENERIC,
2149 .ntt_flag = NRS_TBF_FLAG_GENERIC,
2150 .ntt_ops = &nrs_tbf_generic_ops,
2155 * Is called before the policy transitions into
2156 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED; allocates and initializes a
2157 * policy-specific private data structure.
2159 * \param[in] policy The policy to start
2161 * \retval -ENOMEM OOM error
2164 * \see nrs_policy_register()
2165 * \see nrs_policy_ctl()
2167 static int nrs_tbf_start(struct ptlrpc_nrs_policy *policy, char *arg)
2169 struct nrs_tbf_head *head;
2170 struct nrs_tbf_ops *ops;
2178 name = NRS_TBF_TYPE_GENERIC;
2179 else if (strlen(arg) < NRS_TBF_TYPE_MAX_LEN)
2182 GOTO(out, rc = -EINVAL);
2184 for (i = 0; i < ARRAY_SIZE(nrs_tbf_types); i++) {
2185 if (strcmp(name, nrs_tbf_types[i].ntt_name) == 0) {
2186 ops = nrs_tbf_types[i].ntt_ops;
2187 type = nrs_tbf_types[i].ntt_flag;
2193 GOTO(out, rc = -ENOTSUPP);
2195 OBD_CPT_ALLOC_PTR(head, nrs_pol2cptab(policy), nrs_pol2cptid(policy));
2197 GOTO(out, rc = -ENOMEM);
2199 memcpy(head->th_type, name, strlen(name));
2200 head->th_type[strlen(name)] = '\0';
2202 head->th_type_flag = type;
2204 head->th_binheap = cfs_binheap_create(&nrs_tbf_heap_ops,
2205 CBH_FLAG_ATOMIC_GROW, 4096, NULL,
2206 nrs_pol2cptab(policy),
2207 nrs_pol2cptid(policy));
2208 if (head->th_binheap == NULL)
2209 GOTO(out_free_head, rc = -ENOMEM);
2211 atomic_set(&head->th_rule_sequence, 0);
2212 spin_lock_init(&head->th_rule_lock);
2213 INIT_LIST_HEAD(&head->th_list);
2214 hrtimer_init(&head->th_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
2215 head->th_timer.function = nrs_tbf_timer_cb;
2216 rc = head->th_ops->o_startup(policy, head);
2218 GOTO(out_free_heap, rc);
2220 policy->pol_private = head;
2223 cfs_binheap_destroy(head->th_binheap);
2231 * Is called before the policy transitions into
2232 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED; deallocates the policy-specific
2233 * private data structure.
2235 * \param[in] policy The policy to stop
2237 * \see nrs_policy_stop0()
2239 static void nrs_tbf_stop(struct ptlrpc_nrs_policy *policy)
2241 struct nrs_tbf_head *head = policy->pol_private;
2242 struct ptlrpc_nrs *nrs = policy->pol_nrs;
2243 struct nrs_tbf_rule *rule, *n;
2245 LASSERT(head != NULL);
2246 LASSERT(head->th_cli_hash != NULL);
2247 hrtimer_cancel(&head->th_timer);
2248 /* Should cleanup hash first before free rules */
2249 cfs_hash_putref(head->th_cli_hash);
2250 list_for_each_entry_safe(rule, n, &head->th_list, tr_linkage) {
2251 list_del_init(&rule->tr_linkage);
2252 nrs_tbf_rule_put(rule);
2254 LASSERT(list_empty(&head->th_list));
2255 LASSERT(head->th_binheap != NULL);
2256 LASSERT(cfs_binheap_is_empty(head->th_binheap));
2257 cfs_binheap_destroy(head->th_binheap);
2259 nrs->nrs_throttling = 0;
2260 wake_up(&policy->pol_nrs->nrs_svcpt->scp_waitq);
2264 * Performs a policy-specific ctl function on TBF policy instances; similar
2267 * \param[in] policy the policy instance
2268 * \param[in] opc the opcode
2269 * \param[in,out] arg used for passing parameters and information
2271 * \pre assert_spin_locked(&policy->pol_nrs->->nrs_lock)
2272 * \post assert_spin_locked(&policy->pol_nrs->->nrs_lock)
2274 * \retval 0 operation carried out successfully
2277 static int nrs_tbf_ctl(struct ptlrpc_nrs_policy *policy,
2278 enum ptlrpc_nrs_ctl opc,
2284 assert_spin_locked(&policy->pol_nrs->nrs_lock);
2286 switch ((enum nrs_ctl_tbf)opc) {
2291 * Read RPC rate size of a policy instance.
2293 case NRS_CTL_TBF_RD_RULE: {
2294 struct nrs_tbf_head *head = policy->pol_private;
2295 struct seq_file *m = (struct seq_file *) arg;
2296 struct ptlrpc_service_part *svcpt;
2298 svcpt = policy->pol_nrs->nrs_svcpt;
2299 seq_printf(m, "CPT %d:\n", svcpt->scp_cpt);
2301 rc = nrs_tbf_rule_dump_all(head, m);
2306 * Write RPC rate of a policy instance.
2308 case NRS_CTL_TBF_WR_RULE: {
2309 struct nrs_tbf_head *head = policy->pol_private;
2310 struct nrs_tbf_cmd *cmd;
2312 cmd = (struct nrs_tbf_cmd *)arg;
2313 rc = nrs_tbf_command(policy,
2319 * Read the TBF policy type of a policy instance.
2321 case NRS_CTL_TBF_RD_TYPE_FLAG: {
2322 struct nrs_tbf_head *head = policy->pol_private;
2324 *(__u32 *)arg = head->th_type_flag;
2333 * Is called for obtaining a TBF policy resource.
2335 * \param[in] policy The policy on which the request is being asked for
2336 * \param[in] nrq The request for which resources are being taken
2337 * \param[in] parent Parent resource, unused in this policy
2338 * \param[out] resp Resources references are placed in this array
2339 * \param[in] moving_req Signifies limited caller context; unused in this
2343 * \see nrs_resource_get_safe()
2345 static int nrs_tbf_res_get(struct ptlrpc_nrs_policy *policy,
2346 struct ptlrpc_nrs_request *nrq,
2347 const struct ptlrpc_nrs_resource *parent,
2348 struct ptlrpc_nrs_resource **resp,
2351 struct nrs_tbf_head *head;
2352 struct nrs_tbf_client *cli;
2353 struct nrs_tbf_client *tmp;
2354 struct ptlrpc_request *req;
2356 if (parent == NULL) {
2357 *resp = &((struct nrs_tbf_head *)policy->pol_private)->th_res;
2361 head = container_of(parent, struct nrs_tbf_head, th_res);
2362 req = container_of(nrq, struct ptlrpc_request, rq_nrq);
2363 cli = head->th_ops->o_cli_find(head, req);
2365 spin_lock(&policy->pol_nrs->nrs_svcpt->scp_req_lock);
2366 LASSERT(cli->tc_rule);
2367 if (cli->tc_rule_sequence !=
2368 atomic_read(&head->th_rule_sequence) ||
2369 cli->tc_rule->tr_flags & NTRS_STOPPING) {
2370 struct nrs_tbf_rule *rule;
2373 "TBF class@%p rate %llu sequence %d, "
2374 "rule flags %d, head sequence %d\n",
2375 cli, cli->tc_rpc_rate,
2376 cli->tc_rule_sequence,
2377 cli->tc_rule->tr_flags,
2378 atomic_read(&head->th_rule_sequence));
2379 rule = nrs_tbf_rule_match(head, cli);
2380 if (rule != cli->tc_rule) {
2381 nrs_tbf_cli_reset(head, rule, cli);
2383 if (cli->tc_rule_generation != rule->tr_generation)
2384 nrs_tbf_cli_reset_value(head, cli);
2385 nrs_tbf_rule_put(rule);
2387 } else if (cli->tc_rule_generation !=
2388 cli->tc_rule->tr_generation) {
2389 nrs_tbf_cli_reset_value(head, cli);
2391 spin_unlock(&policy->pol_nrs->nrs_svcpt->scp_req_lock);
2395 OBD_CPT_ALLOC_GFP(cli, nrs_pol2cptab(policy), nrs_pol2cptid(policy),
2396 sizeof(*cli), moving_req ? GFP_ATOMIC : __GFP_IO);
2400 nrs_tbf_cli_init(head, cli, req);
2401 tmp = head->th_ops->o_cli_findadd(head, cli);
2403 atomic_dec(&cli->tc_ref);
2404 nrs_tbf_cli_fini(cli);
2408 *resp = &cli->tc_res;
2414 * Called when releasing references to the resource hierachy obtained for a
2415 * request for scheduling using the TBF policy.
2417 * \param[in] policy the policy the resource belongs to
2418 * \param[in] res the resource to be released
2420 static void nrs_tbf_res_put(struct ptlrpc_nrs_policy *policy,
2421 const struct ptlrpc_nrs_resource *res)
2423 struct nrs_tbf_head *head;
2424 struct nrs_tbf_client *cli;
2427 * Do nothing for freeing parent, nrs_tbf_net resources
2429 if (res->res_parent == NULL)
2432 cli = container_of(res, struct nrs_tbf_client, tc_res);
2433 head = container_of(res->res_parent, struct nrs_tbf_head, th_res);
2435 head->th_ops->o_cli_put(head, cli);
2439 * Called when getting a request from the TBF policy for handling, or just
2440 * peeking; removes the request from the policy when it is to be handled.
2442 * \param[in] policy The policy
2443 * \param[in] peek When set, signifies that we just want to examine the
2444 * request, and not handle it, so the request is not removed
2446 * \param[in] force Force the policy to return a request; unused in this
2449 * \retval The request to be handled; this is the next request in the TBF
2452 * \see ptlrpc_nrs_req_get_nolock()
2453 * \see nrs_request_get()
2456 struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
2457 bool peek, bool force)
2459 struct nrs_tbf_head *head = policy->pol_private;
2460 struct ptlrpc_nrs_request *nrq = NULL;
2461 struct nrs_tbf_client *cli;
2462 struct cfs_binheap_node *node;
2464 assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock);
2466 if (!peek && policy->pol_nrs->nrs_throttling)
2469 node = cfs_binheap_root(head->th_binheap);
2470 if (unlikely(node == NULL))
2473 cli = container_of(node, struct nrs_tbf_client, tc_node);
2474 LASSERT(cli->tc_in_heap);
2476 nrq = list_entry(cli->tc_list.next,
2477 struct ptlrpc_nrs_request,
2480 __u64 now = ktime_to_ns(ktime_get());
2485 deadline = cli->tc_check_time +
2487 LASSERT(now >= cli->tc_check_time);
2488 passed = now - cli->tc_check_time;
2489 ntoken = passed * cli->tc_rpc_rate;
2490 do_div(ntoken, NSEC_PER_SEC);
2491 ntoken += cli->tc_ntoken;
2492 if (ntoken > cli->tc_depth)
2493 ntoken = cli->tc_depth;
2495 struct ptlrpc_request *req;
2496 nrq = list_entry(cli->tc_list.next,
2497 struct ptlrpc_nrs_request,
2499 req = container_of(nrq,
2500 struct ptlrpc_request,
2503 cli->tc_ntoken = ntoken;
2504 cli->tc_check_time = now;
2505 list_del_init(&nrq->nr_u.tbf.tr_list);
2506 if (list_empty(&cli->tc_list)) {
2507 cfs_binheap_remove(head->th_binheap,
2509 cli->tc_in_heap = false;
2511 cfs_binheap_relocate(head->th_binheap,
2515 "TBF dequeues: class@%p rate %llu gen %llu "
2516 "token %llu, rule@%p rate %llu gen %llu\n",
2517 cli, cli->tc_rpc_rate,
2518 cli->tc_rule_generation, cli->tc_ntoken,
2519 cli->tc_rule, cli->tc_rule->tr_rpc_rate,
2520 cli->tc_rule->tr_generation);
2524 policy->pol_nrs->nrs_throttling = 1;
2525 head->th_deadline = deadline;
2526 time = ktime_set(0, 0);
2527 time = ktime_add_ns(time, deadline);
2528 hrtimer_start(&head->th_timer, time, HRTIMER_MODE_ABS);
2536 * Adds request \a nrq to \a policy's list of queued requests
2538 * \param[in] policy The policy
2539 * \param[in] nrq The request to add
2541 * \retval 0 success; nrs_request_enqueue() assumes this function will always
2544 static int nrs_tbf_req_add(struct ptlrpc_nrs_policy *policy,
2545 struct ptlrpc_nrs_request *nrq)
2547 struct nrs_tbf_head *head;
2548 struct nrs_tbf_client *cli;
2551 assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock);
2553 cli = container_of(nrs_request_resource(nrq),
2554 struct nrs_tbf_client, tc_res);
2555 head = container_of(nrs_request_resource(nrq)->res_parent,
2556 struct nrs_tbf_head, th_res);
2557 if (list_empty(&cli->tc_list)) {
2558 LASSERT(!cli->tc_in_heap);
2559 rc = cfs_binheap_insert(head->th_binheap, &cli->tc_node);
2561 cli->tc_in_heap = true;
2562 nrq->nr_u.tbf.tr_sequence = head->th_sequence++;
2563 list_add_tail(&nrq->nr_u.tbf.tr_list,
2565 if (policy->pol_nrs->nrs_throttling) {
2566 __u64 deadline = cli->tc_check_time +
2568 if ((head->th_deadline > deadline) &&
2569 (hrtimer_try_to_cancel(&head->th_timer)
2572 head->th_deadline = deadline;
2573 time = ktime_set(0, 0);
2574 time = ktime_add_ns(time, deadline);
2575 hrtimer_start(&head->th_timer, time,
2581 LASSERT(cli->tc_in_heap);
2582 nrq->nr_u.tbf.tr_sequence = head->th_sequence++;
2583 list_add_tail(&nrq->nr_u.tbf.tr_list,
2589 "TBF enqueues: class@%p rate %llu gen %llu "
2590 "token %llu, rule@%p rate %llu gen %llu\n",
2591 cli, cli->tc_rpc_rate,
2592 cli->tc_rule_generation, cli->tc_ntoken,
2593 cli->tc_rule, cli->tc_rule->tr_rpc_rate,
2594 cli->tc_rule->tr_generation);
2600 * Removes request \a nrq from \a policy's list of queued requests.
2602 * \param[in] policy The policy
2603 * \param[in] nrq The request to remove
2605 static void nrs_tbf_req_del(struct ptlrpc_nrs_policy *policy,
2606 struct ptlrpc_nrs_request *nrq)
2608 struct nrs_tbf_head *head;
2609 struct nrs_tbf_client *cli;
2611 assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock);
2613 cli = container_of(nrs_request_resource(nrq),
2614 struct nrs_tbf_client, tc_res);
2615 head = container_of(nrs_request_resource(nrq)->res_parent,
2616 struct nrs_tbf_head, th_res);
2618 LASSERT(!list_empty(&nrq->nr_u.tbf.tr_list));
2619 list_del_init(&nrq->nr_u.tbf.tr_list);
2620 if (list_empty(&cli->tc_list)) {
2621 cfs_binheap_remove(head->th_binheap,
2623 cli->tc_in_heap = false;
2625 cfs_binheap_relocate(head->th_binheap,
2631 * Prints a debug statement right before the request \a nrq stops being
2634 * \param[in] policy The policy handling the request
2635 * \param[in] nrq The request being handled
2637 * \see ptlrpc_server_finish_request()
2638 * \see ptlrpc_nrs_req_stop_nolock()
2640 static void nrs_tbf_req_stop(struct ptlrpc_nrs_policy *policy,
2641 struct ptlrpc_nrs_request *nrq)
2643 struct ptlrpc_request *req = container_of(nrq, struct ptlrpc_request,
2646 assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock);
2648 CDEBUG(D_RPCTRACE, "NRS stop %s request from %s, seq: %llu\n",
2649 policy->pol_desc->pd_name, libcfs_id2str(req->rq_peer),
2650 nrq->nr_u.tbf.tr_sequence);
2653 #ifdef CONFIG_PROC_FS
2660 * The maximum RPC rate.
2662 #define LPROCFS_NRS_RATE_MAX 65535
2665 ptlrpc_lprocfs_nrs_tbf_rule_seq_show(struct seq_file *m, void *data)
2667 struct ptlrpc_service *svc = m->private;
2670 seq_printf(m, "regular_requests:\n");
2672 * Perform two separate calls to this as only one of the NRS heads'
2673 * policies may be in the ptlrpc_nrs_pol_state::NRS_POL_STATE_STARTED or
2674 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPING state.
2676 rc = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_REG,
2678 NRS_CTL_TBF_RD_RULE,
2682 * -ENOSPC means buf in the parameter m is overflow, return 0
2683 * here to let upper layer function seq_read alloc a larger
2684 * memory area and do this process again.
2686 } else if (rc == -ENOSPC) {
2690 * Ignore -ENODEV as the regular NRS head's policy may be in the
2691 * ptlrpc_nrs_pol_state::NRS_POL_STATE_STOPPED state.
2693 } else if (rc != -ENODEV) {
2697 if (!nrs_svc_has_hp(svc))
2700 seq_printf(m, "high_priority_requests:\n");
2701 rc = ptlrpc_nrs_policy_control(svc, PTLRPC_NRS_QUEUE_HP,
2703 NRS_CTL_TBF_RD_RULE,
2707 * -ENOSPC means buf in the parameter m is overflow, return 0
2708 * here to let upper layer function seq_read alloc a larger
2709 * memory area and do this process again.
2711 } else if (rc == -ENOSPC) {
2720 static int nrs_tbf_id_parse(struct nrs_tbf_cmd *cmd, char *token)
2724 switch (cmd->u.tc_start.ts_valid_type) {
2725 case NRS_TBF_FLAG_JOBID:
2726 rc = nrs_tbf_jobid_parse(cmd, token);
2728 case NRS_TBF_FLAG_NID:
2729 rc = nrs_tbf_nid_parse(cmd, token);
2731 case NRS_TBF_FLAG_OPCODE:
2732 rc = nrs_tbf_opcode_parse(cmd, token);
2734 case NRS_TBF_FLAG_GENERIC:
2735 rc = nrs_tbf_generic_parse(cmd, token);
2744 static void nrs_tbf_cmd_fini(struct nrs_tbf_cmd *cmd)
2746 if (cmd->tc_cmd == NRS_CTL_TBF_START_RULE) {
2747 if (cmd->u.tc_start.ts_valid_type == NRS_TBF_FLAG_JOBID)
2748 nrs_tbf_jobid_cmd_fini(cmd);
2749 else if (cmd->u.tc_start.ts_valid_type == NRS_TBF_FLAG_NID)
2750 nrs_tbf_nid_cmd_fini(cmd);
2751 else if (cmd->u.tc_start.ts_valid_type == NRS_TBF_FLAG_OPCODE)
2752 nrs_tbf_opcode_cmd_fini(cmd);
2753 else if (cmd->u.tc_start.ts_valid_type == NRS_TBF_FLAG_GENERIC)
2754 nrs_tbf_generic_cmd_fini(cmd);
2758 static bool name_is_valid(const char *name)
2762 for (i = 0; i < strlen(name); i++) {
2763 if ((!isalnum(name[i])) &&
2771 nrs_tbf_parse_value_pair(struct nrs_tbf_cmd *cmd, char *buffer)
2779 key = strsep(&val, "=");
2780 if (val == NULL || strlen(val) == 0)
2783 /* Key of the value pair */
2784 if (strcmp(key, "rate") == 0) {
2785 rc = kstrtoull(val, 10, &rate);
2789 if (rate <= 0 || rate >= LPROCFS_NRS_RATE_MAX)
2792 if (cmd->tc_cmd == NRS_CTL_TBF_START_RULE)
2793 cmd->u.tc_start.ts_rpc_rate = rate;
2794 else if (cmd->tc_cmd == NRS_CTL_TBF_CHANGE_RULE)
2795 cmd->u.tc_change.tc_rpc_rate = rate;
2798 } else if (strcmp(key, "rank") == 0) {
2799 if (!name_is_valid(val))
2802 if (cmd->tc_cmd == NRS_CTL_TBF_START_RULE)
2803 cmd->u.tc_start.ts_next_name = val;
2804 else if (cmd->tc_cmd == NRS_CTL_TBF_CHANGE_RULE)
2805 cmd->u.tc_change.tc_next_name = val;
2815 nrs_tbf_parse_value_pairs(struct nrs_tbf_cmd *cmd, char *buffer)
2822 while (val != NULL && strlen(val) != 0) {
2823 token = strsep(&val, " ");
2824 rc = nrs_tbf_parse_value_pair(cmd, token);
2829 switch (cmd->tc_cmd) {
2830 case NRS_CTL_TBF_START_RULE:
2831 if (cmd->u.tc_start.ts_rpc_rate == 0)
2832 cmd->u.tc_start.ts_rpc_rate = tbf_rate;
2834 case NRS_CTL_TBF_CHANGE_RULE:
2835 if (cmd->u.tc_change.tc_rpc_rate == 0 &&
2836 cmd->u.tc_change.tc_next_name == NULL)
2839 case NRS_CTL_TBF_STOP_RULE:
2847 static struct nrs_tbf_cmd *
2848 nrs_tbf_parse_cmd(char *buffer, unsigned long count, __u32 type_flag)
2850 static struct nrs_tbf_cmd *cmd;
2857 GOTO(out, rc = -ENOMEM);
2858 memset(cmd, 0, sizeof(*cmd));
2861 token = strsep(&val, " ");
2862 if (val == NULL || strlen(val) == 0)
2863 GOTO(out_free_cmd, rc = -EINVAL);
2865 /* Type of the command */
2866 if (strcmp(token, "start") == 0) {
2867 cmd->tc_cmd = NRS_CTL_TBF_START_RULE;
2868 cmd->u.tc_start.ts_valid_type = type_flag;
2869 } else if (strcmp(token, "stop") == 0)
2870 cmd->tc_cmd = NRS_CTL_TBF_STOP_RULE;
2871 else if (strcmp(token, "change") == 0)
2872 cmd->tc_cmd = NRS_CTL_TBF_CHANGE_RULE;
2874 GOTO(out_free_cmd, rc = -EINVAL);
2876 /* Name of the rule */
2877 token = strsep(&val, " ");
2878 if ((val == NULL && cmd->tc_cmd != NRS_CTL_TBF_STOP_RULE) ||
2879 !name_is_valid(token))
2880 GOTO(out_free_cmd, rc = -EINVAL);
2881 cmd->tc_name = token;
2883 if (cmd->tc_cmd == NRS_CTL_TBF_START_RULE) {
2887 val = strrchr(token, '}');
2889 GOTO(out_free_cmd, rc = -EINVAL);
2895 } else if (*val == ' ') {
2899 GOTO(out_free_cmd, rc = -EINVAL);
2901 rc = nrs_tbf_id_parse(cmd, token);
2903 GOTO(out_free_cmd, rc);
2906 rc = nrs_tbf_parse_value_pairs(cmd, val);
2908 GOTO(out_cmd_fini, rc = -EINVAL);
2911 nrs_tbf_cmd_fini(cmd);
2921 * Get the TBF policy type (nid, jobid, etc) preset by
2922 * proc entry 'nrs_policies' for command buffer parsing.
2924 * \param[in] svc the PTLRPC service
2925 * \param[in] queue the NRS queue type
2927 * \retval the preset TBF policy type flag
2930 nrs_tbf_type_flag(struct ptlrpc_service *svc, enum ptlrpc_nrs_queue_type queue)
2935 rc = ptlrpc_nrs_policy_control(svc, queue,
2937 NRS_CTL_TBF_RD_TYPE_FLAG,
2940 type = NRS_TBF_FLAG_INVALID;
2945 extern struct nrs_core nrs_core;
2946 #define LPROCFS_WR_NRS_TBF_MAX_CMD (4096)
2948 ptlrpc_lprocfs_nrs_tbf_rule_seq_write(struct file *file,
2949 const char __user *buffer,
2950 size_t count, loff_t *off)
2952 struct seq_file *m = file->private_data;
2953 struct ptlrpc_service *svc = m->private;
2957 static struct nrs_tbf_cmd *cmd;
2958 enum ptlrpc_nrs_queue_type queue = PTLRPC_NRS_QUEUE_BOTH;
2959 unsigned long length;
2962 OBD_ALLOC(kernbuf, LPROCFS_WR_NRS_TBF_MAX_CMD);
2963 if (kernbuf == NULL)
2964 GOTO(out, rc = -ENOMEM);
2966 if (count > LPROCFS_WR_NRS_TBF_MAX_CMD - 1)
2967 GOTO(out_free_kernbuff, rc = -EINVAL);
2969 if (copy_from_user(kernbuf, buffer, count))
2970 GOTO(out_free_kernbuff, rc = -EFAULT);
2973 token = strsep(&val, " ");
2975 GOTO(out_free_kernbuff, rc = -EINVAL);
2977 if (strcmp(token, "reg") == 0) {
2978 queue = PTLRPC_NRS_QUEUE_REG;
2979 } else if (strcmp(token, "hp") == 0) {
2980 queue = PTLRPC_NRS_QUEUE_HP;
2982 kernbuf[strlen(token)] = ' ';
2985 length = strlen(val);
2988 GOTO(out_free_kernbuff, rc = -EINVAL);
2990 if (queue == PTLRPC_NRS_QUEUE_HP && !nrs_svc_has_hp(svc))
2991 GOTO(out_free_kernbuff, rc = -ENODEV);
2992 else if (queue == PTLRPC_NRS_QUEUE_BOTH && !nrs_svc_has_hp(svc))
2993 queue = PTLRPC_NRS_QUEUE_REG;
2995 cmd = nrs_tbf_parse_cmd(val, length, nrs_tbf_type_flag(svc, queue));
2997 GOTO(out_free_kernbuff, rc = PTR_ERR(cmd));
3000 * Serialize NRS core lprocfs operations with policy registration/
3003 mutex_lock(&nrs_core.nrs_mutex);
3004 rc = ptlrpc_nrs_policy_control(svc, queue,
3006 NRS_CTL_TBF_WR_RULE,
3008 mutex_unlock(&nrs_core.nrs_mutex);
3010 nrs_tbf_cmd_fini(cmd);
3013 OBD_FREE(kernbuf, LPROCFS_WR_NRS_TBF_MAX_CMD);
3015 return rc ? rc : count;
3017 LPROC_SEQ_FOPS(ptlrpc_lprocfs_nrs_tbf_rule);
3020 * Initializes a TBF policy's lprocfs interface for service \a svc
3022 * \param[in] svc the service
3025 * \retval != 0 error
3027 static int nrs_tbf_lprocfs_init(struct ptlrpc_service *svc)
3029 struct lprocfs_vars nrs_tbf_lprocfs_vars[] = {
3030 { .name = "nrs_tbf_rule",
3031 .fops = &ptlrpc_lprocfs_nrs_tbf_rule_fops,
3036 if (svc->srv_procroot == NULL)
3039 return lprocfs_add_vars(svc->srv_procroot, nrs_tbf_lprocfs_vars, NULL);
3043 * Cleans up a TBF policy's lprocfs interface for service \a svc
3045 * \param[in] svc the service
3047 static void nrs_tbf_lprocfs_fini(struct ptlrpc_service *svc)
3049 if (svc->srv_procroot == NULL)
3052 lprocfs_remove_proc_entry("nrs_tbf_rule", svc->srv_procroot);
3055 #endif /* CONFIG_PROC_FS */
3058 * TBF policy operations
3060 static const struct ptlrpc_nrs_pol_ops nrs_tbf_ops = {
3061 .op_policy_start = nrs_tbf_start,
3062 .op_policy_stop = nrs_tbf_stop,
3063 .op_policy_ctl = nrs_tbf_ctl,
3064 .op_res_get = nrs_tbf_res_get,
3065 .op_res_put = nrs_tbf_res_put,
3066 .op_req_get = nrs_tbf_req_get,
3067 .op_req_enqueue = nrs_tbf_req_add,
3068 .op_req_dequeue = nrs_tbf_req_del,
3069 .op_req_stop = nrs_tbf_req_stop,
3070 #ifdef CONFIG_PROC_FS
3071 .op_lprocfs_init = nrs_tbf_lprocfs_init,
3072 .op_lprocfs_fini = nrs_tbf_lprocfs_fini,
3077 * TBF policy configuration
3079 struct ptlrpc_nrs_pol_conf nrs_conf_tbf = {
3080 .nc_name = NRS_POL_NAME_TBF,
3081 .nc_ops = &nrs_tbf_ops,
3082 .nc_compat = nrs_policy_compat_all,
3089 #endif /* HAVE_SERVER_SUPPORT */