All of lore.kernel.org
 help / color / mirror / Atom feed
From: Niraj Kumar <niraj17@gmail.com>
To: Eric Paris <eparis@redhat.com>
Cc: linux-kernel@vger.kernel.org, zbr@ioremap.net
Subject: Re: [RFC PATCH -v4 00/14] fsnotify, dnotify, and inotify
Date: Mon, 22 Dec 2008 16:28:27 +0530	[thread overview]
Message-ID: <20081222105827.GA10208@niraj-laptop> (raw)
In-Reply-To: <1229916126.29604.47.camel@localhost.localdomain>

O Sun, Dec 21, 2008 at 10:22:06PM -0500, Eric Paris wrote:
> On Thu, 2008-12-18 at 18:36 -0500, C. Scott Ananian wrote:
> > On Fri, Dec 12, 2008 at 4:51 PM, Eric Paris <eparis@redhat.com> wrote:
> > > The following series implements a new generic in kernel filesystem
> > > notification system, fsnotify.  On top of fsnotify I reimplement dnotify and
> > > inotify.  I have not finished with the change from inotify although I think
> > > inotify_user should be completed.  In kernel inotify users (aka audit) still
> > > (until I get positive feedback) relay on the old inotify backend.  This can be
> > > 'easily' fixed.
> > > All of this is in preperation for fanotify and using fanotify as an on access
> > > file scanner.   So you better know it's coming.

Eric,

I was also getting my hands dirty with inotify (and friends)
but I see that you are already ahead. So, I thought I would
rather list my immediate requirements and see how far we can go with that.

My application is interested in only filesystem events (read/write/delete) but:

1)  wants notification of only those events which are generated by the
calling process and it's children.
2) Subject to the constraint as mentioned above (1), it would be nice if I 
can just say that I need to be notified of events on all filesystem
objects (perhaps within a namespace) rather than specifying each and 
every file/dir that I am interested in. This is somewhat similar to the
"recursive watch" problem that others have mentioned.

The first part is fairly easy to achieve and I had already created a
patch for that on top of inotify. (See patch below). I was still 
thinking about second part when I saw your patches. Can you tell me
whether your work is going to achive this? Maybe I can modify my
patch to work on top of what you are proposing ...

-Niraj

--------------------------------

Inotify: filter events only by the current process and it's children.

Adds a new flag (to be used with sys_inotify_init1) which
restricts notifications of only those events which has been
generated by the calling process and it's children.

This patch is on top of 2.6.28-rc5.

Signed-off-by: Niraj Kumar <niraj17@gmail.com>


diff --git a/fs/inotify.c b/fs/inotify.c
index 7bbed1b..f7ed34e 100644
--- a/fs/inotify.c
+++ b/fs/inotify.c
@@ -80,6 +80,8 @@ struct inotify_handle {
 	struct list_head	watches;	/* list of watches */
 	atomic_t		count;		/* reference count */
 	u32			last_wd;	/* the last wd allocated */
+	struct task_struct      *owner_task;    /* owner task_struct */
+	u32			flags;	        /* operations flags */
 	const struct inotify_operations *in_ops; /* inotify caller operations */
 };
 
