linux/fs/lockd/nlm3xdr_gen.c
Chuck Lever 4b386d8ddb Documentation: Add the RPC language description of NLM version 3
In order to generate source code to encode and decode NLMv3 protocol
elements, include a copy of the RPC language description of NLMv3
for xdrgen to process. The language description is derived from the
Open Group's XNFS specification:

  https://pubs.opengroup.org/onlinepubs/9629799/chap10.htm#tagcjh_11_03

The C code committed here was generated from the new nlm3.x file
using tools/net/sunrpc/xdrgen/xdrgen.

The goals of replacing hand-written XDR functions with ones that
are tool-generated are to improve memory safety and make XDR
encoding and decoding less brittle to maintain. Parts of the
NFSv4 protocol are still being extended actively. Tool-generated
XDR code reduces the time it takes to get a working implementation
of new protocol elements.

The xdrgen utility derives both the type definitions and the
encode/decode functions directly from protocol specifications,
using names and symbols familiar to anyone who knows those specs.
Unlike hand-written code that can inadvertently diverge from the
specification, xdrgen guarantees that the generated code matches
the specification exactly.

We would eventually like xdrgen to generate Rust code as well,
making the conversion of the kernel's NFS stacks to use Rust just
a little easier for us.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
2026-06-09 16:32:59 -04:00

715 lines
18 KiB
C

