^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/fs/lockd/xdr.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * XDR support for lockd and the lock client.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/nfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/sunrpc/xdr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/sunrpc/svc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/sunrpc/stats.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/lockd/lockd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <uapi/linux/nfs2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define NLMDBG_FACILITY NLMDBG_XDR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static inline loff_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) s32_to_loff_t(__s32 offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return (loff_t)offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static inline __s32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) loff_t_to_s32(loff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) __s32 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (offset >= NLM_OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) res = NLM_OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) else if (offset <= -NLM_OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) res = -NLM_OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) res = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * XDR functions for basic NLM types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static __be32 *nlm_decode_cookie(__be32 *p, struct nlm_cookie *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) len = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if(len==0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) c->len=4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) memset(c->data, 0, 4); /* hockeypux brain damage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) else if(len<=NLM_MAXCOOKIELEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) c->len=len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) memcpy(c->data, p, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) p+=XDR_QUADLEN(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) dprintk("lockd: bad cookie size %d (only cookies under "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) "%d bytes are supported.)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) len, NLM_MAXCOOKIELEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static inline __be32 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) nlm_encode_cookie(__be32 *p, struct nlm_cookie *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) *p++ = htonl(c->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) memcpy(p, c->data, c->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) p+=XDR_QUADLEN(c->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static __be32 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) nlm_decode_fh(__be32 *p, struct nfs_fh *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if ((len = ntohl(*p++)) != NFS2_FHSIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) dprintk("lockd: bad fhandle size %d (should be %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) len, NFS2_FHSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) f->size = NFS2_FHSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) memset(f->data, 0, sizeof(f->data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) memcpy(f->data, p, NFS2_FHSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return p + XDR_QUADLEN(NFS2_FHSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * Encode and decode owner handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static inline __be32 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) nlm_decode_oh(__be32 *p, struct xdr_netobj *oh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return xdr_decode_netobj(p, oh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static inline __be32 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) nlm_encode_oh(__be32 *p, struct xdr_netobj *oh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return xdr_encode_netobj(p, oh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static __be32 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) nlm_decode_lock(__be32 *p, struct nlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct file_lock *fl = &lock->fl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) s32 start, len, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (!(p = xdr_decode_string_inplace(p, &lock->caller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) &lock->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) NLM_MAXSTRLEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) || !(p = nlm_decode_fh(p, &lock->fh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) || !(p = nlm_decode_oh(p, &lock->oh)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) lock->svid = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) locks_init_lock(fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) fl->fl_flags = FL_POSIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) fl->fl_type = F_RDLCK; /* as good as anything else */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) start = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) len = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) end = start + len - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) fl->fl_start = s32_to_loff_t(start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (len == 0 || end < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) fl->fl_end = OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) fl->fl_end = s32_to_loff_t(end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * Encode result of a TEST/TEST_MSG call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static __be32 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) nlm_encode_testres(__be32 *p, struct nlm_res *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) s32 start, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (!(p = nlm_encode_cookie(p, &resp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) *p++ = resp->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (resp->status == nlm_lck_denied) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct file_lock *fl = &resp->lock.fl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) *p++ = (fl->fl_type == F_RDLCK)? xdr_zero : xdr_one;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) *p++ = htonl(resp->lock.svid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /* Encode owner handle. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (!(p = xdr_encode_netobj(p, &resp->lock.oh)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) start = loff_t_to_s32(fl->fl_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (fl->fl_end == OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) *p++ = htonl(start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) *p++ = htonl(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * First, the server side XDR functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) nlmsvc_decode_testargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct nlm_args *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) u32 exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (!(p = nlm_decode_cookie(p, &argp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) exclusive = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (!(p = nlm_decode_lock(p, &argp->lock)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (exclusive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) argp->lock.fl.fl_type = F_WRLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) nlmsvc_encode_testres(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct nlm_res *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (!(p = nlm_encode_testres(p, resp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return xdr_ressize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) nlmsvc_decode_lockargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct nlm_args *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) u32 exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (!(p = nlm_decode_cookie(p, &argp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) argp->block = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) exclusive = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (!(p = nlm_decode_lock(p, &argp->lock)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (exclusive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) argp->lock.fl.fl_type = F_WRLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) argp->reclaim = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) argp->state = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) argp->monitor = 1; /* monitor client by default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) nlmsvc_decode_cancargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct nlm_args *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) u32 exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (!(p = nlm_decode_cookie(p, &argp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) argp->block = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) exclusive = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (!(p = nlm_decode_lock(p, &argp->lock)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (exclusive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) argp->lock.fl.fl_type = F_WRLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct nlm_args *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (!(p = nlm_decode_cookie(p, &argp->cookie))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) || !(p = nlm_decode_lock(p, &argp->lock)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) argp->lock.fl.fl_type = F_UNLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) nlmsvc_decode_shareargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) struct nlm_args *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct nlm_lock *lock = &argp->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) memset(lock, 0, sizeof(*lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) locks_init_lock(&lock->fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) lock->svid = ~(u32) 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (!(p = nlm_decode_cookie(p, &argp->cookie))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) || !(p = xdr_decode_string_inplace(p, &lock->caller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) &lock->len, NLM_MAXSTRLEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) || !(p = nlm_decode_fh(p, &lock->fh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) || !(p = nlm_decode_oh(p, &lock->oh)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) argp->fsm_mode = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) argp->fsm_access = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) nlmsvc_encode_shareres(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct nlm_res *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (!(p = nlm_encode_cookie(p, &resp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) *p++ = resp->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) *p++ = xdr_zero; /* sequence argument */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return xdr_ressize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) nlmsvc_encode_res(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct nlm_res *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (!(p = nlm_encode_cookie(p, &resp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) *p++ = resp->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return xdr_ressize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) nlmsvc_decode_notify(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct nlm_args *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct nlm_lock *lock = &argp->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (!(p = xdr_decode_string_inplace(p, &lock->caller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) &lock->len, NLM_MAXSTRLEN)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) argp->state = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) nlmsvc_decode_reboot(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct nlm_reboot *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (!(p = xdr_decode_string_inplace(p, &argp->mon, &argp->len, SM_MAXSTRLEN)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) argp->state = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) memcpy(&argp->priv.data, p, sizeof(argp->priv.data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) p += XDR_QUADLEN(SM_PRIV_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) nlmsvc_decode_res(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct nlm_res *resp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (!(p = nlm_decode_cookie(p, &resp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) resp->status = *p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) nlmsvc_decode_void(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) nlmsvc_encode_void(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) return xdr_ressize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }