4 * Copyright (C) 1992 Rick Sladkey
6 #include <linux/nfs_fs.h>
11 #ifdef CONFIG_NFS_V4_2
15 #define NFSDBG_FACILITY NFSDBG_FILE
18 nfs4_file_open(struct inode *inode, struct file *filp)
20 struct nfs_open_context *ctx;
21 struct dentry *dentry = filp->f_path.dentry;
22 struct dentry *parent = NULL;
24 unsigned openflags = filp->f_flags;
30 * If no cached dentry exists or if it's negative, NFSv4 handled the
31 * opens in ->lookup() or ->create().
33 * We only get this far for a cached positive dentry. We skipped
34 * revalidation, so handle it here by dropping the dentry and returning
35 * -EOPENSTALE. The VFS will retry the lookup/create/open.
38 dprintk("NFS: open file(%pd2)\n", dentry);
40 if ((openflags & O_ACCMODE) == 3)
43 /* We can't create new files here */
44 openflags &= ~(O_CREAT|O_EXCL);
46 parent = dget_parent(dentry);
47 dir = parent->d_inode;
49 ctx = alloc_nfs_open_context(filp->f_path.dentry, filp->f_mode);
54 attr.ia_valid = ATTR_OPEN;
55 if (openflags & O_TRUNC) {
56 attr.ia_valid |= ATTR_SIZE;
61 inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, &attr, &opened);
75 if (inode != dentry->d_inode)
78 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
79 nfs_file_set_open_context(filp, ctx);
80 nfs_fscache_open_file(inode, filp);
84 put_nfs_open_context(ctx);
96 nfs4_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
99 struct inode *inode = file_inode(file);
102 ret = filemap_write_and_wait_range(inode->i_mapping, start, end);
105 mutex_lock(&inode->i_mutex);
106 ret = nfs_file_fsync_commit(file, start, end, datasync);
108 ret = pnfs_layoutcommit_inode(inode, true);
109 mutex_unlock(&inode->i_mutex);
111 * If nfs_file_fsync_commit detected a server reboot, then
112 * resend all dirty pages that might have been covered by
113 * the NFS_CONTEXT_RESEND_WRITES flag
117 } while (ret == -EAGAIN);
122 #ifdef CONFIG_NFS_V4_2
123 static loff_t nfs4_file_llseek(struct file *filep, loff_t offset, int whence)
130 ret = nfs42_proc_llseek(filep, offset, whence);
131 if (ret != -ENOTSUPP)
134 return nfs_file_llseek(filep, offset, whence);
137 #endif /* CONFIG_NFS_V4_2 */
139 const struct file_operations nfs4_file_operations = {
140 #ifdef CONFIG_NFS_V4_2
141 .llseek = nfs4_file_llseek,
143 .llseek = nfs_file_llseek,
145 .read = new_sync_read,
146 .write = new_sync_write,
147 .read_iter = nfs_file_read,
148 .write_iter = nfs_file_write,
149 .mmap = nfs_file_mmap,
150 .open = nfs4_file_open,
151 .flush = nfs_file_flush,
152 .release = nfs_file_release,
153 .fsync = nfs4_file_fsync,
156 .splice_read = nfs_file_splice_read,
157 .splice_write = iter_file_splice_write,
158 .check_flags = nfs_check_flags,
159 .setlease = simple_nosetlease,