]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup: Introduce the new namespace keyword
authorDhaval Giani <dhaval@linux.vnet.ibm.com>
Thu, 7 Jan 2010 10:54:34 +0000 (16:24 +0530)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Thu, 7 Jan 2010 15:39:08 +0000 (21:09 +0530)
This patch introduces a new keywork NAMESPACE which allow cgroups
to be created starting from a certain point as mentioned by the
administrator. This is provided via the configuration file.

Newer APIs will use this feature.

Changes from v1:
1. Attempted to fix the indentation
2. Change a variable name

Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
src/config.c
src/lex.l
src/libcgroup-internal.h
src/parse.y

index 130fac1fedee56a34aeeb4c829b2a1b9e2a6e949..7435795a5bc5bda50d0fa8c6f5b5ed7daeb2563c 100644 (file)
@@ -59,8 +59,11 @@ extern int yyparse(void);
  * cgroup_table_index -> Where in the cgroup_table we are.
  */
 static struct cg_mount_table_s config_mount_table[CG_CONTROLLER_MAX];
+static struct cg_mount_table_s config_namespace_table[CG_CONTROLLER_MAX];
 static int config_table_index;
+static int namespace_table_index;
 static pthread_rwlock_t config_table_lock = PTHREAD_RWLOCK_INITIALIZER;
+static pthread_rwlock_t namespace_table_lock = PTHREAD_RWLOCK_INITIALIZER;
 static struct cgroup config_cgroup_table[MAX_CGROUPS];
 int cgroup_table_index;
 
@@ -351,6 +354,36 @@ void cgroup_config_cleanup_mount_table(void)
                        sizeof(struct cg_mount_table_s) * CG_CONTROLLER_MAX);
 }
 
+/*
+ * The moment we have found the controller's information
+ * insert it into the config_mount_table.
+ */
+int cgroup_config_insert_into_namespace_table(char *name, char *nspath)
+{
+       if (namespace_table_index >= CG_CONTROLLER_MAX)
+               return 0;
+
+       pthread_rwlock_wrlock(&namespace_table_lock);
+
+       strcpy(config_namespace_table[namespace_table_index].name, name);
+       strcpy(config_namespace_table[namespace_table_index].path, nspath);
+       namespace_table_index++;
+
+       pthread_rwlock_unlock(&namespace_table_lock);
+       free(name);
+       free(nspath);
+       return 1;
+}
+
+/*
+ * Cleanup all the data from the config_mount_table
+ */
+void cgroup_config_cleanup_namespace_table(void)
+{
+       memset(&config_namespace_table, 0,
+                       sizeof(struct cg_mount_table_s) * CG_CONTROLLER_MAX);
+}
+
 /*
  * Start mounting the mount table.
  */
index 817b6b68bd36904b855fe0e9818262e1425b7e6d..6291b5536f398a542e2208a08fb63cf6417fce78 100644 (file)
--- a/src/lex.l
+++ b/src/lex.l
@@ -23,11 +23,12 @@ int line_no = 1;
 [ \t]  {/* DO NOTHING */}
 ^#.*[ \t]*  {/* Comments */}
 ^\*.*[ \t]* {/* Comments */}
-"mount"        {return MOUNT;}
-"task" {return TASK;}
-"admin"        {return ADMIN;}
-"perm" {return PERM;}
-"group"        {return GROUP;}
+"mount"                {return MOUNT;}
+"task"         {return TASK;}
+"admin"                {return ADMIN;}
+"perm"         {return PERM;}
+"group"                {return GROUP;}
+"namespace"    {return NAMESPACE;}
 [a-zA-Z0-9_\-\/\.]+ {yylval.name = strdup(yytext); return ID;}
 .      {return yytext[0];}
 %%
index 8ceb73e1c9d48b3b8db51b5a49336cb298f65dac..81a7b989b0b27c74bf9a6b0e74f135b72dc55f4a 100644 (file)
@@ -125,6 +125,7 @@ int cgroup_config_parse_controller_options(char *controller, char *name_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);
+int cgroup_config_insert_into_namespace_table(char *name, char *mount_point);
 void cgroup_config_cleanup_mount_table(void);
 __END_DECLS
 
index 32a3c74e829d19dc652c8fe3f12fdb7b42157903..47abee6882928633bb7ffec1f29d486f6f3ab52a 100644 (file)
@@ -37,7 +37,7 @@ int yywrap(void)
 
 %}
 
-%token ID MOUNT GROUP PERM TASK ADMIN
+%token ID MOUNT GROUP PERM TASK ADMIN NAMESPACE
 
 %union {
        char *name;
@@ -47,6 +47,7 @@ int yywrap(void)
 %type <name> ID namevalue_conf
 %type <val> mountvalue_conf mount task_namevalue_conf admin_namevalue_conf
 %type <val> admin_conf task_conf task_or_admin group_conf group start
+%type <val> namespace namespace_conf
 %start start
 %%
 
@@ -58,7 +59,11 @@ start   : start group
        {
                $$ = $1;
        }
-        |
+        | start namespace
+       {
+               $$ = $1;
+       }
+       |
        {
                $$ = 1;
        }
@@ -266,5 +271,37 @@ mount   :       MOUNT '{' mountvalue_conf '}'
        }
         ;
 
+namespace_conf
+        :       ID '=' ID ';'
+       {
+               if (!cgroup_config_insert_into_namespace_table($1, $3)) {
+                       cgroup_config_cleanup_namespace_table();
+                       $$ = 0;
+                       return $$;
+               }
+               $$ = 1;
+       }
+        |       namespace_conf ID '=' ID ';'
+       {
+               if (!cgroup_config_insert_into_namespace_table($2, $4)) {
+                       cgroup_config_cleanup_namespace_table();
+                       $$ = 0;
+                       return $$;
+               }
+               $$ = 1;
+       }
+        ;
+
+namespace   :       NAMESPACE '{' namespace_conf '}'
+       {
+               $$ = $3;
+               if (!$$) {
+                       fprintf(stderr, "parsing failed at line number %d\n",
+                               line_no);
+                       $$ = 0;
+                       return $$;
+               }
+       }
+        ;
 
 %%