Skip to contentSkip to conversation

Object creation with a pre-defined id (v2)

RFC PATCH In review Nadia.Derbey-6ktuUTfB/[email protected] 3 participants 9 messages Mar 28, 2008 – Apr 2, 2008 3 messages not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Object creation with a pre-defined id (v2)

Hi,

Here is a second version of what has been proposed 2 weeks ago to create
an object with a pre-defined id (this feature would be used during the
restart operation) - see thread https://lists.linux-foundation.org/pipermail/containers/2008-March/thread.html#10287

Main changes since last version:
. Pavel's suggestion has been integrated; this makes things more readable:
alloc_pidmap() is unchanged and a alloc_fixed_pidmap() is added for the predefined ids.
. Oren's suggestion has been integrated:
We now have a single file under /proc/self (/proc/self/next_id). When this file is filled, a structure pointed to by the calling task struct is filled with the id(s).
Then, when the object is created, the id(s) present in that structure are used, instead of the default ones.
The syntax is one of:
. echo "LONG XX" > /proc/self/next_id
next object to be created will have an id set to XX
. echo "LONG<n> X0 ... X<n-1>" > /proc/self/next_id
next object to be created will have its ids set to XX0, ... X<n-1> This is particularly useful for processes that may have several ids if they belong to nested namespaces.

The objects covered here are ipc objects and processes.

The patches are still against 2.6.25-rc3-mm1, in the following order:

[PATCH 1/4] adds the procfs facility for next object to be created, this
object being associated to a single id.
[PATCH 2/4] enhances the procfs facility for objects associated to multiple
ids (like processes).
[PATCH 3/4] makes use of the specified id (if any) to allocate the new IPC
object (changes the ipc_addid() path).
[PATCH 4/4] uses the specified id(s) (if any) to set the upid nr(s) for a newly
allocated process (changes the alloc_pid() path).

Any comment and/or suggestions are welcome.

Regards,
Nadia

--

#1 lore raw

RFC PATCH 1/4 Provide a new procfs interface to set next id

[PATCH 01/04]

This patch proposes the procfs facilities needed to feed the id for the next object to be allocated.

if an
echo "LONG XX" > /proc/self/next_id
is issued, next object to be created will have XX as its id.

This applies to objects that need a single id, such as ipc objects.

---
 fs/proc/base.c         |   73 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/sched.h  |    3 ++
 include/linux/sysids.h |   18 ++++++++++++
 kernel/Makefile        |    2 -
 kernel/fork.c          |    2 +
 kernel/nextid.c        |   69 ++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 166 insertions(+), 1 deletion(-)
include/linux/sysids.h new file +18 -0
Index: linux-2.6.25-rc3-mm1/include/linux/sysids.h
===================================================================
@@ -0,0 +1,18 @@
+/*
+ * include/linux/sysids.h
+ *
+ * Definitions to support object creation with predefined id.
+ *
+ */
+
+#ifndef _LINUX_SYSIDS_H
+#define _LINUX_SYSIDS_H
+
+struct sys_id {
+	long id;
+};
+
+extern ssize_t get_nextid(struct task_struct *, char *);
+extern int set_nextid(struct task_struct *, char *);
+
+#endif /* _LINUX_SYSIDS_H */
include/linux/sched.h +3 -0
Index: linux-2.6.25-rc3-mm1/include/linux/sched.h
===================================================================
@@ -87,6 +87,7 @@ struct sched_param {
 #include <linux/task_io_accounting.h>
 #include <linux/kobject.h>
 #include <linux/latencytop.h>
+#include <linux/sysids.h>
 
 #include <asm/processor.h>
 
@@ -1261,6 +1262,8 @@ struct task_struct {
 	int latency_record_count;
 	struct latency_record latency_record[LT_SAVECOUNT];
 #endif
+	/* Id to assign to the next resource to be created */
+	struct sys_id *next_id;
 };
 
 /*
fs/proc/base.c +73 -0

91 lines not on this page · raw message

kernel/Makefile +1 -1
Index: linux-2.6.25-rc3-mm1/kernel/Makefile
===================================================================
@@ -9,7 +9,7 @@ obj-y     = sched.o fork.o exec_domain.o
 	    rcupdate.o extable.o params.o posix-timers.o \
 	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
 	    hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
-	    notifier.o ksysfs.o pm_qos_params.o
+	    notifier.o ksysfs.o pm_qos_params.o nextid.o
 
 obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
 obj-$(CONFIG_STACKTRACE) += stacktrace.o
kernel/nextid.c new file +69 -0

69 lines not on this page · raw message

kernel/fork.c +2 -0
Index: linux-2.6.25-rc3-mm1/kernel/fork.c
===================================================================
@@ -1166,6 +1166,8 @@ static struct task_struct *copy_process(
 	p->blocked_on = NULL; /* not blocked yet */
 #endif
 
+	p->next_id = NULL;
+
 	/* Perform scheduler related setup. Assign this task to a CPU. */
 	sched_fork(p, clone_flags);
 

--

A message that is not in the archive (sent off-list or not yet received): 20080328095546.729576000-6ktuUTfB/[email protected]

#3 lore raw

Re: [RFC][PATCH 1/4] Provide a new procfs interface to set next id

Quoted 197 lines · On Fri, 28 Mar 2008, Nadia.Derbey-6ktuUTfB/[email protected] wrote:

[PATCH 01/04]

This patch proposes the procfs facilities needed to feed the id for the next object to be allocated.

if an
echo "LONG XX" > /proc/self/next_id
is issued, next object to be created will have XX as its id.

This applies to objects that need a single id, such as ipc objects.

---

fs/proc/base.c         |   73 +++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/sched.h  |    3 ++
include/linux/sysids.h |   18 ++++++++++++
kernel/Makefile        |    2 -
kernel/fork.c          |    2 +
kernel/nextid.c        |   69 ++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 166 insertions(+), 1 deletion(-)

Index: linux-2.6.25-rc3-mm1/include/linux/sysids.h
===================================================================

include/linux/sysids.h new file +18 -0
@@ -0,0 +1,18 @@
+/*
+ * include/linux/sysids.h
+ *
+ * Definitions to support object creation with predefined id.
+ *
+ */
+
+#ifndef _LINUX_SYSIDS_H
+#define _LINUX_SYSIDS_H
+
+struct sys_id {
+	long id;
+};
+
+extern ssize_t get_nextid(struct task_struct *, char *);
+extern int set_nextid(struct task_struct *, char *);
+
+#endif /* _LINUX_SYSIDS_H */

Index: linux-2.6.25-rc3-mm1/include/linux/sched.h
===================================================================

include/linux/sched.h +3 -0
@@ -87,6 +87,7 @@ struct sched_param {
 #include <linux/task_io_accounting.h>
 #include <linux/kobject.h>
 #include <linux/latencytop.h>
+#include <linux/sysids.h>
 
 #include <asm/processor.h>
 
@@ -1261,6 +1262,8 @@ struct task_struct {
 	int latency_record_count;
 	struct latency_record latency_record[LT_SAVECOUNT];
 #endif
+	/* Id to assign to the next resource to be created */
+	struct sys_id *next_id;
 };
 
 /*

Index: linux-2.6.25-rc3-mm1/fs/proc/base.c
===================================================================

fs/proc/base.c +73 -0
@@ -1080,6 +1080,77 @@ static const struct file_operations proc
 #endif
 
 
+static ssize_t next_id_read(struct file *file, char __user *buf,
+				size_t count, loff_t *ppos)
+{
+	struct task_struct *task;
+	char *page;
+	ssize_t length;
+
+	task = get_proc_task(file->f_path.dentry->d_inode);
+	if (!task)
+		return -ESRCH;
+
+	if (count > PROC_BLOCK_SIZE)
+		count = PROC_BLOCK_SIZE;
+
+	length = -ENOMEM;
+	page = (char *) __get_free_page(GFP_TEMPORARY);
+	if (!page)
+		goto out;
+
+	length = get_nextid(task, (char *) page);
+	if (length >= 0)
+		length = simple_read_from_buffer(buf, count, ppos,
+						(char *)page, length);
+	free_page((unsigned long) page);
+
+out:
+	put_task_struct(task);
+	return length;
+}
+
+static ssize_t next_id_write(struct file *file, const char __user *buf,
+				size_t count, loff_t *ppos)
+{
+	struct inode *inode = file->f_path.dentry->d_inode;
+	char *page;
+	ssize_t length;
+
+	if (pid_task(proc_pid(inode), PIDTYPE_PID) != current)
+		return -EPERM;
+
+	if (count >= PAGE_SIZE)
+		count = PAGE_SIZE - 1;
+
+	if (*ppos != 0) {
+		/* No partial writes. */
+		return -EINVAL;
+	}
+	page = (char *)__get_free_page(GFP_TEMPORARY);
+	if (!page)
+		return -ENOMEM;
+	length = -EFAULT;
+	if (copy_from_user(page, buf, count))
+		goto out_free_page;
+
+	page[count] = '\0';
+
+	length = set_nextid(current, page);
+	if (!length)
+		length = count;
+
+out_free_page:
+	free_page((unsigned long) page);
+	return length;
+}
+
+static const struct file_operations proc_next_id_operations = {
+	.read		= next_id_read,
+	.write		= next_id_write,
+};
+
+
 #ifdef CONFIG_SCHED_DEBUG
 /*
 * Print out various scheduling related per-task fields:
@@ -2391,6 +2462,7 @@ static const struct pid_entry tgid_base_
 #ifdef CONFIG_TASK_IO_ACCOUNTING
 	INF("io",	S_IRUGO, pid_io_accounting),
 #endif
+	REG("next_id", S_IRUGO|S_IWUSR, next_id),
 };
 
 static int proc_tgid_base_readdir(struct file * filp,
@@ -2716,6 +2788,7 @@ static const struct pid_entry tid_base_s
 #ifdef CONFIG_FAULT_INJECTION
 	REG("make-it-fail", S_IRUGO|S_IWUSR, fault_inject),
 #endif
+	REG("next_id", S_IRUGO|S_IWUSR, next_id),
 };
 
 static int proc_tid_base_readdir(struct file * filp,

Index: linux-2.6.25-rc3-mm1/kernel/Makefile
===================================================================

kernel/Makefile +1 -1
@@ -9,7 +9,7 @@ obj-y     = sched.o fork.o exec_domain.o
 	    rcupdate.o extable.o params.o posix-timers.o \
 	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
 	    hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
-	    notifier.o ksysfs.o pm_qos_params.o
+	    notifier.o ksysfs.o pm_qos_params.o nextid.o
 

obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o obj-$(CONFIG_STACKTRACE) += stacktrace.o
Index: linux-2.6.25-rc3-mm1/kernel/nextid.c
===================================================================

kernel/nextid.c new file +15 -0
@@ -0,0 +1,69 @@
+/*
+ * linux/kernel/nextid.c
+ *
+ *
+ * Provide the get_nextid() / set_nextid() routines
+ * (called from fs/proc/base.c).
+ * They allow to specify the id for the next resource to be allocated,
+ * instead of letting the allocator set it for us.
+ */
+
+#include <linux/sched.h>
+#include <linux/ctype.h>
+
+
+

