diff options
author | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
---|---|---|
committer | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
commit | c71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch) | |
tree | ecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /fs/nfsd/nfs4callback.c | |
parent | ea53c912f8a86a8567697115b6a0d8152beee5c8 (diff) | |
parent | 6a00f206debf8a5c8899055726ad127dbeeed098 (diff) |
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts:
litmus/sched_cedf.c
Diffstat (limited to 'fs/nfsd/nfs4callback.c')
-rw-r--r-- | fs/nfsd/nfs4callback.c | 1034 |
1 files changed, 635 insertions, 399 deletions
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c index 988cbb3a19b6..02eb4edf0ece 100644 --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c | |||
@@ -41,7 +41,6 @@ | |||
41 | 41 | ||
42 | #define NFSPROC4_CB_NULL 0 | 42 | #define NFSPROC4_CB_NULL 0 |
43 | #define NFSPROC4_CB_COMPOUND 1 | 43 | #define NFSPROC4_CB_COMPOUND 1 |
44 | #define NFS4_STATEID_SIZE 16 | ||
45 | 44 | ||
46 | /* Index of predefined Linux callback client operations */ | 45 | /* Index of predefined Linux callback client operations */ |
47 | 46 | ||
@@ -51,11 +50,6 @@ enum { | |||
51 | NFSPROC4_CLNT_CB_SEQUENCE, | 50 | NFSPROC4_CLNT_CB_SEQUENCE, |
52 | }; | 51 | }; |
53 | 52 | ||
54 | enum nfs_cb_opnum4 { | ||
55 | OP_CB_RECALL = 4, | ||
56 | OP_CB_SEQUENCE = 11, | ||
57 | }; | ||
58 | |||
59 | #define NFS4_MAXTAGLEN 20 | 53 | #define NFS4_MAXTAGLEN 20 |
60 | 54 | ||
61 | #define NFS4_enc_cb_null_sz 0 | 55 | #define NFS4_enc_cb_null_sz 0 |
@@ -80,61 +74,6 @@ enum nfs_cb_opnum4 { | |||
80 | cb_sequence_dec_sz + \ | 74 | cb_sequence_dec_sz + \ |
81 | op_dec_sz) | 75 | op_dec_sz) |
82 | 76 | ||
83 | /* | ||
84 | * Generic encode routines from fs/nfs/nfs4xdr.c | ||
85 | */ | ||
86 | static inline __be32 * | ||
87 | xdr_writemem(__be32 *p, const void *ptr, int nbytes) | ||
88 | { | ||
89 | int tmp = XDR_QUADLEN(nbytes); | ||
90 | if (!tmp) | ||
91 | return p; | ||
92 | p[tmp-1] = 0; | ||
93 | memcpy(p, ptr, nbytes); | ||
94 | return p + tmp; | ||
95 | } | ||
96 | |||
97 | #define WRITE32(n) *p++ = htonl(n) | ||
98 | #define WRITEMEM(ptr,nbytes) do { \ | ||
99 | p = xdr_writemem(p, ptr, nbytes); \ | ||
100 | } while (0) | ||
101 | #define RESERVE_SPACE(nbytes) do { \ | ||
102 | p = xdr_reserve_space(xdr, nbytes); \ | ||
103 | if (!p) dprintk("NFSD: RESERVE_SPACE(%d) failed in function %s\n", (int) (nbytes), __func__); \ | ||
104 | BUG_ON(!p); \ | ||
105 | } while (0) | ||
106 | |||
107 | /* | ||
108 | * Generic decode routines from fs/nfs/nfs4xdr.c | ||
109 | */ | ||
110 | #define DECODE_TAIL \ | ||
111 | status = 0; \ | ||
112 | out: \ | ||
113 | return status; \ | ||
114 | xdr_error: \ | ||
115 | dprintk("NFSD: xdr error! (%s:%d)\n", __FILE__, __LINE__); \ | ||
116 | status = -EIO; \ | ||
117 | goto out | ||
118 | |||
119 | #define READ32(x) (x) = ntohl(*p++) | ||
120 | #define READ64(x) do { \ | ||
121 | (x) = (u64)ntohl(*p++) << 32; \ | ||
122 | (x) |= ntohl(*p++); \ | ||
123 | } while (0) | ||
124 | #define READTIME(x) do { \ | ||
125 | p++; \ | ||
126 | (x.tv_sec) = ntohl(*p++); \ | ||
127 | (x.tv_nsec) = ntohl(*p++); \ | ||
128 | } while (0) | ||
129 | #define READ_BUF(nbytes) do { \ | ||
130 | p = xdr_inline_decode(xdr, nbytes); \ | ||
131 | if (!p) { \ | ||
132 | dprintk("NFSD: %s: reply buffer overflowed in line %d.\n", \ | ||
133 | __func__, __LINE__); \ | ||
134 | return -EIO; \ | ||
135 | } \ | ||
136 | } while (0) | ||
137 | |||
138 | struct nfs4_cb_compound_hdr { | 77 | struct nfs4_cb_compound_hdr { |
139 | /* args */ | 78 | /* args */ |
140 | u32 ident; /* minorversion 0 only */ | 79 | u32 ident; /* minorversion 0 only */ |
@@ -145,270 +84,487 @@ struct nfs4_cb_compound_hdr { | |||
145 | int status; | 84 | int status; |
146 | }; | 85 | }; |
147 | 86 | ||
148 | static struct { | 87 | /* |
149 | int stat; | 88 | * Handle decode buffer overflows out-of-line. |
150 | int errno; | 89 | */ |
151 | } nfs_cb_errtbl[] = { | 90 | static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) |
152 | { NFS4_OK, 0 }, | 91 | { |
153 | { NFS4ERR_PERM, EPERM }, | 92 | dprintk("NFS: %s prematurely hit the end of our receive buffer. " |
154 | { NFS4ERR_NOENT, ENOENT }, | 93 | "Remaining buffer length is %tu words.\n", |
155 | { NFS4ERR_IO, EIO }, | 94 | func, xdr->end - xdr->p); |
156 | { NFS4ERR_NXIO, ENXIO }, | 95 | } |
157 | { NFS4ERR_ACCESS, EACCES }, | ||
158 | { NFS4ERR_EXIST, EEXIST }, | ||
159 | { NFS4ERR_XDEV, EXDEV }, | ||
160 | { NFS4ERR_NOTDIR, ENOTDIR }, | ||
161 | { NFS4ERR_ISDIR, EISDIR }, | ||
162 | { NFS4ERR_INVAL, EINVAL }, | ||
163 | { NFS4ERR_FBIG, EFBIG }, | ||
164 | { NFS4ERR_NOSPC, ENOSPC }, | ||
165 | { NFS4ERR_ROFS, EROFS }, | ||
166 | { NFS4ERR_MLINK, EMLINK }, | ||
167 | { NFS4ERR_NAMETOOLONG, ENAMETOOLONG }, | ||
168 | { NFS4ERR_NOTEMPTY, ENOTEMPTY }, | ||
169 | { NFS4ERR_DQUOT, EDQUOT }, | ||
170 | { NFS4ERR_STALE, ESTALE }, | ||
171 | { NFS4ERR_BADHANDLE, EBADHANDLE }, | ||
172 | { NFS4ERR_BAD_COOKIE, EBADCOOKIE }, | ||
173 | { NFS4ERR_NOTSUPP, ENOTSUPP }, | ||
174 | { NFS4ERR_TOOSMALL, ETOOSMALL }, | ||
175 | { NFS4ERR_SERVERFAULT, ESERVERFAULT }, | ||
176 | { NFS4ERR_BADTYPE, EBADTYPE }, | ||
177 | { NFS4ERR_LOCKED, EAGAIN }, | ||
178 | { NFS4ERR_RESOURCE, EREMOTEIO }, | ||
179 | { NFS4ERR_SYMLINK, ELOOP }, | ||
180 | { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP }, | ||
181 | { NFS4ERR_DEADLOCK, EDEADLK }, | ||
182 | { -1, EIO } | ||
183 | }; | ||
184 | 96 | ||
185 | static int | 97 | static __be32 *xdr_encode_empty_array(__be32 *p) |
186 | nfs_cb_stat_to_errno(int stat) | ||
187 | { | 98 | { |
188 | int i; | 99 | *p++ = xdr_zero; |
189 | for (i = 0; nfs_cb_errtbl[i].stat != -1; i++) { | 100 | return p; |
190 | if (nfs_cb_errtbl[i].stat == stat) | ||
191 | return nfs_cb_errtbl[i].errno; | ||
192 | } | ||
193 | /* If we cannot translate the error, the recovery routines should | ||
194 | * handle it. | ||
195 | * Note: remaining NFSv4 error codes have values > 10000, so should | ||
196 | * not conflict with native Linux error codes. | ||
197 | */ | ||
198 | return stat; | ||
199 | } | 101 | } |
200 | 102 | ||
201 | /* | 103 | /* |
202 | * XDR encode | 104 | * Encode/decode NFSv4 CB basic data types |
105 | * | ||
106 | * Basic NFSv4 callback data types are defined in section 15 of RFC | ||
107 | * 3530: "Network File System (NFS) version 4 Protocol" and section | ||
108 | * 20 of RFC 5661: "Network File System (NFS) Version 4 Minor Version | ||
109 | * 1 Protocol" | ||
203 | */ | 110 | */ |
204 | 111 | ||
205 | static void | 112 | /* |
206 | encode_stateid(struct xdr_stream *xdr, stateid_t *sid) | 113 | * nfs_cb_opnum4 |
114 | * | ||
115 | * enum nfs_cb_opnum4 { | ||
116 | * OP_CB_GETATTR = 3, | ||
117 | * ... | ||
118 | * }; | ||
119 | */ | ||
120 | enum nfs_cb_opnum4 { | ||
121 | OP_CB_GETATTR = 3, | ||
122 | OP_CB_RECALL = 4, | ||
123 | OP_CB_LAYOUTRECALL = 5, | ||
124 | OP_CB_NOTIFY = 6, | ||
125 | OP_CB_PUSH_DELEG = 7, | ||
126 | OP_CB_RECALL_ANY = 8, | ||
127 | OP_CB_RECALLABLE_OBJ_AVAIL = 9, | ||
128 | OP_CB_RECALL_SLOT = 10, | ||
129 | OP_CB_SEQUENCE = 11, | ||
130 | OP_CB_WANTS_CANCELLED = 12, | ||
131 | OP_CB_NOTIFY_LOCK = 13, | ||
132 | OP_CB_NOTIFY_DEVICEID = 14, | ||
133 | OP_CB_ILLEGAL = 10044 | ||
134 | }; | ||
135 | |||
136 | static void encode_nfs_cb_opnum4(struct xdr_stream *xdr, enum nfs_cb_opnum4 op) | ||
207 | { | 137 | { |
208 | __be32 *p; | 138 | __be32 *p; |
209 | 139 | ||
210 | RESERVE_SPACE(sizeof(stateid_t)); | 140 | p = xdr_reserve_space(xdr, 4); |
211 | WRITE32(sid->si_generation); | 141 | *p = cpu_to_be32(op); |
212 | WRITEMEM(&sid->si_opaque, sizeof(stateid_opaque_t)); | ||
213 | } | 142 | } |
214 | 143 | ||
215 | static void | 144 | /* |
216 | encode_cb_compound_hdr(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr) | 145 | * nfs_fh4 |
146 | * | ||
147 | * typedef opaque nfs_fh4<NFS4_FHSIZE>; | ||
148 | */ | ||
149 | static void encode_nfs_fh4(struct xdr_stream *xdr, const struct knfsd_fh *fh) | ||
217 | { | 150 | { |
218 | __be32 * p; | 151 | u32 length = fh->fh_size; |
152 | __be32 *p; | ||
219 | 153 | ||
220 | RESERVE_SPACE(16); | 154 | BUG_ON(length > NFS4_FHSIZE); |
221 | WRITE32(0); /* tag length is always 0 */ | 155 | p = xdr_reserve_space(xdr, 4 + length); |
222 | WRITE32(hdr->minorversion); | 156 | xdr_encode_opaque(p, &fh->fh_base, length); |
223 | WRITE32(hdr->ident); | ||
224 | hdr->nops_p = p; | ||
225 | WRITE32(hdr->nops); | ||
226 | } | 157 | } |
227 | 158 | ||
228 | static void encode_cb_nops(struct nfs4_cb_compound_hdr *hdr) | 159 | /* |
160 | * stateid4 | ||
161 | * | ||
162 | * struct stateid4 { | ||
163 | * uint32_t seqid; | ||
164 | * opaque other[12]; | ||
165 | * }; | ||
166 | */ | ||
167 | static void encode_stateid4(struct xdr_stream *xdr, const stateid_t *sid) | ||
229 | { | 168 | { |
230 | *hdr->nops_p = htonl(hdr->nops); | 169 | __be32 *p; |
170 | |||
171 | p = xdr_reserve_space(xdr, NFS4_STATEID_SIZE); | ||
172 | *p++ = cpu_to_be32(sid->si_generation); | ||
173 | xdr_encode_opaque_fixed(p, &sid->si_opaque, NFS4_STATEID_OTHER_SIZE); | ||
231 | } | 174 | } |
232 | 175 | ||
233 | static void | 176 | /* |
234 | encode_cb_recall(struct xdr_stream *xdr, struct nfs4_delegation *dp, | 177 | * sessionid4 |
235 | struct nfs4_cb_compound_hdr *hdr) | 178 | * |
179 | * typedef opaque sessionid4[NFS4_SESSIONID_SIZE]; | ||
180 | */ | ||
181 | static void encode_sessionid4(struct xdr_stream *xdr, | ||
182 | const struct nfsd4_session *session) | ||
236 | { | 183 | { |
237 | __be32 *p; | 184 | __be32 *p; |
238 | int len = dp->dl_fh.fh_size; | 185 | |
239 | 186 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN); | |
240 | RESERVE_SPACE(4); | 187 | xdr_encode_opaque_fixed(p, session->se_sessionid.data, |
241 | WRITE32(OP_CB_RECALL); | 188 | NFS4_MAX_SESSIONID_LEN); |
242 | encode_stateid(xdr, &dp->dl_stateid); | ||
243 | RESERVE_SPACE(8 + (XDR_QUADLEN(len) << 2)); | ||
244 | WRITE32(0); /* truncate optimization not implemented */ | ||
245 | WRITE32(len); | ||
246 | WRITEMEM(&dp->dl_fh.fh_base, len); | ||
247 | hdr->nops++; | ||
248 | } | 189 | } |
249 | 190 | ||
250 | static void | 191 | /* |
251 | encode_cb_sequence(struct xdr_stream *xdr, struct nfsd4_cb_sequence *args, | 192 | * nfsstat4 |
252 | struct nfs4_cb_compound_hdr *hdr) | 193 | */ |
253 | { | 194 | static const struct { |
254 | __be32 *p; | 195 | int stat; |
196 | int errno; | ||
197 | } nfs_cb_errtbl[] = { | ||
198 | { NFS4_OK, 0 }, | ||
199 | { NFS4ERR_PERM, -EPERM }, | ||
200 | { NFS4ERR_NOENT, -ENOENT }, | ||
201 | { NFS4ERR_IO, -EIO }, | ||
202 | { NFS4ERR_NXIO, -ENXIO }, | ||
203 | { NFS4ERR_ACCESS, -EACCES }, | ||
204 | { NFS4ERR_EXIST, -EEXIST }, | ||
205 | { NFS4ERR_XDEV, -EXDEV }, | ||
206 | { NFS4ERR_NOTDIR, -ENOTDIR }, | ||
207 | { NFS4ERR_ISDIR, -EISDIR }, | ||
208 | { NFS4ERR_INVAL, -EINVAL }, | ||
209 | { NFS4ERR_FBIG, -EFBIG }, | ||
210 | { NFS4ERR_NOSPC, -ENOSPC }, | ||
211 | { NFS4ERR_ROFS, -EROFS }, | ||
212 | { NFS4ERR_MLINK, -EMLINK }, | ||
213 | { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, | ||
214 | { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, | ||
215 | { NFS4ERR_DQUOT, -EDQUOT }, | ||
216 | { NFS4ERR_STALE, -ESTALE }, | ||
217 | { NFS4ERR_BADHANDLE, -EBADHANDLE }, | ||
218 | { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, | ||
219 | { NFS4ERR_NOTSUPP, -ENOTSUPP }, | ||
220 | { NFS4ERR_TOOSMALL, -ETOOSMALL }, | ||
221 | { NFS4ERR_SERVERFAULT, -ESERVERFAULT }, | ||
222 | { NFS4ERR_BADTYPE, -EBADTYPE }, | ||
223 | { NFS4ERR_LOCKED, -EAGAIN }, | ||
224 | { NFS4ERR_RESOURCE, -EREMOTEIO }, | ||
225 | { NFS4ERR_SYMLINK, -ELOOP }, | ||
226 | { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, | ||
227 | { NFS4ERR_DEADLOCK, -EDEADLK }, | ||
228 | { -1, -EIO } | ||
229 | }; | ||
255 | 230 | ||
256 | if (hdr->minorversion == 0) | 231 | /* |
257 | return; | 232 | * If we cannot translate the error, the recovery routines should |
233 | * handle it. | ||
234 | * | ||
235 | * Note: remaining NFSv4 error codes have values > 10000, so should | ||
236 | * not conflict with native Linux error codes. | ||
237 | */ | ||
238 | static int nfs_cb_stat_to_errno(int status) | ||
239 | { | ||
240 | int i; | ||
258 | 241 | ||
259 | RESERVE_SPACE(1 + NFS4_MAX_SESSIONID_LEN + 20); | 242 | for (i = 0; nfs_cb_errtbl[i].stat != -1; i++) { |
243 | if (nfs_cb_errtbl[i].stat == status) | ||
244 | return nfs_cb_errtbl[i].errno; | ||
245 | } | ||
260 | 246 | ||
261 | WRITE32(OP_CB_SEQUENCE); | 247 | dprintk("NFSD: Unrecognized NFS CB status value: %u\n", status); |
262 | WRITEMEM(args->cbs_clp->cl_sessionid.data, NFS4_MAX_SESSIONID_LEN); | 248 | return -status; |
263 | WRITE32(args->cbs_clp->cl_cb_seq_nr); | ||
264 | WRITE32(0); /* slotid, always 0 */ | ||
265 | WRITE32(0); /* highest slotid always 0 */ | ||
266 | WRITE32(0); /* cachethis always 0 */ | ||
267 | WRITE32(0); /* FIXME: support referring_call_lists */ | ||
268 | hdr->nops++; | ||
269 | } | 249 | } |
270 | 250 | ||
271 | static int | 251 | static int decode_cb_op_status(struct xdr_stream *xdr, enum nfs_opnum4 expected, |
272 | nfs4_xdr_enc_cb_null(struct rpc_rqst *req, __be32 *p) | 252 | enum nfsstat4 *status) |
273 | { | 253 | { |
274 | struct xdr_stream xdrs, *xdr = &xdrs; | 254 | __be32 *p; |
255 | u32 op; | ||
275 | 256 | ||
276 | xdr_init_encode(&xdrs, &req->rq_snd_buf, p); | 257 | p = xdr_inline_decode(xdr, 4 + 4); |
277 | RESERVE_SPACE(0); | 258 | if (unlikely(p == NULL)) |
259 | goto out_overflow; | ||
260 | op = be32_to_cpup(p++); | ||
261 | if (unlikely(op != expected)) | ||
262 | goto out_unexpected; | ||
263 | *status = be32_to_cpup(p); | ||
278 | return 0; | 264 | return 0; |
265 | out_overflow: | ||
266 | print_overflow_msg(__func__, xdr); | ||
267 | return -EIO; | ||
268 | out_unexpected: | ||
269 | dprintk("NFSD: Callback server returned operation %d but " | ||
270 | "we issued a request for %d\n", op, expected); | ||
271 | return -EIO; | ||
279 | } | 272 | } |
280 | 273 | ||
281 | static int | 274 | /* |
282 | nfs4_xdr_enc_cb_recall(struct rpc_rqst *req, __be32 *p, | 275 | * CB_COMPOUND4args |
283 | struct nfs4_rpc_args *rpc_args) | 276 | * |
277 | * struct CB_COMPOUND4args { | ||
278 | * utf8str_cs tag; | ||
279 | * uint32_t minorversion; | ||
280 | * uint32_t callback_ident; | ||
281 | * nfs_cb_argop4 argarray<>; | ||
282 | * }; | ||
283 | */ | ||
284 | static void encode_cb_compound4args(struct xdr_stream *xdr, | ||
285 | struct nfs4_cb_compound_hdr *hdr) | ||
284 | { | 286 | { |
285 | struct xdr_stream xdr; | 287 | __be32 * p; |
286 | struct nfs4_delegation *args = rpc_args->args_op; | ||
287 | struct nfs4_cb_compound_hdr hdr = { | ||
288 | .ident = args->dl_ident, | ||
289 | .minorversion = rpc_args->args_seq.cbs_minorversion, | ||
290 | }; | ||
291 | 288 | ||
292 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); | 289 | p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4); |
293 | encode_cb_compound_hdr(&xdr, &hdr); | 290 | p = xdr_encode_empty_array(p); /* empty tag */ |
294 | encode_cb_sequence(&xdr, &rpc_args->args_seq, &hdr); | 291 | *p++ = cpu_to_be32(hdr->minorversion); |
295 | encode_cb_recall(&xdr, args, &hdr); | 292 | *p++ = cpu_to_be32(hdr->ident); |
296 | encode_cb_nops(&hdr); | 293 | |
294 | hdr->nops_p = p; | ||
295 | *p = cpu_to_be32(hdr->nops); /* argarray element count */ | ||
296 | } | ||
297 | |||
298 | /* | ||
299 | * Update argarray element count | ||
300 | */ | ||
301 | static void encode_cb_nops(struct nfs4_cb_compound_hdr *hdr) | ||
302 | { | ||
303 | BUG_ON(hdr->nops > NFS4_MAX_BACK_CHANNEL_OPS); | ||
304 | *hdr->nops_p = cpu_to_be32(hdr->nops); | ||
305 | } | ||
306 | |||
307 | /* | ||
308 | * CB_COMPOUND4res | ||
309 | * | ||
310 | * struct CB_COMPOUND4res { | ||
311 | * nfsstat4 status; | ||
312 | * utf8str_cs tag; | ||
313 | * nfs_cb_resop4 resarray<>; | ||
314 | * }; | ||
315 | */ | ||
316 | static int decode_cb_compound4res(struct xdr_stream *xdr, | ||
317 | struct nfs4_cb_compound_hdr *hdr) | ||
318 | { | ||
319 | u32 length; | ||
320 | __be32 *p; | ||
321 | |||
322 | p = xdr_inline_decode(xdr, 4 + 4); | ||
323 | if (unlikely(p == NULL)) | ||
324 | goto out_overflow; | ||
325 | hdr->status = be32_to_cpup(p++); | ||
326 | /* Ignore the tag */ | ||
327 | length = be32_to_cpup(p++); | ||
328 | p = xdr_inline_decode(xdr, length + 4); | ||
329 | if (unlikely(p == NULL)) | ||
330 | goto out_overflow; | ||
331 | hdr->nops = be32_to_cpup(p); | ||
297 | return 0; | 332 | return 0; |
333 | out_overflow: | ||
334 | print_overflow_msg(__func__, xdr); | ||
335 | return -EIO; | ||
298 | } | 336 | } |
299 | 337 | ||
338 | /* | ||
339 | * CB_RECALL4args | ||
340 | * | ||
341 | * struct CB_RECALL4args { | ||
342 | * stateid4 stateid; | ||
343 | * bool truncate; | ||
344 | * nfs_fh4 fh; | ||
345 | * }; | ||
346 | */ | ||
347 | static void encode_cb_recall4args(struct xdr_stream *xdr, | ||
348 | const struct nfs4_delegation *dp, | ||
349 | struct nfs4_cb_compound_hdr *hdr) | ||
350 | { | ||
351 | __be32 *p; | ||
352 | |||
353 | encode_nfs_cb_opnum4(xdr, OP_CB_RECALL); | ||
354 | encode_stateid4(xdr, &dp->dl_stateid); | ||
300 | 355 | ||
301 | static int | 356 | p = xdr_reserve_space(xdr, 4); |
302 | decode_cb_compound_hdr(struct xdr_stream *xdr, struct nfs4_cb_compound_hdr *hdr){ | 357 | *p++ = xdr_zero; /* truncate */ |
303 | __be32 *p; | ||
304 | u32 taglen; | ||
305 | 358 | ||
306 | READ_BUF(8); | 359 | encode_nfs_fh4(xdr, &dp->dl_fh); |
307 | READ32(hdr->status); | 360 | |
308 | /* We've got no use for the tag; ignore it: */ | 361 | hdr->nops++; |
309 | READ32(taglen); | ||
310 | READ_BUF(taglen + 4); | ||
311 | p += XDR_QUADLEN(taglen); | ||
312 | READ32(hdr->nops); | ||
313 | return 0; | ||
314 | } | 362 | } |
315 | 363 | ||
316 | static int | 364 | /* |
317 | decode_cb_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected) | 365 | * CB_SEQUENCE4args |
366 | * | ||
367 | * struct CB_SEQUENCE4args { | ||
368 | * sessionid4 csa_sessionid; | ||
369 | * sequenceid4 csa_sequenceid; | ||
370 | * slotid4 csa_slotid; | ||
371 | * slotid4 csa_highest_slotid; | ||
372 | * bool csa_cachethis; | ||
373 | * referring_call_list4 csa_referring_call_lists<>; | ||
374 | * }; | ||
375 | */ | ||
376 | static void encode_cb_sequence4args(struct xdr_stream *xdr, | ||
377 | const struct nfsd4_callback *cb, | ||
378 | struct nfs4_cb_compound_hdr *hdr) | ||
318 | { | 379 | { |
380 | struct nfsd4_session *session = cb->cb_clp->cl_cb_session; | ||
319 | __be32 *p; | 381 | __be32 *p; |
320 | u32 op; | 382 | |
321 | int32_t nfserr; | 383 | if (hdr->minorversion == 0) |
322 | 384 | return; | |
323 | READ_BUF(8); | 385 | |
324 | READ32(op); | 386 | encode_nfs_cb_opnum4(xdr, OP_CB_SEQUENCE); |
325 | if (op != expected) { | 387 | encode_sessionid4(xdr, session); |
326 | dprintk("NFSD: decode_cb_op_hdr: Callback server returned " | 388 | |
327 | " operation %d but we issued a request for %d\n", | 389 | p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4 + 4); |
328 | op, expected); | 390 | *p++ = cpu_to_be32(session->se_cb_seq_nr); /* csa_sequenceid */ |
329 | return -EIO; | 391 | *p++ = xdr_zero; /* csa_slotid */ |
330 | } | 392 | *p++ = xdr_zero; /* csa_highest_slotid */ |
331 | READ32(nfserr); | 393 | *p++ = xdr_zero; /* csa_cachethis */ |
332 | if (nfserr != NFS_OK) | 394 | xdr_encode_empty_array(p); /* csa_referring_call_lists */ |
333 | return -nfs_cb_stat_to_errno(nfserr); | 395 | |
334 | return 0; | 396 | hdr->nops++; |
335 | } | 397 | } |
336 | 398 | ||
337 | /* | 399 | /* |
400 | * CB_SEQUENCE4resok | ||
401 | * | ||
402 | * struct CB_SEQUENCE4resok { | ||
403 | * sessionid4 csr_sessionid; | ||
404 | * sequenceid4 csr_sequenceid; | ||
405 | * slotid4 csr_slotid; | ||
406 | * slotid4 csr_highest_slotid; | ||
407 | * slotid4 csr_target_highest_slotid; | ||
408 | * }; | ||
409 | * | ||
410 | * union CB_SEQUENCE4res switch (nfsstat4 csr_status) { | ||
411 | * case NFS4_OK: | ||
412 | * CB_SEQUENCE4resok csr_resok4; | ||
413 | * default: | ||
414 | * void; | ||
415 | * }; | ||
416 | * | ||
338 | * Our current back channel implmentation supports a single backchannel | 417 | * Our current back channel implmentation supports a single backchannel |
339 | * with a single slot. | 418 | * with a single slot. |
340 | */ | 419 | */ |
341 | static int | 420 | static int decode_cb_sequence4resok(struct xdr_stream *xdr, |
342 | decode_cb_sequence(struct xdr_stream *xdr, struct nfsd4_cb_sequence *res, | 421 | struct nfsd4_callback *cb) |
343 | struct rpc_rqst *rqstp) | ||
344 | { | 422 | { |
423 | struct nfsd4_session *session = cb->cb_clp->cl_cb_session; | ||
345 | struct nfs4_sessionid id; | 424 | struct nfs4_sessionid id; |
346 | int status; | 425 | int status; |
347 | u32 dummy; | ||
348 | __be32 *p; | 426 | __be32 *p; |
427 | u32 dummy; | ||
349 | 428 | ||
350 | if (res->cbs_minorversion == 0) | 429 | status = -ESERVERFAULT; |
351 | return 0; | ||
352 | |||
353 | status = decode_cb_op_hdr(xdr, OP_CB_SEQUENCE); | ||
354 | if (status) | ||
355 | return status; | ||
356 | 430 | ||
357 | /* | 431 | /* |
358 | * If the server returns different values for sessionID, slotID or | 432 | * If the server returns different values for sessionID, slotID or |
359 | * sequence number, the server is looney tunes. | 433 | * sequence number, the server is looney tunes. |
360 | */ | 434 | */ |
361 | status = -ESERVERFAULT; | 435 | p = xdr_inline_decode(xdr, NFS4_MAX_SESSIONID_LEN + 4 + 4 + 4 + 4); |
362 | 436 | if (unlikely(p == NULL)) | |
363 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 16); | 437 | goto out_overflow; |
364 | memcpy(id.data, p, NFS4_MAX_SESSIONID_LEN); | 438 | memcpy(id.data, p, NFS4_MAX_SESSIONID_LEN); |
365 | p += XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN); | 439 | if (memcmp(id.data, session->se_sessionid.data, |
366 | if (memcmp(id.data, res->cbs_clp->cl_sessionid.data, | 440 | NFS4_MAX_SESSIONID_LEN) != 0) { |
367 | NFS4_MAX_SESSIONID_LEN)) { | 441 | dprintk("NFS: %s Invalid session id\n", __func__); |
368 | dprintk("%s Invalid session id\n", __func__); | ||
369 | goto out; | 442 | goto out; |
370 | } | 443 | } |
371 | READ32(dummy); | 444 | p += XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN); |
372 | if (dummy != res->cbs_clp->cl_cb_seq_nr) { | 445 | |
373 | dprintk("%s Invalid sequence number\n", __func__); | 446 | dummy = be32_to_cpup(p++); |
447 | if (dummy != session->se_cb_seq_nr) { | ||
448 | dprintk("NFS: %s Invalid sequence number\n", __func__); | ||
374 | goto out; | 449 | goto out; |
375 | } | 450 | } |
376 | READ32(dummy); /* slotid must be 0 */ | 451 | |
452 | dummy = be32_to_cpup(p++); | ||
377 | if (dummy != 0) { | 453 | if (dummy != 0) { |
378 | dprintk("%s Invalid slotid\n", __func__); | 454 | dprintk("NFS: %s Invalid slotid\n", __func__); |
379 | goto out; | 455 | goto out; |
380 | } | 456 | } |
381 | /* FIXME: process highest slotid and target highest slotid */ | 457 | |
458 | /* | ||
459 | * FIXME: process highest slotid and target highest slotid | ||
460 | */ | ||
382 | status = 0; | 461 | status = 0; |
383 | out: | 462 | out: |
384 | return status; | 463 | return status; |
464 | out_overflow: | ||
465 | print_overflow_msg(__func__, xdr); | ||
466 | return -EIO; | ||
467 | } | ||
468 | |||
469 | static int decode_cb_sequence4res(struct xdr_stream *xdr, | ||
470 | struct nfsd4_callback *cb) | ||
471 | { | ||
472 | enum nfsstat4 nfserr; | ||
473 | int status; | ||
474 | |||
475 | if (cb->cb_minorversion == 0) | ||
476 | return 0; | ||
477 | |||
478 | status = decode_cb_op_status(xdr, OP_CB_SEQUENCE, &nfserr); | ||
479 | if (unlikely(status)) | ||
480 | goto out; | ||
481 | if (unlikely(nfserr != NFS4_OK)) | ||
482 | goto out_default; | ||
483 | status = decode_cb_sequence4resok(xdr, cb); | ||
484 | out: | ||
485 | return status; | ||
486 | out_default: | ||
487 | return nfs_cb_stat_to_errno(nfserr); | ||
488 | } | ||
489 | |||
490 | /* | ||
491 | * NFSv4.0 and NFSv4.1 XDR encode functions | ||
492 | * | ||
493 | * NFSv4.0 callback argument types are defined in section 15 of RFC | ||
494 | * 3530: "Network File System (NFS) version 4 Protocol" and section 20 | ||
495 | * of RFC 5661: "Network File System (NFS) Version 4 Minor Version 1 | ||
496 | * Protocol". | ||
497 | */ | ||
498 | |||
499 | /* | ||
500 | * NB: Without this zero space reservation, callbacks over krb5p fail | ||
501 | */ | ||
502 | static void nfs4_xdr_enc_cb_null(struct rpc_rqst *req, struct xdr_stream *xdr, | ||
503 | void *__unused) | ||
504 | { | ||
505 | xdr_reserve_space(xdr, 0); | ||
506 | } | ||
507 | |||
508 | /* | ||
509 | * 20.2. Operation 4: CB_RECALL - Recall a Delegation | ||
510 | */ | ||
511 | static void nfs4_xdr_enc_cb_recall(struct rpc_rqst *req, struct xdr_stream *xdr, | ||
512 | const struct nfsd4_callback *cb) | ||
513 | { | ||
514 | const struct nfs4_delegation *args = cb->cb_op; | ||
515 | struct nfs4_cb_compound_hdr hdr = { | ||
516 | .ident = cb->cb_clp->cl_cb_ident, | ||
517 | .minorversion = cb->cb_minorversion, | ||
518 | }; | ||
519 | |||
520 | encode_cb_compound4args(xdr, &hdr); | ||
521 | encode_cb_sequence4args(xdr, cb, &hdr); | ||
522 | encode_cb_recall4args(xdr, args, &hdr); | ||
523 | encode_cb_nops(&hdr); | ||
385 | } | 524 | } |
386 | 525 | ||
387 | 526 | ||
388 | static int | 527 | /* |
389 | nfs4_xdr_dec_cb_null(struct rpc_rqst *req, __be32 *p) | 528 | * NFSv4.0 and NFSv4.1 XDR decode functions |
529 | * | ||
530 | * NFSv4.0 callback result types are defined in section 15 of RFC | ||
531 | * 3530: "Network File System (NFS) version 4 Protocol" and section 20 | ||
532 | * of RFC 5661: "Network File System (NFS) Version 4 Minor Version 1 | ||
533 | * Protocol". | ||
534 | */ | ||
535 | |||
536 | static int nfs4_xdr_dec_cb_null(struct rpc_rqst *req, struct xdr_stream *xdr, | ||
537 | void *__unused) | ||
390 | { | 538 | { |
391 | return 0; | 539 | return 0; |
392 | } | 540 | } |
393 | 541 | ||
394 | static int | 542 | /* |
395 | nfs4_xdr_dec_cb_recall(struct rpc_rqst *rqstp, __be32 *p, | 543 | * 20.2. Operation 4: CB_RECALL - Recall a Delegation |
396 | struct nfsd4_cb_sequence *seq) | 544 | */ |
545 | static int nfs4_xdr_dec_cb_recall(struct rpc_rqst *rqstp, | ||
546 | struct xdr_stream *xdr, | ||
547 | struct nfsd4_callback *cb) | ||
397 | { | 548 | { |
398 | struct xdr_stream xdr; | ||
399 | struct nfs4_cb_compound_hdr hdr; | 549 | struct nfs4_cb_compound_hdr hdr; |
550 | enum nfsstat4 nfserr; | ||
400 | int status; | 551 | int status; |
401 | 552 | ||
402 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); | 553 | status = decode_cb_compound4res(xdr, &hdr); |
403 | status = decode_cb_compound_hdr(&xdr, &hdr); | 554 | if (unlikely(status)) |
404 | if (status) | ||
405 | goto out; | 555 | goto out; |
406 | if (seq) { | 556 | |
407 | status = decode_cb_sequence(&xdr, seq, rqstp); | 557 | if (cb != NULL) { |
408 | if (status) | 558 | status = decode_cb_sequence4res(xdr, cb); |
559 | if (unlikely(status)) | ||
409 | goto out; | 560 | goto out; |
410 | } | 561 | } |
411 | status = decode_cb_op_hdr(&xdr, OP_CB_RECALL); | 562 | |
563 | status = decode_cb_op_status(xdr, OP_CB_RECALL, &nfserr); | ||
564 | if (unlikely(status)) | ||
565 | goto out; | ||
566 | if (unlikely(nfserr != NFS4_OK)) | ||
567 | status = nfs_cb_stat_to_errno(nfserr); | ||
412 | out: | 568 | out: |
413 | return status; | 569 | return status; |
414 | } | 570 | } |
@@ -416,23 +572,23 @@ out: | |||
416 | /* | 572 | /* |
417 | * RPC procedure tables | 573 | * RPC procedure tables |
418 | */ | 574 | */ |
419 | #define PROC(proc, call, argtype, restype) \ | 575 | #define PROC(proc, call, argtype, restype) \ |
420 | [NFSPROC4_CLNT_##proc] = { \ | 576 | [NFSPROC4_CLNT_##proc] = { \ |
421 | .p_proc = NFSPROC4_CB_##call, \ | 577 | .p_proc = NFSPROC4_CB_##call, \ |
422 | .p_encode = (kxdrproc_t) nfs4_xdr_##argtype, \ | 578 | .p_encode = (kxdreproc_t)nfs4_xdr_enc_##argtype, \ |
423 | .p_decode = (kxdrproc_t) nfs4_xdr_##restype, \ | 579 | .p_decode = (kxdrdproc_t)nfs4_xdr_dec_##restype, \ |
424 | .p_arglen = NFS4_##argtype##_sz, \ | 580 | .p_arglen = NFS4_enc_##argtype##_sz, \ |
425 | .p_replen = NFS4_##restype##_sz, \ | 581 | .p_replen = NFS4_dec_##restype##_sz, \ |
426 | .p_statidx = NFSPROC4_CB_##call, \ | 582 | .p_statidx = NFSPROC4_CB_##call, \ |
427 | .p_name = #proc, \ | 583 | .p_name = #proc, \ |
428 | } | 584 | } |
429 | 585 | ||
430 | static struct rpc_procinfo nfs4_cb_procedures[] = { | 586 | static struct rpc_procinfo nfs4_cb_procedures[] = { |
431 | PROC(CB_NULL, NULL, enc_cb_null, dec_cb_null), | 587 | PROC(CB_NULL, NULL, cb_null, cb_null), |
432 | PROC(CB_RECALL, COMPOUND, enc_cb_recall, dec_cb_recall), | 588 | PROC(CB_RECALL, COMPOUND, cb_recall, cb_recall), |
433 | }; | 589 | }; |
434 | 590 | ||
435 | static struct rpc_version nfs_cb_version4 = { | 591 | static struct rpc_version nfs_cb_version4 = { |
436 | /* | 592 | /* |
437 | * Note on the callback rpc program version number: despite language in rfc | 593 | * Note on the callback rpc program version number: despite language in rfc |
438 | * 5661 section 18.36.3 requiring servers to use 4 in this field, the | 594 | * 5661 section 18.36.3 requiring servers to use 4 in this field, the |
@@ -440,29 +596,29 @@ static struct rpc_version nfs_cb_version4 = { | |||
440 | * in practice that appears to be what implementations use. The section | 596 | * in practice that appears to be what implementations use. The section |
441 | * 18.36.3 language is expected to be fixed in an erratum. | 597 | * 18.36.3 language is expected to be fixed in an erratum. |
442 | */ | 598 | */ |
443 | .number = 1, | 599 | .number = 1, |
444 | .nrprocs = ARRAY_SIZE(nfs4_cb_procedures), | 600 | .nrprocs = ARRAY_SIZE(nfs4_cb_procedures), |
445 | .procs = nfs4_cb_procedures | 601 | .procs = nfs4_cb_procedures |
446 | }; | 602 | }; |
447 | 603 | ||
448 | static struct rpc_version * nfs_cb_version[] = { | 604 | static struct rpc_version *nfs_cb_version[] = { |
449 | &nfs_cb_version4, | 605 | &nfs_cb_version4, |
450 | }; | 606 | }; |
451 | 607 | ||
452 | static struct rpc_program cb_program; | 608 | static struct rpc_program cb_program; |
453 | 609 | ||
454 | static struct rpc_stat cb_stats = { | 610 | static struct rpc_stat cb_stats = { |
455 | .program = &cb_program | 611 | .program = &cb_program |
456 | }; | 612 | }; |
457 | 613 | ||
458 | #define NFS4_CALLBACK 0x40000000 | 614 | #define NFS4_CALLBACK 0x40000000 |
459 | static struct rpc_program cb_program = { | 615 | static struct rpc_program cb_program = { |
460 | .name = "nfs4_cb", | 616 | .name = "nfs4_cb", |
461 | .number = NFS4_CALLBACK, | 617 | .number = NFS4_CALLBACK, |
462 | .nrvers = ARRAY_SIZE(nfs_cb_version), | 618 | .nrvers = ARRAY_SIZE(nfs_cb_version), |
463 | .version = nfs_cb_version, | 619 | .version = nfs_cb_version, |
464 | .stats = &cb_stats, | 620 | .stats = &cb_stats, |
465 | .pipe_dir_name = "/nfsd4_cb", | 621 | .pipe_dir_name = "/nfsd4_cb", |
466 | }; | 622 | }; |
467 | 623 | ||
468 | static int max_cb_time(void) | 624 | static int max_cb_time(void) |
@@ -470,33 +626,40 @@ static int max_cb_time(void) | |||
470 | return max(nfsd4_lease/10, (time_t)1) * HZ; | 626 | return max(nfsd4_lease/10, (time_t)1) * HZ; |
471 | } | 627 | } |
472 | 628 | ||
473 | /* Reference counting, callback cleanup, etc., all look racy as heck. | ||
474 | * And why is cl_cb_set an atomic? */ | ||
475 | 629 | ||
476 | int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *cb) | 630 | static int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *conn, struct nfsd4_session *ses) |
477 | { | 631 | { |
478 | struct rpc_timeout timeparms = { | 632 | struct rpc_timeout timeparms = { |
479 | .to_initval = max_cb_time(), | 633 | .to_initval = max_cb_time(), |
480 | .to_retries = 0, | 634 | .to_retries = 0, |
481 | }; | 635 | }; |
482 | struct rpc_create_args args = { | 636 | struct rpc_create_args args = { |
483 | .protocol = XPRT_TRANSPORT_TCP, | 637 | .net = &init_net, |
484 | .address = (struct sockaddr *) &cb->cb_addr, | 638 | .address = (struct sockaddr *) &conn->cb_addr, |
485 | .addrsize = cb->cb_addrlen, | 639 | .addrsize = conn->cb_addrlen, |
640 | .saddress = (struct sockaddr *) &conn->cb_saddr, | ||
486 | .timeout = &timeparms, | 641 | .timeout = &timeparms, |
487 | .program = &cb_program, | 642 | .program = &cb_program, |
488 | .prognumber = cb->cb_prog, | ||
489 | .version = 0, | 643 | .version = 0, |
490 | .authflavor = clp->cl_flavor, | 644 | .authflavor = clp->cl_flavor, |
491 | .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET), | 645 | .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET), |
492 | .client_name = clp->cl_principal, | ||
493 | }; | 646 | }; |
494 | struct rpc_clnt *client; | 647 | struct rpc_clnt *client; |
495 | 648 | ||
496 | if (!clp->cl_principal && (clp->cl_flavor >= RPC_AUTH_GSS_KRB5)) | 649 | if (clp->cl_minorversion == 0) { |
497 | return -EINVAL; | 650 | if (!clp->cl_principal && (clp->cl_flavor >= RPC_AUTH_GSS_KRB5)) |
498 | if (cb->cb_minorversion) { | 651 | return -EINVAL; |
499 | args.bc_xprt = cb->cb_xprt; | 652 | args.client_name = clp->cl_principal; |
653 | args.prognumber = conn->cb_prog, | ||
654 | args.protocol = XPRT_TRANSPORT_TCP; | ||
655 | clp->cl_cb_ident = conn->cb_ident; | ||
656 | } else { | ||
657 | if (!conn->cb_xprt) | ||
658 | return -EINVAL; | ||
659 | clp->cl_cb_conn.cb_xprt = conn->cb_xprt; | ||
660 | clp->cl_cb_session = ses; | ||
661 | args.bc_xprt = conn->cb_xprt; | ||
662 | args.prognumber = clp->cl_cb_session->se_cb_prog; | ||
500 | args.protocol = XPRT_TRANSPORT_BC_TCP; | 663 | args.protocol = XPRT_TRANSPORT_BC_TCP; |
501 | } | 664 | } |
502 | /* Create RPC client */ | 665 | /* Create RPC client */ |
@@ -506,7 +669,7 @@ int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *cb) | |||
506 | PTR_ERR(client)); | 669 | PTR_ERR(client)); |
507 | return PTR_ERR(client); | 670 | return PTR_ERR(client); |
508 | } | 671 | } |
509 | nfsd4_set_callback_client(clp, client); | 672 | clp->cl_cb_client = client; |
510 | return 0; | 673 | return 0; |
511 | 674 | ||
512 | } | 675 | } |
@@ -517,17 +680,25 @@ static void warn_no_callback_path(struct nfs4_client *clp, int reason) | |||
517 | (int)clp->cl_name.len, clp->cl_name.data, reason); | 680 | (int)clp->cl_name.len, clp->cl_name.data, reason); |
518 | } | 681 | } |
519 | 682 | ||
683 | static void nfsd4_mark_cb_down(struct nfs4_client *clp, int reason) | ||
684 | { | ||
685 | clp->cl_cb_state = NFSD4_CB_DOWN; | ||
686 | warn_no_callback_path(clp, reason); | ||
687 | } | ||
688 | |||
520 | static void nfsd4_cb_probe_done(struct rpc_task *task, void *calldata) | 689 | static void nfsd4_cb_probe_done(struct rpc_task *task, void *calldata) |
521 | { | 690 | { |
522 | struct nfs4_client *clp = calldata; | 691 | struct nfs4_client *clp = container_of(calldata, struct nfs4_client, cl_cb_null); |
523 | 692 | ||
524 | if (task->tk_status) | 693 | if (task->tk_status) |
525 | warn_no_callback_path(clp, task->tk_status); | 694 | nfsd4_mark_cb_down(clp, task->tk_status); |
526 | else | 695 | else |
527 | atomic_set(&clp->cl_cb_set, 1); | 696 | clp->cl_cb_state = NFSD4_CB_UP; |
528 | } | 697 | } |
529 | 698 | ||
530 | static const struct rpc_call_ops nfsd4_cb_probe_ops = { | 699 | static const struct rpc_call_ops nfsd4_cb_probe_ops = { |
700 | /* XXX: release method to ensure we set the cb channel down if | ||
701 | * necessary on early failure? */ | ||
531 | .rpc_call_done = nfsd4_cb_probe_done, | 702 | .rpc_call_done = nfsd4_cb_probe_done, |
532 | }; | 703 | }; |
533 | 704 | ||
@@ -543,38 +714,54 @@ int set_callback_cred(void) | |||
543 | return 0; | 714 | return 0; |
544 | } | 715 | } |
545 | 716 | ||
717 | static struct workqueue_struct *callback_wq; | ||
546 | 718 | ||
547 | void do_probe_callback(struct nfs4_client *clp) | 719 | static void run_nfsd4_cb(struct nfsd4_callback *cb) |
548 | { | 720 | { |
549 | struct rpc_message msg = { | 721 | queue_work(callback_wq, &cb->cb_work); |
550 | .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL], | 722 | } |
551 | .rpc_argp = clp, | 723 | |
552 | .rpc_cred = callback_cred | 724 | static void do_probe_callback(struct nfs4_client *clp) |
553 | }; | 725 | { |
554 | int status; | 726 | struct nfsd4_callback *cb = &clp->cl_cb_null; |
727 | |||
728 | cb->cb_op = NULL; | ||
729 | cb->cb_clp = clp; | ||
730 | |||
731 | cb->cb_msg.rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL]; | ||
732 | cb->cb_msg.rpc_argp = NULL; | ||
733 | cb->cb_msg.rpc_resp = NULL; | ||
734 | cb->cb_msg.rpc_cred = callback_cred; | ||
555 | 735 | ||
556 | status = rpc_call_async(clp->cl_cb_client, &msg, | 736 | cb->cb_ops = &nfsd4_cb_probe_ops; |
557 | RPC_TASK_SOFT | RPC_TASK_SOFTCONN, | 737 | |
558 | &nfsd4_cb_probe_ops, (void *)clp); | 738 | run_nfsd4_cb(cb); |
559 | if (status) | ||
560 | warn_no_callback_path(clp, status); | ||
561 | } | 739 | } |
562 | 740 | ||
563 | /* | 741 | /* |
564 | * Set up the callback client and put a NFSPROC4_CB_NULL on the wire... | 742 | * Poke the callback thread to process any updates to the callback |
743 | * parameters, and send a null probe. | ||
565 | */ | 744 | */ |
566 | void nfsd4_probe_callback(struct nfs4_client *clp, struct nfs4_cb_conn *cb) | 745 | void nfsd4_probe_callback(struct nfs4_client *clp) |
567 | { | 746 | { |
568 | int status; | 747 | /* XXX: atomicity? Also, should we be using cl_cb_flags? */ |
748 | clp->cl_cb_state = NFSD4_CB_UNKNOWN; | ||
749 | set_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_cb_flags); | ||
750 | do_probe_callback(clp); | ||
751 | } | ||
569 | 752 | ||
570 | BUG_ON(atomic_read(&clp->cl_cb_set)); | 753 | void nfsd4_probe_callback_sync(struct nfs4_client *clp) |
754 | { | ||
755 | nfsd4_probe_callback(clp); | ||
756 | flush_workqueue(callback_wq); | ||
757 | } | ||
571 | 758 | ||
572 | status = setup_callback_client(clp, cb); | 759 | void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *conn) |
573 | if (status) { | 760 | { |
574 | warn_no_callback_path(clp, status); | 761 | clp->cl_cb_state = NFSD4_CB_UNKNOWN; |
575 | return; | 762 | spin_lock(&clp->cl_lock); |
576 | } | 763 | memcpy(&clp->cl_cb_conn, conn, sizeof(struct nfs4_cb_conn)); |
577 | do_probe_callback(clp); | 764 | spin_unlock(&clp->cl_lock); |
578 | } | 765 | } |
579 | 766 | ||
580 | /* | 767 | /* |
@@ -582,33 +769,14 @@ void nfsd4_probe_callback(struct nfs4_client *clp, struct nfs4_cb_conn *cb) | |||
582 | * If the slot is available, then mark it busy. Otherwise, set the | 769 | * If the slot is available, then mark it busy. Otherwise, set the |
583 | * thread for sleeping on the callback RPC wait queue. | 770 | * thread for sleeping on the callback RPC wait queue. |
584 | */ | 771 | */ |
585 | static int nfsd41_cb_setup_sequence(struct nfs4_client *clp, | 772 | static bool nfsd41_cb_get_slot(struct nfs4_client *clp, struct rpc_task *task) |
586 | struct rpc_task *task) | ||
587 | { | 773 | { |
588 | struct nfs4_rpc_args *args = task->tk_msg.rpc_argp; | ||
589 | u32 *ptr = (u32 *)clp->cl_sessionid.data; | ||
590 | int status = 0; | ||
591 | |||
592 | dprintk("%s: %u:%u:%u:%u\n", __func__, | ||
593 | ptr[0], ptr[1], ptr[2], ptr[3]); | ||
594 | |||
595 | if (test_and_set_bit(0, &clp->cl_cb_slot_busy) != 0) { | 774 | if (test_and_set_bit(0, &clp->cl_cb_slot_busy) != 0) { |
596 | rpc_sleep_on(&clp->cl_cb_waitq, task, NULL); | 775 | rpc_sleep_on(&clp->cl_cb_waitq, task, NULL); |
597 | dprintk("%s slot is busy\n", __func__); | 776 | dprintk("%s slot is busy\n", __func__); |
598 | status = -EAGAIN; | 777 | return false; |
599 | goto out; | ||
600 | } | 778 | } |
601 | 779 | return true; | |
602 | /* | ||
603 | * We'll need the clp during XDR encoding and decoding, | ||
604 | * and the sequence during decoding to verify the reply | ||
605 | */ | ||
606 | args->args_seq.cbs_clp = clp; | ||
607 | task->tk_msg.rpc_resp = &args->args_seq; | ||
608 | |||
609 | out: | ||
610 | dprintk("%s status=%d\n", __func__, status); | ||
611 | return status; | ||
612 | } | 780 | } |
613 | 781 | ||
614 | /* | 782 | /* |
@@ -617,42 +785,42 @@ out: | |||
617 | */ | 785 | */ |
618 | static void nfsd4_cb_prepare(struct rpc_task *task, void *calldata) | 786 | static void nfsd4_cb_prepare(struct rpc_task *task, void *calldata) |
619 | { | 787 | { |
620 | struct nfs4_delegation *dp = calldata; | 788 | struct nfsd4_callback *cb = calldata; |
789 | struct nfs4_delegation *dp = container_of(cb, struct nfs4_delegation, dl_recall); | ||
621 | struct nfs4_client *clp = dp->dl_client; | 790 | struct nfs4_client *clp = dp->dl_client; |
622 | struct nfs4_rpc_args *args = task->tk_msg.rpc_argp; | 791 | u32 minorversion = clp->cl_minorversion; |
623 | u32 minorversion = clp->cl_cb_conn.cb_minorversion; | ||
624 | int status = 0; | ||
625 | 792 | ||
626 | args->args_seq.cbs_minorversion = minorversion; | 793 | cb->cb_minorversion = minorversion; |
627 | if (minorversion) { | 794 | if (minorversion) { |
628 | status = nfsd41_cb_setup_sequence(clp, task); | 795 | if (!nfsd41_cb_get_slot(clp, task)) |
629 | if (status) { | ||
630 | if (status != -EAGAIN) { | ||
631 | /* terminate rpc task */ | ||
632 | task->tk_status = status; | ||
633 | task->tk_action = NULL; | ||
634 | } | ||
635 | return; | 796 | return; |
636 | } | ||
637 | } | 797 | } |
798 | spin_lock(&clp->cl_lock); | ||
799 | if (list_empty(&cb->cb_per_client)) { | ||
800 | /* This is the first call, not a restart */ | ||
801 | cb->cb_done = false; | ||
802 | list_add(&cb->cb_per_client, &clp->cl_callbacks); | ||
803 | } | ||
804 | spin_unlock(&clp->cl_lock); | ||
638 | rpc_call_start(task); | 805 | rpc_call_start(task); |
639 | } | 806 | } |
640 | 807 | ||
641 | static void nfsd4_cb_done(struct rpc_task *task, void *calldata) | 808 | static void nfsd4_cb_done(struct rpc_task *task, void *calldata) |
642 | { | 809 | { |
643 | struct nfs4_delegation *dp = calldata; | 810 | struct nfsd4_callback *cb = calldata; |
811 | struct nfs4_delegation *dp = container_of(cb, struct nfs4_delegation, dl_recall); | ||
644 | struct nfs4_client *clp = dp->dl_client; | 812 | struct nfs4_client *clp = dp->dl_client; |
645 | 813 | ||
646 | dprintk("%s: minorversion=%d\n", __func__, | 814 | dprintk("%s: minorversion=%d\n", __func__, |
647 | clp->cl_cb_conn.cb_minorversion); | 815 | clp->cl_minorversion); |
648 | 816 | ||
649 | if (clp->cl_cb_conn.cb_minorversion) { | 817 | if (clp->cl_minorversion) { |
650 | /* No need for lock, access serialized in nfsd4_cb_prepare */ | 818 | /* No need for lock, access serialized in nfsd4_cb_prepare */ |
651 | ++clp->cl_cb_seq_nr; | 819 | ++clp->cl_cb_session->se_cb_seq_nr; |
652 | clear_bit(0, &clp->cl_cb_slot_busy); | 820 | clear_bit(0, &clp->cl_cb_slot_busy); |
653 | rpc_wake_up_next(&clp->cl_cb_waitq); | 821 | rpc_wake_up_next(&clp->cl_cb_waitq); |
654 | dprintk("%s: freed slot, new seqid=%d\n", __func__, | 822 | dprintk("%s: freed slot, new seqid=%d\n", __func__, |
655 | clp->cl_cb_seq_nr); | 823 | clp->cl_cb_session->se_cb_seq_nr); |
656 | 824 | ||
657 | /* We're done looking into the sequence information */ | 825 | /* We're done looking into the sequence information */ |
658 | task->tk_msg.rpc_resp = NULL; | 826 | task->tk_msg.rpc_resp = NULL; |
@@ -662,21 +830,25 @@ static void nfsd4_cb_done(struct rpc_task *task, void *calldata) | |||
662 | 830 | ||
663 | static void nfsd4_cb_recall_done(struct rpc_task *task, void *calldata) | 831 | static void nfsd4_cb_recall_done(struct rpc_task *task, void *calldata) |
664 | { | 832 | { |
665 | struct nfs4_delegation *dp = calldata; | 833 | struct nfsd4_callback *cb = calldata; |
834 | struct nfs4_delegation *dp = container_of(cb, struct nfs4_delegation, dl_recall); | ||
666 | struct nfs4_client *clp = dp->dl_client; | 835 | struct nfs4_client *clp = dp->dl_client; |
667 | struct rpc_clnt *current_rpc_client = clp->cl_cb_client; | 836 | struct rpc_clnt *current_rpc_client = clp->cl_cb_client; |
668 | 837 | ||
669 | nfsd4_cb_done(task, calldata); | 838 | nfsd4_cb_done(task, calldata); |
670 | 839 | ||
671 | if (current_rpc_client == NULL) { | 840 | if (current_rpc_client != task->tk_client) { |
672 | /* We're shutting down; give up. */ | 841 | /* We're shutting down or changing cl_cb_client; leave |
673 | /* XXX: err, or is it ok just to fall through | 842 | * it to nfsd4_process_cb_update to restart the call if |
674 | * and rpc_restart_call? */ | 843 | * necessary. */ |
675 | return; | 844 | return; |
676 | } | 845 | } |
677 | 846 | ||
847 | if (cb->cb_done) | ||
848 | return; | ||
678 | switch (task->tk_status) { | 849 | switch (task->tk_status) { |
679 | case 0: | 850 | case 0: |
851 | cb->cb_done = true; | ||
680 | return; | 852 | return; |
681 | case -EBADHANDLE: | 853 | case -EBADHANDLE: |
682 | case -NFS4ERR_BAD_STATEID: | 854 | case -NFS4ERR_BAD_STATEID: |
@@ -685,31 +857,30 @@ static void nfsd4_cb_recall_done(struct rpc_task *task, void *calldata) | |||
685 | break; | 857 | break; |
686 | default: | 858 | default: |
687 | /* Network partition? */ | 859 | /* Network partition? */ |
688 | atomic_set(&clp->cl_cb_set, 0); | 860 | nfsd4_mark_cb_down(clp, task->tk_status); |
689 | warn_no_callback_path(clp, task->tk_status); | ||
690 | if (current_rpc_client != task->tk_client) { | ||
691 | /* queue a callback on the new connection: */ | ||
692 | atomic_inc(&dp->dl_count); | ||
693 | nfsd4_cb_recall(dp); | ||
694 | return; | ||
695 | } | ||
696 | } | 861 | } |
697 | if (dp->dl_retries--) { | 862 | if (dp->dl_retries--) { |
698 | rpc_delay(task, 2*HZ); | 863 | rpc_delay(task, 2*HZ); |
699 | task->tk_status = 0; | 864 | task->tk_status = 0; |
700 | rpc_restart_call_prepare(task); | 865 | rpc_restart_call_prepare(task); |
701 | return; | 866 | return; |
702 | } else { | ||
703 | atomic_set(&clp->cl_cb_set, 0); | ||
704 | warn_no_callback_path(clp, task->tk_status); | ||
705 | } | 867 | } |
868 | nfsd4_mark_cb_down(clp, task->tk_status); | ||
869 | cb->cb_done = true; | ||
706 | } | 870 | } |
707 | 871 | ||
708 | static void nfsd4_cb_recall_release(void *calldata) | 872 | static void nfsd4_cb_recall_release(void *calldata) |
709 | { | 873 | { |
710 | struct nfs4_delegation *dp = calldata; | 874 | struct nfsd4_callback *cb = calldata; |
711 | 875 | struct nfs4_client *clp = cb->cb_clp; | |
712 | nfs4_put_delegation(dp); | 876 | struct nfs4_delegation *dp = container_of(cb, struct nfs4_delegation, dl_recall); |
877 | |||
878 | if (cb->cb_done) { | ||
879 | spin_lock(&clp->cl_lock); | ||
880 | list_del(&cb->cb_per_client); | ||
881 | spin_unlock(&clp->cl_lock); | ||
882 | nfs4_put_delegation(dp); | ||
883 | } | ||
713 | } | 884 | } |
714 | 885 | ||
715 | static const struct rpc_call_ops nfsd4_cb_recall_ops = { | 886 | static const struct rpc_call_ops nfsd4_cb_recall_ops = { |
@@ -718,8 +889,6 @@ static const struct rpc_call_ops nfsd4_cb_recall_ops = { | |||
718 | .rpc_release = nfsd4_cb_recall_release, | 889 | .rpc_release = nfsd4_cb_recall_release, |
719 | }; | 890 | }; |
720 | 891 | ||
721 | static struct workqueue_struct *callback_wq; | ||
722 | |||
723 | int nfsd4_create_callback_queue(void) | 892 | int nfsd4_create_callback_queue(void) |
724 | { | 893 | { |
725 | callback_wq = create_singlethread_workqueue("nfsd4_callbacks"); | 894 | callback_wq = create_singlethread_workqueue("nfsd4_callbacks"); |
@@ -734,57 +903,124 @@ void nfsd4_destroy_callback_queue(void) | |||
734 | } | 903 | } |
735 | 904 | ||
736 | /* must be called under the state lock */ | 905 | /* must be called under the state lock */ |
737 | void nfsd4_set_callback_client(struct nfs4_client *clp, struct rpc_clnt *new) | 906 | void nfsd4_shutdown_callback(struct nfs4_client *clp) |
738 | { | 907 | { |
739 | struct rpc_clnt *old = clp->cl_cb_client; | 908 | set_bit(NFSD4_CLIENT_KILL, &clp->cl_cb_flags); |
740 | |||
741 | clp->cl_cb_client = new; | ||
742 | /* | 909 | /* |
743 | * After this, any work that saw the old value of cl_cb_client will | 910 | * Note this won't actually result in a null callback; |
744 | * be gone: | 911 | * instead, nfsd4_do_callback_rpc() will detect the killed |
912 | * client, destroy the rpc client, and stop: | ||
745 | */ | 913 | */ |
914 | do_probe_callback(clp); | ||
746 | flush_workqueue(callback_wq); | 915 | flush_workqueue(callback_wq); |
747 | /* So we can safely shut it down: */ | ||
748 | if (old) | ||
749 | rpc_shutdown_client(old); | ||
750 | } | 916 | } |
751 | 917 | ||
752 | /* | 918 | static void nfsd4_release_cb(struct nfsd4_callback *cb) |
753 | * called with dp->dl_count inc'ed. | ||
754 | */ | ||
755 | static void _nfsd4_cb_recall(struct nfs4_delegation *dp) | ||
756 | { | 919 | { |
757 | struct nfs4_client *clp = dp->dl_client; | 920 | if (cb->cb_ops->rpc_release) |
758 | struct rpc_clnt *clnt = clp->cl_cb_client; | 921 | cb->cb_ops->rpc_release(cb); |
759 | struct nfs4_rpc_args *args = &dp->dl_recall.cb_args; | 922 | } |
760 | struct rpc_message msg = { | ||
761 | .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_RECALL], | ||
762 | .rpc_cred = callback_cred | ||
763 | }; | ||
764 | 923 | ||
765 | if (clnt == NULL) { | 924 | /* requires cl_lock: */ |
766 | nfs4_put_delegation(dp); | 925 | static struct nfsd4_conn * __nfsd4_find_backchannel(struct nfs4_client *clp) |
767 | return; /* Client is shutting down; give up. */ | 926 | { |
927 | struct nfsd4_session *s; | ||
928 | struct nfsd4_conn *c; | ||
929 | |||
930 | list_for_each_entry(s, &clp->cl_sessions, se_perclnt) { | ||
931 | list_for_each_entry(c, &s->se_conns, cn_persession) { | ||
932 | if (c->cn_flags & NFS4_CDFC4_BACK) | ||
933 | return c; | ||
934 | } | ||
768 | } | 935 | } |
936 | return NULL; | ||
937 | } | ||
769 | 938 | ||
770 | args->args_op = dp; | 939 | static void nfsd4_process_cb_update(struct nfsd4_callback *cb) |
771 | msg.rpc_argp = args; | 940 | { |
772 | dp->dl_retries = 1; | 941 | struct nfs4_cb_conn conn; |
773 | rpc_call_async(clnt, &msg, RPC_TASK_SOFT, &nfsd4_cb_recall_ops, dp); | 942 | struct nfs4_client *clp = cb->cb_clp; |
943 | struct nfsd4_session *ses = NULL; | ||
944 | struct nfsd4_conn *c; | ||
945 | int err; | ||
946 | |||
947 | /* | ||
948 | * This is either an update, or the client dying; in either case, | ||
949 | * kill the old client: | ||
950 | */ | ||
951 | if (clp->cl_cb_client) { | ||
952 | rpc_shutdown_client(clp->cl_cb_client); | ||
953 | clp->cl_cb_client = NULL; | ||
954 | } | ||
955 | if (clp->cl_cb_conn.cb_xprt) { | ||
956 | svc_xprt_put(clp->cl_cb_conn.cb_xprt); | ||
957 | clp->cl_cb_conn.cb_xprt = NULL; | ||
958 | } | ||
959 | if (test_bit(NFSD4_CLIENT_KILL, &clp->cl_cb_flags)) | ||
960 | return; | ||
961 | spin_lock(&clp->cl_lock); | ||
962 | /* | ||
963 | * Only serialized callback code is allowed to clear these | ||
964 | * flags; main nfsd code can only set them: | ||
965 | */ | ||
966 | BUG_ON(!clp->cl_cb_flags); | ||
967 | clear_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_cb_flags); | ||
968 | memcpy(&conn, &cb->cb_clp->cl_cb_conn, sizeof(struct nfs4_cb_conn)); | ||
969 | c = __nfsd4_find_backchannel(clp); | ||
970 | if (c) { | ||
971 | svc_xprt_get(c->cn_xprt); | ||
972 | conn.cb_xprt = c->cn_xprt; | ||
973 | ses = c->cn_session; | ||
974 | } | ||
975 | spin_unlock(&clp->cl_lock); | ||
976 | |||
977 | err = setup_callback_client(clp, &conn, ses); | ||
978 | if (err) { | ||
979 | warn_no_callback_path(clp, err); | ||
980 | return; | ||
981 | } | ||
982 | /* Yay, the callback channel's back! Restart any callbacks: */ | ||
983 | list_for_each_entry(cb, &clp->cl_callbacks, cb_per_client) | ||
984 | run_nfsd4_cb(cb); | ||
774 | } | 985 | } |
775 | 986 | ||
776 | void nfsd4_do_callback_rpc(struct work_struct *w) | 987 | void nfsd4_do_callback_rpc(struct work_struct *w) |
777 | { | 988 | { |
778 | /* XXX: for now, just send off delegation recall. */ | 989 | struct nfsd4_callback *cb = container_of(w, struct nfsd4_callback, cb_work); |
779 | /* In future, generalize to handle any sort of callback. */ | 990 | struct nfs4_client *clp = cb->cb_clp; |
780 | struct nfsd4_callback *c = container_of(w, struct nfsd4_callback, cb_work); | 991 | struct rpc_clnt *clnt; |
781 | struct nfs4_delegation *dp = container_of(c, struct nfs4_delegation, dl_recall); | ||
782 | 992 | ||
783 | _nfsd4_cb_recall(dp); | 993 | if (clp->cl_cb_flags) |
784 | } | 994 | nfsd4_process_cb_update(cb); |
785 | 995 | ||
996 | clnt = clp->cl_cb_client; | ||
997 | if (!clnt) { | ||
998 | /* Callback channel broken, or client killed; give up: */ | ||
999 | nfsd4_release_cb(cb); | ||
1000 | return; | ||
1001 | } | ||
1002 | rpc_call_async(clnt, &cb->cb_msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN, | ||
1003 | cb->cb_ops, cb); | ||
1004 | } | ||
786 | 1005 | ||
787 | void nfsd4_cb_recall(struct nfs4_delegation *dp) | 1006 | void nfsd4_cb_recall(struct nfs4_delegation *dp) |
788 | { | 1007 | { |
789 | queue_work(callback_wq, &dp->dl_recall.cb_work); | 1008 | struct nfsd4_callback *cb = &dp->dl_recall; |
1009 | struct nfs4_client *clp = dp->dl_client; | ||
1010 | |||
1011 | dp->dl_retries = 1; | ||
1012 | cb->cb_op = dp; | ||
1013 | cb->cb_clp = clp; | ||
1014 | cb->cb_msg.rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_RECALL]; | ||
1015 | cb->cb_msg.rpc_argp = cb; | ||
1016 | cb->cb_msg.rpc_resp = cb; | ||
1017 | cb->cb_msg.rpc_cred = callback_cred; | ||
1018 | |||
1019 | cb->cb_ops = &nfsd4_cb_recall_ops; | ||
1020 | dp->dl_retries = 1; | ||
1021 | |||
1022 | INIT_LIST_HEAD(&cb->cb_per_client); | ||
1023 | cb->cb_done = true; | ||
1024 | |||
1025 | run_nfsd4_cb(&dp->dl_recall); | ||
790 | } | 1026 | } |