linux/Documentation/sunrpc/xdr/nlm3.x
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

169 lines
2.9 KiB
Plaintext

/*
* This file was extracted by hand from
* https://pubs.opengroup.org/onlinepubs/9629799/chap10.htm#tagcjh_11_03
*/
/*
* The NLMv3 protocol
*/
pragma header nlm3;
const LM_MAXSTRLEN = 1024;
const LM_MAXNAMELEN = 1025;
const MAXNETOBJ_SZ = 1024;
typedef opaque netobj<MAXNETOBJ_SZ>;
enum nlm_stats {
LCK_GRANTED = 0,
LCK_DENIED = 1,
LCK_DENIED_NOLOCKS = 2,
LCK_BLOCKED = 3,
LCK_DENIED_GRACE_PERIOD = 4
};
pragma big_endian nlm_stats;
struct nlm_stat {
nlm_stats stat;
};
struct nlm_res {
netobj cookie;
nlm_stat stat;
};
struct nlm_holder {
bool exclusive;
int uppid;
netobj oh;
unsigned int l_offset;
unsigned int l_len;
};
union nlm_testrply switch (nlm_stats stat) {
case LCK_DENIED:
nlm_holder holder;
default:
void;
};
struct nlm_testres {
netobj cookie;
nlm_testrply test_stat;
};
struct nlm_lock {
string caller_name<LM_MAXSTRLEN>;
netobj fh;
netobj oh;
int uppid;
unsigned int l_offset;
unsigned int l_len;
};
struct nlm_lockargs {
netobj cookie;
bool block;
bool exclusive;
nlm_lock alock;
bool reclaim;
int state;
};
struct nlm_cancargs {
netobj cookie;
bool block;
bool exclusive;
nlm_lock alock;
};
struct nlm_testargs {
netobj cookie;
bool exclusive;
nlm_lock alock;
};
struct nlm_unlockargs {
netobj cookie;
nlm_lock alock;
};
enum fsh_mode {
fsm_DN = 0,
fsm_DR = 1,
fsm_DW = 2,
fsm_DRW = 3
};
enum fsh_access {
fsa_NONE = 0,
fsa_R = 1,
fsa_W = 2,
fsa_RW = 3
};
struct nlm_share {
string caller_name<LM_MAXSTRLEN>;
netobj fh;
netobj oh;
fsh_mode mode;
fsh_access access;
};
struct nlm_shareargs {
netobj cookie;
nlm_share share;
bool reclaim;
};
struct nlm_shareres {
netobj cookie;
nlm_stats stat;
int sequence;
};
struct nlm_notify {
string name<LM_MAXNAMELEN>;
long state;
};
/*
* Argument for the Linux-private SM_NOTIFY procedure
*/
const SM_PRIV_SIZE = 16;
struct nlm_notifyargs {
nlm_notify notify;
opaque private[SM_PRIV_SIZE];
};
program NLM_PROG {
version NLM_VERS {
void NLM_NULL(void) = 0;
nlm_testres NLM_TEST(nlm_testargs) = 1;
nlm_res NLM_LOCK(nlm_lockargs) = 2;
nlm_res NLM_CANCEL(nlm_cancargs) = 3;
nlm_res NLM_UNLOCK(nlm_unlockargs) = 4;
nlm_res NLM_GRANTED(nlm_testargs) = 5;
void NLM_TEST_MSG(nlm_testargs) = 6;
void NLM_LOCK_MSG(nlm_lockargs) = 7;
void NLM_CANCEL_MSG(nlm_cancargs) = 8;
void NLM_UNLOCK_MSG(nlm_unlockargs) = 9;
void NLM_GRANTED_MSG(nlm_testargs) = 10;
void NLM_TEST_RES(nlm_testres) = 11;
void NLM_LOCK_RES(nlm_res) = 12;
void NLM_CANCEL_RES(nlm_res) = 13;
void NLM_UNLOCK_RES(nlm_res) = 14;
void NLM_GRANTED_RES(nlm_res) = 15;
void NLM_SM_NOTIFY(nlm_notifyargs) = 16;
nlm_shareres NLM_SHARE(nlm_shareargs) = 20;
nlm_shareres NLM_UNSHARE(nlm_shareargs) = 21;
nlm_res NLM_NM_LOCK(nlm_lockargs) = 22;
void NLM_FREE_ALL(nlm_notify) = 23;
} = 3;
} = 100021;