^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/xdr4.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) * Copyright (C) 1999, Trond Myklebust <trond.myklebust@fys.uio.no>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/nfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/sunrpc/xdr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/sunrpc/svc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/sunrpc/stats.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/lockd/lockd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define NLMDBG_FACILITY NLMDBG_XDR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static inline loff_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) s64_to_loff_t(__s64 offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) return (loff_t)offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static inline s64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) loff_t_to_s64(loff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) s64 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (offset > NLM4_OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) res = NLM4_OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) else if (offset < -NLM4_OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) res = -NLM4_OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) res = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^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) * XDR functions for basic NLM types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static __be32 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) nlm4_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 __be32 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) nlm4_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) nlm4_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) memset(f->data, 0, sizeof(f->data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) f->size = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (f->size > NFS_MAXFHSIZE) {
^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) f->size, NFS_MAXFHSIZE);
^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) memcpy(f->data, p, f->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return p + XDR_QUADLEN(f->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * Encode and decode owner handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static __be32 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) nlm4_decode_oh(__be32 *p, struct xdr_netobj *oh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return xdr_decode_netobj(p, oh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static __be32 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) nlm4_decode_lock(__be32 *p, struct nlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct file_lock *fl = &lock->fl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) __u64 len, start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) __s64 end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (!(p = xdr_decode_string_inplace(p, &lock->caller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) &lock->len, NLM_MAXSTRLEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) || !(p = nlm4_decode_fh(p, &lock->fh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) || !(p = nlm4_decode_oh(p, &lock->oh)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) lock->svid = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) locks_init_lock(fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) fl->fl_flags = FL_POSIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) fl->fl_type = F_RDLCK; /* as good as anything else */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) p = xdr_decode_hyper(p, &start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) p = xdr_decode_hyper(p, &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) end = start + len - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) fl->fl_start = s64_to_loff_t(start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (len == 0 || end < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) fl->fl_end = OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) fl->fl_end = s64_to_loff_t(end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * Encode result of a TEST/TEST_MSG call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static __be32 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) nlm4_encode_testres(__be32 *p, struct nlm_res *resp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) s64 start, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) dprintk("xdr: before encode_testres (p %p resp %p)\n", p, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (!(p = nlm4_encode_cookie(p, &resp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) *p++ = resp->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (resp->status == nlm_lck_denied) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct file_lock *fl = &resp->lock.fl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) *p++ = (fl->fl_type == F_RDLCK)? xdr_zero : xdr_one;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) *p++ = htonl(resp->lock.svid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /* Encode owner handle. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (!(p = xdr_encode_netobj(p, &resp->lock.oh)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) start = loff_t_to_s64(fl->fl_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (fl->fl_end == OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) len = loff_t_to_s64(fl->fl_end - fl->fl_start + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) p = xdr_encode_hyper(p, start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) p = xdr_encode_hyper(p, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) dprintk("xdr: encode_testres (status %u pid %d type %d start %Ld end %Ld)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) resp->status, (int)resp->lock.svid, fl->fl_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) (long long)fl->fl_start, (long long)fl->fl_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) dprintk("xdr: after encode_testres (p %p resp %p)\n", p, resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return p;
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * First, the server side XDR functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) nlm4svc_decode_testargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct nlm_args *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) u32 exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (!(p = nlm4_decode_cookie(p, &argp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) exclusive = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (!(p = nlm4_decode_lock(p, &argp->lock)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (exclusive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) argp->lock.fl.fl_type = F_WRLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) nlm4svc_encode_testres(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct nlm_res *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (!(p = nlm4_encode_testres(p, resp)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return xdr_ressize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) nlm4svc_decode_lockargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct nlm_args *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) u32 exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (!(p = nlm4_decode_cookie(p, &argp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) argp->block = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) exclusive = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (!(p = nlm4_decode_lock(p, &argp->lock)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (exclusive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) argp->lock.fl.fl_type = F_WRLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) argp->reclaim = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) argp->state = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) argp->monitor = 1; /* monitor client by default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) nlm4svc_decode_cancargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct nlm_args *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) u32 exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (!(p = nlm4_decode_cookie(p, &argp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) argp->block = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) exclusive = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (!(p = nlm4_decode_lock(p, &argp->lock)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (exclusive)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) argp->lock.fl.fl_type = F_WRLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) nlm4svc_decode_unlockargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct nlm_args *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (!(p = nlm4_decode_cookie(p, &argp->cookie))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) || !(p = nlm4_decode_lock(p, &argp->lock)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) argp->lock.fl.fl_type = F_UNLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) nlm4svc_decode_shareargs(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct nlm_args *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct nlm_lock *lock = &argp->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) memset(lock, 0, sizeof(*lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) locks_init_lock(&lock->fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) lock->svid = ~(u32) 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (!(p = nlm4_decode_cookie(p, &argp->cookie))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) || !(p = xdr_decode_string_inplace(p, &lock->caller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) &lock->len, NLM_MAXSTRLEN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) || !(p = nlm4_decode_fh(p, &lock->fh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) || !(p = nlm4_decode_oh(p, &lock->oh)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) argp->fsm_mode = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) argp->fsm_access = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) nlm4svc_encode_shareres(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct nlm_res *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (!(p = nlm4_encode_cookie(p, &resp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) *p++ = resp->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) *p++ = xdr_zero; /* sequence argument */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return xdr_ressize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) nlm4svc_encode_res(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct nlm_res *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (!(p = nlm4_encode_cookie(p, &resp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) *p++ = resp->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return xdr_ressize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) nlm4svc_decode_notify(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct nlm_args *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct nlm_lock *lock = &argp->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (!(p = xdr_decode_string_inplace(p, &lock->caller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) &lock->len, NLM_MAXSTRLEN)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) argp->state = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) nlm4svc_decode_reboot(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct nlm_reboot *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (!(p = xdr_decode_string_inplace(p, &argp->mon, &argp->len, SM_MAXSTRLEN)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) argp->state = ntohl(*p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) memcpy(&argp->priv.data, p, sizeof(argp->priv.data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) p += XDR_QUADLEN(SM_PRIV_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) nlm4svc_decode_res(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct nlm_res *resp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (!(p = nlm4_decode_cookie(p, &resp->cookie)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) resp->status = *p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) nlm4svc_decode_void(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return xdr_argsize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) nlm4svc_encode_void(struct svc_rqst *rqstp, __be32 *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) return xdr_ressize_check(rqstp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }