blob: d8148cc461e771c4a427fe6180555a12558f6ca5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (c) 2001 The Regents of the University of Michigan.
3 * All rights reserved.
4 *
5 * Kendrick Smith <kmsmith@umich.edu>
6 * Andy Adamson <andros@umich.edu>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/sunrpc/clnt.h>
J. Bruce Fieldsb5a1a812010-03-03 14:52:55 -050035#include <linux/sunrpc/svc_xprt.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090036#include <linux/slab.h>
Boaz Harrosh9a74af22009-12-03 20:30:56 +020037#include "nfsd.h"
38#include "state.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#define NFSDDBG_FACILITY NFSDDBG_PROC
41
42#define NFSPROC4_CB_NULL 0
43#define NFSPROC4_CB_COMPOUND 1
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/* Index of predefined Linux callback client operations */
46
47enum {
Benny Halevy4be36ca2009-09-10 12:25:46 +030048 NFSPROC4_CLNT_CB_NULL = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 NFSPROC4_CLNT_CB_RECALL,
Andy Adamson38524ab2009-09-10 12:25:59 +030050 NFSPROC4_CLNT_CB_SEQUENCE,
Linus Torvalds1da177e2005-04-16 15:20:36 -070051};
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#define NFS4_MAXTAGLEN 20
54
55#define NFS4_enc_cb_null_sz 0
56#define NFS4_dec_cb_null_sz 0
57#define cb_compound_enc_hdr_sz 4
58#define cb_compound_dec_hdr_sz (3 + (NFS4_MAXTAGLEN >> 2))
Andy Adamson38524ab2009-09-10 12:25:59 +030059#define sessionid_sz (NFS4_MAX_SESSIONID_LEN >> 2)
60#define cb_sequence_enc_sz (sessionid_sz + 4 + \
61 1 /* no referring calls list yet */)
62#define cb_sequence_dec_sz (op_dec_sz + sessionid_sz + 4)
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#define op_enc_sz 1
65#define op_dec_sz 2
66#define enc_nfs4_fh_sz (1 + (NFS4_FHSIZE >> 2))
Benny Halevy0ac68d12007-07-17 04:04:37 -070067#define enc_stateid_sz (NFS4_STATEID_SIZE >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define NFS4_enc_cb_recall_sz (cb_compound_enc_hdr_sz + \
Andy Adamson38524ab2009-09-10 12:25:59 +030069 cb_sequence_enc_sz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 1 + enc_stateid_sz + \
71 enc_nfs4_fh_sz)
72
73#define NFS4_dec_cb_recall_sz (cb_compound_dec_hdr_sz + \
Andy Adamson38524ab2009-09-10 12:25:59 +030074 cb_sequence_dec_sz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 op_dec_sz)
76
77/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 * Generic decode routines from fs/nfs/nfs4xdr.c
79 */
80#define DECODE_TAIL \
81 status = 0; \
82out: \
83 return status; \
84xdr_error: \
85 dprintk("NFSD: xdr error! (%s:%d)\n", __FILE__, __LINE__); \
86 status = -EIO; \
87 goto out
88
89#define READ32(x) (x) = ntohl(*p++)
90#define READ64(x) do { \
91 (x) = (u64)ntohl(*p++) << 32; \
92 (x) |= ntohl(*p++); \
93} while (0)
94#define READTIME(x) do { \
95 p++; \
96 (x.tv_sec) = ntohl(*p++); \
97 (x.tv_nsec) = ntohl(*p++); \
98} while (0)
99#define READ_BUF(nbytes) do { \
100 p = xdr_inline_decode(xdr, nbytes); \
101 if (!p) { \
Greg Banks3e3b4802006-10-02 02:17:41 -0700102 dprintk("NFSD: %s: reply buffer overflowed in line %d.\n", \
Harvey Harrison8e24eea2008-04-30 00:55:09 -0700103 __func__, __LINE__); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 return -EIO; \
105 } \
106} while (0)
107
108struct nfs4_cb_compound_hdr {
Andy Adamson38524ab2009-09-10 12:25:59 +0300109 /* args */
110 u32 ident; /* minorversion 0 only */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 u32 nops;
Andy Adamsonef52bff2009-06-16 04:20:50 +0300112 __be32 *nops_p;
Andy Adamsonab52ae62009-06-16 04:20:53 +0300113 u32 minorversion;
Andy Adamson38524ab2009-09-10 12:25:59 +0300114 /* res */
115 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116};
117
118static struct {
119int stat;
120int errno;
121} nfs_cb_errtbl[] = {
122 { NFS4_OK, 0 },
123 { NFS4ERR_PERM, EPERM },
124 { NFS4ERR_NOENT, ENOENT },
125 { NFS4ERR_IO, EIO },
126 { NFS4ERR_NXIO, ENXIO },
127 { NFS4ERR_ACCESS, EACCES },
128 { NFS4ERR_EXIST, EEXIST },
129 { NFS4ERR_XDEV, EXDEV },
130 { NFS4ERR_NOTDIR, ENOTDIR },
131 { NFS4ERR_ISDIR, EISDIR },
132 { NFS4ERR_INVAL, EINVAL },
133 { NFS4ERR_FBIG, EFBIG },
134 { NFS4ERR_NOSPC, ENOSPC },
135 { NFS4ERR_ROFS, EROFS },
136 { NFS4ERR_MLINK, EMLINK },
137 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG },
138 { NFS4ERR_NOTEMPTY, ENOTEMPTY },
139 { NFS4ERR_DQUOT, EDQUOT },
140 { NFS4ERR_STALE, ESTALE },
141 { NFS4ERR_BADHANDLE, EBADHANDLE },
142 { NFS4ERR_BAD_COOKIE, EBADCOOKIE },
143 { NFS4ERR_NOTSUPP, ENOTSUPP },
144 { NFS4ERR_TOOSMALL, ETOOSMALL },
145 { NFS4ERR_SERVERFAULT, ESERVERFAULT },
146 { NFS4ERR_BADTYPE, EBADTYPE },
147 { NFS4ERR_LOCKED, EAGAIN },
148 { NFS4ERR_RESOURCE, EREMOTEIO },
149 { NFS4ERR_SYMLINK, ELOOP },
150 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP },
151 { NFS4ERR_DEADLOCK, EDEADLK },
152 { -1, EIO }
153};
154
155static int
156nfs_cb_stat_to_errno(int stat)
157{
158 int i;
159 for (i = 0; nfs_cb_errtbl[i].stat != -1; i++) {
160 if (nfs_cb_errtbl[i].stat == stat)
161 return nfs_cb_errtbl[i].errno;
162 }
163 /* If we cannot translate the error, the recovery routines should
164 * handle it.
165 * Note: remaining NFSv4 error codes have values > 10000, so should
166 * not conflict with native Linux error codes.
167 */
168 return stat;
169}
170
Chuck Levera033db42010-12-14 14:57:22 +0000171static __be32 *xdr_encode_empty_array(__be32 *p)
172{
173 *p++ = xdr_zero;
174 return p;
175}
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177/*
Chuck Levera033db42010-12-14 14:57:22 +0000178 * Encode/decode NFSv4 CB basic data types
179 *
180 * Basic NFSv4 callback data types are defined in section 15 of RFC
181 * 3530: "Network File System (NFS) version 4 Protocol" and section
182 * 20 of RFC 5661: "Network File System (NFS) Version 4 Minor Version
183 * 1 Protocol"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 */
185
Chuck Levera033db42010-12-14 14:57:22 +0000186/*
187 * nfs_cb_opnum4
188 *
189 * enum nfs_cb_opnum4 {
190 * OP_CB_GETATTR = 3,
191 * ...
192 * };
193 */
194enum nfs_cb_opnum4 {
195 OP_CB_GETATTR = 3,
196 OP_CB_RECALL = 4,
197 OP_CB_LAYOUTRECALL = 5,
198 OP_CB_NOTIFY = 6,
199 OP_CB_PUSH_DELEG = 7,
200 OP_CB_RECALL_ANY = 8,
201 OP_CB_RECALLABLE_OBJ_AVAIL = 9,
202 OP_CB_RECALL_SLOT = 10,
203 OP_CB_SEQUENCE = 11,
204 OP_CB_WANTS_CANCELLED = 12,
205 OP_CB_NOTIFY_LOCK = 13,
206 OP_CB_NOTIFY_DEVICEID = 14,
207 OP_CB_ILLEGAL = 10044
208};
209
210static void encode_nfs_cb_opnum4(struct xdr_stream *xdr, enum nfs_cb_opnum4 op)
Benny Halevy9303bbd2010-05-25 09:50:23 +0300211{
212 __be32 *p;
213
Chuck Levera033db42010-12-14 14:57:22 +0000214 p = xdr_reserve_space(xdr, 4);
215 *p = cpu_to_be32(op);
Benny Halevy9303bbd2010-05-25 09:50:23 +0300216}
217
Chuck Levera033db42010-12-14 14:57:22 +0000218/*
219 * nfs_fh4
220 *
221 * typedef opaque nfs_fh4<NFS4_FHSIZE>;
222 */
223static void encode_nfs_fh4(struct xdr_stream *xdr, const struct knfsd_fh *fh)
224{
225 u32 length = fh->fh_size;
226 __be32 *p;
227
228 BUG_ON(length > NFS4_FHSIZE);
229 p = xdr_reserve_space(xdr, 4 + length);
230 xdr_encode_opaque(p, &fh->fh_base, length);
231}
232
233/*
234 * stateid4
235 *
236 * struct stateid4 {
237 * uint32_t seqid;
238 * opaque other[12];
239 * };
240 */
241static void encode_stateid4(struct xdr_stream *xdr, const stateid_t *sid)
242{
243 __be32 *p;
244
245 p = xdr_reserve_space(xdr, NFS4_STATEID_SIZE);
246 *p++ = cpu_to_be32(sid->si_generation);
247 xdr_encode_opaque_fixed(p, &sid->si_opaque, NFS4_STATEID_OTHER_SIZE);
248}
249
250/*
251 * sessionid4
252 *
253 * typedef opaque sessionid4[NFS4_SESSIONID_SIZE];
254 */
255static void encode_sessionid4(struct xdr_stream *xdr,
256 const struct nfsd4_session *session)
257{
258 __be32 *p;
259
260 p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN);
261 xdr_encode_opaque_fixed(p, session->se_sessionid.data,
262 NFS4_MAX_SESSIONID_LEN);
263}
264
265/*
266 * CB_COMPOUND4args
267 *
268 * struct CB_COMPOUND4args {
269 * utf8str_cs tag;
270 * uint32_t minorversion;
271 * uint32_t callback_ident;
272 * nfs_cb_argop4 argarray<>;
273 * };
274*/
275static void encode_cb_compound4args(struct xdr_stream *xdr,
276 struct nfs4_cb_compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
Al Virof00f3282006-10-19 23:29:01 -0700278 __be32 * p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Chuck Levera033db42010-12-14 14:57:22 +0000280 p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4);
281 p = xdr_encode_empty_array(p); /* empty tag */
282 *p++ = cpu_to_be32(hdr->minorversion);
283 *p++ = cpu_to_be32(hdr->ident);
284
Andy Adamsonef52bff2009-06-16 04:20:50 +0300285 hdr->nops_p = p;
Chuck Levera033db42010-12-14 14:57:22 +0000286 *p = cpu_to_be32(hdr->nops); /* argarray element count */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}
288
Chuck Levera033db42010-12-14 14:57:22 +0000289/*
290 * Update argarray element count
291 */
Andy Adamsonef52bff2009-06-16 04:20:50 +0300292static void encode_cb_nops(struct nfs4_cb_compound_hdr *hdr)
293{
Chuck Levera033db42010-12-14 14:57:22 +0000294 BUG_ON(hdr->nops > NFS4_MAX_BACK_CHANNEL_OPS);
295 *hdr->nops_p = cpu_to_be32(hdr->nops);
Andy Adamsonef52bff2009-06-16 04:20:50 +0300296}
297
Chuck Levera033db42010-12-14 14:57:22 +0000298/*
299 * CB_RECALL4args
300 *
301 * struct CB_RECALL4args {
302 * stateid4 stateid;
303 * bool truncate;
304 * nfs_fh4 fh;
305 * };
306 */
307static void encode_cb_recall4args(struct xdr_stream *xdr,
308 const struct nfs4_delegation *dp,
309 struct nfs4_cb_compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Al Virof00f3282006-10-19 23:29:01 -0700311 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Chuck Levera033db42010-12-14 14:57:22 +0000313 encode_nfs_cb_opnum4(xdr, OP_CB_RECALL);
314 encode_stateid4(xdr, &dp->dl_stateid);
315
316 p = xdr_reserve_space(xdr, 4);
317 *p++ = xdr_zero; /* truncate */
318
319 encode_nfs_fh4(xdr, &dp->dl_fh);
320
Andy Adamsonef52bff2009-06-16 04:20:50 +0300321 hdr->nops++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322}
323
Chuck Levera033db42010-12-14 14:57:22 +0000324/*
325 * CB_SEQUENCE4args
326 *
327 * struct CB_SEQUENCE4args {
328 * sessionid4 csa_sessionid;
329 * sequenceid4 csa_sequenceid;
330 * slotid4 csa_slotid;
331 * slotid4 csa_highest_slotid;
332 * bool csa_cachethis;
333 * referring_call_list4 csa_referring_call_lists<>;
334 * };
335 */
336static void encode_cb_sequence4args(struct xdr_stream *xdr,
337 const struct nfsd4_callback *cb,
338 struct nfs4_cb_compound_hdr *hdr)
Benny Halevy2af73582009-09-10 12:26:51 +0300339{
Chuck Levera033db42010-12-14 14:57:22 +0000340 struct nfsd4_session *session = cb->cb_clp->cl_cb_session;
Benny Halevy2af73582009-09-10 12:26:51 +0300341 __be32 *p;
342
343 if (hdr->minorversion == 0)
344 return;
345
Chuck Levera033db42010-12-14 14:57:22 +0000346 encode_nfs_cb_opnum4(xdr, OP_CB_SEQUENCE);
347 encode_sessionid4(xdr, session);
Benny Halevy2af73582009-09-10 12:26:51 +0300348
Chuck Levera033db42010-12-14 14:57:22 +0000349 p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4 + 4);
350 *p++ = cpu_to_be32(session->se_cb_seq_nr); /* csa_sequenceid */
351 *p++ = xdr_zero; /* csa_slotid */
352 *p++ = xdr_zero; /* csa_highest_slotid */
353 *p++ = xdr_zero; /* csa_cachethis */
354 xdr_encode_empty_array(p); /* csa_referring_call_lists */
355
Benny Halevy2af73582009-09-10 12:26:51 +0300356 hdr->nops++;
357}
358
Chuck Levera033db42010-12-14 14:57:22 +0000359/*
360 * NFSv4.0 and NFSv4.1 XDR encode functions
361 *
362 * NFSv4.0 callback argument types are defined in section 15 of RFC
363 * 3530: "Network File System (NFS) version 4 Protocol" and section 20
364 * of RFC 5661: "Network File System (NFS) Version 4 Minor Version 1
365 * Protocol".
366 */
367
368/*
369 * NB: Without this zero space reservation, callbacks over krb5p fail
370 */
371static int nfs4_xdr_enc_cb_null(struct rpc_rqst *req, __be32 *p, void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372{
373 struct xdr_stream xdrs, *xdr = &xdrs;
374
375 xdr_init_encode(&xdrs, &req->rq_snd_buf, p);
Chuck Levera033db42010-12-14 14:57:22 +0000376 xdr_reserve_space(xdr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 return 0;
378}
379
Chuck Levera033db42010-12-14 14:57:22 +0000380/*
381 * 20.2. Operation 4: CB_RECALL - Recall a Delegation
382 */
383static int nfs4_xdr_enc_cb_recall(struct rpc_rqst *req, __be32 *p,
384 const struct nfsd4_callback *cb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
386 struct xdr_stream xdr;
Chuck Levera033db42010-12-14 14:57:22 +0000387 const struct nfs4_delegation *args = cb->cb_op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 struct nfs4_cb_compound_hdr hdr = {
J. Bruce Fields6ff8da02010-06-04 20:04:45 -0400389 .ident = cb->cb_clp->cl_cb_ident,
J. Bruce Fieldsfb003922010-05-31 18:21:37 -0400390 .minorversion = cb->cb_minorversion,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 };
392
393 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
Chuck Levera033db42010-12-14 14:57:22 +0000394 encode_cb_compound4args(&xdr, &hdr);
395 encode_cb_sequence4args(&xdr, cb, &hdr);
396 encode_cb_recall4args(&xdr, args, &hdr);
Andy Adamsonef52bff2009-06-16 04:20:50 +0300397 encode_cb_nops(&hdr);
398 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399}
400
401
402static int
403decode_cb_compound_hdr(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr){
Al Virof00f3282006-10-19 23:29:01 -0700404 __be32 *p;
J. Bruce Fields68a4b482010-05-27 09:30:39 -0400405 u32 taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407 READ_BUF(8);
408 READ32(hdr->status);
J. Bruce Fields68a4b482010-05-27 09:30:39 -0400409 /* We've got no use for the tag; ignore it: */
410 READ32(taglen);
411 READ_BUF(taglen + 4);
412 p += XDR_QUADLEN(taglen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 READ32(hdr->nops);
414 return 0;
415}
416
417static int
418decode_cb_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
419{
Al Virof00f3282006-10-19 23:29:01 -0700420 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 u32 op;
422 int32_t nfserr;
423
424 READ_BUF(8);
425 READ32(op);
426 if (op != expected) {
427 dprintk("NFSD: decode_cb_op_hdr: Callback server returned "
428 " operation %d but we issued a request for %d\n",
429 op, expected);
430 return -EIO;
431 }
432 READ32(nfserr);
433 if (nfserr != NFS_OK)
434 return -nfs_cb_stat_to_errno(nfserr);
435 return 0;
436}
437
Benny Halevy2af73582009-09-10 12:26:51 +0300438/*
439 * Our current back channel implmentation supports a single backchannel
440 * with a single slot.
441 */
442static int
J. Bruce Fieldsfb003922010-05-31 18:21:37 -0400443decode_cb_sequence(struct xdr_stream *xdr, struct nfsd4_callback *cb,
Benny Halevy2af73582009-09-10 12:26:51 +0300444 struct rpc_rqst *rqstp)
445{
J. Bruce Fields90c81452010-06-14 17:49:37 -0400446 struct nfsd4_session *ses = cb->cb_clp->cl_cb_session;
Benny Halevy2af73582009-09-10 12:26:51 +0300447 struct nfs4_sessionid id;
448 int status;
449 u32 dummy;
450 __be32 *p;
451
J. Bruce Fieldsfb003922010-05-31 18:21:37 -0400452 if (cb->cb_minorversion == 0)
Benny Halevy2af73582009-09-10 12:26:51 +0300453 return 0;
454
455 status = decode_cb_op_hdr(xdr, OP_CB_SEQUENCE);
456 if (status)
457 return status;
458
459 /*
460 * If the server returns different values for sessionID, slotID or
461 * sequence number, the server is looney tunes.
462 */
463 status = -ESERVERFAULT;
464
465 READ_BUF(NFS4_MAX_SESSIONID_LEN + 16);
466 memcpy(id.data, p, NFS4_MAX_SESSIONID_LEN);
467 p += XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN);
J. Bruce Fields90c81452010-06-14 17:49:37 -0400468 if (memcmp(id.data, ses->se_sessionid.data, NFS4_MAX_SESSIONID_LEN)) {
Benny Halevy2af73582009-09-10 12:26:51 +0300469 dprintk("%s Invalid session id\n", __func__);
470 goto out;
471 }
472 READ32(dummy);
J. Bruce Fieldsac7c46f2010-06-14 19:01:57 -0400473 if (dummy != ses->se_cb_seq_nr) {
Benny Halevy2af73582009-09-10 12:26:51 +0300474 dprintk("%s Invalid sequence number\n", __func__);
475 goto out;
476 }
477 READ32(dummy); /* slotid must be 0 */
478 if (dummy != 0) {
479 dprintk("%s Invalid slotid\n", __func__);
480 goto out;
481 }
482 /* FIXME: process highest slotid and target highest slotid */
483 status = 0;
484out:
485 return status;
486}
487
488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489static int
Al Virof00f3282006-10-19 23:29:01 -0700490nfs4_xdr_dec_cb_null(struct rpc_rqst *req, __be32 *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
492 return 0;
493}
494
495static int
Ricardo Labiaga0421b5c2009-09-10 12:27:04 +0300496nfs4_xdr_dec_cb_recall(struct rpc_rqst *rqstp, __be32 *p,
J. Bruce Fieldsfb003922010-05-31 18:21:37 -0400497 struct nfsd4_callback *cb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
499 struct xdr_stream xdr;
500 struct nfs4_cb_compound_hdr hdr;
501 int status;
502
503 xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p);
504 status = decode_cb_compound_hdr(&xdr, &hdr);
505 if (status)
506 goto out;
J. Bruce Fieldsfb003922010-05-31 18:21:37 -0400507 if (cb) {
508 status = decode_cb_sequence(&xdr, cb, rqstp);
Ricardo Labiaga0421b5c2009-09-10 12:27:04 +0300509 if (status)
510 goto out;
511 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 status = decode_cb_op_hdr(&xdr, OP_CB_RECALL);
513out:
514 return status;
515}
516
517/*
518 * RPC procedure tables
519 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#define PROC(proc, call, argtype, restype) \
521[NFSPROC4_CLNT_##proc] = { \
522 .p_proc = NFSPROC4_CB_##call, \
523 .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \
524 .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -0400525 .p_arglen = NFS4_##argtype##_sz, \
526 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -0500527 .p_statidx = NFSPROC4_CB_##call, \
528 .p_name = #proc, \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529}
530
NeilBrownfd39ca92005-06-23 22:04:03 -0700531static struct rpc_procinfo nfs4_cb_procedures[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 PROC(CB_NULL, NULL, enc_cb_null, dec_cb_null),
533 PROC(CB_RECALL, COMPOUND, enc_cb_recall, dec_cb_recall),
534};
535
NeilBrownfd39ca92005-06-23 22:04:03 -0700536static struct rpc_version nfs_cb_version4 = {
J. Bruce Fieldsb7299f42010-05-14 17:57:35 -0400537/*
538 * Note on the callback rpc program version number: despite language in rfc
539 * 5661 section 18.36.3 requiring servers to use 4 in this field, the
540 * official xdr descriptions for both 4.0 and 4.1 specify version 1, and
541 * in practice that appears to be what implementations use. The section
542 * 18.36.3 language is expected to be fixed in an erratum.
543 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 .number = 1,
Tobias Klausere8c96f82006-03-24 03:15:34 -0800545 .nrprocs = ARRAY_SIZE(nfs4_cb_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 .procs = nfs4_cb_procedures
547};
548
549static struct rpc_version * nfs_cb_version[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 &nfs_cb_version4,
551};
552
Olga Kornievskaiaff7d9752008-03-28 16:04:56 -0400553static struct rpc_program cb_program;
554
555static struct rpc_stat cb_stats = {
556 .program = &cb_program
557};
558
559#define NFS4_CALLBACK 0x40000000
560static struct rpc_program cb_program = {
561 .name = "nfs4_cb",
562 .number = NFS4_CALLBACK,
563 .nrvers = ARRAY_SIZE(nfs_cb_version),
564 .version = nfs_cb_version,
565 .stats = &cb_stats,
Olga Kornievskaia61054b12008-12-23 16:19:00 -0500566 .pipe_dir_name = "/nfsd4_cb",
Olga Kornievskaiaff7d9752008-03-28 16:04:56 -0400567};
568
J. Bruce Fields595947a2009-03-05 17:18:10 -0500569static int max_cb_time(void)
570{
J. Bruce Fieldscf07d2e2010-02-28 23:20:19 -0500571 return max(nfsd4_lease/10, (time_t)1) * HZ;
J. Bruce Fields595947a2009-03-05 17:18:10 -0500572}
573
J. Bruce Fields2b47eec2007-07-27 18:06:50 -0400574/* Reference counting, callback cleanup, etc., all look racy as heck.
J. Bruce Fields2bf23872010-03-08 12:37:27 -0500575 * And why is cl_cb_set an atomic? */
J. Bruce Fields2b47eec2007-07-27 18:06:50 -0400576
J. Bruce Fields07263f12010-05-31 19:09:40 -0400577int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *conn)
J. Bruce Fields2b47eec2007-07-27 18:06:50 -0400578{
Chuck Leverae5c7942006-08-22 20:06:21 -0400579 struct rpc_timeout timeparms = {
J. Bruce Fields595947a2009-03-05 17:18:10 -0500580 .to_initval = max_cb_time(),
581 .to_retries = 0,
Chuck Leverae5c7942006-08-22 20:06:21 -0400582 };
Chuck Leverae5c7942006-08-22 20:06:21 -0400583 struct rpc_create_args args = {
Pavel Emelyanovc653ce32010-09-29 16:04:45 +0400584 .net = &init_net,
J. Bruce Fields07263f12010-05-31 19:09:40 -0400585 .address = (struct sockaddr *) &conn->cb_addr,
586 .addrsize = conn->cb_addrlen,
Chuck Leverae5c7942006-08-22 20:06:21 -0400587 .timeout = &timeparms,
Olga Kornievskaiaff7d9752008-03-28 16:04:56 -0400588 .program = &cb_program,
J. Bruce Fieldsb7299f42010-05-14 17:57:35 -0400589 .version = 0,
Olga Kornievskaia61054b12008-12-23 16:19:00 -0500590 .authflavor = clp->cl_flavor,
Olga Kornievskaiab6b61522008-06-09 16:51:31 -0400591 .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET),
Chuck Leverae5c7942006-08-22 20:06:21 -0400592 };
J. Bruce Fields63c86712007-10-25 19:00:26 -0400593 struct rpc_clnt *client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
J. Bruce Fields5d18c1c2010-10-19 23:00:12 -0400595 if (clp->cl_minorversion == 0) {
596 if (!clp->cl_principal && (clp->cl_flavor >= RPC_AUTH_GSS_KRB5))
597 return -EINVAL;
598 args.client_name = clp->cl_principal;
599 args.prognumber = conn->cb_prog,
600 args.protocol = XPRT_TRANSPORT_TCP;
601 clp->cl_cb_ident = conn->cb_ident;
602 } else {
J. Bruce Fields07263f12010-05-31 19:09:40 -0400603 args.bc_xprt = conn->cb_xprt;
J. Bruce Fields8b5ce5c2010-10-19 17:31:50 -0400604 args.prognumber = clp->cl_cb_session->se_cb_prog;
Alexandros Batsakis3ddc8bf2009-09-10 12:27:21 +0300605 args.protocol = XPRT_TRANSPORT_BC_TCP;
606 }
Chuck Leverae5c7942006-08-22 20:06:21 -0400607 /* Create RPC client */
J. Bruce Fields63c86712007-10-25 19:00:26 -0400608 client = rpc_create(&args);
J. Bruce Fieldse1cab5a52009-02-23 10:45:27 -0800609 if (IS_ERR(client)) {
J. Bruce Fieldsa601cae2009-02-22 16:43:45 -0800610 dprintk("NFSD: couldn't create callback client: %ld\n",
611 PTR_ERR(client));
J. Bruce Fieldse1cab5a52009-02-23 10:45:27 -0800612 return PTR_ERR(client);
613 }
J. Bruce Fields6ff8da02010-06-04 20:04:45 -0400614 clp->cl_cb_client = client;
J. Bruce Fieldse1cab5a52009-02-23 10:45:27 -0800615 return 0;
J. Bruce Fieldsa601cae2009-02-22 16:43:45 -0800616
617}
618
J. Bruce Fieldsecdd03b2009-02-23 19:35:22 -0800619static void warn_no_callback_path(struct nfs4_client *clp, int reason)
620{
621 dprintk("NFSD: warning: no callback path to client %.*s: error %d\n",
622 (int)clp->cl_name.len, clp->cl_name.data, reason);
623}
624
J. Bruce Fieldse300a632009-03-05 15:01:11 -0500625static void nfsd4_cb_probe_done(struct rpc_task *task, void *calldata)
626{
J. Bruce Fieldscee277d2010-05-26 17:52:14 -0400627 struct nfs4_client *clp = container_of(calldata, struct nfs4_client, cl_cb_null);
J. Bruce Fieldse300a632009-03-05 15:01:11 -0500628
629 if (task->tk_status)
630 warn_no_callback_path(clp, task->tk_status);
631 else
J. Bruce Fields2bf23872010-03-08 12:37:27 -0500632 atomic_set(&clp->cl_cb_set, 1);
J. Bruce Fieldse300a632009-03-05 15:01:11 -0500633}
634
635static const struct rpc_call_ops nfsd4_cb_probe_ops = {
J. Bruce Fieldscee277d2010-05-26 17:52:14 -0400636 /* XXX: release method to ensure we set the cb channel down if
637 * necessary on early failure? */
J. Bruce Fieldse300a632009-03-05 15:01:11 -0500638 .rpc_call_done = nfsd4_cb_probe_done,
639};
640
J. Bruce Fields80fc0152009-09-15 18:07:35 -0400641static struct rpc_cred *callback_cred;
J. Bruce Fields3cef9ab2009-02-23 21:42:10 -0800642
J. Bruce Fields80fc0152009-09-15 18:07:35 -0400643int set_callback_cred(void)
644{
J. Bruce Fields8d75da82010-03-03 16:13:29 -0500645 if (callback_cred)
646 return 0;
J. Bruce Fields80fc0152009-09-15 18:07:35 -0400647 callback_cred = rpc_lookup_machine_cred();
648 if (!callback_cred)
649 return -ENOMEM;
650 return 0;
J. Bruce Fields3cef9ab2009-02-23 21:42:10 -0800651}
652
J. Bruce Fieldscee277d2010-05-26 17:52:14 -0400653static struct workqueue_struct *callback_wq;
J. Bruce Fields80fc0152009-09-15 18:07:35 -0400654
J. Bruce Fields5a3c9d72010-10-19 17:56:52 -0400655static void do_probe_callback(struct nfs4_client *clp)
J. Bruce Fieldsa601cae2009-02-22 16:43:45 -0800656{
J. Bruce Fieldscee277d2010-05-26 17:52:14 -0400657 struct nfsd4_callback *cb = &clp->cl_cb_null;
J. Bruce Fieldsa601cae2009-02-22 16:43:45 -0800658
J. Bruce Fieldsfb003922010-05-31 18:21:37 -0400659 cb->cb_op = NULL;
660 cb->cb_clp = clp;
J. Bruce Fieldscee277d2010-05-26 17:52:14 -0400661
662 cb->cb_msg.rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL];
663 cb->cb_msg.rpc_argp = NULL;
664 cb->cb_msg.rpc_resp = NULL;
665 cb->cb_msg.rpc_cred = callback_cred;
666
667 cb->cb_ops = &nfsd4_cb_probe_ops;
668
669 queue_work(callback_wq, &cb->cb_work);
J. Bruce Fields63c86712007-10-25 19:00:26 -0400670}
671
672/*
J. Bruce Fields5a3c9d72010-10-19 17:56:52 -0400673 * Poke the callback thread to process any updates to the callback
674 * parameters, and send a null probe.
J. Bruce Fields63c86712007-10-25 19:00:26 -0400675 */
J. Bruce Fields5a3c9d72010-10-19 17:56:52 -0400676void nfsd4_probe_callback(struct nfs4_client *clp)
677{
678 set_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_cb_flags);
679 do_probe_callback(clp);
680}
681
682void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *conn)
J. Bruce Fields63c86712007-10-25 19:00:26 -0400683{
J. Bruce Fields2bf23872010-03-08 12:37:27 -0500684 BUG_ON(atomic_read(&clp->cl_cb_set));
J. Bruce Fields63c86712007-10-25 19:00:26 -0400685
J. Bruce Fields6ff8da02010-06-04 20:04:45 -0400686 spin_lock(&clp->cl_lock);
687 memcpy(&clp->cl_cb_conn, conn, sizeof(struct nfs4_cb_conn));
J. Bruce Fields6ff8da02010-06-04 20:04:45 -0400688 spin_unlock(&clp->cl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
Ricardo Labiaga2a1d1b52009-09-10 12:26:38 +0300691/*
692 * There's currently a single callback channel slot.
693 * If the slot is available, then mark it busy. Otherwise, set the
694 * thread for sleeping on the callback RPC wait queue.
695 */
696static int nfsd41_cb_setup_sequence(struct nfs4_client *clp,
697 struct rpc_task *task)
698{
J. Bruce Fields90c81452010-06-14 17:49:37 -0400699 u32 *ptr = (u32 *)clp->cl_cb_session->se_sessionid.data;
Ricardo Labiaga2a1d1b52009-09-10 12:26:38 +0300700 int status = 0;
701
702 dprintk("%s: %u:%u:%u:%u\n", __func__,
703 ptr[0], ptr[1], ptr[2], ptr[3]);
704
705 if (test_and_set_bit(0, &clp->cl_cb_slot_busy) != 0) {
706 rpc_sleep_on(&clp->cl_cb_waitq, task, NULL);
707 dprintk("%s slot is busy\n", __func__);
708 status = -EAGAIN;
709 goto out;
710 }
Ricardo Labiaga2a1d1b52009-09-10 12:26:38 +0300711out:
712 dprintk("%s status=%d\n", __func__, status);
713 return status;
714}
715
716/*
717 * TODO: cb_sequence should support referring call lists, cachethis, multiple
718 * slots, and mark callback channel down on communication errors.
719 */
720static void nfsd4_cb_prepare(struct rpc_task *task, void *calldata)
721{
J. Bruce Fields58784532010-05-16 16:47:08 -0400722 struct nfsd4_callback *cb = calldata;
723 struct nfs4_delegation *dp = container_of(cb, struct nfs4_delegation, dl_recall);
Ricardo Labiaga2a1d1b52009-09-10 12:26:38 +0300724 struct nfs4_client *clp = dp->dl_client;
J. Bruce Fields8323c3b2010-10-19 19:36:51 -0400725 u32 minorversion = clp->cl_minorversion;
Ricardo Labiaga2a1d1b52009-09-10 12:26:38 +0300726 int status = 0;
727
J. Bruce Fieldsfb003922010-05-31 18:21:37 -0400728 cb->cb_minorversion = minorversion;
Ricardo Labiaga2a1d1b52009-09-10 12:26:38 +0300729 if (minorversion) {
730 status = nfsd41_cb_setup_sequence(clp, task);
731 if (status) {
732 if (status != -EAGAIN) {
733 /* terminate rpc task */
734 task->tk_status = status;
735 task->tk_action = NULL;
736 }
737 return;
738 }
739 }
740 rpc_call_start(task);
741}
742
Ricardo Labiaga0421b5c2009-09-10 12:27:04 +0300743static void nfsd4_cb_done(struct rpc_task *task, void *calldata)
744{
J. Bruce Fields58784532010-05-16 16:47:08 -0400745 struct nfsd4_callback *cb = calldata;
746 struct nfs4_delegation *dp = container_of(cb, struct nfs4_delegation, dl_recall);
Ricardo Labiaga0421b5c2009-09-10 12:27:04 +0300747 struct nfs4_client *clp = dp->dl_client;
748
749 dprintk("%s: minorversion=%d\n", __func__,
J. Bruce Fields8323c3b2010-10-19 19:36:51 -0400750 clp->cl_minorversion);
Ricardo Labiaga0421b5c2009-09-10 12:27:04 +0300751
J. Bruce Fields8323c3b2010-10-19 19:36:51 -0400752 if (clp->cl_minorversion) {
Ricardo Labiaga0421b5c2009-09-10 12:27:04 +0300753 /* No need for lock, access serialized in nfsd4_cb_prepare */
J. Bruce Fieldsac7c46f2010-06-14 19:01:57 -0400754 ++clp->cl_cb_session->se_cb_seq_nr;
Ricardo Labiaga0421b5c2009-09-10 12:27:04 +0300755 clear_bit(0, &clp->cl_cb_slot_busy);
756 rpc_wake_up_next(&clp->cl_cb_waitq);
757 dprintk("%s: freed slot, new seqid=%d\n", __func__,
J. Bruce Fieldsac7c46f2010-06-14 19:01:57 -0400758 clp->cl_cb_session->se_cb_seq_nr);
Ricardo Labiaga0421b5c2009-09-10 12:27:04 +0300759
760 /* We're done looking into the sequence information */
761 task->tk_msg.rpc_resp = NULL;
762 }
763}
764
J. Bruce Fields4b21d0d2010-03-07 23:39:01 -0500765
J. Bruce Fields63e48632009-05-01 22:36:55 -0400766static void nfsd4_cb_recall_done(struct rpc_task *task, void *calldata)
767{
J. Bruce Fields58784532010-05-16 16:47:08 -0400768 struct nfsd4_callback *cb = calldata;
769 struct nfs4_delegation *dp = container_of(cb, struct nfs4_delegation, dl_recall);
J. Bruce Fields63e48632009-05-01 22:36:55 -0400770 struct nfs4_client *clp = dp->dl_client;
J. Bruce Fields4b21d0d2010-03-07 23:39:01 -0500771 struct rpc_clnt *current_rpc_client = clp->cl_cb_client;
J. Bruce Fields63e48632009-05-01 22:36:55 -0400772
Ricardo Labiaga0421b5c2009-09-10 12:27:04 +0300773 nfsd4_cb_done(task, calldata);
774
J. Bruce Fields4b21d0d2010-03-07 23:39:01 -0500775 if (current_rpc_client == NULL) {
776 /* We're shutting down; give up. */
777 /* XXX: err, or is it ok just to fall through
778 * and rpc_restart_call? */
779 return;
780 }
781
J. Bruce Fields63e48632009-05-01 22:36:55 -0400782 switch (task->tk_status) {
J. Bruce Fields172c85d2010-05-30 11:53:12 -0400783 case 0:
784 return;
785 case -EBADHANDLE:
786 case -NFS4ERR_BAD_STATEID:
787 /* Race: client probably got cb_recall
788 * before open reply granting delegation */
789 break;
790 default:
J. Bruce Fields63e48632009-05-01 22:36:55 -0400791 /* Network partition? */
J. Bruce Fields2bf23872010-03-08 12:37:27 -0500792 atomic_set(&clp->cl_cb_set, 0);
J. Bruce Fields63e48632009-05-01 22:36:55 -0400793 warn_no_callback_path(clp, task->tk_status);
J. Bruce Fields4b21d0d2010-03-07 23:39:01 -0500794 if (current_rpc_client != task->tk_client) {
795 /* queue a callback on the new connection: */
J. Bruce Fieldscba9ba42010-06-01 11:21:40 -0400796 atomic_inc(&dp->dl_count);
J. Bruce Fields4b21d0d2010-03-07 23:39:01 -0500797 nfsd4_cb_recall(dp);
798 return;
799 }
J. Bruce Fields63e48632009-05-01 22:36:55 -0400800 }
801 if (dp->dl_retries--) {
802 rpc_delay(task, 2*HZ);
803 task->tk_status = 0;
Boaz Harroshc18c8212010-06-29 14:33:55 +0300804 rpc_restart_call_prepare(task);
Ricardo Labiaga0421b5c2009-09-10 12:27:04 +0300805 return;
J. Bruce Fields63e48632009-05-01 22:36:55 -0400806 } else {
J. Bruce Fields2bf23872010-03-08 12:37:27 -0500807 atomic_set(&clp->cl_cb_set, 0);
J. Bruce Fields63e48632009-05-01 22:36:55 -0400808 warn_no_callback_path(clp, task->tk_status);
809 }
810}
811
812static void nfsd4_cb_recall_release(void *calldata)
813{
J. Bruce Fields58784532010-05-16 16:47:08 -0400814 struct nfsd4_callback *cb = calldata;
815 struct nfs4_delegation *dp = container_of(cb, struct nfs4_delegation, dl_recall);
J. Bruce Fields63e48632009-05-01 22:36:55 -0400816
817 nfs4_put_delegation(dp);
J. Bruce Fields63e48632009-05-01 22:36:55 -0400818}
819
820static const struct rpc_call_ops nfsd4_cb_recall_ops = {
Ricardo Labiaga2a1d1b52009-09-10 12:26:38 +0300821 .rpc_call_prepare = nfsd4_cb_prepare,
J. Bruce Fields63e48632009-05-01 22:36:55 -0400822 .rpc_call_done = nfsd4_cb_recall_done,
823 .rpc_release = nfsd4_cb_recall_release,
824};
825
J. Bruce Fieldsb5a1a812010-03-03 14:52:55 -0500826int nfsd4_create_callback_queue(void)
827{
828 callback_wq = create_singlethread_workqueue("nfsd4_callbacks");
829 if (!callback_wq)
830 return -ENOMEM;
831 return 0;
832}
833
834void nfsd4_destroy_callback_queue(void)
835{
836 destroy_workqueue(callback_wq);
837}
838
Benny Halevyab707e152010-05-12 00:14:06 +0300839/* must be called under the state lock */
J. Bruce Fields6ff8da02010-06-04 20:04:45 -0400840void nfsd4_shutdown_callback(struct nfs4_client *clp)
J. Bruce Fieldsb5a1a812010-03-03 14:52:55 -0500841{
J. Bruce Fields6ff8da02010-06-04 20:04:45 -0400842 set_bit(NFSD4_CLIENT_KILL, &clp->cl_cb_flags);
J. Bruce Fieldsb5a1a812010-03-03 14:52:55 -0500843 /*
J. Bruce Fields6ff8da02010-06-04 20:04:45 -0400844 * Note this won't actually result in a null callback;
845 * instead, nfsd4_do_callback_rpc() will detect the killed
846 * client, destroy the rpc client, and stop:
J. Bruce Fieldsb5a1a812010-03-03 14:52:55 -0500847 */
J. Bruce Fields6ff8da02010-06-04 20:04:45 -0400848 do_probe_callback(clp);
J. Bruce Fieldsb5a1a812010-03-03 14:52:55 -0500849 flush_workqueue(callback_wq);
J. Bruce Fieldsb5a1a812010-03-03 14:52:55 -0500850}
851
J. Bruce Fields58784532010-05-16 16:47:08 -0400852void nfsd4_release_cb(struct nfsd4_callback *cb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853{
J. Bruce Fields58784532010-05-16 16:47:08 -0400854 if (cb->cb_ops->rpc_release)
855 cb->cb_ops->rpc_release(cb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856}
J. Bruce Fieldsb5a1a812010-03-03 14:52:55 -0500857
J. Bruce Fields6ff8da02010-06-04 20:04:45 -0400858void nfsd4_process_cb_update(struct nfsd4_callback *cb)
859{
860 struct nfs4_cb_conn conn;
861 struct nfs4_client *clp = cb->cb_clp;
862 int err;
863
864 /*
865 * This is either an update, or the client dying; in either case,
866 * kill the old client:
867 */
868 if (clp->cl_cb_client) {
869 rpc_shutdown_client(clp->cl_cb_client);
870 clp->cl_cb_client = NULL;
871 }
872 if (test_bit(NFSD4_CLIENT_KILL, &clp->cl_cb_flags))
873 return;
874 spin_lock(&clp->cl_lock);
875 /*
876 * Only serialized callback code is allowed to clear these
877 * flags; main nfsd code can only set them:
878 */
879 BUG_ON(!clp->cl_cb_flags);
880 clear_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_cb_flags);
881 memcpy(&conn, &cb->cb_clp->cl_cb_conn, sizeof(struct nfs4_cb_conn));
882 spin_unlock(&clp->cl_lock);
883
884 err = setup_callback_client(clp, &conn);
885 if (err)
886 warn_no_callback_path(clp, err);
887}
888
J. Bruce Fieldsb5a1a812010-03-03 14:52:55 -0500889void nfsd4_do_callback_rpc(struct work_struct *w)
890{
J. Bruce Fields58784532010-05-16 16:47:08 -0400891 struct nfsd4_callback *cb = container_of(w, struct nfsd4_callback, cb_work);
J. Bruce Fieldsfb003922010-05-31 18:21:37 -0400892 struct nfs4_client *clp = cb->cb_clp;
J. Bruce Fields6ff8da02010-06-04 20:04:45 -0400893 struct rpc_clnt *clnt;
J. Bruce Fieldsb5a1a812010-03-03 14:52:55 -0500894
J. Bruce Fields6ff8da02010-06-04 20:04:45 -0400895 if (clp->cl_cb_flags)
896 nfsd4_process_cb_update(cb);
897
898 clnt = clp->cl_cb_client;
899 if (!clnt) {
900 /* Callback channel broken, or client killed; give up: */
J. Bruce Fields58784532010-05-16 16:47:08 -0400901 nfsd4_release_cb(cb);
J. Bruce Fields6ff8da02010-06-04 20:04:45 -0400902 return;
J. Bruce Fields58784532010-05-16 16:47:08 -0400903 }
J. Bruce Fieldscee277d2010-05-26 17:52:14 -0400904 rpc_call_async(clnt, &cb->cb_msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN,
905 cb->cb_ops, cb);
J. Bruce Fieldsb5a1a812010-03-03 14:52:55 -0500906}
907
J. Bruce Fieldsb5a1a812010-03-03 14:52:55 -0500908void nfsd4_cb_recall(struct nfs4_delegation *dp)
909{
J. Bruce Fields58784532010-05-16 16:47:08 -0400910 struct nfsd4_callback *cb = &dp->dl_recall;
911
912 dp->dl_retries = 1;
J. Bruce Fieldsfb003922010-05-31 18:21:37 -0400913 cb->cb_op = dp;
914 cb->cb_clp = dp->dl_client;
J. Bruce Fields58784532010-05-16 16:47:08 -0400915 cb->cb_msg.rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_RECALL];
J. Bruce Fieldsfb003922010-05-31 18:21:37 -0400916 cb->cb_msg.rpc_argp = cb;
917 cb->cb_msg.rpc_resp = cb;
J. Bruce Fields58784532010-05-16 16:47:08 -0400918 cb->cb_msg.rpc_cred = callback_cred;
919
920 cb->cb_ops = &nfsd4_cb_recall_ops;
921 dp->dl_retries = 1;
922
J. Bruce Fieldsb5a1a812010-03-03 14:52:55 -0500923 queue_work(callback_wq, &dp->dl_recall.cb_work);
924}