[Devel] [PATCH libvzctl 4/6] cgroup: Allow to attach to specific cgroup only
Cyrill Gorcunov
gorcunov at gmail.com
Tue Feb 7 13:05:39 PST 2017
From: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
lib/cgroup.c | 4 +++-
lib/cgroup.h | 2 +-
lib/env_nsops.c | 4 ++--
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/lib/cgroup.c b/lib/cgroup.c
index bc39da9..17535c1 100644
--- a/lib/cgroup.c
+++ b/lib/cgroup.c
@@ -618,11 +618,13 @@ int cg_disable_pseudosuper(const int pseudosuper_fd)
return do_write_data(pseudosuper_fd, NULL, "0", 1);
}
-int cg_attach_task(const char *ctid, pid_t pid)
+int cg_attach_task(const char *ctid, pid_t pid, char *cg_subsys)
{
int ret, i;
for (i = 0; i < sizeof(cg_ctl_map)/sizeof(cg_ctl_map[0]); i++) {
+ if (cg_subsys && strcmp(cg_ctl_map[i].subsys, cg_subsys))
+ continue;
ret = cg_set_ul(ctid, cg_ctl_map[i].subsys, "tasks", pid);
if (ret == -1)
return -1;
diff --git a/lib/cgroup.h b/lib/cgroup.h
index 9d4508d..f815e1e 100644
--- a/lib/cgroup.h
+++ b/lib/cgroup.h
@@ -51,7 +51,7 @@ int cg_destroy_cgroup(const char *ctid);
int cg_enable_pseudosuper(const char *ctid);
int cg_pseudosuper_open(const char *ctid, int *fd);
int cg_disable_pseudosuper(const int pseudosuper_fd);
-int cg_attach_task(const char *ctid, pid_t pid);
+int cg_attach_task(const char *ctid, pid_t pid, char *cg_subsys);
int cg_set_param(const char *ctid, const char *subsys, const char *name, const char *data);
int cg_get_param(const char *ctid, const char *subsys, const char *name, char *out, int size);
int cg_get_ul(const char *ctid, const char *subsys, const char *name,
diff --git a/lib/env_nsops.c b/lib/env_nsops.c
index 20d1acb..4650506 100644
--- a/lib/env_nsops.c
+++ b/lib/env_nsops.c
@@ -705,7 +705,7 @@ static int do_env_create(struct vzctl_env_handle *h, struct start_param *param)
* children into appropriate cgroups.
*/
if (!param->fn) {
- ret = cg_attach_task(h->ctid, getpid());
+ ret = cg_attach_task(h->ctid, getpid(), NULL);
if (ret)
goto err;
}
@@ -866,7 +866,7 @@ static int ns_env_enter(struct vzctl_env_handle *h, int flags)
if (dp == NULL)
return vzctl_err(-1, errno, "Unable to open dir %s", path);
- ret = cg_attach_task(EID(h), getpid());
+ ret = cg_attach_task(EID(h), getpid(), NULL);
if (ret)
goto err;
--
2.7.4
More information about the Devel
mailing list