Skip to content

Commit

Permalink
[PATCH] Streamline generic_file_* interfaces and filemap cleanups
Browse files Browse the repository at this point in the history
This patch cleans up generic_file_*_read/write() interfaces.  Christoph
Hellwig gave me the idea for this clean ups.

In a nutshell, all filesystems should set .aio_read/.aio_write methods and use
do_sync_read/ do_sync_write() as their .read/.write methods.  This allows us
to cleanup all variants of generic_file_* routines.

Final available interfaces:

generic_file_aio_read() - read handler
generic_file_aio_write() - write handler
generic_file_aio_write_nolock() - no lock write handler

__generic_file_aio_write_nolock() - internal worker routine

Signed-off-by: Badari Pulavarty <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Badari Pulavarty authored and Linus Torvalds committed Oct 1, 2006
1 parent ee0b3e6 commit 543ade1
Show file tree
Hide file tree
Showing 27 changed files with 105 additions and 165 deletions.
15 changes: 2 additions & 13 deletions drivers/char/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,10 @@ static int raw_ctl_ioctl(struct inode *inode, struct file *filp,
return err;
}

static ssize_t raw_file_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
struct iovec local_iov = {
.iov_base = (char __user *)buf,
.iov_len = count
};

return generic_file_write_nolock(file, &local_iov, 1, ppos);
}

static const struct file_operations raw_fops = {
.read = generic_file_read,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.write = raw_file_write,
.write = do_sync_write,
.aio_write = generic_file_aio_write_nolock,
.open = raw_open,
.release= raw_release,
Expand Down
6 changes: 4 additions & 2 deletions fs/adfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@

const struct file_operations adfs_file_operations = {
.llseek = generic_file_llseek,
.read = generic_file_read,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.mmap = generic_file_mmap,
.fsync = file_fsync,
.write = generic_file_write,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.sendfile = generic_file_sendfile,
};

Expand Down
6 changes: 4 additions & 2 deletions fs/affs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ static int affs_file_release(struct inode *inode, struct file *filp);

const struct file_operations affs_file_operations = {
.llseek = generic_file_llseek,
.read = generic_file_read,
.write = generic_file_write,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.mmap = generic_file_mmap,
.open = affs_file_open,
.release = affs_file_release,
Expand Down
6 changes: 4 additions & 2 deletions fs/bfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

const struct file_operations bfs_file_operations = {
.llseek = generic_file_llseek,
.read = generic_file_read,
.write = generic_file_write,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.mmap = generic_file_mmap,
.sendfile = generic_file_sendfile,
};
Expand Down
12 changes: 2 additions & 10 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,14 +1154,6 @@ static int blkdev_close(struct inode * inode, struct file * filp)
return blkdev_put(bdev);
}

static ssize_t blkdev_file_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
struct iovec local_iov = { .iov_base = (void __user *)buf, .iov_len = count };

return generic_file_write_nolock(file, &local_iov, 1, ppos);
}

