Skip to content

Commit c44dcc5

Browse files
author
Al Viro
committed
switch inotify_user to anon_inode
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent cccc6bb commit c44dcc5

2 files changed

Lines changed: 6 additions & 54 deletions

File tree

‎fs/notify/inotify/inotify_user.c‎

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@
2929
#include <linux/init.h> /* module_init */
3030
#include <linux/inotify.h>
3131
#include <linux/kernel.h> /* roundup() */
32-
#include <linux/magic.h> /* superblock magic number */
33-
#include <linux/mount.h> /* mntget */
3432
#include <linux/namei.h> /* LOOKUP_FOLLOW */
35-
#include <linux/path.h> /* struct path */
3633
#include <linux/sched.h> /* struct user */
3734
#include <linux/slab.h> /* struct kmem_cache */
3835
#include <linux/syscalls.h>
3936
#include <linux/types.h>
37+
#include <linux/anon_inodes.h>
4038
#include <linux/uaccess.h>
4139
#include <linux/poll.h>
4240
#include <linux/wait.h>
@@ -45,8 +43,6 @@
4543

4644
#include <asm/ioctls.h>
4745

48-
static struct vfsmount *inotify_mnt __read_mostly;
49-
5046
/* these are configurable via /proc/sys/fs/inotify/ */
5147
static int inotify_max_user_instances __read_mostly;
5248
static int inotify_max_queued_events __read_mostly;
@@ -645,9 +641,7 @@ SYSCALL_DEFINE1(inotify_init1, int, flags)
645641
{
646642
struct fsnotify_group *group;
647643
struct user_struct *user;
648-
struct file *filp;
649-
struct path path;
650-
int fd, ret;
644+
int ret;
651645

652646
/* Check the IN_* constants for consistency. */
653647
BUILD_BUG_ON(IN_CLOEXEC != O_CLOEXEC);
@@ -656,10 +650,6 @@ SYSCALL_DEFINE1(inotify_init1, int, flags)
656650
if (flags & ~(IN_CLOEXEC | IN_NONBLOCK))
657651
return -EINVAL;
658652

659-
fd = get_unused_fd_flags(flags & O_CLOEXEC);
660-
if (fd < 0)
661-
return fd;
662-
663653
user = get_current_user();
664654
if (unlikely(atomic_read(&user->inotify_devs) >=
665655
inotify_max_user_instances)) {
@@ -676,27 +666,14 @@ SYSCALL_DEFINE1(inotify_init1, int, flags)
676666

677667
atomic_inc(&user->inotify_devs);
678668

679-
path.mnt = inotify_mnt;
680-
path.dentry = inotify_mnt->mnt_root;
681-
path_get(&path);
682-
filp = alloc_file(&path, FMODE_READ, &inotify_fops);
683-
if (!filp)
684-
goto Enfile;
669+
ret = anon_inode_getfd("inotify", &inotify_fops, group,
670+
O_RDONLY | flags);
671+
if (ret >= 0)
672+
return ret;
685673

686-
filp->f_flags = O_RDONLY | (flags & O_NONBLOCK);
687-
filp->private_data = group;
688-
689-
fd_install(fd, filp);
690-
691-
return fd;
692-
693-
Enfile:
694-
ret = -ENFILE;
695-
path_put(&path);
696674
atomic_dec(&user->inotify_devs);
697675
out_free_uid:
698676
free_uid(user);
699-
put_unused_fd(fd);
700677
return ret;
701678
}
702679

@@ -783,37 +760,13 @@ SYSCALL_DEFINE2(inotify_rm_watch, int, fd, __s32, wd)
783760
return ret;
784761
}
785762

786-
static int
787-
inotify_get_sb(struct file_system_type *fs_type, int flags,
788-
const char *dev_name, void *data, struct vfsmount *mnt)
789-
{
790-
return get_sb_pseudo(fs_type, "inotify", NULL,
791-
INOTIFYFS_SUPER_MAGIC, mnt);
792-
}
793-
794-
static struct file_system_type inotify_fs_type = {
795-
.name = "inotifyfs",
796-
.get_sb = inotify_get_sb,
797-
.kill_sb = kill_anon_super,
798-
};
799-
800763
/*
801764
* inotify_user_setup - Our initialization function. Note that we cannnot return
802765
* error because we have compiled-in VFS hooks. So an (unlikely) failure here
803766
* must result in panic().
804767
*/
805768
static int __init inotify_user_setup(void)
806769
{
807-
int ret;
808-
809-
ret = register_filesystem(&inotify_fs_type);
810-
if (unlikely(ret))
811-
panic("inotify: register_filesystem returned %d!\n", ret);
812-
813-
inotify_mnt = kern_mount(&inotify_fs_type);
814-
if (IS_ERR(inotify_mnt))
815-
panic("inotify: kern_mount ret %ld!\n", PTR_ERR(inotify_mnt));
816-
817770
inotify_inode_mark_cachep = KMEM_CACHE(inotify_inode_mark_entry, SLAB_PANIC);
818771
event_priv_cachep = KMEM_CACHE(inotify_event_private_data, SLAB_PANIC);
819772

‎include/linux/magic.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#define CGROUP_SUPER_MAGIC 0x27e0eb
5353

5454
#define FUTEXFS_SUPER_MAGIC 0xBAD1DEA
55-
#define INOTIFYFS_SUPER_MAGIC 0x2BAD1DEA
5655

5756
#define STACK_END_MAGIC 0x57AC6E9D
5857

0 commit comments

Comments
 (0)