Whamcloud - gitweb
LU-9750 nrs: some code cleanup in NRS policies
[fs/lustre-release.git] / lustre / ptlrpc / nrs_tbf.c
index 9fb43e4..c858b6c 100644 (file)
@@ -348,6 +348,9 @@ 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",
+              rule, rule->tr_rpc_rate, rule->tr_generation);
+
        return 0;
 }
 
@@ -809,9 +812,11 @@ nrs_tbf_jobid_list_free(struct list_head *jobid_list)
 }
 
 static int
-nrs_tbf_jobid_list_add(const struct cfs_lstr *id, struct list_head *jobid_list)
+nrs_tbf_jobid_list_add(struct cfs_lstr *id, struct list_head *jobid_list)
 {
        struct nrs_tbf_jobid *jobid;
+       struct cfs_lstr res;
+       int rc;
 
        OBD_ALLOC(jobid, sizeof(struct nrs_tbf_jobid));
        if (jobid == NULL)
@@ -824,17 +829,62 @@ nrs_tbf_jobid_list_add(const struct cfs_lstr *id, struct list_head *jobid_list)
        }
 
        memcpy(jobid->tj_id, id->ls_str, id->ls_len);
+       rc = cfs_gettok(id, '*', &res);
+       if (rc == 0)
+               jobid->tj_match_flag = NRS_TBF_MATCH_FULL;
+       else
+               jobid->tj_match_flag = NRS_TBF_MATCH_WILDCARD;
+
        list_add_tail(&jobid->tj_linkage, jobid_list);
        return 0;
 }
 
+static bool
+cfs_match_wildcard(const char *pattern, const char *content)
+{
+       if (*pattern == '\0' && *content == '\0')
+               return true;
+
+       if (*pattern == '*' && *(pattern + 1) != '\0' && *content == '\0')
+               return false;
+
+       while (*pattern == *content) {
+               pattern++;
+               content++;
+               if (*pattern == '\0' && *content == '\0')
+                       return true;
+
+               if (*pattern == '*' && *(pattern + 1) != '\0' &&
+                   *content == '\0')
+                       return false;
+       }
+
+       if (*pattern == '*')
+               return (cfs_match_wildcard(pattern + 1, content) ||
+                       cfs_match_wildcard(pattern, content + 1));
+
+       return false;
+}
+
+static inline bool
+nrs_tbf_jobid_match(const struct nrs_tbf_jobid *jobid, const char *id)
+{
+       if (jobid->tj_match_flag == NRS_TBF_MATCH_FULL)
+               return strcmp(jobid->tj_id, id) == 0;
+
+       if (jobid->tj_match_flag == NRS_TBF_MATCH_WILDCARD)
+               return cfs_match_wildcard(jobid->tj_id, id);
+
+       return false;
+}
+
 static int
 nrs_tbf_jobid_list_match(struct list_head *jobid_list, char *id)
 {
        struct nrs_tbf_jobid *jobid;
 
        list_for_each_entry(jobid, jobid_list, tj_linkage) {
-               if (strcmp(id, jobid->tj_id) == 0)
+               if (nrs_tbf_jobid_match(jobid, id))
                        return 1;
        }
        return 0;
@@ -2319,11 +2369,21 @@ static int nrs_tbf_res_get(struct ptlrpc_nrs_policy *policy,
                    cli->tc_rule->tr_flags & NTRS_STOPPING) {
                        struct nrs_tbf_rule *rule;
 
+                       CDEBUG(D_RPCTRACE,
+                              "TBF class@%p rate %llu sequence %d, "
+                              "rule flags %d, head sequence %d\n",
+                              cli, cli->tc_rpc_rate,
+                              cli->tc_rule_sequence,
+                              cli->tc_rule->tr_flags,
+                              atomic_read(&head->th_rule_sequence));
                        rule = nrs_tbf_rule_match(head, cli);
-                       if (rule != cli->tc_rule)
+                       if (rule != cli->tc_rule) {
                                nrs_tbf_cli_reset(head, rule, cli);
-                       else
+                       } else {
+                               if (cli->tc_rule_generation != rule->tr_generation)
+                                       nrs_tbf_cli_reset_value(head, cli);
                                nrs_tbf_rule_put(rule);
+                       }
                } else if (cli->tc_rule_generation !=
                           cli->tc_rule->tr_generation) {
                        nrs_tbf_cli_reset_value(head, cli);
@@ -2452,11 +2512,12 @@ struct ptlrpc_nrs_request *nrs_tbf_req_get(struct ptlrpc_nrs_policy *policy,
                                                     &cli->tc_node);
                        }
                        CDEBUG(D_RPCTRACE,
-                              "NRS start %s request from %s, "
-                              "seq: %llu\n",
-                              policy->pol_desc->pd_name,
-                              libcfs_id2str(req->rq_peer),
-                              nrq->nr_u.tbf.tr_sequence);
+                              "TBF dequeues: class@%p rate %llu gen %llu "
+                              "token %llu, rule@%p rate %llu gen %llu\n",
+                              cli, cli->tc_rpc_rate,
+                              cli->tc_rule_generation, cli->tc_ntoken,
+                              cli->tc_rule, cli->tc_rule->tr_rpc_rate,
+                              cli->tc_rule->tr_generation);
                } else {
                        ktime_t time;
 
@@ -2522,6 +2583,16 @@ static int nrs_tbf_req_add(struct ptlrpc_nrs_policy *policy,
                list_add_tail(&nrq->nr_u.tbf.tr_list,
                                  &cli->tc_list);
        }
+
+       if (rc == 0)
+               CDEBUG(D_RPCTRACE,
+                      "TBF enqueues: class@%p rate %llu gen %llu "
+                      "token %llu, rule@%p rate %llu gen %llu\n",
+                      cli, cli->tc_rpc_rate,
+                      cli->tc_rule_generation, cli->tc_ntoken,
+                      cli->tc_rule, cli->tc_rule->tr_rpc_rate,
+                      cli->tc_rule->tr_generation);
+
        return rc;
 }