On 12/15/2012 07:00 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 <[email protected]>
Acked-by: Jan Safranek<[email protected]>
> ---
>
> 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);
> +
> +/**
> * @}
> * @}
> */
> diff --git a/src/config.c b/src/config.c
> index 6281767..6955546 100644
> --- a/src/config.c
> +++ b/src/config.c
> @@ -83,6 +83,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"
> @@ -1408,3 +1417,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
>
>
> ------------------------------------------------------------------------------
> 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
> [email protected]
> 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
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel