* [patch] add two inotify_add_watch flags
@ 2005-12-07 3:54 John McCutchan
2005-12-07 18:26 ` Robert Love
2005-12-09 22:51 ` Andrew Morton
0 siblings, 2 replies; 4+ messages in thread
From: John McCutchan @ 2005-12-07 3:54 UTC (permalink / raw)
To: Linux Kernel; +Cc: Robert Love, Andrew Morton
Yo,
The below patch lets user space have more control over the inodes that
inotify will watch. It introduces two new flags.
IN_ONLYDIR -- only watch the inode if it is a directory
This is needed to avoid the race that can occur when we want to be sure
that we are watching a directory.
IN_DONT_FOLLOW -- don't follow a symlink. In combination with
IN_ONLYDIR we can make sure that we don't watch the target of symlinks.
The issues the flags fix came up when writing the gnome-vfs inotify
backend. Default behaviour is unchanged.
Signed-off-by: John McCutchan <ttb@tentacle.dhs.org>
Index: linux-2.6.14-rc5/fs/inotify.c
===================================================================
--- linux-2.6.14-rc5.orig/fs/inotify.c 2005-10-20 02:23:05.000000000 -0400
+++ linux-2.6.14-rc5/fs/inotify.c 2005-12-06 19:01:22.000000000 -0500
@@ -363,11 +363,18 @@
/*
* find_inode - resolve a user-given path to a specific inode and return a nd
*/
-static int find_inode(const char __user *dirname, struct nameidata *nd)
+static int find_inode(const char __user *dirname, struct nameidata *nd,
+ int only_dir, int dont_follow_symlink)
{
int error;
+ unsigned flags = 0;
- error = __user_walk(dirname, LOOKUP_FOLLOW, nd);
+ if (!dont_follow_symlink)
+ flags |= LOOKUP_FOLLOW;
+ if (only_dir)
+ flags |= LOOKUP_DIRECTORY;
+
+ error = __user_walk(dirname, flags, nd);
if (error)
return error;
/* you can only watch an inode if you have read permissions on it */
@@ -943,7 +950,7 @@
goto fput_and_out;
}
- ret = find_inode(path, &nd);
+ ret = find_inode(path, &nd, mask & IN_ONLYDIR, mask & IN_DONT_FOLLOW);
if (unlikely(ret))
goto fput_and_out;
Index: linux-2.6.14-rc5/include/linux/inotify.h
===================================================================
--- linux-2.6.14-rc5.orig/include/linux/inotify.h 2005-10-20 02:23:05.000000000 -0400
+++ linux-2.6.14-rc5/include/linux/inotify.h 2005-12-06 18:57:11.000000000 -0500
@@ -47,6 +47,8 @@
#define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */
/* special flags */
+#define IN_ONLYDIR 0x01000000 /* only watch the path if it is a directory */
+#define IN_DONT_FOLLOW 0x02000000 /* don't follow a sym link */
#define IN_MASK_ADD 0x20000000 /* add to the mask of an already existing watch */
#define IN_ISDIR 0x40000000 /* event occurred against dir */
#define IN_ONESHOT 0x80000000 /* only send event once */
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [patch] add two inotify_add_watch flags 2005-12-07 3:54 [patch] add two inotify_add_watch flags John McCutchan @ 2005-12-07 18:26 ` Robert Love 2005-12-09 22:51 ` Andrew Morton 1 sibling, 0 replies; 4+ messages in thread From: Robert Love @ 2005-12-07 18:26 UTC (permalink / raw) To: John McCutchan; +Cc: Linux Kernel, Andrew Morton On Tue, 2005-12-06 at 22:54 -0500, John McCutchan wrote: > The below patch lets user space have more control over the inodes that > inotify will watch. It introduces two new flags. > > IN_ONLYDIR -- only watch the inode if it is a directory > This is needed to avoid the race that can occur when we want to be sure > that we are watching a directory. > > IN_DONT_FOLLOW -- don't follow a symlink. In combination with > IN_ONLYDIR we can make sure that we don't watch the target of symlinks. > > The issues the flags fix came up when writing the gnome-vfs inotify > backend. Default behaviour is unchanged. Looks good to me, and I confirm we hit these issues in real-life with gnome-vfs. Acked-by: Robert Love <rml@novell.com> Robert Love ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] add two inotify_add_watch flags 2005-12-07 3:54 [patch] add two inotify_add_watch flags John McCutchan 2005-12-07 18:26 ` Robert Love @ 2005-12-09 22:51 ` Andrew Morton 2005-12-09 23:07 ` John McCutchan 1 sibling, 1 reply; 4+ messages in thread From: Andrew Morton @ 2005-12-09 22:51 UTC (permalink / raw) To: John McCutchan; +Cc: linux-kernel, rml John McCutchan <ttb@tentacle.dhs.org> wrote: > > -static int find_inode(const char __user *dirname, struct nameidata *nd) > +static int find_inode(const char __user *dirname, struct nameidata *nd, > + int only_dir, int dont_follow_symlink) > { > int error; > + unsigned flags = 0; > > - error = __user_walk(dirname, LOOKUP_FOLLOW, nd); > + if (!dont_follow_symlink) > + flags |= LOOKUP_FOLLOW; > + if (only_dir) > + flags |= LOOKUP_DIRECTORY; > + > + error = __user_walk(dirname, flags, nd); > if (error) > return error; > /* you can only watch an inode if you have read permissions on it */ > @@ -943,7 +950,7 @@ > goto fput_and_out; > } > > - ret = find_inode(path, &nd); > + ret = find_inode(path, &nd, mask & IN_ONLYDIR, mask & IN_DONT_FOLLOW); > if (unlikely(ret)) > goto fput_and_out; I'd have thought that it'd be more general to pass the __user_walk flags into find_inode(), rather than calculating them in the callee. Slightly more efficient too. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] add two inotify_add_watch flags 2005-12-09 22:51 ` Andrew Morton @ 2005-12-09 23:07 ` John McCutchan 0 siblings, 0 replies; 4+ messages in thread From: John McCutchan @ 2005-12-09 23:07 UTC (permalink / raw) To: Andrew Morton; +Cc: linux-kernel, rml On Fri, 2005-09-12 at 14:51 -0800, Andrew Morton wrote: > John McCutchan <ttb@tentacle.dhs.org> wrote: > > > > -static int find_inode(const char __user *dirname, struct nameidata *nd) > > +static int find_inode(const char __user *dirname, struct nameidata *nd, > > + int only_dir, int dont_follow_symlink) > > { > > int error; > > + unsigned flags = 0; > > > > - error = __user_walk(dirname, LOOKUP_FOLLOW, nd); > > + if (!dont_follow_symlink) > > + flags |= LOOKUP_FOLLOW; > > + if (only_dir) > > + flags |= LOOKUP_DIRECTORY; > > + > > + error = __user_walk(dirname, flags, nd); > > if (error) > > return error; > > /* you can only watch an inode if you have read permissions on it */ > > @@ -943,7 +950,7 @@ > > goto fput_and_out; > > } > > > > - ret = find_inode(path, &nd); > > + ret = find_inode(path, &nd, mask & IN_ONLYDIR, mask & IN_DONT_FOLLOW); > > if (unlikely(ret)) > > goto fput_and_out; > > I'd have thought that it'd be more general to pass the __user_walk flags > into find_inode(), rather than calculating them in the callee. Slightly > more efficient too. Makes sense. Signed-off-by: John McCutchan <ttb@tentacle.dhs.org> Index: linux-2.6.14-rc5/fs/inotify.c =================================================================== --- linux-2.6.14-rc5.orig/fs/inotify.c 2005-12-09 17:59:10.000000000 -0500 +++ linux-2.6.14-rc5/fs/inotify.c 2005-12-09 18:04:22.000000000 -0500 @@ -363,11 +363,12 @@ /* * find_inode - resolve a user-given path to a specific inode and return a nd */ -static int find_inode(const char __user *dirname, struct nameidata *nd) +static int find_inode(const char __user *dirname, struct nameidata *nd, + unsigned flags) { int error; - error = __user_walk(dirname, LOOKUP_FOLLOW, nd); + error = __user_walk(dirname, flags, nd); if (error) return error; /* you can only watch an inode if you have read permissions on it */ @@ -932,6 +933,7 @@ struct file *filp; int ret, fput_needed; int mask_add = 0; + unsigned flags = 0; filp = fget_light(fd, &fput_needed); if (unlikely(!filp)) @@ -943,7 +945,12 @@ goto fput_and_out; } - ret = find_inode(path, &nd); + if (!(mask & IN_DONT_FOLLOW)) + flags |= LOOKUP_FOLLOW; + if (mask & IN_ONLYDIR) + flags |= LOOKUP_DIRECTORY; + + ret = find_inode(path, &nd, flags); if (unlikely(ret)) goto fput_and_out; Index: linux-2.6.14-rc5/include/linux/inotify.h =================================================================== --- linux-2.6.14-rc5.orig/include/linux/inotify.h 2005-12-09 17:59:10.000000000 -0500 +++ linux-2.6.14-rc5/include/linux/inotify.h 2005-12-09 18:00:49.000000000 -0500 @@ -47,6 +47,8 @@ #define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */ /* special flags */ +#define IN_ONLYDIR 0x01000000 /* only watch the path if it is a directory */ +#define IN_DONT_FOLLOW 0x02000000 /* don't follow a sym link */ #define IN_MASK_ADD 0x20000000 /* add to the mask of an already existing watch */ #define IN_ISDIR 0x40000000 /* event occurred against dir */ #define IN_ONESHOT 0x80000000 /* only send event once */ ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-12-09 23:07 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-12-07 3:54 [patch] add two inotify_add_watch flags John McCutchan 2005-12-07 18:26 ` Robert Love 2005-12-09 22:51 ` Andrew Morton 2005-12-09 23:07 ` John McCutchan
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®