Hi Ivana,

        what do you think about this patch ?

Thanks!
Weng Meiling


-------- Original Message --------
Subject: [PATCH] cgdelete:fix the display problem
Date: Sat, 14 Sep 2013 15:15:04 +0800
From: Weng Meiling <wengmeiling.w...@huawei.com>
CC: Ivana Varekova <varek...@redhat.com>,  Huang Qiang 
<h.huangqi...@huawei.com>, Libcg Development list 
<libcg-devel@lists.sourceforge.net>,  libo chen <libo.c...@huawei.com>


From: Weng Meiling <wengmeiling.w...@huawei.com>

When multi subsystems mounted on one place like this:

# lssubsys -m
cpu,cpuacct /cgroup/cpu

# lscgroup
cpu,cpuacct:/
cpu,cpuacct:/test

if we delete the cgroup with the cgdelete -g, and specifying multi
controllers like this:

# cgdelete -g cpu,cpuacct:test

or

# cgdelete -g cpu:test -g cpuacct:test

it will report error:
cgdelete: cannot remove group 'test': No such file or directory

this patch fix the problem.

Signed-off-by: Weng Meiling <wengmeiling.w...@huawei.com>
---
 src/tools/cgdelete.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/tools/cgdelete.c b/src/tools/cgdelete.c
index e84cd2d..a06ec75 100644
--- a/src/tools/cgdelete.c
+++ b/src/tools/cgdelete.c
@@ -60,6 +60,8 @@ int main(int argc, char *argv[])
        int c;
        int flags = 0;
        int final_ret = 0;
+       int counter = 0;
+       int h_list[CG_CONTROLLER_MAX];

        struct cgroup_group_spec **cgroup_list = NULL;
        struct cgroup *cgroup;
@@ -139,6 +141,37 @@ int main(int argc, char *argv[])
                /* add controllers to the cgroup */
                j = 0;
                while (cgroup_list[i]->controllers[j]) {
+                       int k;
+                       struct controller_data info;
+                       void *handle;
+
+                       /* determine and skip the controllers mounted on one 
place */
+                       ret = cgroup_get_all_controller_begin(&handle, &info);
+                       while (ret == 0) {
+                               if (!strcmp(info.name, 
cgroup_list[i]->controllers[j])) {
+                                       for (k = 0; k < counter; k++)
+                                               if (h_list[k] == info.hierarchy)
+                                                       break;
+                                       if (k < counter)
+                                               goto skip_add;
+                                       else {
+                                               h_list[counter] = 
info.hierarchy;
+                                               counter++;
+                                       }
+                                       break;
+                               }
+                               ret = cgroup_get_all_controller_next(&handle, 
&info);
+                       }
+                       cgroup_get_all_controller_end(&handle);
+                       if (ret == ECGEOF)
+                               ret = 0;
+                       if (ret) {
+                               fprintf(stderr,
+                                       "cgroup_get_controller_begin/next 
failed(%s)\n",
+                               cgroup_strerror(ret));
+                               goto err;
+                       }
+
                        cgc = cgroup_add_controller(cgroup,
                                cgroup_list[i]->controllers[j]);
                        if (!cgc) {
@@ -150,6 +183,7 @@ int main(int argc, char *argv[])
                                cgroup_free(&cgroup);
                                goto err;
                        }
+               skip_add:
                        j++;
                }

-- 
1.8.2.2





------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to