kernel/nextid.c line 25

Quoted 10 lines
kernel/nextid.c new file +10 -0
+ssize_t get_nextid(struct task_struct *task, char *buffer)
+{
+	struct sys_id *sid;
+
+	sid = task->next_id;
+	if (!sid)
+		return snprintf(buffer, sizeof(buffer), "-1\n");
+
+	return snprintf(buffer, sizeof(buffer), "%ld\n", sid->id);
+}

Since the input format is "LONG <id>", why not have the output format be the same ? This way, if in the future there are other formats (eg CHAR, IPv4 ...). Same comment for the next patch, for LONG<n> format.

(disclaimer: at this point I don't see why one would want to read this file, or usage for other formats...)

Quoted 49 lines
kernel/nextid.c new file +44 -0
+
+static int set_single_id(struct task_struct *task, char *buffer)
+{
+	struct sys_id *sid;
+	long next_id;
+	char *end;
+
+	next_id = simple_strtol(buffer, &end, 0);
+	if (end == buffer || (end && !isspace(*end)))
+		return -EINVAL;
+
+	sid = task->next_id;
+	if (!sid) {
+		sid = kzalloc(sizeof(*sid), GFP_KERNEL);
+		if (!sid)
+			return -ENOMEM;
+		task->next_id = sid;
+	}
+
+	sid->id = next_id;
+
+	return 0;
+}
+
+#define SINGLE_LONG "LONG"
+
+/*
+ * Parses a line written to /proc/self/next_id.
+ * this line has the following format:
+ * LONG id              --> a single id is specified
+ */
+int set_nextid(struct task_struct *task, char *buffer)
+{
+	char *token, *out = buffer;
+
+	token = strsep(&out, " ");
+	if (!token || !out)
+		return -EINVAL;
+
+	if (!strcmp(token, SINGLE_LONG))
+		return set_single_id(task, out);
+	else
+		return -EINVAL;
+}

Index: linux-2.6.25-rc3-mm1/kernel/fork.c
===================================================================

kernel/fork.c static struct task_struct *copy_process( · line 1172

Quoted 7 lines
kernel/fork.c +2 -0
@@ -1166,6 +1166,8 @@ static struct task_struct *copy_process(
 	p->blocked_on = NULL; /* not blocked yet */
 #endif
 
+	p->next_id = NULL;
+
 	/* Perform scheduler related setup. Assign this task to a CPU. */
 	sched_fork(p, clone_flags);

Freeing this memory when the task terminates could be helpful, too. Probably execve() is another good candidate to free this, just in case.

Oren.

#4 lore raw

RFC PATCH 2/4 Provide a new procfs interface to set next upid nr(s)

In reply to Nadia.Derbey-6ktuUTfB/[email protected]

[PATCH 02/04]

This patch proposes the procfs facilities needed to feed the id(s) for the next task to be forked.

say n is the number of pids to be provided through procfs:

if an
echo "LONG<n> X0 X1 ... X<n-1>" > /proc/self/next_id
is issued, the next task to be forked will have its upid nrs set as follows (say it is forked in a pid ns of level L):

level upid nr
L ----------> X0
..
L - i ------> Xi
..
L - n + 1 --> X<n-1>

Then, for levels L-n down to level 0, the pids will be left to the kernel choice.

---
 include/linux/sysids.h |   27 ++++++++-
 kernel/nextid.c        |  146 ++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 153 insertions(+), 20 deletions(-)
include/linux/sysids.h +26 -1
Index: linux-2.6.25-rc3-mm1/include/linux/sysids.h
===================================================================
@@ -8,8 +8,33 @@
 #ifndef _LINUX_SYSIDS_H
 #define _LINUX_SYSIDS_H
 
+
+#define NIDS_SMALL       32
+#define NIDS_PER_BLOCK   ((unsigned int)(PAGE_SIZE / sizeof(long)))
+
+/* access the ids "array" with this macro */
+#define ID_AT(pi, i)	\
+	((pi)->blocks[(i) / NIDS_PER_BLOCK][(i) % NIDS_PER_BLOCK])
+
+
+/*
+ * List of ids for the next object to be created. This presently applies to
+ * next process to be created.
+ * The next process to be created is associated to a set of upid nrs: one for
+ * each pid namespace level that process belongs to.
+ * upid nrs from level 0 up to level <npids - 1> will be automatically
+ * allocated.
+ * upid nr for level nids will be set to blocks[0][0]
+ * upid nr for level <nids + i> will be set to ID_AT(ids, i);
+ *
+ * If a single id is needed, nids is set to 1 and small_block[0] is set to
+ * that id.
+ */
 struct sys_id {
-	long id;
+	int nids;
+	long small_block[NIDS_SMALL];
+	int nblocks;
+	long *blocks[0];
 };
 
 extern ssize_t get_nextid(struct task_struct *, char *);
kernel/nextid.c +127 -19

180 lines not on this page · raw message

--

#5 lore raw

RFC PATCH 3/4 IPC: use the target ID specified in procfs

In reply to Nadia.Derbey-6ktuUTfB/[email protected]

[PATCH 03/04]

This patch makes use of the target id specified by a previous write into /proc/self/next_id as the id to use to allocate the next IPC object.

---
 include/linux/sysids.h |    7 +++++++
 ipc/util.c             |   39 +++++++++++++++++++++++++++++++--------
 kernel/nextid.c        |    2 +-
 3 files changed, 39 insertions(+), 9 deletions(-)
include/linux/sysids.h +7 -0
Index: linux-2.6.25-rc3-mm1/include/linux/sysids.h
===================================================================
@@ -37,7 +37,14 @@ struct sys_id {
 	long *blocks[0];
 };
 
+#define next_ipcid(tsk) ((tsk)->next_id					\
+				? ((tsk)->next_id->nids			\
+					? ID_AT((tsk)->next_id, 0)	\
+					: -1)				\
+				: -1)
+
 extern ssize_t get_nextid(struct task_struct *, char *);
 extern int set_nextid(struct task_struct *, char *);
+extern void id_blocks_free(struct sys_id *);
 
 #endif /* _LINUX_SYSIDS_H */
kernel/nextid.c +1 -1
Index: linux-2.6.25-rc3-mm1/kernel/nextid.c
===================================================================
@@ -49,7 +49,7 @@ out_undo_partial_alloc:
 	return NULL;
 }
 
-static void id_blocks_free(struct sys_id *ids)
+void id_blocks_free(struct sys_id *ids)
 {
 	if (ids == NULL)
 		return;
ipc/util.c +31 -8
Index: linux-2.6.25-rc3-mm1/ipc/util.c
===================================================================
@@ -260,6 +260,7 @@ int ipc_get_maxid(struct ipc_ids *ids)
 int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
 {
 	int id, err;
+	int next_id;
 
 	if (size > IPCMNI)
 		size = IPCMNI;
@@ -267,20 +268,42 @@ int ipc_addid(struct ipc_ids* ids, struc
 	if (ids->in_use >= size)
 		return -ENOSPC;
 
-	err = idr_get_new(&ids->ipcs_idr, new, &id);
-	if (err)
-		return err;
+	next_id = next_ipcid(current);
+	if (next_id >= 0) {
+		/* There is a target id specified, try to use it */
+		int new_lid = next_id % SEQ_MULTIPLIER;
+
+		if (next_id !=
+		    (new_lid + (next_id / SEQ_MULTIPLIER) * SEQ_MULTIPLIER))
+			return -EINVAL;
+
+		err = idr_get_new_above(&ids->ipcs_idr, new, new_lid, &id);
+		if (err)
+			return err;
+		if (id != new_lid) {
+			idr_remove(&ids->ipcs_idr, id);
+			return -EBUSY;
+		}
+
+		new->id = next_id;
+		new->seq = next_id / SEQ_MULTIPLIER;
+		id_blocks_free(current->next_id);
+	} else {
+		err = idr_get_new(&ids->ipcs_idr, new, &id);
+		if (err)
+			return err;
+
+		new->seq = ids->seq++;
+		if (ids->seq > ids->seq_max)
+			ids->seq = 0;
+		new->id = ipc_buildid(id, new->seq);
+	}
 
 	ids->in_use++;
 
 	new->cuid = new->uid = current->euid;
 	new->gid = new->cgid = current->egid;
 
-	new->seq = ids->seq++;
-	if(ids->seq > ids->seq_max)
-		ids->seq = 0;
-
-	new->id = ipc_buildid(id, new->seq);
 	spin_lock_init(&new->lock);
 	new->deleted = 0;
 	rcu_read_lock();

--

#6 lore raw

RFC PATCH 4/4 PID: use the target ID specified in procfs

In reply to Nadia.Derbey-6ktuUTfB/[email protected]

[PATCH 04/04]

This patch makes use of the target ids specified by a previous write to /proc/self/next_id as the ids to use to allocate the next upid nrs. Upper levels upid nrs that are not specified in next_pids file are left to the kernel choice.

---
 include/linux/pid.h |    2 
 kernel/fork.c       |    3 -
 kernel/pid.c        |  141 +++++++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 126 insertions(+), 20 deletions(-)
include/linux/pid.h +1 -1
Index: linux-2.6.25-rc3-mm1/include/linux/pid.h
===================================================================
@@ -119,7 +119,7 @@ extern struct pid *find_get_pid(int nr);
 extern struct pid *find_ge_pid(int nr, struct pid_namespace *);
 int next_pidmap(struct pid_namespace *pid_ns, int last);
 
-extern struct pid *alloc_pid(struct pid_namespace *ns);
+extern struct pid *alloc_pid(struct pid_namespace *ns, int *retval);
 extern void free_pid(struct pid *pid);
 
 /*
kernel/fork.c +1 -2
Index: linux-2.6.25-rc3-mm1/kernel/fork.c
===================================================================
@@ -1199,8 +1199,7 @@ static struct task_struct *copy_process(
 		goto bad_fork_cleanup_io;
 
 	if (pid != &init_struct_pid) {
-		retval = -ENOMEM;
-		pid = alloc_pid(task_active_pid_ns(p));
+		pid = alloc_pid(task_active_pid_ns(p), &retval);
 		if (!pid)
 			goto bad_fork_cleanup_io;
 
kernel/pid.c +124 -17

177 lines not on this page · raw message

--

A message that is not in the archive (sent off-list or not yet received): 20080328095309.117134000-6ktuUTfB/[email protected]

#8 lore raw
Quoted 16 lines · On Fri, 28 Mar 2008, Nadia.Derbey-6ktuUTfB/[email protected] wrote:

Hi,

Here is a second version of what has been proposed 2 weeks ago to create
an object with a pre-defined id (this feature would be used during the
restart operation) - see thread https://lists.linux-foundation.org/pipermail/containers/2008-March/thread.html#10287

Main changes since last version:
. Pavel's suggestion has been integrated; this makes things more readable:
alloc_pidmap() is unchanged and a alloc_fixed_pidmap() is added for the predefined ids.
. Oren's suggestion has been integrated:
We now have a single file under /proc/self (/proc/self/next_id). When this file is filled, a structure pointed to by the calling task struct is filled with the id(s).
Then, when the object is created, the id(s) present in that structure are

Quoted 8 lines

used, instead of the default ones.
The syntax is one of:
. echo "LONG XX" > /proc/self/next_id
next object to be created will have an id set to XX
. echo "LONG<n> X0 ... X<n-1>" > /proc/self/next_id
next object to be created will have its ids set to XX0, ... X<n-1> This is particularly useful for processes that may have several ids if they belong to nested namespaces.

I suggest that there be a way for the process to reset its task->next_id discarding previous settings, e.g. to recover from an error condition and prevent subsuquent syscalls from using the task->next_id unintentionally. Something like "echo RESET > /proc/self/next_id" (or s/RESET/0/ ... etc).

Quoted 20 lines

The objects covered here are ipc objects and processes.

The patches are still against 2.6.25-rc3-mm1, in the following order:

[PATCH 1/4] adds the procfs facility for next object to be created, this
object being associated to a single id.
[PATCH 2/4] enhances the procfs facility for objects associated to multiple
ids (like processes).
[PATCH 3/4] makes use of the specified id (if any) to allocate the new IPC
object (changes the ipc_addid() path).
[PATCH 4/4] uses the specified id(s) (if any) to set the upid nr(s) for a newly
allocated process (changes the alloc_pid() path).

Any comment and/or suggestions are welcome.

Regards,
Nadia

--

A message that is not in the archive (sent off-list or not yet received): Pine.LNX.4.64.0803282001280.1670-qCy6tK2KoXYxx4h7iLwZUsysmGwsrwg7TsgBfEgxSsDMrJhsLK8IO4dd74u8MsAO@public.gmane.org

#10 lore raw
Quoted 29 lines · Oren Laadan
Quoted 16 lines · On Fri, 28 Mar 2008, Nadia.Derbey-6ktuUTfB/[email protected] wrote:

Hi,

Here is a second version of what has been proposed 2 weeks ago to create
an object with a pre-defined id (this feature would be used during the
restart operation) - see thread https://lists.linux-foundation.org/pipermail/containers/2008-March/thread.html#10287

Main changes since last version:
. Pavel's suggestion has been integrated; this makes things more readable:
alloc_pidmap() is unchanged and a alloc_fixed_pidmap() is added for the predefined ids.
. Oren's suggestion has been integrated:
We now have a single file under /proc/self (/proc/self/next_id). When this file is filled, a structure pointed to by the calling task struct is filled with the id(s).
Then, when the object is created, the id(s) present in that structure are

Quoted 8 lines

used, instead of the default ones.
The syntax is one of:
. echo "LONG XX" > /proc/self/next_id
next object to be created will have an id set to XX
. echo "LONG<n> X0 ... X<n-1>" > /proc/self/next_id
next object to be created will have its ids set to XX0, ... X<n-1> This is particularly useful for processes that may have several ids if they belong to nested namespaces.

Quoted 4 lines

I suggest that there be a way for the process to reset its task->next_id discarding previous settings, e.g. to recover from an error condition and prevent subsuquent syscalls from using the task->next_id unintentionally. Something like "echo RESET > /proc/self/next_id" (or s/RESET/0/ ... etc).

Makes sense, and should be trivial enough.

If there are no objections to this approach on this list, should you be sending this patchset (addressing Oren's comments) on to lkml? Or is it too soon for that?

thanks,
-serge

Quoted 24 lines
Quoted 13 lines

The objects covered here are ipc objects and processes.

The patches are still against 2.6.25-rc3-mm1, in the following order:

[PATCH 1/4] adds the procfs facility for next object to be created, this
object being associated to a single id.
[PATCH 2/4] enhances the procfs facility for objects associated to multiple
ids (like processes).
[PATCH 3/4] makes use of the specified id (if any) to allocate the new IPC
object (changes the ipc_addid() path).
[PATCH 4/4] uses the specified id(s) (if any) to set the upid nr(s) for a newly
allocated process (changes the alloc_pid() path).

Quoted 7 lines

Any comment and/or suggestions are welcome.

Regards,
Nadia

--

_______________________________________________
Containers mailing list Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers

#11 lore raw
In reply to a message not in the archive
Quoted 16 lines · On Fri, 28 Mar 2008, Nadia.Derbey-6ktuUTfB/[email protected] wrote:

Hi,

Here is a second version of what has been proposed 2 weeks ago to create
an object with a pre-defined id (this feature would be used during the
restart operation) - see thread https://lists.linux-foundation.org/pipermail/containers/2008-March/thread.html#10287

Main changes since last version:
. Pavel's suggestion has been integrated; this makes things more readable:
alloc_pidmap() is unchanged and a alloc_fixed_pidmap() is added for the predefined ids.
. Oren's suggestion has been integrated:
We now have a single file under /proc/self (/proc/self/next_id). When this file is filled, a structure pointed to by the calling task struct is filled with the id(s).
Then, when the object is created, the id(s) present in that structure are

Quoted 8 lines

used, instead of the default ones.
The syntax is one of:
. echo "LONG XX" > /proc/self/next_id
next object to be created will have an id set to XX
. echo "LONG<n> X0 ... X<n-1>" > /proc/self/next_id
next object to be created will have its ids set to XX0, ... X<n-1> This is particularly useful for processes that may have several ids if they belong to nested namespaces.

I suggest that there be a way for the process to reset its task->next_id discarding previous settings, e.g. to recover from an error condition and prevent subsuquent syscalls from using the task->next_id unintentionally. Something like "echo RESET > /proc/self/next_id" (or s/RESET/0/ ... etc).

Oren.

Quoted 20 lines

The objects covered here are ipc objects and processes.

The patches are still against 2.6.25-rc3-mm1, in the following order:

[PATCH 1/4] adds the procfs facility for next object to be created, this
object being associated to a single id.
[PATCH 2/4] enhances the procfs facility for objects associated to multiple
ids (like processes).
[PATCH 3/4] makes use of the specified id (if any) to allocate the new IPC
object (changes the ipc_addid() path).
[PATCH 4/4] uses the specified id(s) (if any) to set the upid nr(s) for a newly
allocated process (changes the alloc_pid() path).

Any comment and/or suggestions are welcome.

Regards,
Nadia

--