From: Nadia.Derbey-6ktuUTfB/bM@public.gmane.org
To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
nick-dnCCA748QAperShJXdIFYw@public.gmane.org,
Nadia Derbey <Nadia.Derbey-6ktuUTfB/bM@public.gmane.org>
Subject: [PATCH 3/4] - v2 - IPC: use the target ID specified in procfs
Date: Fri, 18 Apr 2008 07:45:02 +0200 [thread overview]
Message-ID: <20080418054719.201912000@bull.net> (raw)
In-Reply-To: 20080418054459.891481000@bull.net
[-- Attachment #1: ipc_use_next_id.patch --]
[-- Type: text/plain, Size: 3381 bytes --]
[PATCH 03/04]
This patch makes use of the target id specified by a previous write into
/proc/self/task/<tid>/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 | 41 +++++++++++++++++++++++++++++++++--------
kernel/nextid.c | 2 +-
3 files changed, 41 insertions(+), 9 deletions(-)
Index: linux-2.6.25-rc8-mm2/include/linux/sysids.h
===================================================================
--- linux-2.6.25-rc8-mm2.orig/include/linux/sysids.h 2008-04-17 16:03:07.000000000 +0200
+++ linux-2.6.25-rc8-mm2/include/linux/sysids.h 2008-04-17 17:05:54.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-mm2/kernel/nextid.c
===================================================================
--- linux-2.6.25-rc8-mm2.orig/kernel/nextid.c 2008-04-17 16:54:30.000000000 +0200
+++ linux-2.6.25-rc8-mm2/kernel/nextid.c 2008-04-17 17:06:43.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-mm2/ipc/util.c
===================================================================
--- linux-2.6.25-rc8-mm2.orig/ipc/util.c 2008-04-17 12:50:37.000000000 +0200
+++ linux-2.6.25-rc8-mm2/ipc/util.c 2008-04-17 17:09:37.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 = IPCMNI;
@@ -267,20 +268,44 @@ 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);
+ current->next_id = NULL;
+ } 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();
--
next prev parent reply other threads:[~2008-04-18 5:45 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20080418054459.891481000@bull.net>
2008-04-18 5:45 ` [PATCH 1/4] - v2 - Provide a new procfs interface to set next id Nadia.Derbey-6ktuUTfB/bM
2008-04-18 5:45 ` [PATCH 2/4] - v2 - Provide a new procfs interface to set next upid nr(s) Nadia.Derbey-6ktuUTfB/bM
2008-04-18 5:45 ` Nadia.Derbey-6ktuUTfB/bM [this message]
2008-04-18 5:45 ` [PATCH 4/4] - v2 - PID: use the target ID specified in procfs Nadia.Derbey-6ktuUTfB/bM
[not found] ` <20080422193612.GA15835@martell.zuzino.mipt.ru>
[not found] ` <20080422193612.GA15835-QDJVlCTZ4KWTKS93B3g+7KFoa47nwP16@public.gmane.org>
2008-04-22 18:56 ` Checkpoint/restart (was Re: [PATCH 0/4] - v2 - Object creation with a specified id) Dave Hansen
[not found] ` <1208890580.17117.14.camel-FpcvD5N4B9G9xGwK5P7XA+TW4wlIGRCZ@public.gmane.org>
2008-04-22 19:51 ` Serge E. Hallyn
2008-04-22 21:01 ` Alexey Dobriyan
[not found] ` <20080422210130.GA15937@martell.zuzino.mipt.ru>
[not found] ` <20080422210130.GA15937-QDJVlCTZ4KWTKS93B3g+7KFoa47nwP16@public.gmane.org>
2008-04-22 22:56 ` Dave Hansen
[not found] ` <1208904967.17117.51.camel@nimitz.home.sr71.net>
[not found] ` <1208904967.17117.51.camel-FpcvD5N4B9G9xGwK5P7XA+TW4wlIGRCZ@public.gmane.org>
2008-04-23 6:40 ` Kirill Korotaev
[not found] ` <480ED9D5.1010906@parallels.com>
[not found] ` <480ED9D5.1010906-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2008-04-23 15:33 ` Dave Hansen
2008-04-24 1:19 ` Oren Laadan
[not found] ` <480FE037.2010302-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2008-07-10 1:58 ` Eric W. Biederman
[not found] ` <m1y74a7b4w.fsf@frodo.ebiederm.org>
[not found] ` <m1y74a7b4w.fsf-B27657KtZYmhTnVgQlOflh2eb7JE58TQ@public.gmane.org>
2008-07-10 17:12 ` Dave Hansen
2008-07-17 23:09 ` Oren Laadan
[not found] ` <1215709949.9398.15.camel@nimitz>
2008-07-10 17:32 ` Serge E. Hallyn
[not found] ` <20080710173246.GA1857@us.ibm.com>
[not found] ` <20080710173246.GA1857-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-07-10 18:55 ` Eric W. Biederman
[not found] ` <m163rd1sd5.fsf-B27657KtZYmhTnVgQlOflh2eb7JE58TQ@public.gmane.org>
2008-07-10 19:06 ` Dave Hansen
2008-07-10 19:21 ` Eric W. Biederman
[not found] ` <m14p6xy27s.fsf@frodo.ebiederm.org>
[not found] ` <m14p6xy27s.fsf-B27657KtZYmhTnVgQlOflh2eb7JE58TQ@public.gmane.org>
2008-07-10 19:47 ` Dave Hansen
[not found] ` <1215719252.9398.53.camel@nimitz>
2008-07-11 0:32 ` Alexey Dobriyan
2008-07-17 23:19 ` Oren Laadan
2008-07-17 23:16 ` Oren Laadan
2008-07-17 23:14 ` Oren Laadan
[not found] ` <1208964798.17117.72.camel@nimitz.home.sr71.net>
[not found] ` <1208964798.17117.72.camel-FpcvD5N4B9G9xGwK5P7XA+TW4wlIGRCZ@public.gmane.org>
2008-04-24 7:00 ` Kirill Korotaev
[not found] ` <48103002.5090806@parallels.com>
[not found] ` <48103002.5090806-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2008-04-24 18:30 ` Dave Hansen
[not found] ` <1209061809.12718.36.camel@nimitz.home.sr71.net>
[not found] ` <1209061809.12718.36.camel-FpcvD5N4B9G9xGwK5P7XA+TW4wlIGRCZ@public.gmane.org>
2008-04-24 23:13 ` Oren Laadan
[not found] ` <20080418054459.891481000-6ktuUTfB/bM@public.gmane.org>
2008-04-18 17:07 ` [PATCH 0/4] - v2 - Object creation with a specified id Dave Hansen
[not found] ` <1208538427.25363.40.camel-FpcvD5N4B9G9xGwK5P7XA+TW4wlIGRCZ@public.gmane.org>
2008-04-21 11:32 ` Nadia Derbey
2008-04-22 19:36 ` Checkpoint/restart (was Re: [PATCH 0/4] - v2 - Object creation with a specified id) Alexey Dobriyan
2008-04-23 14:23 ` [PATCH 0/4] - v2 - Object creation with a specified id Pavel Machek
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=20080418054719.201912000@bull.net \
--to=nadia.derbey-6ktuutfb/bm@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=nick-dnCCA748QAperShJXdIFYw@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