This patch adds devices controller logic to cgsnapshot tool
so now it is able to parse devices.

EXAMPLE:
# cgget -g devices /dev
/dev:
devices.list=c 1:* wm
devices.deny=
devices.allow=

# cgsnapshot -b samples/blacklist.conf -w samples/whitelist.conf
# Configuration file generated by cgsnapshot
mount {
        cpuset = /cgroup/1;
        cpu = /cgroup/2;
        cpuacct = /cgroup/3;
        memory = /cgroup/4;
        devices = /cgroup/5;
        freezer = /cgroup/6;
        net_cls = /cgroup/7;
}

group dev {
        perm {
                admin {
                        uid = root;
                        gid = root;
                }
                task {
                        uid = root;
                        gid = root;
                }
        }
        devices {
                devices.deny="a *:* rwm";
                devices.allow="c 1:* wm";
        }
}


Signed-off-by: Ivana Hutarova Varekova <[email protected]>
---

 samples/cgsnapshot_blacklist.conf |    2 --
 samples/cgsnapshot_whitelist.conf |    3 +++
 src/tools/cgsnapshot.c            |   27 +++++++++++++++++++++++++--
 3 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/samples/cgsnapshot_blacklist.conf 
b/samples/cgsnapshot_blacklist.conf
index ff14b7d..2892469 100644
--- a/samples/cgsnapshot_blacklist.conf
+++ b/samples/cgsnapshot_blacklist.conf
@@ -11,8 +11,6 @@ cpuacct.stat
 cpuacct.usage_percpu
 
 #devices
-devices.deny
-devices.allow
 
 #cpuset
 
diff --git a/samples/cgsnapshot_whitelist.conf 
b/samples/cgsnapshot_whitelist.conf
index c8481ea..2c9ab23 100644
--- a/samples/cgsnapshot_whitelist.conf
+++ b/samples/cgsnapshot_whitelist.conf
@@ -20,6 +20,9 @@ cpu.rt_period_us
 cpuacct.usage
 
 #devices
+devices.deny
+devices.allow
+devices.list
 
 #cpuset
 cpuset.memory_spread_slab
diff --git a/src/tools/cgsnapshot.c b/src/tools/cgsnapshot.c
index 5e2c7ad..dcab130 100644
--- a/src/tools/cgsnapshot.c
+++ b/src/tools/cgsnapshot.c
@@ -280,6 +280,7 @@ static int display_cgroup_data(struct cgroup *group,
        int bl, wl = 0; /* is on the blacklist/whitelist flag */
        int nr_var = 0;
        char *name;
+       char *output_name;
        struct cgroup_controller *group_controller = NULL;
        char *value = NULL;
        char var_path[FILENAME_MAX];
@@ -325,8 +326,11 @@ static int display_cgroup_data(struct cgroup *group,
                        ret = stat(var_path, &sb);
                        /* freezer.state is not in root group so ret != 0,
                         * but it should be listed
+                        * device.list should be read to create
+                        * device.allow input
                         */
-                       if ((ret == 0) && ((sb.st_mode & S_IWUSR) == 0)) {
+                       if ((ret == 0) && ((sb.st_mode & S_IWUSR) == 0) &&
+                           (strcmp("devices.list", name) != 0)) {
                                /* variable is not writable */
                                continue;
                        }
@@ -352,6 +356,25 @@ static int display_cgroup_data(struct cgroup *group,
                                        "neither blacklisted nor "\
                                        "whitelisted\n", name);
 
+                       output_name = name;
+
+                       /* deal with devices variables:
+                        * - omit devices.deny and device.allow,
+                        * - generate devices.{deny,allow} from
+                        * device.list variable (deny all and then
+                        * all device.list devices */
+                       if ((strcmp("devices.deny", name) == 0) ||
+                               (strcmp("devices.allow", name) == 0)) {
+                               continue;
+                       }
+                       if (strcmp("devices.list", name) == 0) {
+                               output_name = (char *)malloc(sizeof(char) *
+                                       (strlen("devices.allow")+1));
+                               strcpy(output_name, "devices.allow");
+                               fprintf(of,
+                                       "\t\tdevices.deny=\"a *:* rwm\";\n");
+                       }
+
                        ret = cgroup_get_value_string(group_controller,
                                name, &value);
 
@@ -363,7 +386,7 @@ static int display_cgroup_data(struct cgroup *group,
                                        name);
                                goto err;
                        }
-                       fprintf(of, "\t\t%s=\"%s\";\n", name, value);
+                       fprintf(of, "\t\t%s=\"%s\";\n", output_name, value);
                }
                fprintf(of, "\t}\n");
        }


------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to