2 * fs/inotify.c - inode-based file event notifications
5 * John McCutchan <ttb@tentacle.dhs.org>
6 * Robert Love <rml@novell.com>
8 * Copyright (C) 2005 John McCutchan
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2, or (at your option) any
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/sched.h>
24 #include <linux/spinlock.h>
25 #include <linux/idr.h>
26 #include <linux/slab.h>
28 #include <linux/file.h>
29 #include <linux/mount.h>
30 #include <linux/namei.h>
31 #include <linux/poll.h>
32 #include <linux/device.h>
33 #include <linux/miscdevice.h>
34 #include <linux/init.h>
35 #include <linux/list.h>
36 #include <linux/writeback.h>
37 #include <linux/inotify.h>
39 #include <asm/ioctls.h>
41 static atomic_t inotify_cookie;
43 static kmem_cache_t *watch_cachep;
44 static kmem_cache_t *event_cachep;
46 static struct vfsmount *inotify_mnt;
48 /* these are configurable via /proc/sys/fs/inotify/ */
49 int inotify_max_user_instances;
50 int inotify_max_user_watches;
51 int inotify_max_queued_events;
56 * dentry->d_lock (used to keep d_move() away from dentry->d_parent)
57 * iprune_sem (synchronize shrink_icache_memory())
58 * inode_lock (protects the super_block->s_inodes list)
59 * inode->inotify_sem (protects inode->inotify_watches and watches->i_list)
60 * inotify_dev->sem (protects inotify_device and watches->d_list)
64 * Lifetimes of the three main data structures--inotify_device, inode, and
65 * inotify_watch--are managed by reference count.
67 * inotify_device: Lifetime is from open until release. Additional references
68 * can bump the count via get_inotify_dev() and drop the count via
71 * inotify_watch: Lifetime is from create_watch() to destory_watch().
72 * Additional references can bump the count via get_inotify_watch() and drop
73 * the count via put_inotify_watch().
75 * inode: Pinned so long as the inode is associated with a watch, from
76 * create_watch() to put_inotify_watch().
80 * struct inotify_device - represents an open instance of an inotify device
82 * This structure is protected by the semaphore 'sem'.
84 struct inotify_device {
85 wait_queue_head_t wq; /* wait queue for i/o */
86 struct idr idr; /* idr mapping wd -> watch */
87 struct semaphore sem; /* protects this bad boy */
88 struct list_head events; /* list of queued events */
89 struct list_head watches; /* list of watches */
90 atomic_t count; /* reference count */
91 struct user_struct *user; /* user who opened this dev */
92 unsigned int queue_size; /* size of the queue (bytes) */
93 unsigned int event_count; /* number of pending events */
94 unsigned int max_events; /* maximum number of events */
98 * struct inotify_kernel_event - An inotify event, originating from a watch and
99 * queued for user-space. A list of these is attached to each instance of the
100 * device. In read(), this list is walked and all events that can fit in the
101 * buffer are returned.
103 * Protected by dev->sem of the device in which we are queued.
105 struct inotify_kernel_event {
106 struct inotify_event event; /* the user-space event */
107 struct list_head list; /* entry in inotify_device's list */
108 char *name; /* filename, if any */
112 * struct inotify_watch - represents a watch request on a specific inode
114 * d_list is protected by dev->sem of the associated watch->dev.
115 * i_list and mask are protected by inode->inotify_sem of the associated inode.
116 * dev, inode, and wd are never written to once the watch is created.
118 struct inotify_watch {
119 struct list_head d_list; /* entry in inotify_device's list */
120 struct list_head i_list; /* entry in inode's list */
121 atomic_t count; /* reference count */
122 struct inotify_device *dev; /* associated device */
123 struct inode *inode; /* associated inode */
124 s32 wd; /* watch descriptor */
125 u32 mask; /* event mask for this watch */
130 #include <linux/sysctl.h>
134 ctl_table inotify_table[] = {
136 .ctl_name = INOTIFY_MAX_USER_INSTANCES,
137 .procname = "max_user_instances",
138 .data = &inotify_max_user_instances,
139 .maxlen = sizeof(int),
141 .proc_handler = &proc_dointvec_minmax,
142 .strategy = &sysctl_intvec,
146 .ctl_name = INOTIFY_MAX_USER_WATCHES,
147 .procname = "max_user_watches",
148 .data = &inotify_max_user_watches,
149 .maxlen = sizeof(int),
151 .proc_handler = &proc_dointvec_minmax,
152 .strategy = &sysctl_intvec,
156 .ctl_name = INOTIFY_MAX_QUEUED_EVENTS,
157 .procname = "max_queued_events",
158 .data = &inotify_max_queued_events,
159 .maxlen = sizeof(int),
161 .proc_handler = &proc_dointvec_minmax,
162 .strategy = &sysctl_intvec,
167 #endif /* CONFIG_SYSCTL */
169 static inline void get_inotify_dev(struct inotify_device *dev)
171 atomic_inc(&dev->count);
174 static inline void put_inotify_dev(struct inotify_device *dev)
176 if (atomic_dec_and_test(&dev->count)) {
177 atomic_dec(&dev->user->inotify_devs);
183 static inline void get_inotify_watch(struct inotify_watch *watch)
185 atomic_inc(&watch->count);
189 * put_inotify_watch - decrements the ref count on a given watch. cleans up
190 * the watch and its references if the count reaches zero.
192 static inline void put_inotify_watch(struct inotify_watch *watch)
194 if (atomic_dec_and_test(&watch->count)) {
195 put_inotify_dev(watch->dev);
197 kmem_cache_free(watch_cachep, watch);
202 * kernel_event - create a new kernel event with the given parameters
204 * This function can sleep.
206 static struct inotify_kernel_event * kernel_event(s32 wd, u32 mask, u32 cookie,
209 struct inotify_kernel_event *kevent;
211 kevent = kmem_cache_alloc(event_cachep, GFP_KERNEL);
212 if (unlikely(!kevent))
215 /* we hand this out to user-space, so zero it just in case */
216 memset(&kevent->event, 0, sizeof(struct inotify_event));
218 kevent->event.wd = wd;
219 kevent->event.mask = mask;
220 kevent->event.cookie = cookie;
222 INIT_LIST_HEAD(&kevent->list);
225 size_t len, rem, event_size = sizeof(struct inotify_event);
228 * We need to pad the filename so as to properly align an
229 * array of inotify_event structures. Because the structure is
230 * small and the common case is a small filename, we just round
231 * up to the next multiple of the structure's sizeof. This is
232 * simple and safe for all architectures.
234 len = strlen(name) + 1;
235 rem = event_size - len;
236 if (len > event_size) {
237 rem = event_size - (len % event_size);
238 if (len % event_size == 0)
242 kevent->name = kmalloc(len + rem, GFP_KERNEL);
243 if (unlikely(!kevent->name)) {
244 kmem_cache_free(event_cachep, kevent);
247 memcpy(kevent->name, name, len);
249 memset(kevent->name + len, 0, rem);
250 kevent->event.len = len + rem;
252 kevent->event.len = 0;
260 * inotify_dev_get_event - return the next event in the given dev's queue
262 * Caller must hold dev->sem.
264 static inline struct inotify_kernel_event *
265 inotify_dev_get_event(struct inotify_device *dev)
267 return list_entry(dev->events.next, struct inotify_kernel_event, list);
271 * inotify_dev_queue_event - add a new event to the given device
273 * Caller must hold dev->sem. Can sleep (calls kernel_event()).
275 static void inotify_dev_queue_event(struct inotify_device *dev,
276 struct inotify_watch *watch, u32 mask,
277 u32 cookie, const char *name)
279 struct inotify_kernel_event *kevent, *last;
281 /* coalescing: drop this event if it is a dupe of the previous */
282 last = inotify_dev_get_event(dev);
283 if (last && last->event.mask == mask && last->event.wd == watch->wd &&
284 last->event.cookie == cookie) {
285 const char *lastname = last->name;
287 if (!name && !lastname)
289 if (name && lastname && !strcmp(lastname, name))
293 /* the queue overflowed and we already sent the Q_OVERFLOW event */
294 if (unlikely(dev->event_count > dev->max_events))
297 /* if the queue overflows, we need to notify user space */
298 if (unlikely(dev->event_count == dev->max_events))
299 kevent = kernel_event(-1, IN_Q_OVERFLOW, cookie, NULL);
301 kevent = kernel_event(watch->wd, mask, cookie, name);
303 if (unlikely(!kevent))
306 /* queue the event and wake up anyone waiting */
308 dev->queue_size += sizeof(struct inotify_event) + kevent->event.len;
309 list_add_tail(&kevent->list, &dev->events);
310 wake_up_interruptible(&dev->wq);
314 * remove_kevent - cleans up and ultimately frees the given kevent
316 * Caller must hold dev->sem.
318 static void remove_kevent(struct inotify_device *dev,
319 struct inotify_kernel_event *kevent)
321 list_del(&kevent->list);
324 dev->queue_size -= sizeof(struct inotify_event) + kevent->event.len;
327 kmem_cache_free(event_cachep, kevent);
331 * inotify_dev_event_dequeue - destroy an event on the given device
333 * Caller must hold dev->sem.
335 static void inotify_dev_event_dequeue(struct inotify_device *dev)
337 if (!list_empty(&dev->events)) {
338 struct inotify_kernel_event *kevent;
339 kevent = inotify_dev_get_event(dev);
340 remove_kevent(dev, kevent);
345 * inotify_dev_get_wd - returns the next WD for use by the given dev
347 * Callers must hold dev->sem. This function can sleep.
349 static int inotify_dev_get_wd(struct inotify_device *dev,
350 struct inotify_watch *watch)
355 if (unlikely(!idr_pre_get(&dev->idr, GFP_KERNEL)))
357 ret = idr_get_new(&dev->idr, watch, &watch->wd);
358 } while (ret == -EAGAIN);
364 * find_inode - resolve a user-given path to a specific inode and return a nd
366 static int find_inode(const char __user *dirname, struct nameidata *nd)
370 error = __user_walk(dirname, LOOKUP_FOLLOW, nd);
373 /* you can only watch an inode if you have read permissions on it */
374 error = permission(nd->dentry->d_inode, MAY_READ, NULL);
381 * create_watch - creates a watch on the given device.
383 * Callers must hold dev->sem. Calls inotify_dev_get_wd() so may sleep.
384 * Both 'dev' and 'inode' (by way of nameidata) need to be pinned.
386 static struct inotify_watch *create_watch(struct inotify_device *dev,
387 u32 mask, struct inode *inode)
389 struct inotify_watch *watch;
392 if (atomic_read(&dev->user->inotify_watches) >= inotify_max_user_watches)
393 return ERR_PTR(-ENOSPC);
395 watch = kmem_cache_alloc(watch_cachep, GFP_KERNEL);
396 if (unlikely(!watch))
397 return ERR_PTR(-ENOMEM);
399 ret = inotify_dev_get_wd(dev, watch);
401 kmem_cache_free(watch_cachep, watch);
406 atomic_set(&watch->count, 0);
407 INIT_LIST_HEAD(&watch->d_list);
408 INIT_LIST_HEAD(&watch->i_list);
410 /* save a reference to device and bump the count to make it official */
411 get_inotify_dev(dev);
415 * Save a reference to the inode and bump the ref count to make it
416 * official. We hold a reference to nameidata, which makes this safe.
418 watch->inode = igrab(inode);
420 /* bump our own count, corresponding to our entry in dev->watches */
421 get_inotify_watch(watch);
423 atomic_inc(&dev->user->inotify_watches);
429 * inotify_find_dev - find the watch associated with the given inode and dev
431 * Callers must hold inode->inotify_sem.
433 static struct inotify_watch *inode_find_dev(struct inode *inode,
434 struct inotify_device *dev)
436 struct inotify_watch *watch;
438 list_for_each_entry(watch, &inode->inotify_watches, i_list) {
439 if (watch->dev == dev)
447 * remove_watch_no_event - remove_watch() without the IN_IGNORED event.
449 static void remove_watch_no_event(struct inotify_watch *watch,
450 struct inotify_device *dev)
452 list_del(&watch->i_list);
453 list_del(&watch->d_list);
455 atomic_dec(&dev->user->inotify_watches);
456 idr_remove(&dev->idr, watch->wd);
457 put_inotify_watch(watch);
461 * remove_watch - Remove a watch from both the device and the inode. Sends
462 * the IN_IGNORED event to the given device signifying that the inode is no
465 * Callers must hold both inode->inotify_sem and dev->sem. We drop a
466 * reference to the inode before returning.
468 * The inode is not iput() so as to remain atomic. If the inode needs to be
469 * iput(), the call returns one. Otherwise, it returns zero.
471 static void remove_watch(struct inotify_watch *watch,struct inotify_device *dev)
473 inotify_dev_queue_event(dev, watch, IN_IGNORED, 0, NULL);
474 remove_watch_no_event(watch, dev);
478 * inotify_inode_watched - returns nonzero if there are watches on this inode
479 * and zero otherwise. We call this lockless, we do not care if we race.
481 static inline int inotify_inode_watched(struct inode *inode)
483 return !list_empty(&inode->inotify_watches);
489 * inotify_inode_queue_event - queue an event to all watches on this inode
490 * @inode: inode event is originating from
491 * @mask: event mask describing this event
492 * @cookie: cookie for synchronization, or zero
493 * @name: filename, if any
495 void inotify_inode_queue_event(struct inode *inode, u32 mask, u32 cookie,
498 struct inotify_watch *watch, *next;
500 if (!inotify_inode_watched(inode))
503 down(&inode->inotify_sem);
504 list_for_each_entry_safe(watch, next, &inode->inotify_watches, i_list) {
505 u32 watch_mask = watch->mask;
506 if (watch_mask & mask) {
507 struct inotify_device *dev = watch->dev;
508 get_inotify_watch(watch);
510 inotify_dev_queue_event(dev, watch, mask, cookie, name);
511 if (watch_mask & IN_ONESHOT)
512 remove_watch_no_event(watch, dev);
514 put_inotify_watch(watch);
517 up(&inode->inotify_sem);
519 EXPORT_SYMBOL_GPL(inotify_inode_queue_event);
522 * inotify_dentry_parent_queue_event - queue an event to a dentry's parent
523 * @dentry: the dentry in question, we queue against this dentry's parent
524 * @mask: event mask describing this event
525 * @cookie: cookie for synchronization, or zero
526 * @name: filename, if any
528 void inotify_dentry_parent_queue_event(struct dentry *dentry, u32 mask,
529 u32 cookie, const char *name)
531 struct dentry *parent;
534 spin_lock(&dentry->d_lock);
535 parent = dentry->d_parent;
536 inode = parent->d_inode;
538 if (inotify_inode_watched(inode)) {
540 spin_unlock(&dentry->d_lock);
541 inotify_inode_queue_event(inode, mask, cookie, name);
544 spin_unlock(&dentry->d_lock);
546 EXPORT_SYMBOL_GPL(inotify_dentry_parent_queue_event);
549 * inotify_get_cookie - return a unique cookie for use in synchronizing events.
551 u32 inotify_get_cookie(void)
553 return atomic_inc_return(&inotify_cookie);
555 EXPORT_SYMBOL_GPL(inotify_get_cookie);
558 * inotify_unmount_inodes - an sb is unmounting. handle any watched inodes.
559 * @list: list of inodes being unmounted (sb->s_inodes)
561 * Called with inode_lock held, protecting the unmounting super block's list
562 * of inodes, and with iprune_sem held, keeping shrink_icache_memory() at bay.
563 * We temporarily drop inode_lock, however, and CAN block.
565 void inotify_unmount_inodes(struct list_head *list)
567 struct inode *inode, *next_i, *need_iput = NULL;
569 list_for_each_entry_safe(inode, next_i, list, i_sb_list) {
570 struct inotify_watch *watch, *next_w;
571 struct inode *need_iput_tmp;
572 struct list_head *watches;
575 * If i_count is zero, the inode cannot have any watches and
576 * doing an __iget/iput with MS_ACTIVE clear would actually
577 * evict all inodes with zero i_count from icache which is
578 * unnecessarily violent and may in fact be illegal to do.
580 if (!atomic_read(&inode->i_count))
584 * We cannot __iget() an inode in state I_CLEAR, I_FREEING, or
585 * I_WILL_FREE which is fine because by that point the inode
586 * cannot have any associated watches.
588 if (inode->i_state & (I_CLEAR | I_FREEING | I_WILL_FREE))
591 need_iput_tmp = need_iput;
593 /* In case the remove_watch() drops a reference. */
594 if (inode != need_iput_tmp)
597 need_iput_tmp = NULL;
598 /* In case the dropping of a reference would nuke next_i. */
599 if ((&next_i->i_sb_list != list) &&
600 atomic_read(&next_i->i_count) &&
601 !(next_i->i_state & (I_CLEAR | I_FREEING |
608 * We can safely drop inode_lock here because we hold
609 * references on both inode and next_i. Also no new inodes
610 * will be added since the umount has begun. Finally,
611 * iprune_sem keeps shrink_icache_memory() away.
613 spin_unlock(&inode_lock);
618 /* for each watch, send IN_UNMOUNT and then remove it */
619 down(&inode->inotify_sem);
620 watches = &inode->inotify_watches;
621 list_for_each_entry_safe(watch, next_w, watches, i_list) {
622 struct inotify_device *dev = watch->dev;
624 inotify_dev_queue_event(dev, watch, IN_UNMOUNT,0,NULL);
625 remove_watch(watch, dev);
628 up(&inode->inotify_sem);
631 spin_lock(&inode_lock);
634 EXPORT_SYMBOL_GPL(inotify_unmount_inodes);
637 * inotify_inode_is_dead - an inode has been deleted, cleanup any watches
638 * @inode: inode that is about to be removed
640 void inotify_inode_is_dead(struct inode *inode)
642 struct inotify_watch *watch, *next;
644 down(&inode->inotify_sem);
645 list_for_each_entry_safe(watch, next, &inode->inotify_watches, i_list) {
646 struct inotify_device *dev = watch->dev;
648 remove_watch(watch, dev);
651 up(&inode->inotify_sem);
653 EXPORT_SYMBOL_GPL(inotify_inode_is_dead);
655 /* Device Interface */
657 static unsigned int inotify_poll(struct file *file, poll_table *wait)
659 struct inotify_device *dev = file->private_data;
662 poll_wait(file, &dev->wq, wait);
664 if (!list_empty(&dev->events))
665 ret = POLLIN | POLLRDNORM;
671 static ssize_t inotify_read(struct file *file, char __user *buf,
672 size_t count, loff_t *pos)
674 size_t event_size = sizeof (struct inotify_event);
675 struct inotify_device *dev;
681 dev = file->private_data;
686 prepare_to_wait(&dev->wq, &wait, TASK_INTERRUPTIBLE);
689 events = !list_empty(&dev->events);
696 if (file->f_flags & O_NONBLOCK) {
701 if (signal_pending(current)) {
709 finish_wait(&dev->wq, &wait);
715 struct inotify_kernel_event *kevent;
718 if (list_empty(&dev->events))
721 kevent = inotify_dev_get_event(dev);
722 if (event_size + kevent->event.len > count)
725 if (copy_to_user(buf, &kevent->event, event_size)) {
733 if (copy_to_user(buf, kevent->name, kevent->event.len)){
737 buf += kevent->event.len;
738 count -= kevent->event.len;
741 remove_kevent(dev, kevent);
748 static int inotify_release(struct inode *ignored, struct file *file)
750 struct inotify_device *dev = file->private_data;
753 * Destroy all of the watches on this device. Unfortunately, not very
754 * pretty. We cannot do a simple iteration over the list, because we
755 * do not know the inode until we iterate to the watch. But we need to
756 * hold inode->inotify_sem before dev->sem. The following works.
759 struct inotify_watch *watch;
760 struct list_head *watches;
764 watches = &dev->watches;
765 if (list_empty(watches)) {
769 watch = list_entry(watches->next, struct inotify_watch, d_list);
770 get_inotify_watch(watch);
773 inode = watch->inode;
774 down(&inode->inotify_sem);
776 remove_watch_no_event(watch, dev);
778 up(&inode->inotify_sem);
779 put_inotify_watch(watch);
782 /* destroy all of the events on this device */
784 while (!list_empty(&dev->events))
785 inotify_dev_event_dequeue(dev);
788 /* free this device: the put matching the get in inotify_open() */
789 put_inotify_dev(dev);
795 * inotify_ignore - handle the INOTIFY_IGNORE ioctl, asking that a given wd be
796 * removed from the device.
800 static int inotify_ignore(struct inotify_device *dev, s32 wd)
802 struct inotify_watch *watch;
806 watch = idr_find(&dev->idr, wd);
807 if (unlikely(!watch)) {
811 get_inotify_watch(watch);
812 inode = watch->inode;
815 down(&inode->inotify_sem);
818 /* make sure that we did not race */
819 watch = idr_find(&dev->idr, wd);
821 remove_watch(watch, dev);
824 up(&inode->inotify_sem);
825 put_inotify_watch(watch);
830 static long inotify_ioctl(struct file *file, unsigned int cmd,
833 struct inotify_device *dev;
837 dev = file->private_data;
838 p = (void __user *) arg;
842 ret = put_user(dev->queue_size, (int __user *) p);
849 static struct file_operations inotify_fops = {
850 .poll = inotify_poll,
851 .read = inotify_read,
852 .release = inotify_release,
853 .unlocked_ioctl = inotify_ioctl,
854 .compat_ioctl = inotify_ioctl,
857 asmlinkage long sys_inotify_init(void)
859 struct inotify_device *dev;
860 struct user_struct *user;
865 fd = get_unused_fd();
871 filp = get_empty_filp();
877 filp->f_op = &inotify_fops;
878 filp->f_vfsmnt = mntget(inotify_mnt);
879 filp->f_dentry = dget(inotify_mnt->mnt_root);
880 filp->f_mapping = filp->f_dentry->d_inode->i_mapping;
881 filp->f_mode = FMODE_READ;
882 filp->f_flags = O_RDONLY;
884 user = get_uid(current->user);
886 if (unlikely(atomic_read(&user->inotify_devs) >= inotify_max_user_instances)) {
891 dev = kmalloc(sizeof(struct inotify_device), GFP_KERNEL);
892 if (unlikely(!dev)) {
898 INIT_LIST_HEAD(&dev->events);
899 INIT_LIST_HEAD(&dev->watches);
900 init_waitqueue_head(&dev->wq);
901 sema_init(&dev->sem, 1);
902 dev->event_count = 0;
904 dev->max_events = inotify_max_queued_events;
906 atomic_set(&dev->count, 0);
908 get_inotify_dev(dev);
909 atomic_inc(&user->inotify_devs);
911 filp->private_data = dev;
912 fd_install (fd, filp);
922 asmlinkage long sys_inotify_add_watch(int fd, const char *path, u32 mask)
924 struct inotify_watch *watch, *old;
926 struct inotify_device *dev;
935 dev = filp->private_data;
937 ret = find_inode ((const char __user*)path, &nd);
941 /* Held in place by reference in nd */
942 inode = nd.dentry->d_inode;
944 down(&inode->inotify_sem);
947 /* don't let user-space set invalid bits: we don't want flags set */
948 mask &= IN_ALL_EVENTS;
955 * Handle the case of re-adding a watch on an (inode,dev) pair that we
956 * are already watching. We just update the mask and return its wd.
958 old = inode_find_dev(inode, dev);
965 watch = create_watch(dev, mask, inode);
966 if (unlikely(IS_ERR(watch))) {
967 ret = PTR_ERR(watch);
971 /* Add the watch to the device's and the inode's list */
972 list_add(&watch->d_list, &dev->watches);
973 list_add(&watch->i_list, &inode->inotify_watches);
978 up(&inode->inotify_sem);
984 asmlinkage long sys_inotify_rm_watch(int fd, u32 wd)
987 struct inotify_device *dev;
993 dev = filp->private_data;
994 ret = inotify_ignore (dev, wd);
999 static struct super_block *
1000 inotify_get_sb(struct file_system_type *fs_type, int flags,
1001 const char *dev_name, void *data)
1003 return get_sb_pseudo(fs_type, "inotify", NULL, 0xBAD1DEA);
1006 static struct file_system_type inotify_fs_type = {
1007 .name = "inotifyfs",
1008 .get_sb = inotify_get_sb,
1009 .kill_sb = kill_anon_super,
1013 * inotify_init - Our initialization function. Note that we cannnot return
1014 * error because we have compiled-in VFS hooks. So an (unlikely) failure here
1015 * must result in panic().
1017 static int __init inotify_init(void)
1019 register_filesystem(&inotify_fs_type);
1020 inotify_mnt = kern_mount(&inotify_fs_type);
1022 inotify_max_queued_events = 8192;
1023 inotify_max_user_instances = 8;
1024 inotify_max_user_watches = 8192;
1026 atomic_set(&inotify_cookie, 0);
1028 watch_cachep = kmem_cache_create("inotify_watch_cache",
1029 sizeof(struct inotify_watch),
1030 0, SLAB_PANIC, NULL, NULL);
1031 event_cachep = kmem_cache_create("inotify_event_cache",
1032 sizeof(struct inotify_kernel_event),
1033 0, SLAB_PANIC, NULL, NULL);
1035 printk(KERN_INFO "inotify syscall\n");
1040 module_init(inotify_init);