diff --git a/modules/cas_cache/classifier.c b/modules/cas_cache/classifier.c index 00dd008..99e4220 100644 --- a/modules/cas_cache/classifier.c +++ b/modules/cas_cache/classifier.c @@ -185,6 +185,34 @@ error: return result; } +/* String condition constructor. @data is expected to contain string + * to be matched. */ +static int _cas_cls_string_ctr(struct cas_classifier *cls, + struct cas_cls_condition *c, char *data) +{ + struct cas_cls_string *ctx; + + if (!data || strlen(data) == 0) { + CAS_CLS_MSG(KERN_ERR, "Missing string specifier\n"); + return -EINVAL; + } + + if (strlen(data) > MAX_STRING_SPECIFIER_LEN) { + CAS_CLS_MSG(KERN_ERR, "String specifier to long: %s\n", data); + return -EINVAL; + } + + ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + strcpy(ctx->string, data); + + c->context = ctx; + + return 0; +} + /* Unsigned int numeric test function */ static cas_cls_eval_t _cas_cls_numeric_test_u( struct cas_cls_condition *c, uint64_t val) diff --git a/modules/cas_cache/classifier_defs.h b/modules/cas_cache/classifier_defs.h index 0ce3809..52c4a58 100644 --- a/modules/cas_cache/classifier_defs.h +++ b/modules/cas_cache/classifier_defs.h @@ -6,6 +6,8 @@ #ifndef __CLASSIFIER_DEFS_H__ #define __CLASSIFIER_DEFS_H__ +#define MAX_STRING_SPECIFIER_LEN 256 + /* Rule matches 1:1 with io class. It contains multiple conditions with * associated logical operator (and/or) */ struct cas_cls_rule { @@ -118,6 +120,12 @@ struct cas_cls_numeric { uint64_t v_u64; }; +/* String condition context */ +struct cas_cls_string { + /* String specifier*/ + char string[MAX_STRING_SPECIFIER_LEN]; +}; + /* Directory condition context */ struct cas_cls_directory { /* 1 if directory had been resolved */