Introducing a new IO class caching rule - file name prefix
Signed-off-by: Mariusz Barczak <mariusz.barczak@intel.com> Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
parent
9c7b485cef
commit
7facb1e926
@ -190,14 +190,21 @@ error:
|
|||||||
static int _cas_cls_string_ctr(struct cas_classifier *cls,
|
static int _cas_cls_string_ctr(struct cas_classifier *cls,
|
||||||
struct cas_cls_condition *c, char *data)
|
struct cas_cls_condition *c, char *data)
|
||||||
{
|
{
|
||||||
|
size_t len;
|
||||||
struct cas_cls_string *ctx;
|
struct cas_cls_string *ctx;
|
||||||
|
|
||||||
if (!data || strlen(data) == 0) {
|
if (!data) {
|
||||||
CAS_CLS_MSG(KERN_ERR, "Missing string specifier\n");
|
CAS_CLS_MSG(KERN_ERR, "Missing string specifier\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(data) > MAX_STRING_SPECIFIER_LEN) {
|
len = strlen(data);
|
||||||
|
if (len == 0) {
|
||||||
|
CAS_CLS_MSG(KERN_ERR, "String specifier is empty\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len > MAX_STRING_SPECIFIER_LEN) {
|
||||||
CAS_CLS_MSG(KERN_ERR, "String specifier to long: %s\n", data);
|
CAS_CLS_MSG(KERN_ERR, "String specifier to long: %s\n", data);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@ -207,6 +214,7 @@ static int _cas_cls_string_ctr(struct cas_classifier *cls,
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
strcpy(ctx->string, data);
|
strcpy(ctx->string, data);
|
||||||
|
ctx->len = len;
|
||||||
|
|
||||||
c->context = ctx;
|
c->context = ctx;
|
||||||
|
|
||||||
@ -477,6 +485,41 @@ static cas_cls_eval_t _cas_cls_extension_test(
|
|||||||
return cas_cls_eval_no;
|
return cas_cls_eval_no;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* File name prefix test function */
|
||||||
|
static cas_cls_eval_t _cas_cls_file_name_prefix_test(
|
||||||
|
struct cas_classifier *cls, struct cas_cls_condition *c,
|
||||||
|
struct cas_cls_io *io, ocf_part_id_t part_id)
|
||||||
|
{
|
||||||
|
struct cas_cls_string *ctx;
|
||||||
|
struct inode *inode;
|
||||||
|
struct dentry *dentry;
|
||||||
|
uint32_t len;
|
||||||
|
|
||||||
|
ctx = c->context;
|
||||||
|
inode = io->inode;
|
||||||
|
|
||||||
|
if (!inode)
|
||||||
|
return cas_cls_eval_no;
|
||||||
|
|
||||||
|
/* I/O target inode dentry */
|
||||||
|
dentry = _cas_cls_dir_get_inode_dentry(inode);
|
||||||
|
|
||||||
|
/* Check if dentry and its name is valid */
|
||||||
|
if (!dentry || !dentry->d_name.name)
|
||||||
|
return cas_cls_eval_no;
|
||||||
|
|
||||||
|
/* Check if name is not too short, we expect full prefix in name */
|
||||||
|
if (dentry->d_name.len < ctx->len)
|
||||||
|
return cas_cls_eval_no;
|
||||||
|
|
||||||
|
/* Final string comparison check */
|
||||||
|
len = min(ctx->len, dentry->d_name.len);
|
||||||
|
if (strncmp(dentry->d_name.name, ctx->string, len) == 0)
|
||||||
|
return cas_cls_eval_yes;
|
||||||
|
|
||||||
|
return cas_cls_eval_no;
|
||||||
|
}
|
||||||
|
|
||||||
/* LBA test function */
|
/* LBA test function */
|
||||||
static cas_cls_eval_t _cas_cls_lba_test(
|
static cas_cls_eval_t _cas_cls_lba_test(
|
||||||
struct cas_classifier *cls, struct cas_cls_condition *c,
|
struct cas_classifier *cls, struct cas_cls_condition *c,
|
||||||
@ -566,6 +609,8 @@ static struct cas_cls_condition_handler _handlers[] = {
|
|||||||
_cas_cls_directory_dtr },
|
_cas_cls_directory_dtr },
|
||||||
{ "extension", _cas_cls_extension_test, _cas_cls_string_ctr,
|
{ "extension", _cas_cls_extension_test, _cas_cls_string_ctr,
|
||||||
_cas_cls_generic_dtr },
|
_cas_cls_generic_dtr },
|
||||||
|
{ "file_name_prefix", _cas_cls_file_name_prefix_test, _cas_cls_string_ctr,
|
||||||
|
_cas_cls_generic_dtr },
|
||||||
{ "lba", _cas_cls_lba_test, _cas_cls_numeric_ctr, _cas_cls_generic_dtr },
|
{ "lba", _cas_cls_lba_test, _cas_cls_numeric_ctr, _cas_cls_generic_dtr },
|
||||||
{ "pid", _cas_cls_pid_test, _cas_cls_numeric_ctr, _cas_cls_generic_dtr },
|
{ "pid", _cas_cls_pid_test, _cas_cls_numeric_ctr, _cas_cls_generic_dtr },
|
||||||
{ "process_name", _cas_cls_process_name_test, _cas_cls_string_ctr,
|
{ "process_name", _cas_cls_process_name_test, _cas_cls_string_ctr,
|
||||||
|
@ -124,6 +124,9 @@ struct cas_cls_numeric {
|
|||||||
struct cas_cls_string {
|
struct cas_cls_string {
|
||||||
/* String specifier*/
|
/* String specifier*/
|
||||||
char string[MAX_STRING_SPECIFIER_LEN];
|
char string[MAX_STRING_SPECIFIER_LEN];
|
||||||
|
|
||||||
|
/* String length */
|
||||||
|
uint32_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Directory condition context */
|
/* Directory condition context */
|
||||||
|
Loading…
Reference in New Issue
Block a user