9p: get rid of v9fs_direct_file_write()
authorAl Viro <viro@zeniv.linux.org.uk>
Thu, 2 Apr 2015 02:32:23 +0000 (22:32 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sun, 12 Apr 2015 02:28:26 +0000 (22:28 -0400)
just handle it in ->direct_IO()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/9p/vfs_addr.c
fs/9p/vfs_file.c

index 0e153f07e0fcf4e2b419c674108b9c24568a93b2..402269c108cd865545fd3762ad1b3f28361b339f 100644 (file)
@@ -252,15 +252,21 @@ static int v9fs_launder_page(struct page *page)
 static ssize_t
 v9fs_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter, loff_t pos)
 {
-       /*
-        * FIXME
-        * Now that we do caching with cache mode enabled, We need
-        * to support direct IO
-        */
-       p9_debug(P9_DEBUG_VFS, "v9fs_direct_IO: v9fs_direct_IO (%pD) off/no(%lld/%lu) EINVAL\n",
-                iocb->ki_filp,
-                (long long)pos, iter->nr_segs);
-
+       struct file *file = iocb->ki_filp;
+       if (rw == WRITE) {
+               ssize_t written;
+               int err = 0;
+
+               written = p9_client_write(file->private_data, pos, iter, &err);
+               if (written) {
+                       struct inode *inode = file_inode(file);
+                       loff_t i_size = i_size_read(inode);
+                       if (pos + written > i_size)
+                               inode_add_bytes(inode, pos + written - i_size);
+                       return written;
+               }
+               return err;
+       }
        return -EINVAL;
 }
 
index a54d81f9097f88bc84b86d16651db0ae77f96eaf..1e4619693721b7d0401cd0f095e817261e12579e 100644 (file)
@@ -688,77 +688,6 @@ v9fs_mmap_file_read(struct file *filp, char __user *data, size_t count,
        return v9fs_file_read(filp, data, count, offset);
 }
 
-static ssize_t
-v9fs_direct_write(struct file *filp, const char __user * data,
-                 size_t count, loff_t *offsetp)
-{
-       loff_t offset;
-       ssize_t retval;
-       struct inode *inode;
-       struct address_space *mapping;
-
-       offset = *offsetp;
-       mapping = filp->f_mapping;
-       inode = mapping->host;
-       if (!count)
-               return 0;
-
-       mutex_lock(&inode->i_mutex);
-       retval = filemap_write_and_wait_range(mapping, offset,
-                                             offset + count - 1);
-       if (retval)
-               goto err_out;
-       /*
-        * After a write we want buffered reads to be sure to go to disk to get
-        * the new data.  We invalidate clean cached page from the region we're
-        * about to write.  We do this *before* the write so that if we fail
-        * here we fall back to buffered write
-        */
-       if (mapping->nrpages) {
-               pgoff_t pg_start = offset >> PAGE_CACHE_SHIFT;
-               pgoff_t pg_end   = (offset + count - 1) >> PAGE_CACHE_SHIFT;
-
-               retval = invalidate_inode_pages2_range(mapping,
-                                                       pg_start, pg_end);
-               /*
-                * If a page can not be invalidated, fall back
-                * to buffered write.
-                */
-               if (retval) {
-                       if (retval == -EBUSY)
-                               goto buff_write;
-                       goto err_out;
-               }
-       }
-       retval = v9fs_file_write(filp, data, count, offsetp);
-err_out:
-       mutex_unlock(&inode->i_mutex);
-       return retval;
-
-buff_write:
-       mutex_unlock(&inode->i_mutex);
-       return new_sync_write(filp, data, count, offsetp);
-}
-
-/**
- * v9fs_cached_file_write - write to a file
- * @filp: file pointer to write
- * @data: data buffer to write data from
- * @count: size of buffer
- * @offset: offset at which to write data
- *
- */
-static ssize_t
-v9fs_cached_file_write(struct file *filp, const char __user * data,
-                      size_t count, loff_t *offset)
-{
-
-       if (filp->f_flags & O_DIRECT)
-               return v9fs_direct_write(filp, data, count, offset);
-       return new_sync_write(filp, data, count, offset);
-}
-
-
 /**
  * v9fs_mmap_file_write - write to a file
  * @filp: file pointer to write
@@ -821,7 +750,7 @@ static const struct vm_operations_struct v9fs_mmap_file_vm_ops = {
 const struct file_operations v9fs_cached_file_operations = {
        .llseek = generic_file_llseek,
        .read = v9fs_cached_file_read,
-       .write = v9fs_cached_file_write,
+       .write = new_sync_write,
        .read_iter = generic_file_read_iter,
        .write_iter = generic_file_write_iter,
        .open = v9fs_file_open,
@@ -834,7 +763,7 @@ const struct file_operations v9fs_cached_file_operations = {
 const struct file_operations v9fs_cached_file_operations_dotl = {
        .llseek = generic_file_llseek,
        .read = v9fs_cached_file_read,
-       .write = v9fs_cached_file_write,
+       .write = new_sync_write,
        .read_iter = generic_file_read_iter,
        .write_iter = generic_file_write_iter,
        .open = v9fs_file_open,