Skip to contentSkip to conversation

containers: improve automatic container naming

RFC PATCH In review Serge E. Hallyn 2 participants 4 messages Jun 1, 2007

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 containers: improve automatic container naming

This compiles and boots, but is not intended for inclusion in -mm (yet), just as an RFC for the naming scheme to fix the bug Andrew pointed out.

Seem ok overall?

thanks,
-serge

Quoted 1 line

From 8e9b972f7482415777e982d3bc9a0d55cbaf862b Mon Sep 17 00:00:00 2001

From: Serge E. Hallyn <[email protected]>
Date: Fri, 1 Jun 2007 15:32:15 -0400
Subject: [PATCH 1/2] containers: improve automatic container naming

The automatic naming of containers created using container_clone() is currently broken (not protected from wraparound) and inconvenient.

Add a per-container counter for use in naming children of the container. Before two unshares in a row by one process, and a third in another, would result in

	/node1/node2
	/node3

The current scheme should result in

	/node1/node1
	/node2

Also, keep a hash table populated with used names, to protect against counter wrap-around.

---
 include/linux/container.h |    8 +++
 kernel/container.c        |  116 +++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 120 insertions(+), 4 deletions(-)
include/linux/container.h +8 -0
index 37c0bdf..61c750d 100644
@@ -75,6 +75,14 @@ struct container {
 	atomic_t count;
 
 	/*
+	 * these are to support automatic naming of automatically
+	 * created containers
+	 */
+	int auto_cnt_set;  /* 1 if thie container is using up a auto_cnt */
+	unsigned long auto_cnt; /* the auto_cnt it's using up */
+	unsigned long next_childcnt; /* next avail cnt for child containers */
+
+	/*
 	 * We link our 'sibling' struct into our parent's 'children'.
 	 * Our children link their 'sibling' into our 'children'.
 	 */
kernel/container.c +112 -4

177 lines not on this page · raw message

Signature · 1 line
1.5.1.1.GIT
#1 lore raw

RFC PATCH 2/2 containers interface to nsproxy subsystem

Again, not compiles and boots, but not sufficiently tested for inclusion.

thanks,
-serge

Quoted 1 line

From 6c03518dbda04bf20a9ddeefb291bf1c63e32ec1 Mon Sep 17 00:00:00 2001

From: Serge E. Hallyn <[email protected]>
Date: Fri, 1 Jun 2007 17:30:16 -0400
Subject: [PATCH 2/2] Container interface to nsproxy subsystem

When a task enters a new namespace via a clone() or unshare(), a new container is created and the task moves into it.

---
 include/linux/container_subsys.h |    6 ++
 include/linux/nsproxy.h          |    7 +++
 init/Kconfig                     |    9 ++++
 kernel/Makefile                  |    1 +
 kernel/container.c               |   15 +++++-
 kernel/ns_container.c            |   96 ++++++++++++++++++++++++++++++++++++++
 kernel/nsproxy.c                 |   16 ++++++
 7 files changed, 148 insertions(+), 2 deletions(-)
 create mode 100644 kernel/ns_container.c
include/linux/container_subsys.h +6 -0
index 8fea7cf..9861751 100644
@@ -24,3 +24,9 @@ SUBSYS(debug)
 #endif
 
 /* */
+
+#ifdef CONFIG_CONTAINER_NS
+SUBSYS(ns)
+#endif
+
+/* */
include/linux/nsproxy.h +7 -0
index 189e0dc..8be975b 100644
@@ -54,4 +54,11 @@ static inline void exit_task_namespaces(struct task_struct *p)
 		put_nsproxy(ns);
 	}
 }
+
+#ifdef CONFIG_CONTAINER_NS
+int ns_container_clone(struct task_struct *tsk);
+#else
+static inline int ns_container_clone(struct task_struct *tsk) { return 0; }
+#endif
+
 #endif
init/Kconfig +9 -0
index 5861ad9..d79c505 100644
@@ -355,6 +355,15 @@ config CONTAINER_CPUACCT
 	  Provides a simple Resource Controller for monitoring the
 	  total CPU consumed by the tasks in a container
 
+config CONTAINER_NS
+        bool "Namespace container subsystem"
+        select CONTAINERS
+        help
+          Provides a simple namespace container subsystem to
+          provide hierarchical naming of sets of namespaces,
+          for instance virtual servers and checkpoint/restart
+          jobs.
+
 config PROC_PID_CPUSET
 	bool "Include legacy /proc/<pid>/cpuset file"
 	depends on CPUSETS
kernel/Makefile +1 -0
index f73b3d3..34f2345 100644
@@ -40,6 +40,7 @@ obj-$(CONFIG_CONTAINERS) += container.o
 obj-$(CONFIG_CONTAINER_DEBUG) += container_debug.o
 obj-$(CONFIG_CPUSETS) += cpuset.o
 obj-$(CONFIG_CONTAINER_CPUACCT) += cpu_acct.o
+obj-$(CONFIG_CONTAINER_NS) += ns_container.o
 obj-$(CONFIG_IKCONFIG) += configs.o
 obj-$(CONFIG_STOP_MACHINE) += stop_machine.o
 obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
kernel/container.c +13 -2
index 2b2f6f2..ac5879f 100644
@@ -2523,14 +2523,25 @@ int container_clone(struct task_struct *tsk, struct container_subsys *subsys)
 	return ret;
 }
 
