[PATCH] Vectorize aio_read/aio_write fileop methods
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / nfs / file.c
index fade02c15e6ef11a8575e6381b6f10445a1de375..cc93865cea932a4e9c78ea95e1c0165e575630d1 100644 (file)
@@ -41,9 +41,11 @@ static int nfs_file_release(struct inode *, struct file *);
 static loff_t nfs_file_llseek(struct file *file, loff_t offset, int origin);
 static int  nfs_file_mmap(struct file *, struct vm_area_struct *);
 static ssize_t nfs_file_sendfile(struct file *, loff_t *, size_t, read_actor_t, void *);
-static ssize_t nfs_file_read(struct kiocb *, char __user *, size_t, loff_t);
-static ssize_t nfs_file_write(struct kiocb *, const char __user *, size_t, loff_t);
-static int  nfs_file_flush(struct file *);
+static ssize_t nfs_file_read(struct kiocb *, const struct iovec *iov,
+                               unsigned long nr_segs, loff_t pos);
+static ssize_t nfs_file_write(struct kiocb *, const struct iovec *iov,
+                               unsigned long nr_segs, loff_t pos);
+static int  nfs_file_flush(struct file *, fl_owner_t id);
 static int  nfs_fsync(struct file *, struct dentry *dentry, int datasync);
 static int nfs_check_flags(int flags);
 static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl);
@@ -53,8 +55,8 @@ const struct file_operations nfs_file_operations = {
        .llseek         = nfs_file_llseek,
        .read           = do_sync_read,
        .write          = do_sync_write,
-       .aio_read               = nfs_file_read,
-       .aio_write              = nfs_file_write,
+       .aio_read       = nfs_file_read,
+       .aio_write      = nfs_file_write,
        .mmap           = nfs_file_mmap,
        .open           = nfs_file_open,
        .flush          = nfs_file_flush,
@@ -111,7 +113,7 @@ nfs_file_open(struct inode *inode, struct file *filp)
 
        nfs_inc_stats(inode, NFSIOS_VFSOPEN);
        lock_kernel();
-       res = NFS_SERVER(inode)->rpc_ops->file_open(inode, filp);
+       res = NFS_PROTO(inode)->file_open(inode, filp);
        unlock_kernel();
        return res;
 }
@@ -126,23 +128,6 @@ nfs_file_release(struct inode *inode, struct file *filp)
        return NFS_PROTO(inode)->file_release(inode, filp);
 }
 
-/**
- * nfs_revalidate_file - Revalidate the page cache & related metadata
- * @inode - pointer to inode struct
- * @file - pointer to file
- */
-static int nfs_revalidate_file(struct inode *inode, struct file *filp)
-{
-       struct nfs_inode *nfsi = NFS_I(inode);
-       int retval = 0;
-
-       if ((nfsi->cache_validity & (NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_ATTR))
-                       || nfs_attribute_timeout(inode))
-               retval = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
-       nfs_revalidate_mapping(inode, filp->f_mapping);
-       return 0;
-}
-
 /**
  * nfs_revalidate_size - Revalidate the file size
  * @inode - pointer to inode struct
@@ -174,7 +159,7 @@ force_reval:
 static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
 {
        /* origin == SEEK_END => we must revalidate the cached file length */
-       if (origin == 2) {
+       if (origin == SEEK_END) {
                struct inode *inode = filp->f_mapping->host;
                int retval = nfs_revalidate_file_size(inode, filp);
                if (retval < 0)
@@ -188,7 +173,7 @@ static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin)
  *
  */
 static int
-nfs_file_flush(struct file *file)
+nfs_file_flush(struct file *file, fl_owner_t id)
 {
        struct nfs_open_context *ctx = (struct nfs_open_context *)file->private_data;
        struct inode    *inode = file->f_dentry->d_inode;
@@ -213,25 +198,27 @@ nfs_file_flush(struct file *file)
 }
 
 static ssize_t
-nfs_file_read(struct kiocb *iocb, char __user * buf, size_t count, loff_t pos)
+nfs_file_read(struct kiocb *iocb, const struct iovec *iov,
+               unsigned long nr_segs, loff_t pos)
 {
        struct dentry * dentry = iocb->ki_filp->f_dentry;
        struct inode * inode = dentry->d_inode;
        ssize_t result;
+       size_t count = iov_length(iov, nr_segs);
 
 #ifdef CONFIG_NFS_DIRECTIO
        if (iocb->ki_filp->f_flags & O_DIRECT)
-               return nfs_file_direct_read(iocb, buf, count, pos);
+               return nfs_file_direct_read(iocb, iov, nr_segs, pos);
 #endif
 
        dfprintk(VFS, "nfs: read(%s/%s, %lu@%lu)\n",
                dentry->d_parent->d_name.name, dentry->d_name.name,
                (unsigned long) count, (unsigned long) pos);
 
-       result = nfs_revalidate_file(inode, iocb->ki_filp);
+       result = nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping);
        nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, count);
        if (!result)
