OpenVZ Forum - RDF feed
type: channel
items: [RFC][PATCH 0/4] Object creation with a specified id
items: [RFC][PATCH 2/4] Provide a new procfs interface to set next upid nr(s)
items: [RFC][PATCH 3/4] IPC: use the target ID specified in procfs
items: [RFC][PATCH 4/4] PID: use the target ID specified in procfs
items: Re: [RFC][PATCH 0/4] Object creation with a specified id

[RFC][PATCH 0/4] Object creation with a specified id
type: item
description: Hi, When restarting a process that has been previously checkpointed, that process should keep on using some of its ids (such as its process id, or sysV ipc ids). This patch provides a feature that can help ensuring this saved state reuse: it makes it possible to create an object with a pre-defined id. A first implementation had been proposed 2 months ago. It consisted in changing an object's id after it had been created. Here is a second implementation based on Oren Ladaan's idea: Oren's suggestion was to force an object's id during its creation, rather than 1. create it, 2. change its id. A new file is created in procfs: /proc/self/next_id. When this file is filled with and id value, a structure pointed to by the calling task struct is filled with that id. Then, when an object supporting this feature is created, the id present in that new structure is used, instead of the default one. 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. Today, the ids are specified as long, but having a type string specified in the next_id file makes it possible to cover more types in the future, if needed. The patches are 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()/alloc_pidmap() paths). Any comment and/o…
creator: Nadia Derbey
date: 2008-04-04T14:51:29-00:00

[RFC][PATCH 2/4] Provide a new procfs interface to set next upid nr(s)
type: item
description: [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_pids 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. Signed-off-by: Nadia Derbey <Nadia.Derbey@bull.net> --- include/linux/sysids.h | 27 ++++++++ kernel/nextid.c | 150 ++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 155 insertions(+), 22 deletions(-) Index: linux-2.6.25-rc8-mm1/include/linux/sysids.h =================================================================== --- linux-2.6.25-rc8-mm1.orig/include/linux/sysids.h 2008-04-04 13:53:04.000000000 +0200 +++ linux-2.6.25-rc8-mm1/include/linux/sysids.h 2008-04-04 14:18:04.000000000 +0200 @@ -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(struc…
creator: Nadia Derbey
date: 2008-04-04T14:51:31-00:00

[RFC][PATCH 3/4] IPC: use the target ID specified in procfs
type: item
description: [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. Signed-off-by: Nadia Derbey <Nadia.Derbey@bull.net> --- include/linux/sysids.h | 7 +++++++ ipc/util.c | 40 ++++++++++++++++++++++++++++++++-------- kernel/nextid.c | 2 +- 3 files changed, 40 insertions(+), 9 deletions(-) Index: linux-2.6.25-rc8-mm1/include/linux/sysids.h =================================================================== --- linux-2.6.25-rc8-mm1.orig/include/linux/sysids.h 2008-04-04 14:18:04.000000000 +0200 +++ linux-2.6.25-rc8-mm1/include/linux/sysids.h 2008-04-04 14:37:45.000000000 +0200 @@ -37,9 +37,16 @@ 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 *, size_t); extern int set_nextid(struct task_struct *, char *); extern int reset_nextid(struct task_struct *); +extern void id_blocks_free(struct sys_id *); static inline void exit_nextid(struct task_struct *tsk) { Index: linux-2.6.25-rc8-mm1/kernel/nextid.c =================================================================== --- linux-2.6.25-rc8-mm1.orig/kernel/nextid.c 2008-04-04 14:28:13.000000000 +0200 +++ linux-2.6.25-rc8-mm1/kernel/nextid.c 2008-04-04 14:38:38.000000000 +0200 @@ -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; Index: linux-2.6.25-rc8-mm1/ipc/util.c =================================================================== --- linux-2.6.25-rc8-mm1.orig/ipc/util.c 2008-04-04 13:11:37.000000000 +0200 +++ linux-2.6.25-rc8-mm1/ipc/util.c 2008-04-04 14:41:53.000000000 +0200 @@ -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 …
creator: Nadia Derbey
date: 2008-04-04T14:51:32-00:00

[RFC][PATCH 4/4] PID: use the target ID specified in procfs
type: item
description: [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. Signed-off-by: Nadia Derbey <Nadia.Derbey@bull.net> --- include/linux/pid.h | 2 kernel/fork.c | 3 - kernel/pid.c | 141 +++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 126 insertions(+), 20 deletions(-) Index: linux-2.6.25-rc8-mm1/include/linux/pid.h =================================================================== --- linux-2.6.25-rc8-mm1.orig/include/linux/pid.h 2008-04-04 13:11:37.000000000 +0200 +++ linux-2.6.25-rc8-mm1/include/linux/pid.h 2008-04-04 14:54:09.000000000 +0200 @@ -121,7 +121,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); /* Index: linux-2.6.25-rc8-mm1/kernel/fork.c =================================================================== --- linux-2.6.25-rc8-mm1.orig/kernel/fork.c 2008-04-04 14:00:35.000000000 +0200 +++ linux-2.6.25-rc8-mm1/kernel/fork.c 2008-04-04 14:54:43.000000000 +0200 @@ -1200,8 +1200,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; Index: linux-2.6.25-rc8-mm1/kernel/pid.c =================================================================== --- linux-2.6.25-rc8-mm1.orig/kernel/pid.c 2008-04-04 13:11:39.000000000 +0200 +++ linux-2.6.25-rc8-mm1/kernel/pid.c 2008-04-04 14:59:24.000000000 +0200 @@ -122,6 +122,26 @@ static void free_pidmap(struct upid *upi atomic_inc(&map->nr_free); } +static…
creator: Nadia Derbey
date: 2008-04-04T14:51:33-00:00

Re: [RFC][PATCH 0/4] Object creation with a specified id
type: item
description: On Fri, Apr 04, 2008 at 04:51:29PM +0200, Nadia.Derbey@bull.net wrote: > . 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. How do you handle race conditions, i.e. you specify the ID for the next object to be created, and then some other thread goes and creates an object before your thread creates one? Nick. -- PGP Key ID = 0x418487E7 http://www.nick-andrew.net/ PGP Key fingerprint = B3ED 6894 8E49 1770 C24A 67E3 6266 6EB9 4184 87E7 _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/containers
creator: Nick Andrew
date: 2008-04-15T03:06:23-00:00