19 #include <linux/module.h>
20 #include <linux/time.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/fcntl.h>
24 #include <linux/stat.h>
25 #include <linux/nfs_fs.h>
33 #include <asm/uaccess.h>
40 #define NFSDBG_FACILITY NFSDBG_FILE
42 static const struct vm_operations_struct nfs_file_vm_ops;
46 # define IS_SWAPFILE(inode) (0)
66 dprintk(
"NFS: open file(%s/%s)\n",
67 filp->
f_path.dentry->d_parent->d_name.name,
68 filp->
f_path.dentry->d_name.name);
82 dprintk(
"NFS: release(%s/%s)\n",
83 filp->
f_path.dentry->d_parent->d_name.name,
84 filp->
f_path.dentry->d_name.name);
102 static int nfs_revalidate_file_size(
struct inode *inode,
struct file *filp)
104 struct nfs_server *server = NFS_SERVER(inode);
107 if (nfs_have_delegated_attributes(inode))
124 dprintk(
"NFS: llseek file(%s/%s, %lld, %d)\n",
125 filp->
f_path.dentry->d_parent->d_name.name,
126 filp->
f_path.dentry->d_name.name,
134 struct inode *inode = filp->
f_mapping->host;
136 int retval = nfs_revalidate_file_size(inode, filp);
152 struct inode *inode = dentry->
d_inode;
166 if (NFS_PROTO(inode)->have_delegation(inode,
FMODE_WRITE))
176 unsigned long nr_segs, loff_t
pos)
179 struct inode * inode = dentry->
d_inode;
185 dprintk(
"NFS: read(%s/%s, %lu@%lu)\n",
187 (
unsigned long) iov_length(iov, nr_segs), (
unsigned long) pos);
205 struct inode *inode = dentry->
d_inode;
208 dprintk(
"NFS: splice_read(%s/%s, %lu@%Lu)\n",
210 (
unsigned long) count, (
unsigned long long) *ppos);
226 struct inode *inode = dentry->
d_inode;
237 vma->
vm_ops = &nfs_file_vm_ops;
261 struct inode *inode = dentry->
d_inode;
262 int have_error, do_resend,
status;
265 dprintk(
"NFS: fsync file(%s/%s) datasync %d\n",
295 struct inode *inode = file->
f_path.dentry->d_inode;
336 static int nfs_want_read_modify_write(
struct file *file,
struct page *
page,
337 loff_t
pos,
unsigned len)
339 unsigned int pglen = nfs_page_length(page);
341 unsigned int end = offset + len;
344 !PageUptodate(page) &&
345 !PagePrivate(page) &&
361 loff_t pos,
unsigned len,
unsigned flags,
362 struct page **pagep,
void **fsdata)
369 dfprintk(PAGECACHE,
"NFS: write_begin(%s/%s(%ld), %u@%lld)\n",
370 file->
f_path.dentry->d_parent->d_name.name,
371 file->
f_path.dentry->d_name.name,
372 mapping->
host->i_ino, len, (
long long) pos);
393 }
else if (!once_thru &&
394 nfs_want_read_modify_write(file, page, pos, len)) {
404 static int nfs_write_end(
struct file *file,
struct address_space *mapping,
405 loff_t pos,
unsigned len,
unsigned copied,
406 struct page *page,
void *fsdata)
411 dfprintk(PAGECACHE,
"NFS: write_end(%s/%s(%ld), %u@%lld)\n",
412 file->
f_path.dentry->d_parent->d_name.name,
413 file->
f_path.dentry->d_name.name,
414 mapping->
host->i_ino, len, (
long long) pos);
420 if (!PageUptodate(page)) {
421 unsigned pglen = nfs_page_length(page);
422 unsigned end = offset + len;
425 zero_user_segments(page, 0, offset,
427 SetPageUptodate(page);
428 }
else if (end >= pglen) {
431 SetPageUptodate(page);
443 NFS_I(mapping->
host)->write_io += copied;
454 static void nfs_invalidate_page(
struct page *page,
unsigned long offset)
456 dfprintk(PAGECACHE,
"NFS: invalidate_page(%p, %lu)\n", page, offset);
463 nfs_fscache_invalidate_page(page, page->
mapping->host);
472 static int nfs_release_page(
struct page *page,
gfp_t gfp)
476 dfprintk(PAGECACHE,
"NFS: release_page(%p)\n", page);
481 if (mapping && (gfp &
GFP_KERNEL) == GFP_KERNEL &&
486 if (current_is_kswapd())
488 nfs_commit_inode(mapping->
host, how);
491 if (PagePrivate(page))
504 static int nfs_launder_page(
struct page *page)
506 struct inode *inode = page_file_mapping(page)->host;
509 dfprintk(PAGECACHE,
"NFS: launder_page(%ld, %llu)\n",
512 nfs_fscache_wait_on_page_write(nfsi, page);
516 #ifdef CONFIG_NFS_SWAP
517 static int nfs_swap_activate(
struct swap_info_struct *sis,
struct file *file,
521 return xs_swapper(NFS_CLIENT(file->
f_mapping->host)->cl_xprt, 1);
524 static void nfs_swap_deactivate(
struct file *file)
526 xs_swapper(NFS_CLIENT(file->
f_mapping->host)->cl_xprt, 0);
536 .write_begin = nfs_write_begin,
537 .write_end = nfs_write_end,
538 .invalidatepage = nfs_invalidate_page,
539 .releasepage = nfs_release_page,
542 .launder_page = nfs_launder_page,
544 #ifdef CONFIG_NFS_SWAP
545 .swap_activate = nfs_swap_activate,
546 .swap_deactivate = nfs_swap_deactivate,
555 static int nfs_vm_page_mkwrite(
struct vm_area_struct *vma,
struct vm_fault *vmf)
557 struct page *page = vmf->page;
558 struct file *filp = vma->
vm_file;
561 int ret = VM_FAULT_NOPAGE;
564 dfprintk(PAGECACHE,
"NFS: vm_page_mkwrite(%s/%s(%ld), offset %lld)\n",
570 nfs_fscache_wait_on_page_write(NFS_I(dentry->
d_inode), page);
573 mapping = page_file_mapping(page);
574 if (mapping != dentry->
d_inode->i_mapping)
577 wait_on_page_writeback(page);
579 pagelen = nfs_page_length(page);
583 ret = VM_FAULT_LOCKED;
588 ret = VM_FAULT_SIGBUS;
595 static const struct vm_operations_struct nfs_file_vm_ops = {
597 .page_mkwrite = nfs_vm_page_mkwrite,
601 static int nfs_need_sync_write(
struct file *filp,
struct inode *inode)
607 ctx = nfs_file_open_context(filp);
614 unsigned long nr_segs, loff_t pos)
616 struct dentry * dentry = iocb->
ki_filp->f_path.dentry;
617 struct inode * inode = dentry->
d_inode;
618 unsigned long written = 0;
620 size_t count = iov_length(iov, nr_segs);
625 dprintk(
"NFS: write(%s/%s, %lu@%Ld)\n",
627 (
unsigned long) count, (
long long) pos);
636 result = nfs_revalidate_file_size(inode, iocb->
ki_filp);
650 if (result >= 0 && nfs_need_sync_write(iocb->
ki_filp, inode)) {
667 struct file *filp, loff_t *ppos,
668 size_t count,
unsigned int flags)
670 struct dentry *dentry = filp->
f_path.dentry;
671 struct inode *inode = dentry->
d_inode;
672 unsigned long written = 0;
675 dprintk(
"NFS splice_write(%s/%s, %lu@%llu)\n",
677 (
unsigned long) count, (
unsigned long long) *ppos);
687 if (ret >= 0 && nfs_need_sync_write(filp, inode)) {
699 do_getlk(
struct file *filp,
int cmd,
struct file_lock *
fl,
int is_local)
701 struct inode *inode = filp->
f_mapping->host;
703 unsigned int saved_type = fl->
fl_type;
713 if (NFS_PROTO(inode)->have_delegation(inode,
FMODE_READ))
719 status = NFS_PROTO(inode)->lock(filp, cmd, fl);
727 static int do_vfs_lock(
struct file *file,
struct file_lock *fl)
744 do_unlk(
struct file *filp,
int cmd,
struct file_lock *fl,
int is_local)
746 struct inode *inode = filp->
f_mapping->host;
764 status = NFS_PROTO(inode)->lock(filp, cmd, fl);
766 status = do_vfs_lock(filp, fl);
776 do_setlk(
struct file *filp,
int cmd,
struct file_lock *fl,
int is_local)
778 struct inode *inode = filp->
f_mapping->host;
794 status = NFS_PROTO(inode)->lock(filp, cmd, fl);
796 status = do_vfs_lock(filp, fl);
808 if (!NFS_PROTO(inode)->have_delegation(inode,
FMODE_READ)) {
809 if (is_time_granular(&NFS_SERVER(inode)->time_delta))
823 struct inode *inode = filp->
f_mapping->host;
827 dprintk(
"NFS: lock(%s/%s, t=%x, fl=%x, r=%lld:%lld)\n",
828 filp->
f_path.dentry->d_parent->d_name.name,
829 filp->
f_path.dentry->d_name.name,
842 if (NFS_PROTO(inode)->lock_check_bounds !=
NULL) {
843 ret = NFS_PROTO(inode)->lock_check_bounds(fl);
849 ret = do_getlk(filp, cmd, fl, is_local);
851 ret = do_unlk(filp, cmd, fl, is_local);
853 ret = do_setlk(filp, cmd, fl, is_local);
864 struct inode *inode = filp->
f_mapping->host;
867 dprintk(
"NFS: flock(%s/%s, t=%x, fl=%x)\n",
868 filp->
f_path.dentry->d_parent->d_name.name,
869 filp->
f_path.dentry->d_name.name,
893 return do_unlk(filp, cmd, fl, is_local);
894 return do_setlk(filp, cmd, fl, is_local);
904 dprintk(
"NFS: setlease(%s/%s, arg=%ld)\n",
905 file->
f_path.dentry->d_parent->d_name.name,
906 file->
f_path.dentry->d_name.name, arg);
918 .open = nfs_file_open,
921 .fsync = nfs_file_fsync,