inotify_user.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /*
  2. * fs/inotify_user.c - inotify support for userspace
  3. *
  4. * Authors:
  5. * John McCutchan <ttb@tentacle.dhs.org>
  6. * Robert Love <rml@novell.com>
  7. *
  8. * Copyright (C) 2005 John McCutchan
  9. * Copyright 2006 Hewlett-Packard Development Company, L.P.
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2, or (at your option) any
  14. * later version.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/sched.h>
  23. #include <linux/slab.h>
  24. #include <linux/fs.h>
  25. #include <linux/file.h>
  26. #include <linux/mount.h>
  27. #include <linux/namei.h>
  28. #include <linux/poll.h>
  29. #include <linux/init.h>
  30. #include <linux/list.h>
  31. #include <linux/inotify.h>
  32. #include <linux/syscalls.h>
  33. #include <asm/ioctls.h>
  34. static struct kmem_cache *watch_cachep __read_mostly;
  35. static struct kmem_cache *event_cachep __read_mostly;
  36. static struct vfsmount *inotify_mnt __read_mostly;
  37. /* these are configurable via /proc/sys/fs/inotify/ */
  38. int inotify_max_user_instances __read_mostly;
  39. int inotify_max_user_watches __read_mostly;
  40. int inotify_max_queued_events __read_mostly;
  41. /*
  42. * Lock ordering:
  43. *
  44. * inotify_dev->up_mutex (ensures we don't re-add the same watch)
  45. * inode->inotify_mutex (protects inode's watch list)
  46. * inotify_handle->mutex (protects inotify_handle's watch list)
  47. * inotify_dev->ev_mutex (protects device's event queue)
  48. */
  49. /*
  50. * Lifetimes of the main data structures:
  51. *
  52. * inotify_device: Lifetime is managed by reference count, from
  53. * sys_inotify_init() until release. Additional references can bump the count
  54. * via get_inotify_dev() and drop the count via put_inotify_dev().
  55. *
  56. * inotify_user_watch: Lifetime is from create_watch() to the receipt of an
  57. * IN_IGNORED event from inotify, or when using IN_ONESHOT, to receipt of the
  58. * first event, or to inotify_destroy().
  59. */
  60. /*
  61. * struct inotify_device - represents an inotify instance
  62. *
  63. * This structure is protected by the mutex 'mutex'.
  64. */
  65. struct inotify_device {
  66. wait_queue_head_t wq; /* wait queue for i/o */
  67. struct mutex ev_mutex; /* protects event queue */
  68. struct mutex up_mutex; /* synchronizes watch updates */
  69. struct list_head events; /* list of queued events */
  70. atomic_t count; /* reference count */
  71. struct user_struct *user; /* user who opened this dev */
  72. struct inotify_handle *ih; /* inotify handle */
  73. unsigned int queue_size; /* size of the queue (bytes) */
  74. unsigned int event_count; /* number of pending events */
  75. unsigned int max_events; /* maximum number of events */
  76. };
  77. /*
  78. * struct inotify_kernel_event - An inotify event, originating from a watch and
  79. * queued for user-space. A list of these is attached to each instance of the
  80. * device. In read(), this list is walked and all events that can fit in the
  81. * buffer are returned.
  82. *
  83. * Protected by dev->ev_mutex of the device in which we are queued.
  84. */
  85. struct inotify_kernel_event {
  86. struct inotify_event event; /* the user-space event */
  87. struct list_head list; /* entry in inotify_device's list */
  88. char *name; /* filename, if any */
  89. };
  90. /*
  91. * struct inotify_user_watch - our version of an inotify_watch, we add
  92. * a reference to the associated inotify_device.
  93. */
  94. struct inotify_user_watch {
  95. struct inotify_device *dev; /* associated device */
  96. struct inotify_watch wdata; /* inotify watch data */
  97. };
  98. #ifdef CONFIG_SYSCTL
  99. #include <linux/sysctl.h>
  100. static int zero;
  101. ctl_table inotify_table[] = {
  102. {
  103. .ctl_name = INOTIFY_MAX_USER_INSTANCES,
  104. .procname = "max_user_instances",
  105. .data = &inotify_max_user_instances,
  106. .maxlen = sizeof(int),
  107. .mode = 0644,
  108. .proc_handler = &proc_dointvec_minmax,
  109. .strategy = &sysctl_intvec,
  110. .extra1 = &zero,
  111. },
  112. {
  113. .ctl_name = INOTIFY_MAX_USER_WATCHES,
  114. .procname = "max_user_watches",
  115. .data = &inotify_max_user_watches,
  116. .maxlen = sizeof(int),
  117. .mode = 0644,
  118. .proc_handler = &proc_dointvec_minmax,
  119. .strategy = &sysctl_intvec,
  120. .extra1 = &zero,
  121. },
  122. {
  123. .ctl_name = INOTIFY_MAX_QUEUED_EVENTS,
  124. .procname = "max_queued_events",
  125. .data = &inotify_max_queued_events,
  126. .maxlen = sizeof(int),
  127. .mode = 0644,
  128. .proc_handler = &proc_dointvec_minmax,
  129. .strategy = &sysctl_intvec,
  130. .extra1 = &zero
  131. },
  132. { .ctl_name = 0 }
  133. };
  134. #endif /* CONFIG_SYSCTL */
  135. static inline void get_inotify_dev(struct inotify_device *dev)
  136. {
  137. atomic_inc(&dev->count);
  138. }
  139. static inline void put_inotify_dev(struct inotify_device *dev)
  140. {
  141. if (atomic_dec_and_test(&dev->count)) {
  142. atomic_dec(&dev->user->inotify_devs);
  143. free_uid(dev->user);
  144. kfree(dev);
  145. }
  146. }
  147. /*
  148. * free_inotify_user_watch - cleans up the watch and its references
  149. */
  150. static void free_inotify_user_watch(struct inotify_watch *w)
  151. {
  152. struct inotify_user_watch *watch;
  153. struct inotify_device *dev;
  154. watch = container_of(w, struct inotify_user_watch, wdata);
  155. dev = watch->dev;
  156. atomic_dec(&dev->user->inotify_watches);
  157. put_inotify_dev(dev);
  158. kmem_cache_free(watch_cachep, watch);
  159. }
  160. /*
  161. * kernel_event - create a new kernel event with the given parameters
  162. *
  163. * This function can sleep.
  164. */
  165. static struct inotify_kernel_event * kernel_event(s32 wd, u32 mask, u32 cookie,
  166. const char *name)
  167. {
  168. struct inotify_kernel_event *kevent;
  169. kevent = kmem_cache_alloc(event_cachep, GFP_NOFS);
  170. if (unlikely(!kevent))
  171. return NULL;
  172. /* we hand this out to user-space, so zero it just in case */
  173. memset(&kevent->event, 0, sizeof(struct inotify_event));
  174. kevent->event.wd = wd;
  175. kevent->event.mask = mask;
  176. kevent->event.cookie = cookie;
  177. INIT_LIST_HEAD(&kevent->list);
  178. if (name) {
  179. size_t len, rem, event_size = sizeof(struct inotify_event);
  180. /*
  181. * We need to pad the filename so as to properly align an
  182. * array of inotify_event structures. Because the structure is
  183. * small and the common case is a small filename, we just round
  184. * up to the next multiple of the structure's sizeof. This is
  185. * simple and safe for all architectures.
  186. */
  187. len = strlen(name) + 1;
  188. rem = event_size - len;
  189. if (len > event_size) {
  190. rem = event_size - (len % event_size);
  191. if (len % event_size == 0)
  192. rem = 0;
  193. }
  194. kevent->name = kmalloc(len + rem, GFP_KERNEL);
  195. if (unlikely(!kevent->name)) {
  196. kmem_cache_free(event_cachep, kevent);
  197. return NULL;
  198. }
  199. memcpy(kevent->name, name, len);
  200. if (rem)
  201. memset(kevent->name + len, 0, rem);
  202. kevent->event.len = len + rem;
  203. } else {
  204. kevent->event.len = 0;
  205. kevent->name = NULL;
  206. }
  207. return kevent;
  208. }
  209. /*
  210. * inotify_dev_get_event - return the next event in the given dev's queue
  211. *
  212. * Caller must hold dev->ev_mutex.
  213. */
  214. static inline struct inotify_kernel_event *
  215. inotify_dev_get_event(struct inotify_device *dev)
  216. {
  217. return list_entry(dev->events.next, struct inotify_kernel_event, list);
  218. }
  219. /*
  220. * inotify_dev_queue_event - event handler registered with core inotify, adds
  221. * a new event to the given device
  222. *
  223. * Can sleep (calls kernel_event()).
  224. */
  225. static void inotify_dev_queue_event(struct inotify_watch *w, u32 wd, u32 mask,
  226. u32 cookie, const char *name,
  227. struct inode *ignored)
  228. {
  229. struct inotify_user_watch *watch;
  230. struct inotify_device *dev;
  231. struct inotify_kernel_event *kevent, *last;
  232. watch = container_of(w, struct inotify_user_watch, wdata);
  233. dev = watch->dev;
  234. mutex_lock(&dev->ev_mutex);
  235. /* we can safely put the watch as we don't reference it while
  236. * generating the event
  237. */
  238. if (mask & IN_IGNORED || mask & IN_ONESHOT)
  239. put_inotify_watch(w); /* final put */
  240. /* coalescing: drop this event if it is a dupe of the previous */
  241. last = inotify_dev_get_event(dev);
  242. if (last && last->event.mask == mask && last->event.wd == wd &&
  243. last->event.cookie == cookie) {
  244. const char *lastname = last->name;
  245. if (!name && !lastname)
  246. goto out;
  247. if (name && lastname && !strcmp(lastname, name))
  248. goto out;
  249. }
  250. /* the queue overflowed and we already sent the Q_OVERFLOW event */
  251. if (unlikely(dev->event_count > dev->max_events))
  252. goto out;
  253. /* if the queue overflows, we need to notify user space */
  254. if (unlikely(dev->event_count == dev->max_events))
  255. kevent = kernel_event(-1, IN_Q_OVERFLOW, cookie, NULL);
  256. else
  257. kevent = kernel_event(wd, mask, cookie, name);
  258. if (unlikely(!kevent))
  259. goto out;
  260. /* queue the event and wake up anyone waiting */
  261. dev->event_count++;
  262. dev->queue_size += sizeof(struct inotify_event) + kevent->event.len;
  263. list_add_tail(&kevent->list, &dev->events);
  264. wake_up_interruptible(&dev->wq);
  265. out:
  266. mutex_unlock(&dev->ev_mutex);
  267. }
  268. /*
  269. * remove_kevent - cleans up and ultimately frees the given kevent
  270. *
  271. * Caller must hold dev->ev_mutex.
  272. */
  273. static void remove_kevent(struct inotify_device *dev,
  274. struct inotify_kernel_event *kevent)
  275. {
  276. list_del(&kevent->list);
  277. dev->event_count--;
  278. dev->queue_size -= sizeof(struct inotify_event) + kevent->event.len;
  279. kfree(kevent->name);
  280. kmem_cache_free(event_cachep, kevent);
  281. }
  282. /*
  283. * inotify_dev_event_dequeue - destroy an event on the given device
  284. *
  285. * Caller must hold dev->ev_mutex.
  286. */
  287. static void inotify_dev_event_dequeue(struct inotify_device *dev)
  288. {
  289. if (!list_empty(&dev->events)) {
  290. struct inotify_kernel_event *kevent;
  291. kevent = inotify_dev_get_event(dev);
  292. remove_kevent(dev, kevent);
  293. }
  294. }
  295. /*
  296. * find_inode - resolve a user-given path to a specific inode and return a nd
  297. */
  298. static int find_inode(const char __user *dirname, struct nameidata *nd,
  299. unsigned flags)
  300. {
  301. int error;
  302. error = __user_walk(dirname, flags, nd);
  303. if (error)
  304. return error;
  305. /* you can only watch an inode if you have read permissions on it */
  306. error = vfs_permission(nd, MAY_READ);
  307. if (error)
  308. path_release(nd);
  309. return error;
  310. }
  311. /*
  312. * create_watch - creates a watch on the given device.
  313. *
  314. * Callers must hold dev->up_mutex.
  315. */
  316. static int create_watch(struct inotify_device *dev, struct inode *inode,
  317. u32 mask)
  318. {
  319. struct inotify_user_watch *watch;
  320. int ret;
  321. if (atomic_read(&dev->user->inotify_watches) >=
  322. inotify_max_user_watches)
  323. return -ENOSPC;
  324. watch = kmem_cache_alloc(watch_cachep, GFP_KERNEL);
  325. if (unlikely(!watch))
  326. return -ENOMEM;
  327. /* save a reference to device and bump the count to make it official */
  328. get_inotify_dev(dev);
  329. watch->dev = dev;
  330. atomic_inc(&dev->user->inotify_watches);
  331. inotify_init_watch(&watch->wdata);
  332. ret = inotify_add_watch(dev->ih, &watch->wdata, inode, mask);
  333. if (ret < 0)
  334. free_inotify_user_watch(&watch->wdata);
  335. return ret;
  336. }
  337. /* Device Interface */
  338. static unsigned int inotify_poll(struct file *file, poll_table *wait)
  339. {
  340. struct inotify_device *dev = file->private_data;
  341. int ret = 0;
  342. poll_wait(file, &dev->wq, wait);
  343. mutex_lock(&dev->ev_mutex);
  344. if (!list_empty(&dev->events))
  345. ret = POLLIN | POLLRDNORM;
  346. mutex_unlock(&dev->ev_mutex);
  347. return ret;
  348. }
  349. static ssize_t inotify_read(struct file *file, char __user *buf,
  350. size_t count, loff_t *pos)
  351. {
  352. size_t event_size = sizeof (struct inotify_event);
  353. struct inotify_device *dev;
  354. char __user *start;
  355. int ret;
  356. DEFINE_WAIT(wait);
  357. start = buf;
  358. dev = file->private_data;
  359. while (1) {
  360. int events;
  361. prepare_to_wait(&dev->wq, &wait, TASK_INTERRUPTIBLE);
  362. mutex_lock(&dev->ev_mutex);
  363. events = !list_empty(&dev->events);
  364. mutex_unlock(&dev->ev_mutex);
  365. if (events) {
  366. ret = 0;
  367. break;
  368. }
  369. if (file->f_flags & O_NONBLOCK) {
  370. ret = -EAGAIN;
  371. break;
  372. }
  373. if (signal_pending(current)) {
  374. ret = -EINTR;
  375. break;
  376. }
  377. schedule();
  378. }
  379. finish_wait(&dev->wq, &wait);
  380. if (ret)
  381. return ret;
  382. mutex_lock(&dev->ev_mutex);
  383. while (1) {
  384. struct inotify_kernel_event *kevent;
  385. ret = buf - start;
  386. if (list_empty(&dev->events))
  387. break;
  388. kevent = inotify_dev_get_event(dev);
  389. if (event_size + kevent->event.len > count) {
  390. if (ret == 0 && count > 0) {
  391. /*
  392. * could not get a single event because we
  393. * didn't have enough buffer space.
  394. */
  395. ret = -EINVAL;
  396. }
  397. break;
  398. }
  399. if (copy_to_user(buf, &kevent->event, event_size)) {
  400. ret = -EFAULT;
  401. break;
  402. }
  403. buf += event_size;
  404. count -= event_size;
  405. if (kevent->name) {
  406. if (copy_to_user(buf, kevent->name, kevent->event.len)){
  407. ret = -EFAULT;
  408. break;
  409. }
  410. buf += kevent->event.len;
  411. count -= kevent->event.len;
  412. }
  413. remove_kevent(dev, kevent);
  414. }
  415. mutex_unlock(&dev->ev_mutex);
  416. return ret;
  417. }
  418. static int inotify_release(struct inode *ignored, struct file *file)
  419. {
  420. struct inotify_device *dev = file->private_data;
  421. inotify_destroy(dev->ih);
  422. /* destroy all of the events on this device */
  423. mutex_lock(&dev->ev_mutex);
  424. while (!list_empty(&dev->events))
  425. inotify_dev_event_dequeue(dev);
  426. mutex_unlock(&dev->ev_mutex);
  427. /* free this device: the put matching the get in inotify_init() */
  428. put_inotify_dev(dev);
  429. return 0;
  430. }
  431. static long inotify_ioctl(struct file *file, unsigned int cmd,
  432. unsigned long arg)
  433. {
  434. struct inotify_device *dev;
  435. void __user *p;
  436. int ret = -ENOTTY;
  437. dev = file->private_data;
  438. p = (void __user *) arg;
  439. switch (cmd) {
  440. case FIONREAD:
  441. ret = put_user(dev->queue_size, (int __user *) p);
  442. break;
  443. }
  444. return ret;
  445. }
  446. static const struct file_operations inotify_fops = {
  447. .poll = inotify_poll,
  448. .read = inotify_read,
  449. .release = inotify_release,
  450. .unlocked_ioctl = inotify_ioctl,
  451. .compat_ioctl = inotify_ioctl,
  452. };
  453. static const struct inotify_operations inotify_user_ops = {
  454. .handle_event = inotify_dev_queue_event,
  455. .destroy_watch = free_inotify_user_watch,
  456. };
  457. asmlinkage long sys_inotify_init(void)
  458. {
  459. struct inotify_device *dev;
  460. struct inotify_handle *ih;
  461. struct user_struct *user;
  462. struct file *filp;
  463. int fd, ret;
  464. fd = get_unused_fd();
  465. if (fd < 0)
  466. return fd;
  467. filp = get_empty_filp();
  468. if (!filp) {
  469. ret = -ENFILE;
  470. goto out_put_fd;
  471. }
  472. user = get_uid(current->user);
  473. if (unlikely(atomic_read(&user->inotify_devs) >=
  474. inotify_max_user_instances)) {
  475. ret = -EMFILE;
  476. goto out_free_uid;
  477. }
  478. dev = kmalloc(sizeof(struct inotify_device), GFP_KERNEL);
  479. if (unlikely(!dev)) {
  480. ret = -ENOMEM;
  481. goto out_free_uid;
  482. }
  483. ih = inotify_init(&inotify_user_ops);
  484. if (unlikely(IS_ERR(ih))) {
  485. ret = PTR_ERR(ih);
  486. goto out_free_dev;
  487. }
  488. dev->ih = ih;
  489. filp->f_op = &inotify_fops;
  490. filp->f_path.mnt = mntget(inotify_mnt);
  491. filp->f_path.dentry = dget(inotify_mnt->mnt_root);
  492. filp->f_mapping = filp->f_path.dentry->d_inode->i_mapping;
  493. filp->f_mode = FMODE_READ;
  494. filp->f_flags = O_RDONLY;
  495. filp->private_data = dev;
  496. INIT_LIST_HEAD(&dev->events);
  497. init_waitqueue_head(&dev->wq);
  498. mutex_init(&dev->ev_mutex);
  499. mutex_init(&dev->up_mutex);
  500. dev->event_count = 0;
  501. dev->queue_size = 0;
  502. dev->max_events = inotify_max_queued_events;
  503. dev->user = user;
  504. atomic_set(&dev->count, 0);
  505. get_inotify_dev(dev);
  506. atomic_inc(&user->inotify_devs);
  507. fd_install(fd, filp);
  508. return fd;
  509. out_free_dev:
  510. kfree(dev);
  511. out_free_uid:
  512. free_uid(user);
  513. put_filp(filp);
  514. out_put_fd:
  515. put_unused_fd(fd);
  516. return ret;
  517. }
  518. asmlinkage long sys_inotify_add_watch(int fd, const char __user *path, u32 mask)
  519. {
  520. struct inode *inode;
  521. struct inotify_device *dev;
  522. struct nameidata nd;
  523. struct file *filp;
  524. int ret, fput_needed;
  525. unsigned flags = 0;
  526. filp = fget_light(fd, &fput_needed);
  527. if (unlikely(!filp))
  528. return -EBADF;
  529. /* verify that this is indeed an inotify instance */
  530. if (unlikely(filp->f_op != &inotify_fops)) {
  531. ret = -EINVAL;
  532. goto fput_and_out;
  533. }
  534. if (!(mask & IN_DONT_FOLLOW))
  535. flags |= LOOKUP_FOLLOW;
  536. if (mask & IN_ONLYDIR)
  537. flags |= LOOKUP_DIRECTORY;
  538. ret = find_inode(path, &nd, flags);
  539. if (unlikely(ret))
  540. goto fput_and_out;
  541. /* inode held in place by reference to nd; dev by fget on fd */
  542. inode = nd.dentry->d_inode;
  543. dev = filp->private_data;
  544. mutex_lock(&dev->up_mutex);
  545. ret = inotify_find_update_watch(dev->ih, inode, mask);
  546. if (ret == -ENOENT)
  547. ret = create_watch(dev, inode, mask);
  548. mutex_unlock(&dev->up_mutex);
  549. path_release(&nd);
  550. fput_and_out:
  551. fput_light(filp, fput_needed);
  552. return ret;
  553. }
  554. asmlinkage long sys_inotify_rm_watch(int fd, u32 wd)
  555. {
  556. struct file *filp;
  557. struct inotify_device *dev;
  558. int ret, fput_needed;
  559. filp = fget_light(fd, &fput_needed);
  560. if (unlikely(!filp))
  561. return -EBADF;
  562. /* verify that this is indeed an inotify instance */
  563. if (unlikely(filp->f_op != &inotify_fops)) {
  564. ret = -EINVAL;
  565. goto out;
  566. }
  567. dev = filp->private_data;
  568. /* we free our watch data when we get IN_IGNORED */
  569. ret = inotify_rm_wd(dev->ih, wd);
  570. out:
  571. fput_light(filp, fput_needed);
  572. return ret;
  573. }
  574. static int
  575. inotify_get_sb(struct file_system_type *fs_type, int flags,
  576. const char *dev_name, void *data, struct vfsmount *mnt)
  577. {
  578. return get_sb_pseudo(fs_type, "inotify", NULL, 0xBAD1DEA, mnt);
  579. }
  580. static struct file_system_type inotify_fs_type = {
  581. .name = "inotifyfs",
  582. .get_sb = inotify_get_sb,
  583. .kill_sb = kill_anon_super,
  584. };
  585. /*
  586. * inotify_user_setup - Our initialization function. Note that we cannnot return
  587. * error because we have compiled-in VFS hooks. So an (unlikely) failure here
  588. * must result in panic().
  589. */
  590. static int __init inotify_user_setup(void)
  591. {
  592. int ret;
  593. ret = register_filesystem(&inotify_fs_type);
  594. if (unlikely(ret))
  595. panic("inotify: register_filesystem returned %d!\n", ret);
  596. inotify_mnt = kern_mount(&inotify_fs_type);
  597. if (IS_ERR(inotify_mnt))
  598. panic("inotify: kern_mount ret %ld!\n", PTR_ERR(inotify_mnt));
  599. inotify_max_queued_events = 16384;
  600. inotify_max_user_instances = 128;
  601. inotify_max_user_watches = 8192;
  602. watch_cachep = kmem_cache_create("inotify_watch_cache",
  603. sizeof(struct inotify_user_watch),
  604. 0, SLAB_PANIC, NULL, NULL);
  605. event_cachep = kmem_cache_create("inotify_event_cache",
  606. sizeof(struct inotify_kernel_event),
  607. 0, SLAB_PANIC, NULL, NULL);
  608. return 0;
  609. }
  610. module_init(inotify_user_setup);