Commit 0411a752 by François-Xavier Bourlet Committed by Daniel Lezcano

lxc_cgroup_path_get, cache the right value

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: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent bf83c5b9
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment