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 | |
| 25 | static inline loff_t |
| 26 | s32_to_loff_t(__s32 offset) |
| 27 | { |
| 28 | return (loff_t)offset; |
| 29 | } |
| 30 | |
| 31 | static inline __s32 |
| 32 | loff_t_to_s32(loff_t offset) |
| 33 | { |
| 34 | __s32 res; |
| 35 | if (offset >= NLM_OFFSET_MAX) |
| 36 | res = NLM_OFFSET_MAX; |
| 37 | else if (offset <= -NLM_OFFSET_MAX) |
| 38 | res = -NLM_OFFSET_MAX; |
| 39 | else |
| 40 | res = offset; |
| 41 | return res; |
| 42 | } |
| 43 | |
| 44 | /* |
Chuck Lever | 2fd0c67 | 2021-06-03 16:51:04 -0400 | [diff] [blame] | 45 | * NLM file handles are defined by specification to be a variable-length |
| 46 | * XDR opaque no longer than 1024 bytes. However, this implementation |
| 47 | * constrains their length to exactly the length of an NFSv2 file |
| 48 | * handle. |
| 49 | */ |
| 50 | static bool |
| 51 | svcxdr_decode_fhandle(struct xdr_stream *xdr, struct nfs_fh *fh) |
| 52 | { |
| 53 | __be32 *p; |
| 54 | u32 len; |
| 55 | |
| 56 | if (xdr_stream_decode_u32(xdr, &len) < 0) |
| 57 | return false; |
| 58 | if (len != NFS2_FHSIZE) |
| 59 | return false; |
| 60 | |
| 61 | p = xdr_inline_decode(xdr, len); |
| 62 | if (!p) |
| 63 | return false; |
| 64 | fh->size = NFS2_FHSIZE; |
| 65 | memcpy(fh->data, p, len); |
| 66 | memset(fh->data + NFS2_FHSIZE, 0, sizeof(fh->data) - NFS2_FHSIZE); |
| 67 | |
| 68 | return true; |
| 69 | } |
| 70 | |
Chuck Lever | 2fd0c67 | 2021-06-03 16:51:04 -0400 | [diff] [blame] | 71 | static bool |
| 72 | svcxdr_decode_lock(struct xdr_stream *xdr, struct nlm_lock *lock) |
| 73 | { |
| 74 | struct file_lock *fl = &lock->fl; |
| 75 | s32 start, len, end; |
| 76 | |
| 77 | if (!svcxdr_decode_string(xdr, &lock->caller, &lock->len)) |
| 78 | return false; |
| 79 | if (!svcxdr_decode_fhandle(xdr, &lock->fh)) |
| 80 | return false; |
| 81 | if (!svcxdr_decode_owner(xdr, &lock->oh)) |
| 82 | return false; |
| 83 | if (xdr_stream_decode_u32(xdr, &lock->svid) < 0) |
| 84 | return false; |
| 85 | if (xdr_stream_decode_u32(xdr, &start) < 0) |
| 86 | return false; |
| 87 | if (xdr_stream_decode_u32(xdr, &len) < 0) |
| 88 | return false; |
| 89 | |
| 90 | locks_init_lock(fl); |
| 91 | fl->fl_flags = FL_POSIX; |
| 92 | fl->fl_type = F_RDLCK; |
| 93 | end = start + len - 1; |
| 94 | fl->fl_start = s32_to_loff_t(start); |
| 95 | if (len == 0 || end < 0) |
| 96 | fl->fl_end = OFFSET_MAX; |
| 97 | else |
| 98 | fl->fl_end = s32_to_loff_t(end); |
| 99 | |
| 100 | return true; |
| 101 | } |
| 102 | |
Chuck Lever | adf98a4 | 2021-06-03 16:51:58 -0400 | [diff] [blame] | 103 | static bool |
| 104 | svcxdr_encode_holder(struct xdr_stream *xdr, const struct nlm_lock *lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { |
Chuck Lever | adf98a4 | 2021-06-03 16:51:58 -0400 | [diff] [blame] | 106 | const struct file_lock *fl = &lock->fl; |
| 107 | s32 start, len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Chuck Lever | adf98a4 | 2021-06-03 16:51:58 -0400 | [diff] [blame] | 109 | /* exclusive */ |
| 110 | if (xdr_stream_encode_bool(xdr, fl->fl_type != F_RDLCK) < 0) |
| 111 | return false; |
| 112 | if (xdr_stream_encode_u32(xdr, lock->svid) < 0) |
| 113 | return false; |
| 114 | if (!svcxdr_encode_owner(xdr, &lock->oh)) |
| 115 | return false; |
| 116 | start = loff_t_to_s32(fl->fl_start); |
| 117 | if (fl->fl_end == OFFSET_MAX) |
| 118 | len = 0; |
| 119 | else |
| 120 | len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1); |
| 121 | if (xdr_stream_encode_u32(xdr, start) < 0) |
| 122 | return false; |
| 123 | if (xdr_stream_encode_u32(xdr, len) < 0) |
| 124 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Chuck Lever | adf98a4 | 2021-06-03 16:51:58 -0400 | [diff] [blame] | 126 | return true; |
| 127 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Chuck Lever | adf98a4 | 2021-06-03 16:51:58 -0400 | [diff] [blame] | 129 | static bool |
| 130 | svcxdr_encode_testrply(struct xdr_stream *xdr, const struct nlm_res *resp) |
| 131 | { |
| 132 | if (!svcxdr_encode_stats(xdr, resp->status)) |
| 133 | return false; |
| 134 | switch (resp->status) { |
| 135 | case nlm_lck_denied: |
| 136 | if (!svcxdr_encode_holder(xdr, &resp->lock)) |
| 137 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Chuck Lever | adf98a4 | 2021-06-03 16:51:58 -0400 | [diff] [blame] | 140 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
| 144 | /* |
Chuck Lever | cc1029b | 2021-06-03 16:50:58 -0400 | [diff] [blame] | 145 | * Decode Call arguments |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | */ |
Chuck Lever | cc1029b | 2021-06-03 16:50:58 -0400 | [diff] [blame] | 147 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 148 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 149 | nlmsvc_decode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | cc1029b | 2021-06-03 16:50:58 -0400 | [diff] [blame] | 150 | { |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 151 | return true; |
Chuck Lever | cc1029b | 2021-06-03 16:50:58 -0400 | [diff] [blame] | 152 | } |
| 153 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 154 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 155 | nlmsvc_decode_testargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 157 | struct nlm_args *argp = rqstp->rq_argp; |
Chuck Lever | 2fd0c67 | 2021-06-03 16:51:04 -0400 | [diff] [blame] | 158 | u32 exclusive; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Chuck Lever | 2fd0c67 | 2021-06-03 16:51:04 -0400 | [diff] [blame] | 160 | if (!svcxdr_decode_cookie(xdr, &argp->cookie)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 161 | return false; |
Chuck Lever | 2fd0c67 | 2021-06-03 16:51:04 -0400 | [diff] [blame] | 162 | if (xdr_stream_decode_bool(xdr, &exclusive) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 163 | return false; |
Chuck Lever | 2fd0c67 | 2021-06-03 16:51:04 -0400 | [diff] [blame] | 164 | if (!svcxdr_decode_lock(xdr, &argp->lock)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 165 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | if (exclusive) |
| 167 | argp->lock.fl.fl_type = F_WRLCK; |
| 168 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 169 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 172 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 173 | nlmsvc_decode_lockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | c1adb8c | 2021-06-03 16:51:10 -0400 | [diff] [blame] | 174 | { |
Chuck Lever | c1adb8c | 2021-06-03 16:51:10 -0400 | [diff] [blame] | 175 | struct nlm_args *argp = rqstp->rq_argp; |
| 176 | u32 exclusive; |
| 177 | |
| 178 | if (!svcxdr_decode_cookie(xdr, &argp->cookie)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 179 | return false; |
Chuck Lever | c1adb8c | 2021-06-03 16:51:10 -0400 | [diff] [blame] | 180 | if (xdr_stream_decode_bool(xdr, &argp->block) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 181 | return false; |
Chuck Lever | c1adb8c | 2021-06-03 16:51:10 -0400 | [diff] [blame] | 182 | if (xdr_stream_decode_bool(xdr, &exclusive) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 183 | return false; |
Chuck Lever | c1adb8c | 2021-06-03 16:51:10 -0400 | [diff] [blame] | 184 | if (!svcxdr_decode_lock(xdr, &argp->lock)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 185 | return false; |
Chuck Lever | c1adb8c | 2021-06-03 16:51:10 -0400 | [diff] [blame] | 186 | if (exclusive) |
| 187 | argp->lock.fl.fl_type = F_WRLCK; |
| 188 | if (xdr_stream_decode_bool(xdr, &argp->reclaim) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 189 | return false; |
Chuck Lever | c1adb8c | 2021-06-03 16:51:10 -0400 | [diff] [blame] | 190 | if (xdr_stream_decode_u32(xdr, &argp->state) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 191 | return false; |
Chuck Lever | c1adb8c | 2021-06-03 16:51:10 -0400 | [diff] [blame] | 192 | argp->monitor = 1; /* monitor client by default */ |
| 193 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 194 | return true; |
Chuck Lever | c1adb8c | 2021-06-03 16:51:10 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 197 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 198 | nlmsvc_decode_cancargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | f4e08f3 | 2021-06-03 16:51:16 -0400 | [diff] [blame] | 199 | { |
Chuck Lever | f4e08f3 | 2021-06-03 16:51:16 -0400 | [diff] [blame] | 200 | struct nlm_args *argp = rqstp->rq_argp; |
| 201 | u32 exclusive; |
| 202 | |
| 203 | if (!svcxdr_decode_cookie(xdr, &argp->cookie)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 204 | return false; |
Chuck Lever | f4e08f3 | 2021-06-03 16:51:16 -0400 | [diff] [blame] | 205 | if (xdr_stream_decode_bool(xdr, &argp->block) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 206 | return false; |
Chuck Lever | f4e08f3 | 2021-06-03 16:51:16 -0400 | [diff] [blame] | 207 | if (xdr_stream_decode_bool(xdr, &exclusive) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 208 | return false; |
Chuck Lever | f4e08f3 | 2021-06-03 16:51:16 -0400 | [diff] [blame] | 209 | if (!svcxdr_decode_lock(xdr, &argp->lock)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 210 | return false; |
Chuck Lever | f4e08f3 | 2021-06-03 16:51:16 -0400 | [diff] [blame] | 211 | if (exclusive) |
| 212 | argp->lock.fl.fl_type = F_WRLCK; |
| 213 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 214 | return true; |
Chuck Lever | f4e08f3 | 2021-06-03 16:51:16 -0400 | [diff] [blame] | 215 | } |
| 216 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 217 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 218 | nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | c27045d | 2021-06-03 16:51:22 -0400 | [diff] [blame] | 219 | { |
Chuck Lever | c27045d | 2021-06-03 16:51:22 -0400 | [diff] [blame] | 220 | struct nlm_args *argp = rqstp->rq_argp; |
| 221 | |
| 222 | if (!svcxdr_decode_cookie(xdr, &argp->cookie)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 223 | return false; |
Chuck Lever | c27045d | 2021-06-03 16:51:22 -0400 | [diff] [blame] | 224 | if (!svcxdr_decode_lock(xdr, &argp->lock)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 225 | return false; |
Chuck Lever | c27045d | 2021-06-03 16:51:22 -0400 | [diff] [blame] | 226 | argp->lock.fl.fl_type = F_UNLCK; |
| 227 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 228 | return true; |
Chuck Lever | c27045d | 2021-06-03 16:51:22 -0400 | [diff] [blame] | 229 | } |
| 230 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 231 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 232 | nlmsvc_decode_res(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | 16ddcab | 2021-06-03 16:51:28 -0400 | [diff] [blame] | 233 | { |
Chuck Lever | 16ddcab | 2021-06-03 16:51:28 -0400 | [diff] [blame] | 234 | struct nlm_res *resp = rqstp->rq_argp; |
| 235 | |
| 236 | if (!svcxdr_decode_cookie(xdr, &resp->cookie)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 237 | return false; |
Chuck Lever | 16ddcab | 2021-06-03 16:51:28 -0400 | [diff] [blame] | 238 | if (!svcxdr_decode_stats(xdr, &resp->status)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 239 | return false; |
Chuck Lever | 16ddcab | 2021-06-03 16:51:28 -0400 | [diff] [blame] | 240 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 241 | return true; |
Chuck Lever | 16ddcab | 2021-06-03 16:51:28 -0400 | [diff] [blame] | 242 | } |
| 243 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 244 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 245 | nlmsvc_decode_reboot(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | 137e05e | 2021-06-03 16:51:34 -0400 | [diff] [blame] | 246 | { |
Chuck Lever | 137e05e | 2021-06-03 16:51:34 -0400 | [diff] [blame] | 247 | struct nlm_reboot *argp = rqstp->rq_argp; |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 248 | __be32 *p; |
Chuck Lever | 137e05e | 2021-06-03 16:51:34 -0400 | [diff] [blame] | 249 | u32 len; |
| 250 | |
| 251 | if (xdr_stream_decode_u32(xdr, &len) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 252 | return false; |
Chuck Lever | 137e05e | 2021-06-03 16:51:34 -0400 | [diff] [blame] | 253 | if (len > SM_MAXSTRLEN) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 254 | return false; |
Chuck Lever | 137e05e | 2021-06-03 16:51:34 -0400 | [diff] [blame] | 255 | p = xdr_inline_decode(xdr, len); |
| 256 | if (!p) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 257 | return false; |
Chuck Lever | 137e05e | 2021-06-03 16:51:34 -0400 | [diff] [blame] | 258 | argp->len = len; |
| 259 | argp->mon = (char *)p; |
| 260 | if (xdr_stream_decode_u32(xdr, &argp->state) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 261 | return false; |
Chuck Lever | 137e05e | 2021-06-03 16:51:34 -0400 | [diff] [blame] | 262 | p = xdr_inline_decode(xdr, SM_PRIV_SIZE); |
| 263 | if (!p) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 264 | return false; |
Chuck Lever | 137e05e | 2021-06-03 16:51:34 -0400 | [diff] [blame] | 265 | memcpy(&argp->priv.data, p, sizeof(argp->priv.data)); |
| 266 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 267 | return true; |
Chuck Lever | 137e05e | 2021-06-03 16:51:34 -0400 | [diff] [blame] | 268 | } |
| 269 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 270 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 271 | nlmsvc_decode_shareargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | 890939e | 2021-06-03 16:51:40 -0400 | [diff] [blame] | 272 | { |
Chuck Lever | 890939e | 2021-06-03 16:51:40 -0400 | [diff] [blame] | 273 | struct nlm_args *argp = rqstp->rq_argp; |
| 274 | struct nlm_lock *lock = &argp->lock; |
| 275 | |
| 276 | memset(lock, 0, sizeof(*lock)); |
| 277 | locks_init_lock(&lock->fl); |
| 278 | lock->svid = ~(u32)0; |
| 279 | |
| 280 | if (!svcxdr_decode_cookie(xdr, &argp->cookie)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 281 | return false; |
Chuck Lever | 890939e | 2021-06-03 16:51:40 -0400 | [diff] [blame] | 282 | if (!svcxdr_decode_string(xdr, &lock->caller, &lock->len)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 283 | return false; |
Chuck Lever | 890939e | 2021-06-03 16:51:40 -0400 | [diff] [blame] | 284 | if (!svcxdr_decode_fhandle(xdr, &lock->fh)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 285 | return false; |
Chuck Lever | 890939e | 2021-06-03 16:51:40 -0400 | [diff] [blame] | 286 | if (!svcxdr_decode_owner(xdr, &lock->oh)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 287 | return false; |
Chuck Lever | 890939e | 2021-06-03 16:51:40 -0400 | [diff] [blame] | 288 | /* XXX: Range checks are missing in the original code */ |
| 289 | if (xdr_stream_decode_u32(xdr, &argp->fsm_mode) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 290 | return false; |
Chuck Lever | 890939e | 2021-06-03 16:51:40 -0400 | [diff] [blame] | 291 | if (xdr_stream_decode_u32(xdr, &argp->fsm_access) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 292 | return false; |
Chuck Lever | 890939e | 2021-06-03 16:51:40 -0400 | [diff] [blame] | 293 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 294 | return true; |
Chuck Lever | 890939e | 2021-06-03 16:51:40 -0400 | [diff] [blame] | 295 | } |
| 296 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 297 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 298 | nlmsvc_decode_notify(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | 14e1052 | 2021-06-03 16:51:46 -0400 | [diff] [blame] | 299 | { |
Chuck Lever | 14e1052 | 2021-06-03 16:51:46 -0400 | [diff] [blame] | 300 | struct nlm_args *argp = rqstp->rq_argp; |
| 301 | struct nlm_lock *lock = &argp->lock; |
| 302 | |
| 303 | if (!svcxdr_decode_string(xdr, &lock->caller, &lock->len)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 304 | return false; |
Chuck Lever | 14e1052 | 2021-06-03 16:51:46 -0400 | [diff] [blame] | 305 | if (xdr_stream_decode_u32(xdr, &argp->state) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 306 | return false; |
Chuck Lever | 14e1052 | 2021-06-03 16:51:46 -0400 | [diff] [blame] | 307 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 308 | return true; |
Chuck Lever | 14e1052 | 2021-06-03 16:51:46 -0400 | [diff] [blame] | 309 | } |
| 310 | |
Chuck Lever | e26ec89 | 2021-06-03 16:51:52 -0400 | [diff] [blame] | 311 | |
| 312 | /* |
| 313 | * Encode Reply results |
| 314 | */ |
| 315 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 316 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 317 | nlmsvc_encode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | e26ec89 | 2021-06-03 16:51:52 -0400 | [diff] [blame] | 318 | { |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 319 | return true; |
Chuck Lever | e26ec89 | 2021-06-03 16:51:52 -0400 | [diff] [blame] | 320 | } |
| 321 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 322 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 323 | nlmsvc_encode_testres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 325 | struct nlm_res *resp = rqstp->rq_resp; |
| 326 | |
Chuck Lever | adf98a4 | 2021-06-03 16:51:58 -0400 | [diff] [blame] | 327 | return svcxdr_encode_cookie(xdr, &resp->cookie) && |
| 328 | svcxdr_encode_testrply(xdr, resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 331 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 332 | nlmsvc_encode_res(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | e96735a | 2021-06-03 16:52:04 -0400 | [diff] [blame] | 333 | { |
Chuck Lever | e96735a | 2021-06-03 16:52:04 -0400 | [diff] [blame] | 334 | struct nlm_res *resp = rqstp->rq_resp; |
| 335 | |
| 336 | return svcxdr_encode_cookie(xdr, &resp->cookie) && |
| 337 | svcxdr_encode_stats(xdr, resp->status); |
| 338 | } |
| 339 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 340 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 341 | nlmsvc_encode_shareres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 343 | struct nlm_res *resp = rqstp->rq_resp; |
| 344 | |
Chuck Lever | 529ca3a | 2021-06-03 16:52:10 -0400 | [diff] [blame] | 345 | if (!svcxdr_encode_cookie(xdr, &resp->cookie)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 346 | return false; |
Chuck Lever | 529ca3a | 2021-06-03 16:52:10 -0400 | [diff] [blame] | 347 | if (!svcxdr_encode_stats(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 348 | return false; |
Chuck Lever | 529ca3a | 2021-06-03 16:52:10 -0400 | [diff] [blame] | 349 | /* sequence */ |
| 350 | if (xdr_stream_encode_u32(xdr, 0) < 0) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 351 | return false; |
Chuck Lever | 529ca3a | 2021-06-03 16:52:10 -0400 | [diff] [blame] | 352 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 353 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | } |