Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/lockd/xdr.c |
| 4 | * |
| 5 | * XDR support for lockd and the lock client. |
| 6 | * |
| 7 | * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> |
| 8 | */ |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/types.h> |
| 11 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/nfs.h> |
| 13 | |
| 14 | #include <linux/sunrpc/xdr.h> |
| 15 | #include <linux/sunrpc/clnt.h> |
| 16 | #include <linux/sunrpc/svc.h> |
| 17 | #include <linux/sunrpc/stats.h> |
| 18 | #include <linux/lockd/lockd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Christoph Hellwig | 9c69de4 | 2014-05-06 19:37:13 +0200 | [diff] [blame] | 20 | #include <uapi/linux/nfs2.h> |
| 21 | |
Chuck Lever | cc1029b | 2021-06-03 16:50:58 -0400 | [diff] [blame] | 22 | #include "svcxdr.h" |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #define NLMDBG_FACILITY NLMDBG_XDR |
| 25 | |
| 26 | |
| 27 | static inline loff_t |
| 28 | s32_to_loff_t(__s32 offset) |
| 29 | { |
| 30 | return (loff_t)offset; |
| 31 | } |
| 32 | |
| 33 | static inline __s32 |
| 34 | loff_t_to_s32(loff_t offset) |
| 35 | { |
| 36 | __s32 res; |
| 37 | if (offset >= NLM_OFFSET_MAX) |
| 38 | res = NLM_OFFSET_MAX; |
| 39 | else if (offset <= -NLM_OFFSET_MAX) |
| 40 | res = -NLM_OFFSET_MAX; |
| 41 | else |
| 42 | res = offset; |
| 43 | return res; |
| 44 | } |
| 45 | |
| 46 | /* |
| 47 | * XDR functions for basic NLM types |
| 48 | */ |
Al Viro | 52921e0 | 2006-10-19 23:28:46 -0700 | [diff] [blame] | 49 | static __be32 *nlm_decode_cookie(__be32 *p, struct nlm_cookie *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
| 51 | unsigned int len; |
| 52 | |
| 53 | len = ntohl(*p++); |
| 54 | |
| 55 | if(len==0) |
| 56 | { |
| 57 | c->len=4; |
| 58 | memset(c->data, 0, 4); /* hockeypux brain damage */ |
| 59 | } |
| 60 | else if(len<=NLM_MAXCOOKIELEN) |
| 61 | { |
| 62 | c->len=len; |
| 63 | memcpy(c->data, p, len); |
| 64 | p+=XDR_QUADLEN(len); |
| 65 | } |
| 66 | else |
| 67 | { |
Chuck Lever | e159a08 | 2007-09-11 18:01:15 -0400 | [diff] [blame] | 68 | dprintk("lockd: bad cookie size %d (only cookies under " |
| 69 | "%d bytes are supported.)\n", |
| 70 | len, NLM_MAXCOOKIELEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | return NULL; |
| 72 | } |
| 73 | return p; |
| 74 | } |
| 75 | |
Al Viro | 52921e0 | 2006-10-19 23:28:46 -0700 | [diff] [blame] | 76 | static inline __be32 * |
| 77 | nlm_encode_cookie(__be32 *p, struct nlm_cookie *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | *p++ = htonl(c->len); |
| 80 | memcpy(p, c->data, c->len); |
| 81 | p+=XDR_QUADLEN(c->len); |
| 82 | return p; |
| 83 | } |
| 84 | |
Al Viro | 52921e0 | 2006-10-19 23:28:46 -0700 | [diff] [blame] | 85 | static __be32 * |
| 86 | nlm_decode_fh(__be32 *p, struct nfs_fh *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
| 88 | unsigned int len; |
| 89 | |
| 90 | if ((len = ntohl(*p++)) != NFS2_FHSIZE) { |
Chuck Lever | e159a08 | 2007-09-11 18:01:15 -0400 | [diff] [blame] | 91 | dprintk("lockd: bad fhandle size %d (should be %d)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | len, NFS2_FHSIZE); |
| 93 | return NULL; |
| 94 | } |
| 95 | f->size = NFS2_FHSIZE; |
| 96 | memset(f->data, 0, sizeof(f->data)); |
| 97 | memcpy(f->data, p, NFS2_FHSIZE); |
| 98 | return p + XDR_QUADLEN(NFS2_FHSIZE); |
| 99 | } |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | /* |
Chuck Lever | 2fd0c67 | 2021-06-03 16:51:04 -0400 | [diff] [blame] | 102 | * NLM file handles are defined by specification to be a variable-length |
| 103 | * XDR opaque no longer than 1024 bytes. However, this implementation |
| 104 | * constrains their length to exactly the length of an NFSv2 file |
| 105 | * handle. |
| 106 | */ |
| 107 | static bool |
| 108 | svcxdr_decode_fhandle(struct xdr_stream *xdr, struct nfs_fh *fh) |
| 109 | { |
| 110 | __be32 *p; |
| 111 | u32 len; |
| 112 | |
| 113 | if (xdr_stream_decode_u32(xdr, &len) < 0) |
| 114 | return false; |
| 115 | if (len != NFS2_FHSIZE) |
| 116 | return false; |
| 117 | |
| 118 | p = xdr_inline_decode(xdr, len); |
| 119 | if (!p) |
| 120 | return false; |
| 121 | fh->size = NFS2_FHSIZE; |
| 122 | memcpy(fh->data, p, len); |
| 123 | memset(fh->data + NFS2_FHSIZE, 0, sizeof(fh->data) - NFS2_FHSIZE); |
| 124 | |
| 125 | return true; |
| 126 | } |
| 127 | |
| 128 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | * Encode and decode owner handle |
| 130 | */ |
Al Viro | 52921e0 | 2006-10-19 23:28:46 -0700 | [diff] [blame] | 131 | static inline __be32 * |
| 132 | nlm_decode_oh(__be32 *p, struct xdr_netobj *oh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
| 134 | return xdr_decode_netobj(p, oh); |
| 135 | } |
| 136 | |
Al Viro | 52921e0 | 2006-10-19 23:28:46 -0700 | [diff] [blame] | 137 | static inline __be32 * |
| 138 | nlm_encode_oh(__be32 *p, struct xdr_netobj *oh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | { |
| 140 | return xdr_encode_netobj(p, oh); |
| 141 | } |
| 142 | |
Al Viro | 52921e0 | 2006-10-19 23:28:46 -0700 | [diff] [blame] | 143 | static __be32 * |
| 144 | nlm_decode_lock(__be32 *p, struct nlm_lock *lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
| 146 | struct file_lock *fl = &lock->fl; |
| 147 | s32 start, len, end; |
| 148 | |
| 149 | if (!(p = xdr_decode_string_inplace(p, &lock->caller, |
| 150 | &lock->len, |
| 151 | NLM_MAXSTRLEN)) |
| 152 | || !(p = nlm_decode_fh(p, &lock->fh)) |
| 153 | || !(p = nlm_decode_oh(p, &lock->oh))) |
| 154 | return NULL; |
Trond Myklebust | 7bab377 | 2006-03-20 13:44:06 -0500 | [diff] [blame] | 155 | lock->svid = ntohl(*p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | locks_init_lock(fl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | fl->fl_flags = FL_POSIX; |
| 159 | fl->fl_type = F_RDLCK; /* as good as anything else */ |
| 160 | start = ntohl(*p++); |
| 161 | len = ntohl(*p++); |
| 162 | end = start + len - 1; |
| 163 | |
| 164 | fl->fl_start = s32_to_loff_t(start); |
| 165 | |
| 166 | if (len == 0 || end < 0) |
| 167 | fl->fl_end = OFFSET_MAX; |
| 168 | else |
| 169 | fl->fl_end = s32_to_loff_t(end); |
| 170 | return p; |
| 171 | } |
| 172 | |
Chuck Lever | 2fd0c67 | 2021-06-03 16:51:04 -0400 | [diff] [blame] | 173 | static bool |
| 174 | svcxdr_decode_lock(struct xdr_stream *xdr, struct nlm_lock *lock) |
| 175 | { |
| 176 | struct file_lock *fl = &lock->fl; |
| 177 | s32 start, len, end; |
| 178 | |
| 179 | if (!svcxdr_decode_string(xdr, &lock->caller, &lock->len)) |
| 180 | return false; |
| 181 | if (!svcxdr_decode_fhandle(xdr, &lock->fh)) |
| 182 | return false; |
| 183 | if (!svcxdr_decode_owner(xdr, &lock->oh)) |
| 184 | return false; |
| 185 | if (xdr_stream_decode_u32(xdr, &lock->svid) < 0) |
| 186 | return false; |
| 187 | if (xdr_stream_decode_u32(xdr, &start) < 0) |
| 188 | return false; |
| 189 | if (xdr_stream_decode_u32(xdr, &len) < 0) |
| 190 | return false; |
| 191 | |
| 192 | locks_init_lock(fl); |
| 193 | fl->fl_flags = FL_POSIX; |
| 194 | fl->fl_type = F_RDLCK; |
| 195 | end = start + len - 1; |
| 196 | fl->fl_start = s32_to_loff_t(start); |
| 197 | if (len == 0 || end < 0) |
| 198 | fl->fl_end = OFFSET_MAX; |
| 199 | else |
| 200 | fl->fl_end = s32_to_loff_t(end); |
| 201 | |
| 202 | return true; |
| 203 | } |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | * Encode result of a TEST/TEST_MSG call |
| 207 | */ |
Al Viro | 52921e0 | 2006-10-19 23:28:46 -0700 | [diff] [blame] | 208 | static __be32 * |
| 209 | nlm_encode_testres(__be32 *p, struct nlm_res *resp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | { |
| 211 | s32 start, len; |
| 212 | |
| 213 | if (!(p = nlm_encode_cookie(p, &resp->cookie))) |
| 214 | return NULL; |
| 215 | *p++ = resp->status; |
| 216 | |
| 217 | if (resp->status == nlm_lck_denied) { |
| 218 | struct file_lock *fl = &resp->lock.fl; |
| 219 | |
| 220 | *p++ = (fl->fl_type == F_RDLCK)? xdr_zero : xdr_one; |
Trond Myklebust | 7bab377 | 2006-03-20 13:44:06 -0500 | [diff] [blame] | 221 | *p++ = htonl(resp->lock.svid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
| 223 | /* Encode owner handle. */ |
| 224 | if (!(p = xdr_encode_netobj(p, &resp->lock.oh))) |
| 225 | return NULL; |
| 226 | |
| 227 | start = loff_t_to_s32(fl->fl_start); |
| 228 | if (fl->fl_end == OFFSET_MAX) |
| 229 | len = 0; |
| 230 | else |
| 231 | len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1); |
| 232 | |
| 233 | *p++ = htonl(start); |
| 234 | *p++ = htonl(len); |
| 235 | } |
| 236 | |
| 237 | return p; |
| 238 | } |
| 239 | |
| 240 | |
| 241 | /* |
Chuck Lever | cc1029b | 2021-06-03 16:50:58 -0400 | [diff] [blame] | 242 | * Decode Call arguments |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | */ |
Chuck Lever | cc1029b | 2021-06-03 16:50:58 -0400 | [diff] [blame] | 244 | |
| 245 | int |
| 246 | nlmsvc_decode_void(struct svc_rqst *rqstp, __be32 *p) |
| 247 | { |
| 248 | return 1; |
| 249 | } |
| 250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 252 | nlmsvc_decode_testargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { |
Chuck Lever | 2fd0c67 | 2021-06-03 16:51:04 -0400 | [diff] [blame] | 254 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 255 | struct nlm_args *argp = rqstp->rq_argp; |
Chuck Lever | 2fd0c67 | 2021-06-03 16:51:04 -0400 | [diff] [blame] | 256 | u32 exclusive; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Chuck Lever | 2fd0c67 | 2021-06-03 16:51:04 -0400 | [diff] [blame] | 258 | if (!svcxdr_decode_cookie(xdr, &argp->cookie)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | return 0; |
Chuck Lever | 2fd0c67 | 2021-06-03 16:51:04 -0400 | [diff] [blame] | 260 | if (xdr_stream_decode_bool(xdr, &exclusive) < 0) |
| 261 | return 0; |
| 262 | if (!svcxdr_decode_lock(xdr, &argp->lock)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | return 0; |
| 264 | if (exclusive) |
| 265 | argp->lock.fl.fl_type = F_WRLCK; |
| 266 | |
Chuck Lever | 2fd0c67 | 2021-06-03 16:51:04 -0400 | [diff] [blame] | 267 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | int |
Chuck Lever | c1adb8c | 2021-06-03 16:51:10 -0400 | [diff] [blame] | 271 | nlmsvc_decode_lockargs(struct svc_rqst *rqstp, __be32 *p) |
| 272 | { |
| 273 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
| 274 | struct nlm_args *argp = rqstp->rq_argp; |
| 275 | u32 exclusive; |
| 276 | |
| 277 | if (!svcxdr_decode_cookie(xdr, &argp->cookie)) |
| 278 | return 0; |
| 279 | if (xdr_stream_decode_bool(xdr, &argp->block) < 0) |
| 280 | return 0; |
| 281 | if (xdr_stream_decode_bool(xdr, &exclusive) < 0) |
| 282 | return 0; |
| 283 | if (!svcxdr_decode_lock(xdr, &argp->lock)) |
| 284 | return 0; |
| 285 | if (exclusive) |
| 286 | argp->lock.fl.fl_type = F_WRLCK; |
| 287 | if (xdr_stream_decode_bool(xdr, &argp->reclaim) < 0) |
| 288 | return 0; |
| 289 | if (xdr_stream_decode_u32(xdr, &argp->state) < 0) |
| 290 | return 0; |
| 291 | argp->monitor = 1; /* monitor client by default */ |
| 292 | |
| 293 | return 1; |
| 294 | } |
| 295 | |
| 296 | int |
Chuck Lever | f4e08f3 | 2021-06-03 16:51:16 -0400 | [diff] [blame^] | 297 | nlmsvc_decode_cancargs(struct svc_rqst *rqstp, __be32 *p) |
| 298 | { |
| 299 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; |
| 300 | struct nlm_args *argp = rqstp->rq_argp; |
| 301 | u32 exclusive; |
| 302 | |
| 303 | if (!svcxdr_decode_cookie(xdr, &argp->cookie)) |
| 304 | return 0; |
| 305 | if (xdr_stream_decode_bool(xdr, &argp->block) < 0) |
| 306 | return 0; |
| 307 | if (xdr_stream_decode_bool(xdr, &exclusive) < 0) |
| 308 | return 0; |
| 309 | if (!svcxdr_decode_lock(xdr, &argp->lock)) |
| 310 | return 0; |
| 311 | if (exclusive) |
| 312 | argp->lock.fl.fl_type = F_WRLCK; |
| 313 | |
| 314 | return 1; |
| 315 | } |
| 316 | |
| 317 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 318 | nlmsvc_encode_testres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 320 | struct nlm_res *resp = rqstp->rq_resp; |
| 321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | if (!(p = nlm_encode_testres(p, resp))) |
| 323 | return 0; |
| 324 | return xdr_ressize_check(rqstp, p); |
| 325 | } |
| 326 | |
| 327 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 328 | nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 330 | struct nlm_args *argp = rqstp->rq_argp; |
| 331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | if (!(p = nlm_decode_cookie(p, &argp->cookie)) |
| 333 | || !(p = nlm_decode_lock(p, &argp->lock))) |
| 334 | return 0; |
| 335 | argp->lock.fl.fl_type = F_UNLCK; |
| 336 | return xdr_argsize_check(rqstp, p); |
| 337 | } |
| 338 | |
| 339 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 340 | nlmsvc_decode_shareargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 342 | struct nlm_args *argp = rqstp->rq_argp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | struct nlm_lock *lock = &argp->lock; |
| 344 | |
| 345 | memset(lock, 0, sizeof(*lock)); |
| 346 | locks_init_lock(&lock->fl); |
Trond Myklebust | 7bab377 | 2006-03-20 13:44:06 -0500 | [diff] [blame] | 347 | lock->svid = ~(u32) 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
| 349 | if (!(p = nlm_decode_cookie(p, &argp->cookie)) |
| 350 | || !(p = xdr_decode_string_inplace(p, &lock->caller, |
| 351 | &lock->len, NLM_MAXSTRLEN)) |
| 352 | || !(p = nlm_decode_fh(p, &lock->fh)) |
| 353 | || !(p = nlm_decode_oh(p, &lock->oh))) |
| 354 | return 0; |
| 355 | argp->fsm_mode = ntohl(*p++); |
| 356 | argp->fsm_access = ntohl(*p++); |
| 357 | return xdr_argsize_check(rqstp, p); |
| 358 | } |
| 359 | |
| 360 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 361 | nlmsvc_encode_shareres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 363 | struct nlm_res *resp = rqstp->rq_resp; |
| 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | if (!(p = nlm_encode_cookie(p, &resp->cookie))) |
| 366 | return 0; |
| 367 | *p++ = resp->status; |
| 368 | *p++ = xdr_zero; /* sequence argument */ |
| 369 | return xdr_ressize_check(rqstp, p); |
| 370 | } |
| 371 | |
| 372 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 373 | nlmsvc_encode_res(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 375 | struct nlm_res *resp = rqstp->rq_resp; |
| 376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | if (!(p = nlm_encode_cookie(p, &resp->cookie))) |
| 378 | return 0; |
| 379 | *p++ = resp->status; |
| 380 | return xdr_ressize_check(rqstp, p); |
| 381 | } |
| 382 | |
| 383 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 384 | nlmsvc_decode_notify(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 386 | struct nlm_args *argp = rqstp->rq_argp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | struct nlm_lock *lock = &argp->lock; |
| 388 | |
| 389 | if (!(p = xdr_decode_string_inplace(p, &lock->caller, |
| 390 | &lock->len, NLM_MAXSTRLEN))) |
| 391 | return 0; |
| 392 | argp->state = ntohl(*p++); |
| 393 | return xdr_argsize_check(rqstp, p); |
| 394 | } |
| 395 | |
| 396 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 397 | nlmsvc_decode_reboot(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 399 | struct nlm_reboot *argp = rqstp->rq_argp; |
| 400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | if (!(p = xdr_decode_string_inplace(p, &argp->mon, &argp->len, SM_MAXSTRLEN))) |
| 402 | return 0; |
| 403 | argp->state = ntohl(*p++); |
Chuck Lever | 576df46 | 2008-12-05 19:03:39 -0500 | [diff] [blame] | 404 | memcpy(&argp->priv.data, p, sizeof(argp->priv.data)); |
| 405 | p += XDR_QUADLEN(SM_PRIV_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | return xdr_argsize_check(rqstp, p); |
| 407 | } |
| 408 | |
| 409 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 410 | nlmsvc_decode_res(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 412 | struct nlm_res *resp = rqstp->rq_argp; |
| 413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | if (!(p = nlm_decode_cookie(p, &resp->cookie))) |
| 415 | return 0; |
Al Viro | e8c5c04 | 2006-12-13 00:35:03 -0800 | [diff] [blame] | 416 | resp->status = *p++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | return xdr_argsize_check(rqstp, p); |
| 418 | } |
| 419 | |
| 420 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 421 | nlmsvc_encode_void(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | { |
| 423 | return xdr_ressize_check(rqstp, p); |
| 424 | } |