nfs: merge nfs_direct_read into nfs_file_direct_read
Simple code cleanup to prepare for later fixes. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
This commit is contained in:
parent
1f90ee2746
commit
14a3ec7943
107
fs/nfs/direct.c
107
fs/nfs/direct.c
|
@ -458,14 +458,55 @@ static ssize_t nfs_direct_read_schedule_iovec(struct nfs_direct_req *dreq,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t nfs_direct_read(struct kiocb *iocb, const struct iovec *iov,
|
||||
unsigned long nr_segs, loff_t pos, bool uio)
|
||||
/**
|
||||
* nfs_file_direct_read - file direct read operation for NFS files
|
||||
* @iocb: target I/O control block
|
||||
* @iov: vector of user buffers into which to read data
|
||||
* @nr_segs: size of iov vector
|
||||
* @pos: byte offset in file where reading starts
|
||||
*
|
||||
* We use this function for direct reads instead of calling
|
||||
* generic_file_aio_read() in order to avoid gfar's check to see if
|
||||
* the request starts before the end of the file. For that check
|
||||
* to work, we must generate a GETATTR before each direct read, and
|
||||
* even then there is a window between the GETATTR and the subsequent
|
||||
* READ where the file size could change. Our preference is simply
|
||||
* to do all reads the application wants, and the server will take
|
||||
* care of managing the end of file boundary.
|
||||
*
|
||||
* This function also eliminates unnecessarily updating the file's
|
||||
* atime locally, as the NFS server sets the file's atime, and this
|
||||
* client must read the updated atime from the server back into its
|
||||
* cache.
|
||||
*/
|
||||
ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov,
|
||||
unsigned long nr_segs, loff_t pos, bool uio)
|
||||
{
|
||||
ssize_t result = -ENOMEM;
|
||||
struct inode *inode = iocb->ki_filp->f_mapping->host;
|
||||
struct file *file = iocb->ki_filp;
|
||||
struct address_space *mapping = file->f_mapping;
|
||||
struct inode *inode = mapping->host;
|
||||
struct nfs_direct_req *dreq;
|
||||
struct nfs_lock_context *l_ctx;
|
||||
ssize_t result = -EINVAL;
|
||||
size_t count;
|
||||
|
||||
count = iov_length(iov, nr_segs);
|
||||
nfs_add_stats(mapping->host, NFSIOS_DIRECTREADBYTES, count);
|
||||
|
||||
dfprintk(FILE, "NFS: direct read(%pD2, %zd@%Ld)\n",
|
||||
file, count, (long long) pos);
|
||||
|
||||
result = 0;
|
||||
if (!count)
|
||||
goto out;
|
||||
|
||||
result = nfs_sync_mapping(mapping);
|
||||
if (result)
|
||||
goto out;
|
||||
|
||||
task_io_account_read(count);
|
||||
|
||||
result = -ENOMEM;
|
||||
dreq = nfs_direct_req_alloc();
|
||||
if (dreq == NULL)
|
||||
goto out;
|
||||
|
@ -484,8 +525,11 @@ static ssize_t nfs_direct_read(struct kiocb *iocb, const struct iovec *iov,
|
|||
|
||||
NFS_I(inode)->read_io += iov_length(iov, nr_segs);
|
||||
result = nfs_direct_read_schedule_iovec(dreq, iov, nr_segs, pos, uio);
|
||||
if (!result)
|
||||
if (!result) {
|
||||
result = nfs_direct_wait(dreq);
|
||||
if (result > 0)
|
||||
iocb->ki_pos = pos + result;
|
||||
}
|
||||
out_release:
|
||||
nfs_direct_req_release(dreq);
|
||||
out:
|
||||
|
@ -888,59 +932,6 @@ out:
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* nfs_file_direct_read - file direct read operation for NFS files
|
||||
* @iocb: target I/O control block
|
||||
* @iov: vector of user buffers into which to read data
|
||||
* @nr_segs: size of iov vector
|
||||
* @pos: byte offset in file where reading starts
|
||||
*
|
||||
* We use this function for direct reads instead of calling
|
||||
* generic_file_aio_read() in order to avoid gfar's check to see if
|
||||
* the request starts before the end of the file. For that check
|
||||
* to work, we must generate a GETATTR before each direct read, and
|
||||
* even then there is a window between the GETATTR and the subsequent
|
||||
* READ where the file size could change. Our preference is simply
|
||||
* to do all reads the application wants, and the server will take
|
||||
* care of managing the end of file boundary.
|
||||
*
|
||||
* This function also eliminates unnecessarily updating the file's
|
||||
* atime locally, as the NFS server sets the file's atime, and this
|
||||
* client must read the updated atime from the server back into its
|
||||
* cache.
|
||||
*/
|
||||
ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov,
|
||||
unsigned long nr_segs, loff_t pos, bool uio)
|
||||
{
|
||||
ssize_t retval = -EINVAL;
|
||||
struct file *file = iocb->ki_filp;
|
||||
struct address_space *mapping = file->f_mapping;
|
||||
size_t count;
|
||||
|
||||
count = iov_length(iov, nr_segs);
|
||||
nfs_add_stats(mapping->host, NFSIOS_DIRECTREADBYTES, count);
|
||||
|
||||
dfprintk(FILE, "NFS: direct read(%pD2, %zd@%Ld)\n",
|
||||
file, count, (long long) pos);
|
||||
|
||||
retval = 0;
|
||||
if (!count)
|
||||
goto out;
|
||||
|
||||
retval = nfs_sync_mapping(mapping);
|
||||
if (retval)
|
||||
goto out;
|
||||
|
||||
task_io_account_read(count);
|
||||
|
||||
retval = nfs_direct_read(iocb, iov, nr_segs, pos, uio);
|
||||
if (retval > 0)
|
||||
iocb->ki_pos = pos + retval;
|
||||
|
||||
out:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* nfs_file_direct_write - file direct write operation for NFS files
|
||||
* @iocb: target I/O control block
|
||||
|
|
Loading…
Reference in New Issue