@@ -310,6 +312,18 @@ void inotify_inode_queue_event(struct inode *inode, u32 mask, u32 cookie,
 		u32 watch_mask = watch->mask;
 		if (watch_mask & mask) {
 			struct inotify_handle *ih= watch->ih;
+			struct task_struct *curr = current;
+			int found = 0;
+			if (ih->flags & IN_ONLY_CHILD) {
+				for (curr = current; curr != &init_task;
+							 curr = curr->parent)
+					if (ih->owner_task == curr) {
+						found = 1;
+						break;
+					}
+				if (!found)
+					continue;
+			}
 			mutex_lock(&ih->mutex);
 			if (watch_mask & IN_ONESHOT)
 				remove_watch_no_event(watch, ih);
@@ -467,7 +481,8 @@ EXPORT_SYMBOL_GPL(inotify_inode_is_dead);
  * inotify_init - allocate and initialize an inotify instance
  * @ops: caller's inotify operations
  */
-struct inotify_handle *inotify_init(const struct inotify_operations *ops)
+struct inotify_handle *inotify_init(const struct inotify_operations *ops,
+			 int flags)
 {
 	struct inotify_handle *ih;
 
@@ -479,6 +494,8 @@ struct inotify_handle *inotify_init(const struct inotify_operations *ops)
 	INIT_LIST_HEAD(&ih->watches);
 	mutex_init(&ih->mutex);
 	ih->last_wd = 0;
+	ih->owner_task = current;
+	ih->flags = flags;
 	ih->in_ops = ops;
 	atomic_set(&ih->count, 0);
 	get_inotify_handle(ih);
diff --git a/fs/inotify_user.c b/fs/inotify_user.c
index d367e9b..15359e3 100644
--- a/fs/inotify_user.c
+++ b/fs/inotify_user.c
@@ -588,7 +588,7 @@ asmlinkage long sys_inotify_init1(int flags)
 	BUILD_BUG_ON(IN_CLOEXEC != O_CLOEXEC);
 	BUILD_BUG_ON(IN_NONBLOCK != O_NONBLOCK);
 
-	if (flags & ~(IN_CLOEXEC | IN_NONBLOCK))
+	if (flags & ~(IN_CLOEXEC | IN_NONBLOCK | IN_ONLY_CHILD))
 		return -EINVAL;
 
 	fd = get_unused_fd_flags(flags & O_CLOEXEC);
@@ -614,7 +614,7 @@ asmlinkage long sys_inotify_init1(int flags)
 		goto out_free_uid;
 	}
 
-	ih = inotify_init(&inotify_user_ops);
+	ih = inotify_init(&inotify_user_ops, flags);
 	if (IS_ERR(ih)) {
 		ret = PTR_ERR(ih);
 		goto out_free_dev;
diff --git a/include/linux/inotify.h b/include/linux/inotify.h
index 37ea289..24adb0e 100644
--- a/include/linux/inotify.h
+++ b/include/linux/inotify.h
@@ -66,8 +66,10 @@ struct inotify_event {
 			 IN_MOVE_SELF)
 
 /* Flags for sys_inotify_init1.  */
-#define IN_CLOEXEC O_CLOEXEC
-#define IN_NONBLOCK O_NONBLOCK
+#define IN_CLOEXEC O_CLOEXEC     /* 02000000 */
+#define IN_NONBLOCK O_NONBLOCK   /* 00004000 */
+#define IN_ONLY_CHILD 0x00000002 /* only notify event generated by this
+					 process and children. */
 
 #ifdef __KERNEL__
 
@@ -117,7 +119,8 @@ extern u32 inotify_get_cookie(void);
 
 /* Kernel Consumer API */
 
-extern struct inotify_handle *inotify_init(const struct inotify_operations *);
+extern struct inotify_handle *inotify_init(const struct inotify_operations *,
+							 int);
 extern void inotify_init_watch(struct inotify_watch *);
 extern void inotify_destroy(struct inotify_handle *);
 extern __s32 inotify_find_watch(struct inotify_handle *, struct inode *,
diff --git a/kernel/audit.c b/kernel/audit.c
index 4414e93..c3c9e7d 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -983,7 +983,7 @@ static int __init audit_init(void)
 	audit_log(NULL, GFP_KERNEL, AUDIT_KERNEL, "initialized");
 
 #ifdef CONFIG_AUDITSYSCALL
-	audit_ih = inotify_init(&audit_inotify_ops);
+	audit_ih = inotify_init(&audit_inotify_ops, 0);
 	if (IS_ERR(audit_ih))
 		audit_panic("cannot initialize inotify handle");
 #endif
diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c
index 8b50944..e631b60 100644
--- a/kernel/audit_tree.c
+++ b/kernel/audit_tree.c
@@ -907,7 +907,7 @@ static int __init audit_tree_init(void)
 {
 	int i;
 
-	rtree_ih = inotify_init(&rtree_inotify_ops);
+	rtree_ih = inotify_init(&rtree_inotify_ops, 0);
 	if (IS_ERR(rtree_ih))
 		audit_panic("cannot initialize inotify handle for rectree watches");
 


  reply	other threads:[~2008-12-22 10:58 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-12 21:51 [RFC PATCH -v4 00/14] fsnotify, dnotify, and inotify Eric Paris
2008-12-12 21:51 ` [RFC PATCH -v4 01/14] filesystem notification: create fs/notify to contain all fs notification Eric Paris
2008-12-12 21:51 ` [RFC PATCH -v4 02/14] fsnotify: pass a file instead of an inode to open, read, and write Eric Paris
2008-12-12 21:51 ` [RFC PATCH -v4 03/14] fsnotify: sys_execve and sys_uselib do not call into fsnotify Eric Paris
2008-12-12 21:51 ` [RFC PATCH -v4 04/14] fsnotify: use the new open-exec hook for inotify and dnotify Eric Paris
2008-12-13 15:29   ` Christoph Hellwig
2008-12-12 21:51 ` [RFC PATCH -v4 05/14] fsnotify: unified filesystem notification backend Eric Paris
2008-12-13  2:54   ` Evgeniy Polyakov
2008-12-13 15:01     ` Eric Paris
2008-12-12 21:51 ` [RFC PATCH -v4 06/14] fsnotify: add group priorities Eric Paris
2008-12-12 21:51 ` [RFC PATCH -v4 07/14] fsnotify: add in inode fsnotify markings Eric Paris
2008-12-13  3:07   ` Evgeniy Polyakov
2008-12-13 16:35     ` Eric Paris
2008-12-22 13:43       ` Al Viro
2008-12-22 14:45         ` Eric Paris
2008-12-12 21:51 ` [RFC PATCH -v4 08/14] fsnotify: parent event notification Eric Paris
2008-12-12 21:52 ` [RFC PATCH -v4 09/14] dnotify: reimplement dnotify using fsnotify Eric Paris
2008-12-12 21:52 ` [RFC PATCH -v4 10/14] fsnotify: generic notification queue and waitq Eric Paris
2008-12-12 21:52 ` [RFC PATCH -v4 11/14] fsnotify: include pathnames with entries when possible Eric Paris
2008-12-13  3:19   ` Evgeniy Polyakov
2008-12-13 16:42     ` Eric Paris
2008-12-12 21:52 ` [RFC PATCH -v4 12/14] fsnotify: add correlations between events Eric Paris
2008-12-18 22:28   ` C. Scott Ananian
2008-12-22  2:40     ` Eric Paris
2008-12-22  9:01       ` Evgeniy Polyakov
2008-12-22 20:06       ` C. Scott Ananian
2008-12-12 21:52 ` [RFC PATCH -v4 13/14] inotify: reimplement inotify using fsnotify Eric Paris
2008-12-13  3:22   ` Evgeniy Polyakov
2008-12-13 16:44     ` Eric Paris
2008-12-15 15:48       ` Evgeniy Polyakov
2008-12-12 21:52 ` [RFC PATCH -v4 14/14] shit on top for debugging Eric Paris
2008-12-14 22:40   ` James Morris
2008-12-14 22:47     ` Eric Paris
2008-12-18 23:36 ` [RFC PATCH -v4 00/14] fsnotify, dnotify, and inotify C. Scott Ananian
2008-12-22  3:22   ` Eric Paris
2008-12-22 10:58     ` Niraj Kumar [this message]
2008-12-22 19:59     ` C. Scott Ananian
2008-12-22 20:53       ` Eric Paris
2008-12-29 18:19         ` C. Scott Ananian
2008-12-22 21:04       ` Al Viro
2008-12-22 23:08         ` C. Scott Ananian
2008-12-22 23:20           ` Al Viro
2008-12-22 23:21           ` Christoph Hellwig
2008-12-25 18:17             ` C. Scott Ananian
2008-12-25 20:33               ` Al Viro
2008-12-26  0:58                 ` C. Scott Ananian
2008-12-26  1:44                   ` Al Viro
2008-12-27 21:23                     ` C. Scott Ananian

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=20081222105827.GA10208@niraj-laptop \
    --to=niraj17@gmail.com \
    --cc=eparis@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zbr@ioremap.net \
    /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.