Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

NFS: Split out NFS v4 file operations

This patch moves the NFS v4 file functions into a new file that is only
compiled when CONFIG_NFS_V4 is enabled.

Signed-off-by: Bryan Schumaker <bjschuma@netapp.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>

authored by

Bryan Schumaker and committed by
Trond Myklebust
ce4ef7c0 466bfe7f

+160 -136
+1 -1
fs/nfs/Makefile
··· 13 13 nfs-$(CONFIG_NFS_V3) += nfs3proc.o nfs3xdr.o 14 14 nfs-$(CONFIG_NFS_V3_ACL) += nfs3acl.o 15 15 nfs-$(CONFIG_NFS_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \ 16 - nfs4super.o delegation.o idmap.o \ 16 + nfs4super.o nfs4file.o delegation.o idmap.o \ 17 17 callback.o callback_xdr.o callback_proc.o \ 18 18 nfs4namespace.o 19 19 nfs-$(CONFIG_NFS_V4_1) += pnfs.o pnfs_dev.o
+16 -135
fs/nfs/file.c
··· 35 35 #include "internal.h" 36 36 #include "iostat.h" 37 37 #include "fscache.h" 38 - #include "pnfs.h" 39 38 40 39 #define NFSDBG_FACILITY NFSDBG_FILE 41 40 ··· 45 46 # define IS_SWAPFILE(inode) (0) 46 47 #endif 47 48 48 - static int nfs_check_flags(int flags) 49 + int nfs_check_flags(int flags) 49 50 { 50 51 if ((flags & (O_APPEND | O_DIRECT)) == (O_APPEND | O_DIRECT)) 51 52 return -EINVAL; ··· 74 75 return res; 75 76 } 76 77 77 - static int 78 + int 78 79 nfs_file_release(struct inode *inode, struct file *filp) 79 80 { 80 81 dprintk("NFS: release(%s/%s)\n", ··· 116 117 return __nfs_revalidate_inode(server, inode); 117 118 } 118 119 119 - static loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin) 120 + loff_t nfs_file_llseek(struct file *filp, loff_t offset, int origin) 120 121 { 121 122 dprintk("NFS: llseek file(%s/%s, %lld, %d)\n", 122 123 filp->f_path.dentry->d_parent->d_name.name, ··· 141 142 /* 142 143 * Flush all dirty pages, and check for write errors. 143 144 */ 144 - static int 145 + int 145 146 nfs_file_flush(struct file *file, fl_owner_t id) 146 147 { 147 148 struct dentry *dentry = file->f_path.dentry; ··· 166 167 return vfs_fsync(file, 0); 167 168 } 168 169 169 - static ssize_t 170 + ssize_t 170 171 nfs_file_read(struct kiocb *iocb, const struct iovec *iov, 171 172 unsigned long nr_segs, loff_t pos) 172 173 { ··· 190 191 return result; 191 192 } 192 193 193 - static ssize_t 194 + ssize_t 194 195 nfs_file_splice_read(struct file *filp, loff_t *ppos, 195 196 struct pipe_inode_info *pipe, size_t count, 196 197 unsigned int flags) ··· 212 213 return res; 213 214 } 214 215 215 - static int 216 + int 216 217 nfs_file_mmap(struct file * file, struct vm_area_struct * vma) 217 218 { 218 219 struct dentry *dentry = file->f_path.dentry; ··· 245 246 * nfs_file_write() that a write error occurred, and hence cause it to 246 247 * fall back to doing a synchronous write. 247 248 */ 248 - static int 249 + int 249 250 nfs_file_fsync_commit(struct file *file, loff_t start, loff_t end, int datasync) 250 251 { 251 252 struct dentry *dentry = file->f_path.dentry; ··· 560 561 return 0; 561 562 } 562 563 563 - static ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov, 564 - unsigned long nr_segs, loff_t pos) 564 + ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov, 565 + unsigned long nr_segs, loff_t pos) 565 566 { 566 567 struct dentry * dentry = iocb->ki_filp->f_path.dentry; 567 568 struct inode * inode = dentry->d_inode; ··· 612 613 goto out; 613 614 } 614 615 615 - static ssize_t nfs_file_splice_write(struct pipe_inode_info *pipe, 616 - struct file *filp, loff_t *ppos, 617 - size_t count, unsigned int flags) 616 + ssize_t nfs_file_splice_write(struct pipe_inode_info *pipe, 617 + struct file *filp, loff_t *ppos, 618 + size_t count, unsigned int flags) 618 619 { 619 620 struct dentry *dentry = filp->f_path.dentry; 620 621 struct inode *inode = dentry->d_inode; ··· 766 767 /* 767 768 * Lock a (portion of) a file 768 769 */ 769 - static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl) 770 + int nfs_lock(struct file *filp, int cmd, struct file_lock *fl) 770 771 { 771 772 struct inode *inode = filp->f_mapping->host; 772 773 int ret = -ENOLCK; ··· 806 807 /* 807 808 * Lock a (portion of) a file 808 809 */ 809 - static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl) 810 + int nfs_flock(struct file *filp, int cmd, struct file_lock *fl) 810 811 { 811 812 struct inode *inode = filp->f_mapping->host; 812 813 int is_local = 0; ··· 836 837 * There is no protocol support for leases, so we have no way to implement 837 838 * them correctly in the face of opens by other clients. 838 839 */ 839 - static int nfs_setlease(struct file *file, long arg, struct file_lock **fl) 840 + int nfs_setlease(struct file *file, long arg, struct file_lock **fl) 840 841 { 841 842 dprintk("NFS: setlease(%s/%s, arg=%ld)\n", 842 843 file->f_path.dentry->d_parent->d_name.name, ··· 862 863 .check_flags = nfs_check_flags, 863 864 .setlease = nfs_setlease, 864 865 }; 865 - 866 - #ifdef CONFIG_NFS_V4 867 - static int 868 - nfs4_file_open(struct inode *inode, struct file *filp) 869 - { 870 - struct nfs_open_context *ctx; 871 - struct dentry *dentry = filp->f_path.dentry; 872 - struct dentry *parent = NULL; 873 - struct inode *dir; 874 - unsigned openflags = filp->f_flags; 875 - struct iattr attr; 876 - int err; 877 - 878 - BUG_ON(inode != dentry->d_inode); 879 - /* 880 - * If no cached dentry exists or if it's negative, NFSv4 handled the 881 - * opens in ->lookup() or ->create(). 882 - * 883 - * We only get this far for a cached positive dentry. We skipped 884 - * revalidation, so handle it here by dropping the dentry and returning 885 - * -EOPENSTALE. The VFS will retry the lookup/create/open. 886 - */ 887 - 888 - dprintk("NFS: open file(%s/%s)\n", 889 - dentry->d_parent->d_name.name, 890 - dentry->d_name.name); 891 - 892 - if ((openflags & O_ACCMODE) == 3) 893 - openflags--; 894 - 895 - /* We can't create new files here */ 896 - openflags &= ~(O_CREAT|O_EXCL); 897 - 898 - parent = dget_parent(dentry); 899 - dir = parent->d_inode; 900 - 901 - ctx = alloc_nfs_open_context(filp->f_path.dentry, filp->f_mode); 902 - err = PTR_ERR(ctx); 903 - if (IS_ERR(ctx)) 904 - goto out; 905 - 906 - attr.ia_valid = ATTR_OPEN; 907 - if (openflags & O_TRUNC) { 908 - attr.ia_valid |= ATTR_SIZE; 909 - attr.ia_size = 0; 910 - nfs_wb_all(inode); 911 - } 912 - 913 - inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, &attr); 914 - if (IS_ERR(inode)) { 915 - err = PTR_ERR(inode); 916 - switch (err) { 917 - case -EPERM: 918 - case -EACCES: 919 - case -EDQUOT: 920 - case -ENOSPC: 921 - case -EROFS: 922 - goto out_put_ctx; 923 - default: 924 - goto out_drop; 925 - } 926 - } 927 - iput(inode); 928 - if (inode != dentry->d_inode) 929 - goto out_drop; 930 - 931 - nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 932 - nfs_file_set_open_context(filp, ctx); 933 - err = 0; 934 - 935 - out_put_ctx: 936 - put_nfs_open_context(ctx); 937 - out: 938 - dput(parent); 939 - return err; 940 - 941 - out_drop: 942 - d_drop(dentry); 943 - err = -EOPENSTALE; 944 - goto out_put_ctx; 945 - } 946 - 947 - static int 948 - nfs4_file_fsync(struct file *file, loff_t start, loff_t end, int datasync) 949 - { 950 - int ret; 951 - struct inode *inode = file->f_path.dentry->d_inode; 952 - 953 - ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 954 - mutex_lock(&inode->i_mutex); 955 - ret = nfs_file_fsync_commit(file, start, end, datasync); 956 - if (!ret && !datasync) 957 - /* application has asked for meta-data sync */ 958 - ret = pnfs_layoutcommit_inode(inode, true); 959 - mutex_unlock(&inode->i_mutex); 960 - 961 - return ret; 962 - } 963 - 964 - const struct file_operations nfs4_file_operations = { 965 - .llseek = nfs_file_llseek, 966 - .read = do_sync_read, 967 - .write = do_sync_write, 968 - .aio_read = nfs_file_read, 969 - .aio_write = nfs_file_write, 970 - .mmap = nfs_file_mmap, 971 - .open = nfs4_file_open, 972 - .flush = nfs_file_flush, 973 - .release = nfs_file_release, 974 - .fsync = nfs4_file_fsync, 975 - .lock = nfs_lock, 976 - .flock = nfs_flock, 977 - .splice_read = nfs_file_splice_read, 978 - .splice_write = nfs_file_splice_write, 979 - .check_flags = nfs_check_flags, 980 - .setlease = nfs_setlease, 981 - }; 982 - #endif /* CONFIG_NFS_V4 */
+17
fs/nfs/internal.h
··· 257 257 int nfs_mknod(struct inode *, struct dentry *, umode_t, dev_t); 258 258 int nfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *); 259 259 260 + /* file.c */ 261 + int nfs_file_fsync_commit(struct file *, loff_t, loff_t, int); 262 + loff_t nfs_file_llseek(struct file *, loff_t, int); 263 + int nfs_file_flush(struct file *, fl_owner_t); 264 + ssize_t nfs_file_read(struct kiocb *, const struct iovec *, unsigned long, loff_t); 265 + ssize_t nfs_file_splice_read(struct file *, loff_t *, struct pipe_inode_info *, 266 + size_t, unsigned int); 267 + int nfs_file_mmap(struct file *, struct vm_area_struct *); 268 + ssize_t nfs_file_write(struct kiocb *, const struct iovec *, unsigned long, loff_t); 269 + int nfs_file_release(struct inode *, struct file *); 270 + int nfs_lock(struct file *, int, struct file_lock *); 271 + int nfs_flock(struct file *, int, struct file_lock *); 272 + ssize_t nfs_file_splice_write(struct pipe_inode_info *, struct file *, loff_t *, 273 + size_t, unsigned int); 274 + int nfs_check_flags(int); 275 + int nfs_setlease(struct file *, long, struct file_lock **); 276 + 260 277 /* inode.c */ 261 278 extern struct workqueue_struct *nfsiod_workqueue; 262 279 extern struct inode *nfs_alloc_inode(struct super_block *sb);
+126
fs/nfs/nfs4file.c
··· 1 + /* 2 + * linux/fs/nfs/file.c 3 + * 4 + * Copyright (C) 1992 Rick Sladkey 5 + */ 6 + #include <linux/nfs_fs.h> 7 + #include "internal.h" 8 + #include "pnfs.h" 9 + 10 + #define NFSDBG_FACILITY NFSDBG_FILE 11 + 12 + static int 13 + nfs4_file_open(struct inode *inode, struct file *filp) 14 + { 15 + struct nfs_open_context *ctx; 16 + struct dentry *dentry = filp->f_path.dentry; 17 + struct dentry *parent = NULL; 18 + struct inode *dir; 19 + unsigned openflags = filp->f_flags; 20 + struct iattr attr; 21 + int err; 22 + 23 + BUG_ON(inode != dentry->d_inode); 24 + /* 25 + * If no cached dentry exists or if it's negative, NFSv4 handled the 26 + * opens in ->lookup() or ->create(). 27 + * 28 + * We only get this far for a cached positive dentry. We skipped 29 + * revalidation, so handle it here by dropping the dentry and returning 30 + * -EOPENSTALE. The VFS will retry the lookup/create/open. 31 + */ 32 + 33 + dprintk("NFS: open file(%s/%s)\n", 34 + dentry->d_parent->d_name.name, 35 + dentry->d_name.name); 36 + 37 + if ((openflags & O_ACCMODE) == 3) 38 + openflags--; 39 + 40 + /* We can't create new files here */ 41 + openflags &= ~(O_CREAT|O_EXCL); 42 + 43 + parent = dget_parent(dentry); 44 + dir = parent->d_inode; 45 + 46 + ctx = alloc_nfs_open_context(filp->f_path.dentry, filp->f_mode); 47 + err = PTR_ERR(ctx); 48 + if (IS_ERR(ctx)) 49 + goto out; 50 + 51 + attr.ia_valid = ATTR_OPEN; 52 + if (openflags & O_TRUNC) { 53 + attr.ia_valid |= ATTR_SIZE; 54 + attr.ia_size = 0; 55 + nfs_wb_all(inode); 56 + } 57 + 58 + inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, &attr); 59 + if (IS_ERR(inode)) { 60 + err = PTR_ERR(inode); 61 + switch (err) { 62 + case -EPERM: 63 + case -EACCES: 64 + case -EDQUOT: 65 + case -ENOSPC: 66 + case -EROFS: 67 + goto out_put_ctx; 68 + default: 69 + goto out_drop; 70 + } 71 + } 72 + iput(inode); 73 + if (inode != dentry->d_inode) 74 + goto out_drop; 75 + 76 + nfs_set_verifier(dentry, nfs_save_change_attribute(dir)); 77 + nfs_file_set_open_context(filp, ctx); 78 + err = 0; 79 + 80 + out_put_ctx: 81 + put_nfs_open_context(ctx); 82 + out: 83 + dput(parent); 84 + return err; 85 + 86 + out_drop: 87 + d_drop(dentry); 88 + err = -EOPENSTALE; 89 + goto out_put_ctx; 90 + } 91 + 92 + static int 93 + nfs4_file_fsync(struct file *file, loff_t start, loff_t end, int datasync) 94 + { 95 + int ret; 96 + struct inode *inode = file->f_path.dentry->d_inode; 97 + 98 + ret = filemap_write_and_wait_range(inode->i_mapping, start, end); 99 + mutex_lock(&inode->i_mutex); 100 + ret = nfs_file_fsync_commit(file, start, end, datasync); 101 + if (!ret && !datasync) 102 + /* application has asked for meta-data sync */ 103 + ret = pnfs_layoutcommit_inode(inode, true); 104 + mutex_unlock(&inode->i_mutex); 105 + 106 + return ret; 107 + } 108 + 109 + const struct file_operations nfs4_file_operations = { 110 + .llseek = nfs_file_llseek, 111 + .read = do_sync_read, 112 + .write = do_sync_write, 113 + .aio_read = nfs_file_read, 114 + .aio_write = nfs_file_write, 115 + .mmap = nfs_file_mmap, 116 + .open = nfs4_file_open, 117 + .flush = nfs_file_flush, 118 + .release = nfs_file_release, 119 + .fsync = nfs4_file_fsync, 120 + .lock = nfs_lock, 121 + .flock = nfs_flock, 122 + .splice_read = nfs_file_splice_read, 123 + .splice_write = nfs_file_splice_write, 124 + .check_flags = nfs_check_flags, 125 + .setlease = nfs_setlease, 126 + };