Whamcloud - gitweb
LU-6142 lustre: ptlrpc: don't use list_for_each_entry_safe unnecessarily.
[fs/lustre-release.git] / lustre / ptlrpc / nrs_tbf.c
index e15f54d..32adf79 100644 (file)
@@ -31,8 +31,6 @@
  *
  */
 
-#ifdef HAVE_SERVER_SUPPORT
-
 /**
  * \addtogoup nrs
  * @{
@@ -140,8 +138,8 @@ nrs_tbf_cli_reset_value(struct nrs_tbf_head *head,
        cli->tc_rule_generation = rule->tr_generation;
 
        if (cli->tc_in_heap)
-               cfs_binheap_relocate(head->th_binheap,
-                                    &cli->tc_node);
+               binheap_relocate(head->th_binheap,
+                                &cli->tc_node);
 }
 
 static void
@@ -513,7 +511,7 @@ nrs_tbf_command(struct ptlrpc_nrs_policy *policy,
  * \retval 1 e1 < e2
  */
 static int
-tbf_cli_compare(struct cfs_binheap_node *e1, struct cfs_binheap_node *e2)
+tbf_cli_compare(struct binheap_node *e1, struct binheap_node *e2)
 {
        struct nrs_tbf_client *cli1;
        struct nrs_tbf_client *cli2;
@@ -538,7 +536,7 @@ tbf_cli_compare(struct cfs_binheap_node *e1, struct cfs_binheap_node *e2)
 /**
  * TBF binary heap operations
  */
-static struct cfs_binheap_ops nrs_tbf_heap_ops = {
+static struct binheap_ops nrs_tbf_heap_ops = {
        .hop_enter      = NULL,
        .hop_exit       = NULL,
        .hop_compare    = tbf_cli_compare,
@@ -630,7 +628,7 @@ nrs_tbf_jobid_hash_lookup(struct cfs_hash *hs,
        if (hnode == NULL)
                return NULL;
 
-       cli = container_of0(hnode, struct nrs_tbf_client, tc_hnode);
+       cli = container_of(hnode, struct nrs_tbf_client, tc_hnode);
        if (!list_empty(&cli->tc_lru))
                list_del_init(&cli->tc_lru);
        return cli;
@@ -713,8 +711,8 @@ nrs_tbf_jobid_cli_put(struct nrs_tbf_head *head,
        cfs_hash_bd_unlock(head->th_cli_hash, &bd, 1);
 
        while (!list_empty(&zombies)) {
-               cli = container_of0(zombies.next,
-                                   struct nrs_tbf_client, tc_lru);
+               cli = container_of(zombies.next,
+                                  struct nrs_tbf_client, tc_lru);
                list_del_init(&cli->tc_lru);
                nrs_tbf_cli_fini(cli);
        }
@@ -1396,7 +1394,7 @@ nrs_tbf_cli_hash_lookup(struct cfs_hash *hs, struct cfs_hash_bd *bd,
        if (hnode == NULL)
                return NULL;
 
-       cli = container_of0(hnode, struct nrs_tbf_client, tc_hnode);
+       cli = container_of(hnode, struct nrs_tbf_client, tc_hnode);
        if (!list_empty(&cli->tc_lru))
                list_del_init(&cli->tc_lru);
        return cli;
@@ -1720,8 +1718,8 @@ nrs_tbf_cli_put(struct nrs_tbf_head *head, struct nrs_tbf_client *cli)
        cfs_hash_bd_unlock(head->th_cli_hash, &bd, 1);
 
        while (!list_empty(&zombies)) {
-               cli = container_of0(zombies.next,
-                                   struct nrs_tbf_client, tc_lru);
+               cli = container_of(zombies.next,
+                                  struct nrs_tbf_client, tc_lru);
                list_del_init(&cli->tc_lru);
                nrs_tbf_cli_fini(cli);
        }
@@ -2182,7 +2180,6 @@ nrs_tbf_opcode_startup(struct ptlrpc_nrs_policy *policy,
        if (head->th_cli_hash == NULL)
                return -ENOMEM;
 
-       start.u.tc_start.ts_opcodes = NULL;
        start.u.tc_start.ts_opcodes_str = "*";
 
        start.u.tc_start.ts_rpc_rate = tbf_rate;
@@ -2265,7 +2262,7 @@ nrs_tbf_opcode_list_parse(char *str, int len, struct cfs_bitmap **bitmaptr)
                        break;
        }
 
-       if (rc == 0)
+       if (rc == 0 && bitmaptr)
                *bitmaptr = opcodes;
        else
                CFS_FREE_BITMAP(opcodes);
@@ -2275,9 +2272,6 @@ nrs_tbf_opcode_list_parse(char *str, int len, struct cfs_bitmap **bitmaptr)
 
 static void nrs_tbf_opcode_cmd_fini(struct nrs_tbf_cmd *cmd)
 {
-       if (cmd->u.tc_start.ts_opcodes)
-               CFS_FREE_BITMAP(cmd->u.tc_start.ts_opcodes);
-
        if (cmd->u.tc_start.ts_opcodes_str)
                OBD_FREE(cmd->u.tc_start.ts_opcodes_str,
                         strlen(cmd->u.tc_start.ts_opcodes_str) + 1);
@@ -2304,7 +2298,7 @@ static int nrs_tbf_opcode_parse(struct nrs_tbf_cmd *cmd, char *id)
        /* parse opcode list */
        rc = nrs_tbf_opcode_list_parse(cmd->u.tc_start.ts_opcodes_str,
                                       strlen(cmd->u.tc_start.ts_opcodes_str),
-                                      &cmd->u.tc_start.ts_opcodes);
+                                      NULL);
        if (rc)
                nrs_tbf_opcode_cmd_fini(cmd);
 
@@ -2337,7 +2331,7 @@ static int nrs_tbf_opcode_rule_init(struct ptlrpc_nrs_policy *policy,
                strlen(start->u.tc_start.ts_opcodes_str) + 1);
 
        /* Default rule '*' */
-       if (start->u.tc_start.ts_opcodes == NULL)
+       if (strcmp(start->u.tc_start.ts_opcodes_str, "*") == 0)
                return 0;
 
        rc = nrs_tbf_opcode_list_parse(rule->tr_opcodes_str,
@@ -2790,10 +2784,10 @@ static int nrs_tbf_start(struct ptlrpc_nrs_policy *policy, char *arg)
        head->th_ops = ops;
        head->th_type_flag = type;
 
-       head->th_binheap = cfs_binheap_create(&nrs_tbf_heap_ops,
-                                             CBH_FLAG_ATOMIC_GROW, 4096, NULL,
-                                             nrs_pol2cptab(policy),
-                                             nrs_pol2cptid(policy));
+       head->th_binheap = binheap_create(&nrs_tbf_heap_ops,
+                                         CBH_FLAG_ATOMIC_GROW, 4096, NULL,
+                                         nrs_pol2cptab(policy),
+                                         nrs_pol2cptid(policy));
        if (head->th_binheap == NULL)
                GOTO(out_free_head, rc = -ENOMEM);
 
@@ -2809,7 +2803,7 @@ static int nrs_tbf_start(struct ptlrpc_nrs_policy *policy, char *arg)
        policy->pol_private = head;
        return 0;
 out_free_heap:
-       cfs_binheap_destroy(head->th_binheap);
+       binheap_destroy(head->th_binheap);
 out_free_head:
        OBD_FREE_PTR(head);
 out:
@@ -2842,8 +2836,8 @@ static void nrs_tbf_stop(struct ptlrpc_nrs_policy *policy)
        }
        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);
+       LASSERT(binheap_is_empty(head->th_binheap));
+       binheap_destroy(head->th_binheap);
        OBD_FREE_PTR(head);
        nrs->nrs_throttling = 0;
        wake_up(&policy->pol_nrs->nrs_svcpt->scp_waitq);
@@ -3048,14 +3042,14 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
        struct nrs_tbf_head       *head = policy->pol_private;
        struct ptlrpc_nrs_request *nrq = NULL;
        struct nrs_tbf_client     *cli;
-       struct cfs_binheap_node   *node;
+       struct binheap_node       *node;
 
        assert_spin_locked(&policy->pol_nrs->nrs_svcpt->scp_req_lock);
 
        if (!peek && policy->pol_nrs->nrs_throttling)
                return NULL;
 
-       node = cfs_binheap_root(head->th_binheap);
+       node = binheap_root(head->th_binheap);
        if (unlikely(node == NULL))
                return NULL;
 
@@ -3105,14 +3099,14 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
                        cli->tc_check_time = now;
                        list_del_init(&nrq->nr_u.tbf.tr_list);
                        if (list_empty(&cli->tc_list)) {
-                               cfs_binheap_remove(head->th_binheap,
-                                                  &cli->tc_node);
+                               binheap_remove(head->th_binheap,
+                                              &cli->tc_node);
                                cli->tc_in_heap = false;
                        } else {
                                if (!(rule->tr_flags & NTRS_REALTIME))
                                        cli->tc_deadline = now + cli->tc_nsecs;
-                               cfs_binheap_relocate(head->th_binheap,
-                                                    &cli->tc_node);
+                               binheap_relocate(head->th_binheap,
+                                                &cli->tc_node);
                        }
                        CDEBUG(D_RPCTRACE,
                               "TBF dequeues: class@%p rate %u gen %llu "
@@ -3127,9 +3121,9 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
                        if (rule->tr_flags & NTRS_REALTIME) {
                                cli->tc_deadline = deadline;
                                cli->tc_nsecs_resid = old_resid;
-                               cfs_binheap_relocate(head->th_binheap,
-                                                    &cli->tc_node);
-                               if (node != cfs_binheap_root(head->th_binheap))
+                               binheap_relocate(head->th_binheap,
+                                                &cli->tc_node);
+                               if (node != binheap_root(head->th_binheap))
                                        return nrs_tbf_req_get(policy,
                                                               peek, force);
                        }
@@ -3169,7 +3163,7 @@ static int nrs_tbf_req_add(struct ptlrpc_nrs_policy *policy,
        if (list_empty(&cli->tc_list)) {
                LASSERT(!cli->tc_in_heap);
                cli->tc_deadline = cli->tc_check_time + cli->tc_nsecs;
-               rc = cfs_binheap_insert(head->th_binheap, &cli->tc_node);
+               rc = 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++;
@@ -3230,12 +3224,12 @@ static void nrs_tbf_req_del(struct ptlrpc_nrs_policy *policy,
        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);
+               binheap_remove(head->th_binheap,
+                              &cli->tc_node);
                cli->tc_in_heap = false;
        } else {
-               cfs_binheap_relocate(head->th_binheap,
-                                    &cli->tc_node);
+               binheap_relocate(head->th_binheap,
+                                &cli->tc_node);
        }
 }
 
@@ -3663,7 +3657,7 @@ LDEBUGFS_SEQ_FOPS(ptlrpc_lprocfs_nrs_tbf_rule);
  */
 static int nrs_tbf_lprocfs_init(struct ptlrpc_service *svc)
 {
-       struct lprocfs_vars nrs_tbf_lprocfs_vars[] = {
+       struct ldebugfs_vars nrs_tbf_lprocfs_vars[] = {
                { .name         = "nrs_tbf_rule",
                  .fops         = &ptlrpc_lprocfs_nrs_tbf_rule_fops,
                  .data = svc },
@@ -3706,5 +3700,3 @@ struct ptlrpc_nrs_pol_conf nrs_conf_tbf = {
 /** @} tbf */
 
 /** @} nrs */
-
-#endif /* HAVE_SERVER_SUPPORT */