From: Ivana Hutarova Varekova Date: Mon, 28 Jan 2013 13:38:16 +0000 (+0100) Subject: cgconfigparser: add template tag to cgconfigparser X-Git-Tag: v0.41~91 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3c3fce99f0ee0885b76f66ee8e1913153b31577;p=thirdparty%2Flibcgroup.git cgconfigparser: add template tag to cgconfigparser Template cgroups mean control groups which are set in cgrules.conf file and the name contains % variable like %U (see cgrules.conf manual page for the whole list of variables). This patch tunes cgconfigparser to accept template tag. With this patch the tag is accepted and ignored. The next patch will parse it and do relevant work. Example: template student/%u { cpu { cpu.shares = "1000"; } } Signed-off-by: Ivana Hutarova Varekova Acked-By: Jan Safranek --- diff --git a/src/config.c b/src/config.c index fd25c9d1..59b3383b 100644 --- a/src/config.c +++ b/src/config.c @@ -122,6 +122,16 @@ int cgroup_config_insert_cgroup(char *cg_name) return 1; } +/* + * TODO: This call just sets the name of the template. It will + * always be called in the end, because the parser will + * work bottom up. + */ +int template_config_insert_cgroup(char *cg_name) +{ + return 1; +} + /* * This function sets the various controller's control * files. It will always append values for cgroup_table_index @@ -180,6 +190,17 @@ parse_error: return 0; } +/* TODO: This function sets the various controller's control + * files. It will always append values for config_template_table_index + * entry in the config_template_table. The index is incremented in + * temlate_config_insert_cgroup + */ +int template_config_parse_controller_options(char *controller, + struct cgroup_dictionary *values) +{ + return 1; +} + /* * Sets the tasks file's uid and gid */ @@ -253,6 +274,14 @@ group_task_error: return 0; } +/* + * TODO: Sets the tasks file's uid and gid for templates + */ +int template_config_group_task_perm(char *perm_type, char *value) +{ + return 1; +} + /* * Set the control file's uid/gid */ @@ -334,6 +363,14 @@ admin_error: return 0; } +/* + * TODO: Set the control file's uid and gid for templates + */ +int template_config_group_admin_perm(char *perm_type, char *value) +{ + return 1; +} + /* * The moment we have found the controller's information * insert it into the config_mount_table. diff --git a/src/lex.l b/src/lex.l index 9ff37ecd..d47807be 100644 --- a/src/lex.l +++ b/src/lex.l @@ -39,8 +39,9 @@ jmp_buf parser_error_env; "perm" {return PERM;} "group" {return GROUP;} "namespace" {return NAMESPACE;} +"template" {return TEMPLATE;} "default" {return DEFAULT;} -[a-zA-Z0-9_\-\/\.\,]+ {yylval.name = strdup(yytext); return ID;} +[a-zA-Z0-9_\-\/\.\,\%]+ {yylval.name = strdup(yytext); return ID;} \"[^"]*\" {yylval.name = strdup(yytext+1); yylval.name[strlen(yylval.name)-1] = '\0'; return ID; } . {return yytext[0];} %% diff --git a/src/libcgroup-internal.h b/src/libcgroup-internal.h index 8bcfd969..e59a59e1 100644 --- a/src/libcgroup-internal.h +++ b/src/libcgroup-internal.h @@ -220,6 +220,11 @@ extern __thread char *cg_namespace_table[CG_CONTROLLER_MAX]; int cgroup_config_insert_cgroup(char *cg_name); int cgroup_config_parse_controller_options(char *controller, struct cgroup_dictionary *values); +int template_config_insert_cgroup(char *cg_name); +int template_config_parse_controller_options(char *controller, + struct cgroup_dictionary *values); +int template_config_group_task_perm(char *perm_type, char *value); +int template_config_group_admin_perm(char *perm_type, char *value); int cgroup_config_group_task_perm(char *perm_type, char *value); int cgroup_config_group_admin_perm(char *perm_type, char *value); int cgroup_config_insert_into_mount_table(char *name, char *mount_point); diff --git a/src/parse.y b/src/parse.y index 7cc444cf..f51332c3 100644 --- a/src/parse.y +++ b/src/parse.y @@ -37,7 +37,7 @@ int yywrap(void) %} -%token ID MOUNT GROUP PERM TASK ADMIN NAMESPACE DEFAULT +%token ID MOUNT GROUP PERM TASK ADMIN NAMESPACE DEFAULT TEMPLATE %union { char *name; @@ -50,6 +50,9 @@ int yywrap(void) %type admin_conf task_conf task_or_admin group_conf group start %type namespace namespace_conf default default_conf %type namevalue_conf +%type template template_conf +%type template_task_or_admin template_task_namevalue_conf +%type template_admin_namevalue_conf %start start %% @@ -69,6 +72,10 @@ start : start group { $$ = $1; } + | start template + { + $$ = $1; + } | { $$ = 1; @@ -146,6 +153,86 @@ group_conf } ; +template : TEMPLATE ID '{' template_conf '}' + { + $$ = $4; + if ($$) { + $$ = template_config_insert_cgroup($2); + if (!$$) { + fprintf(stderr, "parsing failed at line number %d\n", + line_no); + $$ = ECGOTHER; + return $$; + } + } else { + fprintf(stderr, "parsing failed at line number %d\n", + line_no); + $$ = ECGCONFIGPARSEFAIL; + return $$; + } + } + ; + + +template_conf + : ID '{' namevalue_conf '}' + { + $$ = template_config_parse_controller_options($1, $3); + cgroup_dictionary_free($3); + if (!$$) { + fprintf(stderr, "parsing failed at line number %d\n", + line_no); + $$ = ECGCONFIGPARSEFAIL; + return $$; + } + } + | template_conf ID '{' namevalue_conf '}' + { + $$ = template_config_parse_controller_options($2, $4); + cgroup_dictionary_free($4); + if (!$$) { + fprintf(stderr, "parsing failed at line number %d\n", + line_no); + $$ = ECGCONFIGPARSEFAIL; + return $$; + } + } + | PERM '{' template_task_or_admin '}' + { + $$ = $3; + if (!$$) { + fprintf(stderr, "parsing failed at line number %d\n", + line_no); + $$ = ECGCONFIGPARSEFAIL; + return $$; + } + } + ; + +template_task_or_admin + : TASK '{' template_task_namevalue_conf '}' admin_conf + { + $$ = $3 && $5; + if (!$$) { + fprintf(stderr, "parsing failed at line number %d\n", + line_no); + $$ = ECGCONFIGPARSEFAIL; + return $$; + } + } + | ADMIN '{' template_admin_namevalue_conf '}' task_conf + { + $$ = $3 && $5; + if (!$$) { + fprintf(stderr, "parsing failed at line number %d\n", + line_no); + $$ = ECGCONFIGPARSEFAIL; + return $$; + } + } + ; + + namevalue_conf : ID '=' ID ';' { @@ -227,6 +314,53 @@ admin_namevalue_conf } ; +template_task_namevalue_conf + : ID '=' ID ';' + { + $$ = template_config_group_task_perm($1, $3); + if (!$$) { + fprintf(stderr, "parsing failed at line number %d\n", + line_no); + $$ = ECGCONFIGPARSEFAIL; + return $$; + } + } + | task_namevalue_conf ID '=' ID ';' + { + $$ = $1 && template_config_group_task_perm($2, $4); + if (!$$) { + fprintf(stderr, "parsing failed at line number %d\n", + line_no); + $$ = ECGCONFIGPARSEFAIL; + return $$; + } + } + ; + +template_admin_namevalue_conf + : ID '=' ID ';' + { + $$ = template_config_group_admin_perm($1, $3); + if (!$$) { + fprintf(stderr, "parsing failed at line number %d\n", + line_no); + $$ = ECGCONFIGPARSEFAIL; + return $$; + } + } + | admin_namevalue_conf ID '=' ID ';' + { + $$ = $1 && template_config_group_admin_perm($2, $4); + if (!$$) { + fprintf(stderr, "parsing failed at line number %d\n", + line_no); + $$ = ECGCONFIGPARSEFAIL; + return $$; + } + } + ; + + task_or_admin : TASK '{' task_namevalue_conf '}' admin_conf {