]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgconfigparser: add template tag to cgconfigparser
authorIvana Hutarova Varekova <varekova@redhat.com>
Mon, 28 Jan 2013 13:38:16 +0000 (14:38 +0100)
committerIvana Hutarova Varekova <varekova@redhat.com>
Mon, 28 Jan 2013 13:38:16 +0000 (14:38 +0100)
    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 <varekova@redhat.com>
Acked-By: Jan Safranek <jsafrane@redhat.com>
src/config.c
src/lex.l
src/libcgroup-internal.h
src/parse.y

index fd25c9d1ede701433681838eb5c61e5eb4cc5a34..59b3383bb44f98c873642b4fdea8e883a7f39986 100644 (file)
@@ -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.
index 9ff37ecdf40c09a3b1a5e445df4747a64ef8331b..d47807beedcfad5ecf23f7cd70f1790b4d6eca08 100644 (file)
--- 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];}
 %%
index 8bcfd969f82cdd426462475f072ab78e665bc6ea..e59a59e125d53bec3659aeaf28c004c1869be2a9 100644 (file)
@@ -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);
index 7cc444cfadd655d6629264da1c986447ebb26e29..f51332c32345863bb0cca8286ebd1b8270c6d359 100644 (file)
@@ -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 <val> admin_conf task_conf task_or_admin group_conf group start
 %type <val> namespace namespace_conf default default_conf
 %type <values> namevalue_conf
+%type <val> template template_conf
+%type <val> template_task_or_admin template_task_namevalue_conf
+%type <val> 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
        {