diff options
author | David S. Miller <davem@davemloft.net> | 2011-01-24 16:17:06 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-01-24 16:17:06 -0500 |
commit | e92427b289d252cfbd4cb5282d92f4ce1a5bb1fb (patch) | |
tree | 6d30e5e7b7f8e9aaa51d43b7128ac56860fa03bb /fs/nfs | |
parent | c506653d35249bb4738bb139c24362e1ae724bc1 (diff) | |
parent | ec30f343d61391ab23705e50a525da1d55395780 (diff) |
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'fs/nfs')
-rw-r--r-- | fs/nfs/callback.c | 83 | ||||
-rw-r--r-- | fs/nfs/callback.h | 59 | ||||
-rw-r--r-- | fs/nfs/callback_proc.c | 326 | ||||
-rw-r--r-- | fs/nfs/callback_xdr.c | 143 | ||||
-rw-r--r-- | fs/nfs/client.c | 302 | ||||
-rw-r--r-- | fs/nfs/delegation.c | 362 | ||||
-rw-r--r-- | fs/nfs/delegation.h | 1 | ||||
-rw-r--r-- | fs/nfs/dir.c | 92 | ||||
-rw-r--r-- | fs/nfs/getroot.c | 6 | ||||
-rw-r--r-- | fs/nfs/idmap.c | 2 | ||||
-rw-r--r-- | fs/nfs/inode.c | 7 | ||||
-rw-r--r-- | fs/nfs/internal.h | 20 | ||||
-rw-r--r-- | fs/nfs/mount_clnt.c | 83 | ||||
-rw-r--r-- | fs/nfs/namespace.c | 77 | ||||
-rw-r--r-- | fs/nfs/nfs2xdr.c | 1294 | ||||
-rw-r--r-- | fs/nfs/nfs3xdr.c | 2817 | ||||
-rw-r--r-- | fs/nfs/nfs4_fs.h | 13 | ||||
-rw-r--r-- | fs/nfs/nfs4filelayout.c | 6 | ||||
-rw-r--r-- | fs/nfs/nfs4proc.c | 188 | ||||
-rw-r--r-- | fs/nfs/nfs4renewd.c | 11 | ||||
-rw-r--r-- | fs/nfs/nfs4state.c | 293 | ||||
-rw-r--r-- | fs/nfs/nfs4xdr.c | 1426 | ||||
-rw-r--r-- | fs/nfs/pagelist.c | 7 | ||||
-rw-r--r-- | fs/nfs/pnfs.c | 524 | ||||
-rw-r--r-- | fs/nfs/pnfs.h | 76 | ||||
-rw-r--r-- | fs/nfs/proc.c | 5 | ||||
-rw-r--r-- | fs/nfs/super.c | 19 | ||||
-rw-r--r-- | fs/nfs/unlink.c | 2 |
28 files changed, 5441 insertions, 2803 deletions
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c index 93a8b3bd69e3..199016528fcb 100644 --- a/fs/nfs/callback.c +++ b/fs/nfs/callback.c | |||
@@ -16,9 +16,7 @@ | |||
16 | #include <linux/freezer.h> | 16 | #include <linux/freezer.h> |
17 | #include <linux/kthread.h> | 17 | #include <linux/kthread.h> |
18 | #include <linux/sunrpc/svcauth_gss.h> | 18 | #include <linux/sunrpc/svcauth_gss.h> |
19 | #if defined(CONFIG_NFS_V4_1) | ||
20 | #include <linux/sunrpc/bc_xprt.h> | 19 | #include <linux/sunrpc/bc_xprt.h> |
21 | #endif | ||
22 | 20 | ||
23 | #include <net/inet_sock.h> | 21 | #include <net/inet_sock.h> |
24 | 22 | ||
@@ -137,6 +135,33 @@ out_err: | |||
137 | 135 | ||
138 | #if defined(CONFIG_NFS_V4_1) | 136 | #if defined(CONFIG_NFS_V4_1) |
139 | /* | 137 | /* |
138 | * * CB_SEQUENCE operations will fail until the callback sessionid is set. | ||
139 | * */ | ||
140 | int nfs4_set_callback_sessionid(struct nfs_client *clp) | ||
141 | { | ||
142 | struct svc_serv *serv = clp->cl_rpcclient->cl_xprt->bc_serv; | ||
143 | struct nfs4_sessionid *bc_sid; | ||
144 | |||
145 | if (!serv->sv_bc_xprt) | ||
146 | return -EINVAL; | ||
147 | |||
148 | /* on success freed in xprt_free */ | ||
149 | bc_sid = kmalloc(sizeof(struct nfs4_sessionid), GFP_KERNEL); | ||
150 | if (!bc_sid) | ||
151 | return -ENOMEM; | ||
152 | memcpy(bc_sid->data, &clp->cl_session->sess_id.data, | ||
153 | NFS4_MAX_SESSIONID_LEN); | ||
154 | spin_lock_bh(&serv->sv_cb_lock); | ||
155 | serv->sv_bc_xprt->xpt_bc_sid = bc_sid; | ||
156 | spin_unlock_bh(&serv->sv_cb_lock); | ||
157 | dprintk("%s set xpt_bc_sid=%u:%u:%u:%u for sv_bc_xprt %p\n", __func__, | ||
158 | ((u32 *)bc_sid->data)[0], ((u32 *)bc_sid->data)[1], | ||
159 | ((u32 *)bc_sid->data)[2], ((u32 *)bc_sid->data)[3], | ||
160 | serv->sv_bc_xprt); | ||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | /* | ||
140 | * The callback service for NFSv4.1 callbacks | 165 | * The callback service for NFSv4.1 callbacks |
141 | */ | 166 | */ |
142 | static int | 167 | static int |
@@ -177,30 +202,38 @@ nfs41_callback_svc(void *vrqstp) | |||
177 | struct svc_rqst * | 202 | struct svc_rqst * |
178 | nfs41_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt) | 203 | nfs41_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt) |
179 | { | 204 | { |
180 | struct svc_xprt *bc_xprt; | 205 | struct svc_rqst *rqstp; |
181 | struct svc_rqst *rqstp = ERR_PTR(-ENOMEM); | 206 | int ret; |
182 | 207 | ||
183 | dprintk("--> %s\n", __func__); | 208 | /* |
184 | /* Create a svc_sock for the service */ | 209 | * Create an svc_sock for the back channel service that shares the |
185 | bc_xprt = svc_sock_create(serv, xprt->prot); | 210 | * fore channel connection. |
186 | if (!bc_xprt) | 211 | * Returns the input port (0) and sets the svc_serv bc_xprt on success |
212 | */ | ||
213 | ret = svc_create_xprt(serv, "tcp-bc", &init_net, PF_INET, 0, | ||
214 | SVC_SOCK_ANONYMOUS); | ||
215 | if (ret < 0) { | ||
216 | rqstp = ERR_PTR(ret); | ||
187 | goto out; | 217 | goto out; |
218 | } | ||
188 | 219 | ||
189 | /* | 220 | /* |
190 | * Save the svc_serv in the transport so that it can | 221 | * Save the svc_serv in the transport so that it can |
191 | * be referenced when the session backchannel is initialized | 222 | * be referenced when the session backchannel is initialized |
192 | */ | 223 | */ |
193 | serv->bc_xprt = bc_xprt; | ||
194 | xprt->bc_serv = serv; | 224 | xprt->bc_serv = serv; |
195 | 225 | ||
196 | INIT_LIST_HEAD(&serv->sv_cb_list); | 226 | INIT_LIST_HEAD(&serv->sv_cb_list); |
197 | spin_lock_init(&serv->sv_cb_lock); | 227 | spin_lock_init(&serv->sv_cb_lock); |
198 | init_waitqueue_head(&serv->sv_cb_waitq); | 228 | init_waitqueue_head(&serv->sv_cb_waitq); |
199 | rqstp = svc_prepare_thread(serv, &serv->sv_pools[0]); | 229 | rqstp = svc_prepare_thread(serv, &serv->sv_pools[0]); |
200 | if (IS_ERR(rqstp)) | 230 | if (IS_ERR(rqstp)) { |
201 | svc_sock_destroy(bc_xprt); | 231 | svc_xprt_put(serv->sv_bc_xprt); |
232 | serv->sv_bc_xprt = NULL; | ||
233 | } | ||
202 | out: | 234 | out: |
203 | dprintk("--> %s return %p\n", __func__, rqstp); | 235 | dprintk("--> %s return %ld\n", __func__, |
236 | IS_ERR(rqstp) ? PTR_ERR(rqstp) : 0); | ||
204 | return rqstp; | 237 | return rqstp; |
205 | } | 238 | } |
206 | 239 | ||
@@ -233,6 +266,10 @@ static inline void nfs_callback_bc_serv(u32 minorversion, struct rpc_xprt *xprt, | |||
233 | struct nfs_callback_data *cb_info) | 266 | struct nfs_callback_data *cb_info) |
234 | { | 267 | { |
235 | } | 268 | } |
269 | int nfs4_set_callback_sessionid(struct nfs_client *clp) | ||
270 | { | ||
271 | return 0; | ||
272 | } | ||
236 | #endif /* CONFIG_NFS_V4_1 */ | 273 | #endif /* CONFIG_NFS_V4_1 */ |
237 | 274 | ||
238 | /* | 275 | /* |
@@ -328,6 +365,9 @@ static int check_gss_callback_principal(struct nfs_client *clp, | |||
328 | struct rpc_clnt *r = clp->cl_rpcclient; | 365 | struct rpc_clnt *r = clp->cl_rpcclient; |
329 | char *p = svc_gss_principal(rqstp); | 366 | char *p = svc_gss_principal(rqstp); |
330 | 367 | ||
368 | /* No RPC_AUTH_GSS on NFSv4.1 back channel yet */ | ||
369 | if (clp->cl_minorversion != 0) | ||
370 | return SVC_DROP; | ||
331 | /* | 371 | /* |
332 | * It might just be a normal user principal, in which case | 372 | * It might just be a normal user principal, in which case |
333 | * userspace won't bother to tell us the name at all. | 373 | * userspace won't bother to tell us the name at all. |
@@ -345,6 +385,23 @@ static int check_gss_callback_principal(struct nfs_client *clp, | |||
345 | return SVC_OK; | 385 | return SVC_OK; |
346 | } | 386 | } |
347 | 387 | ||
388 | /* pg_authenticate method helper */ | ||
389 | static struct nfs_client *nfs_cb_find_client(struct svc_rqst *rqstp) | ||
390 | { | ||
391 | struct nfs4_sessionid *sessionid = bc_xprt_sid(rqstp); | ||
392 | int is_cb_compound = rqstp->rq_proc == CB_COMPOUND ? 1 : 0; | ||
393 | |||
394 | dprintk("--> %s rq_proc %d\n", __func__, rqstp->rq_proc); | ||
395 | if (svc_is_backchannel(rqstp)) | ||
396 | /* Sessionid (usually) set after CB_NULL ping */ | ||
397 | return nfs4_find_client_sessionid(svc_addr(rqstp), sessionid, | ||
398 | is_cb_compound); | ||
399 | else | ||
400 | /* No callback identifier in pg_authenticate */ | ||
401 | return nfs4_find_client_no_ident(svc_addr(rqstp)); | ||
402 | } | ||
403 | |||
404 | /* pg_authenticate method for nfsv4 callback threads. */ | ||
348 | static int nfs_callback_authenticate(struct svc_rqst *rqstp) | 405 | static int nfs_callback_authenticate(struct svc_rqst *rqstp) |
349 | { | 406 | { |
350 | struct nfs_client *clp; | 407 | struct nfs_client *clp; |
@@ -352,7 +409,7 @@ static int nfs_callback_authenticate(struct svc_rqst *rqstp) | |||
352 | int ret = SVC_OK; | 409 | int ret = SVC_OK; |
353 | 410 | ||
354 | /* Don't talk to strangers */ | 411 | /* Don't talk to strangers */ |
355 | clp = nfs_find_client(svc_addr(rqstp), 4); | 412 | clp = nfs_cb_find_client(rqstp); |
356 | if (clp == NULL) | 413 | if (clp == NULL) |
357 | return SVC_DROP; | 414 | return SVC_DROP; |
358 | 415 | ||
diff --git a/fs/nfs/callback.h b/fs/nfs/callback.h index 85a7cfd1b8dd..d3b44f9bd747 100644 --- a/fs/nfs/callback.h +++ b/fs/nfs/callback.h | |||
@@ -34,10 +34,17 @@ enum nfs4_callback_opnum { | |||
34 | OP_CB_ILLEGAL = 10044, | 34 | OP_CB_ILLEGAL = 10044, |
35 | }; | 35 | }; |
36 | 36 | ||
37 | struct cb_process_state { | ||
38 | __be32 drc_status; | ||
39 | struct nfs_client *clp; | ||
40 | struct nfs4_sessionid *svc_sid; /* v4.1 callback service sessionid */ | ||
41 | }; | ||
42 | |||
37 | struct cb_compound_hdr_arg { | 43 | struct cb_compound_hdr_arg { |
38 | unsigned int taglen; | 44 | unsigned int taglen; |
39 | const char *tag; | 45 | const char *tag; |
40 | unsigned int minorversion; | 46 | unsigned int minorversion; |
47 | unsigned int cb_ident; /* v4.0 callback identifier */ | ||
41 | unsigned nops; | 48 | unsigned nops; |
42 | }; | 49 | }; |
43 | 50 | ||
@@ -103,14 +110,23 @@ struct cb_sequenceres { | |||
103 | uint32_t csr_target_highestslotid; | 110 | uint32_t csr_target_highestslotid; |
104 | }; | 111 | }; |
105 | 112 | ||
106 | extern unsigned nfs4_callback_sequence(struct cb_sequenceargs *args, | 113 | extern __be32 nfs4_callback_sequence(struct cb_sequenceargs *args, |
107 | struct cb_sequenceres *res); | 114 | struct cb_sequenceres *res, |
115 | struct cb_process_state *cps); | ||
108 | 116 | ||
109 | extern int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, | 117 | extern int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, |
110 | const nfs4_stateid *stateid); | 118 | const nfs4_stateid *stateid); |
111 | 119 | ||
112 | #define RCA4_TYPE_MASK_RDATA_DLG 0 | 120 | #define RCA4_TYPE_MASK_RDATA_DLG 0 |
113 | #define RCA4_TYPE_MASK_WDATA_DLG 1 | 121 | #define RCA4_TYPE_MASK_WDATA_DLG 1 |
122 | #define RCA4_TYPE_MASK_DIR_DLG 2 | ||
123 | #define RCA4_TYPE_MASK_FILE_LAYOUT 3 | ||
124 | #define RCA4_TYPE_MASK_BLK_LAYOUT 4 | ||
125 | #define RCA4_TYPE_MASK_OBJ_LAYOUT_MIN 8 | ||
126 | #define RCA4_TYPE_MASK_OBJ_LAYOUT_MAX 9 | ||
127 | #define RCA4_TYPE_MASK_OTHER_LAYOUT_MIN 12 | ||
128 | #define RCA4_TYPE_MASK_OTHER_LAYOUT_MAX 15 | ||
129 | #define RCA4_TYPE_MASK_ALL 0xf31f | ||
114 | 130 | ||
115 | struct cb_recallanyargs { | 131 | struct cb_recallanyargs { |
116 | struct sockaddr *craa_addr; | 132 | struct sockaddr *craa_addr; |
@@ -118,25 +134,52 @@ struct cb_recallanyargs { | |||
118 | uint32_t craa_type_mask; | 134 | uint32_t craa_type_mask; |
119 | }; | 135 | }; |
120 | 136 | ||
121 | extern unsigned nfs4_callback_recallany(struct cb_recallanyargs *args, void *dummy); | 137 | extern __be32 nfs4_callback_recallany(struct cb_recallanyargs *args, |
138 | void *dummy, | ||
139 | struct cb_process_state *cps); | ||
122 | 140 | ||
123 | struct cb_recallslotargs { | 141 | struct cb_recallslotargs { |
124 | struct sockaddr *crsa_addr; | 142 | struct sockaddr *crsa_addr; |
125 | uint32_t crsa_target_max_slots; | 143 | uint32_t crsa_target_max_slots; |
126 | }; | 144 | }; |
127 | extern unsigned nfs4_callback_recallslot(struct cb_recallslotargs *args, | 145 | extern __be32 nfs4_callback_recallslot(struct cb_recallslotargs *args, |
128 | void *dummy); | 146 | void *dummy, |
147 | struct cb_process_state *cps); | ||
148 | |||
149 | struct cb_layoutrecallargs { | ||
150 | struct sockaddr *cbl_addr; | ||
151 | uint32_t cbl_recall_type; | ||
152 | uint32_t cbl_layout_type; | ||
153 | uint32_t cbl_layoutchanged; | ||
154 | union { | ||
155 | struct { | ||
156 | struct nfs_fh cbl_fh; | ||
157 | struct pnfs_layout_range cbl_range; | ||
158 | nfs4_stateid cbl_stateid; | ||
159 | }; | ||
160 | struct nfs_fsid cbl_fsid; | ||
161 | }; | ||
162 | }; | ||
129 | 163 | ||
130 | #endif /* CONFIG_NFS_V4_1 */ | 164 | extern unsigned nfs4_callback_layoutrecall( |
165 | struct cb_layoutrecallargs *args, | ||
166 | void *dummy, struct cb_process_state *cps); | ||
131 | 167 | ||
132 | extern __be32 nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres *res); | 168 | extern void nfs4_check_drain_bc_complete(struct nfs4_session *ses); |
133 | extern __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy); | 169 | extern void nfs4_cb_take_slot(struct nfs_client *clp); |
170 | #endif /* CONFIG_NFS_V4_1 */ | ||
134 | 171 | ||
172 | extern __be32 nfs4_callback_getattr(struct cb_getattrargs *args, | ||
173 | struct cb_getattrres *res, | ||
174 | struct cb_process_state *cps); | ||
175 | extern __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy, | ||
176 | struct cb_process_state *cps); | ||
135 | #ifdef CONFIG_NFS_V4 | 177 | #ifdef CONFIG_NFS_V4 |
136 | extern int nfs_callback_up(u32 minorversion, struct rpc_xprt *xprt); | 178 | extern int nfs_callback_up(u32 minorversion, struct rpc_xprt *xprt); |
137 | extern void nfs_callback_down(int minorversion); | 179 | extern void nfs_callback_down(int minorversion); |
138 | extern int nfs4_validate_delegation_stateid(struct nfs_delegation *delegation, | 180 | extern int nfs4_validate_delegation_stateid(struct nfs_delegation *delegation, |
139 | const nfs4_stateid *stateid); | 181 | const nfs4_stateid *stateid); |
182 | extern int nfs4_set_callback_sessionid(struct nfs_client *clp); | ||
140 | #endif /* CONFIG_NFS_V4 */ | 183 | #endif /* CONFIG_NFS_V4 */ |
141 | /* | 184 | /* |
142 | * nfs41: Callbacks are expected to not cause substantial latency, | 185 | * nfs41: Callbacks are expected to not cause substantial latency, |
diff --git a/fs/nfs/callback_proc.c b/fs/nfs/callback_proc.c index 2950fca0c61b..4bb91cb2620d 100644 --- a/fs/nfs/callback_proc.c +++ b/fs/nfs/callback_proc.c | |||
@@ -12,30 +12,33 @@ | |||
12 | #include "callback.h" | 12 | #include "callback.h" |
13 | #include "delegation.h" | 13 | #include "delegation.h" |
14 | #include "internal.h" | 14 | #include "internal.h" |
15 | #include "pnfs.h" | ||
15 | 16 | ||
16 | #ifdef NFS_DEBUG | 17 | #ifdef NFS_DEBUG |
17 | #define NFSDBG_FACILITY NFSDBG_CALLBACK | 18 | #define NFSDBG_FACILITY NFSDBG_CALLBACK |
18 | #endif | 19 | #endif |
19 | 20 | ||
20 | __be32 nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres *res) | 21 | __be32 nfs4_callback_getattr(struct cb_getattrargs *args, |
22 | struct cb_getattrres *res, | ||
23 | struct cb_process_state *cps) | ||
21 | { | 24 | { |
22 | struct nfs_client *clp; | ||
23 | struct nfs_delegation *delegation; | 25 | struct nfs_delegation *delegation; |
24 | struct nfs_inode *nfsi; | 26 | struct nfs_inode *nfsi; |
25 | struct inode *inode; | 27 | struct inode *inode; |
26 | 28 | ||
29 | res->status = htonl(NFS4ERR_OP_NOT_IN_SESSION); | ||
30 | if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */ | ||
31 | goto out; | ||
32 | |||
27 | res->bitmap[0] = res->bitmap[1] = 0; | 33 | res->bitmap[0] = res->bitmap[1] = 0; |
28 | res->status = htonl(NFS4ERR_BADHANDLE); | 34 | res->status = htonl(NFS4ERR_BADHANDLE); |
29 | clp = nfs_find_client(args->addr, 4); | ||
30 | if (clp == NULL) | ||
31 | goto out; | ||
32 | 35 | ||
33 | dprintk("NFS: GETATTR callback request from %s\n", | 36 | dprintk("NFS: GETATTR callback request from %s\n", |
34 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)); | 37 | rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR)); |
35 | 38 | ||
36 | inode = nfs_delegation_find_inode(clp, &args->fh); | 39 | inode = nfs_delegation_find_inode(cps->clp, &args->fh); |
37 | if (inode == NULL) | 40 | if (inode == NULL) |
38 | goto out_putclient; | 41 | goto out; |
39 | nfsi = NFS_I(inode); | 42 | nfsi = NFS_I(inode); |
40 | rcu_read_lock(); | 43 | rcu_read_lock(); |
41 | delegation = rcu_dereference(nfsi->delegation); | 44 | delegation = rcu_dereference(nfsi->delegation); |
@@ -55,49 +58,41 @@ __be32 nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres * | |||
55 | out_iput: | 58 | out_iput: |
56 | rcu_read_unlock(); | 59 | rcu_read_unlock(); |
57 | iput(inode); | 60 | iput(inode); |
58 | out_putclient: | ||
59 | nfs_put_client(clp); | ||
60 | out: | 61 | out: |
61 | dprintk("%s: exit with status = %d\n", __func__, ntohl(res->status)); | 62 | dprintk("%s: exit with status = %d\n", __func__, ntohl(res->status)); |
62 | return res->status; | 63 | return res->status; |
63 | } | 64 | } |
64 | 65 | ||
65 | __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy) | 66 | __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy, |
67 | struct cb_process_state *cps) | ||
66 | { | 68 | { |
67 | struct nfs_client *clp; | ||
68 | struct inode *inode; | 69 | struct inode *inode; |
69 | __be32 res; | 70 | __be32 res; |
70 | 71 | ||
71 | res = htonl(NFS4ERR_BADHANDLE); | 72 | res = htonl(NFS4ERR_OP_NOT_IN_SESSION); |
72 | clp = nfs_find_client(args->addr, 4); | 73 | if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */ |
73 | if (clp == NULL) | ||
74 | goto out; | 74 | goto out; |
75 | 75 | ||
76 | dprintk("NFS: RECALL callback request from %s\n", | 76 | dprintk("NFS: RECALL callback request from %s\n", |
77 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)); | 77 | rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR)); |
78 | 78 | ||
79 | do { | 79 | res = htonl(NFS4ERR_BADHANDLE); |
80 | struct nfs_client *prev = clp; | 80 | inode = nfs_delegation_find_inode(cps->clp, &args->fh); |
81 | 81 | if (inode == NULL) | |
82 | inode = nfs_delegation_find_inode(clp, &args->fh); | 82 | goto out; |
83 | if (inode != NULL) { | 83 | /* Set up a helper thread to actually return the delegation */ |
84 | /* Set up a helper thread to actually return the delegation */ | 84 | switch (nfs_async_inode_return_delegation(inode, &args->stateid)) { |
85 | switch (nfs_async_inode_return_delegation(inode, &args->stateid)) { | 85 | case 0: |
86 | case 0: | 86 | res = 0; |
87 | res = 0; | 87 | break; |
88 | break; | 88 | case -ENOENT: |
89 | case -ENOENT: | 89 | if (res != 0) |
90 | if (res != 0) | 90 | res = htonl(NFS4ERR_BAD_STATEID); |
91 | res = htonl(NFS4ERR_BAD_STATEID); | 91 | break; |
92 | break; | 92 | default: |
93 | default: | 93 | res = htonl(NFS4ERR_RESOURCE); |
94 | res = htonl(NFS4ERR_RESOURCE); | 94 | } |
95 | } | 95 | iput(inode); |
96 | iput(inode); | ||
97 | } | ||
98 | clp = nfs_find_client_next(prev); | ||
99 | nfs_put_client(prev); | ||
100 | } while (clp != NULL); | ||
101 | out: | 96 | out: |
102 | dprintk("%s: exit with status = %d\n", __func__, ntohl(res)); | 97 | dprintk("%s: exit with status = %d\n", __func__, ntohl(res)); |
103 | return res; | 98 | return res; |
@@ -113,6 +108,139 @@ int nfs4_validate_delegation_stateid(struct nfs_delegation *delegation, const nf | |||
113 | 108 | ||
114 | #if defined(CONFIG_NFS_V4_1) | 109 | #if defined(CONFIG_NFS_V4_1) |
115 | 110 | ||
111 | static u32 initiate_file_draining(struct nfs_client *clp, | ||
112 | struct cb_layoutrecallargs *args) | ||
113 | { | ||
114 | struct pnfs_layout_hdr *lo; | ||
115 | struct inode *ino; | ||
116 | bool found = false; | ||
117 | u32 rv = NFS4ERR_NOMATCHING_LAYOUT; | ||
118 | LIST_HEAD(free_me_list); | ||
119 | |||
120 | spin_lock(&clp->cl_lock); | ||
121 | list_for_each_entry(lo, &clp->cl_layouts, plh_layouts) { | ||
122 | if (nfs_compare_fh(&args->cbl_fh, | ||
123 | &NFS_I(lo->plh_inode)->fh)) | ||
124 | continue; | ||
125 | ino = igrab(lo->plh_inode); | ||
126 | if (!ino) | ||
127 | continue; | ||
128 | found = true; | ||
129 | /* Without this, layout can be freed as soon | ||
130 | * as we release cl_lock. | ||
131 | */ | ||
132 | get_layout_hdr(lo); | ||
133 | break; | ||
134 | } | ||
135 | spin_unlock(&clp->cl_lock); | ||
136 | if (!found) | ||
137 | return NFS4ERR_NOMATCHING_LAYOUT; | ||
138 | |||
139 | spin_lock(&ino->i_lock); | ||
140 | if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) || | ||
141 | mark_matching_lsegs_invalid(lo, &free_me_list, | ||
142 | args->cbl_range.iomode)) | ||
143 | rv = NFS4ERR_DELAY; | ||
144 | else | ||
145 | rv = NFS4ERR_NOMATCHING_LAYOUT; | ||
146 | pnfs_set_layout_stateid(lo, &args->cbl_stateid, true); | ||
147 | spin_unlock(&ino->i_lock); | ||
148 | pnfs_free_lseg_list(&free_me_list); | ||
149 | put_layout_hdr(lo); | ||
150 | iput(ino); | ||
151 | return rv; | ||
152 | } | ||
153 | |||
154 | static u32 initiate_bulk_draining(struct nfs_client *clp, | ||
155 | struct cb_layoutrecallargs *args) | ||
156 | { | ||
157 | struct pnfs_layout_hdr *lo; | ||
158 | struct inode *ino; | ||
159 | u32 rv = NFS4ERR_NOMATCHING_LAYOUT; | ||
160 | struct pnfs_layout_hdr *tmp; | ||
161 | LIST_HEAD(recall_list); | ||
162 | LIST_HEAD(free_me_list); | ||
163 | struct pnfs_layout_range range = { | ||
164 | .iomode = IOMODE_ANY, | ||
165 | .offset = 0, | ||
166 | .length = NFS4_MAX_UINT64, | ||
167 | }; | ||
168 | |||
169 | spin_lock(&clp->cl_lock); | ||
170 | list_for_each_entry(lo, &clp->cl_layouts, plh_layouts) { | ||
171 | if ((args->cbl_recall_type == RETURN_FSID) && | ||
172 | memcmp(&NFS_SERVER(lo->plh_inode)->fsid, | ||
173 | &args->cbl_fsid, sizeof(struct nfs_fsid))) | ||
174 | continue; | ||
175 | if (!igrab(lo->plh_inode)) | ||
176 | continue; | ||
177 | get_layout_hdr(lo); | ||
178 | BUG_ON(!list_empty(&lo->plh_bulk_recall)); | ||
179 | list_add(&lo->plh_bulk_recall, &recall_list); | ||
180 | } | ||
181 | spin_unlock(&clp->cl_lock); | ||
182 | list_for_each_entry_safe(lo, tmp, | ||
183 | &recall_list, plh_bulk_recall) { | ||
184 | ino = lo->plh_inode; | ||
185 | spin_lock(&ino->i_lock); | ||
186 | set_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags); | ||
187 | if (mark_matching_lsegs_invalid(lo, &free_me_list, range.iomode)) | ||
188 | rv = NFS4ERR_DELAY; | ||
189 | list_del_init(&lo->plh_bulk_recall); | ||
190 | spin_unlock(&ino->i_lock); | ||
191 | put_layout_hdr(lo); | ||
192 | iput(ino); | ||
193 | } | ||
194 | pnfs_free_lseg_list(&free_me_list); | ||
195 | return rv; | ||
196 | } | ||
197 | |||
198 | static u32 do_callback_layoutrecall(struct nfs_client *clp, | ||
199 | struct cb_layoutrecallargs *args) | ||
200 | { | ||
201 | u32 res = NFS4ERR_DELAY; | ||
202 | |||
203 | dprintk("%s enter, type=%i\n", __func__, args->cbl_recall_type); | ||
204 | if (test_and_set_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state)) | ||
205 | goto out; | ||
206 | if (args->cbl_recall_type == RETURN_FILE) | ||
207 | res = initiate_file_draining(clp, args); | ||
208 | else | ||
209 | res = initiate_bulk_draining(clp, args); | ||
210 | clear_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state); | ||
211 | out: | ||
212 | dprintk("%s returning %i\n", __func__, res); | ||
213 | return res; | ||
214 | |||
215 | } | ||
216 | |||
217 | __be32 nfs4_callback_layoutrecall(struct cb_layoutrecallargs *args, | ||
218 | void *dummy, struct cb_process_state *cps) | ||
219 | { | ||
220 | u32 res; | ||
221 | |||
222 | dprintk("%s: -->\n", __func__); | ||
223 | |||
224 | if (cps->clp) | ||
225 | res = do_callback_layoutrecall(cps->clp, args); | ||
226 | else | ||
227 | res = NFS4ERR_OP_NOT_IN_SESSION; | ||
228 | |||
229 | dprintk("%s: exit with status = %d\n", __func__, res); | ||
230 | return cpu_to_be32(res); | ||
231 | } | ||
232 | |||
233 | static void pnfs_recall_all_layouts(struct nfs_client *clp) | ||
234 | { | ||
235 | struct cb_layoutrecallargs args; | ||
236 | |||
237 | /* Pretend we got a CB_LAYOUTRECALL(ALL) */ | ||
238 | memset(&args, 0, sizeof(args)); | ||
239 | args.cbl_recall_type = RETURN_ALL; | ||
240 | /* FIXME we ignore errors, what should we do? */ | ||
241 | do_callback_layoutrecall(clp, &args); | ||
242 | } | ||
243 | |||
116 | int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid) | 244 | int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid) |
117 | { | 245 | { |
118 | if (delegation == NULL) | 246 | if (delegation == NULL) |
@@ -185,42 +313,6 @@ validate_seqid(struct nfs4_slot_table *tbl, struct cb_sequenceargs * args) | |||
185 | } | 313 | } |
186 | 314 | ||
187 | /* | 315 | /* |
188 | * Returns a pointer to a held 'struct nfs_client' that matches the server's | ||
189 | * address, major version number, and session ID. It is the caller's | ||
190 | * responsibility to release the returned reference. | ||
191 | * | ||
192 | * Returns NULL if there are no connections with sessions, or if no session | ||
193 | * matches the one of interest. | ||
194 | */ | ||
195 | static struct nfs_client *find_client_with_session( | ||
196 | const struct sockaddr *addr, u32 nfsversion, | ||
197 | struct nfs4_sessionid *sessionid) | ||
198 | { | ||
199 | struct nfs_client *clp; | ||
200 | |||
201 | clp = nfs_find_client(addr, 4); | ||
202 | if (clp == NULL) | ||
203 | return NULL; | ||
204 | |||
205 | do { | ||
206 | struct nfs_client *prev = clp; | ||
207 | |||
208 | if (clp->cl_session != NULL) { | ||
209 | if (memcmp(clp->cl_session->sess_id.data, | ||
210 | sessionid->data, | ||
211 | NFS4_MAX_SESSIONID_LEN) == 0) { | ||
212 | /* Returns a held reference to clp */ | ||
213 | return clp; | ||
214 | } | ||
215 | } | ||
216 | clp = nfs_find_client_next(prev); | ||
217 | nfs_put_client(prev); | ||
218 | } while (clp != NULL); | ||
219 | |||
220 | return NULL; | ||
221 | } | ||
222 | |||
223 | /* | ||
224 | * For each referring call triple, check the session's slot table for | 316 | * For each referring call triple, check the session's slot table for |
225 | * a match. If the slot is in use and the sequence numbers match, the | 317 | * a match. If the slot is in use and the sequence numbers match, the |
226 | * client is still waiting for a response to the original request. | 318 | * client is still waiting for a response to the original request. |
@@ -276,20 +368,34 @@ out: | |||
276 | } | 368 | } |
277 | 369 | ||
278 | __be32 nfs4_callback_sequence(struct cb_sequenceargs *args, | 370 | __be32 nfs4_callback_sequence(struct cb_sequenceargs *args, |
279 | struct cb_sequenceres *res) | 371 | struct cb_sequenceres *res, |
372 | struct cb_process_state *cps) | ||
280 | { | 373 | { |
281 | struct nfs_client *clp; | 374 | struct nfs_client *clp; |
282 | int i; | 375 | int i; |
283 | __be32 status; | 376 | __be32 status; |
284 | 377 | ||
378 | cps->clp = NULL; | ||
379 | |||
285 | status = htonl(NFS4ERR_BADSESSION); | 380 | status = htonl(NFS4ERR_BADSESSION); |
286 | clp = find_client_with_session(args->csa_addr, 4, &args->csa_sessionid); | 381 | /* Incoming session must match the callback session */ |
382 | if (memcmp(&args->csa_sessionid, cps->svc_sid, NFS4_MAX_SESSIONID_LEN)) | ||
383 | goto out; | ||
384 | |||
385 | clp = nfs4_find_client_sessionid(args->csa_addr, | ||
386 | &args->csa_sessionid, 1); | ||
287 | if (clp == NULL) | 387 | if (clp == NULL) |
288 | goto out; | 388 | goto out; |
289 | 389 | ||
390 | /* state manager is resetting the session */ | ||
391 | if (test_bit(NFS4_SESSION_DRAINING, &clp->cl_session->session_state)) { | ||
392 | status = NFS4ERR_DELAY; | ||
393 | goto out; | ||
394 | } | ||
395 | |||
290 | status = validate_seqid(&clp->cl_session->bc_slot_table, args); | 396 | status = validate_seqid(&clp->cl_session->bc_slot_table, args); |
291 | if (status) | 397 | if (status) |
292 | goto out_putclient; | 398 | goto out; |
293 | 399 | ||
294 | /* | 400 | /* |
295 | * Check for pending referring calls. If a match is found, a | 401 | * Check for pending referring calls. If a match is found, a |
@@ -298,7 +404,7 @@ __be32 nfs4_callback_sequence(struct cb_sequenceargs *args, | |||
298 | */ | 404 | */ |
299 | if (referring_call_exists(clp, args->csa_nrclists, args->csa_rclists)) { | 405 | if (referring_call_exists(clp, args->csa_nrclists, args->csa_rclists)) { |
300 | status = htonl(NFS4ERR_DELAY); | 406 | status = htonl(NFS4ERR_DELAY); |
301 | goto out_putclient; | 407 | goto out; |
302 | } | 408 | } |
303 | 409 | ||
304 | memcpy(&res->csr_sessionid, &args->csa_sessionid, | 410 | memcpy(&res->csr_sessionid, &args->csa_sessionid, |
@@ -307,83 +413,93 @@ __be32 nfs4_callback_sequence(struct cb_sequenceargs *args, | |||
307 | res->csr_slotid = args->csa_slotid; | 413 | res->csr_slotid = args->csa_slotid; |
308 | res->csr_highestslotid = NFS41_BC_MAX_CALLBACKS - 1; | 414 | res->csr_highestslotid = NFS41_BC_MAX_CALLBACKS - 1; |
309 | res->csr_target_highestslotid = NFS41_BC_MAX_CALLBACKS - 1; | 415 | res->csr_target_highestslotid = NFS41_BC_MAX_CALLBACKS - 1; |
416 | nfs4_cb_take_slot(clp); | ||
417 | cps->clp = clp; /* put in nfs4_callback_compound */ | ||
310 | 418 | ||
311 | out_putclient: | ||
312 | nfs_put_client(clp); | ||
313 | out: | 419 | out: |
314 | for (i = 0; i < args->csa_nrclists; i++) | 420 | for (i = 0; i < args->csa_nrclists; i++) |
315 | kfree(args->csa_rclists[i].rcl_refcalls); | 421 | kfree(args->csa_rclists[i].rcl_refcalls); |
316 | kfree(args->csa_rclists); | 422 | kfree(args->csa_rclists); |
317 | 423 | ||
318 | if (status == htonl(NFS4ERR_RETRY_UNCACHED_REP)) | 424 | if (status == htonl(NFS4ERR_RETRY_UNCACHED_REP)) { |
319 | res->csr_status = 0; | 425 | cps->drc_status = status; |
320 | else | 426 | status = 0; |
427 | } else | ||
321 | res->csr_status = status; | 428 | res->csr_status = status; |
429 | |||
322 | dprintk("%s: exit with status = %d res->csr_status %d\n", __func__, | 430 | dprintk("%s: exit with status = %d res->csr_status %d\n", __func__, |
323 | ntohl(status), ntohl(res->csr_status)); | 431 | ntohl(status), ntohl(res->csr_status)); |
324 | return status; | 432 | return status; |
325 | } | 433 | } |
326 | 434 | ||
327 | __be32 nfs4_callback_recallany(struct cb_recallanyargs *args, void *dummy) | 435 | static bool |
436 | validate_bitmap_values(unsigned long mask) | ||
437 | { | ||
438 | return (mask & ~RCA4_TYPE_MASK_ALL) == 0; | ||
439 | } | ||
440 | |||
441 | __be32 nfs4_callback_recallany(struct cb_recallanyargs *args, void *dummy, | ||
442 | struct cb_process_state *cps) | ||
328 | { | 443 | { |
329 | struct nfs_client *clp; | ||
330 | __be32 status; | 444 | __be32 status; |
331 | fmode_t flags = 0; | 445 | fmode_t flags = 0; |
332 | 446 | ||
333 | status = htonl(NFS4ERR_OP_NOT_IN_SESSION); | 447 | status = cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION); |
334 | clp = nfs_find_client(args->craa_addr, 4); | 448 | if (!cps->clp) /* set in cb_sequence */ |
335 | if (clp == NULL) | ||
336 | goto out; | 449 | goto out; |
337 | 450 | ||
338 | dprintk("NFS: RECALL_ANY callback request from %s\n", | 451 | dprintk("NFS: RECALL_ANY callback request from %s\n", |
339 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR)); | 452 | rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR)); |
453 | |||
454 | status = cpu_to_be32(NFS4ERR_INVAL); | ||
455 | if (!validate_bitmap_values(args->craa_type_mask)) | ||
456 | goto out; | ||
340 | 457 | ||
458 | status = cpu_to_be32(NFS4_OK); | ||
341 | if (test_bit(RCA4_TYPE_MASK_RDATA_DLG, (const unsigned long *) | 459 | if (test_bit(RCA4_TYPE_MASK_RDATA_DLG, (const unsigned long *) |
342 | &args->craa_type_mask)) | 460 | &args->craa_type_mask)) |
343 | flags = FMODE_READ; | 461 | flags = FMODE_READ; |
344 | if (test_bit(RCA4_TYPE_MASK_WDATA_DLG, (const unsigned long *) | 462 | if (test_bit(RCA4_TYPE_MASK_WDATA_DLG, (const unsigned long *) |
345 | &args->craa_type_mask)) | 463 | &args->craa_type_mask)) |
346 | flags |= FMODE_WRITE; | 464 | flags |= FMODE_WRITE; |
347 | 465 | if (test_bit(RCA4_TYPE_MASK_FILE_LAYOUT, (const unsigned long *) | |
466 | &args->craa_type_mask)) | ||
467 | pnfs_recall_all_layouts(cps->clp); | ||
348 | if (flags) | 468 | if (flags) |
349 | nfs_expire_all_delegation_types(clp, flags); | 469 | nfs_expire_all_delegation_types(cps->clp, flags); |
350 | status = htonl(NFS4_OK); | ||
351 | out: | 470 | out: |
352 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); | 471 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); |
353 | return status; | 472 | return status; |
354 | } | 473 | } |
355 | 474 | ||
356 | /* Reduce the fore channel's max_slots to the target value */ | 475 | /* Reduce the fore channel's max_slots to the target value */ |
357 | __be32 nfs4_callback_recallslot(struct cb_recallslotargs *args, void *dummy) | 476 | __be32 nfs4_callback_recallslot(struct cb_recallslotargs *args, void *dummy, |
477 | struct cb_process_state *cps) | ||
358 | { | 478 | { |
359 | struct nfs_client *clp; | ||
360 | struct nfs4_slot_table *fc_tbl; | 479 | struct nfs4_slot_table *fc_tbl; |
361 | __be32 status; | 480 | __be32 status; |
362 | 481 | ||
363 | status = htonl(NFS4ERR_OP_NOT_IN_SESSION); | 482 | status = htonl(NFS4ERR_OP_NOT_IN_SESSION); |
364 | clp = nfs_find_client(args->crsa_addr, 4); | 483 | if (!cps->clp) /* set in cb_sequence */ |
365 | if (clp == NULL) | ||
366 | goto out; | 484 | goto out; |
367 | 485 | ||
368 | dprintk("NFS: CB_RECALL_SLOT request from %s target max slots %d\n", | 486 | dprintk("NFS: CB_RECALL_SLOT request from %s target max slots %d\n", |
369 | rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR), | 487 | rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR), |
370 | args->crsa_target_max_slots); | 488 | args->crsa_target_max_slots); |
371 | 489 | ||
372 | fc_tbl = &clp->cl_session->fc_slot_table; | 490 | fc_tbl = &cps->clp->cl_session->fc_slot_table; |
373 | 491 | ||
374 | status = htonl(NFS4ERR_BAD_HIGH_SLOT); | 492 | status = htonl(NFS4ERR_BAD_HIGH_SLOT); |
375 | if (args->crsa_target_max_slots > fc_tbl->max_slots || | 493 | if (args->crsa_target_max_slots > fc_tbl->max_slots || |
376 | args->crsa_target_max_slots < 1) | 494 | args->crsa_target_max_slots < 1) |
377 | goto out_putclient; | 495 | goto out; |
378 | 496 | ||
379 | status = htonl(NFS4_OK); | 497 | status = htonl(NFS4_OK); |
380 | if (args->crsa_target_max_slots == fc_tbl->max_slots) | 498 | if (args->crsa_target_max_slots == fc_tbl->max_slots) |
381 | goto out_putclient; | 499 | goto out; |
382 | 500 | ||
383 | fc_tbl->target_max_slots = args->crsa_target_max_slots; | 501 | fc_tbl->target_max_slots = args->crsa_target_max_slots; |
384 | nfs41_handle_recall_slot(clp); | 502 | nfs41_handle_recall_slot(cps->clp); |
385 | out_putclient: | ||
386 | nfs_put_client(clp); /* balance nfs_find_client */ | ||
387 | out: | 503 | out: |
388 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); | 504 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); |
389 | return status; | 505 | return status; |
diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c index 05af212f0edf..23112c263f81 100644 --- a/fs/nfs/callback_xdr.c +++ b/fs/nfs/callback_xdr.c | |||
@@ -10,8 +10,10 @@ | |||
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/slab.h> | 12 | #include <linux/slab.h> |
13 | #include <linux/sunrpc/bc_xprt.h> | ||
13 | #include "nfs4_fs.h" | 14 | #include "nfs4_fs.h" |
14 | #include "callback.h" | 15 | #include "callback.h" |
16 | #include "internal.h" | ||
15 | 17 | ||
16 | #define CB_OP_TAGLEN_MAXSZ (512) | 18 | #define CB_OP_TAGLEN_MAXSZ (512) |
17 | #define CB_OP_HDR_RES_MAXSZ (2 + CB_OP_TAGLEN_MAXSZ) | 19 | #define CB_OP_HDR_RES_MAXSZ (2 + CB_OP_TAGLEN_MAXSZ) |
@@ -22,6 +24,7 @@ | |||
22 | #define CB_OP_RECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) | 24 | #define CB_OP_RECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
23 | 25 | ||
24 | #if defined(CONFIG_NFS_V4_1) | 26 | #if defined(CONFIG_NFS_V4_1) |
27 | #define CB_OP_LAYOUTRECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) | ||
25 | #define CB_OP_SEQUENCE_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \ | 28 | #define CB_OP_SEQUENCE_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \ |
26 | 4 + 1 + 3) | 29 | 4 + 1 + 3) |
27 | #define CB_OP_RECALLANY_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) | 30 | #define CB_OP_RECALLANY_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
@@ -33,7 +36,8 @@ | |||
33 | /* Internal error code */ | 36 | /* Internal error code */ |
34 | #define NFS4ERR_RESOURCE_HDR 11050 | 37 | #define NFS4ERR_RESOURCE_HDR 11050 |
35 | 38 | ||
36 | typedef __be32 (*callback_process_op_t)(void *, void *); | 39 | typedef __be32 (*callback_process_op_t)(void *, void *, |
40 | struct cb_process_state *); | ||
37 | typedef __be32 (*callback_decode_arg_t)(struct svc_rqst *, struct xdr_stream *, void *); | 41 | typedef __be32 (*callback_decode_arg_t)(struct svc_rqst *, struct xdr_stream *, void *); |
38 | typedef __be32 (*callback_encode_res_t)(struct svc_rqst *, struct xdr_stream *, void *); | 42 | typedef __be32 (*callback_encode_res_t)(struct svc_rqst *, struct xdr_stream *, void *); |
39 | 43 | ||
@@ -160,7 +164,7 @@ static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound | |||
160 | hdr->minorversion = ntohl(*p++); | 164 | hdr->minorversion = ntohl(*p++); |
161 | /* Check minor version is zero or one. */ | 165 | /* Check minor version is zero or one. */ |
162 | if (hdr->minorversion <= 1) { | 166 | if (hdr->minorversion <= 1) { |
163 | p++; /* skip callback_ident */ | 167 | hdr->cb_ident = ntohl(*p++); /* ignored by v4.1 */ |
164 | } else { | 168 | } else { |
165 | printk(KERN_WARNING "%s: NFSv4 server callback with " | 169 | printk(KERN_WARNING "%s: NFSv4 server callback with " |
166 | "illegal minor version %u!\n", | 170 | "illegal minor version %u!\n", |
@@ -220,6 +224,66 @@ out: | |||
220 | 224 | ||
221 | #if defined(CONFIG_NFS_V4_1) | 225 | #if defined(CONFIG_NFS_V4_1) |
222 | 226 | ||
227 | static __be32 decode_layoutrecall_args(struct svc_rqst *rqstp, | ||
228 | struct xdr_stream *xdr, | ||
229 | struct cb_layoutrecallargs *args) | ||
230 | { | ||
231 | __be32 *p; | ||
232 | __be32 status = 0; | ||
233 | uint32_t iomode; | ||
234 | |||
235 | args->cbl_addr = svc_addr(rqstp); | ||
236 | p = read_buf(xdr, 4 * sizeof(uint32_t)); | ||
237 | if (unlikely(p == NULL)) { | ||
238 | status = htonl(NFS4ERR_BADXDR); | ||
239 | goto out; | ||
240 | } | ||
241 | |||
242 | args->cbl_layout_type = ntohl(*p++); | ||
243 | /* Depite the spec's xdr, iomode really belongs in the FILE switch, | ||
244 | * as it is unuseable and ignored with the other types. | ||
245 | */ | ||
246 | iomode = ntohl(*p++); | ||
247 | args->cbl_layoutchanged = ntohl(*p++); | ||
248 | args->cbl_recall_type = ntohl(*p++); | ||
249 | |||
250 | if (args->cbl_recall_type == RETURN_FILE) { | ||
251 | args->cbl_range.iomode = iomode; | ||
252 | status = decode_fh(xdr, &args->cbl_fh); | ||
253 | if (unlikely(status != 0)) | ||
254 | goto out; | ||
255 | |||
256 | p = read_buf(xdr, 2 * sizeof(uint64_t)); | ||
257 | if (unlikely(p == NULL)) { | ||
258 | status = htonl(NFS4ERR_BADXDR); | ||
259 | goto out; | ||
260 | } | ||
261 | p = xdr_decode_hyper(p, &args->cbl_range.offset); | ||
262 | p = xdr_decode_hyper(p, &args->cbl_range.length); | ||
263 | status = decode_stateid(xdr, &args->cbl_stateid); | ||
264 | if (unlikely(status != 0)) | ||
265 | goto out; | ||
266 | } else if (args->cbl_recall_type == RETURN_FSID) { | ||
267 | p = read_buf(xdr, 2 * sizeof(uint64_t)); | ||
268 | if (unlikely(p == NULL)) { | ||
269 | status = htonl(NFS4ERR_BADXDR); | ||
270 | goto out; | ||
271 | } | ||
272 | p = xdr_decode_hyper(p, &args->cbl_fsid.major); | ||
273 | p = xdr_decode_hyper(p, &args->cbl_fsid.minor); | ||
274 | } else if (args->cbl_recall_type != RETURN_ALL) { | ||
275 | status = htonl(NFS4ERR_BADXDR); | ||
276 | goto out; | ||
277 | } | ||
278 | dprintk("%s: ltype 0x%x iomode %d changed %d recall_type %d\n", | ||
279 | __func__, | ||
280 | args->cbl_layout_type, iomode, | ||
281 | args->cbl_layoutchanged, args->cbl_recall_type); | ||
282 | out: | ||
283 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); | ||
284 | return status; | ||
285 | } | ||
286 | |||
223 | static __be32 decode_sessionid(struct xdr_stream *xdr, | 287 | static __be32 decode_sessionid(struct xdr_stream *xdr, |
224 | struct nfs4_sessionid *sid) | 288 | struct nfs4_sessionid *sid) |
225 | { | 289 | { |
@@ -574,10 +638,10 @@ preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op) | |||
574 | case OP_CB_SEQUENCE: | 638 | case OP_CB_SEQUENCE: |
575 | case OP_CB_RECALL_ANY: | 639 | case OP_CB_RECALL_ANY: |
576 | case OP_CB_RECALL_SLOT: | 640 | case OP_CB_RECALL_SLOT: |
641 | case OP_CB_LAYOUTRECALL: | ||
577 | *op = &callback_ops[op_nr]; | 642 | *op = &callback_ops[op_nr]; |
578 | break; | 643 | break; |
579 | 644 | ||
580 | case OP_CB_LAYOUTRECALL: | ||
581 | case OP_CB_NOTIFY_DEVICEID: | 645 | case OP_CB_NOTIFY_DEVICEID: |
582 | case OP_CB_NOTIFY: | 646 | case OP_CB_NOTIFY: |
583 | case OP_CB_PUSH_DELEG: | 647 | case OP_CB_PUSH_DELEG: |
@@ -593,6 +657,37 @@ preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op) | |||
593 | return htonl(NFS_OK); | 657 | return htonl(NFS_OK); |
594 | } | 658 | } |
595 | 659 | ||
660 | static void nfs4_callback_free_slot(struct nfs4_session *session) | ||
661 | { | ||
662 | struct nfs4_slot_table *tbl = &session->bc_slot_table; | ||
663 | |||
664 | spin_lock(&tbl->slot_tbl_lock); | ||
665 | /* | ||
666 | * Let the state manager know callback processing done. | ||
667 | * A single slot, so highest used slotid is either 0 or -1 | ||
668 | */ | ||
669 | tbl->highest_used_slotid--; | ||
670 | nfs4_check_drain_bc_complete(session); | ||
671 | spin_unlock(&tbl->slot_tbl_lock); | ||
672 | } | ||
673 | |||
674 | static void nfs4_cb_free_slot(struct nfs_client *clp) | ||
675 | { | ||
676 | if (clp && clp->cl_session) | ||
677 | nfs4_callback_free_slot(clp->cl_session); | ||
678 | } | ||
679 | |||
680 | /* A single slot, so highest used slotid is either 0 or -1 */ | ||
681 | void nfs4_cb_take_slot(struct nfs_client *clp) | ||
682 | { | ||
683 | struct nfs4_slot_table *tbl = &clp->cl_session->bc_slot_table; | ||
684 | |||
685 | spin_lock(&tbl->slot_tbl_lock); | ||
686 | tbl->highest_used_slotid++; | ||
687 | BUG_ON(tbl->highest_used_slotid != 0); | ||
688 | spin_unlock(&tbl->slot_tbl_lock); | ||
689 | } | ||
690 | |||
596 | #else /* CONFIG_NFS_V4_1 */ | 691 | #else /* CONFIG_NFS_V4_1 */ |
597 | 692 | ||
598 | static __be32 | 693 | static __be32 |
@@ -601,6 +696,9 @@ preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op) | |||
601 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); | 696 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); |
602 | } | 697 | } |
603 | 698 | ||
699 | static void nfs4_cb_free_slot(struct nfs_client *clp) | ||
700 | { | ||
701 | } | ||
604 | #endif /* CONFIG_NFS_V4_1 */ | 702 | #endif /* CONFIG_NFS_V4_1 */ |
605 | 703 | ||
606 | static __be32 | 704 | static __be32 |
@@ -621,7 +719,8 @@ preprocess_nfs4_op(unsigned int op_nr, struct callback_op **op) | |||
621 | static __be32 process_op(uint32_t minorversion, int nop, | 719 | static __be32 process_op(uint32_t minorversion, int nop, |
622 | struct svc_rqst *rqstp, | 720 | struct svc_rqst *rqstp, |
623 | struct xdr_stream *xdr_in, void *argp, | 721 | struct xdr_stream *xdr_in, void *argp, |
624 | struct xdr_stream *xdr_out, void *resp, int* drc_status) | 722 | struct xdr_stream *xdr_out, void *resp, |
723 | struct cb_process_state *cps) | ||
625 | { | 724 | { |
626 | struct callback_op *op = &callback_ops[0]; | 725 | struct callback_op *op = &callback_ops[0]; |
627 | unsigned int op_nr; | 726 | unsigned int op_nr; |
@@ -644,8 +743,8 @@ static __be32 process_op(uint32_t minorversion, int nop, | |||
644 | if (status) | 743 | if (status) |
645 | goto encode_hdr; | 744 | goto encode_hdr; |
646 | 745 | ||
647 | if (*drc_status) { | 746 | if (cps->drc_status) { |
648 | status = *drc_status; | 747 | status = cps->drc_status; |
649 | goto encode_hdr; | 748 | goto encode_hdr; |
650 | } | 749 | } |
651 | 750 | ||
@@ -653,16 +752,10 @@ static __be32 process_op(uint32_t minorversion, int nop, | |||
653 | if (maxlen > 0 && maxlen < PAGE_SIZE) { | 752 | if (maxlen > 0 && maxlen < PAGE_SIZE) { |
654 | status = op->decode_args(rqstp, xdr_in, argp); | 753 | status = op->decode_args(rqstp, xdr_in, argp); |
655 | if (likely(status == 0)) | 754 | if (likely(status == 0)) |
656 | status = op->process_op(argp, resp); | 755 | status = op->process_op(argp, resp, cps); |
657 | } else | 756 | } else |
658 | status = htonl(NFS4ERR_RESOURCE); | 757 | status = htonl(NFS4ERR_RESOURCE); |
659 | 758 | ||
660 | /* Only set by OP_CB_SEQUENCE processing */ | ||
661 | if (status == htonl(NFS4ERR_RETRY_UNCACHED_REP)) { | ||
662 | *drc_status = status; | ||
663 | status = 0; | ||
664 | } | ||
665 | |||
666 | encode_hdr: | 759 | encode_hdr: |
667 | res = encode_op_hdr(xdr_out, op_nr, status); | 760 | res = encode_op_hdr(xdr_out, op_nr, status); |
668 | if (unlikely(res)) | 761 | if (unlikely(res)) |
@@ -681,8 +774,11 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r | |||
681 | struct cb_compound_hdr_arg hdr_arg = { 0 }; | 774 | struct cb_compound_hdr_arg hdr_arg = { 0 }; |
682 | struct cb_compound_hdr_res hdr_res = { NULL }; | 775 | struct cb_compound_hdr_res hdr_res = { NULL }; |
683 | struct xdr_stream xdr_in, xdr_out; | 776 | struct xdr_stream xdr_in, xdr_out; |
684 | __be32 *p; | 777 | __be32 *p, status; |
685 | __be32 status, drc_status = 0; | 778 | struct cb_process_state cps = { |
779 | .drc_status = 0, | ||
780 | .clp = NULL, | ||
781 | }; | ||
686 | unsigned int nops = 0; | 782 | unsigned int nops = 0; |
687 | 783 | ||
688 | dprintk("%s: start\n", __func__); | 784 | dprintk("%s: start\n", __func__); |
@@ -696,6 +792,13 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r | |||
696 | if (status == __constant_htonl(NFS4ERR_RESOURCE)) | 792 | if (status == __constant_htonl(NFS4ERR_RESOURCE)) |
697 | return rpc_garbage_args; | 793 | return rpc_garbage_args; |
698 | 794 | ||
795 | if (hdr_arg.minorversion == 0) { | ||
796 | cps.clp = nfs4_find_client_ident(hdr_arg.cb_ident); | ||
797 | if (!cps.clp) | ||
798 | return rpc_drop_reply; | ||
799 | } else | ||
800 | cps.svc_sid = bc_xprt_sid(rqstp); | ||
801 | |||
699 | hdr_res.taglen = hdr_arg.taglen; | 802 | hdr_res.taglen = hdr_arg.taglen; |
700 | hdr_res.tag = hdr_arg.tag; | 803 | hdr_res.tag = hdr_arg.tag; |
701 | if (encode_compound_hdr_res(&xdr_out, &hdr_res) != 0) | 804 | if (encode_compound_hdr_res(&xdr_out, &hdr_res) != 0) |
@@ -703,7 +806,7 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r | |||
703 | 806 | ||
704 | while (status == 0 && nops != hdr_arg.nops) { | 807 | while (status == 0 && nops != hdr_arg.nops) { |
705 | status = process_op(hdr_arg.minorversion, nops, rqstp, | 808 | status = process_op(hdr_arg.minorversion, nops, rqstp, |
706 | &xdr_in, argp, &xdr_out, resp, &drc_status); | 809 | &xdr_in, argp, &xdr_out, resp, &cps); |
707 | nops++; | 810 | nops++; |
708 | } | 811 | } |
709 | 812 | ||
@@ -716,6 +819,8 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r | |||
716 | 819 | ||
717 | *hdr_res.status = status; | 820 | *hdr_res.status = status; |
718 | *hdr_res.nops = htonl(nops); | 821 | *hdr_res.nops = htonl(nops); |
822 | nfs4_cb_free_slot(cps.clp); | ||
823 | nfs_put_client(cps.clp); | ||
719 | dprintk("%s: done, status = %u\n", __func__, ntohl(status)); | 824 | dprintk("%s: done, status = %u\n", __func__, ntohl(status)); |
720 | return rpc_success; | 825 | return rpc_success; |
721 | } | 826 | } |
@@ -739,6 +844,12 @@ static struct callback_op callback_ops[] = { | |||
739 | .res_maxsize = CB_OP_RECALL_RES_MAXSZ, | 844 | .res_maxsize = CB_OP_RECALL_RES_MAXSZ, |
740 | }, | 845 | }, |
741 | #if defined(CONFIG_NFS_V4_1) | 846 | #if defined(CONFIG_NFS_V4_1) |
847 | [OP_CB_LAYOUTRECALL] = { | ||
848 | .process_op = (callback_process_op_t)nfs4_callback_layoutrecall, | ||
849 | .decode_args = | ||
850 | (callback_decode_arg_t)decode_layoutrecall_args, | ||
851 | .res_maxsize = CB_OP_LAYOUTRECALL_RES_MAXSZ, | ||
852 | }, | ||
742 | [OP_CB_SEQUENCE] = { | 853 | [OP_CB_SEQUENCE] = { |
743 | .process_op = (callback_process_op_t)nfs4_callback_sequence, | 854 | .process_op = (callback_process_op_t)nfs4_callback_sequence, |
744 | .decode_args = (callback_decode_arg_t)decode_cb_sequence_args, | 855 | .decode_args = (callback_decode_arg_t)decode_cb_sequence_args, |
diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 0870d0d4efc0..192f2f860265 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c | |||
@@ -56,6 +56,30 @@ static DEFINE_SPINLOCK(nfs_client_lock); | |||
56 | static LIST_HEAD(nfs_client_list); | 56 | static LIST_HEAD(nfs_client_list); |
57 | static LIST_HEAD(nfs_volume_list); | 57 | static LIST_HEAD(nfs_volume_list); |
58 | static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); | 58 | static DECLARE_WAIT_QUEUE_HEAD(nfs_client_active_wq); |
59 | #ifdef CONFIG_NFS_V4 | ||
60 | static DEFINE_IDR(cb_ident_idr); /* Protected by nfs_client_lock */ | ||
61 | |||
62 | /* | ||
63 | * Get a unique NFSv4.0 callback identifier which will be used | ||
64 | * by the V4.0 callback service to lookup the nfs_client struct | ||
65 | */ | ||
66 | static int nfs_get_cb_ident_idr(struct nfs_client *clp, int minorversion) | ||
67 | { | ||
68 | int ret = 0; | ||
69 | |||
70 | if (clp->rpc_ops->version != 4 || minorversion != 0) | ||
71 | return ret; | ||
72 | retry: | ||
73 | if (!idr_pre_get(&cb_ident_idr, GFP_KERNEL)) | ||
74 | return -ENOMEM; | ||
75 | spin_lock(&nfs_client_lock); | ||
76 | ret = idr_get_new(&cb_ident_idr, clp, &clp->cl_cb_ident); | ||
77 | spin_unlock(&nfs_client_lock); | ||
78 | if (ret == -EAGAIN) | ||
79 | goto retry; | ||
80 | return ret; | ||
81 | } | ||
82 | #endif /* CONFIG_NFS_V4 */ | ||
59 | 83 | ||
60 | /* | 84 | /* |
61 | * RPC cruft for NFS | 85 | * RPC cruft for NFS |
@@ -144,7 +168,10 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_ | |||
144 | clp->cl_proto = cl_init->proto; | 168 | clp->cl_proto = cl_init->proto; |
145 | 169 | ||
146 | #ifdef CONFIG_NFS_V4 | 170 | #ifdef CONFIG_NFS_V4 |
147 | INIT_LIST_HEAD(&clp->cl_delegations); | 171 | err = nfs_get_cb_ident_idr(clp, cl_init->minorversion); |
172 | if (err) | ||
173 | goto error_cleanup; | ||
174 | |||
148 | spin_lock_init(&clp->cl_lock); | 175 | spin_lock_init(&clp->cl_lock); |
149 | INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state); | 176 | INIT_DELAYED_WORK(&clp->cl_renewd, nfs4_renew_state); |
150 | rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client"); | 177 | rpc_init_wait_queue(&clp->cl_rpcwaitq, "NFS client"); |
@@ -170,21 +197,17 @@ error_0: | |||
170 | } | 197 | } |
171 | 198 | ||
172 | #ifdef CONFIG_NFS_V4 | 199 | #ifdef CONFIG_NFS_V4 |
173 | /* | ||
174 | * Clears/puts all minor version specific parts from an nfs_client struct | ||
175 | * reverting it to minorversion 0. | ||
176 | */ | ||
177 | static void nfs4_clear_client_minor_version(struct nfs_client *clp) | ||
178 | { | ||
179 | #ifdef CONFIG_NFS_V4_1 | 200 | #ifdef CONFIG_NFS_V4_1 |
180 | if (nfs4_has_session(clp)) { | 201 | static void nfs4_shutdown_session(struct nfs_client *clp) |
202 | { | ||
203 | if (nfs4_has_session(clp)) | ||
181 | nfs4_destroy_session(clp->cl_session); | 204 | nfs4_destroy_session(clp->cl_session); |
182 | clp->cl_session = NULL; | ||
183 | } | ||
184 | |||
185 | clp->cl_mvops = nfs_v4_minor_ops[0]; | ||
186 | #endif /* CONFIG_NFS_V4_1 */ | ||
187 | } | 205 | } |
206 | #else /* CONFIG_NFS_V4_1 */ | ||
207 | static void nfs4_shutdown_session(struct nfs_client *clp) | ||
208 | { | ||
209 | } | ||
210 | #endif /* CONFIG_NFS_V4_1 */ | ||
188 | 211 | ||
189 | /* | 212 | /* |
190 | * Destroy the NFS4 callback service | 213 | * Destroy the NFS4 callback service |
@@ -199,17 +222,49 @@ static void nfs4_shutdown_client(struct nfs_client *clp) | |||
199 | { | 222 | { |
200 | if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state)) | 223 | if (__test_and_clear_bit(NFS_CS_RENEWD, &clp->cl_res_state)) |
201 | nfs4_kill_renewd(clp); | 224 | nfs4_kill_renewd(clp); |
202 | nfs4_clear_client_minor_version(clp); | 225 | nfs4_shutdown_session(clp); |
203 | nfs4_destroy_callback(clp); | 226 | nfs4_destroy_callback(clp); |
204 | if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state)) | 227 | if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state)) |
205 | nfs_idmap_delete(clp); | 228 | nfs_idmap_delete(clp); |
206 | 229 | ||
207 | rpc_destroy_wait_queue(&clp->cl_rpcwaitq); | 230 | rpc_destroy_wait_queue(&clp->cl_rpcwaitq); |
208 | } | 231 | } |
232 | |||
233 | /* idr_remove_all is not needed as all id's are removed by nfs_put_client */ | ||
234 | void nfs_cleanup_cb_ident_idr(void) | ||
235 | { | ||
236 | idr_destroy(&cb_ident_idr); | ||
237 | } | ||
238 | |||
239 | /* nfs_client_lock held */ | ||
240 | static void nfs_cb_idr_remove_locked(struct nfs_client *clp) | ||
241 | { | ||
242 | if (clp->cl_cb_ident) | ||
243 | idr_remove(&cb_ident_idr, clp->cl_cb_ident); | ||
244 | } | ||
245 | |||
246 | static void pnfs_init_server(struct nfs_server *server) | ||
247 | { | ||
248 | rpc_init_wait_queue(&server->roc_rpcwaitq, "pNFS ROC"); | ||
249 | } | ||
250 | |||
209 | #else | 251 | #else |
210 | static void nfs4_shutdown_client(struct nfs_client *clp) | 252 | static void nfs4_shutdown_client(struct nfs_client *clp) |
211 | { | 253 | { |
212 | } | 254 | } |
255 | |||
256 | void nfs_cleanup_cb_ident_idr(void) | ||
257 | { | ||
258 | } | ||
259 | |||
260 | static void nfs_cb_idr_remove_locked(struct nfs_client *clp) | ||
261 | { | ||
262 | } | ||
263 | |||
264 | static void pnfs_init_server(struct nfs_server *server) | ||
265 | { | ||
266 | } | ||
267 | |||
213 | #endif /* CONFIG_NFS_V4 */ | 268 | #endif /* CONFIG_NFS_V4 */ |
214 | 269 | ||
215 | /* | 270 | /* |
@@ -248,6 +303,7 @@ void nfs_put_client(struct nfs_client *clp) | |||
248 | 303 | ||
249 | if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) { | 304 | if (atomic_dec_and_lock(&clp->cl_count, &nfs_client_lock)) { |
250 | list_del(&clp->cl_share_link); | 305 | list_del(&clp->cl_share_link); |
306 | nfs_cb_idr_remove_locked(clp); | ||
251 | spin_unlock(&nfs_client_lock); | 307 | spin_unlock(&nfs_client_lock); |
252 | 308 | ||
253 | BUG_ON(!list_empty(&clp->cl_superblocks)); | 309 | BUG_ON(!list_empty(&clp->cl_superblocks)); |
@@ -363,70 +419,28 @@ static int nfs_sockaddr_cmp(const struct sockaddr *sa1, | |||
363 | return 0; | 419 | return 0; |
364 | } | 420 | } |
365 | 421 | ||
366 | /* | 422 | /* Common match routine for v4.0 and v4.1 callback services */ |
367 | * Find a client by IP address and protocol version | 423 | bool |
368 | * - returns NULL if no such client | 424 | nfs4_cb_match_client(const struct sockaddr *addr, struct nfs_client *clp, |
369 | */ | 425 | u32 minorversion) |
370 | struct nfs_client *nfs_find_client(const struct sockaddr *addr, u32 nfsversion) | ||
371 | { | ||
372 | struct nfs_client *clp; | ||
373 | |||
374 | spin_lock(&nfs_client_lock); | ||
375 | list_for_each_entry(clp, &nfs_client_list, cl_share_link) { | ||
376 | struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; | ||
377 | |||
378 | /* Don't match clients that failed to initialise properly */ | ||
379 | if (!(clp->cl_cons_state == NFS_CS_READY || | ||
380 | clp->cl_cons_state == NFS_CS_SESSION_INITING)) | ||
381 | continue; | ||
382 | |||
383 | /* Different NFS versions cannot share the same nfs_client */ | ||
384 | if (clp->rpc_ops->version != nfsversion) | ||
385 | continue; | ||
386 | |||
387 | /* Match only the IP address, not the port number */ | ||
388 | if (!nfs_sockaddr_match_ipaddr(addr, clap)) | ||
389 | continue; | ||
390 | |||
391 | atomic_inc(&clp->cl_count); | ||
392 | spin_unlock(&nfs_client_lock); | ||
393 | return clp; | ||
394 | } | ||
395 | spin_unlock(&nfs_client_lock); | ||
396 | return NULL; | ||
397 | } | ||
398 | |||
399 | /* | ||
400 | * Find a client by IP address and protocol version | ||
401 | * - returns NULL if no such client | ||
402 | */ | ||
403 | struct nfs_client *nfs_find_client_next(struct nfs_client *clp) | ||
404 | { | 426 | { |
405 | struct sockaddr *sap = (struct sockaddr *)&clp->cl_addr; | 427 | struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; |
406 | u32 nfsvers = clp->rpc_ops->version; | ||
407 | 428 | ||
408 | spin_lock(&nfs_client_lock); | 429 | /* Don't match clients that failed to initialise */ |
409 | list_for_each_entry_continue(clp, &nfs_client_list, cl_share_link) { | 430 | if (!(clp->cl_cons_state == NFS_CS_READY || |
410 | struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; | 431 | clp->cl_cons_state == NFS_CS_SESSION_INITING)) |
432 | return false; | ||
411 | 433 | ||
412 | /* Don't match clients that failed to initialise properly */ | 434 | /* Match the version and minorversion */ |
413 | if (clp->cl_cons_state != NFS_CS_READY) | 435 | if (clp->rpc_ops->version != 4 || |
414 | continue; | 436 | clp->cl_minorversion != minorversion) |
437 | return false; | ||
415 | 438 | ||
416 | /* Different NFS versions cannot share the same nfs_client */ | 439 | /* Match only the IP address, not the port number */ |
417 | if (clp->rpc_ops->version != nfsvers) | 440 | if (!nfs_sockaddr_match_ipaddr(addr, clap)) |
418 | continue; | 441 | return false; |
419 | 442 | ||
420 | /* Match only the IP address, not the port number */ | 443 | return true; |
421 | if (!nfs_sockaddr_match_ipaddr(sap, clap)) | ||
422 | continue; | ||
423 | |||
424 | atomic_inc(&clp->cl_count); | ||
425 | spin_unlock(&nfs_client_lock); | ||
426 | return clp; | ||
427 | } | ||
428 | spin_unlock(&nfs_client_lock); | ||
429 | return NULL; | ||
430 | } | 444 | } |
431 | 445 | ||
432 | /* | 446 | /* |
@@ -988,6 +1002,27 @@ static void nfs_server_copy_userdata(struct nfs_server *target, struct nfs_serve | |||
988 | target->options = source->options; | 1002 | target->options = source->options; |
989 | } | 1003 | } |
990 | 1004 | ||
1005 | static void nfs_server_insert_lists(struct nfs_server *server) | ||
1006 | { | ||
1007 | struct nfs_client *clp = server->nfs_client; | ||
1008 | |||
1009 | spin_lock(&nfs_client_lock); | ||
1010 | list_add_tail_rcu(&server->client_link, &clp->cl_superblocks); | ||
1011 | list_add_tail(&server->master_link, &nfs_volume_list); | ||
1012 | spin_unlock(&nfs_client_lock); | ||
1013 | |||
1014 | } | ||
1015 | |||
1016 | static void nfs_server_remove_lists(struct nfs_server *server) | ||
1017 | { | ||
1018 | spin_lock(&nfs_client_lock); | ||
1019 | list_del_rcu(&server->client_link); | ||
1020 | list_del(&server->master_link); | ||
1021 | spin_unlock(&nfs_client_lock); | ||
1022 | |||
1023 | synchronize_rcu(); | ||
1024 | } | ||
1025 | |||
991 | /* | 1026 | /* |
992 | * Allocate and initialise a server record | 1027 | * Allocate and initialise a server record |
993 | */ | 1028 | */ |
@@ -1004,6 +1039,7 @@ static struct nfs_server *nfs_alloc_server(void) | |||
1004 | /* Zero out the NFS state stuff */ | 1039 | /* Zero out the NFS state stuff */ |
1005 | INIT_LIST_HEAD(&server->client_link); | 1040 | INIT_LIST_HEAD(&server->client_link); |
1006 | INIT_LIST_HEAD(&server->master_link); | 1041 | INIT_LIST_HEAD(&server->master_link); |
1042 | INIT_LIST_HEAD(&server->delegations); | ||
1007 | 1043 | ||
1008 | atomic_set(&server->active, 0); | 1044 | atomic_set(&server->active, 0); |
1009 | 1045 | ||
@@ -1019,6 +1055,8 @@ static struct nfs_server *nfs_alloc_server(void) | |||
1019 | return NULL; | 1055 | return NULL; |
1020 | } | 1056 | } |
1021 | 1057 | ||
1058 | pnfs_init_server(server); | ||
1059 | |||
1022 | return server; | 1060 | return server; |
1023 | } | 1061 | } |
1024 | 1062 | ||
@@ -1029,11 +1067,8 @@ void nfs_free_server(struct nfs_server *server) | |||
1029 | { | 1067 | { |
1030 | dprintk("--> nfs_free_server()\n"); | 1068 | dprintk("--> nfs_free_server()\n"); |
1031 | 1069 | ||
1070 | nfs_server_remove_lists(server); | ||
1032 | unset_pnfs_layoutdriver(server); | 1071 | unset_pnfs_layoutdriver(server); |
1033 | spin_lock(&nfs_client_lock); | ||
1034 | list_del(&server->client_link); | ||
1035 | list_del(&server->master_link); | ||
1036 | spin_unlock(&nfs_client_lock); | ||
1037 | 1072 | ||
1038 | if (server->destroy != NULL) | 1073 | if (server->destroy != NULL) |
1039 | server->destroy(server); | 1074 | server->destroy(server); |
@@ -1108,11 +1143,7 @@ struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data, | |||
1108 | (unsigned long long) server->fsid.major, | 1143 | (unsigned long long) server->fsid.major, |
1109 | (unsigned long long) server->fsid.minor); | 1144 | (unsigned long long) server->fsid.minor); |
1110 | 1145 | ||
1111 | spin_lock(&nfs_client_lock); | 1146 | nfs_server_insert_lists(server); |
1112 | list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); | ||
1113 | list_add_tail(&server->master_link, &nfs_volume_list); | ||
1114 | spin_unlock(&nfs_client_lock); | ||
1115 | |||
1116 | server->mount_time = jiffies; | 1147 | server->mount_time = jiffies; |
1117 | nfs_free_fattr(fattr); | 1148 | nfs_free_fattr(fattr); |
1118 | return server; | 1149 | return server; |
@@ -1125,6 +1156,101 @@ error: | |||
1125 | 1156 | ||
1126 | #ifdef CONFIG_NFS_V4 | 1157 | #ifdef CONFIG_NFS_V4 |
1127 | /* | 1158 | /* |
1159 | * NFSv4.0 callback thread helper | ||
1160 | * | ||
1161 | * Find a client by IP address, protocol version, and minorversion | ||
1162 | * | ||
1163 | * Called from the pg_authenticate method. The callback identifier | ||
1164 | * is not used as it has not been decoded. | ||
1165 | * | ||
1166 | * Returns NULL if no such client | ||
1167 | */ | ||
1168 | struct nfs_client * | ||
1169 | nfs4_find_client_no_ident(const struct sockaddr *addr) | ||
1170 | { | ||
1171 | struct nfs_client *clp; | ||
1172 | |||
1173 | spin_lock(&nfs_client_lock); | ||
1174 | list_for_each_entry(clp, &nfs_client_list, cl_share_link) { | ||
1175 | if (nfs4_cb_match_client(addr, clp, 0) == false) | ||
1176 | continue; | ||
1177 | atomic_inc(&clp->cl_count); | ||
1178 | spin_unlock(&nfs_client_lock); | ||
1179 | return clp; | ||
1180 | } | ||
1181 | spin_unlock(&nfs_client_lock); | ||
1182 | return NULL; | ||
1183 | } | ||
1184 | |||
1185 | /* | ||
1186 | * NFSv4.0 callback thread helper | ||
1187 | * | ||
1188 | * Find a client by callback identifier | ||
1189 | */ | ||
1190 | struct nfs_client * | ||
1191 | nfs4_find_client_ident(int cb_ident) | ||
1192 | { | ||
1193 | struct nfs_client *clp; | ||
1194 | |||
1195 | spin_lock(&nfs_client_lock); | ||
1196 | clp = idr_find(&cb_ident_idr, cb_ident); | ||
1197 | if (clp) | ||
1198 | atomic_inc(&clp->cl_count); | ||
1199 | spin_unlock(&nfs_client_lock); | ||
1200 | return clp; | ||
1201 | } | ||
1202 | |||
1203 | #if defined(CONFIG_NFS_V4_1) | ||
1204 | /* | ||
1205 | * NFSv4.1 callback thread helper | ||
1206 | * For CB_COMPOUND calls, find a client by IP address, protocol version, | ||
1207 | * minorversion, and sessionID | ||
1208 | * | ||
1209 | * CREATE_SESSION triggers a CB_NULL ping from servers. The callback service | ||
1210 | * sessionid can only be set after the CREATE_SESSION return, so a CB_NULL | ||
1211 | * can arrive before the callback sessionid is set. For CB_NULL calls, | ||
1212 | * find a client by IP address protocol version, and minorversion. | ||
1213 | * | ||
1214 | * Returns NULL if no such client | ||
1215 | */ | ||
1216 | struct nfs_client * | ||
1217 | nfs4_find_client_sessionid(const struct sockaddr *addr, | ||
1218 | struct nfs4_sessionid *sid, int is_cb_compound) | ||
1219 | { | ||
1220 | struct nfs_client *clp; | ||
1221 | |||
1222 | spin_lock(&nfs_client_lock); | ||
1223 | list_for_each_entry(clp, &nfs_client_list, cl_share_link) { | ||
1224 | if (nfs4_cb_match_client(addr, clp, 1) == false) | ||
1225 | continue; | ||
1226 | |||
1227 | if (!nfs4_has_session(clp)) | ||
1228 | continue; | ||
1229 | |||
1230 | /* Match sessionid unless cb_null call*/ | ||
1231 | if (is_cb_compound && (memcmp(clp->cl_session->sess_id.data, | ||
1232 | sid->data, NFS4_MAX_SESSIONID_LEN) != 0)) | ||
1233 | continue; | ||
1234 | |||
1235 | atomic_inc(&clp->cl_count); | ||
1236 | spin_unlock(&nfs_client_lock); | ||
1237 | return clp; | ||
1238 | } | ||
1239 | spin_unlock(&nfs_client_lock); | ||
1240 | return NULL; | ||
1241 | } | ||
1242 | |||
1243 | #else /* CONFIG_NFS_V4_1 */ | ||
1244 | |||
1245 | struct nfs_client * | ||
1246 | nfs4_find_client_sessionid(const struct sockaddr *addr, | ||
1247 | struct nfs4_sessionid *sid, int is_cb_compound) | ||
1248 | { | ||
1249 | return NULL; | ||
1250 | } | ||
1251 | #endif /* CONFIG_NFS_V4_1 */ | ||
1252 | |||
1253 | /* | ||
1128 | * Initialize the NFS4 callback service | 1254 | * Initialize the NFS4 callback service |
1129 | */ | 1255 | */ |
1130 | static int nfs4_init_callback(struct nfs_client *clp) | 1256 | static int nfs4_init_callback(struct nfs_client *clp) |
@@ -1342,11 +1468,7 @@ static int nfs4_server_common_setup(struct nfs_server *server, | |||
1342 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) | 1468 | if (server->namelen == 0 || server->namelen > NFS4_MAXNAMLEN) |
1343 | server->namelen = NFS4_MAXNAMLEN; | 1469 | server->namelen = NFS4_MAXNAMLEN; |
1344 | 1470 | ||
1345 | spin_lock(&nfs_client_lock); | 1471 | nfs_server_insert_lists(server); |
1346 | list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); | ||
1347 | list_add_tail(&server->master_link, &nfs_volume_list); | ||
1348 | spin_unlock(&nfs_client_lock); | ||
1349 | |||
1350 | server->mount_time = jiffies; | 1472 | server->mount_time = jiffies; |
1351 | out: | 1473 | out: |
1352 | nfs_free_fattr(fattr); | 1474 | nfs_free_fattr(fattr); |
@@ -1551,11 +1673,7 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source, | |||
1551 | if (error < 0) | 1673 | if (error < 0) |
1552 | goto out_free_server; | 1674 | goto out_free_server; |
1553 | 1675 | ||
1554 | spin_lock(&nfs_client_lock); | 1676 | nfs_server_insert_lists(server); |
1555 | list_add_tail(&server->client_link, &server->nfs_client->cl_superblocks); | ||
1556 | list_add_tail(&server->master_link, &nfs_volume_list); | ||
1557 | spin_unlock(&nfs_client_lock); | ||
1558 | |||
1559 | server->mount_time = jiffies; | 1677 | server->mount_time = jiffies; |
1560 | 1678 | ||
1561 | nfs_free_fattr(fattr_fsinfo); | 1679 | nfs_free_fattr(fattr_fsinfo); |
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index 1fd62fc49be3..364e4328f392 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c | |||
@@ -40,11 +40,23 @@ static void nfs_free_delegation(struct nfs_delegation *delegation) | |||
40 | call_rcu(&delegation->rcu, nfs_free_delegation_callback); | 40 | call_rcu(&delegation->rcu, nfs_free_delegation_callback); |
41 | } | 41 | } |
42 | 42 | ||
43 | /** | ||
44 | * nfs_mark_delegation_referenced - set delegation's REFERENCED flag | ||
45 | * @delegation: delegation to process | ||
46 | * | ||
47 | */ | ||
43 | void nfs_mark_delegation_referenced(struct nfs_delegation *delegation) | 48 | void nfs_mark_delegation_referenced(struct nfs_delegation *delegation) |
44 | { | 49 | { |
45 | set_bit(NFS_DELEGATION_REFERENCED, &delegation->flags); | 50 | set_bit(NFS_DELEGATION_REFERENCED, &delegation->flags); |
46 | } | 51 | } |
47 | 52 | ||
53 | /** | ||
54 | * nfs_have_delegation - check if inode has a delegation | ||
55 | * @inode: inode to check | ||
56 | * @flags: delegation types to check for | ||
57 | * | ||
58 | * Returns one if inode has the indicated delegation, otherwise zero. | ||
59 | */ | ||
48 | int nfs_have_delegation(struct inode *inode, fmode_t flags) | 60 | int nfs_have_delegation(struct inode *inode, fmode_t flags) |
49 | { | 61 | { |
50 | struct nfs_delegation *delegation; | 62 | struct nfs_delegation *delegation; |
@@ -119,10 +131,15 @@ again: | |||
119 | return 0; | 131 | return 0; |
120 | } | 132 | } |
121 | 133 | ||
122 | /* | 134 | /** |
123 | * Set up a delegation on an inode | 135 | * nfs_inode_reclaim_delegation - process a delegation reclaim request |
136 | * @inode: inode to process | ||
137 | * @cred: credential to use for request | ||
138 | * @res: new delegation state from server | ||
139 | * | ||
124 | */ | 140 | */ |
125 | void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res) | 141 | void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred, |
142 | struct nfs_openres *res) | ||
126 | { | 143 | { |
127 | struct nfs_delegation *delegation; | 144 | struct nfs_delegation *delegation; |
128 | struct rpc_cred *oldcred = NULL; | 145 | struct rpc_cred *oldcred = NULL; |
@@ -175,38 +192,52 @@ static struct inode *nfs_delegation_grab_inode(struct nfs_delegation *delegation | |||
175 | return inode; | 192 | return inode; |
176 | } | 193 | } |
177 | 194 | ||
178 | static struct nfs_delegation *nfs_detach_delegation_locked(struct nfs_inode *nfsi, | 195 | static struct nfs_delegation * |
179 | const nfs4_stateid *stateid, | 196 | nfs_detach_delegation_locked(struct nfs_inode *nfsi, |
180 | struct nfs_client *clp) | 197 | struct nfs_server *server) |
181 | { | 198 | { |
182 | struct nfs_delegation *delegation = | 199 | struct nfs_delegation *delegation = |
183 | rcu_dereference_protected(nfsi->delegation, | 200 | rcu_dereference_protected(nfsi->delegation, |
184 | lockdep_is_held(&clp->cl_lock)); | 201 | lockdep_is_held(&server->nfs_client->cl_lock)); |
185 | 202 | ||
186 | if (delegation == NULL) | 203 | if (delegation == NULL) |
187 | goto nomatch; | 204 | goto nomatch; |
205 | |||
188 | spin_lock(&delegation->lock); | 206 | spin_lock(&delegation->lock); |
189 | if (stateid != NULL && memcmp(delegation->stateid.data, stateid->data, | ||
190 | sizeof(delegation->stateid.data)) != 0) | ||
191 | goto nomatch_unlock; | ||
192 | list_del_rcu(&delegation->super_list); | 207 | list_del_rcu(&delegation->super_list); |
193 | delegation->inode = NULL; | 208 | delegation->inode = NULL; |
194 | nfsi->delegation_state = 0; | 209 | nfsi->delegation_state = 0; |
195 | rcu_assign_pointer(nfsi->delegation, NULL); | 210 | rcu_assign_pointer(nfsi->delegation, NULL); |
196 | spin_unlock(&delegation->lock); | 211 | spin_unlock(&delegation->lock); |
197 | return delegation; | 212 | return delegation; |
198 | nomatch_unlock: | ||
199 | spin_unlock(&delegation->lock); | ||
200 | nomatch: | 213 | nomatch: |
201 | return NULL; | 214 | return NULL; |
202 | } | 215 | } |
203 | 216 | ||
204 | /* | 217 | static struct nfs_delegation *nfs_detach_delegation(struct nfs_inode *nfsi, |
205 | * Set up a delegation on an inode | 218 | struct nfs_server *server) |
219 | { | ||
220 | struct nfs_client *clp = server->nfs_client; | ||
221 | struct nfs_delegation *delegation; | ||
222 | |||
223 | spin_lock(&clp->cl_lock); | ||
224 | delegation = nfs_detach_delegation_locked(nfsi, server); | ||
225 | spin_unlock(&clp->cl_lock); | ||
226 | return delegation; | ||
227 | } | ||
228 | |||
229 | /** | ||
230 | * nfs_inode_set_delegation - set up a delegation on an inode | ||
231 | * @inode: inode to which delegation applies | ||
232 | * @cred: cred to use for subsequent delegation processing | ||
233 | * @res: new delegation state from server | ||
234 | * | ||
235 | * Returns zero on success, or a negative errno value. | ||
206 | */ | 236 | */ |
207 | int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res) | 237 | int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res) |
208 | { | 238 | { |
209 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; | 239 | struct nfs_server *server = NFS_SERVER(inode); |
240 | struct nfs_client *clp = server->nfs_client; | ||
210 | struct nfs_inode *nfsi = NFS_I(inode); | 241 | struct nfs_inode *nfsi = NFS_I(inode); |
211 | struct nfs_delegation *delegation, *old_delegation; | 242 | struct nfs_delegation *delegation, *old_delegation; |
212 | struct nfs_delegation *freeme = NULL; | 243 | struct nfs_delegation *freeme = NULL; |
@@ -227,7 +258,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct | |||
227 | 258 | ||
228 | spin_lock(&clp->cl_lock); | 259 | spin_lock(&clp->cl_lock); |
229 | old_delegation = rcu_dereference_protected(nfsi->delegation, | 260 | old_delegation = rcu_dereference_protected(nfsi->delegation, |
230 | lockdep_is_held(&clp->cl_lock)); | 261 | lockdep_is_held(&clp->cl_lock)); |
231 | if (old_delegation != NULL) { | 262 | if (old_delegation != NULL) { |
232 | if (memcmp(&delegation->stateid, &old_delegation->stateid, | 263 | if (memcmp(&delegation->stateid, &old_delegation->stateid, |
233 | sizeof(old_delegation->stateid)) == 0 && | 264 | sizeof(old_delegation->stateid)) == 0 && |
@@ -246,9 +277,9 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct | |||
246 | delegation = NULL; | 277 | delegation = NULL; |
247 | goto out; | 278 | goto out; |
248 | } | 279 | } |
249 | freeme = nfs_detach_delegation_locked(nfsi, NULL, clp); | 280 | freeme = nfs_detach_delegation_locked(nfsi, server); |
250 | } | 281 | } |
251 | list_add_rcu(&delegation->super_list, &clp->cl_delegations); | 282 | list_add_rcu(&delegation->super_list, &server->delegations); |
252 | nfsi->delegation_state = delegation->type; | 283 | nfsi->delegation_state = delegation->type; |
253 | rcu_assign_pointer(nfsi->delegation, delegation); | 284 | rcu_assign_pointer(nfsi->delegation, delegation); |
254 | delegation = NULL; | 285 | delegation = NULL; |
@@ -290,73 +321,85 @@ out: | |||
290 | return err; | 321 | return err; |
291 | } | 322 | } |
292 | 323 | ||
293 | /* | 324 | /** |
294 | * Return all delegations that have been marked for return | 325 | * nfs_client_return_marked_delegations - return previously marked delegations |
326 | * @clp: nfs_client to process | ||
327 | * | ||
328 | * Returns zero on success, or a negative errno value. | ||
295 | */ | 329 | */ |
296 | int nfs_client_return_marked_delegations(struct nfs_client *clp) | 330 | int nfs_client_return_marked_delegations(struct nfs_client *clp) |
297 | { | 331 | { |
298 | struct nfs_delegation *delegation; | 332 | struct nfs_delegation *delegation; |
333 | struct nfs_server *server; | ||
299 | struct inode *inode; | 334 | struct inode *inode; |
300 | int err = 0; | 335 | int err = 0; |
301 | 336 | ||
302 | restart: | 337 | restart: |
303 | rcu_read_lock(); | 338 | rcu_read_lock(); |
304 | list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { | 339 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { |
305 | if (!test_and_clear_bit(NFS_DELEGATION_RETURN, &delegation->flags)) | 340 | list_for_each_entry_rcu(delegation, &server->delegations, |
306 | continue; | 341 | super_list) { |
307 | inode = nfs_delegation_grab_inode(delegation); | 342 | if (!test_and_clear_bit(NFS_DELEGATION_RETURN, |
308 | if (inode == NULL) | 343 | &delegation->flags)) |
309 | continue; | 344 | continue; |
310 | spin_lock(&clp->cl_lock); | 345 | inode = nfs_delegation_grab_inode(delegation); |
311 | delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL, clp); | 346 | if (inode == NULL) |
312 | spin_unlock(&clp->cl_lock); | 347 | continue; |
313 | rcu_read_unlock(); | 348 | delegation = nfs_detach_delegation(NFS_I(inode), |
314 | if (delegation != NULL) { | 349 | server); |
315 | filemap_flush(inode->i_mapping); | 350 | rcu_read_unlock(); |
316 | err = __nfs_inode_return_delegation(inode, delegation, 0); | 351 | |
352 | if (delegation != NULL) { | ||
353 | filemap_flush(inode->i_mapping); | ||
354 | err = __nfs_inode_return_delegation(inode, | ||
355 | delegation, 0); | ||
356 | } | ||
357 | iput(inode); | ||
358 | if (!err) | ||
359 | goto restart; | ||
360 | set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state); | ||
361 | return err; | ||
317 | } | 362 | } |
318 | iput(inode); | ||
319 | if (!err) | ||
320 | goto restart; | ||
321 | set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state); | ||
322 | return err; | ||
323 | } | 363 | } |
324 | rcu_read_unlock(); | 364 | rcu_read_unlock(); |
325 | return 0; | 365 | return 0; |
326 | } | 366 | } |
327 | 367 | ||
328 | /* | 368 | /** |
329 | * This function returns the delegation without reclaiming opens | 369 | * nfs_inode_return_delegation_noreclaim - return delegation, don't reclaim opens |
330 | * or protecting against delegation reclaims. | 370 | * @inode: inode to process |
331 | * It is therefore really only safe to be called from | 371 | * |
332 | * nfs4_clear_inode() | 372 | * Does not protect against delegation reclaims, therefore really only safe |
373 | * to be called from nfs4_clear_inode(). | ||
333 | */ | 374 | */ |
334 | void nfs_inode_return_delegation_noreclaim(struct inode *inode) | 375 | void nfs_inode_return_delegation_noreclaim(struct inode *inode) |
335 | { | 376 | { |
336 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; | 377 | struct nfs_server *server = NFS_SERVER(inode); |
337 | struct nfs_inode *nfsi = NFS_I(inode); | 378 | struct nfs_inode *nfsi = NFS_I(inode); |
338 | struct nfs_delegation *delegation; | 379 | struct nfs_delegation *delegation; |
339 | 380 | ||
340 | if (rcu_access_pointer(nfsi->delegation) != NULL) { | 381 | if (rcu_access_pointer(nfsi->delegation) != NULL) { |
341 | spin_lock(&clp->cl_lock); | 382 | delegation = nfs_detach_delegation(nfsi, server); |
342 | delegation = nfs_detach_delegation_locked(nfsi, NULL, clp); | ||
343 | spin_unlock(&clp->cl_lock); | ||
344 | if (delegation != NULL) | 383 | if (delegation != NULL) |
345 | nfs_do_return_delegation(inode, delegation, 0); | 384 | nfs_do_return_delegation(inode, delegation, 0); |
346 | } | 385 | } |
347 | } | 386 | } |
348 | 387 | ||
388 | /** | ||
389 | * nfs_inode_return_delegation - synchronously return a delegation | ||
390 | * @inode: inode to process | ||
391 | * | ||
392 | * Returns zero on success, or a negative errno value. | ||
393 | */ | ||
349 | int nfs_inode_return_delegation(struct inode *inode) | 394 | int nfs_inode_return_delegation(struct inode *inode) |
350 | { | 395 | { |
351 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; | 396 | struct nfs_server *server = NFS_SERVER(inode); |
352 | struct nfs_inode *nfsi = NFS_I(inode); | 397 | struct nfs_inode *nfsi = NFS_I(inode); |
353 | struct nfs_delegation *delegation; | 398 | struct nfs_delegation *delegation; |
354 | int err = 0; | 399 | int err = 0; |
355 | 400 | ||
356 | if (rcu_access_pointer(nfsi->delegation) != NULL) { | 401 | if (rcu_access_pointer(nfsi->delegation) != NULL) { |
357 | spin_lock(&clp->cl_lock); | 402 | delegation = nfs_detach_delegation(nfsi, server); |
358 | delegation = nfs_detach_delegation_locked(nfsi, NULL, clp); | ||
359 | spin_unlock(&clp->cl_lock); | ||
360 | if (delegation != NULL) { | 403 | if (delegation != NULL) { |
361 | nfs_wb_all(inode); | 404 | nfs_wb_all(inode); |
362 | err = __nfs_inode_return_delegation(inode, delegation, 1); | 405 | err = __nfs_inode_return_delegation(inode, delegation, 1); |
@@ -365,46 +408,61 @@ int nfs_inode_return_delegation(struct inode *inode) | |||
365 | return err; | 408 | return err; |
366 | } | 409 | } |
367 | 410 | ||
368 | static void nfs_mark_return_delegation(struct nfs_client *clp, struct nfs_delegation *delegation) | 411 | static void nfs_mark_return_delegation(struct nfs_delegation *delegation) |
369 | { | 412 | { |
413 | struct nfs_client *clp = NFS_SERVER(delegation->inode)->nfs_client; | ||
414 | |||
370 | set_bit(NFS_DELEGATION_RETURN, &delegation->flags); | 415 | set_bit(NFS_DELEGATION_RETURN, &delegation->flags); |
371 | set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state); | 416 | set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state); |
372 | } | 417 | } |
373 | 418 | ||
374 | /* | 419 | /** |
375 | * Return all delegations associated to a super block | 420 | * nfs_super_return_all_delegations - return delegations for one superblock |
421 | * @sb: sb to process | ||
422 | * | ||
376 | */ | 423 | */ |
377 | void nfs_super_return_all_delegations(struct super_block *sb) | 424 | void nfs_super_return_all_delegations(struct super_block *sb) |
378 | { | 425 | { |
379 | struct nfs_client *clp = NFS_SB(sb)->nfs_client; | 426 | struct nfs_server *server = NFS_SB(sb); |
427 | struct nfs_client *clp = server->nfs_client; | ||
380 | struct nfs_delegation *delegation; | 428 | struct nfs_delegation *delegation; |
381 | 429 | ||
382 | if (clp == NULL) | 430 | if (clp == NULL) |
383 | return; | 431 | return; |
432 | |||
384 | rcu_read_lock(); | 433 | rcu_read_lock(); |
385 | list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { | 434 | list_for_each_entry_rcu(delegation, &server->delegations, super_list) { |
386 | spin_lock(&delegation->lock); | 435 | spin_lock(&delegation->lock); |
387 | if (delegation->inode != NULL && delegation->inode->i_sb == sb) | 436 | set_bit(NFS_DELEGATION_RETURN, &delegation->flags); |
388 | set_bit(NFS_DELEGATION_RETURN, &delegation->flags); | ||
389 | spin_unlock(&delegation->lock); | 437 | spin_unlock(&delegation->lock); |
390 | } | 438 | } |
391 | rcu_read_unlock(); | 439 | rcu_read_unlock(); |
440 | |||
392 | if (nfs_client_return_marked_delegations(clp) != 0) | 441 | if (nfs_client_return_marked_delegations(clp) != 0) |
393 | nfs4_schedule_state_manager(clp); | 442 | nfs4_schedule_state_manager(clp); |
394 | } | 443 | } |
395 | 444 | ||
396 | static | 445 | static void nfs_mark_return_all_delegation_types(struct nfs_server *server, |
397 | void nfs_client_mark_return_all_delegation_types(struct nfs_client *clp, fmode_t flags) | 446 | fmode_t flags) |
398 | { | 447 | { |
399 | struct nfs_delegation *delegation; | 448 | struct nfs_delegation *delegation; |
400 | 449 | ||
401 | rcu_read_lock(); | 450 | list_for_each_entry_rcu(delegation, &server->delegations, super_list) { |
402 | list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { | ||
403 | if ((delegation->type == (FMODE_READ|FMODE_WRITE)) && !(flags & FMODE_WRITE)) | 451 | if ((delegation->type == (FMODE_READ|FMODE_WRITE)) && !(flags & FMODE_WRITE)) |
404 | continue; | 452 | continue; |
405 | if (delegation->type & flags) | 453 | if (delegation->type & flags) |
406 | nfs_mark_return_delegation(clp, delegation); | 454 | nfs_mark_return_delegation(delegation); |
407 | } | 455 | } |
456 | } | ||
457 | |||
458 | static void nfs_client_mark_return_all_delegation_types(struct nfs_client *clp, | ||
459 | fmode_t flags) | ||
460 | { | ||
461 | struct nfs_server *server; | ||
462 | |||
463 | rcu_read_lock(); | ||
464 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) | ||
465 | nfs_mark_return_all_delegation_types(server, flags); | ||
408 | rcu_read_unlock(); | 466 | rcu_read_unlock(); |
409 | } | 467 | } |
410 | 468 | ||
@@ -419,19 +477,32 @@ static void nfs_delegation_run_state_manager(struct nfs_client *clp) | |||
419 | nfs4_schedule_state_manager(clp); | 477 | nfs4_schedule_state_manager(clp); |
420 | } | 478 | } |
421 | 479 | ||
480 | /** | ||
481 | * nfs_expire_all_delegation_types | ||
482 | * @clp: client to process | ||
483 | * @flags: delegation types to expire | ||
484 | * | ||
485 | */ | ||
422 | void nfs_expire_all_delegation_types(struct nfs_client *clp, fmode_t flags) | 486 | void nfs_expire_all_delegation_types(struct nfs_client *clp, fmode_t flags) |
423 | { | 487 | { |
424 | nfs_client_mark_return_all_delegation_types(clp, flags); | 488 | nfs_client_mark_return_all_delegation_types(clp, flags); |
425 | nfs_delegation_run_state_manager(clp); | 489 | nfs_delegation_run_state_manager(clp); |
426 | } | 490 | } |
427 | 491 | ||
492 | /** | ||
493 | * nfs_expire_all_delegations | ||
494 | * @clp: client to process | ||
495 | * | ||
496 | */ | ||
428 | void nfs_expire_all_delegations(struct nfs_client *clp) | 497 | void nfs_expire_all_delegations(struct nfs_client *clp) |
429 | { | 498 | { |
430 | nfs_expire_all_delegation_types(clp, FMODE_READ|FMODE_WRITE); | 499 | nfs_expire_all_delegation_types(clp, FMODE_READ|FMODE_WRITE); |
431 | } | 500 | } |
432 | 501 | ||
433 | /* | 502 | /** |
434 | * Return all delegations following an NFS4ERR_CB_PATH_DOWN error. | 503 | * nfs_handle_cb_pathdown - return all delegations after NFS4ERR_CB_PATH_DOWN |
504 | * @clp: client to process | ||
505 | * | ||
435 | */ | 506 | */ |
436 | void nfs_handle_cb_pathdown(struct nfs_client *clp) | 507 | void nfs_handle_cb_pathdown(struct nfs_client *clp) |
437 | { | 508 | { |
@@ -440,29 +511,43 @@ void nfs_handle_cb_pathdown(struct nfs_client *clp) | |||
440 | nfs_client_mark_return_all_delegations(clp); | 511 | nfs_client_mark_return_all_delegations(clp); |
441 | } | 512 | } |
442 | 513 | ||
443 | static void nfs_client_mark_return_unreferenced_delegations(struct nfs_client *clp) | 514 | static void nfs_mark_return_unreferenced_delegations(struct nfs_server *server) |
444 | { | 515 | { |
445 | struct nfs_delegation *delegation; | 516 | struct nfs_delegation *delegation; |
446 | 517 | ||
447 | rcu_read_lock(); | 518 | list_for_each_entry_rcu(delegation, &server->delegations, super_list) { |
448 | list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { | ||
449 | if (test_and_clear_bit(NFS_DELEGATION_REFERENCED, &delegation->flags)) | 519 | if (test_and_clear_bit(NFS_DELEGATION_REFERENCED, &delegation->flags)) |
450 | continue; | 520 | continue; |
451 | nfs_mark_return_delegation(clp, delegation); | 521 | nfs_mark_return_delegation(delegation); |
452 | } | 522 | } |
453 | rcu_read_unlock(); | ||
454 | } | 523 | } |
455 | 524 | ||
525 | /** | ||
526 | * nfs_expire_unreferenced_delegations - Eliminate unused delegations | ||
527 | * @clp: nfs_client to process | ||
528 | * | ||
529 | */ | ||
456 | void nfs_expire_unreferenced_delegations(struct nfs_client *clp) | 530 | void nfs_expire_unreferenced_delegations(struct nfs_client *clp) |
457 | { | 531 | { |
458 | nfs_client_mark_return_unreferenced_delegations(clp); | 532 | struct nfs_server *server; |
533 | |||
534 | rcu_read_lock(); | ||
535 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) | ||
536 | nfs_mark_return_unreferenced_delegations(server); | ||
537 | rcu_read_unlock(); | ||
538 | |||
459 | nfs_delegation_run_state_manager(clp); | 539 | nfs_delegation_run_state_manager(clp); |
460 | } | 540 | } |
461 | 541 | ||
462 | /* | 542 | /** |
463 | * Asynchronous delegation recall! | 543 | * nfs_async_inode_return_delegation - asynchronously return a delegation |
544 | * @inode: inode to process | ||
545 | * @stateid: state ID information from CB_RECALL arguments | ||
546 | * | ||
547 | * Returns zero on success, or a negative errno value. | ||
464 | */ | 548 | */ |
465 | int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *stateid) | 549 | int nfs_async_inode_return_delegation(struct inode *inode, |
550 | const nfs4_stateid *stateid) | ||
466 | { | 551 | { |
467 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; | 552 | struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; |
468 | struct nfs_delegation *delegation; | 553 | struct nfs_delegation *delegation; |
@@ -474,22 +559,21 @@ int nfs_async_inode_return_delegation(struct inode *inode, const nfs4_stateid *s | |||
474 | rcu_read_unlock(); | 559 | rcu_read_unlock(); |
475 | return -ENOENT; | 560 | return -ENOENT; |
476 | } | 561 | } |
477 | 562 | nfs_mark_return_delegation(delegation); | |
478 | nfs_mark_return_delegation(clp, delegation); | ||
479 | rcu_read_unlock(); | 563 | rcu_read_unlock(); |
564 | |||
480 | nfs_delegation_run_state_manager(clp); | 565 | nfs_delegation_run_state_manager(clp); |
481 | return 0; | 566 | return 0; |
482 | } | 567 | } |
483 | 568 | ||
484 | /* | 569 | static struct inode * |
485 | * Retrieve the inode associated with a delegation | 570 | nfs_delegation_find_inode_server(struct nfs_server *server, |
486 | */ | 571 | const struct nfs_fh *fhandle) |
487 | struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs_fh *fhandle) | ||
488 | { | 572 | { |
489 | struct nfs_delegation *delegation; | 573 | struct nfs_delegation *delegation; |
490 | struct inode *res = NULL; | 574 | struct inode *res = NULL; |
491 | rcu_read_lock(); | 575 | |
492 | list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { | 576 | list_for_each_entry_rcu(delegation, &server->delegations, super_list) { |
493 | spin_lock(&delegation->lock); | 577 | spin_lock(&delegation->lock); |
494 | if (delegation->inode != NULL && | 578 | if (delegation->inode != NULL && |
495 | nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) { | 579 | nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) { |
@@ -499,49 +583,121 @@ struct inode *nfs_delegation_find_inode(struct nfs_client *clp, const struct nfs | |||
499 | if (res != NULL) | 583 | if (res != NULL) |
500 | break; | 584 | break; |
501 | } | 585 | } |
586 | return res; | ||
587 | } | ||
588 | |||
589 | /** | ||
590 | * nfs_delegation_find_inode - retrieve the inode associated with a delegation | ||
591 | * @clp: client state handle | ||
592 | * @fhandle: filehandle from a delegation recall | ||
593 | * | ||
594 | * Returns pointer to inode matching "fhandle," or NULL if a matching inode | ||
595 | * cannot be found. | ||
596 | */ | ||
597 | struct inode *nfs_delegation_find_inode(struct nfs_client *clp, | ||
598 | const struct nfs_fh *fhandle) | ||
599 | { | ||
600 | struct nfs_server *server; | ||
601 | struct inode *res = NULL; | ||
602 | |||
603 | rcu_read_lock(); | ||
604 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { | ||
605 | res = nfs_delegation_find_inode_server(server, fhandle); | ||
606 | if (res != NULL) | ||
607 | break; | ||
608 | } | ||
502 | rcu_read_unlock(); | 609 | rcu_read_unlock(); |
503 | return res; | 610 | return res; |
504 | } | 611 | } |
505 | 612 | ||
506 | /* | 613 | static void nfs_delegation_mark_reclaim_server(struct nfs_server *server) |
507 | * Mark all delegations as needing to be reclaimed | 614 | { |
615 | struct nfs_delegation *delegation; | ||
616 | |||
617 | list_for_each_entry_rcu(delegation, &server->delegations, super_list) | ||
618 | set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags); | ||
619 | } | ||
620 | |||
621 | /** | ||
622 | * nfs_delegation_mark_reclaim - mark all delegations as needing to be reclaimed | ||
623 | * @clp: nfs_client to process | ||
624 | * | ||
508 | */ | 625 | */ |
509 | void nfs_delegation_mark_reclaim(struct nfs_client *clp) | 626 | void nfs_delegation_mark_reclaim(struct nfs_client *clp) |
510 | { | 627 | { |
511 | struct nfs_delegation *delegation; | 628 | struct nfs_server *server; |
629 | |||
512 | rcu_read_lock(); | 630 | rcu_read_lock(); |
513 | list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) | 631 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) |
514 | set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags); | 632 | nfs_delegation_mark_reclaim_server(server); |
515 | rcu_read_unlock(); | 633 | rcu_read_unlock(); |
516 | } | 634 | } |
517 | 635 | ||
518 | /* | 636 | /** |
519 | * Reap all unclaimed delegations after reboot recovery is done | 637 | * nfs_delegation_reap_unclaimed - reap unclaimed delegations after reboot recovery is done |
638 | * @clp: nfs_client to process | ||
639 | * | ||
520 | */ | 640 | */ |
521 | void nfs_delegation_reap_unclaimed(struct nfs_client *clp) | 641 | void nfs_delegation_reap_unclaimed(struct nfs_client *clp) |
522 | { | 642 | { |
523 | struct nfs_delegation *delegation; | 643 | struct nfs_delegation *delegation; |
644 | struct nfs_server *server; | ||
524 | struct inode *inode; | 645 | struct inode *inode; |
646 | |||
525 | restart: | 647 | restart: |
526 | rcu_read_lock(); | 648 | rcu_read_lock(); |
527 | list_for_each_entry_rcu(delegation, &clp->cl_delegations, super_list) { | 649 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { |
528 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags) == 0) | 650 | list_for_each_entry_rcu(delegation, &server->delegations, |
529 | continue; | 651 | super_list) { |
530 | inode = nfs_delegation_grab_inode(delegation); | 652 | if (test_bit(NFS_DELEGATION_NEED_RECLAIM, |
531 | if (inode == NULL) | 653 | &delegation->flags) == 0) |
532 | continue; | 654 | continue; |
533 | spin_lock(&clp->cl_lock); | 655 | inode = nfs_delegation_grab_inode(delegation); |
534 | delegation = nfs_detach_delegation_locked(NFS_I(inode), NULL, clp); | 656 | if (inode == NULL) |
535 | spin_unlock(&clp->cl_lock); | 657 | continue; |
536 | rcu_read_unlock(); | 658 | delegation = nfs_detach_delegation(NFS_I(inode), |
537 | if (delegation != NULL) | 659 | server); |
538 | nfs_free_delegation(delegation); | 660 | rcu_read_unlock(); |
539 | iput(inode); | 661 | |
540 | goto restart; | 662 | if (delegation != NULL) |
663 | nfs_free_delegation(delegation); | ||
664 | iput(inode); | ||
665 | goto restart; | ||
666 | } | ||
541 | } | 667 | } |
542 | rcu_read_unlock(); | 668 | rcu_read_unlock(); |
543 | } | 669 | } |
544 | 670 | ||
671 | /** | ||
672 | * nfs_delegations_present - check for existence of delegations | ||
673 | * @clp: client state handle | ||
674 | * | ||
675 | * Returns one if there are any nfs_delegation structures attached | ||
676 | * to this nfs_client. | ||
677 | */ | ||
678 | int nfs_delegations_present(struct nfs_client *clp) | ||
679 | { | ||
680 | struct nfs_server *server; | ||
681 | int ret = 0; | ||
682 | |||
683 | rcu_read_lock(); | ||
684 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) | ||
685 | if (!list_empty(&server->delegations)) { | ||
686 | ret = 1; | ||
687 | break; | ||
688 | } | ||
689 | rcu_read_unlock(); | ||
690 | return ret; | ||
691 | } | ||
692 | |||
693 | /** | ||
694 | * nfs4_copy_delegation_stateid - Copy inode's state ID information | ||
695 | * @dst: stateid data structure to fill in | ||
696 | * @inode: inode to check | ||
697 | * | ||
698 | * Returns one and fills in "dst->data" * if inode had a delegation, | ||
699 | * otherwise zero is returned. | ||
700 | */ | ||
545 | int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode) | 701 | int nfs4_copy_delegation_stateid(nfs4_stateid *dst, struct inode *inode) |
546 | { | 702 | { |
547 | struct nfs_inode *nfsi = NFS_I(inode); | 703 | struct nfs_inode *nfsi = NFS_I(inode); |
diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h index 2026304bda19..d9322e490c56 100644 --- a/fs/nfs/delegation.h +++ b/fs/nfs/delegation.h | |||
@@ -44,6 +44,7 @@ void nfs_expire_all_delegation_types(struct nfs_client *clp, fmode_t flags); | |||
44 | void nfs_expire_unreferenced_delegations(struct nfs_client *clp); | 44 | void nfs_expire_unreferenced_delegations(struct nfs_client *clp); |
45 | void nfs_handle_cb_pathdown(struct nfs_client *clp); | 45 | void nfs_handle_cb_pathdown(struct nfs_client *clp); |
46 | int nfs_client_return_marked_delegations(struct nfs_client *clp); | 46 | int nfs_client_return_marked_delegations(struct nfs_client *clp); |
47 | int nfs_delegations_present(struct nfs_client *clp); | ||
47 | 48 | ||
48 | void nfs_delegation_mark_reclaim(struct nfs_client *clp); | 49 | void nfs_delegation_mark_reclaim(struct nfs_client *clp); |
49 | void nfs_delegation_reap_unclaimed(struct nfs_client *clp); | 50 | void nfs_delegation_reap_unclaimed(struct nfs_client *clp); |
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index d33da530097a..2c3eb33b904d 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c | |||
@@ -33,8 +33,8 @@ | |||
33 | #include <linux/namei.h> | 33 | #include <linux/namei.h> |
34 | #include <linux/mount.h> | 34 | #include <linux/mount.h> |
35 | #include <linux/sched.h> | 35 | #include <linux/sched.h> |
36 | #include <linux/vmalloc.h> | ||
37 | #include <linux/kmemleak.h> | 36 | #include <linux/kmemleak.h> |
37 | #include <linux/xattr.h> | ||
38 | 38 | ||
39 | #include "delegation.h" | 39 | #include "delegation.h" |
40 | #include "iostat.h" | 40 | #include "iostat.h" |
@@ -125,9 +125,10 @@ const struct inode_operations nfs4_dir_inode_operations = { | |||
125 | .permission = nfs_permission, | 125 | .permission = nfs_permission, |
126 | .getattr = nfs_getattr, | 126 | .getattr = nfs_getattr, |
127 | .setattr = nfs_setattr, | 127 | .setattr = nfs_setattr, |
128 | .getxattr = nfs4_getxattr, | 128 | .getxattr = generic_getxattr, |
129 | .setxattr = nfs4_setxattr, | 129 | .setxattr = generic_setxattr, |
130 | .listxattr = nfs4_listxattr, | 130 | .listxattr = generic_listxattr, |
131 | .removexattr = generic_removexattr, | ||
131 | }; | 132 | }; |
132 | 133 | ||
133 | #endif /* CONFIG_NFS_V4 */ | 134 | #endif /* CONFIG_NFS_V4 */ |
@@ -172,7 +173,7 @@ struct nfs_cache_array { | |||
172 | struct nfs_cache_array_entry array[0]; | 173 | struct nfs_cache_array_entry array[0]; |
173 | }; | 174 | }; |
174 | 175 | ||
175 | typedef __be32 * (*decode_dirent_t)(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int); | 176 | typedef int (*decode_dirent_t)(struct xdr_stream *, struct nfs_entry *, int); |
176 | typedef struct { | 177 | typedef struct { |
177 | struct file *file; | 178 | struct file *file; |
178 | struct page *page; | 179 | struct page *page; |
@@ -378,14 +379,14 @@ error: | |||
378 | return error; | 379 | return error; |
379 | } | 380 | } |
380 | 381 | ||
381 | /* Fill in an entry based on the xdr code stored in desc->page */ | 382 | static int xdr_decode(nfs_readdir_descriptor_t *desc, |
382 | static | 383 | struct nfs_entry *entry, struct xdr_stream *xdr) |
383 | int xdr_decode(nfs_readdir_descriptor_t *desc, struct nfs_entry *entry, struct xdr_stream *stream) | ||
384 | { | 384 | { |
385 | __be32 *p = desc->decode(stream, entry, NFS_SERVER(desc->file->f_path.dentry->d_inode), desc->plus); | 385 | int error; |
386 | if (IS_ERR(p)) | ||
387 | return PTR_ERR(p); | ||
388 | 386 | ||
387 | error = desc->decode(xdr, entry, desc->plus); | ||
388 | if (error) | ||
389 | return error; | ||
389 | entry->fattr->time_start = desc->timestamp; | 390 | entry->fattr->time_start = desc->timestamp; |
390 | entry->fattr->gencount = desc->gencount; | 391 | entry->fattr->gencount = desc->gencount; |
391 | return 0; | 392 | return 0; |
@@ -438,7 +439,6 @@ void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry) | |||
438 | if (dentry == NULL) | 439 | if (dentry == NULL) |
439 | return; | 440 | return; |
440 | 441 | ||
441 | d_set_d_op(dentry, NFS_PROTO(dir)->dentry_ops); | ||
442 | inode = nfs_fhget(dentry->d_sb, entry->fh, entry->fattr); | 442 | inode = nfs_fhget(dentry->d_sb, entry->fh, entry->fattr); |
443 | if (IS_ERR(inode)) | 443 | if (IS_ERR(inode)) |
444 | goto out; | 444 | goto out; |
@@ -459,25 +459,26 @@ out: | |||
459 | /* Perform conversion from xdr to cache array */ | 459 | /* Perform conversion from xdr to cache array */ |
460 | static | 460 | static |
461 | int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *entry, | 461 | int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *entry, |
462 | void *xdr_page, struct page *page, unsigned int buflen) | 462 | struct page **xdr_pages, struct page *page, unsigned int buflen) |
463 | { | 463 | { |
464 | struct xdr_stream stream; | 464 | struct xdr_stream stream; |
465 | struct xdr_buf buf; | 465 | struct xdr_buf buf = { |
466 | __be32 *ptr = xdr_page; | 466 | .pages = xdr_pages, |
467 | .page_len = buflen, | ||
468 | .buflen = buflen, | ||
469 | .len = buflen, | ||
470 | }; | ||
471 | struct page *scratch; | ||
467 | struct nfs_cache_array *array; | 472 | struct nfs_cache_array *array; |
468 | unsigned int count = 0; | 473 | unsigned int count = 0; |
469 | int status; | 474 | int status; |
470 | 475 | ||
471 | buf.head->iov_base = xdr_page; | 476 | scratch = alloc_page(GFP_KERNEL); |
472 | buf.head->iov_len = buflen; | 477 | if (scratch == NULL) |
473 | buf.tail->iov_len = 0; | 478 | return -ENOMEM; |
474 | buf.page_base = 0; | ||
475 | buf.page_len = 0; | ||
476 | buf.buflen = buf.head->iov_len; | ||
477 | buf.len = buf.head->iov_len; | ||
478 | |||
479 | xdr_init_decode(&stream, &buf, ptr); | ||
480 | 479 | ||
480 | xdr_init_decode(&stream, &buf, NULL); | ||
481 | xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); | ||
481 | 482 | ||
482 | do { | 483 | do { |
483 | status = xdr_decode(desc, entry, &stream); | 484 | status = xdr_decode(desc, entry, &stream); |
@@ -506,6 +507,8 @@ int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *en | |||
506 | } else | 507 | } else |
507 | status = PTR_ERR(array); | 508 | status = PTR_ERR(array); |
508 | } | 509 | } |
510 | |||
511 | put_page(scratch); | ||
509 | return status; | 512 | return status; |
510 | } | 513 | } |
511 | 514 | ||
@@ -521,7 +524,6 @@ static | |||
521 | void nfs_readdir_free_large_page(void *ptr, struct page **pages, | 524 | void nfs_readdir_free_large_page(void *ptr, struct page **pages, |
522 | unsigned int npages) | 525 | unsigned int npages) |
523 | { | 526 | { |
524 | vm_unmap_ram(ptr, npages); | ||
525 | nfs_readdir_free_pagearray(pages, npages); | 527 | nfs_readdir_free_pagearray(pages, npages); |
526 | } | 528 | } |
527 | 529 | ||
@@ -530,9 +532,8 @@ void nfs_readdir_free_large_page(void *ptr, struct page **pages, | |||
530 | * to nfs_readdir_free_large_page | 532 | * to nfs_readdir_free_large_page |
531 | */ | 533 | */ |
532 | static | 534 | static |
533 | void *nfs_readdir_large_page(struct page **pages, unsigned int npages) | 535 | int nfs_readdir_large_page(struct page **pages, unsigned int npages) |
534 | { | 536 | { |
535 | void *ptr; | ||
536 | unsigned int i; | 537 | unsigned int i; |
537 | 538 | ||
538 | for (i = 0; i < npages; i++) { | 539 | for (i = 0; i < npages; i++) { |
@@ -541,13 +542,11 @@ void *nfs_readdir_large_page(struct page **pages, unsigned int npages) | |||
541 | goto out_freepages; | 542 | goto out_freepages; |
542 | pages[i] = page; | 543 | pages[i] = page; |
543 | } | 544 | } |
545 | return 0; | ||
544 | 546 | ||
545 | ptr = vm_map_ram(pages, npages, 0, PAGE_KERNEL); | ||
546 | if (!IS_ERR_OR_NULL(ptr)) | ||
547 | return ptr; | ||
548 | out_freepages: | 547 | out_freepages: |
549 | nfs_readdir_free_pagearray(pages, i); | 548 | nfs_readdir_free_pagearray(pages, i); |
550 | return NULL; | 549 | return -ENOMEM; |
551 | } | 550 | } |
552 | 551 | ||
553 | static | 552 | static |
@@ -566,6 +565,7 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page, | |||
566 | entry.eof = 0; | 565 | entry.eof = 0; |
567 | entry.fh = nfs_alloc_fhandle(); | 566 | entry.fh = nfs_alloc_fhandle(); |
568 | entry.fattr = nfs_alloc_fattr(); | 567 | entry.fattr = nfs_alloc_fattr(); |
568 | entry.server = NFS_SERVER(inode); | ||
569 | if (entry.fh == NULL || entry.fattr == NULL) | 569 | if (entry.fh == NULL || entry.fattr == NULL) |
570 | goto out; | 570 | goto out; |
571 | 571 | ||
@@ -577,8 +577,8 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page, | |||
577 | memset(array, 0, sizeof(struct nfs_cache_array)); | 577 | memset(array, 0, sizeof(struct nfs_cache_array)); |
578 | array->eof_index = -1; | 578 | array->eof_index = -1; |
579 | 579 | ||
580 | pages_ptr = nfs_readdir_large_page(pages, array_size); | 580 | status = nfs_readdir_large_page(pages, array_size); |
581 | if (!pages_ptr) | 581 | if (status < 0) |
582 | goto out_release_array; | 582 | goto out_release_array; |
583 | do { | 583 | do { |
584 | unsigned int pglen; | 584 | unsigned int pglen; |
@@ -587,7 +587,7 @@ int nfs_readdir_xdr_to_array(nfs_readdir_descriptor_t *desc, struct page *page, | |||
587 | if (status < 0) | 587 | if (status < 0) |
588 | break; | 588 | break; |
589 | pglen = status; | 589 | pglen = status; |
590 | status = nfs_readdir_page_filler(desc, &entry, pages_ptr, page, pglen); | 590 | status = nfs_readdir_page_filler(desc, &entry, pages, page, pglen); |
591 | if (status < 0) { | 591 | if (status < 0) { |
592 | if (status == -ENOSPC) | 592 | if (status == -ENOSPC) |
593 | status = 0; | 593 | status = 0; |
@@ -970,7 +970,7 @@ int nfs_lookup_verify_inode(struct inode *inode, struct nameidata *nd) | |||
970 | { | 970 | { |
971 | struct nfs_server *server = NFS_SERVER(inode); | 971 | struct nfs_server *server = NFS_SERVER(inode); |
972 | 972 | ||
973 | if (test_bit(NFS_INO_MOUNTPOINT, &NFS_I(inode)->flags)) | 973 | if (IS_AUTOMOUNT(inode)) |
974 | return 0; | 974 | return 0; |
975 | if (nd != NULL) { | 975 | if (nd != NULL) { |
976 | /* VFS wants an on-the-wire revalidation */ | 976 | /* VFS wants an on-the-wire revalidation */ |
@@ -1173,6 +1173,7 @@ const struct dentry_operations nfs_dentry_operations = { | |||
1173 | .d_revalidate = nfs_lookup_revalidate, | 1173 | .d_revalidate = nfs_lookup_revalidate, |
1174 | .d_delete = nfs_dentry_delete, | 1174 | .d_delete = nfs_dentry_delete, |
1175 | .d_iput = nfs_dentry_iput, | 1175 | .d_iput = nfs_dentry_iput, |
1176 | .d_automount = nfs_d_automount, | ||
1176 | }; | 1177 | }; |
1177 | 1178 | ||
1178 | static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd) | 1179 | static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd) |
@@ -1192,8 +1193,6 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru | |||
1192 | if (dentry->d_name.len > NFS_SERVER(dir)->namelen) | 1193 | if (dentry->d_name.len > NFS_SERVER(dir)->namelen) |
1193 | goto out; | 1194 | goto out; |
1194 | 1195 | ||
1195 | d_set_d_op(dentry, NFS_PROTO(dir)->dentry_ops); | ||
1196 | |||
1197 | /* | 1196 | /* |
1198 | * If we're doing an exclusive create, optimize away the lookup | 1197 | * If we're doing an exclusive create, optimize away the lookup |
1199 | * but don't hash the dentry. | 1198 | * but don't hash the dentry. |
@@ -1221,7 +1220,7 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru | |||
1221 | goto out_unblock_sillyrename; | 1220 | goto out_unblock_sillyrename; |
1222 | } | 1221 | } |
1223 | inode = nfs_fhget(dentry->d_sb, fhandle, fattr); | 1222 | inode = nfs_fhget(dentry->d_sb, fhandle, fattr); |
1224 | res = (struct dentry *)inode; | 1223 | res = ERR_CAST(inode); |
1225 | if (IS_ERR(res)) | 1224 | if (IS_ERR(res)) |
1226 | goto out_unblock_sillyrename; | 1225 | goto out_unblock_sillyrename; |
1227 | 1226 | ||
@@ -1248,6 +1247,7 @@ const struct dentry_operations nfs4_dentry_operations = { | |||
1248 | .d_revalidate = nfs_open_revalidate, | 1247 | .d_revalidate = nfs_open_revalidate, |
1249 | .d_delete = nfs_dentry_delete, | 1248 | .d_delete = nfs_dentry_delete, |
1250 | .d_iput = nfs_dentry_iput, | 1249 | .d_iput = nfs_dentry_iput, |
1250 | .d_automount = nfs_d_automount, | ||
1251 | }; | 1251 | }; |
1252 | 1252 | ||
1253 | /* | 1253 | /* |
@@ -1337,7 +1337,6 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry | |||
1337 | res = ERR_PTR(-ENAMETOOLONG); | 1337 | res = ERR_PTR(-ENAMETOOLONG); |
1338 | goto out; | 1338 | goto out; |
1339 | } | 1339 | } |
1340 | d_set_d_op(dentry, NFS_PROTO(dir)->dentry_ops); | ||
1341 | 1340 | ||
1342 | /* Let vfs_create() deal with O_EXCL. Instantiate, but don't hash | 1341 | /* Let vfs_create() deal with O_EXCL. Instantiate, but don't hash |
1343 | * the dentry. */ | 1342 | * the dentry. */ |
@@ -1355,8 +1354,7 @@ static struct dentry *nfs_atomic_lookup(struct inode *dir, struct dentry *dentry | |||
1355 | if (nd->flags & LOOKUP_CREATE) { | 1354 | if (nd->flags & LOOKUP_CREATE) { |
1356 | attr.ia_mode = nd->intent.open.create_mode; | 1355 | attr.ia_mode = nd->intent.open.create_mode; |
1357 | attr.ia_valid = ATTR_MODE; | 1356 | attr.ia_valid = ATTR_MODE; |
1358 | if (!IS_POSIXACL(dir)) | 1357 | attr.ia_mode &= ~current_umask(); |
1359 | attr.ia_mode &= ~current_umask(); | ||
1360 | } else { | 1358 | } else { |
1361 | open_flags &= ~(O_EXCL | O_CREAT); | 1359 | open_flags &= ~(O_EXCL | O_CREAT); |
1362 | attr.ia_valid = 0; | 1360 | attr.ia_valid = 0; |
@@ -1410,11 +1408,15 @@ no_open: | |||
1410 | static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd) | 1408 | static int nfs_open_revalidate(struct dentry *dentry, struct nameidata *nd) |
1411 | { | 1409 | { |
1412 | struct dentry *parent = NULL; | 1410 | struct dentry *parent = NULL; |
1413 | struct inode *inode = dentry->d_inode; | 1411 | struct inode *inode; |
1414 | struct inode *dir; | 1412 | struct inode *dir; |
1415 | struct nfs_open_context *ctx; | 1413 | struct nfs_open_context *ctx; |
1416 | int openflags, ret = 0; | 1414 | int openflags, ret = 0; |
1417 | 1415 | ||
1416 | if (nd->flags & LOOKUP_RCU) | ||
1417 | return -ECHILD; | ||
1418 | |||
1419 | inode = dentry->d_inode; | ||
1418 | if (!is_atomic_open(nd) || d_mountpoint(dentry)) | 1420 | if (!is_atomic_open(nd) || d_mountpoint(dentry)) |
1419 | goto no_open; | 1421 | goto no_open; |
1420 | 1422 | ||
@@ -1583,6 +1585,7 @@ static int nfs_create(struct inode *dir, struct dentry *dentry, int mode, | |||
1583 | { | 1585 | { |
1584 | struct iattr attr; | 1586 | struct iattr attr; |
1585 | int error; | 1587 | int error; |
1588 | int open_flags = 0; | ||
1586 | 1589 | ||
1587 | dfprintk(VFS, "NFS: create(%s/%ld), %s\n", | 1590 | dfprintk(VFS, "NFS: create(%s/%ld), %s\n", |
1588 | dir->i_sb->s_id, dir->i_ino, dentry->d_name.name); | 1591 | dir->i_sb->s_id, dir->i_ino, dentry->d_name.name); |
@@ -1590,7 +1593,10 @@ static int nfs_create(struct inode *dir, struct dentry *dentry, int mode, | |||
1590 | attr.ia_mode = mode; | 1593 | attr.ia_mode = mode; |
1591 | attr.ia_valid = ATTR_MODE; | 1594 | attr.ia_valid = ATTR_MODE; |
1592 | 1595 | ||
1593 | error = NFS_PROTO(dir)->create(dir, dentry, &attr, 0, NULL); | 1596 | if ((nd->flags & LOOKUP_CREATE) != 0) |
1597 | open_flags = nd->intent.open.flags; | ||
1598 | |||
1599 | error = NFS_PROTO(dir)->create(dir, dentry, &attr, open_flags, NULL); | ||
1594 | if (error != 0) | 1600 | if (error != 0) |
1595 | goto out_err; | 1601 | goto out_err; |
1596 | return 0; | 1602 | return 0; |
diff --git a/fs/nfs/getroot.c b/fs/nfs/getroot.c index 5596c6a2881e..b5ffe8fa291f 100644 --- a/fs/nfs/getroot.c +++ b/fs/nfs/getroot.c | |||
@@ -119,9 +119,6 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh) | |||
119 | } | 119 | } |
120 | 120 | ||
121 | security_d_instantiate(ret, inode); | 121 | security_d_instantiate(ret, inode); |
122 | |||
123 | if (ret->d_op == NULL) | ||
124 | d_set_d_op(ret, server->nfs_client->rpc_ops->dentry_ops); | ||
125 | out: | 122 | out: |
126 | nfs_free_fattr(fsinfo.fattr); | 123 | nfs_free_fattr(fsinfo.fattr); |
127 | return ret; | 124 | return ret; |
@@ -227,9 +224,6 @@ struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh) | |||
227 | 224 | ||
228 | security_d_instantiate(ret, inode); | 225 | security_d_instantiate(ret, inode); |
229 | 226 | ||
230 | if (ret->d_op == NULL) | ||
231 | d_set_d_op(ret, server->nfs_client->rpc_ops->dentry_ops); | ||
232 | |||
233 | out: | 227 | out: |
234 | nfs_free_fattr(fattr); | 228 | nfs_free_fattr(fattr); |
235 | dprintk("<-- nfs4_get_root()\n"); | 229 | dprintk("<-- nfs4_get_root()\n"); |
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c index 4e2d9b6b1380..18696882f1c6 100644 --- a/fs/nfs/idmap.c +++ b/fs/nfs/idmap.c | |||
@@ -238,7 +238,7 @@ int nfs_map_gid_to_group(struct nfs_client *clp, __u32 gid, char *buf, size_t bu | |||
238 | return nfs_idmap_lookup_name(gid, "group", buf, buflen); | 238 | return nfs_idmap_lookup_name(gid, "group", buf, buflen); |
239 | } | 239 | } |
240 | 240 | ||
241 | #else /* CONFIG_NFS_USE_IDMAPPER not defined */ | 241 | #else /* CONFIG_NFS_USE_NEW_IDMAPPER not defined */ |
242 | 242 | ||
243 | #include <linux/module.h> | 243 | #include <linux/module.h> |
244 | #include <linux/mutex.h> | 244 | #include <linux/mutex.h> |
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 017daa3bed38..d8512423ba72 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c | |||
@@ -300,7 +300,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr) | |||
300 | else | 300 | else |
301 | inode->i_op = &nfs_mountpoint_inode_operations; | 301 | inode->i_op = &nfs_mountpoint_inode_operations; |
302 | inode->i_fop = NULL; | 302 | inode->i_fop = NULL; |
303 | set_bit(NFS_INO_MOUNTPOINT, &nfsi->flags); | 303 | inode->i_flags |= S_AUTOMOUNT; |
304 | } | 304 | } |
305 | } else if (S_ISLNK(inode->i_mode)) | 305 | } else if (S_ISLNK(inode->i_mode)) |
306 | inode->i_op = &nfs_symlink_inode_operations; | 306 | inode->i_op = &nfs_symlink_inode_operations; |
@@ -1208,7 +1208,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1208 | /* Update the fsid? */ | 1208 | /* Update the fsid? */ |
1209 | if (S_ISDIR(inode->i_mode) && (fattr->valid & NFS_ATTR_FATTR_FSID) && | 1209 | if (S_ISDIR(inode->i_mode) && (fattr->valid & NFS_ATTR_FATTR_FSID) && |
1210 | !nfs_fsid_equal(&server->fsid, &fattr->fsid) && | 1210 | !nfs_fsid_equal(&server->fsid, &fattr->fsid) && |
1211 | !test_bit(NFS_INO_MOUNTPOINT, &nfsi->flags)) | 1211 | !IS_AUTOMOUNT(inode)) |
1212 | server->fsid = fattr->fsid; | 1212 | server->fsid = fattr->fsid; |
1213 | 1213 | ||
1214 | /* | 1214 | /* |
@@ -1410,9 +1410,9 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1410 | */ | 1410 | */ |
1411 | void nfs4_evict_inode(struct inode *inode) | 1411 | void nfs4_evict_inode(struct inode *inode) |
1412 | { | 1412 | { |
1413 | pnfs_destroy_layout(NFS_I(inode)); | ||
1413 | truncate_inode_pages(&inode->i_data, 0); | 1414 | truncate_inode_pages(&inode->i_data, 0); |
1414 | end_writeback(inode); | 1415 | end_writeback(inode); |
1415 | pnfs_destroy_layout(NFS_I(inode)); | ||
1416 | /* If we are holding a delegation, return it! */ | 1416 | /* If we are holding a delegation, return it! */ |
1417 | nfs_inode_return_delegation_noreclaim(inode); | 1417 | nfs_inode_return_delegation_noreclaim(inode); |
1418 | /* First call standard NFS clear_inode() code */ | 1418 | /* First call standard NFS clear_inode() code */ |
@@ -1619,6 +1619,7 @@ static void __exit exit_nfs_fs(void) | |||
1619 | #ifdef CONFIG_PROC_FS | 1619 | #ifdef CONFIG_PROC_FS |
1620 | rpc_proc_unregister("nfs"); | 1620 | rpc_proc_unregister("nfs"); |
1621 | #endif | 1621 | #endif |
1622 | nfs_cleanup_cb_ident_idr(); | ||
1622 | unregister_nfs_fs(); | 1623 | unregister_nfs_fs(); |
1623 | nfs_fs_proc_exit(); | 1624 | nfs_fs_proc_exit(); |
1624 | nfsiod_stop(); | 1625 | nfsiod_stop(); |
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index e6356b750b77..4644f04b4b46 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h | |||
@@ -128,9 +128,13 @@ extern void nfs_umount(const struct nfs_mount_request *info); | |||
128 | /* client.c */ | 128 | /* client.c */ |
129 | extern struct rpc_program nfs_program; | 129 | extern struct rpc_program nfs_program; |
130 | 130 | ||
131 | extern void nfs_cleanup_cb_ident_idr(void); | ||
131 | extern void nfs_put_client(struct nfs_client *); | 132 | extern void nfs_put_client(struct nfs_client *); |
132 | extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32); | 133 | extern struct nfs_client *nfs4_find_client_no_ident(const struct sockaddr *); |
133 | extern struct nfs_client *nfs_find_client_next(struct nfs_client *); | 134 | extern struct nfs_client *nfs4_find_client_ident(int); |
135 | extern struct nfs_client * | ||
136 | nfs4_find_client_sessionid(const struct sockaddr *, struct nfs4_sessionid *, | ||
137 | int); | ||
134 | extern struct nfs_server *nfs_create_server( | 138 | extern struct nfs_server *nfs_create_server( |
135 | const struct nfs_parsed_mount_data *, | 139 | const struct nfs_parsed_mount_data *, |
136 | struct nfs_fh *); | 140 | struct nfs_fh *); |
@@ -185,17 +189,20 @@ extern int __init nfs_init_directcache(void); | |||
185 | extern void nfs_destroy_directcache(void); | 189 | extern void nfs_destroy_directcache(void); |
186 | 190 | ||
187 | /* nfs2xdr.c */ | 191 | /* nfs2xdr.c */ |
188 | extern int nfs_stat_to_errno(int); | 192 | extern int nfs_stat_to_errno(enum nfs_stat); |
189 | extern struct rpc_procinfo nfs_procedures[]; | 193 | extern struct rpc_procinfo nfs_procedures[]; |
190 | extern __be32 *nfs_decode_dirent(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int); | 194 | extern int nfs2_decode_dirent(struct xdr_stream *, |
195 | struct nfs_entry *, int); | ||
191 | 196 | ||
192 | /* nfs3xdr.c */ | 197 | /* nfs3xdr.c */ |
193 | extern struct rpc_procinfo nfs3_procedures[]; | 198 | extern struct rpc_procinfo nfs3_procedures[]; |
194 | extern __be32 *nfs3_decode_dirent(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int); | 199 | extern int nfs3_decode_dirent(struct xdr_stream *, |
200 | struct nfs_entry *, int); | ||
195 | 201 | ||
196 | /* nfs4xdr.c */ | 202 | /* nfs4xdr.c */ |
197 | #ifdef CONFIG_NFS_V4 | 203 | #ifdef CONFIG_NFS_V4 |
198 | extern __be32 *nfs4_decode_dirent(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int); | 204 | extern int nfs4_decode_dirent(struct xdr_stream *, |
205 | struct nfs_entry *, int); | ||
199 | #endif | 206 | #endif |
200 | #ifdef CONFIG_NFS_V4_1 | 207 | #ifdef CONFIG_NFS_V4_1 |
201 | extern const u32 nfs41_maxread_overhead; | 208 | extern const u32 nfs41_maxread_overhead; |
@@ -245,6 +252,7 @@ extern char *nfs_path(const char *base, | |||
245 | const struct dentry *droot, | 252 | const struct dentry *droot, |
246 | const struct dentry *dentry, | 253 | const struct dentry *dentry, |
247 | char *buffer, ssize_t buflen); | 254 | char *buffer, ssize_t buflen); |
255 | extern struct vfsmount *nfs_d_automount(struct path *path); | ||
248 | 256 | ||
249 | /* getroot.c */ | 257 | /* getroot.c */ |
250 | extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *); | 258 | extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *); |
diff --git a/fs/nfs/mount_clnt.c b/fs/nfs/mount_clnt.c index 4f981f1f6689..d4c2d6b7507e 100644 --- a/fs/nfs/mount_clnt.c +++ b/fs/nfs/mount_clnt.c | |||
@@ -236,10 +236,8 @@ void nfs_umount(const struct nfs_mount_request *info) | |||
236 | .authflavor = RPC_AUTH_UNIX, | 236 | .authflavor = RPC_AUTH_UNIX, |
237 | .flags = RPC_CLNT_CREATE_NOPING, | 237 | .flags = RPC_CLNT_CREATE_NOPING, |
238 | }; | 238 | }; |
239 | struct mountres result; | ||
240 | struct rpc_message msg = { | 239 | struct rpc_message msg = { |
241 | .rpc_argp = info->dirpath, | 240 | .rpc_argp = info->dirpath, |
242 | .rpc_resp = &result, | ||
243 | }; | 241 | }; |
244 | struct rpc_clnt *clnt; | 242 | struct rpc_clnt *clnt; |
245 | int status; | 243 | int status; |
@@ -248,7 +246,7 @@ void nfs_umount(const struct nfs_mount_request *info) | |||
248 | args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; | 246 | args.flags |= RPC_CLNT_CREATE_NONPRIVPORT; |
249 | 247 | ||
250 | clnt = rpc_create(&args); | 248 | clnt = rpc_create(&args); |
251 | if (unlikely(IS_ERR(clnt))) | 249 | if (IS_ERR(clnt)) |
252 | goto out_clnt_err; | 250 | goto out_clnt_err; |
253 | 251 | ||
254 | dprintk("NFS: sending UMNT request for %s:%s\n", | 252 | dprintk("NFS: sending UMNT request for %s:%s\n", |
@@ -280,29 +278,20 @@ out_call_err: | |||
280 | * XDR encode/decode functions for MOUNT | 278 | * XDR encode/decode functions for MOUNT |
281 | */ | 279 | */ |
282 | 280 | ||
283 | static int encode_mntdirpath(struct xdr_stream *xdr, const char *pathname) | 281 | static void encode_mntdirpath(struct xdr_stream *xdr, const char *pathname) |
284 | { | 282 | { |
285 | const u32 pathname_len = strlen(pathname); | 283 | const u32 pathname_len = strlen(pathname); |
286 | __be32 *p; | 284 | __be32 *p; |
287 | 285 | ||
288 | if (unlikely(pathname_len > MNTPATHLEN)) | 286 | BUG_ON(pathname_len > MNTPATHLEN); |
289 | return -EIO; | 287 | p = xdr_reserve_space(xdr, 4 + pathname_len); |
290 | |||
291 | p = xdr_reserve_space(xdr, sizeof(u32) + pathname_len); | ||
292 | if (unlikely(p == NULL)) | ||
293 | return -EIO; | ||
294 | xdr_encode_opaque(p, pathname, pathname_len); | 288 | xdr_encode_opaque(p, pathname, pathname_len); |
295 | |||
296 | return 0; | ||
297 | } | 289 | } |
298 | 290 | ||
299 | static int mnt_enc_dirpath(struct rpc_rqst *req, __be32 *p, | 291 | static void mnt_xdr_enc_dirpath(struct rpc_rqst *req, struct xdr_stream *xdr, |
300 | const char *dirpath) | 292 | const char *dirpath) |
301 | { | 293 | { |
302 | struct xdr_stream xdr; | 294 | encode_mntdirpath(xdr, dirpath); |
303 | |||
304 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | ||
305 | return encode_mntdirpath(&xdr, dirpath); | ||
306 | } | 295 | } |
307 | 296 | ||
308 | /* | 297 | /* |
@@ -320,10 +309,10 @@ static int decode_status(struct xdr_stream *xdr, struct mountres *res) | |||
320 | u32 status; | 309 | u32 status; |
321 | __be32 *p; | 310 | __be32 *p; |
322 | 311 | ||
323 | p = xdr_inline_decode(xdr, sizeof(status)); | 312 | p = xdr_inline_decode(xdr, 4); |
324 | if (unlikely(p == NULL)) | 313 | if (unlikely(p == NULL)) |
325 | return -EIO; | 314 | return -EIO; |
326 | status = ntohl(*p); | 315 | status = be32_to_cpup(p); |
327 | 316 | ||
328 | for (i = 0; i < ARRAY_SIZE(mnt_errtbl); i++) { | 317 | for (i = 0; i < ARRAY_SIZE(mnt_errtbl); i++) { |
329 | if (mnt_errtbl[i].status == status) { | 318 | if (mnt_errtbl[i].status == status) { |
@@ -351,18 +340,16 @@ static int decode_fhandle(struct xdr_stream *xdr, struct mountres *res) | |||
351 | return 0; | 340 | return 0; |
352 | } | 341 | } |
353 | 342 | ||
354 | static int mnt_dec_mountres(struct rpc_rqst *req, __be32 *p, | 343 | static int mnt_xdr_dec_mountres(struct rpc_rqst *req, |
355 | struct mountres *res) | 344 | struct xdr_stream *xdr, |
345 | struct mountres *res) | ||
356 | { | 346 | { |
357 | struct xdr_stream xdr; | ||
358 | int status; | 347 | int status; |
359 | 348 | ||
360 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | 349 | status = decode_status(xdr, res); |
361 | |||
362 | status = decode_status(&xdr, res); | ||
363 | if (unlikely(status != 0 || res->errno != 0)) | 350 | if (unlikely(status != 0 || res->errno != 0)) |
364 | return status; | 351 | return status; |
365 | return decode_fhandle(&xdr, res); | 352 | return decode_fhandle(xdr, res); |
366 | } | 353 | } |
367 | 354 | ||
368 | static int decode_fhs_status(struct xdr_stream *xdr, struct mountres *res) | 355 | static int decode_fhs_status(struct xdr_stream *xdr, struct mountres *res) |
@@ -371,10 +358,10 @@ static int decode_fhs_status(struct xdr_stream *xdr, struct mountres *res) | |||
371 | u32 status; | 358 | u32 status; |
372 | __be32 *p; | 359 | __be32 *p; |
373 | 360 | ||
374 | p = xdr_inline_decode(xdr, sizeof(status)); | 361 | p = xdr_inline_decode(xdr, 4); |
375 | if (unlikely(p == NULL)) | 362 | if (unlikely(p == NULL)) |
376 | return -EIO; | 363 | return -EIO; |
377 | status = ntohl(*p); | 364 | status = be32_to_cpup(p); |
378 | 365 | ||
379 | for (i = 0; i < ARRAY_SIZE(mnt3_errtbl); i++) { | 366 | for (i = 0; i < ARRAY_SIZE(mnt3_errtbl); i++) { |
380 | if (mnt3_errtbl[i].status == status) { | 367 | if (mnt3_errtbl[i].status == status) { |
@@ -394,11 +381,11 @@ static int decode_fhandle3(struct xdr_stream *xdr, struct mountres *res) | |||
394 | u32 size; | 381 | u32 size; |
395 | __be32 *p; | 382 | __be32 *p; |
396 | 383 | ||
397 | p = xdr_inline_decode(xdr, sizeof(size)); | 384 | p = xdr_inline_decode(xdr, 4); |
398 | if (unlikely(p == NULL)) | 385 | if (unlikely(p == NULL)) |
399 | return -EIO; | 386 | return -EIO; |
400 | 387 | ||
401 | size = ntohl(*p++); | 388 | size = be32_to_cpup(p); |
402 | if (size > NFS3_FHSIZE || size == 0) | 389 | if (size > NFS3_FHSIZE || size == 0) |
403 | return -EIO; | 390 | return -EIO; |
404 | 391 | ||
@@ -421,15 +408,15 @@ static int decode_auth_flavors(struct xdr_stream *xdr, struct mountres *res) | |||
421 | if (*count == 0) | 408 | if (*count == 0) |
422 | return 0; | 409 | return 0; |
423 | 410 | ||
424 | p = xdr_inline_decode(xdr, sizeof(entries)); | 411 | p = xdr_inline_decode(xdr, 4); |
425 | if (unlikely(p == NULL)) | 412 | if (unlikely(p == NULL)) |
426 | return -EIO; | 413 | return -EIO; |
427 | entries = ntohl(*p); | 414 | entries = be32_to_cpup(p); |
428 | dprintk("NFS: received %u auth flavors\n", entries); | 415 | dprintk("NFS: received %u auth flavors\n", entries); |
429 | if (entries > NFS_MAX_SECFLAVORS) | 416 | if (entries > NFS_MAX_SECFLAVORS) |
430 | entries = NFS_MAX_SECFLAVORS; | 417 | entries = NFS_MAX_SECFLAVORS; |
431 | 418 | ||
432 | p = xdr_inline_decode(xdr, sizeof(u32) * entries); | 419 | p = xdr_inline_decode(xdr, 4 * entries); |
433 | if (unlikely(p == NULL)) | 420 | if (unlikely(p == NULL)) |
434 | return -EIO; | 421 | return -EIO; |
435 | 422 | ||
@@ -437,7 +424,7 @@ static int decode_auth_flavors(struct xdr_stream *xdr, struct mountres *res) | |||
437 | entries = *count; | 424 | entries = *count; |
438 | 425 | ||
439 | for (i = 0; i < entries; i++) { | 426 | for (i = 0; i < entries; i++) { |
440 | flavors[i] = ntohl(*p++); | 427 | flavors[i] = be32_to_cpup(p++); |
441 | dprintk("NFS: auth flavor[%u]: %d\n", i, flavors[i]); | 428 | dprintk("NFS: auth flavor[%u]: %d\n", i, flavors[i]); |
442 | } | 429 | } |
443 | *count = i; | 430 | *count = i; |
@@ -445,30 +432,28 @@ static int decode_auth_flavors(struct xdr_stream *xdr, struct mountres *res) | |||
445 | return 0; | 432 | return 0; |
446 | } | 433 | } |
447 | 434 | ||
448 | static int mnt_dec_mountres3(struct rpc_rqst *req, __be32 *p, | 435 | static int mnt_xdr_dec_mountres3(struct rpc_rqst *req, |
449 | struct mountres *res) | 436 | struct xdr_stream *xdr, |
437 | struct mountres *res) | ||
450 | { | 438 | { |
451 | struct xdr_stream xdr; | ||
452 | int status; | 439 | int status; |
453 | 440 | ||
454 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | 441 | status = decode_fhs_status(xdr, res); |
455 | |||
456 | status = decode_fhs_status(&xdr, res); | ||
457 | if (unlikely(status != 0 || res->errno != 0)) | 442 | if (unlikely(status != 0 || res->errno != 0)) |
458 | return status; | 443 | return status; |
459 | status = decode_fhandle3(&xdr, res); | 444 | status = decode_fhandle3(xdr, res); |
460 | if (unlikely(status != 0)) { | 445 | if (unlikely(status != 0)) { |
461 | res->errno = -EBADHANDLE; | 446 | res->errno = -EBADHANDLE; |
462 | return 0; | 447 | return 0; |
463 | } | 448 | } |
464 | return decode_auth_flavors(&xdr, res); | 449 | return decode_auth_flavors(xdr, res); |
465 | } | 450 | } |
466 | 451 | ||
467 | static struct rpc_procinfo mnt_procedures[] = { | 452 | static struct rpc_procinfo mnt_procedures[] = { |
468 | [MOUNTPROC_MNT] = { | 453 | [MOUNTPROC_MNT] = { |
469 | .p_proc = MOUNTPROC_MNT, | 454 | .p_proc = MOUNTPROC_MNT, |
470 | .p_encode = (kxdrproc_t)mnt_enc_dirpath, | 455 | .p_encode = (kxdreproc_t)mnt_xdr_enc_dirpath, |
471 | .p_decode = (kxdrproc_t)mnt_dec_mountres, | 456 | .p_decode = (kxdrdproc_t)mnt_xdr_dec_mountres, |
472 | .p_arglen = MNT_enc_dirpath_sz, | 457 | .p_arglen = MNT_enc_dirpath_sz, |
473 | .p_replen = MNT_dec_mountres_sz, | 458 | .p_replen = MNT_dec_mountres_sz, |
474 | .p_statidx = MOUNTPROC_MNT, | 459 | .p_statidx = MOUNTPROC_MNT, |
@@ -476,7 +461,7 @@ static struct rpc_procinfo mnt_procedures[] = { | |||
476 | }, | 461 | }, |
477 | [MOUNTPROC_UMNT] = { | 462 | [MOUNTPROC_UMNT] = { |
478 | .p_proc = MOUNTPROC_UMNT, | 463 | .p_proc = MOUNTPROC_UMNT, |
479 | .p_encode = (kxdrproc_t)mnt_enc_dirpath, | 464 | .p_encode = (kxdreproc_t)mnt_xdr_enc_dirpath, |
480 | .p_arglen = MNT_enc_dirpath_sz, | 465 | .p_arglen = MNT_enc_dirpath_sz, |
481 | .p_statidx = MOUNTPROC_UMNT, | 466 | .p_statidx = MOUNTPROC_UMNT, |
482 | .p_name = "UMOUNT", | 467 | .p_name = "UMOUNT", |
@@ -486,8 +471,8 @@ static struct rpc_procinfo mnt_procedures[] = { | |||
486 | static struct rpc_procinfo mnt3_procedures[] = { | 471 | static struct rpc_procinfo mnt3_procedures[] = { |
487 | [MOUNTPROC3_MNT] = { | 472 | [MOUNTPROC3_MNT] = { |
488 | .p_proc = MOUNTPROC3_MNT, | 473 | .p_proc = MOUNTPROC3_MNT, |
489 | .p_encode = (kxdrproc_t)mnt_enc_dirpath, | 474 | .p_encode = (kxdreproc_t)mnt_xdr_enc_dirpath, |
490 | .p_decode = (kxdrproc_t)mnt_dec_mountres3, | 475 | .p_decode = (kxdrdproc_t)mnt_xdr_dec_mountres3, |
491 | .p_arglen = MNT_enc_dirpath_sz, | 476 | .p_arglen = MNT_enc_dirpath_sz, |
492 | .p_replen = MNT_dec_mountres3_sz, | 477 | .p_replen = MNT_dec_mountres3_sz, |
493 | .p_statidx = MOUNTPROC3_MNT, | 478 | .p_statidx = MOUNTPROC3_MNT, |
@@ -495,7 +480,7 @@ static struct rpc_procinfo mnt3_procedures[] = { | |||
495 | }, | 480 | }, |
496 | [MOUNTPROC3_UMNT] = { | 481 | [MOUNTPROC3_UMNT] = { |
497 | .p_proc = MOUNTPROC3_UMNT, | 482 | .p_proc = MOUNTPROC3_UMNT, |
498 | .p_encode = (kxdrproc_t)mnt_enc_dirpath, | 483 | .p_encode = (kxdreproc_t)mnt_xdr_enc_dirpath, |
499 | .p_arglen = MNT_enc_dirpath_sz, | 484 | .p_arglen = MNT_enc_dirpath_sz, |
500 | .p_statidx = MOUNTPROC3_UMNT, | 485 | .p_statidx = MOUNTPROC3_UMNT, |
501 | .p_name = "UMOUNT", | 486 | .p_name = "UMOUNT", |
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c index 74aaf3963c10..f32b8603dca8 100644 --- a/fs/nfs/namespace.c +++ b/fs/nfs/namespace.c | |||
@@ -97,9 +97,8 @@ Elong: | |||
97 | } | 97 | } |
98 | 98 | ||
99 | /* | 99 | /* |
100 | * nfs_follow_mountpoint - handle crossing a mountpoint on the server | 100 | * nfs_d_automount - Handle crossing a mountpoint on the server |
101 | * @dentry - dentry of mountpoint | 101 | * @path - The mountpoint |
102 | * @nd - nameidata info | ||
103 | * | 102 | * |
104 | * When we encounter a mountpoint on the server, we want to set up | 103 | * When we encounter a mountpoint on the server, we want to set up |
105 | * a mountpoint on the client too, to prevent inode numbers from | 104 | * a mountpoint on the client too, to prevent inode numbers from |
@@ -109,87 +108,65 @@ Elong: | |||
109 | * situation, and that different filesystems may want to use | 108 | * situation, and that different filesystems may want to use |
110 | * different security flavours. | 109 | * different security flavours. |
111 | */ | 110 | */ |
112 | static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd) | 111 | struct vfsmount *nfs_d_automount(struct path *path) |
113 | { | 112 | { |
114 | struct vfsmount *mnt; | 113 | struct vfsmount *mnt; |
115 | struct nfs_server *server = NFS_SERVER(dentry->d_inode); | 114 | struct nfs_server *server = NFS_SERVER(path->dentry->d_inode); |
116 | struct dentry *parent; | 115 | struct dentry *parent; |
117 | struct nfs_fh *fh = NULL; | 116 | struct nfs_fh *fh = NULL; |
118 | struct nfs_fattr *fattr = NULL; | 117 | struct nfs_fattr *fattr = NULL; |
119 | int err; | 118 | int err; |
120 | 119 | ||
121 | dprintk("--> nfs_follow_mountpoint()\n"); | 120 | dprintk("--> nfs_d_automount()\n"); |
122 | 121 | ||
123 | err = -ESTALE; | 122 | mnt = ERR_PTR(-ESTALE); |
124 | if (IS_ROOT(dentry)) | 123 | if (IS_ROOT(path->dentry)) |
125 | goto out_err; | 124 | goto out_nofree; |
126 | 125 | ||
127 | err = -ENOMEM; | 126 | mnt = ERR_PTR(-ENOMEM); |
128 | fh = nfs_alloc_fhandle(); | 127 | fh = nfs_alloc_fhandle(); |
129 | fattr = nfs_alloc_fattr(); | 128 | fattr = nfs_alloc_fattr(); |
130 | if (fh == NULL || fattr == NULL) | 129 | if (fh == NULL || fattr == NULL) |
131 | goto out_err; | 130 | goto out; |
132 | 131 | ||
133 | dprintk("%s: enter\n", __func__); | 132 | dprintk("%s: enter\n", __func__); |
134 | dput(nd->path.dentry); | ||
135 | nd->path.dentry = dget(dentry); | ||
136 | 133 | ||
137 | /* Look it up again */ | 134 | /* Look it up again to get its attributes */ |
138 | parent = dget_parent(nd->path.dentry); | 135 | parent = dget_parent(path->dentry); |
139 | err = server->nfs_client->rpc_ops->lookup(parent->d_inode, | 136 | err = server->nfs_client->rpc_ops->lookup(parent->d_inode, |
140 | &nd->path.dentry->d_name, | 137 | &path->dentry->d_name, |
141 | fh, fattr); | 138 | fh, fattr); |
142 | dput(parent); | 139 | dput(parent); |
143 | if (err != 0) | 140 | if (err != 0) { |
144 | goto out_err; | 141 | mnt = ERR_PTR(err); |
142 | goto out; | ||
143 | } | ||
145 | 144 | ||
146 | if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) | 145 | if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) |
147 | mnt = nfs_do_refmount(nd->path.mnt, nd->path.dentry); | 146 | mnt = nfs_do_refmount(path->mnt, path->dentry); |
148 | else | 147 | else |
149 | mnt = nfs_do_submount(nd->path.mnt, nd->path.dentry, fh, | 148 | mnt = nfs_do_submount(path->mnt, path->dentry, fh, fattr); |
150 | fattr); | ||
151 | err = PTR_ERR(mnt); | ||
152 | if (IS_ERR(mnt)) | 149 | if (IS_ERR(mnt)) |
153 | goto out_err; | 150 | goto out; |
154 | 151 | ||
155 | mntget(mnt); | 152 | dprintk("%s: done, success\n", __func__); |
156 | err = do_add_mount(mnt, &nd->path, nd->path.mnt->mnt_flags|MNT_SHRINKABLE, | 153 | mntget(mnt); /* prevent immediate expiration */ |
157 | &nfs_automount_list); | 154 | mnt_set_expiry(mnt, &nfs_automount_list); |
158 | if (err < 0) { | ||
159 | mntput(mnt); | ||
160 | if (err == -EBUSY) | ||
161 | goto out_follow; | ||
162 | goto out_err; | ||
163 | } | ||
164 | path_put(&nd->path); | ||
165 | nd->path.mnt = mnt; | ||
166 | nd->path.dentry = dget(mnt->mnt_root); | ||
167 | schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); | 155 | schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout); |
156 | |||
168 | out: | 157 | out: |
169 | nfs_free_fattr(fattr); | 158 | nfs_free_fattr(fattr); |
170 | nfs_free_fhandle(fh); | 159 | nfs_free_fhandle(fh); |
171 | dprintk("%s: done, returned %d\n", __func__, err); | 160 | out_nofree: |
172 | 161 | dprintk("<-- nfs_follow_mountpoint() = %p\n", mnt); | |
173 | dprintk("<-- nfs_follow_mountpoint() = %d\n", err); | 162 | return mnt; |
174 | return ERR_PTR(err); | ||
175 | out_err: | ||
176 | path_put(&nd->path); | ||
177 | goto out; | ||
178 | out_follow: | ||
179 | while (d_mountpoint(nd->path.dentry) && | ||
180 | follow_down(&nd->path)) | ||
181 | ; | ||
182 | err = 0; | ||
183 | goto out; | ||
184 | } | 163 | } |
185 | 164 | ||
186 | const struct inode_operations nfs_mountpoint_inode_operations = { | 165 | const struct inode_operations nfs_mountpoint_inode_operations = { |
187 | .follow_link = nfs_follow_mountpoint, | ||
188 | .getattr = nfs_getattr, | 166 | .getattr = nfs_getattr, |
189 | }; | 167 | }; |
190 | 168 | ||
191 | const struct inode_operations nfs_referral_inode_operations = { | 169 | const struct inode_operations nfs_referral_inode_operations = { |
192 | .follow_link = nfs_follow_mountpoint, | ||
193 | }; | 170 | }; |
194 | 171 | ||
195 | static void nfs_expire_automounts(struct work_struct *work) | 172 | static void nfs_expire_automounts(struct work_struct *work) |
diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c index 5914a1911c95..792cb13a4304 100644 --- a/fs/nfs/nfs2xdr.c +++ b/fs/nfs/nfs2xdr.c | |||
@@ -61,584 +61,1008 @@ | |||
61 | #define NFS_readdirres_sz (1) | 61 | #define NFS_readdirres_sz (1) |
62 | #define NFS_statfsres_sz (1+NFS_info_sz) | 62 | #define NFS_statfsres_sz (1+NFS_info_sz) |
63 | 63 | ||
64 | |||
64 | /* | 65 | /* |
65 | * Common NFS XDR functions as inlines | 66 | * While encoding arguments, set up the reply buffer in advance to |
67 | * receive reply data directly into the page cache. | ||
66 | */ | 68 | */ |
67 | static inline __be32 * | 69 | static void prepare_reply_buffer(struct rpc_rqst *req, struct page **pages, |
68 | xdr_encode_fhandle(__be32 *p, const struct nfs_fh *fhandle) | 70 | unsigned int base, unsigned int len, |
71 | unsigned int bufsize) | ||
69 | { | 72 | { |
70 | memcpy(p, fhandle->data, NFS2_FHSIZE); | 73 | struct rpc_auth *auth = req->rq_cred->cr_auth; |
71 | return p + XDR_QUADLEN(NFS2_FHSIZE); | 74 | unsigned int replen; |
75 | |||
76 | replen = RPC_REPHDRSIZE + auth->au_rslack + bufsize; | ||
77 | xdr_inline_pages(&req->rq_rcv_buf, replen << 2, pages, base, len); | ||
72 | } | 78 | } |
73 | 79 | ||
74 | static inline __be32 * | 80 | /* |
75 | xdr_decode_fhandle(__be32 *p, struct nfs_fh *fhandle) | 81 | * Handle decode buffer overflows out-of-line. |
82 | */ | ||
83 | static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) | ||
76 | { | 84 | { |
77 | /* NFSv2 handles have a fixed length */ | 85 | dprintk("NFS: %s prematurely hit the end of our receive buffer. " |
78 | fhandle->size = NFS2_FHSIZE; | 86 | "Remaining buffer length is %tu words.\n", |
79 | memcpy(fhandle->data, p, NFS2_FHSIZE); | 87 | func, xdr->end - xdr->p); |
80 | return p + XDR_QUADLEN(NFS2_FHSIZE); | 88 | } |
89 | |||
90 | |||
91 | /* | ||
92 | * Encode/decode NFSv2 basic data types | ||
93 | * | ||
94 | * Basic NFSv2 data types are defined in section 2.3 of RFC 1094: | ||
95 | * "NFS: Network File System Protocol Specification". | ||
96 | * | ||
97 | * Not all basic data types have their own encoding and decoding | ||
98 | * functions. For run-time efficiency, some data types are encoded | ||
99 | * or decoded inline. | ||
100 | */ | ||
101 | |||
102 | /* | ||
103 | * typedef opaque nfsdata<>; | ||
104 | */ | ||
105 | static int decode_nfsdata(struct xdr_stream *xdr, struct nfs_readres *result) | ||
106 | { | ||
107 | u32 recvd, count; | ||
108 | size_t hdrlen; | ||
109 | __be32 *p; | ||
110 | |||
111 | p = xdr_inline_decode(xdr, 4); | ||
112 | if (unlikely(p == NULL)) | ||
113 | goto out_overflow; | ||
114 | count = be32_to_cpup(p); | ||
115 | hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base; | ||
116 | recvd = xdr->buf->len - hdrlen; | ||
117 | if (unlikely(count > recvd)) | ||
118 | goto out_cheating; | ||
119 | out: | ||
120 | xdr_read_pages(xdr, count); | ||
121 | result->eof = 0; /* NFSv2 does not pass EOF flag on the wire. */ | ||
122 | result->count = count; | ||
123 | return count; | ||
124 | out_cheating: | ||
125 | dprintk("NFS: server cheating in read result: " | ||
126 | "count %u > recvd %u\n", count, recvd); | ||
127 | count = recvd; | ||
128 | goto out; | ||
129 | out_overflow: | ||
130 | print_overflow_msg(__func__, xdr); | ||
131 | return -EIO; | ||
132 | } | ||
133 | |||
134 | /* | ||
135 | * enum stat { | ||
136 | * NFS_OK = 0, | ||
137 | * NFSERR_PERM = 1, | ||
138 | * NFSERR_NOENT = 2, | ||
139 | * NFSERR_IO = 5, | ||
140 | * NFSERR_NXIO = 6, | ||
141 | * NFSERR_ACCES = 13, | ||
142 | * NFSERR_EXIST = 17, | ||
143 | * NFSERR_NODEV = 19, | ||
144 | * NFSERR_NOTDIR = 20, | ||
145 | * NFSERR_ISDIR = 21, | ||
146 | * NFSERR_FBIG = 27, | ||
147 | * NFSERR_NOSPC = 28, | ||
148 | * NFSERR_ROFS = 30, | ||
149 | * NFSERR_NAMETOOLONG = 63, | ||
150 | * NFSERR_NOTEMPTY = 66, | ||
151 | * NFSERR_DQUOT = 69, | ||
152 | * NFSERR_STALE = 70, | ||
153 | * NFSERR_WFLUSH = 99 | ||
154 | * }; | ||
155 | */ | ||
156 | static int decode_stat(struct xdr_stream *xdr, enum nfs_stat *status) | ||
157 | { | ||
158 | __be32 *p; | ||
159 | |||
160 | p = xdr_inline_decode(xdr, 4); | ||
161 | if (unlikely(p == NULL)) | ||
162 | goto out_overflow; | ||
163 | *status = be32_to_cpup(p); | ||
164 | return 0; | ||
165 | out_overflow: | ||
166 | print_overflow_msg(__func__, xdr); | ||
167 | return -EIO; | ||
81 | } | 168 | } |
82 | 169 | ||
83 | static inline __be32* | 170 | /* |
84 | xdr_encode_time(__be32 *p, struct timespec *timep) | 171 | * 2.3.2. ftype |
172 | * | ||
173 | * enum ftype { | ||
174 | * NFNON = 0, | ||
175 | * NFREG = 1, | ||
176 | * NFDIR = 2, | ||
177 | * NFBLK = 3, | ||
178 | * NFCHR = 4, | ||
179 | * NFLNK = 5 | ||
180 | * }; | ||
181 | * | ||
182 | */ | ||
183 | static __be32 *xdr_decode_ftype(__be32 *p, u32 *type) | ||
85 | { | 184 | { |
86 | *p++ = htonl(timep->tv_sec); | 185 | *type = be32_to_cpup(p++); |
87 | /* Convert nanoseconds into microseconds */ | 186 | if (unlikely(*type > NF2FIFO)) |
88 | *p++ = htonl(timep->tv_nsec ? timep->tv_nsec / 1000 : 0); | 187 | *type = NFBAD; |
89 | return p; | 188 | return p; |
90 | } | 189 | } |
91 | 190 | ||
92 | static inline __be32* | 191 | /* |
93 | xdr_encode_current_server_time(__be32 *p, struct timespec *timep) | 192 | * 2.3.3. fhandle |
193 | * | ||
194 | * typedef opaque fhandle[FHSIZE]; | ||
195 | */ | ||
196 | static void encode_fhandle(struct xdr_stream *xdr, const struct nfs_fh *fh) | ||
94 | { | 197 | { |
95 | /* | 198 | __be32 *p; |
96 | * Passing the invalid value useconds=1000000 is a | 199 | |
97 | * Sun convention for "set to current server time". | 200 | BUG_ON(fh->size != NFS2_FHSIZE); |
98 | * It's needed to make permissions checks for the | 201 | p = xdr_reserve_space(xdr, NFS2_FHSIZE); |
99 | * "touch" program across v2 mounts to Solaris and | 202 | memcpy(p, fh->data, NFS2_FHSIZE); |
100 | * Irix boxes work correctly. See description of | 203 | } |
101 | * sattr in section 6.1 of "NFS Illustrated" by | 204 | |
102 | * Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5 | 205 | static int decode_fhandle(struct xdr_stream *xdr, struct nfs_fh *fh) |
103 | */ | 206 | { |
104 | *p++ = htonl(timep->tv_sec); | 207 | __be32 *p; |
105 | *p++ = htonl(1000000); | 208 | |
209 | p = xdr_inline_decode(xdr, NFS2_FHSIZE); | ||
210 | if (unlikely(p == NULL)) | ||
211 | goto out_overflow; | ||
212 | fh->size = NFS2_FHSIZE; | ||
213 | memcpy(fh->data, p, NFS2_FHSIZE); | ||
214 | return 0; | ||
215 | out_overflow: | ||
216 | print_overflow_msg(__func__, xdr); | ||
217 | return -EIO; | ||
218 | } | ||
219 | |||
220 | /* | ||
221 | * 2.3.4. timeval | ||
222 | * | ||
223 | * struct timeval { | ||
224 | * unsigned int seconds; | ||
225 | * unsigned int useconds; | ||
226 | * }; | ||
227 | */ | ||
228 | static __be32 *xdr_encode_time(__be32 *p, const struct timespec *timep) | ||
229 | { | ||
230 | *p++ = cpu_to_be32(timep->tv_sec); | ||
231 | if (timep->tv_nsec != 0) | ||
232 | *p++ = cpu_to_be32(timep->tv_nsec / NSEC_PER_USEC); | ||
233 | else | ||
234 | *p++ = cpu_to_be32(0); | ||
106 | return p; | 235 | return p; |
107 | } | 236 | } |
108 | 237 | ||
109 | static inline __be32* | 238 | /* |
110 | xdr_decode_time(__be32 *p, struct timespec *timep) | 239 | * Passing the invalid value useconds=1000000 is a Sun convention for |
240 | * "set to current server time". It's needed to make permissions checks | ||
241 | * for the "touch" program across v2 mounts to Solaris and Irix servers | ||
242 | * work correctly. See description of sattr in section 6.1 of "NFS | ||
243 | * Illustrated" by Brent Callaghan, Addison-Wesley, ISBN 0-201-32750-5. | ||
244 | */ | ||
245 | static __be32 *xdr_encode_current_server_time(__be32 *p, | ||
246 | const struct timespec *timep) | ||
111 | { | 247 | { |
112 | timep->tv_sec = ntohl(*p++); | 248 | *p++ = cpu_to_be32(timep->tv_sec); |
113 | /* Convert microseconds into nanoseconds */ | 249 | *p++ = cpu_to_be32(1000000); |
114 | timep->tv_nsec = ntohl(*p++) * 1000; | ||
115 | return p; | 250 | return p; |
116 | } | 251 | } |
117 | 252 | ||
118 | static __be32 * | 253 | static __be32 *xdr_decode_time(__be32 *p, struct timespec *timep) |
119 | xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr) | 254 | { |
255 | timep->tv_sec = be32_to_cpup(p++); | ||
256 | timep->tv_nsec = be32_to_cpup(p++) * NSEC_PER_USEC; | ||
257 | return p; | ||
258 | } | ||
259 | |||
260 | /* | ||
261 | * 2.3.5. fattr | ||
262 | * | ||
263 | * struct fattr { | ||
264 | * ftype type; | ||
265 | * unsigned int mode; | ||
266 | * unsigned int nlink; | ||
267 | * unsigned int uid; | ||
268 | * unsigned int gid; | ||
269 | * unsigned int size; | ||
270 | * unsigned int blocksize; | ||
271 | * unsigned int rdev; | ||
272 | * unsigned int blocks; | ||
273 | * unsigned int fsid; | ||
274 | * unsigned int fileid; | ||
275 | * timeval atime; | ||
276 | * timeval mtime; | ||
277 | * timeval ctime; | ||
278 | * }; | ||
279 | * | ||
280 | */ | ||
281 | static int decode_fattr(struct xdr_stream *xdr, struct nfs_fattr *fattr) | ||
120 | { | 282 | { |
121 | u32 rdev, type; | 283 | u32 rdev, type; |
122 | type = ntohl(*p++); | 284 | __be32 *p; |
123 | fattr->mode = ntohl(*p++); | 285 | |
124 | fattr->nlink = ntohl(*p++); | 286 | p = xdr_inline_decode(xdr, NFS_fattr_sz << 2); |
125 | fattr->uid = ntohl(*p++); | 287 | if (unlikely(p == NULL)) |
126 | fattr->gid = ntohl(*p++); | 288 | goto out_overflow; |
127 | fattr->size = ntohl(*p++); | 289 | |
128 | fattr->du.nfs2.blocksize = ntohl(*p++); | ||
129 | rdev = ntohl(*p++); | ||
130 | fattr->du.nfs2.blocks = ntohl(*p++); | ||
131 | fattr->fsid.major = ntohl(*p++); | ||
132 | fattr->fsid.minor = 0; | ||
133 | fattr->fileid = ntohl(*p++); | ||
134 | p = xdr_decode_time(p, &fattr->atime); | ||
135 | p = xdr_decode_time(p, &fattr->mtime); | ||
136 | p = xdr_decode_time(p, &fattr->ctime); | ||
137 | fattr->valid |= NFS_ATTR_FATTR_V2; | 290 | fattr->valid |= NFS_ATTR_FATTR_V2; |
291 | |||
292 | p = xdr_decode_ftype(p, &type); | ||
293 | |||
294 | fattr->mode = be32_to_cpup(p++); | ||
295 | fattr->nlink = be32_to_cpup(p++); | ||
296 | fattr->uid = be32_to_cpup(p++); | ||
297 | fattr->gid = be32_to_cpup(p++); | ||
298 | fattr->size = be32_to_cpup(p++); | ||
299 | fattr->du.nfs2.blocksize = be32_to_cpup(p++); | ||
300 | |||
301 | rdev = be32_to_cpup(p++); | ||
138 | fattr->rdev = new_decode_dev(rdev); | 302 | fattr->rdev = new_decode_dev(rdev); |
139 | if (type == NFCHR && rdev == NFS2_FIFO_DEV) { | 303 | if (type == (u32)NFCHR && rdev == (u32)NFS2_FIFO_DEV) { |
140 | fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO; | 304 | fattr->mode = (fattr->mode & ~S_IFMT) | S_IFIFO; |
141 | fattr->rdev = 0; | 305 | fattr->rdev = 0; |
142 | } | 306 | } |
307 | |||
308 | fattr->du.nfs2.blocks = be32_to_cpup(p++); | ||
309 | fattr->fsid.major = be32_to_cpup(p++); | ||
310 | fattr->fsid.minor = 0; | ||
311 | fattr->fileid = be32_to_cpup(p++); | ||
312 | |||
313 | p = xdr_decode_time(p, &fattr->atime); | ||
314 | p = xdr_decode_time(p, &fattr->mtime); | ||
315 | xdr_decode_time(p, &fattr->ctime); | ||
316 | return 0; | ||
317 | out_overflow: | ||
318 | print_overflow_msg(__func__, xdr); | ||
319 | return -EIO; | ||
320 | } | ||
321 | |||
322 | /* | ||
323 | * 2.3.6. sattr | ||
324 | * | ||
325 | * struct sattr { | ||
326 | * unsigned int mode; | ||
327 | * unsigned int uid; | ||
328 | * unsigned int gid; | ||
329 | * unsigned int size; | ||
330 | * timeval atime; | ||
331 | * timeval mtime; | ||
332 | * }; | ||
333 | */ | ||
334 | |||
335 | #define NFS2_SATTR_NOT_SET (0xffffffff) | ||
336 | |||
337 | static __be32 *xdr_time_not_set(__be32 *p) | ||
338 | { | ||
339 | *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET); | ||
340 | *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET); | ||
143 | return p; | 341 | return p; |
144 | } | 342 | } |
145 | 343 | ||
146 | static inline __be32 * | 344 | static void encode_sattr(struct xdr_stream *xdr, const struct iattr *attr) |
147 | xdr_encode_sattr(__be32 *p, struct iattr *attr) | ||
148 | { | 345 | { |
149 | const __be32 not_set = __constant_htonl(0xFFFFFFFF); | 346 | __be32 *p; |
150 | 347 | ||
151 | *p++ = (attr->ia_valid & ATTR_MODE) ? htonl(attr->ia_mode) : not_set; | 348 | p = xdr_reserve_space(xdr, NFS_sattr_sz << 2); |
152 | *p++ = (attr->ia_valid & ATTR_UID) ? htonl(attr->ia_uid) : not_set; | ||
153 | *p++ = (attr->ia_valid & ATTR_GID) ? htonl(attr->ia_gid) : not_set; | ||
154 | *p++ = (attr->ia_valid & ATTR_SIZE) ? htonl(attr->ia_size) : not_set; | ||
155 | 349 | ||
156 | if (attr->ia_valid & ATTR_ATIME_SET) { | 350 | if (attr->ia_valid & ATTR_MODE) |
351 | *p++ = cpu_to_be32(attr->ia_mode); | ||
352 | else | ||
353 | *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET); | ||
354 | if (attr->ia_valid & ATTR_UID) | ||
355 | *p++ = cpu_to_be32(attr->ia_uid); | ||
356 | else | ||
357 | *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET); | ||
358 | if (attr->ia_valid & ATTR_GID) | ||
359 | *p++ = cpu_to_be32(attr->ia_gid); | ||
360 | else | ||
361 | *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET); | ||
362 | if (attr->ia_valid & ATTR_SIZE) | ||
363 | *p++ = cpu_to_be32((u32)attr->ia_size); | ||
364 | else | ||
365 | *p++ = cpu_to_be32(NFS2_SATTR_NOT_SET); | ||
366 | |||
367 | if (attr->ia_valid & ATTR_ATIME_SET) | ||
157 | p = xdr_encode_time(p, &attr->ia_atime); | 368 | p = xdr_encode_time(p, &attr->ia_atime); |
158 | } else if (attr->ia_valid & ATTR_ATIME) { | 369 | else if (attr->ia_valid & ATTR_ATIME) |
159 | p = xdr_encode_current_server_time(p, &attr->ia_atime); | 370 | p = xdr_encode_current_server_time(p, &attr->ia_atime); |
160 | } else { | 371 | else |
161 | *p++ = not_set; | 372 | p = xdr_time_not_set(p); |
162 | *p++ = not_set; | 373 | if (attr->ia_valid & ATTR_MTIME_SET) |
163 | } | 374 | xdr_encode_time(p, &attr->ia_mtime); |
164 | 375 | else if (attr->ia_valid & ATTR_MTIME) | |
165 | if (attr->ia_valid & ATTR_MTIME_SET) { | 376 | xdr_encode_current_server_time(p, &attr->ia_mtime); |
166 | p = xdr_encode_time(p, &attr->ia_mtime); | 377 | else |
167 | } else if (attr->ia_valid & ATTR_MTIME) { | 378 | xdr_time_not_set(p); |
168 | p = xdr_encode_current_server_time(p, &attr->ia_mtime); | ||
169 | } else { | ||
170 | *p++ = not_set; | ||
171 | *p++ = not_set; | ||
172 | } | ||
173 | return p; | ||
174 | } | 379 | } |
175 | 380 | ||
176 | /* | 381 | /* |
177 | * NFS encode functions | 382 | * 2.3.7. filename |
383 | * | ||
384 | * typedef string filename<MAXNAMLEN>; | ||
178 | */ | 385 | */ |
386 | static void encode_filename(struct xdr_stream *xdr, | ||
387 | const char *name, u32 length) | ||
388 | { | ||
389 | __be32 *p; | ||
390 | |||
391 | BUG_ON(length > NFS2_MAXNAMLEN); | ||
392 | p = xdr_reserve_space(xdr, 4 + length); | ||
393 | xdr_encode_opaque(p, name, length); | ||
394 | } | ||
395 | |||
396 | static int decode_filename_inline(struct xdr_stream *xdr, | ||
397 | const char **name, u32 *length) | ||
398 | { | ||
399 | __be32 *p; | ||
400 | u32 count; | ||
401 | |||
402 | p = xdr_inline_decode(xdr, 4); | ||
403 | if (unlikely(p == NULL)) | ||
404 | goto out_overflow; | ||
405 | count = be32_to_cpup(p); | ||
406 | if (count > NFS3_MAXNAMLEN) | ||
407 | goto out_nametoolong; | ||
408 | p = xdr_inline_decode(xdr, count); | ||
409 | if (unlikely(p == NULL)) | ||
410 | goto out_overflow; | ||
411 | *name = (const char *)p; | ||
412 | *length = count; | ||
413 | return 0; | ||
414 | out_nametoolong: | ||
415 | dprintk("NFS: returned filename too long: %u\n", count); | ||
416 | return -ENAMETOOLONG; | ||
417 | out_overflow: | ||
418 | print_overflow_msg(__func__, xdr); | ||
419 | return -EIO; | ||
420 | } | ||
421 | |||
179 | /* | 422 | /* |
180 | * Encode file handle argument | 423 | * 2.3.8. path |
181 | * GETATTR, READLINK, STATFS | 424 | * |
425 | * typedef string path<MAXPATHLEN>; | ||
182 | */ | 426 | */ |
183 | static int | 427 | static void encode_path(struct xdr_stream *xdr, struct page **pages, u32 length) |
184 | nfs_xdr_fhandle(struct rpc_rqst *req, __be32 *p, struct nfs_fh *fh) | ||
185 | { | 428 | { |
186 | p = xdr_encode_fhandle(p, fh); | 429 | __be32 *p; |
187 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 430 | |
431 | BUG_ON(length > NFS2_MAXPATHLEN); | ||
432 | p = xdr_reserve_space(xdr, 4); | ||
433 | *p = cpu_to_be32(length); | ||
434 | xdr_write_pages(xdr, pages, 0, length); | ||
435 | } | ||
436 | |||
437 | static int decode_path(struct xdr_stream *xdr) | ||
438 | { | ||
439 | u32 length, recvd; | ||
440 | size_t hdrlen; | ||
441 | __be32 *p; | ||
442 | |||
443 | p = xdr_inline_decode(xdr, 4); | ||
444 | if (unlikely(p == NULL)) | ||
445 | goto out_overflow; | ||
446 | length = be32_to_cpup(p); | ||
447 | if (unlikely(length >= xdr->buf->page_len || length > NFS_MAXPATHLEN)) | ||
448 | goto out_size; | ||
449 | hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base; | ||
450 | recvd = xdr->buf->len - hdrlen; | ||
451 | if (unlikely(length > recvd)) | ||
452 | goto out_cheating; | ||
453 | |||
454 | xdr_read_pages(xdr, length); | ||
455 | xdr_terminate_string(xdr->buf, length); | ||
188 | return 0; | 456 | return 0; |
457 | out_size: | ||
458 | dprintk("NFS: returned pathname too long: %u\n", length); | ||
459 | return -ENAMETOOLONG; | ||
460 | out_cheating: | ||
461 | dprintk("NFS: server cheating in pathname result: " | ||
462 | "length %u > received %u\n", length, recvd); | ||
463 | return -EIO; | ||
464 | out_overflow: | ||
465 | print_overflow_msg(__func__, xdr); | ||
466 | return -EIO; | ||
189 | } | 467 | } |
190 | 468 | ||
191 | /* | 469 | /* |
192 | * Encode SETATTR arguments | 470 | * 2.3.9. attrstat |
471 | * | ||
472 | * union attrstat switch (stat status) { | ||
473 | * case NFS_OK: | ||
474 | * fattr attributes; | ||
475 | * default: | ||
476 | * void; | ||
477 | * }; | ||
193 | */ | 478 | */ |
194 | static int | 479 | static int decode_attrstat(struct xdr_stream *xdr, struct nfs_fattr *result) |
195 | nfs_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs_sattrargs *args) | ||
196 | { | 480 | { |
197 | p = xdr_encode_fhandle(p, args->fh); | 481 | enum nfs_stat status; |
198 | p = xdr_encode_sattr(p, args->sattr); | 482 | int error; |
199 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 483 | |
200 | return 0; | 484 | error = decode_stat(xdr, &status); |
485 | if (unlikely(error)) | ||
486 | goto out; | ||
487 | if (status != NFS_OK) | ||
488 | goto out_default; | ||
489 | error = decode_fattr(xdr, result); | ||
490 | out: | ||
491 | return error; | ||
492 | out_default: | ||
493 | return nfs_stat_to_errno(status); | ||
201 | } | 494 | } |
202 | 495 | ||
203 | /* | 496 | /* |
204 | * Encode directory ops argument | 497 | * 2.3.10. diropargs |
205 | * LOOKUP, RMDIR | 498 | * |
499 | * struct diropargs { | ||
500 | * fhandle dir; | ||
501 | * filename name; | ||
502 | * }; | ||
206 | */ | 503 | */ |
207 | static int | 504 | static void encode_diropargs(struct xdr_stream *xdr, const struct nfs_fh *fh, |
208 | nfs_xdr_diropargs(struct rpc_rqst *req, __be32 *p, struct nfs_diropargs *args) | 505 | const char *name, u32 length) |
209 | { | 506 | { |
210 | p = xdr_encode_fhandle(p, args->fh); | 507 | encode_fhandle(xdr, fh); |
211 | p = xdr_encode_array(p, args->name, args->len); | 508 | encode_filename(xdr, name, length); |
212 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
213 | return 0; | ||
214 | } | 509 | } |
215 | 510 | ||
216 | /* | 511 | /* |
217 | * Encode REMOVE argument | 512 | * 2.3.11. diropres |
513 | * | ||
514 | * union diropres switch (stat status) { | ||
515 | * case NFS_OK: | ||
516 | * struct { | ||
517 | * fhandle file; | ||
518 | * fattr attributes; | ||
519 | * } diropok; | ||
520 | * default: | ||
521 | * void; | ||
522 | * }; | ||
218 | */ | 523 | */ |
219 | static int | 524 | static int decode_diropok(struct xdr_stream *xdr, struct nfs_diropok *result) |
220 | nfs_xdr_removeargs(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args) | ||
221 | { | 525 | { |
222 | p = xdr_encode_fhandle(p, args->fh); | 526 | int error; |
223 | p = xdr_encode_array(p, args->name.name, args->name.len); | 527 | |
224 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 528 | error = decode_fhandle(xdr, result->fh); |
225 | return 0; | 529 | if (unlikely(error)) |
530 | goto out; | ||
531 | error = decode_fattr(xdr, result->fattr); | ||
532 | out: | ||
533 | return error; | ||
534 | } | ||
535 | |||
536 | static int decode_diropres(struct xdr_stream *xdr, struct nfs_diropok *result) | ||
537 | { | ||
538 | enum nfs_stat status; | ||
539 | int error; | ||
540 | |||
541 | error = decode_stat(xdr, &status); | ||
542 | if (unlikely(error)) | ||
543 | goto out; | ||
544 | if (status != NFS_OK) | ||
545 | goto out_default; | ||
546 | error = decode_diropok(xdr, result); | ||
547 | out: | ||
548 | return error; | ||
549 | out_default: | ||
550 | return nfs_stat_to_errno(status); | ||
226 | } | 551 | } |
227 | 552 | ||
553 | |||
228 | /* | 554 | /* |
229 | * Arguments to a READ call. Since we read data directly into the page | 555 | * NFSv2 XDR encode functions |
230 | * cache, we also set up the reply iovec here so that iov[1] points | 556 | * |
231 | * exactly to the page we want to fetch. | 557 | * NFSv2 argument types are defined in section 2.2 of RFC 1094: |
558 | * "NFS: Network File System Protocol Specification". | ||
232 | */ | 559 | */ |
233 | static int | 560 | |
234 | nfs_xdr_readargs(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args) | 561 | static void nfs2_xdr_enc_fhandle(struct rpc_rqst *req, |
562 | struct xdr_stream *xdr, | ||
563 | const struct nfs_fh *fh) | ||
235 | { | 564 | { |
236 | struct rpc_auth *auth = req->rq_cred->cr_auth; | 565 | encode_fhandle(xdr, fh); |
237 | unsigned int replen; | 566 | } |
238 | u32 offset = (u32)args->offset; | 567 | |
568 | /* | ||
569 | * 2.2.3. sattrargs | ||
570 | * | ||
571 | * struct sattrargs { | ||
572 | * fhandle file; | ||
573 | * sattr attributes; | ||
574 | * }; | ||
575 | */ | ||
576 | static void nfs2_xdr_enc_sattrargs(struct rpc_rqst *req, | ||
577 | struct xdr_stream *xdr, | ||
578 | const struct nfs_sattrargs *args) | ||
579 | { | ||
580 | encode_fhandle(xdr, args->fh); | ||
581 | encode_sattr(xdr, args->sattr); | ||
582 | } | ||
583 | |||
584 | static void nfs2_xdr_enc_diropargs(struct rpc_rqst *req, | ||
585 | struct xdr_stream *xdr, | ||
586 | const struct nfs_diropargs *args) | ||
587 | { | ||
588 | encode_diropargs(xdr, args->fh, args->name, args->len); | ||
589 | } | ||
590 | |||
591 | static void nfs2_xdr_enc_readlinkargs(struct rpc_rqst *req, | ||
592 | struct xdr_stream *xdr, | ||
593 | const struct nfs_readlinkargs *args) | ||
594 | { | ||
595 | encode_fhandle(xdr, args->fh); | ||
596 | prepare_reply_buffer(req, args->pages, args->pgbase, | ||
597 | args->pglen, NFS_readlinkres_sz); | ||
598 | } | ||
599 | |||
600 | /* | ||
601 | * 2.2.7. readargs | ||
602 | * | ||
603 | * struct readargs { | ||
604 | * fhandle file; | ||
605 | * unsigned offset; | ||
606 | * unsigned count; | ||
607 | * unsigned totalcount; | ||
608 | * }; | ||
609 | */ | ||
610 | static void encode_readargs(struct xdr_stream *xdr, | ||
611 | const struct nfs_readargs *args) | ||
612 | { | ||
613 | u32 offset = args->offset; | ||
239 | u32 count = args->count; | 614 | u32 count = args->count; |
615 | __be32 *p; | ||
240 | 616 | ||
241 | p = xdr_encode_fhandle(p, args->fh); | 617 | encode_fhandle(xdr, args->fh); |
242 | *p++ = htonl(offset); | ||
243 | *p++ = htonl(count); | ||
244 | *p++ = htonl(count); | ||
245 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
246 | 618 | ||
247 | /* Inline the page array */ | 619 | p = xdr_reserve_space(xdr, 4 + 4 + 4); |
248 | replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS_readres_sz) << 2; | 620 | *p++ = cpu_to_be32(offset); |
249 | xdr_inline_pages(&req->rq_rcv_buf, replen, | 621 | *p++ = cpu_to_be32(count); |
250 | args->pages, args->pgbase, count); | 622 | *p = cpu_to_be32(count); |
623 | } | ||
624 | |||
625 | static void nfs2_xdr_enc_readargs(struct rpc_rqst *req, | ||
626 | struct xdr_stream *xdr, | ||
627 | const struct nfs_readargs *args) | ||
628 | { | ||
629 | encode_readargs(xdr, args); | ||
630 | prepare_reply_buffer(req, args->pages, args->pgbase, | ||
631 | args->count, NFS_readres_sz); | ||
251 | req->rq_rcv_buf.flags |= XDRBUF_READ; | 632 | req->rq_rcv_buf.flags |= XDRBUF_READ; |
252 | return 0; | ||
253 | } | 633 | } |
254 | 634 | ||
255 | /* | 635 | /* |
256 | * Decode READ reply | 636 | * 2.2.9. writeargs |
637 | * | ||
638 | * struct writeargs { | ||
639 | * fhandle file; | ||
640 | * unsigned beginoffset; | ||
641 | * unsigned offset; | ||
642 | * unsigned totalcount; | ||
643 | * nfsdata data; | ||
644 | * }; | ||
257 | */ | 645 | */ |
258 | static int | 646 | static void encode_writeargs(struct xdr_stream *xdr, |
259 | nfs_xdr_readres(struct rpc_rqst *req, __be32 *p, struct nfs_readres *res) | 647 | const struct nfs_writeargs *args) |
260 | { | 648 | { |
261 | struct kvec *iov = req->rq_rcv_buf.head; | 649 | u32 offset = args->offset; |
262 | size_t hdrlen; | 650 | u32 count = args->count; |
263 | u32 count, recvd; | 651 | __be32 *p; |
264 | int status; | ||
265 | |||
266 | if ((status = ntohl(*p++))) | ||
267 | return nfs_stat_to_errno(status); | ||
268 | p = xdr_decode_fattr(p, res->fattr); | ||
269 | |||
270 | count = ntohl(*p++); | ||
271 | res->eof = 0; | ||
272 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; | ||
273 | if (iov->iov_len < hdrlen) { | ||
274 | dprintk("NFS: READ reply header overflowed:" | ||
275 | "length %Zu > %Zu\n", hdrlen, iov->iov_len); | ||
276 | return -errno_NFSERR_IO; | ||
277 | } else if (iov->iov_len != hdrlen) { | ||
278 | dprintk("NFS: READ header is short. iovec will be shifted.\n"); | ||
279 | xdr_shift_buf(&req->rq_rcv_buf, iov->iov_len - hdrlen); | ||
280 | } | ||
281 | 652 | ||
282 | recvd = req->rq_rcv_buf.len - hdrlen; | 653 | encode_fhandle(xdr, args->fh); |
283 | if (count > recvd) { | ||
284 | dprintk("NFS: server cheating in read reply: " | ||
285 | "count %u > recvd %u\n", count, recvd); | ||
286 | count = recvd; | ||
287 | } | ||
288 | 654 | ||
289 | dprintk("RPC: readres OK count %u\n", count); | 655 | p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4); |
290 | if (count < res->count) | 656 | *p++ = cpu_to_be32(offset); |
291 | res->count = count; | 657 | *p++ = cpu_to_be32(offset); |
658 | *p++ = cpu_to_be32(count); | ||
292 | 659 | ||
293 | return count; | 660 | /* nfsdata */ |
661 | *p = cpu_to_be32(count); | ||
662 | xdr_write_pages(xdr, args->pages, args->pgbase, count); | ||
294 | } | 663 | } |
295 | 664 | ||
665 | static void nfs2_xdr_enc_writeargs(struct rpc_rqst *req, | ||
666 | struct xdr_stream *xdr, | ||
667 | const struct nfs_writeargs *args) | ||
668 | { | ||
669 | encode_writeargs(xdr, args); | ||
670 | xdr->buf->flags |= XDRBUF_WRITE; | ||
671 | } | ||
296 | 672 | ||
297 | /* | 673 | /* |
298 | * Write arguments. Splice the buffer to be written into the iovec. | 674 | * 2.2.10. createargs |
675 | * | ||
676 | * struct createargs { | ||
677 | * diropargs where; | ||
678 | * sattr attributes; | ||
679 | * }; | ||
299 | */ | 680 | */ |
300 | static int | 681 | static void nfs2_xdr_enc_createargs(struct rpc_rqst *req, |
301 | nfs_xdr_writeargs(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) | 682 | struct xdr_stream *xdr, |
683 | const struct nfs_createargs *args) | ||
302 | { | 684 | { |
303 | struct xdr_buf *sndbuf = &req->rq_snd_buf; | 685 | encode_diropargs(xdr, args->fh, args->name, args->len); |
304 | u32 offset = (u32)args->offset; | 686 | encode_sattr(xdr, args->sattr); |
305 | u32 count = args->count; | 687 | } |
306 | |||
307 | p = xdr_encode_fhandle(p, args->fh); | ||
308 | *p++ = htonl(offset); | ||
309 | *p++ = htonl(offset); | ||
310 | *p++ = htonl(count); | ||
311 | *p++ = htonl(count); | ||
312 | sndbuf->len = xdr_adjust_iovec(sndbuf->head, p); | ||
313 | 688 | ||
314 | /* Copy the page array */ | 689 | static void nfs2_xdr_enc_removeargs(struct rpc_rqst *req, |
315 | xdr_encode_pages(sndbuf, args->pages, args->pgbase, count); | 690 | struct xdr_stream *xdr, |
316 | sndbuf->flags |= XDRBUF_WRITE; | 691 | const struct nfs_removeargs *args) |
317 | return 0; | 692 | { |
693 | encode_diropargs(xdr, args->fh, args->name.name, args->name.len); | ||
318 | } | 694 | } |
319 | 695 | ||
320 | /* | 696 | /* |
321 | * Encode create arguments | 697 | * 2.2.12. renameargs |
322 | * CREATE, MKDIR | 698 | * |
699 | * struct renameargs { | ||
700 | * diropargs from; | ||
701 | * diropargs to; | ||
702 | * }; | ||
323 | */ | 703 | */ |
324 | static int | 704 | static void nfs2_xdr_enc_renameargs(struct rpc_rqst *req, |
325 | nfs_xdr_createargs(struct rpc_rqst *req, __be32 *p, struct nfs_createargs *args) | 705 | struct xdr_stream *xdr, |
706 | const struct nfs_renameargs *args) | ||
326 | { | 707 | { |
327 | p = xdr_encode_fhandle(p, args->fh); | 708 | const struct qstr *old = args->old_name; |
328 | p = xdr_encode_array(p, args->name, args->len); | 709 | const struct qstr *new = args->new_name; |
329 | p = xdr_encode_sattr(p, args->sattr); | 710 | |
330 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 711 | encode_diropargs(xdr, args->old_dir, old->name, old->len); |
331 | return 0; | 712 | encode_diropargs(xdr, args->new_dir, new->name, new->len); |
332 | } | 713 | } |
333 | 714 | ||
334 | /* | 715 | /* |
335 | * Encode RENAME arguments | 716 | * 2.2.13. linkargs |
717 | * | ||
718 | * struct linkargs { | ||
719 | * fhandle from; | ||
720 | * diropargs to; | ||
721 | * }; | ||
336 | */ | 722 | */ |
337 | static int | 723 | static void nfs2_xdr_enc_linkargs(struct rpc_rqst *req, |
338 | nfs_xdr_renameargs(struct rpc_rqst *req, __be32 *p, struct nfs_renameargs *args) | 724 | struct xdr_stream *xdr, |
725 | const struct nfs_linkargs *args) | ||
339 | { | 726 | { |
340 | p = xdr_encode_fhandle(p, args->old_dir); | 727 | encode_fhandle(xdr, args->fromfh); |
341 | p = xdr_encode_array(p, args->old_name->name, args->old_name->len); | 728 | encode_diropargs(xdr, args->tofh, args->toname, args->tolen); |
342 | p = xdr_encode_fhandle(p, args->new_dir); | ||
343 | p = xdr_encode_array(p, args->new_name->name, args->new_name->len); | ||
344 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
345 | return 0; | ||
346 | } | 729 | } |
347 | 730 | ||
348 | /* | 731 | /* |
349 | * Encode LINK arguments | 732 | * 2.2.14. symlinkargs |
733 | * | ||
734 | * struct symlinkargs { | ||
735 | * diropargs from; | ||
736 | * path to; | ||
737 | * sattr attributes; | ||
738 | * }; | ||
350 | */ | 739 | */ |
351 | static int | 740 | static void nfs2_xdr_enc_symlinkargs(struct rpc_rqst *req, |
352 | nfs_xdr_linkargs(struct rpc_rqst *req, __be32 *p, struct nfs_linkargs *args) | 741 | struct xdr_stream *xdr, |
742 | const struct nfs_symlinkargs *args) | ||
353 | { | 743 | { |
354 | p = xdr_encode_fhandle(p, args->fromfh); | 744 | encode_diropargs(xdr, args->fromfh, args->fromname, args->fromlen); |
355 | p = xdr_encode_fhandle(p, args->tofh); | 745 | encode_path(xdr, args->pages, args->pathlen); |
356 | p = xdr_encode_array(p, args->toname, args->tolen); | 746 | encode_sattr(xdr, args->sattr); |
357 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
358 | return 0; | ||
359 | } | 747 | } |
360 | 748 | ||
361 | /* | 749 | /* |
362 | * Encode SYMLINK arguments | 750 | * 2.2.17. readdirargs |
751 | * | ||
752 | * struct readdirargs { | ||
753 | * fhandle dir; | ||
754 | * nfscookie cookie; | ||
755 | * unsigned count; | ||
756 | * }; | ||
363 | */ | 757 | */ |
364 | static int | 758 | static void encode_readdirargs(struct xdr_stream *xdr, |
365 | nfs_xdr_symlinkargs(struct rpc_rqst *req, __be32 *p, struct nfs_symlinkargs *args) | 759 | const struct nfs_readdirargs *args) |
366 | { | 760 | { |
367 | struct xdr_buf *sndbuf = &req->rq_snd_buf; | 761 | __be32 *p; |
368 | size_t pad; | ||
369 | 762 | ||
370 | p = xdr_encode_fhandle(p, args->fromfh); | 763 | encode_fhandle(xdr, args->fh); |
371 | p = xdr_encode_array(p, args->fromname, args->fromlen); | ||
372 | *p++ = htonl(args->pathlen); | ||
373 | sndbuf->len = xdr_adjust_iovec(sndbuf->head, p); | ||
374 | 764 | ||
375 | xdr_encode_pages(sndbuf, args->pages, 0, args->pathlen); | 765 | p = xdr_reserve_space(xdr, 4 + 4); |
766 | *p++ = cpu_to_be32(args->cookie); | ||
767 | *p = cpu_to_be32(args->count); | ||
768 | } | ||
376 | 769 | ||
377 | /* | 770 | static void nfs2_xdr_enc_readdirargs(struct rpc_rqst *req, |
378 | * xdr_encode_pages may have added a few bytes to ensure the | 771 | struct xdr_stream *xdr, |
379 | * pathname ends on a 4-byte boundary. Start encoding the | 772 | const struct nfs_readdirargs *args) |
380 | * attributes after the pad bytes. | 773 | { |
381 | */ | 774 | encode_readdirargs(xdr, args); |
382 | pad = sndbuf->tail->iov_len; | 775 | prepare_reply_buffer(req, args->pages, 0, |
383 | if (pad > 0) | 776 | args->count, NFS_readdirres_sz); |
384 | p++; | ||
385 | p = xdr_encode_sattr(p, args->sattr); | ||
386 | sndbuf->len += xdr_adjust_iovec(sndbuf->tail, p) - pad; | ||
387 | return 0; | ||
388 | } | 777 | } |
389 | 778 | ||
390 | /* | 779 | /* |
391 | * Encode arguments to readdir call | 780 | * NFSv2 XDR decode functions |
781 | * | ||
782 | * NFSv2 result types are defined in section 2.2 of RFC 1094: | ||
783 | * "NFS: Network File System Protocol Specification". | ||
392 | */ | 784 | */ |
393 | static int | 785 | |
394 | nfs_xdr_readdirargs(struct rpc_rqst *req, __be32 *p, struct nfs_readdirargs *args) | 786 | static int nfs2_xdr_dec_stat(struct rpc_rqst *req, struct xdr_stream *xdr, |
787 | void *__unused) | ||
395 | { | 788 | { |
396 | struct rpc_auth *auth = req->rq_cred->cr_auth; | 789 | enum nfs_stat status; |
397 | unsigned int replen; | 790 | int error; |
398 | u32 count = args->count; | 791 | |
792 | error = decode_stat(xdr, &status); | ||
793 | if (unlikely(error)) | ||
794 | goto out; | ||
795 | if (status != NFS_OK) | ||
796 | goto out_default; | ||
797 | out: | ||
798 | return error; | ||
799 | out_default: | ||
800 | return nfs_stat_to_errno(status); | ||
801 | } | ||
399 | 802 | ||
400 | p = xdr_encode_fhandle(p, args->fh); | 803 | static int nfs2_xdr_dec_attrstat(struct rpc_rqst *req, struct xdr_stream *xdr, |
401 | *p++ = htonl(args->cookie); | 804 | struct nfs_fattr *result) |
402 | *p++ = htonl(count); /* see above */ | 805 | { |
403 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 806 | return decode_attrstat(xdr, result); |
807 | } | ||
404 | 808 | ||
405 | /* Inline the page array */ | 809 | static int nfs2_xdr_dec_diropres(struct rpc_rqst *req, struct xdr_stream *xdr, |
406 | replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS_readdirres_sz) << 2; | 810 | struct nfs_diropok *result) |
407 | xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages, 0, count); | 811 | { |
408 | return 0; | 812 | return decode_diropres(xdr, result); |
409 | } | 813 | } |
410 | 814 | ||
411 | /* | 815 | /* |
412 | * Decode the result of a readdir call. | 816 | * 2.2.6. readlinkres |
413 | * We're not really decoding anymore, we just leave the buffer untouched | 817 | * |
414 | * and only check that it is syntactically correct. | 818 | * union readlinkres switch (stat status) { |
415 | * The real decoding happens in nfs_decode_entry below, called directly | 819 | * case NFS_OK: |
416 | * from nfs_readdir for each entry. | 820 | * path data; |
821 | * default: | ||
822 | * void; | ||
823 | * }; | ||
417 | */ | 824 | */ |
418 | static int | 825 | static int nfs2_xdr_dec_readlinkres(struct rpc_rqst *req, |
419 | nfs_xdr_readdirres(struct rpc_rqst *req, __be32 *p, void *dummy) | 826 | struct xdr_stream *xdr, void *__unused) |
420 | { | 827 | { |
421 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; | 828 | enum nfs_stat status; |
422 | struct kvec *iov = rcvbuf->head; | 829 | int error; |
423 | struct page **page; | 830 | |
424 | size_t hdrlen; | 831 | error = decode_stat(xdr, &status); |
425 | unsigned int pglen, recvd; | 832 | if (unlikely(error)) |
426 | int status; | 833 | goto out; |
427 | 834 | if (status != NFS_OK) | |
428 | if ((status = ntohl(*p++))) | 835 | goto out_default; |
429 | return nfs_stat_to_errno(status); | 836 | error = decode_path(xdr); |
430 | 837 | out: | |
431 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; | 838 | return error; |
432 | if (iov->iov_len < hdrlen) { | 839 | out_default: |
433 | dprintk("NFS: READDIR reply header overflowed:" | 840 | return nfs_stat_to_errno(status); |
434 | "length %Zu > %Zu\n", hdrlen, iov->iov_len); | 841 | } |
435 | return -errno_NFSERR_IO; | ||
436 | } else if (iov->iov_len != hdrlen) { | ||
437 | dprintk("NFS: READDIR header is short. iovec will be shifted.\n"); | ||
438 | xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen); | ||
439 | } | ||
440 | 842 | ||
441 | pglen = rcvbuf->page_len; | 843 | /* |
442 | recvd = rcvbuf->len - hdrlen; | 844 | * 2.2.7. readres |
443 | if (pglen > recvd) | 845 | * |
444 | pglen = recvd; | 846 | * union readres switch (stat status) { |
445 | page = rcvbuf->pages; | 847 | * case NFS_OK: |
446 | return pglen; | 848 | * fattr attributes; |
849 | * nfsdata data; | ||
850 | * default: | ||
851 | * void; | ||
852 | * }; | ||
853 | */ | ||
854 | static int nfs2_xdr_dec_readres(struct rpc_rqst *req, struct xdr_stream *xdr, | ||
855 | struct nfs_readres *result) | ||
856 | { | ||
857 | enum nfs_stat status; | ||
858 | int error; | ||
859 | |||
860 | error = decode_stat(xdr, &status); | ||
861 | if (unlikely(error)) | ||
862 | goto out; | ||
863 | if (status != NFS_OK) | ||
864 | goto out_default; | ||
865 | error = decode_fattr(xdr, result->fattr); | ||
866 | if (unlikely(error)) | ||
867 | goto out; | ||
868 | error = decode_nfsdata(xdr, result); | ||
869 | out: | ||
870 | return error; | ||
871 | out_default: | ||
872 | return nfs_stat_to_errno(status); | ||
447 | } | 873 | } |
448 | 874 | ||
449 | static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) | 875 | static int nfs2_xdr_dec_writeres(struct rpc_rqst *req, struct xdr_stream *xdr, |
876 | struct nfs_writeres *result) | ||
450 | { | 877 | { |
451 | dprintk("nfs: %s: prematurely hit end of receive buffer. " | 878 | /* All NFSv2 writes are "file sync" writes */ |
452 | "Remaining buffer length is %tu words.\n", | 879 | result->verf->committed = NFS_FILE_SYNC; |
453 | func, xdr->end - xdr->p); | 880 | return decode_attrstat(xdr, result->fattr); |
454 | } | 881 | } |
455 | 882 | ||
456 | __be32 * | 883 | /** |
457 | nfs_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_server *server, int plus) | 884 | * nfs2_decode_dirent - Decode a single NFSv2 directory entry stored in |
885 | * the local page cache. | ||
886 | * @xdr: XDR stream where entry resides | ||
887 | * @entry: buffer to fill in with entry data | ||
888 | * @plus: boolean indicating whether this should be a readdirplus entry | ||
889 | * | ||
890 | * Returns zero if successful, otherwise a negative errno value is | ||
891 | * returned. | ||
892 | * | ||
893 | * This function is not invoked during READDIR reply decoding, but | ||
894 | * rather whenever an application invokes the getdents(2) system call | ||
895 | * on a directory already in our cache. | ||
896 | * | ||
897 | * 2.2.17. entry | ||
898 | * | ||
899 | * struct entry { | ||
900 | * unsigned fileid; | ||
901 | * filename name; | ||
902 | * nfscookie cookie; | ||
903 | * entry *nextentry; | ||
904 | * }; | ||
905 | */ | ||
906 | int nfs2_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, | ||
907 | int plus) | ||
458 | { | 908 | { |
459 | __be32 *p; | 909 | __be32 *p; |
910 | int error; | ||
911 | |||
460 | p = xdr_inline_decode(xdr, 4); | 912 | p = xdr_inline_decode(xdr, 4); |
461 | if (unlikely(!p)) | 913 | if (unlikely(p == NULL)) |
462 | goto out_overflow; | 914 | goto out_overflow; |
463 | if (!ntohl(*p++)) { | 915 | if (*p++ == xdr_zero) { |
464 | p = xdr_inline_decode(xdr, 4); | 916 | p = xdr_inline_decode(xdr, 4); |
465 | if (unlikely(!p)) | 917 | if (unlikely(p == NULL)) |
466 | goto out_overflow; | 918 | goto out_overflow; |
467 | if (!ntohl(*p++)) | 919 | if (*p++ == xdr_zero) |
468 | return ERR_PTR(-EAGAIN); | 920 | return -EAGAIN; |
469 | entry->eof = 1; | 921 | entry->eof = 1; |
470 | return ERR_PTR(-EBADCOOKIE); | 922 | return -EBADCOOKIE; |
471 | } | 923 | } |
472 | 924 | ||
473 | p = xdr_inline_decode(xdr, 8); | 925 | p = xdr_inline_decode(xdr, 4); |
474 | if (unlikely(!p)) | 926 | if (unlikely(p == NULL)) |
475 | goto out_overflow; | 927 | goto out_overflow; |
928 | entry->ino = be32_to_cpup(p); | ||
476 | 929 | ||
477 | entry->ino = ntohl(*p++); | 930 | error = decode_filename_inline(xdr, &entry->name, &entry->len); |
478 | entry->len = ntohl(*p++); | 931 | if (unlikely(error)) |
932 | return error; | ||
479 | 933 | ||
480 | p = xdr_inline_decode(xdr, entry->len + 4); | 934 | /* |
481 | if (unlikely(!p)) | 935 | * The type (size and byte order) of nfscookie isn't defined in |
936 | * RFC 1094. This implementation assumes that it's an XDR uint32. | ||
937 | */ | ||
938 | entry->prev_cookie = entry->cookie; | ||
939 | p = xdr_inline_decode(xdr, 4); | ||
940 | if (unlikely(p == NULL)) | ||
482 | goto out_overflow; | 941 | goto out_overflow; |
483 | entry->name = (const char *) p; | 942 | entry->cookie = be32_to_cpup(p); |
484 | p += XDR_QUADLEN(entry->len); | ||
485 | entry->prev_cookie = entry->cookie; | ||
486 | entry->cookie = ntohl(*p++); | ||
487 | 943 | ||
488 | entry->d_type = DT_UNKNOWN; | 944 | entry->d_type = DT_UNKNOWN; |
489 | 945 | ||
490 | p = xdr_inline_peek(xdr, 8); | 946 | return 0; |
491 | if (p != NULL) | ||
492 | entry->eof = !p[0] && p[1]; | ||
493 | else | ||
494 | entry->eof = 0; | ||
495 | |||
496 | return p; | ||
497 | 947 | ||
498 | out_overflow: | 948 | out_overflow: |
499 | print_overflow_msg(__func__, xdr); | 949 | print_overflow_msg(__func__, xdr); |
500 | return ERR_PTR(-EAGAIN); | 950 | return -EAGAIN; |
501 | } | ||
502 | |||
503 | /* | ||
504 | * NFS XDR decode functions | ||
505 | */ | ||
506 | /* | ||
507 | * Decode simple status reply | ||
508 | */ | ||
509 | static int | ||
510 | nfs_xdr_stat(struct rpc_rqst *req, __be32 *p, void *dummy) | ||
511 | { | ||
512 | int status; | ||
513 | |||
514 | if ((status = ntohl(*p++)) != 0) | ||
515 | status = nfs_stat_to_errno(status); | ||
516 | return status; | ||
517 | } | 951 | } |
518 | 952 | ||
519 | /* | 953 | /* |
520 | * Decode attrstat reply | 954 | * 2.2.17. readdirres |
521 | * GETATTR, SETATTR, WRITE | 955 | * |
522 | */ | 956 | * union readdirres switch (stat status) { |
523 | static int | 957 | * case NFS_OK: |
524 | nfs_xdr_attrstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr) | 958 | * struct { |
525 | { | 959 | * entry *entries; |
526 | int status; | 960 | * bool eof; |
527 | 961 | * } readdirok; | |
528 | if ((status = ntohl(*p++))) | 962 | * default: |
529 | return nfs_stat_to_errno(status); | 963 | * void; |
530 | xdr_decode_fattr(p, fattr); | 964 | * }; |
531 | return 0; | 965 | * |
532 | } | 966 | * Read the directory contents into the page cache, but don't |
533 | 967 | * touch them. The actual decoding is done by nfs2_decode_dirent() | |
534 | /* | 968 | * during subsequent nfs_readdir() calls. |
535 | * Decode diropres reply | ||
536 | * LOOKUP, CREATE, MKDIR | ||
537 | */ | 969 | */ |
538 | static int | 970 | static int decode_readdirok(struct xdr_stream *xdr) |
539 | nfs_xdr_diropres(struct rpc_rqst *req, __be32 *p, struct nfs_diropok *res) | ||
540 | { | 971 | { |
541 | int status; | 972 | u32 recvd, pglen; |
973 | size_t hdrlen; | ||
542 | 974 | ||
543 | if ((status = ntohl(*p++))) | 975 | pglen = xdr->buf->page_len; |
544 | return nfs_stat_to_errno(status); | 976 | hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base; |
545 | p = xdr_decode_fhandle(p, res->fh); | 977 | recvd = xdr->buf->len - hdrlen; |
546 | xdr_decode_fattr(p, res->fattr); | 978 | if (unlikely(pglen > recvd)) |
547 | return 0; | 979 | goto out_cheating; |
980 | out: | ||
981 | xdr_read_pages(xdr, pglen); | ||
982 | return pglen; | ||
983 | out_cheating: | ||
984 | dprintk("NFS: server cheating in readdir result: " | ||
985 | "pglen %u > recvd %u\n", pglen, recvd); | ||
986 | pglen = recvd; | ||
987 | goto out; | ||
548 | } | 988 | } |
549 | 989 | ||
550 | /* | 990 | static int nfs2_xdr_dec_readdirres(struct rpc_rqst *req, |
551 | * Encode READLINK args | 991 | struct xdr_stream *xdr, void *__unused) |
552 | */ | ||
553 | static int | ||
554 | nfs_xdr_readlinkargs(struct rpc_rqst *req, __be32 *p, struct nfs_readlinkargs *args) | ||
555 | { | 992 | { |
556 | struct rpc_auth *auth = req->rq_cred->cr_auth; | 993 | enum nfs_stat status; |
557 | unsigned int replen; | 994 | int error; |
558 | 995 | ||
559 | p = xdr_encode_fhandle(p, args->fh); | 996 | error = decode_stat(xdr, &status); |
560 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 997 | if (unlikely(error)) |
561 | 998 | goto out; | |
562 | /* Inline the page array */ | 999 | if (status != NFS_OK) |
563 | replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS_readlinkres_sz) << 2; | 1000 | goto out_default; |
564 | xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages, args->pgbase, args->pglen); | 1001 | error = decode_readdirok(xdr); |
565 | return 0; | 1002 | out: |
1003 | return error; | ||
1004 | out_default: | ||
1005 | return nfs_stat_to_errno(status); | ||
566 | } | 1006 | } |
567 | 1007 | ||
568 | /* | 1008 | /* |
569 | * Decode READLINK reply | 1009 | * 2.2.18. statfsres |
1010 | * | ||
1011 | * union statfsres (stat status) { | ||
1012 | * case NFS_OK: | ||
1013 | * struct { | ||
1014 | * unsigned tsize; | ||
1015 | * unsigned bsize; | ||
1016 | * unsigned blocks; | ||
1017 | * unsigned bfree; | ||
1018 | * unsigned bavail; | ||
1019 | * } info; | ||
1020 | * default: | ||
1021 | * void; | ||
1022 | * }; | ||
570 | */ | 1023 | */ |
571 | static int | 1024 | static int decode_info(struct xdr_stream *xdr, struct nfs2_fsstat *result) |
572 | nfs_xdr_readlinkres(struct rpc_rqst *req, __be32 *p, void *dummy) | ||
573 | { | 1025 | { |
574 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; | 1026 | __be32 *p; |
575 | struct kvec *iov = rcvbuf->head; | ||
576 | size_t hdrlen; | ||
577 | u32 len, recvd; | ||
578 | int status; | ||
579 | |||
580 | if ((status = ntohl(*p++))) | ||
581 | return nfs_stat_to_errno(status); | ||
582 | /* Convert length of symlink */ | ||
583 | len = ntohl(*p++); | ||
584 | if (len >= rcvbuf->page_len) { | ||
585 | dprintk("nfs: server returned giant symlink!\n"); | ||
586 | return -ENAMETOOLONG; | ||
587 | } | ||
588 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; | ||
589 | if (iov->iov_len < hdrlen) { | ||
590 | dprintk("NFS: READLINK reply header overflowed:" | ||
591 | "length %Zu > %Zu\n", hdrlen, iov->iov_len); | ||
592 | return -errno_NFSERR_IO; | ||
593 | } else if (iov->iov_len != hdrlen) { | ||
594 | dprintk("NFS: READLINK header is short. iovec will be shifted.\n"); | ||
595 | xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen); | ||
596 | } | ||
597 | recvd = req->rq_rcv_buf.len - hdrlen; | ||
598 | if (recvd < len) { | ||
599 | dprintk("NFS: server cheating in readlink reply: " | ||
600 | "count %u > recvd %u\n", len, recvd); | ||
601 | return -EIO; | ||
602 | } | ||
603 | 1027 | ||
604 | xdr_terminate_string(rcvbuf, len); | 1028 | p = xdr_inline_decode(xdr, NFS_info_sz << 2); |
1029 | if (unlikely(p == NULL)) | ||
1030 | goto out_overflow; | ||
1031 | result->tsize = be32_to_cpup(p++); | ||
1032 | result->bsize = be32_to_cpup(p++); | ||
1033 | result->blocks = be32_to_cpup(p++); | ||
1034 | result->bfree = be32_to_cpup(p++); | ||
1035 | result->bavail = be32_to_cpup(p); | ||
605 | return 0; | 1036 | return 0; |
1037 | out_overflow: | ||
1038 | print_overflow_msg(__func__, xdr); | ||
1039 | return -EIO; | ||
606 | } | 1040 | } |
607 | 1041 | ||
608 | /* | 1042 | static int nfs2_xdr_dec_statfsres(struct rpc_rqst *req, struct xdr_stream *xdr, |
609 | * Decode WRITE reply | 1043 | struct nfs2_fsstat *result) |
610 | */ | ||
611 | static int | ||
612 | nfs_xdr_writeres(struct rpc_rqst *req, __be32 *p, struct nfs_writeres *res) | ||
613 | { | 1044 | { |
614 | res->verf->committed = NFS_FILE_SYNC; | 1045 | enum nfs_stat status; |
615 | return nfs_xdr_attrstat(req, p, res->fattr); | 1046 | int error; |
1047 | |||
1048 | error = decode_stat(xdr, &status); | ||
1049 | if (unlikely(error)) | ||
1050 | goto out; | ||
1051 | if (status != NFS_OK) | ||
1052 | goto out_default; | ||
1053 | error = decode_info(xdr, result); | ||
1054 | out: | ||
1055 | return error; | ||
1056 | out_default: | ||
1057 | return nfs_stat_to_errno(status); | ||
616 | } | 1058 | } |
617 | 1059 | ||
618 | /* | ||
619 | * Decode STATFS reply | ||
620 | */ | ||
621 | static int | ||
622 | nfs_xdr_statfsres(struct rpc_rqst *req, __be32 *p, struct nfs2_fsstat *res) | ||
623 | { | ||
624 | int status; | ||
625 | |||
626 | if ((status = ntohl(*p++))) | ||
627 | return nfs_stat_to_errno(status); | ||
628 | |||
629 | res->tsize = ntohl(*p++); | ||
630 | res->bsize = ntohl(*p++); | ||
631 | res->blocks = ntohl(*p++); | ||
632 | res->bfree = ntohl(*p++); | ||
633 | res->bavail = ntohl(*p++); | ||
634 | return 0; | ||
635 | } | ||
636 | 1060 | ||
637 | /* | 1061 | /* |
638 | * We need to translate between nfs status return values and | 1062 | * We need to translate between nfs status return values and |
639 | * the local errno values which may not be the same. | 1063 | * the local errno values which may not be the same. |
640 | */ | 1064 | */ |
641 | static struct { | 1065 | static const struct { |
642 | int stat; | 1066 | int stat; |
643 | int errno; | 1067 | int errno; |
644 | } nfs_errtbl[] = { | 1068 | } nfs_errtbl[] = { |
@@ -678,28 +1102,30 @@ static struct { | |||
678 | { -1, -EIO } | 1102 | { -1, -EIO } |
679 | }; | 1103 | }; |
680 | 1104 | ||
681 | /* | 1105 | /** |
682 | * Convert an NFS error code to a local one. | 1106 | * nfs_stat_to_errno - convert an NFS status code to a local errno |
683 | * This one is used jointly by NFSv2 and NFSv3. | 1107 | * @status: NFS status code to convert |
1108 | * | ||
1109 | * Returns a local errno value, or -EIO if the NFS status code is | ||
1110 | * not recognized. This function is used jointly by NFSv2 and NFSv3. | ||
684 | */ | 1111 | */ |
685 | int | 1112 | int nfs_stat_to_errno(enum nfs_stat status) |
686 | nfs_stat_to_errno(int stat) | ||
687 | { | 1113 | { |
688 | int i; | 1114 | int i; |
689 | 1115 | ||
690 | for (i = 0; nfs_errtbl[i].stat != -1; i++) { | 1116 | for (i = 0; nfs_errtbl[i].stat != -1; i++) { |
691 | if (nfs_errtbl[i].stat == stat) | 1117 | if (nfs_errtbl[i].stat == (int)status) |
692 | return nfs_errtbl[i].errno; | 1118 | return nfs_errtbl[i].errno; |
693 | } | 1119 | } |
694 | dprintk("nfs_stat_to_errno: bad nfs status return value: %d\n", stat); | 1120 | dprintk("NFS: Unrecognized nfs status value: %u\n", status); |
695 | return nfs_errtbl[i].errno; | 1121 | return nfs_errtbl[i].errno; |
696 | } | 1122 | } |
697 | 1123 | ||
698 | #define PROC(proc, argtype, restype, timer) \ | 1124 | #define PROC(proc, argtype, restype, timer) \ |
699 | [NFSPROC_##proc] = { \ | 1125 | [NFSPROC_##proc] = { \ |
700 | .p_proc = NFSPROC_##proc, \ | 1126 | .p_proc = NFSPROC_##proc, \ |
701 | .p_encode = (kxdrproc_t) nfs_xdr_##argtype, \ | 1127 | .p_encode = (kxdreproc_t)nfs2_xdr_enc_##argtype, \ |
702 | .p_decode = (kxdrproc_t) nfs_xdr_##restype, \ | 1128 | .p_decode = (kxdrdproc_t)nfs2_xdr_dec_##restype, \ |
703 | .p_arglen = NFS_##argtype##_sz, \ | 1129 | .p_arglen = NFS_##argtype##_sz, \ |
704 | .p_replen = NFS_##restype##_sz, \ | 1130 | .p_replen = NFS_##restype##_sz, \ |
705 | .p_timer = timer, \ | 1131 | .p_timer = timer, \ |
@@ -707,21 +1133,21 @@ nfs_stat_to_errno(int stat) | |||
707 | .p_name = #proc, \ | 1133 | .p_name = #proc, \ |
708 | } | 1134 | } |
709 | struct rpc_procinfo nfs_procedures[] = { | 1135 | struct rpc_procinfo nfs_procedures[] = { |
710 | PROC(GETATTR, fhandle, attrstat, 1), | 1136 | PROC(GETATTR, fhandle, attrstat, 1), |
711 | PROC(SETATTR, sattrargs, attrstat, 0), | 1137 | PROC(SETATTR, sattrargs, attrstat, 0), |
712 | PROC(LOOKUP, diropargs, diropres, 2), | 1138 | PROC(LOOKUP, diropargs, diropres, 2), |
713 | PROC(READLINK, readlinkargs, readlinkres, 3), | 1139 | PROC(READLINK, readlinkargs, readlinkres, 3), |
714 | PROC(READ, readargs, readres, 3), | 1140 | PROC(READ, readargs, readres, 3), |
715 | PROC(WRITE, writeargs, writeres, 4), | 1141 | PROC(WRITE, writeargs, writeres, 4), |
716 | PROC(CREATE, createargs, diropres, 0), | 1142 | PROC(CREATE, createargs, diropres, 0), |
717 | PROC(REMOVE, removeargs, stat, 0), | 1143 | PROC(REMOVE, removeargs, stat, 0), |
718 | PROC(RENAME, renameargs, stat, 0), | 1144 | PROC(RENAME, renameargs, stat, 0), |
719 | PROC(LINK, linkargs, stat, 0), | 1145 | PROC(LINK, linkargs, stat, 0), |
720 | PROC(SYMLINK, symlinkargs, stat, 0), | 1146 | PROC(SYMLINK, symlinkargs, stat, 0), |
721 | PROC(MKDIR, createargs, diropres, 0), | 1147 | PROC(MKDIR, createargs, diropres, 0), |
722 | PROC(RMDIR, diropargs, stat, 0), | 1148 | PROC(RMDIR, diropargs, stat, 0), |
723 | PROC(READDIR, readdirargs, readdirres, 3), | 1149 | PROC(READDIR, readdirargs, readdirres, 3), |
724 | PROC(STATFS, fhandle, statfsres, 0), | 1150 | PROC(STATFS, fhandle, statfsres, 0), |
725 | }; | 1151 | }; |
726 | 1152 | ||
727 | struct rpc_version nfs_version2 = { | 1153 | struct rpc_version nfs_version2 = { |
diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c index f6cc60f06dac..01c5e8b1941d 100644 --- a/fs/nfs/nfs3xdr.c +++ b/fs/nfs/nfs3xdr.c | |||
@@ -37,18 +37,16 @@ | |||
37 | #define NFS3_filename_sz (1+(NFS3_MAXNAMLEN>>2)) | 37 | #define NFS3_filename_sz (1+(NFS3_MAXNAMLEN>>2)) |
38 | #define NFS3_path_sz (1+(NFS3_MAXPATHLEN>>2)) | 38 | #define NFS3_path_sz (1+(NFS3_MAXPATHLEN>>2)) |
39 | #define NFS3_fattr_sz (21) | 39 | #define NFS3_fattr_sz (21) |
40 | #define NFS3_wcc_attr_sz (6) | 40 | #define NFS3_cookieverf_sz (NFS3_COOKIEVERFSIZE>>2) |
41 | #define NFS3_wcc_attr_sz (6) | ||
41 | #define NFS3_pre_op_attr_sz (1+NFS3_wcc_attr_sz) | 42 | #define NFS3_pre_op_attr_sz (1+NFS3_wcc_attr_sz) |
42 | #define NFS3_post_op_attr_sz (1+NFS3_fattr_sz) | 43 | #define NFS3_post_op_attr_sz (1+NFS3_fattr_sz) |
43 | #define NFS3_wcc_data_sz (NFS3_pre_op_attr_sz+NFS3_post_op_attr_sz) | 44 | #define NFS3_wcc_data_sz (NFS3_pre_op_attr_sz+NFS3_post_op_attr_sz) |
44 | #define NFS3_fsstat_sz | ||
45 | #define NFS3_fsinfo_sz | ||
46 | #define NFS3_pathconf_sz | ||
47 | #define NFS3_entry_sz (NFS3_filename_sz+3) | ||
48 | |||
49 | #define NFS3_sattrargs_sz (NFS3_fh_sz+NFS3_sattr_sz+3) | ||
50 | #define NFS3_diropargs_sz (NFS3_fh_sz+NFS3_filename_sz) | 45 | #define NFS3_diropargs_sz (NFS3_fh_sz+NFS3_filename_sz) |
51 | #define NFS3_removeargs_sz (NFS3_fh_sz+NFS3_filename_sz) | 46 | |
47 | #define NFS3_getattrargs_sz (NFS3_fh_sz) | ||
48 | #define NFS3_setattrargs_sz (NFS3_fh_sz+NFS3_sattr_sz+3) | ||
49 | #define NFS3_lookupargs_sz (NFS3_fh_sz+NFS3_filename_sz) | ||
52 | #define NFS3_accessargs_sz (NFS3_fh_sz+1) | 50 | #define NFS3_accessargs_sz (NFS3_fh_sz+1) |
53 | #define NFS3_readlinkargs_sz (NFS3_fh_sz) | 51 | #define NFS3_readlinkargs_sz (NFS3_fh_sz) |
54 | #define NFS3_readargs_sz (NFS3_fh_sz+3) | 52 | #define NFS3_readargs_sz (NFS3_fh_sz+3) |
@@ -57,14 +55,16 @@ | |||
57 | #define NFS3_mkdirargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz) | 55 | #define NFS3_mkdirargs_sz (NFS3_diropargs_sz+NFS3_sattr_sz) |
58 | #define NFS3_symlinkargs_sz (NFS3_diropargs_sz+1+NFS3_sattr_sz) | 56 | #define NFS3_symlinkargs_sz (NFS3_diropargs_sz+1+NFS3_sattr_sz) |
59 | #define NFS3_mknodargs_sz (NFS3_diropargs_sz+2+NFS3_sattr_sz) | 57 | #define NFS3_mknodargs_sz (NFS3_diropargs_sz+2+NFS3_sattr_sz) |
58 | #define NFS3_removeargs_sz (NFS3_fh_sz+NFS3_filename_sz) | ||
60 | #define NFS3_renameargs_sz (NFS3_diropargs_sz+NFS3_diropargs_sz) | 59 | #define NFS3_renameargs_sz (NFS3_diropargs_sz+NFS3_diropargs_sz) |
61 | #define NFS3_linkargs_sz (NFS3_fh_sz+NFS3_diropargs_sz) | 60 | #define NFS3_linkargs_sz (NFS3_fh_sz+NFS3_diropargs_sz) |
62 | #define NFS3_readdirargs_sz (NFS3_fh_sz+2) | 61 | #define NFS3_readdirargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+3) |
62 | #define NFS3_readdirplusargs_sz (NFS3_fh_sz+NFS3_cookieverf_sz+4) | ||
63 | #define NFS3_commitargs_sz (NFS3_fh_sz+3) | 63 | #define NFS3_commitargs_sz (NFS3_fh_sz+3) |
64 | 64 | ||
65 | #define NFS3_attrstat_sz (1+NFS3_fattr_sz) | 65 | #define NFS3_getattrres_sz (1+NFS3_fattr_sz) |
66 | #define NFS3_wccstat_sz (1+NFS3_wcc_data_sz) | 66 | #define NFS3_setattrres_sz (1+NFS3_wcc_data_sz) |
67 | #define NFS3_removeres_sz (NFS3_wccstat_sz) | 67 | #define NFS3_removeres_sz (NFS3_setattrres_sz) |
68 | #define NFS3_lookupres_sz (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz)) | 68 | #define NFS3_lookupres_sz (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz)) |
69 | #define NFS3_accessres_sz (1+NFS3_post_op_attr_sz+1) | 69 | #define NFS3_accessres_sz (1+NFS3_post_op_attr_sz+1) |
70 | #define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1) | 70 | #define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1) |
@@ -100,1079 +100,2362 @@ static const umode_t nfs_type2fmt[] = { | |||
100 | [NF3FIFO] = S_IFIFO, | 100 | [NF3FIFO] = S_IFIFO, |
101 | }; | 101 | }; |
102 | 102 | ||
103 | /* | ||
104 | * While encoding arguments, set up the reply buffer in advance to | ||
105 | * receive reply data directly into the page cache. | ||
106 | */ | ||
107 | static void prepare_reply_buffer(struct rpc_rqst *req, struct page **pages, | ||
108 | unsigned int base, unsigned int len, | ||
109 | unsigned int bufsize) | ||
110 | { | ||
111 | struct rpc_auth *auth = req->rq_cred->cr_auth; | ||
112 | unsigned int replen; | ||
113 | |||
114 | replen = RPC_REPHDRSIZE + auth->au_rslack + bufsize; | ||
115 | xdr_inline_pages(&req->rq_rcv_buf, replen << 2, pages, base, len); | ||
116 | } | ||
117 | |||
118 | /* | ||
119 | * Handle decode buffer overflows out-of-line. | ||
120 | */ | ||
103 | static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) | 121 | static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) |
104 | { | 122 | { |
105 | dprintk("nfs: %s: prematurely hit end of receive buffer. " | 123 | dprintk("NFS: %s prematurely hit the end of our receive buffer. " |
106 | "Remaining buffer length is %tu words.\n", | 124 | "Remaining buffer length is %tu words.\n", |
107 | func, xdr->end - xdr->p); | 125 | func, xdr->end - xdr->p); |
108 | } | 126 | } |
109 | 127 | ||
128 | |||
110 | /* | 129 | /* |
111 | * Common NFS XDR functions as inlines | 130 | * Encode/decode NFSv3 basic data types |
131 | * | ||
132 | * Basic NFSv3 data types are defined in section 2.5 of RFC 1813: | ||
133 | * "NFS Version 3 Protocol Specification". | ||
134 | * | ||
135 | * Not all basic data types have their own encoding and decoding | ||
136 | * functions. For run-time efficiency, some data types are encoded | ||
137 | * or decoded inline. | ||
112 | */ | 138 | */ |
113 | static inline __be32 * | 139 | |
114 | xdr_encode_fhandle(__be32 *p, const struct nfs_fh *fh) | 140 | static void encode_uint32(struct xdr_stream *xdr, u32 value) |
115 | { | 141 | { |
116 | return xdr_encode_array(p, fh->data, fh->size); | 142 | __be32 *p = xdr_reserve_space(xdr, 4); |
143 | *p = cpu_to_be32(value); | ||
117 | } | 144 | } |
118 | 145 | ||
119 | static inline __be32 * | 146 | static int decode_uint32(struct xdr_stream *xdr, u32 *value) |
120 | xdr_decode_fhandle(__be32 *p, struct nfs_fh *fh) | ||
121 | { | 147 | { |
122 | if ((fh->size = ntohl(*p++)) <= NFS3_FHSIZE) { | 148 | __be32 *p; |
123 | memcpy(fh->data, p, fh->size); | 149 | |
124 | return p + XDR_QUADLEN(fh->size); | 150 | p = xdr_inline_decode(xdr, 4); |
125 | } | 151 | if (unlikely(p == NULL)) |
126 | return NULL; | 152 | goto out_overflow; |
153 | *value = be32_to_cpup(p); | ||
154 | return 0; | ||
155 | out_overflow: | ||
156 | print_overflow_msg(__func__, xdr); | ||
157 | return -EIO; | ||
158 | } | ||
159 | |||
160 | static int decode_uint64(struct xdr_stream *xdr, u64 *value) | ||
161 | { | ||
162 | __be32 *p; | ||
163 | |||
164 | p = xdr_inline_decode(xdr, 8); | ||
165 | if (unlikely(p == NULL)) | ||
166 | goto out_overflow; | ||
167 | xdr_decode_hyper(p, value); | ||
168 | return 0; | ||
169 | out_overflow: | ||
170 | print_overflow_msg(__func__, xdr); | ||
171 | return -EIO; | ||
172 | } | ||
173 | |||
174 | /* | ||
175 | * fileid3 | ||
176 | * | ||
177 | * typedef uint64 fileid3; | ||
178 | */ | ||
179 | static __be32 *xdr_decode_fileid3(__be32 *p, u64 *fileid) | ||
180 | { | ||
181 | return xdr_decode_hyper(p, fileid); | ||
182 | } | ||
183 | |||
184 | static int decode_fileid3(struct xdr_stream *xdr, u64 *fileid) | ||
185 | { | ||
186 | return decode_uint64(xdr, fileid); | ||
187 | } | ||
188 | |||
189 | /* | ||
190 | * filename3 | ||
191 | * | ||
192 | * typedef string filename3<>; | ||
193 | */ | ||
194 | static void encode_filename3(struct xdr_stream *xdr, | ||
195 | const char *name, u32 length) | ||
196 | { | ||
197 | __be32 *p; | ||
198 | |||
199 | BUG_ON(length > NFS3_MAXNAMLEN); | ||
200 | p = xdr_reserve_space(xdr, 4 + length); | ||
201 | xdr_encode_opaque(p, name, length); | ||
127 | } | 202 | } |
128 | 203 | ||
129 | static inline __be32 * | 204 | static int decode_inline_filename3(struct xdr_stream *xdr, |
130 | xdr_decode_fhandle_stream(struct xdr_stream *xdr, struct nfs_fh *fh) | 205 | const char **name, u32 *length) |
131 | { | 206 | { |
132 | __be32 *p; | 207 | __be32 *p; |
208 | u32 count; | ||
209 | |||
133 | p = xdr_inline_decode(xdr, 4); | 210 | p = xdr_inline_decode(xdr, 4); |
134 | if (unlikely(!p)) | 211 | if (unlikely(p == NULL)) |
212 | goto out_overflow; | ||
213 | count = be32_to_cpup(p); | ||
214 | if (count > NFS3_MAXNAMLEN) | ||
215 | goto out_nametoolong; | ||
216 | p = xdr_inline_decode(xdr, count); | ||
217 | if (unlikely(p == NULL)) | ||
135 | goto out_overflow; | 218 | goto out_overflow; |
136 | fh->size = ntohl(*p++); | 219 | *name = (const char *)p; |
220 | *length = count; | ||
221 | return 0; | ||
137 | 222 | ||
138 | if (fh->size <= NFS3_FHSIZE) { | 223 | out_nametoolong: |
139 | p = xdr_inline_decode(xdr, fh->size); | 224 | dprintk("NFS: returned filename too long: %u\n", count); |
140 | if (unlikely(!p)) | 225 | return -ENAMETOOLONG; |
141 | goto out_overflow; | 226 | out_overflow: |
142 | memcpy(fh->data, p, fh->size); | 227 | print_overflow_msg(__func__, xdr); |
143 | return p + XDR_QUADLEN(fh->size); | 228 | return -EIO; |
144 | } | 229 | } |
145 | return NULL; | 230 | |
231 | /* | ||
232 | * nfspath3 | ||
233 | * | ||
234 | * typedef string nfspath3<>; | ||
235 | */ | ||
236 | static void encode_nfspath3(struct xdr_stream *xdr, struct page **pages, | ||
237 | const u32 length) | ||
238 | { | ||
239 | BUG_ON(length > NFS3_MAXPATHLEN); | ||
240 | encode_uint32(xdr, length); | ||
241 | xdr_write_pages(xdr, pages, 0, length); | ||
242 | } | ||
146 | 243 | ||
244 | static int decode_nfspath3(struct xdr_stream *xdr) | ||
245 | { | ||
246 | u32 recvd, count; | ||
247 | size_t hdrlen; | ||
248 | __be32 *p; | ||
249 | |||
250 | p = xdr_inline_decode(xdr, 4); | ||
251 | if (unlikely(p == NULL)) | ||
252 | goto out_overflow; | ||
253 | count = be32_to_cpup(p); | ||
254 | if (unlikely(count >= xdr->buf->page_len || count > NFS3_MAXPATHLEN)) | ||
255 | goto out_nametoolong; | ||
256 | hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base; | ||
257 | recvd = xdr->buf->len - hdrlen; | ||
258 | if (unlikely(count > recvd)) | ||
259 | goto out_cheating; | ||
260 | |||
261 | xdr_read_pages(xdr, count); | ||
262 | xdr_terminate_string(xdr->buf, count); | ||
263 | return 0; | ||
264 | |||
265 | out_nametoolong: | ||
266 | dprintk("NFS: returned pathname too long: %u\n", count); | ||
267 | return -ENAMETOOLONG; | ||
268 | out_cheating: | ||
269 | dprintk("NFS: server cheating in pathname result: " | ||
270 | "count %u > recvd %u\n", count, recvd); | ||
271 | return -EIO; | ||
147 | out_overflow: | 272 | out_overflow: |
148 | print_overflow_msg(__func__, xdr); | 273 | print_overflow_msg(__func__, xdr); |
149 | return ERR_PTR(-EIO); | 274 | return -EIO; |
150 | } | 275 | } |
151 | 276 | ||
152 | /* | 277 | /* |
153 | * Encode/decode time. | 278 | * cookie3 |
279 | * | ||
280 | * typedef uint64 cookie3 | ||
154 | */ | 281 | */ |
155 | static inline __be32 * | 282 | static __be32 *xdr_encode_cookie3(__be32 *p, u64 cookie) |
156 | xdr_encode_time3(__be32 *p, struct timespec *timep) | ||
157 | { | 283 | { |
158 | *p++ = htonl(timep->tv_sec); | 284 | return xdr_encode_hyper(p, cookie); |
159 | *p++ = htonl(timep->tv_nsec); | ||
160 | return p; | ||
161 | } | 285 | } |
162 | 286 | ||
163 | static inline __be32 * | 287 | static int decode_cookie3(struct xdr_stream *xdr, u64 *cookie) |
164 | xdr_decode_time3(__be32 *p, struct timespec *timep) | ||
165 | { | 288 | { |
166 | timep->tv_sec = ntohl(*p++); | 289 | return decode_uint64(xdr, cookie); |
167 | timep->tv_nsec = ntohl(*p++); | 290 | } |
168 | return p; | 291 | |
292 | /* | ||
293 | * cookieverf3 | ||
294 | * | ||
295 | * typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE]; | ||
296 | */ | ||
297 | static __be32 *xdr_encode_cookieverf3(__be32 *p, const __be32 *verifier) | ||
298 | { | ||
299 | memcpy(p, verifier, NFS3_COOKIEVERFSIZE); | ||
300 | return p + XDR_QUADLEN(NFS3_COOKIEVERFSIZE); | ||
301 | } | ||
302 | |||
303 | static int decode_cookieverf3(struct xdr_stream *xdr, __be32 *verifier) | ||
304 | { | ||
305 | __be32 *p; | ||
306 | |||
307 | p = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE); | ||
308 | if (unlikely(p == NULL)) | ||
309 | goto out_overflow; | ||
310 | memcpy(verifier, p, NFS3_COOKIEVERFSIZE); | ||
311 | return 0; | ||
312 | out_overflow: | ||
313 | print_overflow_msg(__func__, xdr); | ||
314 | return -EIO; | ||
315 | } | ||
316 | |||
317 | /* | ||
318 | * createverf3 | ||
319 | * | ||
320 | * typedef opaque createverf3[NFS3_CREATEVERFSIZE]; | ||
321 | */ | ||
322 | static void encode_createverf3(struct xdr_stream *xdr, const __be32 *verifier) | ||
323 | { | ||
324 | __be32 *p; | ||
325 | |||
326 | p = xdr_reserve_space(xdr, NFS3_CREATEVERFSIZE); | ||
327 | memcpy(p, verifier, NFS3_CREATEVERFSIZE); | ||
328 | } | ||
329 | |||
330 | static int decode_writeverf3(struct xdr_stream *xdr, __be32 *verifier) | ||
331 | { | ||
332 | __be32 *p; | ||
333 | |||
334 | p = xdr_inline_decode(xdr, NFS3_WRITEVERFSIZE); | ||
335 | if (unlikely(p == NULL)) | ||
336 | goto out_overflow; | ||
337 | memcpy(verifier, p, NFS3_WRITEVERFSIZE); | ||
338 | return 0; | ||
339 | out_overflow: | ||
340 | print_overflow_msg(__func__, xdr); | ||
341 | return -EIO; | ||
342 | } | ||
343 | |||
344 | /* | ||
345 | * size3 | ||
346 | * | ||
347 | * typedef uint64 size3; | ||
348 | */ | ||
349 | static __be32 *xdr_decode_size3(__be32 *p, u64 *size) | ||
350 | { | ||
351 | return xdr_decode_hyper(p, size); | ||
352 | } | ||
353 | |||
354 | /* | ||
355 | * nfsstat3 | ||
356 | * | ||
357 | * enum nfsstat3 { | ||
358 | * NFS3_OK = 0, | ||
359 | * ... | ||
360 | * } | ||
361 | */ | ||
362 | #define NFS3_OK NFS_OK | ||
363 | |||
364 | static int decode_nfsstat3(struct xdr_stream *xdr, enum nfs_stat *status) | ||
365 | { | ||
366 | __be32 *p; | ||
367 | |||
368 | p = xdr_inline_decode(xdr, 4); | ||
369 | if (unlikely(p == NULL)) | ||
370 | goto out_overflow; | ||
371 | *status = be32_to_cpup(p); | ||
372 | return 0; | ||
373 | out_overflow: | ||
374 | print_overflow_msg(__func__, xdr); | ||
375 | return -EIO; | ||
376 | } | ||
377 | |||
378 | /* | ||
379 | * ftype3 | ||
380 | * | ||
381 | * enum ftype3 { | ||
382 | * NF3REG = 1, | ||
383 | * NF3DIR = 2, | ||
384 | * NF3BLK = 3, | ||
385 | * NF3CHR = 4, | ||
386 | * NF3LNK = 5, | ||
387 | * NF3SOCK = 6, | ||
388 | * NF3FIFO = 7 | ||
389 | * }; | ||
390 | */ | ||
391 | static void encode_ftype3(struct xdr_stream *xdr, const u32 type) | ||
392 | { | ||
393 | BUG_ON(type > NF3FIFO); | ||
394 | encode_uint32(xdr, type); | ||
169 | } | 395 | } |
170 | 396 | ||
171 | static __be32 * | 397 | static __be32 *xdr_decode_ftype3(__be32 *p, umode_t *mode) |
172 | xdr_decode_fattr(__be32 *p, struct nfs_fattr *fattr) | ||
173 | { | 398 | { |
174 | unsigned int type, major, minor; | 399 | u32 type; |
175 | umode_t fmode; | ||
176 | 400 | ||
177 | type = ntohl(*p++); | 401 | type = be32_to_cpup(p++); |
178 | if (type > NF3FIFO) | 402 | if (type > NF3FIFO) |
179 | type = NF3NON; | 403 | type = NF3NON; |
180 | fmode = nfs_type2fmt[type]; | 404 | *mode = nfs_type2fmt[type]; |
181 | fattr->mode = (ntohl(*p++) & ~S_IFMT) | fmode; | 405 | return p; |
182 | fattr->nlink = ntohl(*p++); | 406 | } |
183 | fattr->uid = ntohl(*p++); | ||
184 | fattr->gid = ntohl(*p++); | ||
185 | p = xdr_decode_hyper(p, &fattr->size); | ||
186 | p = xdr_decode_hyper(p, &fattr->du.nfs3.used); | ||
187 | |||
188 | /* Turn remote device info into Linux-specific dev_t */ | ||
189 | major = ntohl(*p++); | ||
190 | minor = ntohl(*p++); | ||
191 | fattr->rdev = MKDEV(major, minor); | ||
192 | if (MAJOR(fattr->rdev) != major || MINOR(fattr->rdev) != minor) | ||
193 | fattr->rdev = 0; | ||
194 | 407 | ||
195 | p = xdr_decode_hyper(p, &fattr->fsid.major); | 408 | /* |
196 | fattr->fsid.minor = 0; | 409 | * specdata3 |
197 | p = xdr_decode_hyper(p, &fattr->fileid); | 410 | * |
198 | p = xdr_decode_time3(p, &fattr->atime); | 411 | * struct specdata3 { |
199 | p = xdr_decode_time3(p, &fattr->mtime); | 412 | * uint32 specdata1; |
200 | p = xdr_decode_time3(p, &fattr->ctime); | 413 | * uint32 specdata2; |
414 | * }; | ||
415 | */ | ||
416 | static void encode_specdata3(struct xdr_stream *xdr, const dev_t rdev) | ||
417 | { | ||
418 | __be32 *p; | ||
201 | 419 | ||
202 | /* Update the mode bits */ | 420 | p = xdr_reserve_space(xdr, 8); |
203 | fattr->valid |= NFS_ATTR_FATTR_V3; | 421 | *p++ = cpu_to_be32(MAJOR(rdev)); |
422 | *p = cpu_to_be32(MINOR(rdev)); | ||
423 | } | ||
424 | |||
425 | static __be32 *xdr_decode_specdata3(__be32 *p, dev_t *rdev) | ||
426 | { | ||
427 | unsigned int major, minor; | ||
428 | |||
429 | major = be32_to_cpup(p++); | ||
430 | minor = be32_to_cpup(p++); | ||
431 | *rdev = MKDEV(major, minor); | ||
432 | if (MAJOR(*rdev) != major || MINOR(*rdev) != minor) | ||
433 | *rdev = 0; | ||
434 | return p; | ||
435 | } | ||
436 | |||
437 | /* | ||
438 | * nfs_fh3 | ||
439 | * | ||
440 | * struct nfs_fh3 { | ||
441 | * opaque data<NFS3_FHSIZE>; | ||
442 | * }; | ||
443 | */ | ||
444 | static void encode_nfs_fh3(struct xdr_stream *xdr, const struct nfs_fh *fh) | ||
445 | { | ||
446 | __be32 *p; | ||
447 | |||
448 | BUG_ON(fh->size > NFS3_FHSIZE); | ||
449 | p = xdr_reserve_space(xdr, 4 + fh->size); | ||
450 | xdr_encode_opaque(p, fh->data, fh->size); | ||
451 | } | ||
452 | |||
453 | static int decode_nfs_fh3(struct xdr_stream *xdr, struct nfs_fh *fh) | ||
454 | { | ||
455 | u32 length; | ||
456 | __be32 *p; | ||
457 | |||
458 | p = xdr_inline_decode(xdr, 4); | ||
459 | if (unlikely(p == NULL)) | ||
460 | goto out_overflow; | ||
461 | length = be32_to_cpup(p++); | ||
462 | if (unlikely(length > NFS3_FHSIZE)) | ||
463 | goto out_toobig; | ||
464 | p = xdr_inline_decode(xdr, length); | ||
465 | if (unlikely(p == NULL)) | ||
466 | goto out_overflow; | ||
467 | fh->size = length; | ||
468 | memcpy(fh->data, p, length); | ||
469 | return 0; | ||
470 | out_toobig: | ||
471 | dprintk("NFS: file handle size (%u) too big\n", length); | ||
472 | return -E2BIG; | ||
473 | out_overflow: | ||
474 | print_overflow_msg(__func__, xdr); | ||
475 | return -EIO; | ||
476 | } | ||
477 | |||
478 | static void zero_nfs_fh3(struct nfs_fh *fh) | ||
479 | { | ||
480 | memset(fh, 0, sizeof(*fh)); | ||
481 | } | ||
482 | |||
483 | /* | ||
484 | * nfstime3 | ||
485 | * | ||
486 | * struct nfstime3 { | ||
487 | * uint32 seconds; | ||
488 | * uint32 nseconds; | ||
489 | * }; | ||
490 | */ | ||
491 | static __be32 *xdr_encode_nfstime3(__be32 *p, const struct timespec *timep) | ||
492 | { | ||
493 | *p++ = cpu_to_be32(timep->tv_sec); | ||
494 | *p++ = cpu_to_be32(timep->tv_nsec); | ||
204 | return p; | 495 | return p; |
205 | } | 496 | } |
206 | 497 | ||
207 | static inline __be32 * | 498 | static __be32 *xdr_decode_nfstime3(__be32 *p, struct timespec *timep) |
208 | xdr_encode_sattr(__be32 *p, struct iattr *attr) | ||
209 | { | 499 | { |
500 | timep->tv_sec = be32_to_cpup(p++); | ||
501 | timep->tv_nsec = be32_to_cpup(p++); | ||
502 | return p; | ||
503 | } | ||
504 | |||
505 | /* | ||
506 | * sattr3 | ||
507 | * | ||
508 | * enum time_how { | ||
509 | * DONT_CHANGE = 0, | ||
510 | * SET_TO_SERVER_TIME = 1, | ||
511 | * SET_TO_CLIENT_TIME = 2 | ||
512 | * }; | ||
513 | * | ||
514 | * union set_mode3 switch (bool set_it) { | ||
515 | * case TRUE: | ||
516 | * mode3 mode; | ||
517 | * default: | ||
518 | * void; | ||
519 | * }; | ||
520 | * | ||
521 | * union set_uid3 switch (bool set_it) { | ||
522 | * case TRUE: | ||
523 | * uid3 uid; | ||
524 | * default: | ||
525 | * void; | ||
526 | * }; | ||
527 | * | ||
528 | * union set_gid3 switch (bool set_it) { | ||
529 | * case TRUE: | ||
530 | * gid3 gid; | ||
531 | * default: | ||
532 | * void; | ||
533 | * }; | ||
534 | * | ||
535 | * union set_size3 switch (bool set_it) { | ||
536 | * case TRUE: | ||
537 | * size3 size; | ||
538 | * default: | ||
539 | * void; | ||
540 | * }; | ||
541 | * | ||
542 | * union set_atime switch (time_how set_it) { | ||
543 | * case SET_TO_CLIENT_TIME: | ||
544 | * nfstime3 atime; | ||
545 | * default: | ||
546 | * void; | ||
547 | * }; | ||
548 | * | ||
549 | * union set_mtime switch (time_how set_it) { | ||
550 | * case SET_TO_CLIENT_TIME: | ||
551 | * nfstime3 mtime; | ||
552 | * default: | ||
553 | * void; | ||
554 | * }; | ||
555 | * | ||
556 | * struct sattr3 { | ||
557 | * set_mode3 mode; | ||
558 | * set_uid3 uid; | ||
559 | * set_gid3 gid; | ||
560 | * set_size3 size; | ||
561 | * set_atime atime; | ||
562 | * set_mtime mtime; | ||
563 | * }; | ||
564 | */ | ||
565 | static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr) | ||
566 | { | ||
567 | u32 nbytes; | ||
568 | __be32 *p; | ||
569 | |||
570 | /* | ||
571 | * In order to make only a single xdr_reserve_space() call, | ||
572 | * pre-compute the total number of bytes to be reserved. | ||
573 | * Six boolean values, one for each set_foo field, are always | ||
574 | * present in the encoded result, so start there. | ||
575 | */ | ||
576 | nbytes = 6 * 4; | ||
577 | if (attr->ia_valid & ATTR_MODE) | ||
578 | nbytes += 4; | ||
579 | if (attr->ia_valid & ATTR_UID) | ||
580 | nbytes += 4; | ||
581 | if (attr->ia_valid & ATTR_GID) | ||
582 | nbytes += 4; | ||
583 | if (attr->ia_valid & ATTR_SIZE) | ||
584 | nbytes += 8; | ||
585 | if (attr->ia_valid & ATTR_ATIME_SET) | ||
586 | nbytes += 8; | ||
587 | if (attr->ia_valid & ATTR_MTIME_SET) | ||
588 | nbytes += 8; | ||
589 | p = xdr_reserve_space(xdr, nbytes); | ||
590 | |||
210 | if (attr->ia_valid & ATTR_MODE) { | 591 | if (attr->ia_valid & ATTR_MODE) { |
211 | *p++ = xdr_one; | 592 | *p++ = xdr_one; |
212 | *p++ = htonl(attr->ia_mode & S_IALLUGO); | 593 | *p++ = cpu_to_be32(attr->ia_mode & S_IALLUGO); |
213 | } else { | 594 | } else |
214 | *p++ = xdr_zero; | 595 | *p++ = xdr_zero; |
215 | } | 596 | |
216 | if (attr->ia_valid & ATTR_UID) { | 597 | if (attr->ia_valid & ATTR_UID) { |
217 | *p++ = xdr_one; | 598 | *p++ = xdr_one; |
218 | *p++ = htonl(attr->ia_uid); | 599 | *p++ = cpu_to_be32(attr->ia_uid); |
219 | } else { | 600 | } else |
220 | *p++ = xdr_zero; | 601 | *p++ = xdr_zero; |
221 | } | 602 | |
222 | if (attr->ia_valid & ATTR_GID) { | 603 | if (attr->ia_valid & ATTR_GID) { |
223 | *p++ = xdr_one; | 604 | *p++ = xdr_one; |
224 | *p++ = htonl(attr->ia_gid); | 605 | *p++ = cpu_to_be32(attr->ia_gid); |
225 | } else { | 606 | } else |
226 | *p++ = xdr_zero; | 607 | *p++ = xdr_zero; |
227 | } | 608 | |
228 | if (attr->ia_valid & ATTR_SIZE) { | 609 | if (attr->ia_valid & ATTR_SIZE) { |
229 | *p++ = xdr_one; | 610 | *p++ = xdr_one; |
230 | p = xdr_encode_hyper(p, (__u64) attr->ia_size); | 611 | p = xdr_encode_hyper(p, (u64)attr->ia_size); |
231 | } else { | 612 | } else |
232 | *p++ = xdr_zero; | 613 | *p++ = xdr_zero; |
233 | } | 614 | |
234 | if (attr->ia_valid & ATTR_ATIME_SET) { | 615 | if (attr->ia_valid & ATTR_ATIME_SET) { |
235 | *p++ = xdr_two; | 616 | *p++ = xdr_two; |
236 | p = xdr_encode_time3(p, &attr->ia_atime); | 617 | p = xdr_encode_nfstime3(p, &attr->ia_atime); |
237 | } else if (attr->ia_valid & ATTR_ATIME) { | 618 | } else if (attr->ia_valid & ATTR_ATIME) { |
238 | *p++ = xdr_one; | 619 | *p++ = xdr_one; |
239 | } else { | 620 | } else |
240 | *p++ = xdr_zero; | 621 | *p++ = xdr_zero; |
241 | } | 622 | |
242 | if (attr->ia_valid & ATTR_MTIME_SET) { | 623 | if (attr->ia_valid & ATTR_MTIME_SET) { |
243 | *p++ = xdr_two; | 624 | *p++ = xdr_two; |
244 | p = xdr_encode_time3(p, &attr->ia_mtime); | 625 | xdr_encode_nfstime3(p, &attr->ia_mtime); |
245 | } else if (attr->ia_valid & ATTR_MTIME) { | 626 | } else if (attr->ia_valid & ATTR_MTIME) { |
246 | *p++ = xdr_one; | 627 | *p = xdr_one; |
247 | } else { | 628 | } else |
248 | *p++ = xdr_zero; | 629 | *p = xdr_zero; |
249 | } | 630 | } |
250 | return p; | 631 | |
632 | /* | ||
633 | * fattr3 | ||
634 | * | ||
635 | * struct fattr3 { | ||
636 | * ftype3 type; | ||
637 | * mode3 mode; | ||
638 | * uint32 nlink; | ||
639 | * uid3 uid; | ||
640 | * gid3 gid; | ||
641 | * size3 size; | ||
642 | * size3 used; | ||
643 | * specdata3 rdev; | ||
644 | * uint64 fsid; | ||
645 | * fileid3 fileid; | ||
646 | * nfstime3 atime; | ||
647 | * nfstime3 mtime; | ||
648 | * nfstime3 ctime; | ||
649 | * }; | ||
650 | */ | ||
651 | static int decode_fattr3(struct xdr_stream *xdr, struct nfs_fattr *fattr) | ||
652 | { | ||
653 | umode_t fmode; | ||
654 | __be32 *p; | ||
655 | |||
656 | p = xdr_inline_decode(xdr, NFS3_fattr_sz << 2); | ||
657 | if (unlikely(p == NULL)) | ||
658 | goto out_overflow; | ||
659 | |||
660 | p = xdr_decode_ftype3(p, &fmode); | ||
661 | |||
662 | fattr->mode = (be32_to_cpup(p++) & ~S_IFMT) | fmode; | ||
663 | fattr->nlink = be32_to_cpup(p++); | ||
664 | fattr->uid = be32_to_cpup(p++); | ||
665 | fattr->gid = be32_to_cpup(p++); | ||
666 | |||
667 | p = xdr_decode_size3(p, &fattr->size); | ||
668 | p = xdr_decode_size3(p, &fattr->du.nfs3.used); | ||
669 | p = xdr_decode_specdata3(p, &fattr->rdev); | ||
670 | |||
671 | p = xdr_decode_hyper(p, &fattr->fsid.major); | ||
672 | fattr->fsid.minor = 0; | ||
673 | |||
674 | p = xdr_decode_fileid3(p, &fattr->fileid); | ||
675 | p = xdr_decode_nfstime3(p, &fattr->atime); | ||
676 | p = xdr_decode_nfstime3(p, &fattr->mtime); | ||
677 | xdr_decode_nfstime3(p, &fattr->ctime); | ||
678 | |||
679 | fattr->valid |= NFS_ATTR_FATTR_V3; | ||
680 | return 0; | ||
681 | out_overflow: | ||
682 | print_overflow_msg(__func__, xdr); | ||
683 | return -EIO; | ||
251 | } | 684 | } |
252 | 685 | ||
253 | static inline __be32 * | 686 | /* |
254 | xdr_decode_wcc_attr(__be32 *p, struct nfs_fattr *fattr) | 687 | * post_op_attr |
688 | * | ||
689 | * union post_op_attr switch (bool attributes_follow) { | ||
690 | * case TRUE: | ||
691 | * fattr3 attributes; | ||
692 | * case FALSE: | ||
693 | * void; | ||
694 | * }; | ||
695 | */ | ||
696 | static int decode_post_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr) | ||
255 | { | 697 | { |
256 | p = xdr_decode_hyper(p, &fattr->pre_size); | 698 | __be32 *p; |
257 | p = xdr_decode_time3(p, &fattr->pre_mtime); | 699 | |
258 | p = xdr_decode_time3(p, &fattr->pre_ctime); | 700 | p = xdr_inline_decode(xdr, 4); |
701 | if (unlikely(p == NULL)) | ||
702 | goto out_overflow; | ||
703 | if (*p != xdr_zero) | ||
704 | return decode_fattr3(xdr, fattr); | ||
705 | return 0; | ||
706 | out_overflow: | ||
707 | print_overflow_msg(__func__, xdr); | ||
708 | return -EIO; | ||
709 | } | ||
710 | |||
711 | /* | ||
712 | * wcc_attr | ||
713 | * struct wcc_attr { | ||
714 | * size3 size; | ||
715 | * nfstime3 mtime; | ||
716 | * nfstime3 ctime; | ||
717 | * }; | ||
718 | */ | ||
719 | static int decode_wcc_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr) | ||
720 | { | ||
721 | __be32 *p; | ||
722 | |||
723 | p = xdr_inline_decode(xdr, NFS3_wcc_attr_sz << 2); | ||
724 | if (unlikely(p == NULL)) | ||
725 | goto out_overflow; | ||
726 | |||
259 | fattr->valid |= NFS_ATTR_FATTR_PRESIZE | 727 | fattr->valid |= NFS_ATTR_FATTR_PRESIZE |
260 | | NFS_ATTR_FATTR_PREMTIME | 728 | | NFS_ATTR_FATTR_PREMTIME |
261 | | NFS_ATTR_FATTR_PRECTIME; | 729 | | NFS_ATTR_FATTR_PRECTIME; |
262 | return p; | ||
263 | } | ||
264 | 730 | ||
265 | static inline __be32 * | 731 | p = xdr_decode_size3(p, &fattr->pre_size); |
266 | xdr_decode_post_op_attr(__be32 *p, struct nfs_fattr *fattr) | 732 | p = xdr_decode_nfstime3(p, &fattr->pre_mtime); |
267 | { | 733 | xdr_decode_nfstime3(p, &fattr->pre_ctime); |
268 | if (*p++) | 734 | |
269 | p = xdr_decode_fattr(p, fattr); | 735 | return 0; |
270 | return p; | 736 | out_overflow: |
737 | print_overflow_msg(__func__, xdr); | ||
738 | return -EIO; | ||
271 | } | 739 | } |
272 | 740 | ||
273 | static inline __be32 * | 741 | /* |
274 | xdr_decode_post_op_attr_stream(struct xdr_stream *xdr, struct nfs_fattr *fattr) | 742 | * pre_op_attr |
743 | * union pre_op_attr switch (bool attributes_follow) { | ||
744 | * case TRUE: | ||
745 | * wcc_attr attributes; | ||
746 | * case FALSE: | ||
747 | * void; | ||
748 | * }; | ||
749 | * | ||
750 | * wcc_data | ||
751 | * | ||
752 | * struct wcc_data { | ||
753 | * pre_op_attr before; | ||
754 | * post_op_attr after; | ||
755 | * }; | ||
756 | */ | ||
757 | static int decode_pre_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr) | ||
275 | { | 758 | { |
276 | __be32 *p; | 759 | __be32 *p; |
277 | 760 | ||
278 | p = xdr_inline_decode(xdr, 4); | 761 | p = xdr_inline_decode(xdr, 4); |
279 | if (unlikely(!p)) | 762 | if (unlikely(p == NULL)) |
280 | goto out_overflow; | 763 | goto out_overflow; |
281 | if (ntohl(*p++)) { | 764 | if (*p != xdr_zero) |
282 | p = xdr_inline_decode(xdr, 84); | 765 | return decode_wcc_attr(xdr, fattr); |
283 | if (unlikely(!p)) | 766 | return 0; |
284 | goto out_overflow; | ||
285 | p = xdr_decode_fattr(p, fattr); | ||
286 | } | ||
287 | return p; | ||
288 | out_overflow: | 767 | out_overflow: |
289 | print_overflow_msg(__func__, xdr); | 768 | print_overflow_msg(__func__, xdr); |
290 | return ERR_PTR(-EIO); | 769 | return -EIO; |
291 | } | 770 | } |
292 | 771 | ||
293 | static inline __be32 * | 772 | static int decode_wcc_data(struct xdr_stream *xdr, struct nfs_fattr *fattr) |
294 | xdr_decode_pre_op_attr(__be32 *p, struct nfs_fattr *fattr) | ||
295 | { | 773 | { |
296 | if (*p++) | 774 | int error; |
297 | return xdr_decode_wcc_attr(p, fattr); | 775 | |
298 | return p; | 776 | error = decode_pre_op_attr(xdr, fattr); |
777 | if (unlikely(error)) | ||
778 | goto out; | ||
779 | error = decode_post_op_attr(xdr, fattr); | ||
780 | out: | ||
781 | return error; | ||
299 | } | 782 | } |
300 | 783 | ||
784 | /* | ||
785 | * post_op_fh3 | ||
786 | * | ||
787 | * union post_op_fh3 switch (bool handle_follows) { | ||
788 | * case TRUE: | ||
789 | * nfs_fh3 handle; | ||
790 | * case FALSE: | ||
791 | * void; | ||
792 | * }; | ||
793 | */ | ||
794 | static int decode_post_op_fh3(struct xdr_stream *xdr, struct nfs_fh *fh) | ||
795 | { | ||
796 | __be32 *p = xdr_inline_decode(xdr, 4); | ||
797 | if (unlikely(p == NULL)) | ||
798 | goto out_overflow; | ||
799 | if (*p != xdr_zero) | ||
800 | return decode_nfs_fh3(xdr, fh); | ||
801 | zero_nfs_fh3(fh); | ||
802 | return 0; | ||
803 | out_overflow: | ||
804 | print_overflow_msg(__func__, xdr); | ||
805 | return -EIO; | ||
806 | } | ||
301 | 807 | ||
302 | static inline __be32 * | 808 | /* |
303 | xdr_decode_wcc_data(__be32 *p, struct nfs_fattr *fattr) | 809 | * diropargs3 |
810 | * | ||
811 | * struct diropargs3 { | ||
812 | * nfs_fh3 dir; | ||
813 | * filename3 name; | ||
814 | * }; | ||
815 | */ | ||
816 | static void encode_diropargs3(struct xdr_stream *xdr, const struct nfs_fh *fh, | ||
817 | const char *name, u32 length) | ||
304 | { | 818 | { |
305 | p = xdr_decode_pre_op_attr(p, fattr); | 819 | encode_nfs_fh3(xdr, fh); |
306 | return xdr_decode_post_op_attr(p, fattr); | 820 | encode_filename3(xdr, name, length); |
307 | } | 821 | } |
308 | 822 | ||
823 | |||
309 | /* | 824 | /* |
310 | * NFS encode functions | 825 | * NFSv3 XDR encode functions |
826 | * | ||
827 | * NFSv3 argument types are defined in section 3.3 of RFC 1813: | ||
828 | * "NFS Version 3 Protocol Specification". | ||
311 | */ | 829 | */ |
312 | 830 | ||
313 | /* | 831 | /* |
314 | * Encode file handle argument | 832 | * 3.3.1 GETATTR3args |
833 | * | ||
834 | * struct GETATTR3args { | ||
835 | * nfs_fh3 object; | ||
836 | * }; | ||
315 | */ | 837 | */ |
316 | static int | 838 | static void nfs3_xdr_enc_getattr3args(struct rpc_rqst *req, |
317 | nfs3_xdr_fhandle(struct rpc_rqst *req, __be32 *p, struct nfs_fh *fh) | 839 | struct xdr_stream *xdr, |
840 | const struct nfs_fh *fh) | ||
318 | { | 841 | { |
319 | p = xdr_encode_fhandle(p, fh); | 842 | encode_nfs_fh3(xdr, fh); |
320 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
321 | return 0; | ||
322 | } | 843 | } |
323 | 844 | ||
324 | /* | 845 | /* |
325 | * Encode SETATTR arguments | 846 | * 3.3.2 SETATTR3args |
847 | * | ||
848 | * union sattrguard3 switch (bool check) { | ||
849 | * case TRUE: | ||
850 | * nfstime3 obj_ctime; | ||
851 | * case FALSE: | ||
852 | * void; | ||
853 | * }; | ||
854 | * | ||
855 | * struct SETATTR3args { | ||
856 | * nfs_fh3 object; | ||
857 | * sattr3 new_attributes; | ||
858 | * sattrguard3 guard; | ||
859 | * }; | ||
326 | */ | 860 | */ |
327 | static int | 861 | static void encode_sattrguard3(struct xdr_stream *xdr, |
328 | nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args) | 862 | const struct nfs3_sattrargs *args) |
329 | { | 863 | { |
330 | p = xdr_encode_fhandle(p, args->fh); | 864 | __be32 *p; |
331 | p = xdr_encode_sattr(p, args->sattr); | 865 | |
332 | *p++ = htonl(args->guard); | 866 | if (args->guard) { |
333 | if (args->guard) | 867 | p = xdr_reserve_space(xdr, 4 + 8); |
334 | p = xdr_encode_time3(p, &args->guardtime); | 868 | *p++ = xdr_one; |
335 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 869 | xdr_encode_nfstime3(p, &args->guardtime); |
336 | return 0; | 870 | } else { |
871 | p = xdr_reserve_space(xdr, 4); | ||
872 | *p = xdr_zero; | ||
873 | } | ||
874 | } | ||
875 | |||
876 | static void nfs3_xdr_enc_setattr3args(struct rpc_rqst *req, | ||
877 | struct xdr_stream *xdr, | ||
878 | const struct nfs3_sattrargs *args) | ||
879 | { | ||
880 | encode_nfs_fh3(xdr, args->fh); | ||
881 | encode_sattr3(xdr, args->sattr); | ||
882 | encode_sattrguard3(xdr, args); | ||
337 | } | 883 | } |
338 | 884 | ||
339 | /* | 885 | /* |
340 | * Encode directory ops argument | 886 | * 3.3.3 LOOKUP3args |
887 | * | ||
888 | * struct LOOKUP3args { | ||
889 | * diropargs3 what; | ||
890 | * }; | ||
341 | */ | 891 | */ |
342 | static int | 892 | static void nfs3_xdr_enc_lookup3args(struct rpc_rqst *req, |
343 | nfs3_xdr_diropargs(struct rpc_rqst *req, __be32 *p, struct nfs3_diropargs *args) | 893 | struct xdr_stream *xdr, |
894 | const struct nfs3_diropargs *args) | ||
344 | { | 895 | { |
345 | p = xdr_encode_fhandle(p, args->fh); | 896 | encode_diropargs3(xdr, args->fh, args->name, args->len); |
346 | p = xdr_encode_array(p, args->name, args->len); | ||
347 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
348 | return 0; | ||
349 | } | 897 | } |
350 | 898 | ||
351 | /* | 899 | /* |
352 | * Encode REMOVE argument | 900 | * 3.3.4 ACCESS3args |
901 | * | ||
902 | * struct ACCESS3args { | ||
903 | * nfs_fh3 object; | ||
904 | * uint32 access; | ||
905 | * }; | ||
353 | */ | 906 | */ |
354 | static int | 907 | static void encode_access3args(struct xdr_stream *xdr, |
355 | nfs3_xdr_removeargs(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args) | 908 | const struct nfs3_accessargs *args) |
356 | { | 909 | { |
357 | p = xdr_encode_fhandle(p, args->fh); | 910 | encode_nfs_fh3(xdr, args->fh); |
358 | p = xdr_encode_array(p, args->name.name, args->name.len); | 911 | encode_uint32(xdr, args->access); |
359 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 912 | } |
360 | return 0; | 913 | |
914 | static void nfs3_xdr_enc_access3args(struct rpc_rqst *req, | ||
915 | struct xdr_stream *xdr, | ||
916 | const struct nfs3_accessargs *args) | ||
917 | { | ||
918 | encode_access3args(xdr, args); | ||
361 | } | 919 | } |
362 | 920 | ||
363 | /* | 921 | /* |
364 | * Encode access() argument | 922 | * 3.3.5 READLINK3args |
923 | * | ||
924 | * struct READLINK3args { | ||
925 | * nfs_fh3 symlink; | ||
926 | * }; | ||
365 | */ | 927 | */ |
366 | static int | 928 | static void nfs3_xdr_enc_readlink3args(struct rpc_rqst *req, |
367 | nfs3_xdr_accessargs(struct rpc_rqst *req, __be32 *p, struct nfs3_accessargs *args) | 929 | struct xdr_stream *xdr, |
930 | const struct nfs3_readlinkargs *args) | ||
368 | { | 931 | { |
369 | p = xdr_encode_fhandle(p, args->fh); | 932 | encode_nfs_fh3(xdr, args->fh); |
370 | *p++ = htonl(args->access); | 933 | prepare_reply_buffer(req, args->pages, args->pgbase, |
371 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 934 | args->pglen, NFS3_readlinkres_sz); |
372 | return 0; | ||
373 | } | 935 | } |
374 | 936 | ||
375 | /* | 937 | /* |
376 | * Arguments to a READ call. Since we read data directly into the page | 938 | * 3.3.6 READ3args |
377 | * cache, we also set up the reply iovec here so that iov[1] points | 939 | * |
378 | * exactly to the page we want to fetch. | 940 | * struct READ3args { |
941 | * nfs_fh3 file; | ||
942 | * offset3 offset; | ||
943 | * count3 count; | ||
944 | * }; | ||
379 | */ | 945 | */ |
380 | static int | 946 | static void encode_read3args(struct xdr_stream *xdr, |
381 | nfs3_xdr_readargs(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args) | 947 | const struct nfs_readargs *args) |
382 | { | 948 | { |
383 | struct rpc_auth *auth = req->rq_cred->cr_auth; | 949 | __be32 *p; |
384 | unsigned int replen; | 950 | |
385 | u32 count = args->count; | 951 | encode_nfs_fh3(xdr, args->fh); |
386 | 952 | ||
387 | p = xdr_encode_fhandle(p, args->fh); | 953 | p = xdr_reserve_space(xdr, 8 + 4); |
388 | p = xdr_encode_hyper(p, args->offset); | 954 | p = xdr_encode_hyper(p, args->offset); |
389 | *p++ = htonl(count); | 955 | *p = cpu_to_be32(args->count); |
390 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 956 | } |
391 | 957 | ||
392 | /* Inline the page array */ | 958 | static void nfs3_xdr_enc_read3args(struct rpc_rqst *req, |
393 | replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS3_readres_sz) << 2; | 959 | struct xdr_stream *xdr, |
394 | xdr_inline_pages(&req->rq_rcv_buf, replen, | 960 | const struct nfs_readargs *args) |
395 | args->pages, args->pgbase, count); | 961 | { |
962 | encode_read3args(xdr, args); | ||
963 | prepare_reply_buffer(req, args->pages, args->pgbase, | ||
964 | args->count, NFS3_readres_sz); | ||
396 | req->rq_rcv_buf.flags |= XDRBUF_READ; | 965 | req->rq_rcv_buf.flags |= XDRBUF_READ; |
397 | return 0; | ||
398 | } | 966 | } |
399 | 967 | ||
400 | /* | 968 | /* |
401 | * Write arguments. Splice the buffer to be written into the iovec. | 969 | * 3.3.7 WRITE3args |
970 | * | ||
971 | * enum stable_how { | ||
972 | * UNSTABLE = 0, | ||
973 | * DATA_SYNC = 1, | ||
974 | * FILE_SYNC = 2 | ||
975 | * }; | ||
976 | * | ||
977 | * struct WRITE3args { | ||
978 | * nfs_fh3 file; | ||
979 | * offset3 offset; | ||
980 | * count3 count; | ||
981 | * stable_how stable; | ||
982 | * opaque data<>; | ||
983 | * }; | ||
402 | */ | 984 | */ |
403 | static int | 985 | static void encode_write3args(struct xdr_stream *xdr, |
404 | nfs3_xdr_writeargs(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) | 986 | const struct nfs_writeargs *args) |
405 | { | 987 | { |
406 | struct xdr_buf *sndbuf = &req->rq_snd_buf; | 988 | __be32 *p; |
407 | u32 count = args->count; | 989 | |
990 | encode_nfs_fh3(xdr, args->fh); | ||
408 | 991 | ||
409 | p = xdr_encode_fhandle(p, args->fh); | 992 | p = xdr_reserve_space(xdr, 8 + 4 + 4 + 4); |
410 | p = xdr_encode_hyper(p, args->offset); | 993 | p = xdr_encode_hyper(p, args->offset); |
411 | *p++ = htonl(count); | 994 | *p++ = cpu_to_be32(args->count); |
412 | *p++ = htonl(args->stable); | 995 | *p++ = cpu_to_be32(args->stable); |
413 | *p++ = htonl(count); | 996 | *p = cpu_to_be32(args->count); |
414 | sndbuf->len = xdr_adjust_iovec(sndbuf->head, p); | 997 | xdr_write_pages(xdr, args->pages, args->pgbase, args->count); |
415 | 998 | } | |
416 | /* Copy the page array */ | 999 | |
417 | xdr_encode_pages(sndbuf, args->pages, args->pgbase, count); | 1000 | static void nfs3_xdr_enc_write3args(struct rpc_rqst *req, |
418 | sndbuf->flags |= XDRBUF_WRITE; | 1001 | struct xdr_stream *xdr, |
419 | return 0; | 1002 | const struct nfs_writeargs *args) |
1003 | { | ||
1004 | encode_write3args(xdr, args); | ||
1005 | xdr->buf->flags |= XDRBUF_WRITE; | ||
420 | } | 1006 | } |
421 | 1007 | ||
422 | /* | 1008 | /* |
423 | * Encode CREATE arguments | 1009 | * 3.3.8 CREATE3args |
1010 | * | ||
1011 | * enum createmode3 { | ||
1012 | * UNCHECKED = 0, | ||
1013 | * GUARDED = 1, | ||
1014 | * EXCLUSIVE = 2 | ||
1015 | * }; | ||
1016 | * | ||
1017 | * union createhow3 switch (createmode3 mode) { | ||
1018 | * case UNCHECKED: | ||
1019 | * case GUARDED: | ||
1020 | * sattr3 obj_attributes; | ||
1021 | * case EXCLUSIVE: | ||
1022 | * createverf3 verf; | ||
1023 | * }; | ||
1024 | * | ||
1025 | * struct CREATE3args { | ||
1026 | * diropargs3 where; | ||
1027 | * createhow3 how; | ||
1028 | * }; | ||
424 | */ | 1029 | */ |
425 | static int | 1030 | static void encode_createhow3(struct xdr_stream *xdr, |
426 | nfs3_xdr_createargs(struct rpc_rqst *req, __be32 *p, struct nfs3_createargs *args) | 1031 | const struct nfs3_createargs *args) |
427 | { | 1032 | { |
428 | p = xdr_encode_fhandle(p, args->fh); | 1033 | encode_uint32(xdr, args->createmode); |
429 | p = xdr_encode_array(p, args->name, args->len); | 1034 | switch (args->createmode) { |
430 | 1035 | case NFS3_CREATE_UNCHECKED: | |
431 | *p++ = htonl(args->createmode); | 1036 | case NFS3_CREATE_GUARDED: |
432 | if (args->createmode == NFS3_CREATE_EXCLUSIVE) { | 1037 | encode_sattr3(xdr, args->sattr); |
433 | *p++ = args->verifier[0]; | 1038 | break; |
434 | *p++ = args->verifier[1]; | 1039 | case NFS3_CREATE_EXCLUSIVE: |
435 | } else | 1040 | encode_createverf3(xdr, args->verifier); |
436 | p = xdr_encode_sattr(p, args->sattr); | 1041 | break; |
1042 | default: | ||
1043 | BUG(); | ||
1044 | } | ||
1045 | } | ||
437 | 1046 | ||
438 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 1047 | static void nfs3_xdr_enc_create3args(struct rpc_rqst *req, |
439 | return 0; | 1048 | struct xdr_stream *xdr, |
1049 | const struct nfs3_createargs *args) | ||
1050 | { | ||
1051 | encode_diropargs3(xdr, args->fh, args->name, args->len); | ||
1052 | encode_createhow3(xdr, args); | ||
440 | } | 1053 | } |
441 | 1054 | ||
442 | /* | 1055 | /* |
443 | * Encode MKDIR arguments | 1056 | * 3.3.9 MKDIR3args |
1057 | * | ||
1058 | * struct MKDIR3args { | ||
1059 | * diropargs3 where; | ||
1060 | * sattr3 attributes; | ||
1061 | * }; | ||
444 | */ | 1062 | */ |
445 | static int | 1063 | static void nfs3_xdr_enc_mkdir3args(struct rpc_rqst *req, |
446 | nfs3_xdr_mkdirargs(struct rpc_rqst *req, __be32 *p, struct nfs3_mkdirargs *args) | 1064 | struct xdr_stream *xdr, |
1065 | const struct nfs3_mkdirargs *args) | ||
447 | { | 1066 | { |
448 | p = xdr_encode_fhandle(p, args->fh); | 1067 | encode_diropargs3(xdr, args->fh, args->name, args->len); |
449 | p = xdr_encode_array(p, args->name, args->len); | 1068 | encode_sattr3(xdr, args->sattr); |
450 | p = xdr_encode_sattr(p, args->sattr); | ||
451 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
452 | return 0; | ||
453 | } | 1069 | } |
454 | 1070 | ||
455 | /* | 1071 | /* |
456 | * Encode SYMLINK arguments | 1072 | * 3.3.10 SYMLINK3args |
1073 | * | ||
1074 | * struct symlinkdata3 { | ||
1075 | * sattr3 symlink_attributes; | ||
1076 | * nfspath3 symlink_data; | ||
1077 | * }; | ||
1078 | * | ||
1079 | * struct SYMLINK3args { | ||
1080 | * diropargs3 where; | ||
1081 | * symlinkdata3 symlink; | ||
1082 | * }; | ||
457 | */ | 1083 | */ |
458 | static int | 1084 | static void encode_symlinkdata3(struct xdr_stream *xdr, |
459 | nfs3_xdr_symlinkargs(struct rpc_rqst *req, __be32 *p, struct nfs3_symlinkargs *args) | 1085 | const struct nfs3_symlinkargs *args) |
460 | { | 1086 | { |
461 | p = xdr_encode_fhandle(p, args->fromfh); | 1087 | encode_sattr3(xdr, args->sattr); |
462 | p = xdr_encode_array(p, args->fromname, args->fromlen); | 1088 | encode_nfspath3(xdr, args->pages, args->pathlen); |
463 | p = xdr_encode_sattr(p, args->sattr); | 1089 | } |
464 | *p++ = htonl(args->pathlen); | ||
465 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
466 | 1090 | ||
467 | /* Copy the page */ | 1091 | static void nfs3_xdr_enc_symlink3args(struct rpc_rqst *req, |
468 | xdr_encode_pages(&req->rq_snd_buf, args->pages, 0, args->pathlen); | 1092 | struct xdr_stream *xdr, |
469 | return 0; | 1093 | const struct nfs3_symlinkargs *args) |
1094 | { | ||
1095 | encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen); | ||
1096 | encode_symlinkdata3(xdr, args); | ||
470 | } | 1097 | } |
471 | 1098 | ||
472 | /* | 1099 | /* |
473 | * Encode MKNOD arguments | 1100 | * 3.3.11 MKNOD3args |
1101 | * | ||
1102 | * struct devicedata3 { | ||
1103 | * sattr3 dev_attributes; | ||
1104 | * specdata3 spec; | ||
1105 | * }; | ||
1106 | * | ||
1107 | * union mknoddata3 switch (ftype3 type) { | ||
1108 | * case NF3CHR: | ||
1109 | * case NF3BLK: | ||
1110 | * devicedata3 device; | ||
1111 | * case NF3SOCK: | ||
1112 | * case NF3FIFO: | ||
1113 | * sattr3 pipe_attributes; | ||
1114 | * default: | ||
1115 | * void; | ||
1116 | * }; | ||
1117 | * | ||
1118 | * struct MKNOD3args { | ||
1119 | * diropargs3 where; | ||
1120 | * mknoddata3 what; | ||
1121 | * }; | ||
474 | */ | 1122 | */ |
475 | static int | 1123 | static void encode_devicedata3(struct xdr_stream *xdr, |
476 | nfs3_xdr_mknodargs(struct rpc_rqst *req, __be32 *p, struct nfs3_mknodargs *args) | 1124 | const struct nfs3_mknodargs *args) |
477 | { | 1125 | { |
478 | p = xdr_encode_fhandle(p, args->fh); | 1126 | encode_sattr3(xdr, args->sattr); |
479 | p = xdr_encode_array(p, args->name, args->len); | 1127 | encode_specdata3(xdr, args->rdev); |
480 | *p++ = htonl(args->type); | 1128 | } |
481 | p = xdr_encode_sattr(p, args->sattr); | 1129 | |
482 | if (args->type == NF3CHR || args->type == NF3BLK) { | 1130 | static void encode_mknoddata3(struct xdr_stream *xdr, |
483 | *p++ = htonl(MAJOR(args->rdev)); | 1131 | const struct nfs3_mknodargs *args) |
484 | *p++ = htonl(MINOR(args->rdev)); | 1132 | { |
1133 | encode_ftype3(xdr, args->type); | ||
1134 | switch (args->type) { | ||
1135 | case NF3CHR: | ||
1136 | case NF3BLK: | ||
1137 | encode_devicedata3(xdr, args); | ||
1138 | break; | ||
1139 | case NF3SOCK: | ||
1140 | case NF3FIFO: | ||
1141 | encode_sattr3(xdr, args->sattr); | ||
1142 | break; | ||
1143 | case NF3REG: | ||
1144 | case NF3DIR: | ||
1145 | break; | ||
1146 | default: | ||
1147 | BUG(); | ||
485 | } | 1148 | } |
1149 | } | ||
486 | 1150 | ||
487 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 1151 | static void nfs3_xdr_enc_mknod3args(struct rpc_rqst *req, |
488 | return 0; | 1152 | struct xdr_stream *xdr, |
1153 | const struct nfs3_mknodargs *args) | ||
1154 | { | ||
1155 | encode_diropargs3(xdr, args->fh, args->name, args->len); | ||
1156 | encode_mknoddata3(xdr, args); | ||
489 | } | 1157 | } |
490 | 1158 | ||
491 | /* | 1159 | /* |
492 | * Encode RENAME arguments | 1160 | * 3.3.12 REMOVE3args |
1161 | * | ||
1162 | * struct REMOVE3args { | ||
1163 | * diropargs3 object; | ||
1164 | * }; | ||
493 | */ | 1165 | */ |
494 | static int | 1166 | static void nfs3_xdr_enc_remove3args(struct rpc_rqst *req, |
495 | nfs3_xdr_renameargs(struct rpc_rqst *req, __be32 *p, struct nfs_renameargs *args) | 1167 | struct xdr_stream *xdr, |
496 | { | 1168 | const struct nfs_removeargs *args) |
497 | p = xdr_encode_fhandle(p, args->old_dir); | 1169 | { |
498 | p = xdr_encode_array(p, args->old_name->name, args->old_name->len); | 1170 | encode_diropargs3(xdr, args->fh, args->name.name, args->name.len); |
499 | p = xdr_encode_fhandle(p, args->new_dir); | ||
500 | p = xdr_encode_array(p, args->new_name->name, args->new_name->len); | ||
501 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
502 | return 0; | ||
503 | } | 1171 | } |
504 | 1172 | ||
505 | /* | 1173 | /* |
506 | * Encode LINK arguments | 1174 | * 3.3.14 RENAME3args |
1175 | * | ||
1176 | * struct RENAME3args { | ||
1177 | * diropargs3 from; | ||
1178 | * diropargs3 to; | ||
1179 | * }; | ||
507 | */ | 1180 | */ |
508 | static int | 1181 | static void nfs3_xdr_enc_rename3args(struct rpc_rqst *req, |
509 | nfs3_xdr_linkargs(struct rpc_rqst *req, __be32 *p, struct nfs3_linkargs *args) | 1182 | struct xdr_stream *xdr, |
1183 | const struct nfs_renameargs *args) | ||
510 | { | 1184 | { |
511 | p = xdr_encode_fhandle(p, args->fromfh); | 1185 | const struct qstr *old = args->old_name; |
512 | p = xdr_encode_fhandle(p, args->tofh); | 1186 | const struct qstr *new = args->new_name; |
513 | p = xdr_encode_array(p, args->toname, args->tolen); | 1187 | |
514 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 1188 | encode_diropargs3(xdr, args->old_dir, old->name, old->len); |
515 | return 0; | 1189 | encode_diropargs3(xdr, args->new_dir, new->name, new->len); |
516 | } | 1190 | } |
517 | 1191 | ||
518 | /* | 1192 | /* |
519 | * Encode arguments to readdir call | 1193 | * 3.3.15 LINK3args |
1194 | * | ||
1195 | * struct LINK3args { | ||
1196 | * nfs_fh3 file; | ||
1197 | * diropargs3 link; | ||
1198 | * }; | ||
520 | */ | 1199 | */ |
521 | static int | 1200 | static void nfs3_xdr_enc_link3args(struct rpc_rqst *req, |
522 | nfs3_xdr_readdirargs(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirargs *args) | 1201 | struct xdr_stream *xdr, |
1202 | const struct nfs3_linkargs *args) | ||
523 | { | 1203 | { |
524 | struct rpc_auth *auth = req->rq_cred->cr_auth; | 1204 | encode_nfs_fh3(xdr, args->fromfh); |
525 | unsigned int replen; | 1205 | encode_diropargs3(xdr, args->tofh, args->toname, args->tolen); |
526 | u32 count = args->count; | ||
527 | |||
528 | p = xdr_encode_fhandle(p, args->fh); | ||
529 | p = xdr_encode_hyper(p, args->cookie); | ||
530 | *p++ = args->verf[0]; | ||
531 | *p++ = args->verf[1]; | ||
532 | if (args->plus) { | ||
533 | /* readdirplus: need dircount + buffer size. | ||
534 | * We just make sure we make dircount big enough */ | ||
535 | *p++ = htonl(count >> 3); | ||
536 | } | ||
537 | *p++ = htonl(count); | ||
538 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
539 | |||
540 | /* Inline the page array */ | ||
541 | replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS3_readdirres_sz) << 2; | ||
542 | xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages, 0, count); | ||
543 | return 0; | ||
544 | } | 1206 | } |
545 | 1207 | ||
546 | /* | 1208 | /* |
547 | * Decode the result of a readdir call. | 1209 | * 3.3.16 READDIR3args |
548 | * We just check for syntactical correctness. | 1210 | * |
1211 | * struct READDIR3args { | ||
1212 | * nfs_fh3 dir; | ||
1213 | * cookie3 cookie; | ||
1214 | * cookieverf3 cookieverf; | ||
1215 | * count3 count; | ||
1216 | * }; | ||
549 | */ | 1217 | */ |
550 | static int | 1218 | static void encode_readdir3args(struct xdr_stream *xdr, |
551 | nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res) | 1219 | const struct nfs3_readdirargs *args) |
552 | { | 1220 | { |
553 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; | 1221 | __be32 *p; |
554 | struct kvec *iov = rcvbuf->head; | ||
555 | struct page **page; | ||
556 | size_t hdrlen; | ||
557 | u32 recvd, pglen; | ||
558 | int status; | ||
559 | |||
560 | status = ntohl(*p++); | ||
561 | /* Decode post_op_attrs */ | ||
562 | p = xdr_decode_post_op_attr(p, res->dir_attr); | ||
563 | if (status) | ||
564 | return nfs_stat_to_errno(status); | ||
565 | /* Decode verifier cookie */ | ||
566 | if (res->verf) { | ||
567 | res->verf[0] = *p++; | ||
568 | res->verf[1] = *p++; | ||
569 | } else { | ||
570 | p += 2; | ||
571 | } | ||
572 | 1222 | ||
573 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; | 1223 | encode_nfs_fh3(xdr, args->fh); |
574 | if (iov->iov_len < hdrlen) { | ||
575 | dprintk("NFS: READDIR reply header overflowed:" | ||
576 | "length %Zu > %Zu\n", hdrlen, iov->iov_len); | ||
577 | return -errno_NFSERR_IO; | ||
578 | } else if (iov->iov_len != hdrlen) { | ||
579 | dprintk("NFS: READDIR header is short. iovec will be shifted.\n"); | ||
580 | xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen); | ||
581 | } | ||
582 | 1224 | ||
583 | pglen = rcvbuf->page_len; | 1225 | p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4); |
584 | recvd = rcvbuf->len - hdrlen; | 1226 | p = xdr_encode_cookie3(p, args->cookie); |
585 | if (pglen > recvd) | 1227 | p = xdr_encode_cookieverf3(p, args->verf); |
586 | pglen = recvd; | 1228 | *p = cpu_to_be32(args->count); |
587 | page = rcvbuf->pages; | 1229 | } |
588 | 1230 | ||
589 | return pglen; | 1231 | static void nfs3_xdr_enc_readdir3args(struct rpc_rqst *req, |
1232 | struct xdr_stream *xdr, | ||
1233 | const struct nfs3_readdirargs *args) | ||
1234 | { | ||
1235 | encode_readdir3args(xdr, args); | ||
1236 | prepare_reply_buffer(req, args->pages, 0, | ||
1237 | args->count, NFS3_readdirres_sz); | ||
590 | } | 1238 | } |
591 | 1239 | ||
592 | __be32 * | 1240 | /* |
593 | nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_server *server, int plus) | 1241 | * 3.3.17 READDIRPLUS3args |
1242 | * | ||
1243 | * struct READDIRPLUS3args { | ||
1244 | * nfs_fh3 dir; | ||
1245 | * cookie3 cookie; | ||
1246 | * cookieverf3 cookieverf; | ||
1247 | * count3 dircount; | ||
1248 | * count3 maxcount; | ||
1249 | * }; | ||
1250 | */ | ||
1251 | static void encode_readdirplus3args(struct xdr_stream *xdr, | ||
1252 | const struct nfs3_readdirargs *args) | ||
594 | { | 1253 | { |
595 | __be32 *p; | 1254 | __be32 *p; |
596 | struct nfs_entry old = *entry; | ||
597 | |||
598 | p = xdr_inline_decode(xdr, 4); | ||
599 | if (unlikely(!p)) | ||
600 | goto out_overflow; | ||
601 | if (!ntohl(*p++)) { | ||
602 | p = xdr_inline_decode(xdr, 4); | ||
603 | if (unlikely(!p)) | ||
604 | goto out_overflow; | ||
605 | if (!ntohl(*p++)) | ||
606 | return ERR_PTR(-EAGAIN); | ||
607 | entry->eof = 1; | ||
608 | return ERR_PTR(-EBADCOOKIE); | ||
609 | } | ||
610 | 1255 | ||
611 | p = xdr_inline_decode(xdr, 12); | 1256 | encode_nfs_fh3(xdr, args->fh); |
612 | if (unlikely(!p)) | ||
613 | goto out_overflow; | ||
614 | p = xdr_decode_hyper(p, &entry->ino); | ||
615 | entry->len = ntohl(*p++); | ||
616 | 1257 | ||
617 | p = xdr_inline_decode(xdr, entry->len + 8); | 1258 | p = xdr_reserve_space(xdr, 8 + NFS3_COOKIEVERFSIZE + 4 + 4); |
618 | if (unlikely(!p)) | 1259 | p = xdr_encode_cookie3(p, args->cookie); |
619 | goto out_overflow; | 1260 | p = xdr_encode_cookieverf3(p, args->verf); |
620 | entry->name = (const char *) p; | ||
621 | p += XDR_QUADLEN(entry->len); | ||
622 | entry->prev_cookie = entry->cookie; | ||
623 | p = xdr_decode_hyper(p, &entry->cookie); | ||
624 | |||
625 | entry->d_type = DT_UNKNOWN; | ||
626 | if (plus) { | ||
627 | entry->fattr->valid = 0; | ||
628 | p = xdr_decode_post_op_attr_stream(xdr, entry->fattr); | ||
629 | if (IS_ERR(p)) | ||
630 | goto out_overflow_exit; | ||
631 | entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); | ||
632 | /* In fact, a post_op_fh3: */ | ||
633 | p = xdr_inline_decode(xdr, 4); | ||
634 | if (unlikely(!p)) | ||
635 | goto out_overflow; | ||
636 | if (*p++) { | ||
637 | p = xdr_decode_fhandle_stream(xdr, entry->fh); | ||
638 | if (IS_ERR(p)) | ||
639 | goto out_overflow_exit; | ||
640 | /* Ugh -- server reply was truncated */ | ||
641 | if (p == NULL) { | ||
642 | dprintk("NFS: FH truncated\n"); | ||
643 | *entry = old; | ||
644 | return ERR_PTR(-EAGAIN); | ||
645 | } | ||
646 | } else | ||
647 | memset((u8*)(entry->fh), 0, sizeof(*entry->fh)); | ||
648 | } | ||
649 | 1261 | ||
650 | p = xdr_inline_peek(xdr, 8); | 1262 | /* |
651 | if (p != NULL) | 1263 | * readdirplus: need dircount + buffer size. |
652 | entry->eof = !p[0] && p[1]; | 1264 | * We just make sure we make dircount big enough |
653 | else | 1265 | */ |
654 | entry->eof = 0; | 1266 | *p++ = cpu_to_be32(args->count >> 3); |
655 | 1267 | ||
656 | return p; | 1268 | *p = cpu_to_be32(args->count); |
1269 | } | ||
657 | 1270 | ||
658 | out_overflow: | 1271 | static void nfs3_xdr_enc_readdirplus3args(struct rpc_rqst *req, |
659 | print_overflow_msg(__func__, xdr); | 1272 | struct xdr_stream *xdr, |
660 | out_overflow_exit: | 1273 | const struct nfs3_readdirargs *args) |
661 | return ERR_PTR(-EAGAIN); | 1274 | { |
1275 | encode_readdirplus3args(xdr, args); | ||
1276 | prepare_reply_buffer(req, args->pages, 0, | ||
1277 | args->count, NFS3_readdirres_sz); | ||
662 | } | 1278 | } |
663 | 1279 | ||
664 | /* | 1280 | /* |
665 | * Encode COMMIT arguments | 1281 | * 3.3.21 COMMIT3args |
1282 | * | ||
1283 | * struct COMMIT3args { | ||
1284 | * nfs_fh3 file; | ||
1285 | * offset3 offset; | ||
1286 | * count3 count; | ||
1287 | * }; | ||
666 | */ | 1288 | */ |
667 | static int | 1289 | static void encode_commit3args(struct xdr_stream *xdr, |
668 | nfs3_xdr_commitargs(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) | 1290 | const struct nfs_writeargs *args) |
669 | { | 1291 | { |
670 | p = xdr_encode_fhandle(p, args->fh); | 1292 | __be32 *p; |
1293 | |||
1294 | encode_nfs_fh3(xdr, args->fh); | ||
1295 | |||
1296 | p = xdr_reserve_space(xdr, 8 + 4); | ||
671 | p = xdr_encode_hyper(p, args->offset); | 1297 | p = xdr_encode_hyper(p, args->offset); |
672 | *p++ = htonl(args->count); | 1298 | *p = cpu_to_be32(args->count); |
673 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
674 | return 0; | ||
675 | } | 1299 | } |
676 | 1300 | ||
677 | #ifdef CONFIG_NFS_V3_ACL | 1301 | static void nfs3_xdr_enc_commit3args(struct rpc_rqst *req, |
678 | /* | 1302 | struct xdr_stream *xdr, |
679 | * Encode GETACL arguments | 1303 | const struct nfs_writeargs *args) |
680 | */ | ||
681 | static int | ||
682 | nfs3_xdr_getaclargs(struct rpc_rqst *req, __be32 *p, | ||
683 | struct nfs3_getaclargs *args) | ||
684 | { | 1304 | { |
685 | struct rpc_auth *auth = req->rq_cred->cr_auth; | 1305 | encode_commit3args(xdr, args); |
686 | unsigned int replen; | 1306 | } |
687 | 1307 | ||
688 | p = xdr_encode_fhandle(p, args->fh); | 1308 | #ifdef CONFIG_NFS_V3_ACL |
689 | *p++ = htonl(args->mask); | ||
690 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
691 | 1309 | ||
692 | if (args->mask & (NFS_ACL | NFS_DFACL)) { | 1310 | static void nfs3_xdr_enc_getacl3args(struct rpc_rqst *req, |
693 | /* Inline the page array */ | 1311 | struct xdr_stream *xdr, |
694 | replen = (RPC_REPHDRSIZE + auth->au_rslack + | 1312 | const struct nfs3_getaclargs *args) |
695 | ACL3_getaclres_sz) << 2; | 1313 | { |
696 | xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages, 0, | 1314 | encode_nfs_fh3(xdr, args->fh); |
697 | NFSACL_MAXPAGES << PAGE_SHIFT); | 1315 | encode_uint32(xdr, args->mask); |
698 | } | 1316 | if (args->mask & (NFS_ACL | NFS_DFACL)) |
699 | return 0; | 1317 | prepare_reply_buffer(req, args->pages, 0, |
1318 | NFSACL_MAXPAGES << PAGE_SHIFT, | ||
1319 | ACL3_getaclres_sz); | ||
700 | } | 1320 | } |
701 | 1321 | ||
702 | /* | 1322 | static void nfs3_xdr_enc_setacl3args(struct rpc_rqst *req, |
703 | * Encode SETACL arguments | 1323 | struct xdr_stream *xdr, |
704 | */ | 1324 | const struct nfs3_setaclargs *args) |
705 | static int | ||
706 | nfs3_xdr_setaclargs(struct rpc_rqst *req, __be32 *p, | ||
707 | struct nfs3_setaclargs *args) | ||
708 | { | 1325 | { |
709 | struct xdr_buf *buf = &req->rq_snd_buf; | ||
710 | unsigned int base; | 1326 | unsigned int base; |
711 | int err; | 1327 | int error; |
712 | |||
713 | p = xdr_encode_fhandle(p, NFS_FH(args->inode)); | ||
714 | *p++ = htonl(args->mask); | ||
715 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | ||
716 | base = req->rq_slen; | ||
717 | 1328 | ||
1329 | encode_nfs_fh3(xdr, NFS_FH(args->inode)); | ||
1330 | encode_uint32(xdr, args->mask); | ||
718 | if (args->npages != 0) | 1331 | if (args->npages != 0) |
719 | xdr_encode_pages(buf, args->pages, 0, args->len); | 1332 | xdr_write_pages(xdr, args->pages, 0, args->len); |
720 | else | ||
721 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, | ||
722 | p + XDR_QUADLEN(args->len)); | ||
723 | 1333 | ||
724 | err = nfsacl_encode(buf, base, args->inode, | 1334 | base = req->rq_slen; |
1335 | error = nfsacl_encode(xdr->buf, base, args->inode, | ||
725 | (args->mask & NFS_ACL) ? | 1336 | (args->mask & NFS_ACL) ? |
726 | args->acl_access : NULL, 1, 0); | 1337 | args->acl_access : NULL, 1, 0); |
727 | if (err > 0) | 1338 | BUG_ON(error < 0); |
728 | err = nfsacl_encode(buf, base + err, args->inode, | 1339 | error = nfsacl_encode(xdr->buf, base + error, args->inode, |
729 | (args->mask & NFS_DFACL) ? | 1340 | (args->mask & NFS_DFACL) ? |
730 | args->acl_default : NULL, 1, | 1341 | args->acl_default : NULL, 1, |
731 | NFS_ACL_DEFAULT); | 1342 | NFS_ACL_DEFAULT); |
732 | return (err > 0) ? 0 : err; | 1343 | BUG_ON(error < 0); |
733 | } | 1344 | } |
1345 | |||
734 | #endif /* CONFIG_NFS_V3_ACL */ | 1346 | #endif /* CONFIG_NFS_V3_ACL */ |
735 | 1347 | ||
736 | /* | 1348 | /* |
737 | * NFS XDR decode functions | 1349 | * NFSv3 XDR decode functions |
1350 | * | ||
1351 | * NFSv3 result types are defined in section 3.3 of RFC 1813: | ||
1352 | * "NFS Version 3 Protocol Specification". | ||
738 | */ | 1353 | */ |
739 | 1354 | ||
740 | /* | 1355 | /* |
741 | * Decode attrstat reply. | 1356 | * 3.3.1 GETATTR3res |
1357 | * | ||
1358 | * struct GETATTR3resok { | ||
1359 | * fattr3 obj_attributes; | ||
1360 | * }; | ||
1361 | * | ||
1362 | * union GETATTR3res switch (nfsstat3 status) { | ||
1363 | * case NFS3_OK: | ||
1364 | * GETATTR3resok resok; | ||
1365 | * default: | ||
1366 | * void; | ||
1367 | * }; | ||
742 | */ | 1368 | */ |
743 | static int | 1369 | static int nfs3_xdr_dec_getattr3res(struct rpc_rqst *req, |
744 | nfs3_xdr_attrstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr) | 1370 | struct xdr_stream *xdr, |
1371 | struct nfs_fattr *result) | ||
745 | { | 1372 | { |
746 | int status; | 1373 | enum nfs_stat status; |
747 | 1374 | int error; | |
748 | if ((status = ntohl(*p++))) | 1375 | |
749 | return nfs_stat_to_errno(status); | 1376 | error = decode_nfsstat3(xdr, &status); |
750 | xdr_decode_fattr(p, fattr); | 1377 | if (unlikely(error)) |
751 | return 0; | 1378 | goto out; |
1379 | if (status != NFS3_OK) | ||
1380 | goto out_default; | ||
1381 | error = decode_fattr3(xdr, result); | ||
1382 | out: | ||
1383 | return error; | ||
1384 | out_default: | ||
1385 | return nfs_stat_to_errno(status); | ||
752 | } | 1386 | } |
753 | 1387 | ||
754 | /* | 1388 | /* |
755 | * Decode status+wcc_data reply | 1389 | * 3.3.2 SETATTR3res |
756 | * SATTR, REMOVE, RMDIR | 1390 | * |
1391 | * struct SETATTR3resok { | ||
1392 | * wcc_data obj_wcc; | ||
1393 | * }; | ||
1394 | * | ||
1395 | * struct SETATTR3resfail { | ||
1396 | * wcc_data obj_wcc; | ||
1397 | * }; | ||
1398 | * | ||
1399 | * union SETATTR3res switch (nfsstat3 status) { | ||
1400 | * case NFS3_OK: | ||
1401 | * SETATTR3resok resok; | ||
1402 | * default: | ||
1403 | * SETATTR3resfail resfail; | ||
1404 | * }; | ||
757 | */ | 1405 | */ |
758 | static int | 1406 | static int nfs3_xdr_dec_setattr3res(struct rpc_rqst *req, |
759 | nfs3_xdr_wccstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr) | 1407 | struct xdr_stream *xdr, |
1408 | struct nfs_fattr *result) | ||
760 | { | 1409 | { |
761 | int status; | 1410 | enum nfs_stat status; |
762 | 1411 | int error; | |
763 | if ((status = ntohl(*p++))) | 1412 | |
764 | status = nfs_stat_to_errno(status); | 1413 | error = decode_nfsstat3(xdr, &status); |
765 | xdr_decode_wcc_data(p, fattr); | 1414 | if (unlikely(error)) |
766 | return status; | 1415 | goto out; |
1416 | error = decode_wcc_data(xdr, result); | ||
1417 | if (unlikely(error)) | ||
1418 | goto out; | ||
1419 | if (status != NFS3_OK) | ||
1420 | goto out_status; | ||
1421 | out: | ||
1422 | return error; | ||
1423 | out_status: | ||
1424 | return nfs_stat_to_errno(status); | ||
767 | } | 1425 | } |
768 | 1426 | ||
769 | static int | 1427 | /* |
770 | nfs3_xdr_removeres(struct rpc_rqst *req, __be32 *p, struct nfs_removeres *res) | 1428 | * 3.3.3 LOOKUP3res |
1429 | * | ||
1430 | * struct LOOKUP3resok { | ||
1431 | * nfs_fh3 object; | ||
1432 | * post_op_attr obj_attributes; | ||
1433 | * post_op_attr dir_attributes; | ||
1434 | * }; | ||
1435 | * | ||
1436 | * struct LOOKUP3resfail { | ||
1437 | * post_op_attr dir_attributes; | ||
1438 | * }; | ||
1439 | * | ||
1440 | * union LOOKUP3res switch (nfsstat3 status) { | ||
1441 | * case NFS3_OK: | ||
1442 | * LOOKUP3resok resok; | ||
1443 | * default: | ||
1444 | * LOOKUP3resfail resfail; | ||
1445 | * }; | ||
1446 | */ | ||
1447 | static int nfs3_xdr_dec_lookup3res(struct rpc_rqst *req, | ||
1448 | struct xdr_stream *xdr, | ||
1449 | struct nfs3_diropres *result) | ||
771 | { | 1450 | { |
772 | return nfs3_xdr_wccstat(req, p, res->dir_attr); | 1451 | enum nfs_stat status; |
1452 | int error; | ||
1453 | |||
1454 | error = decode_nfsstat3(xdr, &status); | ||
1455 | if (unlikely(error)) | ||
1456 | goto out; | ||
1457 | if (status != NFS3_OK) | ||
1458 | goto out_default; | ||
1459 | error = decode_nfs_fh3(xdr, result->fh); | ||
1460 | if (unlikely(error)) | ||
1461 | goto out; | ||
1462 | error = decode_post_op_attr(xdr, result->fattr); | ||
1463 | if (unlikely(error)) | ||
1464 | goto out; | ||
1465 | error = decode_post_op_attr(xdr, result->dir_attr); | ||
1466 | out: | ||
1467 | return error; | ||
1468 | out_default: | ||
1469 | error = decode_post_op_attr(xdr, result->dir_attr); | ||
1470 | if (unlikely(error)) | ||
1471 | goto out; | ||
1472 | return nfs_stat_to_errno(status); | ||
773 | } | 1473 | } |
774 | 1474 | ||
775 | /* | 1475 | /* |
776 | * Decode LOOKUP reply | 1476 | * 3.3.4 ACCESS3res |
1477 | * | ||
1478 | * struct ACCESS3resok { | ||
1479 | * post_op_attr obj_attributes; | ||
1480 | * uint32 access; | ||
1481 | * }; | ||
1482 | * | ||
1483 | * struct ACCESS3resfail { | ||
1484 | * post_op_attr obj_attributes; | ||
1485 | * }; | ||
1486 | * | ||
1487 | * union ACCESS3res switch (nfsstat3 status) { | ||
1488 | * case NFS3_OK: | ||
1489 | * ACCESS3resok resok; | ||
1490 | * default: | ||
1491 | * ACCESS3resfail resfail; | ||
1492 | * }; | ||
777 | */ | 1493 | */ |
778 | static int | 1494 | static int nfs3_xdr_dec_access3res(struct rpc_rqst *req, |
779 | nfs3_xdr_lookupres(struct rpc_rqst *req, __be32 *p, struct nfs3_diropres *res) | 1495 | struct xdr_stream *xdr, |
1496 | struct nfs3_accessres *result) | ||
780 | { | 1497 | { |
781 | int status; | 1498 | enum nfs_stat status; |
782 | 1499 | int error; | |
783 | if ((status = ntohl(*p++))) { | 1500 | |
784 | status = nfs_stat_to_errno(status); | 1501 | error = decode_nfsstat3(xdr, &status); |
785 | } else { | 1502 | if (unlikely(error)) |
786 | if (!(p = xdr_decode_fhandle(p, res->fh))) | 1503 | goto out; |
787 | return -errno_NFSERR_IO; | 1504 | error = decode_post_op_attr(xdr, result->fattr); |
788 | p = xdr_decode_post_op_attr(p, res->fattr); | 1505 | if (unlikely(error)) |
789 | } | 1506 | goto out; |
790 | xdr_decode_post_op_attr(p, res->dir_attr); | 1507 | if (status != NFS3_OK) |
791 | return status; | 1508 | goto out_default; |
1509 | error = decode_uint32(xdr, &result->access); | ||
1510 | out: | ||
1511 | return error; | ||
1512 | out_default: | ||
1513 | return nfs_stat_to_errno(status); | ||
792 | } | 1514 | } |
793 | 1515 | ||
794 | /* | 1516 | /* |
795 | * Decode ACCESS reply | 1517 | * 3.3.5 READLINK3res |
1518 | * | ||
1519 | * struct READLINK3resok { | ||
1520 | * post_op_attr symlink_attributes; | ||
1521 | * nfspath3 data; | ||
1522 | * }; | ||
1523 | * | ||
1524 | * struct READLINK3resfail { | ||
1525 | * post_op_attr symlink_attributes; | ||
1526 | * }; | ||
1527 | * | ||
1528 | * union READLINK3res switch (nfsstat3 status) { | ||
1529 | * case NFS3_OK: | ||
1530 | * READLINK3resok resok; | ||
1531 | * default: | ||
1532 | * READLINK3resfail resfail; | ||
1533 | * }; | ||
796 | */ | 1534 | */ |
797 | static int | 1535 | static int nfs3_xdr_dec_readlink3res(struct rpc_rqst *req, |
798 | nfs3_xdr_accessres(struct rpc_rqst *req, __be32 *p, struct nfs3_accessres *res) | 1536 | struct xdr_stream *xdr, |
1537 | struct nfs_fattr *result) | ||
799 | { | 1538 | { |
800 | int status = ntohl(*p++); | 1539 | enum nfs_stat status; |
801 | 1540 | int error; | |
802 | p = xdr_decode_post_op_attr(p, res->fattr); | 1541 | |
803 | if (status) | 1542 | error = decode_nfsstat3(xdr, &status); |
804 | return nfs_stat_to_errno(status); | 1543 | if (unlikely(error)) |
805 | res->access = ntohl(*p++); | 1544 | goto out; |
806 | return 0; | 1545 | error = decode_post_op_attr(xdr, result); |
1546 | if (unlikely(error)) | ||
1547 | goto out; | ||
1548 | if (status != NFS3_OK) | ||
1549 | goto out_default; | ||
1550 | error = decode_nfspath3(xdr); | ||
1551 | out: | ||
1552 | return error; | ||
1553 | out_default: | ||
1554 | return nfs_stat_to_errno(status); | ||
807 | } | 1555 | } |
808 | 1556 | ||
809 | static int | 1557 | /* |
810 | nfs3_xdr_readlinkargs(struct rpc_rqst *req, __be32 *p, struct nfs3_readlinkargs *args) | 1558 | * 3.3.6 READ3res |
1559 | * | ||
1560 | * struct READ3resok { | ||
1561 | * post_op_attr file_attributes; | ||
1562 | * count3 count; | ||
1563 | * bool eof; | ||
1564 | * opaque data<>; | ||
1565 | * }; | ||
1566 | * | ||
1567 | * struct READ3resfail { | ||
1568 | * post_op_attr file_attributes; | ||
1569 | * }; | ||
1570 | * | ||
1571 | * union READ3res switch (nfsstat3 status) { | ||
1572 | * case NFS3_OK: | ||
1573 | * READ3resok resok; | ||
1574 | * default: | ||
1575 | * READ3resfail resfail; | ||
1576 | * }; | ||
1577 | */ | ||
1578 | static int decode_read3resok(struct xdr_stream *xdr, | ||
1579 | struct nfs_readres *result) | ||
811 | { | 1580 | { |
812 | struct rpc_auth *auth = req->rq_cred->cr_auth; | 1581 | u32 eof, count, ocount, recvd; |
813 | unsigned int replen; | 1582 | size_t hdrlen; |
1583 | __be32 *p; | ||
814 | 1584 | ||
815 | p = xdr_encode_fhandle(p, args->fh); | 1585 | p = xdr_inline_decode(xdr, 4 + 4 + 4); |
816 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); | 1586 | if (unlikely(p == NULL)) |
1587 | goto out_overflow; | ||
1588 | count = be32_to_cpup(p++); | ||
1589 | eof = be32_to_cpup(p++); | ||
1590 | ocount = be32_to_cpup(p++); | ||
1591 | if (unlikely(ocount != count)) | ||
1592 | goto out_mismatch; | ||
1593 | hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base; | ||
1594 | recvd = xdr->buf->len - hdrlen; | ||
1595 | if (unlikely(count > recvd)) | ||
1596 | goto out_cheating; | ||
1597 | |||
1598 | out: | ||
1599 | xdr_read_pages(xdr, count); | ||
1600 | result->eof = eof; | ||
1601 | result->count = count; | ||
1602 | return count; | ||
1603 | out_mismatch: | ||
1604 | dprintk("NFS: READ count doesn't match length of opaque: " | ||
1605 | "count %u != ocount %u\n", count, ocount); | ||
1606 | return -EIO; | ||
1607 | out_cheating: | ||
1608 | dprintk("NFS: server cheating in read result: " | ||
1609 | "count %u > recvd %u\n", count, recvd); | ||
1610 | count = recvd; | ||
1611 | eof = 0; | ||
1612 | goto out; | ||
1613 | out_overflow: | ||
1614 | print_overflow_msg(__func__, xdr); | ||
1615 | return -EIO; | ||
1616 | } | ||
817 | 1617 | ||
818 | /* Inline the page array */ | 1618 | static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr, |
819 | replen = (RPC_REPHDRSIZE + auth->au_rslack + NFS3_readlinkres_sz) << 2; | 1619 | struct nfs_readres *result) |
820 | xdr_inline_pages(&req->rq_rcv_buf, replen, args->pages, args->pgbase, args->pglen); | 1620 | { |
821 | return 0; | 1621 | enum nfs_stat status; |
1622 | int error; | ||
1623 | |||
1624 | error = decode_nfsstat3(xdr, &status); | ||
1625 | if (unlikely(error)) | ||
1626 | goto out; | ||
1627 | error = decode_post_op_attr(xdr, result->fattr); | ||
1628 | if (unlikely(error)) | ||
1629 | goto out; | ||
1630 | if (status != NFS3_OK) | ||
1631 | goto out_status; | ||
1632 | error = decode_read3resok(xdr, result); | ||
1633 | out: | ||
1634 | return error; | ||
1635 | out_status: | ||
1636 | return nfs_stat_to_errno(status); | ||
822 | } | 1637 | } |
823 | 1638 | ||
824 | /* | 1639 | /* |
825 | * Decode READLINK reply | 1640 | * 3.3.7 WRITE3res |
1641 | * | ||
1642 | * enum stable_how { | ||
1643 | * UNSTABLE = 0, | ||
1644 | * DATA_SYNC = 1, | ||
1645 | * FILE_SYNC = 2 | ||
1646 | * }; | ||
1647 | * | ||
1648 | * struct WRITE3resok { | ||
1649 | * wcc_data file_wcc; | ||
1650 | * count3 count; | ||
1651 | * stable_how committed; | ||
1652 | * writeverf3 verf; | ||
1653 | * }; | ||
1654 | * | ||
1655 | * struct WRITE3resfail { | ||
1656 | * wcc_data file_wcc; | ||
1657 | * }; | ||
1658 | * | ||
1659 | * union WRITE3res switch (nfsstat3 status) { | ||
1660 | * case NFS3_OK: | ||
1661 | * WRITE3resok resok; | ||
1662 | * default: | ||
1663 | * WRITE3resfail resfail; | ||
1664 | * }; | ||
826 | */ | 1665 | */ |
827 | static int | 1666 | static int decode_write3resok(struct xdr_stream *xdr, |
828 | nfs3_xdr_readlinkres(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr) | 1667 | struct nfs_writeres *result) |
829 | { | 1668 | { |
830 | struct xdr_buf *rcvbuf = &req->rq_rcv_buf; | 1669 | __be32 *p; |
831 | struct kvec *iov = rcvbuf->head; | ||
832 | size_t hdrlen; | ||
833 | u32 len, recvd; | ||
834 | int status; | ||
835 | |||
836 | status = ntohl(*p++); | ||
837 | p = xdr_decode_post_op_attr(p, fattr); | ||
838 | |||
839 | if (status != 0) | ||
840 | return nfs_stat_to_errno(status); | ||
841 | |||
842 | /* Convert length of symlink */ | ||
843 | len = ntohl(*p++); | ||
844 | if (len >= rcvbuf->page_len) { | ||
845 | dprintk("nfs: server returned giant symlink!\n"); | ||
846 | return -ENAMETOOLONG; | ||
847 | } | ||
848 | 1670 | ||
849 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; | 1671 | p = xdr_inline_decode(xdr, 4 + 4 + NFS3_WRITEVERFSIZE); |
850 | if (iov->iov_len < hdrlen) { | 1672 | if (unlikely(p == NULL)) |
851 | dprintk("NFS: READLINK reply header overflowed:" | 1673 | goto out_overflow; |
852 | "length %Zu > %Zu\n", hdrlen, iov->iov_len); | 1674 | result->count = be32_to_cpup(p++); |
853 | return -errno_NFSERR_IO; | 1675 | result->verf->committed = be32_to_cpup(p++); |
854 | } else if (iov->iov_len != hdrlen) { | 1676 | if (unlikely(result->verf->committed > NFS_FILE_SYNC)) |
855 | dprintk("NFS: READLINK header is short. " | 1677 | goto out_badvalue; |
856 | "iovec will be shifted.\n"); | 1678 | memcpy(result->verf->verifier, p, NFS3_WRITEVERFSIZE); |
857 | xdr_shift_buf(rcvbuf, iov->iov_len - hdrlen); | 1679 | return result->count; |
858 | } | 1680 | out_badvalue: |
859 | recvd = req->rq_rcv_buf.len - hdrlen; | 1681 | dprintk("NFS: bad stable_how value: %u\n", result->verf->committed); |
860 | if (recvd < len) { | 1682 | return -EIO; |
861 | dprintk("NFS: server cheating in readlink reply: " | 1683 | out_overflow: |
862 | "count %u > recvd %u\n", len, recvd); | 1684 | print_overflow_msg(__func__, xdr); |
863 | return -EIO; | 1685 | return -EIO; |
864 | } | 1686 | } |
865 | 1687 | ||
866 | xdr_terminate_string(rcvbuf, len); | 1688 | static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, struct xdr_stream *xdr, |
867 | return 0; | 1689 | struct nfs_writeres *result) |
1690 | { | ||
1691 | enum nfs_stat status; | ||
1692 | int error; | ||
1693 | |||
1694 | error = decode_nfsstat3(xdr, &status); | ||
1695 | if (unlikely(error)) | ||
1696 | goto out; | ||
1697 | error = decode_wcc_data(xdr, result->fattr); | ||
1698 | if (unlikely(error)) | ||
1699 | goto out; | ||
1700 | if (status != NFS3_OK) | ||
1701 | goto out_status; | ||
1702 | error = decode_write3resok(xdr, result); | ||
1703 | out: | ||
1704 | return error; | ||
1705 | out_status: | ||
1706 | return nfs_stat_to_errno(status); | ||
868 | } | 1707 | } |
869 | 1708 | ||
870 | /* | 1709 | /* |
871 | * Decode READ reply | 1710 | * 3.3.8 CREATE3res |
1711 | * | ||
1712 | * struct CREATE3resok { | ||
1713 | * post_op_fh3 obj; | ||
1714 | * post_op_attr obj_attributes; | ||
1715 | * wcc_data dir_wcc; | ||
1716 | * }; | ||
1717 | * | ||
1718 | * struct CREATE3resfail { | ||
1719 | * wcc_data dir_wcc; | ||
1720 | * }; | ||
1721 | * | ||
1722 | * union CREATE3res switch (nfsstat3 status) { | ||
1723 | * case NFS3_OK: | ||
1724 | * CREATE3resok resok; | ||
1725 | * default: | ||
1726 | * CREATE3resfail resfail; | ||
1727 | * }; | ||
872 | */ | 1728 | */ |
873 | static int | 1729 | static int decode_create3resok(struct xdr_stream *xdr, |
874 | nfs3_xdr_readres(struct rpc_rqst *req, __be32 *p, struct nfs_readres *res) | 1730 | struct nfs3_diropres *result) |
875 | { | 1731 | { |
876 | struct kvec *iov = req->rq_rcv_buf.head; | 1732 | int error; |
877 | size_t hdrlen; | 1733 | |
878 | u32 count, ocount, recvd; | 1734 | error = decode_post_op_fh3(xdr, result->fh); |
879 | int status; | 1735 | if (unlikely(error)) |
1736 | goto out; | ||
1737 | error = decode_post_op_attr(xdr, result->fattr); | ||
1738 | if (unlikely(error)) | ||
1739 | goto out; | ||
1740 | /* The server isn't required to return a file handle. | ||
1741 | * If it didn't, force the client to perform a LOOKUP | ||
1742 | * to determine the correct file handle and attribute | ||
1743 | * values for the new object. */ | ||
1744 | if (result->fh->size == 0) | ||
1745 | result->fattr->valid = 0; | ||
1746 | error = decode_wcc_data(xdr, result->dir_attr); | ||
1747 | out: | ||
1748 | return error; | ||
1749 | } | ||
880 | 1750 | ||
881 | status = ntohl(*p++); | 1751 | static int nfs3_xdr_dec_create3res(struct rpc_rqst *req, |
882 | p = xdr_decode_post_op_attr(p, res->fattr); | 1752 | struct xdr_stream *xdr, |
1753 | struct nfs3_diropres *result) | ||
1754 | { | ||
1755 | enum nfs_stat status; | ||
1756 | int error; | ||
1757 | |||
1758 | error = decode_nfsstat3(xdr, &status); | ||
1759 | if (unlikely(error)) | ||
1760 | goto out; | ||
1761 | if (status != NFS3_OK) | ||
1762 | goto out_default; | ||
1763 | error = decode_create3resok(xdr, result); | ||
1764 | out: | ||
1765 | return error; | ||
1766 | out_default: | ||
1767 | error = decode_wcc_data(xdr, result->dir_attr); | ||
1768 | if (unlikely(error)) | ||
1769 | goto out; | ||
1770 | return nfs_stat_to_errno(status); | ||
1771 | } | ||
883 | 1772 | ||
884 | if (status != 0) | 1773 | /* |
885 | return nfs_stat_to_errno(status); | 1774 | * 3.3.12 REMOVE3res |
1775 | * | ||
1776 | * struct REMOVE3resok { | ||
1777 | * wcc_data dir_wcc; | ||
1778 | * }; | ||
1779 | * | ||
1780 | * struct REMOVE3resfail { | ||
1781 | * wcc_data dir_wcc; | ||
1782 | * }; | ||
1783 | * | ||
1784 | * union REMOVE3res switch (nfsstat3 status) { | ||
1785 | * case NFS3_OK: | ||
1786 | * REMOVE3resok resok; | ||
1787 | * default: | ||
1788 | * REMOVE3resfail resfail; | ||
1789 | * }; | ||
1790 | */ | ||
1791 | static int nfs3_xdr_dec_remove3res(struct rpc_rqst *req, | ||
1792 | struct xdr_stream *xdr, | ||
1793 | struct nfs_removeres *result) | ||
1794 | { | ||
1795 | enum nfs_stat status; | ||
1796 | int error; | ||
1797 | |||
1798 | error = decode_nfsstat3(xdr, &status); | ||
1799 | if (unlikely(error)) | ||
1800 | goto out; | ||
1801 | error = decode_wcc_data(xdr, result->dir_attr); | ||
1802 | if (unlikely(error)) | ||
1803 | goto out; | ||
1804 | if (status != NFS3_OK) | ||
1805 | goto out_status; | ||
1806 | out: | ||
1807 | return error; | ||
1808 | out_status: | ||
1809 | return nfs_stat_to_errno(status); | ||
1810 | } | ||
886 | 1811 | ||
887 | /* Decode reply count and EOF flag. NFSv3 is somewhat redundant | 1812 | /* |
888 | * in that it puts the count both in the res struct and in the | 1813 | * 3.3.14 RENAME3res |
889 | * opaque data count. */ | 1814 | * |
890 | count = ntohl(*p++); | 1815 | * struct RENAME3resok { |
891 | res->eof = ntohl(*p++); | 1816 | * wcc_data fromdir_wcc; |
892 | ocount = ntohl(*p++); | 1817 | * wcc_data todir_wcc; |
1818 | * }; | ||
1819 | * | ||
1820 | * struct RENAME3resfail { | ||
1821 | * wcc_data fromdir_wcc; | ||
1822 | * wcc_data todir_wcc; | ||
1823 | * }; | ||
1824 | * | ||
1825 | * union RENAME3res switch (nfsstat3 status) { | ||
1826 | * case NFS3_OK: | ||
1827 | * RENAME3resok resok; | ||
1828 | * default: | ||
1829 | * RENAME3resfail resfail; | ||
1830 | * }; | ||
1831 | */ | ||
1832 | static int nfs3_xdr_dec_rename3res(struct rpc_rqst *req, | ||
1833 | struct xdr_stream *xdr, | ||
1834 | struct nfs_renameres *result) | ||
1835 | { | ||
1836 | enum nfs_stat status; | ||
1837 | int error; | ||
1838 | |||
1839 | error = decode_nfsstat3(xdr, &status); | ||
1840 | if (unlikely(error)) | ||
1841 | goto out; | ||
1842 | error = decode_wcc_data(xdr, result->old_fattr); | ||
1843 | if (unlikely(error)) | ||
1844 | goto out; | ||
1845 | error = decode_wcc_data(xdr, result->new_fattr); | ||
1846 | if (unlikely(error)) | ||
1847 | goto out; | ||
1848 | if (status != NFS3_OK) | ||
1849 | goto out_status; | ||
1850 | out: | ||
1851 | return error; | ||
1852 | out_status: | ||
1853 | return nfs_stat_to_errno(status); | ||
1854 | } | ||
893 | 1855 | ||
894 | if (ocount != count) { | 1856 | /* |
895 | dprintk("NFS: READ count doesn't match RPC opaque count.\n"); | 1857 | * 3.3.15 LINK3res |
896 | return -errno_NFSERR_IO; | 1858 | * |
897 | } | 1859 | * struct LINK3resok { |
1860 | * post_op_attr file_attributes; | ||
1861 | * wcc_data linkdir_wcc; | ||
1862 | * }; | ||
1863 | * | ||
1864 | * struct LINK3resfail { | ||
1865 | * post_op_attr file_attributes; | ||
1866 | * wcc_data linkdir_wcc; | ||
1867 | * }; | ||
1868 | * | ||
1869 | * union LINK3res switch (nfsstat3 status) { | ||
1870 | * case NFS3_OK: | ||
1871 | * LINK3resok resok; | ||
1872 | * default: | ||
1873 | * LINK3resfail resfail; | ||
1874 | * }; | ||
1875 | */ | ||
1876 | static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr, | ||
1877 | struct nfs3_linkres *result) | ||
1878 | { | ||
1879 | enum nfs_stat status; | ||
1880 | int error; | ||
1881 | |||
1882 | error = decode_nfsstat3(xdr, &status); | ||
1883 | if (unlikely(error)) | ||
1884 | goto out; | ||
1885 | error = decode_post_op_attr(xdr, result->fattr); | ||
1886 | if (unlikely(error)) | ||
1887 | goto out; | ||
1888 | error = decode_wcc_data(xdr, result->dir_attr); | ||
1889 | if (unlikely(error)) | ||
1890 | goto out; | ||
1891 | if (status != NFS3_OK) | ||
1892 | goto out_status; | ||
1893 | out: | ||
1894 | return error; | ||
1895 | out_status: | ||
1896 | return nfs_stat_to_errno(status); | ||
1897 | } | ||
898 | 1898 | ||
899 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; | 1899 | /** |
900 | if (iov->iov_len < hdrlen) { | 1900 | * nfs3_decode_dirent - Decode a single NFSv3 directory entry stored in |
901 | dprintk("NFS: READ reply header overflowed:" | 1901 | * the local page cache |
902 | "length %Zu > %Zu\n", hdrlen, iov->iov_len); | 1902 | * @xdr: XDR stream where entry resides |
903 | return -errno_NFSERR_IO; | 1903 | * @entry: buffer to fill in with entry data |
904 | } else if (iov->iov_len != hdrlen) { | 1904 | * @plus: boolean indicating whether this should be a readdirplus entry |
905 | dprintk("NFS: READ header is short. iovec will be shifted.\n"); | 1905 | * |
906 | xdr_shift_buf(&req->rq_rcv_buf, iov->iov_len - hdrlen); | 1906 | * Returns zero if successful, otherwise a negative errno value is |
907 | } | 1907 | * returned. |
1908 | * | ||
1909 | * This function is not invoked during READDIR reply decoding, but | ||
1910 | * rather whenever an application invokes the getdents(2) system call | ||
1911 | * on a directory already in our cache. | ||
1912 | * | ||
1913 | * 3.3.16 entry3 | ||
1914 | * | ||
1915 | * struct entry3 { | ||
1916 | * fileid3 fileid; | ||
1917 | * filename3 name; | ||
1918 | * cookie3 cookie; | ||
1919 | * fhandle3 filehandle; | ||
1920 | * post_op_attr3 attributes; | ||
1921 | * entry3 *nextentry; | ||
1922 | * }; | ||
1923 | * | ||
1924 | * 3.3.17 entryplus3 | ||
1925 | * struct entryplus3 { | ||
1926 | * fileid3 fileid; | ||
1927 | * filename3 name; | ||
1928 | * cookie3 cookie; | ||
1929 | * post_op_attr name_attributes; | ||
1930 | * post_op_fh3 name_handle; | ||
1931 | * entryplus3 *nextentry; | ||
1932 | * }; | ||
1933 | */ | ||
1934 | int nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, | ||
1935 | int plus) | ||
1936 | { | ||
1937 | struct nfs_entry old = *entry; | ||
1938 | __be32 *p; | ||
1939 | int error; | ||
908 | 1940 | ||
909 | recvd = req->rq_rcv_buf.len - hdrlen; | 1941 | p = xdr_inline_decode(xdr, 4); |
910 | if (count > recvd) { | 1942 | if (unlikely(p == NULL)) |
911 | dprintk("NFS: server cheating in read reply: " | 1943 | goto out_overflow; |
912 | "count %u > recvd %u\n", count, recvd); | 1944 | if (*p == xdr_zero) { |
913 | count = recvd; | 1945 | p = xdr_inline_decode(xdr, 4); |
914 | res->eof = 0; | 1946 | if (unlikely(p == NULL)) |
1947 | goto out_overflow; | ||
1948 | if (*p == xdr_zero) | ||
1949 | return -EAGAIN; | ||
1950 | entry->eof = 1; | ||
1951 | return -EBADCOOKIE; | ||
915 | } | 1952 | } |
916 | 1953 | ||
917 | if (count < res->count) | 1954 | error = decode_fileid3(xdr, &entry->ino); |
918 | res->count = count; | 1955 | if (unlikely(error)) |
1956 | return error; | ||
919 | 1957 | ||
920 | return count; | 1958 | error = decode_inline_filename3(xdr, &entry->name, &entry->len); |
921 | } | 1959 | if (unlikely(error)) |
1960 | return error; | ||
922 | 1961 | ||
923 | /* | 1962 | entry->prev_cookie = entry->cookie; |
924 | * Decode WRITE response | 1963 | error = decode_cookie3(xdr, &entry->cookie); |
925 | */ | 1964 | if (unlikely(error)) |
926 | static int | 1965 | return error; |
927 | nfs3_xdr_writeres(struct rpc_rqst *req, __be32 *p, struct nfs_writeres *res) | ||
928 | { | ||
929 | int status; | ||
930 | 1966 | ||
931 | status = ntohl(*p++); | 1967 | entry->d_type = DT_UNKNOWN; |
932 | p = xdr_decode_wcc_data(p, res->fattr); | ||
933 | 1968 | ||
934 | if (status != 0) | 1969 | if (plus) { |
935 | return nfs_stat_to_errno(status); | 1970 | entry->fattr->valid = 0; |
1971 | error = decode_post_op_attr(xdr, entry->fattr); | ||
1972 | if (unlikely(error)) | ||
1973 | return error; | ||
1974 | if (entry->fattr->valid & NFS_ATTR_FATTR_V3) | ||
1975 | entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); | ||
936 | 1976 | ||
937 | res->count = ntohl(*p++); | 1977 | /* In fact, a post_op_fh3: */ |
938 | res->verf->committed = (enum nfs3_stable_how)ntohl(*p++); | 1978 | p = xdr_inline_decode(xdr, 4); |
939 | res->verf->verifier[0] = *p++; | 1979 | if (unlikely(p == NULL)) |
940 | res->verf->verifier[1] = *p++; | 1980 | goto out_overflow; |
1981 | if (*p != xdr_zero) { | ||
1982 | error = decode_nfs_fh3(xdr, entry->fh); | ||
1983 | if (unlikely(error)) { | ||
1984 | if (error == -E2BIG) | ||
1985 | goto out_truncated; | ||
1986 | return error; | ||
1987 | } | ||
1988 | } else | ||
1989 | zero_nfs_fh3(entry->fh); | ||
1990 | } | ||
941 | 1991 | ||
942 | return res->count; | 1992 | return 0; |
943 | } | ||
944 | 1993 | ||
945 | /* | 1994 | out_overflow: |
946 | * Decode a CREATE response | 1995 | print_overflow_msg(__func__, xdr); |
947 | */ | 1996 | return -EAGAIN; |
948 | static int | 1997 | out_truncated: |
949 | nfs3_xdr_createres(struct rpc_rqst *req, __be32 *p, struct nfs3_diropres *res) | 1998 | dprintk("NFS: directory entry contains invalid file handle\n"); |
950 | { | 1999 | *entry = old; |
951 | int status; | 2000 | return -EAGAIN; |
952 | |||
953 | status = ntohl(*p++); | ||
954 | if (status == 0) { | ||
955 | if (*p++) { | ||
956 | if (!(p = xdr_decode_fhandle(p, res->fh))) | ||
957 | return -errno_NFSERR_IO; | ||
958 | p = xdr_decode_post_op_attr(p, res->fattr); | ||
959 | } else { | ||
960 | memset(res->fh, 0, sizeof(*res->fh)); | ||
961 | /* Do decode post_op_attr but set it to NULL */ | ||
962 | p = xdr_decode_post_op_attr(p, res->fattr); | ||
963 | res->fattr->valid = 0; | ||
964 | } | ||
965 | } else { | ||
966 | status = nfs_stat_to_errno(status); | ||
967 | } | ||
968 | p = xdr_decode_wcc_data(p, res->dir_attr); | ||
969 | return status; | ||
970 | } | 2001 | } |
971 | 2002 | ||
972 | /* | 2003 | /* |
973 | * Decode RENAME reply | 2004 | * 3.3.16 READDIR3res |
2005 | * | ||
2006 | * struct dirlist3 { | ||
2007 | * entry3 *entries; | ||
2008 | * bool eof; | ||
2009 | * }; | ||
2010 | * | ||
2011 | * struct READDIR3resok { | ||
2012 | * post_op_attr dir_attributes; | ||
2013 | * cookieverf3 cookieverf; | ||
2014 | * dirlist3 reply; | ||
2015 | * }; | ||
2016 | * | ||
2017 | * struct READDIR3resfail { | ||
2018 | * post_op_attr dir_attributes; | ||
2019 | * }; | ||
2020 | * | ||
2021 | * union READDIR3res switch (nfsstat3 status) { | ||
2022 | * case NFS3_OK: | ||
2023 | * READDIR3resok resok; | ||
2024 | * default: | ||
2025 | * READDIR3resfail resfail; | ||
2026 | * }; | ||
2027 | * | ||
2028 | * Read the directory contents into the page cache, but otherwise | ||
2029 | * don't touch them. The actual decoding is done by nfs3_decode_entry() | ||
2030 | * during subsequent nfs_readdir() calls. | ||
974 | */ | 2031 | */ |
975 | static int | 2032 | static int decode_dirlist3(struct xdr_stream *xdr) |
976 | nfs3_xdr_renameres(struct rpc_rqst *req, __be32 *p, struct nfs_renameres *res) | ||
977 | { | 2033 | { |
978 | int status; | 2034 | u32 recvd, pglen; |
2035 | size_t hdrlen; | ||
979 | 2036 | ||
980 | if ((status = ntohl(*p++)) != 0) | 2037 | pglen = xdr->buf->page_len; |
981 | status = nfs_stat_to_errno(status); | 2038 | hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base; |
982 | p = xdr_decode_wcc_data(p, res->old_fattr); | 2039 | recvd = xdr->buf->len - hdrlen; |
983 | p = xdr_decode_wcc_data(p, res->new_fattr); | 2040 | if (unlikely(pglen > recvd)) |
984 | return status; | 2041 | goto out_cheating; |
2042 | out: | ||
2043 | xdr_read_pages(xdr, pglen); | ||
2044 | return pglen; | ||
2045 | out_cheating: | ||
2046 | dprintk("NFS: server cheating in readdir result: " | ||
2047 | "pglen %u > recvd %u\n", pglen, recvd); | ||
2048 | pglen = recvd; | ||
2049 | goto out; | ||
985 | } | 2050 | } |
986 | 2051 | ||
987 | /* | 2052 | static int decode_readdir3resok(struct xdr_stream *xdr, |
988 | * Decode LINK reply | 2053 | struct nfs3_readdirres *result) |
989 | */ | ||
990 | static int | ||
991 | nfs3_xdr_linkres(struct rpc_rqst *req, __be32 *p, struct nfs3_linkres *res) | ||
992 | { | 2054 | { |
993 | int status; | 2055 | int error; |
2056 | |||
2057 | error = decode_post_op_attr(xdr, result->dir_attr); | ||
2058 | if (unlikely(error)) | ||
2059 | goto out; | ||
2060 | /* XXX: do we need to check if result->verf != NULL ? */ | ||
2061 | error = decode_cookieverf3(xdr, result->verf); | ||
2062 | if (unlikely(error)) | ||
2063 | goto out; | ||
2064 | error = decode_dirlist3(xdr); | ||
2065 | out: | ||
2066 | return error; | ||
2067 | } | ||
994 | 2068 | ||
995 | if ((status = ntohl(*p++)) != 0) | 2069 | static int nfs3_xdr_dec_readdir3res(struct rpc_rqst *req, |
996 | status = nfs_stat_to_errno(status); | 2070 | struct xdr_stream *xdr, |
997 | p = xdr_decode_post_op_attr(p, res->fattr); | 2071 | struct nfs3_readdirres *result) |
998 | p = xdr_decode_wcc_data(p, res->dir_attr); | 2072 | { |
999 | return status; | 2073 | enum nfs_stat status; |
2074 | int error; | ||
2075 | |||
2076 | error = decode_nfsstat3(xdr, &status); | ||
2077 | if (unlikely(error)) | ||
2078 | goto out; | ||
2079 | if (status != NFS3_OK) | ||
2080 | goto out_default; | ||
2081 | error = decode_readdir3resok(xdr, result); | ||
2082 | out: | ||
2083 | return error; | ||
2084 | out_default: | ||
2085 | error = decode_post_op_attr(xdr, result->dir_attr); | ||
2086 | if (unlikely(error)) | ||
2087 | goto out; | ||
2088 | return nfs_stat_to_errno(status); | ||
1000 | } | 2089 | } |
1001 | 2090 | ||
1002 | /* | 2091 | /* |
1003 | * Decode FSSTAT reply | 2092 | * 3.3.18 FSSTAT3res |
2093 | * | ||
2094 | * struct FSSTAT3resok { | ||
2095 | * post_op_attr obj_attributes; | ||
2096 | * size3 tbytes; | ||
2097 | * size3 fbytes; | ||
2098 | * size3 abytes; | ||
2099 | * size3 tfiles; | ||
2100 | * size3 ffiles; | ||
2101 | * size3 afiles; | ||
2102 | * uint32 invarsec; | ||
2103 | * }; | ||
2104 | * | ||
2105 | * struct FSSTAT3resfail { | ||
2106 | * post_op_attr obj_attributes; | ||
2107 | * }; | ||
2108 | * | ||
2109 | * union FSSTAT3res switch (nfsstat3 status) { | ||
2110 | * case NFS3_OK: | ||
2111 | * FSSTAT3resok resok; | ||
2112 | * default: | ||
2113 | * FSSTAT3resfail resfail; | ||
2114 | * }; | ||
1004 | */ | 2115 | */ |
1005 | static int | 2116 | static int decode_fsstat3resok(struct xdr_stream *xdr, |
1006 | nfs3_xdr_fsstatres(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *res) | 2117 | struct nfs_fsstat *result) |
1007 | { | 2118 | { |
1008 | int status; | 2119 | __be32 *p; |
1009 | |||
1010 | status = ntohl(*p++); | ||
1011 | |||
1012 | p = xdr_decode_post_op_attr(p, res->fattr); | ||
1013 | if (status != 0) | ||
1014 | return nfs_stat_to_errno(status); | ||
1015 | |||
1016 | p = xdr_decode_hyper(p, &res->tbytes); | ||
1017 | p = xdr_decode_hyper(p, &res->fbytes); | ||
1018 | p = xdr_decode_hyper(p, &res->abytes); | ||
1019 | p = xdr_decode_hyper(p, &res->tfiles); | ||
1020 | p = xdr_decode_hyper(p, &res->ffiles); | ||
1021 | p = xdr_decode_hyper(p, &res->afiles); | ||
1022 | 2120 | ||
2121 | p = xdr_inline_decode(xdr, 8 * 6 + 4); | ||
2122 | if (unlikely(p == NULL)) | ||
2123 | goto out_overflow; | ||
2124 | p = xdr_decode_size3(p, &result->tbytes); | ||
2125 | p = xdr_decode_size3(p, &result->fbytes); | ||
2126 | p = xdr_decode_size3(p, &result->abytes); | ||
2127 | p = xdr_decode_size3(p, &result->tfiles); | ||
2128 | p = xdr_decode_size3(p, &result->ffiles); | ||
2129 | xdr_decode_size3(p, &result->afiles); | ||
1023 | /* ignore invarsec */ | 2130 | /* ignore invarsec */ |
1024 | return 0; | 2131 | return 0; |
2132 | out_overflow: | ||
2133 | print_overflow_msg(__func__, xdr); | ||
2134 | return -EIO; | ||
2135 | } | ||
2136 | |||
2137 | static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req, | ||
2138 | struct xdr_stream *xdr, | ||
2139 | struct nfs_fsstat *result) | ||
2140 | { | ||
2141 | enum nfs_stat status; | ||
2142 | int error; | ||
2143 | |||
2144 | error = decode_nfsstat3(xdr, &status); | ||
2145 | if (unlikely(error)) | ||
2146 | goto out; | ||
2147 | error = decode_post_op_attr(xdr, result->fattr); | ||
2148 | if (unlikely(error)) | ||
2149 | goto out; | ||
2150 | if (status != NFS3_OK) | ||
2151 | goto out_status; | ||
2152 | error = decode_fsstat3resok(xdr, result); | ||
2153 | out: | ||
2154 | return error; | ||
2155 | out_status: | ||
2156 | return nfs_stat_to_errno(status); | ||
1025 | } | 2157 | } |
1026 | 2158 | ||
1027 | /* | 2159 | /* |
1028 | * Decode FSINFO reply | 2160 | * 3.3.19 FSINFO3res |
2161 | * | ||
2162 | * struct FSINFO3resok { | ||
2163 | * post_op_attr obj_attributes; | ||
2164 | * uint32 rtmax; | ||
2165 | * uint32 rtpref; | ||
2166 | * uint32 rtmult; | ||
2167 | * uint32 wtmax; | ||
2168 | * uint32 wtpref; | ||
2169 | * uint32 wtmult; | ||
2170 | * uint32 dtpref; | ||
2171 | * size3 maxfilesize; | ||
2172 | * nfstime3 time_delta; | ||
2173 | * uint32 properties; | ||
2174 | * }; | ||
2175 | * | ||
2176 | * struct FSINFO3resfail { | ||
2177 | * post_op_attr obj_attributes; | ||
2178 | * }; | ||
2179 | * | ||
2180 | * union FSINFO3res switch (nfsstat3 status) { | ||
2181 | * case NFS3_OK: | ||
2182 | * FSINFO3resok resok; | ||
2183 | * default: | ||
2184 | * FSINFO3resfail resfail; | ||
2185 | * }; | ||
1029 | */ | 2186 | */ |
1030 | static int | 2187 | static int decode_fsinfo3resok(struct xdr_stream *xdr, |
1031 | nfs3_xdr_fsinfores(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *res) | 2188 | struct nfs_fsinfo *result) |
1032 | { | 2189 | { |
1033 | int status; | 2190 | __be32 *p; |
1034 | |||
1035 | status = ntohl(*p++); | ||
1036 | |||
1037 | p = xdr_decode_post_op_attr(p, res->fattr); | ||
1038 | if (status != 0) | ||
1039 | return nfs_stat_to_errno(status); | ||
1040 | 2191 | ||
1041 | res->rtmax = ntohl(*p++); | 2192 | p = xdr_inline_decode(xdr, 4 * 7 + 8 + 8 + 4); |
1042 | res->rtpref = ntohl(*p++); | 2193 | if (unlikely(p == NULL)) |
1043 | res->rtmult = ntohl(*p++); | 2194 | goto out_overflow; |
1044 | res->wtmax = ntohl(*p++); | 2195 | result->rtmax = be32_to_cpup(p++); |
1045 | res->wtpref = ntohl(*p++); | 2196 | result->rtpref = be32_to_cpup(p++); |
1046 | res->wtmult = ntohl(*p++); | 2197 | result->rtmult = be32_to_cpup(p++); |
1047 | res->dtpref = ntohl(*p++); | 2198 | result->wtmax = be32_to_cpup(p++); |
1048 | p = xdr_decode_hyper(p, &res->maxfilesize); | 2199 | result->wtpref = be32_to_cpup(p++); |
1049 | p = xdr_decode_time3(p, &res->time_delta); | 2200 | result->wtmult = be32_to_cpup(p++); |
2201 | result->dtpref = be32_to_cpup(p++); | ||
2202 | p = xdr_decode_size3(p, &result->maxfilesize); | ||
2203 | xdr_decode_nfstime3(p, &result->time_delta); | ||
1050 | 2204 | ||
1051 | /* ignore properties */ | 2205 | /* ignore properties */ |
1052 | res->lease_time = 0; | 2206 | result->lease_time = 0; |
1053 | return 0; | 2207 | return 0; |
2208 | out_overflow: | ||
2209 | print_overflow_msg(__func__, xdr); | ||
2210 | return -EIO; | ||
2211 | } | ||
2212 | |||
2213 | static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req, | ||
2214 | struct xdr_stream *xdr, | ||
2215 | struct nfs_fsinfo *result) | ||
2216 | { | ||
2217 | enum nfs_stat status; | ||
2218 | int error; | ||
2219 | |||
2220 | error = decode_nfsstat3(xdr, &status); | ||
2221 | if (unlikely(error)) | ||
2222 | goto out; | ||
2223 | error = decode_post_op_attr(xdr, result->fattr); | ||
2224 | if (unlikely(error)) | ||
2225 | goto out; | ||
2226 | if (status != NFS3_OK) | ||
2227 | goto out_status; | ||
2228 | error = decode_fsinfo3resok(xdr, result); | ||
2229 | out: | ||
2230 | return error; | ||
2231 | out_status: | ||
2232 | return nfs_stat_to_errno(status); | ||
1054 | } | 2233 | } |
1055 | 2234 | ||
1056 | /* | 2235 | /* |
1057 | * Decode PATHCONF reply | 2236 | * 3.3.20 PATHCONF3res |
2237 | * | ||
2238 | * struct PATHCONF3resok { | ||
2239 | * post_op_attr obj_attributes; | ||
2240 | * uint32 linkmax; | ||
2241 | * uint32 name_max; | ||
2242 | * bool no_trunc; | ||
2243 | * bool chown_restricted; | ||
2244 | * bool case_insensitive; | ||
2245 | * bool case_preserving; | ||
2246 | * }; | ||
2247 | * | ||
2248 | * struct PATHCONF3resfail { | ||
2249 | * post_op_attr obj_attributes; | ||
2250 | * }; | ||
2251 | * | ||
2252 | * union PATHCONF3res switch (nfsstat3 status) { | ||
2253 | * case NFS3_OK: | ||
2254 | * PATHCONF3resok resok; | ||
2255 | * default: | ||
2256 | * PATHCONF3resfail resfail; | ||
2257 | * }; | ||
1058 | */ | 2258 | */ |
1059 | static int | 2259 | static int decode_pathconf3resok(struct xdr_stream *xdr, |
1060 | nfs3_xdr_pathconfres(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *res) | 2260 | struct nfs_pathconf *result) |
1061 | { | 2261 | { |
1062 | int status; | 2262 | __be32 *p; |
1063 | |||
1064 | status = ntohl(*p++); | ||
1065 | |||
1066 | p = xdr_decode_post_op_attr(p, res->fattr); | ||
1067 | if (status != 0) | ||
1068 | return nfs_stat_to_errno(status); | ||
1069 | res->max_link = ntohl(*p++); | ||
1070 | res->max_namelen = ntohl(*p++); | ||
1071 | 2263 | ||
2264 | p = xdr_inline_decode(xdr, 4 * 6); | ||
2265 | if (unlikely(p == NULL)) | ||
2266 | goto out_overflow; | ||
2267 | result->max_link = be32_to_cpup(p++); | ||
2268 | result->max_namelen = be32_to_cpup(p); | ||
1072 | /* ignore remaining fields */ | 2269 | /* ignore remaining fields */ |
1073 | return 0; | 2270 | return 0; |
2271 | out_overflow: | ||
2272 | print_overflow_msg(__func__, xdr); | ||
2273 | return -EIO; | ||
2274 | } | ||
2275 | |||
2276 | static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req, | ||
2277 | struct xdr_stream *xdr, | ||
2278 | struct nfs_pathconf *result) | ||
2279 | { | ||
2280 | enum nfs_stat status; | ||
2281 | int error; | ||
2282 | |||
2283 | error = decode_nfsstat3(xdr, &status); | ||
2284 | if (unlikely(error)) | ||
2285 | goto out; | ||
2286 | error = decode_post_op_attr(xdr, result->fattr); | ||
2287 | if (unlikely(error)) | ||
2288 | goto out; | ||
2289 | if (status != NFS3_OK) | ||
2290 | goto out_status; | ||
2291 | error = decode_pathconf3resok(xdr, result); | ||
2292 | out: | ||
2293 | return error; | ||
2294 | out_status: | ||
2295 | return nfs_stat_to_errno(status); | ||
1074 | } | 2296 | } |
1075 | 2297 | ||
1076 | /* | 2298 | /* |
1077 | * Decode COMMIT reply | 2299 | * 3.3.21 COMMIT3res |
2300 | * | ||
2301 | * struct COMMIT3resok { | ||
2302 | * wcc_data file_wcc; | ||
2303 | * writeverf3 verf; | ||
2304 | * }; | ||
2305 | * | ||
2306 | * struct COMMIT3resfail { | ||
2307 | * wcc_data file_wcc; | ||
2308 | * }; | ||
2309 | * | ||
2310 | * union COMMIT3res switch (nfsstat3 status) { | ||
2311 | * case NFS3_OK: | ||
2312 | * COMMIT3resok resok; | ||
2313 | * default: | ||
2314 | * COMMIT3resfail resfail; | ||
2315 | * }; | ||
1078 | */ | 2316 | */ |
1079 | static int | 2317 | static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req, |
1080 | nfs3_xdr_commitres(struct rpc_rqst *req, __be32 *p, struct nfs_writeres *res) | 2318 | struct xdr_stream *xdr, |
2319 | struct nfs_writeres *result) | ||
1081 | { | 2320 | { |
1082 | int status; | 2321 | enum nfs_stat status; |
1083 | 2322 | int error; | |
1084 | status = ntohl(*p++); | 2323 | |
1085 | p = xdr_decode_wcc_data(p, res->fattr); | 2324 | error = decode_nfsstat3(xdr, &status); |
1086 | if (status != 0) | 2325 | if (unlikely(error)) |
1087 | return nfs_stat_to_errno(status); | 2326 | goto out; |
1088 | 2327 | error = decode_wcc_data(xdr, result->fattr); | |
1089 | res->verf->verifier[0] = *p++; | 2328 | if (unlikely(error)) |
1090 | res->verf->verifier[1] = *p++; | 2329 | goto out; |
1091 | return 0; | 2330 | if (status != NFS3_OK) |
2331 | goto out_status; | ||
2332 | error = decode_writeverf3(xdr, result->verf->verifier); | ||
2333 | out: | ||
2334 | return error; | ||
2335 | out_status: | ||
2336 | return nfs_stat_to_errno(status); | ||
1092 | } | 2337 | } |
1093 | 2338 | ||
1094 | #ifdef CONFIG_NFS_V3_ACL | 2339 | #ifdef CONFIG_NFS_V3_ACL |
1095 | /* | 2340 | |
1096 | * Decode GETACL reply | 2341 | static inline int decode_getacl3resok(struct xdr_stream *xdr, |
1097 | */ | 2342 | struct nfs3_getaclres *result) |
1098 | static int | ||
1099 | nfs3_xdr_getaclres(struct rpc_rqst *req, __be32 *p, | ||
1100 | struct nfs3_getaclres *res) | ||
1101 | { | 2343 | { |
1102 | struct xdr_buf *buf = &req->rq_rcv_buf; | ||
1103 | int status = ntohl(*p++); | ||
1104 | struct posix_acl **acl; | 2344 | struct posix_acl **acl; |
1105 | unsigned int *aclcnt; | 2345 | unsigned int *aclcnt; |
1106 | int err, base; | 2346 | size_t hdrlen; |
1107 | 2347 | int error; | |
1108 | if (status != 0) | 2348 | |
1109 | return nfs_stat_to_errno(status); | 2349 | error = decode_post_op_attr(xdr, result->fattr); |
1110 | p = xdr_decode_post_op_attr(p, res->fattr); | 2350 | if (unlikely(error)) |
1111 | res->mask = ntohl(*p++); | 2351 | goto out; |
1112 | if (res->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT)) | 2352 | error = decode_uint32(xdr, &result->mask); |
1113 | return -EINVAL; | 2353 | if (unlikely(error)) |
1114 | base = (char *)p - (char *)req->rq_rcv_buf.head->iov_base; | 2354 | goto out; |
1115 | 2355 | error = -EINVAL; | |
1116 | acl = (res->mask & NFS_ACL) ? &res->acl_access : NULL; | 2356 | if (result->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT)) |
1117 | aclcnt = (res->mask & NFS_ACLCNT) ? &res->acl_access_count : NULL; | 2357 | goto out; |
1118 | err = nfsacl_decode(buf, base, aclcnt, acl); | 2358 | |
1119 | 2359 | hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base; | |
1120 | acl = (res->mask & NFS_DFACL) ? &res->acl_default : NULL; | 2360 | |
1121 | aclcnt = (res->mask & NFS_DFACLCNT) ? &res->acl_default_count : NULL; | 2361 | acl = NULL; |
1122 | if (err > 0) | 2362 | if (result->mask & NFS_ACL) |
1123 | err = nfsacl_decode(buf, base + err, aclcnt, acl); | 2363 | acl = &result->acl_access; |
1124 | return (err > 0) ? 0 : err; | 2364 | aclcnt = NULL; |
2365 | if (result->mask & NFS_ACLCNT) | ||
2366 | aclcnt = &result->acl_access_count; | ||
2367 | error = nfsacl_decode(xdr->buf, hdrlen, aclcnt, acl); | ||
2368 | if (unlikely(error <= 0)) | ||
2369 | goto out; | ||
2370 | |||
2371 | acl = NULL; | ||
2372 | if (result->mask & NFS_DFACL) | ||
2373 | acl = &result->acl_default; | ||
2374 | aclcnt = NULL; | ||
2375 | if (result->mask & NFS_DFACLCNT) | ||
2376 | aclcnt = &result->acl_default_count; | ||
2377 | error = nfsacl_decode(xdr->buf, hdrlen + error, aclcnt, acl); | ||
2378 | if (unlikely(error <= 0)) | ||
2379 | return error; | ||
2380 | error = 0; | ||
2381 | out: | ||
2382 | return error; | ||
1125 | } | 2383 | } |
1126 | 2384 | ||
1127 | /* | 2385 | static int nfs3_xdr_dec_getacl3res(struct rpc_rqst *req, |
1128 | * Decode setacl reply. | 2386 | struct xdr_stream *xdr, |
1129 | */ | 2387 | struct nfs3_getaclres *result) |
1130 | static int | ||
1131 | nfs3_xdr_setaclres(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr) | ||
1132 | { | 2388 | { |
1133 | int status = ntohl(*p++); | 2389 | enum nfs_stat status; |
2390 | int error; | ||
2391 | |||
2392 | error = decode_nfsstat3(xdr, &status); | ||
2393 | if (unlikely(error)) | ||
2394 | goto out; | ||
2395 | if (status != NFS3_OK) | ||
2396 | goto out_default; | ||
2397 | error = decode_getacl3resok(xdr, result); | ||
2398 | out: | ||
2399 | return error; | ||
2400 | out_default: | ||
2401 | return nfs_stat_to_errno(status); | ||
2402 | } | ||
1134 | 2403 | ||
1135 | if (status) | 2404 | static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req, |
1136 | return nfs_stat_to_errno(status); | 2405 | struct xdr_stream *xdr, |
1137 | xdr_decode_post_op_attr(p, fattr); | 2406 | struct nfs_fattr *result) |
1138 | return 0; | 2407 | { |
2408 | enum nfs_stat status; | ||
2409 | int error; | ||
2410 | |||
2411 | error = decode_nfsstat3(xdr, &status); | ||
2412 | if (unlikely(error)) | ||
2413 | goto out; | ||
2414 | if (status != NFS3_OK) | ||
2415 | goto out_default; | ||
2416 | error = decode_post_op_attr(xdr, result); | ||
2417 | out: | ||
2418 | return error; | ||
2419 | out_default: | ||
2420 | return nfs_stat_to_errno(status); | ||
1139 | } | 2421 | } |
2422 | |||
1140 | #endif /* CONFIG_NFS_V3_ACL */ | 2423 | #endif /* CONFIG_NFS_V3_ACL */ |
1141 | 2424 | ||
1142 | #define PROC(proc, argtype, restype, timer) \ | 2425 | #define PROC(proc, argtype, restype, timer) \ |
1143 | [NFS3PROC_##proc] = { \ | 2426 | [NFS3PROC_##proc] = { \ |
1144 | .p_proc = NFS3PROC_##proc, \ | 2427 | .p_proc = NFS3PROC_##proc, \ |
1145 | .p_encode = (kxdrproc_t) nfs3_xdr_##argtype, \ | 2428 | .p_encode = (kxdreproc_t)nfs3_xdr_enc_##argtype##3args, \ |
1146 | .p_decode = (kxdrproc_t) nfs3_xdr_##restype, \ | 2429 | .p_decode = (kxdrdproc_t)nfs3_xdr_dec_##restype##3res, \ |
1147 | .p_arglen = NFS3_##argtype##_sz, \ | 2430 | .p_arglen = NFS3_##argtype##args_sz, \ |
1148 | .p_replen = NFS3_##restype##_sz, \ | 2431 | .p_replen = NFS3_##restype##res_sz, \ |
1149 | .p_timer = timer, \ | 2432 | .p_timer = timer, \ |
1150 | .p_statidx = NFS3PROC_##proc, \ | 2433 | .p_statidx = NFS3PROC_##proc, \ |
1151 | .p_name = #proc, \ | 2434 | .p_name = #proc, \ |
1152 | } | 2435 | } |
1153 | 2436 | ||
1154 | struct rpc_procinfo nfs3_procedures[] = { | 2437 | struct rpc_procinfo nfs3_procedures[] = { |
1155 | PROC(GETATTR, fhandle, attrstat, 1), | 2438 | PROC(GETATTR, getattr, getattr, 1), |
1156 | PROC(SETATTR, sattrargs, wccstat, 0), | 2439 | PROC(SETATTR, setattr, setattr, 0), |
1157 | PROC(LOOKUP, diropargs, lookupres, 2), | 2440 | PROC(LOOKUP, lookup, lookup, 2), |
1158 | PROC(ACCESS, accessargs, accessres, 1), | 2441 | PROC(ACCESS, access, access, 1), |
1159 | PROC(READLINK, readlinkargs, readlinkres, 3), | 2442 | PROC(READLINK, readlink, readlink, 3), |
1160 | PROC(READ, readargs, readres, 3), | 2443 | PROC(READ, read, read, 3), |
1161 | PROC(WRITE, writeargs, writeres, 4), | 2444 | PROC(WRITE, write, write, 4), |
1162 | PROC(CREATE, createargs, createres, 0), | 2445 | PROC(CREATE, create, create, 0), |
1163 | PROC(MKDIR, mkdirargs, createres, 0), | 2446 | PROC(MKDIR, mkdir, create, 0), |
1164 | PROC(SYMLINK, symlinkargs, createres, 0), | 2447 | PROC(SYMLINK, symlink, create, 0), |
1165 | PROC(MKNOD, mknodargs, createres, 0), | 2448 | PROC(MKNOD, mknod, create, 0), |
1166 | PROC(REMOVE, removeargs, removeres, 0), | 2449 | PROC(REMOVE, remove, remove, 0), |
1167 | PROC(RMDIR, diropargs, wccstat, 0), | 2450 | PROC(RMDIR, lookup, setattr, 0), |
1168 | PROC(RENAME, renameargs, renameres, 0), | 2451 | PROC(RENAME, rename, rename, 0), |
1169 | PROC(LINK, linkargs, linkres, 0), | 2452 | PROC(LINK, link, link, 0), |
1170 | PROC(READDIR, readdirargs, readdirres, 3), | 2453 | PROC(READDIR, readdir, readdir, 3), |
1171 | PROC(READDIRPLUS, readdirargs, readdirres, 3), | 2454 | PROC(READDIRPLUS, readdirplus, readdir, 3), |
1172 | PROC(FSSTAT, fhandle, fsstatres, 0), | 2455 | PROC(FSSTAT, getattr, fsstat, 0), |
1173 | PROC(FSINFO, fhandle, fsinfores, 0), | 2456 | PROC(FSINFO, getattr, fsinfo, 0), |
1174 | PROC(PATHCONF, fhandle, pathconfres, 0), | 2457 | PROC(PATHCONF, getattr, pathconf, 0), |
1175 | PROC(COMMIT, commitargs, commitres, 5), | 2458 | PROC(COMMIT, commit, commit, 5), |
1176 | }; | 2459 | }; |
1177 | 2460 | ||
1178 | struct rpc_version nfs_version3 = { | 2461 | struct rpc_version nfs_version3 = { |
@@ -1185,8 +2468,8 @@ struct rpc_version nfs_version3 = { | |||
1185 | static struct rpc_procinfo nfs3_acl_procedures[] = { | 2468 | static struct rpc_procinfo nfs3_acl_procedures[] = { |
1186 | [ACLPROC3_GETACL] = { | 2469 | [ACLPROC3_GETACL] = { |
1187 | .p_proc = ACLPROC3_GETACL, | 2470 | .p_proc = ACLPROC3_GETACL, |
1188 | .p_encode = (kxdrproc_t) nfs3_xdr_getaclargs, | 2471 | .p_encode = (kxdreproc_t)nfs3_xdr_enc_getacl3args, |
1189 | .p_decode = (kxdrproc_t) nfs3_xdr_getaclres, | 2472 | .p_decode = (kxdrdproc_t)nfs3_xdr_dec_getacl3res, |
1190 | .p_arglen = ACL3_getaclargs_sz, | 2473 | .p_arglen = ACL3_getaclargs_sz, |
1191 | .p_replen = ACL3_getaclres_sz, | 2474 | .p_replen = ACL3_getaclres_sz, |
1192 | .p_timer = 1, | 2475 | .p_timer = 1, |
@@ -1194,8 +2477,8 @@ static struct rpc_procinfo nfs3_acl_procedures[] = { | |||
1194 | }, | 2477 | }, |
1195 | [ACLPROC3_SETACL] = { | 2478 | [ACLPROC3_SETACL] = { |
1196 | .p_proc = ACLPROC3_SETACL, | 2479 | .p_proc = ACLPROC3_SETACL, |
1197 | .p_encode = (kxdrproc_t) nfs3_xdr_setaclargs, | 2480 | .p_encode = (kxdreproc_t)nfs3_xdr_enc_setacl3args, |
1198 | .p_decode = (kxdrproc_t) nfs3_xdr_setaclres, | 2481 | .p_decode = (kxdrdproc_t)nfs3_xdr_dec_setacl3res, |
1199 | .p_arglen = ACL3_setaclargs_sz, | 2482 | .p_arglen = ACL3_setaclargs_sz, |
1200 | .p_replen = ACL3_setaclres_sz, | 2483 | .p_replen = ACL3_setaclres_sz, |
1201 | .p_timer = 0, | 2484 | .p_timer = 0, |
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index 9fa496387fdf..7a7474073148 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h | |||
@@ -44,6 +44,7 @@ enum nfs4_client_state { | |||
44 | NFS4CLNT_RECLAIM_REBOOT, | 44 | NFS4CLNT_RECLAIM_REBOOT, |
45 | NFS4CLNT_RECLAIM_NOGRACE, | 45 | NFS4CLNT_RECLAIM_NOGRACE, |
46 | NFS4CLNT_DELEGRETURN, | 46 | NFS4CLNT_DELEGRETURN, |
47 | NFS4CLNT_LAYOUTRECALL, | ||
47 | NFS4CLNT_SESSION_RESET, | 48 | NFS4CLNT_SESSION_RESET, |
48 | NFS4CLNT_RECALL_SLOT, | 49 | NFS4CLNT_RECALL_SLOT, |
49 | }; | 50 | }; |
@@ -109,7 +110,7 @@ struct nfs_unique_id { | |||
109 | struct nfs4_state_owner { | 110 | struct nfs4_state_owner { |
110 | struct nfs_unique_id so_owner_id; | 111 | struct nfs_unique_id so_owner_id; |
111 | struct nfs_server *so_server; | 112 | struct nfs_server *so_server; |
112 | struct rb_node so_client_node; | 113 | struct rb_node so_server_node; |
113 | 114 | ||
114 | struct rpc_cred *so_cred; /* Associated cred */ | 115 | struct rpc_cred *so_cred; /* Associated cred */ |
115 | 116 | ||
@@ -227,12 +228,6 @@ struct nfs4_state_maintenance_ops { | |||
227 | extern const struct dentry_operations nfs4_dentry_operations; | 228 | extern const struct dentry_operations nfs4_dentry_operations; |
228 | extern const struct inode_operations nfs4_dir_inode_operations; | 229 | extern const struct inode_operations nfs4_dir_inode_operations; |
229 | 230 | ||
230 | /* inode.c */ | ||
231 | extern ssize_t nfs4_getxattr(struct dentry *, const char *, void *, size_t); | ||
232 | extern int nfs4_setxattr(struct dentry *, const char *, const void *, size_t, int); | ||
233 | extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t); | ||
234 | |||
235 | |||
236 | /* nfs4proc.c */ | 231 | /* nfs4proc.c */ |
237 | extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *); | 232 | extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *); |
238 | extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *); | 233 | extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *); |
@@ -241,11 +236,12 @@ extern int nfs4_proc_async_renew(struct nfs_client *, struct rpc_cred *); | |||
241 | extern int nfs4_proc_renew(struct nfs_client *, struct rpc_cred *); | 236 | extern int nfs4_proc_renew(struct nfs_client *, struct rpc_cred *); |
242 | extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *); | 237 | extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *); |
243 | extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *); | 238 | extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *); |
244 | extern int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait); | 239 | extern int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc); |
245 | extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle); | 240 | extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle); |
246 | extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, | 241 | extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, |
247 | struct nfs4_fs_locations *fs_locations, struct page *page); | 242 | struct nfs4_fs_locations *fs_locations, struct page *page); |
248 | extern void nfs4_release_lockowner(const struct nfs4_lock_state *); | 243 | extern void nfs4_release_lockowner(const struct nfs4_lock_state *); |
244 | extern const struct xattr_handler *nfs4_xattr_handlers[]; | ||
249 | 245 | ||
250 | #if defined(CONFIG_NFS_V4_1) | 246 | #if defined(CONFIG_NFS_V4_1) |
251 | static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *server) | 247 | static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *server) |
@@ -331,7 +327,6 @@ extern void nfs_free_seqid(struct nfs_seqid *seqid); | |||
331 | extern const nfs4_stateid zero_stateid; | 327 | extern const nfs4_stateid zero_stateid; |
332 | 328 | ||
333 | /* nfs4xdr.c */ | 329 | /* nfs4xdr.c */ |
334 | extern __be32 *nfs4_decode_dirent(struct xdr_stream *, struct nfs_entry *, struct nfs_server *, int); | ||
335 | extern struct rpc_procinfo nfs4_procedures[]; | 330 | extern struct rpc_procinfo nfs4_procedures[]; |
336 | 331 | ||
337 | struct nfs4_mount_data; | 332 | struct nfs4_mount_data; |
diff --git a/fs/nfs/nfs4filelayout.c b/fs/nfs/nfs4filelayout.c index 2e92f0d8d654..23f930caf1e2 100644 --- a/fs/nfs/nfs4filelayout.c +++ b/fs/nfs/nfs4filelayout.c | |||
@@ -82,7 +82,7 @@ filelayout_check_layout(struct pnfs_layout_hdr *lo, | |||
82 | { | 82 | { |
83 | struct nfs4_file_layout_dsaddr *dsaddr; | 83 | struct nfs4_file_layout_dsaddr *dsaddr; |
84 | int status = -EINVAL; | 84 | int status = -EINVAL; |
85 | struct nfs_server *nfss = NFS_SERVER(lo->inode); | 85 | struct nfs_server *nfss = NFS_SERVER(lo->plh_inode); |
86 | 86 | ||
87 | dprintk("--> %s\n", __func__); | 87 | dprintk("--> %s\n", __func__); |
88 | 88 | ||
@@ -101,7 +101,7 @@ filelayout_check_layout(struct pnfs_layout_hdr *lo, | |||
101 | /* find and reference the deviceid */ | 101 | /* find and reference the deviceid */ |
102 | dsaddr = nfs4_fl_find_get_deviceid(nfss->nfs_client, id); | 102 | dsaddr = nfs4_fl_find_get_deviceid(nfss->nfs_client, id); |
103 | if (dsaddr == NULL) { | 103 | if (dsaddr == NULL) { |
104 | dsaddr = get_device_info(lo->inode, id); | 104 | dsaddr = get_device_info(lo->plh_inode, id); |
105 | if (dsaddr == NULL) | 105 | if (dsaddr == NULL) |
106 | goto out; | 106 | goto out; |
107 | } | 107 | } |
@@ -243,7 +243,7 @@ filelayout_alloc_lseg(struct pnfs_layout_hdr *layoutid, | |||
243 | static void | 243 | static void |
244 | filelayout_free_lseg(struct pnfs_layout_segment *lseg) | 244 | filelayout_free_lseg(struct pnfs_layout_segment *lseg) |
245 | { | 245 | { |
246 | struct nfs_server *nfss = NFS_SERVER(lseg->layout->inode); | 246 | struct nfs_server *nfss = NFS_SERVER(lseg->pls_layout->plh_inode); |
247 | struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg); | 247 | struct nfs4_filelayout_segment *fl = FILELAYOUT_LSEG(lseg); |
248 | 248 | ||
249 | dprintk("--> %s\n", __func__); | 249 | dprintk("--> %s\n", __func__); |
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 4435e5e1f904..9d992b0346e3 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c | |||
@@ -49,6 +49,7 @@ | |||
49 | #include <linux/mount.h> | 49 | #include <linux/mount.h> |
50 | #include <linux/module.h> | 50 | #include <linux/module.h> |
51 | #include <linux/sunrpc/bc_xprt.h> | 51 | #include <linux/sunrpc/bc_xprt.h> |
52 | #include <linux/xattr.h> | ||
52 | 53 | ||
53 | #include "nfs4_fs.h" | 54 | #include "nfs4_fs.h" |
54 | #include "delegation.h" | 55 | #include "delegation.h" |
@@ -355,9 +356,9 @@ nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *free_slot) | |||
355 | } | 356 | } |
356 | 357 | ||
357 | /* | 358 | /* |
358 | * Signal state manager thread if session is drained | 359 | * Signal state manager thread if session fore channel is drained |
359 | */ | 360 | */ |
360 | static void nfs41_check_drain_session_complete(struct nfs4_session *ses) | 361 | static void nfs4_check_drain_fc_complete(struct nfs4_session *ses) |
361 | { | 362 | { |
362 | struct rpc_task *task; | 363 | struct rpc_task *task; |
363 | 364 | ||
@@ -371,8 +372,20 @@ static void nfs41_check_drain_session_complete(struct nfs4_session *ses) | |||
371 | if (ses->fc_slot_table.highest_used_slotid != -1) | 372 | if (ses->fc_slot_table.highest_used_slotid != -1) |
372 | return; | 373 | return; |
373 | 374 | ||
374 | dprintk("%s COMPLETE: Session Drained\n", __func__); | 375 | dprintk("%s COMPLETE: Session Fore Channel Drained\n", __func__); |
375 | complete(&ses->complete); | 376 | complete(&ses->fc_slot_table.complete); |
377 | } | ||
378 | |||
379 | /* | ||
380 | * Signal state manager thread if session back channel is drained | ||
381 | */ | ||
382 | void nfs4_check_drain_bc_complete(struct nfs4_session *ses) | ||
383 | { | ||
384 | if (!test_bit(NFS4_SESSION_DRAINING, &ses->session_state) || | ||
385 | ses->bc_slot_table.highest_used_slotid != -1) | ||
386 | return; | ||
387 | dprintk("%s COMPLETE: Session Back Channel Drained\n", __func__); | ||
388 | complete(&ses->bc_slot_table.complete); | ||
376 | } | 389 | } |
377 | 390 | ||
378 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) | 391 | static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) |
@@ -389,7 +402,7 @@ static void nfs41_sequence_free_slot(struct nfs4_sequence_res *res) | |||
389 | 402 | ||
390 | spin_lock(&tbl->slot_tbl_lock); | 403 | spin_lock(&tbl->slot_tbl_lock); |
391 | nfs4_free_slot(tbl, res->sr_slot); | 404 | nfs4_free_slot(tbl, res->sr_slot); |
392 | nfs41_check_drain_session_complete(res->sr_session); | 405 | nfs4_check_drain_fc_complete(res->sr_session); |
393 | spin_unlock(&tbl->slot_tbl_lock); | 406 | spin_unlock(&tbl->slot_tbl_lock); |
394 | res->sr_slot = NULL; | 407 | res->sr_slot = NULL; |
395 | } | 408 | } |
@@ -1826,6 +1839,8 @@ struct nfs4_closedata { | |||
1826 | struct nfs_closeres res; | 1839 | struct nfs_closeres res; |
1827 | struct nfs_fattr fattr; | 1840 | struct nfs_fattr fattr; |
1828 | unsigned long timestamp; | 1841 | unsigned long timestamp; |
1842 | bool roc; | ||
1843 | u32 roc_barrier; | ||
1829 | }; | 1844 | }; |
1830 | 1845 | ||
1831 | static void nfs4_free_closedata(void *data) | 1846 | static void nfs4_free_closedata(void *data) |
@@ -1833,6 +1848,8 @@ static void nfs4_free_closedata(void *data) | |||
1833 | struct nfs4_closedata *calldata = data; | 1848 | struct nfs4_closedata *calldata = data; |
1834 | struct nfs4_state_owner *sp = calldata->state->owner; | 1849 | struct nfs4_state_owner *sp = calldata->state->owner; |
1835 | 1850 | ||
1851 | if (calldata->roc) | ||
1852 | pnfs_roc_release(calldata->state->inode); | ||
1836 | nfs4_put_open_state(calldata->state); | 1853 | nfs4_put_open_state(calldata->state); |
1837 | nfs_free_seqid(calldata->arg.seqid); | 1854 | nfs_free_seqid(calldata->arg.seqid); |
1838 | nfs4_put_state_owner(sp); | 1855 | nfs4_put_state_owner(sp); |
@@ -1865,6 +1882,9 @@ static void nfs4_close_done(struct rpc_task *task, void *data) | |||
1865 | */ | 1882 | */ |
1866 | switch (task->tk_status) { | 1883 | switch (task->tk_status) { |
1867 | case 0: | 1884 | case 0: |
1885 | if (calldata->roc) | ||
1886 | pnfs_roc_set_barrier(state->inode, | ||
1887 | calldata->roc_barrier); | ||
1868 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); | 1888 | nfs_set_open_stateid(state, &calldata->res.stateid, 0); |
1869 | renew_lease(server, calldata->timestamp); | 1889 | renew_lease(server, calldata->timestamp); |
1870 | nfs4_close_clear_stateid_flags(state, | 1890 | nfs4_close_clear_stateid_flags(state, |
@@ -1917,8 +1937,15 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) | |||
1917 | return; | 1937 | return; |
1918 | } | 1938 | } |
1919 | 1939 | ||
1920 | if (calldata->arg.fmode == 0) | 1940 | if (calldata->arg.fmode == 0) { |
1921 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; | 1941 | task->tk_msg.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLOSE]; |
1942 | if (calldata->roc && | ||
1943 | pnfs_roc_drain(calldata->inode, &calldata->roc_barrier)) { | ||
1944 | rpc_sleep_on(&NFS_SERVER(calldata->inode)->roc_rpcwaitq, | ||
1945 | task, NULL); | ||
1946 | return; | ||
1947 | } | ||
1948 | } | ||
1922 | 1949 | ||
1923 | nfs_fattr_init(calldata->res.fattr); | 1950 | nfs_fattr_init(calldata->res.fattr); |
1924 | calldata->timestamp = jiffies; | 1951 | calldata->timestamp = jiffies; |
@@ -1946,7 +1973,7 @@ static const struct rpc_call_ops nfs4_close_ops = { | |||
1946 | * | 1973 | * |
1947 | * NOTE: Caller must be holding the sp->so_owner semaphore! | 1974 | * NOTE: Caller must be holding the sp->so_owner semaphore! |
1948 | */ | 1975 | */ |
1949 | int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait) | 1976 | int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait, bool roc) |
1950 | { | 1977 | { |
1951 | struct nfs_server *server = NFS_SERVER(state->inode); | 1978 | struct nfs_server *server = NFS_SERVER(state->inode); |
1952 | struct nfs4_closedata *calldata; | 1979 | struct nfs4_closedata *calldata; |
@@ -1981,11 +2008,12 @@ int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, i | |||
1981 | calldata->res.fattr = &calldata->fattr; | 2008 | calldata->res.fattr = &calldata->fattr; |
1982 | calldata->res.seqid = calldata->arg.seqid; | 2009 | calldata->res.seqid = calldata->arg.seqid; |
1983 | calldata->res.server = server; | 2010 | calldata->res.server = server; |
2011 | calldata->roc = roc; | ||
1984 | path_get(path); | 2012 | path_get(path); |
1985 | calldata->path = *path; | 2013 | calldata->path = *path; |
1986 | 2014 | ||
1987 | msg.rpc_argp = &calldata->arg, | 2015 | msg.rpc_argp = &calldata->arg; |
1988 | msg.rpc_resp = &calldata->res, | 2016 | msg.rpc_resp = &calldata->res; |
1989 | task_setup_data.callback_data = calldata; | 2017 | task_setup_data.callback_data = calldata; |
1990 | task = rpc_run_task(&task_setup_data); | 2018 | task = rpc_run_task(&task_setup_data); |
1991 | if (IS_ERR(task)) | 2019 | if (IS_ERR(task)) |
@@ -1998,6 +2026,8 @@ int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, i | |||
1998 | out_free_calldata: | 2026 | out_free_calldata: |
1999 | kfree(calldata); | 2027 | kfree(calldata); |
2000 | out: | 2028 | out: |
2029 | if (roc) | ||
2030 | pnfs_roc_release(state->inode); | ||
2001 | nfs4_put_open_state(state); | 2031 | nfs4_put_open_state(state); |
2002 | nfs4_put_state_owner(sp); | 2032 | nfs4_put_state_owner(sp); |
2003 | return status; | 2033 | return status; |
@@ -2486,6 +2516,7 @@ nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, | |||
2486 | path = &ctx->path; | 2516 | path = &ctx->path; |
2487 | fmode = ctx->mode; | 2517 | fmode = ctx->mode; |
2488 | } | 2518 | } |
2519 | sattr->ia_mode &= ~current_umask(); | ||
2489 | state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); | 2520 | state = nfs4_do_open(dir, path, fmode, flags, sattr, cred); |
2490 | d_drop(dentry); | 2521 | d_drop(dentry); |
2491 | if (IS_ERR(state)) { | 2522 | if (IS_ERR(state)) { |
@@ -2816,6 +2847,8 @@ static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, | |||
2816 | { | 2847 | { |
2817 | struct nfs4_exception exception = { }; | 2848 | struct nfs4_exception exception = { }; |
2818 | int err; | 2849 | int err; |
2850 | |||
2851 | sattr->ia_mode &= ~current_umask(); | ||
2819 | do { | 2852 | do { |
2820 | err = nfs4_handle_exception(NFS_SERVER(dir), | 2853 | err = nfs4_handle_exception(NFS_SERVER(dir), |
2821 | _nfs4_proc_mkdir(dir, dentry, sattr), | 2854 | _nfs4_proc_mkdir(dir, dentry, sattr), |
@@ -2916,6 +2949,8 @@ static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry, | |||
2916 | { | 2949 | { |
2917 | struct nfs4_exception exception = { }; | 2950 | struct nfs4_exception exception = { }; |
2918 | int err; | 2951 | int err; |
2952 | |||
2953 | sattr->ia_mode &= ~current_umask(); | ||
2919 | do { | 2954 | do { |
2920 | err = nfs4_handle_exception(NFS_SERVER(dir), | 2955 | err = nfs4_handle_exception(NFS_SERVER(dir), |
2921 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), | 2956 | _nfs4_proc_mknod(dir, dentry, sattr, rdev), |
@@ -3478,6 +3513,7 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, | |||
3478 | struct nfs4_setclientid setclientid = { | 3513 | struct nfs4_setclientid setclientid = { |
3479 | .sc_verifier = &sc_verifier, | 3514 | .sc_verifier = &sc_verifier, |
3480 | .sc_prog = program, | 3515 | .sc_prog = program, |
3516 | .sc_cb_ident = clp->cl_cb_ident, | ||
3481 | }; | 3517 | }; |
3482 | struct rpc_message msg = { | 3518 | struct rpc_message msg = { |
3483 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], | 3519 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID], |
@@ -3517,7 +3553,7 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, | |||
3517 | if (signalled()) | 3553 | if (signalled()) |
3518 | break; | 3554 | break; |
3519 | if (loop++ & 1) | 3555 | if (loop++ & 1) |
3520 | ssleep(clp->cl_lease_time + 1); | 3556 | ssleep(clp->cl_lease_time / HZ + 1); |
3521 | else | 3557 | else |
3522 | if (++clp->cl_id_uniquifier == 0) | 3558 | if (++clp->cl_id_uniquifier == 0) |
3523 | break; | 3559 | break; |
@@ -3663,8 +3699,8 @@ static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, co | |||
3663 | data->rpc_status = 0; | 3699 | data->rpc_status = 0; |
3664 | 3700 | ||
3665 | task_setup_data.callback_data = data; | 3701 | task_setup_data.callback_data = data; |
3666 | msg.rpc_argp = &data->args, | 3702 | msg.rpc_argp = &data->args; |
3667 | msg.rpc_resp = &data->res, | 3703 | msg.rpc_resp = &data->res; |
3668 | task = rpc_run_task(&task_setup_data); | 3704 | task = rpc_run_task(&task_setup_data); |
3669 | if (IS_ERR(task)) | 3705 | if (IS_ERR(task)) |
3670 | return PTR_ERR(task); | 3706 | return PTR_ERR(task); |
@@ -3743,6 +3779,7 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock | |||
3743 | goto out; | 3779 | goto out; |
3744 | lsp = request->fl_u.nfs4_fl.owner; | 3780 | lsp = request->fl_u.nfs4_fl.owner; |
3745 | arg.lock_owner.id = lsp->ls_id.id; | 3781 | arg.lock_owner.id = lsp->ls_id.id; |
3782 | arg.lock_owner.s_dev = server->s_dev; | ||
3746 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); | 3783 | status = nfs4_call_sync(server, &msg, &arg, &res, 1); |
3747 | switch (status) { | 3784 | switch (status) { |
3748 | case 0: | 3785 | case 0: |
@@ -3908,8 +3945,8 @@ static struct rpc_task *nfs4_do_unlck(struct file_lock *fl, | |||
3908 | return ERR_PTR(-ENOMEM); | 3945 | return ERR_PTR(-ENOMEM); |
3909 | } | 3946 | } |
3910 | 3947 | ||
3911 | msg.rpc_argp = &data->arg, | 3948 | msg.rpc_argp = &data->arg; |
3912 | msg.rpc_resp = &data->res, | 3949 | msg.rpc_resp = &data->res; |
3913 | task_setup_data.callback_data = data; | 3950 | task_setup_data.callback_data = data; |
3914 | return rpc_run_task(&task_setup_data); | 3951 | return rpc_run_task(&task_setup_data); |
3915 | } | 3952 | } |
@@ -3988,6 +4025,7 @@ static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl, | |||
3988 | p->arg.lock_stateid = &lsp->ls_stateid; | 4025 | p->arg.lock_stateid = &lsp->ls_stateid; |
3989 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; | 4026 | p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; |
3990 | p->arg.lock_owner.id = lsp->ls_id.id; | 4027 | p->arg.lock_owner.id = lsp->ls_id.id; |
4028 | p->arg.lock_owner.s_dev = server->s_dev; | ||
3991 | p->res.lock_seqid = p->arg.lock_seqid; | 4029 | p->res.lock_seqid = p->arg.lock_seqid; |
3992 | p->lsp = lsp; | 4030 | p->lsp = lsp; |
3993 | p->server = server; | 4031 | p->server = server; |
@@ -4145,8 +4183,8 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *f | |||
4145 | data->arg.reclaim = NFS_LOCK_RECLAIM; | 4183 | data->arg.reclaim = NFS_LOCK_RECLAIM; |
4146 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; | 4184 | task_setup_data.callback_ops = &nfs4_recover_lock_ops; |
4147 | } | 4185 | } |
4148 | msg.rpc_argp = &data->arg, | 4186 | msg.rpc_argp = &data->arg; |
4149 | msg.rpc_resp = &data->res, | 4187 | msg.rpc_resp = &data->res; |
4150 | task_setup_data.callback_data = data; | 4188 | task_setup_data.callback_data = data; |
4151 | task = rpc_run_task(&task_setup_data); | 4189 | task = rpc_run_task(&task_setup_data); |
4152 | if (IS_ERR(task)) | 4190 | if (IS_ERR(task)) |
@@ -4392,48 +4430,43 @@ void nfs4_release_lockowner(const struct nfs4_lock_state *lsp) | |||
4392 | return; | 4430 | return; |
4393 | args->lock_owner.clientid = server->nfs_client->cl_clientid; | 4431 | args->lock_owner.clientid = server->nfs_client->cl_clientid; |
4394 | args->lock_owner.id = lsp->ls_id.id; | 4432 | args->lock_owner.id = lsp->ls_id.id; |
4433 | args->lock_owner.s_dev = server->s_dev; | ||
4395 | msg.rpc_argp = args; | 4434 | msg.rpc_argp = args; |
4396 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); | 4435 | rpc_call_async(server->client, &msg, 0, &nfs4_release_lockowner_ops, args); |
4397 | } | 4436 | } |
4398 | 4437 | ||
4399 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" | 4438 | #define XATTR_NAME_NFSV4_ACL "system.nfs4_acl" |
4400 | 4439 | ||
4401 | int nfs4_setxattr(struct dentry *dentry, const char *key, const void *buf, | 4440 | static int nfs4_xattr_set_nfs4_acl(struct dentry *dentry, const char *key, |
4402 | size_t buflen, int flags) | 4441 | const void *buf, size_t buflen, |
4442 | int flags, int type) | ||
4403 | { | 4443 | { |
4404 | struct inode *inode = dentry->d_inode; | 4444 | if (strcmp(key, "") != 0) |
4405 | 4445 | return -EINVAL; | |
4406 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) | ||
4407 | return -EOPNOTSUPP; | ||
4408 | 4446 | ||
4409 | return nfs4_proc_set_acl(inode, buf, buflen); | 4447 | return nfs4_proc_set_acl(dentry->d_inode, buf, buflen); |
4410 | } | 4448 | } |
4411 | 4449 | ||
4412 | /* The getxattr man page suggests returning -ENODATA for unknown attributes, | 4450 | static int nfs4_xattr_get_nfs4_acl(struct dentry *dentry, const char *key, |
4413 | * and that's what we'll do for e.g. user attributes that haven't been set. | 4451 | void *buf, size_t buflen, int type) |
4414 | * But we'll follow ext2/ext3's lead by returning -EOPNOTSUPP for unsupported | ||
4415 | * attributes in kernel-managed attribute namespaces. */ | ||
4416 | ssize_t nfs4_getxattr(struct dentry *dentry, const char *key, void *buf, | ||
4417 | size_t buflen) | ||
4418 | { | 4452 | { |
4419 | struct inode *inode = dentry->d_inode; | 4453 | if (strcmp(key, "") != 0) |
4420 | 4454 | return -EINVAL; | |
4421 | if (strcmp(key, XATTR_NAME_NFSV4_ACL) != 0) | ||
4422 | return -EOPNOTSUPP; | ||
4423 | 4455 | ||
4424 | return nfs4_proc_get_acl(inode, buf, buflen); | 4456 | return nfs4_proc_get_acl(dentry->d_inode, buf, buflen); |
4425 | } | 4457 | } |
4426 | 4458 | ||
4427 | ssize_t nfs4_listxattr(struct dentry *dentry, char *buf, size_t buflen) | 4459 | static size_t nfs4_xattr_list_nfs4_acl(struct dentry *dentry, char *list, |
4460 | size_t list_len, const char *name, | ||
4461 | size_t name_len, int type) | ||
4428 | { | 4462 | { |
4429 | size_t len = strlen(XATTR_NAME_NFSV4_ACL) + 1; | 4463 | size_t len = sizeof(XATTR_NAME_NFSV4_ACL); |
4430 | 4464 | ||
4431 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) | 4465 | if (!nfs4_server_supports_acls(NFS_SERVER(dentry->d_inode))) |
4432 | return 0; | 4466 | return 0; |
4433 | if (buf && buflen < len) | 4467 | |
4434 | return -ERANGE; | 4468 | if (list && len <= list_len) |
4435 | if (buf) | 4469 | memcpy(list, XATTR_NAME_NFSV4_ACL, len); |
4436 | memcpy(buf, XATTR_NAME_NFSV4_ACL, len); | ||
4437 | return len; | 4470 | return len; |
4438 | } | 4471 | } |
4439 | 4472 | ||
@@ -4486,6 +4519,25 @@ int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name, | |||
4486 | 4519 | ||
4487 | #ifdef CONFIG_NFS_V4_1 | 4520 | #ifdef CONFIG_NFS_V4_1 |
4488 | /* | 4521 | /* |
4522 | * Check the exchange flags returned by the server for invalid flags, having | ||
4523 | * both PNFS and NON_PNFS flags set, and not having one of NON_PNFS, PNFS, or | ||
4524 | * DS flags set. | ||
4525 | */ | ||
4526 | static int nfs4_check_cl_exchange_flags(u32 flags) | ||
4527 | { | ||
4528 | if (flags & ~EXCHGID4_FLAG_MASK_R) | ||
4529 | goto out_inval; | ||
4530 | if ((flags & EXCHGID4_FLAG_USE_PNFS_MDS) && | ||
4531 | (flags & EXCHGID4_FLAG_USE_NON_PNFS)) | ||
4532 | goto out_inval; | ||
4533 | if (!(flags & (EXCHGID4_FLAG_MASK_PNFS))) | ||
4534 | goto out_inval; | ||
4535 | return NFS_OK; | ||
4536 | out_inval: | ||
4537 | return -NFS4ERR_INVAL; | ||
4538 | } | ||
4539 | |||
4540 | /* | ||
4489 | * nfs4_proc_exchange_id() | 4541 | * nfs4_proc_exchange_id() |
4490 | * | 4542 | * |
4491 | * Since the clientid has expired, all compounds using sessions | 4543 | * Since the clientid has expired, all compounds using sessions |
@@ -4498,7 +4550,7 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) | |||
4498 | nfs4_verifier verifier; | 4550 | nfs4_verifier verifier; |
4499 | struct nfs41_exchange_id_args args = { | 4551 | struct nfs41_exchange_id_args args = { |
4500 | .client = clp, | 4552 | .client = clp, |
4501 | .flags = clp->cl_exchange_flags, | 4553 | .flags = EXCHGID4_FLAG_SUPP_MOVED_REFER, |
4502 | }; | 4554 | }; |
4503 | struct nfs41_exchange_id_res res = { | 4555 | struct nfs41_exchange_id_res res = { |
4504 | .client = clp, | 4556 | .client = clp, |
@@ -4515,9 +4567,6 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) | |||
4515 | dprintk("--> %s\n", __func__); | 4567 | dprintk("--> %s\n", __func__); |
4516 | BUG_ON(clp == NULL); | 4568 | BUG_ON(clp == NULL); |
4517 | 4569 | ||
4518 | /* Remove server-only flags */ | ||
4519 | args.flags &= ~EXCHGID4_FLAG_CONFIRMED_R; | ||
4520 | |||
4521 | p = (u32 *)verifier.data; | 4570 | p = (u32 *)verifier.data; |
4522 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); | 4571 | *p++ = htonl((u32)clp->cl_boot_time.tv_sec); |
4523 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); | 4572 | *p = htonl((u32)clp->cl_boot_time.tv_nsec); |
@@ -4543,6 +4592,7 @@ int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred) | |||
4543 | break; | 4592 | break; |
4544 | } | 4593 | } |
4545 | 4594 | ||
4595 | status = nfs4_check_cl_exchange_flags(clp->cl_exchange_flags); | ||
4546 | dprintk("<-- %s status= %d\n", __func__, status); | 4596 | dprintk("<-- %s status= %d\n", __func__, status); |
4547 | return status; | 4597 | return status; |
4548 | } | 4598 | } |
@@ -4776,17 +4826,17 @@ struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp) | |||
4776 | if (!session) | 4826 | if (!session) |
4777 | return NULL; | 4827 | return NULL; |
4778 | 4828 | ||
4779 | init_completion(&session->complete); | ||
4780 | |||
4781 | tbl = &session->fc_slot_table; | 4829 | tbl = &session->fc_slot_table; |
4782 | tbl->highest_used_slotid = -1; | 4830 | tbl->highest_used_slotid = -1; |
4783 | spin_lock_init(&tbl->slot_tbl_lock); | 4831 | spin_lock_init(&tbl->slot_tbl_lock); |
4784 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); | 4832 | rpc_init_priority_wait_queue(&tbl->slot_tbl_waitq, "ForeChannel Slot table"); |
4833 | init_completion(&tbl->complete); | ||
4785 | 4834 | ||
4786 | tbl = &session->bc_slot_table; | 4835 | tbl = &session->bc_slot_table; |
4787 | tbl->highest_used_slotid = -1; | 4836 | tbl->highest_used_slotid = -1; |
4788 | spin_lock_init(&tbl->slot_tbl_lock); | 4837 | spin_lock_init(&tbl->slot_tbl_lock); |
4789 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); | 4838 | rpc_init_wait_queue(&tbl->slot_tbl_waitq, "BackChannel Slot table"); |
4839 | init_completion(&tbl->complete); | ||
4790 | 4840 | ||
4791 | session->session_state = 1<<NFS4_SESSION_INITING; | 4841 | session->session_state = 1<<NFS4_SESSION_INITING; |
4792 | 4842 | ||
@@ -5280,13 +5330,23 @@ static void | |||
5280 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) | 5330 | nfs4_layoutget_prepare(struct rpc_task *task, void *calldata) |
5281 | { | 5331 | { |
5282 | struct nfs4_layoutget *lgp = calldata; | 5332 | struct nfs4_layoutget *lgp = calldata; |
5283 | struct inode *ino = lgp->args.inode; | 5333 | struct nfs_server *server = NFS_SERVER(lgp->args.inode); |
5284 | struct nfs_server *server = NFS_SERVER(ino); | ||
5285 | 5334 | ||
5286 | dprintk("--> %s\n", __func__); | 5335 | dprintk("--> %s\n", __func__); |
5336 | /* Note the is a race here, where a CB_LAYOUTRECALL can come in | ||
5337 | * right now covering the LAYOUTGET we are about to send. | ||
5338 | * However, that is not so catastrophic, and there seems | ||
5339 | * to be no way to prevent it completely. | ||
5340 | */ | ||
5287 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, | 5341 | if (nfs4_setup_sequence(server, &lgp->args.seq_args, |
5288 | &lgp->res.seq_res, 0, task)) | 5342 | &lgp->res.seq_res, 0, task)) |
5289 | return; | 5343 | return; |
5344 | if (pnfs_choose_layoutget_stateid(&lgp->args.stateid, | ||
5345 | NFS_I(lgp->args.inode)->layout, | ||
5346 | lgp->args.ctx->state)) { | ||
5347 | rpc_exit(task, NFS4_OK); | ||
5348 | return; | ||
5349 | } | ||
5290 | rpc_call_start(task); | 5350 | rpc_call_start(task); |
5291 | } | 5351 | } |
5292 | 5352 | ||
@@ -5313,7 +5373,6 @@ static void nfs4_layoutget_done(struct rpc_task *task, void *calldata) | |||
5313 | return; | 5373 | return; |
5314 | } | 5374 | } |
5315 | } | 5375 | } |
5316 | lgp->status = task->tk_status; | ||
5317 | dprintk("<-- %s\n", __func__); | 5376 | dprintk("<-- %s\n", __func__); |
5318 | } | 5377 | } |
5319 | 5378 | ||
@@ -5322,7 +5381,6 @@ static void nfs4_layoutget_release(void *calldata) | |||
5322 | struct nfs4_layoutget *lgp = calldata; | 5381 | struct nfs4_layoutget *lgp = calldata; |
5323 | 5382 | ||
5324 | dprintk("--> %s\n", __func__); | 5383 | dprintk("--> %s\n", __func__); |
5325 | put_layout_hdr(lgp->args.inode); | ||
5326 | if (lgp->res.layout.buf != NULL) | 5384 | if (lgp->res.layout.buf != NULL) |
5327 | free_page((unsigned long) lgp->res.layout.buf); | 5385 | free_page((unsigned long) lgp->res.layout.buf); |
5328 | put_nfs_open_context(lgp->args.ctx); | 5386 | put_nfs_open_context(lgp->args.ctx); |
@@ -5367,13 +5425,10 @@ int nfs4_proc_layoutget(struct nfs4_layoutget *lgp) | |||
5367 | if (IS_ERR(task)) | 5425 | if (IS_ERR(task)) |
5368 | return PTR_ERR(task); | 5426 | return PTR_ERR(task); |
5369 | status = nfs4_wait_for_completion_rpc_task(task); | 5427 | status = nfs4_wait_for_completion_rpc_task(task); |
5370 | if (status != 0) | 5428 | if (status == 0) |
5371 | goto out; | 5429 | status = task->tk_status; |
5372 | status = lgp->status; | 5430 | if (status == 0) |
5373 | if (status != 0) | 5431 | status = pnfs_layout_process(lgp); |
5374 | goto out; | ||
5375 | status = pnfs_layout_process(lgp); | ||
5376 | out: | ||
5377 | rpc_put_task(task); | 5432 | rpc_put_task(task); |
5378 | dprintk("<-- %s status=%d\n", __func__, status); | 5433 | dprintk("<-- %s status=%d\n", __func__, status); |
5379 | return status; | 5434 | return status; |
@@ -5504,9 +5559,10 @@ static const struct inode_operations nfs4_file_inode_operations = { | |||
5504 | .permission = nfs_permission, | 5559 | .permission = nfs_permission, |
5505 | .getattr = nfs_getattr, | 5560 | .getattr = nfs_getattr, |
5506 | .setattr = nfs_setattr, | 5561 | .setattr = nfs_setattr, |
5507 | .getxattr = nfs4_getxattr, | 5562 | .getxattr = generic_getxattr, |
5508 | .setxattr = nfs4_setxattr, | 5563 | .setxattr = generic_setxattr, |
5509 | .listxattr = nfs4_listxattr, | 5564 | .listxattr = generic_listxattr, |
5565 | .removexattr = generic_removexattr, | ||
5510 | }; | 5566 | }; |
5511 | 5567 | ||
5512 | const struct nfs_rpc_ops nfs_v4_clientops = { | 5568 | const struct nfs_rpc_ops nfs_v4_clientops = { |
@@ -5551,6 +5607,18 @@ const struct nfs_rpc_ops nfs_v4_clientops = { | |||
5551 | .open_context = nfs4_atomic_open, | 5607 | .open_context = nfs4_atomic_open, |
5552 | }; | 5608 | }; |
5553 | 5609 | ||
5610 | static const struct xattr_handler nfs4_xattr_nfs4_acl_handler = { | ||
5611 | .prefix = XATTR_NAME_NFSV4_ACL, | ||
5612 | .list = nfs4_xattr_list_nfs4_acl, | ||
5613 | .get = nfs4_xattr_get_nfs4_acl, | ||
5614 | .set = nfs4_xattr_set_nfs4_acl, | ||
5615 | }; | ||
5616 | |||
5617 | const struct xattr_handler *nfs4_xattr_handlers[] = { | ||
5618 | &nfs4_xattr_nfs4_acl_handler, | ||
5619 | NULL | ||
5620 | }; | ||
5621 | |||
5554 | /* | 5622 | /* |
5555 | * Local variables: | 5623 | * Local variables: |
5556 | * c-basic-offset: 8 | 5624 | * c-basic-offset: 8 |
diff --git a/fs/nfs/nfs4renewd.c b/fs/nfs/nfs4renewd.c index 72b6c580af13..402143d75fc5 100644 --- a/fs/nfs/nfs4renewd.c +++ b/fs/nfs/nfs4renewd.c | |||
@@ -63,9 +63,14 @@ nfs4_renew_state(struct work_struct *work) | |||
63 | 63 | ||
64 | ops = clp->cl_mvops->state_renewal_ops; | 64 | ops = clp->cl_mvops->state_renewal_ops; |
65 | dprintk("%s: start\n", __func__); | 65 | dprintk("%s: start\n", __func__); |
66 | /* Are there any active superblocks? */ | 66 | |
67 | if (list_empty(&clp->cl_superblocks)) | 67 | rcu_read_lock(); |
68 | if (list_empty(&clp->cl_superblocks)) { | ||
69 | rcu_read_unlock(); | ||
68 | goto out; | 70 | goto out; |
71 | } | ||
72 | rcu_read_unlock(); | ||
73 | |||
69 | spin_lock(&clp->cl_lock); | 74 | spin_lock(&clp->cl_lock); |
70 | lease = clp->cl_lease_time; | 75 | lease = clp->cl_lease_time; |
71 | last = clp->cl_last_renewal; | 76 | last = clp->cl_last_renewal; |
@@ -75,7 +80,7 @@ nfs4_renew_state(struct work_struct *work) | |||
75 | cred = ops->get_state_renewal_cred_locked(clp); | 80 | cred = ops->get_state_renewal_cred_locked(clp); |
76 | spin_unlock(&clp->cl_lock); | 81 | spin_unlock(&clp->cl_lock); |
77 | if (cred == NULL) { | 82 | if (cred == NULL) { |
78 | if (list_empty(&clp->cl_delegations)) { | 83 | if (!nfs_delegations_present(clp)) { |
79 | set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); | 84 | set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state); |
80 | goto out; | 85 | goto out; |
81 | } | 86 | } |
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index f575a3126737..2336d532cf66 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c | |||
@@ -105,14 +105,17 @@ static void nfs4_clear_machine_cred(struct nfs_client *clp) | |||
105 | put_rpccred(cred); | 105 | put_rpccred(cred); |
106 | } | 106 | } |
107 | 107 | ||
108 | struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp) | 108 | static struct rpc_cred * |
109 | nfs4_get_renew_cred_server_locked(struct nfs_server *server) | ||
109 | { | 110 | { |
111 | struct rpc_cred *cred = NULL; | ||
110 | struct nfs4_state_owner *sp; | 112 | struct nfs4_state_owner *sp; |
111 | struct rb_node *pos; | 113 | struct rb_node *pos; |
112 | struct rpc_cred *cred = NULL; | ||
113 | 114 | ||
114 | for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) { | 115 | for (pos = rb_first(&server->state_owners); |
115 | sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); | 116 | pos != NULL; |
117 | pos = rb_next(pos)) { | ||
118 | sp = rb_entry(pos, struct nfs4_state_owner, so_server_node); | ||
116 | if (list_empty(&sp->so_states)) | 119 | if (list_empty(&sp->so_states)) |
117 | continue; | 120 | continue; |
118 | cred = get_rpccred(sp->so_cred); | 121 | cred = get_rpccred(sp->so_cred); |
@@ -121,6 +124,28 @@ struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp) | |||
121 | return cred; | 124 | return cred; |
122 | } | 125 | } |
123 | 126 | ||
127 | /** | ||
128 | * nfs4_get_renew_cred_locked - Acquire credential for a renew operation | ||
129 | * @clp: client state handle | ||
130 | * | ||
131 | * Returns an rpc_cred with reference count bumped, or NULL. | ||
132 | * Caller must hold clp->cl_lock. | ||
133 | */ | ||
134 | struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp) | ||
135 | { | ||
136 | struct rpc_cred *cred = NULL; | ||
137 | struct nfs_server *server; | ||
138 | |||
139 | rcu_read_lock(); | ||
140 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { | ||
141 | cred = nfs4_get_renew_cred_server_locked(server); | ||
142 | if (cred != NULL) | ||
143 | break; | ||
144 | } | ||
145 | rcu_read_unlock(); | ||
146 | return cred; | ||
147 | } | ||
148 | |||
124 | #if defined(CONFIG_NFS_V4_1) | 149 | #if defined(CONFIG_NFS_V4_1) |
125 | 150 | ||
126 | static int nfs41_setup_state_renewal(struct nfs_client *clp) | 151 | static int nfs41_setup_state_renewal(struct nfs_client *clp) |
@@ -142,6 +167,11 @@ static int nfs41_setup_state_renewal(struct nfs_client *clp) | |||
142 | return status; | 167 | return status; |
143 | } | 168 | } |
144 | 169 | ||
170 | /* | ||
171 | * Back channel returns NFS4ERR_DELAY for new requests when | ||
172 | * NFS4_SESSION_DRAINING is set so there is no work to be done when draining | ||
173 | * is ended. | ||
174 | */ | ||
145 | static void nfs4_end_drain_session(struct nfs_client *clp) | 175 | static void nfs4_end_drain_session(struct nfs_client *clp) |
146 | { | 176 | { |
147 | struct nfs4_session *ses = clp->cl_session; | 177 | struct nfs4_session *ses = clp->cl_session; |
@@ -165,22 +195,32 @@ static void nfs4_end_drain_session(struct nfs_client *clp) | |||
165 | } | 195 | } |
166 | } | 196 | } |
167 | 197 | ||
168 | static int nfs4_begin_drain_session(struct nfs_client *clp) | 198 | static int nfs4_wait_on_slot_tbl(struct nfs4_slot_table *tbl) |
169 | { | 199 | { |
170 | struct nfs4_session *ses = clp->cl_session; | ||
171 | struct nfs4_slot_table *tbl = &ses->fc_slot_table; | ||
172 | |||
173 | spin_lock(&tbl->slot_tbl_lock); | 200 | spin_lock(&tbl->slot_tbl_lock); |
174 | set_bit(NFS4_SESSION_DRAINING, &ses->session_state); | ||
175 | if (tbl->highest_used_slotid != -1) { | 201 | if (tbl->highest_used_slotid != -1) { |
176 | INIT_COMPLETION(ses->complete); | 202 | INIT_COMPLETION(tbl->complete); |
177 | spin_unlock(&tbl->slot_tbl_lock); | 203 | spin_unlock(&tbl->slot_tbl_lock); |
178 | return wait_for_completion_interruptible(&ses->complete); | 204 | return wait_for_completion_interruptible(&tbl->complete); |
179 | } | 205 | } |
180 | spin_unlock(&tbl->slot_tbl_lock); | 206 | spin_unlock(&tbl->slot_tbl_lock); |
181 | return 0; | 207 | return 0; |
182 | } | 208 | } |
183 | 209 | ||
210 | static int nfs4_begin_drain_session(struct nfs_client *clp) | ||
211 | { | ||
212 | struct nfs4_session *ses = clp->cl_session; | ||
213 | int ret = 0; | ||
214 | |||
215 | set_bit(NFS4_SESSION_DRAINING, &ses->session_state); | ||
216 | /* back channel */ | ||
217 | ret = nfs4_wait_on_slot_tbl(&ses->bc_slot_table); | ||
218 | if (ret) | ||
219 | return ret; | ||
220 | /* fore channel */ | ||
221 | return nfs4_wait_on_slot_tbl(&ses->fc_slot_table); | ||
222 | } | ||
223 | |||
184 | int nfs41_init_clientid(struct nfs_client *clp, struct rpc_cred *cred) | 224 | int nfs41_init_clientid(struct nfs_client *clp, struct rpc_cred *cred) |
185 | { | 225 | { |
186 | int status; | 226 | int status; |
@@ -192,6 +232,12 @@ int nfs41_init_clientid(struct nfs_client *clp, struct rpc_cred *cred) | |||
192 | status = nfs4_proc_create_session(clp); | 232 | status = nfs4_proc_create_session(clp); |
193 | if (status != 0) | 233 | if (status != 0) |
194 | goto out; | 234 | goto out; |
235 | status = nfs4_set_callback_sessionid(clp); | ||
236 | if (status != 0) { | ||
237 | printk(KERN_WARNING "Sessionid not set. No callback service\n"); | ||
238 | nfs_callback_down(1); | ||
239 | status = 0; | ||
240 | } | ||
195 | nfs41_setup_state_renewal(clp); | 241 | nfs41_setup_state_renewal(clp); |
196 | nfs_mark_client_ready(clp, NFS_CS_READY); | 242 | nfs_mark_client_ready(clp, NFS_CS_READY); |
197 | out: | 243 | out: |
@@ -210,28 +256,56 @@ struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp) | |||
210 | 256 | ||
211 | #endif /* CONFIG_NFS_V4_1 */ | 257 | #endif /* CONFIG_NFS_V4_1 */ |
212 | 258 | ||
213 | struct rpc_cred *nfs4_get_setclientid_cred(struct nfs_client *clp) | 259 | static struct rpc_cred * |
260 | nfs4_get_setclientid_cred_server(struct nfs_server *server) | ||
214 | { | 261 | { |
262 | struct nfs_client *clp = server->nfs_client; | ||
263 | struct rpc_cred *cred = NULL; | ||
215 | struct nfs4_state_owner *sp; | 264 | struct nfs4_state_owner *sp; |
216 | struct rb_node *pos; | 265 | struct rb_node *pos; |
266 | |||
267 | spin_lock(&clp->cl_lock); | ||
268 | pos = rb_first(&server->state_owners); | ||
269 | if (pos != NULL) { | ||
270 | sp = rb_entry(pos, struct nfs4_state_owner, so_server_node); | ||
271 | cred = get_rpccred(sp->so_cred); | ||
272 | } | ||
273 | spin_unlock(&clp->cl_lock); | ||
274 | return cred; | ||
275 | } | ||
276 | |||
277 | /** | ||
278 | * nfs4_get_setclientid_cred - Acquire credential for a setclientid operation | ||
279 | * @clp: client state handle | ||
280 | * | ||
281 | * Returns an rpc_cred with reference count bumped, or NULL. | ||
282 | */ | ||
283 | struct rpc_cred *nfs4_get_setclientid_cred(struct nfs_client *clp) | ||
284 | { | ||
285 | struct nfs_server *server; | ||
217 | struct rpc_cred *cred; | 286 | struct rpc_cred *cred; |
218 | 287 | ||
219 | spin_lock(&clp->cl_lock); | 288 | spin_lock(&clp->cl_lock); |
220 | cred = nfs4_get_machine_cred_locked(clp); | 289 | cred = nfs4_get_machine_cred_locked(clp); |
290 | spin_unlock(&clp->cl_lock); | ||
221 | if (cred != NULL) | 291 | if (cred != NULL) |
222 | goto out; | 292 | goto out; |
223 | pos = rb_first(&clp->cl_state_owners); | 293 | |
224 | if (pos != NULL) { | 294 | rcu_read_lock(); |
225 | sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); | 295 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { |
226 | cred = get_rpccred(sp->so_cred); | 296 | cred = nfs4_get_setclientid_cred_server(server); |
297 | if (cred != NULL) | ||
298 | break; | ||
227 | } | 299 | } |
300 | rcu_read_unlock(); | ||
301 | |||
228 | out: | 302 | out: |
229 | spin_unlock(&clp->cl_lock); | ||
230 | return cred; | 303 | return cred; |
231 | } | 304 | } |
232 | 305 | ||
233 | static void nfs_alloc_unique_id(struct rb_root *root, struct nfs_unique_id *new, | 306 | static void nfs_alloc_unique_id_locked(struct rb_root *root, |
234 | __u64 minval, int maxbits) | 307 | struct nfs_unique_id *new, |
308 | __u64 minval, int maxbits) | ||
235 | { | 309 | { |
236 | struct rb_node **p, *parent; | 310 | struct rb_node **p, *parent; |
237 | struct nfs_unique_id *pos; | 311 | struct nfs_unique_id *pos; |
@@ -286,16 +360,15 @@ static void nfs_free_unique_id(struct rb_root *root, struct nfs_unique_id *id) | |||
286 | } | 360 | } |
287 | 361 | ||
288 | static struct nfs4_state_owner * | 362 | static struct nfs4_state_owner * |
289 | nfs4_find_state_owner(struct nfs_server *server, struct rpc_cred *cred) | 363 | nfs4_find_state_owner_locked(struct nfs_server *server, struct rpc_cred *cred) |
290 | { | 364 | { |
291 | struct nfs_client *clp = server->nfs_client; | 365 | struct rb_node **p = &server->state_owners.rb_node, |
292 | struct rb_node **p = &clp->cl_state_owners.rb_node, | ||
293 | *parent = NULL; | 366 | *parent = NULL; |
294 | struct nfs4_state_owner *sp, *res = NULL; | 367 | struct nfs4_state_owner *sp, *res = NULL; |
295 | 368 | ||
296 | while (*p != NULL) { | 369 | while (*p != NULL) { |
297 | parent = *p; | 370 | parent = *p; |
298 | sp = rb_entry(parent, struct nfs4_state_owner, so_client_node); | 371 | sp = rb_entry(parent, struct nfs4_state_owner, so_server_node); |
299 | 372 | ||
300 | if (server < sp->so_server) { | 373 | if (server < sp->so_server) { |
301 | p = &parent->rb_left; | 374 | p = &parent->rb_left; |
@@ -319,24 +392,17 @@ nfs4_find_state_owner(struct nfs_server *server, struct rpc_cred *cred) | |||
319 | } | 392 | } |
320 | 393 | ||
321 | static struct nfs4_state_owner * | 394 | static struct nfs4_state_owner * |
322 | nfs4_insert_state_owner(struct nfs_client *clp, struct nfs4_state_owner *new) | 395 | nfs4_insert_state_owner_locked(struct nfs4_state_owner *new) |
323 | { | 396 | { |
324 | struct rb_node **p = &clp->cl_state_owners.rb_node, | 397 | struct nfs_server *server = new->so_server; |
398 | struct rb_node **p = &server->state_owners.rb_node, | ||
325 | *parent = NULL; | 399 | *parent = NULL; |
326 | struct nfs4_state_owner *sp; | 400 | struct nfs4_state_owner *sp; |
327 | 401 | ||
328 | while (*p != NULL) { | 402 | while (*p != NULL) { |
329 | parent = *p; | 403 | parent = *p; |
330 | sp = rb_entry(parent, struct nfs4_state_owner, so_client_node); | 404 | sp = rb_entry(parent, struct nfs4_state_owner, so_server_node); |
331 | 405 | ||
332 | if (new->so_server < sp->so_server) { | ||
333 | p = &parent->rb_left; | ||
334 | continue; | ||
335 | } | ||
336 | if (new->so_server > sp->so_server) { | ||
337 | p = &parent->rb_right; | ||
338 | continue; | ||
339 | } | ||
340 | if (new->so_cred < sp->so_cred) | 406 | if (new->so_cred < sp->so_cred) |
341 | p = &parent->rb_left; | 407 | p = &parent->rb_left; |
342 | else if (new->so_cred > sp->so_cred) | 408 | else if (new->so_cred > sp->so_cred) |
@@ -346,18 +412,21 @@ nfs4_insert_state_owner(struct nfs_client *clp, struct nfs4_state_owner *new) | |||
346 | return sp; | 412 | return sp; |
347 | } | 413 | } |
348 | } | 414 | } |
349 | nfs_alloc_unique_id(&clp->cl_openowner_id, &new->so_owner_id, 1, 64); | 415 | nfs_alloc_unique_id_locked(&server->openowner_id, |
350 | rb_link_node(&new->so_client_node, parent, p); | 416 | &new->so_owner_id, 1, 64); |
351 | rb_insert_color(&new->so_client_node, &clp->cl_state_owners); | 417 | rb_link_node(&new->so_server_node, parent, p); |
418 | rb_insert_color(&new->so_server_node, &server->state_owners); | ||
352 | return new; | 419 | return new; |
353 | } | 420 | } |
354 | 421 | ||
355 | static void | 422 | static void |
356 | nfs4_remove_state_owner(struct nfs_client *clp, struct nfs4_state_owner *sp) | 423 | nfs4_remove_state_owner_locked(struct nfs4_state_owner *sp) |
357 | { | 424 | { |
358 | if (!RB_EMPTY_NODE(&sp->so_client_node)) | 425 | struct nfs_server *server = sp->so_server; |
359 | rb_erase(&sp->so_client_node, &clp->cl_state_owners); | 426 | |
360 | nfs_free_unique_id(&clp->cl_openowner_id, &sp->so_owner_id); | 427 | if (!RB_EMPTY_NODE(&sp->so_server_node)) |
428 | rb_erase(&sp->so_server_node, &server->state_owners); | ||
429 | nfs_free_unique_id(&server->openowner_id, &sp->so_owner_id); | ||
361 | } | 430 | } |
362 | 431 | ||
363 | /* | 432 | /* |
@@ -386,23 +455,32 @@ nfs4_alloc_state_owner(void) | |||
386 | static void | 455 | static void |
387 | nfs4_drop_state_owner(struct nfs4_state_owner *sp) | 456 | nfs4_drop_state_owner(struct nfs4_state_owner *sp) |
388 | { | 457 | { |
389 | if (!RB_EMPTY_NODE(&sp->so_client_node)) { | 458 | if (!RB_EMPTY_NODE(&sp->so_server_node)) { |
390 | struct nfs_client *clp = sp->so_server->nfs_client; | 459 | struct nfs_server *server = sp->so_server; |
460 | struct nfs_client *clp = server->nfs_client; | ||
391 | 461 | ||
392 | spin_lock(&clp->cl_lock); | 462 | spin_lock(&clp->cl_lock); |
393 | rb_erase(&sp->so_client_node, &clp->cl_state_owners); | 463 | rb_erase(&sp->so_server_node, &server->state_owners); |
394 | RB_CLEAR_NODE(&sp->so_client_node); | 464 | RB_CLEAR_NODE(&sp->so_server_node); |
395 | spin_unlock(&clp->cl_lock); | 465 | spin_unlock(&clp->cl_lock); |
396 | } | 466 | } |
397 | } | 467 | } |
398 | 468 | ||
399 | struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct rpc_cred *cred) | 469 | /** |
470 | * nfs4_get_state_owner - Look up a state owner given a credential | ||
471 | * @server: nfs_server to search | ||
472 | * @cred: RPC credential to match | ||
473 | * | ||
474 | * Returns a pointer to an instantiated nfs4_state_owner struct, or NULL. | ||
475 | */ | ||
476 | struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, | ||
477 | struct rpc_cred *cred) | ||
400 | { | 478 | { |
401 | struct nfs_client *clp = server->nfs_client; | 479 | struct nfs_client *clp = server->nfs_client; |
402 | struct nfs4_state_owner *sp, *new; | 480 | struct nfs4_state_owner *sp, *new; |
403 | 481 | ||
404 | spin_lock(&clp->cl_lock); | 482 | spin_lock(&clp->cl_lock); |
405 | sp = nfs4_find_state_owner(server, cred); | 483 | sp = nfs4_find_state_owner_locked(server, cred); |
406 | spin_unlock(&clp->cl_lock); | 484 | spin_unlock(&clp->cl_lock); |
407 | if (sp != NULL) | 485 | if (sp != NULL) |
408 | return sp; | 486 | return sp; |
@@ -412,7 +490,7 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct | |||
412 | new->so_server = server; | 490 | new->so_server = server; |
413 | new->so_cred = cred; | 491 | new->so_cred = cred; |
414 | spin_lock(&clp->cl_lock); | 492 | spin_lock(&clp->cl_lock); |
415 | sp = nfs4_insert_state_owner(clp, new); | 493 | sp = nfs4_insert_state_owner_locked(new); |
416 | spin_unlock(&clp->cl_lock); | 494 | spin_unlock(&clp->cl_lock); |
417 | if (sp == new) | 495 | if (sp == new) |
418 | get_rpccred(cred); | 496 | get_rpccred(cred); |
@@ -423,6 +501,11 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct | |||
423 | return sp; | 501 | return sp; |
424 | } | 502 | } |
425 | 503 | ||
504 | /** | ||
505 | * nfs4_put_state_owner - Release a nfs4_state_owner | ||
506 | * @sp: state owner data to release | ||
507 | * | ||
508 | */ | ||
426 | void nfs4_put_state_owner(struct nfs4_state_owner *sp) | 509 | void nfs4_put_state_owner(struct nfs4_state_owner *sp) |
427 | { | 510 | { |
428 | struct nfs_client *clp = sp->so_server->nfs_client; | 511 | struct nfs_client *clp = sp->so_server->nfs_client; |
@@ -430,7 +513,7 @@ void nfs4_put_state_owner(struct nfs4_state_owner *sp) | |||
430 | 513 | ||
431 | if (!atomic_dec_and_lock(&sp->so_count, &clp->cl_lock)) | 514 | if (!atomic_dec_and_lock(&sp->so_count, &clp->cl_lock)) |
432 | return; | 515 | return; |
433 | nfs4_remove_state_owner(clp, sp); | 516 | nfs4_remove_state_owner_locked(sp); |
434 | spin_unlock(&clp->cl_lock); | 517 | spin_unlock(&clp->cl_lock); |
435 | rpc_destroy_wait_queue(&sp->so_sequence.wait); | 518 | rpc_destroy_wait_queue(&sp->so_sequence.wait); |
436 | put_rpccred(cred); | 519 | put_rpccred(cred); |
@@ -585,8 +668,11 @@ static void __nfs4_close(struct path *path, struct nfs4_state *state, | |||
585 | if (!call_close) { | 668 | if (!call_close) { |
586 | nfs4_put_open_state(state); | 669 | nfs4_put_open_state(state); |
587 | nfs4_put_state_owner(owner); | 670 | nfs4_put_state_owner(owner); |
588 | } else | 671 | } else { |
589 | nfs4_do_close(path, state, gfp_mask, wait); | 672 | bool roc = pnfs_roc(state->inode); |
673 | |||
674 | nfs4_do_close(path, state, gfp_mask, wait, roc); | ||
675 | } | ||
590 | } | 676 | } |
591 | 677 | ||
592 | void nfs4_close_state(struct path *path, struct nfs4_state *state, fmode_t fmode) | 678 | void nfs4_close_state(struct path *path, struct nfs4_state *state, fmode_t fmode) |
@@ -633,7 +719,8 @@ __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_p | |||
633 | static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid, unsigned int type) | 719 | static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid, unsigned int type) |
634 | { | 720 | { |
635 | struct nfs4_lock_state *lsp; | 721 | struct nfs4_lock_state *lsp; |
636 | struct nfs_client *clp = state->owner->so_server->nfs_client; | 722 | struct nfs_server *server = state->owner->so_server; |
723 | struct nfs_client *clp = server->nfs_client; | ||
637 | 724 | ||
638 | lsp = kzalloc(sizeof(*lsp), GFP_NOFS); | 725 | lsp = kzalloc(sizeof(*lsp), GFP_NOFS); |
639 | if (lsp == NULL) | 726 | if (lsp == NULL) |
@@ -657,7 +744,7 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f | |||
657 | return NULL; | 744 | return NULL; |
658 | } | 745 | } |
659 | spin_lock(&clp->cl_lock); | 746 | spin_lock(&clp->cl_lock); |
660 | nfs_alloc_unique_id(&clp->cl_lockowner_id, &lsp->ls_id, 1, 64); | 747 | nfs_alloc_unique_id_locked(&server->lockowner_id, &lsp->ls_id, 1, 64); |
661 | spin_unlock(&clp->cl_lock); | 748 | spin_unlock(&clp->cl_lock); |
662 | INIT_LIST_HEAD(&lsp->ls_locks); | 749 | INIT_LIST_HEAD(&lsp->ls_locks); |
663 | return lsp; | 750 | return lsp; |
@@ -665,10 +752,11 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f | |||
665 | 752 | ||
666 | static void nfs4_free_lock_state(struct nfs4_lock_state *lsp) | 753 | static void nfs4_free_lock_state(struct nfs4_lock_state *lsp) |
667 | { | 754 | { |
668 | struct nfs_client *clp = lsp->ls_state->owner->so_server->nfs_client; | 755 | struct nfs_server *server = lsp->ls_state->owner->so_server; |
756 | struct nfs_client *clp = server->nfs_client; | ||
669 | 757 | ||
670 | spin_lock(&clp->cl_lock); | 758 | spin_lock(&clp->cl_lock); |
671 | nfs_free_unique_id(&clp->cl_lockowner_id, &lsp->ls_id); | 759 | nfs_free_unique_id(&server->lockowner_id, &lsp->ls_id); |
672 | spin_unlock(&clp->cl_lock); | 760 | spin_unlock(&clp->cl_lock); |
673 | rpc_destroy_wait_queue(&lsp->ls_sequence.wait); | 761 | rpc_destroy_wait_queue(&lsp->ls_sequence.wait); |
674 | kfree(lsp); | 762 | kfree(lsp); |
@@ -1114,15 +1202,19 @@ static void nfs4_clear_open_state(struct nfs4_state *state) | |||
1114 | } | 1202 | } |
1115 | } | 1203 | } |
1116 | 1204 | ||
1117 | static void nfs4_state_mark_reclaim_helper(struct nfs_client *clp, int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) | 1205 | static void nfs4_reset_seqids(struct nfs_server *server, |
1206 | int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) | ||
1118 | { | 1207 | { |
1208 | struct nfs_client *clp = server->nfs_client; | ||
1119 | struct nfs4_state_owner *sp; | 1209 | struct nfs4_state_owner *sp; |
1120 | struct rb_node *pos; | 1210 | struct rb_node *pos; |
1121 | struct nfs4_state *state; | 1211 | struct nfs4_state *state; |
1122 | 1212 | ||
1123 | /* Reset all sequence ids to zero */ | 1213 | spin_lock(&clp->cl_lock); |
1124 | for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) { | 1214 | for (pos = rb_first(&server->state_owners); |
1125 | sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); | 1215 | pos != NULL; |
1216 | pos = rb_next(pos)) { | ||
1217 | sp = rb_entry(pos, struct nfs4_state_owner, so_server_node); | ||
1126 | sp->so_seqid.flags = 0; | 1218 | sp->so_seqid.flags = 0; |
1127 | spin_lock(&sp->so_lock); | 1219 | spin_lock(&sp->so_lock); |
1128 | list_for_each_entry(state, &sp->so_states, open_states) { | 1220 | list_for_each_entry(state, &sp->so_states, open_states) { |
@@ -1131,6 +1223,18 @@ static void nfs4_state_mark_reclaim_helper(struct nfs_client *clp, int (*mark_re | |||
1131 | } | 1223 | } |
1132 | spin_unlock(&sp->so_lock); | 1224 | spin_unlock(&sp->so_lock); |
1133 | } | 1225 | } |
1226 | spin_unlock(&clp->cl_lock); | ||
1227 | } | ||
1228 | |||
1229 | static void nfs4_state_mark_reclaim_helper(struct nfs_client *clp, | ||
1230 | int (*mark_reclaim)(struct nfs_client *clp, struct nfs4_state *state)) | ||
1231 | { | ||
1232 | struct nfs_server *server; | ||
1233 | |||
1234 | rcu_read_lock(); | ||
1235 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) | ||
1236 | nfs4_reset_seqids(server, mark_reclaim); | ||
1237 | rcu_read_unlock(); | ||
1134 | } | 1238 | } |
1135 | 1239 | ||
1136 | static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp) | 1240 | static void nfs4_state_start_reclaim_reboot(struct nfs_client *clp) |
@@ -1148,25 +1252,41 @@ static void nfs4_reclaim_complete(struct nfs_client *clp, | |||
1148 | (void)ops->reclaim_complete(clp); | 1252 | (void)ops->reclaim_complete(clp); |
1149 | } | 1253 | } |
1150 | 1254 | ||
1151 | static int nfs4_state_clear_reclaim_reboot(struct nfs_client *clp) | 1255 | static void nfs4_clear_reclaim_server(struct nfs_server *server) |
1152 | { | 1256 | { |
1257 | struct nfs_client *clp = server->nfs_client; | ||
1153 | struct nfs4_state_owner *sp; | 1258 | struct nfs4_state_owner *sp; |
1154 | struct rb_node *pos; | 1259 | struct rb_node *pos; |
1155 | struct nfs4_state *state; | 1260 | struct nfs4_state *state; |
1156 | 1261 | ||
1157 | if (!test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) | 1262 | spin_lock(&clp->cl_lock); |
1158 | return 0; | 1263 | for (pos = rb_first(&server->state_owners); |
1159 | 1264 | pos != NULL; | |
1160 | for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) { | 1265 | pos = rb_next(pos)) { |
1161 | sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); | 1266 | sp = rb_entry(pos, struct nfs4_state_owner, so_server_node); |
1162 | spin_lock(&sp->so_lock); | 1267 | spin_lock(&sp->so_lock); |
1163 | list_for_each_entry(state, &sp->so_states, open_states) { | 1268 | list_for_each_entry(state, &sp->so_states, open_states) { |
1164 | if (!test_and_clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags)) | 1269 | if (!test_and_clear_bit(NFS_STATE_RECLAIM_REBOOT, |
1270 | &state->flags)) | ||
1165 | continue; | 1271 | continue; |
1166 | nfs4_state_mark_reclaim_nograce(clp, state); | 1272 | nfs4_state_mark_reclaim_nograce(clp, state); |
1167 | } | 1273 | } |
1168 | spin_unlock(&sp->so_lock); | 1274 | spin_unlock(&sp->so_lock); |
1169 | } | 1275 | } |
1276 | spin_unlock(&clp->cl_lock); | ||
1277 | } | ||
1278 | |||
1279 | static int nfs4_state_clear_reclaim_reboot(struct nfs_client *clp) | ||
1280 | { | ||
1281 | struct nfs_server *server; | ||
1282 | |||
1283 | if (!test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) | ||
1284 | return 0; | ||
1285 | |||
1286 | rcu_read_lock(); | ||
1287 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) | ||
1288 | nfs4_clear_reclaim_server(server); | ||
1289 | rcu_read_unlock(); | ||
1170 | 1290 | ||
1171 | nfs_delegation_reap_unclaimed(clp); | 1291 | nfs_delegation_reap_unclaimed(clp); |
1172 | return 1; | 1292 | return 1; |
@@ -1238,27 +1358,40 @@ static int nfs4_recovery_handle_error(struct nfs_client *clp, int error) | |||
1238 | 1358 | ||
1239 | static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recovery_ops *ops) | 1359 | static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recovery_ops *ops) |
1240 | { | 1360 | { |
1361 | struct nfs4_state_owner *sp; | ||
1362 | struct nfs_server *server; | ||
1241 | struct rb_node *pos; | 1363 | struct rb_node *pos; |
1242 | int status = 0; | 1364 | int status = 0; |
1243 | 1365 | ||
1244 | restart: | 1366 | restart: |
1245 | spin_lock(&clp->cl_lock); | 1367 | rcu_read_lock(); |
1246 | for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) { | 1368 | list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) { |
1247 | struct nfs4_state_owner *sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); | 1369 | spin_lock(&clp->cl_lock); |
1248 | if (!test_and_clear_bit(ops->owner_flag_bit, &sp->so_flags)) | 1370 | for (pos = rb_first(&server->state_owners); |
1249 | continue; | 1371 | pos != NULL; |
1250 | atomic_inc(&sp->so_count); | 1372 | pos = rb_next(pos)) { |
1251 | spin_unlock(&clp->cl_lock); | 1373 | sp = rb_entry(pos, |
1252 | status = nfs4_reclaim_open_state(sp, ops); | 1374 | struct nfs4_state_owner, so_server_node); |
1253 | if (status < 0) { | 1375 | if (!test_and_clear_bit(ops->owner_flag_bit, |
1254 | set_bit(ops->owner_flag_bit, &sp->so_flags); | 1376 | &sp->so_flags)) |
1377 | continue; | ||
1378 | atomic_inc(&sp->so_count); | ||
1379 | spin_unlock(&clp->cl_lock); | ||
1380 | rcu_read_unlock(); | ||
1381 | |||
1382 | status = nfs4_reclaim_open_state(sp, ops); | ||
1383 | if (status < 0) { | ||
1384 | set_bit(ops->owner_flag_bit, &sp->so_flags); | ||
1385 | nfs4_put_state_owner(sp); | ||
1386 | return nfs4_recovery_handle_error(clp, status); | ||
1387 | } | ||
1388 | |||
1255 | nfs4_put_state_owner(sp); | 1389 | nfs4_put_state_owner(sp); |
1256 | return nfs4_recovery_handle_error(clp, status); | 1390 | goto restart; |
1257 | } | 1391 | } |
1258 | nfs4_put_state_owner(sp); | 1392 | spin_unlock(&clp->cl_lock); |
1259 | goto restart; | ||
1260 | } | 1393 | } |
1261 | spin_unlock(&clp->cl_lock); | 1394 | rcu_read_unlock(); |
1262 | return status; | 1395 | return status; |
1263 | } | 1396 | } |
1264 | 1397 | ||
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c index 9f1826b012e6..2ab8e5cb8f59 100644 --- a/fs/nfs/nfs4xdr.c +++ b/fs/nfs/nfs4xdr.c | |||
@@ -71,8 +71,8 @@ static int nfs4_stat_to_errno(int); | |||
71 | /* lock,open owner id: | 71 | /* lock,open owner id: |
72 | * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) | 72 | * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2) |
73 | */ | 73 | */ |
74 | #define open_owner_id_maxsz (1 + 4) | 74 | #define open_owner_id_maxsz (1 + 1 + 4) |
75 | #define lock_owner_id_maxsz (1 + 4) | 75 | #define lock_owner_id_maxsz (1 + 1 + 4) |
76 | #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) | 76 | #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ)) |
77 | #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) | 77 | #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) |
78 | #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) | 78 | #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2)) |
@@ -1088,10 +1088,11 @@ static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lo | |||
1088 | { | 1088 | { |
1089 | __be32 *p; | 1089 | __be32 *p; |
1090 | 1090 | ||
1091 | p = reserve_space(xdr, 28); | 1091 | p = reserve_space(xdr, 32); |
1092 | p = xdr_encode_hyper(p, lowner->clientid); | 1092 | p = xdr_encode_hyper(p, lowner->clientid); |
1093 | *p++ = cpu_to_be32(16); | 1093 | *p++ = cpu_to_be32(20); |
1094 | p = xdr_encode_opaque_fixed(p, "lock id:", 8); | 1094 | p = xdr_encode_opaque_fixed(p, "lock id:", 8); |
1095 | *p++ = cpu_to_be32(lowner->s_dev); | ||
1095 | xdr_encode_hyper(p, lowner->id); | 1096 | xdr_encode_hyper(p, lowner->id); |
1096 | } | 1097 | } |
1097 | 1098 | ||
@@ -1210,10 +1211,11 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena | |||
1210 | *p++ = cpu_to_be32(OP_OPEN); | 1211 | *p++ = cpu_to_be32(OP_OPEN); |
1211 | *p = cpu_to_be32(arg->seqid->sequence->counter); | 1212 | *p = cpu_to_be32(arg->seqid->sequence->counter); |
1212 | encode_share_access(xdr, arg->fmode); | 1213 | encode_share_access(xdr, arg->fmode); |
1213 | p = reserve_space(xdr, 28); | 1214 | p = reserve_space(xdr, 32); |
1214 | p = xdr_encode_hyper(p, arg->clientid); | 1215 | p = xdr_encode_hyper(p, arg->clientid); |
1215 | *p++ = cpu_to_be32(16); | 1216 | *p++ = cpu_to_be32(20); |
1216 | p = xdr_encode_opaque_fixed(p, "open id:", 8); | 1217 | p = xdr_encode_opaque_fixed(p, "open id:", 8); |
1218 | *p++ = cpu_to_be32(arg->server->s_dev); | ||
1217 | xdr_encode_hyper(p, arg->id); | 1219 | xdr_encode_hyper(p, arg->id); |
1218 | } | 1220 | } |
1219 | 1221 | ||
@@ -1510,7 +1512,7 @@ encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr) | |||
1510 | hdr->replen += decode_restorefh_maxsz; | 1512 | hdr->replen += decode_restorefh_maxsz; |
1511 | } | 1513 | } |
1512 | 1514 | ||
1513 | static int | 1515 | static void |
1514 | encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) | 1516 | encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr) |
1515 | { | 1517 | { |
1516 | __be32 *p; | 1518 | __be32 *p; |
@@ -1521,14 +1523,12 @@ encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compoun | |||
1521 | p = reserve_space(xdr, 2*4); | 1523 | p = reserve_space(xdr, 2*4); |
1522 | *p++ = cpu_to_be32(1); | 1524 | *p++ = cpu_to_be32(1); |
1523 | *p = cpu_to_be32(FATTR4_WORD0_ACL); | 1525 | *p = cpu_to_be32(FATTR4_WORD0_ACL); |
1524 | if (arg->acl_len % 4) | 1526 | BUG_ON(arg->acl_len % 4); |
1525 | return -EINVAL; | ||
1526 | p = reserve_space(xdr, 4); | 1527 | p = reserve_space(xdr, 4); |
1527 | *p = cpu_to_be32(arg->acl_len); | 1528 | *p = cpu_to_be32(arg->acl_len); |
1528 | xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); | 1529 | xdr_write_pages(xdr, arg->acl_pages, arg->acl_pgbase, arg->acl_len); |
1529 | hdr->nops++; | 1530 | hdr->nops++; |
1530 | hdr->replen += decode_setacl_maxsz; | 1531 | hdr->replen += decode_setacl_maxsz; |
1531 | return 0; | ||
1532 | } | 1532 | } |
1533 | 1533 | ||
1534 | static void | 1534 | static void |
@@ -1789,7 +1789,6 @@ encode_layoutget(struct xdr_stream *xdr, | |||
1789 | const struct nfs4_layoutget_args *args, | 1789 | const struct nfs4_layoutget_args *args, |
1790 | struct compound_hdr *hdr) | 1790 | struct compound_hdr *hdr) |
1791 | { | 1791 | { |
1792 | nfs4_stateid stateid; | ||
1793 | __be32 *p; | 1792 | __be32 *p; |
1794 | 1793 | ||
1795 | p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE); | 1794 | p = reserve_space(xdr, 44 + NFS4_STATEID_SIZE); |
@@ -1800,9 +1799,7 @@ encode_layoutget(struct xdr_stream *xdr, | |||
1800 | p = xdr_encode_hyper(p, args->range.offset); | 1799 | p = xdr_encode_hyper(p, args->range.offset); |
1801 | p = xdr_encode_hyper(p, args->range.length); | 1800 | p = xdr_encode_hyper(p, args->range.length); |
1802 | p = xdr_encode_hyper(p, args->minlength); | 1801 | p = xdr_encode_hyper(p, args->minlength); |
1803 | pnfs_get_layout_stateid(&stateid, NFS_I(args->inode)->layout, | 1802 | p = xdr_encode_opaque_fixed(p, &args->stateid.data, NFS4_STATEID_SIZE); |
1804 | args->ctx->state); | ||
1805 | p = xdr_encode_opaque_fixed(p, &stateid.data, NFS4_STATEID_SIZE); | ||
1806 | *p = cpu_to_be32(args->maxcount); | 1803 | *p = cpu_to_be32(args->maxcount); |
1807 | 1804 | ||
1808 | dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", | 1805 | dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n", |
@@ -1833,393 +1830,362 @@ static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args) | |||
1833 | /* | 1830 | /* |
1834 | * Encode an ACCESS request | 1831 | * Encode an ACCESS request |
1835 | */ | 1832 | */ |
1836 | static int nfs4_xdr_enc_access(struct rpc_rqst *req, __be32 *p, const struct nfs4_accessargs *args) | 1833 | static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr, |
1834 | const struct nfs4_accessargs *args) | ||
1837 | { | 1835 | { |
1838 | struct xdr_stream xdr; | ||
1839 | struct compound_hdr hdr = { | 1836 | struct compound_hdr hdr = { |
1840 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 1837 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1841 | }; | 1838 | }; |
1842 | 1839 | ||
1843 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 1840 | encode_compound_hdr(xdr, req, &hdr); |
1844 | encode_compound_hdr(&xdr, req, &hdr); | 1841 | encode_sequence(xdr, &args->seq_args, &hdr); |
1845 | encode_sequence(&xdr, &args->seq_args, &hdr); | 1842 | encode_putfh(xdr, args->fh, &hdr); |
1846 | encode_putfh(&xdr, args->fh, &hdr); | 1843 | encode_access(xdr, args->access, &hdr); |
1847 | encode_access(&xdr, args->access, &hdr); | 1844 | encode_getfattr(xdr, args->bitmask, &hdr); |
1848 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
1849 | encode_nops(&hdr); | 1845 | encode_nops(&hdr); |
1850 | return 0; | ||
1851 | } | 1846 | } |
1852 | 1847 | ||
1853 | /* | 1848 | /* |
1854 | * Encode LOOKUP request | 1849 | * Encode LOOKUP request |
1855 | */ | 1850 | */ |
1856 | static int nfs4_xdr_enc_lookup(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_arg *args) | 1851 | static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr, |
1852 | const struct nfs4_lookup_arg *args) | ||
1857 | { | 1853 | { |
1858 | struct xdr_stream xdr; | ||
1859 | struct compound_hdr hdr = { | 1854 | struct compound_hdr hdr = { |
1860 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 1855 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1861 | }; | 1856 | }; |
1862 | 1857 | ||
1863 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 1858 | encode_compound_hdr(xdr, req, &hdr); |
1864 | encode_compound_hdr(&xdr, req, &hdr); | 1859 | encode_sequence(xdr, &args->seq_args, &hdr); |
1865 | encode_sequence(&xdr, &args->seq_args, &hdr); | 1860 | encode_putfh(xdr, args->dir_fh, &hdr); |
1866 | encode_putfh(&xdr, args->dir_fh, &hdr); | 1861 | encode_lookup(xdr, args->name, &hdr); |
1867 | encode_lookup(&xdr, args->name, &hdr); | 1862 | encode_getfh(xdr, &hdr); |
1868 | encode_getfh(&xdr, &hdr); | 1863 | encode_getfattr(xdr, args->bitmask, &hdr); |
1869 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
1870 | encode_nops(&hdr); | 1864 | encode_nops(&hdr); |
1871 | return 0; | ||
1872 | } | 1865 | } |
1873 | 1866 | ||
1874 | /* | 1867 | /* |
1875 | * Encode LOOKUP_ROOT request | 1868 | * Encode LOOKUP_ROOT request |
1876 | */ | 1869 | */ |
1877 | static int nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, __be32 *p, const struct nfs4_lookup_root_arg *args) | 1870 | static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req, |
1871 | struct xdr_stream *xdr, | ||
1872 | const struct nfs4_lookup_root_arg *args) | ||
1878 | { | 1873 | { |
1879 | struct xdr_stream xdr; | ||
1880 | struct compound_hdr hdr = { | 1874 | struct compound_hdr hdr = { |
1881 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 1875 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1882 | }; | 1876 | }; |
1883 | 1877 | ||
1884 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 1878 | encode_compound_hdr(xdr, req, &hdr); |
1885 | encode_compound_hdr(&xdr, req, &hdr); | 1879 | encode_sequence(xdr, &args->seq_args, &hdr); |
1886 | encode_sequence(&xdr, &args->seq_args, &hdr); | 1880 | encode_putrootfh(xdr, &hdr); |
1887 | encode_putrootfh(&xdr, &hdr); | 1881 | encode_getfh(xdr, &hdr); |
1888 | encode_getfh(&xdr, &hdr); | 1882 | encode_getfattr(xdr, args->bitmask, &hdr); |
1889 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
1890 | encode_nops(&hdr); | 1883 | encode_nops(&hdr); |
1891 | return 0; | ||
1892 | } | 1884 | } |
1893 | 1885 | ||
1894 | /* | 1886 | /* |
1895 | * Encode REMOVE request | 1887 | * Encode REMOVE request |
1896 | */ | 1888 | */ |
1897 | static int nfs4_xdr_enc_remove(struct rpc_rqst *req, __be32 *p, const struct nfs_removeargs *args) | 1889 | static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr, |
1890 | const struct nfs_removeargs *args) | ||
1898 | { | 1891 | { |
1899 | struct xdr_stream xdr; | ||
1900 | struct compound_hdr hdr = { | 1892 | struct compound_hdr hdr = { |
1901 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 1893 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1902 | }; | 1894 | }; |
1903 | 1895 | ||
1904 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 1896 | encode_compound_hdr(xdr, req, &hdr); |
1905 | encode_compound_hdr(&xdr, req, &hdr); | 1897 | encode_sequence(xdr, &args->seq_args, &hdr); |
1906 | encode_sequence(&xdr, &args->seq_args, &hdr); | 1898 | encode_putfh(xdr, args->fh, &hdr); |
1907 | encode_putfh(&xdr, args->fh, &hdr); | 1899 | encode_remove(xdr, &args->name, &hdr); |
1908 | encode_remove(&xdr, &args->name, &hdr); | 1900 | encode_getfattr(xdr, args->bitmask, &hdr); |
1909 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
1910 | encode_nops(&hdr); | 1901 | encode_nops(&hdr); |
1911 | return 0; | ||
1912 | } | 1902 | } |
1913 | 1903 | ||
1914 | /* | 1904 | /* |
1915 | * Encode RENAME request | 1905 | * Encode RENAME request |
1916 | */ | 1906 | */ |
1917 | static int nfs4_xdr_enc_rename(struct rpc_rqst *req, __be32 *p, const struct nfs_renameargs *args) | 1907 | static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr, |
1908 | const struct nfs_renameargs *args) | ||
1918 | { | 1909 | { |
1919 | struct xdr_stream xdr; | ||
1920 | struct compound_hdr hdr = { | 1910 | struct compound_hdr hdr = { |
1921 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 1911 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1922 | }; | 1912 | }; |
1923 | 1913 | ||
1924 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 1914 | encode_compound_hdr(xdr, req, &hdr); |
1925 | encode_compound_hdr(&xdr, req, &hdr); | 1915 | encode_sequence(xdr, &args->seq_args, &hdr); |
1926 | encode_sequence(&xdr, &args->seq_args, &hdr); | 1916 | encode_putfh(xdr, args->old_dir, &hdr); |
1927 | encode_putfh(&xdr, args->old_dir, &hdr); | 1917 | encode_savefh(xdr, &hdr); |
1928 | encode_savefh(&xdr, &hdr); | 1918 | encode_putfh(xdr, args->new_dir, &hdr); |
1929 | encode_putfh(&xdr, args->new_dir, &hdr); | 1919 | encode_rename(xdr, args->old_name, args->new_name, &hdr); |
1930 | encode_rename(&xdr, args->old_name, args->new_name, &hdr); | 1920 | encode_getfattr(xdr, args->bitmask, &hdr); |
1931 | encode_getfattr(&xdr, args->bitmask, &hdr); | 1921 | encode_restorefh(xdr, &hdr); |
1932 | encode_restorefh(&xdr, &hdr); | 1922 | encode_getfattr(xdr, args->bitmask, &hdr); |
1933 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
1934 | encode_nops(&hdr); | 1923 | encode_nops(&hdr); |
1935 | return 0; | ||
1936 | } | 1924 | } |
1937 | 1925 | ||
1938 | /* | 1926 | /* |
1939 | * Encode LINK request | 1927 | * Encode LINK request |
1940 | */ | 1928 | */ |
1941 | static int nfs4_xdr_enc_link(struct rpc_rqst *req, __be32 *p, const struct nfs4_link_arg *args) | 1929 | static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr, |
1930 | const struct nfs4_link_arg *args) | ||
1942 | { | 1931 | { |
1943 | struct xdr_stream xdr; | ||
1944 | struct compound_hdr hdr = { | 1932 | struct compound_hdr hdr = { |
1945 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 1933 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1946 | }; | 1934 | }; |
1947 | 1935 | ||
1948 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 1936 | encode_compound_hdr(xdr, req, &hdr); |
1949 | encode_compound_hdr(&xdr, req, &hdr); | 1937 | encode_sequence(xdr, &args->seq_args, &hdr); |
1950 | encode_sequence(&xdr, &args->seq_args, &hdr); | 1938 | encode_putfh(xdr, args->fh, &hdr); |
1951 | encode_putfh(&xdr, args->fh, &hdr); | 1939 | encode_savefh(xdr, &hdr); |
1952 | encode_savefh(&xdr, &hdr); | 1940 | encode_putfh(xdr, args->dir_fh, &hdr); |
1953 | encode_putfh(&xdr, args->dir_fh, &hdr); | 1941 | encode_link(xdr, args->name, &hdr); |
1954 | encode_link(&xdr, args->name, &hdr); | 1942 | encode_getfattr(xdr, args->bitmask, &hdr); |
1955 | encode_getfattr(&xdr, args->bitmask, &hdr); | 1943 | encode_restorefh(xdr, &hdr); |
1956 | encode_restorefh(&xdr, &hdr); | 1944 | encode_getfattr(xdr, args->bitmask, &hdr); |
1957 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
1958 | encode_nops(&hdr); | 1945 | encode_nops(&hdr); |
1959 | return 0; | ||
1960 | } | 1946 | } |
1961 | 1947 | ||
1962 | /* | 1948 | /* |
1963 | * Encode CREATE request | 1949 | * Encode CREATE request |
1964 | */ | 1950 | */ |
1965 | static int nfs4_xdr_enc_create(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args) | 1951 | static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr, |
1952 | const struct nfs4_create_arg *args) | ||
1966 | { | 1953 | { |
1967 | struct xdr_stream xdr; | ||
1968 | struct compound_hdr hdr = { | 1954 | struct compound_hdr hdr = { |
1969 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 1955 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
1970 | }; | 1956 | }; |
1971 | 1957 | ||
1972 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 1958 | encode_compound_hdr(xdr, req, &hdr); |
1973 | encode_compound_hdr(&xdr, req, &hdr); | 1959 | encode_sequence(xdr, &args->seq_args, &hdr); |
1974 | encode_sequence(&xdr, &args->seq_args, &hdr); | 1960 | encode_putfh(xdr, args->dir_fh, &hdr); |
1975 | encode_putfh(&xdr, args->dir_fh, &hdr); | 1961 | encode_savefh(xdr, &hdr); |
1976 | encode_savefh(&xdr, &hdr); | 1962 | encode_create(xdr, args, &hdr); |
1977 | encode_create(&xdr, args, &hdr); | 1963 | encode_getfh(xdr, &hdr); |
1978 | encode_getfh(&xdr, &hdr); | 1964 | encode_getfattr(xdr, args->bitmask, &hdr); |
1979 | encode_getfattr(&xdr, args->bitmask, &hdr); | 1965 | encode_restorefh(xdr, &hdr); |
1980 | encode_restorefh(&xdr, &hdr); | 1966 | encode_getfattr(xdr, args->bitmask, &hdr); |
1981 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
1982 | encode_nops(&hdr); | 1967 | encode_nops(&hdr); |
1983 | return 0; | ||
1984 | } | 1968 | } |
1985 | 1969 | ||
1986 | /* | 1970 | /* |
1987 | * Encode SYMLINK request | 1971 | * Encode SYMLINK request |
1988 | */ | 1972 | */ |
1989 | static int nfs4_xdr_enc_symlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_create_arg *args) | 1973 | static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr, |
1974 | const struct nfs4_create_arg *args) | ||
1990 | { | 1975 | { |
1991 | return nfs4_xdr_enc_create(req, p, args); | 1976 | nfs4_xdr_enc_create(req, xdr, args); |
1992 | } | 1977 | } |
1993 | 1978 | ||
1994 | /* | 1979 | /* |
1995 | * Encode GETATTR request | 1980 | * Encode GETATTR request |
1996 | */ | 1981 | */ |
1997 | static int nfs4_xdr_enc_getattr(struct rpc_rqst *req, __be32 *p, const struct nfs4_getattr_arg *args) | 1982 | static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr, |
1983 | const struct nfs4_getattr_arg *args) | ||
1998 | { | 1984 | { |
1999 | struct xdr_stream xdr; | ||
2000 | struct compound_hdr hdr = { | 1985 | struct compound_hdr hdr = { |
2001 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 1986 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2002 | }; | 1987 | }; |
2003 | 1988 | ||
2004 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 1989 | encode_compound_hdr(xdr, req, &hdr); |
2005 | encode_compound_hdr(&xdr, req, &hdr); | 1990 | encode_sequence(xdr, &args->seq_args, &hdr); |
2006 | encode_sequence(&xdr, &args->seq_args, &hdr); | 1991 | encode_putfh(xdr, args->fh, &hdr); |
2007 | encode_putfh(&xdr, args->fh, &hdr); | 1992 | encode_getfattr(xdr, args->bitmask, &hdr); |
2008 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
2009 | encode_nops(&hdr); | 1993 | encode_nops(&hdr); |
2010 | return 0; | ||
2011 | } | 1994 | } |
2012 | 1995 | ||
2013 | /* | 1996 | /* |
2014 | * Encode a CLOSE request | 1997 | * Encode a CLOSE request |
2015 | */ | 1998 | */ |
2016 | static int nfs4_xdr_enc_close(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args) | 1999 | static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr, |
2000 | struct nfs_closeargs *args) | ||
2017 | { | 2001 | { |
2018 | struct xdr_stream xdr; | ||
2019 | struct compound_hdr hdr = { | 2002 | struct compound_hdr hdr = { |
2020 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2003 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2021 | }; | 2004 | }; |
2022 | 2005 | ||
2023 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2006 | encode_compound_hdr(xdr, req, &hdr); |
2024 | encode_compound_hdr(&xdr, req, &hdr); | 2007 | encode_sequence(xdr, &args->seq_args, &hdr); |
2025 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2008 | encode_putfh(xdr, args->fh, &hdr); |
2026 | encode_putfh(&xdr, args->fh, &hdr); | 2009 | encode_close(xdr, args, &hdr); |
2027 | encode_close(&xdr, args, &hdr); | 2010 | encode_getfattr(xdr, args->bitmask, &hdr); |
2028 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
2029 | encode_nops(&hdr); | 2011 | encode_nops(&hdr); |
2030 | return 0; | ||
2031 | } | 2012 | } |
2032 | 2013 | ||
2033 | /* | 2014 | /* |
2034 | * Encode an OPEN request | 2015 | * Encode an OPEN request |
2035 | */ | 2016 | */ |
2036 | static int nfs4_xdr_enc_open(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args) | 2017 | static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr, |
2018 | struct nfs_openargs *args) | ||
2037 | { | 2019 | { |
2038 | struct xdr_stream xdr; | ||
2039 | struct compound_hdr hdr = { | 2020 | struct compound_hdr hdr = { |
2040 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2021 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2041 | }; | 2022 | }; |
2042 | 2023 | ||
2043 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2024 | encode_compound_hdr(xdr, req, &hdr); |
2044 | encode_compound_hdr(&xdr, req, &hdr); | 2025 | encode_sequence(xdr, &args->seq_args, &hdr); |
2045 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2026 | encode_putfh(xdr, args->fh, &hdr); |
2046 | encode_putfh(&xdr, args->fh, &hdr); | 2027 | encode_savefh(xdr, &hdr); |
2047 | encode_savefh(&xdr, &hdr); | 2028 | encode_open(xdr, args, &hdr); |
2048 | encode_open(&xdr, args, &hdr); | 2029 | encode_getfh(xdr, &hdr); |
2049 | encode_getfh(&xdr, &hdr); | 2030 | encode_getfattr(xdr, args->bitmask, &hdr); |
2050 | encode_getfattr(&xdr, args->bitmask, &hdr); | 2031 | encode_restorefh(xdr, &hdr); |
2051 | encode_restorefh(&xdr, &hdr); | 2032 | encode_getfattr(xdr, args->bitmask, &hdr); |
2052 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
2053 | encode_nops(&hdr); | 2033 | encode_nops(&hdr); |
2054 | return 0; | ||
2055 | } | 2034 | } |
2056 | 2035 | ||
2057 | /* | 2036 | /* |
2058 | * Encode an OPEN_CONFIRM request | 2037 | * Encode an OPEN_CONFIRM request |
2059 | */ | 2038 | */ |
2060 | static int nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_open_confirmargs *args) | 2039 | static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req, |
2040 | struct xdr_stream *xdr, | ||
2041 | struct nfs_open_confirmargs *args) | ||
2061 | { | 2042 | { |
2062 | struct xdr_stream xdr; | ||
2063 | struct compound_hdr hdr = { | 2043 | struct compound_hdr hdr = { |
2064 | .nops = 0, | 2044 | .nops = 0, |
2065 | }; | 2045 | }; |
2066 | 2046 | ||
2067 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2047 | encode_compound_hdr(xdr, req, &hdr); |
2068 | encode_compound_hdr(&xdr, req, &hdr); | 2048 | encode_putfh(xdr, args->fh, &hdr); |
2069 | encode_putfh(&xdr, args->fh, &hdr); | 2049 | encode_open_confirm(xdr, args, &hdr); |
2070 | encode_open_confirm(&xdr, args, &hdr); | ||
2071 | encode_nops(&hdr); | 2050 | encode_nops(&hdr); |
2072 | return 0; | ||
2073 | } | 2051 | } |
2074 | 2052 | ||
2075 | /* | 2053 | /* |
2076 | * Encode an OPEN request with no attributes. | 2054 | * Encode an OPEN request with no attributes. |
2077 | */ | 2055 | */ |
2078 | static int nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, __be32 *p, struct nfs_openargs *args) | 2056 | static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req, |
2057 | struct xdr_stream *xdr, | ||
2058 | struct nfs_openargs *args) | ||
2079 | { | 2059 | { |
2080 | struct xdr_stream xdr; | ||
2081 | struct compound_hdr hdr = { | 2060 | struct compound_hdr hdr = { |
2082 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2061 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2083 | }; | 2062 | }; |
2084 | 2063 | ||
2085 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2064 | encode_compound_hdr(xdr, req, &hdr); |
2086 | encode_compound_hdr(&xdr, req, &hdr); | 2065 | encode_sequence(xdr, &args->seq_args, &hdr); |
2087 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2066 | encode_putfh(xdr, args->fh, &hdr); |
2088 | encode_putfh(&xdr, args->fh, &hdr); | 2067 | encode_open(xdr, args, &hdr); |
2089 | encode_open(&xdr, args, &hdr); | 2068 | encode_getfattr(xdr, args->bitmask, &hdr); |
2090 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
2091 | encode_nops(&hdr); | 2069 | encode_nops(&hdr); |
2092 | return 0; | ||
2093 | } | 2070 | } |
2094 | 2071 | ||
2095 | /* | 2072 | /* |
2096 | * Encode an OPEN_DOWNGRADE request | 2073 | * Encode an OPEN_DOWNGRADE request |
2097 | */ | 2074 | */ |
2098 | static int nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, __be32 *p, struct nfs_closeargs *args) | 2075 | static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req, |
2076 | struct xdr_stream *xdr, | ||
2077 | struct nfs_closeargs *args) | ||
2099 | { | 2078 | { |
2100 | struct xdr_stream xdr; | ||
2101 | struct compound_hdr hdr = { | 2079 | struct compound_hdr hdr = { |
2102 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2080 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2103 | }; | 2081 | }; |
2104 | 2082 | ||
2105 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2083 | encode_compound_hdr(xdr, req, &hdr); |
2106 | encode_compound_hdr(&xdr, req, &hdr); | 2084 | encode_sequence(xdr, &args->seq_args, &hdr); |
2107 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2085 | encode_putfh(xdr, args->fh, &hdr); |
2108 | encode_putfh(&xdr, args->fh, &hdr); | 2086 | encode_open_downgrade(xdr, args, &hdr); |
2109 | encode_open_downgrade(&xdr, args, &hdr); | 2087 | encode_getfattr(xdr, args->bitmask, &hdr); |
2110 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
2111 | encode_nops(&hdr); | 2088 | encode_nops(&hdr); |
2112 | return 0; | ||
2113 | } | 2089 | } |
2114 | 2090 | ||
2115 | /* | 2091 | /* |
2116 | * Encode a LOCK request | 2092 | * Encode a LOCK request |
2117 | */ | 2093 | */ |
2118 | static int nfs4_xdr_enc_lock(struct rpc_rqst *req, __be32 *p, struct nfs_lock_args *args) | 2094 | static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr, |
2095 | struct nfs_lock_args *args) | ||
2119 | { | 2096 | { |
2120 | struct xdr_stream xdr; | ||
2121 | struct compound_hdr hdr = { | 2097 | struct compound_hdr hdr = { |
2122 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2098 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2123 | }; | 2099 | }; |
2124 | 2100 | ||
2125 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2101 | encode_compound_hdr(xdr, req, &hdr); |
2126 | encode_compound_hdr(&xdr, req, &hdr); | 2102 | encode_sequence(xdr, &args->seq_args, &hdr); |
2127 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2103 | encode_putfh(xdr, args->fh, &hdr); |
2128 | encode_putfh(&xdr, args->fh, &hdr); | 2104 | encode_lock(xdr, args, &hdr); |
2129 | encode_lock(&xdr, args, &hdr); | ||
2130 | encode_nops(&hdr); | 2105 | encode_nops(&hdr); |
2131 | return 0; | ||
2132 | } | 2106 | } |
2133 | 2107 | ||
2134 | /* | 2108 | /* |
2135 | * Encode a LOCKT request | 2109 | * Encode a LOCKT request |
2136 | */ | 2110 | */ |
2137 | static int nfs4_xdr_enc_lockt(struct rpc_rqst *req, __be32 *p, struct nfs_lockt_args *args) | 2111 | static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr, |
2112 | struct nfs_lockt_args *args) | ||
2138 | { | 2113 | { |
2139 | struct xdr_stream xdr; | ||
2140 | struct compound_hdr hdr = { | 2114 | struct compound_hdr hdr = { |
2141 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2115 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2142 | }; | 2116 | }; |
2143 | 2117 | ||
2144 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2118 | encode_compound_hdr(xdr, req, &hdr); |
2145 | encode_compound_hdr(&xdr, req, &hdr); | 2119 | encode_sequence(xdr, &args->seq_args, &hdr); |
2146 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2120 | encode_putfh(xdr, args->fh, &hdr); |
2147 | encode_putfh(&xdr, args->fh, &hdr); | 2121 | encode_lockt(xdr, args, &hdr); |
2148 | encode_lockt(&xdr, args, &hdr); | ||
2149 | encode_nops(&hdr); | 2122 | encode_nops(&hdr); |
2150 | return 0; | ||
2151 | } | 2123 | } |
2152 | 2124 | ||
2153 | /* | 2125 | /* |
2154 | * Encode a LOCKU request | 2126 | * Encode a LOCKU request |
2155 | */ | 2127 | */ |
2156 | static int nfs4_xdr_enc_locku(struct rpc_rqst *req, __be32 *p, struct nfs_locku_args *args) | 2128 | static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr, |
2129 | struct nfs_locku_args *args) | ||
2157 | { | 2130 | { |
2158 | struct xdr_stream xdr; | ||
2159 | struct compound_hdr hdr = { | 2131 | struct compound_hdr hdr = { |
2160 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2132 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2161 | }; | 2133 | }; |
2162 | 2134 | ||
2163 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2135 | encode_compound_hdr(xdr, req, &hdr); |
2164 | encode_compound_hdr(&xdr, req, &hdr); | 2136 | encode_sequence(xdr, &args->seq_args, &hdr); |
2165 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2137 | encode_putfh(xdr, args->fh, &hdr); |
2166 | encode_putfh(&xdr, args->fh, &hdr); | 2138 | encode_locku(xdr, args, &hdr); |
2167 | encode_locku(&xdr, args, &hdr); | ||
2168 | encode_nops(&hdr); | 2139 | encode_nops(&hdr); |
2169 | return 0; | ||
2170 | } | 2140 | } |
2171 | 2141 | ||
2172 | static int nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, __be32 *p, struct nfs_release_lockowner_args *args) | 2142 | static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req, |
2143 | struct xdr_stream *xdr, | ||
2144 | struct nfs_release_lockowner_args *args) | ||
2173 | { | 2145 | { |
2174 | struct xdr_stream xdr; | ||
2175 | struct compound_hdr hdr = { | 2146 | struct compound_hdr hdr = { |
2176 | .minorversion = 0, | 2147 | .minorversion = 0, |
2177 | }; | 2148 | }; |
2178 | 2149 | ||
2179 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2150 | encode_compound_hdr(xdr, req, &hdr); |
2180 | encode_compound_hdr(&xdr, req, &hdr); | 2151 | encode_release_lockowner(xdr, &args->lock_owner, &hdr); |
2181 | encode_release_lockowner(&xdr, &args->lock_owner, &hdr); | ||
2182 | encode_nops(&hdr); | 2152 | encode_nops(&hdr); |
2183 | return 0; | ||
2184 | } | 2153 | } |
2185 | 2154 | ||
2186 | /* | 2155 | /* |
2187 | * Encode a READLINK request | 2156 | * Encode a READLINK request |
2188 | */ | 2157 | */ |
2189 | static int nfs4_xdr_enc_readlink(struct rpc_rqst *req, __be32 *p, const struct nfs4_readlink *args) | 2158 | static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr, |
2159 | const struct nfs4_readlink *args) | ||
2190 | { | 2160 | { |
2191 | struct xdr_stream xdr; | ||
2192 | struct compound_hdr hdr = { | 2161 | struct compound_hdr hdr = { |
2193 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2162 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2194 | }; | 2163 | }; |
2195 | 2164 | ||
2196 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2165 | encode_compound_hdr(xdr, req, &hdr); |
2197 | encode_compound_hdr(&xdr, req, &hdr); | 2166 | encode_sequence(xdr, &args->seq_args, &hdr); |
2198 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2167 | encode_putfh(xdr, args->fh, &hdr); |
2199 | encode_putfh(&xdr, args->fh, &hdr); | 2168 | encode_readlink(xdr, args, req, &hdr); |
2200 | encode_readlink(&xdr, args, req, &hdr); | ||
2201 | 2169 | ||
2202 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, | 2170 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, |
2203 | args->pgbase, args->pglen); | 2171 | args->pgbase, args->pglen); |
2204 | encode_nops(&hdr); | 2172 | encode_nops(&hdr); |
2205 | return 0; | ||
2206 | } | 2173 | } |
2207 | 2174 | ||
2208 | /* | 2175 | /* |
2209 | * Encode a READDIR request | 2176 | * Encode a READDIR request |
2210 | */ | 2177 | */ |
2211 | static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nfs4_readdir_arg *args) | 2178 | static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr, |
2179 | const struct nfs4_readdir_arg *args) | ||
2212 | { | 2180 | { |
2213 | struct xdr_stream xdr; | ||
2214 | struct compound_hdr hdr = { | 2181 | struct compound_hdr hdr = { |
2215 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2182 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2216 | }; | 2183 | }; |
2217 | 2184 | ||
2218 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2185 | encode_compound_hdr(xdr, req, &hdr); |
2219 | encode_compound_hdr(&xdr, req, &hdr); | 2186 | encode_sequence(xdr, &args->seq_args, &hdr); |
2220 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2187 | encode_putfh(xdr, args->fh, &hdr); |
2221 | encode_putfh(&xdr, args->fh, &hdr); | 2188 | encode_readdir(xdr, args, req, &hdr); |
2222 | encode_readdir(&xdr, args, req, &hdr); | ||
2223 | 2189 | ||
2224 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, | 2190 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages, |
2225 | args->pgbase, args->count); | 2191 | args->pgbase, args->count); |
@@ -2227,428 +2193,387 @@ static int nfs4_xdr_enc_readdir(struct rpc_rqst *req, __be32 *p, const struct nf | |||
2227 | __func__, hdr.replen << 2, args->pages, | 2193 | __func__, hdr.replen << 2, args->pages, |
2228 | args->pgbase, args->count); | 2194 | args->pgbase, args->count); |
2229 | encode_nops(&hdr); | 2195 | encode_nops(&hdr); |
2230 | return 0; | ||
2231 | } | 2196 | } |
2232 | 2197 | ||
2233 | /* | 2198 | /* |
2234 | * Encode a READ request | 2199 | * Encode a READ request |
2235 | */ | 2200 | */ |
2236 | static int nfs4_xdr_enc_read(struct rpc_rqst *req, __be32 *p, struct nfs_readargs *args) | 2201 | static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr, |
2202 | struct nfs_readargs *args) | ||
2237 | { | 2203 | { |
2238 | struct xdr_stream xdr; | ||
2239 | struct compound_hdr hdr = { | 2204 | struct compound_hdr hdr = { |
2240 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2205 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2241 | }; | 2206 | }; |
2242 | 2207 | ||
2243 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2208 | encode_compound_hdr(xdr, req, &hdr); |
2244 | encode_compound_hdr(&xdr, req, &hdr); | 2209 | encode_sequence(xdr, &args->seq_args, &hdr); |
2245 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2210 | encode_putfh(xdr, args->fh, &hdr); |
2246 | encode_putfh(&xdr, args->fh, &hdr); | 2211 | encode_read(xdr, args, &hdr); |
2247 | encode_read(&xdr, args, &hdr); | ||
2248 | 2212 | ||
2249 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, | 2213 | xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, |
2250 | args->pages, args->pgbase, args->count); | 2214 | args->pages, args->pgbase, args->count); |
2251 | req->rq_rcv_buf.flags |= XDRBUF_READ; | 2215 | req->rq_rcv_buf.flags |= XDRBUF_READ; |
2252 | encode_nops(&hdr); | 2216 | encode_nops(&hdr); |
2253 | return 0; | ||
2254 | } | 2217 | } |
2255 | 2218 | ||
2256 | /* | 2219 | /* |
2257 | * Encode an SETATTR request | 2220 | * Encode an SETATTR request |
2258 | */ | 2221 | */ |
2259 | static int nfs4_xdr_enc_setattr(struct rpc_rqst *req, __be32 *p, struct nfs_setattrargs *args) | 2222 | static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr, |
2223 | struct nfs_setattrargs *args) | ||
2260 | { | 2224 | { |
2261 | struct xdr_stream xdr; | ||
2262 | struct compound_hdr hdr = { | 2225 | struct compound_hdr hdr = { |
2263 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2226 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2264 | }; | 2227 | }; |
2265 | 2228 | ||
2266 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2229 | encode_compound_hdr(xdr, req, &hdr); |
2267 | encode_compound_hdr(&xdr, req, &hdr); | 2230 | encode_sequence(xdr, &args->seq_args, &hdr); |
2268 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2231 | encode_putfh(xdr, args->fh, &hdr); |
2269 | encode_putfh(&xdr, args->fh, &hdr); | 2232 | encode_setattr(xdr, args, args->server, &hdr); |
2270 | encode_setattr(&xdr, args, args->server, &hdr); | 2233 | encode_getfattr(xdr, args->bitmask, &hdr); |
2271 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
2272 | encode_nops(&hdr); | 2234 | encode_nops(&hdr); |
2273 | return 0; | ||
2274 | } | 2235 | } |
2275 | 2236 | ||
2276 | /* | 2237 | /* |
2277 | * Encode a GETACL request | 2238 | * Encode a GETACL request |
2278 | */ | 2239 | */ |
2279 | static int | 2240 | static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr, |
2280 | nfs4_xdr_enc_getacl(struct rpc_rqst *req, __be32 *p, | 2241 | struct nfs_getaclargs *args) |
2281 | struct nfs_getaclargs *args) | ||
2282 | { | 2242 | { |
2283 | struct xdr_stream xdr; | ||
2284 | struct compound_hdr hdr = { | 2243 | struct compound_hdr hdr = { |
2285 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2244 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2286 | }; | 2245 | }; |
2287 | uint32_t replen; | 2246 | uint32_t replen; |
2288 | 2247 | ||
2289 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2248 | encode_compound_hdr(xdr, req, &hdr); |
2290 | encode_compound_hdr(&xdr, req, &hdr); | 2249 | encode_sequence(xdr, &args->seq_args, &hdr); |
2291 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2250 | encode_putfh(xdr, args->fh, &hdr); |
2292 | encode_putfh(&xdr, args->fh, &hdr); | ||
2293 | replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1; | 2251 | replen = hdr.replen + op_decode_hdr_maxsz + nfs4_fattr_bitmap_maxsz + 1; |
2294 | encode_getattr_two(&xdr, FATTR4_WORD0_ACL, 0, &hdr); | 2252 | encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr); |
2295 | 2253 | ||
2296 | xdr_inline_pages(&req->rq_rcv_buf, replen << 2, | 2254 | xdr_inline_pages(&req->rq_rcv_buf, replen << 2, |
2297 | args->acl_pages, args->acl_pgbase, args->acl_len); | 2255 | args->acl_pages, args->acl_pgbase, args->acl_len); |
2298 | encode_nops(&hdr); | 2256 | encode_nops(&hdr); |
2299 | return 0; | ||
2300 | } | 2257 | } |
2301 | 2258 | ||
2302 | /* | 2259 | /* |
2303 | * Encode a WRITE request | 2260 | * Encode a WRITE request |
2304 | */ | 2261 | */ |
2305 | static int nfs4_xdr_enc_write(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) | 2262 | static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr, |
2263 | struct nfs_writeargs *args) | ||
2306 | { | 2264 | { |
2307 | struct xdr_stream xdr; | ||
2308 | struct compound_hdr hdr = { | 2265 | struct compound_hdr hdr = { |
2309 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2266 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2310 | }; | 2267 | }; |
2311 | 2268 | ||
2312 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2269 | encode_compound_hdr(xdr, req, &hdr); |
2313 | encode_compound_hdr(&xdr, req, &hdr); | 2270 | encode_sequence(xdr, &args->seq_args, &hdr); |
2314 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2271 | encode_putfh(xdr, args->fh, &hdr); |
2315 | encode_putfh(&xdr, args->fh, &hdr); | 2272 | encode_write(xdr, args, &hdr); |
2316 | encode_write(&xdr, args, &hdr); | ||
2317 | req->rq_snd_buf.flags |= XDRBUF_WRITE; | 2273 | req->rq_snd_buf.flags |= XDRBUF_WRITE; |
2318 | encode_getfattr(&xdr, args->bitmask, &hdr); | 2274 | encode_getfattr(xdr, args->bitmask, &hdr); |
2319 | encode_nops(&hdr); | 2275 | encode_nops(&hdr); |
2320 | return 0; | ||
2321 | } | 2276 | } |
2322 | 2277 | ||
2323 | /* | 2278 | /* |
2324 | * a COMMIT request | 2279 | * a COMMIT request |
2325 | */ | 2280 | */ |
2326 | static int nfs4_xdr_enc_commit(struct rpc_rqst *req, __be32 *p, struct nfs_writeargs *args) | 2281 | static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr, |
2282 | struct nfs_writeargs *args) | ||
2327 | { | 2283 | { |
2328 | struct xdr_stream xdr; | ||
2329 | struct compound_hdr hdr = { | 2284 | struct compound_hdr hdr = { |
2330 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2285 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2331 | }; | 2286 | }; |
2332 | 2287 | ||
2333 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2288 | encode_compound_hdr(xdr, req, &hdr); |
2334 | encode_compound_hdr(&xdr, req, &hdr); | 2289 | encode_sequence(xdr, &args->seq_args, &hdr); |
2335 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2290 | encode_putfh(xdr, args->fh, &hdr); |
2336 | encode_putfh(&xdr, args->fh, &hdr); | 2291 | encode_commit(xdr, args, &hdr); |
2337 | encode_commit(&xdr, args, &hdr); | 2292 | encode_getfattr(xdr, args->bitmask, &hdr); |
2338 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
2339 | encode_nops(&hdr); | 2293 | encode_nops(&hdr); |
2340 | return 0; | ||
2341 | } | 2294 | } |
2342 | 2295 | ||
2343 | /* | 2296 | /* |
2344 | * FSINFO request | 2297 | * FSINFO request |
2345 | */ | 2298 | */ |
2346 | static int nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs4_fsinfo_arg *args) | 2299 | static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, |
2300 | struct nfs4_fsinfo_arg *args) | ||
2347 | { | 2301 | { |
2348 | struct xdr_stream xdr; | ||
2349 | struct compound_hdr hdr = { | 2302 | struct compound_hdr hdr = { |
2350 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2303 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2351 | }; | 2304 | }; |
2352 | 2305 | ||
2353 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2306 | encode_compound_hdr(xdr, req, &hdr); |
2354 | encode_compound_hdr(&xdr, req, &hdr); | 2307 | encode_sequence(xdr, &args->seq_args, &hdr); |
2355 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2308 | encode_putfh(xdr, args->fh, &hdr); |
2356 | encode_putfh(&xdr, args->fh, &hdr); | 2309 | encode_fsinfo(xdr, args->bitmask, &hdr); |
2357 | encode_fsinfo(&xdr, args->bitmask, &hdr); | ||
2358 | encode_nops(&hdr); | 2310 | encode_nops(&hdr); |
2359 | return 0; | ||
2360 | } | 2311 | } |
2361 | 2312 | ||
2362 | /* | 2313 | /* |
2363 | * a PATHCONF request | 2314 | * a PATHCONF request |
2364 | */ | 2315 | */ |
2365 | static int nfs4_xdr_enc_pathconf(struct rpc_rqst *req, __be32 *p, const struct nfs4_pathconf_arg *args) | 2316 | static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, |
2317 | const struct nfs4_pathconf_arg *args) | ||
2366 | { | 2318 | { |
2367 | struct xdr_stream xdr; | ||
2368 | struct compound_hdr hdr = { | 2319 | struct compound_hdr hdr = { |
2369 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2320 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2370 | }; | 2321 | }; |
2371 | 2322 | ||
2372 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2323 | encode_compound_hdr(xdr, req, &hdr); |
2373 | encode_compound_hdr(&xdr, req, &hdr); | 2324 | encode_sequence(xdr, &args->seq_args, &hdr); |
2374 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2325 | encode_putfh(xdr, args->fh, &hdr); |
2375 | encode_putfh(&xdr, args->fh, &hdr); | 2326 | encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], |
2376 | encode_getattr_one(&xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0], | ||
2377 | &hdr); | 2327 | &hdr); |
2378 | encode_nops(&hdr); | 2328 | encode_nops(&hdr); |
2379 | return 0; | ||
2380 | } | 2329 | } |
2381 | 2330 | ||
2382 | /* | 2331 | /* |
2383 | * a STATFS request | 2332 | * a STATFS request |
2384 | */ | 2333 | */ |
2385 | static int nfs4_xdr_enc_statfs(struct rpc_rqst *req, __be32 *p, const struct nfs4_statfs_arg *args) | 2334 | static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, |
2335 | const struct nfs4_statfs_arg *args) | ||
2386 | { | 2336 | { |
2387 | struct xdr_stream xdr; | ||
2388 | struct compound_hdr hdr = { | 2337 | struct compound_hdr hdr = { |
2389 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2338 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2390 | }; | 2339 | }; |
2391 | 2340 | ||
2392 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2341 | encode_compound_hdr(xdr, req, &hdr); |
2393 | encode_compound_hdr(&xdr, req, &hdr); | 2342 | encode_sequence(xdr, &args->seq_args, &hdr); |
2394 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2343 | encode_putfh(xdr, args->fh, &hdr); |
2395 | encode_putfh(&xdr, args->fh, &hdr); | 2344 | encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], |
2396 | encode_getattr_two(&xdr, args->bitmask[0] & nfs4_statfs_bitmap[0], | ||
2397 | args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); | 2345 | args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr); |
2398 | encode_nops(&hdr); | 2346 | encode_nops(&hdr); |
2399 | return 0; | ||
2400 | } | 2347 | } |
2401 | 2348 | ||
2402 | /* | 2349 | /* |
2403 | * GETATTR_BITMAP request | 2350 | * GETATTR_BITMAP request |
2404 | */ | 2351 | */ |
2405 | static int nfs4_xdr_enc_server_caps(struct rpc_rqst *req, __be32 *p, | 2352 | static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req, |
2406 | struct nfs4_server_caps_arg *args) | 2353 | struct xdr_stream *xdr, |
2354 | struct nfs4_server_caps_arg *args) | ||
2407 | { | 2355 | { |
2408 | struct xdr_stream xdr; | ||
2409 | struct compound_hdr hdr = { | 2356 | struct compound_hdr hdr = { |
2410 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2357 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2411 | }; | 2358 | }; |
2412 | 2359 | ||
2413 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2360 | encode_compound_hdr(xdr, req, &hdr); |
2414 | encode_compound_hdr(&xdr, req, &hdr); | 2361 | encode_sequence(xdr, &args->seq_args, &hdr); |
2415 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2362 | encode_putfh(xdr, args->fhandle, &hdr); |
2416 | encode_putfh(&xdr, args->fhandle, &hdr); | 2363 | encode_getattr_one(xdr, FATTR4_WORD0_SUPPORTED_ATTRS| |
2417 | encode_getattr_one(&xdr, FATTR4_WORD0_SUPPORTED_ATTRS| | ||
2418 | FATTR4_WORD0_LINK_SUPPORT| | 2364 | FATTR4_WORD0_LINK_SUPPORT| |
2419 | FATTR4_WORD0_SYMLINK_SUPPORT| | 2365 | FATTR4_WORD0_SYMLINK_SUPPORT| |
2420 | FATTR4_WORD0_ACLSUPPORT, &hdr); | 2366 | FATTR4_WORD0_ACLSUPPORT, &hdr); |
2421 | encode_nops(&hdr); | 2367 | encode_nops(&hdr); |
2422 | return 0; | ||
2423 | } | 2368 | } |
2424 | 2369 | ||
2425 | /* | 2370 | /* |
2426 | * a RENEW request | 2371 | * a RENEW request |
2427 | */ | 2372 | */ |
2428 | static int nfs4_xdr_enc_renew(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp) | 2373 | static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr, |
2374 | struct nfs_client *clp) | ||
2429 | { | 2375 | { |
2430 | struct xdr_stream xdr; | ||
2431 | struct compound_hdr hdr = { | 2376 | struct compound_hdr hdr = { |
2432 | .nops = 0, | 2377 | .nops = 0, |
2433 | }; | 2378 | }; |
2434 | 2379 | ||
2435 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2380 | encode_compound_hdr(xdr, req, &hdr); |
2436 | encode_compound_hdr(&xdr, req, &hdr); | 2381 | encode_renew(xdr, clp, &hdr); |
2437 | encode_renew(&xdr, clp, &hdr); | ||
2438 | encode_nops(&hdr); | 2382 | encode_nops(&hdr); |
2439 | return 0; | ||
2440 | } | 2383 | } |
2441 | 2384 | ||
2442 | /* | 2385 | /* |
2443 | * a SETCLIENTID request | 2386 | * a SETCLIENTID request |
2444 | */ | 2387 | */ |
2445 | static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid *sc) | 2388 | static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req, |
2389 | struct xdr_stream *xdr, | ||
2390 | struct nfs4_setclientid *sc) | ||
2446 | { | 2391 | { |
2447 | struct xdr_stream xdr; | ||
2448 | struct compound_hdr hdr = { | 2392 | struct compound_hdr hdr = { |
2449 | .nops = 0, | 2393 | .nops = 0, |
2450 | }; | 2394 | }; |
2451 | 2395 | ||
2452 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2396 | encode_compound_hdr(xdr, req, &hdr); |
2453 | encode_compound_hdr(&xdr, req, &hdr); | 2397 | encode_setclientid(xdr, sc, &hdr); |
2454 | encode_setclientid(&xdr, sc, &hdr); | ||
2455 | encode_nops(&hdr); | 2398 | encode_nops(&hdr); |
2456 | return 0; | ||
2457 | } | 2399 | } |
2458 | 2400 | ||
2459 | /* | 2401 | /* |
2460 | * a SETCLIENTID_CONFIRM request | 2402 | * a SETCLIENTID_CONFIRM request |
2461 | */ | 2403 | */ |
2462 | static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid_res *arg) | 2404 | static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, |
2405 | struct xdr_stream *xdr, | ||
2406 | struct nfs4_setclientid_res *arg) | ||
2463 | { | 2407 | { |
2464 | struct xdr_stream xdr; | ||
2465 | struct compound_hdr hdr = { | 2408 | struct compound_hdr hdr = { |
2466 | .nops = 0, | 2409 | .nops = 0, |
2467 | }; | 2410 | }; |
2468 | const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; | 2411 | const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; |
2469 | 2412 | ||
2470 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2413 | encode_compound_hdr(xdr, req, &hdr); |
2471 | encode_compound_hdr(&xdr, req, &hdr); | 2414 | encode_setclientid_confirm(xdr, arg, &hdr); |
2472 | encode_setclientid_confirm(&xdr, arg, &hdr); | 2415 | encode_putrootfh(xdr, &hdr); |
2473 | encode_putrootfh(&xdr, &hdr); | 2416 | encode_fsinfo(xdr, lease_bitmap, &hdr); |
2474 | encode_fsinfo(&xdr, lease_bitmap, &hdr); | ||
2475 | encode_nops(&hdr); | 2417 | encode_nops(&hdr); |
2476 | return 0; | ||
2477 | } | 2418 | } |
2478 | 2419 | ||
2479 | /* | 2420 | /* |
2480 | * DELEGRETURN request | 2421 | * DELEGRETURN request |
2481 | */ | 2422 | */ |
2482 | static int nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, __be32 *p, const struct nfs4_delegreturnargs *args) | 2423 | static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req, |
2424 | struct xdr_stream *xdr, | ||
2425 | const struct nfs4_delegreturnargs *args) | ||
2483 | { | 2426 | { |
2484 | struct xdr_stream xdr; | ||
2485 | struct compound_hdr hdr = { | 2427 | struct compound_hdr hdr = { |
2486 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2428 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2487 | }; | 2429 | }; |
2488 | 2430 | ||
2489 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2431 | encode_compound_hdr(xdr, req, &hdr); |
2490 | encode_compound_hdr(&xdr, req, &hdr); | 2432 | encode_sequence(xdr, &args->seq_args, &hdr); |
2491 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2433 | encode_putfh(xdr, args->fhandle, &hdr); |
2492 | encode_putfh(&xdr, args->fhandle, &hdr); | 2434 | encode_delegreturn(xdr, args->stateid, &hdr); |
2493 | encode_delegreturn(&xdr, args->stateid, &hdr); | 2435 | encode_getfattr(xdr, args->bitmask, &hdr); |
2494 | encode_getfattr(&xdr, args->bitmask, &hdr); | ||
2495 | encode_nops(&hdr); | 2436 | encode_nops(&hdr); |
2496 | return 0; | ||
2497 | } | 2437 | } |
2498 | 2438 | ||
2499 | /* | 2439 | /* |
2500 | * Encode FS_LOCATIONS request | 2440 | * Encode FS_LOCATIONS request |
2501 | */ | 2441 | */ |
2502 | static int nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, __be32 *p, struct nfs4_fs_locations_arg *args) | 2442 | static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req, |
2443 | struct xdr_stream *xdr, | ||
2444 | struct nfs4_fs_locations_arg *args) | ||
2503 | { | 2445 | { |
2504 | struct xdr_stream xdr; | ||
2505 | struct compound_hdr hdr = { | 2446 | struct compound_hdr hdr = { |
2506 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2447 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2507 | }; | 2448 | }; |
2508 | uint32_t replen; | 2449 | uint32_t replen; |
2509 | 2450 | ||
2510 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2451 | encode_compound_hdr(xdr, req, &hdr); |
2511 | encode_compound_hdr(&xdr, req, &hdr); | 2452 | encode_sequence(xdr, &args->seq_args, &hdr); |
2512 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2453 | encode_putfh(xdr, args->dir_fh, &hdr); |
2513 | encode_putfh(&xdr, args->dir_fh, &hdr); | 2454 | encode_lookup(xdr, args->name, &hdr); |
2514 | encode_lookup(&xdr, args->name, &hdr); | ||
2515 | replen = hdr.replen; /* get the attribute into args->page */ | 2455 | replen = hdr.replen; /* get the attribute into args->page */ |
2516 | encode_fs_locations(&xdr, args->bitmask, &hdr); | 2456 | encode_fs_locations(xdr, args->bitmask, &hdr); |
2517 | 2457 | ||
2518 | xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, | 2458 | xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page, |
2519 | 0, PAGE_SIZE); | 2459 | 0, PAGE_SIZE); |
2520 | encode_nops(&hdr); | 2460 | encode_nops(&hdr); |
2521 | return 0; | ||
2522 | } | 2461 | } |
2523 | 2462 | ||
2524 | #if defined(CONFIG_NFS_V4_1) | 2463 | #if defined(CONFIG_NFS_V4_1) |
2525 | /* | 2464 | /* |
2526 | * EXCHANGE_ID request | 2465 | * EXCHANGE_ID request |
2527 | */ | 2466 | */ |
2528 | static int nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, uint32_t *p, | 2467 | static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req, |
2529 | struct nfs41_exchange_id_args *args) | 2468 | struct xdr_stream *xdr, |
2469 | struct nfs41_exchange_id_args *args) | ||
2530 | { | 2470 | { |
2531 | struct xdr_stream xdr; | ||
2532 | struct compound_hdr hdr = { | 2471 | struct compound_hdr hdr = { |
2533 | .minorversion = args->client->cl_mvops->minor_version, | 2472 | .minorversion = args->client->cl_mvops->minor_version, |
2534 | }; | 2473 | }; |
2535 | 2474 | ||
2536 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2475 | encode_compound_hdr(xdr, req, &hdr); |
2537 | encode_compound_hdr(&xdr, req, &hdr); | 2476 | encode_exchange_id(xdr, args, &hdr); |
2538 | encode_exchange_id(&xdr, args, &hdr); | ||
2539 | encode_nops(&hdr); | 2477 | encode_nops(&hdr); |
2540 | return 0; | ||
2541 | } | 2478 | } |
2542 | 2479 | ||
2543 | /* | 2480 | /* |
2544 | * a CREATE_SESSION request | 2481 | * a CREATE_SESSION request |
2545 | */ | 2482 | */ |
2546 | static int nfs4_xdr_enc_create_session(struct rpc_rqst *req, uint32_t *p, | 2483 | static void nfs4_xdr_enc_create_session(struct rpc_rqst *req, |
2547 | struct nfs41_create_session_args *args) | 2484 | struct xdr_stream *xdr, |
2485 | struct nfs41_create_session_args *args) | ||
2548 | { | 2486 | { |
2549 | struct xdr_stream xdr; | ||
2550 | struct compound_hdr hdr = { | 2487 | struct compound_hdr hdr = { |
2551 | .minorversion = args->client->cl_mvops->minor_version, | 2488 | .minorversion = args->client->cl_mvops->minor_version, |
2552 | }; | 2489 | }; |
2553 | 2490 | ||
2554 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2491 | encode_compound_hdr(xdr, req, &hdr); |
2555 | encode_compound_hdr(&xdr, req, &hdr); | 2492 | encode_create_session(xdr, args, &hdr); |
2556 | encode_create_session(&xdr, args, &hdr); | ||
2557 | encode_nops(&hdr); | 2493 | encode_nops(&hdr); |
2558 | return 0; | ||
2559 | } | 2494 | } |
2560 | 2495 | ||
2561 | /* | 2496 | /* |
2562 | * a DESTROY_SESSION request | 2497 | * a DESTROY_SESSION request |
2563 | */ | 2498 | */ |
2564 | static int nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, uint32_t *p, | 2499 | static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req, |
2565 | struct nfs4_session *session) | 2500 | struct xdr_stream *xdr, |
2501 | struct nfs4_session *session) | ||
2566 | { | 2502 | { |
2567 | struct xdr_stream xdr; | ||
2568 | struct compound_hdr hdr = { | 2503 | struct compound_hdr hdr = { |
2569 | .minorversion = session->clp->cl_mvops->minor_version, | 2504 | .minorversion = session->clp->cl_mvops->minor_version, |
2570 | }; | 2505 | }; |
2571 | 2506 | ||
2572 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2507 | encode_compound_hdr(xdr, req, &hdr); |
2573 | encode_compound_hdr(&xdr, req, &hdr); | 2508 | encode_destroy_session(xdr, session, &hdr); |
2574 | encode_destroy_session(&xdr, session, &hdr); | ||
2575 | encode_nops(&hdr); | 2509 | encode_nops(&hdr); |
2576 | return 0; | ||
2577 | } | 2510 | } |
2578 | 2511 | ||
2579 | /* | 2512 | /* |
2580 | * a SEQUENCE request | 2513 | * a SEQUENCE request |
2581 | */ | 2514 | */ |
2582 | static int nfs4_xdr_enc_sequence(struct rpc_rqst *req, uint32_t *p, | 2515 | static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr, |
2583 | struct nfs4_sequence_args *args) | 2516 | struct nfs4_sequence_args *args) |
2584 | { | 2517 | { |
2585 | struct xdr_stream xdr; | ||
2586 | struct compound_hdr hdr = { | 2518 | struct compound_hdr hdr = { |
2587 | .minorversion = nfs4_xdr_minorversion(args), | 2519 | .minorversion = nfs4_xdr_minorversion(args), |
2588 | }; | 2520 | }; |
2589 | 2521 | ||
2590 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2522 | encode_compound_hdr(xdr, req, &hdr); |
2591 | encode_compound_hdr(&xdr, req, &hdr); | 2523 | encode_sequence(xdr, args, &hdr); |
2592 | encode_sequence(&xdr, args, &hdr); | ||
2593 | encode_nops(&hdr); | 2524 | encode_nops(&hdr); |
2594 | return 0; | ||
2595 | } | 2525 | } |
2596 | 2526 | ||
2597 | /* | 2527 | /* |
2598 | * a GET_LEASE_TIME request | 2528 | * a GET_LEASE_TIME request |
2599 | */ | 2529 | */ |
2600 | static int nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, uint32_t *p, | 2530 | static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req, |
2601 | struct nfs4_get_lease_time_args *args) | 2531 | struct xdr_stream *xdr, |
2532 | struct nfs4_get_lease_time_args *args) | ||
2602 | { | 2533 | { |
2603 | struct xdr_stream xdr; | ||
2604 | struct compound_hdr hdr = { | 2534 | struct compound_hdr hdr = { |
2605 | .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), | 2535 | .minorversion = nfs4_xdr_minorversion(&args->la_seq_args), |
2606 | }; | 2536 | }; |
2607 | const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; | 2537 | const u32 lease_bitmap[2] = { FATTR4_WORD0_LEASE_TIME, 0 }; |
2608 | 2538 | ||
2609 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2539 | encode_compound_hdr(xdr, req, &hdr); |
2610 | encode_compound_hdr(&xdr, req, &hdr); | 2540 | encode_sequence(xdr, &args->la_seq_args, &hdr); |
2611 | encode_sequence(&xdr, &args->la_seq_args, &hdr); | 2541 | encode_putrootfh(xdr, &hdr); |
2612 | encode_putrootfh(&xdr, &hdr); | 2542 | encode_fsinfo(xdr, lease_bitmap, &hdr); |
2613 | encode_fsinfo(&xdr, lease_bitmap, &hdr); | ||
2614 | encode_nops(&hdr); | 2543 | encode_nops(&hdr); |
2615 | return 0; | ||
2616 | } | 2544 | } |
2617 | 2545 | ||
2618 | /* | 2546 | /* |
2619 | * a RECLAIM_COMPLETE request | 2547 | * a RECLAIM_COMPLETE request |
2620 | */ | 2548 | */ |
2621 | static int nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, uint32_t *p, | 2549 | static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req, |
2622 | struct nfs41_reclaim_complete_args *args) | 2550 | struct xdr_stream *xdr, |
2551 | struct nfs41_reclaim_complete_args *args) | ||
2623 | { | 2552 | { |
2624 | struct xdr_stream xdr; | ||
2625 | struct compound_hdr hdr = { | 2553 | struct compound_hdr hdr = { |
2626 | .minorversion = nfs4_xdr_minorversion(&args->seq_args) | 2554 | .minorversion = nfs4_xdr_minorversion(&args->seq_args) |
2627 | }; | 2555 | }; |
2628 | 2556 | ||
2629 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2557 | encode_compound_hdr(xdr, req, &hdr); |
2630 | encode_compound_hdr(&xdr, req, &hdr); | 2558 | encode_sequence(xdr, &args->seq_args, &hdr); |
2631 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2559 | encode_reclaim_complete(xdr, args, &hdr); |
2632 | encode_reclaim_complete(&xdr, args, &hdr); | ||
2633 | encode_nops(&hdr); | 2560 | encode_nops(&hdr); |
2634 | return 0; | ||
2635 | } | 2561 | } |
2636 | 2562 | ||
2637 | /* | 2563 | /* |
2638 | * Encode GETDEVICEINFO request | 2564 | * Encode GETDEVICEINFO request |
2639 | */ | 2565 | */ |
2640 | static int nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, uint32_t *p, | 2566 | static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, |
2641 | struct nfs4_getdeviceinfo_args *args) | 2567 | struct xdr_stream *xdr, |
2568 | struct nfs4_getdeviceinfo_args *args) | ||
2642 | { | 2569 | { |
2643 | struct xdr_stream xdr; | ||
2644 | struct compound_hdr hdr = { | 2570 | struct compound_hdr hdr = { |
2645 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2571 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2646 | }; | 2572 | }; |
2647 | 2573 | ||
2648 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2574 | encode_compound_hdr(xdr, req, &hdr); |
2649 | encode_compound_hdr(&xdr, req, &hdr); | 2575 | encode_sequence(xdr, &args->seq_args, &hdr); |
2650 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2576 | encode_getdeviceinfo(xdr, args, &hdr); |
2651 | encode_getdeviceinfo(&xdr, args, &hdr); | ||
2652 | 2577 | ||
2653 | /* set up reply kvec. Subtract notification bitmap max size (2) | 2578 | /* set up reply kvec. Subtract notification bitmap max size (2) |
2654 | * so that notification bitmap is put in xdr_buf tail */ | 2579 | * so that notification bitmap is put in xdr_buf tail */ |
@@ -2657,27 +2582,24 @@ static int nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req, uint32_t *p, | |||
2657 | args->pdev->pglen); | 2582 | args->pdev->pglen); |
2658 | 2583 | ||
2659 | encode_nops(&hdr); | 2584 | encode_nops(&hdr); |
2660 | return 0; | ||
2661 | } | 2585 | } |
2662 | 2586 | ||
2663 | /* | 2587 | /* |
2664 | * Encode LAYOUTGET request | 2588 | * Encode LAYOUTGET request |
2665 | */ | 2589 | */ |
2666 | static int nfs4_xdr_enc_layoutget(struct rpc_rqst *req, uint32_t *p, | 2590 | static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req, |
2667 | struct nfs4_layoutget_args *args) | 2591 | struct xdr_stream *xdr, |
2592 | struct nfs4_layoutget_args *args) | ||
2668 | { | 2593 | { |
2669 | struct xdr_stream xdr; | ||
2670 | struct compound_hdr hdr = { | 2594 | struct compound_hdr hdr = { |
2671 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 2595 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
2672 | }; | 2596 | }; |
2673 | 2597 | ||
2674 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 2598 | encode_compound_hdr(xdr, req, &hdr); |
2675 | encode_compound_hdr(&xdr, req, &hdr); | 2599 | encode_sequence(xdr, &args->seq_args, &hdr); |
2676 | encode_sequence(&xdr, &args->seq_args, &hdr); | 2600 | encode_putfh(xdr, NFS_FH(args->inode), &hdr); |
2677 | encode_putfh(&xdr, NFS_FH(args->inode), &hdr); | 2601 | encode_layoutget(xdr, args, &hdr); |
2678 | encode_layoutget(&xdr, args, &hdr); | ||
2679 | encode_nops(&hdr); | 2602 | encode_nops(&hdr); |
2680 | return 0; | ||
2681 | } | 2603 | } |
2682 | #endif /* CONFIG_NFS_V4_1 */ | 2604 | #endif /* CONFIG_NFS_V4_1 */ |
2683 | 2605 | ||
@@ -4475,7 +4397,7 @@ static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs_ | |||
4475 | goto out_overflow; | 4397 | goto out_overflow; |
4476 | eof = be32_to_cpup(p++); | 4398 | eof = be32_to_cpup(p++); |
4477 | count = be32_to_cpup(p); | 4399 | count = be32_to_cpup(p); |
4478 | hdrlen = (u8 *) p - (u8 *) iov->iov_base; | 4400 | hdrlen = (u8 *) xdr->p - (u8 *) iov->iov_base; |
4479 | recvd = req->rq_rcv_buf.len - hdrlen; | 4401 | recvd = req->rq_rcv_buf.len - hdrlen; |
4480 | if (count > recvd) { | 4402 | if (count > recvd) { |
4481 | dprintk("NFS: server cheating in read reply: " | 4403 | dprintk("NFS: server cheating in read reply: " |
@@ -5000,7 +4922,7 @@ static int decode_getdeviceinfo(struct xdr_stream *xdr, | |||
5000 | goto out_overflow; | 4922 | goto out_overflow; |
5001 | len = be32_to_cpup(p); | 4923 | len = be32_to_cpup(p); |
5002 | if (len) { | 4924 | if (len) { |
5003 | int i; | 4925 | uint32_t i; |
5004 | 4926 | ||
5005 | p = xdr_inline_decode(xdr, 4 * len); | 4927 | p = xdr_inline_decode(xdr, 4 * len); |
5006 | if (unlikely(!p)) | 4928 | if (unlikely(!p)) |
@@ -5090,26 +5012,26 @@ out_overflow: | |||
5090 | /* | 5012 | /* |
5091 | * Decode OPEN_DOWNGRADE response | 5013 | * Decode OPEN_DOWNGRADE response |
5092 | */ | 5014 | */ |
5093 | static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res) | 5015 | static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp, |
5016 | struct xdr_stream *xdr, | ||
5017 | struct nfs_closeres *res) | ||
5094 | { | 5018 | { |
5095 | struct xdr_stream xdr; | ||
5096 | struct compound_hdr hdr; | 5019 | struct compound_hdr hdr; |
5097 | int status; | 5020 | int status; |
5098 | 5021 | ||
5099 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5022 | status = decode_compound_hdr(xdr, &hdr); |
5100 | status = decode_compound_hdr(&xdr, &hdr); | ||
5101 | if (status) | 5023 | if (status) |
5102 | goto out; | 5024 | goto out; |
5103 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5025 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5104 | if (status) | 5026 | if (status) |
5105 | goto out; | 5027 | goto out; |
5106 | status = decode_putfh(&xdr); | 5028 | status = decode_putfh(xdr); |
5107 | if (status) | 5029 | if (status) |
5108 | goto out; | 5030 | goto out; |
5109 | status = decode_open_downgrade(&xdr, res); | 5031 | status = decode_open_downgrade(xdr, res); |
5110 | if (status != 0) | 5032 | if (status != 0) |
5111 | goto out; | 5033 | goto out; |
5112 | decode_getfattr(&xdr, res->fattr, res->server, | 5034 | decode_getfattr(xdr, res->fattr, res->server, |
5113 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5035 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5114 | out: | 5036 | out: |
5115 | return status; | 5037 | return status; |
@@ -5118,26 +5040,25 @@ out: | |||
5118 | /* | 5040 | /* |
5119 | * Decode ACCESS response | 5041 | * Decode ACCESS response |
5120 | */ | 5042 | */ |
5121 | static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_accessres *res) | 5043 | static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5044 | struct nfs4_accessres *res) | ||
5122 | { | 5045 | { |
5123 | struct xdr_stream xdr; | ||
5124 | struct compound_hdr hdr; | 5046 | struct compound_hdr hdr; |
5125 | int status; | 5047 | int status; |
5126 | 5048 | ||
5127 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5049 | status = decode_compound_hdr(xdr, &hdr); |
5128 | status = decode_compound_hdr(&xdr, &hdr); | ||
5129 | if (status) | 5050 | if (status) |
5130 | goto out; | 5051 | goto out; |
5131 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5052 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5132 | if (status) | 5053 | if (status) |
5133 | goto out; | 5054 | goto out; |
5134 | status = decode_putfh(&xdr); | 5055 | status = decode_putfh(xdr); |
5135 | if (status != 0) | 5056 | if (status != 0) |
5136 | goto out; | 5057 | goto out; |
5137 | status = decode_access(&xdr, res); | 5058 | status = decode_access(xdr, res); |
5138 | if (status != 0) | 5059 | if (status != 0) |
5139 | goto out; | 5060 | goto out; |
5140 | decode_getfattr(&xdr, res->fattr, res->server, | 5061 | decode_getfattr(xdr, res->fattr, res->server, |
5141 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5062 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5142 | out: | 5063 | out: |
5143 | return status; | 5064 | return status; |
@@ -5146,26 +5067,28 @@ out: | |||
5146 | /* | 5067 | /* |
5147 | * Decode LOOKUP response | 5068 | * Decode LOOKUP response |
5148 | */ | 5069 | */ |
5149 | static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res) | 5070 | static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5071 | struct nfs4_lookup_res *res) | ||
5150 | { | 5072 | { |
5151 | struct xdr_stream xdr; | ||
5152 | struct compound_hdr hdr; | 5073 | struct compound_hdr hdr; |
5153 | int status; | 5074 | int status; |
5154 | 5075 | ||
5155 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5076 | status = decode_compound_hdr(xdr, &hdr); |
5156 | status = decode_compound_hdr(&xdr, &hdr); | ||
5157 | if (status) | 5077 | if (status) |
5158 | goto out; | 5078 | goto out; |
5159 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5079 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5160 | if (status) | 5080 | if (status) |
5161 | goto out; | 5081 | goto out; |
5162 | if ((status = decode_putfh(&xdr)) != 0) | 5082 | status = decode_putfh(xdr); |
5083 | if (status) | ||
5163 | goto out; | 5084 | goto out; |
5164 | if ((status = decode_lookup(&xdr)) != 0) | 5085 | status = decode_lookup(xdr); |
5086 | if (status) | ||
5165 | goto out; | 5087 | goto out; |
5166 | if ((status = decode_getfh(&xdr, res->fh)) != 0) | 5088 | status = decode_getfh(xdr, res->fh); |
5089 | if (status) | ||
5167 | goto out; | 5090 | goto out; |
5168 | status = decode_getfattr(&xdr, res->fattr, res->server | 5091 | status = decode_getfattr(xdr, res->fattr, res->server |
5169 | ,!RPC_IS_ASYNC(rqstp->rq_task)); | 5092 | ,!RPC_IS_ASYNC(rqstp->rq_task)); |
5170 | out: | 5093 | out: |
5171 | return status; | 5094 | return status; |
@@ -5174,23 +5097,25 @@ out: | |||
5174 | /* | 5097 | /* |
5175 | * Decode LOOKUP_ROOT response | 5098 | * Decode LOOKUP_ROOT response |
5176 | */ | 5099 | */ |
5177 | static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_lookup_res *res) | 5100 | static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp, |
5101 | struct xdr_stream *xdr, | ||
5102 | struct nfs4_lookup_res *res) | ||
5178 | { | 5103 | { |
5179 | struct xdr_stream xdr; | ||
5180 | struct compound_hdr hdr; | 5104 | struct compound_hdr hdr; |
5181 | int status; | 5105 | int status; |
5182 | 5106 | ||
5183 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5107 | status = decode_compound_hdr(xdr, &hdr); |
5184 | status = decode_compound_hdr(&xdr, &hdr); | ||
5185 | if (status) | 5108 | if (status) |
5186 | goto out; | 5109 | goto out; |
5187 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5110 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5188 | if (status) | 5111 | if (status) |
5189 | goto out; | 5112 | goto out; |
5190 | if ((status = decode_putrootfh(&xdr)) != 0) | 5113 | status = decode_putrootfh(xdr); |
5114 | if (status) | ||
5191 | goto out; | 5115 | goto out; |
5192 | if ((status = decode_getfh(&xdr, res->fh)) == 0) | 5116 | status = decode_getfh(xdr, res->fh); |
5193 | status = decode_getfattr(&xdr, res->fattr, res->server, | 5117 | if (status == 0) |
5118 | status = decode_getfattr(xdr, res->fattr, res->server, | ||
5194 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5119 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5195 | out: | 5120 | out: |
5196 | return status; | 5121 | return status; |
@@ -5199,24 +5124,25 @@ out: | |||
5199 | /* | 5124 | /* |
5200 | * Decode REMOVE response | 5125 | * Decode REMOVE response |
5201 | */ | 5126 | */ |
5202 | static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_removeres *res) | 5127 | static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5128 | struct nfs_removeres *res) | ||
5203 | { | 5129 | { |
5204 | struct xdr_stream xdr; | ||
5205 | struct compound_hdr hdr; | 5130 | struct compound_hdr hdr; |
5206 | int status; | 5131 | int status; |
5207 | 5132 | ||
5208 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5133 | status = decode_compound_hdr(xdr, &hdr); |
5209 | status = decode_compound_hdr(&xdr, &hdr); | ||
5210 | if (status) | 5134 | if (status) |
5211 | goto out; | 5135 | goto out; |
5212 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5136 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5213 | if (status) | 5137 | if (status) |
5214 | goto out; | 5138 | goto out; |
5215 | if ((status = decode_putfh(&xdr)) != 0) | 5139 | status = decode_putfh(xdr); |
5140 | if (status) | ||
5216 | goto out; | 5141 | goto out; |
5217 | if ((status = decode_remove(&xdr, &res->cinfo)) != 0) | 5142 | status = decode_remove(xdr, &res->cinfo); |
5143 | if (status) | ||
5218 | goto out; | 5144 | goto out; |
5219 | decode_getfattr(&xdr, res->dir_attr, res->server, | 5145 | decode_getfattr(xdr, res->dir_attr, res->server, |
5220 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5146 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5221 | out: | 5147 | out: |
5222 | return status; | 5148 | return status; |
@@ -5225,34 +5151,38 @@ out: | |||
5225 | /* | 5151 | /* |
5226 | * Decode RENAME response | 5152 | * Decode RENAME response |
5227 | */ | 5153 | */ |
5228 | static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, __be32 *p, struct nfs_renameres *res) | 5154 | static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5155 | struct nfs_renameres *res) | ||
5229 | { | 5156 | { |
5230 | struct xdr_stream xdr; | ||
5231 | struct compound_hdr hdr; | 5157 | struct compound_hdr hdr; |
5232 | int status; | 5158 | int status; |
5233 | 5159 | ||
5234 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5160 | status = decode_compound_hdr(xdr, &hdr); |
5235 | status = decode_compound_hdr(&xdr, &hdr); | ||
5236 | if (status) | 5161 | if (status) |
5237 | goto out; | 5162 | goto out; |
5238 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5163 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5239 | if (status) | 5164 | if (status) |
5240 | goto out; | 5165 | goto out; |
5241 | if ((status = decode_putfh(&xdr)) != 0) | 5166 | status = decode_putfh(xdr); |
5167 | if (status) | ||
5242 | goto out; | 5168 | goto out; |
5243 | if ((status = decode_savefh(&xdr)) != 0) | 5169 | status = decode_savefh(xdr); |
5170 | if (status) | ||
5244 | goto out; | 5171 | goto out; |
5245 | if ((status = decode_putfh(&xdr)) != 0) | 5172 | status = decode_putfh(xdr); |
5173 | if (status) | ||
5246 | goto out; | 5174 | goto out; |
5247 | if ((status = decode_rename(&xdr, &res->old_cinfo, &res->new_cinfo)) != 0) | 5175 | status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo); |
5176 | if (status) | ||
5248 | goto out; | 5177 | goto out; |
5249 | /* Current FH is target directory */ | 5178 | /* Current FH is target directory */ |
5250 | if (decode_getfattr(&xdr, res->new_fattr, res->server, | 5179 | if (decode_getfattr(xdr, res->new_fattr, res->server, |
5251 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) | 5180 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) |
5252 | goto out; | 5181 | goto out; |
5253 | if ((status = decode_restorefh(&xdr)) != 0) | 5182 | status = decode_restorefh(xdr); |
5183 | if (status) | ||
5254 | goto out; | 5184 | goto out; |
5255 | decode_getfattr(&xdr, res->old_fattr, res->server, | 5185 | decode_getfattr(xdr, res->old_fattr, res->server, |
5256 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5186 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5257 | out: | 5187 | out: |
5258 | return status; | 5188 | return status; |
@@ -5261,37 +5191,41 @@ out: | |||
5261 | /* | 5191 | /* |
5262 | * Decode LINK response | 5192 | * Decode LINK response |
5263 | */ | 5193 | */ |
5264 | static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_link_res *res) | 5194 | static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5195 | struct nfs4_link_res *res) | ||
5265 | { | 5196 | { |
5266 | struct xdr_stream xdr; | ||
5267 | struct compound_hdr hdr; | 5197 | struct compound_hdr hdr; |
5268 | int status; | 5198 | int status; |
5269 | 5199 | ||
5270 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5200 | status = decode_compound_hdr(xdr, &hdr); |
5271 | status = decode_compound_hdr(&xdr, &hdr); | ||
5272 | if (status) | 5201 | if (status) |
5273 | goto out; | 5202 | goto out; |
5274 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5203 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5275 | if (status) | 5204 | if (status) |
5276 | goto out; | 5205 | goto out; |
5277 | if ((status = decode_putfh(&xdr)) != 0) | 5206 | status = decode_putfh(xdr); |
5207 | if (status) | ||
5278 | goto out; | 5208 | goto out; |
5279 | if ((status = decode_savefh(&xdr)) != 0) | 5209 | status = decode_savefh(xdr); |
5210 | if (status) | ||
5280 | goto out; | 5211 | goto out; |
5281 | if ((status = decode_putfh(&xdr)) != 0) | 5212 | status = decode_putfh(xdr); |
5213 | if (status) | ||
5282 | goto out; | 5214 | goto out; |
5283 | if ((status = decode_link(&xdr, &res->cinfo)) != 0) | 5215 | status = decode_link(xdr, &res->cinfo); |
5216 | if (status) | ||
5284 | goto out; | 5217 | goto out; |
5285 | /* | 5218 | /* |
5286 | * Note order: OP_LINK leaves the directory as the current | 5219 | * Note order: OP_LINK leaves the directory as the current |
5287 | * filehandle. | 5220 | * filehandle. |
5288 | */ | 5221 | */ |
5289 | if (decode_getfattr(&xdr, res->dir_attr, res->server, | 5222 | if (decode_getfattr(xdr, res->dir_attr, res->server, |
5290 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) | 5223 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) |
5291 | goto out; | 5224 | goto out; |
5292 | if ((status = decode_restorefh(&xdr)) != 0) | 5225 | status = decode_restorefh(xdr); |
5226 | if (status) | ||
5293 | goto out; | 5227 | goto out; |
5294 | decode_getfattr(&xdr, res->fattr, res->server, | 5228 | decode_getfattr(xdr, res->fattr, res->server, |
5295 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5229 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5296 | out: | 5230 | out: |
5297 | return status; | 5231 | return status; |
@@ -5300,33 +5234,37 @@ out: | |||
5300 | /* | 5234 | /* |
5301 | * Decode CREATE response | 5235 | * Decode CREATE response |
5302 | */ | 5236 | */ |
5303 | static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res) | 5237 | static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5238 | struct nfs4_create_res *res) | ||
5304 | { | 5239 | { |
5305 | struct xdr_stream xdr; | ||
5306 | struct compound_hdr hdr; | 5240 | struct compound_hdr hdr; |
5307 | int status; | 5241 | int status; |
5308 | 5242 | ||
5309 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5243 | status = decode_compound_hdr(xdr, &hdr); |
5310 | status = decode_compound_hdr(&xdr, &hdr); | ||
5311 | if (status) | 5244 | if (status) |
5312 | goto out; | 5245 | goto out; |
5313 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5246 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5314 | if (status) | 5247 | if (status) |
5315 | goto out; | 5248 | goto out; |
5316 | if ((status = decode_putfh(&xdr)) != 0) | 5249 | status = decode_putfh(xdr); |
5250 | if (status) | ||
5317 | goto out; | 5251 | goto out; |
5318 | if ((status = decode_savefh(&xdr)) != 0) | 5252 | status = decode_savefh(xdr); |
5253 | if (status) | ||
5319 | goto out; | 5254 | goto out; |
5320 | if ((status = decode_create(&xdr,&res->dir_cinfo)) != 0) | 5255 | status = decode_create(xdr, &res->dir_cinfo); |
5256 | if (status) | ||
5321 | goto out; | 5257 | goto out; |
5322 | if ((status = decode_getfh(&xdr, res->fh)) != 0) | 5258 | status = decode_getfh(xdr, res->fh); |
5259 | if (status) | ||
5323 | goto out; | 5260 | goto out; |
5324 | if (decode_getfattr(&xdr, res->fattr, res->server, | 5261 | if (decode_getfattr(xdr, res->fattr, res->server, |
5325 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) | 5262 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) |
5326 | goto out; | 5263 | goto out; |
5327 | if ((status = decode_restorefh(&xdr)) != 0) | 5264 | status = decode_restorefh(xdr); |
5265 | if (status) | ||
5328 | goto out; | 5266 | goto out; |
5329 | decode_getfattr(&xdr, res->dir_fattr, res->server, | 5267 | decode_getfattr(xdr, res->dir_fattr, res->server, |
5330 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5268 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5331 | out: | 5269 | out: |
5332 | return status; | 5270 | return status; |
@@ -5335,31 +5273,31 @@ out: | |||
5335 | /* | 5273 | /* |
5336 | * Decode SYMLINK response | 5274 | * Decode SYMLINK response |
5337 | */ | 5275 | */ |
5338 | static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_create_res *res) | 5276 | static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5277 | struct nfs4_create_res *res) | ||
5339 | { | 5278 | { |
5340 | return nfs4_xdr_dec_create(rqstp, p, res); | 5279 | return nfs4_xdr_dec_create(rqstp, xdr, res); |
5341 | } | 5280 | } |
5342 | 5281 | ||
5343 | /* | 5282 | /* |
5344 | * Decode GETATTR response | 5283 | * Decode GETATTR response |
5345 | */ | 5284 | */ |
5346 | static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_getattr_res *res) | 5285 | static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5286 | struct nfs4_getattr_res *res) | ||
5347 | { | 5287 | { |
5348 | struct xdr_stream xdr; | ||
5349 | struct compound_hdr hdr; | 5288 | struct compound_hdr hdr; |
5350 | int status; | 5289 | int status; |
5351 | 5290 | ||
5352 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5291 | status = decode_compound_hdr(xdr, &hdr); |
5353 | status = decode_compound_hdr(&xdr, &hdr); | ||
5354 | if (status) | 5292 | if (status) |
5355 | goto out; | 5293 | goto out; |
5356 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5294 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5357 | if (status) | 5295 | if (status) |
5358 | goto out; | 5296 | goto out; |
5359 | status = decode_putfh(&xdr); | 5297 | status = decode_putfh(xdr); |
5360 | if (status) | 5298 | if (status) |
5361 | goto out; | 5299 | goto out; |
5362 | status = decode_getfattr(&xdr, res->fattr, res->server, | 5300 | status = decode_getfattr(xdr, res->fattr, res->server, |
5363 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5301 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5364 | out: | 5302 | out: |
5365 | return status; | 5303 | return status; |
@@ -5368,46 +5306,40 @@ out: | |||
5368 | /* | 5306 | /* |
5369 | * Encode an SETACL request | 5307 | * Encode an SETACL request |
5370 | */ | 5308 | */ |
5371 | static int | 5309 | static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr, |
5372 | nfs4_xdr_enc_setacl(struct rpc_rqst *req, __be32 *p, struct nfs_setaclargs *args) | 5310 | struct nfs_setaclargs *args) |
5373 | { | 5311 | { |
5374 | struct xdr_stream xdr; | ||
5375 | struct compound_hdr hdr = { | 5312 | struct compound_hdr hdr = { |
5376 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), | 5313 | .minorversion = nfs4_xdr_minorversion(&args->seq_args), |
5377 | }; | 5314 | }; |
5378 | int status; | ||
5379 | 5315 | ||
5380 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 5316 | encode_compound_hdr(xdr, req, &hdr); |
5381 | encode_compound_hdr(&xdr, req, &hdr); | 5317 | encode_sequence(xdr, &args->seq_args, &hdr); |
5382 | encode_sequence(&xdr, &args->seq_args, &hdr); | 5318 | encode_putfh(xdr, args->fh, &hdr); |
5383 | encode_putfh(&xdr, args->fh, &hdr); | 5319 | encode_setacl(xdr, args, &hdr); |
5384 | status = encode_setacl(&xdr, args, &hdr); | ||
5385 | encode_nops(&hdr); | 5320 | encode_nops(&hdr); |
5386 | return status; | ||
5387 | } | 5321 | } |
5388 | 5322 | ||
5389 | /* | 5323 | /* |
5390 | * Decode SETACL response | 5324 | * Decode SETACL response |
5391 | */ | 5325 | */ |
5392 | static int | 5326 | static int |
5393 | nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, __be32 *p, | 5327 | nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5394 | struct nfs_setaclres *res) | 5328 | struct nfs_setaclres *res) |
5395 | { | 5329 | { |
5396 | struct xdr_stream xdr; | ||
5397 | struct compound_hdr hdr; | 5330 | struct compound_hdr hdr; |
5398 | int status; | 5331 | int status; |
5399 | 5332 | ||
5400 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5333 | status = decode_compound_hdr(xdr, &hdr); |
5401 | status = decode_compound_hdr(&xdr, &hdr); | ||
5402 | if (status) | 5334 | if (status) |
5403 | goto out; | 5335 | goto out; |
5404 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5336 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5405 | if (status) | 5337 | if (status) |
5406 | goto out; | 5338 | goto out; |
5407 | status = decode_putfh(&xdr); | 5339 | status = decode_putfh(xdr); |
5408 | if (status) | 5340 | if (status) |
5409 | goto out; | 5341 | goto out; |
5410 | status = decode_setattr(&xdr); | 5342 | status = decode_setattr(xdr); |
5411 | out: | 5343 | out: |
5412 | return status; | 5344 | return status; |
5413 | } | 5345 | } |
@@ -5416,24 +5348,22 @@ out: | |||
5416 | * Decode GETACL response | 5348 | * Decode GETACL response |
5417 | */ | 5349 | */ |
5418 | static int | 5350 | static int |
5419 | nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, __be32 *p, | 5351 | nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5420 | struct nfs_getaclres *res) | 5352 | struct nfs_getaclres *res) |
5421 | { | 5353 | { |
5422 | struct xdr_stream xdr; | ||
5423 | struct compound_hdr hdr; | 5354 | struct compound_hdr hdr; |
5424 | int status; | 5355 | int status; |
5425 | 5356 | ||
5426 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5357 | status = decode_compound_hdr(xdr, &hdr); |
5427 | status = decode_compound_hdr(&xdr, &hdr); | ||
5428 | if (status) | 5358 | if (status) |
5429 | goto out; | 5359 | goto out; |
5430 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5360 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5431 | if (status) | 5361 | if (status) |
5432 | goto out; | 5362 | goto out; |
5433 | status = decode_putfh(&xdr); | 5363 | status = decode_putfh(xdr); |
5434 | if (status) | 5364 | if (status) |
5435 | goto out; | 5365 | goto out; |
5436 | status = decode_getacl(&xdr, rqstp, &res->acl_len); | 5366 | status = decode_getacl(xdr, rqstp, &res->acl_len); |
5437 | 5367 | ||
5438 | out: | 5368 | out: |
5439 | return status; | 5369 | return status; |
@@ -5442,23 +5372,22 @@ out: | |||
5442 | /* | 5372 | /* |
5443 | * Decode CLOSE response | 5373 | * Decode CLOSE response |
5444 | */ | 5374 | */ |
5445 | static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_closeres *res) | 5375 | static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5376 | struct nfs_closeres *res) | ||
5446 | { | 5377 | { |
5447 | struct xdr_stream xdr; | ||
5448 | struct compound_hdr hdr; | 5378 | struct compound_hdr hdr; |
5449 | int status; | 5379 | int status; |
5450 | 5380 | ||
5451 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5381 | status = decode_compound_hdr(xdr, &hdr); |
5452 | status = decode_compound_hdr(&xdr, &hdr); | ||
5453 | if (status) | 5382 | if (status) |
5454 | goto out; | 5383 | goto out; |
5455 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5384 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5456 | if (status) | 5385 | if (status) |
5457 | goto out; | 5386 | goto out; |
5458 | status = decode_putfh(&xdr); | 5387 | status = decode_putfh(xdr); |
5459 | if (status) | 5388 | if (status) |
5460 | goto out; | 5389 | goto out; |
5461 | status = decode_close(&xdr, res); | 5390 | status = decode_close(xdr, res); |
5462 | if (status != 0) | 5391 | if (status != 0) |
5463 | goto out; | 5392 | goto out; |
5464 | /* | 5393 | /* |
@@ -5467,7 +5396,7 @@ static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, __be32 *p, struct nfs_clos | |||
5467 | * an ESTALE error. Shouldn't be a problem, | 5396 | * an ESTALE error. Shouldn't be a problem, |
5468 | * though, since fattr->valid will remain unset. | 5397 | * though, since fattr->valid will remain unset. |
5469 | */ | 5398 | */ |
5470 | decode_getfattr(&xdr, res->fattr, res->server, | 5399 | decode_getfattr(xdr, res->fattr, res->server, |
5471 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5400 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5472 | out: | 5401 | out: |
5473 | return status; | 5402 | return status; |
@@ -5476,36 +5405,35 @@ out: | |||
5476 | /* | 5405 | /* |
5477 | * Decode OPEN response | 5406 | * Decode OPEN response |
5478 | */ | 5407 | */ |
5479 | static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res) | 5408 | static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5409 | struct nfs_openres *res) | ||
5480 | { | 5410 | { |
5481 | struct xdr_stream xdr; | ||
5482 | struct compound_hdr hdr; | 5411 | struct compound_hdr hdr; |
5483 | int status; | 5412 | int status; |
5484 | 5413 | ||
5485 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5414 | status = decode_compound_hdr(xdr, &hdr); |
5486 | status = decode_compound_hdr(&xdr, &hdr); | ||
5487 | if (status) | 5415 | if (status) |
5488 | goto out; | 5416 | goto out; |
5489 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5417 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5490 | if (status) | 5418 | if (status) |
5491 | goto out; | 5419 | goto out; |
5492 | status = decode_putfh(&xdr); | 5420 | status = decode_putfh(xdr); |
5493 | if (status) | 5421 | if (status) |
5494 | goto out; | 5422 | goto out; |
5495 | status = decode_savefh(&xdr); | 5423 | status = decode_savefh(xdr); |
5496 | if (status) | 5424 | if (status) |
5497 | goto out; | 5425 | goto out; |
5498 | status = decode_open(&xdr, res); | 5426 | status = decode_open(xdr, res); |
5499 | if (status) | 5427 | if (status) |
5500 | goto out; | 5428 | goto out; |
5501 | if (decode_getfh(&xdr, &res->fh) != 0) | 5429 | if (decode_getfh(xdr, &res->fh) != 0) |
5502 | goto out; | 5430 | goto out; |
5503 | if (decode_getfattr(&xdr, res->f_attr, res->server, | 5431 | if (decode_getfattr(xdr, res->f_attr, res->server, |
5504 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) | 5432 | !RPC_IS_ASYNC(rqstp->rq_task)) != 0) |
5505 | goto out; | 5433 | goto out; |
5506 | if (decode_restorefh(&xdr) != 0) | 5434 | if (decode_restorefh(xdr) != 0) |
5507 | goto out; | 5435 | goto out; |
5508 | decode_getfattr(&xdr, res->dir_attr, res->server, | 5436 | decode_getfattr(xdr, res->dir_attr, res->server, |
5509 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5437 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5510 | out: | 5438 | out: |
5511 | return status; | 5439 | return status; |
@@ -5514,20 +5442,20 @@ out: | |||
5514 | /* | 5442 | /* |
5515 | * Decode OPEN_CONFIRM response | 5443 | * Decode OPEN_CONFIRM response |
5516 | */ | 5444 | */ |
5517 | static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, __be32 *p, struct nfs_open_confirmres *res) | 5445 | static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp, |
5446 | struct xdr_stream *xdr, | ||
5447 | struct nfs_open_confirmres *res) | ||
5518 | { | 5448 | { |
5519 | struct xdr_stream xdr; | ||
5520 | struct compound_hdr hdr; | 5449 | struct compound_hdr hdr; |
5521 | int status; | 5450 | int status; |
5522 | 5451 | ||
5523 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5452 | status = decode_compound_hdr(xdr, &hdr); |
5524 | status = decode_compound_hdr(&xdr, &hdr); | ||
5525 | if (status) | 5453 | if (status) |
5526 | goto out; | 5454 | goto out; |
5527 | status = decode_putfh(&xdr); | 5455 | status = decode_putfh(xdr); |
5528 | if (status) | 5456 | if (status) |
5529 | goto out; | 5457 | goto out; |
5530 | status = decode_open_confirm(&xdr, res); | 5458 | status = decode_open_confirm(xdr, res); |
5531 | out: | 5459 | out: |
5532 | return status; | 5460 | return status; |
5533 | } | 5461 | } |
@@ -5535,26 +5463,26 @@ out: | |||
5535 | /* | 5463 | /* |
5536 | * Decode OPEN response | 5464 | * Decode OPEN response |
5537 | */ | 5465 | */ |
5538 | static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_openres *res) | 5466 | static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp, |
5467 | struct xdr_stream *xdr, | ||
5468 | struct nfs_openres *res) | ||
5539 | { | 5469 | { |
5540 | struct xdr_stream xdr; | ||
5541 | struct compound_hdr hdr; | 5470 | struct compound_hdr hdr; |
5542 | int status; | 5471 | int status; |
5543 | 5472 | ||
5544 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5473 | status = decode_compound_hdr(xdr, &hdr); |
5545 | status = decode_compound_hdr(&xdr, &hdr); | ||
5546 | if (status) | 5474 | if (status) |
5547 | goto out; | 5475 | goto out; |
5548 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5476 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5549 | if (status) | 5477 | if (status) |
5550 | goto out; | 5478 | goto out; |
5551 | status = decode_putfh(&xdr); | 5479 | status = decode_putfh(xdr); |
5552 | if (status) | 5480 | if (status) |
5553 | goto out; | 5481 | goto out; |
5554 | status = decode_open(&xdr, res); | 5482 | status = decode_open(xdr, res); |
5555 | if (status) | 5483 | if (status) |
5556 | goto out; | 5484 | goto out; |
5557 | decode_getfattr(&xdr, res->f_attr, res->server, | 5485 | decode_getfattr(xdr, res->f_attr, res->server, |
5558 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5486 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5559 | out: | 5487 | out: |
5560 | return status; | 5488 | return status; |
@@ -5563,26 +5491,26 @@ out: | |||
5563 | /* | 5491 | /* |
5564 | * Decode SETATTR response | 5492 | * Decode SETATTR response |
5565 | */ | 5493 | */ |
5566 | static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, __be32 *p, struct nfs_setattrres *res) | 5494 | static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp, |
5495 | struct xdr_stream *xdr, | ||
5496 | struct nfs_setattrres *res) | ||
5567 | { | 5497 | { |
5568 | struct xdr_stream xdr; | ||
5569 | struct compound_hdr hdr; | 5498 | struct compound_hdr hdr; |
5570 | int status; | 5499 | int status; |
5571 | 5500 | ||
5572 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5501 | status = decode_compound_hdr(xdr, &hdr); |
5573 | status = decode_compound_hdr(&xdr, &hdr); | ||
5574 | if (status) | 5502 | if (status) |
5575 | goto out; | 5503 | goto out; |
5576 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5504 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5577 | if (status) | 5505 | if (status) |
5578 | goto out; | 5506 | goto out; |
5579 | status = decode_putfh(&xdr); | 5507 | status = decode_putfh(xdr); |
5580 | if (status) | 5508 | if (status) |
5581 | goto out; | 5509 | goto out; |
5582 | status = decode_setattr(&xdr); | 5510 | status = decode_setattr(xdr); |
5583 | if (status) | 5511 | if (status) |
5584 | goto out; | 5512 | goto out; |
5585 | decode_getfattr(&xdr, res->fattr, res->server, | 5513 | decode_getfattr(xdr, res->fattr, res->server, |
5586 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5514 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5587 | out: | 5515 | out: |
5588 | return status; | 5516 | return status; |
@@ -5591,23 +5519,22 @@ out: | |||
5591 | /* | 5519 | /* |
5592 | * Decode LOCK response | 5520 | * Decode LOCK response |
5593 | */ | 5521 | */ |
5594 | static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lock_res *res) | 5522 | static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5523 | struct nfs_lock_res *res) | ||
5595 | { | 5524 | { |
5596 | struct xdr_stream xdr; | ||
5597 | struct compound_hdr hdr; | 5525 | struct compound_hdr hdr; |
5598 | int status; | 5526 | int status; |
5599 | 5527 | ||
5600 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5528 | status = decode_compound_hdr(xdr, &hdr); |
5601 | status = decode_compound_hdr(&xdr, &hdr); | ||
5602 | if (status) | 5529 | if (status) |
5603 | goto out; | 5530 | goto out; |
5604 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5531 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5605 | if (status) | 5532 | if (status) |
5606 | goto out; | 5533 | goto out; |
5607 | status = decode_putfh(&xdr); | 5534 | status = decode_putfh(xdr); |
5608 | if (status) | 5535 | if (status) |
5609 | goto out; | 5536 | goto out; |
5610 | status = decode_lock(&xdr, res); | 5537 | status = decode_lock(xdr, res); |
5611 | out: | 5538 | out: |
5612 | return status; | 5539 | return status; |
5613 | } | 5540 | } |
@@ -5615,23 +5542,22 @@ out: | |||
5615 | /* | 5542 | /* |
5616 | * Decode LOCKT response | 5543 | * Decode LOCKT response |
5617 | */ | 5544 | */ |
5618 | static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, __be32 *p, struct nfs_lockt_res *res) | 5545 | static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5546 | struct nfs_lockt_res *res) | ||
5619 | { | 5547 | { |
5620 | struct xdr_stream xdr; | ||
5621 | struct compound_hdr hdr; | 5548 | struct compound_hdr hdr; |
5622 | int status; | 5549 | int status; |
5623 | 5550 | ||
5624 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5551 | status = decode_compound_hdr(xdr, &hdr); |
5625 | status = decode_compound_hdr(&xdr, &hdr); | ||
5626 | if (status) | 5552 | if (status) |
5627 | goto out; | 5553 | goto out; |
5628 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5554 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5629 | if (status) | 5555 | if (status) |
5630 | goto out; | 5556 | goto out; |
5631 | status = decode_putfh(&xdr); | 5557 | status = decode_putfh(xdr); |
5632 | if (status) | 5558 | if (status) |
5633 | goto out; | 5559 | goto out; |
5634 | status = decode_lockt(&xdr, res); | 5560 | status = decode_lockt(xdr, res); |
5635 | out: | 5561 | out: |
5636 | return status; | 5562 | return status; |
5637 | } | 5563 | } |
@@ -5639,61 +5565,58 @@ out: | |||
5639 | /* | 5565 | /* |
5640 | * Decode LOCKU response | 5566 | * Decode LOCKU response |
5641 | */ | 5567 | */ |
5642 | static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, __be32 *p, struct nfs_locku_res *res) | 5568 | static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5569 | struct nfs_locku_res *res) | ||
5643 | { | 5570 | { |
5644 | struct xdr_stream xdr; | ||
5645 | struct compound_hdr hdr; | 5571 | struct compound_hdr hdr; |
5646 | int status; | 5572 | int status; |
5647 | 5573 | ||
5648 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5574 | status = decode_compound_hdr(xdr, &hdr); |
5649 | status = decode_compound_hdr(&xdr, &hdr); | ||
5650 | if (status) | 5575 | if (status) |
5651 | goto out; | 5576 | goto out; |
5652 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5577 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5653 | if (status) | 5578 | if (status) |
5654 | goto out; | 5579 | goto out; |
5655 | status = decode_putfh(&xdr); | 5580 | status = decode_putfh(xdr); |
5656 | if (status) | 5581 | if (status) |
5657 | goto out; | 5582 | goto out; |
5658 | status = decode_locku(&xdr, res); | 5583 | status = decode_locku(xdr, res); |
5659 | out: | 5584 | out: |
5660 | return status; | 5585 | return status; |
5661 | } | 5586 | } |
5662 | 5587 | ||
5663 | static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, __be32 *p, void *dummy) | 5588 | static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp, |
5589 | struct xdr_stream *xdr, void *dummy) | ||
5664 | { | 5590 | { |
5665 | struct xdr_stream xdr; | ||
5666 | struct compound_hdr hdr; | 5591 | struct compound_hdr hdr; |
5667 | int status; | 5592 | int status; |
5668 | 5593 | ||
5669 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5594 | status = decode_compound_hdr(xdr, &hdr); |
5670 | status = decode_compound_hdr(&xdr, &hdr); | ||
5671 | if (!status) | 5595 | if (!status) |
5672 | status = decode_release_lockowner(&xdr); | 5596 | status = decode_release_lockowner(xdr); |
5673 | return status; | 5597 | return status; |
5674 | } | 5598 | } |
5675 | 5599 | ||
5676 | /* | 5600 | /* |
5677 | * Decode READLINK response | 5601 | * Decode READLINK response |
5678 | */ | 5602 | */ |
5679 | static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, __be32 *p, | 5603 | static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp, |
5604 | struct xdr_stream *xdr, | ||
5680 | struct nfs4_readlink_res *res) | 5605 | struct nfs4_readlink_res *res) |
5681 | { | 5606 | { |
5682 | struct xdr_stream xdr; | ||
5683 | struct compound_hdr hdr; | 5607 | struct compound_hdr hdr; |
5684 | int status; | 5608 | int status; |
5685 | 5609 | ||
5686 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5610 | status = decode_compound_hdr(xdr, &hdr); |
5687 | status = decode_compound_hdr(&xdr, &hdr); | ||
5688 | if (status) | 5611 | if (status) |
5689 | goto out; | 5612 | goto out; |
5690 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5613 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5691 | if (status) | 5614 | if (status) |
5692 | goto out; | 5615 | goto out; |
5693 | status = decode_putfh(&xdr); | 5616 | status = decode_putfh(xdr); |
5694 | if (status) | 5617 | if (status) |
5695 | goto out; | 5618 | goto out; |
5696 | status = decode_readlink(&xdr, rqstp); | 5619 | status = decode_readlink(xdr, rqstp); |
5697 | out: | 5620 | out: |
5698 | return status; | 5621 | return status; |
5699 | } | 5622 | } |
@@ -5701,23 +5624,22 @@ out: | |||
5701 | /* | 5624 | /* |
5702 | * Decode READDIR response | 5625 | * Decode READDIR response |
5703 | */ | 5626 | */ |
5704 | static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_readdir_res *res) | 5627 | static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5628 | struct nfs4_readdir_res *res) | ||
5705 | { | 5629 | { |
5706 | struct xdr_stream xdr; | ||
5707 | struct compound_hdr hdr; | 5630 | struct compound_hdr hdr; |
5708 | int status; | 5631 | int status; |
5709 | 5632 | ||
5710 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5633 | status = decode_compound_hdr(xdr, &hdr); |
5711 | status = decode_compound_hdr(&xdr, &hdr); | ||
5712 | if (status) | 5634 | if (status) |
5713 | goto out; | 5635 | goto out; |
5714 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5636 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5715 | if (status) | 5637 | if (status) |
5716 | goto out; | 5638 | goto out; |
5717 | status = decode_putfh(&xdr); | 5639 | status = decode_putfh(xdr); |
5718 | if (status) | 5640 | if (status) |
5719 | goto out; | 5641 | goto out; |
5720 | status = decode_readdir(&xdr, rqstp, res); | 5642 | status = decode_readdir(xdr, rqstp, res); |
5721 | out: | 5643 | out: |
5722 | return status; | 5644 | return status; |
5723 | } | 5645 | } |
@@ -5725,23 +5647,22 @@ out: | |||
5725 | /* | 5647 | /* |
5726 | * Decode Read response | 5648 | * Decode Read response |
5727 | */ | 5649 | */ |
5728 | static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, __be32 *p, struct nfs_readres *res) | 5650 | static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5651 | struct nfs_readres *res) | ||
5729 | { | 5652 | { |
5730 | struct xdr_stream xdr; | ||
5731 | struct compound_hdr hdr; | 5653 | struct compound_hdr hdr; |
5732 | int status; | 5654 | int status; |
5733 | 5655 | ||
5734 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5656 | status = decode_compound_hdr(xdr, &hdr); |
5735 | status = decode_compound_hdr(&xdr, &hdr); | ||
5736 | if (status) | 5657 | if (status) |
5737 | goto out; | 5658 | goto out; |
5738 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5659 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5739 | if (status) | 5660 | if (status) |
5740 | goto out; | 5661 | goto out; |
5741 | status = decode_putfh(&xdr); | 5662 | status = decode_putfh(xdr); |
5742 | if (status) | 5663 | if (status) |
5743 | goto out; | 5664 | goto out; |
5744 | status = decode_read(&xdr, rqstp, res); | 5665 | status = decode_read(xdr, rqstp, res); |
5745 | if (!status) | 5666 | if (!status) |
5746 | status = res->count; | 5667 | status = res->count; |
5747 | out: | 5668 | out: |
@@ -5751,26 +5672,25 @@ out: | |||
5751 | /* | 5672 | /* |
5752 | * Decode WRITE response | 5673 | * Decode WRITE response |
5753 | */ | 5674 | */ |
5754 | static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res) | 5675 | static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5676 | struct nfs_writeres *res) | ||
5755 | { | 5677 | { |
5756 | struct xdr_stream xdr; | ||
5757 | struct compound_hdr hdr; | 5678 | struct compound_hdr hdr; |
5758 | int status; | 5679 | int status; |
5759 | 5680 | ||
5760 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5681 | status = decode_compound_hdr(xdr, &hdr); |
5761 | status = decode_compound_hdr(&xdr, &hdr); | ||
5762 | if (status) | 5682 | if (status) |
5763 | goto out; | 5683 | goto out; |
5764 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5684 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5765 | if (status) | 5685 | if (status) |
5766 | goto out; | 5686 | goto out; |
5767 | status = decode_putfh(&xdr); | 5687 | status = decode_putfh(xdr); |
5768 | if (status) | 5688 | if (status) |
5769 | goto out; | 5689 | goto out; |
5770 | status = decode_write(&xdr, res); | 5690 | status = decode_write(xdr, res); |
5771 | if (status) | 5691 | if (status) |
5772 | goto out; | 5692 | goto out; |
5773 | decode_getfattr(&xdr, res->fattr, res->server, | 5693 | decode_getfattr(xdr, res->fattr, res->server, |
5774 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5694 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5775 | if (!status) | 5695 | if (!status) |
5776 | status = res->count; | 5696 | status = res->count; |
@@ -5781,26 +5701,25 @@ out: | |||
5781 | /* | 5701 | /* |
5782 | * Decode COMMIT response | 5702 | * Decode COMMIT response |
5783 | */ | 5703 | */ |
5784 | static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, __be32 *p, struct nfs_writeres *res) | 5704 | static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5705 | struct nfs_writeres *res) | ||
5785 | { | 5706 | { |
5786 | struct xdr_stream xdr; | ||
5787 | struct compound_hdr hdr; | 5707 | struct compound_hdr hdr; |
5788 | int status; | 5708 | int status; |
5789 | 5709 | ||
5790 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5710 | status = decode_compound_hdr(xdr, &hdr); |
5791 | status = decode_compound_hdr(&xdr, &hdr); | ||
5792 | if (status) | 5711 | if (status) |
5793 | goto out; | 5712 | goto out; |
5794 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5713 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5795 | if (status) | 5714 | if (status) |
5796 | goto out; | 5715 | goto out; |
5797 | status = decode_putfh(&xdr); | 5716 | status = decode_putfh(xdr); |
5798 | if (status) | 5717 | if (status) |
5799 | goto out; | 5718 | goto out; |
5800 | status = decode_commit(&xdr, res); | 5719 | status = decode_commit(xdr, res); |
5801 | if (status) | 5720 | if (status) |
5802 | goto out; | 5721 | goto out; |
5803 | decode_getfattr(&xdr, res->fattr, res->server, | 5722 | decode_getfattr(xdr, res->fattr, res->server, |
5804 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5723 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5805 | out: | 5724 | out: |
5806 | return status; | 5725 | return status; |
@@ -5809,85 +5728,80 @@ out: | |||
5809 | /* | 5728 | /* |
5810 | * Decode FSINFO response | 5729 | * Decode FSINFO response |
5811 | */ | 5730 | */ |
5812 | static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, | 5731 | static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr, |
5813 | struct nfs4_fsinfo_res *res) | 5732 | struct nfs4_fsinfo_res *res) |
5814 | { | 5733 | { |
5815 | struct xdr_stream xdr; | ||
5816 | struct compound_hdr hdr; | 5734 | struct compound_hdr hdr; |
5817 | int status; | 5735 | int status; |
5818 | 5736 | ||
5819 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | 5737 | status = decode_compound_hdr(xdr, &hdr); |
5820 | status = decode_compound_hdr(&xdr, &hdr); | ||
5821 | if (!status) | 5738 | if (!status) |
5822 | status = decode_sequence(&xdr, &res->seq_res, req); | 5739 | status = decode_sequence(xdr, &res->seq_res, req); |
5823 | if (!status) | 5740 | if (!status) |
5824 | status = decode_putfh(&xdr); | 5741 | status = decode_putfh(xdr); |
5825 | if (!status) | 5742 | if (!status) |
5826 | status = decode_fsinfo(&xdr, res->fsinfo); | 5743 | status = decode_fsinfo(xdr, res->fsinfo); |
5827 | return status; | 5744 | return status; |
5828 | } | 5745 | } |
5829 | 5746 | ||
5830 | /* | 5747 | /* |
5831 | * Decode PATHCONF response | 5748 | * Decode PATHCONF response |
5832 | */ | 5749 | */ |
5833 | static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, __be32 *p, | 5750 | static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr, |
5834 | struct nfs4_pathconf_res *res) | 5751 | struct nfs4_pathconf_res *res) |
5835 | { | 5752 | { |
5836 | struct xdr_stream xdr; | ||
5837 | struct compound_hdr hdr; | 5753 | struct compound_hdr hdr; |
5838 | int status; | 5754 | int status; |
5839 | 5755 | ||
5840 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | 5756 | status = decode_compound_hdr(xdr, &hdr); |
5841 | status = decode_compound_hdr(&xdr, &hdr); | ||
5842 | if (!status) | 5757 | if (!status) |
5843 | status = decode_sequence(&xdr, &res->seq_res, req); | 5758 | status = decode_sequence(xdr, &res->seq_res, req); |
5844 | if (!status) | 5759 | if (!status) |
5845 | status = decode_putfh(&xdr); | 5760 | status = decode_putfh(xdr); |
5846 | if (!status) | 5761 | if (!status) |
5847 | status = decode_pathconf(&xdr, res->pathconf); | 5762 | status = decode_pathconf(xdr, res->pathconf); |
5848 | return status; | 5763 | return status; |
5849 | } | 5764 | } |
5850 | 5765 | ||
5851 | /* | 5766 | /* |
5852 | * Decode STATFS response | 5767 | * Decode STATFS response |
5853 | */ | 5768 | */ |
5854 | static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, __be32 *p, | 5769 | static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr, |
5855 | struct nfs4_statfs_res *res) | 5770 | struct nfs4_statfs_res *res) |
5856 | { | 5771 | { |
5857 | struct xdr_stream xdr; | ||
5858 | struct compound_hdr hdr; | 5772 | struct compound_hdr hdr; |
5859 | int status; | 5773 | int status; |
5860 | 5774 | ||
5861 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | 5775 | status = decode_compound_hdr(xdr, &hdr); |
5862 | status = decode_compound_hdr(&xdr, &hdr); | ||
5863 | if (!status) | 5776 | if (!status) |
5864 | status = decode_sequence(&xdr, &res->seq_res, req); | 5777 | status = decode_sequence(xdr, &res->seq_res, req); |
5865 | if (!status) | 5778 | if (!status) |
5866 | status = decode_putfh(&xdr); | 5779 | status = decode_putfh(xdr); |
5867 | if (!status) | 5780 | if (!status) |
5868 | status = decode_statfs(&xdr, res->fsstat); | 5781 | status = decode_statfs(xdr, res->fsstat); |
5869 | return status; | 5782 | return status; |
5870 | } | 5783 | } |
5871 | 5784 | ||
5872 | /* | 5785 | /* |
5873 | * Decode GETATTR_BITMAP response | 5786 | * Decode GETATTR_BITMAP response |
5874 | */ | 5787 | */ |
5875 | static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, __be32 *p, struct nfs4_server_caps_res *res) | 5788 | static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req, |
5789 | struct xdr_stream *xdr, | ||
5790 | struct nfs4_server_caps_res *res) | ||
5876 | { | 5791 | { |
5877 | struct xdr_stream xdr; | ||
5878 | struct compound_hdr hdr; | 5792 | struct compound_hdr hdr; |
5879 | int status; | 5793 | int status; |
5880 | 5794 | ||
5881 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | 5795 | status = decode_compound_hdr(xdr, &hdr); |
5882 | status = decode_compound_hdr(&xdr, &hdr); | ||
5883 | if (status) | 5796 | if (status) |
5884 | goto out; | 5797 | goto out; |
5885 | status = decode_sequence(&xdr, &res->seq_res, req); | 5798 | status = decode_sequence(xdr, &res->seq_res, req); |
5886 | if (status) | 5799 | if (status) |
5887 | goto out; | 5800 | goto out; |
5888 | if ((status = decode_putfh(&xdr)) != 0) | 5801 | status = decode_putfh(xdr); |
5802 | if (status) | ||
5889 | goto out; | 5803 | goto out; |
5890 | status = decode_server_caps(&xdr, res); | 5804 | status = decode_server_caps(xdr, res); |
5891 | out: | 5805 | out: |
5892 | return status; | 5806 | return status; |
5893 | } | 5807 | } |
@@ -5895,79 +5809,77 @@ out: | |||
5895 | /* | 5809 | /* |
5896 | * Decode RENEW response | 5810 | * Decode RENEW response |
5897 | */ | 5811 | */ |
5898 | static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy) | 5812 | static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr, |
5813 | void *__unused) | ||
5899 | { | 5814 | { |
5900 | struct xdr_stream xdr; | ||
5901 | struct compound_hdr hdr; | 5815 | struct compound_hdr hdr; |
5902 | int status; | 5816 | int status; |
5903 | 5817 | ||
5904 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5818 | status = decode_compound_hdr(xdr, &hdr); |
5905 | status = decode_compound_hdr(&xdr, &hdr); | ||
5906 | if (!status) | 5819 | if (!status) |
5907 | status = decode_renew(&xdr); | 5820 | status = decode_renew(xdr); |
5908 | return status; | 5821 | return status; |
5909 | } | 5822 | } |
5910 | 5823 | ||
5911 | /* | 5824 | /* |
5912 | * Decode SETCLIENTID response | 5825 | * Decode SETCLIENTID response |
5913 | */ | 5826 | */ |
5914 | static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p, | 5827 | static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, |
5915 | struct nfs4_setclientid_res *res) | 5828 | struct xdr_stream *xdr, |
5829 | struct nfs4_setclientid_res *res) | ||
5916 | { | 5830 | { |
5917 | struct xdr_stream xdr; | ||
5918 | struct compound_hdr hdr; | 5831 | struct compound_hdr hdr; |
5919 | int status; | 5832 | int status; |
5920 | 5833 | ||
5921 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | 5834 | status = decode_compound_hdr(xdr, &hdr); |
5922 | status = decode_compound_hdr(&xdr, &hdr); | ||
5923 | if (!status) | 5835 | if (!status) |
5924 | status = decode_setclientid(&xdr, res); | 5836 | status = decode_setclientid(xdr, res); |
5925 | return status; | 5837 | return status; |
5926 | } | 5838 | } |
5927 | 5839 | ||
5928 | /* | 5840 | /* |
5929 | * Decode SETCLIENTID_CONFIRM response | 5841 | * Decode SETCLIENTID_CONFIRM response |
5930 | */ | 5842 | */ |
5931 | static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *fsinfo) | 5843 | static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, |
5844 | struct xdr_stream *xdr, | ||
5845 | struct nfs_fsinfo *fsinfo) | ||
5932 | { | 5846 | { |
5933 | struct xdr_stream xdr; | ||
5934 | struct compound_hdr hdr; | 5847 | struct compound_hdr hdr; |
5935 | int status; | 5848 | int status; |
5936 | 5849 | ||
5937 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | 5850 | status = decode_compound_hdr(xdr, &hdr); |
5938 | status = decode_compound_hdr(&xdr, &hdr); | ||
5939 | if (!status) | 5851 | if (!status) |
5940 | status = decode_setclientid_confirm(&xdr); | 5852 | status = decode_setclientid_confirm(xdr); |
5941 | if (!status) | 5853 | if (!status) |
5942 | status = decode_putrootfh(&xdr); | 5854 | status = decode_putrootfh(xdr); |
5943 | if (!status) | 5855 | if (!status) |
5944 | status = decode_fsinfo(&xdr, fsinfo); | 5856 | status = decode_fsinfo(xdr, fsinfo); |
5945 | return status; | 5857 | return status; |
5946 | } | 5858 | } |
5947 | 5859 | ||
5948 | /* | 5860 | /* |
5949 | * Decode DELEGRETURN response | 5861 | * Decode DELEGRETURN response |
5950 | */ | 5862 | */ |
5951 | static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, __be32 *p, struct nfs4_delegreturnres *res) | 5863 | static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp, |
5864 | struct xdr_stream *xdr, | ||
5865 | struct nfs4_delegreturnres *res) | ||
5952 | { | 5866 | { |
5953 | struct xdr_stream xdr; | ||
5954 | struct compound_hdr hdr; | 5867 | struct compound_hdr hdr; |
5955 | int status; | 5868 | int status; |
5956 | 5869 | ||
5957 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5870 | status = decode_compound_hdr(xdr, &hdr); |
5958 | status = decode_compound_hdr(&xdr, &hdr); | ||
5959 | if (status) | 5871 | if (status) |
5960 | goto out; | 5872 | goto out; |
5961 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 5873 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
5962 | if (status) | 5874 | if (status) |
5963 | goto out; | 5875 | goto out; |
5964 | status = decode_putfh(&xdr); | 5876 | status = decode_putfh(xdr); |
5965 | if (status != 0) | 5877 | if (status != 0) |
5966 | goto out; | 5878 | goto out; |
5967 | status = decode_delegreturn(&xdr); | 5879 | status = decode_delegreturn(xdr); |
5968 | if (status != 0) | 5880 | if (status != 0) |
5969 | goto out; | 5881 | goto out; |
5970 | decode_getfattr(&xdr, res->fattr, res->server, | 5882 | decode_getfattr(xdr, res->fattr, res->server, |
5971 | !RPC_IS_ASYNC(rqstp->rq_task)); | 5883 | !RPC_IS_ASYNC(rqstp->rq_task)); |
5972 | out: | 5884 | out: |
5973 | return status; | 5885 | return status; |
@@ -5976,26 +5888,27 @@ out: | |||
5976 | /* | 5888 | /* |
5977 | * Decode FS_LOCATIONS response | 5889 | * Decode FS_LOCATIONS response |
5978 | */ | 5890 | */ |
5979 | static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, __be32 *p, | 5891 | static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req, |
5892 | struct xdr_stream *xdr, | ||
5980 | struct nfs4_fs_locations_res *res) | 5893 | struct nfs4_fs_locations_res *res) |
5981 | { | 5894 | { |
5982 | struct xdr_stream xdr; | ||
5983 | struct compound_hdr hdr; | 5895 | struct compound_hdr hdr; |
5984 | int status; | 5896 | int status; |
5985 | 5897 | ||
5986 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | 5898 | status = decode_compound_hdr(xdr, &hdr); |
5987 | status = decode_compound_hdr(&xdr, &hdr); | ||
5988 | if (status) | 5899 | if (status) |
5989 | goto out; | 5900 | goto out; |
5990 | status = decode_sequence(&xdr, &res->seq_res, req); | 5901 | status = decode_sequence(xdr, &res->seq_res, req); |
5991 | if (status) | 5902 | if (status) |
5992 | goto out; | 5903 | goto out; |
5993 | if ((status = decode_putfh(&xdr)) != 0) | 5904 | status = decode_putfh(xdr); |
5905 | if (status) | ||
5994 | goto out; | 5906 | goto out; |
5995 | if ((status = decode_lookup(&xdr)) != 0) | 5907 | status = decode_lookup(xdr); |
5908 | if (status) | ||
5996 | goto out; | 5909 | goto out; |
5997 | xdr_enter_page(&xdr, PAGE_SIZE); | 5910 | xdr_enter_page(xdr, PAGE_SIZE); |
5998 | status = decode_getfattr(&xdr, &res->fs_locations->fattr, | 5911 | status = decode_getfattr(xdr, &res->fs_locations->fattr, |
5999 | res->fs_locations->server, | 5912 | res->fs_locations->server, |
6000 | !RPC_IS_ASYNC(req->rq_task)); | 5913 | !RPC_IS_ASYNC(req->rq_task)); |
6001 | out: | 5914 | out: |
@@ -6006,129 +5919,122 @@ out: | |||
6006 | /* | 5919 | /* |
6007 | * Decode EXCHANGE_ID response | 5920 | * Decode EXCHANGE_ID response |
6008 | */ | 5921 | */ |
6009 | static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, uint32_t *p, | 5922 | static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp, |
5923 | struct xdr_stream *xdr, | ||
6010 | void *res) | 5924 | void *res) |
6011 | { | 5925 | { |
6012 | struct xdr_stream xdr; | ||
6013 | struct compound_hdr hdr; | 5926 | struct compound_hdr hdr; |
6014 | int status; | 5927 | int status; |
6015 | 5928 | ||
6016 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5929 | status = decode_compound_hdr(xdr, &hdr); |
6017 | status = decode_compound_hdr(&xdr, &hdr); | ||
6018 | if (!status) | 5930 | if (!status) |
6019 | status = decode_exchange_id(&xdr, res); | 5931 | status = decode_exchange_id(xdr, res); |
6020 | return status; | 5932 | return status; |
6021 | } | 5933 | } |
6022 | 5934 | ||
6023 | /* | 5935 | /* |
6024 | * Decode CREATE_SESSION response | 5936 | * Decode CREATE_SESSION response |
6025 | */ | 5937 | */ |
6026 | static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, uint32_t *p, | 5938 | static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp, |
5939 | struct xdr_stream *xdr, | ||
6027 | struct nfs41_create_session_res *res) | 5940 | struct nfs41_create_session_res *res) |
6028 | { | 5941 | { |
6029 | struct xdr_stream xdr; | ||
6030 | struct compound_hdr hdr; | 5942 | struct compound_hdr hdr; |
6031 | int status; | 5943 | int status; |
6032 | 5944 | ||
6033 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5945 | status = decode_compound_hdr(xdr, &hdr); |
6034 | status = decode_compound_hdr(&xdr, &hdr); | ||
6035 | if (!status) | 5946 | if (!status) |
6036 | status = decode_create_session(&xdr, res); | 5947 | status = decode_create_session(xdr, res); |
6037 | return status; | 5948 | return status; |
6038 | } | 5949 | } |
6039 | 5950 | ||
6040 | /* | 5951 | /* |
6041 | * Decode DESTROY_SESSION response | 5952 | * Decode DESTROY_SESSION response |
6042 | */ | 5953 | */ |
6043 | static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, uint32_t *p, | 5954 | static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp, |
6044 | void *dummy) | 5955 | struct xdr_stream *xdr, |
5956 | void *res) | ||
6045 | { | 5957 | { |
6046 | struct xdr_stream xdr; | ||
6047 | struct compound_hdr hdr; | 5958 | struct compound_hdr hdr; |
6048 | int status; | 5959 | int status; |
6049 | 5960 | ||
6050 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5961 | status = decode_compound_hdr(xdr, &hdr); |
6051 | status = decode_compound_hdr(&xdr, &hdr); | ||
6052 | if (!status) | 5962 | if (!status) |
6053 | status = decode_destroy_session(&xdr, dummy); | 5963 | status = decode_destroy_session(xdr, res); |
6054 | return status; | 5964 | return status; |
6055 | } | 5965 | } |
6056 | 5966 | ||
6057 | /* | 5967 | /* |
6058 | * Decode SEQUENCE response | 5968 | * Decode SEQUENCE response |
6059 | */ | 5969 | */ |
6060 | static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, uint32_t *p, | 5970 | static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp, |
5971 | struct xdr_stream *xdr, | ||
6061 | struct nfs4_sequence_res *res) | 5972 | struct nfs4_sequence_res *res) |
6062 | { | 5973 | { |
6063 | struct xdr_stream xdr; | ||
6064 | struct compound_hdr hdr; | 5974 | struct compound_hdr hdr; |
6065 | int status; | 5975 | int status; |
6066 | 5976 | ||
6067 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5977 | status = decode_compound_hdr(xdr, &hdr); |
6068 | status = decode_compound_hdr(&xdr, &hdr); | ||
6069 | if (!status) | 5978 | if (!status) |
6070 | status = decode_sequence(&xdr, res, rqstp); | 5979 | status = decode_sequence(xdr, res, rqstp); |
6071 | return status; | 5980 | return status; |
6072 | } | 5981 | } |
6073 | 5982 | ||
6074 | /* | 5983 | /* |
6075 | * Decode GET_LEASE_TIME response | 5984 | * Decode GET_LEASE_TIME response |
6076 | */ | 5985 | */ |
6077 | static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, uint32_t *p, | 5986 | static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp, |
5987 | struct xdr_stream *xdr, | ||
6078 | struct nfs4_get_lease_time_res *res) | 5988 | struct nfs4_get_lease_time_res *res) |
6079 | { | 5989 | { |
6080 | struct xdr_stream xdr; | ||
6081 | struct compound_hdr hdr; | 5990 | struct compound_hdr hdr; |
6082 | int status; | 5991 | int status; |
6083 | 5992 | ||
6084 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 5993 | status = decode_compound_hdr(xdr, &hdr); |
6085 | status = decode_compound_hdr(&xdr, &hdr); | ||
6086 | if (!status) | 5994 | if (!status) |
6087 | status = decode_sequence(&xdr, &res->lr_seq_res, rqstp); | 5995 | status = decode_sequence(xdr, &res->lr_seq_res, rqstp); |
6088 | if (!status) | 5996 | if (!status) |
6089 | status = decode_putrootfh(&xdr); | 5997 | status = decode_putrootfh(xdr); |
6090 | if (!status) | 5998 | if (!status) |
6091 | status = decode_fsinfo(&xdr, res->lr_fsinfo); | 5999 | status = decode_fsinfo(xdr, res->lr_fsinfo); |
6092 | return status; | 6000 | return status; |
6093 | } | 6001 | } |
6094 | 6002 | ||
6095 | /* | 6003 | /* |
6096 | * Decode RECLAIM_COMPLETE response | 6004 | * Decode RECLAIM_COMPLETE response |
6097 | */ | 6005 | */ |
6098 | static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, uint32_t *p, | 6006 | static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp, |
6007 | struct xdr_stream *xdr, | ||
6099 | struct nfs41_reclaim_complete_res *res) | 6008 | struct nfs41_reclaim_complete_res *res) |
6100 | { | 6009 | { |
6101 | struct xdr_stream xdr; | ||
6102 | struct compound_hdr hdr; | 6010 | struct compound_hdr hdr; |
6103 | int status; | 6011 | int status; |
6104 | 6012 | ||
6105 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 6013 | status = decode_compound_hdr(xdr, &hdr); |
6106 | status = decode_compound_hdr(&xdr, &hdr); | ||
6107 | if (!status) | 6014 | if (!status) |
6108 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 6015 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
6109 | if (!status) | 6016 | if (!status) |
6110 | status = decode_reclaim_complete(&xdr, (void *)NULL); | 6017 | status = decode_reclaim_complete(xdr, (void *)NULL); |
6111 | return status; | 6018 | return status; |
6112 | } | 6019 | } |
6113 | 6020 | ||
6114 | /* | 6021 | /* |
6115 | * Decode GETDEVINFO response | 6022 | * Decode GETDEVINFO response |
6116 | */ | 6023 | */ |
6117 | static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, uint32_t *p, | 6024 | static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp, |
6025 | struct xdr_stream *xdr, | ||
6118 | struct nfs4_getdeviceinfo_res *res) | 6026 | struct nfs4_getdeviceinfo_res *res) |
6119 | { | 6027 | { |
6120 | struct xdr_stream xdr; | ||
6121 | struct compound_hdr hdr; | 6028 | struct compound_hdr hdr; |
6122 | int status; | 6029 | int status; |
6123 | 6030 | ||
6124 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 6031 | status = decode_compound_hdr(xdr, &hdr); |
6125 | status = decode_compound_hdr(&xdr, &hdr); | ||
6126 | if (status != 0) | 6032 | if (status != 0) |
6127 | goto out; | 6033 | goto out; |
6128 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 6034 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
6129 | if (status != 0) | 6035 | if (status != 0) |
6130 | goto out; | 6036 | goto out; |
6131 | status = decode_getdeviceinfo(&xdr, res->pdev); | 6037 | status = decode_getdeviceinfo(xdr, res->pdev); |
6132 | out: | 6038 | out: |
6133 | return status; | 6039 | return status; |
6134 | } | 6040 | } |
@@ -6136,31 +6042,44 @@ out: | |||
6136 | /* | 6042 | /* |
6137 | * Decode LAYOUTGET response | 6043 | * Decode LAYOUTGET response |
6138 | */ | 6044 | */ |
6139 | static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, uint32_t *p, | 6045 | static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp, |
6046 | struct xdr_stream *xdr, | ||
6140 | struct nfs4_layoutget_res *res) | 6047 | struct nfs4_layoutget_res *res) |
6141 | { | 6048 | { |
6142 | struct xdr_stream xdr; | ||
6143 | struct compound_hdr hdr; | 6049 | struct compound_hdr hdr; |
6144 | int status; | 6050 | int status; |
6145 | 6051 | ||
6146 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 6052 | status = decode_compound_hdr(xdr, &hdr); |
6147 | status = decode_compound_hdr(&xdr, &hdr); | ||
6148 | if (status) | 6053 | if (status) |
6149 | goto out; | 6054 | goto out; |
6150 | status = decode_sequence(&xdr, &res->seq_res, rqstp); | 6055 | status = decode_sequence(xdr, &res->seq_res, rqstp); |
6151 | if (status) | 6056 | if (status) |
6152 | goto out; | 6057 | goto out; |
6153 | status = decode_putfh(&xdr); | 6058 | status = decode_putfh(xdr); |
6154 | if (status) | 6059 | if (status) |
6155 | goto out; | 6060 | goto out; |
6156 | status = decode_layoutget(&xdr, rqstp, res); | 6061 | status = decode_layoutget(xdr, rqstp, res); |
6157 | out: | 6062 | out: |
6158 | return status; | 6063 | return status; |
6159 | } | 6064 | } |
6160 | #endif /* CONFIG_NFS_V4_1 */ | 6065 | #endif /* CONFIG_NFS_V4_1 */ |
6161 | 6066 | ||
6162 | __be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, | 6067 | /** |
6163 | struct nfs_server *server, int plus) | 6068 | * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in |
6069 | * the local page cache. | ||
6070 | * @xdr: XDR stream where entry resides | ||
6071 | * @entry: buffer to fill in with entry data | ||
6072 | * @plus: boolean indicating whether this should be a readdirplus entry | ||
6073 | * | ||
6074 | * Returns zero if successful, otherwise a negative errno value is | ||
6075 | * returned. | ||
6076 | * | ||
6077 | * This function is not invoked during READDIR reply decoding, but | ||
6078 | * rather whenever an application invokes the getdents(2) system call | ||
6079 | * on a directory already in our cache. | ||
6080 | */ | ||
6081 | int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, | ||
6082 | int plus) | ||
6164 | { | 6083 | { |
6165 | uint32_t bitmap[2] = {0}; | 6084 | uint32_t bitmap[2] = {0}; |
6166 | uint32_t len; | 6085 | uint32_t len; |
@@ -6172,9 +6091,9 @@ __be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, | |||
6172 | if (unlikely(!p)) | 6091 | if (unlikely(!p)) |
6173 | goto out_overflow; | 6092 | goto out_overflow; |
6174 | if (!ntohl(*p++)) | 6093 | if (!ntohl(*p++)) |
6175 | return ERR_PTR(-EAGAIN); | 6094 | return -EAGAIN; |
6176 | entry->eof = 1; | 6095 | entry->eof = 1; |
6177 | return ERR_PTR(-EBADCOOKIE); | 6096 | return -EBADCOOKIE; |
6178 | } | 6097 | } |
6179 | 6098 | ||
6180 | p = xdr_inline_decode(xdr, 12); | 6099 | p = xdr_inline_decode(xdr, 12); |
@@ -6203,7 +6122,8 @@ __be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, | |||
6203 | if (decode_attr_length(xdr, &len, &p) < 0) | 6122 | if (decode_attr_length(xdr, &len, &p) < 0) |
6204 | goto out_overflow; | 6123 | goto out_overflow; |
6205 | 6124 | ||
6206 | if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, server, 1) < 0) | 6125 | if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh, |
6126 | entry->server, 1) < 0) | ||
6207 | goto out_overflow; | 6127 | goto out_overflow; |
6208 | if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) | 6128 | if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID) |
6209 | entry->ino = entry->fattr->fileid; | 6129 | entry->ino = entry->fattr->fileid; |
@@ -6215,17 +6135,11 @@ __be32 *nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, | |||
6215 | if (verify_attr_len(xdr, p, len) < 0) | 6135 | if (verify_attr_len(xdr, p, len) < 0) |
6216 | goto out_overflow; | 6136 | goto out_overflow; |
6217 | 6137 | ||
6218 | p = xdr_inline_peek(xdr, 8); | 6138 | return 0; |
6219 | if (p != NULL) | ||
6220 | entry->eof = !p[0] && p[1]; | ||
6221 | else | ||
6222 | entry->eof = 0; | ||
6223 | |||
6224 | return p; | ||
6225 | 6139 | ||
6226 | out_overflow: | 6140 | out_overflow: |
6227 | print_overflow_msg(__func__, xdr); | 6141 | print_overflow_msg(__func__, xdr); |
6228 | return ERR_PTR(-EAGAIN); | 6142 | return -EAGAIN; |
6229 | } | 6143 | } |
6230 | 6144 | ||
6231 | /* | 6145 | /* |
@@ -6301,8 +6215,8 @@ nfs4_stat_to_errno(int stat) | |||
6301 | #define PROC(proc, argtype, restype) \ | 6215 | #define PROC(proc, argtype, restype) \ |
6302 | [NFSPROC4_CLNT_##proc] = { \ | 6216 | [NFSPROC4_CLNT_##proc] = { \ |
6303 | .p_proc = NFSPROC4_COMPOUND, \ | 6217 | .p_proc = NFSPROC4_COMPOUND, \ |
6304 | .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \ | 6218 | .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \ |
6305 | .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \ | 6219 | .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \ |
6306 | .p_arglen = NFS4_##argtype##_sz, \ | 6220 | .p_arglen = NFS4_##argtype##_sz, \ |
6307 | .p_replen = NFS4_##restype##_sz, \ | 6221 | .p_replen = NFS4_##restype##_sz, \ |
6308 | .p_statidx = NFSPROC4_CLNT_##proc, \ | 6222 | .p_statidx = NFSPROC4_CLNT_##proc, \ |
@@ -6310,50 +6224,50 @@ nfs4_stat_to_errno(int stat) | |||
6310 | } | 6224 | } |
6311 | 6225 | ||
6312 | struct rpc_procinfo nfs4_procedures[] = { | 6226 | struct rpc_procinfo nfs4_procedures[] = { |
6313 | PROC(READ, enc_read, dec_read), | 6227 | PROC(READ, enc_read, dec_read), |
6314 | PROC(WRITE, enc_write, dec_write), | 6228 | PROC(WRITE, enc_write, dec_write), |
6315 | PROC(COMMIT, enc_commit, dec_commit), | 6229 | PROC(COMMIT, enc_commit, dec_commit), |
6316 | PROC(OPEN, enc_open, dec_open), | 6230 | PROC(OPEN, enc_open, dec_open), |
6317 | PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), | 6231 | PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm), |
6318 | PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), | 6232 | PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr), |
6319 | PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), | 6233 | PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade), |
6320 | PROC(CLOSE, enc_close, dec_close), | 6234 | PROC(CLOSE, enc_close, dec_close), |
6321 | PROC(SETATTR, enc_setattr, dec_setattr), | 6235 | PROC(SETATTR, enc_setattr, dec_setattr), |
6322 | PROC(FSINFO, enc_fsinfo, dec_fsinfo), | 6236 | PROC(FSINFO, enc_fsinfo, dec_fsinfo), |
6323 | PROC(RENEW, enc_renew, dec_renew), | 6237 | PROC(RENEW, enc_renew, dec_renew), |
6324 | PROC(SETCLIENTID, enc_setclientid, dec_setclientid), | 6238 | PROC(SETCLIENTID, enc_setclientid, dec_setclientid), |
6325 | PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), | 6239 | PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm), |
6326 | PROC(LOCK, enc_lock, dec_lock), | 6240 | PROC(LOCK, enc_lock, dec_lock), |
6327 | PROC(LOCKT, enc_lockt, dec_lockt), | 6241 | PROC(LOCKT, enc_lockt, dec_lockt), |
6328 | PROC(LOCKU, enc_locku, dec_locku), | 6242 | PROC(LOCKU, enc_locku, dec_locku), |
6329 | PROC(ACCESS, enc_access, dec_access), | 6243 | PROC(ACCESS, enc_access, dec_access), |
6330 | PROC(GETATTR, enc_getattr, dec_getattr), | 6244 | PROC(GETATTR, enc_getattr, dec_getattr), |
6331 | PROC(LOOKUP, enc_lookup, dec_lookup), | 6245 | PROC(LOOKUP, enc_lookup, dec_lookup), |
6332 | PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), | 6246 | PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root), |
6333 | PROC(REMOVE, enc_remove, dec_remove), | 6247 | PROC(REMOVE, enc_remove, dec_remove), |
6334 | PROC(RENAME, enc_rename, dec_rename), | 6248 | PROC(RENAME, enc_rename, dec_rename), |
6335 | PROC(LINK, enc_link, dec_link), | 6249 | PROC(LINK, enc_link, dec_link), |
6336 | PROC(SYMLINK, enc_symlink, dec_symlink), | 6250 | PROC(SYMLINK, enc_symlink, dec_symlink), |
6337 | PROC(CREATE, enc_create, dec_create), | 6251 | PROC(CREATE, enc_create, dec_create), |
6338 | PROC(PATHCONF, enc_pathconf, dec_pathconf), | 6252 | PROC(PATHCONF, enc_pathconf, dec_pathconf), |
6339 | PROC(STATFS, enc_statfs, dec_statfs), | 6253 | PROC(STATFS, enc_statfs, dec_statfs), |
6340 | PROC(READLINK, enc_readlink, dec_readlink), | 6254 | PROC(READLINK, enc_readlink, dec_readlink), |
6341 | PROC(READDIR, enc_readdir, dec_readdir), | 6255 | PROC(READDIR, enc_readdir, dec_readdir), |
6342 | PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), | 6256 | PROC(SERVER_CAPS, enc_server_caps, dec_server_caps), |
6343 | PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), | 6257 | PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn), |
6344 | PROC(GETACL, enc_getacl, dec_getacl), | 6258 | PROC(GETACL, enc_getacl, dec_getacl), |
6345 | PROC(SETACL, enc_setacl, dec_setacl), | 6259 | PROC(SETACL, enc_setacl, dec_setacl), |
6346 | PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), | 6260 | PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations), |
6347 | PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), | 6261 | PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner), |
6348 | #if defined(CONFIG_NFS_V4_1) | 6262 | #if defined(CONFIG_NFS_V4_1) |
6349 | PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), | 6263 | PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id), |
6350 | PROC(CREATE_SESSION, enc_create_session, dec_create_session), | 6264 | PROC(CREATE_SESSION, enc_create_session, dec_create_session), |
6351 | PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), | 6265 | PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session), |
6352 | PROC(SEQUENCE, enc_sequence, dec_sequence), | 6266 | PROC(SEQUENCE, enc_sequence, dec_sequence), |
6353 | PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), | 6267 | PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time), |
6354 | PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), | 6268 | PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete), |
6355 | PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), | 6269 | PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo), |
6356 | PROC(LAYOUTGET, enc_layoutget, dec_layoutget), | 6270 | PROC(LAYOUTGET, enc_layoutget, dec_layoutget), |
6357 | #endif /* CONFIG_NFS_V4_1 */ | 6271 | #endif /* CONFIG_NFS_V4_1 */ |
6358 | }; | 6272 | }; |
6359 | 6273 | ||
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c index b68536cc9046..e1164e3f9e69 100644 --- a/fs/nfs/pagelist.c +++ b/fs/nfs/pagelist.c | |||
@@ -26,12 +26,9 @@ static struct kmem_cache *nfs_page_cachep; | |||
26 | static inline struct nfs_page * | 26 | static inline struct nfs_page * |
27 | nfs_page_alloc(void) | 27 | nfs_page_alloc(void) |
28 | { | 28 | { |
29 | struct nfs_page *p; | 29 | struct nfs_page *p = kmem_cache_zalloc(nfs_page_cachep, GFP_KERNEL); |
30 | p = kmem_cache_alloc(nfs_page_cachep, GFP_KERNEL); | 30 | if (p) |
31 | if (p) { | ||
32 | memset(p, 0, sizeof(*p)); | ||
33 | INIT_LIST_HEAD(&p->wb_list); | 31 | INIT_LIST_HEAD(&p->wb_list); |
34 | } | ||
35 | return p; | 32 | return p; |
36 | } | 33 | } |
37 | 34 | ||
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c index db773428f95f..bc4089769735 100644 --- a/fs/nfs/pnfs.c +++ b/fs/nfs/pnfs.c | |||
@@ -177,105 +177,149 @@ EXPORT_SYMBOL_GPL(pnfs_unregister_layoutdriver); | |||
177 | * pNFS client layout cache | 177 | * pNFS client layout cache |
178 | */ | 178 | */ |
179 | 179 | ||
180 | /* Need to hold i_lock if caller does not already hold reference */ | ||
181 | void | ||
182 | get_layout_hdr(struct pnfs_layout_hdr *lo) | ||
183 | { | ||
184 | atomic_inc(&lo->plh_refcount); | ||
185 | } | ||
186 | |||
180 | static void | 187 | static void |
181 | get_layout_hdr_locked(struct pnfs_layout_hdr *lo) | 188 | destroy_layout_hdr(struct pnfs_layout_hdr *lo) |
182 | { | 189 | { |
183 | assert_spin_locked(&lo->inode->i_lock); | 190 | dprintk("%s: freeing layout cache %p\n", __func__, lo); |
184 | lo->refcount++; | 191 | BUG_ON(!list_empty(&lo->plh_layouts)); |
192 | NFS_I(lo->plh_inode)->layout = NULL; | ||
193 | kfree(lo); | ||
185 | } | 194 | } |
186 | 195 | ||
187 | static void | 196 | static void |
188 | put_layout_hdr_locked(struct pnfs_layout_hdr *lo) | 197 | put_layout_hdr_locked(struct pnfs_layout_hdr *lo) |
189 | { | 198 | { |
190 | assert_spin_locked(&lo->inode->i_lock); | 199 | if (atomic_dec_and_test(&lo->plh_refcount)) |
191 | BUG_ON(lo->refcount == 0); | 200 | destroy_layout_hdr(lo); |
192 | |||
193 | lo->refcount--; | ||
194 | if (!lo->refcount) { | ||
195 | dprintk("%s: freeing layout cache %p\n", __func__, lo); | ||
196 | BUG_ON(!list_empty(&lo->layouts)); | ||
197 | NFS_I(lo->inode)->layout = NULL; | ||
198 | kfree(lo); | ||
199 | } | ||
200 | } | 201 | } |
201 | 202 | ||
202 | void | 203 | void |
203 | put_layout_hdr(struct inode *inode) | 204 | put_layout_hdr(struct pnfs_layout_hdr *lo) |
204 | { | 205 | { |
205 | spin_lock(&inode->i_lock); | 206 | struct inode *inode = lo->plh_inode; |
206 | put_layout_hdr_locked(NFS_I(inode)->layout); | 207 | |
207 | spin_unlock(&inode->i_lock); | 208 | if (atomic_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) { |
209 | destroy_layout_hdr(lo); | ||
210 | spin_unlock(&inode->i_lock); | ||
211 | } | ||
208 | } | 212 | } |
209 | 213 | ||
210 | static void | 214 | static void |
211 | init_lseg(struct pnfs_layout_hdr *lo, struct pnfs_layout_segment *lseg) | 215 | init_lseg(struct pnfs_layout_hdr *lo, struct pnfs_layout_segment *lseg) |
212 | { | 216 | { |
213 | INIT_LIST_HEAD(&lseg->fi_list); | 217 | INIT_LIST_HEAD(&lseg->pls_list); |
214 | kref_init(&lseg->kref); | 218 | atomic_set(&lseg->pls_refcount, 1); |
215 | lseg->layout = lo; | 219 | smp_mb(); |
220 | set_bit(NFS_LSEG_VALID, &lseg->pls_flags); | ||
221 | lseg->pls_layout = lo; | ||
216 | } | 222 | } |
217 | 223 | ||
218 | /* Called without i_lock held, as the free_lseg call may sleep */ | 224 | static void free_lseg(struct pnfs_layout_segment *lseg) |
219 | static void | ||
220 | destroy_lseg(struct kref *kref) | ||
221 | { | 225 | { |
222 | struct pnfs_layout_segment *lseg = | 226 | struct inode *ino = lseg->pls_layout->plh_inode; |
223 | container_of(kref, struct pnfs_layout_segment, kref); | ||
224 | struct inode *ino = lseg->layout->inode; | ||
225 | 227 | ||
226 | dprintk("--> %s\n", __func__); | ||
227 | NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg); | 228 | NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg); |
228 | /* Matched by get_layout_hdr_locked in pnfs_insert_layout */ | 229 | /* Matched by get_layout_hdr in pnfs_insert_layout */ |
229 | put_layout_hdr(ino); | 230 | put_layout_hdr(NFS_I(ino)->layout); |
230 | } | 231 | } |
231 | 232 | ||
232 | static void | 233 | /* The use of tmp_list is necessary because pnfs_curr_ld->free_lseg |
233 | put_lseg(struct pnfs_layout_segment *lseg) | 234 | * could sleep, so must be called outside of the lock. |
235 | * Returns 1 if object was removed, otherwise return 0. | ||
236 | */ | ||
237 | static int | ||
238 | put_lseg_locked(struct pnfs_layout_segment *lseg, | ||
239 | struct list_head *tmp_list) | ||
240 | { | ||
241 | dprintk("%s: lseg %p ref %d valid %d\n", __func__, lseg, | ||
242 | atomic_read(&lseg->pls_refcount), | ||
243 | test_bit(NFS_LSEG_VALID, &lseg->pls_flags)); | ||
244 | if (atomic_dec_and_test(&lseg->pls_refcount)) { | ||
245 | struct inode *ino = lseg->pls_layout->plh_inode; | ||
246 | |||
247 | BUG_ON(test_bit(NFS_LSEG_VALID, &lseg->pls_flags)); | ||
248 | list_del(&lseg->pls_list); | ||
249 | if (list_empty(&lseg->pls_layout->plh_segs)) { | ||
250 | struct nfs_client *clp; | ||
251 | |||
252 | clp = NFS_SERVER(ino)->nfs_client; | ||
253 | spin_lock(&clp->cl_lock); | ||
254 | /* List does not take a reference, so no need for put here */ | ||
255 | list_del_init(&lseg->pls_layout->plh_layouts); | ||
256 | spin_unlock(&clp->cl_lock); | ||
257 | clear_bit(NFS_LAYOUT_BULK_RECALL, &lseg->pls_layout->plh_flags); | ||
258 | } | ||
259 | rpc_wake_up(&NFS_SERVER(ino)->roc_rpcwaitq); | ||
260 | list_add(&lseg->pls_list, tmp_list); | ||
261 | return 1; | ||
262 | } | ||
263 | return 0; | ||
264 | } | ||
265 | |||
266 | static bool | ||
267 | should_free_lseg(u32 lseg_iomode, u32 recall_iomode) | ||
234 | { | 268 | { |
235 | if (!lseg) | 269 | return (recall_iomode == IOMODE_ANY || |
236 | return; | 270 | lseg_iomode == recall_iomode); |
271 | } | ||
237 | 272 | ||
238 | dprintk("%s: lseg %p ref %d\n", __func__, lseg, | 273 | /* Returns 1 if lseg is removed from list, 0 otherwise */ |
239 | atomic_read(&lseg->kref.refcount)); | 274 | static int mark_lseg_invalid(struct pnfs_layout_segment *lseg, |
240 | kref_put(&lseg->kref, destroy_lseg); | 275 | struct list_head *tmp_list) |
276 | { | ||
277 | int rv = 0; | ||
278 | |||
279 | if (test_and_clear_bit(NFS_LSEG_VALID, &lseg->pls_flags)) { | ||
280 | /* Remove the reference keeping the lseg in the | ||
281 | * list. It will now be removed when all | ||
282 | * outstanding io is finished. | ||
283 | */ | ||
284 | rv = put_lseg_locked(lseg, tmp_list); | ||
285 | } | ||
286 | return rv; | ||
241 | } | 287 | } |
242 | 288 | ||
243 | static void | 289 | /* Returns count of number of matching invalid lsegs remaining in list |
244 | pnfs_clear_lseg_list(struct pnfs_layout_hdr *lo, struct list_head *tmp_list) | 290 | * after call. |
291 | */ | ||
292 | int | ||
293 | mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo, | ||
294 | struct list_head *tmp_list, | ||
295 | u32 iomode) | ||
245 | { | 296 | { |
246 | struct pnfs_layout_segment *lseg, *next; | 297 | struct pnfs_layout_segment *lseg, *next; |
247 | struct nfs_client *clp; | 298 | int invalid = 0, removed = 0; |
248 | 299 | ||
249 | dprintk("%s:Begin lo %p\n", __func__, lo); | 300 | dprintk("%s:Begin lo %p\n", __func__, lo); |
250 | 301 | ||
251 | assert_spin_locked(&lo->inode->i_lock); | 302 | list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list) |
252 | list_for_each_entry_safe(lseg, next, &lo->segs, fi_list) { | 303 | if (should_free_lseg(lseg->pls_range.iomode, iomode)) { |
253 | dprintk("%s: freeing lseg %p\n", __func__, lseg); | 304 | dprintk("%s: freeing lseg %p iomode %d " |
254 | list_move(&lseg->fi_list, tmp_list); | 305 | "offset %llu length %llu\n", __func__, |
255 | } | 306 | lseg, lseg->pls_range.iomode, lseg->pls_range.offset, |
256 | clp = NFS_SERVER(lo->inode)->nfs_client; | 307 | lseg->pls_range.length); |
257 | spin_lock(&clp->cl_lock); | 308 | invalid++; |
258 | /* List does not take a reference, so no need for put here */ | 309 | removed += mark_lseg_invalid(lseg, tmp_list); |
259 | list_del_init(&lo->layouts); | 310 | } |
260 | spin_unlock(&clp->cl_lock); | 311 | dprintk("%s:Return %i\n", __func__, invalid - removed); |
261 | write_seqlock(&lo->seqlock); | 312 | return invalid - removed; |
262 | clear_bit(NFS_LAYOUT_STATEID_SET, &lo->state); | ||
263 | write_sequnlock(&lo->seqlock); | ||
264 | |||
265 | dprintk("%s:Return\n", __func__); | ||
266 | } | 313 | } |
267 | 314 | ||
268 | static void | 315 | void |
269 | pnfs_free_lseg_list(struct list_head *tmp_list) | 316 | pnfs_free_lseg_list(struct list_head *free_me) |
270 | { | 317 | { |
271 | struct pnfs_layout_segment *lseg; | 318 | struct pnfs_layout_segment *lseg, *tmp; |
272 | 319 | ||
273 | while (!list_empty(tmp_list)) { | 320 | list_for_each_entry_safe(lseg, tmp, free_me, pls_list) { |
274 | lseg = list_entry(tmp_list->next, struct pnfs_layout_segment, | 321 | list_del(&lseg->pls_list); |
275 | fi_list); | 322 | free_lseg(lseg); |
276 | dprintk("%s calling put_lseg on %p\n", __func__, lseg); | ||
277 | list_del(&lseg->fi_list); | ||
278 | put_lseg(lseg); | ||
279 | } | 323 | } |
280 | } | 324 | } |
281 | 325 | ||
@@ -288,7 +332,8 @@ pnfs_destroy_layout(struct nfs_inode *nfsi) | |||
288 | spin_lock(&nfsi->vfs_inode.i_lock); | 332 | spin_lock(&nfsi->vfs_inode.i_lock); |
289 | lo = nfsi->layout; | 333 | lo = nfsi->layout; |
290 | if (lo) { | 334 | if (lo) { |
291 | pnfs_clear_lseg_list(lo, &tmp_list); | 335 | set_bit(NFS_LAYOUT_DESTROYED, &nfsi->layout->plh_flags); |
336 | mark_matching_lsegs_invalid(lo, &tmp_list, IOMODE_ANY); | ||
292 | /* Matched by refcount set to 1 in alloc_init_layout_hdr */ | 337 | /* Matched by refcount set to 1 in alloc_init_layout_hdr */ |
293 | put_layout_hdr_locked(lo); | 338 | put_layout_hdr_locked(lo); |
294 | } | 339 | } |
@@ -312,76 +357,80 @@ pnfs_destroy_all_layouts(struct nfs_client *clp) | |||
312 | 357 | ||
313 | while (!list_empty(&tmp_list)) { | 358 | while (!list_empty(&tmp_list)) { |
314 | lo = list_entry(tmp_list.next, struct pnfs_layout_hdr, | 359 | lo = list_entry(tmp_list.next, struct pnfs_layout_hdr, |
315 | layouts); | 360 | plh_layouts); |
316 | dprintk("%s freeing layout for inode %lu\n", __func__, | 361 | dprintk("%s freeing layout for inode %lu\n", __func__, |
317 | lo->inode->i_ino); | 362 | lo->plh_inode->i_ino); |
318 | pnfs_destroy_layout(NFS_I(lo->inode)); | 363 | pnfs_destroy_layout(NFS_I(lo->plh_inode)); |
319 | } | 364 | } |
320 | } | 365 | } |
321 | 366 | ||
322 | /* update lo->stateid with new if is more recent | 367 | /* update lo->plh_stateid with new if is more recent */ |
323 | * | 368 | void |
324 | * lo->stateid could be the open stateid, in which case we just use what given. | 369 | pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new, |
325 | */ | 370 | bool update_barrier) |
326 | static void | 371 | { |
327 | pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, | 372 | u32 oldseq, newseq; |
328 | const nfs4_stateid *new) | 373 | |
329 | { | 374 | oldseq = be32_to_cpu(lo->plh_stateid.stateid.seqid); |
330 | nfs4_stateid *old = &lo->stateid; | 375 | newseq = be32_to_cpu(new->stateid.seqid); |
331 | bool overwrite = false; | 376 | if ((int)(newseq - oldseq) > 0) { |
332 | 377 | memcpy(&lo->plh_stateid, &new->stateid, sizeof(new->stateid)); | |
333 | write_seqlock(&lo->seqlock); | 378 | if (update_barrier) { |
334 | if (!test_bit(NFS_LAYOUT_STATEID_SET, &lo->state) || | 379 | u32 new_barrier = be32_to_cpu(new->stateid.seqid); |
335 | memcmp(old->stateid.other, new->stateid.other, sizeof(new->stateid.other))) | 380 | |
336 | overwrite = true; | 381 | if ((int)(new_barrier - lo->plh_barrier)) |
337 | else { | 382 | lo->plh_barrier = new_barrier; |
338 | u32 oldseq, newseq; | 383 | } else { |
339 | 384 | /* Because of wraparound, we want to keep the barrier | |
340 | oldseq = be32_to_cpu(old->stateid.seqid); | 385 | * "close" to the current seqids. It needs to be |
341 | newseq = be32_to_cpu(new->stateid.seqid); | 386 | * within 2**31 to count as "behind", so if it |
342 | if ((int)(newseq - oldseq) > 0) | 387 | * gets too near that limit, give us a litle leeway |
343 | overwrite = true; | 388 | * and bring it to within 2**30. |
389 | * NOTE - and yes, this is all unsigned arithmetic. | ||
390 | */ | ||
391 | if (unlikely((newseq - lo->plh_barrier) > (3 << 29))) | ||
392 | lo->plh_barrier = newseq - (1 << 30); | ||
393 | } | ||
344 | } | 394 | } |
345 | if (overwrite) | ||
346 | memcpy(&old->stateid, &new->stateid, sizeof(new->stateid)); | ||
347 | write_sequnlock(&lo->seqlock); | ||
348 | } | 395 | } |
349 | 396 | ||
350 | static void | 397 | /* lget is set to 1 if called from inside send_layoutget call chain */ |
351 | pnfs_layout_from_open_stateid(struct pnfs_layout_hdr *lo, | 398 | static bool |
352 | struct nfs4_state *state) | 399 | pnfs_layoutgets_blocked(struct pnfs_layout_hdr *lo, nfs4_stateid *stateid, |
400 | int lget) | ||
353 | { | 401 | { |
354 | int seq; | 402 | if ((stateid) && |
355 | 403 | (int)(lo->plh_barrier - be32_to_cpu(stateid->stateid.seqid)) >= 0) | |
356 | dprintk("--> %s\n", __func__); | 404 | return true; |
357 | write_seqlock(&lo->seqlock); | 405 | return lo->plh_block_lgets || |
358 | do { | 406 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) || |
359 | seq = read_seqbegin(&state->seqlock); | 407 | (list_empty(&lo->plh_segs) && |
360 | memcpy(lo->stateid.data, state->stateid.data, | 408 | (atomic_read(&lo->plh_outstanding) > lget)); |
361 | sizeof(state->stateid.data)); | ||
362 | } while (read_seqretry(&state->seqlock, seq)); | ||
363 | set_bit(NFS_LAYOUT_STATEID_SET, &lo->state); | ||
364 | write_sequnlock(&lo->seqlock); | ||
365 | dprintk("<-- %s\n", __func__); | ||
366 | } | 409 | } |
367 | 410 | ||
368 | void | 411 | int |
369 | pnfs_get_layout_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo, | 412 | pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo, |
370 | struct nfs4_state *open_state) | 413 | struct nfs4_state *open_state) |
371 | { | 414 | { |
372 | int seq; | 415 | int status = 0; |
373 | 416 | ||
374 | dprintk("--> %s\n", __func__); | 417 | dprintk("--> %s\n", __func__); |
375 | do { | 418 | spin_lock(&lo->plh_inode->i_lock); |
376 | seq = read_seqbegin(&lo->seqlock); | 419 | if (pnfs_layoutgets_blocked(lo, NULL, 1)) { |
377 | if (!test_bit(NFS_LAYOUT_STATEID_SET, &lo->state)) { | 420 | status = -EAGAIN; |
378 | /* This will trigger retry of the read */ | 421 | } else if (list_empty(&lo->plh_segs)) { |
379 | pnfs_layout_from_open_stateid(lo, open_state); | 422 | int seq; |
380 | } else | 423 | |
381 | memcpy(dst->data, lo->stateid.data, | 424 | do { |
382 | sizeof(lo->stateid.data)); | 425 | seq = read_seqbegin(&open_state->seqlock); |
383 | } while (read_seqretry(&lo->seqlock, seq)); | 426 | memcpy(dst->data, open_state->stateid.data, |
427 | sizeof(open_state->stateid.data)); | ||
428 | } while (read_seqretry(&open_state->seqlock, seq)); | ||
429 | } else | ||
430 | memcpy(dst->data, lo->plh_stateid.data, sizeof(lo->plh_stateid.data)); | ||
431 | spin_unlock(&lo->plh_inode->i_lock); | ||
384 | dprintk("<-- %s\n", __func__); | 432 | dprintk("<-- %s\n", __func__); |
433 | return status; | ||
385 | } | 434 | } |
386 | 435 | ||
387 | /* | 436 | /* |
@@ -395,7 +444,7 @@ send_layoutget(struct pnfs_layout_hdr *lo, | |||
395 | struct nfs_open_context *ctx, | 444 | struct nfs_open_context *ctx, |
396 | u32 iomode) | 445 | u32 iomode) |
397 | { | 446 | { |
398 | struct inode *ino = lo->inode; | 447 | struct inode *ino = lo->plh_inode; |
399 | struct nfs_server *server = NFS_SERVER(ino); | 448 | struct nfs_server *server = NFS_SERVER(ino); |
400 | struct nfs4_layoutget *lgp; | 449 | struct nfs4_layoutget *lgp; |
401 | struct pnfs_layout_segment *lseg = NULL; | 450 | struct pnfs_layout_segment *lseg = NULL; |
@@ -404,10 +453,8 @@ send_layoutget(struct pnfs_layout_hdr *lo, | |||
404 | 453 | ||
405 | BUG_ON(ctx == NULL); | 454 | BUG_ON(ctx == NULL); |
406 | lgp = kzalloc(sizeof(*lgp), GFP_KERNEL); | 455 | lgp = kzalloc(sizeof(*lgp), GFP_KERNEL); |
407 | if (lgp == NULL) { | 456 | if (lgp == NULL) |
408 | put_layout_hdr(lo->inode); | ||
409 | return NULL; | 457 | return NULL; |
410 | } | ||
411 | lgp->args.minlength = NFS4_MAX_UINT64; | 458 | lgp->args.minlength = NFS4_MAX_UINT64; |
412 | lgp->args.maxcount = PNFS_LAYOUT_MAXSIZE; | 459 | lgp->args.maxcount = PNFS_LAYOUT_MAXSIZE; |
413 | lgp->args.range.iomode = iomode; | 460 | lgp->args.range.iomode = iomode; |
@@ -424,11 +471,88 @@ send_layoutget(struct pnfs_layout_hdr *lo, | |||
424 | nfs4_proc_layoutget(lgp); | 471 | nfs4_proc_layoutget(lgp); |
425 | if (!lseg) { | 472 | if (!lseg) { |
426 | /* remember that LAYOUTGET failed and suspend trying */ | 473 | /* remember that LAYOUTGET failed and suspend trying */ |
427 | set_bit(lo_fail_bit(iomode), &lo->state); | 474 | set_bit(lo_fail_bit(iomode), &lo->plh_flags); |
428 | } | 475 | } |
429 | return lseg; | 476 | return lseg; |
430 | } | 477 | } |
431 | 478 | ||
479 | bool pnfs_roc(struct inode *ino) | ||
480 | { | ||
481 | struct pnfs_layout_hdr *lo; | ||
482 | struct pnfs_layout_segment *lseg, *tmp; | ||
483 | LIST_HEAD(tmp_list); | ||
484 | bool found = false; | ||
485 | |||
486 | spin_lock(&ino->i_lock); | ||
487 | lo = NFS_I(ino)->layout; | ||
488 | if (!lo || !test_and_clear_bit(NFS_LAYOUT_ROC, &lo->plh_flags) || | ||
489 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) | ||
490 | goto out_nolayout; | ||
491 | list_for_each_entry_safe(lseg, tmp, &lo->plh_segs, pls_list) | ||
492 | if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) { | ||
493 | mark_lseg_invalid(lseg, &tmp_list); | ||
494 | found = true; | ||
495 | } | ||
496 | if (!found) | ||
497 | goto out_nolayout; | ||
498 | lo->plh_block_lgets++; | ||
499 | get_layout_hdr(lo); /* matched in pnfs_roc_release */ | ||
500 | spin_unlock(&ino->i_lock); | ||
501 | pnfs_free_lseg_list(&tmp_list); | ||
502 | return true; | ||
503 | |||
504 | out_nolayout: | ||
505 | spin_unlock(&ino->i_lock); | ||
506 | return false; | ||
507 | } | ||
508 | |||
509 | void pnfs_roc_release(struct inode *ino) | ||
510 | { | ||
511 | struct pnfs_layout_hdr *lo; | ||
512 | |||
513 | spin_lock(&ino->i_lock); | ||
514 | lo = NFS_I(ino)->layout; | ||
515 | lo->plh_block_lgets--; | ||
516 | put_layout_hdr_locked(lo); | ||
517 | spin_unlock(&ino->i_lock); | ||
518 | } | ||
519 | |||
520 | void pnfs_roc_set_barrier(struct inode *ino, u32 barrier) | ||
521 | { | ||
522 | struct pnfs_layout_hdr *lo; | ||
523 | |||
524 | spin_lock(&ino->i_lock); | ||
525 | lo = NFS_I(ino)->layout; | ||
526 | if ((int)(barrier - lo->plh_barrier) > 0) | ||
527 | lo->plh_barrier = barrier; | ||
528 | spin_unlock(&ino->i_lock); | ||
529 | } | ||
530 | |||
531 | bool pnfs_roc_drain(struct inode *ino, u32 *barrier) | ||
532 | { | ||
533 | struct nfs_inode *nfsi = NFS_I(ino); | ||
534 | struct pnfs_layout_segment *lseg; | ||
535 | bool found = false; | ||
536 | |||
537 | spin_lock(&ino->i_lock); | ||
538 | list_for_each_entry(lseg, &nfsi->layout->plh_segs, pls_list) | ||
539 | if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) { | ||
540 | found = true; | ||
541 | break; | ||
542 | } | ||
543 | if (!found) { | ||
544 | struct pnfs_layout_hdr *lo = nfsi->layout; | ||
545 | u32 current_seqid = be32_to_cpu(lo->plh_stateid.stateid.seqid); | ||
546 | |||
547 | /* Since close does not return a layout stateid for use as | ||
548 | * a barrier, we choose the worst-case barrier. | ||
549 | */ | ||
550 | *barrier = current_seqid + atomic_read(&lo->plh_outstanding); | ||
551 | } | ||
552 | spin_unlock(&ino->i_lock); | ||
553 | return found; | ||
554 | } | ||
555 | |||
432 | /* | 556 | /* |
433 | * Compare two layout segments for sorting into layout cache. | 557 | * Compare two layout segments for sorting into layout cache. |
434 | * We want to preferentially return RW over RO layouts, so ensure those | 558 | * We want to preferentially return RW over RO layouts, so ensure those |
@@ -450,37 +574,29 @@ pnfs_insert_layout(struct pnfs_layout_hdr *lo, | |||
450 | 574 | ||
451 | dprintk("%s:Begin\n", __func__); | 575 | dprintk("%s:Begin\n", __func__); |
452 | 576 | ||
453 | assert_spin_locked(&lo->inode->i_lock); | 577 | assert_spin_locked(&lo->plh_inode->i_lock); |
454 | if (list_empty(&lo->segs)) { | 578 | list_for_each_entry(lp, &lo->plh_segs, pls_list) { |
455 | struct nfs_client *clp = NFS_SERVER(lo->inode)->nfs_client; | 579 | if (cmp_layout(lp->pls_range.iomode, lseg->pls_range.iomode) > 0) |
456 | |||
457 | spin_lock(&clp->cl_lock); | ||
458 | BUG_ON(!list_empty(&lo->layouts)); | ||
459 | list_add_tail(&lo->layouts, &clp->cl_layouts); | ||
460 | spin_unlock(&clp->cl_lock); | ||
461 | } | ||
462 | list_for_each_entry(lp, &lo->segs, fi_list) { | ||
463 | if (cmp_layout(lp->range.iomode, lseg->range.iomode) > 0) | ||
464 | continue; | 580 | continue; |
465 | list_add_tail(&lseg->fi_list, &lp->fi_list); | 581 | list_add_tail(&lseg->pls_list, &lp->pls_list); |
466 | dprintk("%s: inserted lseg %p " | 582 | dprintk("%s: inserted lseg %p " |
467 | "iomode %d offset %llu length %llu before " | 583 | "iomode %d offset %llu length %llu before " |
468 | "lp %p iomode %d offset %llu length %llu\n", | 584 | "lp %p iomode %d offset %llu length %llu\n", |
469 | __func__, lseg, lseg->range.iomode, | 585 | __func__, lseg, lseg->pls_range.iomode, |
470 | lseg->range.offset, lseg->range.length, | 586 | lseg->pls_range.offset, lseg->pls_range.length, |
471 | lp, lp->range.iomode, lp->range.offset, | 587 | lp, lp->pls_range.iomode, lp->pls_range.offset, |
472 | lp->range.length); | 588 | lp->pls_range.length); |
473 | found = 1; | 589 | found = 1; |
474 | break; | 590 | break; |
475 | } | 591 | } |
476 | if (!found) { | 592 | if (!found) { |
477 | list_add_tail(&lseg->fi_list, &lo->segs); | 593 | list_add_tail(&lseg->pls_list, &lo->plh_segs); |
478 | dprintk("%s: inserted lseg %p " | 594 | dprintk("%s: inserted lseg %p " |
479 | "iomode %d offset %llu length %llu at tail\n", | 595 | "iomode %d offset %llu length %llu at tail\n", |
480 | __func__, lseg, lseg->range.iomode, | 596 | __func__, lseg, lseg->pls_range.iomode, |
481 | lseg->range.offset, lseg->range.length); | 597 | lseg->pls_range.offset, lseg->pls_range.length); |
482 | } | 598 | } |
483 | get_layout_hdr_locked(lo); | 599 | get_layout_hdr(lo); |
484 | 600 | ||
485 | dprintk("%s:Return\n", __func__); | 601 | dprintk("%s:Return\n", __func__); |
486 | } | 602 | } |
@@ -493,11 +609,11 @@ alloc_init_layout_hdr(struct inode *ino) | |||
493 | lo = kzalloc(sizeof(struct pnfs_layout_hdr), GFP_KERNEL); | 609 | lo = kzalloc(sizeof(struct pnfs_layout_hdr), GFP_KERNEL); |
494 | if (!lo) | 610 | if (!lo) |
495 | return NULL; | 611 | return NULL; |
496 | lo->refcount = 1; | 612 | atomic_set(&lo->plh_refcount, 1); |
497 | INIT_LIST_HEAD(&lo->layouts); | 613 | INIT_LIST_HEAD(&lo->plh_layouts); |
498 | INIT_LIST_HEAD(&lo->segs); | 614 | INIT_LIST_HEAD(&lo->plh_segs); |
499 | seqlock_init(&lo->seqlock); | 615 | INIT_LIST_HEAD(&lo->plh_bulk_recall); |
500 | lo->inode = ino; | 616 | lo->plh_inode = ino; |
501 | return lo; | 617 | return lo; |
502 | } | 618 | } |
503 | 619 | ||
@@ -510,9 +626,12 @@ pnfs_find_alloc_layout(struct inode *ino) | |||
510 | dprintk("%s Begin ino=%p layout=%p\n", __func__, ino, nfsi->layout); | 626 | dprintk("%s Begin ino=%p layout=%p\n", __func__, ino, nfsi->layout); |
511 | 627 | ||
512 | assert_spin_locked(&ino->i_lock); | 628 | assert_spin_locked(&ino->i_lock); |
513 | if (nfsi->layout) | 629 | if (nfsi->layout) { |
514 | return nfsi->layout; | 630 | if (test_bit(NFS_LAYOUT_DESTROYED, &nfsi->layout->plh_flags)) |
515 | 631 | return NULL; | |
632 | else | ||
633 | return nfsi->layout; | ||
634 | } | ||
516 | spin_unlock(&ino->i_lock); | 635 | spin_unlock(&ino->i_lock); |
517 | new = alloc_init_layout_hdr(ino); | 636 | new = alloc_init_layout_hdr(ino); |
518 | spin_lock(&ino->i_lock); | 637 | spin_lock(&ino->i_lock); |
@@ -538,31 +657,32 @@ pnfs_find_alloc_layout(struct inode *ino) | |||
538 | static int | 657 | static int |
539 | is_matching_lseg(struct pnfs_layout_segment *lseg, u32 iomode) | 658 | is_matching_lseg(struct pnfs_layout_segment *lseg, u32 iomode) |
540 | { | 659 | { |
541 | return (iomode != IOMODE_RW || lseg->range.iomode == IOMODE_RW); | 660 | return (iomode != IOMODE_RW || lseg->pls_range.iomode == IOMODE_RW); |
542 | } | 661 | } |
543 | 662 | ||
544 | /* | 663 | /* |
545 | * lookup range in layout | 664 | * lookup range in layout |
546 | */ | 665 | */ |
547 | static struct pnfs_layout_segment * | 666 | static struct pnfs_layout_segment * |
548 | pnfs_has_layout(struct pnfs_layout_hdr *lo, u32 iomode) | 667 | pnfs_find_lseg(struct pnfs_layout_hdr *lo, u32 iomode) |
549 | { | 668 | { |
550 | struct pnfs_layout_segment *lseg, *ret = NULL; | 669 | struct pnfs_layout_segment *lseg, *ret = NULL; |
551 | 670 | ||
552 | dprintk("%s:Begin\n", __func__); | 671 | dprintk("%s:Begin\n", __func__); |
553 | 672 | ||
554 | assert_spin_locked(&lo->inode->i_lock); | 673 | assert_spin_locked(&lo->plh_inode->i_lock); |
555 | list_for_each_entry(lseg, &lo->segs, fi_list) { | 674 | list_for_each_entry(lseg, &lo->plh_segs, pls_list) { |
556 | if (is_matching_lseg(lseg, iomode)) { | 675 | if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags) && |
676 | is_matching_lseg(lseg, iomode)) { | ||
557 | ret = lseg; | 677 | ret = lseg; |
558 | break; | 678 | break; |
559 | } | 679 | } |
560 | if (cmp_layout(iomode, lseg->range.iomode) > 0) | 680 | if (cmp_layout(iomode, lseg->pls_range.iomode) > 0) |
561 | break; | 681 | break; |
562 | } | 682 | } |
563 | 683 | ||
564 | dprintk("%s:Return lseg %p ref %d\n", | 684 | dprintk("%s:Return lseg %p ref %d\n", |
565 | __func__, ret, ret ? atomic_read(&ret->kref.refcount) : 0); | 685 | __func__, ret, ret ? atomic_read(&ret->pls_refcount) : 0); |
566 | return ret; | 686 | return ret; |
567 | } | 687 | } |
568 | 688 | ||
@@ -576,6 +696,7 @@ pnfs_update_layout(struct inode *ino, | |||
576 | enum pnfs_iomode iomode) | 696 | enum pnfs_iomode iomode) |
577 | { | 697 | { |
578 | struct nfs_inode *nfsi = NFS_I(ino); | 698 | struct nfs_inode *nfsi = NFS_I(ino); |
699 | struct nfs_client *clp = NFS_SERVER(ino)->nfs_client; | ||
579 | struct pnfs_layout_hdr *lo; | 700 | struct pnfs_layout_hdr *lo; |
580 | struct pnfs_layout_segment *lseg = NULL; | 701 | struct pnfs_layout_segment *lseg = NULL; |
581 | 702 | ||
@@ -588,25 +709,53 @@ pnfs_update_layout(struct inode *ino, | |||
588 | goto out_unlock; | 709 | goto out_unlock; |
589 | } | 710 | } |
590 | 711 | ||
591 | /* Check to see if the layout for the given range already exists */ | 712 | /* Do we even need to bother with this? */ |
592 | lseg = pnfs_has_layout(lo, iomode); | 713 | if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) || |
593 | if (lseg) { | 714 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) { |
594 | dprintk("%s: Using cached lseg %p for iomode %d)\n", | 715 | dprintk("%s matches recall, use MDS\n", __func__); |
595 | __func__, lseg, iomode); | ||
596 | goto out_unlock; | 716 | goto out_unlock; |
597 | } | 717 | } |
718 | /* Check to see if the layout for the given range already exists */ | ||
719 | lseg = pnfs_find_lseg(lo, iomode); | ||
720 | if (lseg) | ||
721 | goto out_unlock; | ||
598 | 722 | ||
599 | /* if LAYOUTGET already failed once we don't try again */ | 723 | /* if LAYOUTGET already failed once we don't try again */ |
600 | if (test_bit(lo_fail_bit(iomode), &nfsi->layout->state)) | 724 | if (test_bit(lo_fail_bit(iomode), &nfsi->layout->plh_flags)) |
725 | goto out_unlock; | ||
726 | |||
727 | if (pnfs_layoutgets_blocked(lo, NULL, 0)) | ||
601 | goto out_unlock; | 728 | goto out_unlock; |
729 | atomic_inc(&lo->plh_outstanding); | ||
602 | 730 | ||
603 | get_layout_hdr_locked(lo); /* Matched in nfs4_layoutget_release */ | 731 | get_layout_hdr(lo); |
732 | if (list_empty(&lo->plh_segs)) { | ||
733 | /* The lo must be on the clp list if there is any | ||
734 | * chance of a CB_LAYOUTRECALL(FILE) coming in. | ||
735 | */ | ||
736 | spin_lock(&clp->cl_lock); | ||
737 | BUG_ON(!list_empty(&lo->plh_layouts)); | ||
738 | list_add_tail(&lo->plh_layouts, &clp->cl_layouts); | ||
739 | spin_unlock(&clp->cl_lock); | ||
740 | } | ||
604 | spin_unlock(&ino->i_lock); | 741 | spin_unlock(&ino->i_lock); |
605 | 742 | ||
606 | lseg = send_layoutget(lo, ctx, iomode); | 743 | lseg = send_layoutget(lo, ctx, iomode); |
744 | if (!lseg) { | ||
745 | spin_lock(&ino->i_lock); | ||
746 | if (list_empty(&lo->plh_segs)) { | ||
747 | spin_lock(&clp->cl_lock); | ||
748 | list_del_init(&lo->plh_layouts); | ||
749 | spin_unlock(&clp->cl_lock); | ||
750 | clear_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags); | ||
751 | } | ||
752 | spin_unlock(&ino->i_lock); | ||
753 | } | ||
754 | atomic_dec(&lo->plh_outstanding); | ||
755 | put_layout_hdr(lo); | ||
607 | out: | 756 | out: |
608 | dprintk("%s end, state 0x%lx lseg %p\n", __func__, | 757 | dprintk("%s end, state 0x%lx lseg %p\n", __func__, |
609 | nfsi->layout->state, lseg); | 758 | nfsi->layout->plh_flags, lseg); |
610 | return lseg; | 759 | return lseg; |
611 | out_unlock: | 760 | out_unlock: |
612 | spin_unlock(&ino->i_lock); | 761 | spin_unlock(&ino->i_lock); |
@@ -619,9 +768,21 @@ pnfs_layout_process(struct nfs4_layoutget *lgp) | |||
619 | struct pnfs_layout_hdr *lo = NFS_I(lgp->args.inode)->layout; | 768 | struct pnfs_layout_hdr *lo = NFS_I(lgp->args.inode)->layout; |
620 | struct nfs4_layoutget_res *res = &lgp->res; | 769 | struct nfs4_layoutget_res *res = &lgp->res; |
621 | struct pnfs_layout_segment *lseg; | 770 | struct pnfs_layout_segment *lseg; |
622 | struct inode *ino = lo->inode; | 771 | struct inode *ino = lo->plh_inode; |
772 | struct nfs_client *clp = NFS_SERVER(ino)->nfs_client; | ||
623 | int status = 0; | 773 | int status = 0; |
624 | 774 | ||
775 | /* Verify we got what we asked for. | ||
776 | * Note that because the xdr parsing only accepts a single | ||
777 | * element array, this can fail even if the server is behaving | ||
778 | * correctly. | ||
779 | */ | ||
780 | if (lgp->args.range.iomode > res->range.iomode || | ||
781 | res->range.offset != 0 || | ||
782 | res->range.length != NFS4_MAX_UINT64) { | ||
783 | status = -EINVAL; | ||
784 | goto out; | ||
785 | } | ||
625 | /* Inject layout blob into I/O device driver */ | 786 | /* Inject layout blob into I/O device driver */ |
626 | lseg = NFS_SERVER(ino)->pnfs_curr_ld->alloc_lseg(lo, res); | 787 | lseg = NFS_SERVER(ino)->pnfs_curr_ld->alloc_lseg(lo, res); |
627 | if (!lseg || IS_ERR(lseg)) { | 788 | if (!lseg || IS_ERR(lseg)) { |
@@ -635,16 +796,37 @@ pnfs_layout_process(struct nfs4_layoutget *lgp) | |||
635 | } | 796 | } |
636 | 797 | ||
637 | spin_lock(&ino->i_lock); | 798 | spin_lock(&ino->i_lock); |
799 | if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) || | ||
800 | test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) { | ||
801 | dprintk("%s forget reply due to recall\n", __func__); | ||
802 | goto out_forget_reply; | ||
803 | } | ||
804 | |||
805 | if (pnfs_layoutgets_blocked(lo, &res->stateid, 1)) { | ||
806 | dprintk("%s forget reply due to state\n", __func__); | ||
807 | goto out_forget_reply; | ||
808 | } | ||
638 | init_lseg(lo, lseg); | 809 | init_lseg(lo, lseg); |
639 | lseg->range = res->range; | 810 | lseg->pls_range = res->range; |
640 | *lgp->lsegpp = lseg; | 811 | *lgp->lsegpp = lseg; |
641 | pnfs_insert_layout(lo, lseg); | 812 | pnfs_insert_layout(lo, lseg); |
642 | 813 | ||
814 | if (res->return_on_close) { | ||
815 | set_bit(NFS_LSEG_ROC, &lseg->pls_flags); | ||
816 | set_bit(NFS_LAYOUT_ROC, &lo->plh_flags); | ||
817 | } | ||
818 | |||
643 | /* Done processing layoutget. Set the layout stateid */ | 819 | /* Done processing layoutget. Set the layout stateid */ |
644 | pnfs_set_layout_stateid(lo, &res->stateid); | 820 | pnfs_set_layout_stateid(lo, &res->stateid, false); |
645 | spin_unlock(&ino->i_lock); | 821 | spin_unlock(&ino->i_lock); |
646 | out: | 822 | out: |
647 | return status; | 823 | return status; |
824 | |||
825 | out_forget_reply: | ||
826 | spin_unlock(&ino->i_lock); | ||
827 | lseg->pls_layout = lo; | ||
828 | NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg); | ||
829 | goto out; | ||
648 | } | 830 | } |
649 | 831 | ||
650 | /* | 832 | /* |
diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h index e12367d50489..e2612ea0cbed 100644 --- a/fs/nfs/pnfs.h +++ b/fs/nfs/pnfs.h | |||
@@ -30,11 +30,17 @@ | |||
30 | #ifndef FS_NFS_PNFS_H | 30 | #ifndef FS_NFS_PNFS_H |
31 | #define FS_NFS_PNFS_H | 31 | #define FS_NFS_PNFS_H |
32 | 32 | ||
33 | enum { | ||
34 | NFS_LSEG_VALID = 0, /* cleared when lseg is recalled/returned */ | ||
35 | NFS_LSEG_ROC, /* roc bit received from server */ | ||
36 | }; | ||
37 | |||
33 | struct pnfs_layout_segment { | 38 | struct pnfs_layout_segment { |
34 | struct list_head fi_list; | 39 | struct list_head pls_list; |
35 | struct pnfs_layout_range range; | 40 | struct pnfs_layout_range pls_range; |
36 | struct kref kref; | 41 | atomic_t pls_refcount; |
37 | struct pnfs_layout_hdr *layout; | 42 | unsigned long pls_flags; |
43 | struct pnfs_layout_hdr *pls_layout; | ||
38 | }; | 44 | }; |
39 | 45 | ||
40 | #ifdef CONFIG_NFS_V4_1 | 46 | #ifdef CONFIG_NFS_V4_1 |
@@ -44,7 +50,9 @@ struct pnfs_layout_segment { | |||
44 | enum { | 50 | enum { |
45 | NFS_LAYOUT_RO_FAILED = 0, /* get ro layout failed stop trying */ | 51 | NFS_LAYOUT_RO_FAILED = 0, /* get ro layout failed stop trying */ |
46 | NFS_LAYOUT_RW_FAILED, /* get rw layout failed stop trying */ | 52 | NFS_LAYOUT_RW_FAILED, /* get rw layout failed stop trying */ |
47 | NFS_LAYOUT_STATEID_SET, /* have a valid layout stateid */ | 53 | NFS_LAYOUT_BULK_RECALL, /* bulk recall affecting layout */ |
54 | NFS_LAYOUT_ROC, /* some lseg had roc bit set */ | ||
55 | NFS_LAYOUT_DESTROYED, /* no new use of layout allowed */ | ||
48 | }; | 56 | }; |
49 | 57 | ||
50 | /* Per-layout driver specific registration structure */ | 58 | /* Per-layout driver specific registration structure */ |
@@ -60,13 +68,16 @@ struct pnfs_layoutdriver_type { | |||
60 | }; | 68 | }; |
61 | 69 | ||
62 | struct pnfs_layout_hdr { | 70 | struct pnfs_layout_hdr { |
63 | unsigned long refcount; | 71 | atomic_t plh_refcount; |
64 | struct list_head layouts; /* other client layouts */ | 72 | struct list_head plh_layouts; /* other client layouts */ |
65 | struct list_head segs; /* layout segments list */ | 73 | struct list_head plh_bulk_recall; /* clnt list of bulk recalls */ |
66 | seqlock_t seqlock; /* Protects the stateid */ | 74 | struct list_head plh_segs; /* layout segments list */ |
67 | nfs4_stateid stateid; | 75 | nfs4_stateid plh_stateid; |
68 | unsigned long state; | 76 | atomic_t plh_outstanding; /* number of RPCs out */ |
69 | struct inode *inode; | 77 | unsigned long plh_block_lgets; /* block LAYOUTGET if >0 */ |
78 | u32 plh_barrier; /* ignore lower seqids */ | ||
79 | unsigned long plh_flags; | ||
80 | struct inode *plh_inode; | ||
70 | }; | 81 | }; |
71 | 82 | ||
72 | struct pnfs_device { | 83 | struct pnfs_device { |
@@ -134,17 +145,30 @@ extern int nfs4_proc_getdeviceinfo(struct nfs_server *server, | |||
134 | extern int nfs4_proc_layoutget(struct nfs4_layoutget *lgp); | 145 | extern int nfs4_proc_layoutget(struct nfs4_layoutget *lgp); |
135 | 146 | ||
136 | /* pnfs.c */ | 147 | /* pnfs.c */ |
148 | void get_layout_hdr(struct pnfs_layout_hdr *lo); | ||
137 | struct pnfs_layout_segment * | 149 | struct pnfs_layout_segment * |
138 | pnfs_update_layout(struct inode *ino, struct nfs_open_context *ctx, | 150 | pnfs_update_layout(struct inode *ino, struct nfs_open_context *ctx, |
139 | enum pnfs_iomode access_type); | 151 | enum pnfs_iomode access_type); |
140 | void set_pnfs_layoutdriver(struct nfs_server *, u32 id); | 152 | void set_pnfs_layoutdriver(struct nfs_server *, u32 id); |
141 | void unset_pnfs_layoutdriver(struct nfs_server *); | 153 | void unset_pnfs_layoutdriver(struct nfs_server *); |
142 | int pnfs_layout_process(struct nfs4_layoutget *lgp); | 154 | int pnfs_layout_process(struct nfs4_layoutget *lgp); |
155 | void pnfs_free_lseg_list(struct list_head *tmp_list); | ||
143 | void pnfs_destroy_layout(struct nfs_inode *); | 156 | void pnfs_destroy_layout(struct nfs_inode *); |
144 | void pnfs_destroy_all_layouts(struct nfs_client *); | 157 | void pnfs_destroy_all_layouts(struct nfs_client *); |
145 | void put_layout_hdr(struct inode *inode); | 158 | void put_layout_hdr(struct pnfs_layout_hdr *lo); |
146 | void pnfs_get_layout_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo, | 159 | void pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, |
147 | struct nfs4_state *open_state); | 160 | const nfs4_stateid *new, |
161 | bool update_barrier); | ||
162 | int pnfs_choose_layoutget_stateid(nfs4_stateid *dst, | ||
163 | struct pnfs_layout_hdr *lo, | ||
164 | struct nfs4_state *open_state); | ||
165 | int mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo, | ||
166 | struct list_head *tmp_list, | ||
167 | u32 iomode); | ||
168 | bool pnfs_roc(struct inode *ino); | ||
169 | void pnfs_roc_release(struct inode *ino); | ||
170 | void pnfs_roc_set_barrier(struct inode *ino, u32 barrier); | ||
171 | bool pnfs_roc_drain(struct inode *ino, u32 *barrier); | ||
148 | 172 | ||
149 | 173 | ||
150 | static inline int lo_fail_bit(u32 iomode) | 174 | static inline int lo_fail_bit(u32 iomode) |
@@ -176,6 +200,28 @@ pnfs_update_layout(struct inode *ino, struct nfs_open_context *ctx, | |||
176 | return NULL; | 200 | return NULL; |
177 | } | 201 | } |
178 | 202 | ||
203 | static inline bool | ||
204 | pnfs_roc(struct inode *ino) | ||
205 | { | ||
206 | return false; | ||
207 | } | ||
208 | |||
209 | static inline void | ||
210 | pnfs_roc_release(struct inode *ino) | ||
211 | { | ||
212 | } | ||
213 | |||
214 | static inline void | ||
215 | pnfs_roc_set_barrier(struct inode *ino, u32 barrier) | ||
216 | { | ||
217 | } | ||
218 | |||
219 | static inline bool | ||
220 | pnfs_roc_drain(struct inode *ino, u32 *barrier) | ||
221 | { | ||
222 | return false; | ||
223 | } | ||
224 | |||
179 | static inline void set_pnfs_layoutdriver(struct nfs_server *s, u32 id) | 225 | static inline void set_pnfs_layoutdriver(struct nfs_server *s, u32 id) |
180 | { | 226 | { |
181 | } | 227 | } |
diff --git a/fs/nfs/proc.c b/fs/nfs/proc.c index 58e7f84fc1fd..77d5e21c4ad6 100644 --- a/fs/nfs/proc.c +++ b/fs/nfs/proc.c | |||
@@ -458,7 +458,7 @@ nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page, | |||
458 | fattr = nfs_alloc_fattr(); | 458 | fattr = nfs_alloc_fattr(); |
459 | status = -ENOMEM; | 459 | status = -ENOMEM; |
460 | if (fh == NULL || fattr == NULL) | 460 | if (fh == NULL || fattr == NULL) |
461 | goto out; | 461 | goto out_free; |
462 | 462 | ||
463 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 463 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
464 | nfs_mark_for_revalidate(dir); | 464 | nfs_mark_for_revalidate(dir); |
@@ -471,6 +471,7 @@ nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page, | |||
471 | if (status == 0) | 471 | if (status == 0) |
472 | status = nfs_instantiate(dentry, fh, fattr); | 472 | status = nfs_instantiate(dentry, fh, fattr); |
473 | 473 | ||
474 | out_free: | ||
474 | nfs_free_fattr(fattr); | 475 | nfs_free_fattr(fattr); |
475 | nfs_free_fhandle(fh); | 476 | nfs_free_fhandle(fh); |
476 | out: | 477 | out: |
@@ -731,7 +732,7 @@ const struct nfs_rpc_ops nfs_v2_clientops = { | |||
731 | .statfs = nfs_proc_statfs, | 732 | .statfs = nfs_proc_statfs, |
732 | .fsinfo = nfs_proc_fsinfo, | 733 | .fsinfo = nfs_proc_fsinfo, |
733 | .pathconf = nfs_proc_pathconf, | 734 | .pathconf = nfs_proc_pathconf, |
734 | .decode_dirent = nfs_decode_dirent, | 735 | .decode_dirent = nfs2_decode_dirent, |
735 | .read_setup = nfs_proc_read_setup, | 736 | .read_setup = nfs_proc_read_setup, |
736 | .read_done = nfs_read_done, | 737 | .read_done = nfs_read_done, |
737 | .write_setup = nfs_proc_write_setup, | 738 | .write_setup = nfs_proc_write_setup, |
diff --git a/fs/nfs/super.c b/fs/nfs/super.c index 4100630c9a5b..b68c8607770f 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c | |||
@@ -598,7 +598,9 @@ static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss, | |||
598 | 598 | ||
599 | if (nfss->mountd_version || showdefaults) | 599 | if (nfss->mountd_version || showdefaults) |
600 | seq_printf(m, ",mountvers=%u", nfss->mountd_version); | 600 | seq_printf(m, ",mountvers=%u", nfss->mountd_version); |
601 | if (nfss->mountd_port || showdefaults) | 601 | if ((nfss->mountd_port && |
602 | nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) || | ||
603 | showdefaults) | ||
602 | seq_printf(m, ",mountport=%u", nfss->mountd_port); | 604 | seq_printf(m, ",mountport=%u", nfss->mountd_port); |
603 | 605 | ||
604 | nfs_show_mountd_netid(m, nfss, showdefaults); | 606 | nfs_show_mountd_netid(m, nfss, showdefaults); |
@@ -2200,6 +2202,7 @@ static int nfs_set_super(struct super_block *s, void *data) | |||
2200 | 2202 | ||
2201 | s->s_flags = sb_mntdata->mntflags; | 2203 | s->s_flags = sb_mntdata->mntflags; |
2202 | s->s_fs_info = server; | 2204 | s->s_fs_info = server; |
2205 | s->s_d_op = server->nfs_client->rpc_ops->dentry_ops; | ||
2203 | ret = set_anon_super(s, server); | 2206 | ret = set_anon_super(s, server); |
2204 | if (ret == 0) | 2207 | if (ret == 0) |
2205 | server->s_dev = s->s_dev; | 2208 | server->s_dev = s->s_dev; |
@@ -2494,7 +2497,13 @@ static void nfs4_clone_super(struct super_block *sb, | |||
2494 | sb->s_maxbytes = old_sb->s_maxbytes; | 2497 | sb->s_maxbytes = old_sb->s_maxbytes; |
2495 | sb->s_time_gran = 1; | 2498 | sb->s_time_gran = 1; |
2496 | sb->s_op = old_sb->s_op; | 2499 | sb->s_op = old_sb->s_op; |
2497 | nfs_initialise_sb(sb); | 2500 | /* |
2501 | * The VFS shouldn't apply the umask to mode bits. We will do | ||
2502 | * so ourselves when necessary. | ||
2503 | */ | ||
2504 | sb->s_flags |= MS_POSIXACL; | ||
2505 | sb->s_xattr = old_sb->s_xattr; | ||
2506 | nfs_initialise_sb(sb); | ||
2498 | } | 2507 | } |
2499 | 2508 | ||
2500 | /* | 2509 | /* |
@@ -2504,6 +2513,12 @@ static void nfs4_fill_super(struct super_block *sb) | |||
2504 | { | 2513 | { |
2505 | sb->s_time_gran = 1; | 2514 | sb->s_time_gran = 1; |
2506 | sb->s_op = &nfs4_sops; | 2515 | sb->s_op = &nfs4_sops; |
2516 | /* | ||
2517 | * The VFS shouldn't apply the umask to mode bits. We will do | ||
2518 | * so ourselves when necessary. | ||
2519 | */ | ||
2520 | sb->s_flags |= MS_POSIXACL; | ||
2521 | sb->s_xattr = nfs4_xattr_handlers; | ||
2507 | nfs_initialise_sb(sb); | 2522 | nfs_initialise_sb(sb); |
2508 | } | 2523 | } |
2509 | 2524 | ||
diff --git a/fs/nfs/unlink.c b/fs/nfs/unlink.c index 8fe9eb47a97f..e313a51acdd1 100644 --- a/fs/nfs/unlink.c +++ b/fs/nfs/unlink.c | |||
@@ -429,7 +429,7 @@ nfs_async_rename(struct inode *old_dir, struct inode *new_dir, | |||
429 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 429 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
430 | if (data == NULL) | 430 | if (data == NULL) |
431 | return ERR_PTR(-ENOMEM); | 431 | return ERR_PTR(-ENOMEM); |
432 | task_setup_data.callback_data = data, | 432 | task_setup_data.callback_data = data; |
433 | 433 | ||
434 | data->cred = rpc_lookup_cred(); | 434 | data->cred = rpc_lookup_cred(); |
435 | if (IS_ERR(data->cred)) { | 435 | if (IS_ERR(data->cred)) { |