CGroup Namespaces
Subsystems (8)
v3 cover CGroup Namespaces
Another spin for CGroup Namespaces feature.
Changes from V2:
1. Added documentation in Documentation/cgroups/namespace.txt
2. Fixed a bug that caused crash
3. Incorporated some other suggestions from last patchset:
- removed use of threadgroup_lock() while creating new cgroupns
- use task_lock() instead of rcu_read_lock() while accessing
task->nsproxy
- optimized setns() to own cgroupns
- simplified code around sane-behavior mount option parsing
4. Restored ACKs from Serge Hallyn from v1 on few patches that have not changed since then.
Changes from V1:
1. No pinning of processes within cgroupns. Tasks can be freely moved across cgroups even outside of their cgroupns-root. Usual DAC/MAC policies apply as before.
2. Path in /proc/<pid>/cgroup is now always shown and is relative to cgroupns-root. So path can contain '/..' strings depending on cgroupns-root of the reader and cgroup of <pid>.
3. setns() does not require the process to first move under target cgroupns-root.
Changes form RFC (V0):
1. setns support for cgroupns
2. 'mount -t cgroup cgroup <mntpt>' from inside a cgroupns now mounts the cgroup hierarcy with cgroupns-root as the filesystem root.
3. writes to cgroup files outside of cgroupns-root are not allowed
4. visibility of /proc/<pid>/cgroup is further restricted by not showing anything if the <pid> is in a sibling cgroupns and its cgroup falls outside your cgroupns-root.
--- Documentation/cgroups/namespace.txt | 147 +++++++++++++++++++++++++++ fs/kernfs/dir.c | 195 ++++++++++++++++++++++++++++++++---- fs/kernfs/mount.c | 48 +++++++++ fs/proc/namespaces.c | 1 + include/linux/cgroup.h | 52 +++++++++- include/linux/cgroup_namespace.h | 36 +++++++ include/linux/kernfs.h | 5 + include/linux/nsproxy.h | 2 + include/linux/proc_ns.h | 4 + include/uapi/linux/sched.h | 3 +- kernel/Makefile | 2 +- kernel/cgroup.c | 106 +++++++++++++++----- kernel/cgroup_namespace.c | 140 ++++++++++++++++++++++++++ kernel/fork.c | 2 +- kernel/nsproxy.c | 19 +++- 15 files changed, 711 insertions(+), 51 deletions(-) create mode 100644 Documentation/cgroups/namespace.txt create mode 100644 include/linux/cgroup_namespace.h create mode 100644 kernel/cgroup_namespace.c
[PATCHv3 1/8] kernfs: Add API to generate relative kernfs path [PATCHv3 2/8] sched: new clone flag CLONE_NEWCGROUP for cgroup [PATCHv3 3/8] cgroup: add function to get task's cgroup on default [PATCHv3 4/8] cgroup: export cgroup_get() and cgroup_put() [PATCHv3 5/8] cgroup: introduce cgroup namespaces
[PATCHv3 6/8] cgroup: cgroup namespace setns support [PATCHv3 7/8] cgroup: mount cgroupns-root when inside non-init cgroupns [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
PATCH v3 1/8 kernfs: Add API to generate relative kernfs path
In reply to a message not in the archiveThe new function kernfs_path_from_node() generates and returns kernfs path of a given kernfs_node relative to a given parent kernfs_node.
--- fs/kernfs/dir.c | 195 +++++++++++++++++++++++++++++++++++++++++++------ include/linux/kernfs.h | 3 + 2 files changed, 177 insertions(+), 21 deletions(-)
fs/kernfs/dir.c +174 -21
@@ -44,28 +44,159 @@ static int kernfs_name_locked(struct kernfs_node *kn, char *buf, size_t buflen)return strlcpy (buf, kn->parent ? kn->name :"/" , buflen); } -static char *__must_check kernfs_path_locked (struct kernfs_node *kn,char *buf, -size_t buflen) +/** +* kernfs_node_depth - compute depth of the kernfs node from root. +* The root node itself is considered to be at depth 0. +*/ +static size_t kernfs_node_depth (struct kernfs_node *kn) { -char *p = buf + buflen; +size_t depth =0 ; + +BUG_ON (!kn); +while (kn->parent) { + depth++; + kn = kn->parent; + } +return depth; +} + +/** +* kernfs_path_from_node_locked - find a relative path from @kn_from to @kn_to +* @kn_from: reference node of the path +* @kn_to: kernfs node to which path is needed +* @buf: buffer to copy the path into +* @buflen: size of @buf +* +* We need to handle couple of scenarios here: +* [1] when @kn_from is an ancestor of @kn_to at some level +* kn_from: /n1/n2/n3 +* kn_to: /n1/n2/n3/n4/n5 +* result: /n4/n5 +* +* [2] when @kn_from is on a different hierarchy and we need to find common +* ancestor between @kn_from and @kn_to. +* kn_from: /n1/n2/n3/n4 +* kn_to: /n1/n2/n5 +* result: /../../n5 +* OR +* kn_from: /n1/n2/n3/n4/n5 [depth=5] +* kn_to: /n1/n2/n3 [depth=3] +* result: /../.. +*/ +static char *__must_check kernfs_path_from_node_locked ( +struct kernfs_node *kn_from, +struct kernfs_node *kn_to, +char *buf, +size_t buflen) +{ +char *p = buf; +struct kernfs_node *kn; +size_t depth_from =0 , depth_to, d;int len; - *--p ='\0' ; +/* We atleast need 2 bytes to write "/\0". */ +BUG_ON (buflen <2 ); -do { - len =strlen (kn->name); -if (p - buf < len +1 ) { - buf[0 ] ='\0' ; - p =NULL ; -break ; +/* Short-circuit the easy case - kn_to is the root node. */ +if ((kn_from == kn_to) || (!kn_from && !kn_to->parent)) { + *p ='/' ; + *(p +1 ) ='\0' ; +return p; + } + +/* We can find the relative path only if both the nodes belong to the +* same kernfs root. +*/ +if (kn_from) { +BUG_ON (kernfs_root (kn_from) !=kernfs_root (kn_to)); + depth_from =kernfs_node_depth (kn_from); + } + + depth_to =kernfs_node_depth (kn_to); + +/* We compose path from left to right. So first write out all possible +* "/.." strings needed to reach from 'kn_from' to the common ancestor. +*/ +if (kn_from) { +while (depth_from > depth_to) { + len =strlen ("/.." ); +if ((buflen - (p - buf)) < len +1 ) { +/* buffer not big enough. */ + buf[0 ] ='\0' ; +return NULL ; + } +memcpy (p,"/.." , len); + p += len; + *p ='\0' ; + --depth_from; + kn_from = kn_from->parent; } + + d = depth_to; + kn = kn_to; +while (depth_from < d) { + kn = kn->parent; + d--; + } + +/* Now we have 'depth_from == depth_to' at this point. Add more +* "/.."s until we reach common ancestor. In the worst case, +* root node will be the common ancestor. +*/ +while (depth_from >0 ) { +/* If we reached common ancestor, stop. */ +if (kn_from == kn) +break ; + len =strlen ("/.." ); +if ((buflen - (p - buf)) < len +1 ) { +/* buffer not big enough. */ + buf[0 ] ='\0' ; +return NULL ; + } +memcpy (p,"/.." , len); + p += len; + *p ='\0' ; + --depth_from; + kn_from = kn_from->parent; + kn = kn->parent; + } + } + +/* Figure out how many bytes we need to write the path. +*/ + d = depth_to; + kn = kn_to; + len =0 ; +while (depth_from < d) { +/* Account for "/<name>". */ + len +=strlen (kn->name) +1 ; + kn = kn->parent; + --d; + } + +if ((buflen - (p - buf)) < len +1 ) { +/* buffer not big enough. */ + buf[0 ] ='\0' ; +return NULL ; + } + +/* We have enough space. Move 'p' ahead by computed length and start +* writing node names into buffer. +*/ + p += len; + *p ='\0' ; + d = depth_to; + kn = kn_to; +while (d > depth_from) { + len =strlen (kn->name); p -= len;memcpy (p, kn->name, len); *--p ='/' ; kn = kn->parent; - }while (kn && kn->parent); + --d; + } -return p; +return buf; }/**
@@ -92,26 +223,48 @@ int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen) }/** -* kernfs_path - build full path of a given node +* kernfs_path_from_node - build path of node @kn relative to @kn_root. +* @kn_root: parent kernfs_node relative to which we need to build the path * @kn: kernfs_node of interest -* @buf: buffer to copy @kn's name into +* @buf: buffer to copy @kn's path into * @buflen: size of @buf * -* Builds and returns the full path of @kn in @buf of @buflen bytes. The -* path is built from the end of @buf so the returned pointer usually -* doesn't match @buf. If @buf isn't long enough, @buf is nul terminated +* Builds and returns @kn's path relative to @kn_root. @kn_root and @kn must +* be on the same kernfs-root. If @kn_root is not parent of @kn, then a relative +* path (which includes '..'s) as needed to reach from @kn_root to @kn is +* returned. +* The path may be built from the end of @buf so the returned pointer may not +* match @buf. If @buf isn't long enough, @buf is nul terminated * and %NULL is returned. */ -char *kernfs_path (struct kernfs_node *kn,char *buf,size_t buflen) +char *kernfs_path_from_node (struct kernfs_node *kn_root,struct kernfs_node *kn, +char *buf,size_t buflen) {unsigned long flags;char *p;spin_lock_irqsave (&kernfs_rename_lock, flags); - p =kernfs_path_locked (kn, buf, buflen); + p =kernfs_path_from_node_locked (kn_root, kn, buf, buflen);spin_unlock_irqrestore (&kernfs_rename_lock, flags);return p; } +EXPORT_SYMBOL_GPL (kernfs_path_from_node); + +/** +* kernfs_path - build full path of a given node +* @kn: kernfs_node of interest +* @buf: buffer to copy @kn's name into +* @buflen: size of @buf +* +* Builds and returns the full path of @kn in @buf of @buflen bytes. The +* path is built from the end of @buf so the returned pointer usually +* doesn't match @buf. If @buf isn't long enough, @buf is nul terminated +* and %NULL is returned. +*/ +char *kernfs_path (struct kernfs_node *kn,char *buf,size_t buflen) +{ +return kernfs_path_from_node (NULL , kn, buf, buflen); +}EXPORT_SYMBOL_GPL (kernfs_path);/**
@@ -145,8 +298,8 @@ void pr_cont_kernfs_path(struct kernfs_node *kn)spin_lock_irqsave (&kernfs_rename_lock, flags); - p =kernfs_path_locked (kn, kernfs_pr_cont_buf, -sizeof (kernfs_pr_cont_buf)); + p =kernfs_path_from_node_locked (NULL , kn, kernfs_pr_cont_buf, +sizeof (kernfs_pr_cont_buf));if (p)pr_cont ("%s" , p);else
include/linux/kernfs.h +3 -0
@@ -258,6 +258,9 @@ static inline bool kernfs_ns_enabled(struct kernfs_node *kn) }int kernfs_name (struct kernfs_node *kn,char *buf,size_t buflen); +char *__must_check kernfs_path_from_node (struct kernfs_node *root_kn, +struct kernfs_node *kn,char *buf, +size_t buflen);char *__must_check kernfs_path (struct kernfs_node *kn,char *buf,size_t buflen);void pr_cont_kernfs_name (struct kernfs_node *kn);
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v3 1/8 kernfs: Add API to generate relative kernfs path
In reply to a message not in the archiveThe new function kernfs_path_from_node() generates and returns kernfs path of a given kernfs_node relative to a given parent kernfs_node.
--- fs/kernfs/dir.c | 195 +++++++++++++++++++++++++++++++++++++++++++------ include/linux/kernfs.h | 3 + 2 files changed, 177 insertions(+), 21 deletions(-)
fs/kernfs/dir.c +174 -21
@@ -44,28 +44,159 @@ static int kernfs_name_locked(struct kernfs_node *kn, char *buf, size_t buflen)return strlcpy (buf, kn->parent ? kn->name :"/" , buflen); } -static char *__must_check kernfs_path_locked (struct kernfs_node *kn,char *buf, -size_t buflen) +/** +* kernfs_node_depth - compute depth of the kernfs node from root. +* The root node itself is considered to be at depth 0. +*/ +static size_t kernfs_node_depth (struct kernfs_node *kn) { -char *p = buf + buflen; +size_t depth =0 ; + +BUG_ON (!kn); +while (kn->parent) { + depth++; + kn = kn->parent; + } +return depth; +} + +/** +* kernfs_path_from_node_locked - find a relative path from @kn_from to @kn_to +* @kn_from: reference node of the path +* @kn_to: kernfs node to which path is needed +* @buf: buffer to copy the path into +* @buflen: size of @buf +* +* We need to handle couple of scenarios here: +* [1] when @kn_from is an ancestor of @kn_to at some level +* kn_from: /n1/n2/n3 +* kn_to: /n1/n2/n3/n4/n5 +* result: /n4/n5 +* +* [2] when @kn_from is on a different hierarchy and we need to find common +* ancestor between @kn_from and @kn_to. +* kn_from: /n1/n2/n3/n4 +* kn_to: /n1/n2/n5 +* result: /../../n5 +* OR +* kn_from: /n1/n2/n3/n4/n5 [depth=5] +* kn_to: /n1/n2/n3 [depth=3] +* result: /../.. +*/ +static char *__must_check kernfs_path_from_node_locked ( +struct kernfs_node *kn_from, +struct kernfs_node *kn_to, +char *buf, +size_t buflen) +{ +char *p = buf; +struct kernfs_node *kn; +size_t depth_from =0 , depth_to, d;int len; - *--p ='\0' ; +/* We atleast need 2 bytes to write "/\0". */ +BUG_ON (buflen <2 ); -do { - len =strlen (kn->name); -if (p - buf < len +1 ) { - buf[0 ] ='\0' ; - p =NULL ; -break ; +/* Short-circuit the easy case - kn_to is the root node. */ +if ((kn_from == kn_to) || (!kn_from && !kn_to->parent)) { + *p ='/' ; + *(p +1 ) ='\0' ; +return p; + } + +/* We can find the relative path only if both the nodes belong to the +* same kernfs root. +*/ +if (kn_from) { +BUG_ON (kernfs_root (kn_from) !=kernfs_root (kn_to)); + depth_from =kernfs_node_depth (kn_from); + } + + depth_to =kernfs_node_depth (kn_to); + +/* We compose path from left to right. So first write out all possible +* "/.." strings needed to reach from 'kn_from' to the common ancestor. +*/ +if (kn_from) { +while (depth_from > depth_to) { + len =strlen ("/.." ); +if ((buflen - (p - buf)) < len +1 ) { +/* buffer not big enough. */ + buf[0 ] ='\0' ; +return NULL ; + } +memcpy (p,"/.." , len); + p += len; + *p ='\0' ; + --depth_from; + kn_from = kn_from->parent; } + + d = depth_to; + kn = kn_to; +while (depth_from < d) { + kn = kn->parent; + d--; + } + +/* Now we have 'depth_from == depth_to' at this point. Add more +* "/.."s until we reach common ancestor. In the worst case, +* root node will be the common ancestor. +*/ +while (depth_from >0 ) { +/* If we reached common ancestor, stop. */ +if (kn_from == kn) +break ; + len =strlen ("/.." ); +if ((buflen - (p - buf)) < len +1 ) { +/* buffer not big enough. */ + buf[0 ] ='\0' ; +return NULL ; + } +memcpy (p,"/.." , len); + p += len; + *p ='\0' ; + --depth_from; + kn_from = kn_from->parent; + kn = kn->parent; + } + } + +/* Figure out how many bytes we need to write the path. +*/ + d = depth_to; + kn = kn_to; + len =0 ; +while (depth_from < d) { +/* Account for "/<name>". */ + len +=strlen (kn->name) +1 ; + kn = kn->parent; + --d; + } + +if ((buflen - (p - buf)) < len +1 ) { +/* buffer not big enough. */ + buf[0 ] ='\0' ; +return NULL ; + } + +/* We have enough space. Move 'p' ahead by computed length and start +* writing node names into buffer. +*/ + p += len; + *p ='\0' ; + d = depth_to; + kn = kn_to; +while (d > depth_from) { + len =strlen (kn->name); p -= len;memcpy (p, kn->name, len); *--p ='/' ; kn = kn->parent; - }while (kn && kn->parent); + --d; + } -return p; +return buf; }/**
@@ -92,26 +223,48 @@ int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen) }/** -* kernfs_path - build full path of a given node +* kernfs_path_from_node - build path of node @kn relative to @kn_root. +* @kn_root: parent kernfs_node relative to which we need to build the path * @kn: kernfs_node of interest -* @buf: buffer to copy @kn's name into +* @buf: buffer to copy @kn's path into * @buflen: size of @buf * -* Builds and returns the full path of @kn in @buf of @buflen bytes. The -* path is built from the end of @buf so the returned pointer usually -* doesn't match @buf. If @buf isn't long enough, @buf is nul terminated +* Builds and returns @kn's path relative to @kn_root. @kn_root and @kn must +* be on the same kernfs-root. If @kn_root is not parent of @kn, then a relative +* path (which includes '..'s) as needed to reach from @kn_root to @kn is +* returned. +* The path may be built from the end of @buf so the returned pointer may not +* match @buf. If @buf isn't long enough, @buf is nul terminated * and %NULL is returned. */ -char *kernfs_path (struct kernfs_node *kn,char *buf,size_t buflen) +char *kernfs_path_from_node (struct kernfs_node *kn_root,struct kernfs_node *kn, +char *buf,size_t buflen) {unsigned long flags;char *p;spin_lock_irqsave (&kernfs_rename_lock, flags); - p =kernfs_path_locked (kn, buf, buflen); + p =kernfs_path_from_node_locked (kn_root, kn, buf, buflen);spin_unlock_irqrestore (&kernfs_rename_lock, flags);return p; } +EXPORT_SYMBOL_GPL (kernfs_path_from_node); + +/** +* kernfs_path - build full path of a given node +* @kn: kernfs_node of interest +* @buf: buffer to copy @kn's name into +* @buflen: size of @buf +* +* Builds and returns the full path of @kn in @buf of @buflen bytes. The +* path is built from the end of @buf so the returned pointer usually +* doesn't match @buf. If @buf isn't long enough, @buf is nul terminated +* and %NULL is returned. +*/ +char *kernfs_path (struct kernfs_node *kn,char *buf,size_t buflen) +{ +return kernfs_path_from_node (NULL , kn, buf, buflen); +}EXPORT_SYMBOL_GPL (kernfs_path);/**
@@ -145,8 +298,8 @@ void pr_cont_kernfs_path(struct kernfs_node *kn)spin_lock_irqsave (&kernfs_rename_lock, flags); - p =kernfs_path_locked (kn, kernfs_pr_cont_buf, -sizeof (kernfs_pr_cont_buf)); + p =kernfs_path_from_node_locked (NULL , kn, kernfs_pr_cont_buf, +sizeof (kernfs_pr_cont_buf));if (p)pr_cont ("%s" , p);else
include/linux/kernfs.h +3 -0
@@ -258,6 +258,9 @@ static inline bool kernfs_ns_enabled(struct kernfs_node *kn) }int kernfs_name (struct kernfs_node *kn,char *buf,size_t buflen); +char *__must_check kernfs_path_from_node (struct kernfs_node *root_kn, +struct kernfs_node *kn,char *buf, +size_t buflen);char *__must_check kernfs_path (struct kernfs_node *kn,char *buf,size_t buflen);void pr_cont_kernfs_name (struct kernfs_node *kn);
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v3 2/8 sched: new clone flag CLONE_NEWCGROUP for cgroup namespace
In reply to a message not in the archiveCLONE_NEWCGROUP will be used to create new cgroup namespace.
--- include/uapi/linux/sched.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
include/uapi/linux/sched.h +1 -2
@@ -21,8 +21,7 @@#define CLONE_DETACHED 0x00400000/* Unused, ignored */ #define CLONE_UNTRACED 0x00800000/* set if the tracing process can't force CLONE_PTRACE on this clone */ #define CLONE_CHILD_SETTID 0x01000000/* set the TID in the child */ -/* 0x02000000 was previously the unused CLONE_STOPPED (Start in stopped state) -and is now available for re-use. */ +#define CLONE_NEWCGROUP 0x02000000/* New cgroup namespace */ #define CLONE_NEWUTS 0x04000000/* New utsname group? */ #define CLONE_NEWIPC 0x08000000/* New ipcs */ #define CLONE_NEWUSER 0x10000000/* New user namespace */
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v3 3/8 cgroup: add function to get task's cgroup on default hierarchy
In reply to a message not in the archiveget_task_cgroup() returns the (reference counted) cgroup of the given task on the default hierarchy.
--- include/linux/cgroup.h | 1 + kernel/cgroup.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+)
include/linux/cgroup.h +1 -0
@@ -579,6 +579,7 @@ static inline void pr_cont_cgroup_path(struct cgroup *cgrp) }char *task_cgroup_path (struct task_struct *task,char *buf,size_t buflen); +struct cgroup *get_task_cgroup (struct task_struct *task);int cgroup_add_dfl_cftypes (struct cgroup_subsys *ss,struct cftype *cfts);int cgroup_add_legacy_cftypes (struct cgroup_subsys *ss,struct cftype *cfts);
kernel/cgroup.c +25 -0
@@ -1966,6 +1966,31 @@ char *task_cgroup_path(struct task_struct *task, char *buf, size_t buflen) }EXPORT_SYMBOL_GPL (task_cgroup_path); +/* +* get_task_cgroup - returns the cgroup of the task in the default cgroup +* hierarchy. +* +* @task: target task +* This function returns the @task's cgroup on the default cgroup hierarchy. The +* returned cgroup has its reference incremented (by calling cgroup_get()). So +* the caller must cgroup_put() the obtained reference once it is done with it. +*/ +struct cgroup *get_task_cgroup (struct task_struct *task) +{ +struct cgroup *cgrp; + +mutex_lock (&cgroup_mutex); +down_read (&css_set_rwsem); + + cgrp =task_cgroup_from_root (task, &cgrp_dfl_root); +cgroup_get (cgrp); + +up_read (&css_set_rwsem); +mutex_unlock (&cgroup_mutex); +return cgrp; +} +EXPORT_SYMBOL_GPL (get_task_cgroup); +/* used to track tasks and other necessary states during migration */ struct cgroup_taskset {/* the src and dst cset list running through cset->mg_node */
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v3 4/8 cgroup: export cgroup_get() and cgroup_put()
In reply to a message not in the archivemove cgroup_get() and cgroup_put() into cgroup.h so that they can be called from other places.
--- include/linux/cgroup.h | 22 ++++++++++++++++++++++ kernel/cgroup.c | 22 ---------------------- 2 files changed, 22 insertions(+), 22 deletions(-)
include/linux/cgroup.h +22 -0
@@ -521,6 +521,28 @@ static inline bool cgroup_on_dfl(const struct cgroup *cgrp)return cgrp->root == &cgrp_dfl_root; } +/* convenient tests for these bits */ +static inline bool cgroup_is_dead (const struct cgroup *cgrp) +{ +return !(cgrp->self.flags &CSS_ONLINE ); +} + +static inline void cgroup_get (struct cgroup *cgrp) +{ +WARN_ON_ONCE (cgroup_is_dead (cgrp)); +css_get (&cgrp->self); +} + +static inline bool cgroup_tryget (struct cgroup *cgrp) +{ +return css_tryget (&cgrp->self); +} + +static inline void cgroup_put (struct cgroup *cgrp) +{ +css_put (&cgrp->self); +} +/* no synchronization, the result can only be used as a hint */ static inline bool cgroup_has_tasks (struct cgroup *cgrp) {
kernel/cgroup.c +0 -22
@@ -321,12 +321,6 @@ out_unlock:return css; } -/* convenient tests for these bits */ -static inline bool cgroup_is_dead (const struct cgroup *cgrp) -{ -return !(cgrp->self.flags &CSS_ONLINE ); -} -struct cgroup_subsys_state *of_css (struct kernfs_open_file *of) {struct cgroup *cgrp = of->kn->parent->priv;
@@ -1039,22 +1033,6 @@ static umode_t cgroup_file_mode(const struct cftype *cft)return mode; } -static void cgroup_get (struct cgroup *cgrp) -{ -WARN_ON_ONCE (cgroup_is_dead (cgrp)); -css_get (&cgrp->self); -} - -static bool cgroup_tryget (struct cgroup *cgrp) -{ -return css_tryget (&cgrp->self); -} - -static void cgroup_put (struct cgroup *cgrp) -{ -css_put (&cgrp->self); -} -/** * cgroup_calc_child_subsys_mask - calculate child_subsys_mask * @cgrp: the target cgroup
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v3 5/8 cgroup: introduce cgroup namespaces
In reply to a message not in the archiveIntroduce the ability to create new cgroup namespace. The newly created cgroup namespace remembers the cgroup of the process at the point of creation of the cgroup namespace (referred as cgroupns-root). The main purpose of cgroup namespace is to virtualize the contents of /proc/self/cgroup file. Processes inside a cgroup namespace are only able to see paths relative to their namespace root (unless they are moved outside of their cgroupns-root, at which point
they will see a relative path from their cgroupns-root).
For a correctly setup container this enables container-tools (like libcontainer, lxc, lmctfy, etc.) to create completely virtualized containers without leaking system level cgroup hierarchy to the task. This patch only implements the 'unshare' part of the cgroupns.
--- fs/proc/namespaces.c | 1 + include/linux/cgroup.h | 29 ++++++++- include/linux/cgroup_namespace.h | 36 +++++++++++ include/linux/nsproxy.h | 2 + include/linux/proc_ns.h | 4 ++ kernel/Makefile | 2 +- kernel/cgroup.c | 13 ++++ kernel/cgroup_namespace.c | 127 +++++++++++++++++++++++++++++++++++++++ kernel/fork.c | 2 +- kernel/nsproxy.c | 19 +++++- 10 files changed, 230 insertions(+), 5 deletions(-)
fs/proc/namespaces.c +1 -0
@@ -32,6 +32,7 @@ static const struct proc_ns_operations *ns_entries[] = { &userns_operations, #endif &mntns_operations, + &cgroupns_operations, }; static const struct file_operations ns_file_operations = {
include/linux/cgroup.h +28 -1
@@ -22,6 +22,8 @@#include <linux/seq_file.h> #include <linux/kernfs.h> #include <linux/wait.h> +#include <linux/nsproxy.h> +#include <linux/types.h> #ifdef CONFIG_CGROUPS
@@ -460,6 +462,13 @@ struct cftype {#endif }; +struct cgroup_namespace { +atomic_t count; +unsigned int proc_inum; +struct user_namespace *user_ns; +struct cgroup *root_cgrp; +}; +extern struct cgroup_root cgrp_dfl_root;extern struct css_set init_css_set;
@@ -584,10 +593,28 @@ static inline int cgroup_name(struct cgroup *cgrp, char *buf, size_t buflen)return kernfs_name (cgrp->kn, buf, buflen); } +static inline char *__must_check cgroup_path_ns (struct cgroup_namespace *ns, +struct cgroup *cgrp,char *buf, +size_t buflen) +{ +if (ns) { +BUG_ON (!cgroup_on_dfl (cgrp)); +return kernfs_path_from_node (ns->root_cgrp->kn, cgrp->kn, buf, + buflen); + }else { +return kernfs_path (cgrp->kn, buf, buflen); + } +} +static inline char *__must_check cgroup_path (struct cgroup *cgrp,char *buf,size_t buflen) { -return kernfs_path (cgrp->kn, buf, buflen); +if (cgroup_on_dfl (cgrp)) { +return cgroup_path_ns (current->nsproxy->cgroup_ns, cgrp, buf, + buflen); + }else { +return cgroup_path_ns (NULL , cgrp, buf, buflen); + } }static inline void pr_cont_cgroup_name (struct cgroup *cgrp)
include/linux/cgroup_namespace.h new file +36 -0
@@ -0,0 +1,36 @@ +#ifndef _LINUX_CGROUP_NAMESPACE_H +#define _LINUX_CGROUP_NAMESPACE_H + +#include <linux/nsproxy.h> +#include <linux/cgroup.h> +#include <linux/types.h> +#include <linux/user_namespace.h> + +extern struct cgroup_namespace init_cgroup_ns; + +static inline struct cgroup *current_cgroupns_root (void ) +{ +return current->nsproxy->cgroup_ns->root_cgrp; +} + +extern void free_cgroup_ns (struct cgroup_namespace *ns); + +static inline struct cgroup_namespace *get_cgroup_ns ( +struct cgroup_namespace *ns) +{ +if (ns) +atomic_inc (&ns->count); +return ns; +} + +static inline void put_cgroup_ns (struct cgroup_namespace *ns) +{ +if (ns &&atomic_dec_and_test (&ns->count)) +free_cgroup_ns (ns); +} + +extern struct cgroup_namespace *copy_cgroup_ns (unsigned long flags, +struct user_namespace *user_ns, +struct cgroup_namespace *old_ns); + +#endif /* _LINUX_CGROUP_NAMESPACE_H */
include/linux/nsproxy.h +2 -0
@@ -8,6 +8,7 @@ struct mnt_namespace;struct uts_namespace ;struct ipc_namespace ;struct pid_namespace ; +struct cgroup_namespace ;struct fs_struct ;/*
@@ -33,6 +34,7 @@ struct nsproxy {struct mnt_namespace *mnt_ns;struct pid_namespace *pid_ns_for_children;struct net *net_ns; +struct cgroup_namespace *cgroup_ns; };extern struct nsproxy init_nsproxy;
include/linux/proc_ns.h +4 -0
@@ -6,6 +6,8 @@struct pid_namespace ;struct nsproxy ; +struct task_struct ; +struct inode ;struct proc_ns_operations {const char *name;
@@ -27,6 +29,7 @@ extern const struct proc_ns_operations ipcns_operations;extern const struct proc_ns_operations pidns_operations;extern const struct proc_ns_operations userns_operations;extern const struct proc_ns_operations mntns_operations; +extern const struct proc_ns_operations cgroupns_operations;/* * We always define these enumerators
@@ -37,6 +40,7 @@ enum {PROC_UTS_INIT_INO =0xEFFFFFFEU ,PROC_USER_INIT_INO =0xEFFFFFFDU ,PROC_PID_INIT_INO =0xEFFFFFFCU , + PROC_CGROUP_INIT_INO = 0xEFFFFFFBU, };#ifdef CONFIG_PROC_FS
kernel/Makefile +1 -1
@@ -50,7 +50,7 @@ obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o obj-$(CONFIG_COMPAT) += compat.o -obj-$(CONFIG_CGROUPS) += cgroup.o +obj-$(CONFIG_CGROUPS) += cgroup.o cgroup_namespace.o obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o obj-$(CONFIG_CPUSETS) += cpuset.o obj-$(CONFIG_UTS_NS) += utsname.o
kernel/cgroup.c +13 -0
@@ -57,6 +57,8 @@#include <linux/vmalloc.h> /* TODO: replace with more sophisticated array */ #include <linux/kthread.h> #include <linux/delay.h> +#include <linux/proc_ns.h> +#include <linux/cgroup_namespace.h> #include <linux/atomic.h>
@@ -195,6 +197,15 @@ static void kill_css(struct cgroup_subsys_state *css);static int cgroup_addrm_files (struct cgroup *cgrp,struct cftype cfts[],bool is_add); +struct cgroup_namespace init_cgroup_ns = { + .count = { + .counter =1 , + }, + .proc_inum =PROC_CGROUP_INIT_INO , + .user_ns = &init_user_ns, + .root_cgrp = &cgrp_dfl_root.cgrp, +}; +/* IDR wrappers which synchronize using cgroup_idr_lock */ static int cgroup_idr_alloc (struct idr *idr,void *ptr,int start,int end,gfp_t gfp_mask)
@@ -4989,6 +5000,8 @@ int __init cgroup_init(void)unsigned long key;int ssid, err; +get_user_ns (init_cgroup_ns.user_ns); +BUG_ON (cgroup_init_cftypes (NULL , cgroup_dfl_base_files));BUG_ON (cgroup_init_cftypes (NULL , cgroup_legacy_base_files));
kernel/cgroup_namespace.c new file +127 -0
127 lines not on this page · raw message
kernel/fork.c +1 -1
@@ -1797,7 +1797,7 @@ static int check_unshare_flags(unsigned long unshare_flags)if (unshare_flags & ~(CLONE_THREAD |CLONE_FS |CLONE_NEWNS |CLONE_SIGHAND |CLONE_VM |CLONE_FILES |CLONE_SYSVSEM |CLONE_NEWUTS |CLONE_NEWIPC |CLONE_NEWNET | -CLONE_NEWUSER |CLONE_NEWPID )) +CLONE_NEWUSER |CLONE_NEWPID |CLONE_NEWCGROUP ))return -EINVAL ;/* * Not implemented, but pretend it works if there is nothing to
kernel/nsproxy.c +17 -2
@@ -25,6 +25,7 @@#include <linux/proc_ns.h> #include <linux/file.h> #include <linux/syscalls.h> +#include <linux/cgroup_namespace.h> static struct kmem_cache *nsproxy_cachep;
@@ -39,6 +40,7 @@ struct nsproxy init_nsproxy = {#ifdef CONFIG_NET .net_ns = &init_net, #endif + .cgroup_ns = &init_cgroup_ns, };static inline struct nsproxy *create_nsproxy (void )
@@ -92,6 +94,13 @@ static struct nsproxy *create_new_namespaces(unsigned long flags, goto out_pid; } + new_nsp->cgroup_ns =copy_cgroup_ns (flags, user_ns, + tsk->nsproxy->cgroup_ns); +if (IS_ERR (new_nsp->cgroup_ns)) { + err =PTR_ERR (new_nsp->cgroup_ns); + goto out_cgroup; + } + new_nsp->net_ns =copy_net_ns (flags, user_ns, tsk->nsproxy->net_ns);if (IS_ERR (new_nsp->net_ns)) { err =PTR_ERR (new_nsp->net_ns);
@@ -101,6 +110,9 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,return new_nsp; out_net: +if (new_nsp->cgroup_ns) +put_cgroup_ns (new_nsp->cgroup_ns); +out_cgroup:if (new_nsp->pid_ns_for_children)put_pid_ns (new_nsp->pid_ns_for_children); out_pid:
@@ -128,7 +140,8 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)struct nsproxy *new_ns;if (likely (!(flags & (CLONE_NEWNS |CLONE_NEWUTS |CLONE_NEWIPC | -CLONE_NEWPID |CLONE_NEWNET )))) { +CLONE_NEWPID |CLONE_NEWNET | +CLONE_NEWCGROUP )))) {get_nsproxy (old_ns);return 0 ; }
@@ -165,6 +178,8 @@ void free_nsproxy(struct nsproxy *ns)put_ipc_ns (ns->ipc_ns);if (ns->pid_ns_for_children)put_pid_ns (ns->pid_ns_for_children); +if (ns->cgroup_ns) +put_cgroup_ns (ns->cgroup_ns);put_net (ns->net_ns);kmem_cache_free (nsproxy_cachep, ns); }
@@ -180,7 +195,7 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,int err =0 ;if (!(unshare_flags & (CLONE_NEWNS |CLONE_NEWUTS |CLONE_NEWIPC | -CLONE_NEWNET |CLONE_NEWPID ))) +CLONE_NEWNET |CLONE_NEWPID |CLONE_NEWCGROUP )))return 0 ; user_ns = new_cred ? new_cred->user_ns :current_user_ns ();
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v3 6/8 cgroup: cgroup namespace setns support
In reply to a message not in the archivesetns on a cgroup namespace is allowed only if task has CAP_SYS_ADMIN in its current user-namespace and over the user-namespace associated with target cgroupns. No implicit cgroup changes happen with attaching to another cgroupns. It is expected that the somone moves the attaching process under the target cgroupns-root.
--- kernel/cgroup_namespace.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
kernel/cgroup_namespace.c +15 -2
@@ -79,8 +79,21 @@ err_out:static int cgroupns_install (struct nsproxy *nsproxy,void *ns) { -pr_info ("setns not supported for cgroup namespace" ); -return -EINVAL ; +struct cgroup_namespace *cgroup_ns = ns; + +if (!ns_capable (current_user_ns (),CAP_SYS_ADMIN ) || + !ns_capable (cgroup_ns->user_ns,CAP_SYS_ADMIN )) +return -EPERM ; + +/* Don't need to do anything if we are attaching to our own cgroupns. */ +if (cgroup_ns == nsproxy->cgroup_ns) +return 0 ; + +get_cgroup_ns (cgroup_ns); +put_cgroup_ns (nsproxy->cgroup_ns); + nsproxy->cgroup_ns = cgroup_ns; + +return 0 ; }static void *cgroupns_get (struct task_struct *task)
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v3 7/8 cgroup: mount cgroupns-root when inside non-init cgroupns
In reply to a message not in the archiveThis patch enables cgroup mounting inside userns when a process as appropriate privileges. The cgroup filesystem mounted is rooted at the cgroupns-root. Thus, in a container-setup, only the hierarchy under the cgroupns-root is exposed inside the container. This allows container management tools to run inside the containers without depending on any global state.
In order to support this, a new kernfs api is added to lookup the dentry for the cgroupns-root.
--- fs/kernfs/mount.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/kernfs.h | 2 ++ kernel/cgroup.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 95 insertions(+), 1 deletion(-)
fs/kernfs/mount.c +48 -0
@@ -62,6 +62,54 @@ struct kernfs_root *kernfs_root_from_sb(struct super_block *sb)return NULL ; } +/** +* kernfs_obtain_root - get a dentry for the given kernfs_node +* @sb: the kernfs super_block +* @kn: kernfs_node for which a dentry is needed +* +* This can used used by callers which want to mount only a part of the kernfs +* as root of the filesystem. +*/ +struct dentry *kernfs_obtain_root (struct super_block *sb, +struct kernfs_node *kn) +{ +struct dentry *dentry; +struct inode *inode; + +BUG_ON (sb->s_op != &kernfs_sops); + +/* inode for the given kernfs_node should already exist. */ + inode =ilookup (sb, kn->ino); +if (!inode) { +pr_debug ("kernfs: could not get inode for '" ); +pr_cont_kernfs_path (kn); +pr_cont ("'.\n" ); +return ERR_PTR (-EINVAL ); + } + +/* instantiate and link root dentry */ + dentry =d_obtain_root (inode); +if (!dentry) { +pr_debug ("kernfs: could not get dentry for '" ); +pr_cont_kernfs_path (kn); +pr_cont ("'.\n" ); +return ERR_PTR (-ENOMEM ); + } + +/* If this is a new dentry, set it up. We need kernfs_mutex because this +* may be called by callers other than kernfs_fill_super. */ +mutex_lock (&kernfs_mutex); +if (!dentry->d_fsdata) { +kernfs_get (kn); + dentry->d_fsdata = kn; + }else { +WARN_ON (dentry->d_fsdata != kn); + } +mutex_unlock (&kernfs_mutex); + +return dentry; +} +static int kernfs_fill_super (struct super_block *sb,unsigned long magic) {struct kernfs_super_info *info =kernfs_info (sb);
include/linux/kernfs.h +2 -0
@@ -274,6 +274,8 @@ void kernfs_put(struct kernfs_node *kn);struct kernfs_node *kernfs_node_from_dentry (struct dentry *dentry);struct kernfs_root *kernfs_root_from_sb (struct super_block *sb); +struct dentry *kernfs_obtain_root (struct super_block *sb, +struct kernfs_node *kn);struct kernfs_root *kernfs_create_root (struct kernfs_syscall_ops *scops,unsigned int flags,void *priv);void kernfs_destroy_root (struct kernfs_root *root);
kernel/cgroup.c +45 -1
86 lines not on this page · raw message
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v3 7/8 cgroup: mount cgroupns-root when inside non-init cgroupns
In reply to a message not in the archiveThis patch enables cgroup mounting inside userns when a process as appropriate privileges. The cgroup filesystem mounted is rooted at the cgroupns-root. Thus, in a container-setup, only the hierarchy under the cgroupns-root is exposed inside the container. This allows container management tools to run inside the containers without depending on any global state.
In order to support this, a new kernfs api is added to lookup the dentry for the cgroupns-root.
--- fs/kernfs/mount.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/kernfs.h | 2 ++ kernel/cgroup.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 95 insertions(+), 1 deletion(-)
fs/kernfs/mount.c +48 -0
@@ -62,6 +62,54 @@ struct kernfs_root *kernfs_root_from_sb(struct super_block *sb)return NULL ; } +/** +* kernfs_obtain_root - get a dentry for the given kernfs_node +* @sb: the kernfs super_block +* @kn: kernfs_node for which a dentry is needed +* +* This can used used by callers which want to mount only a part of the kernfs +* as root of the filesystem. +*/ +struct dentry *kernfs_obtain_root (struct super_block *sb, +struct kernfs_node *kn) +{ +struct dentry *dentry; +struct inode *inode; + +BUG_ON (sb->s_op != &kernfs_sops); + +/* inode for the given kernfs_node should already exist. */ + inode =ilookup (sb, kn->ino); +if (!inode) { +pr_debug ("kernfs: could not get inode for '" ); +pr_cont_kernfs_path (kn); +pr_cont ("'.\n" ); +return ERR_PTR (-EINVAL ); + } + +/* instantiate and link root dentry */ + dentry =d_obtain_root (inode); +if (!dentry) { +pr_debug ("kernfs: could not get dentry for '" ); +pr_cont_kernfs_path (kn); +pr_cont ("'.\n" ); +return ERR_PTR (-ENOMEM ); + } + +/* If this is a new dentry, set it up. We need kernfs_mutex because this +* may be called by callers other than kernfs_fill_super. */ +mutex_lock (&kernfs_mutex); +if (!dentry->d_fsdata) { +kernfs_get (kn); + dentry->d_fsdata = kn; + }else { +WARN_ON (dentry->d_fsdata != kn); + } +mutex_unlock (&kernfs_mutex); + +return dentry; +} +static int kernfs_fill_super (struct super_block *sb,unsigned long magic) {struct kernfs_super_info *info =kernfs_info (sb);
include/linux/kernfs.h +2 -0
@@ -274,6 +274,8 @@ void kernfs_put(struct kernfs_node *kn);struct kernfs_node *kernfs_node_from_dentry (struct dentry *dentry);struct kernfs_root *kernfs_root_from_sb (struct super_block *sb); +struct dentry *kernfs_obtain_root (struct super_block *sb, +struct kernfs_node *kn);struct kernfs_root *kernfs_create_root (struct kernfs_syscall_ops *scops,unsigned int flags,void *priv);void kernfs_destroy_root (struct kernfs_root *root);
kernel/cgroup.c +45 -1
86 lines not on this page · raw message
Signature · 1 line
2.2.0.rc0.207.ga3a616c
PATCH v3 8/8 cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archive--- Documentation/cgroups/namespace.txt | 147 ++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 Documentation/cgroups/namespace.txt
Documentation/cgroups/namespace.txt new file +147 -0
@@ -0,0 +1,147 @@ + CGroup Namespaces + +CGroup Namespace provides a mechanism to virtualize the view of the +/proc/<pid>/cgroup file. The CLONE_NEWCGROUP clone-flag can be used with +clone() and unshare() syscalls to create a new cgroup namespace. +The process running inside the cgroup namespace will have its /proc/<pid>/cgroup +output restricted to cgroupns-root. cgroupns-root is the cgroup of the process +at the time of creation of the cgroup namespace. + +Prior to CGroup Namespace, the /proc/<pid>/cgroup file used to show complete +path of the cgroup of a process. In a container setup (where a set of cgroups +and namespaces are intended to isolate processes), the /proc/<pid>/cgroup file +may leak potential system level information to the isolated processes. + +For Example: + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + +The path '/batchjobs/container_id1' can generally be considered as system-data +and its desirable to not expose it to the isolated process. + +CGroup Namespaces can be used to restrict visibility of this path. +For Example: + # Before creating cgroup namespace + $ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:37 /proc/self/ns/cgroup -> cgroup:[4026531835] + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # unshare(CLONE_NEWCGROUP) and exec /bin/bash + $ ~/unshare -c + [ns]$ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:35 /proc/self/ns/cgroup -> cgroup:[4026532183] + # From within new cgroupns, process sees that its in the root cgroup + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/ + + # From global cgroupns: + $ cat /proc/<pid>/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # Unshare cgroupns along with userns and mountns + # Following calls unshare(CLONE_NEWCGROUP|CLONE_NEWUSER|CLONE_NEWNS), then + # sets up uid/gid map and execs /bin/bash + $ ~/unshare -c -u -m + # Originally, we were in /batchjobs/container_id1 cgroup. Mount our own cgroup + # hierarchy. + [ns]$ mount -t cgroup cgroup /tmp/cgroup + [ns]$ ls -l /tmp/cgroup + total 0 + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.controllers + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.populated + -rw-r--r-- 1 root root 0 2014-10-13 09:25 cgroup.procs + -rw-r--r-- 1 root root 0 2014-10-13 09:32 cgroup.subtree_control + +The cgroupns-root (/batchjobs/container_id1 in above example) becomes the +filesystem root for the namespace specific cgroupfs mount. + +The virtualization of /proc/self/cgroup file combined with restricting +the view of cgroup hierarchy by namespace-private cgroupfs mount +should provide a completely isolated cgroup view inside the container. + +Note that CGroup Namespaces virtualizes the path on unified hierarchy only. If +other hierarchies are mounted, /proc/<pid>/cgroup will continue to show the full +cgroup path for those. + +In its current form, the cgroup namespaces patcheset provides following +behavior: + +(1) The 'cgroupns-root' for a cgroup namespace is the cgroup in which + the process calling unshare is running. + For ex. if a process in /batchjobs/container_id1 cgroup calls unshare, + cgroup /batchjobs/container_id1 becomes the cgroupns-root. + For the init_cgroup_ns, this is the real root ('/') cgroup + (identified in code as cgrp_dfl_root.cgrp). + +(2) The cgroupns-root cgroup does not change even if the namespace + creator process later moves to a different cgroup. + $ ~/unshare -c # unshare cgroupns in some cgroup + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/ + [ns]$ mkdir sub_cgrp_1 + [ns]$ echo 0 > sub_cgrp_1/cgroup.procs + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/sub_cgrp_1 + +(3) Each process gets its CGROUPNS specific view of /proc/<pid>/cgroup +(a) Processes running inside the cgroup namespace will be able to see + cgroup paths (in /proc/self/cgroup) only inside their root cgroup + [ns]$ sleep 100000 & # From within unshared cgroupns + [1] 7353 + [ns]$ echo 7353 > sub_cgrp_1/cgroup.procs + [ns]$ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/sub_cgrp_1 + +(b) From global cgroupns, the real cgroup path will be visible: + $ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1/sub_cgrp_1 + +(c) From a sibling cgroupns (cgroupns root-ed at a different cgroup), cgroup + path relative to its own cgroupns-root will be shown: + # ns2's cgroupns-root is at '/batchjobs/container_id2' + [ns2]$ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/../container_id2/sub_cgrp_1 + + Note that the relative path always starts with '/' to indicate that its + relative to the cgroupns-root of the caller. + +(4) Processes inside a cgroupns can move in-and-out of the cgroupns-root + (if they have proper access to external cgroups). + # From inside cgroupns (with cgroupns-root at /batchjobs/container_id1), and + # assuming that the global hierarchy is still accessible inside cgroupns: + $ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/sub_cgrp_1 + $ echo 7353 > batchjobs/container_id2/cgroup.procs + $ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/../container_id2 + + Note that this kind of setup is not encouraged. A task inside cgroupns + should only be exposed to its own cgroupns hierarchy. Otherwise it makes + the virtualization of /proc/<pid>/cgroup less useful. + +(5) Setns to another cgroup namespace is allowed when: + (a) the process has CAP_SYS_ADMIN in its current userns + (b) the process has CAP_SYS_ADMIN in the target cgroupns' userns + No implicit cgroup changes happen with attaching to another cgroupns. It + is expected that the somone moves the attaching process under the target + cgroupns-root. + +(6) When some thread from a multi-threaded process unshares its + cgroup-namespace, the new cgroupns gets applied to the entire + process (all the threads). This should be OK since + unified-hierarchy only allows process-level containerization. So + all the threads in the process will have the same cgroup. + +(7) The cgroup namespace is alive as long as there is atleast 1 + process inside it. When the last process exits, the cgroup + namespace is destroyed. The cgroupns-root and the actual cgroups + remain though. + +(8) Namespace specific cgroup hierarchy can be mounted by a process running + inside cgroupns: + $ mount -t cgroup -o __DEVEL__sane_behavior cgroup $MOUNT_POINT + + This will mount the unified cgroup hierarchy with cgroupns-root as the + filesystem root. The process needs CAP_SYS_ADMIN in its userns and mntns. +
Signature · 1 line
2.2.0.rc0.207.ga3a616c
These patches are now also hosted on github at
https://github.com/adityakali/linux/tree/cgroupns_v3.
Thanks,
Quoted 62 lines · Aditya Kali
Another spin for CGroup Namespaces feature.
Changes from V2:
1. Added documentation inDocumentation/cgroups/namespace.txt
2. Fixed a bug that caused crash
3. Incorporated some other suggestions from last patchset:
- removed use ofthreadgroup_lock()while creating new cgroupns
- usetask_lock()instead ofrcu_read_lock()while accessingtask->nsproxy- optimized
setns()to own cgroupns
- simplified code around sane-behavior mount option parsing
4. Restored ACKs from Serge Hallyn from v1 on few patches that have not changed since then.Changes from V1:
1. No pinning of processes within cgroupns. Tasks can be freely moved across cgroups even outside of their cgroupns-root. Usual DAC/MAC policies apply as before.
2. Path in /proc/<pid>/cgroup is now always shown and is relative to cgroupns-root. So path can contain '/..' strings depending on cgroupns-root of the reader and cgroup of <pid>.
3.setns()does not require the process to first move under target cgroupns-root.Changes form RFC (V0):
1. setns support for cgroupns
2. 'mount -t cgroup cgroup <mntpt>' from inside a cgroupns now mounts the cgroup hierarcy with cgroupns-root as the filesystem root.
3. writes to cgroup files outside of cgroupns-root are not allowed
4. visibility of /proc/<pid>/cgroup is further restricted by not showing anything if the <pid> is in a sibling cgroupns and its cgroup falls outside your cgroupns-root.--- Documentation/cgroups/namespace.txt | 147 +++++++++++++++++++++++++++ fs/kernfs/dir.c | 195 ++++++++++++++++++++++++++++++++---- fs/kernfs/mount.c | 48 +++++++++ fs/proc/namespaces.c | 1 + include/linux/cgroup.h | 52 +++++++++- include/linux/cgroup_namespace.h | 36 +++++++ include/linux/kernfs.h | 5 + include/linux/nsproxy.h | 2 + include/linux/proc_ns.h | 4 + include/uapi/linux/sched.h | 3 +- kernel/Makefile | 2 +- kernel/cgroup.c | 106 +++++++++++++++----- kernel/cgroup_namespace.c | 140 ++++++++++++++++++++++++++ kernel/fork.c | 2 +- kernel/nsproxy.c | 19 +++- 15 files changed, 711 insertions(+), 51 deletions(-) create mode 100644 Documentation/cgroups/namespace.txt create mode 100644 include/linux/cgroup_namespace.h create mode 100644 kernel/cgroup_namespace.c[PATCHv3 1/8] kernfs: Add API to generate relative kernfs path [PATCHv3 2/8] sched: new clone flag
CLONE_NEWCGROUPfor cgroup [PATCHv3 3/8] cgroup: add function to get task's cgroup on default [PATCHv3 4/8] cgroup: exportcgroup_get()andcgroup_put()[PATCHv3 5/8] cgroup: introduce cgroup namespaces
[PATCHv3 6/8] cgroup: cgroup namespace setns support [PATCHv3 7/8] cgroup: mount cgroupns-root when inside non-init cgroupns [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
Signature · 1 line
Aditya
These patches are now also hosted on github at
https://github.com/adityakali/linux/tree/cgroupns_v3.
Thanks,
Quoted 62 lines · Aditya Kali
Another spin for CGroup Namespaces feature.
Changes from V2:
1. Added documentation inDocumentation/cgroups/namespace.txt
2. Fixed a bug that caused crash
3. Incorporated some other suggestions from last patchset:
- removed use ofthreadgroup_lock()while creating new cgroupns
- usetask_lock()instead ofrcu_read_lock()while accessingtask->nsproxy- optimized
setns()to own cgroupns
- simplified code around sane-behavior mount option parsing
4. Restored ACKs from Serge Hallyn from v1 on few patches that have not changed since then.Changes from V1:
1. No pinning of processes within cgroupns. Tasks can be freely moved across cgroups even outside of their cgroupns-root. Usual DAC/MAC policies apply as before.
2. Path in /proc/<pid>/cgroup is now always shown and is relative to cgroupns-root. So path can contain '/..' strings depending on cgroupns-root of the reader and cgroup of <pid>.
3.setns()does not require the process to first move under target cgroupns-root.Changes form RFC (V0):
1. setns support for cgroupns
2. 'mount -t cgroup cgroup <mntpt>' from inside a cgroupns now mounts the cgroup hierarcy with cgroupns-root as the filesystem root.
3. writes to cgroup files outside of cgroupns-root are not allowed
4. visibility of /proc/<pid>/cgroup is further restricted by not showing anything if the <pid> is in a sibling cgroupns and its cgroup falls outside your cgroupns-root.--- Documentation/cgroups/namespace.txt | 147 +++++++++++++++++++++++++++ fs/kernfs/dir.c | 195 ++++++++++++++++++++++++++++++++---- fs/kernfs/mount.c | 48 +++++++++ fs/proc/namespaces.c | 1 + include/linux/cgroup.h | 52 +++++++++- include/linux/cgroup_namespace.h | 36 +++++++ include/linux/kernfs.h | 5 + include/linux/nsproxy.h | 2 + include/linux/proc_ns.h | 4 + include/uapi/linux/sched.h | 3 +- kernel/Makefile | 2 +- kernel/cgroup.c | 106 +++++++++++++++----- kernel/cgroup_namespace.c | 140 ++++++++++++++++++++++++++ kernel/fork.c | 2 +- kernel/nsproxy.c | 19 +++- 15 files changed, 711 insertions(+), 51 deletions(-) create mode 100644 Documentation/cgroups/namespace.txt create mode 100644 include/linux/cgroup_namespace.h create mode 100644 kernel/cgroup_namespace.c[PATCHv3 1/8] kernfs: Add API to generate relative kernfs path [PATCHv3 2/8] sched: new clone flag
CLONE_NEWCGROUPfor cgroup [PATCHv3 3/8] cgroup: add function to get task's cgroup on default [PATCHv3 4/8] cgroup: exportcgroup_get()andcgroup_put()[PATCHv3 5/8] cgroup: introduce cgroup namespaces
[PATCHv3 6/8] cgroup: cgroup namespace setns support [PATCHv3 7/8] cgroup: mount cgroupns-root when inside non-init cgroupns [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
Signature · 1 line
Aditya
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 28 lines
Documentation/cgroups/namespace.txt new file +28
-0+In its current form, the cgroup namespaces patcheset provides following +behavior: + +(1) The 'cgroupns-root' for a cgroup namespace is the cgroup in which + the process calling unshare is running. + For ex. if a process in /batchjobs/container_id1 cgroup calls unshare, + cgroup /batchjobs/container_id1 becomes the cgroupns-root. + For the init_cgroup_ns, this is the real root ('/') cgroup + (identified in code as cgrp_dfl_root.cgrp). + +(2) The cgroupns-root cgroup does not change even if the namespace + creator process later moves to a different cgroup. + $ ~/unshare -c # unshare cgroupns in some cgroup + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/ + [ns]$ mkdir sub_cgrp_1 + [ns]$ echo 0 > sub_cgrp_1/cgroup.procs + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/sub_cgrp_1 + +(3) Each process gets its CGROUPNS specific view of /proc/<pid>/cgroup +(a) Processes running inside the cgroup namespace will be able to see + cgroup paths (in /proc/self/cgroup) only inside their root cgroup + [ns]$ sleep 100000 & # From within unshared cgroupns + [1] 7353 + [ns]$ echo 7353 > sub_cgrp_1/cgroup.procs + [ns]$ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/sub_cgrp_1
Documentation/cgroups/namespace.txt line 104
Quoted 10 lines
Documentation/cgroups/namespace.txt new file +10
-0+ +(b) From global cgroupns, the real cgroup path will be visible: + $ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1/sub_cgrp_1 + +(c) From a sibling cgroupns (cgroupns root-ed at a different cgroup), cgroup + path relative to its own cgroupns-root will be shown: + # ns2's cgroupns-root is at '/batchjobs/container_id2' + [ns2]$ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/../container_id2/sub_cgrp_1
Should be ../container_id1/sub_cgrp_1 ?
Documentation/cgroups/namespace.txt line 107
Quoted 3 lines
Documentation/cgroups/namespace.txt new file +3
-0+ + Note that the relative path always starts with '/' to indicate that its + relative to the cgroupns-root of the caller.
If a path doesn't start with '/', then it's a relative path, so why make it start with '/'?
Quoted 12 lines
Documentation/cgroups/namespace.txt new file +12
-0+ +(4) Processes inside a cgroupns can move in-and-out of the cgroupns-root + (if they have proper access to external cgroups). + # From inside cgroupns (with cgroupns-root at /batchjobs/container_id1), and + # assuming that the global hierarchy is still accessible inside cgroupns: + $ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/sub_cgrp_1 + $ echo 7353 > batchjobs/container_id2/cgroup.procs + $ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/../container_id2 + + Note that this kind of setup is not encouraged. A task inside cgroupns
Documentation/cgroups/namespace.txt line 129
Quoted 10 lines
Documentation/cgroups/namespace.txt new file +10
-0+ should only be exposed to its own cgroupns hierarchy. Otherwise it makes + the virtualization of /proc/<pid>/cgroup less useful. + +(5) Setns to another cgroup namespace is allowed when: + (a) the process has CAP_SYS_ADMIN in its current userns + (b) the process has CAP_SYS_ADMIN in the target cgroupns' userns + No implicit cgroup changes happen with attaching to another cgroupns. It + is expected that the somone moves the attaching process under the target + cgroupns-root. +
s/the somone/someone
Documentation/cgroups/namespace.txt line 136
Quoted 7 lines
Documentation/cgroups/namespace.txt new file +7
-0+(6) When some thread from a multi-threaded process unshares its + cgroup-namespace, the new cgroupns gets applied to the entire + process (all the threads). This should be OK since + unified-hierarchy only allows process-level containerization. So + all the threads in the process will have the same cgroup. + +(7) The cgroup namespace is alive as long as there is atleast 1
s/atelast/at least
Quoted 12 lines
Documentation/cgroups/namespace.txt new file +11
-0+ process inside it. When the last process exits, the cgroup + namespace is destroyed. The cgroupns-root and the actual cgroups + remain though. + +(8) Namespace specific cgroup hierarchy can be mounted by a process running + inside cgroupns: + $ mount -t cgroup -o __DEVEL__sane_behavior cgroup $MOUNT_POINT + + This will mount the unified cgroup hierarchy with cgroupns-root as the + filesystem root. The process needs CAP_SYS_ADMIN in its userns and mntns. +
Re: [PATCHv3 5/8] cgroup: introduce cgroup namespaces
In reply to a message not in the archiveQuoted 32 lines · Aditya Kali
Introduce the ability to create new cgroup namespace. The newly created cgroup namespace remembers the cgroup of the process at the point of creation of the cgroup namespace (referred as cgroupns-root). The main purpose of cgroup namespace is to virtualize the contents of
/proc/self/cgroupfile. Processes inside a cgroup namespace are only able to see paths relative to their namespace root (unless they are moved outside of their cgroupns-root, at which point
they will see a relative path from their cgroupns-root).
For a correctly setup container this enables container-tools (like libcontainer, lxc, lmctfy, etc.) to create completely virtualized containers without leaking system level cgroup hierarchy to the task. This patch only implements the 'unshare' part of the cgroupns.Signed-off-by Aditya Kali <[email protected]>--- fs/proc/namespaces.c | 1 + include/linux/cgroup.h | 29 ++++++++- include/linux/cgroup_namespace.h | 36 +++++++++++ include/linux/nsproxy.h | 2 + include/linux/proc_ns.h | 4 ++ kernel/Makefile | 2 +- kernel/cgroup.c | 13 ++++ kernel/cgroup_namespace.c | 127 +++++++++++++++++++++++++++++++++++++++ kernel/fork.c | 2 +- kernel/nsproxy.c | 19 +++++- 10 files changed, 230 insertions(+), 5 deletions(-)fs/proc/namespaces.c +0
-0
fs/proc/namespaces.c static const struct proc_ns_operations *ns_entries[] = { · line 35
Quoted 4 lines
fs/proc/namespaces.c +1
-0@@ -32,6 +32,7 @@ static const struct proc_ns_operations *ns_entries[] = { &userns_operations, #endif &mntns_operations, + &cgroupns_operations,
Should be guarded with CONFIG_CGROUPS ?
There are other changes that break compile if !CONFIG_CGROUPS.
Quoted 127 lines
fs/proc/namespaces.c +0
-0};static const struct file_operations ns_file_operations = {include/linux/cgroup.h +28
-1@@ -22,6 +22,8 @@#include <linux/seq_file.h> #include <linux/kernfs.h> #include <linux/wait.h> +#include <linux/nsproxy.h> +#include <linux/types.h> #ifdef CONFIG_CGROUPS @@ -460,6 +462,13 @@ struct cftype {#endif }; +struct cgroup_namespace { +atomic_t count; +unsigned int proc_inum; +struct user_namespace *user_ns; +struct cgroup *root_cgrp; +}; +extern struct cgroup_root cgrp_dfl_root;extern struct css_set init_css_set;@@ -584,10 +593,28 @@ static inline int cgroup_name(struct cgroup *cgrp, char *buf, size_t buflen)return kernfs_name (cgrp->kn, buf, buflen); } +static inline char *__must_check cgroup_path_ns (struct cgroup_namespace *ns, +struct cgroup *cgrp,char *buf, +size_t buflen) +{ +if (ns) { +BUG_ON (!cgroup_on_dfl (cgrp)); +return kernfs_path_from_node (ns->root_cgrp->kn, cgrp->kn, buf, + buflen); + }else { +return kernfs_path (cgrp->kn, buf, buflen); + } +} +static inline char *__must_check cgroup_path (struct cgroup *cgrp,char *buf,size_t buflen) { -return kernfs_path (cgrp->kn, buf, buflen); +if (cgroup_on_dfl (cgrp)) { +return cgroup_path_ns (current->nsproxy->cgroup_ns, cgrp, buf, + buflen); + }else { +return cgroup_path_ns (NULL , cgrp, buf, buflen); + } }static inline void pr_cont_cgroup_name (struct cgroup *cgrp)include/linux/cgroup_namespace.h new file +36
-0@@ -0,0 +1,36 @@ +#ifndef _LINUX_CGROUP_NAMESPACE_H +#define _LINUX_CGROUP_NAMESPACE_H + +#include <linux/nsproxy.h> +#include <linux/cgroup.h> +#include <linux/types.h> +#include <linux/user_namespace.h> + +extern struct cgroup_namespace init_cgroup_ns; + +static inline struct cgroup *current_cgroupns_root (void ) +{ +return current->nsproxy->cgroup_ns->root_cgrp; +} + +extern void free_cgroup_ns (struct cgroup_namespace *ns); + +static inline struct cgroup_namespace *get_cgroup_ns ( +struct cgroup_namespace *ns) +{ +if (ns) +atomic_inc (&ns->count); +return ns; +} + +static inline void put_cgroup_ns (struct cgroup_namespace *ns) +{ +if (ns &&atomic_dec_and_test (&ns->count)) +free_cgroup_ns (ns); +} + +extern struct cgroup_namespace *copy_cgroup_ns (unsigned long flags, +struct user_namespace *user_ns, +struct cgroup_namespace *old_ns); + +#endif /* _LINUX_CGROUP_NAMESPACE_H */ include/linux/nsproxy.h +2
-0@@ -8,6 +8,7 @@ struct mnt_namespace;struct uts_namespace ;struct ipc_namespace ;struct pid_namespace ; +struct cgroup_namespace ;struct fs_struct ;/* @@ -33,6 +34,7 @@ struct nsproxy {struct mnt_namespace *mnt_ns;struct pid_namespace *pid_ns_for_children;struct net *net_ns; +struct cgroup_namespace *cgroup_ns; };extern struct nsproxy init_nsproxy;include/linux/proc_ns.h +0
-0
include/linux/proc_ns.h line 10
Quoted 5 lines
include/linux/proc_ns.h +2
-0@@ -6,6 +6,8 @@struct pid_namespace ;struct nsproxy ; +struct task_struct ; +struct inode ;
These two lines seems unnecessary.
Quoted 46 lines
include/linux/proc_ns.h +2
-0struct proc_ns_operations {const char *name;@@ -27,6 +29,7 @@ extern const struct proc_ns_operations ipcns_operations;extern const struct proc_ns_operations pidns_operations;extern const struct proc_ns_operations userns_operations;extern const struct proc_ns_operations mntns_operations; +extern const struct proc_ns_operations cgroupns_operations;/* * We always define these enumerators @@ -37,6 +40,7 @@ enum {PROC_UTS_INIT_INO =0xEFFFFFFEU ,PROC_USER_INIT_INO =0xEFFFFFFDU ,PROC_PID_INIT_INO =0xEFFFFFFCU , + PROC_CGROUP_INIT_INO = 0xEFFFFFFBU, };#ifdef CONFIG_PROC_FS kernel/Makefile +1
-1@@ -50,7 +50,7 @@ obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_BACKTRACE_SELF_TEST) += backtracetest.o obj-$(CONFIG_COMPAT) += compat.o -obj-$(CONFIG_CGROUPS) += cgroup.o +obj-$(CONFIG_CGROUPS) += cgroup.o cgroup_namespace.o obj-$(CONFIG_CGROUP_FREEZER) += cgroup_freezer.o obj-$(CONFIG_CPUSETS) += cpuset.o obj-$(CONFIG_UTS_NS) += utsname.okernel/cgroup.c +2
-0@@ -57,6 +57,8 @@#include <linux/vmalloc.h> /* TODO: replace with more sophisticated array */ #include <linux/kthread.h> #include <linux/delay.h> +#include <linux/proc_ns.h> +#include <linux/cgroup_namespace.h> #include <linux/atomic.h>
kernel/cgroup.c static void kill_css(struct cgroup_subsys_state *css); · line 203
Quoted 7 lines
kernel/cgroup.c +4
-0@@ -195,6 +197,15 @@ static void kill_css(struct cgroup_subsys_state *css);static int cgroup_addrm_files (struct cgroup *cgrp,struct cftype cfts[],bool is_add); +struct cgroup_namespace init_cgroup_ns = { + .count = { + .counter =1 , + },
.count = ATOMIC_INIT(1)
Quoted 39 lines
kernel/cgroup.c +7
-0+ .proc_inum = PROC_CGROUP_INIT_INO, + .user_ns = &init_user_ns, + .root_cgrp = &cgrp_dfl_root.cgrp, +}; +/* IDR wrappers which synchronize using cgroup_idr_lock */ static int cgroup_idr_alloc (struct idr *idr,void *ptr,int start,int end,gfp_t gfp_mask)@@ -4989,6 +5000,8 @@ int __init cgroup_init(void)unsigned long key;int ssid, err; +get_user_ns (init_cgroup_ns.user_ns); +BUG_ON (cgroup_init_cftypes (NULL , cgroup_dfl_base_files));BUG_ON (cgroup_init_cftypes (NULL , cgroup_legacy_base_files));kernel/cgroup_namespace.c new file +16
-0@@ -0,0 +1,127 @@ +/* +* Copyright (C) 2014 Google Inc. +* +* Author: Aditya Kali ([email protected]) +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation, version 2 of the License. +*/ + +#include <linux/cgroup.h> +#include <linux/cgroup_namespace.h> +#include <linux/sched.h> +#include <linux/slab.h> +#include <linux/nsproxy.h> +#include <linux/proc_ns.h>
kernel/cgroup_namespace.c line 26
Quoted 10 lines
kernel/cgroup_namespace.c new file +10
-0+ +static struct cgroup_namespace *alloc_cgroup_ns (void ) +{ +struct cgroup_namespace *new_ns; + + new_ns =kzalloc (sizeof (struct cgroup_namespace ),GFP_KERNEL ); +if (new_ns) +atomic_set (&new_ns->count,1 ); +return new_ns; +}
Better fold this function into copy_cgroup_ns().
kernel/cgroup_namespace.c line 35
Quoted 9 lines
kernel/cgroup_namespace.c new file +9
-0+ +void free_cgroup_ns (struct cgroup_namespace *ns) +{ +cgroup_put (ns->root_cgrp); +put_user_ns (ns->user_ns); +proc_free_inum (ns->proc_inum); +kfree (ns); +} +EXPORT_SYMBOL (free_cgroup_ns);
This should be a static inline function.
Quoted 11 lines
kernel/cgroup_namespace.c new file +11
-0+ +struct cgroup_namespace *copy_cgroup_ns (unsigned long flags, +struct user_namespace *user_ns, +struct cgroup_namespace *old_ns) +{ +struct cgroup_namespace *new_ns =NULL ; +struct cgroup *cgrp =NULL ; +int err; + +BUG_ON (!old_ns); +
kernel/cgroup_namespace.c line 56
Quoted 10 lines
kernel/cgroup_namespace.c new file +10
-0+if (!(flags &CLONE_NEWCGROUP )) +return get_cgroup_ns (old_ns); + +/* Allow only sysadmin to create cgroup namespace. */ + err = -EPERM ; +if (!ns_capable (user_ns,CAP_SYS_ADMIN )) + goto err_out; + +/* CGROUPNS only virtualizes the cgroup path on the unified hierarchy. +*/
The comment style should be
/*
* ...
*/
Quoted 61 lines
kernel/cgroup_namespace.c new file +61
-0+ cgrp =get_task_cgroup (current); + + err = -ENOMEM ; + new_ns =alloc_cgroup_ns (); +if (!new_ns) + goto err_out; + + err =proc_alloc_inum (&new_ns->proc_inum); +if (err) + goto err_out; + + new_ns->user_ns =get_user_ns (user_ns); + new_ns->root_cgrp = cgrp; + +return new_ns; + +err_out: +if (cgrp) +cgroup_put (cgrp); +kfree (new_ns); +return ERR_PTR (err); +} + +static int cgroupns_install (struct nsproxy *nsproxy,void *ns) +{ +pr_info ("setns not supported for cgroup namespace" ); +return -EINVAL ; +} + +static void *cgroupns_get (struct task_struct *task) +{ +struct cgroup_namespace *ns =NULL ; +struct nsproxy *nsproxy; + +task_lock (task); + nsproxy = task->nsproxy; +if (nsproxy) { + ns = nsproxy->cgroup_ns; +get_cgroup_ns (ns); + } +task_unlock (task); + +return ns; +} + +static void cgroupns_put (void *ns) +{ +put_cgroup_ns (ns); +} + +static unsigned int cgroupns_inum (void *ns) +{ +struct cgroup_namespace *cgroup_ns = ns; + +return cgroup_ns->proc_inum; +} + +const struct proc_ns_operations cgroupns_operations = { + .name ="cgroup" , + .type =CLONE_NEWCGROUP , + .get = cgroupns_get,
kernel/cgroup_namespace.c line 127
Quoted 10 lines
kernel/cgroup_namespace.c new file +10
-0+ .put = cgroupns_put, + .install = cgroupns_install, + .inum = cgroupns_inum, +}; + +static __init int cgroup_namespaces_init (void ) +{ +return 0 ; +} +subsys_initcall (cgroup_namespaces_init);
Why provide this unused init function?
Quoted 86 lines
kernel/fork.c +1
-1@@ -1797,7 +1797,7 @@ static int check_unshare_flags(unsigned long unshare_flags)if (unshare_flags & ~(CLONE_THREAD |CLONE_FS |CLONE_NEWNS |CLONE_SIGHAND |CLONE_VM |CLONE_FILES |CLONE_SYSVSEM |CLONE_NEWUTS |CLONE_NEWIPC |CLONE_NEWNET | -CLONE_NEWUSER |CLONE_NEWPID )) +CLONE_NEWUSER |CLONE_NEWPID |CLONE_NEWCGROUP ))return -EINVAL ;/* * Not implemented, but pretend it works if there is nothing to kernel/nsproxy.c +17
-2@@ -25,6 +25,7 @@#include <linux/proc_ns.h> #include <linux/file.h> #include <linux/syscalls.h> +#include <linux/cgroup_namespace.h> static struct kmem_cache *nsproxy_cachep;@@ -39,6 +40,7 @@ struct nsproxy init_nsproxy = {#ifdef CONFIG_NET .net_ns = &init_net, #endif + .cgroup_ns = &init_cgroup_ns, };static inline struct nsproxy *create_nsproxy (void )@@ -92,6 +94,13 @@ static struct nsproxy *create_new_namespaces(unsigned long flags, goto out_pid; } + new_nsp->cgroup_ns =copy_cgroup_ns (flags, user_ns, + tsk->nsproxy->cgroup_ns); +if (IS_ERR (new_nsp->cgroup_ns)) { + err =PTR_ERR (new_nsp->cgroup_ns); + goto out_cgroup; + } + new_nsp->net_ns =copy_net_ns (flags, user_ns, tsk->nsproxy->net_ns);if (IS_ERR (new_nsp->net_ns)) { err =PTR_ERR (new_nsp->net_ns);@@ -101,6 +110,9 @@ static struct nsproxy *create_new_namespaces(unsigned long flags,return new_nsp; out_net: +if (new_nsp->cgroup_ns) +put_cgroup_ns (new_nsp->cgroup_ns); +out_cgroup:if (new_nsp->pid_ns_for_children)put_pid_ns (new_nsp->pid_ns_for_children); out_pid:@@ -128,7 +140,8 @@ int copy_namespaces(unsigned long flags, struct task_struct *tsk)struct nsproxy *new_ns;if (likely (!(flags & (CLONE_NEWNS |CLONE_NEWUTS |CLONE_NEWIPC | -CLONE_NEWPID |CLONE_NEWNET )))) { +CLONE_NEWPID |CLONE_NEWNET | +CLONE_NEWCGROUP )))) {get_nsproxy (old_ns);return 0 ; }@@ -165,6 +178,8 @@ void free_nsproxy(struct nsproxy *ns)put_ipc_ns (ns->ipc_ns);if (ns->pid_ns_for_children)put_pid_ns (ns->pid_ns_for_children); +if (ns->cgroup_ns) +put_cgroup_ns (ns->cgroup_ns);put_net (ns->net_ns);kmem_cache_free (nsproxy_cachep, ns); }@@ -180,7 +195,7 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,int err =0 ;if (!(unshare_flags & (CLONE_NEWNS |CLONE_NEWUTS |CLONE_NEWIPC | -CLONE_NEWNET |CLONE_NEWPID ))) +CLONE_NEWNET |CLONE_NEWPID |CLONE_NEWCGROUP )))return 0 ; user_ns = new_cred ? new_cred->user_ns :current_user_ns ();
Re: [PATCHv3 7/8] cgroup: mount cgroupns-root when inside non-init cgroupns
In reply to a message not in the archiveQuoted 2 lines · Aditya Kali
This patch enables cgroup mounting inside userns when a process as appropriate privileges. The cgroup filesystem mounted is
s/as/has
Quoted 19 lines
rooted at the cgroupns-root. Thus, in a container-setup, only the hierarchy under the cgroupns-root is exposed inside the container. This allows container management tools to run inside the containers without depending on any global state.
In order to support this, a new kernfs api is added to lookup the dentry for the cgroupns-root.Signed-off-by Aditya Kali <[email protected]>--- fs/kernfs/mount.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/kernfs.h | 2 ++ kernel/cgroup.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 95 insertions(+), 1 deletion(-)fs/kernfs/mount.c +0
-0
fs/kernfs/mount.c struct kernfs_root *kernfs_root_from_sb(struct super_block *sb) · line 70
Quoted 9 lines
fs/kernfs/mount.c +6
-0@@ -62,6 +62,54 @@ struct kernfs_root *kernfs_root_from_sb(struct super_block *sb)return NULL ; } +/** +* kernfs_obtain_root - get a dentry for the given kernfs_node +* @sb: the kernfs super_block +* @kn: kernfs_node for which a dentry is needed +* +* This can used used by callers which want to mount only a part of the kernfs
s/used used/be used/
s/which/who
Quoted 20 lines
fs/kernfs/mount.c +20
-0+* as root of the filesystem. +*/ +struct dentry *kernfs_obtain_root (struct super_block *sb, +struct kernfs_node *kn) +{ +struct dentry *dentry; +struct inode *inode; + +BUG_ON (sb->s_op != &kernfs_sops); + +/* inode for the given kernfs_node should already exist. */ + inode =ilookup (sb, kn->ino); +if (!inode) { +pr_debug ("kernfs: could not get inode for '" ); +pr_cont_kernfs_path (kn); +pr_cont ("'.\n" ); +return ERR_PTR (-EINVAL ); + } + +/* instantiate and link root dentry */
fs/kernfs/mount.c struct kernfs_root *kernfs_root_from_sb(struct super_block *sb) · line 100
Quoted 10 lines
fs/kernfs/mount.c +10
-0+ dentry =d_obtain_root (inode); +if (!dentry) { +pr_debug ("kernfs: could not get dentry for '" ); +pr_cont_kernfs_path (kn); +pr_cont ("'.\n" ); +return ERR_PTR (-ENOMEM ); + } + +/* If this is a new dentry, set it up. We need kernfs_mutex because this +* may be called by callers other than kernfs_fill_super. */
/*
* ...
*/
fs/kernfs/mount.c struct kernfs_root *kernfs_root_from_sb(struct super_block *sb) · line 111
Quoted 11 lines
fs/kernfs/mount.c +11
-0+mutex_lock (&kernfs_mutex); +if (!dentry->d_fsdata) { +kernfs_get (kn); + dentry->d_fsdata = kn; + }else { +WARN_ON (dentry->d_fsdata != kn); + } +mutex_unlock (&kernfs_mutex); + +return dentry; +}
Seperate this as a standalone patch?
Quoted 22 lines
fs/kernfs/mount.c +1
-0+static int kernfs_fill_super (struct super_block *sb,unsigned long magic) {struct kernfs_super_info *info =kernfs_info (sb);include/linux/kernfs.h +2
-0@@ -274,6 +274,8 @@ void kernfs_put(struct kernfs_node *kn);struct kernfs_node *kernfs_node_from_dentry (struct dentry *dentry);struct kernfs_root *kernfs_root_from_sb (struct super_block *sb); +struct dentry *kernfs_obtain_root (struct super_block *sb, +struct kernfs_node *kn);struct kernfs_root *kernfs_create_root (struct kernfs_syscall_ops *scops,unsigned int flags,void *priv);void kernfs_destroy_root (struct kernfs_root *root);kernel/cgroup.c +0
-0
kernel/cgroup.c static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts) · line 1443
Quoted 6 lines
kernel/cgroup.c +3
-0@@ -1438,6 +1438,14 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)return -ENOENT ; } +/* If inside a non-init cgroup namespace, only allow default hierarchy +* to be mounted. +*/
/*
* ...
*/
Quoted 86 lines
kernel/cgroup.c +42
-1+if ((current->nsproxy->cgroup_ns != &init_cgroup_ns) && + !(opts->flags &CGRP_ROOT_SANE_BEHAVIOR )) { +return -EINVAL ; + } +if (opts->flags &CGRP_ROOT_SANE_BEHAVIOR ) {pr_warn ("sane_behavior: this is still under development and its behaviors will change, proceed at your own risk\n" );if (nr_opts !=1 ) {@@ -1630,6 +1638,15 @@ static void init_cgroup_root(struct cgroup_root *root,set_bit (CGRP_CPUSET_CLONE_CHILDREN , &root->cgrp.flags); } +struct dentry *cgroupns_get_root (struct super_block *sb, +struct cgroup_namespace *ns) +{ +struct dentry *nsdentry; + + nsdentry =kernfs_obtain_root (sb, ns->root_cgrp->kn); +return nsdentry; +} +static int cgroup_setup_root (struct cgroup_root *root,unsigned int ss_mask) {LIST_HEAD (tmp_links);@@ -1734,6 +1751,14 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,int ret;int i;bool new_sb; +struct cgroup_namespace *ns = +get_cgroup_ns (current->nsproxy->cgroup_ns); + +/* Check if the caller has permission to mount. */ +if (!ns_capable (ns->user_ns,CAP_SYS_ADMIN )) { +put_cgroup_ns (ns); +return ERR_PTR (-EPERM ); + }/* * The first time anyone tries to mount a cgroup, enable the list @@ -1866,11 +1891,28 @@ out_free:kfree (opts.release_agent);kfree (opts.name); -if (ret) +if (ret) { +put_cgroup_ns (ns);return ERR_PTR (ret); + } dentry =kernfs_mount (fs_type, flags, root->kf_root,CGROUP_SUPER_MAGIC , &new_sb); + +if (!IS_ERR (dentry) && (root == &cgrp_dfl_root)) { +/* If this mount is for the default hierarchy in non-init cgroup +* namespace, then instead of root cgroup's dentry, we return +* the dentry corresponding to the cgroupns->root_cgrp. +*/ +if (ns != &init_cgroup_ns) { +struct dentry *nsdentry; + + nsdentry =cgroupns_get_root (dentry->d_sb, ns); +dput (dentry); + dentry = nsdentry; + } + } +if (IS_ERR (dentry) || !new_sb)cgroup_put (&root->cgrp);@@ -1883,6 +1925,7 @@ out_free:deactivate_super (pinned_sb); } +put_cgroup_ns (ns);return dentry; }@@ -1911,6 +1954,7 @@ static struct file_system_type cgroup_fs_type = { .name = "cgroup", .mount = cgroup_mount, .kill_sb = cgroup_kill_sb, + .fs_flags = FS_USERNS_MOUNT, };static struct kobject *cgroup_kobj;
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveAditya,
I gave your patch set a try but it does not work for me. Maybe you can bring some light into the issues I'm facing. Sadly I still had no time to dig into your code.
Am 05.12.2014 um 02:55 schrieb Aditya Kali:
Quoted 47 lines
Signed-off-by Aditya Kali <[email protected]>--- Documentation/cgroups/namespace.txt | 147 ++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 Documentation/cgroups/namespace.txtDocumentation/cgroups/namespace.txt new file +35
-0@@ -0,0 +1,147 @@ + CGroup Namespaces + +CGroup Namespace provides a mechanism to virtualize the view of the +/proc/<pid>/cgroup file. The CLONE_NEWCGROUP clone-flag can be used with +clone() and unshare() syscalls to create a new cgroup namespace. +The process running inside the cgroup namespace will have its /proc/<pid>/cgroup +output restricted to cgroupns-root. cgroupns-root is the cgroup of the process +at the time of creation of the cgroup namespace. + +Prior to CGroup Namespace, the /proc/<pid>/cgroup file used to show complete +path of the cgroup of a process. In a container setup (where a set of cgroups +and namespaces are intended to isolate processes), the /proc/<pid>/cgroup file +may leak potential system level information to the isolated processes. + +For Example: + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + +The path '/batchjobs/container_id1' can generally be considered as system-data +and its desirable to not expose it to the isolated process. + +CGroup Namespaces can be used to restrict visibility of this path. +For Example: + # Before creating cgroup namespace + $ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:37 /proc/self/ns/cgroup -> cgroup:[4026531835] + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # unshare(CLONE_NEWCGROUP) and exec /bin/bash + $ ~/unshare -c + [ns]$ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:35 /proc/self/ns/cgroup -> cgroup:[4026532183] + # From within new cgroupns, process sees that its in the root cgroup + [ns]$ cat /proc/self/cgroup
Documentation/cgroups/namespace.txt line 45
Quoted 10 lines
Documentation/cgroups/namespace.txt new file +10
-0+ 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/ + + # From global cgroupns: + $ cat /proc/<pid>/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # Unshare cgroupns along with userns and mountns + # Following calls unshare(CLONE_NEWCGROUP|CLONE_NEWUSER|CLONE_NEWNS), then + # sets up uid/gid map and execs /bin/bash + $ ~/unshare -c -u -m
This command does not issue CLONE_NEWUSER, -U does.
Documentation/cgroups/namespace.txt line 54
Quoted 9 lines
Documentation/cgroups/namespace.txt new file +9
-0+ # Originally, we were in /batchjobs/container_id1 cgroup. Mount our own cgroup + # hierarchy. + [ns]$ mount -t cgroup cgroup /tmp/cgroup + [ns]$ ls -l /tmp/cgroup + total 0 + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.controllers + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.populated + -rw-r--r-- 1 root root 0 2014-10-13 09:25 cgroup.procs + -rw-r--r-- 1 root root 0 2014-10-13 09:32 cgroup.subtree_control
I've patched libvirt-lxc to issue CLONE_NEWCGROUP and not bind mount cgroupfs into a container. But I'm unable to mount cgroupfs within the container, mount(2) is failing with EINVAL. And /proc/self/cgroup still shows the cgroup from outside.
---cut---
container:/ # ls /sys/fs/cgroup/
container:/ # mount -t cgroup none /sys/fs/cgroup/
mount: wrong fs type, bad option, bad superblock on none,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try dmesg | tail or so.
container:/ # cat /proc/self/cgroup 8:memory:/machine/test00.libvirt-lxc 7:devices:/machine/test00.libvirt-lxc
6:hugetlb:/
5:cpuset:/machine/test00.libvirt-lxc 4:blkio:/machine/test00.libvirt-lxc 3:cpu,cpuacct:/machine/test00.libvirt-lxc 2:freezer:/machine/test00.libvirt-lxc 1:name=systemd:/user.slice/user-0.slice/session-c2.scope container:/ # ls -la /proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:02 .
dr-xr-xr-x 8 root root 0 Dec 14 23:02 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:02 cgroup -> cgroup:[4026532240] lrwxrwxrwx 1 root root 0 Dec 14 23:02 ipc -> ipc:[4026532238] lrwxrwxrwx 1 root root 0 Dec 14 23:02 mnt -> mnt:[4026532235] lrwxrwxrwx 1 root root 0 Dec 14 23:02 net -> net:[4026532242] lrwxrwxrwx 1 root root 0 Dec 14 23:02 pid -> pid:[4026532239] lrwxrwxrwx 1 root root 0 Dec 14 23:02 user -> user:[4026532234] lrwxrwxrwx 1 root root 0 Dec 14 23:02 uts -> uts:[4026532236] container:/ #
#host side
lxc-os132:~ # ls -la /proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:56 .
dr-xr-xr-x 8 root root 0 Dec 14 23:56 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:56 cgroup -> cgroup:[4026531835] lrwxrwxrwx 1 root root 0 Dec 14 23:56 ipc -> ipc:[4026531839] lrwxrwxrwx 1 root root 0 Dec 14 23:56 mnt -> mnt:[4026531840] lrwxrwxrwx 1 root root 0 Dec 14 23:56 net -> net:[4026531957] lrwxrwxrwx 1 root root 0 Dec 14 23:56 pid -> pid:[4026531836] lrwxrwxrwx 1 root root 0 Dec 14 23:56 user -> user:[4026531837] lrwxrwxrwx 1 root root 0 Dec 14 23:56 uts -> uts:[4026531838] ---cut---
Any ideas?
Thanks,
//richard
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 58 lines · Richard Weinberger
Aditya,
I gave your patch set a try but it does not work for me. Maybe you can bring some light into the issues I'm facing. Sadly I still had no time to dig into your code.
Am 05.12.2014 um 02:55 schrieb Aditya Kali:
Quoted 51 lines
Signed-off-by Aditya Kali <[email protected]>--- Documentation/cgroups/namespace.txt | 147 ++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 Documentation/cgroups/namespace.txtDocumentation/cgroups/namespace.txt new file +39
-0@@ -0,0 +1,147 @@ + CGroup Namespaces + +CGroup Namespace provides a mechanism to virtualize the view of the +/proc/<pid>/cgroup file. The CLONE_NEWCGROUP clone-flag can be used with +clone() and unshare() syscalls to create a new cgroup namespace. +The process running inside the cgroup namespace will have its /proc/<pid>/cgroup +output restricted to cgroupns-root. cgroupns-root is the cgroup of the process +at the time of creation of the cgroup namespace. + +Prior to CGroup Namespace, the /proc/<pid>/cgroup file used to show complete +path of the cgroup of a process. In a container setup (where a set of cgroups +and namespaces are intended to isolate processes), the /proc/<pid>/cgroup file +may leak potential system level information to the isolated processes. + +For Example: + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + +The path '/batchjobs/container_id1' can generally be considered as system-data +and its desirable to not expose it to the isolated process. + +CGroup Namespaces can be used to restrict visibility of this path. +For Example: + # Before creating cgroup namespace + $ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:37 /proc/self/ns/cgroup -> cgroup:[4026531835] + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # unshare(CLONE_NEWCGROUP) and exec /bin/bash + $ ~/unshare -c + [ns]$ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:35 /proc/self/ns/cgroup -> cgroup:[4026532183] + # From within new cgroupns, process sees that its in the root cgroup + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/ + + # From global cgroupns: + $ cat /proc/<pid>/cgroup
Quoted 9 lines
Documentation/cgroups/namespace.txt line 45
Quoted 6 lines
Documentation/cgroups/namespace.txt new file +6
-0+ 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # Unshare cgroupns along with userns and mountns + # Following calls unshare(CLONE_NEWCGROUP|CLONE_NEWUSER|CLONE_NEWNS), then + # sets up uid/gid map and execs /bin/bash + $ ~/unshare -c -u -mThis command does not issue
CLONE_NEWUSER, -U does.
I was using a custom unshare binary. But I will update the command line to be similar to the one in util-linux.
Quoted 10 lines
Documentation/cgroups/namespace.txt line 54
Quoted 9 lines
Documentation/cgroups/namespace.txt new file +9
-0+ # Originally, we were in /batchjobs/container_id1 cgroup. Mount our own cgroup + # hierarchy. + [ns]$ mount -t cgroup cgroup /tmp/cgroup + [ns]$ ls -l /tmp/cgroup + total 0 + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.controllers + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.populated + -rw-r--r-- 1 root root 0 2014-10-13 09:25 cgroup.procs + -rw-r--r-- 1 root root 0 2014-10-13 09:32 cgroup.subtree_control
Quoted 7 lines
I've patched libvirt-lxc to issue
CLONE_NEWCGROUPand not bind mount cgroupfs into a container. But I'm unable to mount cgroupfs within the container, mount(2) is failing with EINVAL. And/proc/self/cgroupstill shows the cgroup from outside.---cut---
container:/ # ls/sys/fs/cgroup/container:/ # mount -t cgroup none/sys/fs/cgroup/
You need to provide "-o __DEVEL_sane_behavior" flag. Inside the container, only unified hierarchy can be mounted. So, for now, that flag is needed. I will fix the documentation too.
Quoted 41 lines
mount: wrong fs type, bad option, bad superblock on none,
missing codepage or helper program, or other errorIn some cases useful info is found in syslog - try dmesg | tail or so.
container:/ # cat/proc/self/cgroup8:memory:/machine/test00.libvirt-lxc 7:devices:/machine/test00.libvirt-lxc
6:hugetlb:/
5:cpuset:/machine/test00.libvirt-lxc 4:blkio:/machine/test00.libvirt-lxc 3:cpu,cpuacct:/machine/test00.libvirt-lxc 2:freezer:/machine/test00.libvirt-lxc 1:name=systemd:/user.slice/user-0.slice/session-c2.scope container:/ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:02 .
dr-xr-xr-x 8 root root 0 Dec 14 23:02 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:02 cgroup -> cgroup:[4026532240] lrwxrwxrwx 1 root root 0 Dec 14 23:02 ipc -> ipc:[4026532238] lrwxrwxrwx 1 root root 0 Dec 14 23:02 mnt -> mnt:[4026532235] lrwxrwxrwx 1 root root 0 Dec 14 23:02 net -> net:[4026532242] lrwxrwxrwx 1 root root 0 Dec 14 23:02 pid -> pid:[4026532239] lrwxrwxrwx 1 root root 0 Dec 14 23:02 user -> user:[4026532234] lrwxrwxrwx 1 root root 0 Dec 14 23:02 uts -> uts:[4026532236] container:/ ##host side
lxc-os132:~ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:56 .
dr-xr-xr-x 8 root root 0 Dec 14 23:56 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:56 cgroup -> cgroup:[4026531835] lrwxrwxrwx 1 root root 0 Dec 14 23:56 ipc -> ipc:[4026531839] lrwxrwxrwx 1 root root 0 Dec 14 23:56 mnt -> mnt:[4026531840] lrwxrwxrwx 1 root root 0 Dec 14 23:56 net -> net:[4026531957] lrwxrwxrwx 1 root root 0 Dec 14 23:56 pid -> pid:[4026531836] lrwxrwxrwx 1 root root 0 Dec 14 23:56 user -> user:[4026531837] lrwxrwxrwx 1 root root 0 Dec 14 23:56 uts -> uts:[4026531838] ---cut---
Quoted 2 lines
Any ideas?
Please try with "-o __DEVEL_sane_behavior" flag to the mount command.
Quoted 2 lines
Thanks,
//richard
Thanks,
Signature · 1 line
Aditya
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveAm 05.01.2015 um 23:48 schrieb Aditya Kali:
Quoted 134 lines · Richard Weinberger
Quoted 58 lines
Aditya,
I gave your patch set a try but it does not work for me. Maybe you can bring some light into the issues I'm facing. Sadly I still had no time to dig into your code.
Am 05.12.2014 um 02:55 schrieb Aditya Kali:
Quoted 51 lines
Signed-off-by Aditya Kali <[email protected]>--- Documentation/cgroups/namespace.txt | 147 ++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 Documentation/cgroups/namespace.txtDocumentation/cgroups/namespace.txt new file +39
-0@@ -0,0 +1,147 @@ + CGroup Namespaces + +CGroup Namespace provides a mechanism to virtualize the view of the +/proc/<pid>/cgroup file. The CLONE_NEWCGROUP clone-flag can be used with +clone() and unshare() syscalls to create a new cgroup namespace. +The process running inside the cgroup namespace will have its /proc/<pid>/cgroup +output restricted to cgroupns-root. cgroupns-root is the cgroup of the process +at the time of creation of the cgroup namespace. + +Prior to CGroup Namespace, the /proc/<pid>/cgroup file used to show complete +path of the cgroup of a process. In a container setup (where a set of cgroups +and namespaces are intended to isolate processes), the /proc/<pid>/cgroup file +may leak potential system level information to the isolated processes. + +For Example: + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + +The path '/batchjobs/container_id1' can generally be considered as system-data +and its desirable to not expose it to the isolated process. + +CGroup Namespaces can be used to restrict visibility of this path. +For Example: + # Before creating cgroup namespace + $ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:37 /proc/self/ns/cgroup -> cgroup:[4026531835] + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # unshare(CLONE_NEWCGROUP) and exec /bin/bash + $ ~/unshare -c + [ns]$ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:35 /proc/self/ns/cgroup -> cgroup:[4026532183] + # From within new cgroupns, process sees that its in the root cgroup + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/ + + # From global cgroupns: + $ cat /proc/<pid>/cgroupQuoted 9 lines
Documentation/cgroups/namespace.txt line 45
Quoted 6 lines
Documentation/cgroups/namespace.txt new file +6
-0+ 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # Unshare cgroupns along with userns and mountns + # Following calls unshare(CLONE_NEWCGROUP|CLONE_NEWUSER|CLONE_NEWNS), then + # sets up uid/gid map and execs /bin/bash + $ ~/unshare -c -u -mThis command does not issue
CLONE_NEWUSER, -U does.I was using a custom unshare binary. But I will update the command line to be similar to the one in util-linux.
Quoted 10 lines
Documentation/cgroups/namespace.txt line 54
Quoted 9 lines
Documentation/cgroups/namespace.txt new file +9
-0+ # Originally, we were in /batchjobs/container_id1 cgroup. Mount our own cgroup + # hierarchy. + [ns]$ mount -t cgroup cgroup /tmp/cgroup + [ns]$ ls -l /tmp/cgroup + total 0 + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.controllers + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.populated + -rw-r--r-- 1 root root 0 2014-10-13 09:25 cgroup.procs + -rw-r--r-- 1 root root 0 2014-10-13 09:32 cgroup.subtree_controlQuoted 7 lines
I've patched libvirt-lxc to issue
CLONE_NEWCGROUPand not bind mount cgroupfs into a container. But I'm unable to mount cgroupfs within the container, mount(2) is failing with EINVAL. And/proc/self/cgroupstill shows the cgroup from outside.---cut---
container:/ # ls/sys/fs/cgroup/container:/ # mount -t cgroup none/sys/fs/cgroup/You need to provide "-o
__DEVEL_sane_behavior" flag. Inside the container, only unified hierarchy can be mounted. So, for now, that flag is needed. I will fix the documentation too.Quoted 41 lines
mount: wrong fs type, bad option, bad superblock on none,
missing codepage or helper program, or other errorIn some cases useful info is found in syslog - try dmesg | tail or so.
container:/ # cat/proc/self/cgroup8:memory:/machine/test00.libvirt-lxc 7:devices:/machine/test00.libvirt-lxc
6:hugetlb:/
5:cpuset:/machine/test00.libvirt-lxc 4:blkio:/machine/test00.libvirt-lxc 3:cpu,cpuacct:/machine/test00.libvirt-lxc 2:freezer:/machine/test00.libvirt-lxc 1:name=systemd:/user.slice/user-0.slice/session-c2.scope container:/ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:02 .
dr-xr-xr-x 8 root root 0 Dec 14 23:02 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:02 cgroup -> cgroup:[4026532240] lrwxrwxrwx 1 root root 0 Dec 14 23:02 ipc -> ipc:[4026532238] lrwxrwxrwx 1 root root 0 Dec 14 23:02 mnt -> mnt:[4026532235] lrwxrwxrwx 1 root root 0 Dec 14 23:02 net -> net:[4026532242] lrwxrwxrwx 1 root root 0 Dec 14 23:02 pid -> pid:[4026532239] lrwxrwxrwx 1 root root 0 Dec 14 23:02 user -> user:[4026532234] lrwxrwxrwx 1 root root 0 Dec 14 23:02 uts -> uts:[4026532236] container:/ ##host side
lxc-os132:~ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:56 .
dr-xr-xr-x 8 root root 0 Dec 14 23:56 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:56 cgroup -> cgroup:[4026531835] lrwxrwxrwx 1 root root 0 Dec 14 23:56 ipc -> ipc:[4026531839] lrwxrwxrwx 1 root root 0 Dec 14 23:56 mnt -> mnt:[4026531840] lrwxrwxrwx 1 root root 0 Dec 14 23:56 net -> net:[4026531957] lrwxrwxrwx 1 root root 0 Dec 14 23:56 pid -> pid:[4026531836] lrwxrwxrwx 1 root root 0 Dec 14 23:56 user -> user:[4026531837] lrwxrwxrwx 1 root root 0 Dec 14 23:56 uts -> uts:[4026531838] ---cut---
Quoted 4 lines
Quoted 2 lines
Any ideas?
Please try with "-o
__DEVEL_sane_behavior" flag to the mount command.
Ohh, this renders the whole patch useless for me as systemd needs the "old/default" behavior of cgroups. :-( I really hoped that cgroup namespaces will help me running systemd in a sane way within Linux containers.
Thanks,
//richard
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveThanks for the review. I have made the suggested fixes. Regarding relative path, please see inline.
Quoted 32 lines · Zefan Li
Quoted 32 lines
Documentation/cgroups/namespace.txt new file +32
-0+In its current form, the cgroup namespaces patcheset provides following +behavior: + +(1) The 'cgroupns-root' for a cgroup namespace is the cgroup in which + the process calling unshare is running. + For ex. if a process in /batchjobs/container_id1 cgroup calls unshare, + cgroup /batchjobs/container_id1 becomes the cgroupns-root. + For the init_cgroup_ns, this is the real root ('/') cgroup + (identified in code as cgrp_dfl_root.cgrp). + +(2) The cgroupns-root cgroup does not change even if the namespace + creator process later moves to a different cgroup. + $ ~/unshare -c # unshare cgroupns in some cgroup + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/ + [ns]$ mkdir sub_cgrp_1 + [ns]$ echo 0 > sub_cgrp_1/cgroup.procs + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/sub_cgrp_1 + +(3) Each process gets its CGROUPNS specific view of /proc/<pid>/cgroup +(a) Processes running inside the cgroup namespace will be able to see + cgroup paths (in /proc/self/cgroup) only inside their root cgroup + [ns]$ sleep 100000 & # From within unshared cgroupns + [1] 7353 + [ns]$ echo 7353 > sub_cgrp_1/cgroup.procs + [ns]$ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/sub_cgrp_1 + +(b) From global cgroupns, the real cgroup path will be visible: + $ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1/sub_cgrp_1
Quoted 9 lines
Documentation/cgroups/namespace.txt line 104
Quoted 6 lines
Documentation/cgroups/namespace.txt new file +6
-0+ +(c) From a sibling cgroupns (cgroupns root-ed at a different cgroup), cgroup + path relative to its own cgroupns-root will be shown: + # ns2's cgroupns-root is at '/batchjobs/container_id2' + [ns2]$ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/../container_id2/sub_cgrp_1Should be ../container_id1/sub_cgrp_1 ?
Starting with '/' was deliberate.
Quoted 6 lines
Documentation/cgroups/namespace.txt line 107
Quoted 3 lines
Documentation/cgroups/namespace.txt new file +3
-0+ + Note that the relative path always starts with '/' to indicate that its + relative to the cgroupns-root of the caller.If a path doesn't start with '/', then it's a relative path, so why make it start with '/'?
This is so as not to surprise the apps parsing /proc/<pid>/cgroup files and using the path in it as absolute path. The existing paths there always start with '/' right now. Retaining the '/' means path generated by userspace continuous to work. Does this makes sense?
Quoted 16 lines
Quoted 16 lines
Documentation/cgroups/namespace.txt new file +16
-0+ +(4) Processes inside a cgroupns can move in-and-out of the cgroupns-root + (if they have proper access to external cgroups). + # From inside cgroupns (with cgroupns-root at /batchjobs/container_id1), and + # assuming that the global hierarchy is still accessible inside cgroupns: + $ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/sub_cgrp_1 + $ echo 7353 > batchjobs/container_id2/cgroup.procs + $ cat /proc/7353/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/../container_id2 + + Note that this kind of setup is not encouraged. A task inside cgroupns + should only be exposed to its own cgroupns hierarchy. Otherwise it makes + the virtualization of /proc/<pid>/cgroup less useful. + +(5) Setns to another cgroup namespace is allowed when:
Quoted 9 lines
Documentation/cgroups/namespace.txt line 129
Quoted 6 lines
Documentation/cgroups/namespace.txt new file +6
-0+ (a) the process has CAP_SYS_ADMIN in its current userns + (b) the process has CAP_SYS_ADMIN in the target cgroupns' userns + No implicit cgroup changes happen with attaching to another cgroupns. It + is expected that the somone moves the attaching process under the target + cgroupns-root. +s/the somone/someone
fixed.
Quoted 10 lines
Documentation/cgroups/namespace.txt line 136
Quoted 7 lines
Documentation/cgroups/namespace.txt new file +7
-0+(6) When some thread from a multi-threaded process unshares its + cgroup-namespace, the new cgroupns gets applied to the entire + process (all the threads). This should be OK since + unified-hierarchy only allows process-level containerization. So + all the threads in the process will have the same cgroup. + +(7) The cgroup namespace is alive as long as there is atleast 1s/atelast/at least
fixed.
Quoted 9 lines
Quoted 9 lines
Documentation/cgroups/namespace.txt new file +9
-0+ process inside it. When the last process exits, the cgroup + namespace is destroyed. The cgroupns-root and the actual cgroups + remain though. + +(8) Namespace specific cgroup hierarchy can be mounted by a process running + inside cgroupns: + $ mount -t cgroup -o __DEVEL__sane_behavior cgroup $MOUNT_POINT + + This will mount the unified cgroup hierarchy with cgroupns-root as the
Quoted 8 lines
Documentation/cgroups/namespace.txt line 147
Quoted 3 lines
Documentation/cgroups/namespace.txt new file +2
-0+ filesystem root. The process needs CAP_SYS_ADMIN in its userns and mntns. +--
To unsubscribe from this list: send the line "unsubscribe cgroups" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Thanks!
Signature · 1 line
Aditya
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 135 lines · Richard Weinberger
Am 05.01.2015 um 23:48 schrieb Aditya Kali:
Quoted 134 lines · Richard Weinberger
Quoted 58 lines
Aditya,
I gave your patch set a try but it does not work for me. Maybe you can bring some light into the issues I'm facing. Sadly I still had no time to dig into your code.
Am 05.12.2014 um 02:55 schrieb Aditya Kali:
Quoted 51 lines
Signed-off-by Aditya Kali <[email protected]>--- Documentation/cgroups/namespace.txt | 147 ++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 Documentation/cgroups/namespace.txtDocumentation/cgroups/namespace.txt new file +39
-0@@ -0,0 +1,147 @@ + CGroup Namespaces + +CGroup Namespace provides a mechanism to virtualize the view of the +/proc/<pid>/cgroup file. The CLONE_NEWCGROUP clone-flag can be used with +clone() and unshare() syscalls to create a new cgroup namespace. +The process running inside the cgroup namespace will have its /proc/<pid>/cgroup +output restricted to cgroupns-root. cgroupns-root is the cgroup of the process +at the time of creation of the cgroup namespace. + +Prior to CGroup Namespace, the /proc/<pid>/cgroup file used to show complete +path of the cgroup of a process. In a container setup (where a set of cgroups +and namespaces are intended to isolate processes), the /proc/<pid>/cgroup file +may leak potential system level information to the isolated processes. + +For Example: + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + +The path '/batchjobs/container_id1' can generally be considered as system-data +and its desirable to not expose it to the isolated process. + +CGroup Namespaces can be used to restrict visibility of this path. +For Example: + # Before creating cgroup namespace + $ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:37 /proc/self/ns/cgroup -> cgroup:[4026531835] + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # unshare(CLONE_NEWCGROUP) and exec /bin/bash + $ ~/unshare -c + [ns]$ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:35 /proc/self/ns/cgroup -> cgroup:[4026532183] + # From within new cgroupns, process sees that its in the root cgroup + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/ + + # From global cgroupns: + $ cat /proc/<pid>/cgroupQuoted 9 lines
Documentation/cgroups/namespace.txt line 45
Quoted 6 lines
Documentation/cgroups/namespace.txt new file +6
-0+ 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # Unshare cgroupns along with userns and mountns + # Following calls unshare(CLONE_NEWCGROUP|CLONE_NEWUSER|CLONE_NEWNS), then + # sets up uid/gid map and execs /bin/bash + $ ~/unshare -c -u -mThis command does not issue
CLONE_NEWUSER, -U does.I was using a custom unshare binary. But I will update the command line to be similar to the one in util-linux.
Quoted 10 lines
Documentation/cgroups/namespace.txt line 54
Quoted 9 lines
Documentation/cgroups/namespace.txt new file +9
-0+ # Originally, we were in /batchjobs/container_id1 cgroup. Mount our own cgroup + # hierarchy. + [ns]$ mount -t cgroup cgroup /tmp/cgroup + [ns]$ ls -l /tmp/cgroup + total 0 + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.controllers + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.populated + -rw-r--r-- 1 root root 0 2014-10-13 09:25 cgroup.procs + -rw-r--r-- 1 root root 0 2014-10-13 09:32 cgroup.subtree_controlQuoted 7 lines
I've patched libvirt-lxc to issue
CLONE_NEWCGROUPand not bind mount cgroupfs into a container. But I'm unable to mount cgroupfs within the container, mount(2) is failing with EINVAL. And/proc/self/cgroupstill shows the cgroup from outside.---cut---
container:/ # ls/sys/fs/cgroup/container:/ # mount -t cgroup none/sys/fs/cgroup/You need to provide "-o
__DEVEL_sane_behavior" flag. Inside the container, only unified hierarchy can be mounted. So, for now, that flag is needed. I will fix the documentation too.Quoted 41 lines
mount: wrong fs type, bad option, bad superblock on none,
missing codepage or helper program, or other errorIn some cases useful info is found in syslog - try dmesg | tail or so.
container:/ # cat/proc/self/cgroup8:memory:/machine/test00.libvirt-lxc 7:devices:/machine/test00.libvirt-lxc
6:hugetlb:/
5:cpuset:/machine/test00.libvirt-lxc 4:blkio:/machine/test00.libvirt-lxc 3:cpu,cpuacct:/machine/test00.libvirt-lxc 2:freezer:/machine/test00.libvirt-lxc 1:name=systemd:/user.slice/user-0.slice/session-c2.scope container:/ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:02 .
dr-xr-xr-x 8 root root 0 Dec 14 23:02 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:02 cgroup -> cgroup:[4026532240] lrwxrwxrwx 1 root root 0 Dec 14 23:02 ipc -> ipc:[4026532238] lrwxrwxrwx 1 root root 0 Dec 14 23:02 mnt -> mnt:[4026532235] lrwxrwxrwx 1 root root 0 Dec 14 23:02 net -> net:[4026532242] lrwxrwxrwx 1 root root 0 Dec 14 23:02 pid -> pid:[4026532239] lrwxrwxrwx 1 root root 0 Dec 14 23:02 user -> user:[4026532234] lrwxrwxrwx 1 root root 0 Dec 14 23:02 uts -> uts:[4026532236] container:/ ##host side
lxc-os132:~ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:56 .
dr-xr-xr-x 8 root root 0 Dec 14 23:56 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:56 cgroup -> cgroup:[4026531835] lrwxrwxrwx 1 root root 0 Dec 14 23:56 ipc -> ipc:[4026531839] lrwxrwxrwx 1 root root 0 Dec 14 23:56 mnt -> mnt:[4026531840] lrwxrwxrwx 1 root root 0 Dec 14 23:56 net -> net:[4026531957] lrwxrwxrwx 1 root root 0 Dec 14 23:56 pid -> pid:[4026531836] lrwxrwxrwx 1 root root 0 Dec 14 23:56 user -> user:[4026531837] lrwxrwxrwx 1 root root 0 Dec 14 23:56 uts -> uts:[4026531838] ---cut---
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Any ideas?
Please try with "-o
__DEVEL_sane_behavior" flag to the mount command.Ohh, this renders the whole patch useless for me as systemd needs the "old/default" behavior of cgroups. :-( I really hoped that cgroup namespaces will help me running systemd in a sane way within Linux containers.
Ugh. It sounds like there is a real mess here. At the very least there is misunderstanding.
I have a memory that systemd should have been able to use a unified hierarchy. As you could still mount the different controllers independently (they just use the same directory structure on each mount).
That said from a practical standpoint I am not certain that a cgroup namespace is viable if it can not support the behavior of cgroupsfs that everyone is using.
Eric
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 135 lines · Richard Weinberger
Am 05.01.2015 um 23:48 schrieb Aditya Kali:
Quoted 134 lines · Richard Weinberger
Quoted 58 lines
Aditya,
I gave your patch set a try but it does not work for me. Maybe you can bring some light into the issues I'm facing. Sadly I still had no time to dig into your code.
Am 05.12.2014 um 02:55 schrieb Aditya Kali:
Quoted 51 lines
Signed-off-by Aditya Kali <[email protected]>--- Documentation/cgroups/namespace.txt | 147 ++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 Documentation/cgroups/namespace.txtDocumentation/cgroups/namespace.txt new file +39
-0@@ -0,0 +1,147 @@ + CGroup Namespaces + +CGroup Namespace provides a mechanism to virtualize the view of the +/proc/<pid>/cgroup file. The CLONE_NEWCGROUP clone-flag can be used with +clone() and unshare() syscalls to create a new cgroup namespace. +The process running inside the cgroup namespace will have its /proc/<pid>/cgroup +output restricted to cgroupns-root. cgroupns-root is the cgroup of the process +at the time of creation of the cgroup namespace. + +Prior to CGroup Namespace, the /proc/<pid>/cgroup file used to show complete +path of the cgroup of a process. In a container setup (where a set of cgroups +and namespaces are intended to isolate processes), the /proc/<pid>/cgroup file +may leak potential system level information to the isolated processes. + +For Example: + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + +The path '/batchjobs/container_id1' can generally be considered as system-data +and its desirable to not expose it to the isolated process. + +CGroup Namespaces can be used to restrict visibility of this path. +For Example: + # Before creating cgroup namespace + $ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:37 /proc/self/ns/cgroup -> cgroup:[4026531835] + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # unshare(CLONE_NEWCGROUP) and exec /bin/bash + $ ~/unshare -c + [ns]$ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:35 /proc/self/ns/cgroup -> cgroup:[4026532183] + # From within new cgroupns, process sees that its in the root cgroup + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/ + + # From global cgroupns: + $ cat /proc/<pid>/cgroupQuoted 9 lines
Documentation/cgroups/namespace.txt line 45
Quoted 6 lines
Documentation/cgroups/namespace.txt new file +6
-0+ 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # Unshare cgroupns along with userns and mountns + # Following calls unshare(CLONE_NEWCGROUP|CLONE_NEWUSER|CLONE_NEWNS), then + # sets up uid/gid map and execs /bin/bash + $ ~/unshare -c -u -mThis command does not issue
CLONE_NEWUSER, -U does.I was using a custom unshare binary. But I will update the command line to be similar to the one in util-linux.
Quoted 10 lines
Documentation/cgroups/namespace.txt line 54
Quoted 9 lines
Documentation/cgroups/namespace.txt new file +9
-0+ # Originally, we were in /batchjobs/container_id1 cgroup. Mount our own cgroup + # hierarchy. + [ns]$ mount -t cgroup cgroup /tmp/cgroup + [ns]$ ls -l /tmp/cgroup + total 0 + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.controllers + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.populated + -rw-r--r-- 1 root root 0 2014-10-13 09:25 cgroup.procs + -rw-r--r-- 1 root root 0 2014-10-13 09:32 cgroup.subtree_controlQuoted 7 lines
I've patched libvirt-lxc to issue
CLONE_NEWCGROUPand not bind mount cgroupfs into a container. But I'm unable to mount cgroupfs within the container, mount(2) is failing with EINVAL. And/proc/self/cgroupstill shows the cgroup from outside.---cut---
container:/ # ls/sys/fs/cgroup/container:/ # mount -t cgroup none/sys/fs/cgroup/You need to provide "-o
__DEVEL_sane_behavior" flag. Inside the container, only unified hierarchy can be mounted. So, for now, that flag is needed. I will fix the documentation too.Quoted 41 lines
mount: wrong fs type, bad option, bad superblock on none,
missing codepage or helper program, or other errorIn some cases useful info is found in syslog - try dmesg | tail or so.
container:/ # cat/proc/self/cgroup8:memory:/machine/test00.libvirt-lxc 7:devices:/machine/test00.libvirt-lxc
6:hugetlb:/
5:cpuset:/machine/test00.libvirt-lxc 4:blkio:/machine/test00.libvirt-lxc 3:cpu,cpuacct:/machine/test00.libvirt-lxc 2:freezer:/machine/test00.libvirt-lxc 1:name=systemd:/user.slice/user-0.slice/session-c2.scope container:/ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:02 .
dr-xr-xr-x 8 root root 0 Dec 14 23:02 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:02 cgroup -> cgroup:[4026532240] lrwxrwxrwx 1 root root 0 Dec 14 23:02 ipc -> ipc:[4026532238] lrwxrwxrwx 1 root root 0 Dec 14 23:02 mnt -> mnt:[4026532235] lrwxrwxrwx 1 root root 0 Dec 14 23:02 net -> net:[4026532242] lrwxrwxrwx 1 root root 0 Dec 14 23:02 pid -> pid:[4026532239] lrwxrwxrwx 1 root root 0 Dec 14 23:02 user -> user:[4026532234] lrwxrwxrwx 1 root root 0 Dec 14 23:02 uts -> uts:[4026532236] container:/ ##host side
lxc-os132:~ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:56 .
dr-xr-xr-x 8 root root 0 Dec 14 23:56 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:56 cgroup -> cgroup:[4026531835] lrwxrwxrwx 1 root root 0 Dec 14 23:56 ipc -> ipc:[4026531839] lrwxrwxrwx 1 root root 0 Dec 14 23:56 mnt -> mnt:[4026531840] lrwxrwxrwx 1 root root 0 Dec 14 23:56 net -> net:[4026531957] lrwxrwxrwx 1 root root 0 Dec 14 23:56 pid -> pid:[4026531836] lrwxrwxrwx 1 root root 0 Dec 14 23:56 user -> user:[4026531837] lrwxrwxrwx 1 root root 0 Dec 14 23:56 uts -> uts:[4026531838] ---cut---
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Any ideas?
Please try with "-o
__DEVEL_sane_behavior" flag to the mount command.Ohh, this renders the whole patch useless for me as systemd needs the "old/default" behavior of cgroups. :-( I really hoped that cgroup namespaces will help me running systemd in a sane way within Linux containers.
Ugh. It sounds like there is a real mess here. At the very least there is misunderstanding.
I have a memory that systemd should have been able to use a unified hierarchy. As you could still mount the different controllers independently (they just use the same directory structure on each mount).
That said from a practical standpoint I am not certain that a cgroup namespace is viable if it can not support the behavior of cgroupsfs that everyone is using.
Eric
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveAm 06.01.2015 um 00:53 schrieb Eric W. Biederman:
Quoted 145 lines
Quoted 135 lines · Richard Weinberger
Am 05.01.2015 um 23:48 schrieb Aditya Kali:
Quoted 134 lines · Richard Weinberger
Quoted 58 lines
Aditya,
I gave your patch set a try but it does not work for me. Maybe you can bring some light into the issues I'm facing. Sadly I still had no time to dig into your code.
Am 05.12.2014 um 02:55 schrieb Aditya Kali:
Quoted 51 lines
Signed-off-by Aditya Kali <[email protected]>--- Documentation/cgroups/namespace.txt | 147 ++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 Documentation/cgroups/namespace.txtDocumentation/cgroups/namespace.txt new file +39
-0@@ -0,0 +1,147 @@ + CGroup Namespaces + +CGroup Namespace provides a mechanism to virtualize the view of the +/proc/<pid>/cgroup file. The CLONE_NEWCGROUP clone-flag can be used with +clone() and unshare() syscalls to create a new cgroup namespace. +The process running inside the cgroup namespace will have its /proc/<pid>/cgroup +output restricted to cgroupns-root. cgroupns-root is the cgroup of the process +at the time of creation of the cgroup namespace. + +Prior to CGroup Namespace, the /proc/<pid>/cgroup file used to show complete +path of the cgroup of a process. In a container setup (where a set of cgroups +and namespaces are intended to isolate processes), the /proc/<pid>/cgroup file +may leak potential system level information to the isolated processes. + +For Example: + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + +The path '/batchjobs/container_id1' can generally be considered as system-data +and its desirable to not expose it to the isolated process. + +CGroup Namespaces can be used to restrict visibility of this path. +For Example: + # Before creating cgroup namespace + $ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:37 /proc/self/ns/cgroup -> cgroup:[4026531835] + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # unshare(CLONE_NEWCGROUP) and exec /bin/bash + $ ~/unshare -c + [ns]$ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:35 /proc/self/ns/cgroup -> cgroup:[4026532183] + # From within new cgroupns, process sees that its in the root cgroup + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/ + + # From global cgroupns: + $ cat /proc/<pid>/cgroupQuoted 9 lines
Documentation/cgroups/namespace.txt line 45
Quoted 6 lines
Documentation/cgroups/namespace.txt new file +6
-0+ 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # Unshare cgroupns along with userns and mountns + # Following calls unshare(CLONE_NEWCGROUP|CLONE_NEWUSER|CLONE_NEWNS), then + # sets up uid/gid map and execs /bin/bash + $ ~/unshare -c -u -mThis command does not issue
CLONE_NEWUSER, -U does.I was using a custom unshare binary. But I will update the command line to be similar to the one in util-linux.
Quoted 10 lines
Documentation/cgroups/namespace.txt line 54
Quoted 9 lines
Documentation/cgroups/namespace.txt new file +9
-0+ # Originally, we were in /batchjobs/container_id1 cgroup. Mount our own cgroup + # hierarchy. + [ns]$ mount -t cgroup cgroup /tmp/cgroup + [ns]$ ls -l /tmp/cgroup + total 0 + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.controllers + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.populated + -rw-r--r-- 1 root root 0 2014-10-13 09:25 cgroup.procs + -rw-r--r-- 1 root root 0 2014-10-13 09:32 cgroup.subtree_controlQuoted 7 lines
I've patched libvirt-lxc to issue
CLONE_NEWCGROUPand not bind mount cgroupfs into a container. But I'm unable to mount cgroupfs within the container, mount(2) is failing with EINVAL. And/proc/self/cgroupstill shows the cgroup from outside.---cut---
container:/ # ls/sys/fs/cgroup/container:/ # mount -t cgroup none/sys/fs/cgroup/You need to provide "-o
__DEVEL_sane_behavior" flag. Inside the container, only unified hierarchy can be mounted. So, for now, that flag is needed. I will fix the documentation too.Quoted 41 lines
mount: wrong fs type, bad option, bad superblock on none,
missing codepage or helper program, or other errorIn some cases useful info is found in syslog - try dmesg | tail or so.
container:/ # cat/proc/self/cgroup8:memory:/machine/test00.libvirt-lxc 7:devices:/machine/test00.libvirt-lxc
6:hugetlb:/
5:cpuset:/machine/test00.libvirt-lxc 4:blkio:/machine/test00.libvirt-lxc 3:cpu,cpuacct:/machine/test00.libvirt-lxc 2:freezer:/machine/test00.libvirt-lxc 1:name=systemd:/user.slice/user-0.slice/session-c2.scope container:/ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:02 .
dr-xr-xr-x 8 root root 0 Dec 14 23:02 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:02 cgroup -> cgroup:[4026532240] lrwxrwxrwx 1 root root 0 Dec 14 23:02 ipc -> ipc:[4026532238] lrwxrwxrwx 1 root root 0 Dec 14 23:02 mnt -> mnt:[4026532235] lrwxrwxrwx 1 root root 0 Dec 14 23:02 net -> net:[4026532242] lrwxrwxrwx 1 root root 0 Dec 14 23:02 pid -> pid:[4026532239] lrwxrwxrwx 1 root root 0 Dec 14 23:02 user -> user:[4026532234] lrwxrwxrwx 1 root root 0 Dec 14 23:02 uts -> uts:[4026532236] container:/ ##host side
lxc-os132:~ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:56 .
dr-xr-xr-x 8 root root 0 Dec 14 23:56 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:56 cgroup -> cgroup:[4026531835] lrwxrwxrwx 1 root root 0 Dec 14 23:56 ipc -> ipc:[4026531839] lrwxrwxrwx 1 root root 0 Dec 14 23:56 mnt -> mnt:[4026531840] lrwxrwxrwx 1 root root 0 Dec 14 23:56 net -> net:[4026531957] lrwxrwxrwx 1 root root 0 Dec 14 23:56 pid -> pid:[4026531836] lrwxrwxrwx 1 root root 0 Dec 14 23:56 user -> user:[4026531837] lrwxrwxrwx 1 root root 0 Dec 14 23:56 uts -> uts:[4026531838] ---cut---Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Any ideas?
Please try with "-o
__DEVEL_sane_behavior" flag to the mount command.Ohh, this renders the whole patch useless for me as systemd needs the "old/default" behavior of cgroups. :-( I really hoped that cgroup namespaces will help me running systemd in a sane way within Linux containers.
Quoted 7 lines
Ugh. It sounds like there is a real mess here. At the very least there is misunderstanding.
I have a memory that systemd should have been able to use a unified hierarchy. As you could still mount the different controllers independently (they just use the same directory structure on each mount).
Luckily systemd folks want to move to the unified but as of now it does not work. Please see this mail from Lennart:
https://www.redhat.com/archives/libvir-list/2014-November/msg01090.html
Maybe the porting is easy. Dunno.
I had no time yet to look into that.
Quoted 3 lines
That said from a practical standpoint I am not certain that a cgroup namespace is viable if it can not support the behavior of cgroupsfs that everyone is using.
Yep.
systemd *really* wants to own cgroupfs, so it has to mount it within the container. Currently libvirt does nasty hacks using bind mounts which are also problematic. My hope was that with cgroup namespaces I can simply cheat systemd and give it a cgroupfs to mess with.
Thanks,
//richard
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 145 lines · Eric W. Biederman
Quoted 135 lines · Richard Weinberger
Am 05.01.2015 um 23:48 schrieb Aditya Kali:
Quoted 134 lines · Richard Weinberger
Quoted 58 lines
Aditya,
I gave your patch set a try but it does not work for me. Maybe you can bring some light into the issues I'm facing. Sadly I still had no time to dig into your code.
Am 05.12.2014 um 02:55 schrieb Aditya Kali:
Quoted 51 lines
Signed-off-by Aditya Kali <[email protected]>--- Documentation/cgroups/namespace.txt | 147 ++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 Documentation/cgroups/namespace.txtDocumentation/cgroups/namespace.txt new file +39
-0@@ -0,0 +1,147 @@ + CGroup Namespaces + +CGroup Namespace provides a mechanism to virtualize the view of the +/proc/<pid>/cgroup file. The CLONE_NEWCGROUP clone-flag can be used with +clone() and unshare() syscalls to create a new cgroup namespace. +The process running inside the cgroup namespace will have its /proc/<pid>/cgroup +output restricted to cgroupns-root. cgroupns-root is the cgroup of the process +at the time of creation of the cgroup namespace. + +Prior to CGroup Namespace, the /proc/<pid>/cgroup file used to show complete +path of the cgroup of a process. In a container setup (where a set of cgroups +and namespaces are intended to isolate processes), the /proc/<pid>/cgroup file +may leak potential system level information to the isolated processes. + +For Example: + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + +The path '/batchjobs/container_id1' can generally be considered as system-data +and its desirable to not expose it to the isolated process. + +CGroup Namespaces can be used to restrict visibility of this path. +For Example: + # Before creating cgroup namespace + $ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:37 /proc/self/ns/cgroup -> cgroup:[4026531835] + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # unshare(CLONE_NEWCGROUP) and exec /bin/bash + $ ~/unshare -c + [ns]$ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:35 /proc/self/ns/cgroup -> cgroup:[4026532183] + # From within new cgroupns, process sees that its in the root cgroup + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/ + + # From global cgroupns: + $ cat /proc/<pid>/cgroupQuoted 9 lines
Documentation/cgroups/namespace.txt line 45
Quoted 6 lines
Documentation/cgroups/namespace.txt new file +6
-0+ 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # Unshare cgroupns along with userns and mountns + # Following calls unshare(CLONE_NEWCGROUP|CLONE_NEWUSER|CLONE_NEWNS), then + # sets up uid/gid map and execs /bin/bash + $ ~/unshare -c -u -mThis command does not issue
CLONE_NEWUSER, -U does.I was using a custom unshare binary. But I will update the command line to be similar to the one in util-linux.
Quoted 10 lines
Documentation/cgroups/namespace.txt line 54
Quoted 9 lines
Documentation/cgroups/namespace.txt new file +9
-0+ # Originally, we were in /batchjobs/container_id1 cgroup. Mount our own cgroup + # hierarchy. + [ns]$ mount -t cgroup cgroup /tmp/cgroup + [ns]$ ls -l /tmp/cgroup + total 0 + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.controllers + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.populated + -rw-r--r-- 1 root root 0 2014-10-13 09:25 cgroup.procs + -rw-r--r-- 1 root root 0 2014-10-13 09:32 cgroup.subtree_controlQuoted 7 lines
I've patched libvirt-lxc to issue
CLONE_NEWCGROUPand not bind mount cgroupfs into a container. But I'm unable to mount cgroupfs within the container, mount(2) is failing with EINVAL. And/proc/self/cgroupstill shows the cgroup from outside.---cut---
container:/ # ls/sys/fs/cgroup/container:/ # mount -t cgroup none/sys/fs/cgroup/You need to provide "-o
__DEVEL_sane_behavior" flag. Inside the container, only unified hierarchy can be mounted. So, for now, that flag is needed. I will fix the documentation too.Quoted 41 lines
mount: wrong fs type, bad option, bad superblock on none,
missing codepage or helper program, or other errorIn some cases useful info is found in syslog - try dmesg | tail or so.
container:/ # cat/proc/self/cgroup8:memory:/machine/test00.libvirt-lxc 7:devices:/machine/test00.libvirt-lxc
6:hugetlb:/
5:cpuset:/machine/test00.libvirt-lxc 4:blkio:/machine/test00.libvirt-lxc 3:cpu,cpuacct:/machine/test00.libvirt-lxc 2:freezer:/machine/test00.libvirt-lxc 1:name=systemd:/user.slice/user-0.slice/session-c2.scope container:/ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:02 .
dr-xr-xr-x 8 root root 0 Dec 14 23:02 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:02 cgroup -> cgroup:[4026532240] lrwxrwxrwx 1 root root 0 Dec 14 23:02 ipc -> ipc:[4026532238] lrwxrwxrwx 1 root root 0 Dec 14 23:02 mnt -> mnt:[4026532235] lrwxrwxrwx 1 root root 0 Dec 14 23:02 net -> net:[4026532242] lrwxrwxrwx 1 root root 0 Dec 14 23:02 pid -> pid:[4026532239] lrwxrwxrwx 1 root root 0 Dec 14 23:02 user -> user:[4026532234] lrwxrwxrwx 1 root root 0 Dec 14 23:02 uts -> uts:[4026532236] container:/ ##host side
lxc-os132:~ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:56 .
dr-xr-xr-x 8 root root 0 Dec 14 23:56 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:56 cgroup -> cgroup:[4026531835] lrwxrwxrwx 1 root root 0 Dec 14 23:56 ipc -> ipc:[4026531839] lrwxrwxrwx 1 root root 0 Dec 14 23:56 mnt -> mnt:[4026531840] lrwxrwxrwx 1 root root 0 Dec 14 23:56 net -> net:[4026531957] lrwxrwxrwx 1 root root 0 Dec 14 23:56 pid -> pid:[4026531836] lrwxrwxrwx 1 root root 0 Dec 14 23:56 user -> user:[4026531837] lrwxrwxrwx 1 root root 0 Dec 14 23:56 uts -> uts:[4026531838] ---cut---Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Any ideas?
Please try with "-o
__DEVEL_sane_behavior" flag to the mount command.Ohh, this renders the whole patch useless for me as systemd needs the "old/default" behavior of cgroups. :-( I really hoped that cgroup namespaces will help me running systemd in a sane way within Linux containers.
Quoted 8 lines
Ugh. It sounds like there is a real mess here. At the very least there is misunderstanding.
I have a memory that systemd should have been able to use a unified hierarchy. As you could still mount the different controllers independently (they just use the same directory structure on each mount).
In theory, if you boot kernel with "cgroup__DEVEL__legacy_files_on_dfl" command-line parameter, and mount cgroups with sane-behavior flag, then it should be more-or-less similar to mounting all hierarchies together at the same mount-point (mount -t cgroup -o __DEVEL_sane_behavior none $mntpt). I haven't tried this, but systemd should be able to work with it and you can enable cgroup-namespace too.
Quoted 4 lines
That said from a practical standpoint I am not certain that a cgroup namespace is viable if it can not support the behavior of cgroupsfs that everyone is using.
Since the old/default behavior is on its way out, I didn't invest time in fixing that. Also, some of the properties that make cgroup-namespace simpler are only provided by unified hierarchy (for
example: a single root-cgroup per container).
Quoted 1 line
Eric
Signature · 1 line
Aditya
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 145 lines · Eric W. Biederman
Quoted 135 lines · Richard Weinberger
Am 05.01.2015 um 23:48 schrieb Aditya Kali:
Quoted 134 lines · Richard Weinberger
Quoted 58 lines
Aditya,
I gave your patch set a try but it does not work for me. Maybe you can bring some light into the issues I'm facing. Sadly I still had no time to dig into your code.
Am 05.12.2014 um 02:55 schrieb Aditya Kali:
Quoted 51 lines
Signed-off-by Aditya Kali <[email protected]>--- Documentation/cgroups/namespace.txt | 147 ++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 Documentation/cgroups/namespace.txtDocumentation/cgroups/namespace.txt new file +39
-0@@ -0,0 +1,147 @@ + CGroup Namespaces + +CGroup Namespace provides a mechanism to virtualize the view of the +/proc/<pid>/cgroup file. The CLONE_NEWCGROUP clone-flag can be used with +clone() and unshare() syscalls to create a new cgroup namespace. +The process running inside the cgroup namespace will have its /proc/<pid>/cgroup +output restricted to cgroupns-root. cgroupns-root is the cgroup of the process +at the time of creation of the cgroup namespace. + +Prior to CGroup Namespace, the /proc/<pid>/cgroup file used to show complete +path of the cgroup of a process. In a container setup (where a set of cgroups +and namespaces are intended to isolate processes), the /proc/<pid>/cgroup file +may leak potential system level information to the isolated processes. + +For Example: + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + +The path '/batchjobs/container_id1' can generally be considered as system-data +and its desirable to not expose it to the isolated process. + +CGroup Namespaces can be used to restrict visibility of this path. +For Example: + # Before creating cgroup namespace + $ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:37 /proc/self/ns/cgroup -> cgroup:[4026531835] + $ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # unshare(CLONE_NEWCGROUP) and exec /bin/bash + $ ~/unshare -c + [ns]$ ls -l /proc/self/ns/cgroup + lrwxrwxrwx 1 root root 0 2014-07-15 10:35 /proc/self/ns/cgroup -> cgroup:[4026532183] + # From within new cgroupns, process sees that its in the root cgroup + [ns]$ cat /proc/self/cgroup + 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/ + + # From global cgroupns: + $ cat /proc/<pid>/cgroupQuoted 9 lines
Documentation/cgroups/namespace.txt line 45
Quoted 6 lines
Documentation/cgroups/namespace.txt new file +6
-0+ 0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/container_id1 + + # Unshare cgroupns along with userns and mountns + # Following calls unshare(CLONE_NEWCGROUP|CLONE_NEWUSER|CLONE_NEWNS), then + # sets up uid/gid map and execs /bin/bash + $ ~/unshare -c -u -mThis command does not issue
CLONE_NEWUSER, -U does.I was using a custom unshare binary. But I will update the command line to be similar to the one in util-linux.
Quoted 10 lines
Documentation/cgroups/namespace.txt line 54
Quoted 9 lines
Documentation/cgroups/namespace.txt new file +9
-0+ # Originally, we were in /batchjobs/container_id1 cgroup. Mount our own cgroup + # hierarchy. + [ns]$ mount -t cgroup cgroup /tmp/cgroup + [ns]$ ls -l /tmp/cgroup + total 0 + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.controllers + -r--r--r-- 1 root root 0 2014-10-13 09:32 cgroup.populated + -rw-r--r-- 1 root root 0 2014-10-13 09:25 cgroup.procs + -rw-r--r-- 1 root root 0 2014-10-13 09:32 cgroup.subtree_controlQuoted 7 lines
I've patched libvirt-lxc to issue
CLONE_NEWCGROUPand not bind mount cgroupfs into a container. But I'm unable to mount cgroupfs within the container, mount(2) is failing with EINVAL. And/proc/self/cgroupstill shows the cgroup from outside.---cut---
container:/ # ls/sys/fs/cgroup/container:/ # mount -t cgroup none/sys/fs/cgroup/You need to provide "-o
__DEVEL_sane_behavior" flag. Inside the container, only unified hierarchy can be mounted. So, for now, that flag is needed. I will fix the documentation too.Quoted 41 lines
mount: wrong fs type, bad option, bad superblock on none,
missing codepage or helper program, or other errorIn some cases useful info is found in syslog - try dmesg | tail or so.
container:/ # cat/proc/self/cgroup8:memory:/machine/test00.libvirt-lxc 7:devices:/machine/test00.libvirt-lxc
6:hugetlb:/
5:cpuset:/machine/test00.libvirt-lxc 4:blkio:/machine/test00.libvirt-lxc 3:cpu,cpuacct:/machine/test00.libvirt-lxc 2:freezer:/machine/test00.libvirt-lxc 1:name=systemd:/user.slice/user-0.slice/session-c2.scope container:/ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:02 .
dr-xr-xr-x 8 root root 0 Dec 14 23:02 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:02 cgroup -> cgroup:[4026532240] lrwxrwxrwx 1 root root 0 Dec 14 23:02 ipc -> ipc:[4026532238] lrwxrwxrwx 1 root root 0 Dec 14 23:02 mnt -> mnt:[4026532235] lrwxrwxrwx 1 root root 0 Dec 14 23:02 net -> net:[4026532242] lrwxrwxrwx 1 root root 0 Dec 14 23:02 pid -> pid:[4026532239] lrwxrwxrwx 1 root root 0 Dec 14 23:02 user -> user:[4026532234] lrwxrwxrwx 1 root root 0 Dec 14 23:02 uts -> uts:[4026532236] container:/ ##host side
lxc-os132:~ # ls -la/proc/self/ns
total 0
dr-x--x--x 2 root root 0 Dec 14 23:56 .
dr-xr-xr-x 8 root root 0 Dec 14 23:56 ..
lrwxrwxrwx 1 root root 0 Dec 14 23:56 cgroup -> cgroup:[4026531835] lrwxrwxrwx 1 root root 0 Dec 14 23:56 ipc -> ipc:[4026531839] lrwxrwxrwx 1 root root 0 Dec 14 23:56 mnt -> mnt:[4026531840] lrwxrwxrwx 1 root root 0 Dec 14 23:56 net -> net:[4026531957] lrwxrwxrwx 1 root root 0 Dec 14 23:56 pid -> pid:[4026531836] lrwxrwxrwx 1 root root 0 Dec 14 23:56 user -> user:[4026531837] lrwxrwxrwx 1 root root 0 Dec 14 23:56 uts -> uts:[4026531838] ---cut---Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Any ideas?
Please try with "-o
__DEVEL_sane_behavior" flag to the mount command.Ohh, this renders the whole patch useless for me as systemd needs the "old/default" behavior of cgroups. :-( I really hoped that cgroup namespaces will help me running systemd in a sane way within Linux containers.
Quoted 8 lines
Ugh. It sounds like there is a real mess here. At the very least there is misunderstanding.
I have a memory that systemd should have been able to use a unified hierarchy. As you could still mount the different controllers independently (they just use the same directory structure on each mount).
In theory, if you boot kernel with "cgroup__DEVEL__legacy_files_on_dfl" command-line parameter, and mount cgroups with sane-behavior flag, then it should be more-or-less similar to mounting all hierarchies together at the same mount-point (mount -t cgroup -o __DEVEL_sane_behavior none $mntpt). I haven't tried this, but systemd should be able to work with it and you can enable cgroup-namespace too.
Quoted 4 lines
That said from a practical standpoint I am not certain that a cgroup namespace is viable if it can not support the behavior of cgroupsfs that everyone is using.
Since the old/default behavior is on its way out, I didn't invest time in fixing that. Also, some of the properties that make cgroup-namespace simpler are only provided by unified hierarchy (for
example: a single root-cgroup per container).
Quoted 1 line
Eric
Signature · 1 line
Aditya
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveAm 06.01.2015 um 01:10 schrieb Aditya Kali:
Quoted 4 lines
Since the old/default behavior is on its way out, I didn't invest time in fixing that. Also, some of the properties that make cgroup-namespace simpler are only provided by unified hierarchy (for
example: a single root-cgroup per container).
Does the new sane cgroupfs behavior even have a single real world user? I always thought it isn't stable yet.
Linux distros currently use systemd v210. They don't dare to use a newer one. Even *if* systemd would support the sane sane cgroupfs behavior in the most recent version it will take 1-2 years until it would hit a recent distro.
So please support also the old and nasty behavior such that one day we can run current systemd distros in Linux containers.
Thanks,
//richard
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveAm 06.01.2015 um 01:10 schrieb Aditya Kali:
Quoted 4 lines
Since the old/default behavior is on its way out, I didn't invest time in fixing that. Also, some of the properties that make cgroup-namespace simpler are only provided by unified hierarchy (for
example: a single root-cgroup per container).
Does the new sane cgroupfs behavior even have a single real world user? I always thought it isn't stable yet.
Linux distros currently use systemd v210. They don't dare to use a newer one. Even *if* systemd would support the sane sane cgroupfs behavior in the most recent version it will take 1-2 years until it would hit a recent distro.
So please support also the old and nasty behavior such that one day we can run current systemd distros in Linux containers.
Thanks,
//richard
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveI understand your point. But it will add some complexity to the code.
Before trying to make it work for non-unified hierarchy cases, I would like to get a clearer idea.
What do you expect to be mounted when you run:
container:/ # mount -t cgroup none /sys/fs/cgroup/
from inside the container?
Note that cgroup-namespace wont be able to change the way cgroups are mounted .. i.e., if say cpu and cpuacct subsystems are mounted together at a single mount-point, then we cannot mount them any other way (inside a container or outside). This restriction exists today and cgroup-namespaces won't change that.
So, If on the host we have:
root@adityakali-vm2:/sys/fs/cgroup# cat /proc/mounts | grep cgroup tmpfs /sys/fs/cgroup tmpfs rw,relatime 0 0 cgroup /sys/fs/cgroup/cpu cgroup rw,relatime,cpuset,cpu,cpuacct 0 0 cgroup /sys/fs/cgroup/mem cgroup rw,relatime,memory,hugetlb 0 0 cgroup /sys/fs/cgroup/rest cgroup rw,relatime,devices,freezer,net_cls,blkio,perf_event,net_prio 0 0
And inside the container we want each subsystem to be on its own mount-point, then it will fail. Do you think even then its useful to support virtualizing paths for non-unified hierarchies?
Thanks,
Quoted 18 lines · Richard Weinberger
Am 06.01.2015 um 01:10 schrieb Aditya Kali:
Quoted 4 lines
Since the old/default behavior is on its way out, I didn't invest time in fixing that. Also, some of the properties that make cgroup-namespace simpler are only provided by unified hierarchy (for
example: a single root-cgroup per container).Does the new sane cgroupfs behavior even have a single real world user? I always thought it isn't stable yet.
Linux distros currently use systemd v210. They don't dare to use a newer one. Even *if* systemd would support the sane sane cgroupfs behavior in the most recent version it will take 1-2 years until it would hit a recent distro.
So please support also the old and nasty behavior such that one day we can run current systemd distros in Linux containers.
Thanks,
//richard
Signature · 1 line
Aditya
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveI understand your point. But it will add some complexity to the code.
Before trying to make it work for non-unified hierarchy cases, I would like to get a clearer idea.
What do you expect to be mounted when you run:
container:/ # mount -t cgroup none /sys/fs/cgroup/
from inside the container?
Note that cgroup-namespace wont be able to change the way cgroups are mounted .. i.e., if say cpu and cpuacct subsystems are mounted together at a single mount-point, then we cannot mount them any other way (inside a container or outside). This restriction exists today and cgroup-namespaces won't change that.
So, If on the host we have:
root@adityakali-vm2:/sys/fs/cgroup# cat /proc/mounts | grep cgroup tmpfs /sys/fs/cgroup tmpfs rw,relatime 0 0 cgroup /sys/fs/cgroup/cpu cgroup rw,relatime,cpuset,cpu,cpuacct 0 0 cgroup /sys/fs/cgroup/mem cgroup rw,relatime,memory,hugetlb 0 0 cgroup /sys/fs/cgroup/rest cgroup rw,relatime,devices,freezer,net_cls,blkio,perf_event,net_prio 0 0
And inside the container we want each subsystem to be on its own mount-point, then it will fail. Do you think even then its useful to support virtualizing paths for non-unified hierarchies?
Thanks,
Quoted 18 lines · Richard Weinberger
Am 06.01.2015 um 01:10 schrieb Aditya Kali:
Quoted 4 lines
Since the old/default behavior is on its way out, I didn't invest time in fixing that. Also, some of the properties that make cgroup-namespace simpler are only provided by unified hierarchy (for
example: a single root-cgroup per container).Does the new sane cgroupfs behavior even have a single real world user? I always thought it isn't stable yet.
Linux distros currently use systemd v210. They don't dare to use a newer one. Even *if* systemd would support the sane sane cgroupfs behavior in the most recent version it will take 1-2 years until it would hit a recent distro.
So please support also the old and nasty behavior such that one day we can run current systemd distros in Linux containers.
Thanks,
//richard
Signature · 1 line
Aditya
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveAm 07.01.2015 um 00:20 schrieb Aditya Kali:
Quoted 7 lines
I understand your point. But it will add some complexity to the code.
Before trying to make it work for non-unified hierarchy cases, I would like to get a clearer idea.
What do you expect to be mounted when you run:
container:/ # mount -t cgroup none/sys/fs/cgroup/
from inside the container?
I expect cgroupfs to behave exactly as it would in the initial namespace. Such that the container can do with it whatever it wants. systemd mounts and manages cgroups on its own.
Like for CONFIG_DEVPTS_MULTIPLE_INSTANCES.
If a new cgroup namespace cannot provide a clean and autonomous cgroupfs instance it is fundamentally flawed.
You cannot provide a namespace mechanism which depends on the host side that much.
This will also horrible break container migrations between hosts. i.e. Migrate a container from a Ubuntu host to a Fedora (systemd!) host.
Quoted 5 lines
Note that cgroup-namespace wont be able to change the way cgroups are mounted .. i.e., if say cpu and cpuacct subsystems are mounted together at a single mount-point, then we cannot mount them any other way (inside a container or outside). This restriction exists today and cgroup-namespaces won't change that.
Why can't cgroup namespace change this?
I think of cgroup namespace as a new and clean cgroupfs instance which inherits all limits from the outside.
Quoted 11 lines
So, If on the host we have:
root@adityakali-vm2:/sys/fs/cgroup# cat /proc/mounts | grep cgroup tmpfs /sys/fs/cgroup tmpfs rw,relatime 0 0 cgroup /sys/fs/cgroup/cpu cgroup rw,relatime,cpuset,cpu,cpuacct 0 0 cgroup /sys/fs/cgroup/mem cgroup rw,relatime,memory,hugetlb 0 0 cgroup /sys/fs/cgroup/rest cgroup rw,relatime,devices,freezer,net_cls,blkio,perf_event,net_prio 0 0And inside the container we want each subsystem to be on its own mount-point, then it will fail. Do you think even then its useful to support virtualizing paths for non-unified hierarchies?
As I've stated above I expect from cgroup namespaces a clean and sane cgroupfs instance no matter how the outer mounts are.
Thanks,
//richard
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveAm 07.01.2015 um 00:20 schrieb Aditya Kali:
Quoted 7 lines
I understand your point. But it will add some complexity to the code.
Before trying to make it work for non-unified hierarchy cases, I would like to get a clearer idea.
What do you expect to be mounted when you run:
container:/ # mount -t cgroup none/sys/fs/cgroup/
from inside the container?
I expect cgroupfs to behave exactly as it would in the initial namespace. Such that the container can do with it whatever it wants. systemd mounts and manages cgroups on its own.
Like for CONFIG_DEVPTS_MULTIPLE_INSTANCES.
If a new cgroup namespace cannot provide a clean and autonomous cgroupfs instance it is fundamentally flawed.
You cannot provide a namespace mechanism which depends on the host side that much.
This will also horrible break container migrations between hosts. i.e. Migrate a container from a Ubuntu host to a Fedora (systemd!) host.
Quoted 5 lines
Note that cgroup-namespace wont be able to change the way cgroups are mounted .. i.e., if say cpu and cpuacct subsystems are mounted together at a single mount-point, then we cannot mount them any other way (inside a container or outside). This restriction exists today and cgroup-namespaces won't change that.
Why can't cgroup namespace change this?
I think of cgroup namespace as a new and clean cgroupfs instance which inherits all limits from the outside.
Quoted 11 lines
So, If on the host we have:
root@adityakali-vm2:/sys/fs/cgroup# cat /proc/mounts | grep cgroup tmpfs /sys/fs/cgroup tmpfs rw,relatime 0 0 cgroup /sys/fs/cgroup/cpu cgroup rw,relatime,cpuset,cpu,cpuacct 0 0 cgroup /sys/fs/cgroup/mem cgroup rw,relatime,memory,hugetlb 0 0 cgroup /sys/fs/cgroup/rest cgroup rw,relatime,devices,freezer,net_cls,blkio,perf_event,net_prio 0 0And inside the container we want each subsystem to be on its own mount-point, then it will fail. Do you think even then its useful to support virtualizing paths for non-unified hierarchies?
As I've stated above I expect from cgroup namespaces a clean and sane cgroupfs instance no matter how the outer mounts are.
Thanks,
//richard
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveAm 07.01.2015 um 00:20 schrieb Aditya Kali:
Quoted 8 lines
I understand your point. But it will add some complexity to the code.
Before trying to make it work for non-unified hierarchy cases, I would like to get a clearer idea.
What do you expect to be mounted when you run:
container:/ # mount -t cgroup none/sys/fs/cgroup/
from inside the container?
Quoted 5 lines
Note that cgroup-namespace wont be able to change the way cgroups are mounted .. i.e., if say cpu and cpuacct subsystems are mounted together at a single mount-point, then we cannot mount them any other way (inside a container or outside). This restriction exists today and cgroup-namespaces won't change that.
I wondered why cgroup namespaces won't change that and looked at your patches in more detail.
What you propose as cgroup namespace is much more a cgroup chroot() than a namespace.
As you pass relative paths into the namespace you depend on the mount structure of the host side.
Hence, the abstraction between namespaces happens on the mount paths of the initial cgroupfs. But we really want a new cgroupfs instance within a container and not just a cut out of the initial cgroupfs mount.
I fear you approach is over simplified and won't work for all cases. It may work for your specific use case at Google but we really want something generic. Eric, what do you think?
Thanks,
//richard
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 25 lines · Richard Weinberger
Am 07.01.2015 um 00:20 schrieb Aditya Kali:
Quoted 8 lines
I understand your point. But it will add some complexity to the code.
Before trying to make it work for non-unified hierarchy cases, I would like to get a clearer idea.
What do you expect to be mounted when you run:
container:/ # mount -t cgroup none/sys/fs/cgroup/
from inside the container?Quoted 5 lines
Note that cgroup-namespace wont be able to change the way cgroups are mounted .. i.e., if say cpu and cpuacct subsystems are mounted together at a single mount-point, then we cannot mount them any other way (inside a container or outside). This restriction exists today and cgroup-namespaces won't change that.
I wondered why cgroup namespaces won't change that and looked at your patches in more detail.
What you propose as cgroup namespace is much more a cgroupchroot()than a namespace.
As you pass relative paths into the namespace you depend on the mount structure of the host side.
Hence, the abstraction between namespaces happens on the mount paths of the initial cgroupfs. But we really want a new cgroupfs instance within a container and not just a cut out of the initial cgroupfs mount.
Quoted 3 lines
I fear you approach is over simplified and won't work for all cases. It may work for your specific use case at Google but we really want something generic. Eric, what do you think?
I think I probably need to go back upthread and read the patches.
I think it is a reasonable practical requirement that a widely used long term supported distribution like RHEL 7 needs to be able to run in a linux container bizarre init system and all. And that we the abstractions should be that that we should be able to migrate such a beast.
There are a couple of issues in play and I think we need actual testing rather than reports that something shouldn't work before we reject a set
of patches. Aditya in one of his replies to me has reported a
configuration that he expects will work. So I think that configuration needs to be tested.
cgroups is a weird beast and the problems tend not to lie where a person would first expect.
I suspect no one strongly cares if the cgroup hierarchy is unified or not. By unified hierarchy I mean that every mount of cgroupfs has the same directories with the same processes in each directory.
I do think people will care which controllers will show up in differ mounts of cgroupfs, and I think that is relevant to process migration.
I am going to segway into scope of what is achievable with a cgroup namespace.
- If there are files in cgroupfs that are not safe to delegate we can not support those files in a container.
Last I looked there were such files and systemd used them.
- Which controllers share hierarchies of processes to track resources is a core cgroup issue and not a cgroup namespace issue.
If we find problems with using a unified hierarchy support we need to go fix cgroups in general not cgroupfs.
Eric
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 15 lines · Richard Weinberger
Am 07.01.2015 um 00:20 schrieb Aditya Kali:
Quoted 8 lines
I understand your point. But it will add some complexity to the code.
Before trying to make it work for non-unified hierarchy cases, I would like to get a clearer idea.
What do you expect to be mounted when you run:
container:/ # mount -t cgroup none/sys/fs/cgroup/
from inside the container?Quoted 5 lines
Note that cgroup-namespace wont be able to change the way cgroups are mounted .. i.e., if say cpu and cpuacct subsystems are mounted together at a single mount-point, then we cannot mount them any other way (inside a container or outside). This restriction exists today and cgroup-namespaces won't change that.
Quoted 10 lines
I wondered why cgroup namespaces won't change that and looked at your patches in more detail.
What you propose as cgroup namespace is much more a cgroupchroot()than a namespace.
As you pass relative paths into the namespace you depend on the mount structure of the host side.
Hence, the abstraction between namespaces happens on the mount paths of the initial cgroupfs. But we really want a new cgroupfs instance within a container and not just a cut out of the initial cgroupfs mount.
What you describe will be useful at Google too, just that I found it difficult/infeasible to include it in the scope of cgroup namespaces. The scope of cgroup namespace was deliberately limited to virtualize /proc/<pid>/cgroup file. That too in a way that doesn't need major changes to cgroup code itself. (It was also limited to unified hierarchy to keep things simple, but that can be changed).
Many of the cgroup subsystems (memory, cpu, etc) rely on the fact that they can see entire cgroup view. For example, in a memcg-OOM scenario, the memory controller would need to look at all sub-cgroups inside the OOMing cgroup. A per namespace cgroupfs instance (if I understand correctly) would mean that sub-cgroups created inside the namespace won't be visible outside. I expect this will break the functionality of the subsystem.
Illustration: memcg A is under OOM; [B] and [C] are cgroup namespace roots with possibly namespace-private sub-cgroups.
------ [B]
A --------|
------ [C]Cgroups are heavily used inside the kernel for various purposes which need any namespace-agnostic view. Inherent limitation of running containers running on a machine is that they share the same kernel. Perhaps what you need is something like kexec to be supported inside a container.
Quoted 6 lines
I fear you approach is over simplified and won't work for all cases. It may work for your specific use case at Google but we really want something generic. Eric, what do you think?
Thanks,
//richard
Signature · 1 line
Aditya
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 15 lines · Richard Weinberger
Am 07.01.2015 um 00:20 schrieb Aditya Kali:
Quoted 8 lines
I understand your point. But it will add some complexity to the code.
Before trying to make it work for non-unified hierarchy cases, I would like to get a clearer idea.
What do you expect to be mounted when you run:
container:/ # mount -t cgroup none/sys/fs/cgroup/
from inside the container?Quoted 5 lines
Note that cgroup-namespace wont be able to change the way cgroups are mounted .. i.e., if say cpu and cpuacct subsystems are mounted together at a single mount-point, then we cannot mount them any other way (inside a container or outside). This restriction exists today and cgroup-namespaces won't change that.
Quoted 10 lines
I wondered why cgroup namespaces won't change that and looked at your patches in more detail.
What you propose as cgroup namespace is much more a cgroupchroot()than a namespace.
As you pass relative paths into the namespace you depend on the mount structure of the host side.
Hence, the abstraction between namespaces happens on the mount paths of the initial cgroupfs. But we really want a new cgroupfs instance within a container and not just a cut out of the initial cgroupfs mount.
What you describe will be useful at Google too, just that I found it difficult/infeasible to include it in the scope of cgroup namespaces. The scope of cgroup namespace was deliberately limited to virtualize /proc/<pid>/cgroup file. That too in a way that doesn't need major changes to cgroup code itself. (It was also limited to unified hierarchy to keep things simple, but that can be changed).
Many of the cgroup subsystems (memory, cpu, etc) rely on the fact that they can see entire cgroup view. For example, in a memcg-OOM scenario, the memory controller would need to look at all sub-cgroups inside the OOMing cgroup. A per namespace cgroupfs instance (if I understand correctly) would mean that sub-cgroups created inside the namespace won't be visible outside. I expect this will break the functionality of the subsystem.
Illustration: memcg A is under OOM; [B] and [C] are cgroup namespace roots with possibly namespace-private sub-cgroups.
------ [B]
A --------|
------ [C]Cgroups are heavily used inside the kernel for various purposes which need any namespace-agnostic view. Inherent limitation of running containers running on a machine is that they share the same kernel. Perhaps what you need is something like kexec to be supported inside a container.
Quoted 6 lines
I fear you approach is over simplified and won't work for all cases. It may work for your specific use case at Google but we really want something generic. Eric, what do you think?
Thanks,
//richard
Signature · 1 line
Aditya
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 31 lines · Eric W. Biederman
Quoted 25 lines · Richard Weinberger
Am 07.01.2015 um 00:20 schrieb Aditya Kali:
Quoted 8 lines
I understand your point. But it will add some complexity to the code.
Before trying to make it work for non-unified hierarchy cases, I would like to get a clearer idea.
What do you expect to be mounted when you run:
container:/ # mount -t cgroup none/sys/fs/cgroup/
from inside the container?Quoted 5 lines
Note that cgroup-namespace wont be able to change the way cgroups are mounted .. i.e., if say cpu and cpuacct subsystems are mounted together at a single mount-point, then we cannot mount them any other way (inside a container or outside). This restriction exists today and cgroup-namespaces won't change that.
I wondered why cgroup namespaces won't change that and looked at your patches in more detail.
What you propose as cgroup namespace is much more a cgroupchroot()than a namespace.
As you pass relative paths into the namespace you depend on the mount structure of the host side.
Hence, the abstraction between namespaces happens on the mount paths of the initial cgroupfs. But we really want a new cgroupfs instance within a container and not just a cut out of the initial cgroupfs mount.Quoted 3 lines
I fear you approach is over simplified and won't work for all cases. It may work for your specific use case at Google but we really want something generic. Eric, what do you think?
Quoted 6 lines
I think I probably need to go back upthread and read the patches.
I think it is a reasonable practical requirement that a widely used long term supported distribution like RHEL 7 needs to be able to run in a linux container bizarre init system and all. And that we the abstractions should be that that we should be able to migrate such a beast.
Userspace should be able to deal with however cgroups are mounted for it. The only case I've heard of where it really made a meaningful difference was google's advanced grid usage. In fact, the whole justification of the unified cgroup stuff was that it was claimed (and argued against by google) that that sufficed for any users.
Now yes, until now userspace could cache its info on how cgroups were mounted and assume that wouldn't change (because the kernel wouldn't let it), and migration will break that. But if the cgroup roadmap is to obsolete anything but unified hierarchy, then this was going to happen regardless of what the cgroupns patchset did.
I agree with Aditya. So long as the proclaimed direction of cgroups is to only support unified cgroup hierarchy, there's no point in having cgroupns do anything more than the chrooting.
Quoted 11 lines
There are a couple of issues in play and I think we need actual testing rather than reports that something shouldn't work before we reject a set
of patches. Aditya in one of his replies to me has reported a
configuration that he expects will work. So I think that configuration needs to be tested.cgroups is a weird beast and the problems tend not to lie where a person would first expect.
I suspect no one strongly cares if the cgroup hierarchy is unified or not.
Well, google does. There are cases that were either much more complicated or impossible to represent with unified hierarchy. But complicating cgroupns to support something which Tejun has said is explicitly not going to be supported in the future would be ill-advised.
Quoted 2 lines
By unified hierarchy I mean that every mount of cgroupfs has the
same directories with the same processes in each directory.
No, my reading of Documentation/cgroups/unified-hierarchy.txt is that unified hierarchy means that all (sane) controllers are co-mounted into one hierarchy.
Quoted 24 lines
I do think people will care which controllers will show up in differ mounts of cgroupfs, and I think that is relevant to process migration.
I am going to segway into scope of what is achievable with a cgroup namespace.
- If there are files in cgroupfs that are not safe to delegate we can not support those files in a container.
Last I looked there were such files and systemd used them.
- Which controllers share hierarchies of processes to track resources is a core cgroup issue and not a cgroup namespace issue.
If we find problems with using a unified hierarchy support we need to go fix cgroups in general not cgroupfs.
Eric
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 31 lines · Eric W. Biederman
Quoted 25 lines · Richard Weinberger
Am 07.01.2015 um 00:20 schrieb Aditya Kali:
Quoted 8 lines
I understand your point. But it will add some complexity to the code.
Before trying to make it work for non-unified hierarchy cases, I would like to get a clearer idea.
What do you expect to be mounted when you run:
container:/ # mount -t cgroup none/sys/fs/cgroup/
from inside the container?Quoted 5 lines
Note that cgroup-namespace wont be able to change the way cgroups are mounted .. i.e., if say cpu and cpuacct subsystems are mounted together at a single mount-point, then we cannot mount them any other way (inside a container or outside). This restriction exists today and cgroup-namespaces won't change that.
I wondered why cgroup namespaces won't change that and looked at your patches in more detail.
What you propose as cgroup namespace is much more a cgroupchroot()than a namespace.
As you pass relative paths into the namespace you depend on the mount structure of the host side.
Hence, the abstraction between namespaces happens on the mount paths of the initial cgroupfs. But we really want a new cgroupfs instance within a container and not just a cut out of the initial cgroupfs mount.Quoted 3 lines
I fear you approach is over simplified and won't work for all cases. It may work for your specific use case at Google but we really want something generic. Eric, what do you think?
Quoted 6 lines
I think I probably need to go back upthread and read the patches.
I think it is a reasonable practical requirement that a widely used long term supported distribution like RHEL 7 needs to be able to run in a linux container bizarre init system and all. And that we the abstractions should be that that we should be able to migrate such a beast.
Userspace should be able to deal with however cgroups are mounted for it. The only case I've heard of where it really made a meaningful difference was google's advanced grid usage. In fact, the whole justification of the unified cgroup stuff was that it was claimed (and argued against by google) that that sufficed for any users.
Now yes, until now userspace could cache its info on how cgroups were mounted and assume that wouldn't change (because the kernel wouldn't let it), and migration will break that. But if the cgroup roadmap is to obsolete anything but unified hierarchy, then this was going to happen regardless of what the cgroupns patchset did.
I agree with Aditya. So long as the proclaimed direction of cgroups is to only support unified cgroup hierarchy, there's no point in having cgroupns do anything more than the chrooting.
Quoted 11 lines
There are a couple of issues in play and I think we need actual testing rather than reports that something shouldn't work before we reject a set
of patches. Aditya in one of his replies to me has reported a
configuration that he expects will work. So I think that configuration needs to be tested.cgroups is a weird beast and the problems tend not to lie where a person would first expect.
I suspect no one strongly cares if the cgroup hierarchy is unified or not.
Well, google does. There are cases that were either much more complicated or impossible to represent with unified hierarchy. But complicating cgroupns to support something which Tejun has said is explicitly not going to be supported in the future would be ill-advised.
Quoted 2 lines
By unified hierarchy I mean that every mount of cgroupfs has the
same directories with the same processes in each directory.
No, my reading of Documentation/cgroups/unified-hierarchy.txt is that unified hierarchy means that all (sane) controllers are co-mounted into one hierarchy.
Quoted 24 lines
I do think people will care which controllers will show up in differ mounts of cgroupfs, and I think that is relevant to process migration.
I am going to segway into scope of what is achievable with a cgroup namespace.
- If there are files in cgroupfs that are not safe to delegate we can not support those files in a container.
Last I looked there were such files and systemd used them.
- Which controllers share hierarchies of processes to track resources is a core cgroup issue and not a cgroup namespace issue.
If we find problems with using a unified hierarchy support we need to go fix cgroups in general not cgroupfs.
Eric
_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 6 lines · Serge E. Hallyn
Quoted 2 lines
By unified hierarchy I mean that every mount of cgroupfs has the
same directories with the same processes in each directory.No, my reading of
Documentation/cgroups/unified-hierarchy.txtis that unified hierarchy means that all (sane) controllers are co-mounted into one hierarchy.
I see what you mean. If it is indeed the case than a mount of cgroupfs using the unified hiearchy and can not specify which controllers are present under that mount that very significant bug and presents a very significant regression in user space flexibility.
I think you can still mount the unified hierarchy and select which controls you want to see. If you can not that is a change significantly past what was agreed to and a regression fix needs to be applied.
With a unified hierarchy and separate controllers per mount many cgroup using applications will continue to work as before without changes, or with minimal changes. That is what was agreed to and what I expect has been actually implemented and it is what needs to be implemented in any case.
I will see about making time to see where things are really at.
Eric
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 6 lines · Serge E. Hallyn
Quoted 2 lines
By unified hierarchy I mean that every mount of cgroupfs has the
same directories with the same processes in each directory.No, my reading of
Documentation/cgroups/unified-hierarchy.txtis that unified hierarchy means that all (sane) controllers are co-mounted into one hierarchy.
I see what you mean. If it is indeed the case than a mount of cgroupfs using the unified hiearchy and can not specify which controllers are present under that mount that very significant bug and presents a very significant regression in user space flexibility.
I think you can still mount the unified hierarchy and select which controls you want to see. If you can not that is a change significantly past what was agreed to and a regression fix needs to be applied.
With a unified hierarchy and separate controllers per mount many cgroup using applications will continue to work as before without changes, or with minimal changes. That is what was agreed to and what I expect has been actually implemented and it is what needs to be implemented in any case.
I will see about making time to see where things are really at.
Eric
Tejun Heo
maintainerRe: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 4 lines · Eric W. Biederman
I see what you mean. If it is indeed the case than a mount of cgroupfs using the unified hiearchy and can not specify which controllers are present under that mount that very significant bug and presents a very significant regression in user space flexibility.
The parent always controls which controllers are made available at the children level. Only if the parent enables a controller, its children, whether they're namespaces or not, can choose to further distribute resources using that controller. It's a straight-forward top-down thing.
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 11 lines · Tejun Heo
Quoted 4 lines · Eric W. Biederman
I see what you mean. If it is indeed the case than a mount of cgroupfs using the unified hiearchy and can not specify which controllers are present under that mount that very significant bug and presents a very significant regression in user space flexibility.
The parent always controls which controllers are made available at the children level. Only if the parent enables a controller, its children, whether they're namespaces or not, can choose to further distribute resources using that controller. It's a straight-forward top-down thing.
Ignoring namespace details for a moment. The following should be possible with a unified hierarchy. If it is not it is a show stopper of a regression.
mount -t tmpfs none /sys/fs/cgroup
(cd /sys/fs/cgroup ; mkdir cpu cpuacct devices memory) mount -t cgroupfs -o cpu /sys/fs/cgroup/cpu mount -t cgroupfs -o cpuacct /sys/fs/cgroup/cpuacct mount -t cgroupfs -o devices /sys/fs/cgroup/devices mount -t cgroupfs -o memory /sys/fs/cgroup/memory
With the expectation that only the control files for the specified controllers show up in those mounts.
That is a unified hierarchy is fine. Requiring that there only be one mount point and that every one use it is not ok and it actively a problem.
It is absolutely required to be able to avoid b0rked controllers, and to my knowledge the only way to do that is to have multiple mounts where
we pick the controller on each mount. Even if there is now a way that
doesn't require multiple mounts to keep b0rked controllers from being enabled multiple mounts still need to work to support the existing userspace programs.
This discussion is happening because Documentation/cgroups/unified-hierarchy.txt implies the configuration I have just described will not work with unified hierachies enabled.
Eric
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 11 lines · Tejun Heo
Quoted 4 lines · Eric W. Biederman
I see what you mean. If it is indeed the case than a mount of cgroupfs using the unified hiearchy and can not specify which controllers are present under that mount that very significant bug and presents a very significant regression in user space flexibility.
The parent always controls which controllers are made available at the children level. Only if the parent enables a controller, its children, whether they're namespaces or not, can choose to further distribute resources using that controller. It's a straight-forward top-down thing.
Ignoring namespace details for a moment. The following should be possible with a unified hierarchy. If it is not it is a show stopper of a regression.
mount -t tmpfs none /sys/fs/cgroup
(cd /sys/fs/cgroup ; mkdir cpu cpuacct devices memory) mount -t cgroupfs -o cpu /sys/fs/cgroup/cpu mount -t cgroupfs -o cpuacct /sys/fs/cgroup/cpuacct mount -t cgroupfs -o devices /sys/fs/cgroup/devices mount -t cgroupfs -o memory /sys/fs/cgroup/memory
With the expectation that only the control files for the specified controllers show up in those mounts.
That is a unified hierarchy is fine. Requiring that there only be one mount point and that every one use it is not ok and it actively a problem.
It is absolutely required to be able to avoid b0rked controllers, and to my knowledge the only way to do that is to have multiple mounts where
we pick the controller on each mount. Even if there is now a way that
doesn't require multiple mounts to keep b0rked controllers from being enabled multiple mounts still need to work to support the existing userspace programs.
This discussion is happening because Documentation/cgroups/unified-hierarchy.txt implies the configuration I have just described will not work with unified hierachies enabled.
Eric
Tejun Heo
maintainerRe: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 3 lines · Eric W. Biederman
Ignoring namespace details for a moment. The following should be possible with a unified hierarchy. If it is not it is a show stopper of a regression.
The -o SUBSYS option doesn't exist. Jesus, at least get yourself familiar with the basics before claiming random stuff.
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 7 lines · Tejun Heo
Quoted 3 lines · Eric W. Biederman
Ignoring namespace details for a moment. The following should be possible with a unified hierarchy. If it is not it is a show stopper of a regression.
The -o SUBSYS option doesn't exist. Jesus, at least get yourself familiar with the basics before claiming random stuff.
Not random and I am familiar thank you very much.
I may have mistyped the manual command line configuration for specifying which controllers appear on a mount point does not alter my point.
The old options to enable selecting controllers need to continue and need to continue to work with a unified hierarchy.
Anything else is a gratuitious regression.
Eric
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 7 lines · Tejun Heo
Quoted 3 lines · Eric W. Biederman
Ignoring namespace details for a moment. The following should be possible with a unified hierarchy. If it is not it is a show stopper of a regression.
The -o SUBSYS option doesn't exist. Jesus, at least get yourself familiar with the basics before claiming random stuff.
Not random and I am familiar thank you very much.
I may have mistyped the manual command line configuration for specifying which controllers appear on a mount point does not alter my point.
The old options to enable selecting controllers need to continue and need to continue to work with a unified hierarchy.
Anything else is a gratuitious regression.
Eric
Tejun Heo
maintainerRe: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 2 lines · Eric W. Biederman
I may have mistyped the manual command line configuration for specifying which controllers appear on a mount point does not alter my point.
Hmmm? You were talking about the old hierarchies?
Quoted 4 lines
The old options to enable selecting controllers need to continue and need to continue to work with a unified hierarchy.
Anything else is a gratuitious regression.
I have no idea what you're on about. If the outer system uses unified hierarchy, the inner system should use that too. If the outer system doesn't use unified hierarchy, namespace support has never existed, and even if it did, the inside could never pick and choose controllers independent from the outside. If the outside is co-mounting cpu and cpuacct, the inside is either also doing that or not mounting either.
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 9 lines · ebiederm-aS9lmoZGLiVWk0Htik3J/[email protected] (Eric W. Biederman) writes:
Quoted 7 lines · Tejun Heo
Quoted 3 lines · Eric W. Biederman
Ignoring namespace details for a moment. The following should be possible with a unified hierarchy. If it is not it is a show stopper of a regression.
The -o SUBSYS option doesn't exist. Jesus, at least get yourself familiar with the basics before claiming random stuff.
Oh let's see I got that command line option out of /proc/mounts and yes it works. Perhaps it doesn't if I invoke unified hiearchies but the option does in fact exist and work.
Now I really do need to test report regressions, and send probably send regression fixes. If I understand your strange ranting I think you just told me that option that -o SUBSYS does work with unified hierarchies.
Tejun. I asked you specifically about this case 2 years ago at plumbers and you personally told me this would continue to work. I am going to hold you to that.
Fixing bugs is one thing. Gratuitious regressions that make supporting existing user space applications insane is another.
Eric
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 9 lines · ebiederm-aS9lmoZGLiVWk0Htik3J/[email protected] (Eric W. Biederman) writes:
Quoted 7 lines · Tejun Heo
Quoted 3 lines · Eric W. Biederman
Ignoring namespace details for a moment. The following should be possible with a unified hierarchy. If it is not it is a show stopper of a regression.
The -o SUBSYS option doesn't exist. Jesus, at least get yourself familiar with the basics before claiming random stuff.
Oh let's see I got that command line option out of /proc/mounts and yes it works. Perhaps it doesn't if I invoke unified hiearchies but the option does in fact exist and work.
Now I really do need to test report regressions, and send probably send regression fixes. If I understand your strange ranting I think you just told me that option that -o SUBSYS does work with unified hierarchies.
Tejun. I asked you specifically about this case 2 years ago at plumbers and you personally told me this would continue to work. I am going to hold you to that.
Fixing bugs is one thing. Gratuitious regressions that make supporting existing user space applications insane is another.
Eric
Tejun Heo
maintainerRe: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 6 lines · Eric W. Biederman
Quoted 2 lines
Quoted 2 lines
The -o SUBSYS option doesn't exist. Jesus, at least get yourself familiar with the basics before claiming random stuff.
Oh let's see I got that command line option out of
/proc/mountsand yes it works. Perhaps it doesn't if I invoke unified hiearchies but the option does in fact exist and work.
I meant the -o SUBSYS doesn't exist for unified hierarchy.
Quoted 3 lines
Now I really do need to test report regressions, and send probably send regression fixes. If I understand your strange ranting I think you just told me that option that -o SUBSYS does work with unified hierarchies.
What? Why would -O SUBSYS exist for unified hierarchy? It's unified for all controllers.
Quoted 3 lines
Tejun. I asked you specifically about this case 2 years ago at plumbers and you personally told me this would continue to work. I am going to hold you to that.
I have no idea what you're talking about in *THIS* thread. I'm fully aware of what was discussed *THEN*.
Quoted 2 lines
Fixing bugs is one thing. Gratuitious regressions that make supporting existing user space applications insane is another.
Can you explain what problem you're actually trying to talk about without spouting random claims about regressions?
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 21 lines · Tejun Heo
Quoted 6 lines · Eric W. Biederman
Quoted 2 lines
Quoted 2 lines
The -o SUBSYS option doesn't exist. Jesus, at least get yourself familiar with the basics before claiming random stuff.
Oh let's see I got that command line option out of
/proc/mountsand yes it works. Perhaps it doesn't if I invoke unified hiearchies but the option does in fact exist and work.I meant the -o SUBSYS doesn't exist for unified hierarchy.
Quoted 3 lines
Now I really do need to test report regressions, and send probably send regression fixes. If I understand your strange ranting I think you just told me that option that -o SUBSYS does work with unified hierarchies.
What? Why would -O SUBSYS exist for unified hierarchy? It's unified for all controllers.
Quoted 3 lines
Tejun. I asked you specifically about this case 2 years ago at plumbers and you personally told me this would continue to work. I am going to hold you to that.
Quoted 8 lines
I have no idea what you're talking about in *THIS* thread. I'm fully aware of what was discussed *THEN*.
Quoted 2 lines
Fixing bugs is one thing. Gratuitious regressions that make supporting existing user space applications insane is another.
Can you explain what problem you're actually trying to talk about without spouting random claims about regressions?
A few weeks ago, in order to test the cgroup namespace patchset with lxc, I went through the motions of getting lxc to work with unified hierarchy. A few of the things I had to change:
1. Hierarchy_num in /proc/cgroups and /proc/self/cgroup start at 0. Used to start with 1. I expect many userspace parsers to be broken by this.
2. After creating every non-leaf cgroup, we must fill in the cgroup.subtree_cgroups file. This is extra work which userspace doesn't have to do right now.
3. Let's say we want to create a freezer cgroup /foo/bar for some set of tasks, which they will administer. In fact let's assume we are going to use cgroup namespaces. We have to put the tasks into /foo/bar, unshare the cgroup ns, then create /foo/bar/leaf, move the tasks into /foo/bar/leaf, and then write 'freezer' into /foo/bar. (If we're not using cgroup namespaces, then we have to do a similar thing to let the tasks administer /foo/bar while placing them under /foo/bar/leaf). The oddness I'm pointing to is where the tasks have to know that they can create cgroups in "..".
For containers this becomes odd. We tend to group containers by the tasks in and under a cgroup. We now will have to assume a convention where we know to check for tasks in and under "..", since by definition pid 1's cgroup (in a container) cannot have children.
4. The per-cgroup "tasks" file not existing seems odd, although certainly unexpected by much current software.
So, if the unified hierarchy is going to not cause undue pain, existing software really needs to start working now to use it. It's going to be a sizeable task for lxc.
-serge
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 21 lines · Tejun Heo
Quoted 6 lines · Eric W. Biederman
Quoted 2 lines
Quoted 2 lines
The -o SUBSYS option doesn't exist. Jesus, at least get yourself familiar with the basics before claiming random stuff.
Oh let's see I got that command line option out of
/proc/mountsand yes it works. Perhaps it doesn't if I invoke unified hiearchies but the option does in fact exist and work.I meant the -o SUBSYS doesn't exist for unified hierarchy.
Quoted 3 lines
Now I really do need to test report regressions, and send probably send regression fixes. If I understand your strange ranting I think you just told me that option that -o SUBSYS does work with unified hierarchies.
What? Why would -O SUBSYS exist for unified hierarchy? It's unified for all controllers.
Quoted 3 lines
Tejun. I asked you specifically about this case 2 years ago at plumbers and you personally told me this would continue to work. I am going to hold you to that.
Quoted 8 lines
I have no idea what you're talking about in *THIS* thread. I'm fully aware of what was discussed *THEN*.
Quoted 2 lines
Fixing bugs is one thing. Gratuitious regressions that make supporting existing user space applications insane is another.
Can you explain what problem you're actually trying to talk about without spouting random claims about regressions?
A few weeks ago, in order to test the cgroup namespace patchset with lxc, I went through the motions of getting lxc to work with unified hierarchy. A few of the things I had to change:
1. Hierarchy_num in /proc/cgroups and /proc/self/cgroup start at 0. Used to start with 1. I expect many userspace parsers to be broken by this.
2. After creating every non-leaf cgroup, we must fill in the cgroup.subtree_cgroups file. This is extra work which userspace doesn't have to do right now.
3. Let's say we want to create a freezer cgroup /foo/bar for some set of tasks, which they will administer. In fact let's assume we are going to use cgroup namespaces. We have to put the tasks into /foo/bar, unshare the cgroup ns, then create /foo/bar/leaf, move the tasks into /foo/bar/leaf, and then write 'freezer' into /foo/bar. (If we're not using cgroup namespaces, then we have to do a similar thing to let the tasks administer /foo/bar while placing them under /foo/bar/leaf). The oddness I'm pointing to is where the tasks have to know that they can create cgroups in "..".
For containers this becomes odd. We tend to group containers by the tasks in and under a cgroup. We now will have to assume a convention where we know to check for tasks in and under "..", since by definition pid 1's cgroup (in a container) cannot have children.
4. The per-cgroup "tasks" file not existing seems odd, although certainly unexpected by much current software.
So, if the unified hierarchy is going to not cause undue pain, existing software really needs to start working now to use it. It's going to be a sizeable task for lxc.
-serge
Tejun Heo
maintainerRe: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 2 lines · Serge E. Hallyn
1.
Hierarchy_numin/proc/cgroupsand/proc/self/cgroupstart at 0. Used to start with 1. I expect many userspace parsers to be broken by this.
This is intentional. The unified hierarchy will always have the hierarchy number zero. Userland needs to be updated anyway and the unified hierarchy won't show up unless explicitly enabled.
Quoted 3 lines
2. After creating every non-leaf cgroup, we must fill in the cgroup.subtree_cgroups file. This is extra work which userspace doesn't have to do right now.
Again, by design. This is how organization and control are separated and the differing levels of granularity is achieved.
Quoted 1 line
3. Let's say we want to create a freezer cgroup /foo/bar for some set of
There shouldn't be a "freezer" cgroup. The processes are categorized according to their logical structure and controllers are applied to the hierarchy as necessary.
Quoted 8 lines
tasks, which they will administer. In fact let's assume we are going to use cgroup namespaces. We have to put the tasks into /foo/bar, unshare the cgroup ns, then create /foo/bar/leaf, move the tasks into /foo/bar/leaf, and then write 'freezer' into /foo/bar. (If we're not using cgroup namespaces, then we have to do a similar thing to let the tasks administer /foo/bar while placing them under /foo/bar/leaf). The oddness I'm pointing to is where the tasks have to know that they can create cgroups in "..".
Quoted 4 lines
For containers this becomes odd. We tend to group containers by the tasks in and under a cgroup. We now will have to assume a convention where we know to check for tasks in and under "..", since by definition pid 1's cgroup (in a container) cannot have children.
The semantics is that the parent enables distribution of its given type of resource by enabling the controller in its subtree_control. This scoping isn't necessary for freezer and I'm debating whether to enable controllers which don't need granularity control to be enabled unconditionally. Right now, I'm leaning against it mostly for consistency.
Quoted 2 lines
4. The per-cgroup "tasks" file not existing seems odd, although certainly unexpected by much current software.
And, yes, everything is per-process for reasons described in unified-hierarchy.txt.
Quoted 3 lines
So, if the unified hierarchy is going to not cause undue pain, existing software really needs to start working now to use it. It's going to be a sizeable task for lxc.
Yes, this isn't gonna be a trivial conversion. The usage model changes and so will a lot of controller knobs and behaviors.
Thanks.
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 12 lines · Tejun Heo
Quoted 2 lines · Serge E. Hallyn
1.
Hierarchy_numin/proc/cgroupsand/proc/self/cgroupstart at 0. Used to start with 1. I expect many userspace parsers to be broken by this.This is intentional. The unified hierarchy will always have the hierarchy number zero. Userland needs to be updated anyway and the unified hierarchy won't show up unless explicitly enabled.
Quoted 3 lines
2. After creating every non-leaf cgroup, we must fill in the cgroup.subtree_cgroups file. This is extra work which userspace doesn't have to do right now.
Quoted 8 lines
Again, by design. This is how organization and control are separated and the differing levels of granularity is achieved.
Quoted 1 line
3. Let's say we want to create a freezer cgroup /foo/bar for some set of
There shouldn't be a "freezer" cgroup. The processes are categorized according to their logical structure and controllers are applied to the hierarchy as necessary.
But there can well be cgroups for which only freezer is enabled. If I'm wrong about that, then I am suffering a fundamental misunderstanding.
Quoted 13 lines
Quoted 8 lines
tasks, which they will administer. In fact let's assume we are going to use cgroup namespaces. We have to put the tasks into /foo/bar, unshare the cgroup ns, then create /foo/bar/leaf, move the tasks into /foo/bar/leaf, and then write 'freezer' into /foo/bar. (If we're not using cgroup namespaces, then we have to do a similar thing to let the tasks administer /foo/bar while placing them under /foo/bar/leaf). The oddness I'm pointing to is where the tasks have to know that they can create cgroups in "..".
Quoted 4 lines
For containers this becomes odd. We tend to group containers by the tasks in and under a cgroup. We now will have to assume a convention where we know to check for tasks in and under "..", since by definition pid 1's cgroup (in a container) cannot have children.
Quoted 6 lines
The semantics is that the parent enables distribution of its given type of resource by enabling the controller in its
subtree_control. This scoping isn't necessary for freezer and I'm debating whether to enable controllers which don't need granularity control to be enabled unconditionally. Right now, I'm leaning against it mostly for consistency.
Yeah, IIUC (i.e. freezer would always be enabled?) that would be even-more-confusing.
Quoted 17 lines
Quoted 2 lines
4. The per-cgroup "tasks" file not existing seems odd, although certainly unexpected by much current software.
And, yes, everything is per-process for reasons described in unified-hierarchy.txt.
Quoted 3 lines
So, if the unified hierarchy is going to not cause undue pain, existing software really needs to start working now to use it. It's going to be a sizeable task for lxc.
Yes, this isn't gonna be a trivial conversion. The usage model changes and so will a lot of controller knobs and behaviors.
Thanks.
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 12 lines · Tejun Heo
Quoted 2 lines · Serge E. Hallyn
1.
Hierarchy_numin/proc/cgroupsand/proc/self/cgroupstart at 0. Used to start with 1. I expect many userspace parsers to be broken by this.This is intentional. The unified hierarchy will always have the hierarchy number zero. Userland needs to be updated anyway and the unified hierarchy won't show up unless explicitly enabled.
Quoted 3 lines
2. After creating every non-leaf cgroup, we must fill in the cgroup.subtree_cgroups file. This is extra work which userspace doesn't have to do right now.
Quoted 8 lines
Again, by design. This is how organization and control are separated and the differing levels of granularity is achieved.
Quoted 1 line
3. Let's say we want to create a freezer cgroup /foo/bar for some set of
There shouldn't be a "freezer" cgroup. The processes are categorized according to their logical structure and controllers are applied to the hierarchy as necessary.
But there can well be cgroups for which only freezer is enabled. If I'm wrong about that, then I am suffering a fundamental misunderstanding.
Quoted 13 lines
Quoted 8 lines
tasks, which they will administer. In fact let's assume we are going to use cgroup namespaces. We have to put the tasks into /foo/bar, unshare the cgroup ns, then create /foo/bar/leaf, move the tasks into /foo/bar/leaf, and then write 'freezer' into /foo/bar. (If we're not using cgroup namespaces, then we have to do a similar thing to let the tasks administer /foo/bar while placing them under /foo/bar/leaf). The oddness I'm pointing to is where the tasks have to know that they can create cgroups in "..".
Quoted 4 lines
For containers this becomes odd. We tend to group containers by the tasks in and under a cgroup. We now will have to assume a convention where we know to check for tasks in and under "..", since by definition pid 1's cgroup (in a container) cannot have children.
Quoted 6 lines
The semantics is that the parent enables distribution of its given type of resource by enabling the controller in its
subtree_control. This scoping isn't necessary for freezer and I'm debating whether to enable controllers which don't need granularity control to be enabled unconditionally. Right now, I'm leaning against it mostly for consistency.
Yeah, IIUC (i.e. freezer would always be enabled?) that would be even-more-confusing.
Quoted 17 lines
Quoted 2 lines
4. The per-cgroup "tasks" file not existing seems odd, although certainly unexpected by much current software.
And, yes, everything is per-process for reasons described in unified-hierarchy.txt.
Quoted 3 lines
So, if the unified hierarchy is going to not cause undue pain, existing software really needs to start working now to use it. It's going to be a sizeable task for lxc.
Yes, this isn't gonna be a trivial conversion. The usage model changes and so will a lot of controller knobs and behaviors.
Thanks.
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveA slightly off topic comment, for where this thread has gone but relevant if we are talking about cgroup namespaces.
If don't implement compatibility with existing userspace, they get a nack. A backwards-incompatible change should figure out how to remove the need for any namespaces.
Because that is what namespaces are about backwards compatibility.
Eric
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveA slightly off topic comment, for where this thread has gone but relevant if we are talking about cgroup namespaces.
If don't implement compatibility with existing userspace, they get a nack. A backwards-incompatible change should figure out how to remove the need for any namespaces.
Because that is what namespaces are about backwards compatibility.
Eric
Tejun Heo
maintainerRe: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveHello,
Quoted 6 lines · Serge E. Hallyn
Quoted 3 lines
There shouldn't be a "freezer" cgroup. The processes are categorized according to their logical structure and controllers are applied to the hierarchy as necessary.
But there can well be cgroups for which only freezer is enabled. If I'm wrong about that, then I am suffering a fundamental misunderstanding.
Ah, sure, I was mostly arguing semantics. It's just weird to call it "freezer" cgroup.
Quoted 9 lines
Quoted 6 lines
The semantics is that the parent enables distribution of its given type of resource by enabling the controller in its
subtree_control. This scoping isn't necessary for freezer and I'm debating whether to enable controllers which don't need granularity control to be enabled unconditionally. Right now, I'm leaning against it mostly for consistency.Yeah, IIUC (i.e. freezer would always be enabled?) that would be even-more-confusing.
Right, freezer is kinda weird tho. Its feature can almost be considered a utility feature of cgroups core rather than a separate controller. That said, it's most likely that it'll remain in its current form although how it blocks tasks should definitely be reimplemented.
Thanks.
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveHello,
Quoted 6 lines · Serge E. Hallyn
Quoted 3 lines
There shouldn't be a "freezer" cgroup. The processes are categorized according to their logical structure and controllers are applied to the hierarchy as necessary.
But there can well be cgroups for which only freezer is enabled. If I'm wrong about that, then I am suffering a fundamental misunderstanding.
Ah, sure, I was mostly arguing semantics. It's just weird to call it "freezer" cgroup.
Quoted 9 lines
Quoted 6 lines
The semantics is that the parent enables distribution of its given type of resource by enabling the controller in its
subtree_control. This scoping isn't necessary for freezer and I'm debating whether to enable controllers which don't need granularity control to be enabled unconditionally. Right now, I'm leaning against it mostly for consistency.Yeah, IIUC (i.e. freezer would always be enabled?) that would be even-more-confusing.
Right, freezer is kinda weird tho. Its feature can almost be considered a utility feature of cgroups core rather than a separate controller. That said, it's most likely that it'll remain in its current form although how it blocks tasks should definitely be reimplemented.
Thanks.
Signature · 1 line
tejun
Tejun Heo
maintainerRe: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveHey,
Quoted 8 lines · Eric W. Biederman
A slightly off topic comment, for where this thread has gone but relevant if we are talking about cgroup namespaces.
If don't implement compatibility with existing userspace, they get a nack. A backwards-incompatible change should figure out how to remove the need for any namespaces.
Because that is what namespaces are about backwards compatibility.
Are you claiming that namespaces are soley about backwards compatibility? ie. to trick userland into scoping without letting it notice? That's a very restricted view and namespaces do provide further isolation capabilties in addition to what can be achieved otherwise and it is logical to collect simliar funtionalities there.
Thanks.
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveHey,
Quoted 8 lines · Eric W. Biederman
A slightly off topic comment, for where this thread has gone but relevant if we are talking about cgroup namespaces.
If don't implement compatibility with existing userspace, they get a nack. A backwards-incompatible change should figure out how to remove the need for any namespaces.
Because that is what namespaces are about backwards compatibility.
Are you claiming that namespaces are soley about backwards compatibility? ie. to trick userland into scoping without letting it notice? That's a very restricted view and namespaces do provide further isolation capabilties in addition to what can be achieved otherwise and it is logical to collect simliar funtionalities there.
Thanks.
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 10 lines · Tejun Heo
Hey,
Quoted 7 lines · Eric W. Biederman
A slightly off topic comment, for where this thread has gone but relevant if we are talking about cgroup namespaces.
If don't implement compatibility with existing userspace, they get a nack. A backwards-incompatible change should figure out how to remove the need for any namespaces.
Quoted 7 lines
Quoted 1 line
Because that is what namespaces are about backwards compatibility.
Are you claiming that namespaces are soley about backwards compatibility? ie. to trick userland into scoping without letting it notice? That's a very restricted view and namespaces do provide further isolation capabilties in addition to what can be achieved otherwise and it is logical to collect simliar funtionalities there.
In principle a namespace is an additional layer of indirection from names to objects. A namespace does not invent new kinds of objects. A namespace takes things that were previously global and gives them a scope.
In princple after name resolution a namespace should impose no overhead.
In general namespaces are not necessary if your scope of names already has hierarchy. Which means that new interfaces can almost always be designed in such a way that you can support containers without needing to add any special namespace support. Which typically results in more flexible and useful APIs for everyone, with no real code cost.
Further in the cgroup namespace patchset I looked at a while ago, the only reason for having a cgroup namespace was to provide a measure of backwards compatibility with existing userspace. I expect removing the /proc/<pid>/cgroup file and replacing it with something in cgroupfs itself would serve just as well if backwards compatibility is not the objective. Or possibly replacincg /proc/<pid>/cgroup into a magic symlink onto somewhere in the unified cgroupfs itself.
I just don't see any point in doing weird silly namespace things to keep existing userspace working when the existing userspace won't work.
As such if a namespace doesn't implement compatibility with the existing userspace it gets my nack.
Eric
Tejun Heo
maintainerRe: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveHey,
Quoted 5 lines · Eric W. Biederman
In general namespaces are not necessary if your scope of names already has hierarchy. Which means that new interfaces can almost always be designed in such a way that you can support containers without needing to add any special namespace support. Which typically results in more flexible and useful APIs for everyone, with no real code cost.
Sure, and cgroup ns support isn't doing anything weird there. Just bind mounting a subhierarchy is enough for the core features. The ns part is dealing with things which can't easily be tied to such hierarchical scoping like path reported under through proc and even handling that can be achieved by, for example, marking delegation points in cgroup proper and forcing tasks beyond that point to consider that as its origin when determining the path to report.
However, note that something like that is inherently similar to what's being provided by other namespaces. It is true that it can be implemented outside namespace facility proper but that doesn't automatically make that the right choice and it's more likely to be worse - we'd be introducing a different way to perform about the same thing.
So, the argument that adding namespace interface except for backward compatibility doesn't seem to hold water. Like it or not, namespace is serving as a platform for certain type of features and we'd be foolish to not to consider putting a related feature together there and I fail to see a valid technical argument as of yet.
Quoted 7 lines
Further in the cgroup namespace patchset I looked at a while ago, the only reason for having a cgroup namespace was to provide a measure of backwards compatibility with existing userspace. I expect removing the /proc/<pid>/cgroup file and replacing it with something in cgroupfs itself would serve just as well if backwards compatibility is not the objective. Or possibly replacincg /proc/<pid>/cgroup into a magic symlink onto somewhere in the unified cgroupfs itself.
No matter what we do, we'd still need to mark the delegation point somehow; otherwise, there's no way to produce a scoped identifier. This isn't really about backward compatibility but rather the feature to scope a subhierarcy properly.
Quoted 2 lines
I just don't see any point in doing weird silly namespace things to keep existing userspace working when the existing userspace won't work.
If it's too different from existing namespaces, sure, doing something is definitely an option but is it?
Quoted 2 lines
As such if a namespace doesn't implement compatibility with the existing userspace it gets my nack.
Hmmm.... I don't think making the proposed NS support to work across all hierarchies including the traditional multiple ones would be too difficult. That should work then, right?
Thanks.
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveHey,
Quoted 5 lines · Eric W. Biederman
In general namespaces are not necessary if your scope of names already has hierarchy. Which means that new interfaces can almost always be designed in such a way that you can support containers without needing to add any special namespace support. Which typically results in more flexible and useful APIs for everyone, with no real code cost.
Sure, and cgroup ns support isn't doing anything weird there. Just bind mounting a subhierarchy is enough for the core features. The ns part is dealing with things which can't easily be tied to such hierarchical scoping like path reported under through proc and even handling that can be achieved by, for example, marking delegation points in cgroup proper and forcing tasks beyond that point to consider that as its origin when determining the path to report.
However, note that something like that is inherently similar to what's being provided by other namespaces. It is true that it can be implemented outside namespace facility proper but that doesn't automatically make that the right choice and it's more likely to be worse - we'd be introducing a different way to perform about the same thing.
So, the argument that adding namespace interface except for backward compatibility doesn't seem to hold water. Like it or not, namespace is serving as a platform for certain type of features and we'd be foolish to not to consider putting a related feature together there and I fail to see a valid technical argument as of yet.
Quoted 7 lines
Further in the cgroup namespace patchset I looked at a while ago, the only reason for having a cgroup namespace was to provide a measure of backwards compatibility with existing userspace. I expect removing the /proc/<pid>/cgroup file and replacing it with something in cgroupfs itself would serve just as well if backwards compatibility is not the objective. Or possibly replacincg /proc/<pid>/cgroup into a magic symlink onto somewhere in the unified cgroupfs itself.
No matter what we do, we'd still need to mark the delegation point somehow; otherwise, there's no way to produce a scoped identifier. This isn't really about backward compatibility but rather the feature to scope a subhierarcy properly.
Quoted 2 lines
I just don't see any point in doing weird silly namespace things to keep existing userspace working when the existing userspace won't work.
If it's too different from existing namespaces, sure, doing something is definitely an option but is it?
Quoted 2 lines
As such if a namespace doesn't implement compatibility with the existing userspace it gets my nack.
Hmmm.... I don't think making the proposed NS support to work across all hierarchies including the traditional multiple ones would be too difficult. That should work then, right?
Thanks.
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 10 lines · Tejun Heo
Hey,
Quoted 7 lines · Eric W. Biederman
A slightly off topic comment, for where this thread has gone but relevant if we are talking about cgroup namespaces.
If don't implement compatibility with existing userspace, they get a nack. A backwards-incompatible change should figure out how to remove the need for any namespaces.
Quoted 7 lines
Quoted 1 line
Because that is what namespaces are about backwards compatibility.
Are you claiming that namespaces are soley about backwards compatibility? ie. to trick userland into scoping without letting it notice? That's a very restricted view and namespaces do provide further isolation capabilties in addition to what can be achieved otherwise and it is logical to collect simliar funtionalities there.
We absolutely would love to use cgroup namespaces to run older userspace in containers. I don't know that it's actually possible to do both that and use unified hierarchy at the same time though, which is unfortunate. So an Ubuntu 12.04 container will never, afaics, be able to run inside an ubuntu 16.04 host that is using unified hierarchy, without using backported newer versions of lxc (etc) in the container.
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 10 lines · Tejun Heo
Hey,
Quoted 7 lines · Eric W. Biederman
A slightly off topic comment, for where this thread has gone but relevant if we are talking about cgroup namespaces.
If don't implement compatibility with existing userspace, they get a nack. A backwards-incompatible change should figure out how to remove the need for any namespaces.
Quoted 7 lines
Quoted 1 line
Because that is what namespaces are about backwards compatibility.
Are you claiming that namespaces are soley about backwards compatibility? ie. to trick userland into scoping without letting it notice? That's a very restricted view and namespaces do provide further isolation capabilties in addition to what can be achieved otherwise and it is logical to collect simliar funtionalities there.
We absolutely would love to use cgroup namespaces to run older userspace in containers. I don't know that it's actually possible to do both that and use unified hierarchy at the same time though, which is unfortunate. So an Ubuntu 12.04 container will never, afaics, be able to run inside an ubuntu 16.04 host that is using unified hierarchy, without using backported newer versions of lxc (etc) in the container.
Tejun Heo
maintainerRe: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 7 lines · Serge E. Hallyn
We absolutely would love to use cgroup namespaces to run older userspace in containers. I don't know that it's actually possible to do both that and use unified hierarchy at the same time though, which is unfortunate. So an Ubuntu 12.04 container will never, afaics, be able to run inside an ubuntu 16.04 host that is using unified hierarchy, without using backported newer versions of lxc (etc) in the container.
So, the constraint there are the controllers. A controller can't be attached to two hierarchies at the same time for obvious reasons, so regardless of NS, you can't use the same controller on a unified hierarchy *and* a traditional hierarchy. NS doesn't adds or substracts from the situation. If you decide to attach a controller to a traditional hierarchy, that's where it's gonna be available. If you attach it to the unified hierarchy, the same story.
Thanks.
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 7 lines · Serge E. Hallyn
We absolutely would love to use cgroup namespaces to run older userspace in containers. I don't know that it's actually possible to do both that and use unified hierarchy at the same time though, which is unfortunate. So an Ubuntu 12.04 container will never, afaics, be able to run inside an ubuntu 16.04 host that is using unified hierarchy, without using backported newer versions of lxc (etc) in the container.
So, the constraint there are the controllers. A controller can't be attached to two hierarchies at the same time for obvious reasons, so regardless of NS, you can't use the same controller on a unified hierarchy *and* a traditional hierarchy. NS doesn't adds or substracts from the situation. If you decide to attach a controller to a traditional hierarchy, that's where it's gonna be available. If you attach it to the unified hierarchy, the same story.
Thanks.
Signature · 1 line
tejun
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to Tejun HeoQuoted 9 lines · Tejun Heo
Quoted 7 lines · Serge E. Hallyn
We absolutely would love to use cgroup namespaces to run older userspace in containers. I don't know that it's actually possible to do both that and use unified hierarchy at the same time though, which is unfortunate. So an Ubuntu 12.04 container will never, afaics, be able to run inside an ubuntu 16.04 host that is using unified hierarchy, without using backported newer versions of lxc (etc) in the container.
Quoted 7 lines
So, the constraint there are the controllers. A controller can't be attached to two hierarchies at the same time for obvious reasons, so regardless of NS, you can't use the same controller on a unified hierarchy *and* a traditional hierarchy. NS doesn't adds or substracts from the situation. If you decide to attach a controller to a traditional hierarchy, that's where it's gonna be available. If you attach it to the unified hierarchy, the same story.
Right, exactly.
thanks,
-serge
Re: [PATCHv3 8/8] cgroup: Add documentation for cgroup namespaces
In reply to a message not in the archiveQuoted 9 lines · Tejun Heo
Quoted 7 lines · Serge E. Hallyn
We absolutely would love to use cgroup namespaces to run older userspace in containers. I don't know that it's actually possible to do both that and use unified hierarchy at the same time though, which is unfortunate. So an Ubuntu 12.04 container will never, afaics, be able to run inside an ubuntu 16.04 host that is using unified hierarchy, without using backported newer versions of lxc (etc) in the container.
Quoted 7 lines
So, the constraint there are the controllers. A controller can't be attached to two hierarchies at the same time for obvious reasons, so regardless of NS, you can't use the same controller on a unified hierarchy *and* a traditional hierarchy. NS doesn't adds or substracts from the situation. If you decide to attach a controller to a traditional hierarchy, that's where it's gonna be available. If you attach it to the unified hierarchy, the same story.
Right, exactly.
thanks,
-serge