From: Nadia.Derbey@bull.net
To: linux-kernel@vger.kernel.org
Cc: containers@lists.linux-foundation.org, orenl@cs.columbia.edu,
nick@nick-andrew.net, Nadia Derbey <Nadia.Derbey@bull.net>
Subject: [PATCH 1/4] - v2 - Provide a new procfs interface to set next id
Date: Fri, 18 Apr 2008 07:45:00 +0200 [thread overview]
Message-ID: <20080418054718.407122000@bull.net> (raw)
In-Reply-To: 20080418054459.891481000@bull.net
[-- Attachment #1: proc_set_next_id.patch --]
[-- Type: text/plain, Size: 8705 bytes --]
[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/task/<tid>/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.
Signed-off-by: Nadia Derbey <Nadia.Derbey@bull.net>
---
fs/exec.c | 3 +
fs/proc/base.c | 76 +++++++++++++++++++++++++++++++++++++++++++
include/linux/sched.h | 3 +
include/linux/sysids.h | 24 +++++++++++++
kernel/Makefile | 2 -
kernel/exit.c | 4 ++
kernel/fork.c | 2 +
kernel/nextid.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 199 insertions(+), 1 deletion(-)
Index: linux-2.6.25-rc8-mm2/include/linux/sysids.h
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.25-rc8-mm2/include/linux/sysids.h 2008-04-17 13:35:29.000000000 +0200
@@ -0,0 +1,24 @@
+/*
+ * 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 *, size_t);
+extern int set_nextid(struct task_struct *, char *);
+extern int reset_nextid(struct task_struct *);
+
+static inline void exit_nextid(struct task_struct *tsk)
+{
+ reset_nextid(tsk);
+}
+
+#endif /* _LINUX_SYSIDS_H */
Index: linux-2.6.25-rc8-mm2/include/linux/sched.h
===================================================================
--- linux-2.6.25-rc8-mm2.orig/include/linux/sched.h 2008-04-17 12:50:22.000000000 +0200
+++ linux-2.6.25-rc8-mm2/include/linux/sched.h 2008-04-17 13:38:04.000000000 +0200
@@ -88,6 +88,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>
@@ -1280,6 +1281,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-rc8-mm2/fs/proc/base.c
===================================================================
--- linux-2.6.25-rc8-mm2.orig/fs/proc/base.c 2008-04-17 12:50:40.000000000 +0200
+++ linux-2.6.25-rc8-mm2/fs/proc/base.c 2008-04-17 15:19:25.000000000 +0200
@@ -1138,6 +1138,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 >= PAGE_SIZE)
+ count = PAGE_SIZE - 1;
+
+ length = -ENOMEM;
+ page = (char *) __get_free_page(GFP_TEMPORARY);
+ if (!page)
+ goto out;
+
+ length = get_nextid(task, (char *) page, count);
+ 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:
@@ -2779,6 +2850,11 @@ static const struct pid_entry tid_base_s
#ifdef CONFIG_FAULT_INJECTION
REG("make-it-fail", S_IRUGO|S_IWUSR, fault_inject),
#endif
+ /*
+ * NOTE that next_id is not added into tgid_base_stuff[] since it has
+ * to be specified on a per-thread basis.
+ */
+ REG("next_id", S_IRUGO|S_IWUSR, next_id),
};
static int proc_tid_base_readdir(struct file * filp,
Index: linux-2.6.25-rc8-mm2/kernel/Makefile
===================================================================
--- linux-2.6.25-rc8-mm2.orig/kernel/Makefile 2008-04-17 12:50:25.000000000 +0200
+++ linux-2.6.25-rc8-mm2/kernel/Makefile 2008-04-17 13:47:45.000000000 +0200
@@ -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
ifdef CONFIG_FTRACE
# Do not profile debug utilities
Index: linux-2.6.25-rc8-mm2/kernel/nextid.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.25-rc8-mm2/kernel/nextid.c 2008-04-17 15:16:07.000000000 +0200
@@ -0,0 +1,86 @@
+/*
+ * 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>
+
+
+
+ssize_t get_nextid(struct task_struct *task, char *buffer, size_t size)
+{
+ struct sys_id *sid;
+
+ sid = task->next_id;
+ if (!sid)
+ return snprintf(buffer, size, "UNSET\n");
+
+ return snprintf(buffer, size, "LONG %ld\n", sid->id);
+}
+
+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 && *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;
+}
+
+int reset_nextid(struct task_struct *task)
+{
+ struct sys_id *sid;
+
+ sid = task->next_id;
+ if (!sid)
+ return 0;
+
+ task->next_id = NULL;
+ kfree(sid);
+ return 0;
+}
+
+#define LONG_STR "LONG"
+#define RESET_STR "RESET"
+
+/*
+ * Parses a line written to /proc/self/task/<my_tid>/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;
+
+ if (!out)
+ return -EINVAL;
+
+ token = strsep(&out, " ");
+
+ if (!strcmp(token, LONG_STR))
+ return set_single_id(task, out);
+ else if (!strncmp(token, RESET_STR, strlen(RESET_STR)))
+ return reset_nextid(task);
+ else
+ return -EINVAL;
+}
Index: linux-2.6.25-rc8-mm2/kernel/fork.c
===================================================================
--- linux-2.6.25-rc8-mm2.orig/kernel/fork.c 2008-04-17 12:50:25.000000000 +0200
+++ linux-2.6.25-rc8-mm2/kernel/fork.c 2008-04-17 13:49:09.000000000 +0200
@@ -1167,6 +1167,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);
Index: linux-2.6.25-rc8-mm2/kernel/exit.c
===================================================================
--- linux-2.6.25-rc8-mm2.orig/kernel/exit.c 2008-04-17 12:50:25.000000000 +0200
+++ linux-2.6.25-rc8-mm2/kernel/exit.c 2008-04-17 13:50:42.000000000 +0200
@@ -987,6 +987,10 @@ NORET_TYPE void do_exit(long code)
proc_exit_connector(tsk);
exit_notify(tsk, group_dead);
+
+ if (unlikely(tsk->next_id))
+ exit_nextid(tsk);
+
#ifdef CONFIG_NUMA
mpol_put(tsk->mempolicy);
tsk->mempolicy = NULL;
Index: linux-2.6.25-rc8-mm2/fs/exec.c
===================================================================
--- linux-2.6.25-rc8-mm2.orig/fs/exec.c 2008-04-17 12:50:41.000000000 +0200
+++ linux-2.6.25-rc8-mm2/fs/exec.c 2008-04-17 13:51:47.000000000 +0200
@@ -1024,6 +1024,9 @@ int flush_old_exec(struct linux_binprm *
flush_signal_handlers(current, 0);
flush_old_files(current->files);
+ if (unlikely(current->next_id))
+ reset_nextid(current);
+
return 0;
mmap_failed:
--
next prev parent reply other threads:[~2008-04-18 5:47 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-18 5:44 [PATCH 0/4] - v2 - Object creation with a specified id Nadia.Derbey
2008-04-18 5:45 ` Nadia.Derbey [this message]
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
2008-04-18 5:45 ` [PATCH 3/4] - v2 - IPC: use the target ID specified in procfs Nadia.Derbey-6ktuUTfB/bM
2008-04-18 5:45 ` Nadia.Derbey
2008-04-18 5:45 ` [PATCH 4/4] - v2 - PID: " Nadia.Derbey-6ktuUTfB/bM
2008-04-18 5:45 ` Nadia.Derbey
[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
2008-04-18 17:07 ` Dave Hansen
[not found] ` <1208538427.25363.40.camel-FpcvD5N4B9G9xGwK5P7XA+TW4wlIGRCZ@public.gmane.org>
2008-04-21 11:32 ` Nadia Derbey
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
2008-04-22 19:36 ` Checkpoint/restart (was Re: [PATCH 0/4] - v2 - Object creation with a specified id) Alexey Dobriyan
[not found] ` <20080422193612.GA15835-QDJVlCTZ4KWTKS93B3g+7KFoa47nwP16@public.gmane.org>
2008-04-22 18:56 ` Dave Hansen
2008-04-22 18:56 ` Dave Hansen
[not found] ` <1208890580.17117.14.camel-FpcvD5N4B9G9xGwK5P7XA+TW4wlIGRCZ@public.gmane.org>
2008-04-22 19:51 ` Serge E. Hallyn
2008-04-22 19:51 ` Serge E. Hallyn
2008-04-22 21:01 ` Alexey Dobriyan
2008-04-22 21:01 ` Alexey Dobriyan
2008-04-22 22:56 ` Dave Hansen
2008-04-23 6:40 ` Kirill Korotaev
2008-04-23 15:33 ` Dave Hansen
2008-04-24 7:00 ` Kirill Korotaev
2008-04-24 18:30 ` Dave Hansen
[not found] ` <1209061809.12718.36.camel-FpcvD5N4B9G9xGwK5P7XA+TW4wlIGRCZ@public.gmane.org>
2008-04-24 23:13 ` Oren Laadan
2008-04-24 23:13 ` Oren Laadan
[not found] ` <48103002.5090806-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2008-04-24 18:30 ` Dave Hansen
[not found] ` <1208964798.17117.72.camel-FpcvD5N4B9G9xGwK5P7XA+TW4wlIGRCZ@public.gmane.org>
2008-04-24 7:00 ` Kirill Korotaev
[not found] ` <480ED9D5.1010906-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2008-04-23 15:33 ` Dave Hansen
2008-04-24 1:19 ` Oren Laadan
2008-04-24 1:19 ` Oren Laadan
[not found] ` <480FE037.2010302-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2008-07-10 1:58 ` Eric W. Biederman
2008-07-10 1:58 ` Eric W. Biederman
[not found] ` <m1y74a7b4w.fsf-B27657KtZYmhTnVgQlOflh2eb7JE58TQ@public.gmane.org>
2008-07-10 17:12 ` Dave Hansen
2008-07-17 23:09 ` Oren Laadan
2008-07-17 23:09 ` Oren Laadan
2008-07-10 17:12 ` Dave Hansen
2008-07-10 17:32 ` Serge E. Hallyn
2008-07-10 17:32 ` Serge E. Hallyn
[not found] ` <20080710173246.GA1857-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-07-10 18:55 ` Eric W. Biederman
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:06 ` Dave Hansen
2008-07-10 19:21 ` Eric W. Biederman
2008-07-10 19:21 ` Eric W. Biederman
2008-07-10 19:47 ` Dave Hansen
2008-07-11 0:32 ` Alexey Dobriyan
2008-07-11 0:32 ` Alexey Dobriyan
2008-07-17 23:19 ` Oren Laadan
2008-07-17 23:19 ` Oren Laadan
[not found] ` <m14p6xy27s.fsf-B27657KtZYmhTnVgQlOflh2eb7JE58TQ@public.gmane.org>
2008-07-10 19:47 ` Dave Hansen
2008-07-17 23:16 ` Oren Laadan
2008-07-17 23:16 ` Oren Laadan
2008-07-18 16:18 ` Serge E. Hallyn
2008-07-17 23:14 ` Oren Laadan
2008-07-17 23:14 ` Oren Laadan
[not found] ` <1208904967.17117.51.camel-FpcvD5N4B9G9xGwK5P7XA+TW4wlIGRCZ@public.gmane.org>
2008-04-23 6:40 ` Kirill Korotaev
[not found] ` <20080422210130.GA15937-QDJVlCTZ4KWTKS93B3g+7KFoa47nwP16@public.gmane.org>
2008-04-22 22:56 ` Dave Hansen
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=20080418054718.407122000@bull.net \
--to=nadia.derbey@bull.net \
--cc=containers@lists.linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nick@nick-andrew.net \
--cc=orenl@cs.columbia.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.