On 11/21/2012 01:11 PM, Ivana Hutarova Varekova wrote:
> Two new functions maintain the templates cache:
> int cgroup_init_templates_cache(char *pathname);
> int cgroup_reload_cached_templates(char *pathname);
> 
> their are analogous to cgroup_init_rules_cache and cgroup_reload_cached_rules
> the only difference is there can be set configuration file as a parameter
> 
> Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com>

There is one remark below, otherwise
Acked-By: Jan Safranek <jsafr...@redhat.com>

> ---
> 
>  include/libcgroup/config.h |   10 +++++
>  src/config.c               |   95 
> ++++++++++++++++++++++++++++++++++++++++++++
>  src/libcgroup-internal.h   |    2 +
>  src/libcgroup.map          |    5 ++
>  4 files changed, 112 insertions(+), 0 deletions(-)
> 
> diff --git a/include/libcgroup/config.h b/include/libcgroup/config.h
> index 2dfdd32..d18634e 100644
> --- a/include/libcgroup/config.h
> +++ b/include/libcgroup/config.h
> @@ -74,6 +74,16 @@ int cgroup_config_unload_config(const char *pathname, int 
> flags);
>  int cgroup_config_set_default(struct cgroup *new_default);
>  
>  /**
> + * Initializes the templates cache and load it from file pathname.
> + */
> +int cgroup_init_templates_cache(char *pathname);
> +
> +/**
> + * Reloads the templates list from file pathname.
> + */
> +int cgroup_reload_cached_templates(char *pathname);
> +

These two functions look very similar, can they be refactored to call
one common (private) function instead?

> +/**
>   * @}
>   * @}
>   */
> diff --git a/src/config.c b/src/config.c
> index d59b398..6a91239 100644
> --- a/src/config.c
> +++ b/src/config.c
> @@ -78,6 +78,15 @@ static struct cgroup *config_template_table;
>  static int config_template_table_index;
>  
>  /*
> + * template structures used for templates cache, config_template_table and
> + * cgroup_template_table_index are rewritten  in each cgroup_parse_config
> + * thus not only if we want to reload template cache
> + */
> +static struct cgroup *template_table;
> +static int template_table_index;
> +
> +
> +/*
>   * Needed for the type while mounting cgroupfs.
>   */
>  #define CGROUP_FILESYSTEM "cgroup"
> @@ -1403,3 +1412,89 @@ int cgroup_config_set_default(struct cgroup 
> *new_default)
>  
>       return 0;
>  }
> +
> +/**
> + * Reloads the templates list, using the given configuration file.
> + *   @return 0 on success, > 0 on failure
> + */
> +int cgroup_reload_cached_templates(char *pathname)
> +{
> +     int i;
> +     /* Return codes */
> +     int ret = 0;
> +
> +     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 template structures have to be free as well*/
> +             cgroup_free_config();
> +     }
> +
> +     /* reloading data to config template structures */
> +     cgroup_dbg("Reloading cached templates from %s.\n", pathname);
> +     ret = cgroup_parse_config(pathname);
> +     if (ret) {
> +             cgroup_dbg("Could not reload template cache, error was: %d\n",
> +                     ret);
> +             return ret;
> +     }
> +
> +     /* copy data to templates cache structures */
> +     template_table_index = config_template_table_index;
> +     template_table = calloc(template_table_index, sizeof(struct cgroup));
> +     if (template_table == NULL) {
> +             ret = ECGOTHER;
> +             return  ret;
> +     }
> +
> +     memcpy(template_table, config_template_table,
> +             template_table_index * sizeof(struct cgroup));
> +
> +     return ret;
> +}
> +
> +/**
> + * Initializes the templates cache.
> + *   @return 0 on success, > 0 on error
> + */
> +int cgroup_init_templates_cache(char *pathname)
> +{
> +     /* Return codes */
> +     int ret = 0;
> +
> +     if (config_template_table_index != 0) {
> +             /* config structures have to be clean */
> +             cgroup_free_config();
> +     }
> +
> +     cgroup_dbg("Loading cached templates from %s.\n", pathname);
> +     /* Attempt to read the configuration file and cache the rules. */
> +     ret = cgroup_parse_config(pathname);
> +     if (ret) {
> +             cgroup_dbg("Could not initialize rule cache, error was: %d\n",
> +                     ret);
> +             return ret;
> +     }
> +
> +     /* copy template data to templates cache structures */
> +     template_table_index = config_template_table_index;
> +     template_table = calloc(template_table_index, sizeof(struct cgroup));
> +     if (template_table == NULL) {
> +             ret = ECGOTHER;
> +             return ret;
> +     }
> +
> +     memcpy(template_table, config_template_table,
> +             template_table_index * sizeof(struct cgroup));
> +
> +     return ret;
> +
> +
> +}
> diff --git a/src/libcgroup-internal.h b/src/libcgroup-internal.h
> index e59a59e..dbb8e9a 100644
> --- a/src/libcgroup-internal.h
> +++ b/src/libcgroup-internal.h
> @@ -47,6 +47,8 @@ __BEGIN_DECLS
>  #define CGRULE_SUCCESS_STORE_PID     "SUCCESS_STORE_PID"
>  
>  
> +#define CGCONFIG_CONF_FILE           "/etc/cgconfig.conf"
> +
>  #define CGRULES_CONF_FILE       "/etc/cgrules.conf"
>  #define CGRULES_MAX_FIELDS_PER_LINE          3
>  
> diff --git a/src/libcgroup.map b/src/libcgroup.map
> index e73dd6e..e29f887 100644
> --- a/src/libcgroup.map
> +++ b/src/libcgroup.map
> @@ -105,3 +105,8 @@ CGROUP_0.38 {
>         cgroup_config_unload_config;
>         cgroup_config_set_default;
>  } CGROUP_0.37;
> +
> +CGROUP_0.39 {
> +     cgroup_reload_cached_templates;
> +     cgroup_init_templates_cache;
> +} CGROUP_0.38;
> \ No newline at end of file
> 
> 
> ------------------------------------------------------------------------------
> Monitor your physical, virtual and cloud infrastructure from a single
> web console. Get in-depth insight into apps, servers, databases, vmware,
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.
> Pricing starts from $795 for 25 servers or applications!
> http://p.sf.net/sfu/zoho_dev2dev_nov
> _______________________________________________
> Libcg-devel mailing list
> Libcg-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/libcg-devel
> 


------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to