diff options
Diffstat (limited to 'fs/nfs/file.c')
| -rw-r--r-- | fs/nfs/file.c | 175 | 
1 files changed, 55 insertions, 120 deletions
diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 1e6bfdbc1af..4042ff58fe3 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -65,9 +65,7 @@ nfs_file_open(struct inode *inode, struct file *filp)  {  	int res; -	dprintk("NFS: open file(%s/%s)\n", -			filp->f_path.dentry->d_parent->d_name.name, -			filp->f_path.dentry->d_name.name); +	dprintk("NFS: open file(%pD2)\n", filp);  	nfs_inc_stats(inode, NFSIOS_VFSOPEN);  	res = nfs_check_flags(filp->f_flags); @@ -81,9 +79,7 @@ nfs_file_open(struct inode *inode, struct file *filp)  int  nfs_file_release(struct inode *inode, struct file *filp)  { -	dprintk("NFS: release(%s/%s)\n", -			filp->f_path.dentry->d_parent->d_name.name, -			filp->f_path.dentry->d_name.name); +	dprintk("NFS: release(%pD2)\n", filp);  	nfs_inc_stats(inode, NFSIOS_VFSRELEASE);  	return nfs_release(inode, filp); @@ -123,10 +119,8 @@ force_reval:  loff_t nfs_file_llseek(struct file *filp, loff_t offset, int whence)  { -	dprintk("NFS: llseek file(%s/%s, %lld, %d)\n", -			filp->f_path.dentry->d_parent->d_name.name, -			filp->f_path.dentry->d_name.name, -			offset, whence); +	dprintk("NFS: llseek file(%pD2, %lld, %d)\n", +			filp, offset, whence);  	/*  	 * whence == SEEK_END || SEEK_DATA || SEEK_HOLE => we must revalidate @@ -150,12 +144,9 @@ EXPORT_SYMBOL_GPL(nfs_file_llseek);  int  nfs_file_flush(struct file *file, fl_owner_t id)  { -	struct dentry	*dentry = file->f_path.dentry; -	struct inode	*inode = dentry->d_inode; +	struct inode	*inode = file_inode(file); -	dprintk("NFS: flush(%s/%s)\n", -			dentry->d_parent->d_name.name, -			dentry->d_name.name); +	dprintk("NFS: flush(%pD2)\n", file);  	nfs_inc_stats(inode, NFSIOS_VFSFLUSH);  	if ((file->f_mode & FMODE_WRITE) == 0) @@ -174,23 +165,21 @@ nfs_file_flush(struct file *file, fl_owner_t id)  EXPORT_SYMBOL_GPL(nfs_file_flush);  ssize_t -nfs_file_read(struct kiocb *iocb, const struct iovec *iov, -		unsigned long nr_segs, loff_t pos) +nfs_file_read(struct kiocb *iocb, struct iov_iter *to)  { -	struct dentry * dentry = iocb->ki_filp->f_path.dentry; -	struct inode * inode = dentry->d_inode; +	struct inode *inode = file_inode(iocb->ki_filp);  	ssize_t result;  	if (iocb->ki_filp->f_flags & O_DIRECT) -		return nfs_file_direct_read(iocb, iov, nr_segs, pos, true); +		return nfs_file_direct_read(iocb, to, iocb->ki_pos, true); -	dprintk("NFS: read(%s/%s, %lu@%lu)\n", -		dentry->d_parent->d_name.name, dentry->d_name.name, -		(unsigned long) iov_length(iov, nr_segs), (unsigned long) pos); +	dprintk("NFS: read(%pD2, %zu@%lu)\n", +		iocb->ki_filp, +		iov_iter_count(to), (unsigned long) iocb->ki_pos);  	result = nfs_revalidate_mapping(inode, iocb->ki_filp->f_mapping);  	if (!result) { -		result = generic_file_aio_read(iocb, iov, nr_segs, pos); +		result = generic_file_read_iter(iocb, to);  		if (result > 0)  			nfs_add_stats(inode, NFSIOS_NORMALREADBYTES, result);  	} @@ -203,13 +192,11 @@ nfs_file_splice_read(struct file *filp, loff_t *ppos,  		     struct pipe_inode_info *pipe, size_t count,  		     unsigned int flags)  { -	struct dentry *dentry = filp->f_path.dentry; -	struct inode *inode = dentry->d_inode; +	struct inode *inode = file_inode(filp);  	ssize_t res; -	dprintk("NFS: splice_read(%s/%s, %lu@%Lu)\n", -		dentry->d_parent->d_name.name, dentry->d_name.name, -		(unsigned long) count, (unsigned long long) *ppos); +	dprintk("NFS: splice_read(%pD2, %lu@%Lu)\n", +		filp, (unsigned long) count, (unsigned long long) *ppos);  	res = nfs_revalidate_mapping(inode, filp->f_mapping);  	if (!res) { @@ -224,12 +211,10 @@ EXPORT_SYMBOL_GPL(nfs_file_splice_read);  int  nfs_file_mmap(struct file * file, struct vm_area_struct * vma)  { -	struct dentry *dentry = file->f_path.dentry; -	struct inode *inode = dentry->d_inode; +	struct inode *inode = file_inode(file);  	int	status; -	dprintk("NFS: mmap(%s/%s)\n", -		dentry->d_parent->d_name.name, dentry->d_name.name); +	dprintk("NFS: mmap(%pD2)\n", file);  	/* Note: generic_file_mmap() returns ENOSYS on nommu systems  	 *       so we call that before revalidating the mapping @@ -258,15 +243,12 @@ EXPORT_SYMBOL_GPL(nfs_file_mmap);  int  nfs_file_fsync_commit(struct file *file, loff_t start, loff_t end, int datasync)  { -	struct dentry *dentry = file->f_path.dentry;  	struct nfs_open_context *ctx = nfs_file_open_context(file); -	struct inode *inode = dentry->d_inode; +	struct inode *inode = file_inode(file);  	int have_error, do_resend, status;  	int ret = 0; -	dprintk("NFS: fsync file(%s/%s) datasync %d\n", -			dentry->d_parent->d_name.name, dentry->d_name.name, -			datasync); +	dprintk("NFS: fsync file(%pD2) datasync %d\n", file, datasync);  	nfs_inc_stats(inode, NFSIOS_VFSFSYNC);  	do_resend = test_and_clear_bit(NFS_CONTEXT_RESEND_WRITES, &ctx->flags); @@ -371,10 +353,8 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping,  	struct page *page;  	int once_thru = 0; -	dfprintk(PAGECACHE, "NFS: write_begin(%s/%s(%ld), %u@%lld)\n", -		file->f_path.dentry->d_parent->d_name.name, -		file->f_path.dentry->d_name.name, -		mapping->host->i_ino, len, (long long) pos); +	dfprintk(PAGECACHE, "NFS: write_begin(%pD2(%lu), %u@%lld)\n", +		file, mapping->host->i_ino, len, (long long) pos);  start:  	/* @@ -414,10 +394,8 @@ static int nfs_write_end(struct file *file, struct address_space *mapping,  	struct nfs_open_context *ctx = nfs_file_open_context(file);  	int status; -	dfprintk(PAGECACHE, "NFS: write_end(%s/%s(%ld), %u@%lld)\n", -		file->f_path.dentry->d_parent->d_name.name, -		file->f_path.dentry->d_name.name, -		mapping->host->i_ino, len, (long long) pos); +	dfprintk(PAGECACHE, "NFS: write_end(%pD2(%lu), %u@%lld)\n", +		file, mapping->host->i_ino, len, (long long) pos);  	/*  	 * Zero any uninitialised parts of the page, and then mark the page @@ -601,22 +579,21 @@ static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)  {  	struct page *page = vmf->page;  	struct file *filp = vma->vm_file; -	struct dentry *dentry = filp->f_path.dentry; +	struct inode *inode = file_inode(filp);  	unsigned pagelen;  	int ret = VM_FAULT_NOPAGE;  	struct address_space *mapping; -	dfprintk(PAGECACHE, "NFS: vm_page_mkwrite(%s/%s(%ld), offset %lld)\n", -		dentry->d_parent->d_name.name, dentry->d_name.name, -		filp->f_mapping->host->i_ino, +	dfprintk(PAGECACHE, "NFS: vm_page_mkwrite(%pD2(%lu), offset %lld)\n", +		filp, filp->f_mapping->host->i_ino,  		(long long)page_offset(page));  	/* make sure the cache has finished storing the page */ -	nfs_fscache_wait_on_page_write(NFS_I(dentry->d_inode), page); +	nfs_fscache_wait_on_page_write(NFS_I(inode), page);  	lock_page(page);  	mapping = page_file_mapping(page); -	if (mapping != dentry->d_inode->i_mapping) +	if (mapping != inode->i_mapping)  		goto out_unlock;  	wait_on_page_writeback(page); @@ -639,6 +616,7 @@ out:  static const struct vm_operations_struct nfs_file_vm_ops = {  	.fault = filemap_fault, +	.map_pages = filemap_map_pages,  	.page_mkwrite = nfs_vm_page_mkwrite,  	.remap_pages = generic_file_remap_pages,  }; @@ -656,25 +634,24 @@ static int nfs_need_sync_write(struct file *filp, struct inode *inode)  	return 0;  } -ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov, -		       unsigned long nr_segs, loff_t pos) +ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)  { -	struct dentry * dentry = iocb->ki_filp->f_path.dentry; -	struct inode * inode = dentry->d_inode; +	struct file *file = iocb->ki_filp; +	struct inode *inode = file_inode(file);  	unsigned long written = 0;  	ssize_t result; -	size_t count = iov_length(iov, nr_segs); +	size_t count = iov_iter_count(from); +	loff_t pos = iocb->ki_pos; -	result = nfs_key_timeout_notify(iocb->ki_filp, inode); +	result = nfs_key_timeout_notify(file, inode);  	if (result)  		return result; -	if (iocb->ki_filp->f_flags & O_DIRECT) -		return nfs_file_direct_write(iocb, iov, nr_segs, pos, true); +	if (file->f_flags & O_DIRECT) +		return nfs_file_direct_write(iocb, from, pos, true); -	dprintk("NFS: write(%s/%s, %lu@%Ld)\n", -		dentry->d_parent->d_name.name, dentry->d_name.name, -		(unsigned long) count, (long long) pos); +	dprintk("NFS: write(%pD2, %zu@%Ld)\n", +		file, count, (long long) pos);  	result = -EBUSY;  	if (IS_SWAPFILE(inode)) @@ -682,8 +659,8 @@ ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,  	/*  	 * O_APPEND implies that we must revalidate the file length.  	 */ -	if (iocb->ki_filp->f_flags & O_APPEND) { -		result = nfs_revalidate_file_size(inode, iocb->ki_filp); +	if (file->f_flags & O_APPEND) { +		result = nfs_revalidate_file_size(inode, file);  		if (result)  			goto out;  	} @@ -692,13 +669,13 @@ ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,  	if (!count)  		goto out; -	result = generic_file_aio_write(iocb, iov, nr_segs, pos); +	result = generic_file_write_iter(iocb, from);  	if (result > 0)  		written = result;  	/* Return error values for O_DSYNC and IS_SYNC() */ -	if (result >= 0 && nfs_need_sync_write(iocb->ki_filp, inode)) { -		int err = vfs_fsync(iocb->ki_filp, 0); +	if (result >= 0 && nfs_need_sync_write(file, inode)) { +		int err = vfs_fsync(file, 0);  		if (err < 0)  			result = err;  	} @@ -713,38 +690,6 @@ out_swapfile:  }  EXPORT_SYMBOL_GPL(nfs_file_write); -ssize_t nfs_file_splice_write(struct pipe_inode_info *pipe, -			      struct file *filp, loff_t *ppos, -			      size_t count, unsigned int flags) -{ -	struct dentry *dentry = filp->f_path.dentry; -	struct inode *inode = dentry->d_inode; -	unsigned long written = 0; -	ssize_t ret; - -	dprintk("NFS splice_write(%s/%s, %lu@%llu)\n", -		dentry->d_parent->d_name.name, dentry->d_name.name, -		(unsigned long) count, (unsigned long long) *ppos); - -	/* -	 * The combination of splice and an O_APPEND destination is disallowed. -	 */ - -	ret = generic_file_splice_write(pipe, filp, ppos, count, flags); -	if (ret > 0) -		written = ret; - -	if (ret >= 0 && nfs_need_sync_write(filp, inode)) { -		int err = vfs_fsync(filp, 0); -		if (err < 0) -			ret = err; -	} -	if (ret > 0) -		nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written); -	return ret; -} -EXPORT_SYMBOL_GPL(nfs_file_splice_write); -  static int  do_getlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)  { @@ -883,10 +828,8 @@ int nfs_lock(struct file *filp, int cmd, struct file_lock *fl)  	int ret = -ENOLCK;  	int is_local = 0; -	dprintk("NFS: lock(%s/%s, t=%x, fl=%x, r=%lld:%lld)\n", -			filp->f_path.dentry->d_parent->d_name.name, -			filp->f_path.dentry->d_name.name, -			fl->fl_type, fl->fl_flags, +	dprintk("NFS: lock(%pD2, t=%x, fl=%x, r=%lld:%lld)\n", +			filp, fl->fl_type, fl->fl_flags,  			(long long)fl->fl_start, (long long)fl->fl_end);  	nfs_inc_stats(inode, NFSIOS_VFSLOCK); @@ -923,10 +866,8 @@ int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)  	struct inode *inode = filp->f_mapping->host;  	int is_local = 0; -	dprintk("NFS: flock(%s/%s, t=%x, fl=%x)\n", -			filp->f_path.dentry->d_parent->d_name.name, -			filp->f_path.dentry->d_name.name, -			fl->fl_type, fl->fl_flags); +	dprintk("NFS: flock(%pD2, t=%x, fl=%x)\n", +			filp, fl->fl_type, fl->fl_flags);  	if (!(fl->fl_flags & FL_FLOCK))  		return -ENOLCK; @@ -944,10 +885,6 @@ int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)  		is_local = 1;  	/* We're simulating flock() locks using posix locks on the server */ -	fl->fl_owner = (fl_owner_t)filp; -	fl->fl_start = 0; -	fl->fl_end = OFFSET_MAX; -  	if (fl->fl_type == F_UNLCK)  		return do_unlk(filp, cmd, fl, is_local);  	return do_setlk(filp, cmd, fl, is_local); @@ -960,19 +897,17 @@ EXPORT_SYMBOL_GPL(nfs_flock);   */  int nfs_setlease(struct file *file, long arg, struct file_lock **fl)  { -	dprintk("NFS: setlease(%s/%s, arg=%ld)\n", -			file->f_path.dentry->d_parent->d_name.name, -			file->f_path.dentry->d_name.name, arg); +	dprintk("NFS: setlease(%pD2, arg=%ld)\n", file, arg);  	return -EINVAL;  }  EXPORT_SYMBOL_GPL(nfs_setlease);  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, +	.read		= new_sync_read, +	.write		= new_sync_write, +	.read_iter	= nfs_file_read, +	.write_iter	= nfs_file_write,  	.mmap		= nfs_file_mmap,  	.open		= nfs_file_open,  	.flush		= nfs_file_flush, @@ -981,7 +916,7 @@ const struct file_operations nfs_file_operations = {  	.lock		= nfs_lock,  	.flock		= nfs_flock,  	.splice_read	= nfs_file_splice_read, -	.splice_write	= nfs_file_splice_write, +	.splice_write	= iter_file_splice_write,  	.check_flags	= nfs_check_flags,  	.setlease	= nfs_setlease,  };  | 
