Linux Container Development
 help / color / mirror / Atom feed
From: Nadia.Derbey-6ktuUTfB/bM@public.gmane.org
To: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Cc: Nadia Derbey <Nadia.Derbey-6ktuUTfB/bM@public.gmane.org>,
	xemul-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org
Subject: [RFC][PATCH 3/4] IPC: use the target ID specified in procfs
Date: Fri, 28 Mar 2008 10:53:12 +0100	[thread overview]
Message-ID: <20080328095547.401326000@bull.net> (raw)
In-Reply-To: 20080328095309.117134000@bull.net

[-- Attachment #1: ipc_use_next_id.patch --]
[-- Type: text/plain, Size: 3252 bytes --]

[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-6ktuUTfB/bM@public.gmane.org>

---
 include/linux/sysids.h |    7 +++++++
 ipc/util.c             |   39 +++++++++++++++++++++++++++++++--------
 kernel/nextid.c        |    2 +-
 3 files changed, 39 insertions(+), 9 deletions(-)

Index: linux-2.6.25-rc3-mm1/include/linux/sysids.h
===================================================================
--- linux-2.6.25-rc3-mm1.orig/include/linux/sysids.h	2008-03-28 08:19:49.000000000 +0100
+++ linux-2.6.25-rc3-mm1/include/linux/sysids.h	2008-03-28 08:21:02.000000000 +0100
@@ -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 */
Index: linux-2.6.25-rc3-mm1/kernel/nextid.c
===================================================================
--- linux-2.6.25-rc3-mm1.orig/kernel/nextid.c	2008-03-28 08:20:52.000000000 +0100
+++ linux-2.6.25-rc3-mm1/kernel/nextid.c	2008-03-28 08:21:02.000000000 +0100
@@ -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-rc3-mm1/ipc/util.c
===================================================================
--- linux-2.6.25-rc3-mm1.orig/ipc/util.c	2008-03-28 08:19:49.000000000 +0100
+++ linux-2.6.25-rc3-mm1/ipc/util.c	2008-03-28 08:21:02.000000000 +0100
@@ -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();

--

  parent reply	other threads:[~2008-03-28  9:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-28  9:53 [RFC][PATCH 0/4] Object creation with a pre-defined id (v2) Nadia.Derbey-6ktuUTfB/bM
2008-03-28  9:53 ` [RFC][PATCH 1/4] Provide a new procfs interface to set next id Nadia.Derbey-6ktuUTfB/bM
     [not found]   ` <20080328095546.729576000-6ktuUTfB/bM@public.gmane.org>
2008-03-28 19:12     ` Oren Laadan
2008-03-28  9:53 ` [RFC][PATCH 2/4] Provide a new procfs interface to set next upid nr(s) Nadia.Derbey-6ktuUTfB/bM
2008-03-28  9:53 ` Nadia.Derbey-6ktuUTfB/bM [this message]
2008-03-28  9:53 ` [RFC][PATCH 4/4] PID: use the target ID specified in procfs Nadia.Derbey-6ktuUTfB/bM
     [not found] ` <20080328095309.117134000-6ktuUTfB/bM@public.gmane.org>
2008-03-29  0:09   ` [RFC][PATCH 0/4] Object creation with a pre-defined id (v2) Oren Laadan
     [not found]     ` <Pine.LNX.4.64.0803282001280.1670-qCy6tK2KoXYxx4h7iLwZUsysmGwsrwg7TsgBfEgxSsDMrJhsLK8IO4dd74u8MsAO@public.gmane.org>
2008-04-02 15:56       ` Serge E. Hallyn
2008-03-29  0:13   ` Oren Laadan
     [not found] <20080404145129.637145000@bull.net>
2008-04-04 14:51 ` [RFC][PATCH 3/4] IPC: use the target ID specified in procfs Nadia.Derbey-6ktuUTfB/bM
  -- strict thread matches above, loose matches on Subject: below --
2008-03-10 13:50 [RFC][PATCH 0/4] Object creation with a specified id Nadia.Derbey-6ktuUTfB/bM
2008-03-10 13:50 ` [RFC][PATCH 3/4] IPC: use the target ID specified in procfs Nadia.Derbey-6ktuUTfB/bM

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080328095547.401326000@bull.net \
    --to=nadia.derbey-6ktuutfb/bm@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=xemul-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox