]> git.proxmox.com Git - mirror_lxc.git/commitdiff
lxc_cgroup_path_get, cache the right value
authorFrançois-Xavier Bourlet <francois-xavier.bourlet@dotcloud.com>
Tue, 22 Mar 2011 14:10:37 +0000 (15:10 +0100)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Tue, 22 Mar 2011 14:10:37 +0000 (15:10 +0100)
lxc_cgroup_path_get currently cache the cgroup mount point plus the
container name at the same time, making every call of the function
returning the same value.
It mean that actually every call to lxc_cgroup_get with a different
container name will in fact use the same container name as used for
the primary call.

I join a patch to fix that, still doing some caching, but only caching
the cgroup moint point this time. This patch actually work for me, as
I am using the liblxc for retrieving statistics about all running
containers, using lxc_cgroup_get to retrieve every interesting values.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/cgroup.c

index 69761b4d6bbdd32fb2a48367771a914d6e4929f8..a068a0168b7f4c96d8f77b4ad1008b220b3bec47 100644 (file)
@@ -47,8 +47,6 @@ lxc_log_define(lxc_cgroup, lxc);
 
 #define MTAB "/proc/mounts"
 
-static char nsgroup_path[MAXPATHLEN];
-
 enum {
        CGROUP_NS_CGROUP = 1,
        CGROUP_CLONE_CHILDREN,
@@ -291,22 +289,21 @@ int lxc_cgroup_destroy(const char *name)
 
 int lxc_cgroup_path_get(char **path, const char *name)
 {
-       char cgroup[MAXPATHLEN];
-
-       *path = &nsgroup_path[0];
-
-       /*
-        * report nsgroup_path string if already set
-        */
-       if (**path != 0)
-               return 0;
-
-       if (get_cgroup_mount(MTAB, cgroup)) {
-               ERROR("cgroup is not mounted");
-               return -1;
+       static char        cgroup[MAXPATHLEN];
+       static const char* cgroup_cached = 0;
+       static char        buf[MAXPATHLEN];
+
+       if (!cgroup_cached) {
+               if (get_cgroup_mount(MTAB, cgroup)) {
+                       ERROR("cgroup is not mounted");
+                       return -1;
+               } else {
+                       cgroup_cached = cgroup;
+               }
        }
 
-       snprintf(nsgroup_path, MAXPATHLEN, "%s/%s", cgroup, name);
+       snprintf(buf, MAXPATHLEN, "%s/%s", cgroup_cached, name);
+       *path = buf;
        return 0;
 }