-               result = generic_file_aio_read(iocb, buf, count, pos);
+               result = generic_file_aio_read(iocb, iov, nr_segs, pos);
        return result;
 }
 
@@ -247,7 +234,7 @@ nfs_file_sendfile(struct file *filp, loff_t *ppos, size_t count,
                dentry->d_parent->d_name.name, dentry->d_name.name,
                (unsigned long) count, (unsigned long long) *ppos);
 
-       res = nfs_revalidate_file(inode, filp);
+       res = nfs_revalidate_mapping(inode, filp->f_mapping);
        if (!res)
                res = generic_file_sendfile(filp, ppos, count, actor, target);
        return res;
@@ -263,7 +250,7 @@ nfs_file_mmap(struct file * file, struct vm_area_struct * vma)
        dfprintk(VFS, "nfs: mmap(%s/%s)\n",
                dentry->d_parent->d_name.name, dentry->d_name.name);
 
-       status = nfs_revalidate_file(inode, file);
+       status = nfs_revalidate_mapping(inode, file->f_mapping);
        if (!status)
                status = generic_file_mmap(file, vma);
        return status;
@@ -320,15 +307,25 @@ static int nfs_commit_write(struct file *file, struct page *page, unsigned offse
 
 static void nfs_invalidate_page(struct page *page, unsigned long offset)
 {
-       /* FIXME: we really should cancel any unstarted writes on this page */
+       struct inode *inode = page->mapping->host;
+
+       /* Cancel any unstarted writes on this page */
+       if (offset == 0)
+               nfs_sync_inode_wait(inode, page->index, 1, FLUSH_INVALIDATE);
 }
 
 static int nfs_release_page(struct page *page, gfp_t gfp)
 {
-       return !nfs_wb_page(page->mapping->host, page);
+       if (gfp & __GFP_FS)
+               return !nfs_wb_page(page->mapping->host, page);
+       else
+               /*
+                * Avoid deadlock on nfs_wait_on_request().
+                */
+               return 0;
 }
 
-struct address_space_operations nfs_file_aops = {
+const struct address_space_operations nfs_file_aops = {
        .readpage = nfs_readpage,
        .readpages = nfs_readpages,
        .set_page_dirty = __set_page_dirty_nobuffers,
@@ -343,24 +340,22 @@ struct address_space_operations nfs_file_aops = {
 #endif
 };
 
-/* 
- * Write to a file (through the page cache).
- */
-static ssize_t
-nfs_file_write(struct kiocb *iocb, const char __user *buf, size_t count, loff_t pos)
+static ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,
+                               unsigned long nr_segs, loff_t pos)
 {
        struct dentry * dentry = iocb->ki_filp->f_dentry;
        struct inode * inode = dentry->d_inode;
        ssize_t result;
+       size_t count = iov_length(iov, nr_segs);
 
 #ifdef CONFIG_NFS_DIRECTIO
        if (iocb->ki_filp->f_flags & O_DIRECT)
-               return nfs_file_direct_write(iocb, buf, count, pos);
+               return nfs_file_direct_write(iocb, iov, nr_segs, pos);
 #endif
 
-       dfprintk(VFS, "nfs: write(%s/%s(%ld), %lu@%lu)\n",
+       dfprintk(VFS, "nfs: write(%s/%s(%ld), %lu@%Ld)\n",
                dentry->d_parent->d_name.name, dentry->d_name.name,
-               inode->i_ino, (unsigned long) count, (unsigned long) pos);
+               inode->i_ino, (unsigned long) count, (long long) pos);
 
        result = -EBUSY;
        if (IS_SWAPFILE(inode))
@@ -373,14 +368,13 @@ nfs_file_write(struct kiocb *iocb, const char __user *buf, size_t count, loff_t
                if (result)
                        goto out;
        }
-       nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping);
 
        result = count;
        if (!count)
                goto out;
 
        nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, count);
-       result = generic_file_aio_write(iocb, buf, count, pos);
+       result = generic_file_aio_write(iocb, iov, nr_segs, pos);
 out:
        return result;