-/* See if "cont" is a descendant of the current task's container in
- * the appropriate hierarchy */
+/*
+ * See if "cont" is a descendant of the current task's container in
+ * the appropriate hierarchy
+ *
+ * If we are sending in dummytop, then presumably we are creating
+ * the top container in the subsystem.
+ *
+ * Called only by the ns (nsproxy) container.
+ */
 
 int container_is_descendant(const struct container *cont)
 {
 	int ret;
 	struct container *target;
 	int subsys_id;
+
+	if (cont == dummytop)
+		return 1;
+
 	get_first_subsys(cont, NULL, &subsys_id);
 	target = task_container(current, subsys_id);
 	while (cont != target && cont!= cont->top_container) {
kernel/ns_container.c new file +96 -0

96 lines not on this page · raw message

kernel/nsproxy.c +16 -0
index 1bc4b55..afce808 100644
@@ -124,7 +124,14 @@ int copy_namespaces(int flags, struct task_struct *tsk)
 		goto out;
 	}
 
+	err = ns_container_clone(tsk);
+	if (err) {
+		put_nsproxy(new_ns);
+		goto out;
+	}
+
 	tsk->nsproxy = new_ns;
+
 out:
 	put_nsproxy(old_ns);
 	return err;
@@ -177,6 +184,15 @@ int unshare_nsproxy_namespaces(unsigned long unshare_flags,
 	if (IS_ERR(*new_nsp)) {
 		err = PTR_ERR(*new_nsp);
 		put_nsproxy(old_ns);
+		goto out;
+	}
+
+	err = ns_container_clone(current);
+	if (err) {
+		put_nsproxy(*new_nsp);
+		put_nsproxy(old_ns);
 	}
+
+out:
 	return err;
 }
Signature · 1 line
1.5.1.1.GIT
#2 lore raw
In reply to Serge E. Hallyn
Quoted 28 lines · On Fri, 1 Jun 2007 16:48:09 -0500 "Serge E. Hallyn" <[email protected]> wrote:

This compiles and boots, but is not intended for inclusion in -mm (yet), just as an RFC for the naming scheme to fix the bug Andrew pointed out.

Seem ok overall?

thanks,
-serge

Quoted 1 line

From 8e9b972f7482415777e982d3bc9a0d55cbaf862b Mon Sep 17 00:00:00 2001

From: Serge E. Hallyn <[email protected]>
Date: Fri, 1 Jun 2007 15:32:15 -0400
Subject: [PATCH 1/2] containers: improve automatic container naming

The automatic naming of containers created using container_clone() is currently broken (not protected from wraparound) and inconvenient.

Add a per-container counter for use in naming children of the container. Before two unshares in a row by one process, and a third in another, would result in

	/node1/node2
	/node3

The current scheme should result in

	/node1/node1
	/node2
Quoted 7 lines

Also, keep a hash table populated with used names, to protect against counter wrap-around.

...

 include/linux/container.h |    8 +++
 kernel/container.c        |  116 +++++++++++++++++++++++++++++++++++++++++++--

gad, what's all this stuff?

I think an IDR tree would get you what you're after in much less code. Although it means that container IDs would get recycled quickly across a remove+add.

Be aware that there are IDR enhancements in Greg's driver tree (and hence in -mm) which are relevant to this application.

kernel/container.c static int container_rmdir(struct inode *unused_dir, struct dentry *dentry) · line 2013

Quoted 1 line
kernel/container.c +1 -0
+	if (cont->auto_cnt_set) {

Can we please stop using "cnt" and "cont" to refer to containers? Let's use "container", OK?

#3 lore raw
Quoted 34 lines · Andrew Morton
Quoted 31 lines · On Fri, 1 Jun 2007 16:48:09 -0500 "Serge E. Hallyn" <[email protected]> wrote:

This compiles and boots, but is not intended for inclusion in -mm (yet), just as an RFC for the naming scheme to fix the bug Andrew pointed out.

Seem ok overall?

thanks,
-serge

Quoted 1 line

From 8e9b972f7482415777e982d3bc9a0d55cbaf862b Mon Sep 17 00:00:00 2001

From: Serge E. Hallyn <[email protected]>
Date: Fri, 1 Jun 2007 15:32:15 -0400
Subject: [PATCH 1/2] containers: improve automatic container naming

The automatic naming of containers created using container_clone() is currently broken (not protected from wraparound) and inconvenient.

Add a per-container counter for use in naming children of the container. Before two unshares in a row by one process, and a third in another, would result in

	/node1/node2
	/node3

The current scheme should result in

	/node1/node1
	/node2

Also, keep a hash table populated with used names, to protect against counter wrap-around.

Quoted 6 lines
Quoted 4 lines

...

 include/linux/container.h |    8 +++
 kernel/container.c        |  116 +++++++++++++++++++++++++++++++++++++++++++--

gad, what's all this stuff?

The sound of me starting over.

Quoted 1 line

I think an IDR tree would get you what you're after in much less code.

Ok, will look at that. Thanks for the tip!

Quoted 11 lines

Although it means that container IDs would get recycled quickly across a remove+add.

Be aware that there are IDR enhancements in Greg's driver tree (and hence in -mm) which are relevant to this application.

kernel/container.c static int container_rmdir(struct inode *unused_dir, struct dentry *dentry) · line 2013

Quoted 1 line
kernel/container.c +1 -0
+	if (cont->auto_cnt_set) {

Can we please stop using "cnt" and "cont" to refer to containers? Let's use "container", OK?

Ok.

thanks,
-serge