}
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)
}
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;