// SPDX-License-Identifier: GPL-2.0
// Generated by xdrgen. Manual edits will be lost.
// XDR specification file: ../../Documentation/sunrpc/xdr/nlm3.x
// XDR specification modification time: Thu Apr 23 10:56:34 2026
#include <linux/sunrpc/svc.h>
#include "nlm3xdr_gen.h"
static bool __maybe_unused
xdrgen_decode_netobj(struct xdr_stream *xdr, netobj *ptr)
{
return xdrgen_decode_opaque(xdr, ptr, MAXNETOBJ_SZ);
}
static bool __maybe_unused
xdrgen_decode_nlm_stats(struct xdr_stream *xdr, nlm_stats *ptr)
{
__be32 raw;
u32 val;
if (xdr_stream_decode_be32(xdr, &raw) < 0)
return false;
val = be32_to_cpu(raw);
/* Compiler may optimize to a range check for dense enums */
switch (val) {
case LCK_GRANTED:
case LCK_DENIED:
case LCK_DENIED_NOLOCKS:
case LCK_BLOCKED:
case LCK_DENIED_GRACE_PERIOD:
break;
default:
return false;
}
*ptr = raw;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_stat(struct xdr_stream *xdr, struct nlm_stat *ptr)
{
if (!xdrgen_decode_nlm_stats(xdr, &ptr->stat))
return false;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_res(struct xdr_stream *xdr, struct nlm_res *ptr)
{
if (!xdrgen_decode_netobj(xdr, &ptr->cookie))
return false;
if (!xdrgen_decode_nlm_stat(xdr, &ptr->stat))
return false;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_holder(struct xdr_stream *xdr, struct nlm_holder *ptr)
{
if (!xdrgen_decode_bool(xdr, &ptr->exclusive))
return false;
if (!xdrgen_decode_int(xdr, &ptr->uppid))
return false;
if (!xdrgen_decode_netobj(xdr, &ptr->oh))
return false;
if (!xdrgen_decode_unsigned_int(xdr, &ptr->l_offset))
return false;
if (!xdrgen_decode_unsigned_int(xdr, &ptr->l_len))
return false;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_testrply(struct xdr_stream *xdr, struct nlm_testrply *ptr)
{
if (!xdrgen_decode_nlm_stats(xdr, &ptr->stat))
return false;
switch (ptr->stat) {
case __constant_cpu_to_be32(LCK_DENIED):
if (!xdrgen_decode_nlm_holder(xdr, &ptr->u.holder))
return false;
break;
default:
break;
}
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_testres(struct xdr_stream *xdr, struct nlm_testres *ptr)
{
if (!xdrgen_decode_netobj(xdr, &ptr->cookie))
return false;
if (!xdrgen_decode_nlm_testrply(xdr, &ptr->test_stat))
return false;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_lock(struct xdr_stream *xdr, struct nlm_lock *ptr)
{
if (!xdrgen_decode_string(xdr, (string *)ptr, LM_MAXSTRLEN))
return false;
if (!xdrgen_decode_netobj(xdr, &ptr->fh))
return false;
if (!xdrgen_decode_netobj(xdr, &ptr->oh))
return false;
if (!xdrgen_decode_int(xdr, &ptr->uppid))
return false;
if (!xdrgen_decode_unsigned_int(xdr, &ptr->l_offset))
return false;
if (!xdrgen_decode_unsigned_int(xdr, &ptr->l_len))
return false;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_lockargs(struct xdr_stream *xdr, struct nlm_lockargs *ptr)
{
if (!xdrgen_decode_netobj(xdr, &ptr->cookie))
return false;
if (!xdrgen_decode_bool(xdr, &ptr->block))
return false;
if (!xdrgen_decode_bool(xdr, &ptr->exclusive))
return false;
if (!xdrgen_decode_nlm_lock(xdr, &ptr->alock))
return false;
if (!xdrgen_decode_bool(xdr, &ptr->reclaim))
return false;
if (!xdrgen_decode_int(xdr, &ptr->state))
return false;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_cancargs(struct xdr_stream *xdr, struct nlm_cancargs *ptr)
{
if (!xdrgen_decode_netobj(xdr, &ptr->cookie))
return false;
if (!xdrgen_decode_bool(xdr, &ptr->block))
return false;
if (!xdrgen_decode_bool(xdr, &ptr->exclusive))
return false;
if (!xdrgen_decode_nlm_lock(xdr, &ptr->alock))
return false;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_testargs(struct xdr_stream *xdr, struct nlm_testargs *ptr)
{
if (!xdrgen_decode_netobj(xdr, &ptr->cookie))
return false;
if (!xdrgen_decode_bool(xdr, &ptr->exclusive))
return false;
if (!xdrgen_decode_nlm_lock(xdr, &ptr->alock))
return false;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_unlockargs(struct xdr_stream *xdr, struct nlm_unlockargs *ptr)
{
if (!xdrgen_decode_netobj(xdr, &ptr->cookie))
return false;
if (!xdrgen_decode_nlm_lock(xdr, &ptr->alock))
return false;
return true;
}
static bool __maybe_unused
xdrgen_decode_fsh_mode(struct xdr_stream *xdr, fsh_mode *ptr)
{
u32 val;
if (xdr_stream_decode_u32(xdr, &val) < 0)
return false;
/* Compiler may optimize to a range check for dense enums */
switch (val) {
case fsm_DN:
case fsm_DR:
case fsm_DW:
case fsm_DRW:
break;
default:
return false;
}
*ptr = val;
return true;
}
static bool __maybe_unused
xdrgen_decode_fsh_access(struct xdr_stream *xdr, fsh_access *ptr)
{
u32 val;
if (xdr_stream_decode_u32(xdr, &val) < 0)
return false;
/* Compiler may optimize to a range check for dense enums */
switch (val) {
case fsa_NONE:
case fsa_R:
case fsa_W:
case fsa_RW:
break;
default:
return false;
}
*ptr = val;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_share(struct xdr_stream *xdr, struct nlm_share *ptr)
{
if (!xdrgen_decode_string(xdr, (string *)ptr, LM_MAXSTRLEN))
return false;
if (!xdrgen_decode_netobj(xdr, &ptr->fh))
return false;
if (!xdrgen_decode_netobj(xdr, &ptr->oh))
return false;
if (!xdrgen_decode_fsh_mode(xdr, &ptr->mode))
return false;
if (!xdrgen_decode_fsh_access(xdr, &ptr->access))
return false;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_shareargs(struct xdr_stream *xdr, struct nlm_shareargs *ptr)
{
if (!xdrgen_decode_netobj(xdr, &ptr->cookie))
return false;
if (!xdrgen_decode_nlm_share(xdr, &ptr->share))
return false;
if (!xdrgen_decode_bool(xdr, &ptr->reclaim))
return false;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_shareres(struct xdr_stream *xdr, struct nlm_shareres *ptr)
{
if (!xdrgen_decode_netobj(xdr, &ptr->cookie))
return false;
if (!xdrgen_decode_nlm_stats(xdr, &ptr->stat))
return false;
if (!xdrgen_decode_int(xdr, &ptr->sequence))
return false;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_notify(struct xdr_stream *xdr, struct nlm_notify *ptr)
{
if (!xdrgen_decode_string(xdr, (string *)ptr, LM_MAXNAMELEN))
return false;
if (!xdrgen_decode_long(xdr, &ptr->state))
return false;
return true;
}
static bool __maybe_unused
xdrgen_decode_nlm_notifyargs(struct xdr_stream *xdr, struct nlm_notifyargs *ptr)
{
if (!xdrgen_decode_nlm_notify(xdr, &ptr->notify))
return false;
if (xdr_stream_decode_opaque_fixed(xdr, ptr->private, SM_PRIV_SIZE) < 0)
return false;
return true;
}
/**
* nlm_svc_decode_void - Decode a void argument
* @rqstp: RPC transaction context
* @xdr: source XDR data stream
*
* Return values:
* %true: procedure arguments decoded successfully
* %false: decode failed
*/
bool nlm_svc_decode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
return xdrgen_decode_void(xdr);
}
/**
* nlm_svc_decode_nlm_testargs - Decode a nlm_testargs argument
* @rqstp: RPC transaction context
* @xdr: source XDR data stream
*
* Return values:
* %true: procedure arguments decoded successfully
* %false: decode failed
*/
bool nlm_svc_decode_nlm_testargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
struct nlm_testargs *argp = rqstp->rq_argp;
return xdrgen_decode_nlm_testargs(xdr, argp);
}
/**
* nlm_svc_decode_nlm_lockargs - Decode a nlm_lockargs argument
* @rqstp: RPC transaction context
* @xdr: source XDR data stream
*
* Return values:
* %true: procedure arguments decoded successfully
* %false: decode failed
*/
bool nlm_svc_decode_nlm_lockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
struct nlm_lockargs *argp = rqstp->rq_argp;
return xdrgen_decode_nlm_lockargs(xdr, argp);
}
/**
* nlm_svc_decode_nlm_cancargs - Decode a nlm_cancargs argument
* @rqstp: RPC transaction context
* @xdr: source XDR data stream
*
* Return values:
* %true: procedure arguments decoded successfully
* %false: decode failed
*/
bool nlm_svc_decode_nlm_cancargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
struct nlm_cancargs *argp = rqstp->rq_argp;
return xdrgen_decode_nlm_cancargs(xdr, argp);
}
/**
* nlm_svc_decode_nlm_unlockargs - Decode a nlm_unlockargs argument
* @rqstp: RPC transaction context
* @xdr: source XDR data stream
*
* Return values:
* %true: procedure arguments decoded successfully
* %false: decode failed
*/
bool nlm_svc_decode_nlm_unlockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
struct nlm_unlockargs *argp = rqstp->rq_argp;
return xdrgen_decode_nlm_unlockargs(xdr, argp);
}
/**
* nlm_svc_decode_nlm_testres - Decode a nlm_testres argument
* @rqstp: RPC transaction context
* @xdr: source XDR data stream
*
* Return values:
* %true: procedure arguments decoded successfully
* %false: decode failed
*/
bool nlm_svc_decode_nlm_testres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
struct nlm_testres *argp = rqstp->rq_argp;
return xdrgen_decode_nlm_testres(xdr, argp);
}
/**
* nlm_svc_decode_nlm_res - Decode a nlm_res argument
* @rqstp: RPC transaction context
* @xdr: source XDR data stream
*
* Return values:
* %true: procedure arguments decoded successfully
* %false: decode failed
*/
bool nlm_svc_decode_nlm_res(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
struct nlm_res *argp = rqstp->rq_argp;
return xdrgen_decode_nlm_res(xdr, argp);
}
/**
* nlm_svc_decode_nlm_notifyargs - Decode a nlm_notifyargs argument
* @rqstp: RPC transaction context
* @xdr: source XDR data stream
*
* Return values:
* %true: procedure arguments decoded successfully
* %false: decode failed
*/
bool nlm_svc_decode_nlm_notifyargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
struct nlm_notifyargs *argp = rqstp->rq_argp;
return xdrgen_decode_nlm_notifyargs(xdr, argp);
}
/**
* nlm_svc_decode_nlm_shareargs - Decode a nlm_shareargs argument
* @rqstp: RPC transaction context
* @xdr: source XDR data stream
*
* Return values:
* %true: procedure arguments decoded successfully
* %false: decode failed
*/
bool nlm_svc_decode_nlm_shareargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
struct nlm_shareargs *argp = rqstp->rq_argp;
return xdrgen_decode_nlm_shareargs(xdr, argp);
}
/**
* nlm_svc_decode_nlm_notify - Decode a nlm_notify argument
* @rqstp: RPC transaction context
* @xdr: source XDR data stream
*
* Return values:
* %true: procedure arguments decoded successfully
* %false: decode failed
*/
bool nlm_svc_decode_nlm_notify(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
struct nlm_notify *argp = rqstp->rq_argp;
return xdrgen_decode_nlm_notify(xdr, argp);
}
static bool __maybe_unused
xdrgen_encode_netobj(struct xdr_stream *xdr, const netobj value)
{
return xdr_stream_encode_opaque(xdr, value.data, value.len) >= 0;
}
static bool __maybe_unused
xdrgen_encode_nlm_stats(struct xdr_stream *xdr, nlm_stats value)
{
return xdr_stream_encode_be32(xdr, value) == XDR_UNIT;
}
static bool __maybe_unused
xdrgen_encode_nlm_stat(struct xdr_stream *xdr, const struct nlm_stat *value)
{
if (!xdrgen_encode_nlm_stats(xdr, value->stat))
return false;
return true;
}
static bool __maybe_unused
xdrgen_encode_nlm_res(struct xdr_stream *xdr, const struct nlm_res *value)
{
if (!xdrgen_encode_netobj(xdr, value->cookie))
return false;
if (!xdrgen_encode_nlm_stat(xdr, &value->stat))
return false;
return true;
}
static bool __maybe_unused
xdrgen_encode_nlm_holder(struct xdr_stream *xdr, const struct nlm_holder *value)
{
if (!xdrgen_encode_bool(xdr, value->exclusive))
return false;
if (!xdrgen_encode_int(xdr, value->uppid))
return false;
if (!xdrgen_encode_netobj(xdr, value->oh))
return false;
if (!xdrgen_encode_unsigned_int(xdr, value->l_offset))
return false;
if (!xdrgen_encode_unsigned_int(xdr, value->l_len))
return false;
return true;
}
static bool __maybe_unused
xdrgen_encode_nlm_testrply(struct xdr_stream *xdr, const struct nlm_testrply *ptr)
{
if (!xdrgen_encode_nlm_stats(xdr, ptr->stat))
return false;
switch (ptr->stat) {
case __constant_cpu_to_be32(LCK_DENIED):
if (!xdrgen_encode_nlm_holder(xdr, &ptr->u.holder))
return false;
break;
default:
break;
}
return true;
}
static bool __maybe_unused
xdrgen_encode_nlm_testres(struct xdr_stream *xdr, const struct nlm_testres *value)
{
if (!xdrgen_encode_netobj(xdr, value->cookie))
return false;
if (!xdrgen_encode_nlm_testrply(xdr, &value->test_stat))
return false;
return true;
}
static bool __maybe_unused
xdrgen_encode_nlm_lock(struct xdr_stream *xdr, const struct nlm_lock *value)
{
if (value->caller_name.len > LM_MAXSTRLEN)
return false;
if (xdr_stream_encode_opaque(xdr, value->caller_name.data, value->caller_name.len) < 0)
return false;
if (!xdrgen_encode_netobj(xdr, value->fh))
return false;
if (!xdrgen_encode_netobj(xdr, value->oh))
return false;
if (!xdrgen_encode_int(xdr, value->uppid))
return false;
if (!xdrgen_encode_unsigned_int(xdr, value->l_offset))
return false;
if (!xdrgen_encode_unsigned_int(xdr, value->l_len))
return false;
return true;
}
static bool __maybe_unused
xdrgen_encode_nlm_lockargs(struct xdr_stream *xdr, const struct nlm_lockargs *value)
{
if (!xdrgen_encode_netobj(xdr, value->cookie))
return false;
if (!xdrgen_encode_bool(xdr, value->block))
return false;
if (!xdrgen_encode_bool(xdr, value->exclusive))
return false;
if (!xdrgen_encode_nlm_lock(xdr, &value->alock))
return false;
if (!xdrgen_encode_bool(xdr, value->reclaim))
return false;
if (!xdrgen_encode_int(xdr, value->state))
return false;
return true;
}
static bool __maybe_unused
xdrgen_encode_nlm_cancargs(struct xdr_stream *xdr, const struct nlm_cancargs *value)
{
if (!xdrgen_encode_netobj(xdr, value->cookie))
return false;
if (!xdrgen_encode_bool(xdr, value->block))
return false;
if (!xdrgen_encode_bool(xdr, value->exclusive))
return false;
if (!xdrgen_encode_nlm_lock(xdr, &value->alock))
return false;
return true;
}
static bool __maybe_unused
xdrgen_encode_nlm_testargs(struct xdr_stream *xdr, const struct nlm_testargs *value)
{
if (!xdrgen_encode_netobj(xdr, value->cookie))
return false;
if (!xdrgen_encode_bool(xdr, value->exclusive))
return false;
if (!xdrgen_encode_nlm_lock(xdr, &value->alock))
return false;
return true;
}
static bool __maybe_unused
xdrgen_encode_nlm_unlockargs(struct xdr_stream *xdr, const struct nlm_unlockargs *value)
{
if (!xdrgen_encode_netobj(xdr, value->cookie))
return false;
if (!xdrgen_encode_nlm_lock(xdr, &value->alock))
return false;
return true;
}
static bool __maybe_unused
xdrgen_encode_fsh_mode(struct xdr_stream *xdr, fsh_mode value)
{
return xdr_stream_encode_u32(xdr, value) == XDR_UNIT;
}
static bool __maybe_unused
xdrgen_encode_fsh_access(struct xdr_stream *xdr, fsh_access value)
{
return xdr_stream_encode_u32(xdr, value) == XDR_UNIT;
}
static bool __maybe_unused
xdrgen_encode_nlm_share(struct xdr_stream *xdr, const struct nlm_share *value)
{
if (value->caller_name.len > LM_MAXSTRLEN)
return false;
if (xdr_stream_encode_opaque(xdr, value->caller_name.data, value->caller_name.len) < 0)
return false;
if (!xdrgen_encode_netobj(xdr, value->fh))
return false;
if (!xdrgen_encode_netobj(xdr, value->oh))
return false;
if (!xdrgen_encode_fsh_mode(xdr, value->mode))
return false;
if (!xdrgen_encode_fsh_access(xdr, value->access))
return false;
return true;
}
static bool __maybe_unused
xdrgen_encode_nlm_shareargs(struct xdr_stream *xdr, const struct nlm_shareargs *value)
{
if (!xdrgen_encode_netobj(xdr, value->cookie))
return false;
if (!xdrgen_encode_nlm_share(xdr, &value->share))
return false;
if (!xdrgen_encode_bool(xdr, value->reclaim))
return false;
return true;
}
static bool __maybe_unused
xdrgen_encode_nlm_shareres(struct xdr_stream *xdr, const struct nlm_shareres *value)
{
if (!xdrgen_encode_netobj(xdr, value->cookie))
return false;
if (!xdrgen_encode_nlm_stats(xdr, value->stat))
return false;
if (!xdrgen_encode_int(xdr, value->sequence))
return false;
return true;
}
static bool __maybe_unused
xdrgen_encode_nlm_notify(struct xdr_stream *xdr, const struct nlm_notify *value)
{
if (value->name.len > LM_MAXNAMELEN)
return false;
if (xdr_stream_encode_opaque(xdr, value->name.data, value->name.len) < 0)
return false;
if (!xdrgen_encode_long(xdr, value->state))
return false;
return true;
}
static bool __maybe_unused
xdrgen_encode_nlm_notifyargs(struct xdr_stream *xdr, const struct nlm_notifyargs *value)
{
if (!xdrgen_encode_nlm_notify(xdr, &value->notify))
return false;
if (xdr_stream_encode_opaque_fixed(xdr, value->private, SM_PRIV_SIZE) < 0)
return false;
return true;
}
/**
* nlm_svc_encode_void - Encode a void result
* @rqstp: RPC transaction context
* @xdr: target XDR data stream
*
* Return values:
* %true: procedure results encoded successfully
* %false: encode failed
*/
bool nlm_svc_encode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
return xdrgen_encode_void(xdr);
}
/**
* nlm_svc_encode_nlm_testres - Encode a nlm_testres result
* @rqstp: RPC transaction context
* @xdr: target XDR data stream
*
* Return values:
* %true: procedure results encoded successfully
* %false: encode failed
*/
bool nlm_svc_encode_nlm_testres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
struct nlm_testres *resp = rqstp->rq_resp;
return xdrgen_encode_nlm_testres(xdr, resp);
}
/**
* nlm_svc_encode_nlm_res - Encode a nlm_res result
* @rqstp: RPC transaction context
* @xdr: target XDR data stream
*
* Return values:
* %true: procedure results encoded successfully
* %false: encode failed
*/
bool nlm_svc_encode_nlm_res(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
struct nlm_res *resp = rqstp->rq_resp;
return xdrgen_encode_nlm_res(xdr, resp);
}
/**
* nlm_svc_encode_nlm_shareres - Encode a nlm_shareres result
* @rqstp: RPC transaction context
* @xdr: target XDR data stream
*
* Return values:
* %true: procedure results encoded successfully
* %false: encode failed
*/
bool nlm_svc_encode_nlm_shareres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
{
struct nlm_shareres *resp = rqstp->rq_resp;
return xdrgen_encode_nlm_shareres(xdr, resp);
}