]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/fs/nfsd/nfs4callback.c | |
3 | * | |
4 | * Copyright (c) 2001 The Regents of the University of Michigan. | |
5 | * All rights reserved. | |
6 | * | |
7 | * Kendrick Smith <kmsmith@umich.edu> | |
8 | * Andy Adamson <andros@umich.edu> | |
9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | |
13 | * | |
14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions and the following disclaimer. | |
16 | * 2. Redistributions in binary form must reproduce the above copyright | |
17 | * notice, this list of conditions and the following disclaimer in the | |
18 | * documentation and/or other materials provided with the distribution. | |
19 | * 3. Neither the name of the University nor the names of its | |
20 | * contributors may be used to endorse or promote products derived | |
21 | * from this software without specific prior written permission. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
24 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
26 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | |
30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
34 | */ | |
35 | ||
1da177e4 LT |
36 | #include <linux/module.h> |
37 | #include <linux/list.h> | |
38 | #include <linux/inet.h> | |
39 | #include <linux/errno.h> | |
40 | #include <linux/delay.h> | |
e8edc6e0 | 41 | #include <linux/sched.h> |
2b47eece | 42 | #include <linux/kthread.h> |
1da177e4 LT |
43 | #include <linux/sunrpc/xdr.h> |
44 | #include <linux/sunrpc/svc.h> | |
45 | #include <linux/sunrpc/clnt.h> | |
38524ab3 | 46 | #include <linux/sunrpc/svcsock.h> |
1da177e4 LT |
47 | #include <linux/nfsd/nfsd.h> |
48 | #include <linux/nfsd/state.h> | |
49 | #include <linux/sunrpc/sched.h> | |
50 | #include <linux/nfs4.h> | |
51 | ||
52 | #define NFSDDBG_FACILITY NFSDDBG_PROC | |
53 | ||
54 | #define NFSPROC4_CB_NULL 0 | |
55 | #define NFSPROC4_CB_COMPOUND 1 | |
38524ab3 | 56 | #define NFS4_STATEID_SIZE 16 |
1da177e4 | 57 | |
1da177e4 LT |
58 | /* Index of predefined Linux callback client operations */ |
59 | ||
60 | enum { | |
4be36ca0 | 61 | NFSPROC4_CLNT_CB_NULL = 0, |
1da177e4 | 62 | NFSPROC4_CLNT_CB_RECALL, |
38524ab3 | 63 | NFSPROC4_CLNT_CB_SEQUENCE, |
1da177e4 LT |
64 | }; |
65 | ||
66 | enum nfs_cb_opnum4 { | |
67 | OP_CB_RECALL = 4, | |
38524ab3 | 68 | OP_CB_SEQUENCE = 11, |
1da177e4 LT |
69 | }; |
70 | ||
71 | #define NFS4_MAXTAGLEN 20 | |
72 | ||
73 | #define NFS4_enc_cb_null_sz 0 | |
74 | #define NFS4_dec_cb_null_sz 0 | |
75 | #define cb_compound_enc_hdr_sz 4 | |
76 | #define cb_compound_dec_hdr_sz (3 + (NFS4_MAXTAGLEN >> 2)) | |
38524ab3 AA |
77 | #define sessionid_sz (NFS4_MAX_SESSIONID_LEN >> 2) |
78 | #define cb_sequence_enc_sz (sessionid_sz + 4 + \ | |
79 | 1 /* no referring calls list yet */) | |
80 | #define cb_sequence_dec_sz (op_dec_sz + sessionid_sz + 4) | |
81 | ||
1da177e4 LT |
82 | #define op_enc_sz 1 |
83 | #define op_dec_sz 2 | |
84 | #define enc_nfs4_fh_sz (1 + (NFS4_FHSIZE >> 2)) | |
0ac68d17 | 85 | #define enc_stateid_sz (NFS4_STATEID_SIZE >> 2) |
1da177e4 | 86 | #define NFS4_enc_cb_recall_sz (cb_compound_enc_hdr_sz + \ |
38524ab3 | 87 | cb_sequence_enc_sz + \ |
1da177e4 LT |
88 | 1 + enc_stateid_sz + \ |
89 | enc_nfs4_fh_sz) | |
90 | ||
91 | #define NFS4_dec_cb_recall_sz (cb_compound_dec_hdr_sz + \ | |
38524ab3 | 92 | cb_sequence_dec_sz + \ |
1da177e4 LT |
93 | op_dec_sz) |
94 | ||
132f9771 RL |
95 | struct nfs4_rpc_args { |
96 | void *args_op; | |
97 | struct nfsd4_cb_sequence args_seq; | |
98 | }; | |
99 | ||
1da177e4 LT |
100 | /* |
101 | * Generic encode routines from fs/nfs/nfs4xdr.c | |
102 | */ | |
f00f328f AV |
103 | static inline __be32 * |
104 | xdr_writemem(__be32 *p, const void *ptr, int nbytes) | |
1da177e4 LT |
105 | { |
106 | int tmp = XDR_QUADLEN(nbytes); | |
107 | if (!tmp) | |
108 | return p; | |
109 | p[tmp-1] = 0; | |
110 | memcpy(p, ptr, nbytes); | |
111 | return p + tmp; | |
112 | } | |
113 | ||
114 | #define WRITE32(n) *p++ = htonl(n) | |
115 | #define WRITEMEM(ptr,nbytes) do { \ | |
116 | p = xdr_writemem(p, ptr, nbytes); \ | |
117 | } while (0) | |
118 | #define RESERVE_SPACE(nbytes) do { \ | |
119 | p = xdr_reserve_space(xdr, nbytes); \ | |
8e24eea7 | 120 | if (!p) dprintk("NFSD: RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __func__); \ |
1da177e4 LT |
121 | BUG_ON(!p); \ |
122 | } while (0) | |
123 | ||
124 | /* | |
125 | * Generic decode routines from fs/nfs/nfs4xdr.c | |
126 | */ | |
127 | #define DECODE_TAIL \ | |
128 | status = 0; \ | |
129 | out: \ | |
130 | return status; \ | |
131 | xdr_error: \ | |
132 | dprintk("NFSD: xdr error! (%s:%d)\n", __FILE__, __LINE__); \ | |
133 | status = -EIO; \ | |
134 | goto out | |
135 | ||
136 | #define READ32(x) (x) = ntohl(*p++) | |
137 | #define READ64(x) do { \ | |
138 | (x) = (u64)ntohl(*p++) << 32; \ | |
139 | (x) |= ntohl(*p++); \ | |
140 | } while (0) | |
141 | #define READTIME(x) do { \ | |
142 | p++; \ | |
143 | (x.tv_sec) = ntohl(*p++); \ | |
144 | (x.tv_nsec) = ntohl(*p++); \ | |
145 | } while (0) | |
146 | #define READ_BUF(nbytes) do { \ | |
147 | p = xdr_inline_decode(xdr, nbytes); \ | |
148 | if (!p) { \ | |
3e3b4800 | 149 | dprintk("NFSD: %s: reply buffer overflowed in line %d.\n", \ |
8e24eea7 | 150 | __func__, __LINE__); \ |
1da177e4 LT |
151 | return -EIO; \ |
152 | } \ | |
153 | } while (0) | |
154 | ||
155 | struct nfs4_cb_compound_hdr { | |
38524ab3 AA |
156 | /* args */ |
157 | u32 ident; /* minorversion 0 only */ | |
1da177e4 | 158 | u32 nops; |
ef52bff8 | 159 | __be32 *nops_p; |
ab52ae6d | 160 | u32 minorversion; |
38524ab3 AA |
161 | /* res */ |
162 | int status; | |
1da177e4 | 163 | u32 taglen; |
ef52bff8 | 164 | char *tag; |
1da177e4 LT |
165 | }; |
166 | ||
167 | static struct { | |
168 | int stat; | |
169 | int errno; | |
170 | } nfs_cb_errtbl[] = { | |
171 | { NFS4_OK, 0 }, | |
172 | { NFS4ERR_PERM, EPERM }, | |
173 | { NFS4ERR_NOENT, ENOENT }, | |
174 | { NFS4ERR_IO, EIO }, | |
175 | { NFS4ERR_NXIO, ENXIO }, | |
176 | { NFS4ERR_ACCESS, EACCES }, | |
177 | { NFS4ERR_EXIST, EEXIST }, | |
178 | { NFS4ERR_XDEV, EXDEV }, | |
179 | { NFS4ERR_NOTDIR, ENOTDIR }, | |
180 | { NFS4ERR_ISDIR, EISDIR }, | |
181 | { NFS4ERR_INVAL, EINVAL }, | |
182 | { NFS4ERR_FBIG, EFBIG }, | |
183 | { NFS4ERR_NOSPC, ENOSPC }, | |
184 | { NFS4ERR_ROFS, EROFS }, | |
185 | { NFS4ERR_MLINK, EMLINK }, | |
186 | { NFS4ERR_NAMETOOLONG, ENAMETOOLONG }, | |
187 | { NFS4ERR_NOTEMPTY, ENOTEMPTY }, | |
188 | { NFS4ERR_DQUOT, EDQUOT }, | |
189 | { NFS4ERR_STALE, ESTALE }, | |
190 | { NFS4ERR_BADHANDLE, EBADHANDLE }, | |
191 | { NFS4ERR_BAD_COOKIE, EBADCOOKIE }, | |
192 | { NFS4ERR_NOTSUPP, ENOTSUPP }, | |
193 | { NFS4ERR_TOOSMALL, ETOOSMALL }, | |
194 | { NFS4ERR_SERVERFAULT, ESERVERFAULT }, | |
195 | { NFS4ERR_BADTYPE, EBADTYPE }, | |
196 | { NFS4ERR_LOCKED, EAGAIN }, | |
197 | { NFS4ERR_RESOURCE, EREMOTEIO }, | |
198 | { NFS4ERR_SYMLINK, ELOOP }, | |
199 | { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP }, | |
200 | { NFS4ERR_DEADLOCK, EDEADLK }, | |
201 | { -1, EIO } | |
202 | }; | |
203 | ||
204 | static int | |
205 | nfs_cb_stat_to_errno(int stat) | |
206 | { | |
207 | int i; | |
208 | for (i = 0; nfs_cb_errtbl[i].stat != -1; i++) { | |
209 | if (nfs_cb_errtbl[i].stat == stat) | |
210 | return nfs_cb_errtbl[i].errno; | |
211 | } | |
212 | /* If we cannot translate the error, the recovery routines should | |
213 | * handle it. | |
214 | * Note: remaining NFSv4 error codes have values > 10000, so should | |
215 | * not conflict with native Linux error codes. | |
216 | */ | |
217 | return stat; | |
218 | } | |
219 | ||
220 | /* | |
221 | * XDR encode | |
222 | */ | |
223 | ||
ef52bff8 | 224 | static void |
1da177e4 LT |
225 | encode_cb_compound_hdr(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr) |
226 | { | |
f00f328f | 227 | __be32 * p; |
1da177e4 LT |
228 | |
229 | RESERVE_SPACE(16); | |
230 | WRITE32(0); /* tag length is always 0 */ | |
ab52ae6d | 231 | WRITE32(hdr->minorversion); |
1da177e4 | 232 | WRITE32(hdr->ident); |
ef52bff8 | 233 | hdr->nops_p = p; |
1da177e4 | 234 | WRITE32(hdr->nops); |
1da177e4 LT |
235 | } |
236 | ||
ef52bff8 AA |
237 | static void encode_cb_nops(struct nfs4_cb_compound_hdr *hdr) |
238 | { | |
239 | *hdr->nops_p = htonl(hdr->nops); | |
240 | } | |
241 | ||
242 | static void | |
243 | encode_cb_recall(struct xdr_stream *xdr, struct nfs4_delegation *dp, | |
244 | struct nfs4_cb_compound_hdr *hdr) | |
1da177e4 | 245 | { |
f00f328f | 246 | __be32 *p; |
b53d40c5 | 247 | int len = dp->dl_fh.fh_size; |
1da177e4 | 248 | |
b53d40c5 | 249 | RESERVE_SPACE(12+sizeof(dp->dl_stateid) + len); |
1da177e4 | 250 | WRITE32(OP_CB_RECALL); |
b53d40c5 BF |
251 | WRITE32(dp->dl_stateid.si_generation); |
252 | WRITEMEM(&dp->dl_stateid.si_opaque, sizeof(stateid_opaque_t)); | |
6707bd3d | 253 | WRITE32(0); /* truncate optimization not implemented */ |
1da177e4 | 254 | WRITE32(len); |
b53d40c5 | 255 | WRITEMEM(&dp->dl_fh.fh_base, len); |
ef52bff8 | 256 | hdr->nops++; |
1da177e4 LT |
257 | } |
258 | ||
259 | static int | |
f00f328f | 260 | nfs4_xdr_enc_cb_null(struct rpc_rqst *req, __be32 *p) |
1da177e4 LT |
261 | { |
262 | struct xdr_stream xdrs, *xdr = &xdrs; | |
263 | ||
264 | xdr_init_encode(&xdrs, &req->rq_snd_buf, p); | |
265 | RESERVE_SPACE(0); | |
266 | return 0; | |
267 | } | |
268 | ||
269 | static int | |
b53d40c5 | 270 | nfs4_xdr_enc_cb_recall(struct rpc_rqst *req, __be32 *p, struct nfs4_delegation *args) |
1da177e4 LT |
271 | { |
272 | struct xdr_stream xdr; | |
273 | struct nfs4_cb_compound_hdr hdr = { | |
b53d40c5 | 274 | .ident = args->dl_ident, |
1da177e4 LT |
275 | }; |
276 | ||
277 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | |
278 | encode_cb_compound_hdr(&xdr, &hdr); | |
ef52bff8 AA |
279 | encode_cb_recall(&xdr, args, &hdr); |
280 | encode_cb_nops(&hdr); | |
281 | return 0; | |
1da177e4 LT |
282 | } |
283 | ||
284 | ||
285 | static int | |
286 | decode_cb_compound_hdr(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr){ | |
f00f328f | 287 | __be32 *p; |
1da177e4 LT |
288 | |
289 | READ_BUF(8); | |
290 | READ32(hdr->status); | |
291 | READ32(hdr->taglen); | |
292 | READ_BUF(hdr->taglen + 4); | |
293 | hdr->tag = (char *)p; | |
294 | p += XDR_QUADLEN(hdr->taglen); | |
295 | READ32(hdr->nops); | |
296 | return 0; | |
297 | } | |
298 | ||
299 | static int | |
300 | decode_cb_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) | |
301 | { | |
f00f328f | 302 | __be32 *p; |
1da177e4 LT |
303 | u32 op; |
304 | int32_t nfserr; | |
305 | ||
306 | READ_BUF(8); | |
307 | READ32(op); | |
308 | if (op != expected) { | |
309 | dprintk("NFSD: decode_cb_op_hdr: Callback server returned " | |
310 | " operation %d but we issued a request for %d\n", | |
311 | op, expected); | |
312 | return -EIO; | |
313 | } | |
314 | READ32(nfserr); | |
315 | if (nfserr != NFS_OK) | |
316 | return -nfs_cb_stat_to_errno(nfserr); | |
317 | return 0; | |
318 | } | |
319 | ||
320 | static int | |
f00f328f | 321 | nfs4_xdr_dec_cb_null(struct rpc_rqst *req, __be32 *p) |
1da177e4 LT |
322 | { |
323 | return 0; | |
324 | } | |
325 | ||
326 | static int | |
f00f328f | 327 | nfs4_xdr_dec_cb_recall(struct rpc_rqst *rqstp, __be32 *p) |
1da177e4 LT |
328 | { |
329 | struct xdr_stream xdr; | |
330 | struct nfs4_cb_compound_hdr hdr; | |
331 | int status; | |
332 | ||
333 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | |
334 | status = decode_cb_compound_hdr(&xdr, &hdr); | |
335 | if (status) | |
336 | goto out; | |
337 | status = decode_cb_op_hdr(&xdr, OP_CB_RECALL); | |
338 | out: | |
339 | return status; | |
340 | } | |
341 | ||
342 | /* | |
343 | * RPC procedure tables | |
344 | */ | |
1da177e4 LT |
345 | #define PROC(proc, call, argtype, restype) \ |
346 | [NFSPROC4_CLNT_##proc] = { \ | |
347 | .p_proc = NFSPROC4_CB_##call, \ | |
348 | .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \ | |
349 | .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \ | |
2bea90d4 CL |
350 | .p_arglen = NFS4_##argtype##_sz, \ |
351 | .p_replen = NFS4_##restype##_sz, \ | |
cc0175c1 CL |
352 | .p_statidx = NFSPROC4_CB_##call, \ |
353 | .p_name = #proc, \ | |
1da177e4 LT |
354 | } |
355 | ||
fd39ca9a | 356 | static struct rpc_procinfo nfs4_cb_procedures[] = { |
1da177e4 LT |
357 | PROC(CB_NULL, NULL, enc_cb_null, dec_cb_null), |
358 | PROC(CB_RECALL, COMPOUND, enc_cb_recall, dec_cb_recall), | |
359 | }; | |
360 | ||
fd39ca9a | 361 | static struct rpc_version nfs_cb_version4 = { |
1da177e4 | 362 | .number = 1, |
e8c96f8c | 363 | .nrprocs = ARRAY_SIZE(nfs4_cb_procedures), |
1da177e4 LT |
364 | .procs = nfs4_cb_procedures |
365 | }; | |
366 | ||
367 | static struct rpc_version * nfs_cb_version[] = { | |
368 | NULL, | |
369 | &nfs_cb_version4, | |
370 | }; | |
371 | ||
ff7d9756 OK |
372 | static struct rpc_program cb_program; |
373 | ||
374 | static struct rpc_stat cb_stats = { | |
375 | .program = &cb_program | |
376 | }; | |
377 | ||
378 | #define NFS4_CALLBACK 0x40000000 | |
379 | static struct rpc_program cb_program = { | |
380 | .name = "nfs4_cb", | |
381 | .number = NFS4_CALLBACK, | |
382 | .nrvers = ARRAY_SIZE(nfs_cb_version), | |
383 | .version = nfs_cb_version, | |
384 | .stats = &cb_stats, | |
61054b14 | 385 | .pipe_dir_name = "/nfsd4_cb", |
ff7d9756 OK |
386 | }; |
387 | ||
595947ac BF |
388 | static int max_cb_time(void) |
389 | { | |
390 | return max(NFSD_LEASE_TIME/10, (time_t)1) * HZ; | |
391 | } | |
392 | ||
2b47eece BF |
393 | /* Reference counting, callback cleanup, etc., all look racy as heck. |
394 | * And why is cb_set an atomic? */ | |
395 | ||
e1cab5a5 | 396 | int setup_callback_client(struct nfs4_client *clp) |
2b47eece | 397 | { |
c237dc03 | 398 | struct nfs4_cb_conn *cb = &clp->cl_cb_conn; |
ae5c7947 | 399 | struct rpc_timeout timeparms = { |
595947ac BF |
400 | .to_initval = max_cb_time(), |
401 | .to_retries = 0, | |
ae5c7947 | 402 | }; |
ae5c7947 CL |
403 | struct rpc_create_args args = { |
404 | .protocol = IPPROTO_TCP, | |
aa9a4ec7 JL |
405 | .address = (struct sockaddr *) &cb->cb_addr, |
406 | .addrsize = cb->cb_addrlen, | |
ae5c7947 | 407 | .timeout = &timeparms, |
ff7d9756 | 408 | .program = &cb_program, |
d5b337b4 | 409 | .prognumber = cb->cb_prog, |
ae5c7947 | 410 | .version = nfs_cb_version[1]->number, |
61054b14 | 411 | .authflavor = clp->cl_flavor, |
b6b6152c | 412 | .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET), |
608207e8 | 413 | .client_name = clp->cl_principal, |
ae5c7947 | 414 | }; |
63c86716 | 415 | struct rpc_clnt *client; |
1da177e4 | 416 | |
418cd20a | 417 | if (!clp->cl_principal && (clp->cl_flavor >= RPC_AUTH_GSS_KRB5)) |
e1cab5a5 | 418 | return -EINVAL; |
608207e8 | 419 | |
ae5c7947 | 420 | /* Create RPC client */ |
63c86716 | 421 | client = rpc_create(&args); |
e1cab5a5 | 422 | if (IS_ERR(client)) { |
a601caed BF |
423 | dprintk("NFSD: couldn't create callback client: %ld\n", |
424 | PTR_ERR(client)); | |
e1cab5a5 BF |
425 | return PTR_ERR(client); |
426 | } | |
427 | cb->cb_client = client; | |
428 | return 0; | |
a601caed BF |
429 | |
430 | } | |
431 | ||
ecdd03b7 BF |
432 | static void warn_no_callback_path(struct nfs4_client *clp, int reason) |
433 | { | |
434 | dprintk("NFSD: warning: no callback path to client %.*s: error %d\n", | |
435 | (int)clp->cl_name.len, clp->cl_name.data, reason); | |
436 | } | |
437 | ||
e300a63c BF |
438 | static void nfsd4_cb_probe_done(struct rpc_task *task, void *calldata) |
439 | { | |
440 | struct nfs4_client *clp = calldata; | |
441 | ||
442 | if (task->tk_status) | |
443 | warn_no_callback_path(clp, task->tk_status); | |
444 | else | |
c237dc03 | 445 | atomic_set(&clp->cl_cb_conn.cb_set, 1); |
e300a63c BF |
446 | put_nfs4_client(clp); |
447 | } | |
448 | ||
449 | static const struct rpc_call_ops nfsd4_cb_probe_ops = { | |
450 | .rpc_call_done = nfsd4_cb_probe_done, | |
451 | }; | |
452 | ||
80fc015b BF |
453 | static struct rpc_cred *callback_cred; |
454 | ||
455 | int set_callback_cred(void) | |
3cef9ab2 | 456 | { |
80fc015b BF |
457 | callback_cred = rpc_lookup_machine_cred(); |
458 | if (!callback_cred) | |
459 | return -ENOMEM; | |
460 | return 0; | |
3cef9ab2 BF |
461 | } |
462 | ||
80fc015b | 463 | |
e300a63c | 464 | void do_probe_callback(struct nfs4_client *clp) |
a601caed | 465 | { |
c237dc03 | 466 | struct nfs4_cb_conn *cb = &clp->cl_cb_conn; |
a601caed BF |
467 | struct rpc_message msg = { |
468 | .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL], | |
469 | .rpc_argp = clp, | |
80fc015b | 470 | .rpc_cred = callback_cred |
a601caed | 471 | }; |
a601caed BF |
472 | int status; |
473 | ||
e300a63c BF |
474 | status = rpc_call_async(cb->cb_client, &msg, RPC_TASK_SOFT, |
475 | &nfsd4_cb_probe_ops, (void *)clp); | |
e300a63c | 476 | if (status) { |
ecdd03b7 | 477 | warn_no_callback_path(clp, status); |
e300a63c BF |
478 | put_nfs4_client(clp); |
479 | } | |
63c86716 BF |
480 | } |
481 | ||
482 | /* | |
483 | * Set up the callback client and put a NFSPROC4_CB_NULL on the wire... | |
484 | */ | |
485 | void | |
486 | nfsd4_probe_callback(struct nfs4_client *clp) | |
487 | { | |
ecdd03b7 | 488 | int status; |
63c86716 | 489 | |
c237dc03 | 490 | BUG_ON(atomic_read(&clp->cl_cb_conn.cb_set)); |
63c86716 | 491 | |
ecdd03b7 BF |
492 | status = setup_callback_client(clp); |
493 | if (status) { | |
494 | warn_no_callback_path(clp, status); | |
495 | return; | |
496 | } | |
497 | ||
541e0e09 | 498 | /* the task holds a reference to the nfs4_client struct */ |
1da177e4 LT |
499 | atomic_inc(&clp->cl_count); |
500 | ||
e300a63c | 501 | do_probe_callback(clp); |
1da177e4 LT |
502 | } |
503 | ||
2a1d1b59 RL |
504 | /* |
505 | * There's currently a single callback channel slot. | |
506 | * If the slot is available, then mark it busy. Otherwise, set the | |
507 | * thread for sleeping on the callback RPC wait queue. | |
508 | */ | |
509 | static int nfsd41_cb_setup_sequence(struct nfs4_client *clp, | |
510 | struct rpc_task *task) | |
511 | { | |
512 | struct nfs4_rpc_args *args = task->tk_msg.rpc_argp; | |
513 | u32 *ptr = (u32 *)clp->cl_sessionid.data; | |
514 | int status = 0; | |
515 | ||
516 | dprintk("%s: %u:%u:%u:%u\n", __func__, | |
517 | ptr[0], ptr[1], ptr[2], ptr[3]); | |
518 | ||
519 | if (test_and_set_bit(0, &clp->cl_cb_slot_busy) != 0) { | |
520 | rpc_sleep_on(&clp->cl_cb_waitq, task, NULL); | |
521 | dprintk("%s slot is busy\n", __func__); | |
522 | status = -EAGAIN; | |
523 | goto out; | |
524 | } | |
525 | ||
526 | /* | |
527 | * We'll need the clp during XDR encoding and decoding, | |
528 | * and the sequence during decoding to verify the reply | |
529 | */ | |
530 | args->args_seq.cbs_clp = clp; | |
531 | task->tk_msg.rpc_resp = &args->args_seq; | |
532 | ||
533 | out: | |
534 | dprintk("%s status=%d\n", __func__, status); | |
535 | return status; | |
536 | } | |
537 | ||
538 | /* | |
539 | * TODO: cb_sequence should support referring call lists, cachethis, multiple | |
540 | * slots, and mark callback channel down on communication errors. | |
541 | */ | |
542 | static void nfsd4_cb_prepare(struct rpc_task *task, void *calldata) | |
543 | { | |
544 | struct nfs4_delegation *dp = calldata; | |
545 | struct nfs4_client *clp = dp->dl_client; | |
546 | struct nfs4_rpc_args *args = task->tk_msg.rpc_argp; | |
547 | u32 minorversion = clp->cl_cb_conn.cb_minorversion; | |
548 | int status = 0; | |
549 | ||
550 | args->args_seq.cbs_minorversion = minorversion; | |
551 | if (minorversion) { | |
552 | status = nfsd41_cb_setup_sequence(clp, task); | |
553 | if (status) { | |
554 | if (status != -EAGAIN) { | |
555 | /* terminate rpc task */ | |
556 | task->tk_status = status; | |
557 | task->tk_action = NULL; | |
558 | } | |
559 | return; | |
560 | } | |
561 | } | |
562 | rpc_call_start(task); | |
563 | } | |
564 | ||
63e4863f BF |
565 | static void nfsd4_cb_recall_done(struct rpc_task *task, void *calldata) |
566 | { | |
567 | struct nfs4_delegation *dp = calldata; | |
568 | struct nfs4_client *clp = dp->dl_client; | |
569 | ||
570 | switch (task->tk_status) { | |
571 | case -EIO: | |
572 | /* Network partition? */ | |
573 | atomic_set(&clp->cl_cb_conn.cb_set, 0); | |
574 | warn_no_callback_path(clp, task->tk_status); | |
575 | case -EBADHANDLE: | |
576 | case -NFS4ERR_BAD_STATEID: | |
577 | /* Race: client probably got cb_recall | |
578 | * before open reply granting delegation */ | |
579 | break; | |
580 | default: | |
581 | /* success, or error we can't handle */ | |
582 | return; | |
583 | } | |
584 | if (dp->dl_retries--) { | |
585 | rpc_delay(task, 2*HZ); | |
586 | task->tk_status = 0; | |
587 | rpc_restart_call(task); | |
588 | } else { | |
589 | atomic_set(&clp->cl_cb_conn.cb_set, 0); | |
590 | warn_no_callback_path(clp, task->tk_status); | |
591 | } | |
592 | } | |
593 | ||
594 | static void nfsd4_cb_recall_release(void *calldata) | |
595 | { | |
596 | struct nfs4_delegation *dp = calldata; | |
597 | struct nfs4_client *clp = dp->dl_client; | |
598 | ||
599 | nfs4_put_delegation(dp); | |
600 | put_nfs4_client(clp); | |
601 | } | |
602 | ||
603 | static const struct rpc_call_ops nfsd4_cb_recall_ops = { | |
2a1d1b59 | 604 | .rpc_call_prepare = nfsd4_cb_prepare, |
63e4863f BF |
605 | .rpc_call_done = nfsd4_cb_recall_done, |
606 | .rpc_release = nfsd4_cb_recall_release, | |
607 | }; | |
608 | ||
1da177e4 LT |
609 | /* |
610 | * called with dp->dl_count inc'ed. | |
1da177e4 LT |
611 | */ |
612 | void | |
613 | nfsd4_cb_recall(struct nfs4_delegation *dp) | |
614 | { | |
615 | struct nfs4_client *clp = dp->dl_client; | |
c237dc03 | 616 | struct rpc_clnt *clnt = clp->cl_cb_conn.cb_client; |
1da177e4 LT |
617 | struct rpc_message msg = { |
618 | .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_RECALL], | |
b53d40c5 | 619 | .rpc_argp = dp, |
80fc015b | 620 | .rpc_cred = callback_cred |
1da177e4 | 621 | }; |
63e4863f | 622 | int status; |
1da177e4 | 623 | |
3aea09dc | 624 | dp->dl_retries = 1; |
63e4863f BF |
625 | status = rpc_call_async(clnt, &msg, RPC_TASK_SOFT, |
626 | &nfsd4_cb_recall_ops, dp); | |
627 | if (status) { | |
628 | put_nfs4_client(clp); | |
629 | nfs4_put_delegation(dp); | |
1da177e4 | 630 | } |
1da177e4 | 631 | } |