aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-03-23 11:53:47 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-23 11:53:47 -0400
commitf63d395d47f37a4fe771e6d4b1db9d2cdae5ffc5 (patch)
tree3448a14ae965802adb963762cadeb9989ce4caa2 /fs/nfs
parent643ac9fc5429e85b8b7f534544b80bcc4f34c367 (diff)
parent5a7c9eec9fde1da0e3adf0a4ddb64ff2a324a492 (diff)
Merge tag 'nfs-for-3.4-1' of git://git.linux-nfs.org/projects/trondmy/linux-nfs
Pull NFS client updates for Linux 3.4 from Trond Myklebust: "New features include: - Add NFS client support for containers. This should enable most of the necessary functionality, including lockd support, and support for rpc.statd, NFSv4 idmapper and RPCSEC_GSS upcalls into the correct network namespace from which the mount system call was issued. - NFSv4 idmapper scalability improvements Base the idmapper cache on the keyring interface to allow concurrent access to idmapper entries. Start the process of migrating users from the single-threaded daemon-based approach to the multi-threaded request-key based approach. - NFSv4.1 implementation id. Allows the NFSv4.1 client and server to mutually identify each other for logging and debugging purposes. - Support the 'vers=4.1' mount option for mounting NFSv4.1 instead of having to use the more counterintuitive 'vers=4,minorversion=1'. - SUNRPC tracepoints. Start the process of adding tracepoints in order to improve debugging of the RPC layer. - pNFS object layout support for autologin. Important bugfixes include: - Fix a bug in rpc_wake_up/rpc_wake_up_status that caused them to fail to wake up all tasks when applied to priority waitqueues. - Ensure that we handle read delegations correctly, when we try to truncate a file. - A number of fixes for NFSv4 state manager loops (mostly to do with delegation recovery)." * tag 'nfs-for-3.4-1' of git://git.linux-nfs.org/projects/trondmy/linux-nfs: (224 commits) NFS: fix sb->s_id in nfs debug prints xprtrdma: Remove assumption that each segment is <= PAGE_SIZE xprtrdma: The transport should not bug-check when a dup reply is received pnfs-obj: autologin: Add support for protocol autologin NFS: Remove nfs4_setup_sequence from generic rename code NFS: Remove nfs4_setup_sequence from generic unlink code NFS: Remove nfs4_setup_sequence from generic read code NFS: Remove nfs4_setup_sequence from generic write code NFS: Fix more NFS debug related build warnings SUNRPC/LOCKD: Fix build warnings when CONFIG_SUNRPC_DEBUG is undefined nfs: non void functions must return a value SUNRPC: Kill compiler warning when RPC_DEBUG is unset SUNRPC/NFS: Add Kbuild dependencies for NFS_DEBUG/RPC_DEBUG NFS: Use cond_resched_lock() to reduce latencies in the commit scans NFSv4: It is not safe to dereference lsp->ls_state in release_lockowner NFS: ncommit count is being double decremented SUNRPC: We must not use list_for_each_entry_safe() in rpc_wake_up() Try using machine credentials for RENEW calls NFSv4.1: Fix a few issues in filelayout_commit_pagelist NFSv4.1: Clean ups and bugfixes for the pNFS read/writeback/commit code ...
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/Kconfig29
-rw-r--r--fs/nfs/blocklayout/blocklayout.c161
-rw-r--r--fs/nfs/blocklayout/blocklayout.h11
-rw-r--r--fs/nfs/blocklayout/blocklayoutdev.c46
-rw-r--r--fs/nfs/blocklayout/blocklayoutdm.c33
-rw-r--r--fs/nfs/blocklayout/extents.c2
-rw-r--r--fs/nfs/cache_lib.c61
-rw-r--r--fs/nfs/cache_lib.h10
-rw-r--r--fs/nfs/callback.c19
-rw-r--r--fs/nfs/callback.h3
-rw-r--r--fs/nfs/callback_proc.c99
-rw-r--r--fs/nfs/callback_xdr.c21
-rw-r--r--fs/nfs/client.c246
-rw-r--r--fs/nfs/delegation.c68
-rw-r--r--fs/nfs/delegation.h4
-rw-r--r--fs/nfs/dir.c27
-rw-r--r--fs/nfs/direct.c6
-rw-r--r--fs/nfs/dns_resolve.c130
-rw-r--r--fs/nfs/dns_resolve.h14
-rw-r--r--fs/nfs/file.c2
-rw-r--r--fs/nfs/fscache.c2
-rw-r--r--fs/nfs/idmap.c733
-rw-r--r--fs/nfs/inode.c119
-rw-r--r--fs/nfs/internal.h15
-rw-r--r--fs/nfs/mount_clnt.c16
-rw-r--r--fs/nfs/namespace.c5
-rw-r--r--fs/nfs/netns.h27
-rw-r--r--fs/nfs/nfs2xdr.c2
-rw-r--r--fs/nfs/nfs3acl.c2
-rw-r--r--fs/nfs/nfs3proc.c24
-rw-r--r--fs/nfs/nfs3xdr.c4
-rw-r--r--fs/nfs/nfs4_fs.h58
-rw-r--r--fs/nfs/nfs4filelayout.c272
-rw-r--r--fs/nfs/nfs4filelayout.h7
-rw-r--r--fs/nfs/nfs4filelayoutdev.c90
-rw-r--r--fs/nfs/nfs4namespace.c10
-rw-r--r--fs/nfs/nfs4proc.c559
-rw-r--r--fs/nfs/nfs4state.c355
-rw-r--r--fs/nfs/nfs4xdr.c697
-rw-r--r--fs/nfs/nfsroot.c2
-rw-r--r--fs/nfs/objlayout/objio_osd.c54
-rw-r--r--fs/nfs/objlayout/objlayout.c142
-rw-r--r--fs/nfs/objlayout/objlayout.h2
-rw-r--r--fs/nfs/pagelist.c92
-rw-r--r--fs/nfs/pnfs.c46
-rw-r--r--fs/nfs/pnfs.h98
-rw-r--r--fs/nfs/pnfs_dev.c4
-rw-r--r--fs/nfs/proc.c24
-rw-r--r--fs/nfs/read.c14
-rw-r--r--fs/nfs/super.c167
-rw-r--r--fs/nfs/sysctl.c2
-rw-r--r--fs/nfs/unlink.c45
-rw-r--r--fs/nfs/write.c213
53 files changed, 2902 insertions, 1992 deletions
diff --git a/fs/nfs/Kconfig b/fs/nfs/Kconfig
index dbcd82126ae..2a0e6c59914 100644
--- a/fs/nfs/Kconfig
+++ b/fs/nfs/Kconfig
@@ -64,6 +64,7 @@ config NFS_V4
64 bool "NFS client support for NFS version 4" 64 bool "NFS client support for NFS version 4"
65 depends on NFS_FS 65 depends on NFS_FS
66 select SUNRPC_GSS 66 select SUNRPC_GSS
67 select KEYS
67 help 68 help
68 This option enables support for version 4 of the NFS protocol 69 This option enables support for version 4 of the NFS protocol
69 (RFC 3530) in the kernel's NFS client. 70 (RFC 3530) in the kernel's NFS client.
@@ -98,6 +99,18 @@ config PNFS_OBJLAYOUT
98 depends on NFS_FS && NFS_V4_1 && SCSI_OSD_ULD 99 depends on NFS_FS && NFS_V4_1 && SCSI_OSD_ULD
99 default m 100 default m
100 101
102config NFS_V4_1_IMPLEMENTATION_ID_DOMAIN
103 string "NFSv4.1 Implementation ID Domain"
104 depends on NFS_V4_1
105 default "kernel.org"
106 help
107 This option defines the domain portion of the implementation ID that
108 may be sent in the NFS exchange_id operation. The value must be in
109 the format of a DNS domain name and should be set to the DNS domain
110 name of the distribution.
111 If the NFS client is unchanged from the upstream kernel, this
112 option should be set to the default "kernel.org".
113
101config ROOT_NFS 114config ROOT_NFS
102 bool "Root file system on NFS" 115 bool "Root file system on NFS"
103 depends on NFS_FS=y && IP_PNP 116 depends on NFS_FS=y && IP_PNP
@@ -130,16 +143,10 @@ config NFS_USE_KERNEL_DNS
130 bool 143 bool
131 depends on NFS_V4 && !NFS_USE_LEGACY_DNS 144 depends on NFS_V4 && !NFS_USE_LEGACY_DNS
132 select DNS_RESOLVER 145 select DNS_RESOLVER
133 select KEYS
134 default y 146 default y
135 147
136config NFS_USE_NEW_IDMAPPER 148config NFS_DEBUG
137 bool "Use the new idmapper upcall routine" 149 bool
138 depends on NFS_V4 && KEYS 150 depends on NFS_FS && SUNRPC_DEBUG
139 help 151 select CRC32
140 Say Y here if you want NFS to use the new idmapper upcall functions. 152 default y
141 You will need /sbin/request-key (usually provided by the keyutils
142 package). For details, read
143 <file:Documentation/filesystems/nfs/idmapper.txt>.
144
145 If you are unsure, say N.
diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
index 48cfac31f64..9c94297bb70 100644
--- a/fs/nfs/blocklayout/blocklayout.c
+++ b/fs/nfs/blocklayout/blocklayout.c
@@ -46,9 +46,6 @@ MODULE_LICENSE("GPL");
46MODULE_AUTHOR("Andy Adamson <andros@citi.umich.edu>"); 46MODULE_AUTHOR("Andy Adamson <andros@citi.umich.edu>");
47MODULE_DESCRIPTION("The NFSv4.1 pNFS Block layout driver"); 47MODULE_DESCRIPTION("The NFSv4.1 pNFS Block layout driver");
48 48
49struct dentry *bl_device_pipe;
50wait_queue_head_t bl_wq;
51
52static void print_page(struct page *page) 49static void print_page(struct page *page)
53{ 50{
54 dprintk("PRINTPAGE page %p\n", page); 51 dprintk("PRINTPAGE page %p\n", page);
@@ -236,12 +233,11 @@ bl_read_pagelist(struct nfs_read_data *rdata)
236 sector_t isect, extent_length = 0; 233 sector_t isect, extent_length = 0;
237 struct parallel_io *par; 234 struct parallel_io *par;
238 loff_t f_offset = rdata->args.offset; 235 loff_t f_offset = rdata->args.offset;
239 size_t count = rdata->args.count;
240 struct page **pages = rdata->args.pages; 236 struct page **pages = rdata->args.pages;
241 int pg_index = rdata->args.pgbase >> PAGE_CACHE_SHIFT; 237 int pg_index = rdata->args.pgbase >> PAGE_CACHE_SHIFT;
242 238
243 dprintk("%s enter nr_pages %u offset %lld count %Zd\n", __func__, 239 dprintk("%s enter nr_pages %u offset %lld count %u\n", __func__,
244 rdata->npages, f_offset, count); 240 rdata->npages, f_offset, (unsigned int)rdata->args.count);
245 241
246 par = alloc_parallel(rdata); 242 par = alloc_parallel(rdata);
247 if (!par) 243 if (!par)
@@ -1025,10 +1021,128 @@ static const struct rpc_pipe_ops bl_upcall_ops = {
1025 .destroy_msg = bl_pipe_destroy_msg, 1021 .destroy_msg = bl_pipe_destroy_msg,
1026}; 1022};
1027 1023
1024static struct dentry *nfs4blocklayout_register_sb(struct super_block *sb,
1025 struct rpc_pipe *pipe)
1026{
1027 struct dentry *dir, *dentry;
1028
1029 dir = rpc_d_lookup_sb(sb, NFS_PIPE_DIRNAME);
1030 if (dir == NULL)
1031 return ERR_PTR(-ENOENT);
1032 dentry = rpc_mkpipe_dentry(dir, "blocklayout", NULL, pipe);
1033 dput(dir);
1034 return dentry;
1035}
1036
1037static void nfs4blocklayout_unregister_sb(struct super_block *sb,
1038 struct rpc_pipe *pipe)
1039{
1040 if (pipe->dentry)
1041 rpc_unlink(pipe->dentry);
1042}
1043
1044static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
1045 void *ptr)
1046{
1047 struct super_block *sb = ptr;
1048 struct net *net = sb->s_fs_info;
1049 struct nfs_net *nn = net_generic(net, nfs_net_id);
1050 struct dentry *dentry;
1051 int ret = 0;
1052
1053 if (!try_module_get(THIS_MODULE))
1054 return 0;
1055
1056 if (nn->bl_device_pipe == NULL) {
1057 module_put(THIS_MODULE);
1058 return 0;
1059 }
1060
1061 switch (event) {
1062 case RPC_PIPEFS_MOUNT:
1063 dentry = nfs4blocklayout_register_sb(sb, nn->bl_device_pipe);
1064 if (IS_ERR(dentry)) {
1065 ret = PTR_ERR(dentry);
1066 break;
1067 }
1068 nn->bl_device_pipe->dentry = dentry;
1069 break;
1070 case RPC_PIPEFS_UMOUNT:
1071 if (nn->bl_device_pipe->dentry)
1072 nfs4blocklayout_unregister_sb(sb, nn->bl_device_pipe);
1073 break;
1074 default:
1075 ret = -ENOTSUPP;
1076 break;
1077 }
1078 module_put(THIS_MODULE);
1079 return ret;
1080}
1081
1082static struct notifier_block nfs4blocklayout_block = {
1083 .notifier_call = rpc_pipefs_event,
1084};
1085
1086static struct dentry *nfs4blocklayout_register_net(struct net *net,
1087 struct rpc_pipe *pipe)
1088{
1089 struct super_block *pipefs_sb;
1090 struct dentry *dentry;
1091
1092 pipefs_sb = rpc_get_sb_net(net);
1093 if (!pipefs_sb)
1094 return NULL;
1095 dentry = nfs4blocklayout_register_sb(pipefs_sb, pipe);
1096 rpc_put_sb_net(net);
1097 return dentry;
1098}
1099
1100static void nfs4blocklayout_unregister_net(struct net *net,
1101 struct rpc_pipe *pipe)
1102{
1103 struct super_block *pipefs_sb;
1104
1105 pipefs_sb = rpc_get_sb_net(net);
1106 if (pipefs_sb) {
1107 nfs4blocklayout_unregister_sb(pipefs_sb, pipe);
1108 rpc_put_sb_net(net);
1109 }
1110}
1111
1112static int nfs4blocklayout_net_init(struct net *net)
1113{
1114 struct nfs_net *nn = net_generic(net, nfs_net_id);
1115 struct dentry *dentry;
1116
1117 init_waitqueue_head(&nn->bl_wq);
1118 nn->bl_device_pipe = rpc_mkpipe_data(&bl_upcall_ops, 0);
1119 if (IS_ERR(nn->bl_device_pipe))
1120 return PTR_ERR(nn->bl_device_pipe);
1121 dentry = nfs4blocklayout_register_net(net, nn->bl_device_pipe);
1122 if (IS_ERR(dentry)) {
1123 rpc_destroy_pipe_data(nn->bl_device_pipe);
1124 return PTR_ERR(dentry);
1125 }
1126 nn->bl_device_pipe->dentry = dentry;
1127 return 0;
1128}
1129
1130static void nfs4blocklayout_net_exit(struct net *net)
1131{
1132 struct nfs_net *nn = net_generic(net, nfs_net_id);
1133
1134 nfs4blocklayout_unregister_net(net, nn->bl_device_pipe);
1135 rpc_destroy_pipe_data(nn->bl_device_pipe);
1136 nn->bl_device_pipe = NULL;
1137}
1138
1139static struct pernet_operations nfs4blocklayout_net_ops = {
1140 .init = nfs4blocklayout_net_init,
1141 .exit = nfs4blocklayout_net_exit,
1142};
1143
1028static int __init nfs4blocklayout_init(void) 1144static int __init nfs4blocklayout_init(void)
1029{ 1145{
1030 struct vfsmount *mnt;
1031 struct path path;
1032 int ret; 1146 int ret;
1033 1147
1034 dprintk("%s: NFSv4 Block Layout Driver Registering...\n", __func__); 1148 dprintk("%s: NFSv4 Block Layout Driver Registering...\n", __func__);
@@ -1037,32 +1151,17 @@ static int __init nfs4blocklayout_init(void)
1037 if (ret) 1151 if (ret)
1038 goto out; 1152 goto out;
1039 1153
1040 init_waitqueue_head(&bl_wq); 1154 ret = rpc_pipefs_notifier_register(&nfs4blocklayout_block);
1041 1155 if (ret)
1042 mnt = rpc_get_mount();
1043 if (IS_ERR(mnt)) {
1044 ret = PTR_ERR(mnt);
1045 goto out_remove; 1156 goto out_remove;
1046 } 1157 ret = register_pernet_subsys(&nfs4blocklayout_net_ops);
1047
1048 ret = vfs_path_lookup(mnt->mnt_root,
1049 mnt,
1050 NFS_PIPE_DIRNAME, 0, &path);
1051 if (ret) 1158 if (ret)
1052 goto out_putrpc; 1159 goto out_notifier;
1053
1054 bl_device_pipe = rpc_mkpipe(path.dentry, "blocklayout", NULL,
1055 &bl_upcall_ops, 0);
1056 path_put(&path);
1057 if (IS_ERR(bl_device_pipe)) {
1058 ret = PTR_ERR(bl_device_pipe);
1059 goto out_putrpc;
1060 }
1061out: 1160out:
1062 return ret; 1161 return ret;
1063 1162
1064out_putrpc: 1163out_notifier:
1065 rpc_put_mount(); 1164 rpc_pipefs_notifier_unregister(&nfs4blocklayout_block);
1066out_remove: 1165out_remove:
1067 pnfs_unregister_layoutdriver(&blocklayout_type); 1166 pnfs_unregister_layoutdriver(&blocklayout_type);
1068 return ret; 1167 return ret;
@@ -1073,9 +1172,9 @@ static void __exit nfs4blocklayout_exit(void)
1073 dprintk("%s: NFSv4 Block Layout Driver Unregistering...\n", 1172 dprintk("%s: NFSv4 Block Layout Driver Unregistering...\n",
1074 __func__); 1173 __func__);
1075 1174
1175 rpc_pipefs_notifier_unregister(&nfs4blocklayout_block);
1176 unregister_pernet_subsys(&nfs4blocklayout_net_ops);
1076 pnfs_unregister_layoutdriver(&blocklayout_type); 1177 pnfs_unregister_layoutdriver(&blocklayout_type);
1077 rpc_unlink(bl_device_pipe);
1078 rpc_put_mount();
1079} 1178}
1080 1179
1081MODULE_ALIAS("nfs-layouttype4-3"); 1180MODULE_ALIAS("nfs-layouttype4-3");
diff --git a/fs/nfs/blocklayout/blocklayout.h b/fs/nfs/blocklayout/blocklayout.h
index e31a2df28e7..03350690118 100644
--- a/fs/nfs/blocklayout/blocklayout.h
+++ b/fs/nfs/blocklayout/blocklayout.h
@@ -37,6 +37,7 @@
37#include <linux/sunrpc/rpc_pipe_fs.h> 37#include <linux/sunrpc/rpc_pipe_fs.h>
38 38
39#include "../pnfs.h" 39#include "../pnfs.h"
40#include "../netns.h"
40 41
41#define PAGE_CACHE_SECTORS (PAGE_CACHE_SIZE >> SECTOR_SHIFT) 42#define PAGE_CACHE_SECTORS (PAGE_CACHE_SIZE >> SECTOR_SHIFT)
42#define PAGE_CACHE_SECTOR_SHIFT (PAGE_CACHE_SHIFT - SECTOR_SHIFT) 43#define PAGE_CACHE_SECTOR_SHIFT (PAGE_CACHE_SHIFT - SECTOR_SHIFT)
@@ -50,6 +51,7 @@ struct pnfs_block_dev {
50 struct list_head bm_node; 51 struct list_head bm_node;
51 struct nfs4_deviceid bm_mdevid; /* associated devid */ 52 struct nfs4_deviceid bm_mdevid; /* associated devid */
52 struct block_device *bm_mdev; /* meta device itself */ 53 struct block_device *bm_mdev; /* meta device itself */
54 struct net *net;
53}; 55};
54 56
55enum exstate4 { 57enum exstate4 {
@@ -151,9 +153,9 @@ BLK_LSEG2EXT(struct pnfs_layout_segment *lseg)
151 return BLK_LO2EXT(lseg->pls_layout); 153 return BLK_LO2EXT(lseg->pls_layout);
152} 154}
153 155
154struct bl_dev_msg { 156struct bl_pipe_msg {
155 int32_t status; 157 struct rpc_pipe_msg msg;
156 uint32_t major, minor; 158 wait_queue_head_t *bl_wq;
157}; 159};
158 160
159struct bl_msg_hdr { 161struct bl_msg_hdr {
@@ -161,9 +163,6 @@ struct bl_msg_hdr {
161 u16 totallen; /* length of entire message, including hdr itself */ 163 u16 totallen; /* length of entire message, including hdr itself */
162}; 164};
163 165
164extern struct dentry *bl_device_pipe;
165extern wait_queue_head_t bl_wq;
166
167#define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */ 166#define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */
168#define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/ 167#define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/
169#define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */ 168#define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */
diff --git a/fs/nfs/blocklayout/blocklayoutdev.c b/fs/nfs/blocklayout/blocklayoutdev.c
index d08ba9107fd..a5c88a554d9 100644
--- a/fs/nfs/blocklayout/blocklayoutdev.c
+++ b/fs/nfs/blocklayout/blocklayoutdev.c
@@ -46,7 +46,7 @@ static int decode_sector_number(__be32 **rp, sector_t *sp)
46 46
47 *rp = xdr_decode_hyper(*rp, &s); 47 *rp = xdr_decode_hyper(*rp, &s);
48 if (s & 0x1ff) { 48 if (s & 0x1ff) {
49 printk(KERN_WARNING "%s: sector not aligned\n", __func__); 49 printk(KERN_WARNING "NFS: %s: sector not aligned\n", __func__);
50 return -1; 50 return -1;
51 } 51 }
52 *sp = s >> SECTOR_SHIFT; 52 *sp = s >> SECTOR_SHIFT;
@@ -79,27 +79,30 @@ int nfs4_blkdev_put(struct block_device *bdev)
79 return blkdev_put(bdev, FMODE_READ); 79 return blkdev_put(bdev, FMODE_READ);
80} 80}
81 81
82static struct bl_dev_msg bl_mount_reply;
83
84ssize_t bl_pipe_downcall(struct file *filp, const char __user *src, 82ssize_t bl_pipe_downcall(struct file *filp, const char __user *src,
85 size_t mlen) 83 size_t mlen)
86{ 84{
85 struct nfs_net *nn = net_generic(filp->f_dentry->d_sb->s_fs_info,
86 nfs_net_id);
87
87 if (mlen != sizeof (struct bl_dev_msg)) 88 if (mlen != sizeof (struct bl_dev_msg))
88 return -EINVAL; 89 return -EINVAL;
89 90
90 if (copy_from_user(&bl_mount_reply, src, mlen) != 0) 91 if (copy_from_user(&nn->bl_mount_reply, src, mlen) != 0)
91 return -EFAULT; 92 return -EFAULT;
92 93
93 wake_up(&bl_wq); 94 wake_up(&nn->bl_wq);
94 95
95 return mlen; 96 return mlen;
96} 97}
97 98
98void bl_pipe_destroy_msg(struct rpc_pipe_msg *msg) 99void bl_pipe_destroy_msg(struct rpc_pipe_msg *msg)
99{ 100{
101 struct bl_pipe_msg *bl_pipe_msg = container_of(msg, struct bl_pipe_msg, msg);
102
100 if (msg->errno >= 0) 103 if (msg->errno >= 0)
101 return; 104 return;
102 wake_up(&bl_wq); 105 wake_up(bl_pipe_msg->bl_wq);
103} 106}
104 107
105/* 108/*
@@ -111,29 +114,33 @@ nfs4_blk_decode_device(struct nfs_server *server,
111{ 114{
112 struct pnfs_block_dev *rv; 115 struct pnfs_block_dev *rv;
113 struct block_device *bd = NULL; 116 struct block_device *bd = NULL;
114 struct rpc_pipe_msg msg; 117 struct bl_pipe_msg bl_pipe_msg;
118 struct rpc_pipe_msg *msg = &bl_pipe_msg.msg;
115 struct bl_msg_hdr bl_msg = { 119 struct bl_msg_hdr bl_msg = {
116 .type = BL_DEVICE_MOUNT, 120 .type = BL_DEVICE_MOUNT,
117 .totallen = dev->mincount, 121 .totallen = dev->mincount,
118 }; 122 };
119 uint8_t *dataptr; 123 uint8_t *dataptr;
120 DECLARE_WAITQUEUE(wq, current); 124 DECLARE_WAITQUEUE(wq, current);
121 struct bl_dev_msg *reply = &bl_mount_reply;
122 int offset, len, i, rc; 125 int offset, len, i, rc;
126 struct net *net = server->nfs_client->net;
127 struct nfs_net *nn = net_generic(net, nfs_net_id);
128 struct bl_dev_msg *reply = &nn->bl_mount_reply;
123 129
124 dprintk("%s CREATING PIPEFS MESSAGE\n", __func__); 130 dprintk("%s CREATING PIPEFS MESSAGE\n", __func__);
125 dprintk("%s: deviceid: %s, mincount: %d\n", __func__, dev->dev_id.data, 131 dprintk("%s: deviceid: %s, mincount: %d\n", __func__, dev->dev_id.data,
126 dev->mincount); 132 dev->mincount);
127 133
128 memset(&msg, 0, sizeof(msg)); 134 bl_pipe_msg.bl_wq = &nn->bl_wq;
129 msg.data = kzalloc(sizeof(bl_msg) + dev->mincount, GFP_NOFS); 135 memset(msg, 0, sizeof(*msg));
130 if (!msg.data) { 136 msg->data = kzalloc(sizeof(bl_msg) + dev->mincount, GFP_NOFS);
137 if (!msg->data) {
131 rv = ERR_PTR(-ENOMEM); 138 rv = ERR_PTR(-ENOMEM);
132 goto out; 139 goto out;
133 } 140 }
134 141
135 memcpy(msg.data, &bl_msg, sizeof(bl_msg)); 142 memcpy(msg->data, &bl_msg, sizeof(bl_msg));
136 dataptr = (uint8_t *) msg.data; 143 dataptr = (uint8_t *) msg->data;
137 len = dev->mincount; 144 len = dev->mincount;
138 offset = sizeof(bl_msg); 145 offset = sizeof(bl_msg);
139 for (i = 0; len > 0; i++) { 146 for (i = 0; len > 0; i++) {
@@ -142,13 +149,13 @@ nfs4_blk_decode_device(struct nfs_server *server,
142 len -= PAGE_CACHE_SIZE; 149 len -= PAGE_CACHE_SIZE;
143 offset += PAGE_CACHE_SIZE; 150 offset += PAGE_CACHE_SIZE;
144 } 151 }
145 msg.len = sizeof(bl_msg) + dev->mincount; 152 msg->len = sizeof(bl_msg) + dev->mincount;
146 153
147 dprintk("%s CALLING USERSPACE DAEMON\n", __func__); 154 dprintk("%s CALLING USERSPACE DAEMON\n", __func__);
148 add_wait_queue(&bl_wq, &wq); 155 add_wait_queue(&nn->bl_wq, &wq);
149 rc = rpc_queue_upcall(bl_device_pipe->d_inode, &msg); 156 rc = rpc_queue_upcall(nn->bl_device_pipe, msg);
150 if (rc < 0) { 157 if (rc < 0) {
151 remove_wait_queue(&bl_wq, &wq); 158 remove_wait_queue(&nn->bl_wq, &wq);
152 rv = ERR_PTR(rc); 159 rv = ERR_PTR(rc);
153 goto out; 160 goto out;
154 } 161 }
@@ -156,7 +163,7 @@ nfs4_blk_decode_device(struct nfs_server *server,
156 set_current_state(TASK_UNINTERRUPTIBLE); 163 set_current_state(TASK_UNINTERRUPTIBLE);
157 schedule(); 164 schedule();
158 __set_current_state(TASK_RUNNING); 165 __set_current_state(TASK_RUNNING);
159 remove_wait_queue(&bl_wq, &wq); 166 remove_wait_queue(&nn->bl_wq, &wq);
160 167
161 if (reply->status != BL_DEVICE_REQUEST_PROC) { 168 if (reply->status != BL_DEVICE_REQUEST_PROC) {
162 dprintk("%s failed to open device: %d\n", 169 dprintk("%s failed to open device: %d\n",
@@ -181,13 +188,14 @@ nfs4_blk_decode_device(struct nfs_server *server,
181 188
182 rv->bm_mdev = bd; 189 rv->bm_mdev = bd;
183 memcpy(&rv->bm_mdevid, &dev->dev_id, sizeof(struct nfs4_deviceid)); 190 memcpy(&rv->bm_mdevid, &dev->dev_id, sizeof(struct nfs4_deviceid));
191 rv->net = net;
184 dprintk("%s Created device %s with bd_block_size %u\n", 192 dprintk("%s Created device %s with bd_block_size %u\n",
185 __func__, 193 __func__,
186 bd->bd_disk->disk_name, 194 bd->bd_disk->disk_name,
187 bd->bd_block_size); 195 bd->bd_block_size);
188 196
189out: 197out:
190 kfree(msg.data); 198 kfree(msg->data);
191 return rv; 199 return rv;
192} 200}
193 201
diff --git a/fs/nfs/blocklayout/blocklayoutdm.c b/fs/nfs/blocklayout/blocklayoutdm.c
index d055c755807..737d839bc17 100644
--- a/fs/nfs/blocklayout/blocklayoutdm.c
+++ b/fs/nfs/blocklayout/blocklayoutdm.c
@@ -38,9 +38,10 @@
38 38
39#define NFSDBG_FACILITY NFSDBG_PNFS_LD 39#define NFSDBG_FACILITY NFSDBG_PNFS_LD
40 40
41static void dev_remove(dev_t dev) 41static void dev_remove(struct net *net, dev_t dev)
42{ 42{
43 struct rpc_pipe_msg msg; 43 struct bl_pipe_msg bl_pipe_msg;
44 struct rpc_pipe_msg *msg = &bl_pipe_msg.msg;
44 struct bl_dev_msg bl_umount_request; 45 struct bl_dev_msg bl_umount_request;
45 struct bl_msg_hdr bl_msg = { 46 struct bl_msg_hdr bl_msg = {
46 .type = BL_DEVICE_UMOUNT, 47 .type = BL_DEVICE_UMOUNT,
@@ -48,36 +49,38 @@ static void dev_remove(dev_t dev)
48 }; 49 };
49 uint8_t *dataptr; 50 uint8_t *dataptr;
50 DECLARE_WAITQUEUE(wq, current); 51 DECLARE_WAITQUEUE(wq, current);
52 struct nfs_net *nn = net_generic(net, nfs_net_id);
51 53
52 dprintk("Entering %s\n", __func__); 54 dprintk("Entering %s\n", __func__);
53 55
54 memset(&msg, 0, sizeof(msg)); 56 bl_pipe_msg.bl_wq = &nn->bl_wq;
55 msg.data = kzalloc(1 + sizeof(bl_umount_request), GFP_NOFS); 57 memset(msg, 0, sizeof(*msg));
56 if (!msg.data) 58 msg->data = kzalloc(1 + sizeof(bl_umount_request), GFP_NOFS);
59 if (!msg->data)
57 goto out; 60 goto out;
58 61
59 memset(&bl_umount_request, 0, sizeof(bl_umount_request)); 62 memset(&bl_umount_request, 0, sizeof(bl_umount_request));
60 bl_umount_request.major = MAJOR(dev); 63 bl_umount_request.major = MAJOR(dev);
61 bl_umount_request.minor = MINOR(dev); 64 bl_umount_request.minor = MINOR(dev);
62 65
63 memcpy(msg.data, &bl_msg, sizeof(bl_msg)); 66 memcpy(msg->data, &bl_msg, sizeof(bl_msg));
64 dataptr = (uint8_t *) msg.data; 67 dataptr = (uint8_t *) msg->data;
65 memcpy(&dataptr[sizeof(bl_msg)], &bl_umount_request, sizeof(bl_umount_request)); 68 memcpy(&dataptr[sizeof(bl_msg)], &bl_umount_request, sizeof(bl_umount_request));
66 msg.len = sizeof(bl_msg) + bl_msg.totallen; 69 msg->len = sizeof(bl_msg) + bl_msg.totallen;
67 70
68 add_wait_queue(&bl_wq, &wq); 71 add_wait_queue(&nn->bl_wq, &wq);
69 if (rpc_queue_upcall(bl_device_pipe->d_inode, &msg) < 0) { 72 if (rpc_queue_upcall(nn->bl_device_pipe, msg) < 0) {
70 remove_wait_queue(&bl_wq, &wq); 73 remove_wait_queue(&nn->bl_wq, &wq);
71 goto out; 74 goto out;
72 } 75 }
73 76
74 set_current_state(TASK_UNINTERRUPTIBLE); 77 set_current_state(TASK_UNINTERRUPTIBLE);
75 schedule(); 78 schedule();
76 __set_current_state(TASK_RUNNING); 79 __set_current_state(TASK_RUNNING);
77 remove_wait_queue(&bl_wq, &wq); 80 remove_wait_queue(&nn->bl_wq, &wq);
78 81
79out: 82out:
80 kfree(msg.data); 83 kfree(msg->data);
81} 84}
82 85
83/* 86/*
@@ -90,10 +93,10 @@ static void nfs4_blk_metadev_release(struct pnfs_block_dev *bdev)
90 dprintk("%s Releasing\n", __func__); 93 dprintk("%s Releasing\n", __func__);
91 rv = nfs4_blkdev_put(bdev->bm_mdev); 94 rv = nfs4_blkdev_put(bdev->bm_mdev);
92 if (rv) 95 if (rv)
93 printk(KERN_ERR "%s nfs4_blkdev_put returns %d\n", 96 printk(KERN_ERR "NFS: %s nfs4_blkdev_put returns %d\n",
94 __func__, rv); 97 __func__, rv);
95 98
96 dev_remove(bdev->bm_mdev->bd_dev); 99 dev_remove(bdev->net, bdev->bm_mdev->bd_dev);
97} 100}
98 101
99void bl_free_block_dev(struct pnfs_block_dev *bdev) 102void bl_free_block_dev(struct pnfs_block_dev *bdev)
diff --git a/fs/nfs/blocklayout/extents.c b/fs/nfs/blocklayout/extents.c
index 1abac09f7cd..1f9a6032796 100644
--- a/fs/nfs/blocklayout/extents.c
+++ b/fs/nfs/blocklayout/extents.c
@@ -147,7 +147,7 @@ static int _preload_range(struct pnfs_inval_markings *marks,
147 count = (int)(end - start) / (int)tree->mtt_step_size; 147 count = (int)(end - start) / (int)tree->mtt_step_size;
148 148
149 /* Pre-malloc what memory we might need */ 149 /* Pre-malloc what memory we might need */
150 storage = kmalloc(sizeof(*storage) * count, GFP_NOFS); 150 storage = kcalloc(count, sizeof(*storage), GFP_NOFS);
151 if (!storage) 151 if (!storage)
152 return -ENOMEM; 152 return -ENOMEM;
153 for (i = 0; i < count; i++) { 153 for (i = 0; i < count; i++) {
diff --git a/fs/nfs/cache_lib.c b/fs/nfs/cache_lib.c
index c98b439332f..dded2636811 100644
--- a/fs/nfs/cache_lib.c
+++ b/fs/nfs/cache_lib.c
@@ -13,6 +13,7 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/sunrpc/cache.h> 14#include <linux/sunrpc/cache.h>
15#include <linux/sunrpc/rpc_pipe_fs.h> 15#include <linux/sunrpc/rpc_pipe_fs.h>
16#include <net/net_namespace.h>
16 17
17#include "cache_lib.h" 18#include "cache_lib.h"
18 19
@@ -111,30 +112,54 @@ int nfs_cache_wait_for_upcall(struct nfs_cache_defer_req *dreq)
111 return 0; 112 return 0;
112} 113}
113 114
114int nfs_cache_register(struct cache_detail *cd) 115int nfs_cache_register_sb(struct super_block *sb, struct cache_detail *cd)
115{ 116{
116 struct vfsmount *mnt;
117 struct path path;
118 int ret; 117 int ret;
118 struct dentry *dir;
119 119
120 mnt = rpc_get_mount(); 120 dir = rpc_d_lookup_sb(sb, "cache");
121 if (IS_ERR(mnt)) 121 BUG_ON(dir == NULL);
122 return PTR_ERR(mnt); 122 ret = sunrpc_cache_register_pipefs(dir, cd->name, 0600, cd);
123 ret = vfs_path_lookup(mnt->mnt_root, mnt, "/cache", 0, &path); 123 dput(dir);
124 if (ret)
125 goto err;
126 ret = sunrpc_cache_register_pipefs(path.dentry, cd->name, 0600, cd);
127 path_put(&path);
128 if (!ret)
129 return ret;
130err:
131 rpc_put_mount();
132 return ret; 124 return ret;
133} 125}
134 126
135void nfs_cache_unregister(struct cache_detail *cd) 127int nfs_cache_register_net(struct net *net, struct cache_detail *cd)
136{ 128{
137 sunrpc_cache_unregister_pipefs(cd); 129 struct super_block *pipefs_sb;
138 rpc_put_mount(); 130 int ret = 0;
131
132 pipefs_sb = rpc_get_sb_net(net);
133 if (pipefs_sb) {
134 ret = nfs_cache_register_sb(pipefs_sb, cd);
135 rpc_put_sb_net(net);
136 }
137 return ret;
138}
139
140void nfs_cache_unregister_sb(struct super_block *sb, struct cache_detail *cd)
141{
142 if (cd->u.pipefs.dir)
143 sunrpc_cache_unregister_pipefs(cd);
144}
145
146void nfs_cache_unregister_net(struct net *net, struct cache_detail *cd)
147{
148 struct super_block *pipefs_sb;
149
150 pipefs_sb = rpc_get_sb_net(net);
151 if (pipefs_sb) {
152 nfs_cache_unregister_sb(pipefs_sb, cd);
153 rpc_put_sb_net(net);
154 }
155}
156
157void nfs_cache_init(struct cache_detail *cd)
158{
159 sunrpc_init_cache_detail(cd);
139} 160}
140 161
162void nfs_cache_destroy(struct cache_detail *cd)
163{
164 sunrpc_destroy_cache_detail(cd);
165}
diff --git a/fs/nfs/cache_lib.h b/fs/nfs/cache_lib.h
index 7cf6cafcc00..317db95e37f 100644
--- a/fs/nfs/cache_lib.h
+++ b/fs/nfs/cache_lib.h
@@ -23,5 +23,11 @@ extern struct nfs_cache_defer_req *nfs_cache_defer_req_alloc(void);
23extern void nfs_cache_defer_req_put(struct nfs_cache_defer_req *dreq); 23extern void nfs_cache_defer_req_put(struct nfs_cache_defer_req *dreq);
24extern int nfs_cache_wait_for_upcall(struct nfs_cache_defer_req *dreq); 24extern int nfs_cache_wait_for_upcall(struct nfs_cache_defer_req *dreq);
25 25
26extern int nfs_cache_register(struct cache_detail *cd); 26extern void nfs_cache_init(struct cache_detail *cd);
27extern void nfs_cache_unregister(struct cache_detail *cd); 27extern void nfs_cache_destroy(struct cache_detail *cd);
28extern int nfs_cache_register_net(struct net *net, struct cache_detail *cd);
29extern void nfs_cache_unregister_net(struct net *net, struct cache_detail *cd);
30extern int nfs_cache_register_sb(struct super_block *sb,
31 struct cache_detail *cd);
32extern void nfs_cache_unregister_sb(struct super_block *sb,
33 struct cache_detail *cd);
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index 516f3375e06..eb95f5091c1 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -85,7 +85,7 @@ nfs4_callback_svc(void *vrqstp)
85 } 85 }
86 if (err < 0) { 86 if (err < 0) {
87 if (err != preverr) { 87 if (err != preverr) {
88 printk(KERN_WARNING "%s: unexpected error " 88 printk(KERN_WARNING "NFS: %s: unexpected error "
89 "from svc_recv (%d)\n", __func__, err); 89 "from svc_recv (%d)\n", __func__, err);
90 preverr = err; 90 preverr = err;
91 } 91 }
@@ -101,12 +101,12 @@ nfs4_callback_svc(void *vrqstp)
101/* 101/*
102 * Prepare to bring up the NFSv4 callback service 102 * Prepare to bring up the NFSv4 callback service
103 */ 103 */
104struct svc_rqst * 104static struct svc_rqst *
105nfs4_callback_up(struct svc_serv *serv) 105nfs4_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt)
106{ 106{
107 int ret; 107 int ret;
108 108
109 ret = svc_create_xprt(serv, "tcp", &init_net, PF_INET, 109 ret = svc_create_xprt(serv, "tcp", xprt->xprt_net, PF_INET,
110 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS); 110 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS);
111 if (ret <= 0) 111 if (ret <= 0)
112 goto out_err; 112 goto out_err;
@@ -114,7 +114,7 @@ nfs4_callback_up(struct svc_serv *serv)
114 dprintk("NFS: Callback listener port = %u (af %u)\n", 114 dprintk("NFS: Callback listener port = %u (af %u)\n",
115 nfs_callback_tcpport, PF_INET); 115 nfs_callback_tcpport, PF_INET);
116 116
117 ret = svc_create_xprt(serv, "tcp", &init_net, PF_INET6, 117 ret = svc_create_xprt(serv, "tcp", xprt->xprt_net, PF_INET6,
118 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS); 118 nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS);
119 if (ret > 0) { 119 if (ret > 0) {
120 nfs_callback_tcpport6 = ret; 120 nfs_callback_tcpport6 = ret;
@@ -172,7 +172,7 @@ nfs41_callback_svc(void *vrqstp)
172/* 172/*
173 * Bring up the NFSv4.1 callback service 173 * Bring up the NFSv4.1 callback service
174 */ 174 */
175struct svc_rqst * 175static struct svc_rqst *
176nfs41_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt) 176nfs41_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt)
177{ 177{
178 struct svc_rqst *rqstp; 178 struct svc_rqst *rqstp;
@@ -183,7 +183,7 @@ nfs41_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt)
183 * fore channel connection. 183 * fore channel connection.
184 * Returns the input port (0) and sets the svc_serv bc_xprt on success 184 * Returns the input port (0) and sets the svc_serv bc_xprt on success
185 */ 185 */
186 ret = svc_create_xprt(serv, "tcp-bc", &init_net, PF_INET, 0, 186 ret = svc_create_xprt(serv, "tcp-bc", xprt->xprt_net, PF_INET, 0,
187 SVC_SOCK_ANONYMOUS); 187 SVC_SOCK_ANONYMOUS);
188 if (ret < 0) { 188 if (ret < 0) {
189 rqstp = ERR_PTR(ret); 189 rqstp = ERR_PTR(ret);
@@ -269,7 +269,7 @@ int nfs_callback_up(u32 minorversion, struct rpc_xprt *xprt)
269 serv, xprt, &rqstp, &callback_svc); 269 serv, xprt, &rqstp, &callback_svc);
270 if (!minorversion_setup) { 270 if (!minorversion_setup) {
271 /* v4.0 callback setup */ 271 /* v4.0 callback setup */
272 rqstp = nfs4_callback_up(serv); 272 rqstp = nfs4_callback_up(serv, xprt);
273 callback_svc = nfs4_callback_svc; 273 callback_svc = nfs4_callback_svc;
274 } 274 }
275 275
@@ -332,7 +332,6 @@ void nfs_callback_down(int minorversion)
332int 332int
333check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp) 333check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
334{ 334{
335 struct rpc_clnt *r = clp->cl_rpcclient;
336 char *p = svc_gss_principal(rqstp); 335 char *p = svc_gss_principal(rqstp);
337 336
338 if (rqstp->rq_authop->flavour != RPC_AUTH_GSS) 337 if (rqstp->rq_authop->flavour != RPC_AUTH_GSS)
@@ -353,7 +352,7 @@ check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp)
353 if (memcmp(p, "nfs@", 4) != 0) 352 if (memcmp(p, "nfs@", 4) != 0)
354 return 0; 353 return 0;
355 p += 4; 354 p += 4;
356 if (strcmp(p, r->cl_server) != 0) 355 if (strcmp(p, clp->cl_hostname) != 0)
357 return 0; 356 return 0;
358 return 1; 357 return 1;
359} 358}
diff --git a/fs/nfs/callback.h b/fs/nfs/callback.h
index c89d3b9e483..a5527c90a5a 100644
--- a/fs/nfs/callback.h
+++ b/fs/nfs/callback.h
@@ -38,7 +38,8 @@ enum nfs4_callback_opnum {
38struct cb_process_state { 38struct cb_process_state {
39 __be32 drc_status; 39 __be32 drc_status;
40 struct nfs_client *clp; 40 struct nfs_client *clp;
41 int slotid; 41 u32 slotid;
42 struct net *net;
42}; 43};
43 44
44struct cb_compound_hdr_arg { 45struct cb_compound_hdr_arg {
diff --git a/fs/nfs/callback_proc.c b/fs/nfs/callback_proc.c
index 54cea8ad5a7..1b5d809a105 100644
--- a/fs/nfs/callback_proc.c
+++ b/fs/nfs/callback_proc.c
@@ -8,6 +8,7 @@
8#include <linux/nfs4.h> 8#include <linux/nfs4.h>
9#include <linux/nfs_fs.h> 9#include <linux/nfs_fs.h>
10#include <linux/slab.h> 10#include <linux/slab.h>
11#include <linux/rcupdate.h>
11#include "nfs4_fs.h" 12#include "nfs4_fs.h"
12#include "callback.h" 13#include "callback.h"
13#include "delegation.h" 14#include "delegation.h"
@@ -33,7 +34,7 @@ __be32 nfs4_callback_getattr(struct cb_getattrargs *args,
33 res->bitmap[0] = res->bitmap[1] = 0; 34 res->bitmap[0] = res->bitmap[1] = 0;
34 res->status = htonl(NFS4ERR_BADHANDLE); 35 res->status = htonl(NFS4ERR_BADHANDLE);
35 36
36 dprintk("NFS: GETATTR callback request from %s\n", 37 dprintk_rcu("NFS: GETATTR callback request from %s\n",
37 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR)); 38 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
38 39
39 inode = nfs_delegation_find_inode(cps->clp, &args->fh); 40 inode = nfs_delegation_find_inode(cps->clp, &args->fh);
@@ -73,7 +74,7 @@ __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy,
73 if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */ 74 if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */
74 goto out; 75 goto out;
75 76
76 dprintk("NFS: RECALL callback request from %s\n", 77 dprintk_rcu("NFS: RECALL callback request from %s\n",
77 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR)); 78 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
78 79
79 res = htonl(NFS4ERR_BADHANDLE); 80 res = htonl(NFS4ERR_BADHANDLE);
@@ -86,8 +87,7 @@ __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy,
86 res = 0; 87 res = 0;
87 break; 88 break;
88 case -ENOENT: 89 case -ENOENT:
89 if (res != 0) 90 res = htonl(NFS4ERR_BAD_STATEID);
90 res = htonl(NFS4ERR_BAD_STATEID);
91 break; 91 break;
92 default: 92 default:
93 res = htonl(NFS4ERR_RESOURCE); 93 res = htonl(NFS4ERR_RESOURCE);
@@ -98,52 +98,64 @@ out:
98 return res; 98 return res;
99} 99}
100 100
101int nfs4_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid)
102{
103 if (delegation == NULL || memcmp(delegation->stateid.data, stateid->data,
104 sizeof(delegation->stateid.data)) != 0)
105 return 0;
106 return 1;
107}
108
109#if defined(CONFIG_NFS_V4_1) 101#if defined(CONFIG_NFS_V4_1)
110 102
111static u32 initiate_file_draining(struct nfs_client *clp, 103/*
112 struct cb_layoutrecallargs *args) 104 * Lookup a layout by filehandle.
105 *
106 * Note: gets a refcount on the layout hdr and on its respective inode.
107 * Caller must put the layout hdr and the inode.
108 *
109 * TODO: keep track of all layouts (and delegations) in a hash table
110 * hashed by filehandle.
111 */
112static struct pnfs_layout_hdr * get_layout_by_fh_locked(struct nfs_client *clp, struct nfs_fh *fh)
113{ 113{
114 struct nfs_server *server; 114 struct nfs_server *server;
115 struct pnfs_layout_hdr *lo;
116 struct inode *ino; 115 struct inode *ino;
117 bool found = false; 116 struct pnfs_layout_hdr *lo;
118 u32 rv = NFS4ERR_NOMATCHING_LAYOUT;
119 LIST_HEAD(free_me_list);
120 117
121 spin_lock(&clp->cl_lock);
122 rcu_read_lock();
123 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { 118 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
124 list_for_each_entry(lo, &server->layouts, plh_layouts) { 119 list_for_each_entry(lo, &server->layouts, plh_layouts) {
125 if (nfs_compare_fh(&args->cbl_fh, 120 if (nfs_compare_fh(fh, &NFS_I(lo->plh_inode)->fh))
126 &NFS_I(lo->plh_inode)->fh))
127 continue; 121 continue;
128 ino = igrab(lo->plh_inode); 122 ino = igrab(lo->plh_inode);
129 if (!ino) 123 if (!ino)
130 continue; 124 continue;
131 found = true;
132 /* Without this, layout can be freed as soon
133 * as we release cl_lock.
134 */
135 get_layout_hdr(lo); 125 get_layout_hdr(lo);
136 break; 126 return lo;
137 } 127 }
138 if (found)
139 break;
140 } 128 }
129
130 return NULL;
131}
132
133static struct pnfs_layout_hdr * get_layout_by_fh(struct nfs_client *clp, struct nfs_fh *fh)
134{
135 struct pnfs_layout_hdr *lo;
136
137 spin_lock(&clp->cl_lock);
138 rcu_read_lock();
139 lo = get_layout_by_fh_locked(clp, fh);
141 rcu_read_unlock(); 140 rcu_read_unlock();
142 spin_unlock(&clp->cl_lock); 141 spin_unlock(&clp->cl_lock);
143 142
144 if (!found) 143 return lo;
144}
145
146static u32 initiate_file_draining(struct nfs_client *clp,
147 struct cb_layoutrecallargs *args)
148{
149 struct inode *ino;
150 struct pnfs_layout_hdr *lo;
151 u32 rv = NFS4ERR_NOMATCHING_LAYOUT;
152 LIST_HEAD(free_me_list);
153
154 lo = get_layout_by_fh(clp, &args->cbl_fh);
155 if (!lo)
145 return NFS4ERR_NOMATCHING_LAYOUT; 156 return NFS4ERR_NOMATCHING_LAYOUT;
146 157
158 ino = lo->plh_inode;
147 spin_lock(&ino->i_lock); 159 spin_lock(&ino->i_lock);
148 if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) || 160 if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) ||
149 mark_matching_lsegs_invalid(lo, &free_me_list, 161 mark_matching_lsegs_invalid(lo, &free_me_list,
@@ -213,17 +225,13 @@ static u32 initiate_bulk_draining(struct nfs_client *clp,
213static u32 do_callback_layoutrecall(struct nfs_client *clp, 225static u32 do_callback_layoutrecall(struct nfs_client *clp,
214 struct cb_layoutrecallargs *args) 226 struct cb_layoutrecallargs *args)
215{ 227{
216 u32 res = NFS4ERR_DELAY; 228 u32 res;
217 229
218 dprintk("%s enter, type=%i\n", __func__, args->cbl_recall_type); 230 dprintk("%s enter, type=%i\n", __func__, args->cbl_recall_type);
219 if (test_and_set_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state))
220 goto out;
221 if (args->cbl_recall_type == RETURN_FILE) 231 if (args->cbl_recall_type == RETURN_FILE)
222 res = initiate_file_draining(clp, args); 232 res = initiate_file_draining(clp, args);
223 else 233 else
224 res = initiate_bulk_draining(clp, args); 234 res = initiate_bulk_draining(clp, args);
225 clear_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state);
226out:
227 dprintk("%s returning %i\n", __func__, res); 235 dprintk("%s returning %i\n", __func__, res);
228 return res; 236 return res;
229 237
@@ -303,21 +311,6 @@ out:
303 return res; 311 return res;
304} 312}
305 313
306int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid)
307{
308 if (delegation == NULL)
309 return 0;
310
311 if (stateid->stateid.seqid != 0)
312 return 0;
313 if (memcmp(&delegation->stateid.stateid.other,
314 &stateid->stateid.other,
315 NFS4_STATEID_OTHER_SIZE))
316 return 0;
317
318 return 1;
319}
320
321/* 314/*
322 * Validate the sequenceID sent by the server. 315 * Validate the sequenceID sent by the server.
323 * Return success if the sequenceID is one more than what we last saw on 316 * Return success if the sequenceID is one more than what we last saw on
@@ -441,7 +434,7 @@ __be32 nfs4_callback_sequence(struct cb_sequenceargs *args,
441 int i; 434 int i;
442 __be32 status = htonl(NFS4ERR_BADSESSION); 435 __be32 status = htonl(NFS4ERR_BADSESSION);
443 436
444 clp = nfs4_find_client_sessionid(args->csa_addr, &args->csa_sessionid); 437 clp = nfs4_find_client_sessionid(cps->net, args->csa_addr, &args->csa_sessionid);
445 if (clp == NULL) 438 if (clp == NULL)
446 goto out; 439 goto out;
447 440
@@ -517,7 +510,7 @@ __be32 nfs4_callback_recallany(struct cb_recallanyargs *args, void *dummy,
517 if (!cps->clp) /* set in cb_sequence */ 510 if (!cps->clp) /* set in cb_sequence */
518 goto out; 511 goto out;
519 512
520 dprintk("NFS: RECALL_ANY callback request from %s\n", 513 dprintk_rcu("NFS: RECALL_ANY callback request from %s\n",
521 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR)); 514 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
522 515
523 status = cpu_to_be32(NFS4ERR_INVAL); 516 status = cpu_to_be32(NFS4ERR_INVAL);
@@ -552,7 +545,7 @@ __be32 nfs4_callback_recallslot(struct cb_recallslotargs *args, void *dummy,
552 if (!cps->clp) /* set in cb_sequence */ 545 if (!cps->clp) /* set in cb_sequence */
553 goto out; 546 goto out;
554 547
555 dprintk("NFS: CB_RECALL_SLOT request from %s target max slots %d\n", 548 dprintk_rcu("NFS: CB_RECALL_SLOT request from %s target max slots %d\n",
556 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR), 549 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR),
557 args->crsa_target_max_slots); 550 args->crsa_target_max_slots);
558 551
diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
index d50b2742f23..95bfc243992 100644
--- a/fs/nfs/callback_xdr.c
+++ b/fs/nfs/callback_xdr.c
@@ -9,6 +9,8 @@
9#include <linux/sunrpc/svc.h> 9#include <linux/sunrpc/svc.h>
10#include <linux/nfs4.h> 10#include <linux/nfs4.h>
11#include <linux/nfs_fs.h> 11#include <linux/nfs_fs.h>
12#include <linux/ratelimit.h>
13#include <linux/printk.h>
12#include <linux/slab.h> 14#include <linux/slab.h>
13#include <linux/sunrpc/bc_xprt.h> 15#include <linux/sunrpc/bc_xprt.h>
14#include "nfs4_fs.h" 16#include "nfs4_fs.h"
@@ -73,7 +75,7 @@ static __be32 *read_buf(struct xdr_stream *xdr, int nbytes)
73 75
74 p = xdr_inline_decode(xdr, nbytes); 76 p = xdr_inline_decode(xdr, nbytes);
75 if (unlikely(p == NULL)) 77 if (unlikely(p == NULL))
76 printk(KERN_WARNING "NFSv4 callback reply buffer overflowed!\n"); 78 printk(KERN_WARNING "NFS: NFSv4 callback reply buffer overflowed!\n");
77 return p; 79 return p;
78} 80}
79 81
@@ -138,10 +140,10 @@ static __be32 decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
138{ 140{
139 __be32 *p; 141 __be32 *p;
140 142
141 p = read_buf(xdr, 16); 143 p = read_buf(xdr, NFS4_STATEID_SIZE);
142 if (unlikely(p == NULL)) 144 if (unlikely(p == NULL))
143 return htonl(NFS4ERR_RESOURCE); 145 return htonl(NFS4ERR_RESOURCE);
144 memcpy(stateid->data, p, 16); 146 memcpy(stateid, p, NFS4_STATEID_SIZE);
145 return 0; 147 return 0;
146} 148}
147 149
@@ -155,7 +157,7 @@ static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound
155 return status; 157 return status;
156 /* We do not like overly long tags! */ 158 /* We do not like overly long tags! */
157 if (hdr->taglen > CB_OP_TAGLEN_MAXSZ - 12) { 159 if (hdr->taglen > CB_OP_TAGLEN_MAXSZ - 12) {
158 printk("NFSv4 CALLBACK %s: client sent tag of length %u\n", 160 printk("NFS: NFSv4 CALLBACK %s: client sent tag of length %u\n",
159 __func__, hdr->taglen); 161 __func__, hdr->taglen);
160 return htonl(NFS4ERR_RESOURCE); 162 return htonl(NFS4ERR_RESOURCE);
161 } 163 }
@@ -167,7 +169,7 @@ static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound
167 if (hdr->minorversion <= 1) { 169 if (hdr->minorversion <= 1) {
168 hdr->cb_ident = ntohl(*p++); /* ignored by v4.1 */ 170 hdr->cb_ident = ntohl(*p++); /* ignored by v4.1 */
169 } else { 171 } else {
170 printk(KERN_WARNING "%s: NFSv4 server callback with " 172 pr_warn_ratelimited("NFS: %s: NFSv4 server callback with "
171 "illegal minor version %u!\n", 173 "illegal minor version %u!\n",
172 __func__, hdr->minorversion); 174 __func__, hdr->minorversion);
173 return htonl(NFS4ERR_MINOR_VERS_MISMATCH); 175 return htonl(NFS4ERR_MINOR_VERS_MISMATCH);
@@ -759,14 +761,14 @@ static void nfs4_callback_free_slot(struct nfs4_session *session)
759 * Let the state manager know callback processing done. 761 * Let the state manager know callback processing done.
760 * A single slot, so highest used slotid is either 0 or -1 762 * A single slot, so highest used slotid is either 0 or -1
761 */ 763 */
762 tbl->highest_used_slotid = -1; 764 tbl->highest_used_slotid = NFS4_NO_SLOT;
763 nfs4_check_drain_bc_complete(session); 765 nfs4_check_drain_bc_complete(session);
764 spin_unlock(&tbl->slot_tbl_lock); 766 spin_unlock(&tbl->slot_tbl_lock);
765} 767}
766 768
767static void nfs4_cb_free_slot(struct cb_process_state *cps) 769static void nfs4_cb_free_slot(struct cb_process_state *cps)
768{ 770{
769 if (cps->slotid != -1) 771 if (cps->slotid != NFS4_NO_SLOT)
770 nfs4_callback_free_slot(cps->clp->cl_session); 772 nfs4_callback_free_slot(cps->clp->cl_session);
771} 773}
772 774
@@ -860,7 +862,8 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r
860 struct cb_process_state cps = { 862 struct cb_process_state cps = {
861 .drc_status = 0, 863 .drc_status = 0,
862 .clp = NULL, 864 .clp = NULL,
863 .slotid = -1, 865 .slotid = NFS4_NO_SLOT,
866 .net = rqstp->rq_xprt->xpt_net,
864 }; 867 };
865 unsigned int nops = 0; 868 unsigned int nops = 0;
866 869
@@ -876,7 +879,7 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r
876 return rpc_garbage_args; 879 return rpc_garbage_args;
877 880
878 if (hdr_arg.minorversion == 0) { 881 if (hdr_arg.minorversion == 0) {
879 cps.clp = nfs4_find_client_ident(hdr_arg.cb_ident); 882 cps.clp = nfs4_find_client_ident(rqstp->rq_xprt->xpt_net, hdr_arg.cb_ident);
880 if (!cps.clp || !check_gss_callback_principal(cps.clp, rqstp)) 883 if (!cps.clp || !check_gss_callback_principal(cps.clp, rqstp))
881 return rpc_drop_reply; 884 return rpc_drop_reply;
882 } 885 }
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index d4f772ebd1e..4a108a0a2a6 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -40,6 +40,8 @@
40#include <net/ipv6.h> 40#include <net/ipv6.h>
41#include <linux/nfs_xdr.h> 41#include <linux/nfs_xdr.h>
42#include <linux/sunrpc/bc_xprt.h> 42#include <linux/sunrpc/bc_xprt.h>
43#include <linux/nsproxy.h>
44#include <linux/pid_namespace.h>
43 45
44#include <asm/system.h> 46#include <asm/system.h>
45 47
@@ -50,15 +52,12 @@
50#include "internal.h" 52#include "internal.h"
51#include "fscache.h" 53#include "fscache.h"
52#include "pnfs.h" 54#include "pnfs.h"
55#include "netns.h"
53 56
54#define NFSDBG_FACILITY NFSDBG_CLIENT 57#define NFSDBG_FACILITY NFSDBG_CLIENT
55 58
56static DEFINE_SPINLOCK(nfs_client_lock);
57static LIST_HEAD(nfs_client_list);
58static LIST_HEAD(nfs_volume_list);
59static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); 59static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq);
60#ifdef CONFIG_NFS_V4 60#ifdef CONFIG_NFS_V4
61static DEFINE_IDR(cb_ident_idr); /* Protected by nfs_client_lock */
62 61
63/* 62/*
64 * Get a unique NFSv4.0 callback identifier which will be used 63 * Get a unique NFSv4.0 callback identifier which will be used
@@ -67,15 +66,16 @@ static DEFINE_IDR(cb_ident_idr); /* Protected by nfs_client_lock */
67static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion) 66static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion)
68{ 67{
69 int ret = 0; 68 int ret = 0;
69 struct nfs_net *nn = net_generic(clp->net, nfs_net_id);
70 70
71 if (clp->rpc_ops->version != 4 || minorversion != 0) 71 if (clp->rpc_ops->version != 4 || minorversion != 0)
72 return ret; 72 return ret;
73retry: 73retry:
74 if (!idr_pre_get(&cb_ident_idr, GFP_KERNEL)) 74 if (!idr_pre_get(&nn->cb_ident_idr, GFP_KERNEL))
75 return -ENOMEM; 75 return -ENOMEM;
76 spin_lock(&nfs_client_lock); 76 spin_lock(&nn->nfs_client_lock);
77 ret = idr_get_new(&cb_ident_idr, clp, &clp->cl_cb_ident); 77 ret = idr_get_new(&nn->cb_ident_idr, clp, &clp->cl_cb_ident);
78 spin_unlock(&nfs_client_lock); 78 spin_unlock(&nn->nfs_client_lock);
79 if (ret == -EAGAIN) 79 if (ret == -EAGAIN)
80 goto retry; 80 goto retry;
81 return ret; 81 return ret;
@@ -90,7 +90,7 @@ static bool nfs4_disable_idmapping = true;
90/* 90/*
91 * RPC cruft for NFS 91 * RPC cruft for NFS
92 */ 92 */
93static struct rpc_version *nfs_version[5] = { 93static const struct rpc_version *nfs_version[5] = {
94 [2] = &nfs_version2, 94 [2] = &nfs_version2,
95#ifdef CONFIG_NFS_V3 95#ifdef CONFIG_NFS_V3
96 [3] = &nfs_version3, 96 [3] = &nfs_version3,
@@ -100,7 +100,7 @@ static struct rpc_version *nfs_version[5] = {
100#endif 100#endif
101}; 101};
102 102
103struct rpc_program nfs_program = { 103const struct rpc_program nfs_program = {
104 .name = "nfs", 104 .name = "nfs",
105 .number = NFS_PROGRAM, 105 .number = NFS_PROGRAM,
106 .nrvers = ARRAY_SIZE(nfs_version), 106 .nrvers = ARRAY_SIZE(nfs_version),
@@ -116,11 +116,11 @@ struct rpc_stat nfs_rpcstat = {
116 116
117#ifdef CONFIG_NFS_V3_ACL 117#ifdef CONFIG_NFS_V3_ACL
118static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program }; 118static struct rpc_stat nfsacl_rpcstat = { &nfsacl_program };
119static struct rpc_version * nfsacl_version[] = { 119static const struct rpc_version *nfsacl_version[] = {
120 [3] = &nfsacl_version3, 120 [3] = &nfsacl_version3,
121}; 121};
122 122
123struct rpc_program nfsacl_program = { 123const struct rpc_program nfsacl_program = {
124 .name = "nfsacl", 124 .name = "nfsacl",
125 .number = NFS_ACL_PROGRAM, 125 .number = NFS_ACL_PROGRAM,
126 .nrvers = ARRAY_SIZE(nfsacl_version), 126 .nrvers = ARRAY_SIZE(nfsacl_version),
@@ -136,6 +136,7 @@ struct nfs_client_initdata {
136 const struct nfs_rpc_ops *rpc_ops; 136 const struct nfs_rpc_ops *rpc_ops;
137 int proto; 137 int proto;
138 u32 minorversion; 138 u32 minorversion;
139 struct net *net;
139}; 140};
140 141
141/* 142/*
@@ -172,6 +173,7 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_
172 clp->cl_rpcclient = ERR_PTR(-EINVAL); 173 clp->cl_rpcclient = ERR_PTR(-EINVAL);
173 174
174 clp->cl_proto = cl_init->proto; 175 clp->cl_proto = cl_init->proto;
176 clp->net = get_net(cl_init->net);
175 177
176#ifdef CONFIG_NFS_V4 178#ifdef CONFIG_NFS_V4
177 err = nfs_get_cb_ident_idr(clp, cl_init->minorversion); 179 err = nfs_get_cb_ident_idr(clp, cl_init->minorversion);
@@ -203,8 +205,11 @@ error_0:
203#ifdef CONFIG_NFS_V4_1 205#ifdef CONFIG_NFS_V4_1
204static void nfs4_shutdown_session(struct nfs_client *clp) 206static void nfs4_shutdown_session(struct nfs_client *clp)
205{ 207{
206 if (nfs4_has_session(clp)) 208 if (nfs4_has_session(clp)) {
209 nfs4_deviceid_purge_client(clp);
207 nfs4_destroy_session(clp->cl_session); 210 nfs4_destroy_session(clp->cl_session);
211 }
212
208} 213}
209#else /* CONFIG_NFS_V4_1 */ 214#else /* CONFIG_NFS_V4_1 */
210static void nfs4_shutdown_session(struct nfs_client *clp) 215static void nfs4_shutdown_session(struct nfs_client *clp)
@@ -234,16 +239,20 @@ static void nfs4_shutdown_client(struct nfs_client *clp)
234} 239}
235 240
236/* idr_remove_all is not needed as all id's are removed by nfs_put_client */ 241/* idr_remove_all is not needed as all id's are removed by nfs_put_client */
237void nfs_cleanup_cb_ident_idr(void) 242void nfs_cleanup_cb_ident_idr(struct net *net)
238{ 243{
239 idr_destroy(&cb_ident_idr); 244 struct nfs_net *nn = net_generic(net, nfs_net_id);
245
246 idr_destroy(&nn->cb_ident_idr);
240} 247}
241 248
242/* nfs_client_lock held */ 249/* nfs_client_lock held */
243static void nfs_cb_idr_remove_locked(struct nfs_client *clp) 250static void nfs_cb_idr_remove_locked(struct nfs_client *clp)
244{ 251{
252 struct nfs_net *nn = net_generic(clp->net, nfs_net_id);
253
245 if (clp->cl_cb_ident) 254 if (clp->cl_cb_ident)
246 idr_remove(&cb_ident_idr, clp->cl_cb_ident); 255 idr_remove(&nn->cb_ident_idr, clp->cl_cb_ident);
247} 256}
248 257
249static void pnfs_init_server(struct nfs_server *server) 258static void pnfs_init_server(struct nfs_server *server)
@@ -261,7 +270,7 @@ static void nfs4_shutdown_client(struct nfs_client *clp)
261{ 270{
262} 271}
263 272
264void nfs_cleanup_cb_ident_idr(void) 273void nfs_cleanup_cb_ident_idr(struct net *net)
265{ 274{
266} 275}
267 276
@@ -293,10 +302,10 @@ static void nfs_free_client(struct nfs_client *clp)
293 if (clp->cl_machine_cred != NULL) 302 if (clp->cl_machine_cred != NULL)
294 put_rpccred(clp->cl_machine_cred); 303 put_rpccred(clp->cl_machine_cred);
295 304
296 nfs4_deviceid_purge_client(clp); 305 put_net(clp->net);
297
298 kfree(clp->cl_hostname); 306 kfree(clp->cl_hostname);
299 kfree(clp->server_scope); 307 kfree(clp->server_scope);
308 kfree(clp->impl_id);
300 kfree(clp); 309 kfree(clp);
301 310
302 dprintk("<-- nfs_free_client()\n"); 311 dprintk("<-- nfs_free_client()\n");
@@ -307,15 +316,18 @@ static void nfs_free_client(struct nfs_client *clp)
307 */ 316 */
308void nfs_put_client(struct nfs_client *clp) 317void nfs_put_client(struct nfs_client *clp)
309{ 318{
319 struct nfs_net *nn;
320
310 if (!clp) 321 if (!clp)
311 return; 322 return;
312 323
313 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count)); 324 dprintk("--> nfs_put_client({%d})\n", atomic_read(&clp->cl_count));
325 nn = net_generic(clp->net, nfs_net_id);
314 326
315 if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) { 327 if (atomic_dec_and_lock(&clp->cl_count, &nn->nfs_client_lock)) {
316 list_del(&clp->cl_share_link); 328 list_del(&clp->cl_share_link);
317 nfs_cb_idr_remove_locked(clp); 329 nfs_cb_idr_remove_locked(clp);
318 spin_unlock(&nfs_client_lock); 330 spin_unlock(&nn->nfs_client_lock);
319 331
320 BUG_ON(!list_empty(&clp->cl_superblocks)); 332 BUG_ON(!list_empty(&clp->cl_superblocks));
321 333
@@ -393,6 +405,7 @@ static int nfs_sockaddr_cmp_ip4(const struct sockaddr *sa1,
393 (sin1->sin_port == sin2->sin_port); 405 (sin1->sin_port == sin2->sin_port);
394} 406}
395 407
408#if defined(CONFIG_NFS_V4_1)
396/* 409/*
397 * Test if two socket addresses represent the same actual socket, 410 * Test if two socket addresses represent the same actual socket,
398 * by comparing (only) relevant fields, excluding the port number. 411 * by comparing (only) relevant fields, excluding the port number.
@@ -411,6 +424,7 @@ static int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1,
411 } 424 }
412 return 0; 425 return 0;
413} 426}
427#endif /* CONFIG_NFS_V4_1 */
414 428
415/* 429/*
416 * Test if two socket addresses represent the same actual socket, 430 * Test if two socket addresses represent the same actual socket,
@@ -431,10 +445,10 @@ static int nfs_sockaddr_cmp(const struct sockaddr *sa1,
431 return 0; 445 return 0;
432} 446}
433 447
448#if defined(CONFIG_NFS_V4_1)
434/* Common match routine for v4.0 and v4.1 callback services */ 449/* Common match routine for v4.0 and v4.1 callback services */
435bool 450static bool nfs4_cb_match_client(const struct sockaddr *addr,
436nfs4_cb_match_client(const struct sockaddr *addr, struct nfs_client *clp, 451 struct nfs_client *clp, u32 minorversion)
437 u32 minorversion)
438{ 452{
439 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; 453 struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
440 454
@@ -454,6 +468,7 @@ nfs4_cb_match_client(const struct sockaddr *addr, struct nfs_client *clp,
454 468
455 return true; 469 return true;
456} 470}
471#endif /* CONFIG_NFS_V4_1 */
457 472
458/* 473/*
459 * Find an nfs_client on the list that matches the initialisation data 474 * Find an nfs_client on the list that matches the initialisation data
@@ -463,8 +478,9 @@ static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *dat
463{ 478{
464 struct nfs_client *clp; 479 struct nfs_client *clp;
465 const struct sockaddr *sap = data->addr; 480 const struct sockaddr *sap = data->addr;
481 struct nfs_net *nn = net_generic(data->net, nfs_net_id);
466 482
467 list_for_each_entry(clp, &nfs_client_list, cl_share_link) { 483 list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
468 const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; 484 const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr;
469 /* Don't match clients that failed to initialise properly */ 485 /* Don't match clients that failed to initialise properly */
470 if (clp->cl_cons_state < 0) 486 if (clp->cl_cons_state < 0)
@@ -502,13 +518,14 @@ nfs_get_client(const struct nfs_client_initdata *cl_init,
502{ 518{
503 struct nfs_client *clp, *new = NULL; 519 struct nfs_client *clp, *new = NULL;
504 int error; 520 int error;
521 struct nfs_net *nn = net_generic(cl_init->net, nfs_net_id);
505 522
506 dprintk("--> nfs_get_client(%s,v%u)\n", 523 dprintk("--> nfs_get_client(%s,v%u)\n",
507 cl_init->hostname ?: "", cl_init->rpc_ops->version); 524 cl_init->hostname ?: "", cl_init->rpc_ops->version);
508 525
509 /* see if the client already exists */ 526 /* see if the client already exists */
510 do { 527 do {
511 spin_lock(&nfs_client_lock); 528 spin_lock(&nn->nfs_client_lock);
512 529
513 clp = nfs_match_client(cl_init); 530 clp = nfs_match_client(cl_init);
514 if (clp) 531 if (clp)
@@ -516,7 +533,7 @@ nfs_get_client(const struct nfs_client_initdata *cl_init,
516 if (new) 533 if (new)
517 goto install_client; 534 goto install_client;
518 535
519 spin_unlock(&nfs_client_lock); 536 spin_unlock(&nn->nfs_client_lock);
520 537
521 new = nfs_alloc_client(cl_init); 538 new = nfs_alloc_client(cl_init);
522 } while (!IS_ERR(new)); 539 } while (!IS_ERR(new));
@@ -527,8 +544,8 @@ nfs_get_client(const struct nfs_client_initdata *cl_init,
527 /* install a new client and return with it unready */ 544 /* install a new client and return with it unready */
528install_client: 545install_client:
529 clp = new; 546 clp = new;
530 list_add(&clp->cl_share_link, &nfs_client_list); 547 list_add(&clp->cl_share_link, &nn->nfs_client_list);
531 spin_unlock(&nfs_client_lock); 548 spin_unlock(&nn->nfs_client_lock);
532 549
533 error = cl_init->rpc_ops->init_client(clp, timeparms, ip_addr, 550 error = cl_init->rpc_ops->init_client(clp, timeparms, ip_addr,
534 authflavour, noresvport); 551 authflavour, noresvport);
@@ -543,7 +560,7 @@ install_client:
543 * - make sure it's ready before returning 560 * - make sure it's ready before returning
544 */ 561 */
545found_client: 562found_client:
546 spin_unlock(&nfs_client_lock); 563 spin_unlock(&nn->nfs_client_lock);
547 564
548 if (new) 565 if (new)
549 nfs_free_client(new); 566 nfs_free_client(new);
@@ -643,7 +660,7 @@ static int nfs_create_rpc_client(struct nfs_client *clp,
643{ 660{
644 struct rpc_clnt *clnt = NULL; 661 struct rpc_clnt *clnt = NULL;
645 struct rpc_create_args args = { 662 struct rpc_create_args args = {
646 .net = &init_net, 663 .net = clp->net,
647 .protocol = clp->cl_proto, 664 .protocol = clp->cl_proto,
648 .address = (struct sockaddr *)&clp->cl_addr, 665 .address = (struct sockaddr *)&clp->cl_addr,
649 .addrsize = clp->cl_addrlen, 666 .addrsize = clp->cl_addrlen,
@@ -697,6 +714,7 @@ static int nfs_start_lockd(struct nfs_server *server)
697 .nfs_version = clp->rpc_ops->version, 714 .nfs_version = clp->rpc_ops->version,
698 .noresvport = server->flags & NFS_MOUNT_NORESVPORT ? 715 .noresvport = server->flags & NFS_MOUNT_NORESVPORT ?
699 1 : 0, 716 1 : 0,
717 .net = clp->net,
700 }; 718 };
701 719
702 if (nlm_init.nfs_version > 3) 720 if (nlm_init.nfs_version > 3)
@@ -832,6 +850,7 @@ static int nfs_init_server(struct nfs_server *server,
832 .addrlen = data->nfs_server.addrlen, 850 .addrlen = data->nfs_server.addrlen,
833 .rpc_ops = &nfs_v2_clientops, 851 .rpc_ops = &nfs_v2_clientops,
834 .proto = data->nfs_server.protocol, 852 .proto = data->nfs_server.protocol,
853 .net = data->net,
835 }; 854 };
836 struct rpc_timeout timeparms; 855 struct rpc_timeout timeparms;
837 struct nfs_client *clp; 856 struct nfs_client *clp;
@@ -1030,25 +1049,30 @@ static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_serve
1030static void nfs_server_insert_lists(struct nfs_server *server) 1049static void nfs_server_insert_lists(struct nfs_server *server)
1031{ 1050{
1032 struct nfs_client *clp = server->nfs_client; 1051 struct nfs_client *clp = server->nfs_client;
1052 struct nfs_net *nn = net_generic(clp->net, nfs_net_id);
1033 1053
1034 spin_lock(&nfs_client_lock); 1054 spin_lock(&nn->nfs_client_lock);
1035 list_add_tail_rcu(&server->client_link, &clp->cl_superblocks); 1055 list_add_tail_rcu(&server->client_link, &clp->cl_superblocks);
1036 list_add_tail(&server->master_link, &nfs_volume_list); 1056 list_add_tail(&server->master_link, &nn->nfs_volume_list);
1037 clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); 1057 clear_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state);
1038 spin_unlock(&nfs_client_lock); 1058 spin_unlock(&nn->nfs_client_lock);
1039 1059
1040} 1060}
1041 1061
1042static void nfs_server_remove_lists(struct nfs_server *server) 1062static void nfs_server_remove_lists(struct nfs_server *server)
1043{ 1063{
1044 struct nfs_client *clp = server->nfs_client; 1064 struct nfs_client *clp = server->nfs_client;
1065 struct nfs_net *nn;
1045 1066
1046 spin_lock(&nfs_client_lock); 1067 if (clp == NULL)
1068 return;
1069 nn = net_generic(clp->net, nfs_net_id);
1070 spin_lock(&nn->nfs_client_lock);
1047 list_del_rcu(&server->client_link); 1071 list_del_rcu(&server->client_link);
1048 if (clp && list_empty(&clp->cl_superblocks)) 1072 if (list_empty(&clp->cl_superblocks))
1049 set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state); 1073 set_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state);
1050 list_del(&server->master_link); 1074 list_del(&server->master_link);
1051 spin_unlock(&nfs_client_lock); 1075 spin_unlock(&nn->nfs_client_lock);
1052 1076
1053 synchronize_rcu(); 1077 synchronize_rcu();
1054} 1078}
@@ -1087,6 +1111,8 @@ static struct nfs_server *nfs_alloc_server(void)
1087 return NULL; 1111 return NULL;
1088 } 1112 }
1089 1113
1114 ida_init(&server->openowner_id);
1115 ida_init(&server->lockowner_id);
1090 pnfs_init_server(server); 1116 pnfs_init_server(server);
1091 1117
1092 return server; 1118 return server;
@@ -1112,6 +1138,8 @@ void nfs_free_server(struct nfs_server *server)
1112 1138
1113 nfs_put_client(server->nfs_client); 1139 nfs_put_client(server->nfs_client);
1114 1140
1141 ida_destroy(&server->lockowner_id);
1142 ida_destroy(&server->openowner_id);
1115 nfs_free_iostats(server->io_stats); 1143 nfs_free_iostats(server->io_stats);
1116 bdi_destroy(&server->backing_dev_info); 1144 bdi_destroy(&server->backing_dev_info);
1117 kfree(server); 1145 kfree(server);
@@ -1190,45 +1218,19 @@ error:
1190/* 1218/*
1191 * NFSv4.0 callback thread helper 1219 * NFSv4.0 callback thread helper
1192 * 1220 *
1193 * Find a client by IP address, protocol version, and minorversion
1194 *
1195 * Called from the pg_authenticate method. The callback identifier
1196 * is not used as it has not been decoded.
1197 *
1198 * Returns NULL if no such client
1199 */
1200struct nfs_client *
1201nfs4_find_client_no_ident(const struct sockaddr *addr)
1202{
1203 struct nfs_client *clp;
1204
1205 spin_lock(&nfs_client_lock);
1206 list_for_each_entry(clp, &nfs_client_list, cl_share_link) {
1207 if (nfs4_cb_match_client(addr, clp, 0) == false)
1208 continue;
1209 atomic_inc(&clp->cl_count);
1210 spin_unlock(&nfs_client_lock);
1211 return clp;
1212 }
1213 spin_unlock(&nfs_client_lock);
1214 return NULL;
1215}
1216
1217/*
1218 * NFSv4.0 callback thread helper
1219 *
1220 * Find a client by callback identifier 1221 * Find a client by callback identifier
1221 */ 1222 */
1222struct nfs_client * 1223struct nfs_client *
1223nfs4_find_client_ident(int cb_ident) 1224nfs4_find_client_ident(struct net *net, int cb_ident)
1224{ 1225{
1225 struct nfs_client *clp; 1226 struct nfs_client *clp;
1227 struct nfs_net *nn = net_generic(net, nfs_net_id);
1226 1228
1227 spin_lock(&nfs_client_lock); 1229 spin_lock(&nn->nfs_client_lock);
1228 clp = idr_find(&cb_ident_idr, cb_ident); 1230 clp = idr_find(&nn->cb_ident_idr, cb_ident);
1229 if (clp) 1231 if (clp)
1230 atomic_inc(&clp->cl_count); 1232 atomic_inc(&clp->cl_count);
1231 spin_unlock(&nfs_client_lock); 1233 spin_unlock(&nn->nfs_client_lock);
1232 return clp; 1234 return clp;
1233} 1235}
1234 1236
@@ -1241,13 +1243,14 @@ nfs4_find_client_ident(int cb_ident)
1241 * Returns NULL if no such client 1243 * Returns NULL if no such client
1242 */ 1244 */
1243struct nfs_client * 1245struct nfs_client *
1244nfs4_find_client_sessionid(const struct sockaddr *addr, 1246nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr,
1245 struct nfs4_sessionid *sid) 1247 struct nfs4_sessionid *sid)
1246{ 1248{
1247 struct nfs_client *clp; 1249 struct nfs_client *clp;
1250 struct nfs_net *nn = net_generic(net, nfs_net_id);
1248 1251
1249 spin_lock(&nfs_client_lock); 1252 spin_lock(&nn->nfs_client_lock);
1250 list_for_each_entry(clp, &nfs_client_list, cl_share_link) { 1253 list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
1251 if (nfs4_cb_match_client(addr, clp, 1) == false) 1254 if (nfs4_cb_match_client(addr, clp, 1) == false)
1252 continue; 1255 continue;
1253 1256
@@ -1260,17 +1263,17 @@ nfs4_find_client_sessionid(const struct sockaddr *addr,
1260 continue; 1263 continue;
1261 1264
1262 atomic_inc(&clp->cl_count); 1265 atomic_inc(&clp->cl_count);
1263 spin_unlock(&nfs_client_lock); 1266 spin_unlock(&nn->nfs_client_lock);
1264 return clp; 1267 return clp;
1265 } 1268 }
1266 spin_unlock(&nfs_client_lock); 1269 spin_unlock(&nn->nfs_client_lock);
1267 return NULL; 1270 return NULL;
1268} 1271}
1269 1272
1270#else /* CONFIG_NFS_V4_1 */ 1273#else /* CONFIG_NFS_V4_1 */
1271 1274
1272struct nfs_client * 1275struct nfs_client *
1273nfs4_find_client_sessionid(const struct sockaddr *addr, 1276nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr,
1274 struct nfs4_sessionid *sid) 1277 struct nfs4_sessionid *sid)
1275{ 1278{
1276 return NULL; 1279 return NULL;
@@ -1285,16 +1288,18 @@ static int nfs4_init_callback(struct nfs_client *clp)
1285 int error; 1288 int error;
1286 1289
1287 if (clp->rpc_ops->version == 4) { 1290 if (clp->rpc_ops->version == 4) {
1291 struct rpc_xprt *xprt;
1292
1293 xprt = rcu_dereference_raw(clp->cl_rpcclient->cl_xprt);
1294
1288 if (nfs4_has_session(clp)) { 1295 if (nfs4_has_session(clp)) {
1289 error = xprt_setup_backchannel( 1296 error = xprt_setup_backchannel(xprt,
1290 clp->cl_rpcclient->cl_xprt,
1291 NFS41_BC_MIN_CALLBACKS); 1297 NFS41_BC_MIN_CALLBACKS);
1292 if (error < 0) 1298 if (error < 0)
1293 return error; 1299 return error;
1294 } 1300 }
1295 1301
1296 error = nfs_callback_up(clp->cl_mvops->minor_version, 1302 error = nfs_callback_up(clp->cl_mvops->minor_version, xprt);
1297 clp->cl_rpcclient->cl_xprt);
1298 if (error < 0) { 1303 if (error < 0) {
1299 dprintk("%s: failed to start callback. Error = %d\n", 1304 dprintk("%s: failed to start callback. Error = %d\n",
1300 __func__, error); 1305 __func__, error);
@@ -1345,6 +1350,7 @@ int nfs4_init_client(struct nfs_client *clp,
1345 rpc_authflavor_t authflavour, 1350 rpc_authflavor_t authflavour,
1346 int noresvport) 1351 int noresvport)
1347{ 1352{
1353 char buf[INET6_ADDRSTRLEN + 1];
1348 int error; 1354 int error;
1349 1355
1350 if (clp->cl_cons_state == NFS_CS_READY) { 1356 if (clp->cl_cons_state == NFS_CS_READY) {
@@ -1360,6 +1366,20 @@ int nfs4_init_client(struct nfs_client *clp,
1360 1, noresvport); 1366 1, noresvport);
1361 if (error < 0) 1367 if (error < 0)
1362 goto error; 1368 goto error;
1369
1370 /* If no clientaddr= option was specified, find a usable cb address */
1371 if (ip_addr == NULL) {
1372 struct sockaddr_storage cb_addr;
1373 struct sockaddr *sap = (struct sockaddr *)&cb_addr;
1374
1375 error = rpc_localaddr(clp->cl_rpcclient, sap, sizeof(cb_addr));
1376 if (error < 0)
1377 goto error;
1378 error = rpc_ntop(sap, buf, sizeof(buf));
1379 if (error < 0)
1380 goto error;
1381 ip_addr = (const char *)buf;
1382 }
1363 strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr)); 1383 strlcpy(clp->cl_ipaddr, ip_addr, sizeof(clp->cl_ipaddr));
1364 1384
1365 error = nfs_idmap_new(clp); 1385 error = nfs_idmap_new(clp);
@@ -1394,7 +1414,7 @@ static int nfs4_set_client(struct nfs_server *server,
1394 const char *ip_addr, 1414 const char *ip_addr,
1395 rpc_authflavor_t authflavour, 1415 rpc_authflavor_t authflavour,
1396 int proto, const struct rpc_timeout *timeparms, 1416 int proto, const struct rpc_timeout *timeparms,
1397 u32 minorversion) 1417 u32 minorversion, struct net *net)
1398{ 1418{
1399 struct nfs_client_initdata cl_init = { 1419 struct nfs_client_initdata cl_init = {
1400 .hostname = hostname, 1420 .hostname = hostname,
@@ -1403,6 +1423,7 @@ static int nfs4_set_client(struct nfs_server *server,
1403 .rpc_ops = &nfs_v4_clientops, 1423 .rpc_ops = &nfs_v4_clientops,
1404 .proto = proto, 1424 .proto = proto,
1405 .minorversion = minorversion, 1425 .minorversion = minorversion,
1426 .net = net,
1406 }; 1427 };
1407 struct nfs_client *clp; 1428 struct nfs_client *clp;
1408 int error; 1429 int error;
@@ -1454,6 +1475,7 @@ struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
1454 .rpc_ops = &nfs_v4_clientops, 1475 .rpc_ops = &nfs_v4_clientops,
1455 .proto = ds_proto, 1476 .proto = ds_proto,
1456 .minorversion = mds_clp->cl_minorversion, 1477 .minorversion = mds_clp->cl_minorversion,
1478 .net = mds_clp->net,
1457 }; 1479 };
1458 struct rpc_timeout ds_timeout = { 1480 struct rpc_timeout ds_timeout = {
1459 .to_initval = 15 * HZ, 1481 .to_initval = 15 * HZ,
@@ -1581,7 +1603,8 @@ static int nfs4_init_server(struct nfs_server *server,
1581 data->auth_flavors[0], 1603 data->auth_flavors[0],
1582 data->nfs_server.protocol, 1604 data->nfs_server.protocol,
1583 &timeparms, 1605 &timeparms,
1584 data->minorversion); 1606 data->minorversion,
1607 data->net);
1585 if (error < 0) 1608 if (error < 0)
1586 goto error; 1609 goto error;
1587 1610
@@ -1676,9 +1699,10 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
1676 data->addrlen, 1699 data->addrlen,
1677 parent_client->cl_ipaddr, 1700 parent_client->cl_ipaddr,
1678 data->authflavor, 1701 data->authflavor,
1679 parent_server->client->cl_xprt->prot, 1702 rpc_protocol(parent_server->client),
1680 parent_server->client->cl_timeout, 1703 parent_server->client->cl_timeout,
1681 parent_client->cl_mvops->minor_version); 1704 parent_client->cl_mvops->minor_version,
1705 parent_client->net);
1682 if (error < 0) 1706 if (error < 0)
1683 goto error; 1707 goto error;
1684 1708
@@ -1771,6 +1795,18 @@ out_free_server:
1771 return ERR_PTR(error); 1795 return ERR_PTR(error);
1772} 1796}
1773 1797
1798void nfs_clients_init(struct net *net)
1799{
1800 struct nfs_net *nn = net_generic(net, nfs_net_id);
1801
1802 INIT_LIST_HEAD(&nn->nfs_client_list);
1803 INIT_LIST_HEAD(&nn->nfs_volume_list);
1804#ifdef CONFIG_NFS_V4
1805 idr_init(&nn->cb_ident_idr);
1806#endif
1807 spin_lock_init(&nn->nfs_client_lock);
1808}
1809
1774#ifdef CONFIG_PROC_FS 1810#ifdef CONFIG_PROC_FS
1775static struct proc_dir_entry *proc_fs_nfs; 1811static struct proc_dir_entry *proc_fs_nfs;
1776 1812
@@ -1824,13 +1860,15 @@ static int nfs_server_list_open(struct inode *inode, struct file *file)
1824{ 1860{
1825 struct seq_file *m; 1861 struct seq_file *m;
1826 int ret; 1862 int ret;
1863 struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info;
1864 struct net *net = pid_ns->child_reaper->nsproxy->net_ns;
1827 1865
1828 ret = seq_open(file, &nfs_server_list_ops); 1866 ret = seq_open(file, &nfs_server_list_ops);
1829 if (ret < 0) 1867 if (ret < 0)
1830 return ret; 1868 return ret;
1831 1869
1832 m = file->private_data; 1870 m = file->private_data;
1833 m->private = PDE(inode)->data; 1871 m->private = net;
1834 1872
1835 return 0; 1873 return 0;
1836} 1874}
@@ -1840,9 +1878,11 @@ static int nfs_server_list_open(struct inode *inode, struct file *file)
1840 */ 1878 */
1841static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos) 1879static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos)
1842{ 1880{
1881 struct nfs_net *nn = net_generic(m->private, nfs_net_id);
1882
1843 /* lock the list against modification */ 1883 /* lock the list against modification */
1844 spin_lock(&nfs_client_lock); 1884 spin_lock(&nn->nfs_client_lock);
1845 return seq_list_start_head(&nfs_client_list, *_pos); 1885 return seq_list_start_head(&nn->nfs_client_list, *_pos);
1846} 1886}
1847 1887
1848/* 1888/*
@@ -1850,7 +1890,9 @@ static void *nfs_server_list_start(struct seq_file *m, loff_t *_pos)
1850 */ 1890 */
1851static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos) 1891static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos)
1852{ 1892{
1853 return seq_list_next(v, &nfs_client_list, pos); 1893 struct nfs_net *nn = net_generic(p->private, nfs_net_id);
1894
1895 return seq_list_next(v, &nn->nfs_client_list, pos);
1854} 1896}
1855 1897
1856/* 1898/*
@@ -1858,7 +1900,9 @@ static void *nfs_server_list_next(struct seq_file *p, void *v, loff_t *pos)
1858 */ 1900 */
1859static void nfs_server_list_stop(struct seq_file *p, void *v) 1901static void nfs_server_list_stop(struct seq_file *p, void *v)
1860{ 1902{
1861 spin_unlock(&nfs_client_lock); 1903 struct nfs_net *nn = net_generic(p->private, nfs_net_id);
1904
1905 spin_unlock(&nn->nfs_client_lock);
1862} 1906}
1863 1907
1864/* 1908/*
@@ -1867,9 +1911,10 @@ static void nfs_server_list_stop(struct seq_file *p, void *v)
1867static int nfs_server_list_show(struct seq_file *m, void *v) 1911static int nfs_server_list_show(struct seq_file *m, void *v)
1868{ 1912{
1869 struct nfs_client *clp; 1913 struct nfs_client *clp;
1914 struct nfs_net *nn = net_generic(m->private, nfs_net_id);
1870 1915
1871 /* display header on line 1 */ 1916 /* display header on line 1 */
1872 if (v == &nfs_client_list) { 1917 if (v == &nn->nfs_client_list) {
1873 seq_puts(m, "NV SERVER PORT USE HOSTNAME\n"); 1918 seq_puts(m, "NV SERVER PORT USE HOSTNAME\n");
1874 return 0; 1919 return 0;
1875 } 1920 }
@@ -1881,12 +1926,14 @@ static int nfs_server_list_show(struct seq_file *m, void *v)
1881 if (clp->cl_cons_state != NFS_CS_READY) 1926 if (clp->cl_cons_state != NFS_CS_READY)
1882 return 0; 1927 return 0;
1883 1928
1929 rcu_read_lock();
1884 seq_printf(m, "v%u %s %s %3d %s\n", 1930 seq_printf(m, "v%u %s %s %3d %s\n",
1885 clp->rpc_ops->version, 1931 clp->rpc_ops->version,
1886 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), 1932 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
1887 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT), 1933 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
1888 atomic_read(&clp->cl_count), 1934 atomic_read(&clp->cl_count),
1889 clp->cl_hostname); 1935 clp->cl_hostname);
1936 rcu_read_unlock();
1890 1937
1891 return 0; 1938 return 0;
1892} 1939}
@@ -1898,13 +1945,15 @@ static int nfs_volume_list_open(struct inode *inode, struct file *file)
1898{ 1945{
1899 struct seq_file *m; 1946 struct seq_file *m;
1900 int ret; 1947 int ret;
1948 struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info;
1949 struct net *net = pid_ns->child_reaper->nsproxy->net_ns;
1901 1950
1902 ret = seq_open(file, &nfs_volume_list_ops); 1951 ret = seq_open(file, &nfs_volume_list_ops);
1903 if (ret < 0) 1952 if (ret < 0)
1904 return ret; 1953 return ret;
1905 1954
1906 m = file->private_data; 1955 m = file->private_data;
1907 m->private = PDE(inode)->data; 1956 m->private = net;
1908 1957
1909 return 0; 1958 return 0;
1910} 1959}
@@ -1914,9 +1963,11 @@ static int nfs_volume_list_open(struct inode *inode, struct file *file)
1914 */ 1963 */
1915static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos) 1964static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos)
1916{ 1965{
1966 struct nfs_net *nn = net_generic(m->private, nfs_net_id);
1967
1917 /* lock the list against modification */ 1968 /* lock the list against modification */
1918 spin_lock(&nfs_client_lock); 1969 spin_lock(&nn->nfs_client_lock);
1919 return seq_list_start_head(&nfs_volume_list, *_pos); 1970 return seq_list_start_head(&nn->nfs_volume_list, *_pos);
1920} 1971}
1921 1972
1922/* 1973/*
@@ -1924,7 +1975,9 @@ static void *nfs_volume_list_start(struct seq_file *m, loff_t *_pos)
1924 */ 1975 */
1925static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos) 1976static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos)
1926{ 1977{
1927 return seq_list_next(v, &nfs_volume_list, pos); 1978 struct nfs_net *nn = net_generic(p->private, nfs_net_id);
1979
1980 return seq_list_next(v, &nn->nfs_volume_list, pos);
1928} 1981}
1929 1982
1930/* 1983/*
@@ -1932,7 +1985,9 @@ static void *nfs_volume_list_next(struct seq_file *p, void *v, loff_t *pos)
1932 */ 1985 */
1933static void nfs_volume_list_stop(struct seq_file *p, void *v) 1986static void nfs_volume_list_stop(struct seq_file *p, void *v)
1934{ 1987{
1935 spin_unlock(&nfs_client_lock); 1988 struct nfs_net *nn = net_generic(p->private, nfs_net_id);
1989
1990 spin_unlock(&nn->nfs_client_lock);
1936} 1991}
1937 1992
1938/* 1993/*
@@ -1943,9 +1998,10 @@ static int nfs_volume_list_show(struct seq_file *m, void *v)
1943 struct nfs_server *server; 1998 struct nfs_server *server;
1944 struct nfs_client *clp; 1999 struct nfs_client *clp;
1945 char dev[8], fsid[17]; 2000 char dev[8], fsid[17];
2001 struct nfs_net *nn = net_generic(m->private, nfs_net_id);
1946 2002
1947 /* display header on line 1 */ 2003 /* display header on line 1 */
1948 if (v == &nfs_volume_list) { 2004 if (v == &nn->nfs_volume_list) {
1949 seq_puts(m, "NV SERVER PORT DEV FSID FSC\n"); 2005 seq_puts(m, "NV SERVER PORT DEV FSID FSC\n");
1950 return 0; 2006 return 0;
1951 } 2007 }
@@ -1960,6 +2016,7 @@ static int nfs_volume_list_show(struct seq_file *m, void *v)
1960 (unsigned long long) server->fsid.major, 2016 (unsigned long long) server->fsid.major,
1961 (unsigned long long) server->fsid.minor); 2017 (unsigned long long) server->fsid.minor);
1962 2018
2019 rcu_read_lock();
1963 seq_printf(m, "v%u %s %s %-7s %-17s %s\n", 2020 seq_printf(m, "v%u %s %s %-7s %-17s %s\n",
1964 clp->rpc_ops->version, 2021 clp->rpc_ops->version,
1965 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), 2022 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR),
@@ -1967,6 +2024,7 @@ static int nfs_volume_list_show(struct seq_file *m, void *v)
1967 dev, 2024 dev,
1968 fsid, 2025 fsid,
1969 nfs_server_fscache_state(server)); 2026 nfs_server_fscache_state(server));
2027 rcu_read_unlock();
1970 2028
1971 return 0; 2029 return 0;
1972} 2030}
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 7f265406980..89af1d26927 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -105,7 +105,7 @@ again:
105 continue; 105 continue;
106 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) 106 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
107 continue; 107 continue;
108 if (memcmp(state->stateid.data, stateid->data, sizeof(state->stateid.data)) != 0) 108 if (!nfs4_stateid_match(&state->stateid, stateid))
109 continue; 109 continue;
110 get_nfs_open_context(ctx); 110 get_nfs_open_context(ctx);
111 spin_unlock(&inode->i_lock); 111 spin_unlock(&inode->i_lock);
@@ -139,8 +139,7 @@ void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
139 if (delegation != NULL) { 139 if (delegation != NULL) {
140 spin_lock(&delegation->lock); 140 spin_lock(&delegation->lock);
141 if (delegation->inode != NULL) { 141 if (delegation->inode != NULL) {
142 memcpy(delegation->stateid.data, res->delegation.data, 142 nfs4_stateid_copy(&delegation->stateid, &res->delegation);
143 sizeof(delegation->stateid.data));
144 delegation->type = res->delegation_type; 143 delegation->type = res->delegation_type;
145 delegation->maxsize = res->maxsize; 144 delegation->maxsize = res->maxsize;
146 oldcred = delegation->cred; 145 oldcred = delegation->cred;
@@ -236,8 +235,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
236 delegation = kmalloc(sizeof(*delegation), GFP_NOFS); 235 delegation = kmalloc(sizeof(*delegation), GFP_NOFS);
237 if (delegation == NULL) 236 if (delegation == NULL)
238 return -ENOMEM; 237 return -ENOMEM;
239 memcpy(delegation->stateid.data, res->delegation.data, 238 nfs4_stateid_copy(&delegation->stateid, &res->delegation);
240 sizeof(delegation->stateid.data));
241 delegation->type = res->delegation_type; 239 delegation->type = res->delegation_type;
242 delegation->maxsize = res->maxsize; 240 delegation->maxsize = res->maxsize;
243 delegation->change_attr = inode->i_version; 241 delegation->change_attr = inode->i_version;
@@ -250,19 +248,22 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
250 old_delegation = rcu_dereference_protected(nfsi->delegation, 248 old_delegation = rcu_dereference_protected(nfsi->delegation,
251 lockdep_is_held(&clp->cl_lock)); 249 lockdep_is_held(&clp->cl_lock));
252 if (old_delegation != NULL) { 250 if (old_delegation != NULL) {
253 if (memcmp(&delegation->stateid, &old_delegation->stateid, 251 if (nfs4_stateid_match(&delegation->stateid,
254 sizeof(old_delegation->stateid)) == 0 && 252 &old_delegation->stateid) &&
255 delegation->type == old_delegation->type) { 253 delegation->type == old_delegation->type) {
256 goto out; 254 goto out;
257 } 255 }
258 /* 256 /*
259 * Deal with broken servers that hand out two 257 * Deal with broken servers that hand out two
260 * delegations for the same file. 258 * delegations for the same file.
259 * Allow for upgrades to a WRITE delegation, but
260 * nothing else.
261 */ 261 */
262 dfprintk(FILE, "%s: server %s handed out " 262 dfprintk(FILE, "%s: server %s handed out "
263 "a duplicate delegation!\n", 263 "a duplicate delegation!\n",
264 __func__, clp->cl_hostname); 264 __func__, clp->cl_hostname);
265 if (delegation->type <= old_delegation->type) { 265 if (delegation->type == old_delegation->type ||
266 !(delegation->type & FMODE_WRITE)) {
266 freeme = delegation; 267 freeme = delegation;
267 delegation = NULL; 268 delegation = NULL;
268 goto out; 269 goto out;
@@ -455,17 +456,24 @@ static void nfs_client_mark_return_all_delegation_types(struct nfs_client *clp,
455 rcu_read_unlock(); 456 rcu_read_unlock();
456} 457}
457 458
458static void nfs_client_mark_return_all_delegations(struct nfs_client *clp)
459{
460 nfs_client_mark_return_all_delegation_types(clp, FMODE_READ|FMODE_WRITE);
461}
462
463static void nfs_delegation_run_state_manager(struct nfs_client *clp) 459static void nfs_delegation_run_state_manager(struct nfs_client *clp)
464{ 460{
465 if (test_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state)) 461 if (test_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state))
466 nfs4_schedule_state_manager(clp); 462 nfs4_schedule_state_manager(clp);
467} 463}
468 464
465void nfs_remove_bad_delegation(struct inode *inode)
466{
467 struct nfs_delegation *delegation;
468
469 delegation = nfs_detach_delegation(NFS_I(inode), NFS_SERVER(inode));
470 if (delegation) {
471 nfs_inode_find_state_and_recover(inode, &delegation->stateid);
472 nfs_free_delegation(delegation);
473 }
474}
475EXPORT_SYMBOL_GPL(nfs_remove_bad_delegation);
476
469/** 477/**
470 * nfs_expire_all_delegation_types 478 * nfs_expire_all_delegation_types
471 * @clp: client to process 479 * @clp: client to process
@@ -488,18 +496,6 @@ void nfs_expire_all_delegations(struct nfs_client *clp)
488 nfs_expire_all_delegation_types(clp, FMODE_READ|FMODE_WRITE); 496 nfs_expire_all_delegation_types(clp, FMODE_READ|FMODE_WRITE);
489} 497}
490 498
491/**
492 * nfs_handle_cb_pathdown - return all delegations after NFS4ERR_CB_PATH_DOWN
493 * @clp: client to process
494 *
495 */
496void nfs_handle_cb_pathdown(struct nfs_client *clp)
497{
498 if (clp == NULL)
499 return;
500 nfs_client_mark_return_all_delegations(clp);
501}
502
503static void nfs_mark_return_unreferenced_delegations(struct nfs_server *server) 499static void nfs_mark_return_unreferenced_delegations(struct nfs_server *server)
504{ 500{
505 struct nfs_delegation *delegation; 501 struct nfs_delegation *delegation;
@@ -531,7 +527,7 @@ void nfs_expire_unreferenced_delegations(struct nfs_client *clp)
531/** 527/**
532 * nfs_async_inode_return_delegation - asynchronously return a delegation 528 * nfs_async_inode_return_delegation - asynchronously return a delegation
533 * @inode: inode to process 529 * @inode: inode to process
534 * @stateid: state ID information from CB_RECALL arguments 530 * @stateid: state ID information
535 * 531 *
536 * Returns zero on success, or a negative errno value. 532 * Returns zero on success, or a negative errno value.
537 */ 533 */
@@ -545,7 +541,7 @@ int nfs_async_inode_return_delegation(struct inode *inode,
545 rcu_read_lock(); 541 rcu_read_lock();
546 delegation = rcu_dereference(NFS_I(inode)->delegation); 542 delegation = rcu_dereference(NFS_I(inode)->delegation);
547 543
548 if (!clp->cl_mvops->validate_stateid(delegation, stateid)) { 544 if (!clp->cl_mvops->match_stateid(&delegation->stateid, stateid)) {
549 rcu_read_unlock(); 545 rcu_read_unlock();
550 return -ENOENT; 546 return -ENOENT;
551 } 547 }
@@ -684,21 +680,25 @@ int nfs_delegations_present(struct nfs_client *clp)
684 * nfs4_copy_delegation_stateid - Copy inode's state ID information 680 * nfs4_copy_delegation_stateid - Copy inode's state ID information
685 * @dst: stateid data structure to fill in 681 * @dst: stateid data structure to fill in
686 * @inode: inode to check 682 * @inode: inode to check
683 * @flags: delegation type requirement
687 * 684 *
688 * Returns one and fills in "dst->data" * if inode had a delegation, 685 * Returns "true" and fills in "dst->data" * if inode had a delegation,
689 * otherwise zero is returned. 686 * otherwise "false" is returned.
690 */ 687 */
691int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode) 688bool nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode,
689 fmode_t flags)
692{ 690{
693 struct nfs_inode *nfsi = NFS_I(inode); 691 struct nfs_inode *nfsi = NFS_I(inode);
694 struct nfs_delegation *delegation; 692 struct nfs_delegation *delegation;
695 int ret = 0; 693 bool ret;
696 694
695 flags &= FMODE_READ|FMODE_WRITE;
697 rcu_read_lock(); 696 rcu_read_lock();
698 delegation = rcu_dereference(nfsi->delegation); 697 delegation = rcu_dereference(nfsi->delegation);
699 if (delegation != NULL) { 698 ret = (delegation != NULL && (delegation->type & flags) == flags);
700 memcpy(dst->data, delegation->stateid.data, sizeof(dst->data)); 699 if (ret) {
701 ret = 1; 700 nfs4_stateid_copy(dst, &delegation->stateid);
701 nfs_mark_delegation_referenced(delegation);
702 } 702 }
703 rcu_read_unlock(); 703 rcu_read_unlock();
704 return ret; 704 return ret;
diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h
index d9322e490c5..cd6a7a8dada 100644
--- a/fs/nfs/delegation.h
+++ b/fs/nfs/delegation.h
@@ -42,9 +42,9 @@ void nfs_super_return_all_delegations(struct super_block *sb);
42void nfs_expire_all_delegations(struct nfs_client *clp); 42void nfs_expire_all_delegations(struct nfs_client *clp);
43void nfs_expire_all_delegation_types(struct nfs_client *clp, fmode_t flags); 43void nfs_expire_all_delegation_types(struct nfs_client *clp, fmode_t flags);
44void nfs_expire_unreferenced_delegations(struct nfs_client *clp); 44void nfs_expire_unreferenced_delegations(struct nfs_client *clp);
45void nfs_handle_cb_pathdown(struct nfs_client *clp);
46int nfs_client_return_marked_delegations(struct nfs_client *clp); 45int nfs_client_return_marked_delegations(struct nfs_client *clp);
47int nfs_delegations_present(struct nfs_client *clp); 46int nfs_delegations_present(struct nfs_client *clp);
47void nfs_remove_bad_delegation(struct inode *inode);
48 48
49void nfs_delegation_mark_reclaim(struct nfs_client *clp); 49void nfs_delegation_mark_reclaim(struct nfs_client *clp);
50void nfs_delegation_reap_unclaimed(struct nfs_client *clp); 50void nfs_delegation_reap_unclaimed(struct nfs_client *clp);
@@ -53,7 +53,7 @@ void nfs_delegation_reap_unclaimed(struct nfs_client *clp);
53int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync); 53int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync);
54int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid); 54int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid);
55int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl); 55int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl);
56int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode); 56bool nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode, fmode_t flags);
57 57
58void nfs_mark_delegation_referenced(struct nfs_delegation *delegation); 58void nfs_mark_delegation_referenced(struct nfs_delegation *delegation);
59int nfs_have_delegation(struct inode *inode, fmode_t flags); 59int nfs_have_delegation(struct inode *inode, fmode_t flags);
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 32aa6917265..4aaf0316d76 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -207,7 +207,7 @@ struct nfs_cache_array_entry {
207}; 207};
208 208
209struct nfs_cache_array { 209struct nfs_cache_array {
210 unsigned int size; 210 int size;
211 int eof_index; 211 int eof_index;
212 u64 last_cookie; 212 u64 last_cookie;
213 struct nfs_cache_array_entry array[0]; 213 struct nfs_cache_array_entry array[0];
@@ -1429,6 +1429,7 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
1429 } 1429 }
1430 1430
1431 open_flags = nd->intent.open.flags; 1431 open_flags = nd->intent.open.flags;
1432 attr.ia_valid = 0;
1432 1433
1433 ctx = create_nfs_open_context(dentry, open_flags); 1434 ctx = create_nfs_open_context(dentry, open_flags);
1434 res = ERR_CAST(ctx); 1435 res = ERR_CAST(ctx);
@@ -1437,11 +1438,14 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry
1437 1438
1438 if (nd->flags & LOOKUP_CREATE) { 1439 if (nd->flags & LOOKUP_CREATE) {
1439 attr.ia_mode = nd->intent.open.create_mode; 1440 attr.ia_mode = nd->intent.open.create_mode;
1440 attr.ia_valid = ATTR_MODE; 1441 attr.ia_valid |= ATTR_MODE;
1441 attr.ia_mode &= ~current_umask(); 1442 attr.ia_mode &= ~current_umask();
1442 } else { 1443 } else
1443 open_flags &= ~(O_EXCL | O_CREAT); 1444 open_flags &= ~(O_EXCL | O_CREAT);
1444 attr.ia_valid = 0; 1445
1446 if (open_flags & O_TRUNC) {
1447 attr.ia_valid |= ATTR_SIZE;
1448 attr.ia_size = 0;
1445 } 1449 }
1446 1450
1447 /* Open the file on the server */ 1451 /* Open the file on the server */
@@ -1495,6 +1499,7 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
1495 struct inode *inode; 1499 struct inode *inode;
1496 struct inode *dir; 1500 struct inode *dir;
1497 struct nfs_open_context *ctx; 1501 struct nfs_open_context *ctx;
1502 struct iattr attr;
1498 int openflags, ret = 0; 1503 int openflags, ret = 0;
1499 1504
1500 if (nd->flags & LOOKUP_RCU) 1505 if (nd->flags & LOOKUP_RCU)
@@ -1523,19 +1528,27 @@ static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd)
1523 /* We cannot do exclusive creation on a positive dentry */ 1528 /* We cannot do exclusive creation on a positive dentry */
1524 if ((openflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) 1529 if ((openflags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL))
1525 goto no_open_dput; 1530 goto no_open_dput;
1526 /* We can't create new files, or truncate existing ones here */ 1531 /* We can't create new files here */
1527 openflags &= ~(O_CREAT|O_EXCL|O_TRUNC); 1532 openflags &= ~(O_CREAT|O_EXCL);
1528 1533
1529 ctx = create_nfs_open_context(dentry, openflags); 1534 ctx = create_nfs_open_context(dentry, openflags);
1530 ret = PTR_ERR(ctx); 1535 ret = PTR_ERR(ctx);
1531 if (IS_ERR(ctx)) 1536 if (IS_ERR(ctx))
1532 goto out; 1537 goto out;
1538
1539 attr.ia_valid = 0;
1540 if (openflags & O_TRUNC) {
1541 attr.ia_valid |= ATTR_SIZE;
1542 attr.ia_size = 0;
1543 nfs_wb_all(inode);
1544 }
1545
1533 /* 1546 /*
1534 * Note: we're not holding inode->i_mutex and so may be racing with 1547 * Note: we're not holding inode->i_mutex and so may be racing with
1535 * operations that change the directory. We therefore save the 1548 * operations that change the directory. We therefore save the
1536 * change attribute *before* we do the RPC call. 1549 * change attribute *before* we do the RPC call.
1537 */ 1550 */
1538 inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, NULL); 1551 inode = NFS_PROTO(dir)->open_context(dir, ctx, openflags, &attr);
1539 if (IS_ERR(inode)) { 1552 if (IS_ERR(inode)) {
1540 ret = PTR_ERR(inode); 1553 ret = PTR_ERR(inode);
1541 switch (ret) { 1554 switch (ret) {
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 1940f1a56a5..9c7f66ac6cc 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -265,9 +265,7 @@ static void nfs_direct_read_release(void *calldata)
265} 265}
266 266
267static const struct rpc_call_ops nfs_read_direct_ops = { 267static const struct rpc_call_ops nfs_read_direct_ops = {
268#if defined(CONFIG_NFS_V4_1)
269 .rpc_call_prepare = nfs_read_prepare, 268 .rpc_call_prepare = nfs_read_prepare,
270#endif /* CONFIG_NFS_V4_1 */
271 .rpc_call_done = nfs_direct_read_result, 269 .rpc_call_done = nfs_direct_read_result,
272 .rpc_release = nfs_direct_read_release, 270 .rpc_release = nfs_direct_read_release,
273}; 271};
@@ -554,9 +552,7 @@ static void nfs_direct_commit_release(void *calldata)
554} 552}
555 553
556static const struct rpc_call_ops nfs_commit_direct_ops = { 554static const struct rpc_call_ops nfs_commit_direct_ops = {
557#if defined(CONFIG_NFS_V4_1)
558 .rpc_call_prepare = nfs_write_prepare, 555 .rpc_call_prepare = nfs_write_prepare,
559#endif /* CONFIG_NFS_V4_1 */
560 .rpc_call_done = nfs_direct_commit_result, 556 .rpc_call_done = nfs_direct_commit_result,
561 .rpc_release = nfs_direct_commit_release, 557 .rpc_release = nfs_direct_commit_release,
562}; 558};
@@ -696,9 +692,7 @@ out_unlock:
696} 692}
697 693
698static const struct rpc_call_ops nfs_write_direct_ops = { 694static const struct rpc_call_ops nfs_write_direct_ops = {
699#if defined(CONFIG_NFS_V4_1)
700 .rpc_call_prepare = nfs_write_prepare, 695 .rpc_call_prepare = nfs_write_prepare,
701#endif /* CONFIG_NFS_V4_1 */
702 .rpc_call_done = nfs_direct_write_result, 696 .rpc_call_done = nfs_direct_write_result,
703 .rpc_release = nfs_direct_write_release, 697 .rpc_release = nfs_direct_write_release,
704}; 698};
diff --git a/fs/nfs/dns_resolve.c b/fs/nfs/dns_resolve.c
index a6e711ad130..b3924b8a600 100644
--- a/fs/nfs/dns_resolve.c
+++ b/fs/nfs/dns_resolve.c
@@ -10,8 +10,9 @@
10 10
11#include <linux/sunrpc/clnt.h> 11#include <linux/sunrpc/clnt.h>
12#include <linux/dns_resolver.h> 12#include <linux/dns_resolver.h>
13#include "dns_resolve.h"
13 14
14ssize_t nfs_dns_resolve_name(char *name, size_t namelen, 15ssize_t nfs_dns_resolve_name(struct net *net, char *name, size_t namelen,
15 struct sockaddr *sa, size_t salen) 16 struct sockaddr *sa, size_t salen)
16{ 17{
17 ssize_t ret; 18 ssize_t ret;
@@ -20,7 +21,7 @@ ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
20 21
21 ip_len = dns_query(NULL, name, namelen, NULL, &ip_addr, NULL); 22 ip_len = dns_query(NULL, name, namelen, NULL, &ip_addr, NULL);
22 if (ip_len > 0) 23 if (ip_len > 0)
23 ret = rpc_pton(ip_addr, ip_len, sa, salen); 24 ret = rpc_pton(net, ip_addr, ip_len, sa, salen);
24 else 25 else
25 ret = -ESRCH; 26 ret = -ESRCH;
26 kfree(ip_addr); 27 kfree(ip_addr);
@@ -40,15 +41,15 @@ ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
40#include <linux/sunrpc/clnt.h> 41#include <linux/sunrpc/clnt.h>
41#include <linux/sunrpc/cache.h> 42#include <linux/sunrpc/cache.h>
42#include <linux/sunrpc/svcauth.h> 43#include <linux/sunrpc/svcauth.h>
44#include <linux/sunrpc/rpc_pipe_fs.h>
43 45
44#include "dns_resolve.h" 46#include "dns_resolve.h"
45#include "cache_lib.h" 47#include "cache_lib.h"
48#include "netns.h"
46 49
47#define NFS_DNS_HASHBITS 4 50#define NFS_DNS_HASHBITS 4
48#define NFS_DNS_HASHTBL_SIZE (1 << NFS_DNS_HASHBITS) 51#define NFS_DNS_HASHTBL_SIZE (1 << NFS_DNS_HASHBITS)
49 52
50static struct cache_head *nfs_dns_table[NFS_DNS_HASHTBL_SIZE];
51
52struct nfs_dns_ent { 53struct nfs_dns_ent {
53 struct cache_head h; 54 struct cache_head h;
54 55
@@ -224,7 +225,7 @@ static int nfs_dns_parse(struct cache_detail *cd, char *buf, int buflen)
224 len = qword_get(&buf, buf1, sizeof(buf1)); 225 len = qword_get(&buf, buf1, sizeof(buf1));
225 if (len <= 0) 226 if (len <= 0)
226 goto out; 227 goto out;
227 key.addrlen = rpc_pton(buf1, len, 228 key.addrlen = rpc_pton(cd->net, buf1, len,
228 (struct sockaddr *)&key.addr, 229 (struct sockaddr *)&key.addr,
229 sizeof(key.addr)); 230 sizeof(key.addr));
230 231
@@ -259,21 +260,6 @@ out:
259 return ret; 260 return ret;
260} 261}
261 262
262static struct cache_detail nfs_dns_resolve = {
263 .owner = THIS_MODULE,
264 .hash_size = NFS_DNS_HASHTBL_SIZE,
265 .hash_table = nfs_dns_table,
266 .name = "dns_resolve",
267 .cache_put = nfs_dns_ent_put,
268 .cache_upcall = nfs_dns_upcall,
269 .cache_parse = nfs_dns_parse,
270 .cache_show = nfs_dns_show,
271 .match = nfs_dns_match,
272 .init = nfs_dns_ent_init,
273 .update = nfs_dns_ent_update,
274 .alloc = nfs_dns_ent_alloc,
275};
276
277static int do_cache_lookup(struct cache_detail *cd, 263static int do_cache_lookup(struct cache_detail *cd,
278 struct nfs_dns_ent *key, 264 struct nfs_dns_ent *key,
279 struct nfs_dns_ent **item, 265 struct nfs_dns_ent **item,
@@ -336,8 +322,8 @@ out:
336 return ret; 322 return ret;
337} 323}
338 324
339ssize_t nfs_dns_resolve_name(char *name, size_t namelen, 325ssize_t nfs_dns_resolve_name(struct net *net, char *name,
340 struct sockaddr *sa, size_t salen) 326 size_t namelen, struct sockaddr *sa, size_t salen)
341{ 327{
342 struct nfs_dns_ent key = { 328 struct nfs_dns_ent key = {
343 .hostname = name, 329 .hostname = name,
@@ -345,28 +331,118 @@ ssize_t nfs_dns_resolve_name(char *name, size_t namelen,
345 }; 331 };
346 struct nfs_dns_ent *item = NULL; 332 struct nfs_dns_ent *item = NULL;
347 ssize_t ret; 333 ssize_t ret;
334 struct nfs_net *nn = net_generic(net, nfs_net_id);
348 335
349 ret = do_cache_lookup_wait(&nfs_dns_resolve, &key, &item); 336 ret = do_cache_lookup_wait(nn->nfs_dns_resolve, &key, &item);
350 if (ret == 0) { 337 if (ret == 0) {
351 if (salen >= item->addrlen) { 338 if (salen >= item->addrlen) {
352 memcpy(sa, &item->addr, item->addrlen); 339 memcpy(sa, &item->addr, item->addrlen);
353 ret = item->addrlen; 340 ret = item->addrlen;
354 } else 341 } else
355 ret = -EOVERFLOW; 342 ret = -EOVERFLOW;
356 cache_put(&item->h, &nfs_dns_resolve); 343 cache_put(&item->h, nn->nfs_dns_resolve);
357 } else if (ret == -ENOENT) 344 } else if (ret == -ENOENT)
358 ret = -ESRCH; 345 ret = -ESRCH;
359 return ret; 346 return ret;
360} 347}
361 348
349int nfs_dns_resolver_cache_init(struct net *net)
350{
351 int err = -ENOMEM;
352 struct nfs_net *nn = net_generic(net, nfs_net_id);
353 struct cache_detail *cd;
354 struct cache_head **tbl;
355
356 cd = kzalloc(sizeof(struct cache_detail), GFP_KERNEL);
357 if (cd == NULL)
358 goto err_cd;
359
360 tbl = kzalloc(NFS_DNS_HASHTBL_SIZE * sizeof(struct cache_head *),
361 GFP_KERNEL);
362 if (tbl == NULL)
363 goto err_tbl;
364
365 cd->owner = THIS_MODULE,
366 cd->hash_size = NFS_DNS_HASHTBL_SIZE,
367 cd->hash_table = tbl,
368 cd->name = "dns_resolve",
369 cd->cache_put = nfs_dns_ent_put,
370 cd->cache_upcall = nfs_dns_upcall,
371 cd->cache_parse = nfs_dns_parse,
372 cd->cache_show = nfs_dns_show,
373 cd->match = nfs_dns_match,
374 cd->init = nfs_dns_ent_init,
375 cd->update = nfs_dns_ent_update,
376 cd->alloc = nfs_dns_ent_alloc,
377
378 nfs_cache_init(cd);
379 err = nfs_cache_register_net(net, cd);
380 if (err)
381 goto err_reg;
382 nn->nfs_dns_resolve = cd;
383 return 0;
384
385err_reg:
386 nfs_cache_destroy(cd);
387 kfree(cd->hash_table);
388err_tbl:
389 kfree(cd);
390err_cd:
391 return err;
392}
393
394void nfs_dns_resolver_cache_destroy(struct net *net)
395{
396 struct nfs_net *nn = net_generic(net, nfs_net_id);
397 struct cache_detail *cd = nn->nfs_dns_resolve;
398
399 nfs_cache_unregister_net(net, cd);
400 nfs_cache_destroy(cd);
401 kfree(cd->hash_table);
402 kfree(cd);
403}
404
405static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
406 void *ptr)
407{
408 struct super_block *sb = ptr;
409 struct net *net = sb->s_fs_info;
410 struct nfs_net *nn = net_generic(net, nfs_net_id);
411 struct cache_detail *cd = nn->nfs_dns_resolve;
412 int ret = 0;
413
414 if (cd == NULL)
415 return 0;
416
417 if (!try_module_get(THIS_MODULE))
418 return 0;
419
420 switch (event) {
421 case RPC_PIPEFS_MOUNT:
422 ret = nfs_cache_register_sb(sb, cd);
423 break;
424 case RPC_PIPEFS_UMOUNT:
425 nfs_cache_unregister_sb(sb, cd);
426 break;
427 default:
428 ret = -ENOTSUPP;
429 break;
430 }
431 module_put(THIS_MODULE);
432 return ret;
433}
434
435static struct notifier_block nfs_dns_resolver_block = {
436 .notifier_call = rpc_pipefs_event,
437};
438
362int nfs_dns_resolver_init(void) 439int nfs_dns_resolver_init(void)
363{ 440{
364 return nfs_cache_register(&nfs_dns_resolve); 441 return rpc_pipefs_notifier_register(&nfs_dns_resolver_block);
365} 442}
366 443
367void nfs_dns_resolver_destroy(void) 444void nfs_dns_resolver_destroy(void)
368{ 445{
369 nfs_cache_unregister(&nfs_dns_resolve); 446 rpc_pipefs_notifier_unregister(&nfs_dns_resolver_block);
370} 447}
371
372#endif 448#endif
diff --git a/fs/nfs/dns_resolve.h b/fs/nfs/dns_resolve.h
index 199bb5543a9..2e4f596d292 100644
--- a/fs/nfs/dns_resolve.h
+++ b/fs/nfs/dns_resolve.h
@@ -15,12 +15,22 @@ static inline int nfs_dns_resolver_init(void)
15 15
16static inline void nfs_dns_resolver_destroy(void) 16static inline void nfs_dns_resolver_destroy(void)
17{} 17{}
18
19static inline int nfs_dns_resolver_cache_init(struct net *net)
20{
21 return 0;
22}
23
24static inline void nfs_dns_resolver_cache_destroy(struct net *net)
25{}
18#else 26#else
19extern int nfs_dns_resolver_init(void); 27extern int nfs_dns_resolver_init(void);
20extern void nfs_dns_resolver_destroy(void); 28extern void nfs_dns_resolver_destroy(void);
29extern int nfs_dns_resolver_cache_init(struct net *net);
30extern void nfs_dns_resolver_cache_destroy(struct net *net);
21#endif 31#endif
22 32
23extern ssize_t nfs_dns_resolve_name(char *name, size_t namelen, 33extern ssize_t nfs_dns_resolve_name(struct net *net, char *name,
24 struct sockaddr *sa, size_t salen); 34 size_t namelen, struct sockaddr *sa, size_t salen);
25 35
26#endif 36#endif
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index c43a452f7da..4fdaaa63cf1 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -530,6 +530,8 @@ static int nfs_vm_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
530 if (mapping != dentry->d_inode->i_mapping) 530 if (mapping != dentry->d_inode->i_mapping)
531 goto out_unlock; 531 goto out_unlock;
532 532
533 wait_on_page_writeback(page);
534
533 pagelen = nfs_page_length(page); 535 pagelen = nfs_page_length(page);
534 if (pagelen == 0) 536 if (pagelen == 0)
535 goto out_unlock; 537 goto out_unlock;
diff --git a/fs/nfs/fscache.c b/fs/nfs/fscache.c
index 419119c371b..ae65c16b367 100644
--- a/fs/nfs/fscache.c
+++ b/fs/nfs/fscache.c
@@ -327,7 +327,7 @@ void nfs_fscache_reset_inode_cookie(struct inode *inode)
327{ 327{
328 struct nfs_inode *nfsi = NFS_I(inode); 328 struct nfs_inode *nfsi = NFS_I(inode);
329 struct nfs_server *nfss = NFS_SERVER(inode); 329 struct nfs_server *nfss = NFS_SERVER(inode);
330 struct fscache_cookie *old = nfsi->fscache; 330 NFS_IFDEBUG(struct fscache_cookie *old = nfsi->fscache);
331 331
332 nfs_fscache_inode_lock(inode); 332 nfs_fscache_inode_lock(inode);
333 if (nfsi->fscache) { 333 if (nfsi->fscache) {
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c
index a1bbf7780df..b7f348bb618 100644
--- a/fs/nfs/idmap.c
+++ b/fs/nfs/idmap.c
@@ -34,11 +34,29 @@
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */ 35 */
36#include <linux/types.h> 36#include <linux/types.h>
37#include <linux/string.h> 37#include <linux/parser.h>
38#include <linux/kernel.h> 38#include <linux/fs.h>
39#include <linux/slab.h>
40#include <linux/nfs_idmap.h> 39#include <linux/nfs_idmap.h>
40#include <net/net_namespace.h>
41#include <linux/sunrpc/rpc_pipe_fs.h>
41#include <linux/nfs_fs.h> 42#include <linux/nfs_fs.h>
43#include <linux/nfs_fs_sb.h>
44#include <linux/key.h>
45#include <linux/keyctl.h>
46#include <linux/key-type.h>
47#include <keys/user-type.h>
48#include <linux/module.h>
49
50#include "internal.h"
51#include "netns.h"
52
53#define NFS_UINT_MAXLEN 11
54
55/* Default cache timeout is 10 minutes */
56unsigned int nfs_idmap_cache_timeout = 600;
57static const struct cred *id_resolver_cache;
58static struct key_type key_type_id_resolver_legacy;
59
42 60
43/** 61/**
44 * nfs_fattr_init_names - initialise the nfs_fattr owner_name/group_name fields 62 * nfs_fattr_init_names - initialise the nfs_fattr owner_name/group_name fields
@@ -142,24 +160,7 @@ static int nfs_map_numeric_to_string(__u32 id, char *buf, size_t buflen)
142 return snprintf(buf, buflen, "%u", id); 160 return snprintf(buf, buflen, "%u", id);
143} 161}
144 162
145#ifdef CONFIG_NFS_USE_NEW_IDMAPPER 163static struct key_type key_type_id_resolver = {
146
147#include <linux/cred.h>
148#include <linux/sunrpc/sched.h>
149#include <linux/nfs4.h>
150#include <linux/nfs_fs_sb.h>
151#include <linux/keyctl.h>
152#include <linux/key-type.h>
153#include <linux/rcupdate.h>
154#include <linux/err.h>
155
156#include <keys/user-type.h>
157
158#define NFS_UINT_MAXLEN 11
159
160const struct cred *id_resolver_cache;
161
162struct key_type key_type_id_resolver = {
163 .name = "id_resolver", 164 .name = "id_resolver",
164 .instantiate = user_instantiate, 165 .instantiate = user_instantiate,
165 .match = user_match, 166 .match = user_match,
@@ -169,13 +170,14 @@ struct key_type key_type_id_resolver = {
169 .read = user_read, 170 .read = user_read,
170}; 171};
171 172
172int nfs_idmap_init(void) 173static int nfs_idmap_init_keyring(void)
173{ 174{
174 struct cred *cred; 175 struct cred *cred;
175 struct key *keyring; 176 struct key *keyring;
176 int ret = 0; 177 int ret = 0;
177 178
178 printk(KERN_NOTICE "Registering the %s key type\n", key_type_id_resolver.name); 179 printk(KERN_NOTICE "NFS: Registering the %s key type\n",
180 key_type_id_resolver.name);
179 181
180 cred = prepare_kernel_cred(NULL); 182 cred = prepare_kernel_cred(NULL);
181 if (!cred) 183 if (!cred)
@@ -211,7 +213,7 @@ failed_put_cred:
211 return ret; 213 return ret;
212} 214}
213 215
214void nfs_idmap_quit(void) 216static void nfs_idmap_quit_keyring(void)
215{ 217{
216 key_revoke(id_resolver_cache->thread_keyring); 218 key_revoke(id_resolver_cache->thread_keyring);
217 unregister_key_type(&key_type_id_resolver); 219 unregister_key_type(&key_type_id_resolver);
@@ -246,8 +248,10 @@ static ssize_t nfs_idmap_get_desc(const char *name, size_t namelen,
246 return desclen; 248 return desclen;
247} 249}
248 250
249static ssize_t nfs_idmap_request_key(const char *name, size_t namelen, 251static ssize_t nfs_idmap_request_key(struct key_type *key_type,
250 const char *type, void *data, size_t data_size) 252 const char *name, size_t namelen,
253 const char *type, void *data,
254 size_t data_size, struct idmap *idmap)
251{ 255{
252 const struct cred *saved_cred; 256 const struct cred *saved_cred;
253 struct key *rkey; 257 struct key *rkey;
@@ -260,8 +264,12 @@ static ssize_t nfs_idmap_request_key(const char *name, size_t namelen,
260 goto out; 264 goto out;
261 265
262 saved_cred = override_creds(id_resolver_cache); 266 saved_cred = override_creds(id_resolver_cache);
263 rkey = request_key(&key_type_id_resolver, desc, ""); 267 if (idmap)
268 rkey = request_key_with_auxdata(key_type, desc, "", 0, idmap);
269 else
270 rkey = request_key(&key_type_id_resolver, desc, "");
264 revert_creds(saved_cred); 271 revert_creds(saved_cred);
272
265 kfree(desc); 273 kfree(desc);
266 if (IS_ERR(rkey)) { 274 if (IS_ERR(rkey)) {
267 ret = PTR_ERR(rkey); 275 ret = PTR_ERR(rkey);
@@ -294,31 +302,46 @@ out:
294 return ret; 302 return ret;
295} 303}
296 304
305static ssize_t nfs_idmap_get_key(const char *name, size_t namelen,
306 const char *type, void *data,
307 size_t data_size, struct idmap *idmap)
308{
309 ssize_t ret = nfs_idmap_request_key(&key_type_id_resolver,
310 name, namelen, type, data,
311 data_size, NULL);
312 if (ret < 0) {
313 ret = nfs_idmap_request_key(&key_type_id_resolver_legacy,
314 name, namelen, type, data,
315 data_size, idmap);
316 }
317 return ret;
318}
297 319
298/* ID -> Name */ 320/* ID -> Name */
299static ssize_t nfs_idmap_lookup_name(__u32 id, const char *type, char *buf, size_t buflen) 321static ssize_t nfs_idmap_lookup_name(__u32 id, const char *type, char *buf,
322 size_t buflen, struct idmap *idmap)
300{ 323{
301 char id_str[NFS_UINT_MAXLEN]; 324 char id_str[NFS_UINT_MAXLEN];
302 int id_len; 325 int id_len;
303 ssize_t ret; 326 ssize_t ret;
304 327
305 id_len = snprintf(id_str, sizeof(id_str), "%u", id); 328 id_len = snprintf(id_str, sizeof(id_str), "%u", id);
306 ret = nfs_idmap_request_key(id_str, id_len, type, buf, buflen); 329 ret = nfs_idmap_get_key(id_str, id_len, type, buf, buflen, idmap);
307 if (ret < 0) 330 if (ret < 0)
308 return -EINVAL; 331 return -EINVAL;
309 return ret; 332 return ret;
310} 333}
311 334
312/* Name -> ID */ 335/* Name -> ID */
313static int nfs_idmap_lookup_id(const char *name, size_t namelen, 336static int nfs_idmap_lookup_id(const char *name, size_t namelen, const char *type,
314 const char *type, __u32 *id) 337 __u32 *id, struct idmap *idmap)
315{ 338{
316 char id_str[NFS_UINT_MAXLEN]; 339 char id_str[NFS_UINT_MAXLEN];
317 long id_long; 340 long id_long;
318 ssize_t data_size; 341 ssize_t data_size;
319 int ret = 0; 342 int ret = 0;
320 343
321 data_size = nfs_idmap_request_key(name, namelen, type, id_str, NFS_UINT_MAXLEN); 344 data_size = nfs_idmap_get_key(name, namelen, type, id_str, NFS_UINT_MAXLEN, idmap);
322 if (data_size <= 0) { 345 if (data_size <= 0) {
323 ret = -EINVAL; 346 ret = -EINVAL;
324 } else { 347 } else {
@@ -328,114 +351,103 @@ static int nfs_idmap_lookup_id(const char *name, size_t namelen,
328 return ret; 351 return ret;
329} 352}
330 353
331int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid) 354/* idmap classic begins here */
332{ 355module_param(nfs_idmap_cache_timeout, int, 0644);
333 if (nfs_map_string_to_numeric(name, namelen, uid))
334 return 0;
335 return nfs_idmap_lookup_id(name, namelen, "uid", uid);
336}
337
338int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *gid)
339{
340 if (nfs_map_string_to_numeric(name, namelen, gid))
341 return 0;
342 return nfs_idmap_lookup_id(name, namelen, "gid", gid);
343}
344
345int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen)
346{
347 int ret = -EINVAL;
348
349 if (!(server->caps & NFS_CAP_UIDGID_NOMAP))
350 ret = nfs_idmap_lookup_name(uid, "user", buf, buflen);
351 if (ret < 0)
352 ret = nfs_map_numeric_to_string(uid, buf, buflen);
353 return ret;
354}
355int nfs_map_gid_to_group(const struct nfs_server *server, __u32 gid, char *buf, size_t buflen)
356{
357 int ret = -EINVAL;
358 356
359 if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) 357struct idmap {
360 ret = nfs_idmap_lookup_name(gid, "group", buf, buflen); 358 struct rpc_pipe *idmap_pipe;
361 if (ret < 0) 359 struct key_construction *idmap_key_cons;
362 ret = nfs_map_numeric_to_string(gid, buf, buflen);
363 return ret;
364}
365
366#else /* CONFIG_NFS_USE_NEW_IDMAPPER not defined */
367
368#include <linux/module.h>
369#include <linux/mutex.h>
370#include <linux/init.h>
371#include <linux/socket.h>
372#include <linux/in.h>
373#include <linux/sched.h>
374#include <linux/sunrpc/clnt.h>
375#include <linux/workqueue.h>
376#include <linux/sunrpc/rpc_pipe_fs.h>
377
378#include <linux/nfs_fs.h>
379
380#include "nfs4_fs.h"
381
382#define IDMAP_HASH_SZ 128
383
384/* Default cache timeout is 10 minutes */
385unsigned int nfs_idmap_cache_timeout = 600 * HZ;
386
387static int param_set_idmap_timeout(const char *val, struct kernel_param *kp)
388{
389 char *endp;
390 int num = simple_strtol(val, &endp, 0);
391 int jif = num * HZ;
392 if (endp == val || *endp || num < 0 || jif < num)
393 return -EINVAL;
394 *((int *)kp->arg) = jif;
395 return 0;
396}
397
398module_param_call(idmap_cache_timeout, param_set_idmap_timeout, param_get_int,
399 &nfs_idmap_cache_timeout, 0644);
400
401struct idmap_hashent {
402 unsigned long ih_expires;
403 __u32 ih_id;
404 size_t ih_namelen;
405 char ih_name[IDMAP_NAMESZ];
406}; 360};
407 361
408struct idmap_hashtable { 362enum {
409 __u8 h_type; 363 Opt_find_uid, Opt_find_gid, Opt_find_user, Opt_find_group, Opt_find_err
410 struct idmap_hashent h_entries[IDMAP_HASH_SZ];
411}; 364};
412 365
413struct idmap { 366static const match_table_t nfs_idmap_tokens = {
414 struct dentry *idmap_dentry; 367 { Opt_find_uid, "uid:%s" },
415 wait_queue_head_t idmap_wq; 368 { Opt_find_gid, "gid:%s" },
416 struct idmap_msg idmap_im; 369 { Opt_find_user, "user:%s" },
417 struct mutex idmap_lock; /* Serializes upcalls */ 370 { Opt_find_group, "group:%s" },
418 struct mutex idmap_im_lock; /* Protects the hashtable */ 371 { Opt_find_err, NULL }
419 struct idmap_hashtable idmap_user_hash;
420 struct idmap_hashtable idmap_group_hash;
421}; 372};
422 373
374static int nfs_idmap_legacy_upcall(struct key_construction *, const char *, void *);
423static ssize_t idmap_pipe_downcall(struct file *, const char __user *, 375static ssize_t idmap_pipe_downcall(struct file *, const char __user *,
424 size_t); 376 size_t);
425static void idmap_pipe_destroy_msg(struct rpc_pipe_msg *); 377static void idmap_pipe_destroy_msg(struct rpc_pipe_msg *);
426 378
427static unsigned int fnvhash32(const void *, size_t);
428
429static const struct rpc_pipe_ops idmap_upcall_ops = { 379static const struct rpc_pipe_ops idmap_upcall_ops = {
430 .upcall = rpc_pipe_generic_upcall, 380 .upcall = rpc_pipe_generic_upcall,
431 .downcall = idmap_pipe_downcall, 381 .downcall = idmap_pipe_downcall,
432 .destroy_msg = idmap_pipe_destroy_msg, 382 .destroy_msg = idmap_pipe_destroy_msg,
433}; 383};
434 384
385static struct key_type key_type_id_resolver_legacy = {
386 .name = "id_resolver",
387 .instantiate = user_instantiate,
388 .match = user_match,
389 .revoke = user_revoke,
390 .destroy = user_destroy,
391 .describe = user_describe,
392 .read = user_read,
393 .request_key = nfs_idmap_legacy_upcall,
394};
395
396static void __nfs_idmap_unregister(struct rpc_pipe *pipe)
397{
398 if (pipe->dentry)
399 rpc_unlink(pipe->dentry);
400}
401
402static int __nfs_idmap_register(struct dentry *dir,
403 struct idmap *idmap,
404 struct rpc_pipe *pipe)
405{
406 struct dentry *dentry;
407
408 dentry = rpc_mkpipe_dentry(dir, "idmap", idmap, pipe);
409 if (IS_ERR(dentry))
410 return PTR_ERR(dentry);
411 pipe->dentry = dentry;
412 return 0;
413}
414
415static void nfs_idmap_unregister(struct nfs_client *clp,
416 struct rpc_pipe *pipe)
417{
418 struct net *net = clp->net;
419 struct super_block *pipefs_sb;
420
421 pipefs_sb = rpc_get_sb_net(net);
422 if (pipefs_sb) {
423 __nfs_idmap_unregister(pipe);
424 rpc_put_sb_net(net);
425 }
426}
427
428static int nfs_idmap_register(struct nfs_client *clp,
429 struct idmap *idmap,
430 struct rpc_pipe *pipe)
431{
432 struct net *net = clp->net;
433 struct super_block *pipefs_sb;
434 int err = 0;
435
436 pipefs_sb = rpc_get_sb_net(net);
437 if (pipefs_sb) {
438 if (clp->cl_rpcclient->cl_dentry)
439 err = __nfs_idmap_register(clp->cl_rpcclient->cl_dentry,
440 idmap, pipe);
441 rpc_put_sb_net(net);
442 }
443 return err;
444}
445
435int 446int
436nfs_idmap_new(struct nfs_client *clp) 447nfs_idmap_new(struct nfs_client *clp)
437{ 448{
438 struct idmap *idmap; 449 struct idmap *idmap;
450 struct rpc_pipe *pipe;
439 int error; 451 int error;
440 452
441 BUG_ON(clp->cl_idmap != NULL); 453 BUG_ON(clp->cl_idmap != NULL);
@@ -444,19 +456,19 @@ nfs_idmap_new(struct nfs_client *clp)
444 if (idmap == NULL) 456 if (idmap == NULL)
445 return -ENOMEM; 457 return -ENOMEM;
446 458
447 idmap->idmap_dentry = rpc_mkpipe(clp->cl_rpcclient->cl_path.dentry, 459 pipe = rpc_mkpipe_data(&idmap_upcall_ops, 0);
448 "idmap", idmap, &idmap_upcall_ops, 0); 460 if (IS_ERR(pipe)) {
449 if (IS_ERR(idmap->idmap_dentry)) { 461 error = PTR_ERR(pipe);
450 error = PTR_ERR(idmap->idmap_dentry);
451 kfree(idmap); 462 kfree(idmap);
452 return error; 463 return error;
453 } 464 }
454 465 error = nfs_idmap_register(clp, idmap, pipe);
455 mutex_init(&idmap->idmap_lock); 466 if (error) {
456 mutex_init(&idmap->idmap_im_lock); 467 rpc_destroy_pipe_data(pipe);
457 init_waitqueue_head(&idmap->idmap_wq); 468 kfree(idmap);
458 idmap->idmap_user_hash.h_type = IDMAP_TYPE_USER; 469 return error;
459 idmap->idmap_group_hash.h_type = IDMAP_TYPE_GROUP; 470 }
471 idmap->idmap_pipe = pipe;
460 472
461 clp->cl_idmap = idmap; 473 clp->cl_idmap = idmap;
462 return 0; 474 return 0;
@@ -469,211 +481,220 @@ nfs_idmap_delete(struct nfs_client *clp)
469 481
470 if (!idmap) 482 if (!idmap)
471 return; 483 return;
472 rpc_unlink(idmap->idmap_dentry); 484 nfs_idmap_unregister(clp, idmap->idmap_pipe);
485 rpc_destroy_pipe_data(idmap->idmap_pipe);
473 clp->cl_idmap = NULL; 486 clp->cl_idmap = NULL;
474 kfree(idmap); 487 kfree(idmap);
475} 488}
476 489
477/* 490static int __rpc_pipefs_event(struct nfs_client *clp, unsigned long event,
478 * Helper routines for manipulating the hashtable 491 struct super_block *sb)
479 */
480static inline struct idmap_hashent *
481idmap_name_hash(struct idmap_hashtable* h, const char *name, size_t len)
482{
483 return &h->h_entries[fnvhash32(name, len) % IDMAP_HASH_SZ];
484}
485
486static struct idmap_hashent *
487idmap_lookup_name(struct idmap_hashtable *h, const char *name, size_t len)
488{ 492{
489 struct idmap_hashent *he = idmap_name_hash(h, name, len); 493 int err = 0;
490 494
491 if (he->ih_namelen != len || memcmp(he->ih_name, name, len) != 0) 495 switch (event) {
492 return NULL; 496 case RPC_PIPEFS_MOUNT:
493 if (time_after(jiffies, he->ih_expires)) 497 BUG_ON(clp->cl_rpcclient->cl_dentry == NULL);
494 return NULL; 498 err = __nfs_idmap_register(clp->cl_rpcclient->cl_dentry,
495 return he; 499 clp->cl_idmap,
500 clp->cl_idmap->idmap_pipe);
501 break;
502 case RPC_PIPEFS_UMOUNT:
503 if (clp->cl_idmap->idmap_pipe) {
504 struct dentry *parent;
505
506 parent = clp->cl_idmap->idmap_pipe->dentry->d_parent;
507 __nfs_idmap_unregister(clp->cl_idmap->idmap_pipe);
508 /*
509 * Note: This is a dirty hack. SUNRPC hook has been
510 * called already but simple_rmdir() call for the
511 * directory returned with error because of idmap pipe
512 * inside. Thus now we have to remove this directory
513 * here.
514 */
515 if (rpc_rmdir(parent))
516 printk(KERN_ERR "NFS: %s: failed to remove "
517 "clnt dir!\n", __func__);
518 }
519 break;
520 default:
521 printk(KERN_ERR "NFS: %s: unknown event: %ld\n", __func__,
522 event);
523 return -ENOTSUPP;
524 }
525 return err;
526}
527
528static struct nfs_client *nfs_get_client_for_event(struct net *net, int event)
529{
530 struct nfs_net *nn = net_generic(net, nfs_net_id);
531 struct dentry *cl_dentry;
532 struct nfs_client *clp;
533
534 spin_lock(&nn->nfs_client_lock);
535 list_for_each_entry(clp, &nn->nfs_client_list, cl_share_link) {
536 if (clp->rpc_ops != &nfs_v4_clientops)
537 continue;
538 cl_dentry = clp->cl_idmap->idmap_pipe->dentry;
539 if (((event == RPC_PIPEFS_MOUNT) && cl_dentry) ||
540 ((event == RPC_PIPEFS_UMOUNT) && !cl_dentry))
541 continue;
542 atomic_inc(&clp->cl_count);
543 spin_unlock(&nn->nfs_client_lock);
544 return clp;
545 }
546 spin_unlock(&nn->nfs_client_lock);
547 return NULL;
496} 548}
497 549
498static inline struct idmap_hashent * 550static int rpc_pipefs_event(struct notifier_block *nb, unsigned long event,
499idmap_id_hash(struct idmap_hashtable* h, __u32 id) 551 void *ptr)
500{ 552{
501 return &h->h_entries[fnvhash32(&id, sizeof(id)) % IDMAP_HASH_SZ]; 553 struct super_block *sb = ptr;
502} 554 struct nfs_client *clp;
555 int error = 0;
503 556
504static struct idmap_hashent * 557 while ((clp = nfs_get_client_for_event(sb->s_fs_info, event))) {
505idmap_lookup_id(struct idmap_hashtable *h, __u32 id) 558 error = __rpc_pipefs_event(clp, event, sb);
506{ 559 nfs_put_client(clp);
507 struct idmap_hashent *he = idmap_id_hash(h, id); 560 if (error)
508 if (he->ih_id != id || he->ih_namelen == 0) 561 break;
509 return NULL; 562 }
510 if (time_after(jiffies, he->ih_expires)) 563 return error;
511 return NULL;
512 return he;
513} 564}
514 565
515/* 566#define PIPEFS_NFS_PRIO 1
516 * Routines for allocating new entries in the hashtable. 567
517 * For now, we just have 1 entry per bucket, so it's all 568static struct notifier_block nfs_idmap_block = {
518 * pretty trivial. 569 .notifier_call = rpc_pipefs_event,
519 */ 570 .priority = SUNRPC_PIPEFS_NFS_PRIO,
520static inline struct idmap_hashent * 571};
521idmap_alloc_name(struct idmap_hashtable *h, char *name, size_t len)
522{
523 return idmap_name_hash(h, name, len);
524}
525 572
526static inline struct idmap_hashent * 573int nfs_idmap_init(void)
527idmap_alloc_id(struct idmap_hashtable *h, __u32 id)
528{ 574{
529 return idmap_id_hash(h, id); 575 int ret;
576 ret = nfs_idmap_init_keyring();
577 if (ret != 0)
578 goto out;
579 ret = rpc_pipefs_notifier_register(&nfs_idmap_block);
580 if (ret != 0)
581 nfs_idmap_quit_keyring();
582out:
583 return ret;
530} 584}
531 585
532static void 586void nfs_idmap_quit(void)
533idmap_update_entry(struct idmap_hashent *he, const char *name,
534 size_t namelen, __u32 id)
535{ 587{
536 he->ih_id = id; 588 rpc_pipefs_notifier_unregister(&nfs_idmap_block);
537 memcpy(he->ih_name, name, namelen); 589 nfs_idmap_quit_keyring();
538 he->ih_name[namelen] = '\0';
539 he->ih_namelen = namelen;
540 he->ih_expires = jiffies + nfs_idmap_cache_timeout;
541} 590}
542 591
543/* 592static int nfs_idmap_prepare_message(char *desc, struct idmap_msg *im,
544 * Name -> ID 593 struct rpc_pipe_msg *msg)
545 */
546static int
547nfs_idmap_id(struct idmap *idmap, struct idmap_hashtable *h,
548 const char *name, size_t namelen, __u32 *id)
549{ 594{
550 struct rpc_pipe_msg msg; 595 substring_t substr;
551 struct idmap_msg *im; 596 int token, ret;
552 struct idmap_hashent *he;
553 DECLARE_WAITQUEUE(wq, current);
554 int ret = -EIO;
555
556 im = &idmap->idmap_im;
557
558 /*
559 * String sanity checks
560 * Note that the userland daemon expects NUL terminated strings
561 */
562 for (;;) {
563 if (namelen == 0)
564 return -EINVAL;
565 if (name[namelen-1] != '\0')
566 break;
567 namelen--;
568 }
569 if (namelen >= IDMAP_NAMESZ)
570 return -EINVAL;
571 597
572 mutex_lock(&idmap->idmap_lock); 598 memset(im, 0, sizeof(*im));
573 mutex_lock(&idmap->idmap_im_lock); 599 memset(msg, 0, sizeof(*msg));
574
575 he = idmap_lookup_name(h, name, namelen);
576 if (he != NULL) {
577 *id = he->ih_id;
578 ret = 0;
579 goto out;
580 }
581 600
582 memset(im, 0, sizeof(*im)); 601 im->im_type = IDMAP_TYPE_GROUP;
583 memcpy(im->im_name, name, namelen); 602 token = match_token(desc, nfs_idmap_tokens, &substr);
584 603
585 im->im_type = h->h_type; 604 switch (token) {
586 im->im_conv = IDMAP_CONV_NAMETOID; 605 case Opt_find_uid:
606 im->im_type = IDMAP_TYPE_USER;
607 case Opt_find_gid:
608 im->im_conv = IDMAP_CONV_NAMETOID;
609 ret = match_strlcpy(im->im_name, &substr, IDMAP_NAMESZ);
610 break;
587 611
588 memset(&msg, 0, sizeof(msg)); 612 case Opt_find_user:
589 msg.data = im; 613 im->im_type = IDMAP_TYPE_USER;
590 msg.len = sizeof(*im); 614 case Opt_find_group:
615 im->im_conv = IDMAP_CONV_IDTONAME;
616 ret = match_int(&substr, &im->im_id);
617 break;
591 618
592 add_wait_queue(&idmap->idmap_wq, &wq); 619 default:
593 if (rpc_queue_upcall(idmap->idmap_dentry->d_inode, &msg) < 0) { 620 ret = -EINVAL;
594 remove_wait_queue(&idmap->idmap_wq, &wq);
595 goto out; 621 goto out;
596 } 622 }
597 623
598 set_current_state(TASK_UNINTERRUPTIBLE); 624 msg->data = im;
599 mutex_unlock(&idmap->idmap_im_lock); 625 msg->len = sizeof(struct idmap_msg);
600 schedule();
601 __set_current_state(TASK_RUNNING);
602 remove_wait_queue(&idmap->idmap_wq, &wq);
603 mutex_lock(&idmap->idmap_im_lock);
604 626
605 if (im->im_status & IDMAP_STATUS_SUCCESS) { 627out:
606 *id = im->im_id;
607 ret = 0;
608 }
609
610 out:
611 memset(im, 0, sizeof(*im));
612 mutex_unlock(&idmap->idmap_im_lock);
613 mutex_unlock(&idmap->idmap_lock);
614 return ret; 628 return ret;
615} 629}
616 630
617/* 631static int nfs_idmap_legacy_upcall(struct key_construction *cons,
618 * ID -> Name 632 const char *op,
619 */ 633 void *aux)
620static int
621nfs_idmap_name(struct idmap *idmap, struct idmap_hashtable *h,
622 __u32 id, char *name)
623{ 634{
624 struct rpc_pipe_msg msg; 635 struct rpc_pipe_msg *msg;
625 struct idmap_msg *im; 636 struct idmap_msg *im;
626 struct idmap_hashent *he; 637 struct idmap *idmap = (struct idmap *)aux;
627 DECLARE_WAITQUEUE(wq, current); 638 struct key *key = cons->key;
628 int ret = -EIO; 639 int ret;
629 unsigned int len;
630
631 im = &idmap->idmap_im;
632 640
633 mutex_lock(&idmap->idmap_lock); 641 /* msg and im are freed in idmap_pipe_destroy_msg */
634 mutex_lock(&idmap->idmap_im_lock); 642 msg = kmalloc(sizeof(*msg), GFP_KERNEL);
643 if (IS_ERR(msg)) {
644 ret = PTR_ERR(msg);
645 goto out0;
646 }
635 647
636 he = idmap_lookup_id(h, id); 648 im = kmalloc(sizeof(*im), GFP_KERNEL);
637 if (he) { 649 if (IS_ERR(im)) {
638 memcpy(name, he->ih_name, he->ih_namelen); 650 ret = PTR_ERR(im);
639 ret = he->ih_namelen; 651 goto out1;
640 goto out;
641 } 652 }
642 653
643 memset(im, 0, sizeof(*im)); 654 ret = nfs_idmap_prepare_message(key->description, im, msg);
644 im->im_type = h->h_type; 655 if (ret < 0)
645 im->im_conv = IDMAP_CONV_IDTONAME; 656 goto out2;
646 im->im_id = id;
647 657
648 memset(&msg, 0, sizeof(msg)); 658 idmap->idmap_key_cons = cons;
649 msg.data = im;
650 msg.len = sizeof(*im);
651 659
652 add_wait_queue(&idmap->idmap_wq, &wq); 660 ret = rpc_queue_upcall(idmap->idmap_pipe, msg);
661 if (ret < 0)
662 goto out2;
653 663
654 if (rpc_queue_upcall(idmap->idmap_dentry->d_inode, &msg) < 0) { 664 return ret;
655 remove_wait_queue(&idmap->idmap_wq, &wq); 665
656 goto out; 666out2:
657 } 667 kfree(im);
668out1:
669 kfree(msg);
670out0:
671 key_revoke(cons->key);
672 key_revoke(cons->authkey);
673 return ret;
674}
675
676static int nfs_idmap_instantiate(struct key *key, struct key *authkey, char *data)
677{
678 return key_instantiate_and_link(key, data, strlen(data) + 1,
679 id_resolver_cache->thread_keyring,
680 authkey);
681}
658 682
659 set_current_state(TASK_UNINTERRUPTIBLE); 683static int nfs_idmap_read_message(struct idmap_msg *im, struct key *key, struct key *authkey)
660 mutex_unlock(&idmap->idmap_im_lock); 684{
661 schedule(); 685 char id_str[NFS_UINT_MAXLEN];
662 __set_current_state(TASK_RUNNING); 686 int ret = -EINVAL;
663 remove_wait_queue(&idmap->idmap_wq, &wq); 687
664 mutex_lock(&idmap->idmap_im_lock); 688 switch (im->im_conv) {
665 689 case IDMAP_CONV_NAMETOID:
666 if (im->im_status & IDMAP_STATUS_SUCCESS) { 690 sprintf(id_str, "%d", im->im_id);
667 if ((len = strnlen(im->im_name, IDMAP_NAMESZ)) == 0) 691 ret = nfs_idmap_instantiate(key, authkey, id_str);
668 goto out; 692 break;
669 memcpy(name, im->im_name, len); 693 case IDMAP_CONV_IDTONAME:
670 ret = len; 694 ret = nfs_idmap_instantiate(key, authkey, im->im_name);
695 break;
671 } 696 }
672 697
673 out:
674 memset(im, 0, sizeof(*im));
675 mutex_unlock(&idmap->idmap_im_lock);
676 mutex_unlock(&idmap->idmap_lock);
677 return ret; 698 return ret;
678} 699}
679 700
@@ -682,115 +703,51 @@ idmap_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
682{ 703{
683 struct rpc_inode *rpci = RPC_I(filp->f_path.dentry->d_inode); 704 struct rpc_inode *rpci = RPC_I(filp->f_path.dentry->d_inode);
684 struct idmap *idmap = (struct idmap *)rpci->private; 705 struct idmap *idmap = (struct idmap *)rpci->private;
685 struct idmap_msg im_in, *im = &idmap->idmap_im; 706 struct key_construction *cons = idmap->idmap_key_cons;
686 struct idmap_hashtable *h; 707 struct idmap_msg im;
687 struct idmap_hashent *he = NULL;
688 size_t namelen_in; 708 size_t namelen_in;
689 int ret; 709 int ret;
690 710
691 if (mlen != sizeof(im_in)) 711 if (mlen != sizeof(im)) {
692 return -ENOSPC; 712 ret = -ENOSPC;
693
694 if (copy_from_user(&im_in, src, mlen) != 0)
695 return -EFAULT;
696
697 mutex_lock(&idmap->idmap_im_lock);
698
699 ret = mlen;
700 im->im_status = im_in.im_status;
701 /* If we got an error, terminate now, and wake up pending upcalls */
702 if (!(im_in.im_status & IDMAP_STATUS_SUCCESS)) {
703 wake_up(&idmap->idmap_wq);
704 goto out; 713 goto out;
705 } 714 }
706 715
707 /* Sanity checking of strings */ 716 if (copy_from_user(&im, src, mlen) != 0) {
708 ret = -EINVAL; 717 ret = -EFAULT;
709 namelen_in = strnlen(im_in.im_name, IDMAP_NAMESZ);
710 if (namelen_in == 0 || namelen_in == IDMAP_NAMESZ)
711 goto out; 718 goto out;
719 }
712 720
713 switch (im_in.im_type) { 721 if (!(im.im_status & IDMAP_STATUS_SUCCESS)) {
714 case IDMAP_TYPE_USER: 722 ret = mlen;
715 h = &idmap->idmap_user_hash; 723 complete_request_key(idmap->idmap_key_cons, -ENOKEY);
716 break; 724 goto out_incomplete;
717 case IDMAP_TYPE_GROUP:
718 h = &idmap->idmap_group_hash;
719 break;
720 default:
721 goto out;
722 } 725 }
723 726
724 switch (im_in.im_conv) { 727 namelen_in = strnlen(im.im_name, IDMAP_NAMESZ);
725 case IDMAP_CONV_IDTONAME: 728 if (namelen_in == 0 || namelen_in == IDMAP_NAMESZ) {
726 /* Did we match the current upcall? */ 729 ret = -EINVAL;
727 if (im->im_conv == IDMAP_CONV_IDTONAME
728 && im->im_type == im_in.im_type
729 && im->im_id == im_in.im_id) {
730 /* Yes: copy string, including the terminating '\0' */
731 memcpy(im->im_name, im_in.im_name, namelen_in);
732 im->im_name[namelen_in] = '\0';
733 wake_up(&idmap->idmap_wq);
734 }
735 he = idmap_alloc_id(h, im_in.im_id);
736 break;
737 case IDMAP_CONV_NAMETOID:
738 /* Did we match the current upcall? */
739 if (im->im_conv == IDMAP_CONV_NAMETOID
740 && im->im_type == im_in.im_type
741 && strnlen(im->im_name, IDMAP_NAMESZ) == namelen_in
742 && memcmp(im->im_name, im_in.im_name, namelen_in) == 0) {
743 im->im_id = im_in.im_id;
744 wake_up(&idmap->idmap_wq);
745 }
746 he = idmap_alloc_name(h, im_in.im_name, namelen_in);
747 break;
748 default:
749 goto out; 730 goto out;
750 } 731 }
751 732
752 /* If the entry is valid, also copy it to the cache */ 733 ret = nfs_idmap_read_message(&im, cons->key, cons->authkey);
753 if (he != NULL) 734 if (ret >= 0) {
754 idmap_update_entry(he, im_in.im_name, namelen_in, im_in.im_id); 735 key_set_timeout(cons->key, nfs_idmap_cache_timeout);
755 ret = mlen; 736 ret = mlen;
737 }
738
756out: 739out:
757 mutex_unlock(&idmap->idmap_im_lock); 740 complete_request_key(idmap->idmap_key_cons, ret);
741out_incomplete:
758 return ret; 742 return ret;
759} 743}
760 744
761static void 745static void
762idmap_pipe_destroy_msg(struct rpc_pipe_msg *msg) 746idmap_pipe_destroy_msg(struct rpc_pipe_msg *msg)
763{ 747{
764 struct idmap_msg *im = msg->data; 748 /* Free memory allocated in nfs_idmap_legacy_upcall() */
765 struct idmap *idmap = container_of(im, struct idmap, idmap_im); 749 kfree(msg->data);
766 750 kfree(msg);
767 if (msg->errno >= 0)
768 return;
769 mutex_lock(&idmap->idmap_im_lock);
770 im->im_status = IDMAP_STATUS_LOOKUPFAIL;
771 wake_up(&idmap->idmap_wq);
772 mutex_unlock(&idmap->idmap_im_lock);
773}
774
775/*
776 * Fowler/Noll/Vo hash
777 * http://www.isthe.com/chongo/tech/comp/fnv/
778 */
779
780#define FNV_P_32 ((unsigned int)0x01000193) /* 16777619 */
781#define FNV_1_32 ((unsigned int)0x811c9dc5) /* 2166136261 */
782
783static unsigned int fnvhash32(const void *buf, size_t buflen)
784{
785 const unsigned char *p, *end = (const unsigned char *)buf + buflen;
786 unsigned int hash = FNV_1_32;
787
788 for (p = buf; p < end; p++) {
789 hash *= FNV_P_32;
790 hash ^= (unsigned int)*p;
791 }
792
793 return hash;
794} 751}
795 752
796int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid) 753int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid)
@@ -799,16 +756,16 @@ int nfs_map_name_to_uid(const struct nfs_server *server, const char *name, size_
799 756
800 if (nfs_map_string_to_numeric(name, namelen, uid)) 757 if (nfs_map_string_to_numeric(name, namelen, uid))
801 return 0; 758 return 0;
802 return nfs_idmap_id(idmap, &idmap->idmap_user_hash, name, namelen, uid); 759 return nfs_idmap_lookup_id(name, namelen, "uid", uid, idmap);
803} 760}
804 761
805int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *uid) 762int nfs_map_group_to_gid(const struct nfs_server *server, const char *name, size_t namelen, __u32 *gid)
806{ 763{
807 struct idmap *idmap = server->nfs_client->cl_idmap; 764 struct idmap *idmap = server->nfs_client->cl_idmap;
808 765
809 if (nfs_map_string_to_numeric(name, namelen, uid)) 766 if (nfs_map_string_to_numeric(name, namelen, gid))
810 return 0; 767 return 0;
811 return nfs_idmap_id(idmap, &idmap->idmap_group_hash, name, namelen, uid); 768 return nfs_idmap_lookup_id(name, namelen, "gid", gid, idmap);
812} 769}
813 770
814int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen) 771int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen)
@@ -817,21 +774,19 @@ int nfs_map_uid_to_name(const struct nfs_server *server, __u32 uid, char *buf, s
817 int ret = -EINVAL; 774 int ret = -EINVAL;
818 775
819 if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) 776 if (!(server->caps & NFS_CAP_UIDGID_NOMAP))
820 ret = nfs_idmap_name(idmap, &idmap->idmap_user_hash, uid, buf); 777 ret = nfs_idmap_lookup_name(uid, "user", buf, buflen, idmap);
821 if (ret < 0) 778 if (ret < 0)
822 ret = nfs_map_numeric_to_string(uid, buf, buflen); 779 ret = nfs_map_numeric_to_string(uid, buf, buflen);
823 return ret; 780 return ret;
824} 781}
825int nfs_map_gid_to_group(const struct nfs_server *server, __u32 uid, char *buf, size_t buflen) 782int nfs_map_gid_to_group(const struct nfs_server *server, __u32 gid, char *buf, size_t buflen)
826{ 783{
827 struct idmap *idmap = server->nfs_client->cl_idmap; 784 struct idmap *idmap = server->nfs_client->cl_idmap;
828 int ret = -EINVAL; 785 int ret = -EINVAL;
829 786
830 if (!(server->caps & NFS_CAP_UIDGID_NOMAP)) 787 if (!(server->caps & NFS_CAP_UIDGID_NOMAP))
831 ret = nfs_idmap_name(idmap, &idmap->idmap_group_hash, uid, buf); 788 ret = nfs_idmap_lookup_name(gid, "group", buf, buflen, idmap);
832 if (ret < 0) 789 if (ret < 0)
833 ret = nfs_map_numeric_to_string(uid, buf, buflen); 790 ret = nfs_map_numeric_to_string(gid, buf, buflen);
834 return ret; 791 return ret;
835} 792}
836
837#endif /* CONFIG_NFS_USE_NEW_IDMAPPER */
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index f649fba8c38..7bb4d13c1cd 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -39,6 +39,7 @@
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/compat.h> 40#include <linux/compat.h>
41#include <linux/freezer.h> 41#include <linux/freezer.h>
42#include <linux/crc32.h>
42 43
43#include <asm/system.h> 44#include <asm/system.h>
44#include <asm/uaccess.h> 45#include <asm/uaccess.h>
@@ -51,6 +52,7 @@
51#include "fscache.h" 52#include "fscache.h"
52#include "dns_resolve.h" 53#include "dns_resolve.h"
53#include "pnfs.h" 54#include "pnfs.h"
55#include "netns.h"
54 56
55#define NFSDBG_FACILITY NFSDBG_VFS 57#define NFSDBG_FACILITY NFSDBG_VFS
56 58
@@ -388,9 +390,10 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
388 unlock_new_inode(inode); 390 unlock_new_inode(inode);
389 } else 391 } else
390 nfs_refresh_inode(inode, fattr); 392 nfs_refresh_inode(inode, fattr);
391 dprintk("NFS: nfs_fhget(%s/%Ld ct=%d)\n", 393 dprintk("NFS: nfs_fhget(%s/%Ld fh_crc=0x%08x ct=%d)\n",
392 inode->i_sb->s_id, 394 inode->i_sb->s_id,
393 (long long)NFS_FILEID(inode), 395 (long long)NFS_FILEID(inode),
396 nfs_display_fhandle_hash(fh),
394 atomic_read(&inode->i_count)); 397 atomic_read(&inode->i_count));
395 398
396out: 399out:
@@ -401,7 +404,7 @@ out_no_inode:
401 goto out; 404 goto out;
402} 405}
403 406
404#define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET|ATTR_FILE) 407#define NFS_VALID_ATTRS (ATTR_MODE|ATTR_UID|ATTR_GID|ATTR_SIZE|ATTR_ATIME|ATTR_ATIME_SET|ATTR_MTIME|ATTR_MTIME_SET|ATTR_FILE|ATTR_OPEN)
405 408
406int 409int
407nfs_setattr(struct dentry *dentry, struct iattr *attr) 410nfs_setattr(struct dentry *dentry, struct iattr *attr)
@@ -423,7 +426,7 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
423 426
424 /* Optimization: if the end result is no change, don't RPC */ 427 /* Optimization: if the end result is no change, don't RPC */
425 attr->ia_valid &= NFS_VALID_ATTRS; 428 attr->ia_valid &= NFS_VALID_ATTRS;
426 if ((attr->ia_valid & ~ATTR_FILE) == 0) 429 if ((attr->ia_valid & ~(ATTR_FILE|ATTR_OPEN)) == 0)
427 return 0; 430 return 0;
428 431
429 /* Write all dirty data */ 432 /* Write all dirty data */
@@ -1044,6 +1047,67 @@ struct nfs_fh *nfs_alloc_fhandle(void)
1044 return fh; 1047 return fh;
1045} 1048}
1046 1049
1050#ifdef NFS_DEBUG
1051/*
1052 * _nfs_display_fhandle_hash - calculate the crc32 hash for the filehandle
1053 * in the same way that wireshark does
1054 *
1055 * @fh: file handle
1056 *
1057 * For debugging only.
1058 */
1059u32 _nfs_display_fhandle_hash(const struct nfs_fh *fh)
1060{
1061 /* wireshark uses 32-bit AUTODIN crc and does a bitwise
1062 * not on the result */
1063 return ~crc32(0xFFFFFFFF, &fh->data[0], fh->size);
1064}
1065
1066/*
1067 * _nfs_display_fhandle - display an NFS file handle on the console
1068 *
1069 * @fh: file handle to display
1070 * @caption: display caption
1071 *
1072 * For debugging only.
1073 */
1074void _nfs_display_fhandle(const struct nfs_fh *fh, const char *caption)
1075{
1076 unsigned short i;
1077
1078 if (fh == NULL || fh->size == 0) {
1079 printk(KERN_DEFAULT "%s at %p is empty\n", caption, fh);
1080 return;
1081 }
1082
1083 printk(KERN_DEFAULT "%s at %p is %u bytes, crc: 0x%08x:\n",
1084 caption, fh, fh->size, _nfs_display_fhandle_hash(fh));
1085 for (i = 0; i < fh->size; i += 16) {
1086 __be32 *pos = (__be32 *)&fh->data[i];
1087
1088 switch ((fh->size - i - 1) >> 2) {
1089 case 0:
1090 printk(KERN_DEFAULT " %08x\n",
1091 be32_to_cpup(pos));
1092 break;
1093 case 1:
1094 printk(KERN_DEFAULT " %08x %08x\n",
1095 be32_to_cpup(pos), be32_to_cpup(pos + 1));
1096 break;
1097 case 2:
1098 printk(KERN_DEFAULT " %08x %08x %08x\n",
1099 be32_to_cpup(pos), be32_to_cpup(pos + 1),
1100 be32_to_cpup(pos + 2));
1101 break;
1102 default:
1103 printk(KERN_DEFAULT " %08x %08x %08x %08x\n",
1104 be32_to_cpup(pos), be32_to_cpup(pos + 1),
1105 be32_to_cpup(pos + 2), be32_to_cpup(pos + 3));
1106 }
1107 }
1108}
1109#endif
1110
1047/** 1111/**
1048 * nfs_inode_attrs_need_update - check if the inode attributes need updating 1112 * nfs_inode_attrs_need_update - check if the inode attributes need updating
1049 * @inode - pointer to inode 1113 * @inode - pointer to inode
@@ -1211,8 +1275,9 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1211 unsigned long now = jiffies; 1275 unsigned long now = jiffies;
1212 unsigned long save_cache_validity; 1276 unsigned long save_cache_validity;
1213 1277
1214 dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n", 1278 dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
1215 __func__, inode->i_sb->s_id, inode->i_ino, 1279 __func__, inode->i_sb->s_id, inode->i_ino,
1280 nfs_display_fhandle_hash(NFS_FH(inode)),
1216 atomic_read(&inode->i_count), fattr->valid); 1281 atomic_read(&inode->i_count), fattr->valid);
1217 1282
1218 if ((fattr->valid & NFS_ATTR_FATTR_FILEID) && nfsi->fileid != fattr->fileid) 1283 if ((fattr->valid & NFS_ATTR_FATTR_FILEID) && nfsi->fileid != fattr->fileid)
@@ -1406,7 +1471,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
1406 /* 1471 /*
1407 * Big trouble! The inode has become a different object. 1472 * Big trouble! The inode has become a different object.
1408 */ 1473 */
1409 printk(KERN_DEBUG "%s: inode %ld mode changed, %07o to %07o\n", 1474 printk(KERN_DEBUG "NFS: %s: inode %ld mode changed, %07o to %07o\n",
1410 __func__, inode->i_ino, inode->i_mode, fattr->mode); 1475 __func__, inode->i_ino, inode->i_mode, fattr->mode);
1411 out_err: 1476 out_err:
1412 /* 1477 /*
@@ -1495,7 +1560,7 @@ static void init_once(void *foo)
1495 INIT_LIST_HEAD(&nfsi->open_files); 1560 INIT_LIST_HEAD(&nfsi->open_files);
1496 INIT_LIST_HEAD(&nfsi->access_cache_entry_lru); 1561 INIT_LIST_HEAD(&nfsi->access_cache_entry_lru);
1497 INIT_LIST_HEAD(&nfsi->access_cache_inode_lru); 1562 INIT_LIST_HEAD(&nfsi->access_cache_inode_lru);
1498 INIT_RADIX_TREE(&nfsi->nfs_page_tree, GFP_ATOMIC); 1563 INIT_LIST_HEAD(&nfsi->commit_list);
1499 nfsi->npages = 0; 1564 nfsi->npages = 0;
1500 nfsi->ncommit = 0; 1565 nfsi->ncommit = 0;
1501 atomic_set(&nfsi->silly_count, 1); 1566 atomic_set(&nfsi->silly_count, 1);
@@ -1552,6 +1617,28 @@ static void nfsiod_stop(void)
1552 destroy_workqueue(wq); 1617 destroy_workqueue(wq);
1553} 1618}
1554 1619
1620int nfs_net_id;
1621EXPORT_SYMBOL_GPL(nfs_net_id);
1622
1623static int nfs_net_init(struct net *net)
1624{
1625 nfs_clients_init(net);
1626 return nfs_dns_resolver_cache_init(net);
1627}
1628
1629static void nfs_net_exit(struct net *net)
1630{
1631 nfs_dns_resolver_cache_destroy(net);
1632 nfs_cleanup_cb_ident_idr(net);
1633}
1634
1635static struct pernet_operations nfs_net_ops = {
1636 .init = nfs_net_init,
1637 .exit = nfs_net_exit,
1638 .id = &nfs_net_id,
1639 .size = sizeof(struct nfs_net),
1640};
1641
1555/* 1642/*
1556 * Initialize NFS 1643 * Initialize NFS
1557 */ 1644 */
@@ -1561,10 +1648,14 @@ static int __init init_nfs_fs(void)
1561 1648
1562 err = nfs_idmap_init(); 1649 err = nfs_idmap_init();
1563 if (err < 0) 1650 if (err < 0)
1564 goto out9; 1651 goto out10;
1565 1652
1566 err = nfs_dns_resolver_init(); 1653 err = nfs_dns_resolver_init();
1567 if (err < 0) 1654 if (err < 0)
1655 goto out9;
1656
1657 err = register_pernet_subsys(&nfs_net_ops);
1658 if (err < 0)
1568 goto out8; 1659 goto out8;
1569 1660
1570 err = nfs_fscache_register(); 1661 err = nfs_fscache_register();
@@ -1600,14 +1691,14 @@ static int __init init_nfs_fs(void)
1600 goto out0; 1691 goto out0;
1601 1692
1602#ifdef CONFIG_PROC_FS 1693#ifdef CONFIG_PROC_FS
1603 rpc_proc_register(&nfs_rpcstat); 1694 rpc_proc_register(&init_net, &nfs_rpcstat);
1604#endif 1695#endif
1605 if ((err = register_nfs_fs()) != 0) 1696 if ((err = register_nfs_fs()) != 0)
1606 goto out; 1697 goto out;
1607 return 0; 1698 return 0;
1608out: 1699out:
1609#ifdef CONFIG_PROC_FS 1700#ifdef CONFIG_PROC_FS
1610 rpc_proc_unregister("nfs"); 1701 rpc_proc_unregister(&init_net, "nfs");
1611#endif 1702#endif
1612 nfs_destroy_directcache(); 1703 nfs_destroy_directcache();
1613out0: 1704out0:
@@ -1625,10 +1716,12 @@ out5:
1625out6: 1716out6:
1626 nfs_fscache_unregister(); 1717 nfs_fscache_unregister();
1627out7: 1718out7:
1628 nfs_dns_resolver_destroy(); 1719 unregister_pernet_subsys(&nfs_net_ops);
1629out8: 1720out8:
1630 nfs_idmap_quit(); 1721 nfs_dns_resolver_destroy();
1631out9: 1722out9:
1723 nfs_idmap_quit();
1724out10:
1632 return err; 1725 return err;
1633} 1726}
1634 1727
@@ -1640,12 +1733,12 @@ static void __exit exit_nfs_fs(void)
1640 nfs_destroy_inodecache(); 1733 nfs_destroy_inodecache();
1641 nfs_destroy_nfspagecache(); 1734 nfs_destroy_nfspagecache();
1642 nfs_fscache_unregister(); 1735 nfs_fscache_unregister();
1736 unregister_pernet_subsys(&nfs_net_ops);
1643 nfs_dns_resolver_destroy(); 1737 nfs_dns_resolver_destroy();
1644 nfs_idmap_quit(); 1738 nfs_idmap_quit();
1645#ifdef CONFIG_PROC_FS 1739#ifdef CONFIG_PROC_FS
1646 rpc_proc_unregister("nfs"); 1740 rpc_proc_unregister(&init_net, "nfs");
1647#endif 1741#endif
1648 nfs_cleanup_cb_ident_idr();
1649 unregister_nfs_fs(); 1742 unregister_nfs_fs();
1650 nfs_fs_proc_exit(); 1743 nfs_fs_proc_exit();
1651 nfsiod_stop(); 1744 nfsiod_stop();
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 8102db9b926..2476dc69365 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -123,6 +123,7 @@ struct nfs_parsed_mount_data {
123 } nfs_server; 123 } nfs_server;
124 124
125 struct security_mnt_opts lsm_opts; 125 struct security_mnt_opts lsm_opts;
126 struct net *net;
126}; 127};
127 128
128/* mount_clnt.c */ 129/* mount_clnt.c */
@@ -137,20 +138,22 @@ struct nfs_mount_request {
137 int noresvport; 138 int noresvport;
138 unsigned int *auth_flav_len; 139 unsigned int *auth_flav_len;
139 rpc_authflavor_t *auth_flavs; 140 rpc_authflavor_t *auth_flavs;
141 struct net *net;
140}; 142};
141 143
142extern int nfs_mount(struct nfs_mount_request *info); 144extern int nfs_mount(struct nfs_mount_request *info);
143extern void nfs_umount(const struct nfs_mount_request *info); 145extern void nfs_umount(const struct nfs_mount_request *info);
144 146
145/* client.c */ 147/* client.c */
146extern struct rpc_program nfs_program; 148extern const struct rpc_program nfs_program;
149extern void nfs_clients_init(struct net *net);
147 150
148extern void nfs_cleanup_cb_ident_idr(void); 151extern void nfs_cleanup_cb_ident_idr(struct net *);
149extern void nfs_put_client(struct nfs_client *); 152extern void nfs_put_client(struct nfs_client *);
150extern struct nfs_client *nfs4_find_client_no_ident(const struct sockaddr *); 153extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
151extern struct nfs_client *nfs4_find_client_ident(int);
152extern struct nfs_client * 154extern struct nfs_client *
153nfs4_find_client_sessionid(const struct sockaddr *, struct nfs4_sessionid *); 155nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
156 struct nfs4_sessionid *);
154extern struct nfs_server *nfs_create_server( 157extern struct nfs_server *nfs_create_server(
155 const struct nfs_parsed_mount_data *, 158 const struct nfs_parsed_mount_data *,
156 struct nfs_fh *); 159 struct nfs_fh *);
@@ -329,6 +332,8 @@ void nfs_retry_commit(struct list_head *page_list,
329void nfs_commit_clear_lock(struct nfs_inode *nfsi); 332void nfs_commit_clear_lock(struct nfs_inode *nfsi);
330void nfs_commitdata_release(void *data); 333void nfs_commitdata_release(void *data);
331void nfs_commit_release_pages(struct nfs_write_data *data); 334void nfs_commit_release_pages(struct nfs_write_data *data);
335void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *head);
336void nfs_request_remove_commit_list(struct nfs_page *req);
332 337
333#ifdef CONFIG_MIGRATION 338#ifdef CONFIG_MIGRATION
334extern int nfs_migrate_page(struct address_space *, 339extern int nfs_migrate_page(struct address_space *,
diff --git a/fs/nfs/mount_clnt.c b/fs/nfs/mount_clnt.c
index d4c2d6b7507..8e65c7f1f87 100644
--- a/fs/nfs/mount_clnt.c
+++ b/fs/nfs/mount_clnt.c
@@ -16,7 +16,7 @@
16#include <linux/nfs_fs.h> 16#include <linux/nfs_fs.h>
17#include "internal.h" 17#include "internal.h"
18 18
19#ifdef RPC_DEBUG 19#ifdef NFS_DEBUG
20# define NFSDBG_FACILITY NFSDBG_MOUNT 20# define NFSDBG_FACILITY NFSDBG_MOUNT
21#endif 21#endif
22 22
@@ -67,7 +67,7 @@ enum {
67 MOUNTPROC3_EXPORT = 5, 67 MOUNTPROC3_EXPORT = 5,
68}; 68};
69 69
70static struct rpc_program mnt_program; 70static const struct rpc_program mnt_program;
71 71
72/* 72/*
73 * Defined by OpenGroup XNFS Version 3W, chapter 8 73 * Defined by OpenGroup XNFS Version 3W, chapter 8
@@ -153,7 +153,7 @@ int nfs_mount(struct nfs_mount_request *info)
153 .rpc_resp = &result, 153 .rpc_resp = &result,
154 }; 154 };
155 struct rpc_create_args args = { 155 struct rpc_create_args args = {
156 .net = &init_net, 156 .net = info->net,
157 .protocol = info->protocol, 157 .protocol = info->protocol,
158 .address = info->sap, 158 .address = info->sap,
159 .addrsize = info->salen, 159 .addrsize = info->salen,
@@ -225,7 +225,7 @@ void nfs_umount(const struct nfs_mount_request *info)
225 .to_retries = 2, 225 .to_retries = 2,
226 }; 226 };
227 struct rpc_create_args args = { 227 struct rpc_create_args args = {
228 .net = &init_net, 228 .net = info->net,
229 .protocol = IPPROTO_UDP, 229 .protocol = IPPROTO_UDP,
230 .address = info->sap, 230 .address = info->sap,
231 .addrsize = info->salen, 231 .addrsize = info->salen,
@@ -488,19 +488,19 @@ static struct rpc_procinfo mnt3_procedures[] = {
488}; 488};
489 489
490 490
491static struct rpc_version mnt_version1 = { 491static const struct rpc_version mnt_version1 = {
492 .number = 1, 492 .number = 1,
493 .nrprocs = ARRAY_SIZE(mnt_procedures), 493 .nrprocs = ARRAY_SIZE(mnt_procedures),
494 .procs = mnt_procedures, 494 .procs = mnt_procedures,
495}; 495};
496 496
497static struct rpc_version mnt_version3 = { 497static const struct rpc_version mnt_version3 = {
498 .number = 3, 498 .number = 3,
499 .nrprocs = ARRAY_SIZE(mnt3_procedures), 499 .nrprocs = ARRAY_SIZE(mnt3_procedures),
500 .procs = mnt3_procedures, 500 .procs = mnt3_procedures,
501}; 501};
502 502
503static struct rpc_version *mnt_version[] = { 503static const struct rpc_version *mnt_version[] = {
504 NULL, 504 NULL,
505 &mnt_version1, 505 &mnt_version1,
506 NULL, 506 NULL,
@@ -509,7 +509,7 @@ static struct rpc_version *mnt_version[] = {
509 509
510static struct rpc_stat mnt_stats; 510static struct rpc_stat mnt_stats;
511 511
512static struct rpc_program mnt_program = { 512static const struct rpc_program mnt_program = {
513 .name = "mount", 513 .name = "mount",
514 .number = NFS_MNT_PROGRAM, 514 .number = NFS_MNT_PROGRAM,
515 .nrvers = ARRAY_SIZE(mnt_version), 515 .nrvers = ARRAY_SIZE(mnt_version),
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
index 8102391bb37..1807866bb3a 100644
--- a/fs/nfs/namespace.c
+++ b/fs/nfs/namespace.c
@@ -276,7 +276,10 @@ out:
276 nfs_free_fattr(fattr); 276 nfs_free_fattr(fattr);
277 nfs_free_fhandle(fh); 277 nfs_free_fhandle(fh);
278out_nofree: 278out_nofree:
279 dprintk("<-- nfs_follow_mountpoint() = %p\n", mnt); 279 if (IS_ERR(mnt))
280 dprintk("<-- %s(): error %ld\n", __func__, PTR_ERR(mnt));
281 else
282 dprintk("<-- %s() = %p\n", __func__, mnt);
280 return mnt; 283 return mnt;
281} 284}
282 285
diff --git a/fs/nfs/netns.h b/fs/nfs/netns.h
new file mode 100644
index 00000000000..aa14ec303e9
--- /dev/null
+++ b/fs/nfs/netns.h
@@ -0,0 +1,27 @@
1#ifndef __NFS_NETNS_H__
2#define __NFS_NETNS_H__
3
4#include <net/net_namespace.h>
5#include <net/netns/generic.h>
6
7struct bl_dev_msg {
8 int32_t status;
9 uint32_t major, minor;
10};
11
12struct nfs_net {
13 struct cache_detail *nfs_dns_resolve;
14 struct rpc_pipe *bl_device_pipe;
15 struct bl_dev_msg bl_mount_reply;
16 wait_queue_head_t bl_wq;
17 struct list_head nfs_client_list;
18 struct list_head nfs_volume_list;
19#ifdef CONFIG_NFS_V4
20 struct idr cb_ident_idr; /* Protected by nfs_client_lock */
21#endif
22 spinlock_t nfs_client_lock;
23};
24
25extern int nfs_net_id;
26
27#endif
diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c
index 792cb13a430..1f56000fabb 100644
--- a/fs/nfs/nfs2xdr.c
+++ b/fs/nfs/nfs2xdr.c
@@ -1150,7 +1150,7 @@ struct rpc_procinfo nfs_procedures[] = {
1150 PROC(STATFS, fhandle, statfsres, 0), 1150 PROC(STATFS, fhandle, statfsres, 0),
1151}; 1151};
1152 1152
1153struct rpc_version nfs_version2 = { 1153const struct rpc_version nfs_version2 = {
1154 .number = 2, 1154 .number = 2,
1155 .nrprocs = ARRAY_SIZE(nfs_procedures), 1155 .nrprocs = ARRAY_SIZE(nfs_procedures),
1156 .procs = nfs_procedures 1156 .procs = nfs_procedures
diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
index 7ef23979896..e4498dc351a 100644
--- a/fs/nfs/nfs3acl.c
+++ b/fs/nfs/nfs3acl.c
@@ -192,7 +192,7 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
192 .pages = pages, 192 .pages = pages,
193 }; 193 };
194 struct nfs3_getaclres res = { 194 struct nfs3_getaclres res = {
195 0 195 NULL,
196 }; 196 };
197 struct rpc_message msg = { 197 struct rpc_message msg = {
198 .rpc_argp = &args, 198 .rpc_argp = &args,
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index 91943953a37..5242eae6711 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -428,6 +428,11 @@ nfs3_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
428 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE]; 428 msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE];
429} 429}
430 430
431static void nfs3_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
432{
433 rpc_call_start(task);
434}
435
431static int 436static int
432nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir) 437nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
433{ 438{
@@ -445,6 +450,11 @@ nfs3_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
445 msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME]; 450 msg->rpc_proc = &nfs3_procedures[NFS3PROC_RENAME];
446} 451}
447 452
453static void nfs3_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
454{
455 rpc_call_start(task);
456}
457
448static int 458static int
449nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir, 459nfs3_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
450 struct inode *new_dir) 460 struct inode *new_dir)
@@ -814,6 +824,11 @@ static void nfs3_proc_read_setup(struct nfs_read_data *data, struct rpc_message
814 msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ]; 824 msg->rpc_proc = &nfs3_procedures[NFS3PROC_READ];
815} 825}
816 826
827static void nfs3_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data)
828{
829 rpc_call_start(task);
830}
831
817static int nfs3_write_done(struct rpc_task *task, struct nfs_write_data *data) 832static int nfs3_write_done(struct rpc_task *task, struct nfs_write_data *data)
818{ 833{
819 if (nfs3_async_handle_jukebox(task, data->inode)) 834 if (nfs3_async_handle_jukebox(task, data->inode))
@@ -828,6 +843,11 @@ static void nfs3_proc_write_setup(struct nfs_write_data *data, struct rpc_messag
828 msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE]; 843 msg->rpc_proc = &nfs3_procedures[NFS3PROC_WRITE];
829} 844}
830 845
846static void nfs3_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data)
847{
848 rpc_call_start(task);
849}
850
831static int nfs3_commit_done(struct rpc_task *task, struct nfs_write_data *data) 851static int nfs3_commit_done(struct rpc_task *task, struct nfs_write_data *data)
832{ 852{
833 if (nfs3_async_handle_jukebox(task, data->inode)) 853 if (nfs3_async_handle_jukebox(task, data->inode))
@@ -864,9 +884,11 @@ const struct nfs_rpc_ops nfs_v3_clientops = {
864 .create = nfs3_proc_create, 884 .create = nfs3_proc_create,
865 .remove = nfs3_proc_remove, 885 .remove = nfs3_proc_remove,
866 .unlink_setup = nfs3_proc_unlink_setup, 886 .unlink_setup = nfs3_proc_unlink_setup,
887 .unlink_rpc_prepare = nfs3_proc_unlink_rpc_prepare,
867 .unlink_done = nfs3_proc_unlink_done, 888 .unlink_done = nfs3_proc_unlink_done,
868 .rename = nfs3_proc_rename, 889 .rename = nfs3_proc_rename,
869 .rename_setup = nfs3_proc_rename_setup, 890 .rename_setup = nfs3_proc_rename_setup,
891 .rename_rpc_prepare = nfs3_proc_rename_rpc_prepare,
870 .rename_done = nfs3_proc_rename_done, 892 .rename_done = nfs3_proc_rename_done,
871 .link = nfs3_proc_link, 893 .link = nfs3_proc_link,
872 .symlink = nfs3_proc_symlink, 894 .symlink = nfs3_proc_symlink,
@@ -879,8 +901,10 @@ const struct nfs_rpc_ops nfs_v3_clientops = {
879 .pathconf = nfs3_proc_pathconf, 901 .pathconf = nfs3_proc_pathconf,
880 .decode_dirent = nfs3_decode_dirent, 902 .decode_dirent = nfs3_decode_dirent,
881 .read_setup = nfs3_proc_read_setup, 903 .read_setup = nfs3_proc_read_setup,
904 .read_rpc_prepare = nfs3_proc_read_rpc_prepare,
882 .read_done = nfs3_read_done, 905 .read_done = nfs3_read_done,
883 .write_setup = nfs3_proc_write_setup, 906 .write_setup = nfs3_proc_write_setup,
907 .write_rpc_prepare = nfs3_proc_write_rpc_prepare,
884 .write_done = nfs3_write_done, 908 .write_done = nfs3_write_done,
885 .commit_setup = nfs3_proc_commit_setup, 909 .commit_setup = nfs3_proc_commit_setup,
886 .commit_done = nfs3_commit_done, 910 .commit_done = nfs3_commit_done,
diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c
index 183c6b123d0..a77cc9a3ce5 100644
--- a/fs/nfs/nfs3xdr.c
+++ b/fs/nfs/nfs3xdr.c
@@ -2461,7 +2461,7 @@ struct rpc_procinfo nfs3_procedures[] = {
2461 PROC(COMMIT, commit, commit, 5), 2461 PROC(COMMIT, commit, commit, 5),
2462}; 2462};
2463 2463
2464struct rpc_version nfs_version3 = { 2464const struct rpc_version nfs_version3 = {
2465 .number = 3, 2465 .number = 3,
2466 .nrprocs = ARRAY_SIZE(nfs3_procedures), 2466 .nrprocs = ARRAY_SIZE(nfs3_procedures),
2467 .procs = nfs3_procedures 2467 .procs = nfs3_procedures
@@ -2489,7 +2489,7 @@ static struct rpc_procinfo nfs3_acl_procedures[] = {
2489 }, 2489 },
2490}; 2490};
2491 2491
2492struct rpc_version nfsacl_version3 = { 2492const struct rpc_version nfsacl_version3 = {
2493 .number = 3, 2493 .number = 3,
2494 .nrprocs = sizeof(nfs3_acl_procedures)/ 2494 .nrprocs = sizeof(nfs3_acl_procedures)/
2495 sizeof(nfs3_acl_procedures[0]), 2495 sizeof(nfs3_acl_procedures[0]),
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 4d7d0aedc10..97ecc863dd7 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -20,7 +20,6 @@ enum nfs4_client_state {
20 NFS4CLNT_RECLAIM_REBOOT, 20 NFS4CLNT_RECLAIM_REBOOT,
21 NFS4CLNT_RECLAIM_NOGRACE, 21 NFS4CLNT_RECLAIM_NOGRACE,
22 NFS4CLNT_DELEGRETURN, 22 NFS4CLNT_DELEGRETURN,
23 NFS4CLNT_LAYOUTRECALL,
24 NFS4CLNT_SESSION_RESET, 23 NFS4CLNT_SESSION_RESET,
25 NFS4CLNT_RECALL_SLOT, 24 NFS4CLNT_RECALL_SLOT,
26 NFS4CLNT_LEASE_CONFIRM, 25 NFS4CLNT_LEASE_CONFIRM,
@@ -44,7 +43,7 @@ struct nfs4_minor_version_ops {
44 struct nfs4_sequence_args *args, 43 struct nfs4_sequence_args *args,
45 struct nfs4_sequence_res *res, 44 struct nfs4_sequence_res *res,
46 int cache_reply); 45 int cache_reply);
47 int (*validate_stateid)(struct nfs_delegation *, 46 bool (*match_stateid)(const nfs4_stateid *,
48 const nfs4_stateid *); 47 const nfs4_stateid *);
49 int (*find_root_sec)(struct nfs_server *, struct nfs_fh *, 48 int (*find_root_sec)(struct nfs_server *, struct nfs_fh *,
50 struct nfs_fsinfo *); 49 struct nfs_fsinfo *);
@@ -53,26 +52,25 @@ struct nfs4_minor_version_ops {
53 const struct nfs4_state_maintenance_ops *state_renewal_ops; 52 const struct nfs4_state_maintenance_ops *state_renewal_ops;
54}; 53};
55 54
56/* 55struct nfs_unique_id {
57 * struct rpc_sequence ensures that RPC calls are sent in the exact 56 struct rb_node rb_node;
58 * order that they appear on the list. 57 __u64 id;
59 */
60struct rpc_sequence {
61 struct rpc_wait_queue wait; /* RPC call delay queue */
62 spinlock_t lock; /* Protects the list */
63 struct list_head list; /* Defines sequence of RPC calls */
64}; 58};
65 59
66#define NFS_SEQID_CONFIRMED 1 60#define NFS_SEQID_CONFIRMED 1
67struct nfs_seqid_counter { 61struct nfs_seqid_counter {
68 struct rpc_sequence *sequence; 62 int owner_id;
69 int flags; 63 int flags;
70 u32 counter; 64 u32 counter;
65 spinlock_t lock; /* Protects the list */
66 struct list_head list; /* Defines sequence of RPC calls */
67 struct rpc_wait_queue wait; /* RPC call delay queue */
71}; 68};
72 69
73struct nfs_seqid { 70struct nfs_seqid {
74 struct nfs_seqid_counter *sequence; 71 struct nfs_seqid_counter *sequence;
75 struct list_head list; 72 struct list_head list;
73 struct rpc_task *task;
76}; 74};
77 75
78static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status) 76static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
@@ -81,18 +79,12 @@ static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status
81 seqid->flags |= NFS_SEQID_CONFIRMED; 79 seqid->flags |= NFS_SEQID_CONFIRMED;
82} 80}
83 81
84struct nfs_unique_id {
85 struct rb_node rb_node;
86 __u64 id;
87};
88
89/* 82/*
90 * NFS4 state_owners and lock_owners are simply labels for ordered 83 * NFS4 state_owners and lock_owners are simply labels for ordered
91 * sequences of RPC calls. Their sole purpose is to provide once-only 84 * sequences of RPC calls. Their sole purpose is to provide once-only
92 * semantics by allowing the server to identify replayed requests. 85 * semantics by allowing the server to identify replayed requests.
93 */ 86 */
94struct nfs4_state_owner { 87struct nfs4_state_owner {
95 struct nfs_unique_id so_owner_id;
96 struct nfs_server *so_server; 88 struct nfs_server *so_server;
97 struct list_head so_lru; 89 struct list_head so_lru;
98 unsigned long so_expires; 90 unsigned long so_expires;
@@ -105,7 +97,6 @@ struct nfs4_state_owner {
105 unsigned long so_flags; 97 unsigned long so_flags;
106 struct list_head so_states; 98 struct list_head so_states;
107 struct nfs_seqid_counter so_seqid; 99 struct nfs_seqid_counter so_seqid;
108 struct rpc_sequence so_sequence;
109}; 100};
110 101
111enum { 102enum {
@@ -146,8 +137,6 @@ struct nfs4_lock_state {
146#define NFS_LOCK_INITIALIZED 1 137#define NFS_LOCK_INITIALIZED 1
147 int ls_flags; 138 int ls_flags;
148 struct nfs_seqid_counter ls_seqid; 139 struct nfs_seqid_counter ls_seqid;
149 struct rpc_sequence ls_sequence;
150 struct nfs_unique_id ls_id;
151 nfs4_stateid ls_stateid; 140 nfs4_stateid ls_stateid;
152 atomic_t ls_count; 141 atomic_t ls_count;
153 struct nfs4_lock_owner ls_owner; 142 struct nfs4_lock_owner ls_owner;
@@ -193,6 +182,7 @@ struct nfs4_exception {
193 long timeout; 182 long timeout;
194 int retry; 183 int retry;
195 struct nfs4_state *state; 184 struct nfs4_state *state;
185 struct inode *inode;
196}; 186};
197 187
198struct nfs4_state_recovery_ops { 188struct nfs4_state_recovery_ops {
@@ -224,7 +214,7 @@ extern int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait, boo
224extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle); 214extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
225extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, 215extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
226 struct nfs4_fs_locations *fs_locations, struct page *page); 216 struct nfs4_fs_locations *fs_locations, struct page *page);
227extern void nfs4_release_lockowner(const struct nfs4_lock_state *); 217extern int nfs4_release_lockowner(struct nfs4_lock_state *);
228extern const struct xattr_handler *nfs4_xattr_handlers[]; 218extern const struct xattr_handler *nfs4_xattr_handlers[];
229 219
230#if defined(CONFIG_NFS_V4_1) 220#if defined(CONFIG_NFS_V4_1)
@@ -233,12 +223,13 @@ static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *ser
233 return server->nfs_client->cl_session; 223 return server->nfs_client->cl_session;
234} 224}
235 225
226extern bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy);
236extern int nfs4_setup_sequence(const struct nfs_server *server, 227extern int nfs4_setup_sequence(const struct nfs_server *server,
237 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 228 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res,
238 int cache_reply, struct rpc_task *task); 229 struct rpc_task *task);
239extern int nfs41_setup_sequence(struct nfs4_session *session, 230extern int nfs41_setup_sequence(struct nfs4_session *session,
240 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 231 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res,
241 int cache_reply, struct rpc_task *task); 232 struct rpc_task *task);
242extern void nfs4_destroy_session(struct nfs4_session *session); 233extern void nfs4_destroy_session(struct nfs4_session *session);
243extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp); 234extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp);
244extern int nfs4_proc_create_session(struct nfs_client *); 235extern int nfs4_proc_create_session(struct nfs_client *);
@@ -269,7 +260,7 @@ static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *ser
269 260
270static inline int nfs4_setup_sequence(const struct nfs_server *server, 261static inline int nfs4_setup_sequence(const struct nfs_server *server,
271 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res, 262 struct nfs4_sequence_args *args, struct nfs4_sequence_res *res,
272 int cache_reply, struct rpc_task *task) 263 struct rpc_task *task)
273{ 264{
274 return 0; 265 return 0;
275} 266}
@@ -319,7 +310,7 @@ static inline void nfs4_schedule_session_recovery(struct nfs4_session *session)
319} 310}
320#endif /* CONFIG_NFS_V4_1 */ 311#endif /* CONFIG_NFS_V4_1 */
321 312
322extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *); 313extern struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *, gfp_t);
323extern void nfs4_put_state_owner(struct nfs4_state_owner *); 314extern void nfs4_put_state_owner(struct nfs4_state_owner *);
324extern void nfs4_purge_state_owners(struct nfs_server *); 315extern void nfs4_purge_state_owners(struct nfs_server *);
325extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *); 316extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
@@ -327,6 +318,8 @@ extern void nfs4_put_open_state(struct nfs4_state *);
327extern void nfs4_close_state(struct nfs4_state *, fmode_t); 318extern void nfs4_close_state(struct nfs4_state *, fmode_t);
328extern void nfs4_close_sync(struct nfs4_state *, fmode_t); 319extern void nfs4_close_sync(struct nfs4_state *, fmode_t);
329extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t); 320extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
321extern void nfs_inode_find_state_and_recover(struct inode *inode,
322 const nfs4_stateid *stateid);
330extern void nfs4_schedule_lease_recovery(struct nfs_client *); 323extern void nfs4_schedule_lease_recovery(struct nfs_client *);
331extern void nfs4_schedule_state_manager(struct nfs_client *); 324extern void nfs4_schedule_state_manager(struct nfs_client *);
332extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp); 325extern void nfs4_schedule_path_down_recovery(struct nfs_client *clp);
@@ -337,7 +330,8 @@ extern void nfs41_handle_server_scope(struct nfs_client *,
337 struct server_scope **); 330 struct server_scope **);
338extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp); 331extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
339extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl); 332extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
340extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t, pid_t); 333extern void nfs4_select_rw_stateid(nfs4_stateid *, struct nfs4_state *,
334 fmode_t, fl_owner_t, pid_t);
341 335
342extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask); 336extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
343extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task); 337extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
@@ -346,6 +340,8 @@ extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
346extern void nfs_release_seqid(struct nfs_seqid *seqid); 340extern void nfs_release_seqid(struct nfs_seqid *seqid);
347extern void nfs_free_seqid(struct nfs_seqid *seqid); 341extern void nfs_free_seqid(struct nfs_seqid *seqid);
348 342
343extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp);
344
349extern const nfs4_stateid zero_stateid; 345extern const nfs4_stateid zero_stateid;
350 346
351/* nfs4xdr.c */ 347/* nfs4xdr.c */
@@ -357,6 +353,16 @@ struct nfs4_mount_data;
357extern struct svc_version nfs4_callback_version1; 353extern struct svc_version nfs4_callback_version1;
358extern struct svc_version nfs4_callback_version4; 354extern struct svc_version nfs4_callback_version4;
359 355
356static inline void nfs4_stateid_copy(nfs4_stateid *dst, const nfs4_stateid *src)
357{
358 memcpy(dst, src, sizeof(*dst));
359}
360
361static inline bool nfs4_stateid_match(const nfs4_stateid *dst, const nfs4_stateid *src)
362{
363 return memcmp(dst, src, sizeof(*dst)) == 0;
364}
365
360#else 366#else
361 367
362#define nfs4_close_state(a, b) do { } while (0) 368#define nfs4_close_state(a, b) do { } while (0)
diff --git a/fs/nfs/nfs4filelayout.c b/fs/nfs/nfs4filelayout.c
index 71ec08617e2..634c0bcb4fd 100644
--- a/fs/nfs/nfs4filelayout.c
+++ b/fs/nfs/nfs4filelayout.c
@@ -33,7 +33,10 @@
33#include <linux/nfs_page.h> 33#include <linux/nfs_page.h>
34#include <linux/module.h> 34#include <linux/module.h>
35 35
36#include <linux/sunrpc/metrics.h>
37
36#include "internal.h" 38#include "internal.h"
39#include "delegation.h"
37#include "nfs4filelayout.h" 40#include "nfs4filelayout.h"
38 41
39#define NFSDBG_FACILITY NFSDBG_PNFS_LD 42#define NFSDBG_FACILITY NFSDBG_PNFS_LD
@@ -84,12 +87,27 @@ static int filelayout_async_handle_error(struct rpc_task *task,
84 struct nfs_client *clp, 87 struct nfs_client *clp,
85 int *reset) 88 int *reset)
86{ 89{
90 struct nfs_server *mds_server = NFS_SERVER(state->inode);
91 struct nfs_client *mds_client = mds_server->nfs_client;
92
87 if (task->tk_status >= 0) 93 if (task->tk_status >= 0)
88 return 0; 94 return 0;
89
90 *reset = 0; 95 *reset = 0;
91 96
92 switch (task->tk_status) { 97 switch (task->tk_status) {
98 /* MDS state errors */
99 case -NFS4ERR_DELEG_REVOKED:
100 case -NFS4ERR_ADMIN_REVOKED:
101 case -NFS4ERR_BAD_STATEID:
102 nfs_remove_bad_delegation(state->inode);
103 case -NFS4ERR_OPENMODE:
104 nfs4_schedule_stateid_recovery(mds_server, state);
105 goto wait_on_recovery;
106 case -NFS4ERR_EXPIRED:
107 nfs4_schedule_stateid_recovery(mds_server, state);
108 nfs4_schedule_lease_recovery(mds_client);
109 goto wait_on_recovery;
110 /* DS session errors */
93 case -NFS4ERR_BADSESSION: 111 case -NFS4ERR_BADSESSION:
94 case -NFS4ERR_BADSLOT: 112 case -NFS4ERR_BADSLOT:
95 case -NFS4ERR_BAD_HIGH_SLOT: 113 case -NFS4ERR_BAD_HIGH_SLOT:
@@ -115,8 +133,14 @@ static int filelayout_async_handle_error(struct rpc_task *task,
115 *reset = 1; 133 *reset = 1;
116 break; 134 break;
117 } 135 }
136out:
118 task->tk_status = 0; 137 task->tk_status = 0;
119 return -EAGAIN; 138 return -EAGAIN;
139wait_on_recovery:
140 rpc_sleep_on(&mds_client->cl_rpcwaitq, task, NULL);
141 if (test_bit(NFS4CLNT_MANAGER_RUNNING, &mds_client->cl_state) == 0)
142 rpc_wake_up_queued_task(&mds_client->cl_rpcwaitq, task);
143 goto out;
120} 144}
121 145
122/* NFS_PROTO call done callback routines */ 146/* NFS_PROTO call done callback routines */
@@ -173,7 +197,7 @@ static void filelayout_read_prepare(struct rpc_task *task, void *data)
173 197
174 if (nfs41_setup_sequence(rdata->ds_clp->cl_session, 198 if (nfs41_setup_sequence(rdata->ds_clp->cl_session,
175 &rdata->args.seq_args, &rdata->res.seq_res, 199 &rdata->args.seq_args, &rdata->res.seq_res,
176 0, task)) 200 task))
177 return; 201 return;
178 202
179 rpc_call_start(task); 203 rpc_call_start(task);
@@ -189,10 +213,18 @@ static void filelayout_read_call_done(struct rpc_task *task, void *data)
189 rdata->mds_ops->rpc_call_done(task, data); 213 rdata->mds_ops->rpc_call_done(task, data);
190} 214}
191 215
216static void filelayout_read_count_stats(struct rpc_task *task, void *data)
217{
218 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
219
220 rpc_count_iostats(task, NFS_SERVER(rdata->inode)->client->cl_metrics);
221}
222
192static void filelayout_read_release(void *data) 223static void filelayout_read_release(void *data)
193{ 224{
194 struct nfs_read_data *rdata = (struct nfs_read_data *)data; 225 struct nfs_read_data *rdata = (struct nfs_read_data *)data;
195 226
227 put_lseg(rdata->lseg);
196 rdata->mds_ops->rpc_release(data); 228 rdata->mds_ops->rpc_release(data);
197} 229}
198 230
@@ -254,7 +286,7 @@ static void filelayout_write_prepare(struct rpc_task *task, void *data)
254 286
255 if (nfs41_setup_sequence(wdata->ds_clp->cl_session, 287 if (nfs41_setup_sequence(wdata->ds_clp->cl_session,
256 &wdata->args.seq_args, &wdata->res.seq_res, 288 &wdata->args.seq_args, &wdata->res.seq_res,
257 0, task)) 289 task))
258 return; 290 return;
259 291
260 rpc_call_start(task); 292 rpc_call_start(task);
@@ -268,10 +300,18 @@ static void filelayout_write_call_done(struct rpc_task *task, void *data)
268 wdata->mds_ops->rpc_call_done(task, data); 300 wdata->mds_ops->rpc_call_done(task, data);
269} 301}
270 302
303static void filelayout_write_count_stats(struct rpc_task *task, void *data)
304{
305 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
306
307 rpc_count_iostats(task, NFS_SERVER(wdata->inode)->client->cl_metrics);
308}
309
271static void filelayout_write_release(void *data) 310static void filelayout_write_release(void *data)
272{ 311{
273 struct nfs_write_data *wdata = (struct nfs_write_data *)data; 312 struct nfs_write_data *wdata = (struct nfs_write_data *)data;
274 313
314 put_lseg(wdata->lseg);
275 wdata->mds_ops->rpc_release(data); 315 wdata->mds_ops->rpc_release(data);
276} 316}
277 317
@@ -282,24 +322,28 @@ static void filelayout_commit_release(void *data)
282 nfs_commit_release_pages(wdata); 322 nfs_commit_release_pages(wdata);
283 if (atomic_dec_and_test(&NFS_I(wdata->inode)->commits_outstanding)) 323 if (atomic_dec_and_test(&NFS_I(wdata->inode)->commits_outstanding))
284 nfs_commit_clear_lock(NFS_I(wdata->inode)); 324 nfs_commit_clear_lock(NFS_I(wdata->inode));
325 put_lseg(wdata->lseg);
285 nfs_commitdata_release(wdata); 326 nfs_commitdata_release(wdata);
286} 327}
287 328
288struct rpc_call_ops filelayout_read_call_ops = { 329static const struct rpc_call_ops filelayout_read_call_ops = {
289 .rpc_call_prepare = filelayout_read_prepare, 330 .rpc_call_prepare = filelayout_read_prepare,
290 .rpc_call_done = filelayout_read_call_done, 331 .rpc_call_done = filelayout_read_call_done,
332 .rpc_count_stats = filelayout_read_count_stats,
291 .rpc_release = filelayout_read_release, 333 .rpc_release = filelayout_read_release,
292}; 334};
293 335
294struct rpc_call_ops filelayout_write_call_ops = { 336static const struct rpc_call_ops filelayout_write_call_ops = {
295 .rpc_call_prepare = filelayout_write_prepare, 337 .rpc_call_prepare = filelayout_write_prepare,
296 .rpc_call_done = filelayout_write_call_done, 338 .rpc_call_done = filelayout_write_call_done,
339 .rpc_count_stats = filelayout_write_count_stats,
297 .rpc_release = filelayout_write_release, 340 .rpc_release = filelayout_write_release,
298}; 341};
299 342
300struct rpc_call_ops filelayout_commit_call_ops = { 343static const struct rpc_call_ops filelayout_commit_call_ops = {
301 .rpc_call_prepare = filelayout_write_prepare, 344 .rpc_call_prepare = filelayout_write_prepare,
302 .rpc_call_done = filelayout_write_call_done, 345 .rpc_call_done = filelayout_write_call_done,
346 .rpc_count_stats = filelayout_write_count_stats,
303 .rpc_release = filelayout_commit_release, 347 .rpc_release = filelayout_commit_release,
304}; 348};
305 349
@@ -367,7 +411,8 @@ filelayout_write_pagelist(struct nfs_write_data *data, int sync)
367 idx = nfs4_fl_calc_ds_index(lseg, j); 411 idx = nfs4_fl_calc_ds_index(lseg, j);
368 ds = nfs4_fl_prepare_ds(lseg, idx); 412 ds = nfs4_fl_prepare_ds(lseg, idx);
369 if (!ds) { 413 if (!ds) {
370 printk(KERN_ERR "%s: prepare_ds failed, use MDS\n", __func__); 414 printk(KERN_ERR "NFS: %s: prepare_ds failed, use MDS\n",
415 __func__);
371 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags); 416 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
372 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags); 417 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
373 return PNFS_NOT_ATTEMPTED; 418 return PNFS_NOT_ATTEMPTED;
@@ -575,7 +620,7 @@ filelayout_decode_layout(struct pnfs_layout_hdr *flo,
575 goto out_err_free; 620 goto out_err_free;
576 fl->fh_array[i]->size = be32_to_cpup(p++); 621 fl->fh_array[i]->size = be32_to_cpup(p++);
577 if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) { 622 if (sizeof(struct nfs_fh) < fl->fh_array[i]->size) {
578 printk(KERN_ERR "Too big fh %d received %d\n", 623 printk(KERN_ERR "NFS: Too big fh %d received %d\n",
579 i, fl->fh_array[i]->size); 624 i, fl->fh_array[i]->size);
580 goto out_err_free; 625 goto out_err_free;
581 } 626 }
@@ -640,14 +685,16 @@ filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid,
640 int size = (fl->stripe_type == STRIPE_SPARSE) ? 685 int size = (fl->stripe_type == STRIPE_SPARSE) ?
641 fl->dsaddr->ds_num : fl->dsaddr->stripe_count; 686 fl->dsaddr->ds_num : fl->dsaddr->stripe_count;
642 687
643 fl->commit_buckets = kcalloc(size, sizeof(struct list_head), gfp_flags); 688 fl->commit_buckets = kcalloc(size, sizeof(struct nfs4_fl_commit_bucket), gfp_flags);
644 if (!fl->commit_buckets) { 689 if (!fl->commit_buckets) {
645 filelayout_free_lseg(&fl->generic_hdr); 690 filelayout_free_lseg(&fl->generic_hdr);
646 return NULL; 691 return NULL;
647 } 692 }
648 fl->number_of_buckets = size; 693 fl->number_of_buckets = size;
649 for (i = 0; i < size; i++) 694 for (i = 0; i < size; i++) {
650 INIT_LIST_HEAD(&fl->commit_buckets[i]); 695 INIT_LIST_HEAD(&fl->commit_buckets[i].written);
696 INIT_LIST_HEAD(&fl->commit_buckets[i].committing);
697 }
651 } 698 }
652 return &fl->generic_hdr; 699 return &fl->generic_hdr;
653} 700}
@@ -679,7 +726,7 @@ filelayout_pg_test(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev,
679 return (p_stripe == r_stripe); 726 return (p_stripe == r_stripe);
680} 727}
681 728
682void 729static void
683filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio, 730filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio,
684 struct nfs_page *req) 731 struct nfs_page *req)
685{ 732{
@@ -696,7 +743,7 @@ filelayout_pg_init_read(struct nfs_pageio_descriptor *pgio,
696 nfs_pageio_reset_read_mds(pgio); 743 nfs_pageio_reset_read_mds(pgio);
697} 744}
698 745
699void 746static void
700filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio, 747filelayout_pg_init_write(struct nfs_pageio_descriptor *pgio,
701 struct nfs_page *req) 748 struct nfs_page *req)
702{ 749{
@@ -725,11 +772,6 @@ static const struct nfs_pageio_ops filelayout_pg_write_ops = {
725 .pg_doio = pnfs_generic_pg_writepages, 772 .pg_doio = pnfs_generic_pg_writepages,
726}; 773};
727 774
728static bool filelayout_mark_pnfs_commit(struct pnfs_layout_segment *lseg)
729{
730 return !FILELAYOUT_LSEG(lseg)->commit_through_mds;
731}
732
733static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j) 775static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
734{ 776{
735 if (fl->stripe_type == STRIPE_SPARSE) 777 if (fl->stripe_type == STRIPE_SPARSE)
@@ -738,13 +780,49 @@ static u32 select_bucket_index(struct nfs4_filelayout_segment *fl, u32 j)
738 return j; 780 return j;
739} 781}
740 782
741struct list_head *filelayout_choose_commit_list(struct nfs_page *req) 783/* The generic layer is about to remove the req from the commit list.
784 * If this will make the bucket empty, it will need to put the lseg reference.
785 */
786static void
787filelayout_clear_request_commit(struct nfs_page *req)
788{
789 struct pnfs_layout_segment *freeme = NULL;
790 struct inode *inode = req->wb_context->dentry->d_inode;
791
792 spin_lock(&inode->i_lock);
793 if (!test_and_clear_bit(PG_COMMIT_TO_DS, &req->wb_flags))
794 goto out;
795 if (list_is_singular(&req->wb_list)) {
796 struct inode *inode = req->wb_context->dentry->d_inode;
797 struct pnfs_layout_segment *lseg;
798
799 /* From here we can find the bucket, but for the moment,
800 * since there is only one relevant lseg...
801 */
802 list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list) {
803 if (lseg->pls_range.iomode == IOMODE_RW) {
804 freeme = lseg;
805 break;
806 }
807 }
808 }
809out:
810 nfs_request_remove_commit_list(req);
811 spin_unlock(&inode->i_lock);
812 put_lseg(freeme);
813}
814
815static struct list_head *
816filelayout_choose_commit_list(struct nfs_page *req,
817 struct pnfs_layout_segment *lseg)
742{ 818{
743 struct pnfs_layout_segment *lseg = req->wb_commit_lseg;
744 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg); 819 struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg);
745 u32 i, j; 820 u32 i, j;
746 struct list_head *list; 821 struct list_head *list;
747 822
823 if (fl->commit_through_mds)
824 return &NFS_I(req->wb_context->dentry->d_inode)->commit_list;
825
748 /* Note that we are calling nfs4_fl_calc_j_index on each page 826 /* Note that we are calling nfs4_fl_calc_j_index on each page
749 * that ends up being committed to a data server. An attractive 827 * that ends up being committed to a data server. An attractive
750 * alternative is to add a field to nfs_write_data and nfs_page 828 * alternative is to add a field to nfs_write_data and nfs_page
@@ -754,14 +832,30 @@ struct list_head *filelayout_choose_commit_list(struct nfs_page *req)
754 j = nfs4_fl_calc_j_index(lseg, 832 j = nfs4_fl_calc_j_index(lseg,
755 (loff_t)req->wb_index << PAGE_CACHE_SHIFT); 833 (loff_t)req->wb_index << PAGE_CACHE_SHIFT);
756 i = select_bucket_index(fl, j); 834 i = select_bucket_index(fl, j);
757 list = &fl->commit_buckets[i]; 835 list = &fl->commit_buckets[i].written;
758 if (list_empty(list)) { 836 if (list_empty(list)) {
759 /* Non-empty buckets hold a reference on the lseg */ 837 /* Non-empty buckets hold a reference on the lseg. That ref
838 * is normally transferred to the COMMIT call and released
839 * there. It could also be released if the last req is pulled
840 * off due to a rewrite, in which case it will be done in
841 * filelayout_remove_commit_req
842 */
760 get_lseg(lseg); 843 get_lseg(lseg);
761 } 844 }
845 set_bit(PG_COMMIT_TO_DS, &req->wb_flags);
762 return list; 846 return list;
763} 847}
764 848
849static void
850filelayout_mark_request_commit(struct nfs_page *req,
851 struct pnfs_layout_segment *lseg)
852{
853 struct list_head *list;
854
855 list = filelayout_choose_commit_list(req, lseg);
856 nfs_request_add_commit_list(req, list);
857}
858
765static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i) 859static u32 calc_ds_index_from_commit(struct pnfs_layout_segment *lseg, u32 i)
766{ 860{
767 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg); 861 struct nfs4_filelayout_segment *flseg = FILELAYOUT_LSEG(lseg);
@@ -797,11 +891,12 @@ static int filelayout_initiate_commit(struct nfs_write_data *data, int how)
797 idx = calc_ds_index_from_commit(lseg, data->ds_commit_index); 891 idx = calc_ds_index_from_commit(lseg, data->ds_commit_index);
798 ds = nfs4_fl_prepare_ds(lseg, idx); 892 ds = nfs4_fl_prepare_ds(lseg, idx);
799 if (!ds) { 893 if (!ds) {
800 printk(KERN_ERR "%s: prepare_ds failed, use MDS\n", __func__); 894 printk(KERN_ERR "NFS: %s: prepare_ds failed, use MDS\n",
895 __func__);
801 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags); 896 set_bit(lo_fail_bit(IOMODE_RW), &lseg->pls_layout->plh_flags);
802 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags); 897 set_bit(lo_fail_bit(IOMODE_READ), &lseg->pls_layout->plh_flags);
803 prepare_to_resend_writes(data); 898 prepare_to_resend_writes(data);
804 data->mds_ops->rpc_release(data); 899 filelayout_commit_release(data);
805 return -EAGAIN; 900 return -EAGAIN;
806 } 901 }
807 dprintk("%s ino %lu, how %d\n", __func__, data->inode->i_ino, how); 902 dprintk("%s ino %lu, how %d\n", __func__, data->inode->i_ino, how);
@@ -817,24 +912,87 @@ static int filelayout_initiate_commit(struct nfs_write_data *data, int how)
817/* 912/*
818 * This is only useful while we are using whole file layouts. 913 * This is only useful while we are using whole file layouts.
819 */ 914 */
820static struct pnfs_layout_segment *find_only_write_lseg(struct inode *inode) 915static struct pnfs_layout_segment *
916find_only_write_lseg_locked(struct inode *inode)
821{ 917{
822 struct pnfs_layout_segment *lseg, *rv = NULL; 918 struct pnfs_layout_segment *lseg;
823 919
824 spin_lock(&inode->i_lock);
825 list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list) 920 list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list)
826 if (lseg->pls_range.iomode == IOMODE_RW) 921 if (lseg->pls_range.iomode == IOMODE_RW)
827 rv = get_lseg(lseg); 922 return lseg;
923 return NULL;
924}
925
926static struct pnfs_layout_segment *find_only_write_lseg(struct inode *inode)
927{
928 struct pnfs_layout_segment *rv;
929
930 spin_lock(&inode->i_lock);
931 rv = find_only_write_lseg_locked(inode);
932 if (rv)
933 get_lseg(rv);
828 spin_unlock(&inode->i_lock); 934 spin_unlock(&inode->i_lock);
829 return rv; 935 return rv;
830} 936}
831 937
832static int alloc_ds_commits(struct inode *inode, struct list_head *list) 938static int
939filelayout_scan_ds_commit_list(struct nfs4_fl_commit_bucket *bucket, int max,
940 spinlock_t *lock)
941{
942 struct list_head *src = &bucket->written;
943 struct list_head *dst = &bucket->committing;
944 struct nfs_page *req, *tmp;
945 int ret = 0;
946
947 list_for_each_entry_safe(req, tmp, src, wb_list) {
948 if (!nfs_lock_request(req))
949 continue;
950 if (cond_resched_lock(lock))
951 list_safe_reset_next(req, tmp, wb_list);
952 nfs_request_remove_commit_list(req);
953 clear_bit(PG_COMMIT_TO_DS, &req->wb_flags);
954 nfs_list_add_request(req, dst);
955 ret++;
956 if (ret == max)
957 break;
958 }
959 return ret;
960}
961
962/* Move reqs from written to committing lists, returning count of number moved.
963 * Note called with i_lock held.
964 */
965static int filelayout_scan_commit_lists(struct inode *inode, int max,
966 spinlock_t *lock)
967{
968 struct pnfs_layout_segment *lseg;
969 struct nfs4_filelayout_segment *fl;
970 int i, rv = 0, cnt;
971
972 lseg = find_only_write_lseg_locked(inode);
973 if (!lseg)
974 goto out_done;
975 fl = FILELAYOUT_LSEG(lseg);
976 if (fl->commit_through_mds)
977 goto out_done;
978 for (i = 0; i < fl->number_of_buckets && max != 0; i++) {
979 cnt = filelayout_scan_ds_commit_list(&fl->commit_buckets[i],
980 max, lock);
981 max -= cnt;
982 rv += cnt;
983 }
984out_done:
985 return rv;
986}
987
988static unsigned int
989alloc_ds_commits(struct inode *inode, struct list_head *list)
833{ 990{
834 struct pnfs_layout_segment *lseg; 991 struct pnfs_layout_segment *lseg;
835 struct nfs4_filelayout_segment *fl; 992 struct nfs4_filelayout_segment *fl;
836 struct nfs_write_data *data; 993 struct nfs_write_data *data;
837 int i, j; 994 int i, j;
995 unsigned int nreq = 0;
838 996
839 /* Won't need this when non-whole file layout segments are supported 997 /* Won't need this when non-whole file layout segments are supported
840 * instead we will use a pnfs_layout_hdr structure */ 998 * instead we will use a pnfs_layout_hdr structure */
@@ -843,28 +1001,27 @@ static int alloc_ds_commits(struct inode *inode, struct list_head *list)
843 return 0; 1001 return 0;
844 fl = FILELAYOUT_LSEG(lseg); 1002 fl = FILELAYOUT_LSEG(lseg);
845 for (i = 0; i < fl->number_of_buckets; i++) { 1003 for (i = 0; i < fl->number_of_buckets; i++) {
846 if (list_empty(&fl->commit_buckets[i])) 1004 if (list_empty(&fl->commit_buckets[i].committing))
847 continue; 1005 continue;
848 data = nfs_commitdata_alloc(); 1006 data = nfs_commitdata_alloc();
849 if (!data) 1007 if (!data)
850 goto out_bad; 1008 break;
851 data->ds_commit_index = i; 1009 data->ds_commit_index = i;
852 data->lseg = lseg; 1010 data->lseg = lseg;
853 list_add(&data->pages, list); 1011 list_add(&data->pages, list);
1012 nreq++;
854 } 1013 }
855 put_lseg(lseg);
856 return 0;
857 1014
858out_bad: 1015 /* Clean up on error */
859 for (j = i; j < fl->number_of_buckets; j++) { 1016 for (j = i; j < fl->number_of_buckets; j++) {
860 if (list_empty(&fl->commit_buckets[i])) 1017 if (list_empty(&fl->commit_buckets[i].committing))
861 continue; 1018 continue;
862 nfs_retry_commit(&fl->commit_buckets[i], lseg); 1019 nfs_retry_commit(&fl->commit_buckets[i].committing, lseg);
863 put_lseg(lseg); /* associated with emptying bucket */ 1020 put_lseg(lseg); /* associated with emptying bucket */
864 } 1021 }
865 put_lseg(lseg); 1022 put_lseg(lseg);
866 /* Caller will clean up entries put on list */ 1023 /* Caller will clean up entries put on list */
867 return -ENOMEM; 1024 return nreq;
868} 1025}
869 1026
870/* This follows nfs_commit_list pretty closely */ 1027/* This follows nfs_commit_list pretty closely */
@@ -874,40 +1031,40 @@ filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
874{ 1031{
875 struct nfs_write_data *data, *tmp; 1032 struct nfs_write_data *data, *tmp;
876 LIST_HEAD(list); 1033 LIST_HEAD(list);
1034 unsigned int nreq = 0;
877 1035
878 if (!list_empty(mds_pages)) { 1036 if (!list_empty(mds_pages)) {
879 data = nfs_commitdata_alloc(); 1037 data = nfs_commitdata_alloc();
880 if (!data) 1038 if (data != NULL) {
881 goto out_bad; 1039 data->lseg = NULL;
882 data->lseg = NULL; 1040 list_add(&data->pages, &list);
883 list_add(&data->pages, &list); 1041 nreq++;
1042 } else
1043 nfs_retry_commit(mds_pages, NULL);
884 } 1044 }
885 1045
886 if (alloc_ds_commits(inode, &list)) 1046 nreq += alloc_ds_commits(inode, &list);
887 goto out_bad; 1047
1048 if (nreq == 0) {
1049 nfs_commit_clear_lock(NFS_I(inode));
1050 goto out;
1051 }
1052
1053 atomic_add(nreq, &NFS_I(inode)->commits_outstanding);
888 1054
889 list_for_each_entry_safe(data, tmp, &list, pages) { 1055 list_for_each_entry_safe(data, tmp, &list, pages) {
890 list_del_init(&data->pages); 1056 list_del_init(&data->pages);
891 atomic_inc(&NFS_I(inode)->commits_outstanding);
892 if (!data->lseg) { 1057 if (!data->lseg) {
893 nfs_init_commit(data, mds_pages, NULL); 1058 nfs_init_commit(data, mds_pages, NULL);
894 nfs_initiate_commit(data, NFS_CLIENT(inode), 1059 nfs_initiate_commit(data, NFS_CLIENT(inode),
895 data->mds_ops, how); 1060 data->mds_ops, how);
896 } else { 1061 } else {
897 nfs_init_commit(data, &FILELAYOUT_LSEG(data->lseg)->commit_buckets[data->ds_commit_index], data->lseg); 1062 nfs_init_commit(data, &FILELAYOUT_LSEG(data->lseg)->commit_buckets[data->ds_commit_index].committing, data->lseg);
898 filelayout_initiate_commit(data, how); 1063 filelayout_initiate_commit(data, how);
899 } 1064 }
900 } 1065 }
901 return 0; 1066out:
902 out_bad: 1067 return PNFS_ATTEMPTED;
903 list_for_each_entry_safe(data, tmp, &list, pages) {
904 nfs_retry_commit(&data->pages, data->lseg);
905 list_del_init(&data->pages);
906 nfs_commit_free(data);
907 }
908 nfs_retry_commit(mds_pages, NULL);
909 nfs_commit_clear_lock(NFS_I(inode));
910 return -ENOMEM;
911} 1068}
912 1069
913static void 1070static void
@@ -924,8 +1081,9 @@ static struct pnfs_layoutdriver_type filelayout_type = {
924 .free_lseg = filelayout_free_lseg, 1081 .free_lseg = filelayout_free_lseg,
925 .pg_read_ops = &filelayout_pg_read_ops, 1082 .pg_read_ops = &filelayout_pg_read_ops,
926 .pg_write_ops = &filelayout_pg_write_ops, 1083 .pg_write_ops = &filelayout_pg_write_ops,
927 .mark_pnfs_commit = filelayout_mark_pnfs_commit, 1084 .mark_request_commit = filelayout_mark_request_commit,
928 .choose_commit_list = filelayout_choose_commit_list, 1085 .clear_request_commit = filelayout_clear_request_commit,
1086 .scan_commit_lists = filelayout_scan_commit_lists,
929 .commit_pagelist = filelayout_commit_pagelist, 1087 .commit_pagelist = filelayout_commit_pagelist,
930 .read_pagelist = filelayout_read_pagelist, 1088 .read_pagelist = filelayout_read_pagelist,
931 .write_pagelist = filelayout_write_pagelist, 1089 .write_pagelist = filelayout_write_pagelist,
diff --git a/fs/nfs/nfs4filelayout.h b/fs/nfs/nfs4filelayout.h
index 2e42284253f..21190bb1f5e 100644
--- a/fs/nfs/nfs4filelayout.h
+++ b/fs/nfs/nfs4filelayout.h
@@ -74,6 +74,11 @@ struct nfs4_file_layout_dsaddr {
74 struct nfs4_pnfs_ds *ds_list[1]; 74 struct nfs4_pnfs_ds *ds_list[1];
75}; 75};
76 76
77struct nfs4_fl_commit_bucket {
78 struct list_head written;
79 struct list_head committing;
80};
81
77struct nfs4_filelayout_segment { 82struct nfs4_filelayout_segment {
78 struct pnfs_layout_segment generic_hdr; 83 struct pnfs_layout_segment generic_hdr;
79 u32 stripe_type; 84 u32 stripe_type;
@@ -84,7 +89,7 @@ struct nfs4_filelayout_segment {
84 struct nfs4_file_layout_dsaddr *dsaddr; /* Point to GETDEVINFO data */ 89 struct nfs4_file_layout_dsaddr *dsaddr; /* Point to GETDEVINFO data */
85 unsigned int num_fh; 90 unsigned int num_fh;
86 struct nfs_fh **fh_array; 91 struct nfs_fh **fh_array;
87 struct list_head *commit_buckets; /* Sort commits to ds */ 92 struct nfs4_fl_commit_bucket *commit_buckets; /* Sort commits to ds */
88 int number_of_buckets; 93 int number_of_buckets;
89}; 94};
90 95
diff --git a/fs/nfs/nfs4filelayoutdev.c b/fs/nfs/nfs4filelayoutdev.c
index 8ae91908f5a..a866bbd2890 100644
--- a/fs/nfs/nfs4filelayoutdev.c
+++ b/fs/nfs/nfs4filelayoutdev.c
@@ -45,7 +45,7 @@
45 * - incremented when a device id maps a data server already in the cache. 45 * - incremented when a device id maps a data server already in the cache.
46 * - decremented when deviceid is removed from the cache. 46 * - decremented when deviceid is removed from the cache.
47 */ 47 */
48DEFINE_SPINLOCK(nfs4_ds_cache_lock); 48static DEFINE_SPINLOCK(nfs4_ds_cache_lock);
49static LIST_HEAD(nfs4_data_server_cache); 49static LIST_HEAD(nfs4_data_server_cache);
50 50
51/* Debug routines */ 51/* Debug routines */
@@ -108,58 +108,40 @@ same_sockaddr(struct sockaddr *addr1, struct sockaddr *addr2)
108 return false; 108 return false;
109} 109}
110 110
111/* 111static bool
112 * Lookup DS by addresses. The first matching address returns true. 112_same_data_server_addrs_locked(const struct list_head *dsaddrs1,
113 * nfs4_ds_cache_lock is held 113 const struct list_head *dsaddrs2)
114 */
115static struct nfs4_pnfs_ds *
116_data_server_lookup_locked(struct list_head *dsaddrs)
117{ 114{
118 struct nfs4_pnfs_ds *ds;
119 struct nfs4_pnfs_ds_addr *da1, *da2; 115 struct nfs4_pnfs_ds_addr *da1, *da2;
120 116
121 list_for_each_entry(da1, dsaddrs, da_node) { 117 /* step through both lists, comparing as we go */
122 list_for_each_entry(ds, &nfs4_data_server_cache, ds_node) { 118 for (da1 = list_first_entry(dsaddrs1, typeof(*da1), da_node),
123 list_for_each_entry(da2, &ds->ds_addrs, da_node) { 119 da2 = list_first_entry(dsaddrs2, typeof(*da2), da_node);
124 if (same_sockaddr( 120 da1 != NULL && da2 != NULL;
125 (struct sockaddr *)&da1->da_addr, 121 da1 = list_entry(da1->da_node.next, typeof(*da1), da_node),
126 (struct sockaddr *)&da2->da_addr)) 122 da2 = list_entry(da2->da_node.next, typeof(*da2), da_node)) {
127 return ds; 123 if (!same_sockaddr((struct sockaddr *)&da1->da_addr,
128 } 124 (struct sockaddr *)&da2->da_addr))
129 } 125 return false;
130 } 126 }
131 return NULL; 127 if (da1 == NULL && da2 == NULL)
128 return true;
129
130 return false;
132} 131}
133 132
134/* 133/*
135 * Compare two lists of addresses. 134 * Lookup DS by addresses. nfs4_ds_cache_lock is held
136 */ 135 */
137static bool 136static struct nfs4_pnfs_ds *
138_data_server_match_all_addrs_locked(struct list_head *dsaddrs1, 137_data_server_lookup_locked(const struct list_head *dsaddrs)
139 struct list_head *dsaddrs2)
140{ 138{
141 struct nfs4_pnfs_ds_addr *da1, *da2; 139 struct nfs4_pnfs_ds *ds;
142 size_t count1 = 0,
143 count2 = 0;
144
145 list_for_each_entry(da1, dsaddrs1, da_node)
146 count1++;
147
148 list_for_each_entry(da2, dsaddrs2, da_node) {
149 bool found = false;
150 count2++;
151 list_for_each_entry(da1, dsaddrs1, da_node) {
152 if (same_sockaddr((struct sockaddr *)&da1->da_addr,
153 (struct sockaddr *)&da2->da_addr)) {
154 found = true;
155 break;
156 }
157 }
158 if (!found)
159 return false;
160 }
161 140
162 return (count1 == count2); 141 list_for_each_entry(ds, &nfs4_data_server_cache, ds_node)
142 if (_same_data_server_addrs_locked(&ds->ds_addrs, dsaddrs))
143 return ds;
144 return NULL;
163} 145}
164 146
165/* 147/*
@@ -356,11 +338,6 @@ nfs4_pnfs_ds_add(struct list_head *dsaddrs, gfp_t gfp_flags)
356 dprintk("%s add new data server %s\n", __func__, 338 dprintk("%s add new data server %s\n", __func__,
357 ds->ds_remotestr); 339 ds->ds_remotestr);
358 } else { 340 } else {
359 if (!_data_server_match_all_addrs_locked(&tmp_ds->ds_addrs,
360 dsaddrs)) {
361 dprintk("%s: multipath address mismatch: %s != %s",
362 __func__, tmp_ds->ds_remotestr, remotestr);
363 }
364 kfree(remotestr); 341 kfree(remotestr);
365 kfree(ds); 342 kfree(ds);
366 atomic_inc(&tmp_ds->ds_count); 343 atomic_inc(&tmp_ds->ds_count);
@@ -378,7 +355,7 @@ out:
378 * Currently only supports ipv4, ipv6 and one multi-path address. 355 * Currently only supports ipv4, ipv6 and one multi-path address.
379 */ 356 */
380static struct nfs4_pnfs_ds_addr * 357static struct nfs4_pnfs_ds_addr *
381decode_ds_addr(struct xdr_stream *streamp, gfp_t gfp_flags) 358decode_ds_addr(struct net *net, struct xdr_stream *streamp, gfp_t gfp_flags)
382{ 359{
383 struct nfs4_pnfs_ds_addr *da = NULL; 360 struct nfs4_pnfs_ds_addr *da = NULL;
384 char *buf, *portstr; 361 char *buf, *portstr;
@@ -457,7 +434,7 @@ decode_ds_addr(struct xdr_stream *streamp, gfp_t gfp_flags)
457 434
458 INIT_LIST_HEAD(&da->da_node); 435 INIT_LIST_HEAD(&da->da_node);
459 436
460 if (!rpc_pton(buf, portstr-buf, (struct sockaddr *)&da->da_addr, 437 if (!rpc_pton(net, buf, portstr-buf, (struct sockaddr *)&da->da_addr,
461 sizeof(da->da_addr))) { 438 sizeof(da->da_addr))) {
462 dprintk("%s: error parsing address %s\n", __func__, buf); 439 dprintk("%s: error parsing address %s\n", __func__, buf);
463 goto out_free_da; 440 goto out_free_da;
@@ -554,7 +531,7 @@ decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
554 cnt = be32_to_cpup(p); 531 cnt = be32_to_cpup(p);
555 dprintk("%s stripe count %d\n", __func__, cnt); 532 dprintk("%s stripe count %d\n", __func__, cnt);
556 if (cnt > NFS4_PNFS_MAX_STRIPE_CNT) { 533 if (cnt > NFS4_PNFS_MAX_STRIPE_CNT) {
557 printk(KERN_WARNING "%s: stripe count %d greater than " 534 printk(KERN_WARNING "NFS: %s: stripe count %d greater than "
558 "supported maximum %d\n", __func__, 535 "supported maximum %d\n", __func__,
559 cnt, NFS4_PNFS_MAX_STRIPE_CNT); 536 cnt, NFS4_PNFS_MAX_STRIPE_CNT);
560 goto out_err_free_scratch; 537 goto out_err_free_scratch;
@@ -585,7 +562,7 @@ decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
585 num = be32_to_cpup(p); 562 num = be32_to_cpup(p);
586 dprintk("%s ds_num %u\n", __func__, num); 563 dprintk("%s ds_num %u\n", __func__, num);
587 if (num > NFS4_PNFS_MAX_MULTI_CNT) { 564 if (num > NFS4_PNFS_MAX_MULTI_CNT) {
588 printk(KERN_WARNING "%s: multipath count %d greater than " 565 printk(KERN_WARNING "NFS: %s: multipath count %d greater than "
589 "supported maximum %d\n", __func__, 566 "supported maximum %d\n", __func__,
590 num, NFS4_PNFS_MAX_MULTI_CNT); 567 num, NFS4_PNFS_MAX_MULTI_CNT);
591 goto out_err_free_stripe_indices; 568 goto out_err_free_stripe_indices;
@@ -593,7 +570,7 @@ decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
593 570
594 /* validate stripe indices are all < num */ 571 /* validate stripe indices are all < num */
595 if (max_stripe_index >= num) { 572 if (max_stripe_index >= num) {
596 printk(KERN_WARNING "%s: stripe index %u >= num ds %u\n", 573 printk(KERN_WARNING "NFS: %s: stripe index %u >= num ds %u\n",
597 __func__, max_stripe_index, num); 574 __func__, max_stripe_index, num);
598 goto out_err_free_stripe_indices; 575 goto out_err_free_stripe_indices;
599 } 576 }
@@ -625,7 +602,8 @@ decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
625 602
626 mp_count = be32_to_cpup(p); /* multipath count */ 603 mp_count = be32_to_cpup(p); /* multipath count */
627 for (j = 0; j < mp_count; j++) { 604 for (j = 0; j < mp_count; j++) {
628 da = decode_ds_addr(&stream, gfp_flags); 605 da = decode_ds_addr(NFS_SERVER(ino)->nfs_client->net,
606 &stream, gfp_flags);
629 if (da) 607 if (da)
630 list_add_tail(&da->da_node, &dsaddrs); 608 list_add_tail(&da->da_node, &dsaddrs);
631 } 609 }
@@ -686,7 +664,7 @@ decode_and_add_device(struct inode *inode, struct pnfs_device *dev, gfp_t gfp_fl
686 664
687 new = decode_device(inode, dev, gfp_flags); 665 new = decode_device(inode, dev, gfp_flags);
688 if (!new) { 666 if (!new) {
689 printk(KERN_WARNING "%s: Could not decode or add device\n", 667 printk(KERN_WARNING "NFS: %s: Could not decode or add device\n",
690 __func__); 668 __func__);
691 return NULL; 669 return NULL;
692 } 670 }
@@ -835,7 +813,7 @@ nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg, u32 ds_idx)
835 struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx]; 813 struct nfs4_pnfs_ds *ds = dsaddr->ds_list[ds_idx];
836 814
837 if (ds == NULL) { 815 if (ds == NULL) {
838 printk(KERN_ERR "%s: No data server for offset index %d\n", 816 printk(KERN_ERR "NFS: %s: No data server for offset index %d\n",
839 __func__, ds_idx); 817 __func__, ds_idx);
840 return NULL; 818 return NULL;
841 } 819 }
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index bb80c49b653..9c8eca315f4 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -94,13 +94,14 @@ static int nfs4_validate_fspath(struct dentry *dentry,
94} 94}
95 95
96static size_t nfs_parse_server_name(char *string, size_t len, 96static size_t nfs_parse_server_name(char *string, size_t len,
97 struct sockaddr *sa, size_t salen) 97 struct sockaddr *sa, size_t salen, struct nfs_server *server)
98{ 98{
99 struct net *net = rpc_net_ns(server->client);
99 ssize_t ret; 100 ssize_t ret;
100 101
101 ret = rpc_pton(string, len, sa, salen); 102 ret = rpc_pton(net, string, len, sa, salen);
102 if (ret == 0) { 103 if (ret == 0) {
103 ret = nfs_dns_resolve_name(string, len, sa, salen); 104 ret = nfs_dns_resolve_name(net, string, len, sa, salen);
104 if (ret < 0) 105 if (ret < 0)
105 ret = 0; 106 ret = 0;
106 } 107 }
@@ -137,7 +138,8 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
137 continue; 138 continue;
138 139
139 mountdata->addrlen = nfs_parse_server_name(buf->data, buf->len, 140 mountdata->addrlen = nfs_parse_server_name(buf->data, buf->len,
140 mountdata->addr, addr_bufsize); 141 mountdata->addr, addr_bufsize,
142 NFS_SB(mountdata->sb));
141 if (mountdata->addrlen == 0) 143 if (mountdata->addrlen == 0)
142 continue; 144 continue;
143 145
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index caf92d05c3a..e809d2305eb 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -72,18 +72,21 @@
72 72
73#define NFS4_MAX_LOOP_ON_RECOVER (10) 73#define NFS4_MAX_LOOP_ON_RECOVER (10)
74 74
75static unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
76
75struct nfs4_opendata; 77struct nfs4_opendata;
76static int _nfs4_proc_open(struct nfs4_opendata *data); 78static int _nfs4_proc_open(struct nfs4_opendata *data);
77static int _nfs4_recover_proc_open(struct nfs4_opendata *data); 79static int _nfs4_recover_proc_open(struct nfs4_opendata *data);
78static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *); 80static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
79static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *); 81static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
82static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr);
80static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); 83static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
81static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred, 84static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
82 struct nfs_fattr *fattr, struct iattr *sattr, 85 struct nfs_fattr *fattr, struct iattr *sattr,
83 struct nfs4_state *state); 86 struct nfs4_state *state);
84#ifdef CONFIG_NFS_V4_1 87#ifdef CONFIG_NFS_V4_1
85static int nfs41_test_stateid(struct nfs_server *, struct nfs4_state *); 88static int nfs41_test_stateid(struct nfs_server *, nfs4_stateid *);
86static int nfs41_free_stateid(struct nfs_server *, struct nfs4_state *); 89static int nfs41_free_stateid(struct nfs_server *, nfs4_stateid *);
87#endif 90#endif
88/* Prevent leaks of NFSv4 errors into userland */ 91/* Prevent leaks of NFSv4 errors into userland */
89static int nfs4_map_errors(int err) 92static int nfs4_map_errors(int err)
@@ -259,15 +262,28 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struc
259{ 262{
260 struct nfs_client *clp = server->nfs_client; 263 struct nfs_client *clp = server->nfs_client;
261 struct nfs4_state *state = exception->state; 264 struct nfs4_state *state = exception->state;
265 struct inode *inode = exception->inode;
262 int ret = errorcode; 266 int ret = errorcode;
263 267
264 exception->retry = 0; 268 exception->retry = 0;
265 switch(errorcode) { 269 switch(errorcode) {
266 case 0: 270 case 0:
267 return 0; 271 return 0;
272 case -NFS4ERR_OPENMODE:
273 if (nfs_have_delegation(inode, FMODE_READ)) {
274 nfs_inode_return_delegation(inode);
275 exception->retry = 1;
276 return 0;
277 }
278 if (state == NULL)
279 break;
280 nfs4_schedule_stateid_recovery(server, state);
281 goto wait_on_recovery;
282 case -NFS4ERR_DELEG_REVOKED:
268 case -NFS4ERR_ADMIN_REVOKED: 283 case -NFS4ERR_ADMIN_REVOKED:
269 case -NFS4ERR_BAD_STATEID: 284 case -NFS4ERR_BAD_STATEID:
270 case -NFS4ERR_OPENMODE: 285 if (state != NULL)
286 nfs_remove_bad_delegation(state->inode);
271 if (state == NULL) 287 if (state == NULL)
272 break; 288 break;
273 nfs4_schedule_stateid_recovery(server, state); 289 nfs4_schedule_stateid_recovery(server, state);
@@ -360,16 +376,14 @@ static void renew_lease(const struct nfs_server *server, unsigned long timestamp
360 * When updating highest_used_slotid there may be "holes" in the bitmap 376 * When updating highest_used_slotid there may be "holes" in the bitmap
361 * so we need to scan down from highest_used_slotid to 0 looking for the now 377 * so we need to scan down from highest_used_slotid to 0 looking for the now
362 * highest slotid in use. 378 * highest slotid in use.
363 * If none found, highest_used_slotid is set to -1. 379 * If none found, highest_used_slotid is set to NFS4_NO_SLOT.
364 * 380 *
365 * Must be called while holding tbl->slot_tbl_lock 381 * Must be called while holding tbl->slot_tbl_lock
366 */ 382 */
367static void 383static void
368nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid) 384nfs4_free_slot(struct nfs4_slot_table *tbl, u32 slotid)
369{ 385{
370 int slotid = free_slotid; 386 BUG_ON(slotid >= NFS4_MAX_SLOT_TABLE);
371
372 BUG_ON(slotid < 0 || slotid >= NFS4_MAX_SLOT_TABLE);
373 /* clear used bit in bitmap */ 387 /* clear used bit in bitmap */
374 __clear_bit(slotid, tbl->used_slots); 388 __clear_bit(slotid, tbl->used_slots);
375 389
@@ -379,10 +393,16 @@ nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid)
379 if (slotid < tbl->max_slots) 393 if (slotid < tbl->max_slots)
380 tbl->highest_used_slotid = slotid; 394 tbl->highest_used_slotid = slotid;
381 else 395 else
382 tbl->highest_used_slotid = -1; 396 tbl->highest_used_slotid = NFS4_NO_SLOT;
383 } 397 }
384 dprintk("%s: free_slotid %u highest_used_slotid %d\n", __func__, 398 dprintk("%s: slotid %u highest_used_slotid %d\n", __func__,
385 free_slotid, tbl->highest_used_slotid); 399 slotid, tbl->highest_used_slotid);
400}
401
402bool nfs4_set_task_privileged(struct rpc_task *task, void *dummy)
403{
404 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
405 return true;
386} 406}
387 407
388/* 408/*
@@ -390,16 +410,13 @@ nfs4_free_slot(struct nfs4_slot_table *tbl, u8 free_slotid)
390 */ 410 */
391static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) 411static void nfs4_check_drain_fc_complete(struct nfs4_session *ses)
392{ 412{
393 struct rpc_task *task;
394
395 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { 413 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state)) {
396 task = rpc_wake_up_next(&ses->fc_slot_table.slot_tbl_waitq); 414 rpc_wake_up_first(&ses->fc_slot_table.slot_tbl_waitq,
397 if (task) 415 nfs4_set_task_privileged, NULL);
398 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
399 return; 416 return;
400 } 417 }
401 418
402 if (ses->fc_slot_table.highest_used_slotid != -1) 419 if (ses->fc_slot_table.highest_used_slotid != NFS4_NO_SLOT)
403 return; 420 return;
404 421
405 dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); 422 dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__);
@@ -412,7 +429,7 @@ static void nfs4_check_drain_fc_complete(struct nfs4_session *ses)
412void nfs4_check_drain_bc_complete(struct nfs4_session *ses) 429void nfs4_check_drain_bc_complete(struct nfs4_session *ses)
413{ 430{
414 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || 431 if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) ||
415 ses->bc_slot_table.highest_used_slotid != -1) 432 ses->bc_slot_table.highest_used_slotid != NFS4_NO_SLOT)
416 return; 433 return;
417 dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); 434 dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__);
418 complete(&ses->bc_slot_table.complete); 435 complete(&ses->bc_slot_table.complete);
@@ -507,25 +524,25 @@ static int nfs4_sequence_done(struct rpc_task *task,
507 * nfs4_find_slot looks for an unset bit in the used_slots bitmap. 524 * nfs4_find_slot looks for an unset bit in the used_slots bitmap.
508 * If found, we mark the slot as used, update the highest_used_slotid, 525 * If found, we mark the slot as used, update the highest_used_slotid,
509 * and respectively set up the sequence operation args. 526 * and respectively set up the sequence operation args.
510 * The slot number is returned if found, or NFS4_MAX_SLOT_TABLE otherwise. 527 * The slot number is returned if found, or NFS4_NO_SLOT otherwise.
511 * 528 *
512 * Note: must be called with under the slot_tbl_lock. 529 * Note: must be called with under the slot_tbl_lock.
513 */ 530 */
514static u8 531static u32
515nfs4_find_slot(struct nfs4_slot_table *tbl) 532nfs4_find_slot(struct nfs4_slot_table *tbl)
516{ 533{
517 int slotid; 534 u32 slotid;
518 u8 ret_id = NFS4_MAX_SLOT_TABLE; 535 u32 ret_id = NFS4_NO_SLOT;
519 BUILD_BUG_ON((u8)NFS4_MAX_SLOT_TABLE != (int)NFS4_MAX_SLOT_TABLE);
520 536
521 dprintk("--> %s used_slots=%04lx highest_used=%d max_slots=%d\n", 537 dprintk("--> %s used_slots=%04lx highest_used=%u max_slots=%u\n",
522 __func__, tbl->used_slots[0], tbl->highest_used_slotid, 538 __func__, tbl->used_slots[0], tbl->highest_used_slotid,
523 tbl->max_slots); 539 tbl->max_slots);
524 slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots); 540 slotid = find_first_zero_bit(tbl->used_slots, tbl->max_slots);
525 if (slotid >= tbl->max_slots) 541 if (slotid >= tbl->max_slots)
526 goto out; 542 goto out;
527 __set_bit(slotid, tbl->used_slots); 543 __set_bit(slotid, tbl->used_slots);
528 if (slotid > tbl->highest_used_slotid) 544 if (slotid > tbl->highest_used_slotid ||
545 tbl->highest_used_slotid == NFS4_NO_SLOT)
529 tbl->highest_used_slotid = slotid; 546 tbl->highest_used_slotid = slotid;
530 ret_id = slotid; 547 ret_id = slotid;
531out: 548out:
@@ -534,15 +551,25 @@ out:
534 return ret_id; 551 return ret_id;
535} 552}
536 553
554static void nfs41_init_sequence(struct nfs4_sequence_args *args,
555 struct nfs4_sequence_res *res, int cache_reply)
556{
557 args->sa_session = NULL;
558 args->sa_cache_this = 0;
559 if (cache_reply)
560 args->sa_cache_this = 1;
561 res->sr_session = NULL;
562 res->sr_slot = NULL;
563}
564
537int nfs41_setup_sequence(struct nfs4_session *session, 565int nfs41_setup_sequence(struct nfs4_session *session,
538 struct nfs4_sequence_args *args, 566 struct nfs4_sequence_args *args,
539 struct nfs4_sequence_res *res, 567 struct nfs4_sequence_res *res,
540 int cache_reply,
541 struct rpc_task *task) 568 struct rpc_task *task)
542{ 569{
543 struct nfs4_slot *slot; 570 struct nfs4_slot *slot;
544 struct nfs4_slot_table *tbl; 571 struct nfs4_slot_table *tbl;
545 u8 slotid; 572 u32 slotid;
546 573
547 dprintk("--> %s\n", __func__); 574 dprintk("--> %s\n", __func__);
548 /* slot already allocated? */ 575 /* slot already allocated? */
@@ -570,7 +597,7 @@ int nfs41_setup_sequence(struct nfs4_session *session,
570 } 597 }
571 598
572 slotid = nfs4_find_slot(tbl); 599 slotid = nfs4_find_slot(tbl);
573 if (slotid == NFS4_MAX_SLOT_TABLE) { 600 if (slotid == NFS4_NO_SLOT) {
574 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL); 601 rpc_sleep_on(&tbl->slot_tbl_waitq, task, NULL);
575 spin_unlock(&tbl->slot_tbl_lock); 602 spin_unlock(&tbl->slot_tbl_lock);
576 dprintk("<-- %s: no free slots\n", __func__); 603 dprintk("<-- %s: no free slots\n", __func__);
@@ -582,7 +609,6 @@ int nfs41_setup_sequence(struct nfs4_session *session,
582 slot = tbl->slots + slotid; 609 slot = tbl->slots + slotid;
583 args->sa_session = session; 610 args->sa_session = session;
584 args->sa_slotid = slotid; 611 args->sa_slotid = slotid;
585 args->sa_cache_this = cache_reply;
586 612
587 dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr); 613 dprintk("<-- %s slotid=%d seqid=%d\n", __func__, slotid, slot->seq_nr);
588 614
@@ -602,24 +628,19 @@ EXPORT_SYMBOL_GPL(nfs41_setup_sequence);
602int nfs4_setup_sequence(const struct nfs_server *server, 628int nfs4_setup_sequence(const struct nfs_server *server,
603 struct nfs4_sequence_args *args, 629 struct nfs4_sequence_args *args,
604 struct nfs4_sequence_res *res, 630 struct nfs4_sequence_res *res,
605 int cache_reply,
606 struct rpc_task *task) 631 struct rpc_task *task)
607{ 632{
608 struct nfs4_session *session = nfs4_get_session(server); 633 struct nfs4_session *session = nfs4_get_session(server);
609 int ret = 0; 634 int ret = 0;
610 635
611 if (session == NULL) { 636 if (session == NULL)
612 args->sa_session = NULL;
613 res->sr_session = NULL;
614 goto out; 637 goto out;
615 }
616 638
617 dprintk("--> %s clp %p session %p sr_slot %td\n", 639 dprintk("--> %s clp %p session %p sr_slot %td\n",
618 __func__, session->clp, session, res->sr_slot ? 640 __func__, session->clp, session, res->sr_slot ?
619 res->sr_slot - session->fc_slot_table.slots : -1); 641 res->sr_slot - session->fc_slot_table.slots : -1);
620 642
621 ret = nfs41_setup_sequence(session, args, res, cache_reply, 643 ret = nfs41_setup_sequence(session, args, res, task);
622 task);
623out: 644out:
624 dprintk("<-- %s status=%d\n", __func__, ret); 645 dprintk("<-- %s status=%d\n", __func__, ret);
625 return ret; 646 return ret;
@@ -629,7 +650,6 @@ struct nfs41_call_sync_data {
629 const struct nfs_server *seq_server; 650 const struct nfs_server *seq_server;
630 struct nfs4_sequence_args *seq_args; 651 struct nfs4_sequence_args *seq_args;
631 struct nfs4_sequence_res *seq_res; 652 struct nfs4_sequence_res *seq_res;
632 int cache_reply;
633}; 653};
634 654
635static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata) 655static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
@@ -639,7 +659,7 @@ static void nfs41_call_sync_prepare(struct rpc_task *task, void *calldata)
639 dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server); 659 dprintk("--> %s data->seq_server %p\n", __func__, data->seq_server);
640 660
641 if (nfs4_setup_sequence(data->seq_server, data->seq_args, 661 if (nfs4_setup_sequence(data->seq_server, data->seq_args,
642 data->seq_res, data->cache_reply, task)) 662 data->seq_res, task))
643 return; 663 return;
644 rpc_call_start(task); 664 rpc_call_start(task);
645} 665}
@@ -657,12 +677,12 @@ static void nfs41_call_sync_done(struct rpc_task *task, void *calldata)
657 nfs41_sequence_done(task, data->seq_res); 677 nfs41_sequence_done(task, data->seq_res);
658} 678}
659 679
660struct rpc_call_ops nfs41_call_sync_ops = { 680static const struct rpc_call_ops nfs41_call_sync_ops = {
661 .rpc_call_prepare = nfs41_call_sync_prepare, 681 .rpc_call_prepare = nfs41_call_sync_prepare,
662 .rpc_call_done = nfs41_call_sync_done, 682 .rpc_call_done = nfs41_call_sync_done,
663}; 683};
664 684
665struct rpc_call_ops nfs41_call_priv_sync_ops = { 685static const struct rpc_call_ops nfs41_call_priv_sync_ops = {
666 .rpc_call_prepare = nfs41_call_priv_sync_prepare, 686 .rpc_call_prepare = nfs41_call_priv_sync_prepare,
667 .rpc_call_done = nfs41_call_sync_done, 687 .rpc_call_done = nfs41_call_sync_done,
668}; 688};
@@ -672,7 +692,6 @@ static int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
672 struct rpc_message *msg, 692 struct rpc_message *msg,
673 struct nfs4_sequence_args *args, 693 struct nfs4_sequence_args *args,
674 struct nfs4_sequence_res *res, 694 struct nfs4_sequence_res *res,
675 int cache_reply,
676 int privileged) 695 int privileged)
677{ 696{
678 int ret; 697 int ret;
@@ -681,7 +700,6 @@ static int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
681 .seq_server = server, 700 .seq_server = server,
682 .seq_args = args, 701 .seq_args = args,
683 .seq_res = res, 702 .seq_res = res,
684 .cache_reply = cache_reply,
685 }; 703 };
686 struct rpc_task_setup task_setup = { 704 struct rpc_task_setup task_setup = {
687 .rpc_client = clnt, 705 .rpc_client = clnt,
@@ -690,7 +708,6 @@ static int nfs4_call_sync_sequence(struct rpc_clnt *clnt,
690 .callback_data = &data 708 .callback_data = &data
691 }; 709 };
692 710
693 res->sr_slot = NULL;
694 if (privileged) 711 if (privileged)
695 task_setup.callback_ops = &nfs41_call_priv_sync_ops; 712 task_setup.callback_ops = &nfs41_call_priv_sync_ops;
696 task = rpc_run_task(&task_setup); 713 task = rpc_run_task(&task_setup);
@@ -710,10 +727,17 @@ int _nfs4_call_sync_session(struct rpc_clnt *clnt,
710 struct nfs4_sequence_res *res, 727 struct nfs4_sequence_res *res,
711 int cache_reply) 728 int cache_reply)
712{ 729{
713 return nfs4_call_sync_sequence(clnt, server, msg, args, res, cache_reply, 0); 730 nfs41_init_sequence(args, res, cache_reply);
731 return nfs4_call_sync_sequence(clnt, server, msg, args, res, 0);
714} 732}
715 733
716#else 734#else
735static inline
736void nfs41_init_sequence(struct nfs4_sequence_args *args,
737 struct nfs4_sequence_res *res, int cache_reply)
738{
739}
740
717static int nfs4_sequence_done(struct rpc_task *task, 741static int nfs4_sequence_done(struct rpc_task *task,
718 struct nfs4_sequence_res *res) 742 struct nfs4_sequence_res *res)
719{ 743{
@@ -728,7 +752,7 @@ int _nfs4_call_sync(struct rpc_clnt *clnt,
728 struct nfs4_sequence_res *res, 752 struct nfs4_sequence_res *res,
729 int cache_reply) 753 int cache_reply)
730{ 754{
731 args->sa_session = res->sr_session = NULL; 755 nfs41_init_sequence(args, res, cache_reply);
732 return rpc_call_sync(clnt, msg, 0); 756 return rpc_call_sync(clnt, msg, 0);
733} 757}
734 758
@@ -815,20 +839,22 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
815 p->o_arg.open_flags = flags; 839 p->o_arg.open_flags = flags;
816 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE); 840 p->o_arg.fmode = fmode & (FMODE_READ|FMODE_WRITE);
817 p->o_arg.clientid = server->nfs_client->cl_clientid; 841 p->o_arg.clientid = server->nfs_client->cl_clientid;
818 p->o_arg.id = sp->so_owner_id.id; 842 p->o_arg.id = sp->so_seqid.owner_id;
819 p->o_arg.name = &dentry->d_name; 843 p->o_arg.name = &dentry->d_name;
820 p->o_arg.server = server; 844 p->o_arg.server = server;
821 p->o_arg.bitmask = server->attr_bitmask; 845 p->o_arg.bitmask = server->attr_bitmask;
822 p->o_arg.dir_bitmask = server->cache_consistency_bitmask; 846 p->o_arg.dir_bitmask = server->cache_consistency_bitmask;
823 p->o_arg.claim = NFS4_OPEN_CLAIM_NULL; 847 p->o_arg.claim = NFS4_OPEN_CLAIM_NULL;
824 if (flags & O_CREAT) { 848 if (attrs != NULL && attrs->ia_valid != 0) {
825 u32 *s; 849 __be32 verf[2];
826 850
827 p->o_arg.u.attrs = &p->attrs; 851 p->o_arg.u.attrs = &p->attrs;
828 memcpy(&p->attrs, attrs, sizeof(p->attrs)); 852 memcpy(&p->attrs, attrs, sizeof(p->attrs));
829 s = (u32 *) p->o_arg.u.verifier.data; 853
830 s[0] = jiffies; 854 verf[0] = jiffies;
831 s[1] = current->pid; 855 verf[1] = current->pid;
856 memcpy(p->o_arg.u.verifier.data, verf,
857 sizeof(p->o_arg.u.verifier.data));
832 } 858 }
833 p->c_arg.fh = &p->o_res.fh; 859 p->c_arg.fh = &p->o_res.fh;
834 p->c_arg.stateid = &p->o_res.stateid; 860 p->c_arg.stateid = &p->o_res.stateid;
@@ -878,7 +904,7 @@ static int can_open_cached(struct nfs4_state *state, fmode_t mode, int open_mode
878{ 904{
879 int ret = 0; 905 int ret = 0;
880 906
881 if (open_mode & O_EXCL) 907 if (open_mode & (O_EXCL|O_TRUNC))
882 goto out; 908 goto out;
883 switch (mode & (FMODE_READ|FMODE_WRITE)) { 909 switch (mode & (FMODE_READ|FMODE_WRITE)) {
884 case FMODE_READ: 910 case FMODE_READ:
@@ -927,8 +953,8 @@ static void update_open_stateflags(struct nfs4_state *state, fmode_t fmode)
927static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode) 953static void nfs_set_open_stateid_locked(struct nfs4_state *state, nfs4_stateid *stateid, fmode_t fmode)
928{ 954{
929 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) 955 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
930 memcpy(state->stateid.data, stateid->data, sizeof(state->stateid.data)); 956 nfs4_stateid_copy(&state->stateid, stateid);
931 memcpy(state->open_stateid.data, stateid->data, sizeof(state->open_stateid.data)); 957 nfs4_stateid_copy(&state->open_stateid, stateid);
932 switch (fmode) { 958 switch (fmode) {
933 case FMODE_READ: 959 case FMODE_READ:
934 set_bit(NFS_O_RDONLY_STATE, &state->flags); 960 set_bit(NFS_O_RDONLY_STATE, &state->flags);
@@ -956,7 +982,7 @@ static void __update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_s
956 */ 982 */
957 write_seqlock(&state->seqlock); 983 write_seqlock(&state->seqlock);
958 if (deleg_stateid != NULL) { 984 if (deleg_stateid != NULL) {
959 memcpy(state->stateid.data, deleg_stateid->data, sizeof(state->stateid.data)); 985 nfs4_stateid_copy(&state->stateid, deleg_stateid);
960 set_bit(NFS_DELEGATED_STATE, &state->flags); 986 set_bit(NFS_DELEGATED_STATE, &state->flags);
961 } 987 }
962 if (open_stateid != NULL) 988 if (open_stateid != NULL)
@@ -987,7 +1013,7 @@ static int update_open_stateid(struct nfs4_state *state, nfs4_stateid *open_stat
987 1013
988 if (delegation == NULL) 1014 if (delegation == NULL)
989 delegation = &deleg_cur->stateid; 1015 delegation = &deleg_cur->stateid;
990 else if (memcmp(deleg_cur->stateid.data, delegation->data, NFS4_STATEID_SIZE) != 0) 1016 else if (!nfs4_stateid_match(&deleg_cur->stateid, delegation))
991 goto no_delegation_unlock; 1017 goto no_delegation_unlock;
992 1018
993 nfs_mark_delegation_referenced(deleg_cur); 1019 nfs_mark_delegation_referenced(deleg_cur);
@@ -1026,7 +1052,7 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
1026 struct nfs4_state *state = opendata->state; 1052 struct nfs4_state *state = opendata->state;
1027 struct nfs_inode *nfsi = NFS_I(state->inode); 1053 struct nfs_inode *nfsi = NFS_I(state->inode);
1028 struct nfs_delegation *delegation; 1054 struct nfs_delegation *delegation;
1029 int open_mode = opendata->o_arg.open_flags & O_EXCL; 1055 int open_mode = opendata->o_arg.open_flags & (O_EXCL|O_TRUNC);
1030 fmode_t fmode = opendata->o_arg.fmode; 1056 fmode_t fmode = opendata->o_arg.fmode;
1031 nfs4_stateid stateid; 1057 nfs4_stateid stateid;
1032 int ret = -EAGAIN; 1058 int ret = -EAGAIN;
@@ -1048,7 +1074,7 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
1048 break; 1074 break;
1049 } 1075 }
1050 /* Save the delegation */ 1076 /* Save the delegation */
1051 memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); 1077 nfs4_stateid_copy(&stateid, &delegation->stateid);
1052 rcu_read_unlock(); 1078 rcu_read_unlock();
1053 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode); 1079 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
1054 if (ret != 0) 1080 if (ret != 0)
@@ -1090,6 +1116,7 @@ static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data
1090 if (state == NULL) 1116 if (state == NULL)
1091 goto err_put_inode; 1117 goto err_put_inode;
1092 if (data->o_res.delegation_type != 0) { 1118 if (data->o_res.delegation_type != 0) {
1119 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
1093 int delegation_flags = 0; 1120 int delegation_flags = 0;
1094 1121
1095 rcu_read_lock(); 1122 rcu_read_lock();
@@ -1101,7 +1128,7 @@ static struct nfs4_state *nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data
1101 pr_err_ratelimited("NFS: Broken NFSv4 server %s is " 1128 pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
1102 "returning a delegation for " 1129 "returning a delegation for "
1103 "OPEN(CLAIM_DELEGATE_CUR)\n", 1130 "OPEN(CLAIM_DELEGATE_CUR)\n",
1104 NFS_CLIENT(inode)->cl_server); 1131 clp->cl_hostname);
1105 } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0) 1132 } else if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
1106 nfs_inode_set_delegation(state->inode, 1133 nfs_inode_set_delegation(state->inode,
1107 data->owner->so_cred, 1134 data->owner->so_cred,
@@ -1210,10 +1237,10 @@ static int nfs4_open_recover(struct nfs4_opendata *opendata, struct nfs4_state *
1210 * Check if we need to update the current stateid. 1237 * Check if we need to update the current stateid.
1211 */ 1238 */
1212 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 && 1239 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0 &&
1213 memcmp(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)) != 0) { 1240 !nfs4_stateid_match(&state->stateid, &state->open_stateid)) {
1214 write_seqlock(&state->seqlock); 1241 write_seqlock(&state->seqlock);
1215 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) 1242 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
1216 memcpy(state->stateid.data, state->open_stateid.data, sizeof(state->stateid.data)); 1243 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
1217 write_sequnlock(&state->seqlock); 1244 write_sequnlock(&state->seqlock);
1218 } 1245 }
1219 return 0; 1246 return 0;
@@ -1282,8 +1309,7 @@ static int _nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs
1282 if (IS_ERR(opendata)) 1309 if (IS_ERR(opendata))
1283 return PTR_ERR(opendata); 1310 return PTR_ERR(opendata);
1284 opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR; 1311 opendata->o_arg.claim = NFS4_OPEN_CLAIM_DELEGATE_CUR;
1285 memcpy(opendata->o_arg.u.delegation.data, stateid->data, 1312 nfs4_stateid_copy(&opendata->o_arg.u.delegation, stateid);
1286 sizeof(opendata->o_arg.u.delegation.data));
1287 ret = nfs4_open_recover(opendata, state); 1313 ret = nfs4_open_recover(opendata, state);
1288 nfs4_opendata_put(opendata); 1314 nfs4_opendata_put(opendata);
1289 return ret; 1315 return ret;
@@ -1319,8 +1345,11 @@ int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state
1319 * The show must go on: exit, but mark the 1345 * The show must go on: exit, but mark the
1320 * stateid as needing recovery. 1346 * stateid as needing recovery.
1321 */ 1347 */
1348 case -NFS4ERR_DELEG_REVOKED:
1322 case -NFS4ERR_ADMIN_REVOKED: 1349 case -NFS4ERR_ADMIN_REVOKED:
1323 case -NFS4ERR_BAD_STATEID: 1350 case -NFS4ERR_BAD_STATEID:
1351 nfs_inode_find_state_and_recover(state->inode,
1352 stateid);
1324 nfs4_schedule_stateid_recovery(server, state); 1353 nfs4_schedule_stateid_recovery(server, state);
1325 case -EKEYEXPIRED: 1354 case -EKEYEXPIRED:
1326 /* 1355 /*
@@ -1345,8 +1374,7 @@ static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
1345 1374
1346 data->rpc_status = task->tk_status; 1375 data->rpc_status = task->tk_status;
1347 if (data->rpc_status == 0) { 1376 if (data->rpc_status == 0) {
1348 memcpy(data->o_res.stateid.data, data->c_res.stateid.data, 1377 nfs4_stateid_copy(&data->o_res.stateid, &data->c_res.stateid);
1349 sizeof(data->o_res.stateid.data));
1350 nfs_confirm_seqid(&data->owner->so_seqid, 0); 1378 nfs_confirm_seqid(&data->owner->so_seqid, 0);
1351 renew_lease(data->o_res.server, data->timestamp); 1379 renew_lease(data->o_res.server, data->timestamp);
1352 data->rpc_done = 1; 1380 data->rpc_done = 1;
@@ -1440,7 +1468,7 @@ static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1440 rcu_read_unlock(); 1468 rcu_read_unlock();
1441 } 1469 }
1442 /* Update sequence id. */ 1470 /* Update sequence id. */
1443 data->o_arg.id = sp->so_owner_id.id; 1471 data->o_arg.id = sp->so_seqid.owner_id;
1444 data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid; 1472 data->o_arg.clientid = sp->so_server->nfs_client->cl_clientid;
1445 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) { 1473 if (data->o_arg.claim == NFS4_OPEN_CLAIM_PREVIOUS) {
1446 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR]; 1474 task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OPEN_NOATTR];
@@ -1449,7 +1477,7 @@ static void nfs4_open_prepare(struct rpc_task *task, void *calldata)
1449 data->timestamp = jiffies; 1477 data->timestamp = jiffies;
1450 if (nfs4_setup_sequence(data->o_arg.server, 1478 if (nfs4_setup_sequence(data->o_arg.server,
1451 &data->o_arg.seq_args, 1479 &data->o_arg.seq_args,
1452 &data->o_res.seq_res, 1, task)) 1480 &data->o_res.seq_res, task))
1453 return; 1481 return;
1454 rpc_call_start(task); 1482 rpc_call_start(task);
1455 return; 1483 return;
@@ -1551,6 +1579,7 @@ static int nfs4_run_open_task(struct nfs4_opendata *data, int isrecover)
1551 }; 1579 };
1552 int status; 1580 int status;
1553 1581
1582 nfs41_init_sequence(&o_arg->seq_args, &o_res->seq_res, 1);
1554 kref_get(&data->kref); 1583 kref_get(&data->kref);
1555 data->rpc_done = 0; 1584 data->rpc_done = 0;
1556 data->rpc_status = 0; 1585 data->rpc_status = 0;
@@ -1712,15 +1741,32 @@ static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *sta
1712} 1741}
1713 1742
1714#if defined(CONFIG_NFS_V4_1) 1743#if defined(CONFIG_NFS_V4_1)
1715static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) 1744static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *stateid, unsigned int flags)
1716{ 1745{
1717 int status; 1746 int status = NFS_OK;
1718 struct nfs_server *server = NFS_SERVER(state->inode); 1747 struct nfs_server *server = NFS_SERVER(state->inode);
1719 1748
1720 status = nfs41_test_stateid(server, state); 1749 if (state->flags & flags) {
1721 if (status == NFS_OK) 1750 status = nfs41_test_stateid(server, stateid);
1722 return 0; 1751 if (status != NFS_OK) {
1723 nfs41_free_stateid(server, state); 1752 nfs41_free_stateid(server, stateid);
1753 state->flags &= ~flags;
1754 }
1755 }
1756 return status;
1757}
1758
1759static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
1760{
1761 int deleg_status, open_status;
1762 int deleg_flags = 1 << NFS_DELEGATED_STATE;
1763 int open_flags = (1 << NFS_O_RDONLY_STATE) | (1 << NFS_O_WRONLY_STATE) | (1 << NFS_O_RDWR_STATE);
1764
1765 deleg_status = nfs41_check_expired_stateid(state, &state->stateid, deleg_flags);
1766 open_status = nfs41_check_expired_stateid(state, &state->open_stateid, open_flags);
1767
1768 if ((deleg_status == NFS_OK) && (open_status == NFS_OK))
1769 return NFS_OK;
1724 return nfs4_open_expired(sp, state); 1770 return nfs4_open_expired(sp, state);
1725} 1771}
1726#endif 1772#endif
@@ -1754,7 +1800,8 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, fmode_t fmode
1754 1800
1755 /* Protect against reboot recovery conflicts */ 1801 /* Protect against reboot recovery conflicts */
1756 status = -ENOMEM; 1802 status = -ENOMEM;
1757 if (!(sp = nfs4_get_state_owner(server, cred))) { 1803 sp = nfs4_get_state_owner(server, cred, GFP_KERNEL);
1804 if (sp == NULL) {
1758 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n"); 1805 dprintk("nfs4_do_open: nfs4_get_state_owner failed!\n");
1759 goto out_err; 1806 goto out_err;
1760 } 1807 }
@@ -1829,7 +1876,7 @@ static struct nfs4_state *nfs4_do_open(struct inode *dir, struct dentry *dentry,
1829 * the user though... 1876 * the user though...
1830 */ 1877 */
1831 if (status == -NFS4ERR_BAD_SEQID) { 1878 if (status == -NFS4ERR_BAD_SEQID) {
1832 printk(KERN_WARNING "NFS: v4 server %s " 1879 pr_warn_ratelimited("NFS: v4 server %s "
1833 " returned a bad sequence-id error!\n", 1880 " returned a bad sequence-id error!\n",
1834 NFS_SERVER(dir)->nfs_client->cl_hostname); 1881 NFS_SERVER(dir)->nfs_client->cl_hostname);
1835 exception.retry = 1; 1882 exception.retry = 1;
@@ -1882,12 +1929,14 @@ static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1882 1929
1883 nfs_fattr_init(fattr); 1930 nfs_fattr_init(fattr);
1884 1931
1885 if (nfs4_copy_delegation_stateid(&arg.stateid, inode)) { 1932 if (state != NULL) {
1933 nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE,
1934 current->files, current->tgid);
1935 } else if (nfs4_copy_delegation_stateid(&arg.stateid, inode,
1936 FMODE_WRITE)) {
1886 /* Use that stateid */ 1937 /* Use that stateid */
1887 } else if (state != NULL) {
1888 nfs4_copy_stateid(&arg.stateid, state, current->files, current->tgid);
1889 } else 1938 } else
1890 memcpy(&arg.stateid, &zero_stateid, sizeof(arg.stateid)); 1939 nfs4_stateid_copy(&arg.stateid, &zero_stateid);
1891 1940
1892 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); 1941 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
1893 if (status == 0 && state != NULL) 1942 if (status == 0 && state != NULL)
@@ -1900,7 +1949,10 @@ static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
1900 struct nfs4_state *state) 1949 struct nfs4_state *state)
1901{ 1950{
1902 struct nfs_server *server = NFS_SERVER(inode); 1951 struct nfs_server *server = NFS_SERVER(inode);
1903 struct nfs4_exception exception = { }; 1952 struct nfs4_exception exception = {
1953 .state = state,
1954 .inode = inode,
1955 };
1904 int err; 1956 int err;
1905 do { 1957 do {
1906 err = nfs4_handle_exception(server, 1958 err = nfs4_handle_exception(server,
@@ -1954,6 +2006,7 @@ static void nfs4_close_done(struct rpc_task *task, void *data)
1954 struct nfs4_state *state = calldata->state; 2006 struct nfs4_state *state = calldata->state;
1955 struct nfs_server *server = NFS_SERVER(calldata->inode); 2007 struct nfs_server *server = NFS_SERVER(calldata->inode);
1956 2008
2009 dprintk("%s: begin!\n", __func__);
1957 if (!nfs4_sequence_done(task, &calldata->res.seq_res)) 2010 if (!nfs4_sequence_done(task, &calldata->res.seq_res))
1958 return; 2011 return;
1959 /* hmm. we are done with the inode, and in the process of freeing 2012 /* hmm. we are done with the inode, and in the process of freeing
@@ -1981,6 +2034,7 @@ static void nfs4_close_done(struct rpc_task *task, void *data)
1981 } 2034 }
1982 nfs_release_seqid(calldata->arg.seqid); 2035 nfs_release_seqid(calldata->arg.seqid);
1983 nfs_refresh_inode(calldata->inode, calldata->res.fattr); 2036 nfs_refresh_inode(calldata->inode, calldata->res.fattr);
2037 dprintk("%s: done, ret = %d!\n", __func__, task->tk_status);
1984} 2038}
1985 2039
1986static void nfs4_close_prepare(struct rpc_task *task, void *data) 2040static void nfs4_close_prepare(struct rpc_task *task, void *data)
@@ -1989,6 +2043,7 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)
1989 struct nfs4_state *state = calldata->state; 2043 struct nfs4_state *state = calldata->state;
1990 int call_close = 0; 2044 int call_close = 0;
1991 2045
2046 dprintk("%s: begin!\n", __func__);
1992 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0) 2047 if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
1993 return; 2048 return;
1994 2049
@@ -2013,7 +2068,7 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)
2013 if (!call_close) { 2068 if (!call_close) {
2014 /* Note: exit _without_ calling nfs4_close_done */ 2069 /* Note: exit _without_ calling nfs4_close_done */
2015 task->tk_action = NULL; 2070 task->tk_action = NULL;
2016 return; 2071 goto out;
2017 } 2072 }
2018 2073
2019 if (calldata->arg.fmode == 0) { 2074 if (calldata->arg.fmode == 0) {
@@ -2022,17 +2077,20 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data)
2022 pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { 2077 pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) {
2023 rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, 2078 rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq,
2024 task, NULL); 2079 task, NULL);
2025 return; 2080 goto out;
2026 } 2081 }
2027 } 2082 }
2028 2083
2029 nfs_fattr_init(calldata->res.fattr); 2084 nfs_fattr_init(calldata->res.fattr);
2030 calldata->timestamp = jiffies; 2085 calldata->timestamp = jiffies;
2031 if (nfs4_setup_sequence(NFS_SERVER(calldata->inode), 2086 if (nfs4_setup_sequence(NFS_SERVER(calldata->inode),
2032 &calldata->arg.seq_args, &calldata->res.seq_res, 2087 &calldata->arg.seq_args,
2033 1, task)) 2088 &calldata->res.seq_res,
2034 return; 2089 task))
2090 goto out;
2035 rpc_call_start(task); 2091 rpc_call_start(task);
2092out:
2093 dprintk("%s: done!\n", __func__);
2036} 2094}
2037 2095
2038static const struct rpc_call_ops nfs4_close_ops = { 2096static const struct rpc_call_ops nfs4_close_ops = {
@@ -2074,6 +2132,7 @@ int nfs4_do_close(struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc)
2074 calldata = kzalloc(sizeof(*calldata), gfp_mask); 2132 calldata = kzalloc(sizeof(*calldata), gfp_mask);
2075 if (calldata == NULL) 2133 if (calldata == NULL)
2076 goto out; 2134 goto out;
2135 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 1);
2077 calldata->inode = state->inode; 2136 calldata->inode = state->inode;
2078 calldata->state = state; 2137 calldata->state = state;
2079 calldata->arg.fh = NFS_FH(state->inode); 2138 calldata->arg.fh = NFS_FH(state->inode);
@@ -2182,6 +2241,7 @@ static int _nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *f
2182 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE; 2241 server->cache_consistency_bitmask[0] &= FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE;
2183 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY; 2242 server->cache_consistency_bitmask[1] &= FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
2184 server->acl_bitmask = res.acl_bitmask; 2243 server->acl_bitmask = res.acl_bitmask;
2244 server->fh_expire_type = res.fh_expire_type;
2185 } 2245 }
2186 2246
2187 return status; 2247 return status;
@@ -2303,7 +2363,6 @@ static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle,
2303 return nfs4_map_errors(status); 2363 return nfs4_map_errors(status);
2304} 2364}
2305 2365
2306static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr);
2307/* 2366/*
2308 * Get locations and (maybe) other attributes of a referral. 2367 * Get locations and (maybe) other attributes of a referral.
2309 * Note that we'll actually follow the referral later when 2368 * Note that we'll actually follow the referral later when
@@ -2420,6 +2479,10 @@ nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
2420 } 2479 }
2421 } 2480 }
2422 2481
2482 /* Deal with open(O_TRUNC) */
2483 if (sattr->ia_valid & ATTR_OPEN)
2484 sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN);
2485
2423 status = nfs4_do_setattr(inode, cred, fattr, sattr, state); 2486 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
2424 if (status == 0) 2487 if (status == 0)
2425 nfs_setattr_update_inode(inode, sattr); 2488 nfs_setattr_update_inode(inode, sattr);
@@ -2494,7 +2557,7 @@ static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry
2494 struct nfs_server *server = NFS_SERVER(inode); 2557 struct nfs_server *server = NFS_SERVER(inode);
2495 struct nfs4_accessargs args = { 2558 struct nfs4_accessargs args = {
2496 .fh = NFS_FH(inode), 2559 .fh = NFS_FH(inode),
2497 .bitmask = server->attr_bitmask, 2560 .bitmask = server->cache_consistency_bitmask,
2498 }; 2561 };
2499 struct nfs4_accessres res = { 2562 struct nfs4_accessres res = {
2500 .server = server, 2563 .server = server,
@@ -2712,8 +2775,18 @@ static void nfs4_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
2712 2775
2713 args->bitmask = server->cache_consistency_bitmask; 2776 args->bitmask = server->cache_consistency_bitmask;
2714 res->server = server; 2777 res->server = server;
2715 res->seq_res.sr_slot = NULL;
2716 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE]; 2778 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_REMOVE];
2779 nfs41_init_sequence(&args->seq_args, &res->seq_res, 1);
2780}
2781
2782static void nfs4_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
2783{
2784 if (nfs4_setup_sequence(NFS_SERVER(data->dir),
2785 &data->args.seq_args,
2786 &data->res.seq_res,
2787 task))
2788 return;
2789 rpc_call_start(task);
2717} 2790}
2718 2791
2719static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir) 2792static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
@@ -2738,6 +2811,17 @@ static void nfs4_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
2738 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME]; 2811 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME];
2739 arg->bitmask = server->attr_bitmask; 2812 arg->bitmask = server->attr_bitmask;
2740 res->server = server; 2813 res->server = server;
2814 nfs41_init_sequence(&arg->seq_args, &res->seq_res, 1);
2815}
2816
2817static void nfs4_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
2818{
2819 if (nfs4_setup_sequence(NFS_SERVER(data->old_dir),
2820 &data->args.seq_args,
2821 &data->res.seq_res,
2822 task))
2823 return;
2824 rpc_call_start(task);
2741} 2825}
2742 2826
2743static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir, 2827static int nfs4_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
@@ -3232,6 +3316,17 @@ static void nfs4_proc_read_setup(struct nfs_read_data *data, struct rpc_message
3232 data->timestamp = jiffies; 3316 data->timestamp = jiffies;
3233 data->read_done_cb = nfs4_read_done_cb; 3317 data->read_done_cb = nfs4_read_done_cb;
3234 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ]; 3318 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_READ];
3319 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 0);
3320}
3321
3322static void nfs4_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data)
3323{
3324 if (nfs4_setup_sequence(NFS_SERVER(data->inode),
3325 &data->args.seq_args,
3326 &data->res.seq_res,
3327 task))
3328 return;
3329 rpc_call_start(task);
3235} 3330}
3236 3331
3237/* Reset the the nfs_read_data to send the read to the MDS. */ 3332/* Reset the the nfs_read_data to send the read to the MDS. */
@@ -3305,6 +3400,17 @@ static void nfs4_proc_write_setup(struct nfs_write_data *data, struct rpc_messag
3305 data->timestamp = jiffies; 3400 data->timestamp = jiffies;
3306 3401
3307 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE]; 3402 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_WRITE];
3403 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3404}
3405
3406static void nfs4_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data)
3407{
3408 if (nfs4_setup_sequence(NFS_SERVER(data->inode),
3409 &data->args.seq_args,
3410 &data->res.seq_res,
3411 task))
3412 return;
3413 rpc_call_start(task);
3308} 3414}
3309 3415
3310static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_write_data *data) 3416static int nfs4_commit_done_cb(struct rpc_task *task, struct nfs_write_data *data)
@@ -3339,6 +3445,7 @@ static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_messa
3339 data->write_done_cb = nfs4_commit_done_cb; 3445 data->write_done_cb = nfs4_commit_done_cb;
3340 data->res.server = server; 3446 data->res.server = server;
3341 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT]; 3447 msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
3448 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3342} 3449}
3343 3450
3344struct nfs4_renewdata { 3451struct nfs4_renewdata {
@@ -3714,8 +3821,11 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
3714 if (task->tk_status >= 0) 3821 if (task->tk_status >= 0)
3715 return 0; 3822 return 0;
3716 switch(task->tk_status) { 3823 switch(task->tk_status) {
3824 case -NFS4ERR_DELEG_REVOKED:
3717 case -NFS4ERR_ADMIN_REVOKED: 3825 case -NFS4ERR_ADMIN_REVOKED:
3718 case -NFS4ERR_BAD_STATEID: 3826 case -NFS4ERR_BAD_STATEID:
3827 if (state != NULL)
3828 nfs_remove_bad_delegation(state->inode);
3719 case -NFS4ERR_OPENMODE: 3829 case -NFS4ERR_OPENMODE:
3720 if (state == NULL) 3830 if (state == NULL)
3721 break; 3831 break;
@@ -3764,6 +3874,16 @@ wait_on_recovery:
3764 return -EAGAIN; 3874 return -EAGAIN;
3765} 3875}
3766 3876
3877static void nfs4_construct_boot_verifier(struct nfs_client *clp,
3878 nfs4_verifier *bootverf)
3879{
3880 __be32 verf[2];
3881
3882 verf[0] = htonl((u32)clp->cl_boot_time.tv_sec);
3883 verf[1] = htonl((u32)clp->cl_boot_time.tv_nsec);
3884 memcpy(bootverf->data, verf, sizeof(bootverf->data));
3885}
3886
3767int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, 3887int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
3768 unsigned short port, struct rpc_cred *cred, 3888 unsigned short port, struct rpc_cred *cred,
3769 struct nfs4_setclientid_res *res) 3889 struct nfs4_setclientid_res *res)
@@ -3780,15 +3900,13 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
3780 .rpc_resp = res, 3900 .rpc_resp = res,
3781 .rpc_cred = cred, 3901 .rpc_cred = cred,
3782 }; 3902 };
3783 __be32 *p;
3784 int loop = 0; 3903 int loop = 0;
3785 int status; 3904 int status;
3786 3905
3787 p = (__be32*)sc_verifier.data; 3906 nfs4_construct_boot_verifier(clp, &sc_verifier);
3788 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
3789 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
3790 3907
3791 for(;;) { 3908 for(;;) {
3909 rcu_read_lock();
3792 setclientid.sc_name_len = scnprintf(setclientid.sc_name, 3910 setclientid.sc_name_len = scnprintf(setclientid.sc_name,
3793 sizeof(setclientid.sc_name), "%s/%s %s %s %u", 3911 sizeof(setclientid.sc_name), "%s/%s %s %s %u",
3794 clp->cl_ipaddr, 3912 clp->cl_ipaddr,
@@ -3805,6 +3923,7 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
3805 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr, 3923 setclientid.sc_uaddr_len = scnprintf(setclientid.sc_uaddr,
3806 sizeof(setclientid.sc_uaddr), "%s.%u.%u", 3924 sizeof(setclientid.sc_uaddr), "%s.%u.%u",
3807 clp->cl_ipaddr, port >> 8, port & 255); 3925 clp->cl_ipaddr, port >> 8, port & 255);
3926 rcu_read_unlock();
3808 3927
3809 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); 3928 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
3810 if (status != -NFS4ERR_CLID_INUSE) 3929 if (status != -NFS4ERR_CLID_INUSE)
@@ -3891,7 +4010,7 @@ static void nfs4_delegreturn_prepare(struct rpc_task *task, void *data)
3891 4010
3892 if (nfs4_setup_sequence(d_data->res.server, 4011 if (nfs4_setup_sequence(d_data->res.server,
3893 &d_data->args.seq_args, 4012 &d_data->args.seq_args,
3894 &d_data->res.seq_res, 1, task)) 4013 &d_data->res.seq_res, task))
3895 return; 4014 return;
3896 rpc_call_start(task); 4015 rpc_call_start(task);
3897} 4016}
@@ -3925,11 +4044,12 @@ static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, co
3925 data = kzalloc(sizeof(*data), GFP_NOFS); 4044 data = kzalloc(sizeof(*data), GFP_NOFS);
3926 if (data == NULL) 4045 if (data == NULL)
3927 return -ENOMEM; 4046 return -ENOMEM;
4047 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
3928 data->args.fhandle = &data->fh; 4048 data->args.fhandle = &data->fh;
3929 data->args.stateid = &data->stateid; 4049 data->args.stateid = &data->stateid;
3930 data->args.bitmask = server->attr_bitmask; 4050 data->args.bitmask = server->attr_bitmask;
3931 nfs_copy_fh(&data->fh, NFS_FH(inode)); 4051 nfs_copy_fh(&data->fh, NFS_FH(inode));
3932 memcpy(&data->stateid, stateid, sizeof(data->stateid)); 4052 nfs4_stateid_copy(&data->stateid, stateid);
3933 data->res.fattr = &data->fattr; 4053 data->res.fattr = &data->fattr;
3934 data->res.server = server; 4054 data->res.server = server;
3935 nfs_fattr_init(data->res.fattr); 4055 nfs_fattr_init(data->res.fattr);
@@ -4016,7 +4136,7 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock
4016 if (status != 0) 4136 if (status != 0)
4017 goto out; 4137 goto out;
4018 lsp = request->fl_u.nfs4_fl.owner; 4138 lsp = request->fl_u.nfs4_fl.owner;
4019 arg.lock_owner.id = lsp->ls_id.id; 4139 arg.lock_owner.id = lsp->ls_seqid.owner_id;
4020 arg.lock_owner.s_dev = server->s_dev; 4140 arg.lock_owner.s_dev = server->s_dev;
4021 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1); 4141 status = nfs4_call_sync(server->client, server, &msg, &arg.seq_args, &res.seq_res, 1);
4022 switch (status) { 4142 switch (status) {
@@ -4112,9 +4232,8 @@ static void nfs4_locku_done(struct rpc_task *task, void *data)
4112 return; 4232 return;
4113 switch (task->tk_status) { 4233 switch (task->tk_status) {
4114 case 0: 4234 case 0:
4115 memcpy(calldata->lsp->ls_stateid.data, 4235 nfs4_stateid_copy(&calldata->lsp->ls_stateid,
4116 calldata->res.stateid.data, 4236 &calldata->res.stateid);
4117 sizeof(calldata->lsp->ls_stateid.data));
4118 renew_lease(calldata->server, calldata->timestamp); 4237 renew_lease(calldata->server, calldata->timestamp);
4119 break; 4238 break;
4120 case -NFS4ERR_BAD_STATEID: 4239 case -NFS4ERR_BAD_STATEID:
@@ -4142,7 +4261,7 @@ static void nfs4_locku_prepare(struct rpc_task *task, void *data)
4142 calldata->timestamp = jiffies; 4261 calldata->timestamp = jiffies;
4143 if (nfs4_setup_sequence(calldata->server, 4262 if (nfs4_setup_sequence(calldata->server,
4144 &calldata->arg.seq_args, 4263 &calldata->arg.seq_args,
4145 &calldata->res.seq_res, 1, task)) 4264 &calldata->res.seq_res, task))
4146 return; 4265 return;
4147 rpc_call_start(task); 4266 rpc_call_start(task);
4148} 4267}
@@ -4182,6 +4301,7 @@ static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
4182 return ERR_PTR(-ENOMEM); 4301 return ERR_PTR(-ENOMEM);
4183 } 4302 }
4184 4303
4304 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
4185 msg.rpc_argp = &data->arg; 4305 msg.rpc_argp = &data->arg;
4186 msg.rpc_resp = &data->res; 4306 msg.rpc_resp = &data->res;
4187 task_setup_data.callback_data = data; 4307 task_setup_data.callback_data = data;
@@ -4261,7 +4381,7 @@ static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
4261 goto out_free_seqid; 4381 goto out_free_seqid;
4262 p->arg.lock_stateid = &lsp->ls_stateid; 4382 p->arg.lock_stateid = &lsp->ls_stateid;
4263 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; 4383 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
4264 p->arg.lock_owner.id = lsp->ls_id.id; 4384 p->arg.lock_owner.id = lsp->ls_seqid.owner_id;
4265 p->arg.lock_owner.s_dev = server->s_dev; 4385 p->arg.lock_owner.s_dev = server->s_dev;
4266 p->res.lock_seqid = p->arg.lock_seqid; 4386 p->res.lock_seqid = p->arg.lock_seqid;
4267 p->lsp = lsp; 4387 p->lsp = lsp;
@@ -4297,7 +4417,7 @@ static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
4297 data->timestamp = jiffies; 4417 data->timestamp = jiffies;
4298 if (nfs4_setup_sequence(data->server, 4418 if (nfs4_setup_sequence(data->server,
4299 &data->arg.seq_args, 4419 &data->arg.seq_args,
4300 &data->res.seq_res, 1, task)) 4420 &data->res.seq_res, task))
4301 return; 4421 return;
4302 rpc_call_start(task); 4422 rpc_call_start(task);
4303 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status); 4423 dprintk("%s: done!, ret = %d\n", __func__, data->rpc_status);
@@ -4326,8 +4446,7 @@ static void nfs4_lock_done(struct rpc_task *task, void *calldata)
4326 goto out; 4446 goto out;
4327 } 4447 }
4328 if (data->rpc_status == 0) { 4448 if (data->rpc_status == 0) {
4329 memcpy(data->lsp->ls_stateid.data, data->res.stateid.data, 4449 nfs4_stateid_copy(&data->lsp->ls_stateid, &data->res.stateid);
4330 sizeof(data->lsp->ls_stateid.data));
4331 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; 4450 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED;
4332 renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp); 4451 renew_lease(NFS_SERVER(data->ctx->dentry->d_inode), data->timestamp);
4333 } 4452 }
@@ -4415,6 +4534,7 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *f
4415 data->arg.reclaim = NFS_LOCK_RECLAIM; 4534 data->arg.reclaim = NFS_LOCK_RECLAIM;
4416 task_setup_data.callback_ops = &nfs4_recover_lock_ops; 4535 task_setup_data.callback_ops = &nfs4_recover_lock_ops;
4417 } 4536 }
4537 nfs41_init_sequence(&data->arg.seq_args, &data->res.seq_res, 1);
4418 msg.rpc_argp = &data->arg; 4538 msg.rpc_argp = &data->arg;
4419 msg.rpc_resp = &data->res; 4539 msg.rpc_resp = &data->res;
4420 task_setup_data.callback_data = data; 4540 task_setup_data.callback_data = data;
@@ -4479,15 +4599,34 @@ out:
4479} 4599}
4480 4600
4481#if defined(CONFIG_NFS_V4_1) 4601#if defined(CONFIG_NFS_V4_1)
4482static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request) 4602static int nfs41_check_expired_locks(struct nfs4_state *state)
4483{ 4603{
4484 int status; 4604 int status, ret = NFS_OK;
4605 struct nfs4_lock_state *lsp;
4485 struct nfs_server *server = NFS_SERVER(state->inode); 4606 struct nfs_server *server = NFS_SERVER(state->inode);
4486 4607
4487 status = nfs41_test_stateid(server, state); 4608 list_for_each_entry(lsp, &state->lock_states, ls_locks) {
4609 if (lsp->ls_flags & NFS_LOCK_INITIALIZED) {
4610 status = nfs41_test_stateid(server, &lsp->ls_stateid);
4611 if (status != NFS_OK) {
4612 nfs41_free_stateid(server, &lsp->ls_stateid);
4613 lsp->ls_flags &= ~NFS_LOCK_INITIALIZED;
4614 ret = status;
4615 }
4616 }
4617 };
4618
4619 return ret;
4620}
4621
4622static int nfs41_lock_expired(struct nfs4_state *state, struct file_lock *request)
4623{
4624 int status = NFS_OK;
4625
4626 if (test_bit(LK_STATE_IN_USE, &state->flags))
4627 status = nfs41_check_expired_locks(state);
4488 if (status == NFS_OK) 4628 if (status == NFS_OK)
4489 return 0; 4629 return status;
4490 nfs41_free_stateid(server, state);
4491 return nfs4_lock_expired(state, request); 4630 return nfs4_lock_expired(state, request);
4492} 4631}
4493#endif 4632#endif
@@ -4523,7 +4662,8 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock
4523 /* Note: we always want to sleep here! */ 4662 /* Note: we always want to sleep here! */
4524 request->fl_flags = fl_flags | FL_SLEEP; 4663 request->fl_flags = fl_flags | FL_SLEEP;
4525 if (do_vfs_lock(request->fl_file, request) < 0) 4664 if (do_vfs_lock(request->fl_file, request) < 0)
4526 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __func__); 4665 printk(KERN_WARNING "NFS: %s: VFS is out of sync with lock "
4666 "manager!\n", __func__);
4527out_unlock: 4667out_unlock:
4528 up_read(&nfsi->rwsem); 4668 up_read(&nfsi->rwsem);
4529out: 4669out:
@@ -4533,7 +4673,9 @@ out:
4533 4673
4534static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request) 4674static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
4535{ 4675{
4536 struct nfs4_exception exception = { }; 4676 struct nfs4_exception exception = {
4677 .state = state,
4678 };
4537 int err; 4679 int err;
4538 4680
4539 do { 4681 do {
@@ -4603,8 +4745,8 @@ int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
4603 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW); 4745 err = _nfs4_do_setlk(state, F_SETLK, fl, NFS_LOCK_NEW);
4604 switch (err) { 4746 switch (err) {
4605 default: 4747 default:
4606 printk(KERN_ERR "%s: unhandled error %d.\n", 4748 printk(KERN_ERR "NFS: %s: unhandled error "
4607 __func__, err); 4749 "%d.\n", __func__, err);
4608 case 0: 4750 case 0:
4609 case -ESTALE: 4751 case -ESTALE:
4610 goto out; 4752 goto out;
@@ -4626,6 +4768,7 @@ int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
4626 * The show must go on: exit, but mark the 4768 * The show must go on: exit, but mark the
4627 * stateid as needing recovery. 4769 * stateid as needing recovery.
4628 */ 4770 */
4771 case -NFS4ERR_DELEG_REVOKED:
4629 case -NFS4ERR_ADMIN_REVOKED: 4772 case -NFS4ERR_ADMIN_REVOKED:
4630 case -NFS4ERR_BAD_STATEID: 4773 case -NFS4ERR_BAD_STATEID:
4631 case -NFS4ERR_OPENMODE: 4774 case -NFS4ERR_OPENMODE:
@@ -4655,33 +4798,44 @@ out:
4655 return err; 4798 return err;
4656} 4799}
4657 4800
4801struct nfs_release_lockowner_data {
4802 struct nfs4_lock_state *lsp;
4803 struct nfs_server *server;
4804 struct nfs_release_lockowner_args args;
4805};
4806
4658static void nfs4_release_lockowner_release(void *calldata) 4807static void nfs4_release_lockowner_release(void *calldata)
4659{ 4808{
4809 struct nfs_release_lockowner_data *data = calldata;
4810 nfs4_free_lock_state(data->server, data->lsp);
4660 kfree(calldata); 4811 kfree(calldata);
4661} 4812}
4662 4813
4663const struct rpc_call_ops nfs4_release_lockowner_ops = { 4814static const struct rpc_call_ops nfs4_release_lockowner_ops = {
4664 .rpc_release = nfs4_release_lockowner_release, 4815 .rpc_release = nfs4_release_lockowner_release,
4665}; 4816};
4666 4817
4667void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) 4818int nfs4_release_lockowner(struct nfs4_lock_state *lsp)
4668{ 4819{
4669 struct nfs_server *server = lsp->ls_state->owner->so_server; 4820 struct nfs_server *server = lsp->ls_state->owner->so_server;
4670 struct nfs_release_lockowner_args *args; 4821 struct nfs_release_lockowner_data *data;
4671 struct rpc_message msg = { 4822 struct rpc_message msg = {
4672 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER], 4823 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RELEASE_LOCKOWNER],
4673 }; 4824 };
4674 4825
4675 if (server->nfs_client->cl_mvops->minor_version != 0) 4826 if (server->nfs_client->cl_mvops->minor_version != 0)
4676 return; 4827 return -EINVAL;
4677 args = kmalloc(sizeof(*args), GFP_NOFS); 4828 data = kmalloc(sizeof(*data), GFP_NOFS);
4678 if (!args) 4829 if (!data)
4679 return; 4830 return -ENOMEM;
4680 args->lock_owner.clientid = server->nfs_client->cl_clientid; 4831 data->lsp = lsp;
4681 args->lock_owner.id = lsp->ls_id.id; 4832 data->server = server;
4682 args->lock_owner.s_dev = server->s_dev; 4833 data->args.lock_owner.clientid = server->nfs_client->cl_clientid;
4683 msg.rpc_argp = args; 4834 data->args.lock_owner.id = lsp->ls_seqid.owner_id;
4684 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); 4835 data->args.lock_owner.s_dev = server->s_dev;
4836 msg.rpc_argp = &data->args;
4837 rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, data);
4838 return 0;
4685} 4839}
4686 4840
4687#define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" 4841#define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"
@@ -4727,11 +4881,11 @@ static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr)
4727 if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) || 4881 if (!(((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) ||
4728 (fattr->valid & NFS_ATTR_FATTR_FILEID)) && 4882 (fattr->valid & NFS_ATTR_FATTR_FILEID)) &&
4729 (fattr->valid & NFS_ATTR_FATTR_FSID) && 4883 (fattr->valid & NFS_ATTR_FATTR_FSID) &&
4730 (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL))) 4884 (fattr->valid & NFS_ATTR_FATTR_V4_LOCATIONS)))
4731 return; 4885 return;
4732 4886
4733 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE | 4887 fattr->valid |= NFS_ATTR_FATTR_TYPE | NFS_ATTR_FATTR_MODE |
4734 NFS_ATTR_FATTR_NLINK; 4888 NFS_ATTR_FATTR_NLINK | NFS_ATTR_FATTR_V4_REFERRAL;
4735 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO; 4889 fattr->mode = S_IFDIR | S_IRUGO | S_IXUGO;
4736 fattr->nlink = 2; 4890 fattr->nlink = 2;
4737} 4891}
@@ -4798,7 +4952,8 @@ static int _nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct
4798 return status; 4952 return status;
4799} 4953}
4800 4954
4801int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name, struct nfs4_secinfo_flavors *flavors) 4955static int nfs4_proc_secinfo(struct inode *dir, const struct qstr *name,
4956 struct nfs4_secinfo_flavors *flavors)
4802{ 4957{
4803 struct nfs4_exception exception = { }; 4958 struct nfs4_exception exception = { };
4804 int err; 4959 int err;
@@ -4852,6 +5007,7 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4852{ 5007{
4853 nfs4_verifier verifier; 5008 nfs4_verifier verifier;
4854 struct nfs41_exchange_id_args args = { 5009 struct nfs41_exchange_id_args args = {
5010 .verifier = &verifier,
4855 .client = clp, 5011 .client = clp,
4856 .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, 5012 .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER,
4857 }; 5013 };
@@ -4865,15 +5021,11 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4865 .rpc_resp = &res, 5021 .rpc_resp = &res,
4866 .rpc_cred = cred, 5022 .rpc_cred = cred,
4867 }; 5023 };
4868 __be32 *p;
4869 5024
4870 dprintk("--> %s\n", __func__); 5025 dprintk("--> %s\n", __func__);
4871 BUG_ON(clp == NULL); 5026 BUG_ON(clp == NULL);
4872 5027
4873 p = (u32 *)verifier.data; 5028 nfs4_construct_boot_verifier(clp, &verifier);
4874 *p++ = htonl((u32)clp->cl_boot_time.tv_sec);
4875 *p = htonl((u32)clp->cl_boot_time.tv_nsec);
4876 args.verifier = &verifier;
4877 5029
4878 args.id_len = scnprintf(args.id, sizeof(args.id), 5030 args.id_len = scnprintf(args.id, sizeof(args.id),
4879 "%s/%s.%s/%u", 5031 "%s/%s.%s/%u",
@@ -4888,11 +5040,24 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4888 goto out; 5040 goto out;
4889 } 5041 }
4890 5042
5043 res.impl_id = kzalloc(sizeof(struct nfs41_impl_id), GFP_KERNEL);
5044 if (unlikely(!res.impl_id)) {
5045 status = -ENOMEM;
5046 goto out_server_scope;
5047 }
5048
4891 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT); 5049 status = rpc_call_sync(clp->cl_rpcclient, &msg, RPC_TASK_TIMEOUT);
4892 if (!status) 5050 if (!status)
4893 status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); 5051 status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags);
4894 5052
4895 if (!status) { 5053 if (!status) {
5054 /* use the most recent implementation id */
5055 kfree(clp->impl_id);
5056 clp->impl_id = res.impl_id;
5057 } else
5058 kfree(res.impl_id);
5059
5060 if (!status) {
4896 if (clp->server_scope && 5061 if (clp->server_scope &&
4897 !nfs41_same_server_scope(clp->server_scope, 5062 !nfs41_same_server_scope(clp->server_scope,
4898 res.server_scope)) { 5063 res.server_scope)) {
@@ -4908,8 +5073,16 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred)
4908 goto out; 5073 goto out;
4909 } 5074 }
4910 } 5075 }
5076
5077out_server_scope:
4911 kfree(res.server_scope); 5078 kfree(res.server_scope);
4912out: 5079out:
5080 if (clp->impl_id)
5081 dprintk("%s: Server Implementation ID: "
5082 "domain: %s, name: %s, date: %llu,%u\n",
5083 __func__, clp->impl_id->domain, clp->impl_id->name,
5084 clp->impl_id->date.seconds,
5085 clp->impl_id->date.nseconds);
4913 dprintk("<-- %s status= %d\n", __func__, status); 5086 dprintk("<-- %s status= %d\n", __func__, status);
4914 return status; 5087 return status;
4915} 5088}
@@ -4933,7 +5106,7 @@ static void nfs4_get_lease_time_prepare(struct rpc_task *task,
4933 since we're invoked within one */ 5106 since we're invoked within one */
4934 ret = nfs41_setup_sequence(data->clp->cl_session, 5107 ret = nfs41_setup_sequence(data->clp->cl_session,
4935 &data->args->la_seq_args, 5108 &data->args->la_seq_args,
4936 &data->res->lr_seq_res, 0, task); 5109 &data->res->lr_seq_res, task);
4937 5110
4938 BUG_ON(ret == -EAGAIN); 5111 BUG_ON(ret == -EAGAIN);
4939 rpc_call_start(task); 5112 rpc_call_start(task);
@@ -4966,7 +5139,7 @@ static void nfs4_get_lease_time_done(struct rpc_task *task, void *calldata)
4966 dprintk("<-- %s\n", __func__); 5139 dprintk("<-- %s\n", __func__);
4967} 5140}
4968 5141
4969struct rpc_call_ops nfs4_get_lease_time_ops = { 5142static const struct rpc_call_ops nfs4_get_lease_time_ops = {
4970 .rpc_call_prepare = nfs4_get_lease_time_prepare, 5143 .rpc_call_prepare = nfs4_get_lease_time_prepare,
4971 .rpc_call_done = nfs4_get_lease_time_done, 5144 .rpc_call_done = nfs4_get_lease_time_done,
4972}; 5145};
@@ -4997,6 +5170,7 @@ int nfs4_proc_get_lease_time(struct nfs_client *clp, struct nfs_fsinfo *fsinfo)
4997 }; 5170 };
4998 int status; 5171 int status;
4999 5172
5173 nfs41_init_sequence(&args.la_seq_args, &res.lr_seq_res, 0);
5000 dprintk("--> %s\n", __func__); 5174 dprintk("--> %s\n", __func__);
5001 task = rpc_run_task(&task_setup); 5175 task = rpc_run_task(&task_setup);
5002 5176
@@ -5113,13 +5287,13 @@ struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
5113 return NULL; 5287 return NULL;
5114 5288
5115 tbl = &session->fc_slot_table; 5289 tbl = &session->fc_slot_table;
5116 tbl->highest_used_slotid = -1; 5290 tbl->highest_used_slotid = NFS4_NO_SLOT;
5117 spin_lock_init(&tbl->slot_tbl_lock); 5291 spin_lock_init(&tbl->slot_tbl_lock);
5118 rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); 5292 rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table");
5119 init_completion(&tbl->complete); 5293 init_completion(&tbl->complete);
5120 5294
5121 tbl = &session->bc_slot_table; 5295 tbl = &session->bc_slot_table;
5122 tbl->highest_used_slotid = -1; 5296 tbl->highest_used_slotid = NFS4_NO_SLOT;
5123 spin_lock_init(&tbl->slot_tbl_lock); 5297 spin_lock_init(&tbl->slot_tbl_lock);
5124 rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); 5298 rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table");
5125 init_completion(&tbl->complete); 5299 init_completion(&tbl->complete);
@@ -5132,11 +5306,16 @@ struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
5132 5306
5133void nfs4_destroy_session(struct nfs4_session *session) 5307void nfs4_destroy_session(struct nfs4_session *session)
5134{ 5308{
5309 struct rpc_xprt *xprt;
5310
5135 nfs4_proc_destroy_session(session); 5311 nfs4_proc_destroy_session(session);
5312
5313 rcu_read_lock();
5314 xprt = rcu_dereference(session->clp->cl_rpcclient->cl_xprt);
5315 rcu_read_unlock();
5136 dprintk("%s Destroy backchannel for xprt %p\n", 5316 dprintk("%s Destroy backchannel for xprt %p\n",
5137 __func__, session->clp->cl_rpcclient->cl_xprt); 5317 __func__, xprt);
5138 xprt_destroy_backchannel(session->clp->cl_rpcclient->cl_xprt, 5318 xprt_destroy_backchannel(xprt, NFS41_BC_MIN_CALLBACKS);
5139 NFS41_BC_MIN_CALLBACKS);
5140 nfs4_destroy_slot_tables(session); 5319 nfs4_destroy_slot_tables(session);
5141 kfree(session); 5320 kfree(session);
5142} 5321}
@@ -5164,7 +5343,7 @@ static void nfs4_init_channel_attrs(struct nfs41_create_session_args *args)
5164 args->fc_attrs.max_rqst_sz = mxrqst_sz; 5343 args->fc_attrs.max_rqst_sz = mxrqst_sz;
5165 args->fc_attrs.max_resp_sz = mxresp_sz; 5344 args->fc_attrs.max_resp_sz = mxresp_sz;
5166 args->fc_attrs.max_ops = NFS4_MAX_OPS; 5345 args->fc_attrs.max_ops = NFS4_MAX_OPS;
5167 args->fc_attrs.max_reqs = session->clp->cl_rpcclient->cl_xprt->max_reqs; 5346 args->fc_attrs.max_reqs = max_session_slots;
5168 5347
5169 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u " 5348 dprintk("%s: Fore Channel : max_rqst_sz=%u max_resp_sz=%u "
5170 "max_ops=%u max_reqs=%u\n", 5349 "max_ops=%u max_reqs=%u\n",
@@ -5204,6 +5383,8 @@ static int nfs4_verify_fore_channel_attrs(struct nfs41_create_session_args *args
5204 return -EINVAL; 5383 return -EINVAL;
5205 if (rcvd->max_reqs == 0) 5384 if (rcvd->max_reqs == 0)
5206 return -EINVAL; 5385 return -EINVAL;
5386 if (rcvd->max_reqs > NFS4_MAX_SLOT_TABLE)
5387 rcvd->max_reqs = NFS4_MAX_SLOT_TABLE;
5207 return 0; 5388 return 0;
5208} 5389}
5209 5390
@@ -5219,9 +5400,9 @@ static int nfs4_verify_back_channel_attrs(struct nfs41_create_session_args *args
5219 if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached) 5400 if (rcvd->max_resp_sz_cached > sent->max_resp_sz_cached)
5220 return -EINVAL; 5401 return -EINVAL;
5221 /* These would render the backchannel useless: */ 5402 /* These would render the backchannel useless: */
5222 if (rcvd->max_ops == 0) 5403 if (rcvd->max_ops != sent->max_ops)
5223 return -EINVAL; 5404 return -EINVAL;
5224 if (rcvd->max_reqs == 0) 5405 if (rcvd->max_reqs != sent->max_reqs)
5225 return -EINVAL; 5406 return -EINVAL;
5226 return 0; 5407 return 0;
5227} 5408}
@@ -5324,7 +5505,7 @@ int nfs4_proc_destroy_session(struct nfs4_session *session)
5324 5505
5325 if (status) 5506 if (status)
5326 printk(KERN_WARNING 5507 printk(KERN_WARNING
5327 "Got error %d from the server on DESTROY_SESSION. " 5508 "NFS: Got error %d from the server on DESTROY_SESSION. "
5328 "Session has been destroyed regardless...\n", status); 5509 "Session has been destroyed regardless...\n", status);
5329 5510
5330 dprintk("<-- nfs4_proc_destroy_session\n"); 5511 dprintk("<-- nfs4_proc_destroy_session\n");
@@ -5447,7 +5628,7 @@ static void nfs41_sequence_prepare(struct rpc_task *task, void *data)
5447 args = task->tk_msg.rpc_argp; 5628 args = task->tk_msg.rpc_argp;
5448 res = task->tk_msg.rpc_resp; 5629 res = task->tk_msg.rpc_resp;
5449 5630
5450 if (nfs41_setup_sequence(clp->cl_session, args, res, 0, task)) 5631 if (nfs41_setup_sequence(clp->cl_session, args, res, task))
5451 return; 5632 return;
5452 rpc_call_start(task); 5633 rpc_call_start(task);
5453} 5634}
@@ -5479,6 +5660,7 @@ static struct rpc_task *_nfs41_proc_sequence(struct nfs_client *clp, struct rpc_
5479 nfs_put_client(clp); 5660 nfs_put_client(clp);
5480 return ERR_PTR(-ENOMEM); 5661 return ERR_PTR(-ENOMEM);
5481 } 5662 }
5663 nfs41_init_sequence(&calldata->args, &calldata->res, 0);
5482 msg.rpc_argp = &calldata->args; 5664 msg.rpc_argp = &calldata->args;
5483 msg.rpc_resp = &calldata->res; 5665 msg.rpc_resp = &calldata->res;
5484 calldata->clp = clp; 5666 calldata->clp = clp;
@@ -5540,7 +5722,7 @@ static void nfs4_reclaim_complete_prepare(struct rpc_task *task, void *data)
5540 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED); 5722 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
5541 if (nfs41_setup_sequence(calldata->clp->cl_session, 5723 if (nfs41_setup_sequence(calldata->clp->cl_session,
5542 &calldata->arg.seq_args, 5724 &calldata->arg.seq_args,
5543 &calldata->res.seq_res, 0, task)) 5725 &calldata->res.seq_res, task))
5544 return; 5726 return;
5545 5727
5546 rpc_call_start(task); 5728 rpc_call_start(task);
@@ -5619,6 +5801,7 @@ static int nfs41_proc_reclaim_complete(struct nfs_client *clp)
5619 calldata->clp = clp; 5801 calldata->clp = clp;
5620 calldata->arg.one_fs = 0; 5802 calldata->arg.one_fs = 0;
5621 5803
5804 nfs41_init_sequence(&calldata->arg.seq_args, &calldata->res.seq_res, 0);
5622 msg.rpc_argp = &calldata->arg; 5805 msg.rpc_argp = &calldata->arg;
5623 msg.rpc_resp = &calldata->res; 5806 msg.rpc_resp = &calldata->res;
5624 task_setup_data.callback_data = calldata; 5807 task_setup_data.callback_data = calldata;
@@ -5650,7 +5833,7 @@ nfs4_layoutget_prepare(struct rpc_task *task, void *calldata)
5650 * to be no way to prevent it completely. 5833 * to be no way to prevent it completely.
5651 */ 5834 */
5652 if (nfs4_setup_sequence(server, &lgp->args.seq_args, 5835 if (nfs4_setup_sequence(server, &lgp->args.seq_args,
5653 &lgp->res.seq_res, 0, task)) 5836 &lgp->res.seq_res, task))
5654 return; 5837 return;
5655 if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, 5838 if (pnfs_choose_layoutget_stateid(&lgp->args.stateid,
5656 NFS_I(lgp->args.inode)->layout, 5839 NFS_I(lgp->args.inode)->layout,
@@ -5725,6 +5908,7 @@ int nfs4_proc_layoutget(struct nfs4_layoutget *lgp)
5725 5908
5726 lgp->res.layoutp = &lgp->args.layout; 5909 lgp->res.layoutp = &lgp->args.layout;
5727 lgp->res.seq_res.sr_slot = NULL; 5910 lgp->res.seq_res.sr_slot = NULL;
5911 nfs41_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0);
5728 task = rpc_run_task(&task_setup_data); 5912 task = rpc_run_task(&task_setup_data);
5729 if (IS_ERR(task)) 5913 if (IS_ERR(task))
5730 return PTR_ERR(task); 5914 return PTR_ERR(task);
@@ -5745,7 +5929,7 @@ nfs4_layoutreturn_prepare(struct rpc_task *task, void *calldata)
5745 5929
5746 dprintk("--> %s\n", __func__); 5930 dprintk("--> %s\n", __func__);
5747 if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args, 5931 if (nfs41_setup_sequence(lrp->clp->cl_session, &lrp->args.seq_args,
5748 &lrp->res.seq_res, 0, task)) 5932 &lrp->res.seq_res, task))
5749 return; 5933 return;
5750 rpc_call_start(task); 5934 rpc_call_start(task);
5751} 5935}
@@ -5811,6 +5995,7 @@ int nfs4_proc_layoutreturn(struct nfs4_layoutreturn *lrp)
5811 int status; 5995 int status;
5812 5996
5813 dprintk("--> %s\n", __func__); 5997 dprintk("--> %s\n", __func__);
5998 nfs41_init_sequence(&lrp->args.seq_args, &lrp->res.seq_res, 1);
5814 task = rpc_run_task(&task_setup_data); 5999 task = rpc_run_task(&task_setup_data);
5815 if (IS_ERR(task)) 6000 if (IS_ERR(task))
5816 return PTR_ERR(task); 6001 return PTR_ERR(task);
@@ -5911,7 +6096,7 @@ static void nfs4_layoutcommit_prepare(struct rpc_task *task, void *calldata)
5911 struct nfs_server *server = NFS_SERVER(data->args.inode); 6096 struct nfs_server *server = NFS_SERVER(data->args.inode);
5912 6097
5913 if (nfs4_setup_sequence(server, &data->args.seq_args, 6098 if (nfs4_setup_sequence(server, &data->args.seq_args,
5914 &data->res.seq_res, 1, task)) 6099 &data->res.seq_res, task))
5915 return; 6100 return;
5916 rpc_call_start(task); 6101 rpc_call_start(task);
5917} 6102}
@@ -5998,6 +6183,7 @@ nfs4_proc_layoutcommit(struct nfs4_layoutcommit_data *data, bool sync)
5998 data->args.lastbytewritten, 6183 data->args.lastbytewritten,
5999 data->args.inode->i_ino); 6184 data->args.inode->i_ino);
6000 6185
6186 nfs41_init_sequence(&data->args.seq_args, &data->res.seq_res, 1);
6001 task = rpc_run_task(&task_setup_data); 6187 task = rpc_run_task(&task_setup_data);
6002 if (IS_ERR(task)) 6188 if (IS_ERR(task))
6003 return PTR_ERR(task); 6189 return PTR_ERR(task);
@@ -6091,11 +6277,12 @@ out_freepage:
6091out: 6277out:
6092 return err; 6278 return err;
6093} 6279}
6094static int _nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *state) 6280
6281static int _nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6095{ 6282{
6096 int status; 6283 int status;
6097 struct nfs41_test_stateid_args args = { 6284 struct nfs41_test_stateid_args args = {
6098 .stateid = &state->stateid, 6285 .stateid = stateid,
6099 }; 6286 };
6100 struct nfs41_test_stateid_res res; 6287 struct nfs41_test_stateid_res res;
6101 struct rpc_message msg = { 6288 struct rpc_message msg = {
@@ -6103,28 +6290,31 @@ static int _nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *sta
6103 .rpc_argp = &args, 6290 .rpc_argp = &args,
6104 .rpc_resp = &res, 6291 .rpc_resp = &res,
6105 }; 6292 };
6106 args.seq_args.sa_session = res.seq_res.sr_session = NULL; 6293
6107 status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 0, 1); 6294 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6295 status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1);
6296
6297 if (status == NFS_OK)
6298 return res.status;
6108 return status; 6299 return status;
6109} 6300}
6110 6301
6111static int nfs41_test_stateid(struct nfs_server *server, struct nfs4_state *state) 6302static int nfs41_test_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6112{ 6303{
6113 struct nfs4_exception exception = { }; 6304 struct nfs4_exception exception = { };
6114 int err; 6305 int err;
6115 do { 6306 do {
6116 err = nfs4_handle_exception(server, 6307 err = nfs4_handle_exception(server,
6117 _nfs41_test_stateid(server, state), 6308 _nfs41_test_stateid(server, stateid),
6118 &exception); 6309 &exception);
6119 } while (exception.retry); 6310 } while (exception.retry);
6120 return err; 6311 return err;
6121} 6312}
6122 6313
6123static int _nfs4_free_stateid(struct nfs_server *server, struct nfs4_state *state) 6314static int _nfs4_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6124{ 6315{
6125 int status;
6126 struct nfs41_free_stateid_args args = { 6316 struct nfs41_free_stateid_args args = {
6127 .stateid = &state->stateid, 6317 .stateid = stateid,
6128 }; 6318 };
6129 struct nfs41_free_stateid_res res; 6319 struct nfs41_free_stateid_res res;
6130 struct rpc_message msg = { 6320 struct rpc_message msg = {
@@ -6133,25 +6323,46 @@ static int _nfs4_free_stateid(struct nfs_server *server, struct nfs4_state *stat
6133 .rpc_resp = &res, 6323 .rpc_resp = &res,
6134 }; 6324 };
6135 6325
6136 args.seq_args.sa_session = res.seq_res.sr_session = NULL; 6326 nfs41_init_sequence(&args.seq_args, &res.seq_res, 0);
6137 status = nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 0, 1); 6327 return nfs4_call_sync_sequence(server->client, server, &msg, &args.seq_args, &res.seq_res, 1);
6138 return status;
6139} 6328}
6140 6329
6141static int nfs41_free_stateid(struct nfs_server *server, struct nfs4_state *state) 6330static int nfs41_free_stateid(struct nfs_server *server, nfs4_stateid *stateid)
6142{ 6331{
6143 struct nfs4_exception exception = { }; 6332 struct nfs4_exception exception = { };
6144 int err; 6333 int err;
6145 do { 6334 do {
6146 err = nfs4_handle_exception(server, 6335 err = nfs4_handle_exception(server,
6147 _nfs4_free_stateid(server, state), 6336 _nfs4_free_stateid(server, stateid),
6148 &exception); 6337 &exception);
6149 } while (exception.retry); 6338 } while (exception.retry);
6150 return err; 6339 return err;
6151} 6340}
6341
6342static bool nfs41_match_stateid(const nfs4_stateid *s1,
6343 const nfs4_stateid *s2)
6344{
6345 if (memcmp(s1->other, s2->other, sizeof(s1->other)) != 0)
6346 return false;
6347
6348 if (s1->seqid == s2->seqid)
6349 return true;
6350 if (s1->seqid == 0 || s2->seqid == 0)
6351 return true;
6352
6353 return false;
6354}
6355
6152#endif /* CONFIG_NFS_V4_1 */ 6356#endif /* CONFIG_NFS_V4_1 */
6153 6357
6154struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = { 6358static bool nfs4_match_stateid(const nfs4_stateid *s1,
6359 const nfs4_stateid *s2)
6360{
6361 return nfs4_stateid_match(s1, s2);
6362}
6363
6364
6365static const struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
6155 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, 6366 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6156 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, 6367 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6157 .recover_open = nfs4_open_reclaim, 6368 .recover_open = nfs4_open_reclaim,
@@ -6161,7 +6372,7 @@ struct nfs4_state_recovery_ops nfs40_reboot_recovery_ops = {
6161}; 6372};
6162 6373
6163#if defined(CONFIG_NFS_V4_1) 6374#if defined(CONFIG_NFS_V4_1)
6164struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = { 6375static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
6165 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT, 6376 .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
6166 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT, 6377 .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
6167 .recover_open = nfs4_open_reclaim, 6378 .recover_open = nfs4_open_reclaim,
@@ -6172,7 +6383,7 @@ struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
6172}; 6383};
6173#endif /* CONFIG_NFS_V4_1 */ 6384#endif /* CONFIG_NFS_V4_1 */
6174 6385
6175struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { 6386static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
6176 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, 6387 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
6177 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, 6388 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
6178 .recover_open = nfs4_open_expired, 6389 .recover_open = nfs4_open_expired,
@@ -6182,7 +6393,7 @@ struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
6182}; 6393};
6183 6394
6184#if defined(CONFIG_NFS_V4_1) 6395#if defined(CONFIG_NFS_V4_1)
6185struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = { 6396static const struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
6186 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, 6397 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
6187 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, 6398 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
6188 .recover_open = nfs41_open_expired, 6399 .recover_open = nfs41_open_expired,
@@ -6192,14 +6403,14 @@ struct nfs4_state_recovery_ops nfs41_nograce_recovery_ops = {
6192}; 6403};
6193#endif /* CONFIG_NFS_V4_1 */ 6404#endif /* CONFIG_NFS_V4_1 */
6194 6405
6195struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = { 6406static const struct nfs4_state_maintenance_ops nfs40_state_renewal_ops = {
6196 .sched_state_renewal = nfs4_proc_async_renew, 6407 .sched_state_renewal = nfs4_proc_async_renew,
6197 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked, 6408 .get_state_renewal_cred_locked = nfs4_get_renew_cred_locked,
6198 .renew_lease = nfs4_proc_renew, 6409 .renew_lease = nfs4_proc_renew,
6199}; 6410};
6200 6411
6201#if defined(CONFIG_NFS_V4_1) 6412#if defined(CONFIG_NFS_V4_1)
6202struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = { 6413static const struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
6203 .sched_state_renewal = nfs41_proc_async_sequence, 6414 .sched_state_renewal = nfs41_proc_async_sequence,
6204 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked, 6415 .get_state_renewal_cred_locked = nfs4_get_machine_cred_locked,
6205 .renew_lease = nfs4_proc_sequence, 6416 .renew_lease = nfs4_proc_sequence,
@@ -6209,7 +6420,7 @@ struct nfs4_state_maintenance_ops nfs41_state_renewal_ops = {
6209static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = { 6420static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
6210 .minor_version = 0, 6421 .minor_version = 0,
6211 .call_sync = _nfs4_call_sync, 6422 .call_sync = _nfs4_call_sync,
6212 .validate_stateid = nfs4_validate_delegation_stateid, 6423 .match_stateid = nfs4_match_stateid,
6213 .find_root_sec = nfs4_find_root_sec, 6424 .find_root_sec = nfs4_find_root_sec,
6214 .reboot_recovery_ops = &nfs40_reboot_recovery_ops, 6425 .reboot_recovery_ops = &nfs40_reboot_recovery_ops,
6215 .nograce_recovery_ops = &nfs40_nograce_recovery_ops, 6426 .nograce_recovery_ops = &nfs40_nograce_recovery_ops,
@@ -6220,7 +6431,7 @@ static const struct nfs4_minor_version_ops nfs_v4_0_minor_ops = {
6220static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = { 6431static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
6221 .minor_version = 1, 6432 .minor_version = 1,
6222 .call_sync = _nfs4_call_sync_session, 6433 .call_sync = _nfs4_call_sync_session,
6223 .validate_stateid = nfs41_validate_delegation_stateid, 6434 .match_stateid = nfs41_match_stateid,
6224 .find_root_sec = nfs41_find_root_sec, 6435 .find_root_sec = nfs41_find_root_sec,
6225 .reboot_recovery_ops = &nfs41_reboot_recovery_ops, 6436 .reboot_recovery_ops = &nfs41_reboot_recovery_ops,
6226 .nograce_recovery_ops = &nfs41_nograce_recovery_ops, 6437 .nograce_recovery_ops = &nfs41_nograce_recovery_ops,
@@ -6260,9 +6471,11 @@ const struct nfs_rpc_ops nfs_v4_clientops = {
6260 .create = nfs4_proc_create, 6471 .create = nfs4_proc_create,
6261 .remove = nfs4_proc_remove, 6472 .remove = nfs4_proc_remove,
6262 .unlink_setup = nfs4_proc_unlink_setup, 6473 .unlink_setup = nfs4_proc_unlink_setup,
6474 .unlink_rpc_prepare = nfs4_proc_unlink_rpc_prepare,
6263 .unlink_done = nfs4_proc_unlink_done, 6475 .unlink_done = nfs4_proc_unlink_done,
6264 .rename = nfs4_proc_rename, 6476 .rename = nfs4_proc_rename,
6265 .rename_setup = nfs4_proc_rename_setup, 6477 .rename_setup = nfs4_proc_rename_setup,
6478 .rename_rpc_prepare = nfs4_proc_rename_rpc_prepare,
6266 .rename_done = nfs4_proc_rename_done, 6479 .rename_done = nfs4_proc_rename_done,
6267 .link = nfs4_proc_link, 6480 .link = nfs4_proc_link,
6268 .symlink = nfs4_proc_symlink, 6481 .symlink = nfs4_proc_symlink,
@@ -6276,8 +6489,10 @@ const struct nfs_rpc_ops nfs_v4_clientops = {
6276 .set_capabilities = nfs4_server_capabilities, 6489 .set_capabilities = nfs4_server_capabilities,
6277 .decode_dirent = nfs4_decode_dirent, 6490 .decode_dirent = nfs4_decode_dirent,
6278 .read_setup = nfs4_proc_read_setup, 6491 .read_setup = nfs4_proc_read_setup,
6492 .read_rpc_prepare = nfs4_proc_read_rpc_prepare,
6279 .read_done = nfs4_read_done, 6493 .read_done = nfs4_read_done,
6280 .write_setup = nfs4_proc_write_setup, 6494 .write_setup = nfs4_proc_write_setup,
6495 .write_rpc_prepare = nfs4_proc_write_rpc_prepare,
6281 .write_done = nfs4_write_done, 6496 .write_done = nfs4_write_done,
6282 .commit_setup = nfs4_proc_commit_setup, 6497 .commit_setup = nfs4_proc_commit_setup,
6283 .commit_done = nfs4_commit_done, 6498 .commit_done = nfs4_commit_done,
@@ -6301,6 +6516,10 @@ const struct xattr_handler *nfs4_xattr_handlers[] = {
6301 NULL 6516 NULL
6302}; 6517};
6303 6518
6519module_param(max_session_slots, ushort, 0644);
6520MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
6521 "requests the client will negotiate");
6522
6304/* 6523/*
6305 * Local variables: 6524 * Local variables:
6306 * c-basic-offset: 8 6525 * c-basic-offset: 8
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 45392032e7b..0f43414eb25 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -146,6 +146,11 @@ struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp)
146 struct rpc_cred *cred = NULL; 146 struct rpc_cred *cred = NULL;
147 struct nfs_server *server; 147 struct nfs_server *server;
148 148
149 /* Use machine credentials if available */
150 cred = nfs4_get_machine_cred_locked(clp);
151 if (cred != NULL)
152 goto out;
153
149 rcu_read_lock(); 154 rcu_read_lock();
150 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { 155 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
151 cred = nfs4_get_renew_cred_server_locked(server); 156 cred = nfs4_get_renew_cred_server_locked(server);
@@ -153,6 +158,8 @@ struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp)
153 break; 158 break;
154 } 159 }
155 rcu_read_unlock(); 160 rcu_read_unlock();
161
162out:
156 return cred; 163 return cred;
157} 164}
158 165
@@ -190,30 +197,29 @@ static int nfs41_setup_state_renewal(struct nfs_client *clp)
190static void nfs4_end_drain_session(struct nfs_client *clp) 197static void nfs4_end_drain_session(struct nfs_client *clp)
191{ 198{
192 struct nfs4_session *ses = clp->cl_session; 199 struct nfs4_session *ses = clp->cl_session;
200 struct nfs4_slot_table *tbl;
193 int max_slots; 201 int max_slots;
194 202
195 if (ses == NULL) 203 if (ses == NULL)
196 return; 204 return;
205 tbl = &ses->fc_slot_table;
197 if (test_and_clear_bit(NFS4_SESSION_DRAINING, &ses->session_state)) { 206 if (test_and_clear_bit(NFS4_SESSION_DRAINING, &ses->session_state)) {
198 spin_lock(&ses->fc_slot_table.slot_tbl_lock); 207 spin_lock(&tbl->slot_tbl_lock);
199 max_slots = ses->fc_slot_table.max_slots; 208 max_slots = tbl->max_slots;
200 while (max_slots--) { 209 while (max_slots--) {
201 struct rpc_task *task; 210 if (rpc_wake_up_first(&tbl->slot_tbl_waitq,
202 211 nfs4_set_task_privileged,
203 task = rpc_wake_up_next(&ses->fc_slot_table. 212 NULL) == NULL)
204 slot_tbl_waitq);
205 if (!task)
206 break; 213 break;
207 rpc_task_set_priority(task, RPC_PRIORITY_PRIVILEGED);
208 } 214 }
209 spin_unlock(&ses->fc_slot_table.slot_tbl_lock); 215 spin_unlock(&tbl->slot_tbl_lock);
210 } 216 }
211} 217}
212 218
213static int nfs4_wait_on_slot_tbl(struct nfs4_slot_table *tbl) 219static int nfs4_wait_on_slot_tbl(struct nfs4_slot_table *tbl)
214{ 220{
215 spin_lock(&tbl->slot_tbl_lock); 221 spin_lock(&tbl->slot_tbl_lock);
216 if (tbl->highest_used_slotid != -1) { 222 if (tbl->highest_used_slotid != NFS4_NO_SLOT) {
217 INIT_COMPLETION(tbl->complete); 223 INIT_COMPLETION(tbl->complete);
218 spin_unlock(&tbl->slot_tbl_lock); 224 spin_unlock(&tbl->slot_tbl_lock);
219 return wait_for_completion_interruptible(&tbl->complete); 225 return wait_for_completion_interruptible(&tbl->complete);
@@ -317,62 +323,6 @@ out:
317 return cred; 323 return cred;
318} 324}
319 325
320static void nfs_alloc_unique_id_locked(struct rb_root *root,
321 struct nfs_unique_id *new,
322 __u64 minval, int maxbits)
323{
324 struct rb_node **p, *parent;
325 struct nfs_unique_id *pos;
326 __u64 mask = ~0ULL;
327
328 if (maxbits < 64)
329 mask = (1ULL << maxbits) - 1ULL;
330
331 /* Ensure distribution is more or less flat */
332 get_random_bytes(&new->id, sizeof(new->id));
333 new->id &= mask;
334 if (new->id < minval)
335 new->id += minval;
336retry:
337 p = &root->rb_node;
338 parent = NULL;
339
340 while (*p != NULL) {
341 parent = *p;
342 pos = rb_entry(parent, struct nfs_unique_id, rb_node);
343
344 if (new->id < pos->id)
345 p = &(*p)->rb_left;
346 else if (new->id > pos->id)
347 p = &(*p)->rb_right;
348 else
349 goto id_exists;
350 }
351 rb_link_node(&new->rb_node, parent, p);
352 rb_insert_color(&new->rb_node, root);
353 return;
354id_exists:
355 for (;;) {
356 new->id++;
357 if (new->id < minval || (new->id & mask) != new->id) {
358 new->id = minval;
359 break;
360 }
361 parent = rb_next(parent);
362 if (parent == NULL)
363 break;
364 pos = rb_entry(parent, struct nfs_unique_id, rb_node);
365 if (new->id < pos->id)
366 break;
367 }
368 goto retry;
369}
370
371static void nfs_free_unique_id(struct rb_root *root, struct nfs_unique_id *id)
372{
373 rb_erase(&id->rb_node, root);
374}
375
376static struct nfs4_state_owner * 326static struct nfs4_state_owner *
377nfs4_find_state_owner_locked(struct nfs_server *server, struct rpc_cred *cred) 327nfs4_find_state_owner_locked(struct nfs_server *server, struct rpc_cred *cred)
378{ 328{
@@ -405,6 +355,7 @@ nfs4_insert_state_owner_locked(struct nfs4_state_owner *new)
405 struct rb_node **p = &server->state_owners.rb_node, 355 struct rb_node **p = &server->state_owners.rb_node,
406 *parent = NULL; 356 *parent = NULL;
407 struct nfs4_state_owner *sp; 357 struct nfs4_state_owner *sp;
358 int err;
408 359
409 while (*p != NULL) { 360 while (*p != NULL) {
410 parent = *p; 361 parent = *p;
@@ -421,8 +372,9 @@ nfs4_insert_state_owner_locked(struct nfs4_state_owner *new)
421 return sp; 372 return sp;
422 } 373 }
423 } 374 }
424 nfs_alloc_unique_id_locked(&server->openowner_id, 375 err = ida_get_new(&server->openowner_id, &new->so_seqid.owner_id);
425 &new->so_owner_id, 1, 64); 376 if (err)
377 return ERR_PTR(err);
426 rb_link_node(&new->so_server_node, parent, p); 378 rb_link_node(&new->so_server_node, parent, p);
427 rb_insert_color(&new->so_server_node, &server->state_owners); 379 rb_insert_color(&new->so_server_node, &server->state_owners);
428 return new; 380 return new;
@@ -435,7 +387,23 @@ nfs4_remove_state_owner_locked(struct nfs4_state_owner *sp)
435 387
436 if (!RB_EMPTY_NODE(&sp->so_server_node)) 388 if (!RB_EMPTY_NODE(&sp->so_server_node))
437 rb_erase(&sp->so_server_node, &server->state_owners); 389 rb_erase(&sp->so_server_node, &server->state_owners);
438 nfs_free_unique_id(&server->openowner_id, &sp->so_owner_id); 390 ida_remove(&server->openowner_id, sp->so_seqid.owner_id);
391}
392
393static void
394nfs4_init_seqid_counter(struct nfs_seqid_counter *sc)
395{
396 sc->flags = 0;
397 sc->counter = 0;
398 spin_lock_init(&sc->lock);
399 INIT_LIST_HEAD(&sc->list);
400 rpc_init_wait_queue(&sc->wait, "Seqid_waitqueue");
401}
402
403static void
404nfs4_destroy_seqid_counter(struct nfs_seqid_counter *sc)
405{
406 rpc_destroy_wait_queue(&sc->wait);
439} 407}
440 408
441/* 409/*
@@ -444,19 +412,20 @@ nfs4_remove_state_owner_locked(struct nfs4_state_owner *sp)
444 * 412 *
445 */ 413 */
446static struct nfs4_state_owner * 414static struct nfs4_state_owner *
447nfs4_alloc_state_owner(void) 415nfs4_alloc_state_owner(struct nfs_server *server,
416 struct rpc_cred *cred,
417 gfp_t gfp_flags)
448{ 418{
449 struct nfs4_state_owner *sp; 419 struct nfs4_state_owner *sp;
450 420
451 sp = kzalloc(sizeof(*sp),GFP_NOFS); 421 sp = kzalloc(sizeof(*sp), gfp_flags);
452 if (!sp) 422 if (!sp)
453 return NULL; 423 return NULL;
424 sp->so_server = server;
425 sp->so_cred = get_rpccred(cred);
454 spin_lock_init(&sp->so_lock); 426 spin_lock_init(&sp->so_lock);
455 INIT_LIST_HEAD(&sp->so_states); 427 INIT_LIST_HEAD(&sp->so_states);
456 rpc_init_wait_queue(&sp->so_sequence.wait, "Seqid_waitqueue"); 428 nfs4_init_seqid_counter(&sp->so_seqid);
457 sp->so_seqid.sequence = &sp->so_sequence;
458 spin_lock_init(&sp->so_sequence.lock);
459 INIT_LIST_HEAD(&sp->so_sequence.list);
460 atomic_set(&sp->so_count, 1); 429 atomic_set(&sp->so_count, 1);
461 INIT_LIST_HEAD(&sp->so_lru); 430 INIT_LIST_HEAD(&sp->so_lru);
462 return sp; 431 return sp;
@@ -478,7 +447,7 @@ nfs4_drop_state_owner(struct nfs4_state_owner *sp)
478 447
479static void nfs4_free_state_owner(struct nfs4_state_owner *sp) 448static void nfs4_free_state_owner(struct nfs4_state_owner *sp)
480{ 449{
481 rpc_destroy_wait_queue(&sp->so_sequence.wait); 450 nfs4_destroy_seqid_counter(&sp->so_seqid);
482 put_rpccred(sp->so_cred); 451 put_rpccred(sp->so_cred);
483 kfree(sp); 452 kfree(sp);
484} 453}
@@ -516,7 +485,8 @@ static void nfs4_gc_state_owners(struct nfs_server *server)
516 * Returns a pointer to an instantiated nfs4_state_owner struct, or NULL. 485 * Returns a pointer to an instantiated nfs4_state_owner struct, or NULL.
517 */ 486 */
518struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, 487struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server,
519 struct rpc_cred *cred) 488 struct rpc_cred *cred,
489 gfp_t gfp_flags)
520{ 490{
521 struct nfs_client *clp = server->nfs_client; 491 struct nfs_client *clp = server->nfs_client;
522 struct nfs4_state_owner *sp, *new; 492 struct nfs4_state_owner *sp, *new;
@@ -526,20 +496,18 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server,
526 spin_unlock(&clp->cl_lock); 496 spin_unlock(&clp->cl_lock);
527 if (sp != NULL) 497 if (sp != NULL)
528 goto out; 498 goto out;
529 new = nfs4_alloc_state_owner(); 499 new = nfs4_alloc_state_owner(server, cred, gfp_flags);
530 if (new == NULL) 500 if (new == NULL)
531 goto out; 501 goto out;
532 new->so_server = server; 502 do {
533 new->so_cred = cred; 503 if (ida_pre_get(&server->openowner_id, gfp_flags) == 0)
534 spin_lock(&clp->cl_lock); 504 break;
535 sp = nfs4_insert_state_owner_locked(new); 505 spin_lock(&clp->cl_lock);
536 spin_unlock(&clp->cl_lock); 506 sp = nfs4_insert_state_owner_locked(new);
537 if (sp == new) 507 spin_unlock(&clp->cl_lock);
538 get_rpccred(cred); 508 } while (sp == ERR_PTR(-EAGAIN));
539 else { 509 if (sp != new)
540 rpc_destroy_wait_queue(&new->so_sequence.wait); 510 nfs4_free_state_owner(new);
541 kfree(new);
542 }
543out: 511out:
544 nfs4_gc_state_owners(server); 512 nfs4_gc_state_owners(server);
545 return sp; 513 return sp;
@@ -795,15 +763,11 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f
795{ 763{
796 struct nfs4_lock_state *lsp; 764 struct nfs4_lock_state *lsp;
797 struct nfs_server *server = state->owner->so_server; 765 struct nfs_server *server = state->owner->so_server;
798 struct nfs_client *clp = server->nfs_client;
799 766
800 lsp = kzalloc(sizeof(*lsp), GFP_NOFS); 767 lsp = kzalloc(sizeof(*lsp), GFP_NOFS);
801 if (lsp == NULL) 768 if (lsp == NULL)
802 return NULL; 769 return NULL;
803 rpc_init_wait_queue(&lsp->ls_sequence.wait, "lock_seqid_waitqueue"); 770 nfs4_init_seqid_counter(&lsp->ls_seqid);
804 spin_lock_init(&lsp->ls_sequence.lock);
805 INIT_LIST_HEAD(&lsp->ls_sequence.list);
806 lsp->ls_seqid.sequence = &lsp->ls_sequence;
807 atomic_set(&lsp->ls_count, 1); 771 atomic_set(&lsp->ls_count, 1);
808 lsp->ls_state = state; 772 lsp->ls_state = state;
809 lsp->ls_owner.lo_type = type; 773 lsp->ls_owner.lo_type = type;
@@ -815,25 +779,22 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f
815 lsp->ls_owner.lo_u.posix_owner = fl_owner; 779 lsp->ls_owner.lo_u.posix_owner = fl_owner;
816 break; 780 break;
817 default: 781 default:
818 kfree(lsp); 782 goto out_free;
819 return NULL;
820 } 783 }
821 spin_lock(&clp->cl_lock); 784 lsp->ls_seqid.owner_id = ida_simple_get(&server->lockowner_id, 0, 0, GFP_NOFS);
822 nfs_alloc_unique_id_locked(&server->lockowner_id, &lsp->ls_id, 1, 64); 785 if (lsp->ls_seqid.owner_id < 0)
823 spin_unlock(&clp->cl_lock); 786 goto out_free;
824 INIT_LIST_HEAD(&lsp->ls_locks); 787 INIT_LIST_HEAD(&lsp->ls_locks);
825 return lsp; 788 return lsp;
789out_free:
790 kfree(lsp);
791 return NULL;
826} 792}
827 793
828static void nfs4_free_lock_state(struct nfs4_lock_state *lsp) 794void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp)
829{ 795{
830 struct nfs_server *server = lsp->ls_state->owner->so_server; 796 ida_simple_remove(&server->lockowner_id, lsp->ls_seqid.owner_id);
831 struct nfs_client *clp = server->nfs_client; 797 nfs4_destroy_seqid_counter(&lsp->ls_seqid);
832
833 spin_lock(&clp->cl_lock);
834 nfs_free_unique_id(&server->lockowner_id, &lsp->ls_id);
835 spin_unlock(&clp->cl_lock);
836 rpc_destroy_wait_queue(&lsp->ls_sequence.wait);
837 kfree(lsp); 798 kfree(lsp);
838} 799}
839 800
@@ -865,7 +826,7 @@ static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_
865 } 826 }
866 spin_unlock(&state->state_lock); 827 spin_unlock(&state->state_lock);
867 if (new != NULL) 828 if (new != NULL)
868 nfs4_free_lock_state(new); 829 nfs4_free_lock_state(state->owner->so_server, new);
869 return lsp; 830 return lsp;
870} 831}
871 832
@@ -886,9 +847,11 @@ void nfs4_put_lock_state(struct nfs4_lock_state *lsp)
886 if (list_empty(&state->lock_states)) 847 if (list_empty(&state->lock_states))
887 clear_bit(LK_STATE_IN_USE, &state->flags); 848 clear_bit(LK_STATE_IN_USE, &state->flags);
888 spin_unlock(&state->state_lock); 849 spin_unlock(&state->state_lock);
889 if (lsp->ls_flags & NFS_LOCK_INITIALIZED) 850 if (lsp->ls_flags & NFS_LOCK_INITIALIZED) {
890 nfs4_release_lockowner(lsp); 851 if (nfs4_release_lockowner(lsp) == 0)
891 nfs4_free_lock_state(lsp); 852 return;
853 }
854 nfs4_free_lock_state(lsp->ls_state->owner->so_server, lsp);
892} 855}
893 856
894static void nfs4_fl_copy_lock(struct file_lock *dst, struct file_lock *src) 857static void nfs4_fl_copy_lock(struct file_lock *dst, struct file_lock *src)
@@ -918,7 +881,8 @@ int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
918 if (fl->fl_flags & FL_POSIX) 881 if (fl->fl_flags & FL_POSIX)
919 lsp = nfs4_get_lock_state(state, fl->fl_owner, 0, NFS4_POSIX_LOCK_TYPE); 882 lsp = nfs4_get_lock_state(state, fl->fl_owner, 0, NFS4_POSIX_LOCK_TYPE);
920 else if (fl->fl_flags & FL_FLOCK) 883 else if (fl->fl_flags & FL_FLOCK)
921 lsp = nfs4_get_lock_state(state, 0, fl->fl_pid, NFS4_FLOCK_LOCK_TYPE); 884 lsp = nfs4_get_lock_state(state, NULL, fl->fl_pid,
885 NFS4_FLOCK_LOCK_TYPE);
922 else 886 else
923 return -EINVAL; 887 return -EINVAL;
924 if (lsp == NULL) 888 if (lsp == NULL)
@@ -928,28 +892,49 @@ int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
928 return 0; 892 return 0;
929} 893}
930 894
931/* 895static bool nfs4_copy_lock_stateid(nfs4_stateid *dst, struct nfs4_state *state,
932 * Byte-range lock aware utility to initialize the stateid of read/write 896 fl_owner_t fl_owner, pid_t fl_pid)
933 * requests.
934 */
935void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid)
936{ 897{
937 struct nfs4_lock_state *lsp; 898 struct nfs4_lock_state *lsp;
938 int seq; 899 bool ret = false;
939 900
940 do {
941 seq = read_seqbegin(&state->seqlock);
942 memcpy(dst, &state->stateid, sizeof(*dst));
943 } while (read_seqretry(&state->seqlock, seq));
944 if (test_bit(LK_STATE_IN_USE, &state->flags) == 0) 901 if (test_bit(LK_STATE_IN_USE, &state->flags) == 0)
945 return; 902 goto out;
946 903
947 spin_lock(&state->state_lock); 904 spin_lock(&state->state_lock);
948 lsp = __nfs4_find_lock_state(state, fl_owner, fl_pid, NFS4_ANY_LOCK_TYPE); 905 lsp = __nfs4_find_lock_state(state, fl_owner, fl_pid, NFS4_ANY_LOCK_TYPE);
949 if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) 906 if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0) {
950 memcpy(dst, &lsp->ls_stateid, sizeof(*dst)); 907 nfs4_stateid_copy(dst, &lsp->ls_stateid);
908 ret = true;
909 }
951 spin_unlock(&state->state_lock); 910 spin_unlock(&state->state_lock);
952 nfs4_put_lock_state(lsp); 911 nfs4_put_lock_state(lsp);
912out:
913 return ret;
914}
915
916static void nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)
917{
918 int seq;
919
920 do {
921 seq = read_seqbegin(&state->seqlock);
922 nfs4_stateid_copy(dst, &state->stateid);
923 } while (read_seqretry(&state->seqlock, seq));
924}
925
926/*
927 * Byte-range lock aware utility to initialize the stateid of read/write
928 * requests.
929 */
930void nfs4_select_rw_stateid(nfs4_stateid *dst, struct nfs4_state *state,
931 fmode_t fmode, fl_owner_t fl_owner, pid_t fl_pid)
932{
933 if (nfs4_copy_delegation_stateid(dst, state->inode, fmode))
934 return;
935 if (nfs4_copy_lock_stateid(dst, state, fl_owner, fl_pid))
936 return;
937 nfs4_copy_open_stateid(dst, state);
953} 938}
954 939
955struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask) 940struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask)
@@ -960,20 +945,28 @@ struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_m
960 if (new != NULL) { 945 if (new != NULL) {
961 new->sequence = counter; 946 new->sequence = counter;
962 INIT_LIST_HEAD(&new->list); 947 INIT_LIST_HEAD(&new->list);
948 new->task = NULL;
963 } 949 }
964 return new; 950 return new;
965} 951}
966 952
967void nfs_release_seqid(struct nfs_seqid *seqid) 953void nfs_release_seqid(struct nfs_seqid *seqid)
968{ 954{
969 if (!list_empty(&seqid->list)) { 955 struct nfs_seqid_counter *sequence;
970 struct rpc_sequence *sequence = seqid->sequence->sequence;
971 956
972 spin_lock(&sequence->lock); 957 if (list_empty(&seqid->list))
973 list_del_init(&seqid->list); 958 return;
974 spin_unlock(&sequence->lock); 959 sequence = seqid->sequence;
975 rpc_wake_up(&sequence->wait); 960 spin_lock(&sequence->lock);
961 list_del_init(&seqid->list);
962 if (!list_empty(&sequence->list)) {
963 struct nfs_seqid *next;
964
965 next = list_first_entry(&sequence->list,
966 struct nfs_seqid, list);
967 rpc_wake_up_queued_task(&sequence->wait, next->task);
976 } 968 }
969 spin_unlock(&sequence->lock);
977} 970}
978 971
979void nfs_free_seqid(struct nfs_seqid *seqid) 972void nfs_free_seqid(struct nfs_seqid *seqid)
@@ -989,14 +982,14 @@ void nfs_free_seqid(struct nfs_seqid *seqid)
989 */ 982 */
990static void nfs_increment_seqid(int status, struct nfs_seqid *seqid) 983static void nfs_increment_seqid(int status, struct nfs_seqid *seqid)
991{ 984{
992 BUG_ON(list_first_entry(&seqid->sequence->sequence->list, struct nfs_seqid, list) != seqid); 985 BUG_ON(list_first_entry(&seqid->sequence->list, struct nfs_seqid, list) != seqid);
993 switch (status) { 986 switch (status) {
994 case 0: 987 case 0:
995 break; 988 break;
996 case -NFS4ERR_BAD_SEQID: 989 case -NFS4ERR_BAD_SEQID:
997 if (seqid->sequence->flags & NFS_SEQID_CONFIRMED) 990 if (seqid->sequence->flags & NFS_SEQID_CONFIRMED)
998 return; 991 return;
999 printk(KERN_WARNING "NFS: v4 server returned a bad" 992 pr_warn_ratelimited("NFS: v4 server returned a bad"
1000 " sequence-id error on an" 993 " sequence-id error on an"
1001 " unconfirmed sequence %p!\n", 994 " unconfirmed sequence %p!\n",
1002 seqid->sequence); 995 seqid->sequence);
@@ -1040,10 +1033,11 @@ void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid)
1040 1033
1041int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task) 1034int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task)
1042{ 1035{
1043 struct rpc_sequence *sequence = seqid->sequence->sequence; 1036 struct nfs_seqid_counter *sequence = seqid->sequence;
1044 int status = 0; 1037 int status = 0;
1045 1038
1046 spin_lock(&sequence->lock); 1039 spin_lock(&sequence->lock);
1040 seqid->task = task;
1047 if (list_empty(&seqid->list)) 1041 if (list_empty(&seqid->list))
1048 list_add_tail(&seqid->list, &sequence->list); 1042 list_add_tail(&seqid->list, &sequence->list);
1049 if (list_first_entry(&sequence->list, struct nfs_seqid, list) == seqid) 1043 if (list_first_entry(&sequence->list, struct nfs_seqid, list) == seqid)
@@ -1072,19 +1066,28 @@ static void nfs4_clear_state_manager_bit(struct nfs_client *clp)
1072void nfs4_schedule_state_manager(struct nfs_client *clp) 1066void nfs4_schedule_state_manager(struct nfs_client *clp)
1073{ 1067{
1074 struct task_struct *task; 1068 struct task_struct *task;
1069 char buf[INET6_ADDRSTRLEN + sizeof("-manager") + 1];
1075 1070
1076 if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0) 1071 if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0)
1077 return; 1072 return;
1078 __module_get(THIS_MODULE); 1073 __module_get(THIS_MODULE);
1079 atomic_inc(&clp->cl_count); 1074 atomic_inc(&clp->cl_count);
1080 task = kthread_run(nfs4_run_state_manager, clp, "%s-manager", 1075
1081 rpc_peeraddr2str(clp->cl_rpcclient, 1076 /* The rcu_read_lock() is not strictly necessary, as the state
1082 RPC_DISPLAY_ADDR)); 1077 * manager is the only thread that ever changes the rpc_xprt
1083 if (!IS_ERR(task)) 1078 * after it's initialized. At this point, we're single threaded. */
1084 return; 1079 rcu_read_lock();
1085 nfs4_clear_state_manager_bit(clp); 1080 snprintf(buf, sizeof(buf), "%s-manager",
1086 nfs_put_client(clp); 1081 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
1087 module_put(THIS_MODULE); 1082 rcu_read_unlock();
1083 task = kthread_run(nfs4_run_state_manager, clp, buf);
1084 if (IS_ERR(task)) {
1085 printk(KERN_ERR "%s: kthread_run: %ld\n",
1086 __func__, PTR_ERR(task));
1087 nfs4_clear_state_manager_bit(clp);
1088 nfs_put_client(clp);
1089 module_put(THIS_MODULE);
1090 }
1088} 1091}
1089 1092
1090/* 1093/*
@@ -1098,10 +1101,25 @@ void nfs4_schedule_lease_recovery(struct nfs_client *clp)
1098 set_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state); 1101 set_bit(NFS4CLNT_CHECK_LEASE, &clp->cl_state);
1099 nfs4_schedule_state_manager(clp); 1102 nfs4_schedule_state_manager(clp);
1100} 1103}
1104EXPORT_SYMBOL_GPL(nfs4_schedule_lease_recovery);
1105
1106/*
1107 * nfs40_handle_cb_pathdown - return all delegations after NFS4ERR_CB_PATH_DOWN
1108 * @clp: client to process
1109 *
1110 * Set the NFS4CLNT_LEASE_EXPIRED state in order to force a
1111 * resend of the SETCLIENTID and hence re-establish the
1112 * callback channel. Then return all existing delegations.
1113 */
1114static void nfs40_handle_cb_pathdown(struct nfs_client *clp)
1115{
1116 set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
1117 nfs_expire_all_delegations(clp);
1118}
1101 1119
1102void nfs4_schedule_path_down_recovery(struct nfs_client *clp) 1120void nfs4_schedule_path_down_recovery(struct nfs_client *clp)
1103{ 1121{
1104 nfs_handle_cb_pathdown(clp); 1122 nfs40_handle_cb_pathdown(clp);
1105 nfs4_schedule_state_manager(clp); 1123 nfs4_schedule_state_manager(clp);
1106} 1124}
1107 1125
@@ -1132,11 +1150,37 @@ void nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4
1132{ 1150{
1133 struct nfs_client *clp = server->nfs_client; 1151 struct nfs_client *clp = server->nfs_client;
1134 1152
1135 if (test_and_clear_bit(NFS_DELEGATED_STATE, &state->flags))
1136 nfs_async_inode_return_delegation(state->inode, &state->stateid);
1137 nfs4_state_mark_reclaim_nograce(clp, state); 1153 nfs4_state_mark_reclaim_nograce(clp, state);
1138 nfs4_schedule_state_manager(clp); 1154 nfs4_schedule_state_manager(clp);
1139} 1155}
1156EXPORT_SYMBOL_GPL(nfs4_schedule_stateid_recovery);
1157
1158void nfs_inode_find_state_and_recover(struct inode *inode,
1159 const nfs4_stateid *stateid)
1160{
1161 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
1162 struct nfs_inode *nfsi = NFS_I(inode);
1163 struct nfs_open_context *ctx;
1164 struct nfs4_state *state;
1165 bool found = false;
1166
1167 spin_lock(&inode->i_lock);
1168 list_for_each_entry(ctx, &nfsi->open_files, list) {
1169 state = ctx->state;
1170 if (state == NULL)
1171 continue;
1172 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
1173 continue;
1174 if (!nfs4_stateid_match(&state->stateid, stateid))
1175 continue;
1176 nfs4_state_mark_reclaim_nograce(clp, state);
1177 found = true;
1178 }
1179 spin_unlock(&inode->i_lock);
1180 if (found)
1181 nfs4_schedule_state_manager(clp);
1182}
1183
1140 1184
1141static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops) 1185static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_recovery_ops *ops)
1142{ 1186{
@@ -1175,8 +1219,8 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
1175 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION: 1219 case -NFS4ERR_CONN_NOT_BOUND_TO_SESSION:
1176 goto out; 1220 goto out;
1177 default: 1221 default:
1178 printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n", 1222 printk(KERN_ERR "NFS: %s: unhandled error %d. "
1179 __func__, status); 1223 "Zeroing state\n", __func__, status);
1180 case -ENOMEM: 1224 case -ENOMEM:
1181 case -NFS4ERR_DENIED: 1225 case -NFS4ERR_DENIED:
1182 case -NFS4ERR_RECLAIM_BAD: 1226 case -NFS4ERR_RECLAIM_BAD:
@@ -1222,8 +1266,9 @@ restart:
1222 spin_lock(&state->state_lock); 1266 spin_lock(&state->state_lock);
1223 list_for_each_entry(lock, &state->lock_states, ls_locks) { 1267 list_for_each_entry(lock, &state->lock_states, ls_locks) {
1224 if (!(lock->ls_flags & NFS_LOCK_INITIALIZED)) 1268 if (!(lock->ls_flags & NFS_LOCK_INITIALIZED))
1225 printk("%s: Lock reclaim failed!\n", 1269 pr_warn_ratelimited("NFS: "
1226 __func__); 1270 "%s: Lock reclaim "
1271 "failed!\n", __func__);
1227 } 1272 }
1228 spin_unlock(&state->state_lock); 1273 spin_unlock(&state->state_lock);
1229 nfs4_put_open_state(state); 1274 nfs4_put_open_state(state);
@@ -1232,8 +1277,8 @@ restart:
1232 } 1277 }
1233 switch (status) { 1278 switch (status) {
1234 default: 1279 default:
1235 printk(KERN_ERR "%s: unhandled error %d. Zeroing state\n", 1280 printk(KERN_ERR "NFS: %s: unhandled error %d. "
1236 __func__, status); 1281 "Zeroing state\n", __func__, status);
1237 case -ENOENT: 1282 case -ENOENT:
1238 case -ENOMEM: 1283 case -ENOMEM:
1239 case -ESTALE: 1284 case -ESTALE:
@@ -1241,8 +1286,8 @@ restart:
1241 * Open state on this file cannot be recovered 1286 * Open state on this file cannot be recovered
1242 * All we can do is revert to using the zero stateid. 1287 * All we can do is revert to using the zero stateid.
1243 */ 1288 */
1244 memset(state->stateid.data, 0, 1289 memset(&state->stateid, 0,
1245 sizeof(state->stateid.data)); 1290 sizeof(state->stateid));
1246 /* Mark the file as being 'closed' */ 1291 /* Mark the file as being 'closed' */
1247 state->state = 0; 1292 state->state = 0;
1248 break; 1293 break;
@@ -1420,7 +1465,7 @@ static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)
1420 case 0: 1465 case 0:
1421 break; 1466 break;
1422 case -NFS4ERR_CB_PATH_DOWN: 1467 case -NFS4ERR_CB_PATH_DOWN:
1423 nfs_handle_cb_pathdown(clp); 1468 nfs40_handle_cb_pathdown(clp);
1424 break; 1469 break;
1425 case -NFS4ERR_NO_GRACE: 1470 case -NFS4ERR_NO_GRACE:
1426 nfs4_state_end_reclaim_reboot(clp); 1471 nfs4_state_end_reclaim_reboot(clp);
@@ -1801,7 +1846,7 @@ static void nfs4_state_manager(struct nfs_client *clp)
1801 } while (atomic_read(&clp->cl_count) > 1); 1846 } while (atomic_read(&clp->cl_count) > 1);
1802 return; 1847 return;
1803out_error: 1848out_error:
1804 printk(KERN_WARNING "Error: state manager failed on NFSv4 server %s" 1849 pr_warn_ratelimited("NFS: state manager failed on NFSv4 server %s"
1805 " with error %d\n", clp->cl_hostname, -status); 1850 " with error %d\n", clp->cl_hostname, -status);
1806 nfs4_end_drain_session(clp); 1851 nfs4_end_drain_session(clp);
1807 nfs4_clear_state_manager_bit(clp); 1852 nfs4_clear_state_manager_bit(clp);
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 33bd8d0f745..c74fdb114b4 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -44,6 +44,8 @@
44#include <linux/pagemap.h> 44#include <linux/pagemap.h>
45#include <linux/proc_fs.h> 45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h> 46#include <linux/kdev_t.h>
47#include <linux/module.h>
48#include <linux/utsname.h>
47#include <linux/sunrpc/clnt.h> 49#include <linux/sunrpc/clnt.h>
48#include <linux/sunrpc/msg_prot.h> 50#include <linux/sunrpc/msg_prot.h>
49#include <linux/sunrpc/gss_api.h> 51#include <linux/sunrpc/gss_api.h>
@@ -271,7 +273,12 @@ static int nfs4_stat_to_errno(int);
271 1 /* flags */ + \ 273 1 /* flags */ + \
272 1 /* spa_how */ + \ 274 1 /* spa_how */ + \
273 0 /* SP4_NONE (for now) */ + \ 275 0 /* SP4_NONE (for now) */ + \
274 1 /* zero implemetation id array */) 276 1 /* implementation id array of size 1 */ + \
277 1 /* nii_domain */ + \
278 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
279 1 /* nii_name */ + \
280 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
281 3 /* nii_date */)
275#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \ 282#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
276 2 /* eir_clientid */ + \ 283 2 /* eir_clientid */ + \
277 1 /* eir_sequenceid */ + \ 284 1 /* eir_sequenceid */ + \
@@ -284,7 +291,11 @@ static int nfs4_stat_to_errno(int);
284 /* eir_server_scope<> */ \ 291 /* eir_server_scope<> */ \
285 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \ 292 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
286 1 /* eir_server_impl_id array length */ + \ 293 1 /* eir_server_impl_id array length */ + \
287 0 /* ignored eir_server_impl_id contents */) 294 1 /* nii_domain */ + \
295 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
296 1 /* nii_name */ + \
297 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
298 3 /* nii_date */)
288#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */) 299#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
289#define decode_channel_attrs_maxsz (6 + \ 300#define decode_channel_attrs_maxsz (6 + \
290 1 /* ca_rdma_ird.len */ + \ 301 1 /* ca_rdma_ird.len */ + \
@@ -838,6 +849,12 @@ const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
838 XDR_UNIT); 849 XDR_UNIT);
839#endif /* CONFIG_NFS_V4_1 */ 850#endif /* CONFIG_NFS_V4_1 */
840 851
852static unsigned short send_implementation_id = 1;
853
854module_param(send_implementation_id, ushort, 0644);
855MODULE_PARM_DESC(send_implementation_id,
856 "Send implementation ID with NFSv4.1 exchange_id");
857
841static const umode_t nfs_type2fmt[] = { 858static const umode_t nfs_type2fmt[] = {
842 [NF4BAD] = 0, 859 [NF4BAD] = 0,
843 [NF4REG] = S_IFREG, 860 [NF4REG] = S_IFREG,
@@ -868,15 +885,44 @@ static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
868 return p; 885 return p;
869} 886}
870 887
888static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
889{
890 __be32 *p;
891
892 p = xdr_reserve_space(xdr, len);
893 xdr_encode_opaque_fixed(p, buf, len);
894}
895
871static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) 896static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
872{ 897{
873 __be32 *p; 898 __be32 *p;
874 899
875 p = xdr_reserve_space(xdr, 4 + len); 900 p = reserve_space(xdr, 4 + len);
876 BUG_ON(p == NULL);
877 xdr_encode_opaque(p, str, len); 901 xdr_encode_opaque(p, str, len);
878} 902}
879 903
904static void encode_uint32(struct xdr_stream *xdr, u32 n)
905{
906 __be32 *p;
907
908 p = reserve_space(xdr, 4);
909 *p = cpu_to_be32(n);
910}
911
912static void encode_uint64(struct xdr_stream *xdr, u64 n)
913{
914 __be32 *p;
915
916 p = reserve_space(xdr, 8);
917 xdr_encode_hyper(p, n);
918}
919
920static void encode_nfs4_seqid(struct xdr_stream *xdr,
921 const struct nfs_seqid *seqid)
922{
923 encode_uint32(xdr, seqid->sequence->counter);
924}
925
880static void encode_compound_hdr(struct xdr_stream *xdr, 926static void encode_compound_hdr(struct xdr_stream *xdr,
881 struct rpc_rqst *req, 927 struct rpc_rqst *req,
882 struct compound_hdr *hdr) 928 struct compound_hdr *hdr)
@@ -889,28 +935,37 @@ static void encode_compound_hdr(struct xdr_stream *xdr,
889 * but this is not required as a MUST for the server to do so. */ 935 * but this is not required as a MUST for the server to do so. */
890 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen; 936 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
891 937
892 dprintk("encode_compound: tag=%.*s\n", (int)hdr->taglen, hdr->tag);
893 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN); 938 BUG_ON(hdr->taglen > NFS4_MAXTAGLEN);
894 p = reserve_space(xdr, 4 + hdr->taglen + 8); 939 encode_string(xdr, hdr->taglen, hdr->tag);
895 p = xdr_encode_opaque(p, hdr->tag, hdr->taglen); 940 p = reserve_space(xdr, 8);
896 *p++ = cpu_to_be32(hdr->minorversion); 941 *p++ = cpu_to_be32(hdr->minorversion);
897 hdr->nops_p = p; 942 hdr->nops_p = p;
898 *p = cpu_to_be32(hdr->nops); 943 *p = cpu_to_be32(hdr->nops);
899} 944}
900 945
946static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
947 uint32_t replen,
948 struct compound_hdr *hdr)
949{
950 encode_uint32(xdr, op);
951 hdr->nops++;
952 hdr->replen += replen;
953}
954
901static void encode_nops(struct compound_hdr *hdr) 955static void encode_nops(struct compound_hdr *hdr)
902{ 956{
903 BUG_ON(hdr->nops > NFS4_MAX_OPS); 957 BUG_ON(hdr->nops > NFS4_MAX_OPS);
904 *hdr->nops_p = htonl(hdr->nops); 958 *hdr->nops_p = htonl(hdr->nops);
905} 959}
906 960
907static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf) 961static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
908{ 962{
909 __be32 *p; 963 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
964}
910 965
911 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); 966static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
912 BUG_ON(p == NULL); 967{
913 xdr_encode_opaque_fixed(p, verf->data, NFS4_VERIFIER_SIZE); 968 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
914} 969}
915 970
916static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server) 971static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const struct nfs_server *server)
@@ -1023,7 +1078,7 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
1023 * Now we backfill the bitmap and the attribute buffer length. 1078 * Now we backfill the bitmap and the attribute buffer length.
1024 */ 1079 */
1025 if (len != ((char *)p - (char *)q) + 4) { 1080 if (len != ((char *)p - (char *)q) + 4) {
1026 printk(KERN_ERR "nfs: Attr length error, %u != %Zu\n", 1081 printk(KERN_ERR "NFS: Attr length error, %u != %Zu\n",
1027 len, ((char *)p - (char *)q) + 4); 1082 len, ((char *)p - (char *)q) + 4);
1028 BUG(); 1083 BUG();
1029 } 1084 }
@@ -1037,46 +1092,33 @@ static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap, const
1037 1092
1038static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr) 1093static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
1039{ 1094{
1040 __be32 *p; 1095 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1041 1096 encode_uint32(xdr, access);
1042 p = reserve_space(xdr, 8);
1043 *p++ = cpu_to_be32(OP_ACCESS);
1044 *p = cpu_to_be32(access);
1045 hdr->nops++;
1046 hdr->replen += decode_access_maxsz;
1047} 1097}
1048 1098
1049static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 1099static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1050{ 1100{
1051 __be32 *p; 1101 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
1052 1102 encode_nfs4_seqid(xdr, arg->seqid);
1053 p = reserve_space(xdr, 8+NFS4_STATEID_SIZE); 1103 encode_nfs4_stateid(xdr, arg->stateid);
1054 *p++ = cpu_to_be32(OP_CLOSE);
1055 *p++ = cpu_to_be32(arg->seqid->sequence->counter);
1056 xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1057 hdr->nops++;
1058 hdr->replen += decode_close_maxsz;
1059} 1104}
1060 1105
1061static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 1106static void encode_commit(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1062{ 1107{
1063 __be32 *p; 1108 __be32 *p;
1064 1109
1065 p = reserve_space(xdr, 16); 1110 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1066 *p++ = cpu_to_be32(OP_COMMIT); 1111 p = reserve_space(xdr, 12);
1067 p = xdr_encode_hyper(p, args->offset); 1112 p = xdr_encode_hyper(p, args->offset);
1068 *p = cpu_to_be32(args->count); 1113 *p = cpu_to_be32(args->count);
1069 hdr->nops++;
1070 hdr->replen += decode_commit_maxsz;
1071} 1114}
1072 1115
1073static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr) 1116static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
1074{ 1117{
1075 __be32 *p; 1118 __be32 *p;
1076 1119
1077 p = reserve_space(xdr, 8); 1120 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1078 *p++ = cpu_to_be32(OP_CREATE); 1121 encode_uint32(xdr, create->ftype);
1079 *p = cpu_to_be32(create->ftype);
1080 1122
1081 switch (create->ftype) { 1123 switch (create->ftype) {
1082 case NF4LNK: 1124 case NF4LNK:
@@ -1096,9 +1138,6 @@ static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *
1096 } 1138 }
1097 1139
1098 encode_string(xdr, create->name->len, create->name->name); 1140 encode_string(xdr, create->name->len, create->name->name);
1099 hdr->nops++;
1100 hdr->replen += decode_create_maxsz;
1101
1102 encode_attrs(xdr, create->attrs, create->server); 1141 encode_attrs(xdr, create->attrs, create->server);
1103} 1142}
1104 1143
@@ -1106,25 +1145,21 @@ static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct c
1106{ 1145{
1107 __be32 *p; 1146 __be32 *p;
1108 1147
1109 p = reserve_space(xdr, 12); 1148 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1110 *p++ = cpu_to_be32(OP_GETATTR); 1149 p = reserve_space(xdr, 8);
1111 *p++ = cpu_to_be32(1); 1150 *p++ = cpu_to_be32(1);
1112 *p = cpu_to_be32(bitmap); 1151 *p = cpu_to_be32(bitmap);
1113 hdr->nops++;
1114 hdr->replen += decode_getattr_maxsz;
1115} 1152}
1116 1153
1117static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr) 1154static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
1118{ 1155{
1119 __be32 *p; 1156 __be32 *p;
1120 1157
1121 p = reserve_space(xdr, 16); 1158 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1122 *p++ = cpu_to_be32(OP_GETATTR); 1159 p = reserve_space(xdr, 12);
1123 *p++ = cpu_to_be32(2); 1160 *p++ = cpu_to_be32(2);
1124 *p++ = cpu_to_be32(bm0); 1161 *p++ = cpu_to_be32(bm0);
1125 *p = cpu_to_be32(bm1); 1162 *p = cpu_to_be32(bm1);
1126 hdr->nops++;
1127 hdr->replen += decode_getattr_maxsz;
1128} 1163}
1129 1164
1130static void 1165static void
@@ -1134,8 +1169,7 @@ encode_getattr_three(struct xdr_stream *xdr,
1134{ 1169{
1135 __be32 *p; 1170 __be32 *p;
1136 1171
1137 p = reserve_space(xdr, 4); 1172 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1138 *p = cpu_to_be32(OP_GETATTR);
1139 if (bm2) { 1173 if (bm2) {
1140 p = reserve_space(xdr, 16); 1174 p = reserve_space(xdr, 16);
1141 *p++ = cpu_to_be32(3); 1175 *p++ = cpu_to_be32(3);
@@ -1152,8 +1186,6 @@ encode_getattr_three(struct xdr_stream *xdr,
1152 *p++ = cpu_to_be32(1); 1186 *p++ = cpu_to_be32(1);
1153 *p = cpu_to_be32(bm0); 1187 *p = cpu_to_be32(bm0);
1154 } 1188 }
1155 hdr->nops++;
1156 hdr->replen += decode_getattr_maxsz;
1157} 1189}
1158 1190
1159static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr) 1191static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
@@ -1179,23 +1211,13 @@ static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, stru
1179 1211
1180static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 1212static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1181{ 1213{
1182 __be32 *p; 1214 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
1183
1184 p = reserve_space(xdr, 4);
1185 *p = cpu_to_be32(OP_GETFH);
1186 hdr->nops++;
1187 hdr->replen += decode_getfh_maxsz;
1188} 1215}
1189 1216
1190static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 1217static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1191{ 1218{
1192 __be32 *p; 1219 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
1193 1220 encode_string(xdr, name->len, name->name);
1194 p = reserve_space(xdr, 8 + name->len);
1195 *p++ = cpu_to_be32(OP_LINK);
1196 xdr_encode_opaque(p, name->name, name->len);
1197 hdr->nops++;
1198 hdr->replen += decode_link_maxsz;
1199} 1221}
1200 1222
1201static inline int nfs4_lock_type(struct file_lock *fl, int block) 1223static inline int nfs4_lock_type(struct file_lock *fl, int block)
@@ -1232,79 +1254,60 @@ static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args
1232{ 1254{
1233 __be32 *p; 1255 __be32 *p;
1234 1256
1235 p = reserve_space(xdr, 32); 1257 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1236 *p++ = cpu_to_be32(OP_LOCK); 1258 p = reserve_space(xdr, 28);
1237 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block)); 1259 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1238 *p++ = cpu_to_be32(args->reclaim); 1260 *p++ = cpu_to_be32(args->reclaim);
1239 p = xdr_encode_hyper(p, args->fl->fl_start); 1261 p = xdr_encode_hyper(p, args->fl->fl_start);
1240 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1262 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1241 *p = cpu_to_be32(args->new_lock_owner); 1263 *p = cpu_to_be32(args->new_lock_owner);
1242 if (args->new_lock_owner){ 1264 if (args->new_lock_owner){
1243 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); 1265 encode_nfs4_seqid(xdr, args->open_seqid);
1244 *p++ = cpu_to_be32(args->open_seqid->sequence->counter); 1266 encode_nfs4_stateid(xdr, args->open_stateid);
1245 p = xdr_encode_opaque_fixed(p, args->open_stateid->data, NFS4_STATEID_SIZE); 1267 encode_nfs4_seqid(xdr, args->lock_seqid);
1246 *p++ = cpu_to_be32(args->lock_seqid->sequence->counter);
1247 encode_lockowner(xdr, &args->lock_owner); 1268 encode_lockowner(xdr, &args->lock_owner);
1248 } 1269 }
1249 else { 1270 else {
1250 p = reserve_space(xdr, NFS4_STATEID_SIZE+4); 1271 encode_nfs4_stateid(xdr, args->lock_stateid);
1251 p = xdr_encode_opaque_fixed(p, args->lock_stateid->data, NFS4_STATEID_SIZE); 1272 encode_nfs4_seqid(xdr, args->lock_seqid);
1252 *p = cpu_to_be32(args->lock_seqid->sequence->counter);
1253 } 1273 }
1254 hdr->nops++;
1255 hdr->replen += decode_lock_maxsz;
1256} 1274}
1257 1275
1258static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr) 1276static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
1259{ 1277{
1260 __be32 *p; 1278 __be32 *p;
1261 1279
1262 p = reserve_space(xdr, 24); 1280 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1263 *p++ = cpu_to_be32(OP_LOCKT); 1281 p = reserve_space(xdr, 20);
1264 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1282 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1265 p = xdr_encode_hyper(p, args->fl->fl_start); 1283 p = xdr_encode_hyper(p, args->fl->fl_start);
1266 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1284 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1267 encode_lockowner(xdr, &args->lock_owner); 1285 encode_lockowner(xdr, &args->lock_owner);
1268 hdr->nops++;
1269 hdr->replen += decode_lockt_maxsz;
1270} 1286}
1271 1287
1272static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr) 1288static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
1273{ 1289{
1274 __be32 *p; 1290 __be32 *p;
1275 1291
1276 p = reserve_space(xdr, 12+NFS4_STATEID_SIZE+16); 1292 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1277 *p++ = cpu_to_be32(OP_LOCKU); 1293 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
1278 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0)); 1294 encode_nfs4_seqid(xdr, args->seqid);
1279 *p++ = cpu_to_be32(args->seqid->sequence->counter); 1295 encode_nfs4_stateid(xdr, args->stateid);
1280 p = xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE); 1296 p = reserve_space(xdr, 16);
1281 p = xdr_encode_hyper(p, args->fl->fl_start); 1297 p = xdr_encode_hyper(p, args->fl->fl_start);
1282 xdr_encode_hyper(p, nfs4_lock_length(args->fl)); 1298 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1283 hdr->nops++;
1284 hdr->replen += decode_locku_maxsz;
1285} 1299}
1286 1300
1287static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr) 1301static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1288{ 1302{
1289 __be32 *p; 1303 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1290
1291 p = reserve_space(xdr, 4);
1292 *p = cpu_to_be32(OP_RELEASE_LOCKOWNER);
1293 encode_lockowner(xdr, lowner); 1304 encode_lockowner(xdr, lowner);
1294 hdr->nops++;
1295 hdr->replen += decode_release_lockowner_maxsz;
1296} 1305}
1297 1306
1298static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 1307static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1299{ 1308{
1300 int len = name->len; 1309 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
1301 __be32 *p; 1310 encode_string(xdr, name->len, name->name);
1302
1303 p = reserve_space(xdr, 8 + len);
1304 *p++ = cpu_to_be32(OP_LOOKUP);
1305 xdr_encode_opaque(p, name->name, len);
1306 hdr->nops++;
1307 hdr->replen += decode_lookup_maxsz;
1308} 1311}
1309 1312
1310static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode) 1313static void encode_share_access(struct xdr_stream *xdr, fmode_t fmode)
@@ -1335,9 +1338,7 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena
1335 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4, 1338 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1336 * owner 4 = 32 1339 * owner 4 = 32
1337 */ 1340 */
1338 p = reserve_space(xdr, 8); 1341 encode_nfs4_seqid(xdr, arg->seqid);
1339 *p++ = cpu_to_be32(OP_OPEN);
1340 *p = cpu_to_be32(arg->seqid->sequence->counter);
1341 encode_share_access(xdr, arg->fmode); 1342 encode_share_access(xdr, arg->fmode);
1342 p = reserve_space(xdr, 32); 1343 p = reserve_space(xdr, 32);
1343 p = xdr_encode_hyper(p, arg->clientid); 1344 p = xdr_encode_hyper(p, arg->clientid);
@@ -1437,14 +1438,15 @@ static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struc
1437{ 1438{
1438 __be32 *p; 1439 __be32 *p;
1439 1440
1440 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); 1441 p = reserve_space(xdr, 4);
1441 *p++ = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR); 1442 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1442 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE); 1443 encode_nfs4_stateid(xdr, stateid);
1443 encode_string(xdr, name->len, name->name); 1444 encode_string(xdr, name->len, name->name);
1444} 1445}
1445 1446
1446static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr) 1447static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
1447{ 1448{
1449 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
1448 encode_openhdr(xdr, arg); 1450 encode_openhdr(xdr, arg);
1449 encode_opentype(xdr, arg); 1451 encode_opentype(xdr, arg);
1450 switch (arg->claim) { 1452 switch (arg->claim) {
@@ -1460,88 +1462,64 @@ static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg,
1460 default: 1462 default:
1461 BUG(); 1463 BUG();
1462 } 1464 }
1463 hdr->nops++;
1464 hdr->replen += decode_open_maxsz;
1465} 1465}
1466 1466
1467static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr) 1467static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
1468{ 1468{
1469 __be32 *p; 1469 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1470 1470 encode_nfs4_stateid(xdr, arg->stateid);
1471 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); 1471 encode_nfs4_seqid(xdr, arg->seqid);
1472 *p++ = cpu_to_be32(OP_OPEN_CONFIRM);
1473 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1474 *p = cpu_to_be32(arg->seqid->sequence->counter);
1475 hdr->nops++;
1476 hdr->replen += decode_open_confirm_maxsz;
1477} 1472}
1478 1473
1479static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr) 1474static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
1480{ 1475{
1481 __be32 *p; 1476 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1482 1477 encode_nfs4_stateid(xdr, arg->stateid);
1483 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE+4); 1478 encode_nfs4_seqid(xdr, arg->seqid);
1484 *p++ = cpu_to_be32(OP_OPEN_DOWNGRADE);
1485 p = xdr_encode_opaque_fixed(p, arg->stateid->data, NFS4_STATEID_SIZE);
1486 *p = cpu_to_be32(arg->seqid->sequence->counter);
1487 encode_share_access(xdr, arg->fmode); 1479 encode_share_access(xdr, arg->fmode);
1488 hdr->nops++;
1489 hdr->replen += decode_open_downgrade_maxsz;
1490} 1480}
1491 1481
1492static void 1482static void
1493encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr) 1483encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
1494{ 1484{
1495 int len = fh->size; 1485 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
1496 __be32 *p; 1486 encode_string(xdr, fh->size, fh->data);
1497
1498 p = reserve_space(xdr, 8 + len);
1499 *p++ = cpu_to_be32(OP_PUTFH);
1500 xdr_encode_opaque(p, fh->data, len);
1501 hdr->nops++;
1502 hdr->replen += decode_putfh_maxsz;
1503} 1487}
1504 1488
1505static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr) 1489static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1506{ 1490{
1507 __be32 *p; 1491 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
1508
1509 p = reserve_space(xdr, 4);
1510 *p = cpu_to_be32(OP_PUTROOTFH);
1511 hdr->nops++;
1512 hdr->replen += decode_putrootfh_maxsz;
1513} 1492}
1514 1493
1515static void encode_stateid(struct xdr_stream *xdr, const struct nfs_open_context *ctx, const struct nfs_lock_context *l_ctx, int zero_seqid) 1494static void encode_open_stateid(struct xdr_stream *xdr,
1495 const struct nfs_open_context *ctx,
1496 const struct nfs_lock_context *l_ctx,
1497 fmode_t fmode,
1498 int zero_seqid)
1516{ 1499{
1517 nfs4_stateid stateid; 1500 nfs4_stateid stateid;
1518 __be32 *p;
1519 1501
1520 p = reserve_space(xdr, NFS4_STATEID_SIZE);
1521 if (ctx->state != NULL) { 1502 if (ctx->state != NULL) {
1522 nfs4_copy_stateid(&stateid, ctx->state, l_ctx->lockowner, l_ctx->pid); 1503 nfs4_select_rw_stateid(&stateid, ctx->state,
1504 fmode, l_ctx->lockowner, l_ctx->pid);
1523 if (zero_seqid) 1505 if (zero_seqid)
1524 stateid.stateid.seqid = 0; 1506 stateid.seqid = 0;
1525 xdr_encode_opaque_fixed(p, stateid.data, NFS4_STATEID_SIZE); 1507 encode_nfs4_stateid(xdr, &stateid);
1526 } else 1508 } else
1527 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE); 1509 encode_nfs4_stateid(xdr, &zero_stateid);
1528} 1510}
1529 1511
1530static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr) 1512static void encode_read(struct xdr_stream *xdr, const struct nfs_readargs *args, struct compound_hdr *hdr)
1531{ 1513{
1532 __be32 *p; 1514 __be32 *p;
1533 1515
1534 p = reserve_space(xdr, 4); 1516 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
1535 *p = cpu_to_be32(OP_READ); 1517 encode_open_stateid(xdr, args->context, args->lock_context,
1536 1518 FMODE_READ, hdr->minorversion);
1537 encode_stateid(xdr, args->context, args->lock_context,
1538 hdr->minorversion);
1539 1519
1540 p = reserve_space(xdr, 12); 1520 p = reserve_space(xdr, 12);
1541 p = xdr_encode_hyper(p, args->offset); 1521 p = xdr_encode_hyper(p, args->offset);
1542 *p = cpu_to_be32(args->count); 1522 *p = cpu_to_be32(args->count);
1543 hdr->nops++;
1544 hdr->replen += decode_read_maxsz;
1545} 1523}
1546 1524
1547static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr) 1525static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
@@ -1551,7 +1529,7 @@ static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg
1551 FATTR4_WORD1_MOUNTED_ON_FILEID, 1529 FATTR4_WORD1_MOUNTED_ON_FILEID,
1552 }; 1530 };
1553 uint32_t dircount = readdir->count >> 1; 1531 uint32_t dircount = readdir->count >> 1;
1554 __be32 *p; 1532 __be32 *p, verf[2];
1555 1533
1556 if (readdir->plus) { 1534 if (readdir->plus) {
1557 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE| 1535 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
@@ -1566,80 +1544,54 @@ static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg
1566 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) 1544 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1567 attrs[0] |= FATTR4_WORD0_FILEID; 1545 attrs[0] |= FATTR4_WORD0_FILEID;
1568 1546
1569 p = reserve_space(xdr, 12+NFS4_VERIFIER_SIZE+20); 1547 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1570 *p++ = cpu_to_be32(OP_READDIR); 1548 encode_uint64(xdr, readdir->cookie);
1571 p = xdr_encode_hyper(p, readdir->cookie); 1549 encode_nfs4_verifier(xdr, &readdir->verifier);
1572 p = xdr_encode_opaque_fixed(p, readdir->verifier.data, NFS4_VERIFIER_SIZE); 1550 p = reserve_space(xdr, 20);
1573 *p++ = cpu_to_be32(dircount); 1551 *p++ = cpu_to_be32(dircount);
1574 *p++ = cpu_to_be32(readdir->count); 1552 *p++ = cpu_to_be32(readdir->count);
1575 *p++ = cpu_to_be32(2); 1553 *p++ = cpu_to_be32(2);
1576 1554
1577 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]); 1555 *p++ = cpu_to_be32(attrs[0] & readdir->bitmask[0]);
1578 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]); 1556 *p = cpu_to_be32(attrs[1] & readdir->bitmask[1]);
1579 hdr->nops++; 1557 memcpy(verf, readdir->verifier.data, sizeof(verf));
1580 hdr->replen += decode_readdir_maxsz;
1581 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n", 1558 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1582 __func__, 1559 __func__,
1583 (unsigned long long)readdir->cookie, 1560 (unsigned long long)readdir->cookie,
1584 ((u32 *)readdir->verifier.data)[0], 1561 verf[0], verf[1],
1585 ((u32 *)readdir->verifier.data)[1],
1586 attrs[0] & readdir->bitmask[0], 1562 attrs[0] & readdir->bitmask[0],
1587 attrs[1] & readdir->bitmask[1]); 1563 attrs[1] & readdir->bitmask[1]);
1588} 1564}
1589 1565
1590static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr) 1566static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
1591{ 1567{
1592 __be32 *p; 1568 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
1593
1594 p = reserve_space(xdr, 4);
1595 *p = cpu_to_be32(OP_READLINK);
1596 hdr->nops++;
1597 hdr->replen += decode_readlink_maxsz;
1598} 1569}
1599 1570
1600static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 1571static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1601{ 1572{
1602 __be32 *p; 1573 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
1603 1574 encode_string(xdr, name->len, name->name);
1604 p = reserve_space(xdr, 8 + name->len);
1605 *p++ = cpu_to_be32(OP_REMOVE);
1606 xdr_encode_opaque(p, name->name, name->len);
1607 hdr->nops++;
1608 hdr->replen += decode_remove_maxsz;
1609} 1575}
1610 1576
1611static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr) 1577static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
1612{ 1578{
1613 __be32 *p; 1579 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1614
1615 p = reserve_space(xdr, 4);
1616 *p = cpu_to_be32(OP_RENAME);
1617 encode_string(xdr, oldname->len, oldname->name); 1580 encode_string(xdr, oldname->len, oldname->name);
1618 encode_string(xdr, newname->len, newname->name); 1581 encode_string(xdr, newname->len, newname->name);
1619 hdr->nops++;
1620 hdr->replen += decode_rename_maxsz;
1621} 1582}
1622 1583
1623static void encode_renew(struct xdr_stream *xdr, const struct nfs_client *client_stateid, struct compound_hdr *hdr) 1584static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1585 struct compound_hdr *hdr)
1624{ 1586{
1625 __be32 *p; 1587 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1626 1588 encode_uint64(xdr, clid);
1627 p = reserve_space(xdr, 12);
1628 *p++ = cpu_to_be32(OP_RENEW);
1629 xdr_encode_hyper(p, client_stateid->cl_clientid);
1630 hdr->nops++;
1631 hdr->replen += decode_renew_maxsz;
1632} 1589}
1633 1590
1634static void 1591static void
1635encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 1592encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1636{ 1593{
1637 __be32 *p; 1594 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
1638
1639 p = reserve_space(xdr, 4);
1640 *p = cpu_to_be32(OP_RESTOREFH);
1641 hdr->nops++;
1642 hdr->replen += decode_restorefh_maxsz;
1643} 1595}
1644 1596
1645static void 1597static void
@@ -1647,9 +1599,8 @@ encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compoun
1647{ 1599{
1648 __be32 *p; 1600 __be32 *p;
1649 1601
1650 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE); 1602 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1651 *p++ = cpu_to_be32(OP_SETATTR); 1603 encode_nfs4_stateid(xdr, &zero_stateid);
1652 xdr_encode_opaque_fixed(p, zero_stateid.data, NFS4_STATEID_SIZE);
1653 p = reserve_space(xdr, 2*4); 1604 p = reserve_space(xdr, 2*4);
1654 *p++ = cpu_to_be32(1); 1605 *p++ = cpu_to_be32(1);
1655 *p = cpu_to_be32(FATTR4_WORD0_ACL); 1606 *p = cpu_to_be32(FATTR4_WORD0_ACL);
@@ -1657,30 +1608,18 @@ encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compoun
1657 p = reserve_space(xdr, 4); 1608 p = reserve_space(xdr, 4);
1658 *p = cpu_to_be32(arg->acl_len); 1609 *p = cpu_to_be32(arg->acl_len);
1659 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); 1610 xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len);
1660 hdr->nops++;
1661 hdr->replen += decode_setacl_maxsz;
1662} 1611}
1663 1612
1664static void 1613static void
1665encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr) 1614encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
1666{ 1615{
1667 __be32 *p; 1616 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
1668
1669 p = reserve_space(xdr, 4);
1670 *p = cpu_to_be32(OP_SAVEFH);
1671 hdr->nops++;
1672 hdr->replen += decode_savefh_maxsz;
1673} 1617}
1674 1618
1675static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr) 1619static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
1676{ 1620{
1677 __be32 *p; 1621 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1678 1622 encode_nfs4_stateid(xdr, &arg->stateid);
1679 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1680 *p++ = cpu_to_be32(OP_SETATTR);
1681 xdr_encode_opaque_fixed(p, arg->stateid.data, NFS4_STATEID_SIZE);
1682 hdr->nops++;
1683 hdr->replen += decode_setattr_maxsz;
1684 encode_attrs(xdr, arg->iap, server); 1623 encode_attrs(xdr, arg->iap, server);
1685} 1624}
1686 1625
@@ -1688,9 +1627,8 @@ static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclie
1688{ 1627{
1689 __be32 *p; 1628 __be32 *p;
1690 1629
1691 p = reserve_space(xdr, 4 + NFS4_VERIFIER_SIZE); 1630 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1692 *p++ = cpu_to_be32(OP_SETCLIENTID); 1631 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
1693 xdr_encode_opaque_fixed(p, setclientid->sc_verifier->data, NFS4_VERIFIER_SIZE);
1694 1632
1695 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name); 1633 encode_string(xdr, setclientid->sc_name_len, setclientid->sc_name);
1696 p = reserve_space(xdr, 4); 1634 p = reserve_space(xdr, 4);
@@ -1699,31 +1637,23 @@ static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclie
1699 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr); 1637 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
1700 p = reserve_space(xdr, 4); 1638 p = reserve_space(xdr, 4);
1701 *p = cpu_to_be32(setclientid->sc_cb_ident); 1639 *p = cpu_to_be32(setclientid->sc_cb_ident);
1702 hdr->nops++;
1703 hdr->replen += decode_setclientid_maxsz;
1704} 1640}
1705 1641
1706static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr) 1642static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
1707{ 1643{
1708 __be32 *p; 1644 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1709 1645 decode_setclientid_confirm_maxsz, hdr);
1710 p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE); 1646 encode_uint64(xdr, arg->clientid);
1711 *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM); 1647 encode_nfs4_verifier(xdr, &arg->confirm);
1712 p = xdr_encode_hyper(p, arg->clientid);
1713 xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
1714 hdr->nops++;
1715 hdr->replen += decode_setclientid_confirm_maxsz;
1716} 1648}
1717 1649
1718static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr) 1650static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *args, struct compound_hdr *hdr)
1719{ 1651{
1720 __be32 *p; 1652 __be32 *p;
1721 1653
1722 p = reserve_space(xdr, 4); 1654 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
1723 *p = cpu_to_be32(OP_WRITE); 1655 encode_open_stateid(xdr, args->context, args->lock_context,
1724 1656 FMODE_WRITE, hdr->minorversion);
1725 encode_stateid(xdr, args->context, args->lock_context,
1726 hdr->minorversion);
1727 1657
1728 p = reserve_space(xdr, 16); 1658 p = reserve_space(xdr, 16);
1729 p = xdr_encode_hyper(p, args->offset); 1659 p = xdr_encode_hyper(p, args->offset);
@@ -1731,32 +1661,18 @@ static void encode_write(struct xdr_stream *xdr, const struct nfs_writeargs *arg
1731 *p = cpu_to_be32(args->count); 1661 *p = cpu_to_be32(args->count);
1732 1662
1733 xdr_write_pages(xdr, args->pages, args->pgbase, args->count); 1663 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
1734 hdr->nops++;
1735 hdr->replen += decode_write_maxsz;
1736} 1664}
1737 1665
1738static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr) 1666static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
1739{ 1667{
1740 __be32 *p; 1668 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1741 1669 encode_nfs4_stateid(xdr, stateid);
1742 p = reserve_space(xdr, 4+NFS4_STATEID_SIZE);
1743
1744 *p++ = cpu_to_be32(OP_DELEGRETURN);
1745 xdr_encode_opaque_fixed(p, stateid->data, NFS4_STATEID_SIZE);
1746 hdr->nops++;
1747 hdr->replen += decode_delegreturn_maxsz;
1748} 1670}
1749 1671
1750static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr) 1672static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1751{ 1673{
1752 int len = name->len; 1674 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
1753 __be32 *p; 1675 encode_string(xdr, name->len, name->name);
1754
1755 p = reserve_space(xdr, 8 + len);
1756 *p++ = cpu_to_be32(OP_SECINFO);
1757 xdr_encode_opaque(p, name->name, len);
1758 hdr->nops++;
1759 hdr->replen += decode_secinfo_maxsz;
1760} 1676}
1761 1677
1762#if defined(CONFIG_NFS_V4_1) 1678#if defined(CONFIG_NFS_V4_1)
@@ -1766,19 +1682,39 @@ static void encode_exchange_id(struct xdr_stream *xdr,
1766 struct compound_hdr *hdr) 1682 struct compound_hdr *hdr)
1767{ 1683{
1768 __be32 *p; 1684 __be32 *p;
1685 char impl_name[NFS4_OPAQUE_LIMIT];
1686 int len = 0;
1769 1687
1770 p = reserve_space(xdr, 4 + sizeof(args->verifier->data)); 1688 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1771 *p++ = cpu_to_be32(OP_EXCHANGE_ID); 1689 encode_nfs4_verifier(xdr, args->verifier);
1772 xdr_encode_opaque_fixed(p, args->verifier->data, sizeof(args->verifier->data));
1773 1690
1774 encode_string(xdr, args->id_len, args->id); 1691 encode_string(xdr, args->id_len, args->id);
1775 1692
1776 p = reserve_space(xdr, 12); 1693 p = reserve_space(xdr, 12);
1777 *p++ = cpu_to_be32(args->flags); 1694 *p++ = cpu_to_be32(args->flags);
1778 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */ 1695 *p++ = cpu_to_be32(0); /* zero length state_protect4_a */
1779 *p = cpu_to_be32(0); /* zero length implementation id array */ 1696
1780 hdr->nops++; 1697 if (send_implementation_id &&
1781 hdr->replen += decode_exchange_id_maxsz; 1698 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1699 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1700 <= NFS4_OPAQUE_LIMIT + 1)
1701 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1702 utsname()->sysname, utsname()->release,
1703 utsname()->version, utsname()->machine);
1704
1705 if (len > 0) {
1706 *p = cpu_to_be32(1); /* implementation id array length=1 */
1707
1708 encode_string(xdr,
1709 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1710 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1711 encode_string(xdr, len, impl_name);
1712 /* just send zeros for nii_date - the date is in nii_name */
1713 p = reserve_space(xdr, 12);
1714 p = xdr_encode_hyper(p, 0);
1715 *p = cpu_to_be32(0);
1716 } else
1717 *p = cpu_to_be32(0); /* implementation id array length=0 */
1782} 1718}
1783 1719
1784static void encode_create_session(struct xdr_stream *xdr, 1720static void encode_create_session(struct xdr_stream *xdr,
@@ -1801,8 +1737,8 @@ static void encode_create_session(struct xdr_stream *xdr,
1801 len = scnprintf(machine_name, sizeof(machine_name), "%s", 1737 len = scnprintf(machine_name, sizeof(machine_name), "%s",
1802 clp->cl_ipaddr); 1738 clp->cl_ipaddr);
1803 1739
1804 p = reserve_space(xdr, 20 + 2*28 + 20 + len + 12); 1740 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
1805 *p++ = cpu_to_be32(OP_CREATE_SESSION); 1741 p = reserve_space(xdr, 16 + 2*28 + 20 + len + 12);
1806 p = xdr_encode_hyper(p, clp->cl_clientid); 1742 p = xdr_encode_hyper(p, clp->cl_clientid);
1807 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */ 1743 *p++ = cpu_to_be32(clp->cl_seqid); /*Sequence id */
1808 *p++ = cpu_to_be32(args->flags); /*flags */ 1744 *p++ = cpu_to_be32(args->flags); /*flags */
@@ -1835,33 +1771,22 @@ static void encode_create_session(struct xdr_stream *xdr,
1835 *p++ = cpu_to_be32(0); /* UID */ 1771 *p++ = cpu_to_be32(0); /* UID */
1836 *p++ = cpu_to_be32(0); /* GID */ 1772 *p++ = cpu_to_be32(0); /* GID */
1837 *p = cpu_to_be32(0); /* No more gids */ 1773 *p = cpu_to_be32(0); /* No more gids */
1838 hdr->nops++;
1839 hdr->replen += decode_create_session_maxsz;
1840} 1774}
1841 1775
1842static void encode_destroy_session(struct xdr_stream *xdr, 1776static void encode_destroy_session(struct xdr_stream *xdr,
1843 struct nfs4_session *session, 1777 struct nfs4_session *session,
1844 struct compound_hdr *hdr) 1778 struct compound_hdr *hdr)
1845{ 1779{
1846 __be32 *p; 1780 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1847 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN); 1781 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1848 *p++ = cpu_to_be32(OP_DESTROY_SESSION);
1849 xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1850 hdr->nops++;
1851 hdr->replen += decode_destroy_session_maxsz;
1852} 1782}
1853 1783
1854static void encode_reclaim_complete(struct xdr_stream *xdr, 1784static void encode_reclaim_complete(struct xdr_stream *xdr,
1855 struct nfs41_reclaim_complete_args *args, 1785 struct nfs41_reclaim_complete_args *args,
1856 struct compound_hdr *hdr) 1786 struct compound_hdr *hdr)
1857{ 1787{
1858 __be32 *p; 1788 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1859 1789 encode_uint32(xdr, args->one_fs);
1860 p = reserve_space(xdr, 8);
1861 *p++ = cpu_to_be32(OP_RECLAIM_COMPLETE);
1862 *p++ = cpu_to_be32(args->one_fs);
1863 hdr->nops++;
1864 hdr->replen += decode_reclaim_complete_maxsz;
1865} 1790}
1866#endif /* CONFIG_NFS_V4_1 */ 1791#endif /* CONFIG_NFS_V4_1 */
1867 1792
@@ -1883,8 +1808,7 @@ static void encode_sequence(struct xdr_stream *xdr,
1883 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE); 1808 WARN_ON(args->sa_slotid == NFS4_MAX_SLOT_TABLE);
1884 slot = tp->slots + args->sa_slotid; 1809 slot = tp->slots + args->sa_slotid;
1885 1810
1886 p = reserve_space(xdr, 4 + NFS4_MAX_SESSIONID_LEN + 16); 1811 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1887 *p++ = cpu_to_be32(OP_SEQUENCE);
1888 1812
1889 /* 1813 /*
1890 * Sessionid + seqid + slotid + max slotid + cache_this 1814 * Sessionid + seqid + slotid + max slotid + cache_this
@@ -1898,13 +1822,12 @@ static void encode_sequence(struct xdr_stream *xdr,
1898 ((u32 *)session->sess_id.data)[3], 1822 ((u32 *)session->sess_id.data)[3],
1899 slot->seq_nr, args->sa_slotid, 1823 slot->seq_nr, args->sa_slotid,
1900 tp->highest_used_slotid, args->sa_cache_this); 1824 tp->highest_used_slotid, args->sa_cache_this);
1825 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
1901 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN); 1826 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1902 *p++ = cpu_to_be32(slot->seq_nr); 1827 *p++ = cpu_to_be32(slot->seq_nr);
1903 *p++ = cpu_to_be32(args->sa_slotid); 1828 *p++ = cpu_to_be32(args->sa_slotid);
1904 *p++ = cpu_to_be32(tp->highest_used_slotid); 1829 *p++ = cpu_to_be32(tp->highest_used_slotid);
1905 *p = cpu_to_be32(args->sa_cache_this); 1830 *p = cpu_to_be32(args->sa_cache_this);
1906 hdr->nops++;
1907 hdr->replen += decode_sequence_maxsz;
1908#endif /* CONFIG_NFS_V4_1 */ 1831#endif /* CONFIG_NFS_V4_1 */
1909} 1832}
1910 1833
@@ -1919,14 +1842,12 @@ encode_getdevicelist(struct xdr_stream *xdr,
1919 .data = "dummmmmy", 1842 .data = "dummmmmy",
1920 }; 1843 };
1921 1844
1922 p = reserve_space(xdr, 20); 1845 encode_op_hdr(xdr, OP_GETDEVICELIST, decode_getdevicelist_maxsz, hdr);
1923 *p++ = cpu_to_be32(OP_GETDEVICELIST); 1846 p = reserve_space(xdr, 16);
1924 *p++ = cpu_to_be32(args->layoutclass); 1847 *p++ = cpu_to_be32(args->layoutclass);
1925 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM); 1848 *p++ = cpu_to_be32(NFS4_PNFS_GETDEVLIST_MAXNUM);
1926 xdr_encode_hyper(p, 0ULL); /* cookie */ 1849 xdr_encode_hyper(p, 0ULL); /* cookie */
1927 encode_nfs4_verifier(xdr, &dummy); 1850 encode_nfs4_verifier(xdr, &dummy);
1928 hdr->nops++;
1929 hdr->replen += decode_getdevicelist_maxsz;
1930} 1851}
1931 1852
1932static void 1853static void
@@ -1936,15 +1857,13 @@ encode_getdeviceinfo(struct xdr_stream *xdr,
1936{ 1857{
1937 __be32 *p; 1858 __be32 *p;
1938 1859
1939 p = reserve_space(xdr, 16 + NFS4_DEVICEID4_SIZE); 1860 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
1940 *p++ = cpu_to_be32(OP_GETDEVICEINFO); 1861 p = reserve_space(xdr, 12 + NFS4_DEVICEID4_SIZE);
1941 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data, 1862 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1942 NFS4_DEVICEID4_SIZE); 1863 NFS4_DEVICEID4_SIZE);
1943 *p++ = cpu_to_be32(args->pdev->layout_type); 1864 *p++ = cpu_to_be32(args->pdev->layout_type);
1944 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */ 1865 *p++ = cpu_to_be32(args->pdev->pglen); /* gdia_maxcount */
1945 *p++ = cpu_to_be32(0); /* bitmap length 0 */ 1866 *p++ = cpu_to_be32(0); /* bitmap length 0 */
1946 hdr->nops++;
1947 hdr->replen += decode_getdeviceinfo_maxsz;
1948} 1867}
1949 1868
1950static void 1869static void
@@ -1954,16 +1873,16 @@ encode_layoutget(struct xdr_stream *xdr,
1954{ 1873{
1955 __be32 *p; 1874 __be32 *p;
1956 1875
1957 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE); 1876 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1958 *p++ = cpu_to_be32(OP_LAYOUTGET); 1877 p = reserve_space(xdr, 36);
1959 *p++ = cpu_to_be32(0); /* Signal layout available */ 1878 *p++ = cpu_to_be32(0); /* Signal layout available */
1960 *p++ = cpu_to_be32(args->type); 1879 *p++ = cpu_to_be32(args->type);
1961 *p++ = cpu_to_be32(args->range.iomode); 1880 *p++ = cpu_to_be32(args->range.iomode);
1962 p = xdr_encode_hyper(p, args->range.offset); 1881 p = xdr_encode_hyper(p, args->range.offset);
1963 p = xdr_encode_hyper(p, args->range.length); 1882 p = xdr_encode_hyper(p, args->range.length);
1964 p = xdr_encode_hyper(p, args->minlength); 1883 p = xdr_encode_hyper(p, args->minlength);
1965 p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE); 1884 encode_nfs4_stateid(xdr, &args->stateid);
1966 *p = cpu_to_be32(args->maxcount); 1885 encode_uint32(xdr, args->maxcount);
1967 1886
1968 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", 1887 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1969 __func__, 1888 __func__,
@@ -1972,8 +1891,6 @@ encode_layoutget(struct xdr_stream *xdr,
1972 (unsigned long)args->range.offset, 1891 (unsigned long)args->range.offset,
1973 (unsigned long)args->range.length, 1892 (unsigned long)args->range.length,
1974 args->maxcount); 1893 args->maxcount);
1975 hdr->nops++;
1976 hdr->replen += decode_layoutget_maxsz;
1977} 1894}
1978 1895
1979static int 1896static int
@@ -1987,13 +1904,14 @@ encode_layoutcommit(struct xdr_stream *xdr,
1987 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten, 1904 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1988 NFS_SERVER(args->inode)->pnfs_curr_ld->id); 1905 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1989 1906
1990 p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE); 1907 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1991 *p++ = cpu_to_be32(OP_LAYOUTCOMMIT); 1908 p = reserve_space(xdr, 20);
1992 /* Only whole file layouts */ 1909 /* Only whole file layouts */
1993 p = xdr_encode_hyper(p, 0); /* offset */ 1910 p = xdr_encode_hyper(p, 0); /* offset */
1994 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */ 1911 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
1995 *p++ = cpu_to_be32(0); /* reclaim */ 1912 *p = cpu_to_be32(0); /* reclaim */
1996 p = xdr_encode_opaque_fixed(p, args->stateid.data, NFS4_STATEID_SIZE); 1913 encode_nfs4_stateid(xdr, &args->stateid);
1914 p = reserve_space(xdr, 20);
1997 *p++ = cpu_to_be32(1); /* newoffset = TRUE */ 1915 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1998 p = xdr_encode_hyper(p, args->lastbytewritten); 1916 p = xdr_encode_hyper(p, args->lastbytewritten);
1999 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */ 1917 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
@@ -2002,13 +1920,9 @@ encode_layoutcommit(struct xdr_stream *xdr,
2002 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit) 1920 if (NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit)
2003 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit( 1921 NFS_SERVER(inode)->pnfs_curr_ld->encode_layoutcommit(
2004 NFS_I(inode)->layout, xdr, args); 1922 NFS_I(inode)->layout, xdr, args);
2005 else { 1923 else
2006 p = reserve_space(xdr, 4); 1924 encode_uint32(xdr, 0); /* no layout-type payload */
2007 *p = cpu_to_be32(0); /* no layout-type payload */
2008 }
2009 1925
2010 hdr->nops++;
2011 hdr->replen += decode_layoutcommit_maxsz;
2012 return 0; 1926 return 0;
2013} 1927}
2014 1928
@@ -2019,27 +1933,23 @@ encode_layoutreturn(struct xdr_stream *xdr,
2019{ 1933{
2020 __be32 *p; 1934 __be32 *p;
2021 1935
2022 p = reserve_space(xdr, 20); 1936 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2023 *p++ = cpu_to_be32(OP_LAYOUTRETURN); 1937 p = reserve_space(xdr, 16);
2024 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */ 1938 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2025 *p++ = cpu_to_be32(args->layout_type); 1939 *p++ = cpu_to_be32(args->layout_type);
2026 *p++ = cpu_to_be32(IOMODE_ANY); 1940 *p++ = cpu_to_be32(IOMODE_ANY);
2027 *p = cpu_to_be32(RETURN_FILE); 1941 *p = cpu_to_be32(RETURN_FILE);
2028 p = reserve_space(xdr, 16 + NFS4_STATEID_SIZE); 1942 p = reserve_space(xdr, 16);
2029 p = xdr_encode_hyper(p, 0); 1943 p = xdr_encode_hyper(p, 0);
2030 p = xdr_encode_hyper(p, NFS4_MAX_UINT64); 1944 p = xdr_encode_hyper(p, NFS4_MAX_UINT64);
2031 spin_lock(&args->inode->i_lock); 1945 spin_lock(&args->inode->i_lock);
2032 xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE); 1946 encode_nfs4_stateid(xdr, &args->stateid);
2033 spin_unlock(&args->inode->i_lock); 1947 spin_unlock(&args->inode->i_lock);
2034 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) { 1948 if (NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn) {
2035 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn( 1949 NFS_SERVER(args->inode)->pnfs_curr_ld->encode_layoutreturn(
2036 NFS_I(args->inode)->layout, xdr, args); 1950 NFS_I(args->inode)->layout, xdr, args);
2037 } else { 1951 } else
2038 p = reserve_space(xdr, 4); 1952 encode_uint32(xdr, 0);
2039 *p = cpu_to_be32(0);
2040 }
2041 hdr->nops++;
2042 hdr->replen += decode_layoutreturn_maxsz;
2043} 1953}
2044 1954
2045static int 1955static int
@@ -2047,12 +1957,8 @@ encode_secinfo_no_name(struct xdr_stream *xdr,
2047 const struct nfs41_secinfo_no_name_args *args, 1957 const struct nfs41_secinfo_no_name_args *args,
2048 struct compound_hdr *hdr) 1958 struct compound_hdr *hdr)
2049{ 1959{
2050 __be32 *p; 1960 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2051 p = reserve_space(xdr, 8); 1961 encode_uint32(xdr, args->style);
2052 *p++ = cpu_to_be32(OP_SECINFO_NO_NAME);
2053 *p++ = cpu_to_be32(args->style);
2054 hdr->nops++;
2055 hdr->replen += decode_secinfo_no_name_maxsz;
2056 return 0; 1962 return 0;
2057} 1963}
2058 1964
@@ -2060,26 +1966,17 @@ static void encode_test_stateid(struct xdr_stream *xdr,
2060 struct nfs41_test_stateid_args *args, 1966 struct nfs41_test_stateid_args *args,
2061 struct compound_hdr *hdr) 1967 struct compound_hdr *hdr)
2062{ 1968{
2063 __be32 *p; 1969 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2064 1970 encode_uint32(xdr, 1);
2065 p = reserve_space(xdr, 8 + NFS4_STATEID_SIZE); 1971 encode_nfs4_stateid(xdr, args->stateid);
2066 *p++ = cpu_to_be32(OP_TEST_STATEID);
2067 *p++ = cpu_to_be32(1);
2068 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2069 hdr->nops++;
2070 hdr->replen += decode_test_stateid_maxsz;
2071} 1972}
2072 1973
2073static void encode_free_stateid(struct xdr_stream *xdr, 1974static void encode_free_stateid(struct xdr_stream *xdr,
2074 struct nfs41_free_stateid_args *args, 1975 struct nfs41_free_stateid_args *args,
2075 struct compound_hdr *hdr) 1976 struct compound_hdr *hdr)
2076{ 1977{
2077 __be32 *p; 1978 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
2078 p = reserve_space(xdr, 4 + NFS4_STATEID_SIZE); 1979 encode_nfs4_stateid(xdr, args->stateid);
2079 *p++ = cpu_to_be32(OP_FREE_STATEID);
2080 xdr_encode_opaque_fixed(p, args->stateid->data, NFS4_STATEID_SIZE);
2081 hdr->nops++;
2082 hdr->replen += decode_free_stateid_maxsz;
2083} 1980}
2084#endif /* CONFIG_NFS_V4_1 */ 1981#endif /* CONFIG_NFS_V4_1 */
2085 1982
@@ -2633,6 +2530,7 @@ static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2633 encode_sequence(xdr, &args->seq_args, &hdr); 2530 encode_sequence(xdr, &args->seq_args, &hdr);
2634 encode_putfh(xdr, args->fhandle, &hdr); 2531 encode_putfh(xdr, args->fhandle, &hdr);
2635 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS| 2532 encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS|
2533 FATTR4_WORD0_FH_EXPIRE_TYPE|
2636 FATTR4_WORD0_LINK_SUPPORT| 2534 FATTR4_WORD0_LINK_SUPPORT|
2637 FATTR4_WORD0_SYMLINK_SUPPORT| 2535 FATTR4_WORD0_SYMLINK_SUPPORT|
2638 FATTR4_WORD0_ACLSUPPORT, &hdr); 2536 FATTR4_WORD0_ACLSUPPORT, &hdr);
@@ -2650,7 +2548,7 @@ static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2650 }; 2548 };
2651 2549
2652 encode_compound_hdr(xdr, req, &hdr); 2550 encode_compound_hdr(xdr, req, &hdr);
2653 encode_renew(xdr, clp, &hdr); 2551 encode_renew(xdr, clp->cl_clientid, &hdr);
2654 encode_nops(&hdr); 2552 encode_nops(&hdr);
2655} 2553}
2656 2554
@@ -3180,6 +3078,28 @@ out_overflow:
3180 return -EIO; 3078 return -EIO;
3181} 3079}
3182 3080
3081static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3082 uint32_t *bitmap, uint32_t *type)
3083{
3084 __be32 *p;
3085
3086 *type = 0;
3087 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3088 return -EIO;
3089 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3090 p = xdr_inline_decode(xdr, 4);
3091 if (unlikely(!p))
3092 goto out_overflow;
3093 *type = be32_to_cpup(p);
3094 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3095 }
3096 dprintk("%s: expire type=0x%x\n", __func__, *type);
3097 return 0;
3098out_overflow:
3099 print_overflow_msg(__func__, xdr);
3100 return -EIO;
3101}
3102
3183static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change) 3103static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3184{ 3104{
3185 __be32 *p; 3105 __be32 *p;
@@ -3513,16 +3433,17 @@ static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3513 n = be32_to_cpup(p); 3433 n = be32_to_cpup(p);
3514 if (n == 0) 3434 if (n == 0)
3515 goto root_path; 3435 goto root_path;
3516 dprintk("path "); 3436 dprintk("pathname4: ");
3517 path->ncomponents = 0; 3437 path->ncomponents = 0;
3518 while (path->ncomponents < n) { 3438 while (path->ncomponents < n) {
3519 struct nfs4_string *component = &path->components[path->ncomponents]; 3439 struct nfs4_string *component = &path->components[path->ncomponents];
3520 status = decode_opaque_inline(xdr, &component->len, &component->data); 3440 status = decode_opaque_inline(xdr, &component->len, &component->data);
3521 if (unlikely(status != 0)) 3441 if (unlikely(status != 0))
3522 goto out_eio; 3442 goto out_eio;
3523 if (path->ncomponents != n) 3443 ifdebug (XDR)
3524 dprintk("/"); 3444 pr_cont("%s%.*s ",
3525 dprintk("%s", component->data); 3445 (path->ncomponents != n ? "/ " : ""),
3446 component->len, component->data);
3526 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS) 3447 if (path->ncomponents < NFS4_PATHNAME_MAXCOMPONENTS)
3527 path->ncomponents++; 3448 path->ncomponents++;
3528 else { 3449 else {
@@ -3531,14 +3452,13 @@ static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3531 } 3452 }
3532 } 3453 }
3533out: 3454out:
3534 dprintk("\n");
3535 return status; 3455 return status;
3536root_path: 3456root_path:
3537/* a root pathname is sent as a zero component4 */ 3457/* a root pathname is sent as a zero component4 */
3538 path->ncomponents = 1; 3458 path->ncomponents = 1;
3539 path->components[0].len=0; 3459 path->components[0].len=0;
3540 path->components[0].data=NULL; 3460 path->components[0].data=NULL;
3541 dprintk("path /\n"); 3461 dprintk("pathname4: /\n");
3542 goto out; 3462 goto out;
3543out_eio: 3463out_eio:
3544 dprintk(" status %d", status); 3464 dprintk(" status %d", status);
@@ -3560,7 +3480,11 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
3560 status = 0; 3480 status = 0;
3561 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS))) 3481 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3562 goto out; 3482 goto out;
3563 dprintk("%s: fsroot ", __func__); 3483 status = -EIO;
3484 /* Ignore borken servers that return unrequested attrs */
3485 if (unlikely(res == NULL))
3486 goto out;
3487 dprintk("%s: fsroot:\n", __func__);
3564 status = decode_pathname(xdr, &res->fs_path); 3488 status = decode_pathname(xdr, &res->fs_path);
3565 if (unlikely(status != 0)) 3489 if (unlikely(status != 0))
3566 goto out; 3490 goto out;
@@ -3581,7 +3505,7 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
3581 m = be32_to_cpup(p); 3505 m = be32_to_cpup(p);
3582 3506
3583 loc->nservers = 0; 3507 loc->nservers = 0;
3584 dprintk("%s: servers ", __func__); 3508 dprintk("%s: servers:\n", __func__);
3585 while (loc->nservers < m) { 3509 while (loc->nservers < m) {
3586 struct nfs4_string *server = &loc->servers[loc->nservers]; 3510 struct nfs4_string *server = &loc->servers[loc->nservers];
3587 status = decode_opaque_inline(xdr, &server->len, &server->data); 3511 status = decode_opaque_inline(xdr, &server->len, &server->data);
@@ -3613,7 +3537,7 @@ static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, st
3613 res->nlocations++; 3537 res->nlocations++;
3614 } 3538 }
3615 if (res->nlocations != 0) 3539 if (res->nlocations != 0)
3616 status = NFS_ATTR_FATTR_V4_REFERRAL; 3540 status = NFS_ATTR_FATTR_V4_LOCATIONS;
3617out: 3541out:
3618 dprintk("%s: fs_locations done, error = %d\n", __func__, status); 3542 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3619 return status; 3543 return status;
@@ -4157,7 +4081,7 @@ static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
4157 4081
4158static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) 4082static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4159{ 4083{
4160 return decode_opaque_fixed(xdr, stateid->data, NFS4_STATEID_SIZE); 4084 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
4161} 4085}
4162 4086
4163static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res) 4087static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
@@ -4174,7 +4098,7 @@ static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4174 4098
4175static int decode_verifier(struct xdr_stream *xdr, void *verifier) 4099static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4176{ 4100{
4177 return decode_opaque_fixed(xdr, verifier, 8); 4101 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
4178} 4102}
4179 4103
4180static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res) 4104static int decode_commit(struct xdr_stream *xdr, struct nfs_writeres *res)
@@ -4224,6 +4148,9 @@ static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_re
4224 goto xdr_error; 4148 goto xdr_error;
4225 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0) 4149 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4226 goto xdr_error; 4150 goto xdr_error;
4151 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4152 &res->fh_expire_type)) != 0)
4153 goto xdr_error;
4227 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0) 4154 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4228 goto xdr_error; 4155 goto xdr_error;
4229 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0) 4156 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
@@ -4294,6 +4221,7 @@ xdr_error:
4294 4221
4295static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap, 4222static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4296 struct nfs_fattr *fattr, struct nfs_fh *fh, 4223 struct nfs_fattr *fattr, struct nfs_fh *fh,
4224 struct nfs4_fs_locations *fs_loc,
4297 const struct nfs_server *server) 4225 const struct nfs_server *server)
4298{ 4226{
4299 int status; 4227 int status;
@@ -4341,9 +4269,7 @@ static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4341 goto xdr_error; 4269 goto xdr_error;
4342 fattr->valid |= status; 4270 fattr->valid |= status;
4343 4271
4344 status = decode_attr_fs_locations(xdr, bitmap, container_of(fattr, 4272 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4345 struct nfs4_fs_locations,
4346 fattr));
4347 if (status < 0) 4273 if (status < 0)
4348 goto xdr_error; 4274 goto xdr_error;
4349 fattr->valid |= status; 4275 fattr->valid |= status;
@@ -4407,7 +4333,8 @@ xdr_error:
4407} 4333}
4408 4334
4409static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4335static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4410 struct nfs_fh *fh, const struct nfs_server *server) 4336 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
4337 const struct nfs_server *server)
4411{ 4338{
4412 __be32 *savep; 4339 __be32 *savep;
4413 uint32_t attrlen, 4340 uint32_t attrlen,
@@ -4426,7 +4353,7 @@ static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fat
4426 if (status < 0) 4353 if (status < 0)
4427 goto xdr_error; 4354 goto xdr_error;
4428 4355
4429 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, server); 4356 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
4430 if (status < 0) 4357 if (status < 0)
4431 goto xdr_error; 4358 goto xdr_error;
4432 4359
@@ -4439,7 +4366,7 @@ xdr_error:
4439static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr, 4366static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4440 const struct nfs_server *server) 4367 const struct nfs_server *server)
4441{ 4368{
4442 return decode_getfattr_generic(xdr, fattr, NULL, server); 4369 return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
4443} 4370}
4444 4371
4445/* 4372/*
@@ -4463,8 +4390,8 @@ static int decode_first_pnfs_layout_type(struct xdr_stream *xdr,
4463 return 0; 4390 return 0;
4464 } 4391 }
4465 if (num > 1) 4392 if (num > 1)
4466 printk(KERN_INFO "%s: Warning: Multiple pNFS layout drivers " 4393 printk(KERN_INFO "NFS: %s: Warning: Multiple pNFS layout "
4467 "per filesystem not supported\n", __func__); 4394 "drivers per filesystem not supported\n", __func__);
4468 4395
4469 /* Decode and set first layout type, move xdr->p past unused types */ 4396 /* Decode and set first layout type, move xdr->p past unused types */
4470 p = xdr_inline_decode(xdr, num * 4); 4397 p = xdr_inline_decode(xdr, num * 4);
@@ -4863,17 +4790,16 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n
4863 size_t hdrlen; 4790 size_t hdrlen;
4864 u32 recvd, pglen = rcvbuf->page_len; 4791 u32 recvd, pglen = rcvbuf->page_len;
4865 int status; 4792 int status;
4793 __be32 verf[2];
4866 4794
4867 status = decode_op_hdr(xdr, OP_READDIR); 4795 status = decode_op_hdr(xdr, OP_READDIR);
4868 if (!status) 4796 if (!status)
4869 status = decode_verifier(xdr, readdir->verifier.data); 4797 status = decode_verifier(xdr, readdir->verifier.data);
4870 if (unlikely(status)) 4798 if (unlikely(status))
4871 return status; 4799 return status;
4800 memcpy(verf, readdir->verifier.data, sizeof(verf));
4872 dprintk("%s: verifier = %08x:%08x\n", 4801 dprintk("%s: verifier = %08x:%08x\n",
4873 __func__, 4802 __func__, verf[0], verf[1]);
4874 ((u32 *)readdir->verifier.data)[0],
4875 ((u32 *)readdir->verifier.data)[1]);
4876
4877 4803
4878 hdrlen = (char *) xdr->p - (char *) iov->iov_base; 4804 hdrlen = (char *) xdr->p - (char *) iov->iov_base;
4879 recvd = rcvbuf->len - hdrlen; 4805 recvd = rcvbuf->len - hdrlen;
@@ -5120,7 +5046,7 @@ static int decode_write(struct xdr_stream *xdr, struct nfs_writeres *res)
5120 goto out_overflow; 5046 goto out_overflow;
5121 res->count = be32_to_cpup(p++); 5047 res->count = be32_to_cpup(p++);
5122 res->verf->committed = be32_to_cpup(p++); 5048 res->verf->committed = be32_to_cpup(p++);
5123 memcpy(res->verf->verifier, p, 8); 5049 memcpy(res->verf->verifier, p, NFS4_VERIFIER_SIZE);
5124 return 0; 5050 return 0;
5125out_overflow: 5051out_overflow:
5126 print_overflow_msg(__func__, xdr); 5052 print_overflow_msg(__func__, xdr);
@@ -5214,6 +5140,7 @@ static int decode_exchange_id(struct xdr_stream *xdr,
5214 char *dummy_str; 5140 char *dummy_str;
5215 int status; 5141 int status;
5216 struct nfs_client *clp = res->client; 5142 struct nfs_client *clp = res->client;
5143 uint32_t impl_id_count;
5217 5144
5218 status = decode_op_hdr(xdr, OP_EXCHANGE_ID); 5145 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5219 if (status) 5146 if (status)
@@ -5255,11 +5182,38 @@ static int decode_exchange_id(struct xdr_stream *xdr,
5255 memcpy(res->server_scope->server_scope, dummy_str, dummy); 5182 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5256 res->server_scope->server_scope_sz = dummy; 5183 res->server_scope->server_scope_sz = dummy;
5257 5184
5258 /* Throw away Implementation id array */ 5185 /* Implementation Id */
5259 status = decode_opaque_inline(xdr, &dummy, &dummy_str); 5186 p = xdr_inline_decode(xdr, 4);
5260 if (unlikely(status)) 5187 if (unlikely(!p))
5261 return status; 5188 goto out_overflow;
5189 impl_id_count = be32_to_cpup(p++);
5190
5191 if (impl_id_count) {
5192 /* nii_domain */
5193 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5194 if (unlikely(status))
5195 return status;
5196 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5197 return -EIO;
5198 memcpy(res->impl_id->domain, dummy_str, dummy);
5262 5199
5200 /* nii_name */
5201 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5202 if (unlikely(status))
5203 return status;
5204 if (unlikely(dummy > NFS4_OPAQUE_LIMIT))
5205 return -EIO;
5206 memcpy(res->impl_id->name, dummy_str, dummy);
5207
5208 /* nii_date */
5209 p = xdr_inline_decode(xdr, 12);
5210 if (unlikely(!p))
5211 goto out_overflow;
5212 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5213 res->impl_id->date.nseconds = be32_to_cpup(p);
5214
5215 /* if there's more than one entry, ignore the rest */
5216 }
5263 return 0; 5217 return 0;
5264out_overflow: 5218out_overflow:
5265 print_overflow_msg(__func__, xdr); 5219 print_overflow_msg(__func__, xdr);
@@ -5285,8 +5239,8 @@ static int decode_chan_attrs(struct xdr_stream *xdr,
5285 attrs->max_reqs = be32_to_cpup(p++); 5239 attrs->max_reqs = be32_to_cpup(p++);
5286 nr_attrs = be32_to_cpup(p); 5240 nr_attrs = be32_to_cpup(p);
5287 if (unlikely(nr_attrs > 1)) { 5241 if (unlikely(nr_attrs > 1)) {
5288 printk(KERN_WARNING "%s: Invalid rdma channel attrs count %u\n", 5242 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5289 __func__, nr_attrs); 5243 "count %u\n", __func__, nr_attrs);
5290 return -EINVAL; 5244 return -EINVAL;
5291 } 5245 }
5292 if (nr_attrs == 1) { 5246 if (nr_attrs == 1) {
@@ -5436,14 +5390,14 @@ static int decode_getdevicelist(struct xdr_stream *xdr,
5436 p += 2; 5390 p += 2;
5437 5391
5438 /* Read verifier */ 5392 /* Read verifier */
5439 p = xdr_decode_opaque_fixed(p, verftemp.verifier, 8); 5393 p = xdr_decode_opaque_fixed(p, verftemp.verifier, NFS4_VERIFIER_SIZE);
5440 5394
5441 res->num_devs = be32_to_cpup(p); 5395 res->num_devs = be32_to_cpup(p);
5442 5396
5443 dprintk("%s: num_dev %d\n", __func__, res->num_devs); 5397 dprintk("%s: num_dev %d\n", __func__, res->num_devs);
5444 5398
5445 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) { 5399 if (res->num_devs > NFS4_PNFS_GETDEVLIST_MAXNUM) {
5446 printk(KERN_ERR "%s too many result dev_num %u\n", 5400 printk(KERN_ERR "NFS: %s too many result dev_num %u\n",
5447 __func__, res->num_devs); 5401 __func__, res->num_devs);
5448 return -EIO; 5402 return -EIO;
5449 } 5403 }
@@ -5537,11 +5491,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5537 status = decode_op_hdr(xdr, OP_LAYOUTGET); 5491 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5538 if (status) 5492 if (status)
5539 return status; 5493 return status;
5540 p = xdr_inline_decode(xdr, 8 + NFS4_STATEID_SIZE); 5494 p = xdr_inline_decode(xdr, 4);
5495 if (unlikely(!p))
5496 goto out_overflow;
5497 res->return_on_close = be32_to_cpup(p);
5498 decode_stateid(xdr, &res->stateid);
5499 p = xdr_inline_decode(xdr, 4);
5541 if (unlikely(!p)) 5500 if (unlikely(!p))
5542 goto out_overflow; 5501 goto out_overflow;
5543 res->return_on_close = be32_to_cpup(p++);
5544 p = xdr_decode_opaque_fixed(p, res->stateid.data, NFS4_STATEID_SIZE);
5545 layout_count = be32_to_cpup(p); 5502 layout_count = be32_to_cpup(p);
5546 if (!layout_count) { 5503 if (!layout_count) {
5547 dprintk("%s: server responded with empty layout array\n", 5504 dprintk("%s: server responded with empty layout array\n",
@@ -5666,7 +5623,8 @@ static int decode_test_stateid(struct xdr_stream *xdr,
5666 if (unlikely(!p)) 5623 if (unlikely(!p))
5667 goto out_overflow; 5624 goto out_overflow;
5668 res->status = be32_to_cpup(p++); 5625 res->status = be32_to_cpup(p++);
5669 return res->status; 5626
5627 return status;
5670out_overflow: 5628out_overflow:
5671 print_overflow_msg(__func__, xdr); 5629 print_overflow_msg(__func__, xdr);
5672out: 5630out:
@@ -6583,8 +6541,9 @@ static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6583 if (status) 6541 if (status)
6584 goto out; 6542 goto out;
6585 xdr_enter_page(xdr, PAGE_SIZE); 6543 xdr_enter_page(xdr, PAGE_SIZE);
6586 status = decode_getfattr(xdr, &res->fs_locations->fattr, 6544 status = decode_getfattr_generic(xdr, &res->fs_locations->fattr,
6587 res->fs_locations->server); 6545 NULL, res->fs_locations,
6546 res->fs_locations->server);
6588out: 6547out:
6589 return status; 6548 return status;
6590} 6549}
@@ -6964,7 +6923,7 @@ int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
6964 goto out_overflow; 6923 goto out_overflow;
6965 6924
6966 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, 6925 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
6967 entry->server) < 0) 6926 NULL, entry->server) < 0)
6968 goto out_overflow; 6927 goto out_overflow;
6969 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) 6928 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
6970 entry->ino = entry->fattr->mounted_on_fileid; 6929 entry->ino = entry->fattr->mounted_on_fileid;
@@ -7112,7 +7071,7 @@ struct rpc_procinfo nfs4_procedures[] = {
7112#endif /* CONFIG_NFS_V4_1 */ 7071#endif /* CONFIG_NFS_V4_1 */
7113}; 7072};
7114 7073
7115struct rpc_version nfs_version4 = { 7074const struct rpc_version nfs_version4 = {
7116 .number = 4, 7075 .number = 4,
7117 .nrprocs = ARRAY_SIZE(nfs4_procedures), 7076 .nrprocs = ARRAY_SIZE(nfs4_procedures),
7118 .procs = nfs4_procedures 7077 .procs = nfs4_procedures
diff --git a/fs/nfs/nfsroot.c b/fs/nfs/nfsroot.c
index c4744e1d513..cd3c910d2d1 100644
--- a/fs/nfs/nfsroot.c
+++ b/fs/nfs/nfsroot.c
@@ -104,7 +104,7 @@ static char nfs_export_path[NFS_MAXPATHLEN + 1] __initdata = "";
104/* server:export path string passed to super.c */ 104/* server:export path string passed to super.c */
105static char nfs_root_device[NFS_MAXPATHLEN + 1] __initdata = ""; 105static char nfs_root_device[NFS_MAXPATHLEN + 1] __initdata = "";
106 106
107#ifdef RPC_DEBUG 107#ifdef NFS_DEBUG
108/* 108/*
109 * When the "nfsrootdebug" kernel command line option is specified, 109 * When the "nfsrootdebug" kernel command line option is specified,
110 * enable debugging messages for NFSROOT. 110 * enable debugging messages for NFSROOT.
diff --git a/fs/nfs/objlayout/objio_osd.c b/fs/nfs/objlayout/objio_osd.c
index 55d01280a60..4bff4a3dab4 100644
--- a/fs/nfs/objlayout/objio_osd.c
+++ b/fs/nfs/objlayout/objio_osd.c
@@ -137,6 +137,7 @@ static int objio_devices_lookup(struct pnfs_layout_hdr *pnfslay,
137 struct objio_dev_ent *ode; 137 struct objio_dev_ent *ode;
138 struct osd_dev *od; 138 struct osd_dev *od;
139 struct osd_dev_info odi; 139 struct osd_dev_info odi;
140 bool retry_flag = true;
140 int err; 141 int err;
141 142
142 ode = _dev_list_find(NFS_SERVER(pnfslay->plh_inode), d_id); 143 ode = _dev_list_find(NFS_SERVER(pnfslay->plh_inode), d_id);
@@ -171,10 +172,18 @@ static int objio_devices_lookup(struct pnfs_layout_hdr *pnfslay,
171 goto out; 172 goto out;
172 } 173 }
173 174
175retry_lookup:
174 od = osduld_info_lookup(&odi); 176 od = osduld_info_lookup(&odi);
175 if (unlikely(IS_ERR(od))) { 177 if (unlikely(IS_ERR(od))) {
176 err = PTR_ERR(od); 178 err = PTR_ERR(od);
177 dprintk("%s: osduld_info_lookup => %d\n", __func__, err); 179 dprintk("%s: osduld_info_lookup => %d\n", __func__, err);
180 if (err == -ENODEV && retry_flag) {
181 err = objlayout_autologin(deviceaddr);
182 if (likely(!err)) {
183 retry_flag = false;
184 goto retry_lookup;
185 }
186 }
178 goto out; 187 goto out;
179 } 188 }
180 189
@@ -205,25 +214,36 @@ static void copy_single_comp(struct ore_components *oc, unsigned c,
205int __alloc_objio_seg(unsigned numdevs, gfp_t gfp_flags, 214int __alloc_objio_seg(unsigned numdevs, gfp_t gfp_flags,
206 struct objio_segment **pseg) 215 struct objio_segment **pseg)
207{ 216{
208 struct __alloc_objio_segment { 217/* This is the in memory structure of the objio_segment
209 struct objio_segment olseg; 218 *
210 struct ore_dev *ods[numdevs]; 219 * struct __alloc_objio_segment {
211 struct ore_comp comps[numdevs]; 220 * struct objio_segment olseg;
212 } *aolseg; 221 * struct ore_dev *ods[numdevs];
213 222 * struct ore_comp comps[numdevs];
214 aolseg = kzalloc(sizeof(*aolseg), gfp_flags); 223 * } *aolseg;
215 if (unlikely(!aolseg)) { 224 * NOTE: The code as above compiles and runs perfectly. It is elegant,
225 * type safe and compact. At some Past time Linus has decided he does not
226 * like variable length arrays, For the sake of this principal we uglify
227 * the code as below.
228 */
229 struct objio_segment *lseg;
230 size_t lseg_size = sizeof(*lseg) +
231 numdevs * sizeof(lseg->oc.ods[0]) +
232 numdevs * sizeof(*lseg->oc.comps);
233
234 lseg = kzalloc(lseg_size, gfp_flags);
235 if (unlikely(!lseg)) {
216 dprintk("%s: Faild allocation numdevs=%d size=%zd\n", __func__, 236 dprintk("%s: Faild allocation numdevs=%d size=%zd\n", __func__,
217 numdevs, sizeof(*aolseg)); 237 numdevs, lseg_size);
218 return -ENOMEM; 238 return -ENOMEM;
219 } 239 }
220 240
221 aolseg->olseg.oc.numdevs = numdevs; 241 lseg->oc.numdevs = numdevs;
222 aolseg->olseg.oc.single_comp = EC_MULTPLE_COMPS; 242 lseg->oc.single_comp = EC_MULTPLE_COMPS;
223 aolseg->olseg.oc.comps = aolseg->comps; 243 lseg->oc.ods = (void *)(lseg + 1);
224 aolseg->olseg.oc.ods = aolseg->ods; 244 lseg->oc.comps = (void *)(lseg->oc.ods + numdevs);
225 245
226 *pseg = &aolseg->olseg; 246 *pseg = lseg;
227 return 0; 247 return 0;
228} 248}
229 249
@@ -582,10 +602,10 @@ objlayout_init(void)
582 602
583 if (ret) 603 if (ret)
584 printk(KERN_INFO 604 printk(KERN_INFO
585 "%s: Registering OSD pNFS Layout Driver failed: error=%d\n", 605 "NFS: %s: Registering OSD pNFS Layout Driver failed: error=%d\n",
586 __func__, ret); 606 __func__, ret);
587 else 607 else
588 printk(KERN_INFO "%s: Registered OSD pNFS Layout Driver\n", 608 printk(KERN_INFO "NFS: %s: Registered OSD pNFS Layout Driver\n",
589 __func__); 609 __func__);
590 return ret; 610 return ret;
591} 611}
@@ -594,7 +614,7 @@ static void __exit
594objlayout_exit(void) 614objlayout_exit(void)
595{ 615{
596 pnfs_unregister_layoutdriver(&objlayout_type); 616 pnfs_unregister_layoutdriver(&objlayout_type);
597 printk(KERN_INFO "%s: Unregistered OSD pNFS Layout Driver\n", 617 printk(KERN_INFO "NFS: %s: Unregistered OSD pNFS Layout Driver\n",
598 __func__); 618 __func__);
599} 619}
600 620
diff --git a/fs/nfs/objlayout/objlayout.c b/fs/nfs/objlayout/objlayout.c
index b3c29039f5b..8d45f1c318c 100644
--- a/fs/nfs/objlayout/objlayout.c
+++ b/fs/nfs/objlayout/objlayout.c
@@ -37,6 +37,9 @@
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */ 38 */
39 39
40#include <linux/kmod.h>
41#include <linux/moduleparam.h>
42#include <linux/ratelimit.h>
40#include <scsi/osd_initiator.h> 43#include <scsi/osd_initiator.h>
41#include "objlayout.h" 44#include "objlayout.h"
42 45
@@ -156,7 +159,7 @@ last_byte_offset(u64 start, u64 len)
156 return end > start ? end - 1 : NFS4_MAX_UINT64; 159 return end > start ? end - 1 : NFS4_MAX_UINT64;
157} 160}
158 161
159void _fix_verify_io_params(struct pnfs_layout_segment *lseg, 162static void _fix_verify_io_params(struct pnfs_layout_segment *lseg,
160 struct page ***p_pages, unsigned *p_pgbase, 163 struct page ***p_pages, unsigned *p_pgbase,
161 u64 offset, unsigned long count) 164 u64 offset, unsigned long count)
162{ 165{
@@ -490,9 +493,9 @@ encode_accumulated_error(struct objlayout *objlay, __be32 *p)
490 if (!ioerr->oer_errno) 493 if (!ioerr->oer_errno)
491 continue; 494 continue;
492 495
493 printk(KERN_ERR "%s: err[%d]: errno=%d is_write=%d " 496 printk(KERN_ERR "NFS: %s: err[%d]: errno=%d "
494 "dev(%llx:%llx) par=0x%llx obj=0x%llx " 497 "is_write=%d dev(%llx:%llx) par=0x%llx "
495 "offset=0x%llx length=0x%llx\n", 498 "obj=0x%llx offset=0x%llx length=0x%llx\n",
496 __func__, i, ioerr->oer_errno, 499 __func__, i, ioerr->oer_errno,
497 ioerr->oer_iswrite, 500 ioerr->oer_iswrite,
498 _DEVID_LO(&ioerr->oer_component.oid_device_id), 501 _DEVID_LO(&ioerr->oer_component.oid_device_id),
@@ -651,3 +654,134 @@ void objlayout_put_deviceinfo(struct pnfs_osd_deviceaddr *deviceaddr)
651 __free_page(odi->page); 654 __free_page(odi->page);
652 kfree(odi); 655 kfree(odi);
653} 656}
657
658enum {
659 OBJLAYOUT_MAX_URI_LEN = 256, OBJLAYOUT_MAX_OSDNAME_LEN = 64,
660 OBJLAYOUT_MAX_SYSID_HEX_LEN = OSD_SYSTEMID_LEN * 2 + 1,
661 OSD_LOGIN_UPCALL_PATHLEN = 256
662};
663
664static char osd_login_prog[OSD_LOGIN_UPCALL_PATHLEN] = "/sbin/osd_login";
665
666module_param_string(osd_login_prog, osd_login_prog, sizeof(osd_login_prog),
667 0600);
668MODULE_PARM_DESC(osd_login_prog, "Path to the osd_login upcall program");
669
670struct __auto_login {
671 char uri[OBJLAYOUT_MAX_URI_LEN];
672 char osdname[OBJLAYOUT_MAX_OSDNAME_LEN];
673 char systemid_hex[OBJLAYOUT_MAX_SYSID_HEX_LEN];
674};
675
676static int __objlayout_upcall(struct __auto_login *login)
677{
678 static char *envp[] = { "HOME=/",
679 "TERM=linux",
680 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
681 NULL
682 };
683 char *argv[8];
684 int ret;
685
686 if (unlikely(!osd_login_prog[0])) {
687 dprintk("%s: osd_login_prog is disabled\n", __func__);
688 return -EACCES;
689 }
690
691 dprintk("%s uri: %s\n", __func__, login->uri);
692 dprintk("%s osdname %s\n", __func__, login->osdname);
693 dprintk("%s systemid_hex %s\n", __func__, login->systemid_hex);
694
695 argv[0] = (char *)osd_login_prog;
696 argv[1] = "-u";
697 argv[2] = login->uri;
698 argv[3] = "-o";
699 argv[4] = login->osdname;
700 argv[5] = "-s";
701 argv[6] = login->systemid_hex;
702 argv[7] = NULL;
703
704 ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
705 /*
706 * Disable the upcall mechanism if we're getting an ENOENT or
707 * EACCES error. The admin can re-enable it on the fly by using
708 * sysfs to set the objlayoutdriver.osd_login_prog module parameter once
709 * the problem has been fixed.
710 */
711 if (ret == -ENOENT || ret == -EACCES) {
712 printk(KERN_ERR "PNFS-OBJ: %s was not found please set "
713 "objlayoutdriver.osd_login_prog kernel parameter!\n",
714 osd_login_prog);
715 osd_login_prog[0] = '\0';
716 }
717 dprintk("%s %s return value: %d\n", __func__, osd_login_prog, ret);
718
719 return ret;
720}
721
722/* Assume dest is all zeros */
723static void __copy_nfsS_and_zero_terminate(struct nfs4_string s,
724 char *dest, int max_len,
725 const char *var_name)
726{
727 if (!s.len)
728 return;
729
730 if (s.len >= max_len) {
731 pr_warn_ratelimited(
732 "objlayout_autologin: %s: s.len(%d) >= max_len(%d)",
733 var_name, s.len, max_len);
734 s.len = max_len - 1; /* space for null terminator */
735 }
736
737 memcpy(dest, s.data, s.len);
738}
739
740/* Assume sysid is all zeros */
741static void _sysid_2_hex(struct nfs4_string s,
742 char sysid[OBJLAYOUT_MAX_SYSID_HEX_LEN])
743{
744 int i;
745 char *cur;
746
747 if (!s.len)
748 return;
749
750 if (s.len != OSD_SYSTEMID_LEN) {
751 pr_warn_ratelimited(
752 "objlayout_autologin: systemid_len(%d) != OSD_SYSTEMID_LEN",
753 s.len);
754 if (s.len > OSD_SYSTEMID_LEN)
755 s.len = OSD_SYSTEMID_LEN;
756 }
757
758 cur = sysid;
759 for (i = 0; i < s.len; i++)
760 cur = hex_byte_pack(cur, s.data[i]);
761}
762
763int objlayout_autologin(struct pnfs_osd_deviceaddr *deviceaddr)
764{
765 int rc;
766 struct __auto_login login;
767
768 if (!deviceaddr->oda_targetaddr.ota_netaddr.r_addr.len)
769 return -ENODEV;
770
771 memset(&login, 0, sizeof(login));
772 __copy_nfsS_and_zero_terminate(
773 deviceaddr->oda_targetaddr.ota_netaddr.r_addr,
774 login.uri, sizeof(login.uri), "URI");
775
776 __copy_nfsS_and_zero_terminate(
777 deviceaddr->oda_osdname,
778 login.osdname, sizeof(login.osdname), "OSDNAME");
779
780 _sysid_2_hex(deviceaddr->oda_systemid, login.systemid_hex);
781
782 rc = __objlayout_upcall(&login);
783 if (rc > 0) /* script returns positive values */
784 rc = -ENODEV;
785
786 return rc;
787}
diff --git a/fs/nfs/objlayout/objlayout.h b/fs/nfs/objlayout/objlayout.h
index 8ec34727ed2..880ba086be9 100644
--- a/fs/nfs/objlayout/objlayout.h
+++ b/fs/nfs/objlayout/objlayout.h
@@ -184,4 +184,6 @@ extern void objlayout_encode_layoutreturn(
184 struct xdr_stream *, 184 struct xdr_stream *,
185 const struct nfs4_layoutreturn_args *); 185 const struct nfs4_layoutreturn_args *);
186 186
187extern int objlayout_autologin(struct pnfs_osd_deviceaddr *deviceaddr);
188
187#endif /* _OBJLAYOUT_H */ 189#endif /* _OBJLAYOUT_H */
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index 5668f7c54c4..d21fceaa9f6 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -13,6 +13,7 @@
13#include <linux/file.h> 13#include <linux/file.h>
14#include <linux/sched.h> 14#include <linux/sched.h>
15#include <linux/sunrpc/clnt.h> 15#include <linux/sunrpc/clnt.h>
16#include <linux/nfs.h>
16#include <linux/nfs3.h> 17#include <linux/nfs3.h>
17#include <linux/nfs4.h> 18#include <linux/nfs4.h>
18#include <linux/nfs_page.h> 19#include <linux/nfs_page.h>
@@ -106,36 +107,6 @@ void nfs_unlock_request(struct nfs_page *req)
106 nfs_release_request(req); 107 nfs_release_request(req);
107} 108}
108 109
109/**
110 * nfs_set_page_tag_locked - Tag a request as locked
111 * @req:
112 */
113int nfs_set_page_tag_locked(struct nfs_page *req)
114{
115 if (!nfs_lock_request_dontget(req))
116 return 0;
117 if (test_bit(PG_MAPPED, &req->wb_flags))
118 radix_tree_tag_set(&NFS_I(req->wb_context->dentry->d_inode)->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_LOCKED);
119 return 1;
120}
121
122/**
123 * nfs_clear_page_tag_locked - Clear request tag and wake up sleepers
124 */
125void nfs_clear_page_tag_locked(struct nfs_page *req)
126{
127 if (test_bit(PG_MAPPED, &req->wb_flags)) {
128 struct inode *inode = req->wb_context->dentry->d_inode;
129 struct nfs_inode *nfsi = NFS_I(inode);
130
131 spin_lock(&inode->i_lock);
132 radix_tree_tag_clear(&nfsi->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_LOCKED);
133 nfs_unlock_request(req);
134 spin_unlock(&inode->i_lock);
135 } else
136 nfs_unlock_request(req);
137}
138
139/* 110/*
140 * nfs_clear_request - Free up all resources allocated to the request 111 * nfs_clear_request - Free up all resources allocated to the request
141 * @req: 112 * @req:
@@ -425,67 +396,6 @@ void nfs_pageio_cond_complete(struct nfs_pageio_descriptor *desc, pgoff_t index)
425 } 396 }
426} 397}
427 398
428#define NFS_SCAN_MAXENTRIES 16
429/**
430 * nfs_scan_list - Scan a list for matching requests
431 * @nfsi: NFS inode
432 * @dst: Destination list
433 * @idx_start: lower bound of page->index to scan
434 * @npages: idx_start + npages sets the upper bound to scan.
435 * @tag: tag to scan for
436 *
437 * Moves elements from one of the inode request lists.
438 * If the number of requests is set to 0, the entire address_space
439 * starting at index idx_start, is scanned.
440 * The requests are *not* checked to ensure that they form a contiguous set.
441 * You must be holding the inode's i_lock when calling this function
442 */
443int nfs_scan_list(struct nfs_inode *nfsi,
444 struct list_head *dst, pgoff_t idx_start,
445 unsigned int npages, int tag)
446{
447 struct nfs_page *pgvec[NFS_SCAN_MAXENTRIES];
448 struct nfs_page *req;
449 pgoff_t idx_end;
450 int found, i;
451 int res;
452 struct list_head *list;
453
454 res = 0;
455 if (npages == 0)
456 idx_end = ~0;
457 else
458 idx_end = idx_start + npages - 1;
459
460 for (;;) {
461 found = radix_tree_gang_lookup_tag(&nfsi->nfs_page_tree,
462 (void **)&pgvec[0], idx_start,
463 NFS_SCAN_MAXENTRIES, tag);
464 if (found <= 0)
465 break;
466 for (i = 0; i < found; i++) {
467 req = pgvec[i];
468 if (req->wb_index > idx_end)
469 goto out;
470 idx_start = req->wb_index + 1;
471 if (nfs_set_page_tag_locked(req)) {
472 kref_get(&req->wb_kref);
473 radix_tree_tag_clear(&nfsi->nfs_page_tree,
474 req->wb_index, tag);
475 list = pnfs_choose_commit_list(req, dst);
476 nfs_list_add_request(req, list);
477 res++;
478 if (res == INT_MAX)
479 goto out;
480 }
481 }
482 /* for latency reduction */
483 cond_resched_lock(&nfsi->vfs_inode.i_lock);
484 }
485out:
486 return res;
487}
488
489int __init nfs_init_nfspagecache(void) 399int __init nfs_init_nfspagecache(void)
490{ 400{
491 nfs_page_cachep = kmem_cache_create("nfs_page", 401 nfs_page_cachep = kmem_cache_create("nfs_page",
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 17149a49006..b5d45158694 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -101,8 +101,8 @@ set_pnfs_layoutdriver(struct nfs_server *server, const struct nfs_fh *mntfh,
101 goto out_no_driver; 101 goto out_no_driver;
102 if (!(server->nfs_client->cl_exchange_flags & 102 if (!(server->nfs_client->cl_exchange_flags &
103 (EXCHGID4_FLAG_USE_NON_PNFS | EXCHGID4_FLAG_USE_PNFS_MDS))) { 103 (EXCHGID4_FLAG_USE_NON_PNFS | EXCHGID4_FLAG_USE_PNFS_MDS))) {
104 printk(KERN_ERR "%s: id %u cl_exchange_flags 0x%x\n", __func__, 104 printk(KERN_ERR "NFS: %s: id %u cl_exchange_flags 0x%x\n",
105 id, server->nfs_client->cl_exchange_flags); 105 __func__, id, server->nfs_client->cl_exchange_flags);
106 goto out_no_driver; 106 goto out_no_driver;
107 } 107 }
108 ld_type = find_pnfs_driver(id); 108 ld_type = find_pnfs_driver(id);
@@ -122,8 +122,8 @@ set_pnfs_layoutdriver(struct nfs_server *server, const struct nfs_fh *mntfh,
122 server->pnfs_curr_ld = ld_type; 122 server->pnfs_curr_ld = ld_type;
123 if (ld_type->set_layoutdriver 123 if (ld_type->set_layoutdriver
124 && ld_type->set_layoutdriver(server, mntfh)) { 124 && ld_type->set_layoutdriver(server, mntfh)) {
125 printk(KERN_ERR "%s: Error initializing pNFS layout driver %u.\n", 125 printk(KERN_ERR "NFS: %s: Error initializing pNFS layout "
126 __func__, id); 126 "driver %u.\n", __func__, id);
127 module_put(ld_type->owner); 127 module_put(ld_type->owner);
128 goto out_no_driver; 128 goto out_no_driver;
129 } 129 }
@@ -143,11 +143,11 @@ pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
143 struct pnfs_layoutdriver_type *tmp; 143 struct pnfs_layoutdriver_type *tmp;
144 144
145 if (ld_type->id == 0) { 145 if (ld_type->id == 0) {
146 printk(KERN_ERR "%s id 0 is reserved\n", __func__); 146 printk(KERN_ERR "NFS: %s id 0 is reserved\n", __func__);
147 return status; 147 return status;
148 } 148 }
149 if (!ld_type->alloc_lseg || !ld_type->free_lseg) { 149 if (!ld_type->alloc_lseg || !ld_type->free_lseg) {
150 printk(KERN_ERR "%s Layout driver must provide " 150 printk(KERN_ERR "NFS: %s Layout driver must provide "
151 "alloc_lseg and free_lseg.\n", __func__); 151 "alloc_lseg and free_lseg.\n", __func__);
152 return status; 152 return status;
153 } 153 }
@@ -160,7 +160,7 @@ pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
160 dprintk("%s Registering id:%u name:%s\n", __func__, ld_type->id, 160 dprintk("%s Registering id:%u name:%s\n", __func__, ld_type->id,
161 ld_type->name); 161 ld_type->name);
162 } else { 162 } else {
163 printk(KERN_ERR "%s Module with id %d already loaded!\n", 163 printk(KERN_ERR "NFS: %s Module with id %d already loaded!\n",
164 __func__, ld_type->id); 164 __func__, ld_type->id);
165 } 165 }
166 spin_unlock(&pnfs_spinlock); 166 spin_unlock(&pnfs_spinlock);
@@ -496,12 +496,12 @@ pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
496{ 496{
497 u32 oldseq, newseq; 497 u32 oldseq, newseq;
498 498
499 oldseq = be32_to_cpu(lo->plh_stateid.stateid.seqid); 499 oldseq = be32_to_cpu(lo->plh_stateid.seqid);
500 newseq = be32_to_cpu(new->stateid.seqid); 500 newseq = be32_to_cpu(new->seqid);
501 if ((int)(newseq - oldseq) > 0) { 501 if ((int)(newseq - oldseq) > 0) {
502 memcpy(&lo->plh_stateid, &new->stateid, sizeof(new->stateid)); 502 nfs4_stateid_copy(&lo->plh_stateid, new);
503 if (update_barrier) { 503 if (update_barrier) {
504 u32 new_barrier = be32_to_cpu(new->stateid.seqid); 504 u32 new_barrier = be32_to_cpu(new->seqid);
505 505
506 if ((int)(new_barrier - lo->plh_barrier)) 506 if ((int)(new_barrier - lo->plh_barrier))
507 lo->plh_barrier = new_barrier; 507 lo->plh_barrier = new_barrier;
@@ -525,7 +525,7 @@ pnfs_layoutgets_blocked(struct pnfs_layout_hdr *lo, nfs4_stateid *stateid,
525 int lget) 525 int lget)
526{ 526{
527 if ((stateid) && 527 if ((stateid) &&
528 (int)(lo->plh_barrier - be32_to_cpu(stateid->stateid.seqid)) >= 0) 528 (int)(lo->plh_barrier - be32_to_cpu(stateid->seqid)) >= 0)
529 return true; 529 return true;
530 return lo->plh_block_lgets || 530 return lo->plh_block_lgets ||
531 test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags) || 531 test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags) ||
@@ -549,11 +549,10 @@ pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
549 549
550 do { 550 do {
551 seq = read_seqbegin(&open_state->seqlock); 551 seq = read_seqbegin(&open_state->seqlock);
552 memcpy(dst->data, open_state->stateid.data, 552 nfs4_stateid_copy(dst, &open_state->stateid);
553 sizeof(open_state->stateid.data));
554 } while (read_seqretry(&open_state->seqlock, seq)); 553 } while (read_seqretry(&open_state->seqlock, seq));
555 } else 554 } else
556 memcpy(dst->data, lo->plh_stateid.data, sizeof(lo->plh_stateid.data)); 555 nfs4_stateid_copy(dst, &lo->plh_stateid);
557 spin_unlock(&lo->plh_inode->i_lock); 556 spin_unlock(&lo->plh_inode->i_lock);
558 dprintk("<-- %s\n", __func__); 557 dprintk("<-- %s\n", __func__);
559 return status; 558 return status;
@@ -590,7 +589,7 @@ send_layoutget(struct pnfs_layout_hdr *lo,
590 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz; 589 max_resp_sz = server->nfs_client->cl_session->fc_attrs.max_resp_sz;
591 max_pages = max_resp_sz >> PAGE_SHIFT; 590 max_pages = max_resp_sz >> PAGE_SHIFT;
592 591
593 pages = kzalloc(max_pages * sizeof(struct page *), gfp_flags); 592 pages = kcalloc(max_pages, sizeof(struct page *), gfp_flags);
594 if (!pages) 593 if (!pages)
595 goto out_err_free; 594 goto out_err_free;
596 595
@@ -760,7 +759,7 @@ bool pnfs_roc_drain(struct inode *ino, u32 *barrier)
760 } 759 }
761 if (!found) { 760 if (!found) {
762 struct pnfs_layout_hdr *lo = nfsi->layout; 761 struct pnfs_layout_hdr *lo = nfsi->layout;
763 u32 current_seqid = be32_to_cpu(lo->plh_stateid.stateid.seqid); 762 u32 current_seqid = be32_to_cpu(lo->plh_stateid.seqid);
764 763
765 /* Since close does not return a layout stateid for use as 764 /* Since close does not return a layout stateid for use as
766 * a barrier, we choose the worst-case barrier. 765 * a barrier, we choose the worst-case barrier.
@@ -966,8 +965,7 @@ pnfs_update_layout(struct inode *ino,
966 } 965 }
967 966
968 /* Do we even need to bother with this? */ 967 /* Do we even need to bother with this? */
969 if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) || 968 if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
970 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
971 dprintk("%s matches recall, use MDS\n", __func__); 969 dprintk("%s matches recall, use MDS\n", __func__);
972 goto out_unlock; 970 goto out_unlock;
973 } 971 }
@@ -1032,7 +1030,6 @@ pnfs_layout_process(struct nfs4_layoutget *lgp)
1032 struct nfs4_layoutget_res *res = &lgp->res; 1030 struct nfs4_layoutget_res *res = &lgp->res;
1033 struct pnfs_layout_segment *lseg; 1031 struct pnfs_layout_segment *lseg;
1034 struct inode *ino = lo->plh_inode; 1032 struct inode *ino = lo->plh_inode;
1035 struct nfs_client *clp = NFS_SERVER(ino)->nfs_client;
1036 int status = 0; 1033 int status = 0;
1037 1034
1038 /* Inject layout blob into I/O device driver */ 1035 /* Inject layout blob into I/O device driver */
@@ -1048,8 +1045,7 @@ pnfs_layout_process(struct nfs4_layoutget *lgp)
1048 } 1045 }
1049 1046
1050 spin_lock(&ino->i_lock); 1047 spin_lock(&ino->i_lock);
1051 if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) || 1048 if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
1052 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
1053 dprintk("%s forget reply due to recall\n", __func__); 1049 dprintk("%s forget reply due to recall\n", __func__);
1054 goto out_forget_reply; 1050 goto out_forget_reply;
1055 } 1051 }
@@ -1214,6 +1210,7 @@ void pnfs_ld_write_done(struct nfs_write_data *data)
1214 } 1210 }
1215 data->task.tk_status = pnfs_write_done_resend_to_mds(data->inode, &data->pages); 1211 data->task.tk_status = pnfs_write_done_resend_to_mds(data->inode, &data->pages);
1216 } 1212 }
1213 put_lseg(data->lseg);
1217 data->mds_ops->rpc_release(data); 1214 data->mds_ops->rpc_release(data);
1218} 1215}
1219EXPORT_SYMBOL_GPL(pnfs_ld_write_done); 1216EXPORT_SYMBOL_GPL(pnfs_ld_write_done);
@@ -1227,6 +1224,7 @@ pnfs_write_through_mds(struct nfs_pageio_descriptor *desc,
1227 nfs_list_add_request(data->req, &desc->pg_list); 1224 nfs_list_add_request(data->req, &desc->pg_list);
1228 nfs_pageio_reset_write_mds(desc); 1225 nfs_pageio_reset_write_mds(desc);
1229 desc->pg_recoalesce = 1; 1226 desc->pg_recoalesce = 1;
1227 put_lseg(data->lseg);
1230 nfs_writedata_release(data); 1228 nfs_writedata_release(data);
1231} 1229}
1232 1230
@@ -1327,6 +1325,7 @@ void pnfs_ld_read_done(struct nfs_read_data *data)
1327 data->mds_ops->rpc_call_done(&data->task, data); 1325 data->mds_ops->rpc_call_done(&data->task, data);
1328 } else 1326 } else
1329 pnfs_ld_handle_read_error(data); 1327 pnfs_ld_handle_read_error(data);
1328 put_lseg(data->lseg);
1330 data->mds_ops->rpc_release(data); 1329 data->mds_ops->rpc_release(data);
1331} 1330}
1332EXPORT_SYMBOL_GPL(pnfs_ld_read_done); 1331EXPORT_SYMBOL_GPL(pnfs_ld_read_done);
@@ -1530,8 +1529,7 @@ pnfs_layoutcommit_inode(struct inode *inode, bool sync)
1530 end_pos = nfsi->layout->plh_lwb; 1529 end_pos = nfsi->layout->plh_lwb;
1531 nfsi->layout->plh_lwb = 0; 1530 nfsi->layout->plh_lwb = 0;
1532 1531
1533 memcpy(&data->args.stateid.data, nfsi->layout->plh_stateid.data, 1532 nfs4_stateid_copy(&data->args.stateid, &nfsi->layout->plh_stateid);
1534 sizeof(nfsi->layout->plh_stateid.data));
1535 spin_unlock(&inode->i_lock); 1533 spin_unlock(&inode->i_lock);
1536 1534
1537 data->args.inode = inode; 1535 data->args.inode = inode;
diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h
index 53d593a0a4f..442ebf68eee 100644
--- a/fs/nfs/pnfs.h
+++ b/fs/nfs/pnfs.h
@@ -94,11 +94,10 @@ struct pnfs_layoutdriver_type {
94 const struct nfs_pageio_ops *pg_read_ops; 94 const struct nfs_pageio_ops *pg_read_ops;
95 const struct nfs_pageio_ops *pg_write_ops; 95 const struct nfs_pageio_ops *pg_write_ops;
96 96
97 /* Returns true if layoutdriver wants to divert this request to 97 void (*mark_request_commit) (struct nfs_page *req,
98 * driver's commit routine. 98 struct pnfs_layout_segment *lseg);
99 */ 99 void (*clear_request_commit) (struct nfs_page *req);
100 bool (*mark_pnfs_commit)(struct pnfs_layout_segment *lseg); 100 int (*scan_commit_lists) (struct inode *inode, int max, spinlock_t *lock);
101 struct list_head * (*choose_commit_list) (struct nfs_page *req);
102 int (*commit_pagelist)(struct inode *inode, struct list_head *mds_pages, int how); 101 int (*commit_pagelist)(struct inode *inode, struct list_head *mds_pages, int how);
103 102
104 /* 103 /*
@@ -229,7 +228,6 @@ struct nfs4_deviceid_node {
229 atomic_t ref; 228 atomic_t ref;
230}; 229};
231 230
232void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id);
233struct nfs4_deviceid_node *nfs4_find_get_deviceid(const struct pnfs_layoutdriver_type *, const struct nfs_client *, const struct nfs4_deviceid *); 231struct nfs4_deviceid_node *nfs4_find_get_deviceid(const struct pnfs_layoutdriver_type *, const struct nfs_client *, const struct nfs4_deviceid *);
234void nfs4_delete_deviceid(const struct pnfs_layoutdriver_type *, const struct nfs_client *, const struct nfs4_deviceid *); 232void nfs4_delete_deviceid(const struct pnfs_layoutdriver_type *, const struct nfs_client *, const struct nfs4_deviceid *);
235void nfs4_init_deviceid_node(struct nfs4_deviceid_node *, 233void nfs4_init_deviceid_node(struct nfs4_deviceid_node *,
@@ -262,20 +260,6 @@ static inline int pnfs_enabled_sb(struct nfs_server *nfss)
262 return nfss->pnfs_curr_ld != NULL; 260 return nfss->pnfs_curr_ld != NULL;
263} 261}
264 262
265static inline void
266pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg)
267{
268 if (lseg) {
269 struct pnfs_layoutdriver_type *ld;
270
271 ld = NFS_SERVER(req->wb_page->mapping->host)->pnfs_curr_ld;
272 if (ld->mark_pnfs_commit && ld->mark_pnfs_commit(lseg)) {
273 set_bit(PG_PNFS_COMMIT, &req->wb_flags);
274 req->wb_commit_lseg = get_lseg(lseg);
275 }
276 }
277}
278
279static inline int 263static inline int
280pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how) 264pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how)
281{ 265{
@@ -284,27 +268,42 @@ pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how)
284 return NFS_SERVER(inode)->pnfs_curr_ld->commit_pagelist(inode, mds_pages, how); 268 return NFS_SERVER(inode)->pnfs_curr_ld->commit_pagelist(inode, mds_pages, how);
285} 269}
286 270
287static inline struct list_head * 271static inline bool
288pnfs_choose_commit_list(struct nfs_page *req, struct list_head *mds) 272pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg)
289{ 273{
290 struct list_head *rv; 274 struct inode *inode = req->wb_context->dentry->d_inode;
275 struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
291 276
292 if (test_and_clear_bit(PG_PNFS_COMMIT, &req->wb_flags)) { 277 if (lseg == NULL || ld->mark_request_commit == NULL)
293 struct inode *inode = req->wb_commit_lseg->pls_layout->plh_inode; 278 return false;
279 ld->mark_request_commit(req, lseg);
280 return true;
281}
294 282
295 set_bit(NFS_INO_PNFS_COMMIT, &NFS_I(inode)->flags); 283static inline bool
296 rv = NFS_SERVER(inode)->pnfs_curr_ld->choose_commit_list(req); 284pnfs_clear_request_commit(struct nfs_page *req)
297 /* matched by ref taken when PG_PNFS_COMMIT is set */ 285{
298 put_lseg(req->wb_commit_lseg); 286 struct inode *inode = req->wb_context->dentry->d_inode;
299 } else 287 struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
300 rv = mds; 288
301 return rv; 289 if (ld == NULL || ld->clear_request_commit == NULL)
290 return false;
291 ld->clear_request_commit(req);
292 return true;
302} 293}
303 294
304static inline void pnfs_clear_request_commit(struct nfs_page *req) 295static inline int
296pnfs_scan_commit_lists(struct inode *inode, int max, spinlock_t *lock)
305{ 297{
306 if (test_and_clear_bit(PG_PNFS_COMMIT, &req->wb_flags)) 298 struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
307 put_lseg(req->wb_commit_lseg); 299 int ret;
300
301 if (ld == NULL || ld->scan_commit_lists == NULL)
302 return 0;
303 ret = ld->scan_commit_lists(inode, max, lock);
304 if (ret != 0)
305 set_bit(NFS_INO_PNFS_COMMIT, &NFS_I(inode)->flags);
306 return ret;
308} 307}
309 308
310/* Should the pNFS client commit and return the layout upon a setattr */ 309/* Should the pNFS client commit and return the layout upon a setattr */
@@ -328,6 +327,13 @@ static inline int pnfs_return_layout(struct inode *ino)
328 return 0; 327 return 0;
329} 328}
330 329
330#ifdef NFS_DEBUG
331void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id);
332#else
333static inline void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id)
334{
335}
336#endif /* NFS_DEBUG */
331#else /* CONFIG_NFS_V4_1 */ 337#else /* CONFIG_NFS_V4_1 */
332 338
333static inline void pnfs_destroy_all_layouts(struct nfs_client *clp) 339static inline void pnfs_destroy_all_layouts(struct nfs_client *clp)
@@ -400,35 +406,35 @@ static inline bool pnfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, st
400 return false; 406 return false;
401} 407}
402 408
403static inline void
404pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg)
405{
406}
407
408static inline int 409static inline int
409pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how) 410pnfs_commit_list(struct inode *inode, struct list_head *mds_pages, int how)
410{ 411{
411 return PNFS_NOT_ATTEMPTED; 412 return PNFS_NOT_ATTEMPTED;
412} 413}
413 414
414static inline struct list_head * 415static inline bool
415pnfs_choose_commit_list(struct nfs_page *req, struct list_head *mds) 416pnfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg)
416{ 417{
417 return mds; 418 return false;
418} 419}
419 420
420static inline void pnfs_clear_request_commit(struct nfs_page *req) 421static inline bool
422pnfs_clear_request_commit(struct nfs_page *req)
421{ 423{
424 return false;
422} 425}
423 426
424static inline int pnfs_layoutcommit_inode(struct inode *inode, bool sync) 427static inline int
428pnfs_scan_commit_lists(struct inode *inode, int max, spinlock_t *lock)
425{ 429{
426 return 0; 430 return 0;
427} 431}
428 432
429static inline void nfs4_deviceid_purge_client(struct nfs_client *ncl) 433static inline int pnfs_layoutcommit_inode(struct inode *inode, bool sync)
430{ 434{
435 return 0;
431} 436}
437
432#endif /* CONFIG_NFS_V4_1 */ 438#endif /* CONFIG_NFS_V4_1 */
433 439
434#endif /* FS_NFS_PNFS_H */ 440#endif /* FS_NFS_PNFS_H */
diff --git a/fs/nfs/pnfs_dev.c b/fs/nfs/pnfs_dev.c
index 4f359d2a26e..73f701f1f4d 100644
--- a/fs/nfs/pnfs_dev.c
+++ b/fs/nfs/pnfs_dev.c
@@ -43,6 +43,7 @@
43static struct hlist_head nfs4_deviceid_cache[NFS4_DEVICE_ID_HASH_SIZE]; 43static struct hlist_head nfs4_deviceid_cache[NFS4_DEVICE_ID_HASH_SIZE];
44static DEFINE_SPINLOCK(nfs4_deviceid_lock); 44static DEFINE_SPINLOCK(nfs4_deviceid_lock);
45 45
46#ifdef NFS_DEBUG
46void 47void
47nfs4_print_deviceid(const struct nfs4_deviceid *id) 48nfs4_print_deviceid(const struct nfs4_deviceid *id)
48{ 49{
@@ -52,6 +53,7 @@ nfs4_print_deviceid(const struct nfs4_deviceid *id)
52 p[0], p[1], p[2], p[3]); 53 p[0], p[1], p[2], p[3]);
53} 54}
54EXPORT_SYMBOL_GPL(nfs4_print_deviceid); 55EXPORT_SYMBOL_GPL(nfs4_print_deviceid);
56#endif
55 57
56static inline u32 58static inline u32
57nfs4_deviceid_hash(const struct nfs4_deviceid *id) 59nfs4_deviceid_hash(const struct nfs4_deviceid *id)
@@ -92,7 +94,7 @@ _lookup_deviceid(const struct pnfs_layoutdriver_type *ld,
92 * @clp nfs_client associated with deviceid 94 * @clp nfs_client associated with deviceid
93 * @id deviceid to look up 95 * @id deviceid to look up
94 */ 96 */
95struct nfs4_deviceid_node * 97static struct nfs4_deviceid_node *
96_find_get_deviceid(const struct pnfs_layoutdriver_type *ld, 98_find_get_deviceid(const struct pnfs_layoutdriver_type *ld,
97 const struct nfs_client *clp, const struct nfs4_deviceid *id, 99 const struct nfs_client *clp, const struct nfs4_deviceid *id,
98 long hash) 100 long hash)
diff --git a/fs/nfs/proc.c b/fs/nfs/proc.c
index 0c672588fe5..b63b6f4d14f 100644
--- a/fs/nfs/proc.c
+++ b/fs/nfs/proc.c
@@ -358,6 +358,11 @@ nfs_proc_unlink_setup(struct rpc_message *msg, struct inode *dir)
358 msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE]; 358 msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE];
359} 359}
360 360
361static void nfs_proc_unlink_rpc_prepare(struct rpc_task *task, struct nfs_unlinkdata *data)
362{
363 rpc_call_start(task);
364}
365
361static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir) 366static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir)
362{ 367{
363 if (nfs_async_handle_expired_key(task)) 368 if (nfs_async_handle_expired_key(task))
@@ -372,6 +377,11 @@ nfs_proc_rename_setup(struct rpc_message *msg, struct inode *dir)
372 msg->rpc_proc = &nfs_procedures[NFSPROC_RENAME]; 377 msg->rpc_proc = &nfs_procedures[NFSPROC_RENAME];
373} 378}
374 379
380static void nfs_proc_rename_rpc_prepare(struct rpc_task *task, struct nfs_renamedata *data)
381{
382 rpc_call_start(task);
383}
384
375static int 385static int
376nfs_proc_rename_done(struct rpc_task *task, struct inode *old_dir, 386nfs_proc_rename_done(struct rpc_task *task, struct inode *old_dir,
377 struct inode *new_dir) 387 struct inode *new_dir)
@@ -651,6 +661,11 @@ static void nfs_proc_read_setup(struct nfs_read_data *data, struct rpc_message *
651 msg->rpc_proc = &nfs_procedures[NFSPROC_READ]; 661 msg->rpc_proc = &nfs_procedures[NFSPROC_READ];
652} 662}
653 663
664static void nfs_proc_read_rpc_prepare(struct rpc_task *task, struct nfs_read_data *data)
665{
666 rpc_call_start(task);
667}
668
654static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data) 669static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data)
655{ 670{
656 if (nfs_async_handle_expired_key(task)) 671 if (nfs_async_handle_expired_key(task))
@@ -668,6 +683,11 @@ static void nfs_proc_write_setup(struct nfs_write_data *data, struct rpc_message
668 msg->rpc_proc = &nfs_procedures[NFSPROC_WRITE]; 683 msg->rpc_proc = &nfs_procedures[NFSPROC_WRITE];
669} 684}
670 685
686static void nfs_proc_write_rpc_prepare(struct rpc_task *task, struct nfs_write_data *data)
687{
688 rpc_call_start(task);
689}
690
671static void 691static void
672nfs_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg) 692nfs_proc_commit_setup(struct nfs_write_data *data, struct rpc_message *msg)
673{ 693{
@@ -721,9 +741,11 @@ const struct nfs_rpc_ops nfs_v2_clientops = {
721 .create = nfs_proc_create, 741 .create = nfs_proc_create,
722 .remove = nfs_proc_remove, 742 .remove = nfs_proc_remove,
723 .unlink_setup = nfs_proc_unlink_setup, 743 .unlink_setup = nfs_proc_unlink_setup,
744 .unlink_rpc_prepare = nfs_proc_unlink_rpc_prepare,
724 .unlink_done = nfs_proc_unlink_done, 745 .unlink_done = nfs_proc_unlink_done,
725 .rename = nfs_proc_rename, 746 .rename = nfs_proc_rename,
726 .rename_setup = nfs_proc_rename_setup, 747 .rename_setup = nfs_proc_rename_setup,
748 .rename_rpc_prepare = nfs_proc_rename_rpc_prepare,
727 .rename_done = nfs_proc_rename_done, 749 .rename_done = nfs_proc_rename_done,
728 .link = nfs_proc_link, 750 .link = nfs_proc_link,
729 .symlink = nfs_proc_symlink, 751 .symlink = nfs_proc_symlink,
@@ -736,8 +758,10 @@ const struct nfs_rpc_ops nfs_v2_clientops = {
736 .pathconf = nfs_proc_pathconf, 758 .pathconf = nfs_proc_pathconf,
737 .decode_dirent = nfs2_decode_dirent, 759 .decode_dirent = nfs2_decode_dirent,
738 .read_setup = nfs_proc_read_setup, 760 .read_setup = nfs_proc_read_setup,
761 .read_rpc_prepare = nfs_proc_read_rpc_prepare,
739 .read_done = nfs_read_done, 762 .read_done = nfs_read_done,
740 .write_setup = nfs_proc_write_setup, 763 .write_setup = nfs_proc_write_setup,
764 .write_rpc_prepare = nfs_proc_write_rpc_prepare,
741 .write_done = nfs_write_done, 765 .write_done = nfs_write_done,
742 .commit_setup = nfs_proc_commit_setup, 766 .commit_setup = nfs_proc_commit_setup,
743 .lock = nfs_proc_lock, 767 .lock = nfs_proc_lock,
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index cfa175c223d..cc1f758a7ee 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -66,7 +66,6 @@ void nfs_readdata_free(struct nfs_read_data *p)
66 66
67void nfs_readdata_release(struct nfs_read_data *rdata) 67void nfs_readdata_release(struct nfs_read_data *rdata)
68{ 68{
69 put_lseg(rdata->lseg);
70 put_nfs_open_context(rdata->args.context); 69 put_nfs_open_context(rdata->args.context);
71 nfs_readdata_free(rdata); 70 nfs_readdata_free(rdata);
72} 71}
@@ -465,23 +464,14 @@ static void nfs_readpage_release_partial(void *calldata)
465 nfs_readdata_release(calldata); 464 nfs_readdata_release(calldata);
466} 465}
467 466
468#if defined(CONFIG_NFS_V4_1)
469void nfs_read_prepare(struct rpc_task *task, void *calldata) 467void nfs_read_prepare(struct rpc_task *task, void *calldata)
470{ 468{
471 struct nfs_read_data *data = calldata; 469 struct nfs_read_data *data = calldata;
472 470 NFS_PROTO(data->inode)->read_rpc_prepare(task, data);
473 if (nfs4_setup_sequence(NFS_SERVER(data->inode),
474 &data->args.seq_args, &data->res.seq_res,
475 0, task))
476 return;
477 rpc_call_start(task);
478} 471}
479#endif /* CONFIG_NFS_V4_1 */
480 472
481static const struct rpc_call_ops nfs_read_partial_ops = { 473static const struct rpc_call_ops nfs_read_partial_ops = {
482#if defined(CONFIG_NFS_V4_1)
483 .rpc_call_prepare = nfs_read_prepare, 474 .rpc_call_prepare = nfs_read_prepare,
484#endif /* CONFIG_NFS_V4_1 */
485 .rpc_call_done = nfs_readpage_result_partial, 475 .rpc_call_done = nfs_readpage_result_partial,
486 .rpc_release = nfs_readpage_release_partial, 476 .rpc_release = nfs_readpage_release_partial,
487}; 477};
@@ -545,9 +535,7 @@ static void nfs_readpage_release_full(void *calldata)
545} 535}
546 536
547static const struct rpc_call_ops nfs_read_full_ops = { 537static const struct rpc_call_ops nfs_read_full_ops = {
548#if defined(CONFIG_NFS_V4_1)
549 .rpc_call_prepare = nfs_read_prepare, 538 .rpc_call_prepare = nfs_read_prepare,
550#endif /* CONFIG_NFS_V4_1 */
551 .rpc_call_done = nfs_readpage_result_full, 539 .rpc_call_done = nfs_readpage_result_full,
552 .rpc_release = nfs_readpage_release_full, 540 .rpc_release = nfs_readpage_release_full,
553}; 541};
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 3dfa4f112c0..ccc4cdb1efe 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -52,6 +52,8 @@
52#include <linux/nfs_xdr.h> 52#include <linux/nfs_xdr.h>
53#include <linux/magic.h> 53#include <linux/magic.h>
54#include <linux/parser.h> 54#include <linux/parser.h>
55#include <linux/nsproxy.h>
56#include <linux/rcupdate.h>
55 57
56#include <asm/system.h> 58#include <asm/system.h>
57#include <asm/uaccess.h> 59#include <asm/uaccess.h>
@@ -79,7 +81,6 @@ enum {
79 Opt_cto, Opt_nocto, 81 Opt_cto, Opt_nocto,
80 Opt_ac, Opt_noac, 82 Opt_ac, Opt_noac,
81 Opt_lock, Opt_nolock, 83 Opt_lock, Opt_nolock,
82 Opt_v2, Opt_v3, Opt_v4,
83 Opt_udp, Opt_tcp, Opt_rdma, 84 Opt_udp, Opt_tcp, Opt_rdma,
84 Opt_acl, Opt_noacl, 85 Opt_acl, Opt_noacl,
85 Opt_rdirplus, Opt_nordirplus, 86 Opt_rdirplus, Opt_nordirplus,
@@ -97,10 +98,10 @@ enum {
97 Opt_namelen, 98 Opt_namelen,
98 Opt_mountport, 99 Opt_mountport,
99 Opt_mountvers, 100 Opt_mountvers,
100 Opt_nfsvers,
101 Opt_minorversion, 101 Opt_minorversion,
102 102
103 /* Mount options that take string arguments */ 103 /* Mount options that take string arguments */
104 Opt_nfsvers,
104 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, 105 Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
105 Opt_addr, Opt_mountaddr, Opt_clientaddr, 106 Opt_addr, Opt_mountaddr, Opt_clientaddr,
106 Opt_lookupcache, 107 Opt_lookupcache,
@@ -132,9 +133,6 @@ static const match_table_t nfs_mount_option_tokens = {
132 { Opt_noac, "noac" }, 133 { Opt_noac, "noac" },
133 { Opt_lock, "lock" }, 134 { Opt_lock, "lock" },
134 { Opt_nolock, "nolock" }, 135 { Opt_nolock, "nolock" },
135 { Opt_v2, "v2" },
136 { Opt_v3, "v3" },
137 { Opt_v4, "v4" },
138 { Opt_udp, "udp" }, 136 { Opt_udp, "udp" },
139 { Opt_tcp, "tcp" }, 137 { Opt_tcp, "tcp" },
140 { Opt_rdma, "rdma" }, 138 { Opt_rdma, "rdma" },
@@ -163,9 +161,10 @@ static const match_table_t nfs_mount_option_tokens = {
163 { Opt_namelen, "namlen=%s" }, 161 { Opt_namelen, "namlen=%s" },
164 { Opt_mountport, "mountport=%s" }, 162 { Opt_mountport, "mountport=%s" },
165 { Opt_mountvers, "mountvers=%s" }, 163 { Opt_mountvers, "mountvers=%s" },
164 { Opt_minorversion, "minorversion=%s" },
165
166 { Opt_nfsvers, "nfsvers=%s" }, 166 { Opt_nfsvers, "nfsvers=%s" },
167 { Opt_nfsvers, "vers=%s" }, 167 { Opt_nfsvers, "vers=%s" },
168 { Opt_minorversion, "minorversion=%s" },
169 168
170 { Opt_sec, "sec=%s" }, 169 { Opt_sec, "sec=%s" },
171 { Opt_proto, "proto=%s" }, 170 { Opt_proto, "proto=%s" },
@@ -179,6 +178,9 @@ static const match_table_t nfs_mount_option_tokens = {
179 { Opt_fscache_uniq, "fsc=%s" }, 178 { Opt_fscache_uniq, "fsc=%s" },
180 { Opt_local_lock, "local_lock=%s" }, 179 { Opt_local_lock, "local_lock=%s" },
181 180
181 /* The following needs to be listed after all other options */
182 { Opt_nfsvers, "v%s" },
183
182 { Opt_err, NULL } 184 { Opt_err, NULL }
183}; 185};
184 186
@@ -259,6 +261,22 @@ static match_table_t nfs_local_lock_tokens = {
259 { Opt_local_lock_err, NULL } 261 { Opt_local_lock_err, NULL }
260}; 262};
261 263
264enum {
265 Opt_vers_2, Opt_vers_3, Opt_vers_4, Opt_vers_4_0,
266 Opt_vers_4_1,
267
268 Opt_vers_err
269};
270
271static match_table_t nfs_vers_tokens = {
272 { Opt_vers_2, "2" },
273 { Opt_vers_3, "3" },
274 { Opt_vers_4, "4" },
275 { Opt_vers_4_0, "4.0" },
276 { Opt_vers_4_1, "4.1" },
277
278 { Opt_vers_err, NULL }
279};
262 280
263static void nfs_umount_begin(struct super_block *); 281static void nfs_umount_begin(struct super_block *);
264static int nfs_statfs(struct dentry *, struct kstatfs *); 282static int nfs_statfs(struct dentry *, struct kstatfs *);
@@ -620,7 +638,6 @@ static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
620 struct nfs_client *clp = nfss->nfs_client; 638 struct nfs_client *clp = nfss->nfs_client;
621 639
622 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr); 640 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
623 seq_printf(m, ",minorversion=%u", clp->cl_minorversion);
624} 641}
625#else 642#else
626static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss, 643static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
@@ -629,6 +646,15 @@ static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
629} 646}
630#endif 647#endif
631 648
649static void nfs_show_nfs_version(struct seq_file *m,
650 unsigned int version,
651 unsigned int minorversion)
652{
653 seq_printf(m, ",vers=%u", version);
654 if (version == 4)
655 seq_printf(m, ".%u", minorversion);
656}
657
632/* 658/*
633 * Describe the mount options in force on this server representation 659 * Describe the mount options in force on this server representation
634 */ 660 */
@@ -656,7 +682,7 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
656 u32 version = clp->rpc_ops->version; 682 u32 version = clp->rpc_ops->version;
657 int local_flock, local_fcntl; 683 int local_flock, local_fcntl;
658 684
659 seq_printf(m, ",vers=%u", version); 685 nfs_show_nfs_version(m, version, clp->cl_minorversion);
660 seq_printf(m, ",rsize=%u", nfss->rsize); 686 seq_printf(m, ",rsize=%u", nfss->rsize);
661 seq_printf(m, ",wsize=%u", nfss->wsize); 687 seq_printf(m, ",wsize=%u", nfss->wsize);
662 if (nfss->bsize != 0) 688 if (nfss->bsize != 0)
@@ -676,8 +702,10 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
676 else 702 else
677 seq_puts(m, nfs_infop->nostr); 703 seq_puts(m, nfs_infop->nostr);
678 } 704 }
705 rcu_read_lock();
679 seq_printf(m, ",proto=%s", 706 seq_printf(m, ",proto=%s",
680 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID)); 707 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
708 rcu_read_unlock();
681 if (version == 4) { 709 if (version == 4) {
682 if (nfss->port != NFS_PORT) 710 if (nfss->port != NFS_PORT)
683 seq_printf(m, ",port=%u", nfss->port); 711 seq_printf(m, ",port=%u", nfss->port);
@@ -726,9 +754,11 @@ static int nfs_show_options(struct seq_file *m, struct dentry *root)
726 754
727 nfs_show_mount_options(m, nfss, 0); 755 nfs_show_mount_options(m, nfss, 0);
728 756
757 rcu_read_lock();
729 seq_printf(m, ",addr=%s", 758 seq_printf(m, ",addr=%s",
730 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient, 759 rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
731 RPC_DISPLAY_ADDR)); 760 RPC_DISPLAY_ADDR));
761 rcu_read_unlock();
732 762
733 return 0; 763 return 0;
734} 764}
@@ -745,7 +775,6 @@ static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
745#endif 775#endif
746#endif 776#endif
747 777
748#ifdef CONFIG_NFS_V4
749#ifdef CONFIG_NFS_V4_1 778#ifdef CONFIG_NFS_V4_1
750static void show_pnfs(struct seq_file *m, struct nfs_server *server) 779static void show_pnfs(struct seq_file *m, struct nfs_server *server)
751{ 780{
@@ -755,9 +784,26 @@ static void show_pnfs(struct seq_file *m, struct nfs_server *server)
755 else 784 else
756 seq_printf(m, "not configured"); 785 seq_printf(m, "not configured");
757} 786}
787
788static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
789{
790 if (nfss->nfs_client && nfss->nfs_client->impl_id) {
791 struct nfs41_impl_id *impl_id = nfss->nfs_client->impl_id;
792 seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
793 "date='%llu,%u'",
794 impl_id->name, impl_id->domain,
795 impl_id->date.seconds, impl_id->date.nseconds);
796 }
797}
758#else 798#else
759static void show_pnfs(struct seq_file *m, struct nfs_server *server) {} 799#ifdef CONFIG_NFS_V4
800static void show_pnfs(struct seq_file *m, struct nfs_server *server)
801{
802}
760#endif 803#endif
804static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
805{
806}
761#endif 807#endif
762 808
763static int nfs_show_devname(struct seq_file *m, struct dentry *root) 809static int nfs_show_devname(struct seq_file *m, struct dentry *root)
@@ -806,6 +852,8 @@ static int nfs_show_stats(struct seq_file *m, struct dentry *root)
806 852
807 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ); 853 seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
808 854
855 show_implementation_id(m, nfss);
856
809 seq_printf(m, "\n\tcaps:\t"); 857 seq_printf(m, "\n\tcaps:\t");
810 seq_printf(m, "caps=0x%x", nfss->caps); 858 seq_printf(m, "caps=0x%x", nfss->caps);
811 seq_printf(m, ",wtmult=%u", nfss->wtmult); 859 seq_printf(m, ",wtmult=%u", nfss->wtmult);
@@ -908,6 +956,7 @@ static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(unsigned int ve
908 data->auth_flavor_len = 1; 956 data->auth_flavor_len = 1;
909 data->version = version; 957 data->version = version;
910 data->minorversion = 0; 958 data->minorversion = 0;
959 data->net = current->nsproxy->net_ns;
911 security_init_mnt_opts(&data->lsm_opts); 960 security_init_mnt_opts(&data->lsm_opts);
912 } 961 }
913 return data; 962 return data;
@@ -1052,6 +1101,40 @@ static int nfs_parse_security_flavors(char *value,
1052 return 1; 1101 return 1;
1053} 1102}
1054 1103
1104static int nfs_parse_version_string(char *string,
1105 struct nfs_parsed_mount_data *mnt,
1106 substring_t *args)
1107{
1108 mnt->flags &= ~NFS_MOUNT_VER3;
1109 switch (match_token(string, nfs_vers_tokens, args)) {
1110 case Opt_vers_2:
1111 mnt->version = 2;
1112 break;
1113 case Opt_vers_3:
1114 mnt->flags |= NFS_MOUNT_VER3;
1115 mnt->version = 3;
1116 break;
1117 case Opt_vers_4:
1118 /* Backward compatibility option. In future,
1119 * the mount program should always supply
1120 * a NFSv4 minor version number.
1121 */
1122 mnt->version = 4;
1123 break;
1124 case Opt_vers_4_0:
1125 mnt->version = 4;
1126 mnt->minorversion = 0;
1127 break;
1128 case Opt_vers_4_1:
1129 mnt->version = 4;
1130 mnt->minorversion = 1;
1131 break;
1132 default:
1133 return 0;
1134 }
1135 return 1;
1136}
1137
1055static int nfs_get_option_str(substring_t args[], char **option) 1138static int nfs_get_option_str(substring_t args[], char **option)
1056{ 1139{
1057 kfree(*option); 1140 kfree(*option);
@@ -1157,18 +1240,6 @@ static int nfs_parse_mount_options(char *raw,
1157 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK | 1240 mnt->flags |= (NFS_MOUNT_LOCAL_FLOCK |
1158 NFS_MOUNT_LOCAL_FCNTL); 1241 NFS_MOUNT_LOCAL_FCNTL);
1159 break; 1242 break;
1160 case Opt_v2:
1161 mnt->flags &= ~NFS_MOUNT_VER3;
1162 mnt->version = 2;
1163 break;
1164 case Opt_v3:
1165 mnt->flags |= NFS_MOUNT_VER3;
1166 mnt->version = 3;
1167 break;
1168 case Opt_v4:
1169 mnt->flags &= ~NFS_MOUNT_VER3;
1170 mnt->version = 4;
1171 break;
1172 case Opt_udp: 1243 case Opt_udp:
1173 mnt->flags &= ~NFS_MOUNT_TCP; 1244 mnt->flags &= ~NFS_MOUNT_TCP;
1174 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP; 1245 mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
@@ -1295,26 +1366,6 @@ static int nfs_parse_mount_options(char *raw,
1295 goto out_invalid_value; 1366 goto out_invalid_value;
1296 mnt->mount_server.version = option; 1367 mnt->mount_server.version = option;
1297 break; 1368 break;
1298 case Opt_nfsvers:
1299 if (nfs_get_option_ul(args, &option))
1300 goto out_invalid_value;
1301 switch (option) {
1302 case NFS2_VERSION:
1303 mnt->flags &= ~NFS_MOUNT_VER3;
1304 mnt->version = 2;
1305 break;
1306 case NFS3_VERSION:
1307 mnt->flags |= NFS_MOUNT_VER3;
1308 mnt->version = 3;
1309 break;
1310 case NFS4_VERSION:
1311 mnt->flags &= ~NFS_MOUNT_VER3;
1312 mnt->version = 4;
1313 break;
1314 default:
1315 goto out_invalid_value;
1316 }
1317 break;
1318 case Opt_minorversion: 1369 case Opt_minorversion:
1319 if (nfs_get_option_ul(args, &option)) 1370 if (nfs_get_option_ul(args, &option))
1320 goto out_invalid_value; 1371 goto out_invalid_value;
@@ -1326,6 +1377,15 @@ static int nfs_parse_mount_options(char *raw,
1326 /* 1377 /*
1327 * options that take text values 1378 * options that take text values
1328 */ 1379 */
1380 case Opt_nfsvers:
1381 string = match_strdup(args);
1382 if (string == NULL)
1383 goto out_nomem;
1384 rc = nfs_parse_version_string(string, mnt, args);
1385 kfree(string);
1386 if (!rc)
1387 goto out_invalid_value;
1388 break;
1329 case Opt_sec: 1389 case Opt_sec:
1330 string = match_strdup(args); 1390 string = match_strdup(args);
1331 if (string == NULL) 1391 if (string == NULL)
@@ -1405,7 +1465,7 @@ static int nfs_parse_mount_options(char *raw,
1405 if (string == NULL) 1465 if (string == NULL)
1406 goto out_nomem; 1466 goto out_nomem;
1407 mnt->nfs_server.addrlen = 1467 mnt->nfs_server.addrlen =
1408 rpc_pton(string, strlen(string), 1468 rpc_pton(mnt->net, string, strlen(string),
1409 (struct sockaddr *) 1469 (struct sockaddr *)
1410 &mnt->nfs_server.address, 1470 &mnt->nfs_server.address,
1411 sizeof(mnt->nfs_server.address)); 1471 sizeof(mnt->nfs_server.address));
@@ -1427,7 +1487,7 @@ static int nfs_parse_mount_options(char *raw,
1427 if (string == NULL) 1487 if (string == NULL)
1428 goto out_nomem; 1488 goto out_nomem;
1429 mnt->mount_server.addrlen = 1489 mnt->mount_server.addrlen =
1430 rpc_pton(string, strlen(string), 1490 rpc_pton(mnt->net, string, strlen(string),
1431 (struct sockaddr *) 1491 (struct sockaddr *)
1432 &mnt->mount_server.address, 1492 &mnt->mount_server.address,
1433 sizeof(mnt->mount_server.address)); 1493 sizeof(mnt->mount_server.address));
@@ -1516,6 +1576,9 @@ static int nfs_parse_mount_options(char *raw,
1516 if (!sloppy && invalid_option) 1576 if (!sloppy && invalid_option)
1517 return 0; 1577 return 0;
1518 1578
1579 if (mnt->minorversion && mnt->version != 4)
1580 goto out_minorversion_mismatch;
1581
1519 /* 1582 /*
1520 * verify that any proto=/mountproto= options match the address 1583 * verify that any proto=/mountproto= options match the address
1521 * familiies in the addr=/mountaddr= options. 1584 * familiies in the addr=/mountaddr= options.
@@ -1549,6 +1612,10 @@ out_invalid_address:
1549out_invalid_value: 1612out_invalid_value:
1550 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p); 1613 printk(KERN_INFO "NFS: bad mount option value specified: %s\n", p);
1551 return 0; 1614 return 0;
1615out_minorversion_mismatch:
1616 printk(KERN_INFO "NFS: mount option vers=%u does not support "
1617 "minorversion=%u\n", mnt->version, mnt->minorversion);
1618 return 0;
1552out_nomem: 1619out_nomem:
1553 printk(KERN_INFO "NFS: not enough memory to parse option\n"); 1620 printk(KERN_INFO "NFS: not enough memory to parse option\n");
1554 return 0; 1621 return 0;
@@ -1622,6 +1689,7 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args,
1622 .noresvport = args->flags & NFS_MOUNT_NORESVPORT, 1689 .noresvport = args->flags & NFS_MOUNT_NORESVPORT,
1623 .auth_flav_len = &server_authlist_len, 1690 .auth_flav_len = &server_authlist_len,
1624 .auth_flavs = server_authlist, 1691 .auth_flavs = server_authlist,
1692 .net = args->net,
1625 }; 1693 };
1626 int status; 1694 int status;
1627 1695
@@ -2047,7 +2115,7 @@ static inline void nfs_initialise_sb(struct super_block *sb)
2047 2115
2048 /* We probably want something more informative here */ 2116 /* We probably want something more informative here */
2049 snprintf(sb->s_id, sizeof(sb->s_id), 2117 snprintf(sb->s_id, sizeof(sb->s_id),
2050 "%x:%x", MAJOR(sb->s_dev), MINOR(sb->s_dev)); 2118 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
2051 2119
2052 if (sb->s_blocksize == 0) 2120 if (sb->s_blocksize == 0)
2053 sb->s_blocksize = nfs_block_bits(server->wsize, 2121 sb->s_blocksize = nfs_block_bits(server->wsize,
@@ -2499,12 +2567,6 @@ static int nfs4_validate_text_mount_data(void *options,
2499 return -EINVAL; 2567 return -EINVAL;
2500 } 2568 }
2501 2569
2502 if (args->client_address == NULL) {
2503 dfprintk(MOUNT,
2504 "NFS4: mount program didn't pass callback address\n");
2505 return -EINVAL;
2506 }
2507
2508 return nfs_parse_devname(dev_name, 2570 return nfs_parse_devname(dev_name,
2509 &args->nfs_server.hostname, 2571 &args->nfs_server.hostname,
2510 NFS4_MAXNAMLEN, 2572 NFS4_MAXNAMLEN,
@@ -2663,8 +2725,7 @@ nfs4_remote_mount(struct file_system_type *fs_type, int flags,
2663 if (!s->s_root) { 2725 if (!s->s_root) {
2664 /* initial superblock/root creation */ 2726 /* initial superblock/root creation */
2665 nfs4_fill_super(s); 2727 nfs4_fill_super(s);
2666 nfs_fscache_get_super_cookie( 2728 nfs_fscache_get_super_cookie(s, data->fscache_uniq, NULL);
2667 s, data ? data->fscache_uniq : NULL, NULL);
2668 } 2729 }
2669 2730
2670 mntroot = nfs4_get_root(s, mntfh, dev_name); 2731 mntroot = nfs4_get_root(s, mntfh, dev_name);
diff --git a/fs/nfs/sysctl.c b/fs/nfs/sysctl.c
index 978aaeb8a09..ad4d2e787b2 100644
--- a/fs/nfs/sysctl.c
+++ b/fs/nfs/sysctl.c
@@ -32,7 +32,6 @@ static ctl_table nfs_cb_sysctls[] = {
32 .extra1 = (int *)&nfs_set_port_min, 32 .extra1 = (int *)&nfs_set_port_min,
33 .extra2 = (int *)&nfs_set_port_max, 33 .extra2 = (int *)&nfs_set_port_max,
34 }, 34 },
35#ifndef CONFIG_NFS_USE_NEW_IDMAPPER
36 { 35 {
37 .procname = "idmap_cache_timeout", 36 .procname = "idmap_cache_timeout",
38 .data = &nfs_idmap_cache_timeout, 37 .data = &nfs_idmap_cache_timeout,
@@ -40,7 +39,6 @@ static ctl_table nfs_cb_sysctls[] = {
40 .mode = 0644, 39 .mode = 0644,
41 .proc_handler = proc_dointvec_jiffies, 40 .proc_handler = proc_dointvec_jiffies,
42 }, 41 },
43#endif /* CONFIG_NFS_USE_NEW_IDMAPPER */
44#endif 42#endif
45 { 43 {
46 .procname = "nfs_mountpoint_timeout", 44 .procname = "nfs_mountpoint_timeout",
diff --git a/fs/nfs/unlink.c b/fs/nfs/unlink.c
index 4f9319a2e56..3210a03342f 100644
--- a/fs/nfs/unlink.c
+++ b/fs/nfs/unlink.c
@@ -20,15 +20,6 @@
20#include "iostat.h" 20#include "iostat.h"
21#include "delegation.h" 21#include "delegation.h"
22 22
23struct nfs_unlinkdata {
24 struct hlist_node list;
25 struct nfs_removeargs args;
26 struct nfs_removeres res;
27 struct inode *dir;
28 struct rpc_cred *cred;
29 struct nfs_fattr dir_attr;
30};
31
32/** 23/**
33 * nfs_free_unlinkdata - release data from a sillydelete operation. 24 * nfs_free_unlinkdata - release data from a sillydelete operation.
34 * @data: pointer to unlink structure. 25 * @data: pointer to unlink structure.
@@ -107,25 +98,16 @@ static void nfs_async_unlink_release(void *calldata)
107 nfs_sb_deactive(sb); 98 nfs_sb_deactive(sb);
108} 99}
109 100
110#if defined(CONFIG_NFS_V4_1) 101static void nfs_unlink_prepare(struct rpc_task *task, void *calldata)
111void nfs_unlink_prepare(struct rpc_task *task, void *calldata)
112{ 102{
113 struct nfs_unlinkdata *data = calldata; 103 struct nfs_unlinkdata *data = calldata;
114 struct nfs_server *server = NFS_SERVER(data->dir); 104 NFS_PROTO(data->dir)->unlink_rpc_prepare(task, data);
115
116 if (nfs4_setup_sequence(server, &data->args.seq_args,
117 &data->res.seq_res, 1, task))
118 return;
119 rpc_call_start(task);
120} 105}
121#endif /* CONFIG_NFS_V4_1 */
122 106
123static const struct rpc_call_ops nfs_unlink_ops = { 107static const struct rpc_call_ops nfs_unlink_ops = {
124 .rpc_call_done = nfs_async_unlink_done, 108 .rpc_call_done = nfs_async_unlink_done,
125 .rpc_release = nfs_async_unlink_release, 109 .rpc_release = nfs_async_unlink_release,
126#if defined(CONFIG_NFS_V4_1)
127 .rpc_call_prepare = nfs_unlink_prepare, 110 .rpc_call_prepare = nfs_unlink_prepare,
128#endif /* CONFIG_NFS_V4_1 */
129}; 111};
130 112
131static int nfs_do_call_unlink(struct dentry *parent, struct inode *dir, struct nfs_unlinkdata *data) 113static int nfs_do_call_unlink(struct dentry *parent, struct inode *dir, struct nfs_unlinkdata *data)
@@ -341,18 +323,6 @@ nfs_cancel_async_unlink(struct dentry *dentry)
341 spin_unlock(&dentry->d_lock); 323 spin_unlock(&dentry->d_lock);
342} 324}
343 325
344struct nfs_renamedata {
345 struct nfs_renameargs args;
346 struct nfs_renameres res;
347 struct rpc_cred *cred;
348 struct inode *old_dir;
349 struct dentry *old_dentry;
350 struct nfs_fattr old_fattr;
351 struct inode *new_dir;
352 struct dentry *new_dentry;
353 struct nfs_fattr new_fattr;
354};
355
356/** 326/**
357 * nfs_async_rename_done - Sillyrename post-processing 327 * nfs_async_rename_done - Sillyrename post-processing
358 * @task: rpc_task of the sillyrename 328 * @task: rpc_task of the sillyrename
@@ -403,25 +373,16 @@ static void nfs_async_rename_release(void *calldata)
403 kfree(data); 373 kfree(data);
404} 374}
405 375
406#if defined(CONFIG_NFS_V4_1)
407static void nfs_rename_prepare(struct rpc_task *task, void *calldata) 376static void nfs_rename_prepare(struct rpc_task *task, void *calldata)
408{ 377{
409 struct nfs_renamedata *data = calldata; 378 struct nfs_renamedata *data = calldata;
410 struct nfs_server *server = NFS_SERVER(data->old_dir); 379 NFS_PROTO(data->old_dir)->rename_rpc_prepare(task, data);
411
412 if (nfs4_setup_sequence(server, &data->args.seq_args,
413 &data->res.seq_res, 1, task))
414 return;
415 rpc_call_start(task);
416} 380}
417#endif /* CONFIG_NFS_V4_1 */
418 381
419static const struct rpc_call_ops nfs_rename_ops = { 382static const struct rpc_call_ops nfs_rename_ops = {
420 .rpc_call_done = nfs_async_rename_done, 383 .rpc_call_done = nfs_async_rename_done,
421 .rpc_release = nfs_async_rename_release, 384 .rpc_release = nfs_async_rename_release,
422#if defined(CONFIG_NFS_V4_1)
423 .rpc_call_prepare = nfs_rename_prepare, 385 .rpc_call_prepare = nfs_rename_prepare,
424#endif /* CONFIG_NFS_V4_1 */
425}; 386};
426 387
427/** 388/**
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 834f0fe96f8..2c68818f68a 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -100,7 +100,6 @@ void nfs_writedata_free(struct nfs_write_data *p)
100 100
101void nfs_writedata_release(struct nfs_write_data *wdata) 101void nfs_writedata_release(struct nfs_write_data *wdata)
102{ 102{
103 put_lseg(wdata->lseg);
104 put_nfs_open_context(wdata->args.context); 103 put_nfs_open_context(wdata->args.context);
105 nfs_writedata_free(wdata); 104 nfs_writedata_free(wdata);
106} 105}
@@ -236,10 +235,10 @@ static struct nfs_page *nfs_find_and_lock_request(struct page *page, bool nonblo
236 req = nfs_page_find_request_locked(page); 235 req = nfs_page_find_request_locked(page);
237 if (req == NULL) 236 if (req == NULL)
238 break; 237 break;
239 if (nfs_set_page_tag_locked(req)) 238 if (nfs_lock_request_dontget(req))
240 break; 239 break;
241 /* Note: If we hold the page lock, as is the case in nfs_writepage, 240 /* Note: If we hold the page lock, as is the case in nfs_writepage,
242 * then the call to nfs_set_page_tag_locked() will always 241 * then the call to nfs_lock_request_dontget() will always
243 * succeed provided that someone hasn't already marked the 242 * succeed provided that someone hasn't already marked the
244 * request as dirty (in which case we don't care). 243 * request as dirty (in which case we don't care).
245 */ 244 */
@@ -375,21 +374,14 @@ out_err:
375/* 374/*
376 * Insert a write request into an inode 375 * Insert a write request into an inode
377 */ 376 */
378static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req) 377static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
379{ 378{
380 struct nfs_inode *nfsi = NFS_I(inode); 379 struct nfs_inode *nfsi = NFS_I(inode);
381 int error;
382
383 error = radix_tree_preload(GFP_NOFS);
384 if (error != 0)
385 goto out;
386 380
387 /* Lock the request! */ 381 /* Lock the request! */
388 nfs_lock_request_dontget(req); 382 nfs_lock_request_dontget(req);
389 383
390 spin_lock(&inode->i_lock); 384 spin_lock(&inode->i_lock);
391 error = radix_tree_insert(&nfsi->nfs_page_tree, req->wb_index, req);
392 BUG_ON(error);
393 if (!nfsi->npages && nfs_have_delegation(inode, FMODE_WRITE)) 385 if (!nfsi->npages && nfs_have_delegation(inode, FMODE_WRITE))
394 inode->i_version++; 386 inode->i_version++;
395 set_bit(PG_MAPPED, &req->wb_flags); 387 set_bit(PG_MAPPED, &req->wb_flags);
@@ -397,12 +389,7 @@ static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
397 set_page_private(req->wb_page, (unsigned long)req); 389 set_page_private(req->wb_page, (unsigned long)req);
398 nfsi->npages++; 390 nfsi->npages++;
399 kref_get(&req->wb_kref); 391 kref_get(&req->wb_kref);
400 radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index,
401 NFS_PAGE_TAG_LOCKED);
402 spin_unlock(&inode->i_lock); 392 spin_unlock(&inode->i_lock);
403 radix_tree_preload_end();
404out:
405 return error;
406} 393}
407 394
408/* 395/*
@@ -419,7 +406,6 @@ static void nfs_inode_remove_request(struct nfs_page *req)
419 set_page_private(req->wb_page, 0); 406 set_page_private(req->wb_page, 0);
420 ClearPagePrivate(req->wb_page); 407 ClearPagePrivate(req->wb_page);
421 clear_bit(PG_MAPPED, &req->wb_flags); 408 clear_bit(PG_MAPPED, &req->wb_flags);
422 radix_tree_delete(&nfsi->nfs_page_tree, req->wb_index);
423 nfsi->npages--; 409 nfsi->npages--;
424 spin_unlock(&inode->i_lock); 410 spin_unlock(&inode->i_lock);
425 nfs_release_request(req); 411 nfs_release_request(req);
@@ -432,39 +418,90 @@ nfs_mark_request_dirty(struct nfs_page *req)
432} 418}
433 419
434#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 420#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
435/* 421/**
436 * Add a request to the inode's commit list. 422 * nfs_request_add_commit_list - add request to a commit list
423 * @req: pointer to a struct nfs_page
424 * @head: commit list head
425 *
426 * This sets the PG_CLEAN bit, updates the inode global count of
427 * number of outstanding requests requiring a commit as well as
428 * the MM page stats.
429 *
430 * The caller must _not_ hold the inode->i_lock, but must be
431 * holding the nfs_page lock.
437 */ 432 */
438static void 433void
439nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg) 434nfs_request_add_commit_list(struct nfs_page *req, struct list_head *head)
440{ 435{
441 struct inode *inode = req->wb_context->dentry->d_inode; 436 struct inode *inode = req->wb_context->dentry->d_inode;
442 struct nfs_inode *nfsi = NFS_I(inode);
443 437
444 spin_lock(&inode->i_lock);
445 set_bit(PG_CLEAN, &(req)->wb_flags); 438 set_bit(PG_CLEAN, &(req)->wb_flags);
446 radix_tree_tag_set(&nfsi->nfs_page_tree, 439 spin_lock(&inode->i_lock);
447 req->wb_index, 440 nfs_list_add_request(req, head);
448 NFS_PAGE_TAG_COMMIT); 441 NFS_I(inode)->ncommit++;
449 nfsi->ncommit++;
450 spin_unlock(&inode->i_lock); 442 spin_unlock(&inode->i_lock);
451 pnfs_mark_request_commit(req, lseg);
452 inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); 443 inc_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
453 inc_bdi_stat(req->wb_page->mapping->backing_dev_info, BDI_RECLAIMABLE); 444 inc_bdi_stat(req->wb_page->mapping->backing_dev_info, BDI_RECLAIMABLE);
454 __mark_inode_dirty(inode, I_DIRTY_DATASYNC); 445 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
455} 446}
447EXPORT_SYMBOL_GPL(nfs_request_add_commit_list);
456 448
457static int 449/**
450 * nfs_request_remove_commit_list - Remove request from a commit list
451 * @req: pointer to a nfs_page
452 *
453 * This clears the PG_CLEAN bit, and updates the inode global count of
454 * number of outstanding requests requiring a commit
455 * It does not update the MM page stats.
456 *
457 * The caller _must_ hold the inode->i_lock and the nfs_page lock.
458 */
459void
460nfs_request_remove_commit_list(struct nfs_page *req)
461{
462 struct inode *inode = req->wb_context->dentry->d_inode;
463
464 if (!test_and_clear_bit(PG_CLEAN, &(req)->wb_flags))
465 return;
466 nfs_list_remove_request(req);
467 NFS_I(inode)->ncommit--;
468}
469EXPORT_SYMBOL_GPL(nfs_request_remove_commit_list);
470
471
472/*
473 * Add a request to the inode's commit list.
474 */
475static void
476nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg)
477{
478 struct inode *inode = req->wb_context->dentry->d_inode;
479
480 if (pnfs_mark_request_commit(req, lseg))
481 return;
482 nfs_request_add_commit_list(req, &NFS_I(inode)->commit_list);
483}
484
485static void
486nfs_clear_page_commit(struct page *page)
487{
488 dec_zone_page_state(page, NR_UNSTABLE_NFS);
489 dec_bdi_stat(page->mapping->backing_dev_info, BDI_RECLAIMABLE);
490}
491
492static void
458nfs_clear_request_commit(struct nfs_page *req) 493nfs_clear_request_commit(struct nfs_page *req)
459{ 494{
460 struct page *page = req->wb_page; 495 if (test_bit(PG_CLEAN, &req->wb_flags)) {
496 struct inode *inode = req->wb_context->dentry->d_inode;
461 497
462 if (test_and_clear_bit(PG_CLEAN, &(req)->wb_flags)) { 498 if (!pnfs_clear_request_commit(req)) {
463 dec_zone_page_state(page, NR_UNSTABLE_NFS); 499 spin_lock(&inode->i_lock);
464 dec_bdi_stat(page->mapping->backing_dev_info, BDI_RECLAIMABLE); 500 nfs_request_remove_commit_list(req);
465 return 1; 501 spin_unlock(&inode->i_lock);
502 }
503 nfs_clear_page_commit(req->wb_page);
466 } 504 }
467 return 0;
468} 505}
469 506
470static inline 507static inline
@@ -491,15 +528,14 @@ int nfs_reschedule_unstable_write(struct nfs_page *req,
491 return 0; 528 return 0;
492} 529}
493#else 530#else
494static inline void 531static void
495nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg) 532nfs_mark_request_commit(struct nfs_page *req, struct pnfs_layout_segment *lseg)
496{ 533{
497} 534}
498 535
499static inline int 536static void
500nfs_clear_request_commit(struct nfs_page *req) 537nfs_clear_request_commit(struct nfs_page *req)
501{ 538{
502 return 0;
503} 539}
504 540
505static inline 541static inline
@@ -520,46 +556,65 @@ int nfs_reschedule_unstable_write(struct nfs_page *req,
520static int 556static int
521nfs_need_commit(struct nfs_inode *nfsi) 557nfs_need_commit(struct nfs_inode *nfsi)
522{ 558{
523 return radix_tree_tagged(&nfsi->nfs_page_tree, NFS_PAGE_TAG_COMMIT); 559 return nfsi->ncommit > 0;
560}
561
562/* i_lock held by caller */
563static int
564nfs_scan_commit_list(struct list_head *src, struct list_head *dst, int max,
565 spinlock_t *lock)
566{
567 struct nfs_page *req, *tmp;
568 int ret = 0;
569
570 list_for_each_entry_safe(req, tmp, src, wb_list) {
571 if (!nfs_lock_request(req))
572 continue;
573 if (cond_resched_lock(lock))
574 list_safe_reset_next(req, tmp, wb_list);
575 nfs_request_remove_commit_list(req);
576 nfs_list_add_request(req, dst);
577 ret++;
578 if (ret == max)
579 break;
580 }
581 return ret;
524} 582}
525 583
526/* 584/*
527 * nfs_scan_commit - Scan an inode for commit requests 585 * nfs_scan_commit - Scan an inode for commit requests
528 * @inode: NFS inode to scan 586 * @inode: NFS inode to scan
529 * @dst: destination list 587 * @dst: destination list
530 * @idx_start: lower bound of page->index to scan.
531 * @npages: idx_start + npages sets the upper bound to scan.
532 * 588 *
533 * Moves requests from the inode's 'commit' request list. 589 * Moves requests from the inode's 'commit' request list.
534 * The requests are *not* checked to ensure that they form a contiguous set. 590 * The requests are *not* checked to ensure that they form a contiguous set.
535 */ 591 */
536static int 592static int
537nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages) 593nfs_scan_commit(struct inode *inode, struct list_head *dst)
538{ 594{
539 struct nfs_inode *nfsi = NFS_I(inode); 595 struct nfs_inode *nfsi = NFS_I(inode);
540 int ret; 596 int ret = 0;
541
542 if (!nfs_need_commit(nfsi))
543 return 0;
544 597
545 spin_lock(&inode->i_lock); 598 spin_lock(&inode->i_lock);
546 ret = nfs_scan_list(nfsi, dst, idx_start, npages, NFS_PAGE_TAG_COMMIT); 599 if (nfsi->ncommit > 0) {
547 if (ret > 0) 600 const int max = INT_MAX;
548 nfsi->ncommit -= ret;
549 spin_unlock(&inode->i_lock);
550
551 if (nfs_need_commit(NFS_I(inode)))
552 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
553 601
602 ret = nfs_scan_commit_list(&nfsi->commit_list, dst, max,
603 &inode->i_lock);
604 ret += pnfs_scan_commit_lists(inode, max - ret,
605 &inode->i_lock);
606 }
607 spin_unlock(&inode->i_lock);
554 return ret; 608 return ret;
555} 609}
610
556#else 611#else
557static inline int nfs_need_commit(struct nfs_inode *nfsi) 612static inline int nfs_need_commit(struct nfs_inode *nfsi)
558{ 613{
559 return 0; 614 return 0;
560} 615}
561 616
562static inline int nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages) 617static inline int nfs_scan_commit(struct inode *inode, struct list_head *dst)
563{ 618{
564 return 0; 619 return 0;
565} 620}
@@ -604,7 +659,7 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
604 || end < req->wb_offset) 659 || end < req->wb_offset)
605 goto out_flushme; 660 goto out_flushme;
606 661
607 if (nfs_set_page_tag_locked(req)) 662 if (nfs_lock_request_dontget(req))
608 break; 663 break;
609 664
610 /* The request is locked, so wait and then retry */ 665 /* The request is locked, so wait and then retry */
@@ -616,13 +671,6 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
616 spin_lock(&inode->i_lock); 671 spin_lock(&inode->i_lock);
617 } 672 }
618 673
619 if (nfs_clear_request_commit(req) &&
620 radix_tree_tag_clear(&NFS_I(inode)->nfs_page_tree,
621 req->wb_index, NFS_PAGE_TAG_COMMIT) != NULL) {
622 NFS_I(inode)->ncommit--;
623 pnfs_clear_request_commit(req);
624 }
625
626 /* Okay, the request matches. Update the region */ 674 /* Okay, the request matches. Update the region */
627 if (offset < req->wb_offset) { 675 if (offset < req->wb_offset) {
628 req->wb_offset = offset; 676 req->wb_offset = offset;
@@ -634,6 +682,7 @@ static struct nfs_page *nfs_try_to_update_request(struct inode *inode,
634 req->wb_bytes = rqend - req->wb_offset; 682 req->wb_bytes = rqend - req->wb_offset;
635out_unlock: 683out_unlock:
636 spin_unlock(&inode->i_lock); 684 spin_unlock(&inode->i_lock);
685 nfs_clear_request_commit(req);
637 return req; 686 return req;
638out_flushme: 687out_flushme:
639 spin_unlock(&inode->i_lock); 688 spin_unlock(&inode->i_lock);
@@ -655,7 +704,6 @@ static struct nfs_page * nfs_setup_write_request(struct nfs_open_context* ctx,
655{ 704{
656 struct inode *inode = page->mapping->host; 705 struct inode *inode = page->mapping->host;
657 struct nfs_page *req; 706 struct nfs_page *req;
658 int error;
659 707
660 req = nfs_try_to_update_request(inode, page, offset, bytes); 708 req = nfs_try_to_update_request(inode, page, offset, bytes);
661 if (req != NULL) 709 if (req != NULL)
@@ -663,11 +711,7 @@ static struct nfs_page * nfs_setup_write_request(struct nfs_open_context* ctx,
663 req = nfs_create_request(ctx, inode, page, offset, bytes); 711 req = nfs_create_request(ctx, inode, page, offset, bytes);
664 if (IS_ERR(req)) 712 if (IS_ERR(req))
665 goto out; 713 goto out;
666 error = nfs_inode_add_request(inode, req); 714 nfs_inode_add_request(inode, req);
667 if (error != 0) {
668 nfs_release_request(req);
669 req = ERR_PTR(error);
670 }
671out: 715out:
672 return req; 716 return req;
673} 717}
@@ -684,7 +728,7 @@ static int nfs_writepage_setup(struct nfs_open_context *ctx, struct page *page,
684 nfs_grow_file(page, offset, count); 728 nfs_grow_file(page, offset, count);
685 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes); 729 nfs_mark_uptodate(page, req->wb_pgbase, req->wb_bytes);
686 nfs_mark_request_dirty(req); 730 nfs_mark_request_dirty(req);
687 nfs_clear_page_tag_locked(req); 731 nfs_unlock_request(req);
688 return 0; 732 return 0;
689} 733}
690 734
@@ -777,7 +821,7 @@ static void nfs_writepage_release(struct nfs_page *req,
777 821
778 if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req, data)) 822 if (PageError(req->wb_page) || !nfs_reschedule_unstable_write(req, data))
779 nfs_inode_remove_request(req); 823 nfs_inode_remove_request(req);
780 nfs_clear_page_tag_locked(req); 824 nfs_unlock_request(req);
781 nfs_end_page_writeback(page); 825 nfs_end_page_writeback(page);
782} 826}
783 827
@@ -925,7 +969,7 @@ static void nfs_redirty_request(struct nfs_page *req)
925 struct page *page = req->wb_page; 969 struct page *page = req->wb_page;
926 970
927 nfs_mark_request_dirty(req); 971 nfs_mark_request_dirty(req);
928 nfs_clear_page_tag_locked(req); 972 nfs_unlock_request(req);
929 nfs_end_page_writeback(page); 973 nfs_end_page_writeback(page);
930} 974}
931 975
@@ -1128,23 +1172,14 @@ out:
1128 nfs_writedata_release(calldata); 1172 nfs_writedata_release(calldata);
1129} 1173}
1130 1174
1131#if defined(CONFIG_NFS_V4_1)
1132void nfs_write_prepare(struct rpc_task *task, void *calldata) 1175void nfs_write_prepare(struct rpc_task *task, void *calldata)
1133{ 1176{
1134 struct nfs_write_data *data = calldata; 1177 struct nfs_write_data *data = calldata;
1135 1178 NFS_PROTO(data->inode)->write_rpc_prepare(task, data);
1136 if (nfs4_setup_sequence(NFS_SERVER(data->inode),
1137 &data->args.seq_args,
1138 &data->res.seq_res, 1, task))
1139 return;
1140 rpc_call_start(task);
1141} 1179}
1142#endif /* CONFIG_NFS_V4_1 */
1143 1180
1144static const struct rpc_call_ops nfs_write_partial_ops = { 1181static const struct rpc_call_ops nfs_write_partial_ops = {
1145#if defined(CONFIG_NFS_V4_1)
1146 .rpc_call_prepare = nfs_write_prepare, 1182 .rpc_call_prepare = nfs_write_prepare,
1147#endif /* CONFIG_NFS_V4_1 */
1148 .rpc_call_done = nfs_writeback_done_partial, 1183 .rpc_call_done = nfs_writeback_done_partial,
1149 .rpc_release = nfs_writeback_release_partial, 1184 .rpc_release = nfs_writeback_release_partial,
1150}; 1185};
@@ -1199,16 +1234,14 @@ static void nfs_writeback_release_full(void *calldata)
1199remove_request: 1234remove_request:
1200 nfs_inode_remove_request(req); 1235 nfs_inode_remove_request(req);
1201 next: 1236 next:
1202 nfs_clear_page_tag_locked(req); 1237 nfs_unlock_request(req);
1203 nfs_end_page_writeback(page); 1238 nfs_end_page_writeback(page);
1204 } 1239 }
1205 nfs_writedata_release(calldata); 1240 nfs_writedata_release(calldata);
1206} 1241}
1207 1242
1208static const struct rpc_call_ops nfs_write_full_ops = { 1243static const struct rpc_call_ops nfs_write_full_ops = {
1209#if defined(CONFIG_NFS_V4_1)
1210 .rpc_call_prepare = nfs_write_prepare, 1244 .rpc_call_prepare = nfs_write_prepare,
1211#endif /* CONFIG_NFS_V4_1 */
1212 .rpc_call_done = nfs_writeback_done_full, 1245 .rpc_call_done = nfs_writeback_done_full,
1213 .rpc_release = nfs_writeback_release_full, 1246 .rpc_release = nfs_writeback_release_full,
1214}; 1247};
@@ -1325,7 +1358,6 @@ void nfs_commitdata_release(void *data)
1325{ 1358{
1326 struct nfs_write_data *wdata = data; 1359 struct nfs_write_data *wdata = data;
1327 1360
1328 put_lseg(wdata->lseg);
1329 put_nfs_open_context(wdata->args.context); 1361 put_nfs_open_context(wdata->args.context);
1330 nfs_commit_free(wdata); 1362 nfs_commit_free(wdata);
1331} 1363}
@@ -1411,7 +1443,7 @@ void nfs_retry_commit(struct list_head *page_list,
1411 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS); 1443 dec_zone_page_state(req->wb_page, NR_UNSTABLE_NFS);
1412 dec_bdi_stat(req->wb_page->mapping->backing_dev_info, 1444 dec_bdi_stat(req->wb_page->mapping->backing_dev_info,
1413 BDI_RECLAIMABLE); 1445 BDI_RECLAIMABLE);
1414 nfs_clear_page_tag_locked(req); 1446 nfs_unlock_request(req);
1415 } 1447 }
1416} 1448}
1417EXPORT_SYMBOL_GPL(nfs_retry_commit); 1449EXPORT_SYMBOL_GPL(nfs_retry_commit);
@@ -1460,7 +1492,7 @@ void nfs_commit_release_pages(struct nfs_write_data *data)
1460 while (!list_empty(&data->pages)) { 1492 while (!list_empty(&data->pages)) {
1461 req = nfs_list_entry(data->pages.next); 1493 req = nfs_list_entry(data->pages.next);
1462 nfs_list_remove_request(req); 1494 nfs_list_remove_request(req);
1463 nfs_clear_request_commit(req); 1495 nfs_clear_page_commit(req->wb_page);
1464 1496
1465 dprintk("NFS: commit (%s/%lld %d@%lld)", 1497 dprintk("NFS: commit (%s/%lld %d@%lld)",
1466 req->wb_context->dentry->d_sb->s_id, 1498 req->wb_context->dentry->d_sb->s_id,
@@ -1486,7 +1518,7 @@ void nfs_commit_release_pages(struct nfs_write_data *data)
1486 dprintk(" mismatch\n"); 1518 dprintk(" mismatch\n");
1487 nfs_mark_request_dirty(req); 1519 nfs_mark_request_dirty(req);
1488 next: 1520 next:
1489 nfs_clear_page_tag_locked(req); 1521 nfs_unlock_request(req);
1490 } 1522 }
1491} 1523}
1492EXPORT_SYMBOL_GPL(nfs_commit_release_pages); 1524EXPORT_SYMBOL_GPL(nfs_commit_release_pages);
@@ -1501,9 +1533,7 @@ static void nfs_commit_release(void *calldata)
1501} 1533}
1502 1534
1503static const struct rpc_call_ops nfs_commit_ops = { 1535static const struct rpc_call_ops nfs_commit_ops = {
1504#if defined(CONFIG_NFS_V4_1)
1505 .rpc_call_prepare = nfs_write_prepare, 1536 .rpc_call_prepare = nfs_write_prepare,
1506#endif /* CONFIG_NFS_V4_1 */
1507 .rpc_call_done = nfs_commit_done, 1537 .rpc_call_done = nfs_commit_done,
1508 .rpc_release = nfs_commit_release, 1538 .rpc_release = nfs_commit_release,
1509}; 1539};
@@ -1517,7 +1547,7 @@ int nfs_commit_inode(struct inode *inode, int how)
1517 res = nfs_commit_set_lock(NFS_I(inode), may_wait); 1547 res = nfs_commit_set_lock(NFS_I(inode), may_wait);
1518 if (res <= 0) 1548 if (res <= 0)
1519 goto out_mark_dirty; 1549 goto out_mark_dirty;
1520 res = nfs_scan_commit(inode, &head, 0, 0); 1550 res = nfs_scan_commit(inode, &head);
1521 if (res) { 1551 if (res) {
1522 int error; 1552 int error;
1523 1553
@@ -1635,6 +1665,7 @@ int nfs_wb_page_cancel(struct inode *inode, struct page *page)
1635 if (req == NULL) 1665 if (req == NULL)
1636 break; 1666 break;
1637 if (nfs_lock_request_dontget(req)) { 1667 if (nfs_lock_request_dontget(req)) {
1668 nfs_clear_request_commit(req);
1638 nfs_inode_remove_request(req); 1669 nfs_inode_remove_request(req);
1639 /* 1670 /*
1640 * In case nfs_inode_remove_request has marked the 1671 * In case nfs_inode_remove_request has marked the