All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Helsley <matthltc@us.ibm.com>
To: Andrew Morton <akpm@osdl.org>
Cc: Peter Williams <pwil3058@bigpond.net.au>,
	Linux-Kernel <linux-kernel@vger.kernel.org>,
	Jes Sorensen <jes@sgi.com>,
	LSE-Tech <lse-tech@lists.sourceforge.net>,
	Chandra S Seetharaman <sekharan@us.ibm.com>,
	Alan Stern <stern@rowland.harvard.edu>,
	John T Kohl <jtk@us.ibm.com>, Balbir Singh <balbir@in.ibm.com>,
	Shailabh Nagar <nagar@watson.ibm.com>
Subject: [PATCH] Per-task watchers: Enable inheritance
Date: Wed, 21 Jun 2006 01:47:15 -0700	[thread overview]
Message-ID: <1150879635.21787.964.camel@stark> (raw)

This allows per-task watchers to implement inheritance of the same function
and/or data in response to the initialization of new tasks. A watcher might
implement inheritance using the following notifier_call snippet:

int my_notify_func(struct notifier_block *nb, unsigned long val, void *t)
{
	struct task_struct *tsk = t;
	struct notifier_block *child_nb;
	
	switch(get_watch_event(val)){
	case WATCH_TASK_INIT: /* use container_of() to associate extra data */
		child_nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL);
		if (!child_nb)
			return NOTIFY_DONE;
		child_nb->notifier_call = my_notify_func;
		register_per_task_watcher(tsk, child_nb);
		return NOTIFY_OK;
	case WATCH_TASK_FREE:
		unregister_per_task_watcher(tsk, nb);
		kfree(nb);
		return NOTIFY_OK;

Compile tested only. Peter, is this useful to you?

Signed-off-by: Matt Helsley <matthltc@us.ibm.com>
Cc: Peter Williams <pwil3058@bigpond.net.au>
---

 include/linux/notifier.h |    6 ++++--
 ipc/sem.c                |    2 +-
 kernel/sys.c             |   12 ++++++++----
 3 files changed, 13 insertions(+), 7 deletions(-)

Index: linux-2.6.17-rc6-mm2/kernel/sys.c
===================================================================
--- linux-2.6.17-rc6-mm2.orig/kernel/sys.c
+++ linux-2.6.17-rc6-mm2/kernel/sys.c
@@ -462,19 +462,23 @@ static inline int notify_per_task_watche
 		return raw_notifier_call_chain(&task->real_parent->notify,
 		   			       val, task);
 	return 0;
 }
 
-int register_per_task_watcher(struct notifier_block *nb)
+/* tsk must be current or the fork|clone-ing child of current */
+int register_per_task_watcher(struct task_struct *tsk,
+			      struct notifier_block *nb)
 {
-	return raw_notifier_chain_register(&current->notify, nb);
+	return raw_notifier_chain_register(&tsk->notify, nb);
 }
 EXPORT_SYMBOL_GPL(register_per_task_watcher);
 
-int unregister_per_task_watcher(struct notifier_block *nb)
+/* tsk must be current or the fork|clone-ing child of current */
+int unregister_per_task_watcher(struct task_struct *tsk,
+				struct notifier_block *nb)
 {
-	return raw_notifier_chain_unregister(&current->notify, nb);
+	return raw_notifier_chain_unregister(&tsk->notify, nb);
 }
 EXPORT_SYMBOL_GPL(unregister_per_task_watcher);
 
 int notify_watchers(unsigned long val, void *v)
 {
Index: linux-2.6.17-rc6-mm2/include/linux/notifier.h
===================================================================
--- linux-2.6.17-rc6-mm2.orig/include/linux/notifier.h
+++ linux-2.6.17-rc6-mm2/include/linux/notifier.h
@@ -154,12 +154,14 @@ extern int raw_notifier_call_chain(struc
 #define CPU_DOWN_FAILED		0x0006 /* CPU (unsigned)v NOT going down */
 #define CPU_DEAD		0x0007 /* CPU (unsigned)v dead */
 
 extern int register_task_watcher(struct notifier_block *nb);
 extern int unregister_task_watcher(struct notifier_block *nb);
-extern int register_per_task_watcher(struct notifier_block *nb);
-extern int unregister_per_task_watcher(struct notifier_block *nb);
+extern int register_per_task_watcher(struct task_struct *tsk,
+				     struct notifier_block *nb);
+extern int unregister_per_task_watcher(struct task_struct *tsk,
+				       struct notifier_block *nb);
 #define WATCH_FLAGS_MASK		((-1) ^ 0x0FFFFUL)
 #define get_watch_event(v)		({ ((v) & ~WATCH_FLAGS_MASK); })
 #define get_watch_flags(v) 		({ ((v) & WATCH_FLAGS_MASK); })
 
 #define WATCH_TASK_INIT			0x00000001 /* initialize task_struct */
Index: linux-2.6.17-rc6-mm2/ipc/sem.c
===================================================================
--- linux-2.6.17-rc6-mm2.orig/ipc/sem.c
+++ linux-2.6.17-rc6-mm2/ipc/sem.c
@@ -1035,11 +1035,11 @@ static inline int get_undo_list(struct s
 			goto err;
 		semun_nb = kzalloc(sizeof(*semun_nb), GFP_KERNEL);
 		if (semun_nb == NULL)
 			goto err;
 		semun_nb->notifier_call = sem_undo_task_exit;
-		retval = register_per_task_watcher(semun_nb);
+		retval = register_per_task_watcher(current, semun_nb);
 		if (retval)
 			goto err;
 		memset(undo_list, 0, size);
 		spin_lock_init(&undo_list->lock);
 		atomic_set(&undo_list->refcnt, 1);



             reply	other threads:[~2006-06-21  9:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-21  8:47 Matt Helsley [this message]
2006-06-21 10:30 ` [PATCH] Per-task watchers: Enable inheritance Peter Williams
2006-06-21 21:27   ` Matt Helsley
2006-06-23 21:17 ` John T. Kohl
2006-06-23 23:33   ` Matt Helsley
2006-06-24  0:08     ` Peter Williams
2006-06-26 13:03     ` John T. Kohl
2006-06-26 13:27       ` Peter Williams

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=1150879635.21787.964.camel@stark \
    --to=matthltc@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=balbir@in.ibm.com \
    --cc=jes@sgi.com \
    --cc=jtk@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lse-tech@lists.sourceforge.net \
    --cc=nagar@watson.ibm.com \
    --cc=pwil3058@bigpond.net.au \
    --cc=sekharan@us.ibm.com \
    --cc=stern@rowland.harvard.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.