Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/sunrpc/clnt.h> |
Kinglong Mee | d531c00 | 2014-03-24 11:59:46 +0800 | [diff] [blame] | 35 | #include <linux/sunrpc/xprt.h> |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 36 | #include <linux/sunrpc/svc_xprt.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 38 | #include "nfsd.h" |
| 39 | #include "state.h" |
Stanislav Kinsbursky | 3d73371 | 2012-11-27 14:11:44 +0300 | [diff] [blame] | 40 | #include "netns.h" |
J. Bruce Fields | 06b332a | 2013-04-09 11:34:36 -0400 | [diff] [blame] | 41 | #include "xdr4cb.h" |
Olga Kornievskaia | 9eb190fca8f | 2018-07-20 18:19:17 -0400 | [diff] [blame] | 42 | #include "xdr4.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #define NFSDDBG_FACILITY NFSDDBG_PROC |
| 45 | |
Benny Halevy | 5423732 | 2011-10-19 19:12:58 -0700 | [diff] [blame] | 46 | static void nfsd4_mark_cb_fault(struct nfs4_client *, int reason); |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #define NFSPROC4_CB_NULL 0 |
| 49 | #define NFSPROC4_CB_COMPOUND 1 |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* Index of predefined Linux callback client operations */ |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | struct nfs4_cb_compound_hdr { |
Andy Adamson | 38524ab | 2009-09-10 12:25:59 +0300 | [diff] [blame] | 54 | /* args */ |
| 55 | u32 ident; /* minorversion 0 only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | u32 nops; |
Andy Adamson | ef52bff | 2009-06-16 04:20:50 +0300 | [diff] [blame] | 57 | __be32 *nops_p; |
Andy Adamson | ab52ae6 | 2009-06-16 04:20:53 +0300 | [diff] [blame] | 58 | u32 minorversion; |
Andy Adamson | 38524ab | 2009-09-10 12:25:59 +0300 | [diff] [blame] | 59 | /* res */ |
| 60 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 63 | /* |
| 64 | * Handle decode buffer overflows out-of-line. |
| 65 | */ |
| 66 | static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 68 | dprintk("NFS: %s prematurely hit the end of our receive buffer. " |
| 69 | "Remaining buffer length is %tu words.\n", |
| 70 | func, xdr->end - xdr->p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 73 | static __be32 *xdr_encode_empty_array(__be32 *p) |
| 74 | { |
| 75 | *p++ = xdr_zero; |
| 76 | return p; |
| 77 | } |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 80 | * Encode/decode NFSv4 CB basic data types |
| 81 | * |
| 82 | * Basic NFSv4 callback data types are defined in section 15 of RFC |
| 83 | * 3530: "Network File System (NFS) version 4 Protocol" and section |
| 84 | * 20 of RFC 5661: "Network File System (NFS) Version 4 Minor Version |
| 85 | * 1 Protocol" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | */ |
| 87 | |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 88 | /* |
| 89 | * nfs_cb_opnum4 |
| 90 | * |
| 91 | * enum nfs_cb_opnum4 { |
| 92 | * OP_CB_GETATTR = 3, |
| 93 | * ... |
| 94 | * }; |
| 95 | */ |
| 96 | enum nfs_cb_opnum4 { |
| 97 | OP_CB_GETATTR = 3, |
| 98 | OP_CB_RECALL = 4, |
| 99 | OP_CB_LAYOUTRECALL = 5, |
| 100 | OP_CB_NOTIFY = 6, |
| 101 | OP_CB_PUSH_DELEG = 7, |
| 102 | OP_CB_RECALL_ANY = 8, |
| 103 | OP_CB_RECALLABLE_OBJ_AVAIL = 9, |
| 104 | OP_CB_RECALL_SLOT = 10, |
| 105 | OP_CB_SEQUENCE = 11, |
| 106 | OP_CB_WANTS_CANCELLED = 12, |
| 107 | OP_CB_NOTIFY_LOCK = 13, |
| 108 | OP_CB_NOTIFY_DEVICEID = 14, |
Olga Kornievskaia | 9eb190fca8f | 2018-07-20 18:19:17 -0400 | [diff] [blame] | 109 | OP_CB_OFFLOAD = 15, |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 110 | OP_CB_ILLEGAL = 10044 |
| 111 | }; |
| 112 | |
| 113 | static void encode_nfs_cb_opnum4(struct xdr_stream *xdr, enum nfs_cb_opnum4 op) |
Benny Halevy | 9303bbd | 2010-05-25 09:50:23 +0300 | [diff] [blame] | 114 | { |
| 115 | __be32 *p; |
| 116 | |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 117 | p = xdr_reserve_space(xdr, 4); |
| 118 | *p = cpu_to_be32(op); |
Benny Halevy | 9303bbd | 2010-05-25 09:50:23 +0300 | [diff] [blame] | 119 | } |
| 120 | |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 121 | /* |
| 122 | * nfs_fh4 |
| 123 | * |
| 124 | * typedef opaque nfs_fh4<NFS4_FHSIZE>; |
| 125 | */ |
| 126 | static void encode_nfs_fh4(struct xdr_stream *xdr, const struct knfsd_fh *fh) |
| 127 | { |
| 128 | u32 length = fh->fh_size; |
| 129 | __be32 *p; |
| 130 | |
| 131 | BUG_ON(length > NFS4_FHSIZE); |
| 132 | p = xdr_reserve_space(xdr, 4 + length); |
| 133 | xdr_encode_opaque(p, &fh->fh_base, length); |
| 134 | } |
| 135 | |
| 136 | /* |
| 137 | * stateid4 |
| 138 | * |
| 139 | * struct stateid4 { |
| 140 | * uint32_t seqid; |
| 141 | * opaque other[12]; |
| 142 | * }; |
| 143 | */ |
| 144 | static void encode_stateid4(struct xdr_stream *xdr, const stateid_t *sid) |
| 145 | { |
| 146 | __be32 *p; |
| 147 | |
| 148 | p = xdr_reserve_space(xdr, NFS4_STATEID_SIZE); |
| 149 | *p++ = cpu_to_be32(sid->si_generation); |
| 150 | xdr_encode_opaque_fixed(p, &sid->si_opaque, NFS4_STATEID_OTHER_SIZE); |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * sessionid4 |
| 155 | * |
| 156 | * typedef opaque sessionid4[NFS4_SESSIONID_SIZE]; |
| 157 | */ |
| 158 | static void encode_sessionid4(struct xdr_stream *xdr, |
| 159 | const struct nfsd4_session *session) |
| 160 | { |
| 161 | __be32 *p; |
| 162 | |
| 163 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN); |
| 164 | xdr_encode_opaque_fixed(p, session->se_sessionid.data, |
| 165 | NFS4_MAX_SESSIONID_LEN); |
| 166 | } |
| 167 | |
| 168 | /* |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 169 | * nfsstat4 |
| 170 | */ |
| 171 | static const struct { |
| 172 | int stat; |
| 173 | int errno; |
| 174 | } nfs_cb_errtbl[] = { |
| 175 | { NFS4_OK, 0 }, |
| 176 | { NFS4ERR_PERM, -EPERM }, |
| 177 | { NFS4ERR_NOENT, -ENOENT }, |
| 178 | { NFS4ERR_IO, -EIO }, |
| 179 | { NFS4ERR_NXIO, -ENXIO }, |
| 180 | { NFS4ERR_ACCESS, -EACCES }, |
| 181 | { NFS4ERR_EXIST, -EEXIST }, |
| 182 | { NFS4ERR_XDEV, -EXDEV }, |
| 183 | { NFS4ERR_NOTDIR, -ENOTDIR }, |
| 184 | { NFS4ERR_ISDIR, -EISDIR }, |
| 185 | { NFS4ERR_INVAL, -EINVAL }, |
| 186 | { NFS4ERR_FBIG, -EFBIG }, |
| 187 | { NFS4ERR_NOSPC, -ENOSPC }, |
| 188 | { NFS4ERR_ROFS, -EROFS }, |
| 189 | { NFS4ERR_MLINK, -EMLINK }, |
| 190 | { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG }, |
| 191 | { NFS4ERR_NOTEMPTY, -ENOTEMPTY }, |
| 192 | { NFS4ERR_DQUOT, -EDQUOT }, |
| 193 | { NFS4ERR_STALE, -ESTALE }, |
| 194 | { NFS4ERR_BADHANDLE, -EBADHANDLE }, |
| 195 | { NFS4ERR_BAD_COOKIE, -EBADCOOKIE }, |
| 196 | { NFS4ERR_NOTSUPP, -ENOTSUPP }, |
| 197 | { NFS4ERR_TOOSMALL, -ETOOSMALL }, |
| 198 | { NFS4ERR_SERVERFAULT, -ESERVERFAULT }, |
| 199 | { NFS4ERR_BADTYPE, -EBADTYPE }, |
| 200 | { NFS4ERR_LOCKED, -EAGAIN }, |
| 201 | { NFS4ERR_RESOURCE, -EREMOTEIO }, |
| 202 | { NFS4ERR_SYMLINK, -ELOOP }, |
| 203 | { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP }, |
| 204 | { NFS4ERR_DEADLOCK, -EDEADLK }, |
| 205 | { -1, -EIO } |
| 206 | }; |
| 207 | |
| 208 | /* |
| 209 | * If we cannot translate the error, the recovery routines should |
| 210 | * handle it. |
| 211 | * |
| 212 | * Note: remaining NFSv4 error codes have values > 10000, so should |
| 213 | * not conflict with native Linux error codes. |
| 214 | */ |
| 215 | static int nfs_cb_stat_to_errno(int status) |
| 216 | { |
| 217 | int i; |
| 218 | |
| 219 | for (i = 0; nfs_cb_errtbl[i].stat != -1; i++) { |
| 220 | if (nfs_cb_errtbl[i].stat == status) |
| 221 | return nfs_cb_errtbl[i].errno; |
| 222 | } |
| 223 | |
| 224 | dprintk("NFSD: Unrecognized NFS CB status value: %u\n", status); |
| 225 | return -status; |
| 226 | } |
| 227 | |
Stefan Agner | 47299f7 | 2018-03-19 23:37:05 +0100 | [diff] [blame] | 228 | static int decode_cb_op_status(struct xdr_stream *xdr, |
| 229 | enum nfs_cb_opnum4 expected, int *status) |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 230 | { |
| 231 | __be32 *p; |
| 232 | u32 op; |
| 233 | |
| 234 | p = xdr_inline_decode(xdr, 4 + 4); |
| 235 | if (unlikely(p == NULL)) |
| 236 | goto out_overflow; |
| 237 | op = be32_to_cpup(p++); |
| 238 | if (unlikely(op != expected)) |
| 239 | goto out_unexpected; |
Christoph Hellwig | ef2a1b3 | 2015-04-30 11:49:23 +0200 | [diff] [blame] | 240 | *status = nfs_cb_stat_to_errno(be32_to_cpup(p)); |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 241 | return 0; |
| 242 | out_overflow: |
| 243 | print_overflow_msg(__func__, xdr); |
| 244 | return -EIO; |
| 245 | out_unexpected: |
| 246 | dprintk("NFSD: Callback server returned operation %d but " |
| 247 | "we issued a request for %d\n", op, expected); |
| 248 | return -EIO; |
| 249 | } |
| 250 | |
| 251 | /* |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 252 | * CB_COMPOUND4args |
| 253 | * |
| 254 | * struct CB_COMPOUND4args { |
| 255 | * utf8str_cs tag; |
| 256 | * uint32_t minorversion; |
| 257 | * uint32_t callback_ident; |
| 258 | * nfs_cb_argop4 argarray<>; |
| 259 | * }; |
| 260 | */ |
| 261 | static void encode_cb_compound4args(struct xdr_stream *xdr, |
| 262 | struct nfs4_cb_compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | { |
Al Viro | f00f328 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 264 | __be32 * p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 266 | p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4); |
| 267 | p = xdr_encode_empty_array(p); /* empty tag */ |
| 268 | *p++ = cpu_to_be32(hdr->minorversion); |
| 269 | *p++ = cpu_to_be32(hdr->ident); |
| 270 | |
Andy Adamson | ef52bff | 2009-06-16 04:20:50 +0300 | [diff] [blame] | 271 | hdr->nops_p = p; |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 272 | *p = cpu_to_be32(hdr->nops); /* argarray element count */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 275 | /* |
| 276 | * Update argarray element count |
| 277 | */ |
Andy Adamson | ef52bff | 2009-06-16 04:20:50 +0300 | [diff] [blame] | 278 | static void encode_cb_nops(struct nfs4_cb_compound_hdr *hdr) |
| 279 | { |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 280 | BUG_ON(hdr->nops > NFS4_MAX_BACK_CHANNEL_OPS); |
| 281 | *hdr->nops_p = cpu_to_be32(hdr->nops); |
Andy Adamson | ef52bff | 2009-06-16 04:20:50 +0300 | [diff] [blame] | 282 | } |
| 283 | |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 284 | /* |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 285 | * CB_COMPOUND4res |
| 286 | * |
| 287 | * struct CB_COMPOUND4res { |
| 288 | * nfsstat4 status; |
| 289 | * utf8str_cs tag; |
| 290 | * nfs_cb_resop4 resarray<>; |
| 291 | * }; |
| 292 | */ |
| 293 | static int decode_cb_compound4res(struct xdr_stream *xdr, |
| 294 | struct nfs4_cb_compound_hdr *hdr) |
| 295 | { |
| 296 | u32 length; |
| 297 | __be32 *p; |
| 298 | |
| 299 | p = xdr_inline_decode(xdr, 4 + 4); |
| 300 | if (unlikely(p == NULL)) |
| 301 | goto out_overflow; |
| 302 | hdr->status = be32_to_cpup(p++); |
| 303 | /* Ignore the tag */ |
| 304 | length = be32_to_cpup(p++); |
| 305 | p = xdr_inline_decode(xdr, length + 4); |
| 306 | if (unlikely(p == NULL)) |
| 307 | goto out_overflow; |
Kinglong Mee | e86a40b | 2017-02-05 09:57:37 +0800 | [diff] [blame] | 308 | p += XDR_QUADLEN(length); |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 309 | hdr->nops = be32_to_cpup(p); |
| 310 | return 0; |
| 311 | out_overflow: |
| 312 | print_overflow_msg(__func__, xdr); |
| 313 | return -EIO; |
| 314 | } |
| 315 | |
| 316 | /* |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 317 | * CB_RECALL4args |
| 318 | * |
| 319 | * struct CB_RECALL4args { |
| 320 | * stateid4 stateid; |
| 321 | * bool truncate; |
| 322 | * nfs_fh4 fh; |
| 323 | * }; |
| 324 | */ |
| 325 | static void encode_cb_recall4args(struct xdr_stream *xdr, |
| 326 | const struct nfs4_delegation *dp, |
| 327 | struct nfs4_cb_compound_hdr *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { |
Al Viro | f00f328 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 329 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 331 | encode_nfs_cb_opnum4(xdr, OP_CB_RECALL); |
J. Bruce Fields | d5477a8 | 2011-09-08 12:07:44 -0400 | [diff] [blame] | 332 | encode_stateid4(xdr, &dp->dl_stid.sc_stateid); |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 333 | |
| 334 | p = xdr_reserve_space(xdr, 4); |
| 335 | *p++ = xdr_zero; /* truncate */ |
| 336 | |
Trond Myklebust | 11b9164 | 2014-07-29 21:34:08 -0400 | [diff] [blame] | 337 | encode_nfs_fh4(xdr, &dp->dl_stid.sc_file->fi_fhandle); |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 338 | |
Andy Adamson | ef52bff | 2009-06-16 04:20:50 +0300 | [diff] [blame] | 339 | hdr->nops++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 342 | /* |
| 343 | * CB_SEQUENCE4args |
| 344 | * |
| 345 | * struct CB_SEQUENCE4args { |
| 346 | * sessionid4 csa_sessionid; |
| 347 | * sequenceid4 csa_sequenceid; |
| 348 | * slotid4 csa_slotid; |
| 349 | * slotid4 csa_highest_slotid; |
| 350 | * bool csa_cachethis; |
| 351 | * referring_call_list4 csa_referring_call_lists<>; |
| 352 | * }; |
| 353 | */ |
| 354 | static void encode_cb_sequence4args(struct xdr_stream *xdr, |
| 355 | const struct nfsd4_callback *cb, |
| 356 | struct nfs4_cb_compound_hdr *hdr) |
Benny Halevy | 2af7358 | 2009-09-10 12:26:51 +0300 | [diff] [blame] | 357 | { |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 358 | struct nfsd4_session *session = cb->cb_clp->cl_cb_session; |
Benny Halevy | 2af7358 | 2009-09-10 12:26:51 +0300 | [diff] [blame] | 359 | __be32 *p; |
| 360 | |
| 361 | if (hdr->minorversion == 0) |
| 362 | return; |
| 363 | |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 364 | encode_nfs_cb_opnum4(xdr, OP_CB_SEQUENCE); |
| 365 | encode_sessionid4(xdr, session); |
Benny Halevy | 2af7358 | 2009-09-10 12:26:51 +0300 | [diff] [blame] | 366 | |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 367 | p = xdr_reserve_space(xdr, 4 + 4 + 4 + 4 + 4); |
| 368 | *p++ = cpu_to_be32(session->se_cb_seq_nr); /* csa_sequenceid */ |
| 369 | *p++ = xdr_zero; /* csa_slotid */ |
| 370 | *p++ = xdr_zero; /* csa_highest_slotid */ |
| 371 | *p++ = xdr_zero; /* csa_cachethis */ |
| 372 | xdr_encode_empty_array(p); /* csa_referring_call_lists */ |
| 373 | |
Benny Halevy | 2af7358 | 2009-09-10 12:26:51 +0300 | [diff] [blame] | 374 | hdr->nops++; |
| 375 | } |
| 376 | |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 377 | /* |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 378 | * CB_SEQUENCE4resok |
| 379 | * |
| 380 | * struct CB_SEQUENCE4resok { |
| 381 | * sessionid4 csr_sessionid; |
| 382 | * sequenceid4 csr_sequenceid; |
| 383 | * slotid4 csr_slotid; |
| 384 | * slotid4 csr_highest_slotid; |
| 385 | * slotid4 csr_target_highest_slotid; |
| 386 | * }; |
| 387 | * |
| 388 | * union CB_SEQUENCE4res switch (nfsstat4 csr_status) { |
| 389 | * case NFS4_OK: |
| 390 | * CB_SEQUENCE4resok csr_resok4; |
| 391 | * default: |
| 392 | * void; |
| 393 | * }; |
| 394 | * |
| 395 | * Our current back channel implmentation supports a single backchannel |
| 396 | * with a single slot. |
| 397 | */ |
| 398 | static int decode_cb_sequence4resok(struct xdr_stream *xdr, |
| 399 | struct nfsd4_callback *cb) |
| 400 | { |
| 401 | struct nfsd4_session *session = cb->cb_clp->cl_cb_session; |
Kinglong Mee | 8274338 | 2017-02-05 09:57:48 +0800 | [diff] [blame] | 402 | int status = -ESERVERFAULT; |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 403 | __be32 *p; |
| 404 | u32 dummy; |
| 405 | |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 406 | /* |
| 407 | * If the server returns different values for sessionID, slotID or |
| 408 | * sequence number, the server is looney tunes. |
| 409 | */ |
Benny Halevy | 2c9c8f3 | 2011-02-22 14:43:22 -0800 | [diff] [blame] | 410 | p = xdr_inline_decode(xdr, NFS4_MAX_SESSIONID_LEN + 4 + 4 + 4 + 4); |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 411 | if (unlikely(p == NULL)) |
| 412 | goto out_overflow; |
Kinglong Mee | 8274338 | 2017-02-05 09:57:48 +0800 | [diff] [blame] | 413 | |
| 414 | if (memcmp(p, session->se_sessionid.data, NFS4_MAX_SESSIONID_LEN)) { |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 415 | dprintk("NFS: %s Invalid session id\n", __func__); |
| 416 | goto out; |
| 417 | } |
| 418 | p += XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN); |
| 419 | |
| 420 | dummy = be32_to_cpup(p++); |
| 421 | if (dummy != session->se_cb_seq_nr) { |
| 422 | dprintk("NFS: %s Invalid sequence number\n", __func__); |
| 423 | goto out; |
| 424 | } |
| 425 | |
| 426 | dummy = be32_to_cpup(p++); |
| 427 | if (dummy != 0) { |
| 428 | dprintk("NFS: %s Invalid slotid\n", __func__); |
| 429 | goto out; |
| 430 | } |
| 431 | |
| 432 | /* |
| 433 | * FIXME: process highest slotid and target highest slotid |
| 434 | */ |
| 435 | status = 0; |
| 436 | out: |
Kinglong Mee | 7ba6cad | 2015-06-24 16:33:37 +0800 | [diff] [blame] | 437 | cb->cb_seq_status = status; |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 438 | return status; |
| 439 | out_overflow: |
| 440 | print_overflow_msg(__func__, xdr); |
Kinglong Mee | 7ba6cad | 2015-06-24 16:33:37 +0800 | [diff] [blame] | 441 | status = -EIO; |
| 442 | goto out; |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | static int decode_cb_sequence4res(struct xdr_stream *xdr, |
| 446 | struct nfsd4_callback *cb) |
| 447 | { |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 448 | int status; |
| 449 | |
Jeff Layton | 89dfdc9 | 2016-08-16 13:29:27 -0400 | [diff] [blame] | 450 | if (cb->cb_clp->cl_minorversion == 0) |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 451 | return 0; |
| 452 | |
Kinglong Mee | 7ba6cad | 2015-06-24 16:33:37 +0800 | [diff] [blame] | 453 | status = decode_cb_op_status(xdr, OP_CB_SEQUENCE, &cb->cb_seq_status); |
| 454 | if (unlikely(status || cb->cb_seq_status)) |
Christoph Hellwig | ef2a1b3 | 2015-04-30 11:49:23 +0200 | [diff] [blame] | 455 | return status; |
| 456 | |
| 457 | return decode_cb_sequence4resok(xdr, cb); |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /* |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 461 | * NFSv4.0 and NFSv4.1 XDR encode functions |
| 462 | * |
| 463 | * NFSv4.0 callback argument types are defined in section 15 of RFC |
| 464 | * 3530: "Network File System (NFS) version 4 Protocol" and section 20 |
| 465 | * of RFC 5661: "Network File System (NFS) Version 4 Minor Version 1 |
| 466 | * Protocol". |
| 467 | */ |
| 468 | |
| 469 | /* |
| 470 | * NB: Without this zero space reservation, callbacks over krb5p fail |
| 471 | */ |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 472 | static void nfs4_xdr_enc_cb_null(struct rpc_rqst *req, struct xdr_stream *xdr, |
Christoph Hellwig | 1502c81 | 2017-05-08 14:47:53 +0200 | [diff] [blame] | 473 | const void *__unused) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 475 | xdr_reserve_space(xdr, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Chuck Lever | a033db4 | 2010-12-14 14:57:22 +0000 | [diff] [blame] | 478 | /* |
| 479 | * 20.2. Operation 4: CB_RECALL - Recall a Delegation |
| 480 | */ |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 481 | static void nfs4_xdr_enc_cb_recall(struct rpc_rqst *req, struct xdr_stream *xdr, |
Christoph Hellwig | 1502c81 | 2017-05-08 14:47:53 +0200 | [diff] [blame] | 482 | const void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
Christoph Hellwig | 1502c81 | 2017-05-08 14:47:53 +0200 | [diff] [blame] | 484 | const struct nfsd4_callback *cb = data; |
Jeff Layton | 34549ab | 2014-10-01 08:05:22 -0400 | [diff] [blame] | 485 | const struct nfs4_delegation *dp = cb_to_delegation(cb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | struct nfs4_cb_compound_hdr hdr = { |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 487 | .ident = cb->cb_clp->cl_cb_ident, |
Jeff Layton | 89dfdc9 | 2016-08-16 13:29:27 -0400 | [diff] [blame] | 488 | .minorversion = cb->cb_clp->cl_minorversion, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | }; |
| 490 | |
Chuck Lever | 9f06c71 | 2010-12-14 14:59:18 +0000 | [diff] [blame] | 491 | encode_cb_compound4args(xdr, &hdr); |
| 492 | encode_cb_sequence4args(xdr, cb, &hdr); |
Christoph Hellwig | 2faf3b4 | 2014-09-24 12:19:16 +0200 | [diff] [blame] | 493 | encode_cb_recall4args(xdr, dp, &hdr); |
Andy Adamson | ef52bff | 2009-06-16 04:20:50 +0300 | [diff] [blame] | 494 | encode_cb_nops(&hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 498 | /* |
| 499 | * NFSv4.0 and NFSv4.1 XDR decode functions |
| 500 | * |
| 501 | * NFSv4.0 callback result types are defined in section 15 of RFC |
| 502 | * 3530: "Network File System (NFS) version 4 Protocol" and section 20 |
| 503 | * of RFC 5661: "Network File System (NFS) Version 4 Minor Version 1 |
| 504 | * Protocol". |
| 505 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 507 | static int nfs4_xdr_dec_cb_null(struct rpc_rqst *req, struct xdr_stream *xdr, |
| 508 | void *__unused) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | return 0; |
| 511 | } |
| 512 | |
Benny Halevy | 2af7358 | 2009-09-10 12:26:51 +0300 | [diff] [blame] | 513 | /* |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 514 | * 20.2. Operation 4: CB_RECALL - Recall a Delegation |
Benny Halevy | 2af7358 | 2009-09-10 12:26:51 +0300 | [diff] [blame] | 515 | */ |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 516 | static int nfs4_xdr_dec_cb_recall(struct rpc_rqst *rqstp, |
| 517 | struct xdr_stream *xdr, |
Christoph Hellwig | d39916c | 2017-05-08 15:04:45 +0200 | [diff] [blame] | 518 | void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | { |
Christoph Hellwig | d39916c | 2017-05-08 15:04:45 +0200 | [diff] [blame] | 520 | struct nfsd4_callback *cb = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | struct nfs4_cb_compound_hdr hdr; |
| 522 | int status; |
| 523 | |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 524 | status = decode_cb_compound4res(xdr, &hdr); |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 525 | if (unlikely(status)) |
Christoph Hellwig | ef2a1b3 | 2015-04-30 11:49:23 +0200 | [diff] [blame] | 526 | return status; |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 527 | |
| 528 | if (cb != NULL) { |
Chuck Lever | bf26955 | 2010-12-14 14:59:29 +0000 | [diff] [blame] | 529 | status = decode_cb_sequence4res(xdr, cb); |
Kinglong Mee | 7ba6cad | 2015-06-24 16:33:37 +0800 | [diff] [blame] | 530 | if (unlikely(status || cb->cb_seq_status)) |
Christoph Hellwig | ef2a1b3 | 2015-04-30 11:49:23 +0200 | [diff] [blame] | 531 | return status; |
Ricardo Labiaga | 0421b5c | 2009-09-10 12:27:04 +0300 | [diff] [blame] | 532 | } |
Chuck Lever | 85a5648 | 2010-12-14 14:57:32 +0000 | [diff] [blame] | 533 | |
Christoph Hellwig | ef2a1b3 | 2015-04-30 11:49:23 +0200 | [diff] [blame] | 534 | return decode_cb_op_status(xdr, OP_CB_RECALL, &cb->cb_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Christoph Hellwig | c5c707f | 2014-09-23 12:38:48 +0200 | [diff] [blame] | 537 | #ifdef CONFIG_NFSD_PNFS |
| 538 | /* |
| 539 | * CB_LAYOUTRECALL4args |
| 540 | * |
| 541 | * struct layoutrecall_file4 { |
| 542 | * nfs_fh4 lor_fh; |
| 543 | * offset4 lor_offset; |
| 544 | * length4 lor_length; |
| 545 | * stateid4 lor_stateid; |
| 546 | * }; |
| 547 | * |
| 548 | * union layoutrecall4 switch(layoutrecall_type4 lor_recalltype) { |
| 549 | * case LAYOUTRECALL4_FILE: |
| 550 | * layoutrecall_file4 lor_layout; |
| 551 | * case LAYOUTRECALL4_FSID: |
| 552 | * fsid4 lor_fsid; |
| 553 | * case LAYOUTRECALL4_ALL: |
| 554 | * void; |
| 555 | * }; |
| 556 | * |
| 557 | * struct CB_LAYOUTRECALL4args { |
| 558 | * layouttype4 clora_type; |
| 559 | * layoutiomode4 clora_iomode; |
| 560 | * bool clora_changed; |
| 561 | * layoutrecall4 clora_recall; |
| 562 | * }; |
| 563 | */ |
| 564 | static void encode_cb_layout4args(struct xdr_stream *xdr, |
| 565 | const struct nfs4_layout_stateid *ls, |
| 566 | struct nfs4_cb_compound_hdr *hdr) |
| 567 | { |
| 568 | __be32 *p; |
| 569 | |
| 570 | BUG_ON(hdr->minorversion == 0); |
| 571 | |
| 572 | p = xdr_reserve_space(xdr, 5 * 4); |
| 573 | *p++ = cpu_to_be32(OP_CB_LAYOUTRECALL); |
| 574 | *p++ = cpu_to_be32(ls->ls_layout_type); |
| 575 | *p++ = cpu_to_be32(IOMODE_ANY); |
| 576 | *p++ = cpu_to_be32(1); |
| 577 | *p = cpu_to_be32(RETURN_FILE); |
| 578 | |
| 579 | encode_nfs_fh4(xdr, &ls->ls_stid.sc_file->fi_fhandle); |
| 580 | |
| 581 | p = xdr_reserve_space(xdr, 2 * 8); |
| 582 | p = xdr_encode_hyper(p, 0); |
| 583 | xdr_encode_hyper(p, NFS4_MAX_UINT64); |
| 584 | |
| 585 | encode_stateid4(xdr, &ls->ls_recall_sid); |
| 586 | |
| 587 | hdr->nops++; |
| 588 | } |
| 589 | |
| 590 | static void nfs4_xdr_enc_cb_layout(struct rpc_rqst *req, |
| 591 | struct xdr_stream *xdr, |
Christoph Hellwig | 1502c81 | 2017-05-08 14:47:53 +0200 | [diff] [blame] | 592 | const void *data) |
Christoph Hellwig | c5c707f | 2014-09-23 12:38:48 +0200 | [diff] [blame] | 593 | { |
Christoph Hellwig | 1502c81 | 2017-05-08 14:47:53 +0200 | [diff] [blame] | 594 | const struct nfsd4_callback *cb = data; |
Christoph Hellwig | c5c707f | 2014-09-23 12:38:48 +0200 | [diff] [blame] | 595 | const struct nfs4_layout_stateid *ls = |
| 596 | container_of(cb, struct nfs4_layout_stateid, ls_recall); |
| 597 | struct nfs4_cb_compound_hdr hdr = { |
| 598 | .ident = 0, |
Jeff Layton | 89dfdc9 | 2016-08-16 13:29:27 -0400 | [diff] [blame] | 599 | .minorversion = cb->cb_clp->cl_minorversion, |
Christoph Hellwig | c5c707f | 2014-09-23 12:38:48 +0200 | [diff] [blame] | 600 | }; |
| 601 | |
| 602 | encode_cb_compound4args(xdr, &hdr); |
| 603 | encode_cb_sequence4args(xdr, cb, &hdr); |
| 604 | encode_cb_layout4args(xdr, ls, &hdr); |
| 605 | encode_cb_nops(&hdr); |
| 606 | } |
| 607 | |
| 608 | static int nfs4_xdr_dec_cb_layout(struct rpc_rqst *rqstp, |
| 609 | struct xdr_stream *xdr, |
Christoph Hellwig | d39916c | 2017-05-08 15:04:45 +0200 | [diff] [blame] | 610 | void *data) |
Christoph Hellwig | c5c707f | 2014-09-23 12:38:48 +0200 | [diff] [blame] | 611 | { |
Christoph Hellwig | d39916c | 2017-05-08 15:04:45 +0200 | [diff] [blame] | 612 | struct nfsd4_callback *cb = data; |
Christoph Hellwig | c5c707f | 2014-09-23 12:38:48 +0200 | [diff] [blame] | 613 | struct nfs4_cb_compound_hdr hdr; |
Christoph Hellwig | c5c707f | 2014-09-23 12:38:48 +0200 | [diff] [blame] | 614 | int status; |
| 615 | |
| 616 | status = decode_cb_compound4res(xdr, &hdr); |
| 617 | if (unlikely(status)) |
Christoph Hellwig | ef2a1b3 | 2015-04-30 11:49:23 +0200 | [diff] [blame] | 618 | return status; |
| 619 | |
Christoph Hellwig | c5c707f | 2014-09-23 12:38:48 +0200 | [diff] [blame] | 620 | if (cb) { |
| 621 | status = decode_cb_sequence4res(xdr, cb); |
Kinglong Mee | 7ba6cad | 2015-06-24 16:33:37 +0800 | [diff] [blame] | 622 | if (unlikely(status || cb->cb_seq_status)) |
Christoph Hellwig | ef2a1b3 | 2015-04-30 11:49:23 +0200 | [diff] [blame] | 623 | return status; |
Christoph Hellwig | c5c707f | 2014-09-23 12:38:48 +0200 | [diff] [blame] | 624 | } |
Christoph Hellwig | ef2a1b3 | 2015-04-30 11:49:23 +0200 | [diff] [blame] | 625 | return decode_cb_op_status(xdr, OP_CB_LAYOUTRECALL, &cb->cb_status); |
Christoph Hellwig | c5c707f | 2014-09-23 12:38:48 +0200 | [diff] [blame] | 626 | } |
| 627 | #endif /* CONFIG_NFSD_PNFS */ |
| 628 | |
Jeff Layton | a188620e | 2016-09-16 16:28:23 -0400 | [diff] [blame] | 629 | static void encode_stateowner(struct xdr_stream *xdr, struct nfs4_stateowner *so) |
| 630 | { |
| 631 | __be32 *p; |
| 632 | |
| 633 | p = xdr_reserve_space(xdr, 8 + 4 + so->so_owner.len); |
| 634 | p = xdr_encode_opaque_fixed(p, &so->so_client->cl_clientid, 8); |
| 635 | xdr_encode_opaque(p, so->so_owner.data, so->so_owner.len); |
| 636 | } |
| 637 | |
| 638 | static void nfs4_xdr_enc_cb_notify_lock(struct rpc_rqst *req, |
| 639 | struct xdr_stream *xdr, |
Christoph Hellwig | 1502c81 | 2017-05-08 14:47:53 +0200 | [diff] [blame] | 640 | const void *data) |
Jeff Layton | a188620e | 2016-09-16 16:28:23 -0400 | [diff] [blame] | 641 | { |
Christoph Hellwig | 1502c81 | 2017-05-08 14:47:53 +0200 | [diff] [blame] | 642 | const struct nfsd4_callback *cb = data; |
Jeff Layton | a188620e | 2016-09-16 16:28:23 -0400 | [diff] [blame] | 643 | const struct nfsd4_blocked_lock *nbl = |
| 644 | container_of(cb, struct nfsd4_blocked_lock, nbl_cb); |
| 645 | struct nfs4_lockowner *lo = (struct nfs4_lockowner *)nbl->nbl_lock.fl_owner; |
| 646 | struct nfs4_cb_compound_hdr hdr = { |
| 647 | .ident = 0, |
| 648 | .minorversion = cb->cb_clp->cl_minorversion, |
| 649 | }; |
| 650 | |
| 651 | __be32 *p; |
| 652 | |
| 653 | BUG_ON(hdr.minorversion == 0); |
| 654 | |
| 655 | encode_cb_compound4args(xdr, &hdr); |
| 656 | encode_cb_sequence4args(xdr, cb, &hdr); |
| 657 | |
| 658 | p = xdr_reserve_space(xdr, 4); |
| 659 | *p = cpu_to_be32(OP_CB_NOTIFY_LOCK); |
| 660 | encode_nfs_fh4(xdr, &nbl->nbl_fh); |
| 661 | encode_stateowner(xdr, &lo->lo_owner); |
| 662 | hdr.nops++; |
| 663 | |
| 664 | encode_cb_nops(&hdr); |
| 665 | } |
| 666 | |
| 667 | static int nfs4_xdr_dec_cb_notify_lock(struct rpc_rqst *rqstp, |
| 668 | struct xdr_stream *xdr, |
Christoph Hellwig | d39916c | 2017-05-08 15:04:45 +0200 | [diff] [blame] | 669 | void *data) |
Jeff Layton | a188620e | 2016-09-16 16:28:23 -0400 | [diff] [blame] | 670 | { |
Christoph Hellwig | d39916c | 2017-05-08 15:04:45 +0200 | [diff] [blame] | 671 | struct nfsd4_callback *cb = data; |
Jeff Layton | a188620e | 2016-09-16 16:28:23 -0400 | [diff] [blame] | 672 | struct nfs4_cb_compound_hdr hdr; |
| 673 | int status; |
| 674 | |
| 675 | status = decode_cb_compound4res(xdr, &hdr); |
| 676 | if (unlikely(status)) |
| 677 | return status; |
| 678 | |
| 679 | if (cb) { |
| 680 | status = decode_cb_sequence4res(xdr, cb); |
| 681 | if (unlikely(status || cb->cb_seq_status)) |
| 682 | return status; |
| 683 | } |
| 684 | return decode_cb_op_status(xdr, OP_CB_NOTIFY_LOCK, &cb->cb_status); |
| 685 | } |
| 686 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | /* |
Olga Kornievskaia | 9eb190fca8f | 2018-07-20 18:19:17 -0400 | [diff] [blame] | 688 | * struct write_response4 { |
| 689 | * stateid4 wr_callback_id<1>; |
| 690 | * length4 wr_count; |
| 691 | * stable_how4 wr_committed; |
| 692 | * verifier4 wr_writeverf; |
| 693 | * }; |
| 694 | * union offload_info4 switch (nfsstat4 coa_status) { |
| 695 | * case NFS4_OK: |
| 696 | * write_response4 coa_resok4; |
| 697 | * default: |
| 698 | * length4 coa_bytes_copied; |
| 699 | * }; |
| 700 | * struct CB_OFFLOAD4args { |
| 701 | * nfs_fh4 coa_fh; |
| 702 | * stateid4 coa_stateid; |
| 703 | * offload_info4 coa_offload_info; |
| 704 | * }; |
| 705 | */ |
| 706 | static void encode_offload_info4(struct xdr_stream *xdr, |
| 707 | __be32 nfserr, |
| 708 | const struct nfsd4_copy *cp) |
| 709 | { |
| 710 | __be32 *p; |
| 711 | |
| 712 | p = xdr_reserve_space(xdr, 4); |
| 713 | *p++ = nfserr; |
| 714 | if (!nfserr) { |
| 715 | p = xdr_reserve_space(xdr, 4 + 8 + 4 + NFS4_VERIFIER_SIZE); |
| 716 | p = xdr_encode_empty_array(p); |
| 717 | p = xdr_encode_hyper(p, cp->cp_res.wr_bytes_written); |
| 718 | *p++ = cpu_to_be32(cp->cp_res.wr_stable_how); |
| 719 | p = xdr_encode_opaque_fixed(p, cp->cp_res.wr_verifier.data, |
| 720 | NFS4_VERIFIER_SIZE); |
| 721 | } else { |
| 722 | p = xdr_reserve_space(xdr, 8); |
| 723 | /* We always return success if bytes were written */ |
| 724 | p = xdr_encode_hyper(p, 0); |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | static void encode_cb_offload4args(struct xdr_stream *xdr, |
| 729 | __be32 nfserr, |
| 730 | const struct knfsd_fh *fh, |
| 731 | const struct nfsd4_copy *cp, |
| 732 | struct nfs4_cb_compound_hdr *hdr) |
| 733 | { |
| 734 | __be32 *p; |
| 735 | |
| 736 | p = xdr_reserve_space(xdr, 4); |
| 737 | *p++ = cpu_to_be32(OP_CB_OFFLOAD); |
| 738 | encode_nfs_fh4(xdr, fh); |
| 739 | encode_stateid4(xdr, &cp->cp_res.cb_stateid); |
| 740 | encode_offload_info4(xdr, nfserr, cp); |
| 741 | |
| 742 | hdr->nops++; |
| 743 | } |
| 744 | |
| 745 | static void nfs4_xdr_enc_cb_offload(struct rpc_rqst *req, |
| 746 | struct xdr_stream *xdr, |
| 747 | const void *data) |
| 748 | { |
| 749 | const struct nfsd4_callback *cb = data; |
| 750 | const struct nfsd4_copy *cp = |
| 751 | container_of(cb, struct nfsd4_copy, cp_cb); |
| 752 | struct nfs4_cb_compound_hdr hdr = { |
| 753 | .ident = 0, |
| 754 | .minorversion = cb->cb_clp->cl_minorversion, |
| 755 | }; |
| 756 | |
| 757 | encode_cb_compound4args(xdr, &hdr); |
| 758 | encode_cb_sequence4args(xdr, cb, &hdr); |
| 759 | encode_cb_offload4args(xdr, cp->nfserr, &cp->fh, cp, &hdr); |
| 760 | encode_cb_nops(&hdr); |
| 761 | } |
| 762 | |
| 763 | static int nfs4_xdr_dec_cb_offload(struct rpc_rqst *rqstp, |
| 764 | struct xdr_stream *xdr, |
| 765 | void *data) |
| 766 | { |
| 767 | struct nfsd4_callback *cb = data; |
| 768 | struct nfs4_cb_compound_hdr hdr; |
| 769 | int status; |
| 770 | |
| 771 | status = decode_cb_compound4res(xdr, &hdr); |
| 772 | if (unlikely(status)) |
| 773 | return status; |
| 774 | |
| 775 | if (cb) { |
| 776 | status = decode_cb_sequence4res(xdr, cb); |
| 777 | if (unlikely(status || cb->cb_seq_status)) |
| 778 | return status; |
| 779 | } |
| 780 | return decode_cb_op_status(xdr, OP_CB_OFFLOAD, &cb->cb_status); |
| 781 | } |
| 782 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | * RPC procedure tables |
| 784 | */ |
Chuck Lever | 7d93bd71 | 2010-12-14 14:57:42 +0000 | [diff] [blame] | 785 | #define PROC(proc, call, argtype, restype) \ |
| 786 | [NFSPROC4_CLNT_##proc] = { \ |
| 787 | .p_proc = NFSPROC4_CB_##call, \ |
Christoph Hellwig | 1502c81 | 2017-05-08 14:47:53 +0200 | [diff] [blame] | 788 | .p_encode = nfs4_xdr_enc_##argtype, \ |
Christoph Hellwig | d39916c | 2017-05-08 15:04:45 +0200 | [diff] [blame] | 789 | .p_decode = nfs4_xdr_dec_##restype, \ |
Chuck Lever | 7d93bd71 | 2010-12-14 14:57:42 +0000 | [diff] [blame] | 790 | .p_arglen = NFS4_enc_##argtype##_sz, \ |
| 791 | .p_replen = NFS4_dec_##restype##_sz, \ |
| 792 | .p_statidx = NFSPROC4_CB_##call, \ |
| 793 | .p_name = #proc, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | } |
| 795 | |
Christoph Hellwig | 499b498 | 2017-05-12 15:36:49 +0200 | [diff] [blame] | 796 | static const struct rpc_procinfo nfs4_cb_procedures[] = { |
Chuck Lever | 7d93bd71 | 2010-12-14 14:57:42 +0000 | [diff] [blame] | 797 | PROC(CB_NULL, NULL, cb_null, cb_null), |
| 798 | PROC(CB_RECALL, COMPOUND, cb_recall, cb_recall), |
Christoph Hellwig | c5c707f | 2014-09-23 12:38:48 +0200 | [diff] [blame] | 799 | #ifdef CONFIG_NFSD_PNFS |
| 800 | PROC(CB_LAYOUT, COMPOUND, cb_layout, cb_layout), |
| 801 | #endif |
Jeff Layton | a188620e | 2016-09-16 16:28:23 -0400 | [diff] [blame] | 802 | PROC(CB_NOTIFY_LOCK, COMPOUND, cb_notify_lock, cb_notify_lock), |
Olga Kornievskaia | 9eb190fca8f | 2018-07-20 18:19:17 -0400 | [diff] [blame] | 803 | PROC(CB_OFFLOAD, COMPOUND, cb_offload, cb_offload), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | }; |
| 805 | |
Christoph Hellwig | 1c5876d | 2017-05-08 23:27:10 +0200 | [diff] [blame] | 806 | static unsigned int nfs4_cb_counts[ARRAY_SIZE(nfs4_cb_procedures)]; |
Christoph Hellwig | 02be49f | 2017-05-12 15:58:06 +0200 | [diff] [blame] | 807 | static const struct rpc_version nfs_cb_version4 = { |
J. Bruce Fields | b7299f4 | 2010-05-14 17:57:35 -0400 | [diff] [blame] | 808 | /* |
| 809 | * Note on the callback rpc program version number: despite language in rfc |
| 810 | * 5661 section 18.36.3 requiring servers to use 4 in this field, the |
| 811 | * official xdr descriptions for both 4.0 and 4.1 specify version 1, and |
| 812 | * in practice that appears to be what implementations use. The section |
| 813 | * 18.36.3 language is expected to be fixed in an erratum. |
| 814 | */ |
Chuck Lever | 7d93bd71 | 2010-12-14 14:57:42 +0000 | [diff] [blame] | 815 | .number = 1, |
| 816 | .nrprocs = ARRAY_SIZE(nfs4_cb_procedures), |
Christoph Hellwig | 1c5876d | 2017-05-08 23:27:10 +0200 | [diff] [blame] | 817 | .procs = nfs4_cb_procedures, |
| 818 | .counts = nfs4_cb_counts, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | }; |
| 820 | |
Trond Myklebust | eff7936 | 2017-07-16 22:57:27 +0000 | [diff] [blame] | 821 | static const struct rpc_version *nfs_cb_version[2] = { |
| 822 | [1] = &nfs_cb_version4, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | }; |
| 824 | |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 825 | static const struct rpc_program cb_program; |
Olga Kornievskaia | ff7d975 | 2008-03-28 16:04:56 -0400 | [diff] [blame] | 826 | |
| 827 | static struct rpc_stat cb_stats = { |
Chuck Lever | 7d93bd71 | 2010-12-14 14:57:42 +0000 | [diff] [blame] | 828 | .program = &cb_program |
Olga Kornievskaia | ff7d975 | 2008-03-28 16:04:56 -0400 | [diff] [blame] | 829 | }; |
| 830 | |
| 831 | #define NFS4_CALLBACK 0x40000000 |
Trond Myklebust | a613fa1 | 2012-01-20 13:53:56 -0500 | [diff] [blame] | 832 | static const struct rpc_program cb_program = { |
Chuck Lever | 7d93bd71 | 2010-12-14 14:57:42 +0000 | [diff] [blame] | 833 | .name = "nfs4_cb", |
| 834 | .number = NFS4_CALLBACK, |
| 835 | .nrvers = ARRAY_SIZE(nfs_cb_version), |
| 836 | .version = nfs_cb_version, |
| 837 | .stats = &cb_stats, |
Stanislav Kinsbursky | 0157d02 | 2012-01-11 19:18:01 +0400 | [diff] [blame] | 838 | .pipe_dir_name = "nfsd4_cb", |
Olga Kornievskaia | ff7d975 | 2008-03-28 16:04:56 -0400 | [diff] [blame] | 839 | }; |
| 840 | |
Stanislav Kinsbursky | 3d73371 | 2012-11-27 14:11:44 +0300 | [diff] [blame] | 841 | static int max_cb_time(struct net *net) |
J. Bruce Fields | 595947a | 2009-03-05 17:18:10 -0500 | [diff] [blame] | 842 | { |
Stanislav Kinsbursky | 3d73371 | 2012-11-27 14:11:44 +0300 | [diff] [blame] | 843 | struct nfsd_net *nn = net_generic(net, nfsd_net_id); |
| 844 | return max(nn->nfsd4_lease/10, (time_t)1) * HZ; |
J. Bruce Fields | 595947a | 2009-03-05 17:18:10 -0500 | [diff] [blame] | 845 | } |
| 846 | |
Fengguang Wu | 2b4cf66 | 2012-11-13 15:41:27 -0500 | [diff] [blame] | 847 | static struct rpc_cred *get_backchannel_cred(struct nfs4_client *clp, struct rpc_clnt *client, struct nfsd4_session *ses) |
J. Bruce Fields | c6bb3ca | 2012-11-01 16:31:02 -0400 | [diff] [blame] | 848 | { |
| 849 | if (clp->cl_minorversion == 0) { |
NeilBrown | 5e16923 | 2018-12-03 11:30:30 +1100 | [diff] [blame^] | 850 | client->cl_principal = clp->cl_cred.cr_targ_princ ? |
| 851 | clp->cl_cred.cr_targ_princ : "nfs"; |
Chuck Lever | cb25e7b | 2018-08-16 12:06:04 -0400 | [diff] [blame] | 852 | |
NeilBrown | 5e16923 | 2018-12-03 11:30:30 +1100 | [diff] [blame^] | 853 | return get_rpccred(rpc_machine_cred()); |
J. Bruce Fields | c6bb3ca | 2012-11-01 16:31:02 -0400 | [diff] [blame] | 854 | } else { |
| 855 | struct rpc_auth *auth = client->cl_auth; |
| 856 | struct auth_cred acred = {}; |
NeilBrown | 97f68c6b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 857 | struct cred *kcred; |
| 858 | struct rpc_cred *ret; |
| 859 | |
| 860 | kcred = prepare_kernel_cred(NULL); |
| 861 | if (!kcred) |
| 862 | return NULL; |
J. Bruce Fields | c6bb3ca | 2012-11-01 16:31:02 -0400 | [diff] [blame] | 863 | |
NeilBrown | 8276c90 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 864 | kcred->uid = ses->se_cb_sec.uid; |
| 865 | kcred->gid = ses->se_cb_sec.gid; |
NeilBrown | 97f68c6b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 866 | acred.cred = kcred; |
| 867 | ret = auth->au_ops->lookup_cred(client->cl_auth, &acred, 0); |
| 868 | put_cred(kcred); |
| 869 | return ret; |
J. Bruce Fields | c6bb3ca | 2012-11-01 16:31:02 -0400 | [diff] [blame] | 870 | } |
| 871 | } |
J. Bruce Fields | 2b47eec | 2007-07-27 18:06:50 -0400 | [diff] [blame] | 872 | |
J. Bruce Fields | dcbeaa6 | 2010-06-15 17:25:45 -0400 | [diff] [blame] | 873 | static int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *conn, struct nfsd4_session *ses) |
J. Bruce Fields | 2b47eec | 2007-07-27 18:06:50 -0400 | [diff] [blame] | 874 | { |
Jeff Layton | 3758cf7 | 2014-04-15 08:51:48 -0400 | [diff] [blame] | 875 | int maxtime = max_cb_time(clp->net); |
Chuck Lever | ae5c794 | 2006-08-22 20:06:21 -0400 | [diff] [blame] | 876 | struct rpc_timeout timeparms = { |
Jeff Layton | 3758cf7 | 2014-04-15 08:51:48 -0400 | [diff] [blame] | 877 | .to_initval = maxtime, |
J. Bruce Fields | 595947a | 2009-03-05 17:18:10 -0500 | [diff] [blame] | 878 | .to_retries = 0, |
Jeff Layton | 3758cf7 | 2014-04-15 08:51:48 -0400 | [diff] [blame] | 879 | .to_maxval = maxtime, |
Chuck Lever | ae5c794 | 2006-08-22 20:06:21 -0400 | [diff] [blame] | 880 | }; |
Chuck Lever | ae5c794 | 2006-08-22 20:06:21 -0400 | [diff] [blame] | 881 | struct rpc_create_args args = { |
Stanislav Kinsbursky | c212cec | 2012-11-14 18:21:10 +0300 | [diff] [blame] | 882 | .net = clp->net, |
J. Bruce Fields | 07263f1 | 2010-05-31 19:09:40 -0400 | [diff] [blame] | 883 | .address = (struct sockaddr *) &conn->cb_addr, |
| 884 | .addrsize = conn->cb_addrlen, |
Takuma Umeya | 6f3d772 | 2010-12-15 14:09:01 +0900 | [diff] [blame] | 885 | .saddress = (struct sockaddr *) &conn->cb_saddr, |
Chuck Lever | ae5c794 | 2006-08-22 20:06:21 -0400 | [diff] [blame] | 886 | .timeout = &timeparms, |
Olga Kornievskaia | ff7d975 | 2008-03-28 16:04:56 -0400 | [diff] [blame] | 887 | .program = &cb_program, |
Trond Myklebust | eff7936 | 2017-07-16 22:57:27 +0000 | [diff] [blame] | 888 | .version = 1, |
Olga Kornievskaia | b6b6152 | 2008-06-09 16:51:31 -0400 | [diff] [blame] | 889 | .flags = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET), |
Chuck Lever | ae5c794 | 2006-08-22 20:06:21 -0400 | [diff] [blame] | 890 | }; |
J. Bruce Fields | 63c8671 | 2007-10-25 19:00:26 -0400 | [diff] [blame] | 891 | struct rpc_clnt *client; |
J. Bruce Fields | c6bb3ca | 2012-11-01 16:31:02 -0400 | [diff] [blame] | 892 | struct rpc_cred *cred; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | |
J. Bruce Fields | 5d18c1c | 2010-10-19 23:00:12 -0400 | [diff] [blame] | 894 | if (clp->cl_minorversion == 0) { |
J. Bruce Fields | 03a4e1f | 2012-05-14 19:55:22 -0400 | [diff] [blame] | 895 | if (!clp->cl_cred.cr_principal && |
J. Bruce Fields | 3930765 | 2012-08-16 17:01:21 -0400 | [diff] [blame] | 896 | (clp->cl_cred.cr_flavor >= RPC_AUTH_GSS_KRB5)) |
J. Bruce Fields | 5d18c1c | 2010-10-19 23:00:12 -0400 | [diff] [blame] | 897 | return -EINVAL; |
J. Bruce Fields | 03a4e1f | 2012-05-14 19:55:22 -0400 | [diff] [blame] | 898 | args.client_name = clp->cl_cred.cr_principal; |
Himangi Saraogi | fc8e5a6 | 2014-07-23 20:12:31 +0530 | [diff] [blame] | 899 | args.prognumber = conn->cb_prog; |
J. Bruce Fields | 5d18c1c | 2010-10-19 23:00:12 -0400 | [diff] [blame] | 900 | args.protocol = XPRT_TRANSPORT_TCP; |
J. Bruce Fields | 3930765 | 2012-08-16 17:01:21 -0400 | [diff] [blame] | 901 | args.authflavor = clp->cl_cred.cr_flavor; |
J. Bruce Fields | 5d18c1c | 2010-10-19 23:00:12 -0400 | [diff] [blame] | 902 | clp->cl_cb_ident = conn->cb_ident; |
| 903 | } else { |
J. Bruce Fields | dcbeaa6 | 2010-06-15 17:25:45 -0400 | [diff] [blame] | 904 | if (!conn->cb_xprt) |
| 905 | return -EINVAL; |
| 906 | clp->cl_cb_conn.cb_xprt = conn->cb_xprt; |
| 907 | clp->cl_cb_session = ses; |
J. Bruce Fields | 07263f1 | 2010-05-31 19:09:40 -0400 | [diff] [blame] | 908 | args.bc_xprt = conn->cb_xprt; |
J. Bruce Fields | 8b5ce5c | 2010-10-19 17:31:50 -0400 | [diff] [blame] | 909 | args.prognumber = clp->cl_cb_session->se_cb_prog; |
Chuck Lever | 3c45ddf | 2014-07-16 15:38:32 -0400 | [diff] [blame] | 910 | args.protocol = conn->cb_xprt->xpt_class->xcl_ident | |
| 911 | XPRT_TRANSPORT_BC; |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 912 | args.authflavor = ses->se_cb_sec.flavor; |
Alexandros Batsakis | 3ddc8bf | 2009-09-10 12:27:21 +0300 | [diff] [blame] | 913 | } |
Chuck Lever | ae5c794 | 2006-08-22 20:06:21 -0400 | [diff] [blame] | 914 | /* Create RPC client */ |
J. Bruce Fields | d50039e | 2016-05-16 17:03:42 -0400 | [diff] [blame] | 915 | client = rpc_create(&args); |
J. Bruce Fields | e1cab5a5 | 2009-02-23 10:45:27 -0800 | [diff] [blame] | 916 | if (IS_ERR(client)) { |
J. Bruce Fields | a601cae | 2009-02-22 16:43:45 -0800 | [diff] [blame] | 917 | dprintk("NFSD: couldn't create callback client: %ld\n", |
| 918 | PTR_ERR(client)); |
J. Bruce Fields | e1cab5a5 | 2009-02-23 10:45:27 -0800 | [diff] [blame] | 919 | return PTR_ERR(client); |
| 920 | } |
J. Bruce Fields | c6bb3ca | 2012-11-01 16:31:02 -0400 | [diff] [blame] | 921 | cred = get_backchannel_cred(clp, client, ses); |
| 922 | if (IS_ERR(cred)) { |
| 923 | rpc_shutdown_client(client); |
| 924 | return PTR_ERR(cred); |
| 925 | } |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 926 | clp->cl_cb_client = client; |
J. Bruce Fields | c6bb3ca | 2012-11-01 16:31:02 -0400 | [diff] [blame] | 927 | clp->cl_cb_cred = cred; |
J. Bruce Fields | e1cab5a5 | 2009-02-23 10:45:27 -0800 | [diff] [blame] | 928 | return 0; |
J. Bruce Fields | a601cae | 2009-02-22 16:43:45 -0800 | [diff] [blame] | 929 | } |
| 930 | |
J. Bruce Fields | ecdd03b | 2009-02-23 19:35:22 -0800 | [diff] [blame] | 931 | static void warn_no_callback_path(struct nfs4_client *clp, int reason) |
| 932 | { |
| 933 | dprintk("NFSD: warning: no callback path to client %.*s: error %d\n", |
| 934 | (int)clp->cl_name.len, clp->cl_name.data, reason); |
| 935 | } |
| 936 | |
J. Bruce Fields | 77a3569 | 2010-04-30 18:51:44 -0400 | [diff] [blame] | 937 | static void nfsd4_mark_cb_down(struct nfs4_client *clp, int reason) |
| 938 | { |
J. Bruce Fields | d4f72cb | 2015-11-24 15:43:03 -0700 | [diff] [blame] | 939 | if (test_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_flags)) |
| 940 | return; |
J. Bruce Fields | 77a3569 | 2010-04-30 18:51:44 -0400 | [diff] [blame] | 941 | clp->cl_cb_state = NFSD4_CB_DOWN; |
| 942 | warn_no_callback_path(clp, reason); |
| 943 | } |
| 944 | |
Benny Halevy | 5423732 | 2011-10-19 19:12:58 -0700 | [diff] [blame] | 945 | static void nfsd4_mark_cb_fault(struct nfs4_client *clp, int reason) |
| 946 | { |
J. Bruce Fields | d4f72cb | 2015-11-24 15:43:03 -0700 | [diff] [blame] | 947 | if (test_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_flags)) |
| 948 | return; |
Benny Halevy | 5423732 | 2011-10-19 19:12:58 -0700 | [diff] [blame] | 949 | clp->cl_cb_state = NFSD4_CB_FAULT; |
| 950 | warn_no_callback_path(clp, reason); |
| 951 | } |
| 952 | |
J. Bruce Fields | e300a63 | 2009-03-05 15:01:11 -0500 | [diff] [blame] | 953 | static void nfsd4_cb_probe_done(struct rpc_task *task, void *calldata) |
| 954 | { |
J. Bruce Fields | cee277d | 2010-05-26 17:52:14 -0400 | [diff] [blame] | 955 | struct nfs4_client *clp = container_of(calldata, struct nfs4_client, cl_cb_null); |
J. Bruce Fields | e300a63 | 2009-03-05 15:01:11 -0500 | [diff] [blame] | 956 | |
| 957 | if (task->tk_status) |
J. Bruce Fields | 77a3569 | 2010-04-30 18:51:44 -0400 | [diff] [blame] | 958 | nfsd4_mark_cb_down(clp, task->tk_status); |
J. Bruce Fields | e300a63 | 2009-03-05 15:01:11 -0500 | [diff] [blame] | 959 | else |
J. Bruce Fields | 77a3569 | 2010-04-30 18:51:44 -0400 | [diff] [blame] | 960 | clp->cl_cb_state = NFSD4_CB_UP; |
J. Bruce Fields | e300a63 | 2009-03-05 15:01:11 -0500 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | static const struct rpc_call_ops nfsd4_cb_probe_ops = { |
J. Bruce Fields | cee277d | 2010-05-26 17:52:14 -0400 | [diff] [blame] | 964 | /* XXX: release method to ensure we set the cb channel down if |
| 965 | * necessary on early failure? */ |
J. Bruce Fields | e300a63 | 2009-03-05 15:01:11 -0500 | [diff] [blame] | 966 | .rpc_call_done = nfsd4_cb_probe_done, |
| 967 | }; |
| 968 | |
J. Bruce Fields | cee277d | 2010-05-26 17:52:14 -0400 | [diff] [blame] | 969 | static struct workqueue_struct *callback_wq; |
J. Bruce Fields | 80fc015 | 2009-09-15 18:07:35 -0400 | [diff] [blame] | 970 | |
J. Bruce Fields | 63c8671 | 2007-10-25 19:00:26 -0400 | [diff] [blame] | 971 | /* |
J. Bruce Fields | 5a3c9d7 | 2010-10-19 17:56:52 -0400 | [diff] [blame] | 972 | * Poke the callback thread to process any updates to the callback |
| 973 | * parameters, and send a null probe. |
J. Bruce Fields | 63c8671 | 2007-10-25 19:00:26 -0400 | [diff] [blame] | 974 | */ |
J. Bruce Fields | 5a3c9d7 | 2010-10-19 17:56:52 -0400 | [diff] [blame] | 975 | void nfsd4_probe_callback(struct nfs4_client *clp) |
| 976 | { |
J. Bruce Fields | 77a3569 | 2010-04-30 18:51:44 -0400 | [diff] [blame] | 977 | clp->cl_cb_state = NFSD4_CB_UNKNOWN; |
Jeff Layton | a52d726 | 2012-03-21 09:52:02 -0400 | [diff] [blame] | 978 | set_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_flags); |
Christoph Hellwig | f0b5de1 | 2014-09-24 12:19:18 +0200 | [diff] [blame] | 979 | nfsd4_run_cb(&clp->cl_cb_null); |
J. Bruce Fields | 5a3c9d7 | 2010-10-19 17:56:52 -0400 | [diff] [blame] | 980 | } |
| 981 | |
J. Bruce Fields | 84f5f7c | 2010-12-09 15:52:19 -0500 | [diff] [blame] | 982 | void nfsd4_probe_callback_sync(struct nfs4_client *clp) |
| 983 | { |
| 984 | nfsd4_probe_callback(clp); |
| 985 | flush_workqueue(callback_wq); |
| 986 | } |
| 987 | |
J. Bruce Fields | 5a3c9d7 | 2010-10-19 17:56:52 -0400 | [diff] [blame] | 988 | void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *conn) |
J. Bruce Fields | 63c8671 | 2007-10-25 19:00:26 -0400 | [diff] [blame] | 989 | { |
J. Bruce Fields | 77a3569 | 2010-04-30 18:51:44 -0400 | [diff] [blame] | 990 | clp->cl_cb_state = NFSD4_CB_UNKNOWN; |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 991 | spin_lock(&clp->cl_lock); |
| 992 | memcpy(&clp->cl_cb_conn, conn, sizeof(struct nfs4_cb_conn)); |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 993 | spin_unlock(&clp->cl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | } |
| 995 | |
Ricardo Labiaga | 2a1d1b5 | 2009-09-10 12:26:38 +0300 | [diff] [blame] | 996 | /* |
| 997 | * There's currently a single callback channel slot. |
| 998 | * If the slot is available, then mark it busy. Otherwise, set the |
| 999 | * thread for sleeping on the callback RPC wait queue. |
| 1000 | */ |
J. Bruce Fields | 3ff3600 | 2011-01-10 16:37:51 -0500 | [diff] [blame] | 1001 | static bool nfsd41_cb_get_slot(struct nfs4_client *clp, struct rpc_task *task) |
Ricardo Labiaga | 2a1d1b5 | 2009-09-10 12:26:38 +0300 | [diff] [blame] | 1002 | { |
Ricardo Labiaga | 2a1d1b5 | 2009-09-10 12:26:38 +0300 | [diff] [blame] | 1003 | if (test_and_set_bit(0, &clp->cl_cb_slot_busy) != 0) { |
| 1004 | rpc_sleep_on(&clp->cl_cb_waitq, task, NULL); |
Trond Myklebust | c6c15e1 | 2014-11-19 12:47:50 -0500 | [diff] [blame] | 1005 | /* Race breaker */ |
| 1006 | if (test_and_set_bit(0, &clp->cl_cb_slot_busy) != 0) { |
| 1007 | dprintk("%s slot is busy\n", __func__); |
| 1008 | return false; |
| 1009 | } |
| 1010 | rpc_wake_up_queued_task(&clp->cl_cb_waitq, task); |
Ricardo Labiaga | 2a1d1b5 | 2009-09-10 12:26:38 +0300 | [diff] [blame] | 1011 | } |
J. Bruce Fields | 3ff3600 | 2011-01-10 16:37:51 -0500 | [diff] [blame] | 1012 | return true; |
Ricardo Labiaga | 2a1d1b5 | 2009-09-10 12:26:38 +0300 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | /* |
| 1016 | * TODO: cb_sequence should support referring call lists, cachethis, multiple |
| 1017 | * slots, and mark callback channel down on communication errors. |
| 1018 | */ |
| 1019 | static void nfsd4_cb_prepare(struct rpc_task *task, void *calldata) |
| 1020 | { |
J. Bruce Fields | 5878453 | 2010-05-16 16:47:08 -0400 | [diff] [blame] | 1021 | struct nfsd4_callback *cb = calldata; |
J. Bruce Fields | 8be2d23 | 2013-03-21 10:59:29 -0400 | [diff] [blame] | 1022 | struct nfs4_client *clp = cb->cb_clp; |
J. Bruce Fields | 8323c3b | 2010-10-19 19:36:51 -0400 | [diff] [blame] | 1023 | u32 minorversion = clp->cl_minorversion; |
Ricardo Labiaga | 2a1d1b5 | 2009-09-10 12:26:38 +0300 | [diff] [blame] | 1024 | |
Kinglong Mee | 7ba6cad | 2015-06-24 16:33:37 +0800 | [diff] [blame] | 1025 | /* |
| 1026 | * cb_seq_status is only set in decode_cb_sequence4res, |
| 1027 | * and so will remain 1 if an rpc level failure occurs. |
| 1028 | */ |
| 1029 | cb->cb_seq_status = 1; |
Kinglong Mee | 4399396 | 2015-06-02 18:59:19 +0800 | [diff] [blame] | 1030 | cb->cb_status = 0; |
Ricardo Labiaga | 2a1d1b5 | 2009-09-10 12:26:38 +0300 | [diff] [blame] | 1031 | if (minorversion) { |
J. Bruce Fields | 3ff3600 | 2011-01-10 16:37:51 -0500 | [diff] [blame] | 1032 | if (!nfsd41_cb_get_slot(clp, task)) |
Ricardo Labiaga | 2a1d1b5 | 2009-09-10 12:26:38 +0300 | [diff] [blame] | 1033 | return; |
Ricardo Labiaga | 2a1d1b5 | 2009-09-10 12:26:38 +0300 | [diff] [blame] | 1034 | } |
| 1035 | rpc_call_start(task); |
| 1036 | } |
| 1037 | |
Kinglong Mee | 7ba6cad | 2015-06-24 16:33:37 +0800 | [diff] [blame] | 1038 | static bool nfsd4_cb_sequence_done(struct rpc_task *task, struct nfsd4_callback *cb) |
| 1039 | { |
| 1040 | struct nfs4_client *clp = cb->cb_clp; |
| 1041 | struct nfsd4_session *session = clp->cl_cb_session; |
| 1042 | bool ret = true; |
| 1043 | |
| 1044 | if (!clp->cl_minorversion) { |
| 1045 | /* |
| 1046 | * If the backchannel connection was shut down while this |
| 1047 | * task was queued, we need to resubmit it after setting up |
| 1048 | * a new backchannel connection. |
| 1049 | * |
| 1050 | * Note that if we lost our callback connection permanently |
| 1051 | * the submission code will error out, so we don't need to |
| 1052 | * handle that case here. |
| 1053 | */ |
| 1054 | if (task->tk_flags & RPC_TASK_KILLED) |
| 1055 | goto need_restart; |
| 1056 | |
| 1057 | return true; |
| 1058 | } |
| 1059 | |
| 1060 | switch (cb->cb_seq_status) { |
| 1061 | case 0: |
| 1062 | /* |
| 1063 | * No need for lock, access serialized in nfsd4_cb_prepare |
| 1064 | * |
| 1065 | * RFC5661 20.9.3 |
| 1066 | * If CB_SEQUENCE returns an error, then the state of the slot |
| 1067 | * (sequence ID, cached reply) MUST NOT change. |
| 1068 | */ |
| 1069 | ++session->se_cb_seq_nr; |
| 1070 | break; |
| 1071 | case -ESERVERFAULT: |
| 1072 | ++session->se_cb_seq_nr; |
Gustavo A. R. Silva | 7b4d6da | 2018-07-31 21:24:10 -0500 | [diff] [blame] | 1073 | /* Fall through */ |
Kinglong Mee | 7ba6cad | 2015-06-24 16:33:37 +0800 | [diff] [blame] | 1074 | case 1: |
| 1075 | case -NFS4ERR_BADSESSION: |
| 1076 | nfsd4_mark_cb_fault(cb->cb_clp, cb->cb_seq_status); |
| 1077 | ret = false; |
| 1078 | break; |
| 1079 | case -NFS4ERR_DELAY: |
| 1080 | if (!rpc_restart_call(task)) |
| 1081 | goto out; |
| 1082 | |
| 1083 | rpc_delay(task, 2 * HZ); |
| 1084 | return false; |
| 1085 | case -NFS4ERR_BADSLOT: |
| 1086 | goto retry_nowait; |
| 1087 | case -NFS4ERR_SEQ_MISORDERED: |
| 1088 | if (session->se_cb_seq_nr != 1) { |
| 1089 | session->se_cb_seq_nr = 1; |
| 1090 | goto retry_nowait; |
| 1091 | } |
| 1092 | break; |
| 1093 | default: |
| 1094 | dprintk("%s: unprocessed error %d\n", __func__, |
| 1095 | cb->cb_seq_status); |
| 1096 | } |
| 1097 | |
| 1098 | clear_bit(0, &clp->cl_cb_slot_busy); |
| 1099 | rpc_wake_up_next(&clp->cl_cb_waitq); |
| 1100 | dprintk("%s: freed slot, new seqid=%d\n", __func__, |
| 1101 | clp->cl_cb_session->se_cb_seq_nr); |
| 1102 | |
| 1103 | if (task->tk_flags & RPC_TASK_KILLED) |
| 1104 | goto need_restart; |
| 1105 | out: |
| 1106 | return ret; |
| 1107 | retry_nowait: |
| 1108 | if (rpc_restart_call_prepare(task)) |
| 1109 | ret = false; |
| 1110 | goto out; |
| 1111 | need_restart: |
| 1112 | task->tk_status = 0; |
| 1113 | cb->cb_need_restart = true; |
| 1114 | return false; |
| 1115 | } |
| 1116 | |
Ricardo Labiaga | 0421b5c | 2009-09-10 12:27:04 +0300 | [diff] [blame] | 1117 | static void nfsd4_cb_done(struct rpc_task *task, void *calldata) |
| 1118 | { |
J. Bruce Fields | 5878453 | 2010-05-16 16:47:08 -0400 | [diff] [blame] | 1119 | struct nfsd4_callback *cb = calldata; |
J. Bruce Fields | 8be2d23 | 2013-03-21 10:59:29 -0400 | [diff] [blame] | 1120 | struct nfs4_client *clp = cb->cb_clp; |
Ricardo Labiaga | 0421b5c | 2009-09-10 12:27:04 +0300 | [diff] [blame] | 1121 | |
| 1122 | dprintk("%s: minorversion=%d\n", __func__, |
J. Bruce Fields | 8323c3b | 2010-10-19 19:36:51 -0400 | [diff] [blame] | 1123 | clp->cl_minorversion); |
Ricardo Labiaga | 0421b5c | 2009-09-10 12:27:04 +0300 | [diff] [blame] | 1124 | |
Kinglong Mee | 7ba6cad | 2015-06-24 16:33:37 +0800 | [diff] [blame] | 1125 | if (!nfsd4_cb_sequence_done(task, cb)) |
J. Bruce Fields | 4b21d0d | 2010-03-07 23:39:01 -0500 | [diff] [blame] | 1126 | return; |
J. Bruce Fields | 4b21d0d | 2010-03-07 23:39:01 -0500 | [diff] [blame] | 1127 | |
Christoph Hellwig | ef2a1b3 | 2015-04-30 11:49:23 +0200 | [diff] [blame] | 1128 | if (cb->cb_status) { |
| 1129 | WARN_ON_ONCE(task->tk_status); |
| 1130 | task->tk_status = cb->cb_status; |
| 1131 | } |
| 1132 | |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1133 | switch (cb->cb_ops->done(cb, task)) { |
J. Bruce Fields | 172c85d | 2010-05-30 11:53:12 -0400 | [diff] [blame] | 1134 | case 0: |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1135 | task->tk_status = 0; |
| 1136 | rpc_restart_call_prepare(task); |
| 1137 | return; |
| 1138 | case 1: |
Christoph Hellwig | 444b6e9 | 2014-09-23 08:58:48 +0200 | [diff] [blame] | 1139 | break; |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1140 | case -1: |
J. Bruce Fields | 63e4863 | 2009-05-01 22:36:55 -0400 | [diff] [blame] | 1141 | /* Network partition? */ |
J. Bruce Fields | 77a3569 | 2010-04-30 18:51:44 -0400 | [diff] [blame] | 1142 | nfsd4_mark_cb_down(clp, task->tk_status); |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1143 | break; |
| 1144 | default: |
| 1145 | BUG(); |
J. Bruce Fields | 63e4863 | 2009-05-01 22:36:55 -0400 | [diff] [blame] | 1146 | } |
J. Bruce Fields | 63e4863 | 2009-05-01 22:36:55 -0400 | [diff] [blame] | 1147 | } |
| 1148 | |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1149 | static void nfsd4_cb_release(void *calldata) |
J. Bruce Fields | 63e4863 | 2009-05-01 22:36:55 -0400 | [diff] [blame] | 1150 | { |
J. Bruce Fields | 5878453 | 2010-05-16 16:47:08 -0400 | [diff] [blame] | 1151 | struct nfsd4_callback *cb = calldata; |
J. Bruce Fields | 63e4863 | 2009-05-01 22:36:55 -0400 | [diff] [blame] | 1152 | |
Christoph Hellwig | cba5f62 | 2015-04-30 11:49:24 +0200 | [diff] [blame] | 1153 | if (cb->cb_need_restart) |
| 1154 | nfsd4_run_cb(cb); |
| 1155 | else |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1156 | cb->cb_ops->release(cb); |
Christoph Hellwig | cba5f62 | 2015-04-30 11:49:24 +0200 | [diff] [blame] | 1157 | |
J. Bruce Fields | 63e4863 | 2009-05-01 22:36:55 -0400 | [diff] [blame] | 1158 | } |
| 1159 | |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1160 | static const struct rpc_call_ops nfsd4_cb_ops = { |
Ricardo Labiaga | 2a1d1b5 | 2009-09-10 12:26:38 +0300 | [diff] [blame] | 1161 | .rpc_call_prepare = nfsd4_cb_prepare, |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1162 | .rpc_call_done = nfsd4_cb_done, |
| 1163 | .rpc_release = nfsd4_cb_release, |
J. Bruce Fields | 63e4863 | 2009-05-01 22:36:55 -0400 | [diff] [blame] | 1164 | }; |
| 1165 | |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 1166 | int nfsd4_create_callback_queue(void) |
| 1167 | { |
J. Bruce Fields | 8838203 | 2016-11-14 11:13:43 -0500 | [diff] [blame] | 1168 | callback_wq = alloc_ordered_workqueue("nfsd4_callbacks", 0); |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 1169 | if (!callback_wq) |
| 1170 | return -ENOMEM; |
| 1171 | return 0; |
| 1172 | } |
| 1173 | |
| 1174 | void nfsd4_destroy_callback_queue(void) |
| 1175 | { |
| 1176 | destroy_workqueue(callback_wq); |
| 1177 | } |
| 1178 | |
Benny Halevy | ab707e15 | 2010-05-12 00:14:06 +0300 | [diff] [blame] | 1179 | /* must be called under the state lock */ |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1180 | void nfsd4_shutdown_callback(struct nfs4_client *clp) |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 1181 | { |
Jeff Layton | a52d726 | 2012-03-21 09:52:02 -0400 | [diff] [blame] | 1182 | set_bit(NFSD4_CLIENT_CB_KILL, &clp->cl_flags); |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 1183 | /* |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1184 | * Note this won't actually result in a null callback; |
Jeff Layton | 02e1215 | 2014-07-16 10:31:57 -0400 | [diff] [blame] | 1185 | * instead, nfsd4_run_cb_null() will detect the killed |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1186 | * client, destroy the rpc client, and stop: |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 1187 | */ |
Christoph Hellwig | f0b5de1 | 2014-09-24 12:19:18 +0200 | [diff] [blame] | 1188 | nfsd4_run_cb(&clp->cl_cb_null); |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 1189 | flush_workqueue(callback_wq); |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 1190 | } |
| 1191 | |
J. Bruce Fields | dcbeaa6 | 2010-06-15 17:25:45 -0400 | [diff] [blame] | 1192 | /* requires cl_lock: */ |
| 1193 | static struct nfsd4_conn * __nfsd4_find_backchannel(struct nfs4_client *clp) |
| 1194 | { |
| 1195 | struct nfsd4_session *s; |
| 1196 | struct nfsd4_conn *c; |
| 1197 | |
| 1198 | list_for_each_entry(s, &clp->cl_sessions, se_perclnt) { |
| 1199 | list_for_each_entry(c, &s->se_conns, cn_persession) { |
| 1200 | if (c->cn_flags & NFS4_CDFC4_BACK) |
| 1201 | return c; |
| 1202 | } |
| 1203 | } |
| 1204 | return NULL; |
| 1205 | } |
| 1206 | |
Kirill A. Shutemov | 65e4c89 | 2010-12-16 15:25:54 +0200 | [diff] [blame] | 1207 | static void nfsd4_process_cb_update(struct nfsd4_callback *cb) |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1208 | { |
| 1209 | struct nfs4_cb_conn conn; |
| 1210 | struct nfs4_client *clp = cb->cb_clp; |
J. Bruce Fields | dcbeaa6 | 2010-06-15 17:25:45 -0400 | [diff] [blame] | 1211 | struct nfsd4_session *ses = NULL; |
| 1212 | struct nfsd4_conn *c; |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1213 | int err; |
| 1214 | |
| 1215 | /* |
| 1216 | * This is either an update, or the client dying; in either case, |
| 1217 | * kill the old client: |
| 1218 | */ |
| 1219 | if (clp->cl_cb_client) { |
| 1220 | rpc_shutdown_client(clp->cl_cb_client); |
| 1221 | clp->cl_cb_client = NULL; |
J. Bruce Fields | c6bb3ca | 2012-11-01 16:31:02 -0400 | [diff] [blame] | 1222 | put_rpccred(clp->cl_cb_cred); |
| 1223 | clp->cl_cb_cred = NULL; |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1224 | } |
J. Bruce Fields | dcbeaa6 | 2010-06-15 17:25:45 -0400 | [diff] [blame] | 1225 | if (clp->cl_cb_conn.cb_xprt) { |
| 1226 | svc_xprt_put(clp->cl_cb_conn.cb_xprt); |
| 1227 | clp->cl_cb_conn.cb_xprt = NULL; |
| 1228 | } |
Jeff Layton | a52d726 | 2012-03-21 09:52:02 -0400 | [diff] [blame] | 1229 | if (test_bit(NFSD4_CLIENT_CB_KILL, &clp->cl_flags)) |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1230 | return; |
| 1231 | spin_lock(&clp->cl_lock); |
| 1232 | /* |
| 1233 | * Only serialized callback code is allowed to clear these |
| 1234 | * flags; main nfsd code can only set them: |
| 1235 | */ |
Jeff Layton | a52d726 | 2012-03-21 09:52:02 -0400 | [diff] [blame] | 1236 | BUG_ON(!(clp->cl_flags & NFSD4_CLIENT_CB_FLAG_MASK)); |
| 1237 | clear_bit(NFSD4_CLIENT_CB_UPDATE, &clp->cl_flags); |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1238 | memcpy(&conn, &cb->cb_clp->cl_cb_conn, sizeof(struct nfs4_cb_conn)); |
J. Bruce Fields | dcbeaa6 | 2010-06-15 17:25:45 -0400 | [diff] [blame] | 1239 | c = __nfsd4_find_backchannel(clp); |
| 1240 | if (c) { |
| 1241 | svc_xprt_get(c->cn_xprt); |
| 1242 | conn.cb_xprt = c->cn_xprt; |
| 1243 | ses = c->cn_session; |
| 1244 | } |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1245 | spin_unlock(&clp->cl_lock); |
| 1246 | |
J. Bruce Fields | dcbeaa6 | 2010-06-15 17:25:45 -0400 | [diff] [blame] | 1247 | err = setup_callback_client(clp, &conn, ses); |
J. Bruce Fields | 5ce8ba2 | 2011-01-10 16:44:41 -0500 | [diff] [blame] | 1248 | if (err) { |
J. Bruce Fields | 8546ee5 | 2012-03-09 17:02:28 -0500 | [diff] [blame] | 1249 | nfsd4_mark_cb_down(clp, err); |
J. Bruce Fields | 5ce8ba2 | 2011-01-10 16:44:41 -0500 | [diff] [blame] | 1250 | return; |
| 1251 | } |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1252 | } |
| 1253 | |
Jeff Layton | 02e1215 | 2014-07-16 10:31:57 -0400 | [diff] [blame] | 1254 | static void |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1255 | nfsd4_run_cb_work(struct work_struct *work) |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 1256 | { |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1257 | struct nfsd4_callback *cb = |
| 1258 | container_of(work, struct nfsd4_callback, cb_work); |
J. Bruce Fields | fb00392 | 2010-05-31 18:21:37 -0400 | [diff] [blame] | 1259 | struct nfs4_client *clp = cb->cb_clp; |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1260 | struct rpc_clnt *clnt; |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 1261 | |
Christoph Hellwig | cba5f62 | 2015-04-30 11:49:24 +0200 | [diff] [blame] | 1262 | if (cb->cb_need_restart) { |
| 1263 | cb->cb_need_restart = false; |
| 1264 | } else { |
| 1265 | if (cb->cb_ops && cb->cb_ops->prepare) |
| 1266 | cb->cb_ops->prepare(cb); |
| 1267 | } |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1268 | |
Jeff Layton | a52d726 | 2012-03-21 09:52:02 -0400 | [diff] [blame] | 1269 | if (clp->cl_flags & NFSD4_CLIENT_CB_FLAG_MASK) |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1270 | nfsd4_process_cb_update(cb); |
| 1271 | |
| 1272 | clnt = clp->cl_cb_client; |
| 1273 | if (!clnt) { |
| 1274 | /* Callback channel broken, or client killed; give up: */ |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1275 | if (cb->cb_ops && cb->cb_ops->release) |
| 1276 | cb->cb_ops->release(cb); |
J. Bruce Fields | 6ff8da0 | 2010-06-04 20:04:45 -0400 | [diff] [blame] | 1277 | return; |
J. Bruce Fields | 5878453 | 2010-05-16 16:47:08 -0400 | [diff] [blame] | 1278 | } |
Christoph Hellwig | 4bd9e9b | 2015-04-30 11:49:25 +0200 | [diff] [blame] | 1279 | |
| 1280 | /* |
| 1281 | * Don't send probe messages for 4.1 or later. |
| 1282 | */ |
| 1283 | if (!cb->cb_ops && clp->cl_minorversion) { |
| 1284 | clp->cl_cb_state = NFSD4_CB_UP; |
| 1285 | return; |
| 1286 | } |
| 1287 | |
J. Bruce Fields | c6bb3ca | 2012-11-01 16:31:02 -0400 | [diff] [blame] | 1288 | cb->cb_msg.rpc_cred = clp->cl_cb_cred; |
J. Bruce Fields | cee277d | 2010-05-26 17:52:14 -0400 | [diff] [blame] | 1289 | rpc_call_async(clnt, &cb->cb_msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN, |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1290 | cb->cb_ops ? &nfsd4_cb_ops : &nfsd4_cb_probe_ops, cb); |
Jeff Layton | 02e1215 | 2014-07-16 10:31:57 -0400 | [diff] [blame] | 1291 | } |
| 1292 | |
Christoph Hellwig | f0b5de1 | 2014-09-24 12:19:18 +0200 | [diff] [blame] | 1293 | void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp, |
Julia Lawall | c4cb897 | 2015-11-21 22:57:39 +0100 | [diff] [blame] | 1294 | const struct nfsd4_callback_ops *ops, enum nfsd4_cb_op op) |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 1295 | { |
J. Bruce Fields | 5ce8ba2 | 2011-01-10 16:44:41 -0500 | [diff] [blame] | 1296 | cb->cb_clp = clp; |
Christoph Hellwig | 326129d | 2014-09-24 12:19:17 +0200 | [diff] [blame] | 1297 | cb->cb_msg.rpc_proc = &nfs4_cb_procedures[op]; |
J. Bruce Fields | fb00392 | 2010-05-31 18:21:37 -0400 | [diff] [blame] | 1298 | cb->cb_msg.rpc_argp = cb; |
| 1299 | cb->cb_msg.rpc_resp = cb; |
Christoph Hellwig | 0162ac2 | 2014-09-24 12:19:19 +0200 | [diff] [blame] | 1300 | cb->cb_ops = ops; |
| 1301 | INIT_WORK(&cb->cb_work, nfsd4_run_cb_work); |
Kinglong Mee | 7ba6cad | 2015-06-24 16:33:37 +0800 | [diff] [blame] | 1302 | cb->cb_seq_status = 1; |
Christoph Hellwig | ef2a1b3 | 2015-04-30 11:49:23 +0200 | [diff] [blame] | 1303 | cb->cb_status = 0; |
Christoph Hellwig | cba5f62 | 2015-04-30 11:49:24 +0200 | [diff] [blame] | 1304 | cb->cb_need_restart = false; |
Christoph Hellwig | f0b5de1 | 2014-09-24 12:19:18 +0200 | [diff] [blame] | 1305 | } |
J. Bruce Fields | 5ce8ba2 | 2011-01-10 16:44:41 -0500 | [diff] [blame] | 1306 | |
Christoph Hellwig | f0b5de1 | 2014-09-24 12:19:18 +0200 | [diff] [blame] | 1307 | void nfsd4_run_cb(struct nfsd4_callback *cb) |
| 1308 | { |
Christoph Hellwig | 326129d | 2014-09-24 12:19:17 +0200 | [diff] [blame] | 1309 | queue_work(callback_wq, &cb->cb_work); |
J. Bruce Fields | b5a1a81 | 2010-03-03 14:52:55 -0500 | [diff] [blame] | 1310 | } |