aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Paris <eparis@redhat.com>2009-12-17 20:30:52 -0500
committerEric Paris <eparis@redhat.com>2010-07-28 09:58:31 -0400
commit2dfc1cae4c42b93b831b2417540df2b895ab7108 (patch)
treee07a0075964fd2cb9210b302114255e16ab1d4c0
parent7050c48826d5adb2210bddfb6a67aa13bbe984ed (diff)
inotify: remove inotify in kernel interface
nothing uses inotify in the kernel, drop it! Signed-off-by: Eric Paris <eparis@redhat.com>
-rw-r--r--Documentation/feature-removal-schedule.txt8
-rw-r--r--fs/inode.c6
-rw-r--r--fs/notify/inotify/Kconfig15
-rw-r--r--fs/notify/inotify/Makefile1
-rw-r--r--fs/notify/inotify/inotify.c873
-rw-r--r--fs/open.c1
-rw-r--r--include/linux/fs.h5
-rw-r--r--include/linux/fsnotify.h50
-rw-r--r--include/linux/inotify.h174
-rw-r--r--kernel/auditsc.c1
10 files changed, 4 insertions, 1130 deletions
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 1571c0c83dba..a8188bd3dab8 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -367,14 +367,6 @@ When: 2.6.33
367Why: Should be implemented in userspace, policy daemon. 367Why: Should be implemented in userspace, policy daemon.
368Who: Johannes Berg <johannes@sipsolutions.net> 368Who: Johannes Berg <johannes@sipsolutions.net>
369 369
370---------------------------
371
372What: CONFIG_INOTIFY
373When: 2.6.33
374Why: last user (audit) will be converted to the newer more generic
375 and more easily maintained fsnotify subsystem
376Who: Eric Paris <eparis@redhat.com>
377
378---------------------------- 370----------------------------
379 371
380What: lock_policy_rwsem_* and unlock_policy_rwsem_* will not be 372What: lock_policy_rwsem_* and unlock_policy_rwsem_* will not be
diff --git a/fs/inode.c b/fs/inode.c
index 722860b323a9..8e1bee998796 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -20,7 +20,6 @@
20#include <linux/pagemap.h> 20#include <linux/pagemap.h>
21#include <linux/cdev.h> 21#include <linux/cdev.h>
22#include <linux/bootmem.h> 22#include <linux/bootmem.h>
23#include <linux/inotify.h>
24#include <linux/fsnotify.h> 23#include <linux/fsnotify.h>
25#include <linux/mount.h> 24#include <linux/mount.h>
26#include <linux/async.h> 25#include <linux/async.h>
@@ -264,10 +263,6 @@ void inode_init_once(struct inode *inode)
264 INIT_RAW_PRIO_TREE_ROOT(&inode->i_data.i_mmap); 263 INIT_RAW_PRIO_TREE_ROOT(&inode->i_data.i_mmap);
265 INIT_LIST_HEAD(&inode->i_data.i_mmap_nonlinear); 264 INIT_LIST_HEAD(&inode->i_data.i_mmap_nonlinear);
266 i_size_ordered_init(inode); 265 i_size_ordered_init(inode);
267#ifdef CONFIG_INOTIFY
268 INIT_LIST_HEAD(&inode->inotify_watches);
269 mutex_init(&inode->inotify_mutex);
270#endif
271#ifdef CONFIG_FSNOTIFY 266#ifdef CONFIG_FSNOTIFY
272 INIT_HLIST_HEAD(&inode->i_fsnotify_mark_entries); 267 INIT_HLIST_HEAD(&inode->i_fsnotify_mark_entries);
273#endif 268#endif
@@ -413,7 +408,6 @@ int invalidate_inodes(struct super_block *sb)
413 408
414 down_write(&iprune_sem); 409 down_write(&iprune_sem);
415 spin_lock(&inode_lock); 410 spin_lock(&inode_lock);
416 inotify_unmount_inodes(&sb->s_inodes);
417 fsnotify_unmount_inodes(&sb->s_inodes); 411 fsnotify_unmount_inodes(&sb->s_inodes);
418 busy = invalidate_list(&sb->s_inodes, &throw_away); 412 busy = invalidate_list(&sb->s_inodes, &throw_away);
419 spin_unlock(&inode_lock); 413 spin_unlock(&inode_lock);
diff --git a/fs/notify/inotify/Kconfig b/fs/notify/inotify/Kconfig
index b3a159b21cfd..b981fc0c8379 100644
--- a/fs/notify/inotify/Kconfig
+++ b/fs/notify/inotify/Kconfig
@@ -1,18 +1,3 @@
1config INOTIFY
2 bool "Inotify file change notification support"
3 default n
4 ---help---
5 Say Y here to enable legacy in kernel inotify support. Inotify is a
6 file change notification system. It is a replacement for dnotify.
7 This option only provides the legacy inotify in kernel API. There
8 are no in tree kernel users of this interface since it is deprecated.
9 You only need this if you are loading an out of tree kernel module
10 that uses inotify.
11
12 For more information, see <file:Documentation/filesystems/inotify.txt>
13
14 If unsure, say N.
15
16config INOTIFY_USER 1config INOTIFY_USER
17 bool "Inotify support for userspace" 2 bool "Inotify support for userspace"
18 select ANON_INODES 3 select ANON_INODES
diff --git a/fs/notify/inotify/Makefile b/fs/notify/inotify/Makefile
index 943828171362..a380dabe09de 100644
--- a/fs/notify/inotify/Makefile
+++ b/fs/notify/inotify/Makefile
@@ -1,2 +1 @@
1obj-$(CONFIG_INOTIFY) += inotify.o
2obj-$(CONFIG_INOTIFY_USER) += inotify_fsnotify.o inotify_user.o obj-$(CONFIG_INOTIFY_USER) += inotify_fsnotify.o inotify_user.o
diff --git a/fs/notify/inotify/inotify.c b/fs/notify/inotify/inotify.c
deleted file mode 100644
index 27b75ebc7460..000000000000
--- a/fs/notify/inotify/inotify.c
+++ /dev/null
@@ -1,873 +0,0 @@
1/*
2 * fs/inotify.c - inode-based file event notifications
3 *
4 * Authors:
5 * John McCutchan <ttb@tentacle.dhs.org>
6 * Robert Love <rml@novell.com>
7 *
8 * Kernel API added by: Amy Griffis <amy.griffis@hp.com>
9 *
10 * Copyright (C) 2005 John McCutchan
11 * Copyright 2006 Hewlett-Packard Development Company, L.P.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2, or (at your option) any
16 * later version.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
22 */
23
24#include <linux/module.h>
25#include <linux/kernel.h>
26#include <linux/spinlock.h>
27#include <linux/idr.h>
28#include <linux/slab.h>
29#include <linux/fs.h>
30#include <linux/sched.h>
31#include <linux/init.h>
32#include <linux/list.h>
33#include <linux/writeback.h>
34#include <linux/inotify.h>
35#include <linux/fsnotify_backend.h>
36
37static atomic_t inotify_cookie;
38
39/*
40 * Lock ordering:
41 *
42 * dentry->d_lock (used to keep d_move() away from dentry->d_parent)
43 * iprune_mutex (synchronize shrink_icache_memory())
44 * inode_lock (protects the super_block->s_inodes list)
45 * inode->inotify_mutex (protects inode->inotify_watches and watches->i_list)
46 * inotify_handle->mutex (protects inotify_handle and watches->h_list)
47 *
48 * The inode->inotify_mutex and inotify_handle->mutex and held during execution
49 * of a caller's event handler. Thus, the caller must not hold any locks
50 * taken in their event handler while calling any of the published inotify
51 * interfaces.
52 */
53
54/*
55 * Lifetimes of the three main data structures--inotify_handle, inode, and
56 * inotify_watch--are managed by reference count.
57 *
58 * inotify_handle: Lifetime is from inotify_init() to inotify_destroy().
59 * Additional references can bump the count via get_inotify_handle() and drop
60 * the count via put_inotify_handle().
61 *
62 * inotify_watch: for inotify's purposes, lifetime is from inotify_add_watch()
63 * to remove_watch_no_event(). Additional references can bump the count via
64 * get_inotify_watch() and drop the count via put_inotify_watch(). The caller
65 * is reponsible for the final put after receiving IN_IGNORED, or when using
66 * IN_ONESHOT after receiving the first event. Inotify does the final put if
67 * inotify_destroy() is called.
68 *
69 * inode: Pinned so long as the inode is associated with a watch, from
70 * inotify_add_watch() to the final put_inotify_watch().
71 */
72
73/*
74 * struct inotify_handle - represents an inotify instance
75 *
76 * This structure is protected by the mutex 'mutex'.
77 */
78struct inotify_handle {
79 struct idr idr; /* idr mapping wd -> watch */
80 struct mutex mutex; /* protects this bad boy */
81 struct list_head watches; /* list of watches */
82 atomic_t count; /* reference count */
83 u32 last_wd; /* the last wd allocated */
84 const struct inotify_operations *in_ops; /* inotify caller operations */
85};
86
87static inline void get_inotify_handle(struct inotify_handle *ih)
88{
89 atomic_inc(&ih->count);
90}
91
92static inline void put_inotify_handle(struct inotify_handle *ih)
93{
94 if (atomic_dec_and_test(&ih->count)) {
95 idr_destroy(&ih->idr);
96 kfree(ih);
97 }
98}
99
100/**
101 * get_inotify_watch - grab a reference to an inotify_watch
102 * @watch: watch to grab
103 */
104void get_inotify_watch(struct inotify_watch *watch)
105{
106 atomic_inc(&watch->count);
107}
108EXPORT_SYMBOL_GPL(get_inotify_watch);
109
110int pin_inotify_watch(struct inotify_watch *watch)
111{
112 struct super_block *sb = watch->inode->i_sb;
113 if (atomic_inc_not_zero(&sb->s_active)) {
114 atomic_inc(&watch->count);
115 return 1;
116 }
117 return 0;
118}
119
120/**
121 * put_inotify_watch - decrements the ref count on a given watch. cleans up
122 * watch references if the count reaches zero. inotify_watch is freed by
123 * inotify callers via the destroy_watch() op.
124 * @watch: watch to release
125 */
126void put_inotify_watch(struct inotify_watch *watch)
127{
128 if (atomic_dec_and_test(&watch->count)) {
129 struct inotify_handle *ih = watch->ih;
130
131 iput(watch->inode);
132 ih->in_ops->destroy_watch(watch);
133 put_inotify_handle(ih);
134 }
135}
136EXPORT_SYMBOL_GPL(put_inotify_watch);
137
138void unpin_inotify_watch(struct inotify_watch *watch)
139{
140 struct super_block *sb = watch->inode->i_sb;
141 put_inotify_watch(watch);
142 deactivate_super(sb);
143}
144
145/*
146 * inotify_handle_get_wd - returns the next WD for use by the given handle
147 *
148 * Callers must hold ih->mutex. This function can sleep.
149 */
150static int inotify_handle_get_wd(struct inotify_handle *ih,
151 struct inotify_watch *watch)
152{
153 int ret;
154
155 do {
156 if (unlikely(!idr_pre_get(&ih->idr, GFP_NOFS)))
157 return -ENOSPC;
158 ret = idr_get_new_above(&ih->idr, watch, ih->last_wd+1, &watch->wd);
159 } while (ret == -EAGAIN);
160
161 if (likely(!ret))
162 ih->last_wd = watch->wd;
163
164 return ret;
165}
166
167/*
168 * inotify_inode_watched - returns nonzero if there are watches on this inode
169 * and zero otherwise. We call this lockless, we do not care if we race.
170 */
171static inline int inotify_inode_watched(struct inode *inode)
172{
173 return !list_empty(&inode->inotify_watches);
174}
175
176/*
177 * Get child dentry flag into synch with parent inode.
178 * Flag should always be clear for negative dentrys.
179 */
180static void set_dentry_child_flags(struct inode *inode, int watched)
181{
182 struct dentry *alias;
183
184 spin_lock(&dcache_lock);
185 list_for_each_entry(alias, &inode->i_dentry, d_alias) {
186 struct dentry *child;
187
188 list_for_each_entry(child, &alias->d_subdirs, d_u.d_child) {
189 if (!child->d_inode)
190 continue;
191
192 spin_lock(&child->d_lock);
193 if (watched)
194 child->d_flags |= DCACHE_INOTIFY_PARENT_WATCHED;
195 else
196 child->d_flags &=~DCACHE_INOTIFY_PARENT_WATCHED;
197 spin_unlock(&child->d_lock);
198 }
199 }
200 spin_unlock(&dcache_lock);
201}
202
203/*
204 * inotify_find_handle - find the watch associated with the given inode and
205 * handle
206 *
207 * Callers must hold inode->inotify_mutex.
208 */
209static struct inotify_watch *inode_find_handle(struct inode *inode,
210 struct inotify_handle *ih)
211{
212 struct inotify_watch *watch;
213
214 list_for_each_entry(watch, &inode->inotify_watches, i_list) {
215 if (watch->ih == ih)
216 return watch;
217 }
218
219 return NULL;
220}
221
222/*
223 * remove_watch_no_event - remove watch without the IN_IGNORED event.
224 *
225 * Callers must hold both inode->inotify_mutex and ih->mutex.
226 */
227static void remove_watch_no_event(struct inotify_watch *watch,
228 struct inotify_handle *ih)
229{
230 list_del(&watch->i_list);
231 list_del(&watch->h_list);
232
233 if (!inotify_inode_watched(watch->inode))
234 set_dentry_child_flags(watch->inode, 0);
235
236 idr_remove(&ih->idr, watch->wd);
237}
238
239/**
240 * inotify_remove_watch_locked - Remove a watch from both the handle and the
241 * inode. Sends the IN_IGNORED event signifying that the inode is no longer
242 * watched. May be invoked from a caller's event handler.
243 * @ih: inotify handle associated with watch
244 * @watch: watch to remove
245 *
246 * Callers must hold both inode->inotify_mutex and ih->mutex.
247 */
248void inotify_remove_watch_locked(struct inotify_handle *ih,
249 struct inotify_watch *watch)
250{
251 remove_watch_no_event(watch, ih);
252 ih->in_ops->handle_event(watch, watch->wd, IN_IGNORED, 0, NULL, NULL);
253}
254EXPORT_SYMBOL_GPL(inotify_remove_watch_locked);
255
256/* Kernel API for producing events */
257
258/*
259 * inotify_d_instantiate - instantiate dcache entry for inode
260 */
261void inotify_d_instantiate(struct dentry *entry, struct inode *inode)
262{
263 struct dentry *parent;
264
265 if (!inode)
266 return;
267
268 spin_lock(&entry->d_lock);
269 parent = entry->d_parent;
270 if (parent->d_inode && inotify_inode_watched(parent->d_inode))
271 entry->d_flags |= DCACHE_INOTIFY_PARENT_WATCHED;
272 spin_unlock(&entry->d_lock);
273}
274
275/*
276 * inotify_d_move - dcache entry has been moved
277 */
278void inotify_d_move(struct dentry *entry)
279{
280 struct dentry *parent;
281
282 parent = entry->d_parent;
283 if (inotify_inode_watched(parent->d_inode))
284 entry->d_flags |= DCACHE_INOTIFY_PARENT_WATCHED;
285 else
286 entry->d_flags &= ~DCACHE_INOTIFY_PARENT_WATCHED;
287}
288
289/**
290 * inotify_inode_queue_event - queue an event to all watches on this inode
291 * @inode: inode event is originating from
292 * @mask: event mask describing this event
293 * @cookie: cookie for synchronization, or zero
294 * @name: filename, if any
295 * @n_inode: inode associated with name
296 */
297void inotify_inode_queue_event(struct inode *inode, u32 mask, u32 cookie,
298 const char *name, struct inode *n_inode)
299{
300 struct inotify_watch *watch, *next;
301
302 if (!inotify_inode_watched(inode))
303 return;
304
305 mutex_lock(&inode->inotify_mutex);
306 list_for_each_entry_safe(watch, next, &inode->inotify_watches, i_list) {
307 u32 watch_mask = watch->mask;
308 if (watch_mask & mask) {
309 struct inotify_handle *ih= watch->ih;
310 mutex_lock(&ih->mutex);
311 if (watch_mask & IN_ONESHOT)
312 remove_watch_no_event(watch, ih);
313 ih->in_ops->handle_event(watch, watch->wd, mask, cookie,
314 name, n_inode);
315 mutex_unlock(&ih->mutex);
316 }
317 }
318 mutex_unlock(&inode->inotify_mutex);
319}
320EXPORT_SYMBOL_GPL(inotify_inode_queue_event);
321
322/**
323 * inotify_dentry_parent_queue_event - queue an event to a dentry's parent
324 * @dentry: the dentry in question, we queue against this dentry's parent
325 * @mask: event mask describing this event
326 * @cookie: cookie for synchronization, or zero
327 * @name: filename, if any
328 */
329void inotify_dentry_parent_queue_event(struct dentry *dentry, u32 mask,
330 u32 cookie, const char *name)
331{
332 struct dentry *parent;
333 struct inode *inode;
334
335 if (!(dentry->d_flags & DCACHE_INOTIFY_PARENT_WATCHED))
336 return;
337
338 spin_lock(&dentry->d_lock);
339 parent = dentry->d_parent;
340 inode = parent->d_inode;
341
342 if (inotify_inode_watched(inode)) {
343 dget(parent);
344 spin_unlock(&dentry->d_lock);
345 inotify_inode_queue_event(inode, mask, cookie, name,
346 dentry->d_inode);
347 dput(parent);
348 } else
349 spin_unlock(&dentry->d_lock);
350}
351EXPORT_SYMBOL_GPL(inotify_dentry_parent_queue_event);
352
353/**
354 * inotify_get_cookie - return a unique cookie for use in synchronizing events.
355 */
356u32 inotify_get_cookie(void)
357{
358 return atomic_inc_return(&inotify_cookie);
359}
360EXPORT_SYMBOL_GPL(inotify_get_cookie);
361
362/**
363 * inotify_unmount_inodes - an sb is unmounting. handle any watched inodes.
364 * @list: list of inodes being unmounted (sb->s_inodes)
365 *
366 * Called with inode_lock held, protecting the unmounting super block's list
367 * of inodes, and with iprune_mutex held, keeping shrink_icache_memory() at bay.
368 * We temporarily drop inode_lock, however, and CAN block.
369 */
370void inotify_unmount_inodes(struct list_head *list)
371{
372 struct inode *inode, *next_i, *need_iput = NULL;
373
374 list_for_each_entry_safe(inode, next_i, list, i_sb_list) {
375 struct inotify_watch *watch, *next_w;
376 struct inode *need_iput_tmp;
377 struct list_head *watches;
378
379 /*
380 * We cannot __iget() an inode in state I_CLEAR, I_FREEING,
381 * I_WILL_FREE, or I_NEW which is fine because by that point
382 * the inode cannot have any associated watches.
383 */
384 if (inode->i_state & (I_CLEAR|I_FREEING|I_WILL_FREE|I_NEW))
385 continue;
386
387 /*
388 * If i_count is zero, the inode cannot have any watches and
389 * doing an __iget/iput with MS_ACTIVE clear would actually
390 * evict all inodes with zero i_count from icache which is
391 * unnecessarily violent and may in fact be illegal to do.
392 */
393 if (!atomic_read(&inode->i_count))
394 continue;
395
396 need_iput_tmp = need_iput;
397 need_iput = NULL;
398 /* In case inotify_remove_watch_locked() drops a reference. */
399 if (inode != need_iput_tmp)
400 __iget(inode);
401 else
402 need_iput_tmp = NULL;
403 /* In case the dropping of a reference would nuke next_i. */
404 if ((&next_i->i_sb_list != list) &&
405 atomic_read(&next_i->i_count) &&
406 !(next_i->i_state & (I_CLEAR | I_FREEING |
407 I_WILL_FREE))) {
408 __iget(next_i);
409 need_iput = next_i;
410 }
411
412 /*
413 * We can safely drop inode_lock here because we hold
414 * references on both inode and next_i. Also no new inodes
415 * will be added since the umount has begun. Finally,
416 * iprune_mutex keeps shrink_icache_memory() away.
417 */
418 spin_unlock(&inode_lock);
419
420 if (need_iput_tmp)
421 iput(need_iput_tmp);
422
423 /* for each watch, send IN_UNMOUNT and then remove it */
424 mutex_lock(&inode->inotify_mutex);
425 watches = &inode->inotify_watches;
426 list_for_each_entry_safe(watch, next_w, watches, i_list) {
427 struct inotify_handle *ih= watch->ih;
428 get_inotify_watch(watch);
429 mutex_lock(&ih->mutex);
430 ih->in_ops->handle_event(watch, watch->wd, IN_UNMOUNT, 0,
431 NULL, NULL);
432 inotify_remove_watch_locked(ih, watch);
433 mutex_unlock(&ih->mutex);
434 put_inotify_watch(watch);
435 }
436 mutex_unlock(&inode->inotify_mutex);
437 iput(inode);
438
439 spin_lock(&inode_lock);
440 }
441}
442EXPORT_SYMBOL_GPL(inotify_unmount_inodes);
443
444/**
445 * inotify_inode_is_dead - an inode has been deleted, cleanup any watches
446 * @inode: inode that is about to be removed
447 */
448void inotify_inode_is_dead(struct inode *inode)
449{
450 struct inotify_watch *watch, *next;
451
452 mutex_lock(&inode->inotify_mutex);
453 list_for_each_entry_safe(watch, next, &inode->inotify_watches, i_list) {
454 struct inotify_handle *ih = watch->ih;
455 mutex_lock(&ih->mutex);
456 inotify_remove_watch_locked(ih, watch);
457 mutex_unlock(&ih->mutex);
458 }
459 mutex_unlock(&inode->inotify_mutex);
460}
461EXPORT_SYMBOL_GPL(inotify_inode_is_dead);
462
463/* Kernel Consumer API */
464
465/**
466 * inotify_init - allocate and initialize an inotify instance
467 * @ops: caller's inotify operations
468 */
469struct inotify_handle *inotify_init(const struct inotify_operations *ops)
470{
471 struct inotify_handle *ih;
472
473 ih = kmalloc(sizeof(struct inotify_handle), GFP_KERNEL);
474 if (unlikely(!ih))
475 return ERR_PTR(-ENOMEM);
476
477 idr_init(&ih->idr);
478 INIT_LIST_HEAD(&ih->watches);
479 mutex_init(&ih->mutex);
480 ih->last_wd = 0;
481 ih->in_ops = ops;
482 atomic_set(&ih->count, 0);
483 get_inotify_handle(ih);
484
485 return ih;
486}
487EXPORT_SYMBOL_GPL(inotify_init);
488
489/**
490 * inotify_init_watch - initialize an inotify watch
491 * @watch: watch to initialize
492 */
493void inotify_init_watch(struct inotify_watch *watch)
494{
495 INIT_LIST_HEAD(&watch->h_list);
496 INIT_LIST_HEAD(&watch->i_list);
497 atomic_set(&watch->count, 0);
498 get_inotify_watch(watch); /* initial get */
499}
500EXPORT_SYMBOL_GPL(inotify_init_watch);
501
502/*
503 * Watch removals suck violently. To kick the watch out we need (in this
504 * order) inode->inotify_mutex and ih->mutex. That's fine if we have
505 * a hold on inode; however, for all other cases we need to make damn sure
506 * we don't race with umount. We can *NOT* just grab a reference to a
507 * watch - inotify_unmount_inodes() will happily sail past it and we'll end
508 * with reference to inode potentially outliving its superblock. Ideally
509 * we just want to grab an active reference to superblock if we can; that
510 * will make sure we won't go into inotify_umount_inodes() until we are
511 * done. Cleanup is just deactivate_super(). However, that leaves a messy
512 * case - what if we *are* racing with umount() and active references to
513 * superblock can't be acquired anymore? We can bump ->s_count, grab
514 * ->s_umount, which will wait until the superblock is shut down and the
515 * watch in question is pining for fjords.
516 *
517 * And yes, this is far beyond mere "not very pretty"; so's the entire
518 * concept of inotify to start with.
519 */
520
521/**
522 * pin_to_kill - pin the watch down for removal
523 * @ih: inotify handle
524 * @watch: watch to kill
525 *
526 * Called with ih->mutex held, drops it. Possible return values:
527 * 0 - nothing to do, it has died
528 * 1 - remove it, drop the reference and deactivate_super()
529 */
530static int pin_to_kill(struct inotify_handle *ih, struct inotify_watch *watch)
531{
532 struct super_block *sb = watch->inode->i_sb;
533
534 if (atomic_inc_not_zero(&sb->s_active)) {
535 get_inotify_watch(watch);
536 mutex_unlock(&ih->mutex);
537 return 1; /* the best outcome */
538 }
539 spin_lock(&sb_lock);
540 sb->s_count++;
541 spin_unlock(&sb_lock);
542 mutex_unlock(&ih->mutex); /* can't grab ->s_umount under it */
543 down_read(&sb->s_umount);
544 /* fs is already shut down; the watch is dead */
545 drop_super(sb);
546 return 0;
547}
548
549static void unpin_and_kill(struct inotify_watch *watch)
550{
551 struct super_block *sb = watch->inode->i_sb;
552 put_inotify_watch(watch);
553 deactivate_super(sb);
554}
555
556/**
557 * inotify_destroy - clean up and destroy an inotify instance
558 * @ih: inotify handle
559 */
560void inotify_destroy(struct inotify_handle *ih)
561{
562 /*
563 * Destroy all of the watches for this handle. Unfortunately, not very
564 * pretty. We cannot do a simple iteration over the list, because we
565 * do not know the inode until we iterate to the watch. But we need to
566 * hold inode->inotify_mutex before ih->mutex. The following works.
567 *
568 * AV: it had to become even uglier to start working ;-/
569 */
570 while (1) {
571 struct inotify_watch *watch;
572 struct list_head *watches;
573 struct super_block *sb;
574 struct inode *inode;
575
576 mutex_lock(&ih->mutex);
577 watches = &ih->watches;
578 if (list_empty(watches)) {
579 mutex_unlock(&ih->mutex);
580 break;
581 }
582 watch = list_first_entry(watches, struct inotify_watch, h_list);
583 sb = watch->inode->i_sb;
584 if (!pin_to_kill(ih, watch))
585 continue;
586
587 inode = watch->inode;
588 mutex_lock(&inode->inotify_mutex);
589 mutex_lock(&ih->mutex);
590
591 /* make sure we didn't race with another list removal */
592 if (likely(idr_find(&ih->idr, watch->wd))) {
593 remove_watch_no_event(watch, ih);
594 put_inotify_watch(watch);
595 }
596
597 mutex_unlock(&ih->mutex);
598 mutex_unlock(&inode->inotify_mutex);
599 unpin_and_kill(watch);
600 }
601
602 /* free this handle: the put matching the get in inotify_init() */
603 put_inotify_handle(ih);
604}
605EXPORT_SYMBOL_GPL(inotify_destroy);
606
607/**
608 * inotify_find_watch - find an existing watch for an (ih,inode) pair
609 * @ih: inotify handle
610 * @inode: inode to watch
611 * @watchp: pointer to existing inotify_watch
612 *
613 * Caller must pin given inode (via nameidata).
614 */
615s32 inotify_find_watch(struct inotify_handle *ih, struct inode *inode,
616 struct inotify_watch **watchp)
617{
618 struct inotify_watch *old;
619 int ret = -ENOENT;
620
621 mutex_lock(&inode->inotify_mutex);
622 mutex_lock(&ih->mutex);
623
624 old = inode_find_handle(inode, ih);
625 if (unlikely(old)) {
626 get_inotify_watch(old); /* caller must put watch */
627 *watchp = old;
628 ret = old->wd;
629 }
630
631 mutex_unlock(&ih->mutex);
632 mutex_unlock(&inode->inotify_mutex);
633
634 return ret;
635}
636EXPORT_SYMBOL_GPL(inotify_find_watch);
637
638/**
639 * inotify_find_update_watch - find and update the mask of an existing watch
640 * @ih: inotify handle
641 * @inode: inode's watch to update
642 * @mask: mask of events to watch
643 *
644 * Caller must pin given inode (via nameidata).
645 */
646s32 inotify_find_update_watch(struct inotify_handle *ih, struct inode *inode,
647 u32 mask)
648{
649 struct inotify_watch *old;
650 int mask_add = 0;
651 int ret;
652
653 if (mask & IN_MASK_ADD)
654 mask_add = 1;
655
656 /* don't allow invalid bits: we don't want flags set */
657 mask &= IN_ALL_EVENTS | IN_ONESHOT;
658 if (unlikely(!mask))
659 return -EINVAL;
660
661 mutex_lock(&inode->inotify_mutex);
662 mutex_lock(&ih->mutex);
663
664 /*
665 * Handle the case of re-adding a watch on an (inode,ih) pair that we
666 * are already watching. We just update the mask and return its wd.
667 */
668 old = inode_find_handle(inode, ih);
669 if (unlikely(!old)) {
670 ret = -ENOENT;
671 goto out;
672 }
673
674 if (mask_add)
675 old->mask |= mask;
676 else
677 old->mask = mask;
678 ret = old->wd;
679out:
680 mutex_unlock(&ih->mutex);
681 mutex_unlock(&inode->inotify_mutex);
682 return ret;
683}
684EXPORT_SYMBOL_GPL(inotify_find_update_watch);
685
686/**
687 * inotify_add_watch - add a watch to an inotify instance
688 * @ih: inotify handle
689 * @watch: caller allocated watch structure
690 * @inode: inode to watch
691 * @mask: mask of events to watch
692 *
693 * Caller must pin given inode (via nameidata).
694 * Caller must ensure it only calls inotify_add_watch() once per watch.
695 * Calls inotify_handle_get_wd() so may sleep.
696 */
697s32 inotify_add_watch(struct inotify_handle *ih, struct inotify_watch *watch,
698 struct inode *inode, u32 mask)
699{
700 int ret = 0;
701 int newly_watched;
702
703 /* don't allow invalid bits: we don't want flags set */
704 mask &= IN_ALL_EVENTS | IN_ONESHOT;
705 if (unlikely(!mask))
706 return -EINVAL;
707 watch->mask = mask;
708
709 mutex_lock(&inode->inotify_mutex);
710 mutex_lock(&ih->mutex);
711
712 /* Initialize a new watch */
713 ret = inotify_handle_get_wd(ih, watch);
714 if (unlikely(ret))
715 goto out;
716 ret = watch->wd;
717
718 /* save a reference to handle and bump the count to make it official */
719 get_inotify_handle(ih);
720 watch->ih = ih;
721
722 /*
723 * Save a reference to the inode and bump the ref count to make it
724 * official. We hold a reference to nameidata, which makes this safe.
725 */
726 watch->inode = igrab(inode);
727
728 /* Add the watch to the handle's and the inode's list */
729 newly_watched = !inotify_inode_watched(inode);
730 list_add(&watch->h_list, &ih->watches);
731 list_add(&watch->i_list, &inode->inotify_watches);
732 /*
733 * Set child flags _after_ adding the watch, so there is no race
734 * windows where newly instantiated children could miss their parent's
735 * watched flag.
736 */
737 if (newly_watched)
738 set_dentry_child_flags(inode, 1);
739
740out:
741 mutex_unlock(&ih->mutex);
742 mutex_unlock(&inode->inotify_mutex);
743 return ret;
744}
745EXPORT_SYMBOL_GPL(inotify_add_watch);
746
747/**
748 * inotify_clone_watch - put the watch next to existing one
749 * @old: already installed watch
750 * @new: new watch
751 *
752 * Caller must hold the inotify_mutex of inode we are dealing with;
753 * it is expected to remove the old watch before unlocking the inode.
754 */
755s32 inotify_clone_watch(struct inotify_watch *old, struct inotify_watch *new)
756{
757 struct inotify_handle *ih = old->ih;
758 int ret = 0;
759
760 new->mask = old->mask;
761 new->ih = ih;
762
763 mutex_lock(&ih->mutex);
764
765 /* Initialize a new watch */
766 ret = inotify_handle_get_wd(ih, new);
767 if (unlikely(ret))
768 goto out;
769 ret = new->wd;
770
771 get_inotify_handle(ih);
772
773 new->inode = igrab(old->inode);
774
775 list_add(&new->h_list, &ih->watches);
776 list_add(&new->i_list, &old->inode->inotify_watches);
777out:
778 mutex_unlock(&ih->mutex);
779 return ret;
780}
781
782void inotify_evict_watch(struct inotify_watch *watch)
783{
784 get_inotify_watch(watch);
785 mutex_lock(&watch->ih->mutex);
786 inotify_remove_watch_locked(watch->ih, watch);
787 mutex_unlock(&watch->ih->mutex);
788}
789
790/**
791 * inotify_rm_wd - remove a watch from an inotify instance
792 * @ih: inotify handle
793 * @wd: watch descriptor to remove
794 *
795 * Can sleep.
796 */
797int inotify_rm_wd(struct inotify_handle *ih, u32 wd)
798{
799 struct inotify_watch *watch;
800 struct super_block *sb;
801 struct inode *inode;
802
803 mutex_lock(&ih->mutex);
804 watch = idr_find(&ih->idr, wd);
805 if (unlikely(!watch)) {
806 mutex_unlock(&ih->mutex);
807 return -EINVAL;
808 }
809 sb = watch->inode->i_sb;
810 if (!pin_to_kill(ih, watch))
811 return 0;
812
813 inode = watch->inode;
814
815 mutex_lock(&inode->inotify_mutex);
816 mutex_lock(&ih->mutex);
817
818 /* make sure that we did not race */
819 if (likely(idr_find(&ih->idr, wd) == watch))
820 inotify_remove_watch_locked(ih, watch);
821
822 mutex_unlock(&ih->mutex);
823 mutex_unlock(&inode->inotify_mutex);
824 unpin_and_kill(watch);
825
826 return 0;
827}
828EXPORT_SYMBOL_GPL(inotify_rm_wd);
829
830/**
831 * inotify_rm_watch - remove a watch from an inotify instance
832 * @ih: inotify handle
833 * @watch: watch to remove
834 *
835 * Can sleep.
836 */
837int inotify_rm_watch(struct inotify_handle *ih,
838 struct inotify_watch *watch)
839{
840 return inotify_rm_wd(ih, watch->wd);
841}
842EXPORT_SYMBOL_GPL(inotify_rm_watch);
843
844/*
845 * inotify_setup - core initialization function
846 */
847static int __init inotify_setup(void)
848{
849 BUILD_BUG_ON(IN_ACCESS != FS_ACCESS);
850 BUILD_BUG_ON(IN_MODIFY != FS_MODIFY);
851 BUILD_BUG_ON(IN_ATTRIB != FS_ATTRIB);
852 BUILD_BUG_ON(IN_CLOSE_WRITE != FS_CLOSE_WRITE);
853 BUILD_BUG_ON(IN_CLOSE_NOWRITE != FS_CLOSE_NOWRITE);
854 BUILD_BUG_ON(IN_OPEN != FS_OPEN);
855 BUILD_BUG_ON(IN_MOVED_FROM != FS_MOVED_FROM);
856 BUILD_BUG_ON(IN_MOVED_TO != FS_MOVED_TO);
857 BUILD_BUG_ON(IN_CREATE != FS_CREATE);
858 BUILD_BUG_ON(IN_DELETE != FS_DELETE);
859 BUILD_BUG_ON(IN_DELETE_SELF != FS_DELETE_SELF);
860 BUILD_BUG_ON(IN_MOVE_SELF != FS_MOVE_SELF);
861 BUILD_BUG_ON(IN_Q_OVERFLOW != FS_Q_OVERFLOW);
862
863 BUILD_BUG_ON(IN_UNMOUNT != FS_UNMOUNT);
864 BUILD_BUG_ON(IN_ISDIR != FS_IN_ISDIR);
865 BUILD_BUG_ON(IN_IGNORED != FS_IN_IGNORED);
866 BUILD_BUG_ON(IN_ONESHOT != FS_IN_ONESHOT);
867
868 atomic_set(&inotify_cookie, 0);
869
870 return 0;
871}
872
873module_init(inotify_setup);
diff --git a/fs/open.c b/fs/open.c
index 5463266db9e6..94d54d3efa8b 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -29,6 +29,7 @@
29#include <linux/falloc.h> 29#include <linux/falloc.h>
30#include <linux/fs_struct.h> 30#include <linux/fs_struct.h>
31#include <linux/ima.h> 31#include <linux/ima.h>
32#include <linux/dnotify.h>
32 33
33#include "internal.h" 34#include "internal.h"
34 35
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 68ca1b0491af..e5598d2f99b9 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -771,11 +771,6 @@ struct inode {
771 struct hlist_head i_fsnotify_mark_entries; /* fsnotify mark entries */ 771 struct hlist_head i_fsnotify_mark_entries; /* fsnotify mark entries */
772#endif 772#endif
773 773
774#ifdef CONFIG_INOTIFY
775 struct list_head inotify_watches; /* watches on this inode */
776 struct mutex inotify_mutex; /* protects the watches list */
777#endif
778
779 unsigned long i_state; 774 unsigned long i_state;
780 unsigned long dirtied_when; /* jiffies of first dirtying */ 775 unsigned long dirtied_when; /* jiffies of first dirtying */
781 776
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index 01755909ce81..f958e93feb97 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -11,8 +11,6 @@
11 * (C) Copyright 2005 Robert Love 11 * (C) Copyright 2005 Robert Love
12 */ 12 */
13 13
14#include <linux/dnotify.h>
15#include <linux/inotify.h>
16#include <linux/fsnotify_backend.h> 14#include <linux/fsnotify_backend.h>
17#include <linux/audit.h> 15#include <linux/audit.h>
18#include <linux/slab.h> 16#include <linux/slab.h>
@@ -25,16 +23,12 @@ static inline void fsnotify_d_instantiate(struct dentry *entry,
25 struct inode *inode) 23 struct inode *inode)
26{ 24{
27 __fsnotify_d_instantiate(entry, inode); 25 __fsnotify_d_instantiate(entry, inode);
28
29 inotify_d_instantiate(entry, inode);
30} 26}
31 27
32/* Notify this dentry's parent about a child's events. */ 28/* Notify this dentry's parent about a child's events. */
33static inline void fsnotify_parent(struct dentry *dentry, __u32 mask) 29static inline void fsnotify_parent(struct dentry *dentry, __u32 mask)
34{ 30{
35 __fsnotify_parent(dentry, mask); 31 __fsnotify_parent(dentry, mask);
36
37 inotify_dentry_parent_queue_event(dentry, mask, 0, dentry->d_name.name);
38} 32}
39 33
40/* 34/*
@@ -48,8 +42,6 @@ static inline void fsnotify_d_move(struct dentry *entry)
48 * cares about events from this entry. 42 * cares about events from this entry.
49 */ 43 */
50 __fsnotify_update_dcache_flags(entry); 44 __fsnotify_update_dcache_flags(entry);
51
52 inotify_d_move(entry);
53} 45}
54 46
55/* 47/*
@@ -57,8 +49,6 @@ static inline void fsnotify_d_move(struct dentry *entry)
57 */ 49 */
58static inline void fsnotify_link_count(struct inode *inode) 50static inline void fsnotify_link_count(struct inode *inode)
59{ 51{
60 inotify_inode_queue_event(inode, IN_ATTRIB, 0, NULL, NULL);
61
62 fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0); 52 fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
63} 53}
64 54
@@ -70,7 +60,6 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
70 int isdir, struct inode *target, struct dentry *moved) 60 int isdir, struct inode *target, struct dentry *moved)
71{ 61{
72 struct inode *source = moved->d_inode; 62 struct inode *source = moved->d_inode;
73 u32 in_cookie = inotify_get_cookie();
74 u32 fs_cookie = fsnotify_get_cookie(); 63 u32 fs_cookie = fsnotify_get_cookie();
75 __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM); 64 __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM);
76 __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO); 65 __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO);
@@ -80,31 +69,18 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
80 old_dir_mask |= FS_DN_RENAME; 69 old_dir_mask |= FS_DN_RENAME;
81 70
82 if (isdir) { 71 if (isdir) {
83 isdir = IN_ISDIR;
84 old_dir_mask |= FS_IN_ISDIR; 72 old_dir_mask |= FS_IN_ISDIR;
85 new_dir_mask |= FS_IN_ISDIR; 73 new_dir_mask |= FS_IN_ISDIR;
86 } 74 }
87 75
88 inotify_inode_queue_event(old_dir, IN_MOVED_FROM|isdir, in_cookie, old_name,
89 source);
90 inotify_inode_queue_event(new_dir, IN_MOVED_TO|isdir, in_cookie, new_name,
91 source);
92
93 fsnotify(old_dir, old_dir_mask, old_dir, FSNOTIFY_EVENT_INODE, old_name, fs_cookie); 76 fsnotify(old_dir, old_dir_mask, old_dir, FSNOTIFY_EVENT_INODE, old_name, fs_cookie);
94 fsnotify(new_dir, new_dir_mask, new_dir, FSNOTIFY_EVENT_INODE, new_name, fs_cookie); 77 fsnotify(new_dir, new_dir_mask, new_dir, FSNOTIFY_EVENT_INODE, new_name, fs_cookie);
95 78
96 if (target) { 79 if (target)
97 inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL, NULL);
98 inotify_inode_is_dead(target);
99
100 /* this is really a link_count change not a removal */
101 fsnotify_link_count(target); 80 fsnotify_link_count(target);
102 }
103 81
104 if (source) { 82 if (source)
105 inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL, NULL);
106 fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0); 83 fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);
107 }
108 audit_inode_child(moved, new_dir); 84 audit_inode_child(moved, new_dir);
109} 85}
110 86
@@ -134,9 +110,6 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
134 */ 110 */
135static inline void fsnotify_inoderemove(struct inode *inode) 111static inline void fsnotify_inoderemove(struct inode *inode)
136{ 112{
137 inotify_inode_queue_event(inode, IN_DELETE_SELF, 0, NULL, NULL);
138 inotify_inode_is_dead(inode);
139
140 fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0); 113 fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
141 __fsnotify_inode_delete(inode); 114 __fsnotify_inode_delete(inode);
142} 115}
@@ -146,8 +119,6 @@ static inline void fsnotify_inoderemove(struct inode *inode)
146 */ 119 */
147static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) 120static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
148{ 121{
149 inotify_inode_queue_event(inode, IN_CREATE, 0, dentry->d_name.name,
150 dentry->d_inode);
151 audit_inode_child(dentry, inode); 122 audit_inode_child(dentry, inode);
152 123
153 fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0); 124 fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
@@ -160,8 +131,6 @@ static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
160 */ 131 */
161static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry) 132static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
162{ 133{
163 inotify_inode_queue_event(dir, IN_CREATE, 0, new_dentry->d_name.name,
164 inode);
165 fsnotify_link_count(inode); 134 fsnotify_link_count(inode);
166 audit_inode_child(new_dentry, dir); 135 audit_inode_child(new_dentry, dir);
167 136
@@ -176,7 +145,6 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
176 __u32 mask = (FS_CREATE | FS_IN_ISDIR); 145 __u32 mask = (FS_CREATE | FS_IN_ISDIR);
177 struct inode *d_inode = dentry->d_inode; 146 struct inode *d_inode = dentry->d_inode;
178 147
179 inotify_inode_queue_event(inode, mask, 0, dentry->d_name.name, d_inode);
180 audit_inode_child(dentry, inode); 148 audit_inode_child(dentry, inode);
181 149
182 fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0); 150 fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
@@ -193,8 +161,6 @@ static inline void fsnotify_access(struct dentry *dentry)
193 if (S_ISDIR(inode->i_mode)) 161 if (S_ISDIR(inode->i_mode))
194 mask |= FS_IN_ISDIR; 162 mask |= FS_IN_ISDIR;
195 163
196 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
197
198 fsnotify_parent(dentry, mask); 164 fsnotify_parent(dentry, mask);
199 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); 165 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
200} 166}
@@ -210,8 +176,6 @@ static inline void fsnotify_modify(struct dentry *dentry)
210 if (S_ISDIR(inode->i_mode)) 176 if (S_ISDIR(inode->i_mode))
211 mask |= FS_IN_ISDIR; 177 mask |= FS_IN_ISDIR;
212 178
213 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
214
215 fsnotify_parent(dentry, mask); 179 fsnotify_parent(dentry, mask);
216 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); 180 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
217} 181}
@@ -227,8 +191,6 @@ static inline void fsnotify_open(struct dentry *dentry)
227 if (S_ISDIR(inode->i_mode)) 191 if (S_ISDIR(inode->i_mode))
228 mask |= FS_IN_ISDIR; 192 mask |= FS_IN_ISDIR;
229 193
230 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
231
232 fsnotify_parent(dentry, mask); 194 fsnotify_parent(dentry, mask);
233 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); 195 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
234} 196}
@@ -246,8 +208,6 @@ static inline void fsnotify_close(struct file *file)
246 if (S_ISDIR(inode->i_mode)) 208 if (S_ISDIR(inode->i_mode))
247 mask |= FS_IN_ISDIR; 209 mask |= FS_IN_ISDIR;
248 210
249 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
250
251 fsnotify_parent(dentry, mask); 211 fsnotify_parent(dentry, mask);
252 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0); 212 fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
253} 213}
@@ -263,8 +223,6 @@ static inline void fsnotify_xattr(struct dentry *dentry)
263 if (S_ISDIR(inode->i_mode)) 223 if (S_ISDIR(inode->i_mode))
264 mask |= FS_IN_ISDIR; 224 mask |= FS_IN_ISDIR;
265 225
266 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
267
268 fsnotify_parent(dentry, mask); 226 fsnotify_parent(dentry, mask);
269 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); 227 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
270} 228}
@@ -299,14 +257,12 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
299 if (mask) { 257 if (mask) {
300 if (S_ISDIR(inode->i_mode)) 258 if (S_ISDIR(inode->i_mode))
301 mask |= FS_IN_ISDIR; 259 mask |= FS_IN_ISDIR;
302 inotify_inode_queue_event(inode, mask, 0, NULL, NULL);
303
304 fsnotify_parent(dentry, mask); 260 fsnotify_parent(dentry, mask);
305 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); 261 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
306 } 262 }
307} 263}
308 264
309#if defined(CONFIG_INOTIFY) || defined(CONFIG_FSNOTIFY) /* notify helpers */ 265#if defined(CONFIG_FSNOTIFY) /* notify helpers */
310 266
311/* 267/*
312 * fsnotify_oldname_init - save off the old filename before we change it 268 * fsnotify_oldname_init - save off the old filename before we change it
diff --git a/include/linux/inotify.h b/include/linux/inotify.h
index 37ea2894b3c0..959a38b8f75d 100644
--- a/include/linux/inotify.h
+++ b/include/linux/inotify.h
@@ -69,178 +69,4 @@ struct inotify_event {
69#define IN_CLOEXEC O_CLOEXEC 69#define IN_CLOEXEC O_CLOEXEC
70#define IN_NONBLOCK O_NONBLOCK 70#define IN_NONBLOCK O_NONBLOCK
71 71
72#ifdef __KERNEL__
73
74#include <linux/dcache.h>
75#include <linux/fs.h>
76
77/*
78 * struct inotify_watch - represents a watch request on a specific inode
79 *
80 * h_list is protected by ih->mutex of the associated inotify_handle.
81 * i_list, mask are protected by inode->inotify_mutex of the associated inode.
82 * ih, inode, and wd are never written to once the watch is created.
83 *
84 * Callers must use the established inotify interfaces to access inotify_watch
85 * contents. The content of this structure is private to the inotify
86 * implementation.
87 */
88struct inotify_watch {
89 struct list_head h_list; /* entry in inotify_handle's list */
90 struct list_head i_list; /* entry in inode's list */
91 atomic_t count; /* reference count */
92 struct inotify_handle *ih; /* associated inotify handle */
93 struct inode *inode; /* associated inode */
94 __s32 wd; /* watch descriptor */
95 __u32 mask; /* event mask for this watch */
96};
97
98struct inotify_operations {
99 void (*handle_event)(struct inotify_watch *, u32, u32, u32,
100 const char *, struct inode *);
101 void (*destroy_watch)(struct inotify_watch *);
102};
103
104#ifdef CONFIG_INOTIFY
105
106/* Kernel API for producing events */
107
108extern void inotify_d_instantiate(struct dentry *, struct inode *);
109extern void inotify_d_move(struct dentry *);
110extern void inotify_inode_queue_event(struct inode *, __u32, __u32,
111 const char *, struct inode *);
112extern void inotify_dentry_parent_queue_event(struct dentry *, __u32, __u32,
113 const char *);
114extern void inotify_unmount_inodes(struct list_head *);
115extern void inotify_inode_is_dead(struct inode *);
116extern u32 inotify_get_cookie(void);
117
118/* Kernel Consumer API */
119
120extern struct inotify_handle *inotify_init(const struct inotify_operations *);
121extern void inotify_init_watch(struct inotify_watch *);
122extern void inotify_destroy(struct inotify_handle *);
123extern __s32 inotify_find_watch(struct inotify_handle *, struct inode *,
124 struct inotify_watch **);
125extern __s32 inotify_find_update_watch(struct inotify_handle *, struct inode *,
126 u32);
127extern __s32 inotify_add_watch(struct inotify_handle *, struct inotify_watch *,
128 struct inode *, __u32);
129extern __s32 inotify_clone_watch(struct inotify_watch *, struct inotify_watch *);
130extern void inotify_evict_watch(struct inotify_watch *);
131extern int inotify_rm_watch(struct inotify_handle *, struct inotify_watch *);
132extern int inotify_rm_wd(struct inotify_handle *, __u32);
133extern void inotify_remove_watch_locked(struct inotify_handle *,
134 struct inotify_watch *);
135extern void get_inotify_watch(struct inotify_watch *);
136extern void put_inotify_watch(struct inotify_watch *);
137extern int pin_inotify_watch(struct inotify_watch *);
138extern void unpin_inotify_watch(struct inotify_watch *);
139
140#else
141
142static inline void inotify_d_instantiate(struct dentry *dentry,
143 struct inode *inode)
144{
145}
146
147static inline void inotify_d_move(struct dentry *dentry)
148{
149}
150
151static inline void inotify_inode_queue_event(struct inode *inode,
152 __u32 mask, __u32 cookie,
153 const char *filename,
154 struct inode *n_inode)
155{
156}
157
158static inline void inotify_dentry_parent_queue_event(struct dentry *dentry,
159 __u32 mask, __u32 cookie,
160 const char *filename)
161{
162}
163
164static inline void inotify_unmount_inodes(struct list_head *list)
165{
166}
167
168static inline void inotify_inode_is_dead(struct inode *inode)
169{
170}
171
172static inline u32 inotify_get_cookie(void)
173{
174 return 0;
175}
176
177static inline struct inotify_handle *inotify_init(const struct inotify_operations *ops)
178{
179 return ERR_PTR(-EOPNOTSUPP);
180}
181
182static inline void inotify_init_watch(struct inotify_watch *watch)
183{
184}
185
186static inline void inotify_destroy(struct inotify_handle *ih)
187{
188}
189
190static inline __s32 inotify_find_watch(struct inotify_handle *ih, struct inode *inode,
191 struct inotify_watch **watchp)
192{
193 return -EOPNOTSUPP;
194}
195
196static inline __s32 inotify_find_update_watch(struct inotify_handle *ih,
197 struct inode *inode, u32 mask)
198{
199 return -EOPNOTSUPP;
200}
201
202static inline __s32 inotify_add_watch(struct inotify_handle *ih,
203 struct inotify_watch *watch,
204 struct inode *inode, __u32 mask)
205{
206 return -EOPNOTSUPP;
207}
208
209static inline int inotify_rm_watch(struct inotify_handle *ih,
210 struct inotify_watch *watch)
211{
212 return -EOPNOTSUPP;
213}
214
215static inline int inotify_rm_wd(struct inotify_handle *ih, __u32 wd)
216{
217 return -EOPNOTSUPP;
218}
219
220static inline void inotify_remove_watch_locked(struct inotify_handle *ih,
221 struct inotify_watch *watch)
222{
223}
224
225static inline void get_inotify_watch(struct inotify_watch *watch)
226{
227}
228
229static inline void put_inotify_watch(struct inotify_watch *watch)
230{
231}
232
233extern inline int pin_inotify_watch(struct inotify_watch *watch)
234{
235 return 0;
236}
237
238extern inline void unpin_inotify_watch(struct inotify_watch *watch)
239{
240}
241
242#endif /* CONFIG_INOTIFY */
243
244#endif /* __KERNEL __ */
245
246#endif /* _LINUX_INOTIFY_H */ 72#endif /* _LINUX_INOTIFY_H */
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 786901cd8217..853185f7ba7e 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -65,7 +65,6 @@
65#include <linux/binfmts.h> 65#include <linux/binfmts.h>
66#include <linux/highmem.h> 66#include <linux/highmem.h>
67#include <linux/syscalls.h> 67#include <linux/syscalls.h>
68#include <linux/inotify.h>
69#include <linux/capability.h> 68#include <linux/capability.h>
70#include <linux/fs_struct.h> 69#include <linux/fs_struct.h>
71 70