From 437bc0486c2ed7a645e3155f20d41d89b077e2c7 Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Wed, 6 Apr 2011 08:37:38 +0200 Subject: [PATCH] Enhanced cgsnapshot to print named hierarchies. cgsnapshot should show named hierarchies in 'mount' section. It already shows their groups in 'group' sections and the output should be consistent. And take care of quotes in the output, '=' is not valid character in controller name unless it is in double quotes. Example: $ mount -t cgroup -o none,name=hello none /cgroup/named $ mount -t cgroup -o cpuacct,name=cputest none /cgroup/cpuacct $ cgsnapshot mount { cpuacct = /cgroup/cpuacct; "name=hello" = /cgroup/named; "name=cputest" = /cgroup/cpuacct; } Signed-off-by: Jan Safranek Acked-by: Ivana Hutarova Varekova --- src/tools/cgsnapshot.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/tools/cgsnapshot.c b/src/tools/cgsnapshot.c index 4dbecfd8..0ff74352 100644 --- a/src/tools/cgsnapshot.c +++ b/src/tools/cgsnapshot.c @@ -319,7 +319,10 @@ static int display_cgroup_data(struct cgroup *group, } /* print the controller header */ - fprintf(of, "\t%s {\n", controller[i]); + if (strncmp(controller[i], "name=", 5) == 0) + fprintf(of, "\t\"%s\" {\n", controller[i]); + else + fprintf(of, "\t%s {\n", controller[i]); i++; nr_var = cgroup_get_value_name_count(group_controller); @@ -573,13 +576,20 @@ static int show_mountpoints(const char *controller) char path[FILENAME_MAX]; int ret; void *handle; + int quote = 0; + + if (strncmp(controller, "name=", 5) == 0) + quote = 1; ret = cgroup_get_subsys_mount_point_begin(controller, &handle, path); if (ret) return ret; while (ret == 0) { - printf("\t%s = %s;\n", controller, path); + if (quote) + printf("\t\"%s\" = %s;\n", controller, path); + else + printf("\t%s = %s;\n", controller, path); ret = cgroup_get_subsys_mount_point_next(&handle, path); } cgroup_get_subsys_mount_point_end(&handle); @@ -594,9 +604,10 @@ static int show_mountpoints(const char *controller) static int parse_mountpoints(cont_name_t cont_names[CG_CONTROLLER_MAX], const char *program_name) { - int ret; + int ret, final_ret; void *handle; struct controller_data info; + struct cgroup_mount_point mount; /* start mount section */ fprintf(of, "mount {\n"); @@ -629,7 +640,29 @@ static int parse_mountpoints(cont_name_t cont_names[CG_CONTROLLER_MAX], } } - ret |= cgroup_get_all_controller_end(&handle); + final_ret = ret; + cgroup_get_all_controller_end(&handle); + + /* process also named hierarchies */ + ret = cgroup_get_controller_begin(&handle, &mount); + while (ret == 0) { + if (strncmp(mount.name, "name=", 5) == 0) { + ret = show_mountpoints(mount.name); + if (ret != 0) + break; + } + ret = cgroup_get_controller_next(&handle, &mount); + } + if (ret != ECGEOF) { + if ((flags & FL_SILENT) != 0) { + fprintf(stderr, + "E: in get next controller %s\n", + cgroup_strerror(ret)); + return ret; + } + final_ret = ret; + } + cgroup_get_controller_end(&handle); /* finish mount section */ fprintf(of, "}\n\n"); -- 2.47.2