static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg)
{
return blkdev_ioctl(file->f_mapping->host, file, cmd, arg);
Expand All @@ -1181,8 +1173,8 @@ const struct file_operations def_blk_fops = {
.open = blkdev_open,
.release = blkdev_close,
.llseek = block_llseek,
.read = generic_file_read,
.write = blkdev_file_write,
.read = do_sync_read,
.write = do_sync_write,
.aio_read = generic_file_aio_read,
.aio_write = generic_file_aio_write_nolock,
.mmap = generic_file_mmap,
Expand Down
4 changes: 2 additions & 2 deletions fs/ext2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ static int ext2_release_file (struct inode * inode, struct file * filp)
*/
const struct file_operations ext2_file_operations = {
.llseek = generic_file_llseek,
.read = generic_file_read,
.write = generic_file_write,
.read = do_sync_read,
.write = do_sync_write,
.aio_read = generic_file_aio_read,
.aio_write = generic_file_aio_write,
.ioctl = ext2_ioctl,
Expand Down
6 changes: 4 additions & 2 deletions fs/fuse/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,10 @@ static int fuse_file_lock(struct file *file, int cmd, struct file_lock *fl)

static const struct file_operations fuse_file_operations = {
.llseek = generic_file_llseek,
.read = generic_file_read,
.write = generic_file_write,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.mmap = fuse_file_mmap,
.open = fuse_open,
.flush = fuse_flush,
Expand Down
6 changes: 4 additions & 2 deletions fs/hfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,10 @@ int hfs_inode_setattr(struct dentry *dentry, struct iattr * attr)

static const struct file_operations hfs_file_operations = {
.llseek = generic_file_llseek,
.read = generic_file_read,
.write = generic_file_write,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.mmap = generic_file_mmap,
.sendfile = generic_file_sendfile,
.fsync = file_fsync,
Expand Down
6 changes: 4 additions & 2 deletions fs/hfsplus/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,10 @@ static struct inode_operations hfsplus_file_inode_operations = {

static const struct file_operations hfsplus_file_operations = {
.llseek = generic_file_llseek,
.read = generic_file_read,
.write = generic_file_write,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.mmap = generic_file_mmap,
.sendfile = generic_file_sendfile,
.fsync = file_fsync,
Expand Down
4 changes: 2 additions & 2 deletions fs/hostfs/hostfs_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ int hostfs_fsync(struct file *file, struct dentry *dentry, int datasync)

static const struct file_operations hostfs_file_fops = {
.llseek = generic_file_llseek,
.read = generic_file_read,
.read = do_sync_read,
.sendfile = generic_file_sendfile,
.aio_read = generic_file_aio_read,
.aio_write = generic_file_aio_write,
.write = generic_file_write,
.write = do_sync_write,
.mmap = generic_file_mmap,
.open = hostfs_file_open,
.release = NULL,
Expand Down
6 changes: 4 additions & 2 deletions fs/hpfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static ssize_t hpfs_file_write(struct file *file, const char __user *buf,
{
ssize_t retval;

retval = generic_file_write(file, buf, count, ppos);
retval = do_sync_write(file, buf, count, ppos);
if (retval > 0)
hpfs_i(file->f_dentry->d_inode)->i_dirty = 1;
return retval;
Expand All @@ -122,8 +122,10 @@ static ssize_t hpfs_file_write(struct file *file, const char __user *buf,
const struct file_operations hpfs_file_ops =
{
.llseek = generic_file_llseek,
.read = generic_file_read,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.write = hpfs_file_write,
.aio_write = generic_file_aio_write,
.mmap = generic_file_mmap,
.release = hpfs_file_release,
.fsync = hpfs_file_fsync,
Expand Down
6 changes: 4 additions & 2 deletions fs/jffs/inode-v23.c
Original file line number Diff line number Diff line change
Expand Up @@ -1632,8 +1632,10 @@ static const struct file_operations jffs_file_operations =
{
.open = generic_file_open,
.llseek = generic_file_llseek,
.read = generic_file_read,
.write = generic_file_write,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.ioctl = jffs_ioctl,
.mmap = generic_file_readonly_mmap,
.fsync = jffs_fsync,
Expand Down
6 changes: 4 additions & 2 deletions fs/jffs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ const struct file_operations jffs2_file_operations =
{
.llseek = generic_file_llseek,
.open = generic_file_open,
.read = generic_file_read,
.write = generic_file_write,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.ioctl = jffs2_ioctl,
.mmap = generic_file_readonly_mmap,
.fsync = jffs2_fsync,
Expand Down
4 changes: 2 additions & 2 deletions fs/jfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ struct inode_operations jfs_file_inode_operations = {
const struct file_operations jfs_file_operations = {
.open = jfs_open,
.llseek = generic_file_llseek,
.write = generic_file_write,
.read = generic_file_read,
.write = do_sync_write,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.aio_write = generic_file_aio_write,
.mmap = generic_file_mmap,
Expand Down
6 changes: 4 additions & 2 deletions fs/minix/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ int minix_sync_file(struct file *, struct dentry *, int);

const struct file_operations minix_file_operations = {
.llseek = generic_file_llseek,
.read = generic_file_read,
.write = generic_file_write,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.mmap = generic_file_mmap,
.fsync = minix_sync_file,
.sendfile = generic_file_sendfile,
Expand Down
2 changes: 1 addition & 1 deletion fs/ntfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,7 @@ static int ntfs_file_fsync(struct file *filp, struct dentry *dentry,

const struct file_operations ntfs_file_ops = {
.llseek = generic_file_llseek, /* Seek inside file. */
.read = generic_file_read, /* Read from file. */
.read = do_sync_read, /* Read from file. */
.aio_read = generic_file_aio_read, /* Async read from file. */
#ifdef NTFS_RW
.write = ntfs_file_write, /* Write to file. */
Expand Down
6 changes: 4 additions & 2 deletions fs/qnx4/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
const struct file_operations qnx4_file_operations =
{
.llseek = generic_file_llseek,
.read = generic_file_read,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.mmap = generic_file_mmap,
.sendfile = generic_file_sendfile,
#ifdef CONFIG_QNX4FS_RW
.write = generic_file_write,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.fsync = qnx4_sync_file,
#endif
};
Expand Down
6 changes: 4 additions & 2 deletions fs/ramfs/file-mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ const struct address_space_operations ramfs_aops = {
};

const struct file_operations ramfs_file_operations = {
.read = generic_file_read,
.write = generic_file_write,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.mmap = generic_file_mmap,
.fsync = simple_sync_file,
.sendfile = generic_file_sendfile,
Expand Down
6 changes: 4 additions & 2 deletions fs/ramfs/file-nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ const struct address_space_operations ramfs_aops = {
const struct file_operations ramfs_file_operations = {
.mmap = ramfs_nommu_mmap,
.get_unmapped_area = ramfs_nommu_get_unmapped_area,
.read = generic_file_read,
.write = generic_file_write,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.fsync = simple_sync_file,
.sendfile = generic_file_sendfile,
.llseek = generic_file_llseek,
Expand Down
3 changes: 2 additions & 1 deletion fs/read_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

const struct file_operations generic_ro_fops = {
.llseek = generic_file_llseek,
.read = generic_file_read,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.mmap = generic_file_readonly_mmap,
.sendfile = generic_file_sendfile,
};
Expand Down
24 changes: 15 additions & 9 deletions fs/smbfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,15 @@ smb_updatepage(struct file *file, struct page *page, unsigned long offset,
}

static ssize_t
smb_file_read(struct file * file, char __user * buf, size_t count, loff_t *ppos)
smb_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
unsigned long nr_segs, loff_t pos)
{
struct file * file = iocb->ki_filp;
struct dentry * dentry = file->f_dentry;
ssize_t status;

VERBOSE("file %s/%s, count=%lu@%lu\n", DENTRY_PATH(dentry),
(unsigned long) count, (unsigned long) *ppos);
(unsigned long) iocb->ki_left, (unsigned long) pos);

status = smb_revalidate_inode(dentry);
if (status) {
Expand All @@ -233,7 +235,7 @@ smb_file_read(struct file * file, char __user * buf, size_t count, loff_t *ppos)
(long)dentry->d_inode->i_size,
dentry->d_inode->i_flags, dentry->d_inode->i_atime);

status = generic_file_read(file, buf, count, ppos);
status = generic_file_aio_read(iocb, iov, nr_segs, pos);
out:
return status;
}
Expand Down Expand Up @@ -317,14 +319,16 @@ const struct address_space_operations smb_file_aops = {
* Write to a file (through the page cache).
*/
static ssize_t
smb_file_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
smb_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
unsigned long nr_segs, loff_t pos)
{
struct file * file = iocb->ki_filp;
struct dentry * dentry = file->f_dentry;
ssize_t result;

VERBOSE("file %s/%s, count=%lu@%lu\n",
DENTRY_PATH(dentry),
(unsigned long) count, (unsigned long) *ppos);
(unsigned long) iocb->ki_left, (unsigned long) pos);

result = smb_revalidate_inode(dentry);
if (result) {
Expand All @@ -337,8 +341,8 @@ smb_file_write(struct file *file, const char __user *buf, size_t count, loff_t *
if (result)
goto out;

if (count > 0) {
result = generic_file_write(file, buf, count, ppos);
if (iocb->ki_left > 0) {
result = generic_file_aio_write(iocb, iov, nr_segs, pos);
VERBOSE("pos=%ld, size=%ld, mtime=%ld, atime=%ld\n",
(long) file->f_pos, (long) dentry->d_inode->i_size,
dentry->d_inode->i_mtime, dentry->d_inode->i_atime);
Expand Down Expand Up @@ -402,8 +406,10 @@ smb_file_permission(struct inode *inode, int mask, struct nameidata *nd)
const struct file_operations smb_file_operations =
{
.llseek = remote_llseek,
.read = smb_file_read,
.write = smb_file_write,
.read = do_sync_read,
.aio_read = smb_file_aio_read,
.write = do_sync_write,
.aio_write = smb_file_aio_write,
.ioctl = smb_ioctl,
.mmap = smb_file_mmap,
.open = smb_file_open,
Expand Down
6 changes: 4 additions & 2 deletions fs/sysv/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
*/
const struct file_operations sysv_file_operations = {
.llseek = generic_file_llseek,
.read = generic_file_read,
.write = generic_file_write,
.read = do_sync_read,
.aio_read = generic_file_aio_read,
.write = do_sync_write,
.aio_write = generic_file_aio_write,
.mmap = generic_file_mmap,
.fsync = sysv_sync_file,
.sendfile = generic_file_sendfile,
Expand Down
Loading

0 comments on commit 543ade1

Please sign in to comment.