]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
config.h: create function for init/reload cgconfig template cache
authorIvana Hutarova Varekova <varekova@redhat.com>
Mon, 28 Jan 2013 13:41:38 +0000 (14:41 +0100)
committerIvana Hutarova Varekova <varekova@redhat.com>
Mon, 28 Jan 2013 13:41:38 +0000 (14:41 +0100)
    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

    Changelog: remove useless comments

Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com>
Acked-By: Jan Safranek <jsafrane@redhat.com>
include/libcgroup/config.h
src/config.c
src/libcgroup-internal.h
src/libcgroup.map

index 2dfdd32abad98f4e30c4d7e9603362fdf58bbbf6..d18634ef0d219e59c87c80e34ae491149890369e 100644 (file)
@@ -73,6 +73,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);
+
 /**
  * @}
  * @}
index 628176732ddbf80e209e9b71a9b22b98d8b4d80f..72755daecd79b1cb5cc4d36ec4a91afb7fe80c74 100644 (file)
@@ -82,6 +82,15 @@ static int cgroup_table_index;
 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.
  */
@@ -1408,3 +1417,87 @@ 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;
+       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)
+{
+       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;
+
+
+}
index e59a59e125d53bec3659aeaf28c004c1869be2a9..dbb8e9a2496b16b190de1583e851a215fbf95698 100644 (file)
@@ -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
 
index e73dd6e6b7f5d1fcd8d138a47fb7948a370eb578..e29f88796ffbdce64b8b4f4b2af6d6c5586fecf6 100644 (file)
@@ -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