mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-23 12:14:10 +08:00
inotify: reimplement inotify using fsnotify
Reimplement inotify_user using fsnotify. This should be feature for feature exactly the same as the original inotify_user. This does not make any changes to the in kernel inotify feature used by audit. Those patches (and the eventual removal of in kernel inotify) will come after the new inotify_user proves to be working correctly. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Al Viro <viro@zeniv.linux.org.uk> Cc: Christoph Hellwig <hch@lst.de>
This commit is contained in:
parent
164bc61951
commit
63c882a054
@ -2858,6 +2858,8 @@ P: John McCutchan
|
||||
M: john@johnmccutchan.com
|
||||
P: Robert Love
|
||||
M: rlove@rlove.org
|
||||
P: Eric Paris
|
||||
M: eparis@parisplace.org
|
||||
L: linux-kernel@vger.kernel.org
|
||||
S: Maintained
|
||||
F: Documentation/filesystems/inotify.txt
|
||||
|
@ -1,26 +1,30 @@
|
||||
config INOTIFY
|
||||
bool "Inotify file change notification support"
|
||||
default y
|
||||
default n
|
||||
---help---
|
||||
Say Y here to enable inotify support. Inotify is a file change
|
||||
notification system and a replacement for dnotify. Inotify fixes
|
||||
numerous shortcomings in dnotify and introduces several new features
|
||||
including multiple file events, one-shot support, and unmount
|
||||
notification.
|
||||
Say Y here to enable legacy in kernel inotify support. Inotify is a
|
||||
file change notification system. It is a replacement for dnotify.
|
||||
This option only provides the legacy inotify in kernel API. There
|
||||
are no in tree kernel users of this interface since it is deprecated.
|
||||
You only need this if you are loading an out of tree kernel module
|
||||
that uses inotify.
|
||||
|
||||
For more information, see <file:Documentation/filesystems/inotify.txt>
|
||||
|
||||
If unsure, say Y.
|
||||
If unsure, say N.
|
||||
|
||||
config INOTIFY_USER
|
||||
bool "Inotify support for userspace"
|
||||
depends on INOTIFY
|
||||
depends on FSNOTIFY
|
||||
default y
|
||||
---help---
|
||||
Say Y here to enable inotify support for userspace, including the
|
||||
associated system calls. Inotify allows monitoring of both files and
|
||||
directories via a single open fd. Events are read from the file
|
||||
descriptor, which is also select()- and poll()-able.
|
||||
Inotify fixes numerous shortcomings in dnotify and introduces several
|
||||
new features including multiple file events, one-shot support, and
|
||||
unmount notification.
|
||||
|
||||
For more information, see <file:Documentation/filesystems/inotify.txt>
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
obj-$(CONFIG_INOTIFY) += inotify.o
|
||||
obj-$(CONFIG_INOTIFY_USER) += inotify_user.o
|
||||
obj-$(CONFIG_INOTIFY_USER) += inotify_fsnotify.o inotify_user.o
|
||||
|
21
fs/notify/inotify/inotify.h
Normal file
21
fs/notify/inotify/inotify.h
Normal file
@ -0,0 +1,21 @@
|
||||
#include <linux/fsnotify_backend.h>
|
||||
#include <linux/inotify.h>
|
||||
#include <linux/slab.h> /* struct kmem_cache */
|
||||
|
||||
extern struct kmem_cache *event_priv_cachep;
|
||||
|
||||
struct inotify_event_private_data {
|
||||
struct fsnotify_event_private_data fsnotify_event_priv_data;
|
||||
int wd;
|
||||
};
|
||||
|
||||
struct inotify_inode_mark_entry {
|
||||
/* fsnotify_mark_entry MUST be the first thing */
|
||||
struct fsnotify_mark_entry fsn_entry;
|
||||
int wd;
|
||||
};
|
||||
|
||||
extern void inotify_destroy_mark_entry(struct fsnotify_mark_entry *entry, struct fsnotify_group *group);
|
||||
extern void inotify_free_event_priv(struct fsnotify_event_private_data *event_priv);
|
||||
|
||||
extern const struct fsnotify_ops inotify_fsnotify_ops;
|
137
fs/notify/inotify/inotify_fsnotify.c
Normal file
137
fs/notify/inotify/inotify_fsnotify.c
Normal file
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* fs/inotify_user.c - inotify support for userspace
|
||||
*
|
||||
* Authors:
|
||||
* John McCutchan <ttb@tentacle.dhs.org>
|
||||
* Robert Love <rml@novell.com>
|
||||
*
|
||||
* Copyright (C) 2005 John McCutchan
|
||||
* Copyright 2006 Hewlett-Packard Development Company, L.P.
|
||||
*
|
||||
* Copyright (C) 2009 Eric Paris <Red Hat Inc>
|
||||
* inotify was largely rewriten to make use of the fsnotify infrastructure
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/fs.h> /* struct inode */
|
||||
#include <linux/fsnotify_backend.h>
|
||||
#include <linux/inotify.h>
|
||||
#include <linux/path.h> /* struct path */
|
||||
#include <linux/slab.h> /* kmem_* */
|
||||
#include <linux/types.h>
|
||||
|
||||
#include "inotify.h"
|
||||
|
||||
static int inotify_handle_event(struct fsnotify_group *group, struct fsnotify_event *event)
|
||||
{
|
||||
struct fsnotify_mark_entry *entry;
|
||||
struct inotify_inode_mark_entry *ientry;
|
||||
struct inode *to_tell;
|
||||
struct inotify_event_private_data *event_priv;
|
||||
struct fsnotify_event_private_data *fsn_event_priv;
|
||||
int wd, ret;
|
||||
|
||||
to_tell = event->to_tell;
|
||||
|
||||
spin_lock(&to_tell->i_lock);
|
||||
entry = fsnotify_find_mark_entry(group, to_tell);
|
||||
spin_unlock(&to_tell->i_lock);
|
||||
/* race with watch removal? We already passes should_send */
|
||||
if (unlikely(!entry))
|
||||
return 0;
|
||||
ientry = container_of(entry, struct inotify_inode_mark_entry,
|
||||
fsn_entry);
|
||||
wd = ientry->wd;
|
||||
|
||||
event_priv = kmem_cache_alloc(event_priv_cachep, GFP_KERNEL);
|
||||
if (unlikely(!event_priv))
|
||||
return -ENOMEM;
|
||||
|
||||
fsn_event_priv = &event_priv->fsnotify_event_priv_data;
|
||||
|
||||
fsn_event_priv->group = group;
|
||||
event_priv->wd = wd;
|
||||
|
||||
ret = fsnotify_add_notify_event(group, event, fsn_event_priv);
|
||||
/* EEXIST is not an error */
|
||||
if (ret == -EEXIST)
|
||||
ret = 0;
|
||||
|
||||
/* did event_priv get attached? */
|
||||
if (list_empty(&fsn_event_priv->event_list))
|
||||
inotify_free_event_priv(fsn_event_priv);
|
||||
|
||||
/*
|
||||
* If we hold the entry until after the event is on the queue
|
||||
* IN_IGNORED won't be able to pass this event in the queue
|
||||
*/
|
||||
fsnotify_put_mark(entry);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void inotify_freeing_mark(struct fsnotify_mark_entry *entry, struct fsnotify_group *group)
|
||||
{
|
||||
inotify_destroy_mark_entry(entry, group);
|
||||
}
|
||||
|
||||
static bool inotify_should_send_event(struct fsnotify_group *group, struct inode *inode, __u32 mask)
|
||||
{
|
||||
struct fsnotify_mark_entry *entry;
|
||||
bool send;
|
||||
|
||||
spin_lock(&inode->i_lock);
|
||||
entry = fsnotify_find_mark_entry(group, inode);
|
||||
spin_unlock(&inode->i_lock);
|
||||
if (!entry)
|
||||
return false;
|
||||
|
||||
send = (entry->mask & mask);
|
||||
|
||||
/* find took a reference */
|
||||
fsnotify_put_mark(entry);
|
||||
|
||||
return send;
|
||||
}
|
||||
|
||||
static int idr_callback(int id, void *p, void *data)
|
||||
{
|
||||
BUG();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void inotify_free_group_priv(struct fsnotify_group *group)
|
||||
{
|
||||
/* ideally the idr is empty and we won't hit the BUG in teh callback */
|
||||
idr_for_each(&group->inotify_data.idr, idr_callback, NULL);
|
||||
idr_remove_all(&group->inotify_data.idr);
|
||||
idr_destroy(&group->inotify_data.idr);
|
||||
}
|
||||
|
||||
void inotify_free_event_priv(struct fsnotify_event_private_data *fsn_event_priv)
|
||||
{
|
||||
struct inotify_event_private_data *event_priv;
|
||||
|
||||
|
||||
event_priv = container_of(fsn_event_priv, struct inotify_event_private_data,
|
||||
fsnotify_event_priv_data);
|
||||
|
||||
kmem_cache_free(event_priv_cachep, event_priv);
|
||||
}
|
||||
|
||||
const struct fsnotify_ops inotify_fsnotify_ops = {
|
||||
.handle_event = inotify_handle_event,
|
||||
.should_send_event = inotify_should_send_event,
|
||||
.free_group_priv = inotify_free_group_priv,
|
||||
.free_event_priv = inotify_free_event_priv,
|
||||
.freeing_mark = inotify_freeing_mark,
|
||||
};
|
File diff suppressed because it is too large
Load Diff
@ -9,6 +9,7 @@
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
#include <linux/idr.h> /* inotify uses this */
|
||||
#include <linux/fs.h> /* struct inode */
|
||||
#include <linux/list.h>
|
||||
#include <linux/path.h> /* struct path */
|
||||
@ -59,6 +60,7 @@
|
||||
|
||||
/* listeners that hard code group numbers near the top */
|
||||
#define DNOTIFY_GROUP_NUM UINT_MAX
|
||||
#define INOTIFY_GROUP_NUM (DNOTIFY_GROUP_NUM-1)
|
||||
|
||||
struct fsnotify_group;
|
||||
struct fsnotify_event;
|
||||
@ -141,6 +143,15 @@ struct fsnotify_group {
|
||||
/* groups can define private fields here or use the void *private */
|
||||
union {
|
||||
void *private;
|
||||
#ifdef CONFIG_INOTIFY_USER
|
||||
struct inotify_group_private_data {
|
||||
spinlock_t idr_lock;
|
||||
struct idr idr;
|
||||
u32 last_wd;
|
||||
struct fasync_struct *fa; /* async notification */
|
||||
struct user_struct *user;
|
||||
} inotify_data;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -302,7 +302,8 @@ config AUDITSYSCALL
|
||||
|
||||
config AUDIT_TREE
|
||||
def_bool y
|
||||
depends on AUDITSYSCALL && INOTIFY
|
||||
depends on AUDITSYSCALL
|
||||
select INOTIFY
|
||||
|
||||
menu "RCU Subsystem"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user