Skip to content

Commit

Permalink
fsnotify: pass a file instead of an inode to open, read, and write
Browse files Browse the repository at this point in the history
fanotify, the upcoming notification system actually needs a struct path so it can
do opens in the context of listeners, and it needs a file so it can get f_flags
from the original process.  Close was the only operation that already was passing
a struct file to the notification hook.  This patch passes a file for access,
modify, and open as well as they are easily available to these hooks.

Signed-off-by: Eric Paris <[email protected]>
  • Loading branch information
eparis committed Jul 28, 2010
1 parent 8112e2d commit 2a12a9d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
5 changes: 2 additions & 3 deletions fs/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,11 +1193,10 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
if (iov != iovstack)
kfree(iov);
if ((ret + (type == READ)) > 0) {
struct dentry *dentry = file->f_path.dentry;
if (type == READ)
fsnotify_access(dentry);
fsnotify_access(file);
else
fsnotify_modify(dentry);
fsnotify_modify(file);
}
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
if (file->f_path.mnt->mnt_flags & MNT_NOEXEC)
goto exit;

fsnotify_open(file->f_path.dentry);
fsnotify_open(file);

error = -ENOEXEC;
if(file->f_op) {
Expand Down Expand Up @@ -683,7 +683,7 @@ struct file *open_exec(const char *name)
if (file->f_path.mnt->mnt_flags & MNT_NOEXEC)
goto exit;

fsnotify_open(file->f_path.dentry);
fsnotify_open(file);

err = deny_write_access(file);
if (err)
Expand Down
4 changes: 2 additions & 2 deletions fs/nfsd/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
nfsdstats.io_read += host_err;
*count = host_err;
err = 0;
fsnotify_access(file->f_path.dentry);
fsnotify_access(file);
} else
err = nfserrno(host_err);
out:
Expand Down Expand Up @@ -1062,7 +1062,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
goto out_nfserr;
*cnt = host_err;
nfsdstats.io_write += host_err;
fsnotify_modify(file->f_path.dentry);
fsnotify_modify(file);

/* clear setuid/setgid flag after write */
if (inode->i_mode & (S_ISUID | S_ISGID))
Expand Down
2 changes: 1 addition & 1 deletion fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, int mode)
put_unused_fd(fd);
fd = PTR_ERR(f);
} else {
fsnotify_open(f->f_path.dentry);
fsnotify_open(f);
fd_install(fd, f);
}
}
Expand Down
8 changes: 4 additions & 4 deletions fs/read_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
else
ret = do_sync_read(file, buf, count, pos);
if (ret > 0) {
fsnotify_access(file->f_path.dentry);
fsnotify_access(file);
add_rchar(current, ret);
}
inc_syscr(current);
Expand Down Expand Up @@ -367,7 +367,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
else
ret = do_sync_write(file, buf, count, pos);
if (ret > 0) {
fsnotify_modify(file->f_path.dentry);
fsnotify_modify(file);
add_wchar(current, ret);
}
inc_syscw(current);
Expand Down Expand Up @@ -675,9 +675,9 @@ static ssize_t do_readv_writev(int type, struct file *file,
kfree(iov);
if ((ret + (type == READ)) > 0) {
if (type == READ)
fsnotify_access(file->f_path.dentry);
fsnotify_access(file);
else
fsnotify_modify(file->f_path.dentry);
fsnotify_modify(file);
}
return ret;
}
Expand Down
15 changes: 9 additions & 6 deletions include/linux/fsnotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,46 +153,49 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
/*
* fsnotify_access - file was read
*/
static inline void fsnotify_access(struct dentry *dentry)
static inline void fsnotify_access(struct file *file)
{
struct dentry *dentry = file->f_path.dentry;
struct inode *inode = dentry->d_inode;
__u32 mask = FS_ACCESS;

if (S_ISDIR(inode->i_mode))
mask |= FS_IN_ISDIR;

fsnotify_parent(dentry, mask);
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
}

/*
* fsnotify_modify - file was modified
*/
static inline void fsnotify_modify(struct dentry *dentry)
static inline void fsnotify_modify(struct file *file)
{
struct dentry *dentry = file->f_path.dentry;
struct inode *inode = dentry->d_inode;
__u32 mask = FS_MODIFY;

if (S_ISDIR(inode->i_mode))
mask |= FS_IN_ISDIR;

fsnotify_parent(dentry, mask);
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
}

/*
* fsnotify_open - file was opened
*/
static inline void fsnotify_open(struct dentry *dentry)
static inline void fsnotify_open(struct file *file)
{
struct dentry *dentry = file->f_path.dentry;
struct inode *inode = dentry->d_inode;
__u32 mask = FS_OPEN;

if (S_ISDIR(inode->i_mode))
mask |= FS_IN_ISDIR;

fsnotify_parent(dentry, mask);
fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
fsnotify(inode, mask, file, FSNOTIFY_EVENT_FILE, NULL, 0);
}

/*
Expand Down

0 comments on commit 2a12a9d

Please sign in to comment.