Hello, 
please can you resend the patches in the right format, now the patches can't be 
applied and there are a lot of checkpatch.pl messaes as well. (I try to 
apply/check using checkpatch.pl tool only the first two patches)

Ivana

----- Original Message -----
> From: "Jan Chaloupka" <jchal...@redhat.com>
> To: "Libcg Development list" <libcg-devel@lists.sourceforge.net>
> Cc: "Ivana Varekova" <varek...@redhat.com>
> Sent: Saturday, May 17, 2014 4:35:54 PM
> Subject: [PATCH 1/4] config.c: loading templates from multiple files into one 
> template table
> 
> This patch implements loading files from /etc/cgconfig.d/. It uses
> already implemented functions. To hold list of files to be read for
> template reloading, new static variable for this list (list of template
> files) has been added to config.c. It is the same list as file list read
> with cgconfigparser (cgconfig.c file), i.e. the same functions are
> called. Because parser reads only one file, it is called for each file
> in template file list. Thus initialization, resp. template duplication
> has to be called before, resp. after each file parsing. Thus new
> functions has been presented, thus modifying config.[h|c] api and
> libcgroup.map. Again parsing more files for templates is analogy to
> parsing files for groups in cgconfig.c.
> 
> cgroup_reload_cached_templates_from_file and
> cgroup_init_templates_cache_from_files are modification of
> cgroup_reload_cached_templates and cgroup_init_templates_cache. Only for
> loop and auxiliary variables added.
> 
> Signed-off-by: Jan Chaloupka <jchal...@redhat.com>
> ---
>   include/libcgroup/config.h |  30 ++++++++
>   src/config.c               | 185
> ++++++++++++++++++++++++++++++++++++++++++++-
>   src/libcgroup.map          |   6 ++
>   3 files changed, 218 insertions(+), 3 deletions(-)
> 
> diff --git a/include/libcgroup/config.h b/include/libcgroup/config.h
> index 43568e1..5e47637 100644
> --- a/include/libcgroup/config.h
> +++ b/include/libcgroup/config.h
> @@ -84,11 +84,41 @@ int cgroup_init_templates_cache(char *pathname);
>   int cgroup_reload_cached_templates(char *pathname);
> 
>   /**
> + * Initializes the templates cache from files. Before calling this
> function,
> + * cgroup_templates_cache_set_source_files has to be called first.
> + * @param file_index index of file which was unable to be parsed
> + * @return 0 on success, > 0 on error
> + */
> +struct cgroup_string_list;
> +int cgroup_init_templates_cache_from_files(int *file_index);
> +
> +/**
> + * Reloads the templates list from files. Before calling this function,
> + * cgroup_templates_cache_set_source_files has to be called first.
> + * @param file_index index of file which was unable to be parsed
> + * @return 0 on success, > 0 on failure
> + */
> +int cgroup_reload_cached_templates_from_file(int *file_index);
> +
> +/**
> + * Load the templates cache from files. Used as a common function for
> + * cgroup_[load|init]_templates_cache_from_files.
> + * @param file_index index of file which was unable to be parsed
> + * @return 0 on success, > 0 on error
> + */
> +void cgroup_templates_cache_set_source_files(
> +    struct cgroup_string_list *tmpl_files);
> +
> +/**
>    * Physically create a new control group in kernel, based on given control
>    * group template and configuration file. If given template is not set in
>    * configuration file, then the procedure works create the control group
>    * using  cgroup_create_cgroup() function
>    *
> + * Templates are loaded using
> cgroup_[init|reload]_templates_cache_from_files
> + * function, which must be preceeded by
> cgroup_templates_cache_set_source_files
> + * call.
> + *
>    * The flags can alter the behavior of this function:
>    * CGFLAG_USE_TEMPLATE_CACHE: Use cached templates instead of
>    * parsing the config file
> diff --git a/src/config.c b/src/config.c
> index e1ee0a8..e741703 100644
> --- a/src/config.c
> +++ b/src/config.c
> @@ -41,6 +41,8 @@
>   #include <sys/stat.h>
>   #include <sys/types.h>
> 
> +#include "tools/tools-common.h"
> +
>   unsigned int MAX_CGROUPS = 64;    /* NOTE: This value changes
> dynamically */
>   unsigned int MAX_TEMPLATES = 64;
>                   /* NOTE: This value changes dynamically */
> @@ -89,6 +91,7 @@ static int config_template_table_index;
>    */
>   static struct cgroup *template_table;
>   static int template_table_index;
> +static struct cgroup_string_list *template_files;
> 
> 
>   /*
> @@ -96,6 +99,9 @@ static int template_table_index;
>    */
>   #define CGROUP_FILESYSTEM "cgroup"
> 
> +#define TEMPLATE_ACTION_INIT 0
> +#define TEMPLATE_ACTION_RELOAD 1
> +
>   /*
>    * NOTE: All these functions return 1 on success
>    * and not 0 as is the library convention
> @@ -1572,6 +1578,176 @@ int cgroup_init_templates_cache(char *pathname)
> 
>   }
> 
> +/**
> + * Setting source files of templates. This function has to be called before
> + * any call of cgroup_[init|reload]_templates_cache_from_files.
> + * @param tmpl_files
> + */
> +void cgroup_templates_cache_set_source_files(
> +    struct cgroup_string_list *tmpl_files)
> +{
> +    template_files = tmpl_files;
> +}
> +
> +/**
> + * Appending cgroup templates parsed by parser to template_table
> + * @param offset number of templates already in the table
> + */
> +int cgroup_add_cgroup_templates(int offset)
> +{
> +    int i, ti, ret;
> +
> +    for (i = 0; i < config_template_table_index; i++) {
> +        ti = i + offset;
> +        ret = cgroup_copy_cgroup(&template_table[ti],
> +            &config_template_table[i]);
> +        if (ret)
> +            return ret;
> +
> +        strcpy((template_table[ti]).name,
> +            (config_template_table[i]).name);
> +        template_table[ti].tasks_uid =
> +            config_template_table[i].tasks_uid;
> +        template_table[ti].tasks_gid =
> +            config_template_table[i].tasks_gid;
> +        template_table[ti].task_fperm =
> +            config_template_table[i].task_fperm;
> +        template_table[ti].control_uid =
> +            config_template_table[i].control_uid;
> +        template_table[ti].control_gid =
> +            config_template_table[i].control_gid;
> +        template_table[ti].control_fperm =
> +            config_template_table[i].control_fperm;
> +        template_table[ti].control_dperm =
> +            config_template_table[i].control_dperm;
> +    }
> +
> +    return 0;
> +}
> +
> +/**
> + * Expand template table based on new number of parsed templates, i.e.
> + * on value of config_template_table_index.
> + * Change value of template_table_index.
> + * @return 0 on success, > 0 on error
> + */
> +int cgroup_expand_template_table(void)
> +{
> +    int i, template_table_last_index;
> +
> +    template_table_last_index = template_table_index;
> +    template_table_index += config_template_table_index;
> +    template_table = realloc(template_table,
> +        template_table_index*sizeof(struct cgroup));
> +
> +    if (template_table == NULL)
> +        return -ECGOTHER;
> +
> +    for (i = 0; i < config_template_table_index; i++)
> +        template_table[i + template_table_last_index].index = 0;
> +
> +    return 0;
> +}
> +
> +/**
> + * Load the templates cache from files. Used as a common function for
> + * cgroup_[load|init]_templates_cache_from_files.
> + * @param file_index index of file which was unable to be parsed
> + * @return 0 on success, > 0 on error
> + */
> +int cgroup_load_templates_cache_from_files(int *file_index)
> +{
> +    int ret;
> +    int i, j;
> +    int template_table_last_index;
> +    char *pathname;
> +
> +    if (!template_files) {
> +        /* source files has not been set */
> +        cgroup_dbg("Template source files have not been set\n");
> +        ret = ECGOTHER;
> +        *file_index = -1;
> +        return ret;
> +    }
> +
> +    if (template_table) {
> +        /* template structures have to be free */
> +        for (i = 0; i < template_table_index; i++)
> +            cgroup_free_controllers(&template_table[i]);
> +        free(template_table);
> +        template_table = NULL;
> +    }
> +    template_table_index = 0;
> +
> +    if ((config_template_table_index != 0) || (config_table_index != 0)) {
> +        /* config structures have to be clean before parsing */
> +        cgroup_free_config();
> +    }
> +
> +    for (j = 0; j < template_files->count; j++) {
> +        pathname = template_files->items[j];
> +
> +        cgroup_dbg("Parsing templates from %s.\n", pathname);
> +        /* Attempt to read the configuration file
> +         * and cache the rules. */
> +        ret = cgroup_parse_config(pathname);
> +        if (ret) {
> +#define LTE1 "Could not initialize rule cache, error was: %d\n"
> +            cgroup_dbg(LTE1, ret);
> +            *file_index = j;
> +            return ret;
> +        }
> +
> +        if (config_template_table_index > 0) {
> +            template_table_last_index = template_table_index;
> +            ret = cgroup_expand_template_table();
> +#define LTE2 "Could not expand template table, error was: %d\n"
> +            if (ret) {
> +                cgroup_dbg(LTE2, -ret);
> +                return -ret;
> +            }
> +
> +            /* copy template data to templates cache structures */
> +#define LTE3 "Copying templates to template table from %s.\n"
> +            cgroup_dbg(LTE3, pathname);
> +            ret = cgroup_add_cgroup_templates(
> +                template_table_last_index);
> +            if (ret) {
> +                cgroup_dbg("Unable to copy cgroup\n");
> +                return ret;
> +            }
> +#define LTE4 "Templates to template table copied\n"
> +            cgroup_dbg(LTE4);
> +        }
> +    }
> +
> +    return 0;
> +}
> +
> +/**
> + * Initializes the templates cache from files. Before calling this
> function,
> + * cgroup_templates_cache_set_source_files has to be called first.
> + * @param file_index index of file which was unable to be parsed
> + * @return 0 on success, > 0 on error
> + */
> +int cgroup_init_templates_cache_from_files(int *file_index)
> +{
> +    cgroup_dbg("Init templates cache from files\n");
> +    return cgroup_load_templates_cache_from_files(file_index);
> +}
> +
> +/**
> + * Reloads the templates list from files. Before calling this function,
> + * cgroup_templates_cache_set_source_files has to be called first.
> + * @param file_index index of file which was unable to be parsed
> + * @return 0 on success, > 0 on failure
> + */
> +int cgroup_reload_cached_templates_from_file(int *file_index)
> +{
> +    cgroup_dbg("Reload templates cache from files\n");
> +    return cgroup_load_templates_cache_from_files(file_index);
> +}
> +
>   /*
>    * Create a given cgroup, based on template configuration if it is present
>    * if the template is not present cgroup is creted using
> cgroup_create_cgroup
> @@ -1593,13 +1769,16 @@ int cgroup_config_create_template_group(struct
> cgroup *cgroup,
>        * use CGCONFIG_CONF_FILE by default
>        */
>       if (!(flags & CGFLAG_USE_TEMPLATE_CACHE)) {
> +        int fileindex;
>           if (template_table_index == 0)
>               /* the rules cache is empty */
> -            ret = cgroup_init_templates_cache(CGCONFIG_CONF_FILE);
> +            ret = cgroup_init_templates_cache_from_files(
> +                &fileindex);
> +
>           else
>               /* cache is not empty */
> -            ret = cgroup_reload_cached_templates(
> -                CGCONFIG_CONF_FILE);
> +            ret = cgroup_reload_cached_templates_from_file(
> +                &fileindex);
>           if (ret != 0) {
>               cgroup_dbg("Failed initialize templates cache.\n");
>               return ret;
> diff --git a/src/libcgroup.map b/src/libcgroup.map
> index b0c162c..f853af0 100644
> --- a/src/libcgroup.map
> +++ b/src/libcgroup.map
> @@ -117,3 +117,9 @@ CGROUP_0.39 {
>       cgroup_log;
>       cgroup_parse_log_level_str;
>   } CGROUP_0.38;
> +
> +CGROUP_0.40 {
> +    cgroup_init_templates_cache_from_files;
> +        cgroup_reload_cached_templates_from_file;
> +        cgroup_templates_cache_set_source_files;
> +} CGROUP_0.39;
> --
> 1.9.0
> 
> 
> 

------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to