On 12/15/2012 07:00 PM, Ivana Hutarova Varekova wrote:
> 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 <varek...@redhat.com>
Acked-by: Jan Safranek<jsafr...@redhat.com>

> ---
> 
>  src/config.c             |   37 +++++++++++++
>  src/lex.l                |    3 +
>  src/libcgroup-internal.h |    5 ++
>  src/parse.y              |  136 
> ++++++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 179 insertions(+), 2 deletions(-)
> 
> diff --git a/src/config.c b/src/config.c
> index fd25c9d..59b3383 100644
> --- a/src/config.c
> +++ b/src/config.c
> @@ -123,6 +123,16 @@ int cgroup_config_insert_cgroup(char *cg_name)
>  }
>  
>  /*
> + * 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
>   * entry in the cgroup_table. The index is incremented in
> @@ -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
>   */
> @@ -254,6 +275,14 @@ group_task_error:
>  }
>  
>  /*
> + * 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
>   */
>  int cgroup_config_group_admin_perm(char *perm_type, char *value)
> @@ -335,6 +364,14 @@ admin_error:
>  }
>  
>  /*
> + * 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 9ff37ec..d47807b 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 8bcfd96..e59a59e 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 7cc444c..f51332c 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 <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
>       {
> 
> 
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> _______________________________________________
> Libcg-devel mailing list
> Libcg-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/libcg-devel
> 


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to