Whamcloud - gitweb
LU-9679 nrs: remove ts_opcodes bitmap.
[fs/lustre-release.git] / lustre / ptlrpc / nrs_tbf.c
index d5fab11..76c8e4c 100644 (file)
@@ -132,7 +132,7 @@ nrs_tbf_cli_reset_value(struct nrs_tbf_head *head,
        struct nrs_tbf_rule *rule = cli->tc_rule;
 
        cli->tc_rpc_rate = rule->tr_rpc_rate;
-       cli->tc_nsecs = rule->tr_nsecs;
+       cli->tc_nsecs = rule->tr_nsecs_per_rpc;
        cli->tc_depth = rule->tr_depth;
        cli->tc_ntoken = rule->tr_depth;
        cli->tc_check_time = ktime_to_ns(ktime_get());
@@ -302,8 +302,7 @@ nrs_tbf_rule_start(struct ptlrpc_nrs_policy *policy,
        memcpy(rule->tr_name, start->tc_name, strlen(start->tc_name));
        rule->tr_rpc_rate = start->u.tc_start.ts_rpc_rate;
        rule->tr_flags = start->u.tc_start.ts_rule_flags;
-       rule->tr_nsecs = NSEC_PER_SEC;
-       do_div(rule->tr_nsecs, rule->tr_rpc_rate);
+       rule->tr_nsecs_per_rpc = NSEC_PER_SEC / rule->tr_rpc_rate;
        rule->tr_depth = tbf_depth;
        atomic_set(&rule->tr_ref, 1);
        INIT_LIST_HEAD(&rule->tr_cli_list);
@@ -350,7 +349,7 @@ nrs_tbf_rule_start(struct ptlrpc_nrs_policy *policy,
                head->th_rule = rule;
        }
 
-       CDEBUG(D_RPCTRACE, "TBF starts rule@%p rate %llu gen %llu\n",
+       CDEBUG(D_RPCTRACE, "TBF starts rule@%p rate %u gen %llu\n",
               rule, rule->tr_rpc_rate, rule->tr_generation);
 
        return 0;
@@ -417,8 +416,7 @@ nrs_tbf_rule_change_rate(struct ptlrpc_nrs_policy *policy,
                return -ENOENT;
 
        rule->tr_rpc_rate = rate;
-       rule->tr_nsecs = NSEC_PER_SEC;
-       do_div(rule->tr_nsecs, rule->tr_rpc_rate);
+       rule->tr_nsecs_per_rpc = NSEC_PER_SEC / rule->tr_rpc_rate;
        rule->tr_generation++;
        nrs_tbf_rule_put(rule);
 
@@ -632,7 +630,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;
@@ -688,9 +686,8 @@ nrs_tbf_jobid_cli_put(struct nrs_tbf_head *head,
        struct cfs_hash         *hs = head->th_cli_hash;
        struct nrs_tbf_bucket   *bkt;
        int                      hw;
-       struct list_head        zombies;
+       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))
@@ -716,8 +713,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);
        }
@@ -807,7 +804,7 @@ nrs_tbf_jobid_list_free(struct list_head *jobid_list)
        list_for_each_entry_safe(jobid, n, jobid_list, tj_linkage) {
                OBD_FREE(jobid->tj_id, strlen(jobid->tj_id) + 1);
                list_del(&jobid->tj_linkage);
-               OBD_FREE(jobid, sizeof(struct nrs_tbf_jobid));
+               OBD_FREE_PTR(jobid);
        }
 }
 
@@ -817,13 +814,13 @@ nrs_tbf_jobid_list_add(struct cfs_lstr *id, struct list_head *jobid_list)
        struct nrs_tbf_jobid *jobid;
        char *ptr;
 
-       OBD_ALLOC(jobid, sizeof(struct nrs_tbf_jobid));
+       OBD_ALLOC_PTR(jobid);
        if (jobid == NULL)
                return -ENOMEM;
 
        OBD_ALLOC(jobid->tj_id, id->ls_len + 1);
        if (jobid->tj_id == NULL) {
-               OBD_FREE(jobid, sizeof(struct nrs_tbf_jobid));
+               OBD_FREE_PTR(jobid);
                return -ENOMEM;
        }
 
@@ -1003,7 +1000,7 @@ static int nrs_tbf_jobid_rule_init(struct ptlrpc_nrs_policy *policy,
 static int
 nrs_tbf_jobid_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
 {
-       seq_printf(m, "%s {%s} %llu, ref %d\n", rule->tr_name,
+       seq_printf(m, "%s {%s} %u, ref %d\n", rule->tr_name,
                   rule->tr_jobids_str, rule->tr_rpc_rate,
                   atomic_read(&rule->tr_ref) - 1);
        return 0;
@@ -1208,7 +1205,7 @@ static int nrs_tbf_nid_rule_init(struct ptlrpc_nrs_policy *policy,
 static int
 nrs_tbf_nid_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
 {
-       seq_printf(m, "%s {%s} %llu, ref %d\n", rule->tr_name,
+       seq_printf(m, "%s {%s} %u, ref %d\n", rule->tr_name,
                   rule->tr_nids_str, rule->tr_rpc_rate,
                   atomic_read(&rule->tr_ref) - 1);
        return 0;
@@ -1399,7 +1396,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;
@@ -1697,9 +1694,8 @@ nrs_tbf_cli_put(struct nrs_tbf_head *head, struct nrs_tbf_client *cli)
        struct cfs_hash         *hs = head->th_cli_hash;
        struct nrs_tbf_bucket   *bkt;
        int                      hw;
-       struct list_head         zombies;
+       LIST_HEAD(zombies);
 
-       INIT_LIST_HEAD(&zombies);
        cfs_hash_bd_get(hs, &cli->tc_key, &bd);
        bkt = cfs_hash_bd_extra_get(hs, &bd);
        if (!cfs_hash_bd_dec_and_lock(hs, &bd, &cli->tc_ref))
@@ -1724,8 +1720,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);
        }
@@ -1840,7 +1836,7 @@ nrs_tbf_expression_parse(struct cfs_lstr *src, struct list_head *cond_list)
        struct cfs_lstr field;
        int rc = 0;
 
-       OBD_ALLOC(expr, sizeof(struct nrs_tbf_expression));
+       OBD_ALLOC_PTR(expr);
        if (expr == NULL)
                return -ENOMEM;
 
@@ -1903,7 +1899,7 @@ nrs_tbf_conjunction_parse(struct cfs_lstr *src, struct list_head *cond_list)
        struct cfs_lstr expr;
        int rc = 0;
 
-       OBD_ALLOC(conjunction, sizeof(struct nrs_tbf_conjunction));
+       OBD_ALLOC_PTR(conjunction);
        if (conjunction == NULL)
                return -ENOMEM;
 
@@ -2063,7 +2059,7 @@ nrs_tbf_rule_init(struct ptlrpc_nrs_policy *policy,
 static int
 nrs_tbf_generic_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
 {
-       seq_printf(m, "%s %s %llu, ref %d\n", rule->tr_name,
+       seq_printf(m, "%s %s %u, ref %d\n", rule->tr_name,
                   rule->tr_conds_str, rule->tr_rpc_rate,
                   atomic_read(&rule->tr_ref) - 1);
        return 0;
@@ -2186,7 +2182,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;
@@ -2269,7 +2264,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);
@@ -2279,9 +2274,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);
@@ -2308,7 +2300,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);
 
@@ -2341,7 +2333,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,
@@ -2357,7 +2349,7 @@ static int nrs_tbf_opcode_rule_init(struct ptlrpc_nrs_policy *policy,
 static int
 nrs_tbf_opcode_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
 {
-       seq_printf(m, "%s {%s} %llu, ref %d\n", rule->tr_name,
+       seq_printf(m, "%s {%s} %u, ref %d\n", rule->tr_name,
                   rule->tr_opcodes_str, rule->tr_rpc_rate,
                   atomic_read(&rule->tr_ref) - 1);
        return 0;
@@ -2672,7 +2664,7 @@ nrs_tbf_id_rule_init(struct ptlrpc_nrs_policy *policy,
 static int
 nrs_tbf_id_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m)
 {
-       seq_printf(m, "%s {%s} %llu, ref %d\n", rule->tr_name,
+       seq_printf(m, "%s {%s} %u, ref %d\n", rule->tr_name,
                   rule->tr_ids_str, rule->tr_rpc_rate,
                   atomic_read(&rule->tr_ref) - 1);
        return 0;
@@ -2885,7 +2877,7 @@ static int nrs_tbf_ctl(struct ptlrpc_nrs_policy *policy,
         */
        case NRS_CTL_TBF_RD_RULE: {
                struct nrs_tbf_head *head = policy->pol_private;
-               struct seq_file *m = (struct seq_file *) arg;
+               struct seq_file *m = arg;
                struct ptlrpc_service_part *svcpt;
 
                svcpt = policy->pol_nrs->nrs_svcpt;
@@ -2963,7 +2955,7 @@ static int nrs_tbf_res_get(struct ptlrpc_nrs_policy *policy,
                        struct nrs_tbf_rule *rule;
 
                        CDEBUG(D_RPCTRACE,
-                              "TBF class@%p rate %llu sequence %d, "
+                              "TBF class@%p rate %u sequence %d, "
                               "rule flags %d, head sequence %d\n",
                               cli, cli->tc_rpc_rate,
                               cli->tc_rule_sequence,
@@ -3119,8 +3111,8 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
                                                     &cli->tc_node);
                        }
                        CDEBUG(D_RPCTRACE,
-                              "TBF dequeues: class@%p rate %llu gen %llu "
-                              "token %llu, rule@%p rate %llu gen %llu\n",
+                              "TBF dequeues: class@%p rate %u gen %llu "
+                              "token %llu, rule@%p rate %u gen %llu\n",
                               cli, cli->tc_rpc_rate,
                               cli->tc_rule_generation, cli->tc_ntoken,
                               cli->tc_rule, cli->tc_rule->tr_rpc_rate,
@@ -3202,8 +3194,8 @@ static int nrs_tbf_req_add(struct ptlrpc_nrs_policy *policy,
 
        if (rc == 0)
                CDEBUG(D_RPCTRACE,
-                      "TBF enqueues: class@%p rate %llu gen %llu "
-                      "token %llu, rule@%p rate %llu gen %llu\n",
+                      "TBF enqueues: class@%p rate %u gen %llu "
+                      "token %llu, rule@%p rate %u gen %llu\n",
                       cli, cli->tc_rpc_rate,
                       cli->tc_rule_generation, cli->tc_ntoken,
                       cli->tc_rule, cli->tc_rule->tr_rpc_rate,
@@ -3677,8 +3669,9 @@ static int nrs_tbf_lprocfs_init(struct ptlrpc_service *svc)
        if (!svc->srv_debugfs_entry)
                return 0;
 
-       return ldebugfs_add_vars(svc->srv_debugfs_entry, nrs_tbf_lprocfs_vars,
-                                NULL);
+       ldebugfs_add_vars(svc->srv_debugfs_entry, nrs_tbf_lprocfs_vars, NULL);
+
+       return 0;
 }
 
 /**