Skip to contentSkip to conversation

lockd: Convert NLMv3 server-side procedures to xdrgen

PATCH In review Chuck Lever 2 participants 42 messages May 12 – May 14

Subsystems (3)
lore
Share & tools
lore

Chuck Lever

author maintainer
#0 lore raw

cover lockd: Convert NLMv3 server-side procedures to xdrgen

This series finishes the xdrgen migration of lockd's server-side stack. The companion NLMv4 work landed earlier; here the remaining hand-written XDR in fs/lockd/xdr.c is retired in favour of code generated from a new Documentation/sunrpc/xdr/nlm3.x.

XDR helpers now do wire-format conversion only. NLMv3's 32-bit range limit on TEST conflict-holder byte ranges is clamped at the proc function rather than inside loff_t_to_s32() in the encoder. The HP-UX zero-length cookie rewrite that svcxdr_decode_cookie() has carried since the original kernel import is dropped on the server side; the generated decoder reproduces the cookie verbatim, and neither NLM_TEST reply matching nor CANCEL_MSG depends on the substitution.

A wrapper struct bridges each generated argument type with lockd's legacy lockd_lock/lockd_cookie/lockd_res internals. Each handler reaches xdrgen-decoded fields through argp->xdrgen and the legacy layout through a wrapper member that the handler populates explicitly, typically in nlm3svc_lookup_file(). The core lockd helpers and the async callback path operate on the legacy types unchanged, which is what keeps the conversion incremental.

.pc_argzero is cleared for every converted procedure: the generated decoders fill the substructure they own, so the dispatch layer's zero-memset is no longer needed. The trade-off is that any wrapper field a handler reads must be initialized explicitly. lock members are populated by nlm3svc_lookup_file(), or on the GRANTED path by the new nlm_lock_to_lockd_lock() helper.

Five NLMv4 fixes at the head of the series and three cleanup patches at the tail bracket the conversion. The six lockd_ struct renames between them are split out so that each conversion patch reads as a single concern.

---
Chuck Lever (38):
lockd: Stop warning on nlm__int__drop_reply in !V4 cast_status
lockd: Correct kernel-doc status descriptions for NLMv4 GRANTED
lockd: Drop locks_init_lock() from nlm4_lock_to_lockd_lock()
lockd: Translate nlm__int__deadlock in __nlm4svc_proc_lock_msg()
lockd: Do not monitor when looking up the LOCK_MSG callback host
Documentation: Add the RPC language description of NLM version 3
lockd: Rename struct nlm_cookie to lockd_cookie
lockd: Rename struct nlm_lock to lockd_lock
lockd: Rename struct nlm_args to lockd_args
lockd: Rename struct nlm_res to lockd_res
lockd: Rename struct nlm_reboot to lockd_reboot
lockd: Rename struct nlm_share to lockd_share
lockd: Use xdrgen XDR functions for the NLMv3 NULL procedure
lockd: Use xdrgen XDR functions for the NLMv3 TEST procedure
lockd: Use xdrgen XDR functions for the NLMv3 LOCK procedure
lockd: Use xdrgen XDR functions for the NLMv3 CANCEL procedure
lockd: Use xdrgen XDR functions for the NLMv3 UNLOCK procedure
lockd: Use xdrgen XDR functions for the NLMv3 GRANTED procedure
lockd: Refactor nlmsvc_callback()
lockd: Use xdrgen XDR functions for the NLMv3 TEST_MSG procedure
lockd: Use xdrgen XDR functions for the NLMv3 LOCK_MSG procedure
lockd: Use xdrgen XDR functions for the NLMv3 CANCEL_MSG procedure
lockd: Use xdrgen XDR functions for the NLMv3 UNLOCK_MSG procedure
lockd: Use xdrgen XDR functions for the NLMv3 GRANTED_MSG procedure
lockd: Use xdrgen XDR functions for the NLMv3 TEST_RES procedure
lockd: Use xdrgen XDR functions for the NLMv3 LOCK_RES procedure
lockd: Use xdrgen XDR functions for the NLMv3 CANCEL_RES procedure
lockd: Use xdrgen XDR functions for the NLMv3 UNLOCK_RES procedure
lockd: Use xdrgen XDR functions for the NLMv3 GRANTED_RES procedure
lockd: Use xdrgen XDR functions for the NLMv3 SM_NOTIFY procedure
lockd: Convert NLMv3 server-side undefined procedures to xdrgen
lockd: Use xdrgen XDR functions for the NLMv3 SHARE procedure
lockd: Use xdrgen XDR functions for the NLMv3 UNSHARE procedure
lockd: Use xdrgen XDR functions for the NLMv3 NM_LOCK procedure
lockd: Use xdrgen XDR functions for the NLMv3 FREE_ALL procedure
lockd: Remove C macros that are no longer used
lockd: Remove dead code from fs/lockd/xdr.c
lockd: Unify cast_status

 Documentation/sunrpc/xdr/nlm3.x    |  168 ++++
 fs/lockd/Makefile                  |   19 +-
 fs/lockd/clnt4xdr.c                |   42 +-
 fs/lockd/clntlock.c                |    2 +-
 fs/lockd/clntproc.c                |   14 +-
 fs/lockd/clntxdr.c                 |   44 +-
 fs/lockd/host.c                    |    4 +-
 fs/lockd/lockd.h                   |   57 +-
 fs/lockd/mon.c                     |    2 +-
 fs/lockd/nlm3xdr_gen.c             |  714 ++++++++++++++
 fs/lockd/nlm3xdr_gen.h             |   32 +
 fs/lockd/share.h                   |    4 +-
 fs/lockd/svc4proc.c                |   69 +-
 fs/lockd/svclock.c                 |   38 +-
 fs/lockd/svcproc.c                 | 1844 ++++++++++++++++++++++++------------
 fs/lockd/svcshare.c                |    8 +-
 fs/lockd/svcsubs.c                 |    2 +-
 fs/lockd/svcxdr.h                  |  142 ---
 fs/lockd/trace.h                   |   16 +-
 fs/lockd/xdr.c                     |  354 -------
 fs/lockd/xdr.h                     |   39 +-
 include/linux/sunrpc/xdrgen/nlm3.h |  210 ++++
 22 files changed, 2538 insertions(+), 1286 deletions(-)

---
base-commit: b26490baad0b7318d763b5ad6e5ca2addb20b314
change-id: 20260427-nlm4-xdrgen-35bf1c6869b8

Best regards,

Signature · 1 line
Chuck Lever <[email protected]>
author maintainer
#1 lore raw

PATCH 1/38 lockd: Stop warning on nlm__int__drop_reply in !V4 cast_status

From: Chuck Lever <[email protected]>

cast_status folds internal lock-daemon sentinels into NLMv1/v3 wire status codes. The !CONFIG_LOCKD_V4 variant warns when an unrecognized status falls into the internal-sentinel range, gated by be32_to_cpu(status) >= 30000.

nlm__int__drop_reply is defined as cpu_to_be32(30000), so it sits at the lower edge of that range and trips pr_warn_once ("lockd: unhandled internal status %u"). The status is returned unchanged so the reply is still dropped, but every dropped reply on a !CONFIG_LOCKD_V4 build emits a spurious warning.

Compare against nlm__int__drop_reply directly so the warning still catches the genuinely unexpected sentinels deadlock, stale_fh, and failed (30001 through 30003) but excludes the legitimate dropped-reply marker.

Fixes d343fce148a4 ("[PATCH] knfsd: Allow lockd to drop replies as appropriate")
---
 fs/lockd/svcproc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/lockd/svcproc.c +1 -1
index c0a3487719e2..110e186802b6 100644
@@ -49,7 +49,7 @@ static inline __be32 cast_status(__be32 status)
 		status = nlm_lck_denied_nolocks;
 		break;
 	default:
-		if (be32_to_cpu(status) >= 30000)
+		if (be32_to_cpu(status) > be32_to_cpu(nlm__int__drop_reply))
 			pr_warn_once("lockd: unhandled internal status %u\n",
 				     be32_to_cpu(status));
 		break;
Signature · 1 line
2.54.0
author maintainer
#2 lore raw

PATCH 2/38 lockd: Correct kernel-doc status descriptions for NLMv4 GRANTED

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

NLM_GRANTED is a server-to-client callback; the local node responds in the role of the client. The kernel-doc for nlm4svc_proc_granted attributes NLM4_DENIED and NLM4_DENIED_GRACE_PERIOD to "the server", but per the Open Group XNFS specification the responder for this procedure is the client host, and NLM4_DENIED_GRACE_PERIOD identifies the client's own grace period after a reboot, not the server's.

Rewrite the descriptions to match the spec: NLM4_DENIED reflects the generic internal-resource-constraint failure, and NLM4_DENIED_GRACE_PERIOD attributes the grace period to the client host that received the callback.

Fixes 7a9f7c8f934e ("lockd: Use xdrgen XDR functions for the NLMv4 GRANTED procedure")
---
 fs/lockd/svc4proc.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
fs/lockd/svc4proc.c +6 -6
index 41cab858de57..fc9ed4abb7ca 100644
@@ -513,12 +513,12 @@ nlm4svc_proc_unlock(struct svc_rqst *rqstp)
  *   nlm4_res NLMPROC4_GRANTED(nlm4_testargs) = 5;
  *
  * Permissible procedure status codes:
- *   %NLM4_GRANTED:		The requested lock was granted.
- *   %NLM4_DENIED:		The server could not allocate the resources
- *				needed to process the request.
- *   %NLM4_DENIED_GRACE_PERIOD:	The server has recently restarted and is
- *				re-establishing existing locks, and is not
- *				yet ready to accept normal service requests.
+ *   %NLM4_GRANTED:		The granted lock was accepted.
+ *   %NLM4_DENIED:		The procedure failed, possibly due to
+ *				internal resource constraints.
+ *   %NLM4_DENIED_GRACE_PERIOD:	The client host recently restarted and
+ *				its NLM is re-establishing existing locks,
+ *				so it is not yet ready to accept callbacks.
  */
 static __be32
 nlm4svc_proc_granted(struct svc_rqst *rqstp)
Signature · 1 line
2.54.0
author maintainer
#3 lore raw

PATCH 3/38 lockd: Drop locks_init_lock() from nlm4_lock_to_lockd_lock()

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

The NLMv4 GRANTED helper passes the wrapper's lock to nlmclnt_grant(), which compares only fl_start, fl_end, svid, and fh, and the shared nlmclnt_lock_event tracepoint now sources its byte-range fields from fl_start and fl_end as well. Both fl_start and fl_end are set unconditionally by lockd_set_file_lock_range4() on the line below, so the locks_init_lock() call left no observable
effect: every other field of struct file_lock is unread on the GRANTED path.

---
 fs/lockd/svc4proc.c | 1 -
 1 file changed, 1 deletion(-)
fs/lockd/svc4proc.c +0 -1
index fc9ed4abb7ca..2bd71bc2b481 100644
@@ -119,7 +119,6 @@ nlm4_lock_to_nlm_lock(struct nlm_lock *lock, struct nlm4_lock *alock)
 	lock->oh.len = alock->oh.len;
 	lock->oh.data = alock->oh.data;
 	lock->svid = alock->svid;
-	locks_init_lock(&lock->fl);
 	lockd_set_file_lock_range4(&lock->fl, alock->l_offset, alock->l_len);
 	return nlm_granted;
 }
Signature · 1 line
2.54.0
author maintainer
#4 lore raw

PATCH 4/38 lockd: Translate nlm__int__deadlock in __nlm4svc_proc_lock_msg()

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

When nlmsvc_lock() detects a deadlock it returns the internal sentinel nlm__int__deadlock (30001), which version-specific handlers must translate to a wire-valid status before the reply is encoded. The xdrgen LOCK_MSG handler stores the sentinel unmodified in resp->status; the LOCK_RES callback then places 30001 on the v4 wire, where the client rejects the reply.

Commit 9e0d0c619407 ("lockd: Introduce nlm__int__deadlock") established the translation boundary and updated the synchronous v4 path nlm4svc_do_lock(), but the xdrgen LOCK_MSG handler added later in commit b2be4e28c23a ("lockd: Use xdrgen XDR functions for the NLMv4 LOCK_MSG procedure") missed the corresponding remap. Apply the same translation in __nlm4svc_proc_lock_msg() so deadlock results are reported as nlm4_deadlock on LOCK_RES.

Fixes b2be4e28c23a ("lockd: Use xdrgen XDR functions for the NLMv4 LOCK_MSG procedure")
---
 fs/lockd/svc4proc.c | 2 ++
 1 file changed, 2 insertions(+)
fs/lockd/svc4proc.c +2 -0
index 2bd71bc2b481..886b56317e5f 100644
@@ -668,6 +668,8 @@ __nlm4svc_proc_lock_msg(struct svc_rqst *rqstp, struct nlm_res *resp)
 	resp->status = nlmsvc_lock(rqstp, file, host, &argp->lock,
 				   argp->xdrgen.block, &resp->cookie,
 				   argp->xdrgen.reclaim);
+	if (resp->status == nlm__int__deadlock)
+		resp->status = nlm4_deadlock;
 	nlmsvc_release_lockowner(&argp->lock);
 
 out:
Signature · 1 line
2.54.0
author maintainer
#5 lore raw

PATCH 5/38 lockd: Do not monitor when looking up the LOCK_MSG callback host

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

A LOCK_MSG handler that fails to obtain a host returns rpc_system_err, which causes the dispatcher to send an RPC-level error rather than an NLM LOCK_RES denial. Before the xdrgen conversion, the outer host lookup was unmonitored, so an NSM upcall failure was reported back to the client through LOCK_RES with status nlm_lck_denied_nolocks generated by the inner helper.

The xdrgen conversion replaced the unmonitored lookup with nlm4svc_lookup_host(..., true). When nsm_monitor() fails, the outer lookup now returns NULL, so the procedure short-circuits to rpc_system_err and __nlm4svc_proc_lock_msg() never runs. The client therefore receives no LOCK_RES, regressing the legacy behavior.

The inner helper still performs a monitored lookup while building the LOCK_RES, so the outer call only needs an unmonitored host reference for the callback path. Pass false here to restore the previous semantics.

Fixes b2be4e28c23a ("lockd: Use xdrgen XDR functions for the NLMv4 LOCK_MSG procedure")
---
 fs/lockd/svc4proc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/lockd/svc4proc.c +1 -1
index 886b56317e5f..e3a6d69c1fa6 100644
@@ -698,7 +698,7 @@ static __be32 nlm4svc_proc_lock_msg(struct svc_rqst *rqstp)
 	struct nlm4_lockargs_wrapper *argp = rqstp->rq_argp;
 	struct nlm_host *host;
 
-	host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, true);
+	host = nlm4svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
 	if (!host)
 		return rpc_system_err;
 
Signature · 1 line
2.54.0
author maintainer
#6 lore raw

PATCH 6/38 Documentation: Add the RPC language description of NLM version 3

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

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.

---
 Documentation/sunrpc/xdr/nlm3.x    | 168 +++++++++
 fs/lockd/Makefile                  |  19 +-
 fs/lockd/nlm3xdr_gen.c             | 714 +++++++++++++++++++++++++++++++++++++
 fs/lockd/nlm3xdr_gen.h             |  32 ++
 include/linux/sunrpc/xdrgen/nlm3.h | 210 +++++++++++
 5 files changed, 1139 insertions(+), 4 deletions(-)
Documentation/sunrpc/xdr/nlm3.x new file +168 -0
new file mode 100644
index 000000000000..b2e704f7b864
@@ -0,0 +1,168 @@
+/*
+ * 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;
fs/lockd/Makefile +15 -4
index 808f0f2a7be1..951a74e4847a 100644
@@ -8,7 +8,8 @@ ccflags-y += -I$(src)			# needed for trace events
 obj-$(CONFIG_LOCKD) += lockd.o
 
 lockd-y := clntlock.o clntproc.o clntxdr.o host.o svc.o svclock.o \
-	   svcshare.o svcproc.o svcsubs.o mon.o trace.o xdr.o netlink.o
+	   svcshare.o svcproc.o svcsubs.o mon.o trace.o xdr.o netlink.o \
+	   nlm3xdr_gen.o
 lockd-$(CONFIG_LOCKD_V4) += clnt4xdr.o svc4proc.o nlm4xdr_gen.o
 lockd-$(CONFIG_PROC_FS) += procfs.o
 
@@ -25,17 +26,27 @@ lockd-$(CONFIG_PROC_FS) += procfs.o
 
 XDRGEN			= ../../tools/net/sunrpc/xdrgen/xdrgen
 
-XDRGEN_DEFINITIONS	= ../../include/linux/sunrpc/xdrgen/nlm4.h
-XDRGEN_DECLARATIONS	= nlm4xdr_gen.h
-XDRGEN_SOURCE		= nlm4xdr_gen.c
+XDRGEN_DEFINITIONS	= ../../include/linux/sunrpc/xdrgen/nlm4.h \
+			  ../../include/linux/sunrpc/xdrgen/nlm3.h
+XDRGEN_DECLARATIONS	= nlm4xdr_gen.h nlm3xdr_gen.h
+XDRGEN_SOURCE		= nlm4xdr_gen.c nlm3xdr_gen.c
 
 xdrgen: $(XDRGEN_DEFINITIONS) $(XDRGEN_DECLARATIONS) $(XDRGEN_SOURCE)
 
 ../../include/linux/sunrpc/xdrgen/nlm4.h: ../../Documentation/sunrpc/xdr/nlm4.x
 	$(XDRGEN) definitions $< > $@
 
+../../include/linux/sunrpc/xdrgen/nlm3.h: ../../Documentation/sunrpc/xdr/nlm3.x
+	$(XDRGEN) definitions $< > $@
+
 nlm4xdr_gen.h: ../../Documentation/sunrpc/xdr/nlm4.x
 	$(XDRGEN) declarations $< > $@
 
+nlm3xdr_gen.h: ../../Documentation/sunrpc/xdr/nlm3.x
+	$(XDRGEN) declarations $< > $@
+
 nlm4xdr_gen.c: ../../Documentation/sunrpc/xdr/nlm4.x
 	$(XDRGEN) source --peer server $< > $@
+
+nlm3xdr_gen.c: ../../Documentation/sunrpc/xdr/nlm3.x
+	$(XDRGEN) source --peer server $< > $@
fs/lockd/nlm3xdr_gen.c new file +714 -0

714 lines not on this page · raw message

fs/lockd/nlm3xdr_gen.h new file +32 -0
new file mode 100644
index 000000000000..c99038e99805
@@ -0,0 +1,32 @@
+/* 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 */
+
+#ifndef _LINUX_XDRGEN_NLM3_DECL_H
+#define _LINUX_XDRGEN_NLM3_DECL_H
+
+#include <linux/types.h>
+
+#include <linux/sunrpc/xdr.h>
+#include <linux/sunrpc/xdrgen/_defs.h>
+#include <linux/sunrpc/xdrgen/_builtins.h>
+#include <linux/sunrpc/xdrgen/nlm3.h>
+
+bool nlm_svc_decode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+bool nlm_svc_decode_nlm_testargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+bool nlm_svc_decode_nlm_lockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+bool nlm_svc_decode_nlm_cancargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+bool nlm_svc_decode_nlm_unlockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+bool nlm_svc_decode_nlm_testres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+bool nlm_svc_decode_nlm_res(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+bool nlm_svc_decode_nlm_notifyargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+bool nlm_svc_decode_nlm_shareargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+bool nlm_svc_decode_nlm_notify(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+
+bool nlm_svc_encode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+bool nlm_svc_encode_nlm_testres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+bool nlm_svc_encode_nlm_res(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+bool nlm_svc_encode_nlm_shareres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
+
+#endif /* _LINUX_XDRGEN_NLM3_DECL_H */
include/linux/sunrpc/xdrgen/nlm3.h new file +210 -0

210 lines not on this page · raw message

Signature · 1 line
2.54.0
author maintainer
#7 lore raw

PATCH 7/38 lockd: Rename struct nlm_cookie to lockd_cookie

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Machine-generated XDR types derived from the NLM specification use names that match the protocol. Internal lockd types with identical names cause compilation failures when machine-generated encoders replace hand-coded ones.

Rename the internal struct nlm_cookie type to lockd_cookie to prevent such collisions. The "lockd_" prefix distinguishes implementation-specific types from specified NLM protocol types.

---
 fs/lockd/clnt4xdr.c |  4 ++--
 fs/lockd/clntproc.c |  2 +-
 fs/lockd/clntxdr.c  |  4 ++--
 fs/lockd/lockd.h    |  6 +++---
 fs/lockd/svc4proc.c |  6 +++---
 fs/lockd/svclock.c  | 16 ++++++++--------
 fs/lockd/svcxdr.h   |  4 ++--
 fs/lockd/xdr.h      |  7 +++----
 8 files changed, 24 insertions(+), 25 deletions(-)
fs/lockd/clnt4xdr.c +2 -2
index 2058733eacf8..6d881f9702a9 100644
@@ -132,13 +132,13 @@ static int decode_netobj(struct xdr_stream *xdr,
  *	netobj cookie;
  */
 static void encode_cookie(struct xdr_stream *xdr,
-			  const struct nlm_cookie *cookie)
+			  const struct lockd_cookie *cookie)
 {
 	encode_netobj(xdr, (u8 *)&cookie->data, cookie->len);
 }
 
 static int decode_cookie(struct xdr_stream *xdr,
-			     struct nlm_cookie *cookie)
+			     struct lockd_cookie *cookie)
 {
 	u32 length;
 	__be32 *p;
fs/lockd/clntproc.c +1 -1
index 7f211008a5d2..50cfab2f31c7 100644
@@ -42,7 +42,7 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
  */
 static atomic_t	nlm_cookie = ATOMIC_INIT(0x1234);
 
-void nlmclnt_next_cookie(struct nlm_cookie *c)
+void nlmclnt_next_cookie(struct lockd_cookie *c)
 {
 	u32	cookie = atomic_inc_return(&nlm_cookie);
 
fs/lockd/clntxdr.c +2 -2
index 65555f5224b1..2a4d28847254 100644
@@ -130,13 +130,13 @@ static int decode_netobj(struct xdr_stream *xdr,
  *	netobj cookie;
  */
 static void encode_cookie(struct xdr_stream *xdr,
-			  const struct nlm_cookie *cookie)
+			  const struct lockd_cookie *cookie)
 {
 	encode_netobj(xdr, (u8 *)&cookie->data, cookie->len);
 }
 
 static int decode_cookie(struct xdr_stream *xdr,
-			 struct nlm_cookie *cookie)
+			 struct lockd_cookie *cookie)
 {
 	u32 length;
 	__be32 *p;
fs/lockd/lockd.h +3 -3
index 1db6cb352542..119818568507 100644
@@ -257,7 +257,7 @@ __be32		  nlmclnt_grant(const struct sockaddr *addr,
 void		  nlmclnt_recovery(struct nlm_host *);
 int		  nlmclnt_reclaim(struct nlm_host *, struct file_lock *,
 				  struct nlm_rqst *);
-void		  nlmclnt_next_cookie(struct nlm_cookie *);
+void		  nlmclnt_next_cookie(struct lockd_cookie *);
 
 #ifdef CONFIG_LOCKD_V4
 extern const struct rpc_version nlm_version4;
@@ -314,7 +314,7 @@ typedef int	  (*nlm_host_match_fn_t)(void *cur, struct nlm_host *ref);
 int		  lock_to_openmode(struct file_lock *);
 __be32		  nlmsvc_lock(struct svc_rqst *, struct nlm_file *,
 			      struct nlm_host *, struct nlm_lock *, int,
-			      struct nlm_cookie *, int);
+			      struct lockd_cookie *, int);
 __be32		  nlmsvc_unlock(struct net *net, struct nlm_file *, struct nlm_lock *);
 __be32		  nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
 			struct nlm_host *host, struct nlm_lock *lock,
@@ -323,7 +323,7 @@ __be32		  nlmsvc_cancel_blocked(struct net *net, struct nlm_file *, struct nlm_l
 void		  nlmsvc_retry_blocked(struct svc_rqst *rqstp);
 void		  nlmsvc_traverse_blocks(struct nlm_host *, struct nlm_file *,
 					nlm_host_match_fn_t match);
-void		  nlmsvc_grant_reply(struct nlm_cookie *, __be32);
+void		  nlmsvc_grant_reply(struct lockd_cookie *, __be32);
 void		  nlmsvc_release_call(struct nlm_rqst *);
 void		  nlmsvc_locks_init_private(struct file_lock *, struct nlm_host *, pid_t);
 int		  nlmsvc_dispatch(struct svc_rqst *rqstp);
fs/lockd/svc4proc.c +3 -3
index e3a6d69c1fa6..249ef49f1bcd 100644
@@ -39,7 +39,7 @@ static_assert(offsetof(struct nlm4_testargs_wrapper, xdrgen) == 0);
 
 struct nlm4_lockargs_wrapper {
 	struct nlm4_lockargs		xdrgen;
-	struct nlm_cookie		cookie;
+	struct lockd_cookie		cookie;
 	struct nlm_lock			lock;
 };
 
@@ -88,7 +88,7 @@ static_assert(offsetof(struct nlm4_testres_wrapper, xdrgen) == 0);
 
 struct nlm4_res_wrapper {
 	struct nlm4_res			xdrgen;
-	struct nlm_cookie		cookie;
+	struct lockd_cookie		cookie;
 };
 
 static_assert(offsetof(struct nlm4_res_wrapper, xdrgen) == 0);
@@ -100,7 +100,7 @@ struct nlm4_shareres_wrapper {
 static_assert(offsetof(struct nlm4_shareres_wrapper, xdrgen) == 0);
 
 static __be32
-nlm4_netobj_to_cookie(struct nlm_cookie *cookie, netobj *object)
+nlm4_netobj_to_cookie(struct lockd_cookie *cookie, netobj *object)
 {
 	if (object->len > NLM_MAXCOOKIELEN)
 		return nlm_lck_denied_nolocks;
fs/lockd/svclock.c +8 -8
index f4520149d6d7..7fb03042ebee 100644
@@ -48,7 +48,7 @@ static LIST_HEAD(nlm_blocked);
 static DEFINE_SPINLOCK(nlm_blocked_lock);
 
 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
-static const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
+static const char *nlmdbg_cookie2a(const struct lockd_cookie *cookie)
 {
 	/*
 	 * We can get away with a static buffer because this is only called
@@ -75,7 +75,7 @@ static const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
 	return buf;
 }
 #else
-static inline const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
+static inline const char *nlmdbg_cookie2a(const struct lockd_cookie *cookie)
 {
 	return "???";
 }
@@ -171,7 +171,7 @@ nlmsvc_lookup_block(struct nlm_file *file, struct nlm_lock *lock)
 	return NULL;
 }
 
-static inline int nlm_cookie_match(struct nlm_cookie *a, struct nlm_cookie *b)
+static int lockd_cookie_match(struct lockd_cookie *a, struct lockd_cookie *b)
 {
 	if (a->len != b->len)
 		return 0;
@@ -184,13 +184,13 @@ static inline int nlm_cookie_match(struct nlm_cookie *a, struct nlm_cookie *b)
  * Find a block with a given NLM cookie.
  */
 static inline struct nlm_block *
-nlmsvc_find_block(struct nlm_cookie *cookie)
+nlmsvc_find_block(struct lockd_cookie *cookie)
 {
 	struct nlm_block *block;
 
 	spin_lock(&nlm_blocked_lock);
 	list_for_each_entry(block, &nlm_blocked, b_list) {
-		if (nlm_cookie_match(&block->b_call->a_args.cookie,cookie))
+		if (lockd_cookie_match(&block->b_call->a_args.cookie, cookie))
 			goto found;
 	}
 	spin_unlock(&nlm_blocked_lock);
@@ -222,7 +222,7 @@ nlmsvc_find_block(struct nlm_cookie *cookie)
 static struct nlm_block *
 nlmsvc_create_block(struct svc_rqst *rqstp, struct nlm_host *host,
 		    struct nlm_file *file, struct nlm_lock *lock,
-		    struct nlm_cookie *cookie)
+		    struct lockd_cookie *cookie)
 {
 	struct nlm_block	*block;
 	struct nlm_rqst		*call = NULL;
@@ -477,7 +477,7 @@ nlmsvc_defer_lock_rqst(struct svc_rqst *rqstp, struct nlm_block *block)
 __be32
 nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
 	    struct nlm_host *host, struct nlm_lock *lock, int wait,
-	    struct nlm_cookie *cookie, int reclaim)
+	    struct lockd_cookie *cookie, int reclaim)
 {
 	struct inode		*inode __maybe_unused = nlmsvc_file_inode(file);
 	struct nlm_block	*block = NULL;
@@ -982,7 +982,7 @@ static const struct rpc_call_ops nlmsvc_grant_ops = {
  * block.
  */
 void
-nlmsvc_grant_reply(struct nlm_cookie *cookie, __be32 status)
+nlmsvc_grant_reply(struct lockd_cookie *cookie, __be32 status)
 {
 	struct nlm_block	*block;
 	struct file_lock	*fl;
fs/lockd/svcxdr.h +2 -2
index 4f1a451da5ba..911b5fd707b1 100644
@@ -70,7 +70,7 @@ svcxdr_decode_string(struct xdr_stream *xdr, char **data, unsigned int *data_len
  * specially.
  */
 static inline bool
-svcxdr_decode_cookie(struct xdr_stream *xdr, struct nlm_cookie *cookie)
+svcxdr_decode_cookie(struct xdr_stream *xdr, struct lockd_cookie *cookie)
 {
 	__be32 *p;
 	u32 len;
@@ -98,7 +98,7 @@ svcxdr_decode_cookie(struct xdr_stream *xdr, struct nlm_cookie *cookie)
 }
 
 static inline bool
-svcxdr_encode_cookie(struct xdr_stream *xdr, const struct nlm_cookie *cookie)
+svcxdr_encode_cookie(struct xdr_stream *xdr, const struct lockd_cookie *cookie)
 {
 	__be32 *p;
 
fs/lockd/xdr.h +3 -4
index 3c60817c4349..c7e0518862d7 100644
@@ -49,8 +49,7 @@ struct nlm_lock {
  *	32 bytes.
  */
 
-struct nlm_cookie
-{
+struct lockd_cookie {
 	unsigned char data[NLM_MAXCOOKIELEN];
 	unsigned int len;
 };
@@ -59,7 +58,7 @@ struct nlm_cookie
  * Generic lockd arguments for all but sm_notify
  */
 struct nlm_args {
-	struct nlm_cookie	cookie;
+	struct lockd_cookie	cookie;
 	struct nlm_lock		lock;
 	u32			block;
 	u32			reclaim;
@@ -73,7 +72,7 @@ struct nlm_args {
  * Generic lockd result
  */
 struct nlm_res {
-	struct nlm_cookie	cookie;
+	struct lockd_cookie	cookie;
 	__be32			status;
 	struct nlm_lock		lock;
 };
Signature · 1 line
2.54.0
author maintainer
#8 lore raw

PATCH 8/38 lockd: Rename struct nlm_lock to lockd_lock

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

A subsequent patch will convert fs/lockd/svcproc.c to use machine-generated XDR encoding and decoding functions in a manner similar to fs/lockd/svc4proc.c. Machine-generated types derived from the NLM specification will conflict with the internal types of the same name.

Rename the internal struct nlm_lock type to lockd_lock to avoid such naming conflicts.

---
 fs/lockd/clnt4xdr.c | 16 ++++++++--------
 fs/lockd/clntlock.c |  2 +-
 fs/lockd/clntproc.c |  2 +-
 fs/lockd/clntxdr.c  | 16 ++++++++--------
 fs/lockd/lockd.h    | 16 ++++++++--------
 fs/lockd/svc4proc.c | 30 +++++++++++++++---------------
 fs/lockd/svclock.c  | 22 +++++++++++-----------
 fs/lockd/svcproc.c  |  2 +-
 fs/lockd/svcsubs.c  |  2 +-
 fs/lockd/trace.h    |  4 ++--
 fs/lockd/xdr.c      |  8 ++++----
 fs/lockd/xdr.h      |  6 +++---
 12 files changed, 63 insertions(+), 63 deletions(-)
fs/lockd/clnt4xdr.c +8 -8
index 6d881f9702a9..8973711264cb 100644
@@ -63,7 +63,7 @@ static s64 loff_t_to_s64(loff_t offset)
 	return res;
 }
 
-static void nlm4_compute_offsets(const struct nlm_lock *lock,
+static void nlm4_compute_offsets(const struct lockd_lock *lock,
 				 u64 *l_offset, u64 *l_len)
 {
 	const struct file_lock *fl = &lock->fl;
@@ -240,7 +240,7 @@ static int decode_nlm4_stat(struct xdr_stream *xdr, __be32 *stat)
 static void encode_nlm4_holder(struct xdr_stream *xdr,
 			       const struct nlm_res *result)
 {
-	const struct nlm_lock *lock = &result->lock;
+	const struct lockd_lock *lock = &result->lock;
 	u64 l_offset, l_len;
 	__be32 *p;
 
@@ -256,7 +256,7 @@ static void encode_nlm4_holder(struct xdr_stream *xdr,
 
 static int decode_nlm4_holder(struct xdr_stream *xdr, struct nlm_res *result)
 {
-	struct nlm_lock *lock = &result->lock;
+	struct lockd_lock *lock = &result->lock;
 	struct file_lock *fl = &lock->fl;
 	u64 l_offset, l_len;
 	u32 exclusive;
@@ -317,7 +317,7 @@ static void encode_caller_name(struct xdr_stream *xdr, const char *name)
  *	};
  */
 static void encode_nlm4_lock(struct xdr_stream *xdr,
-			     const struct nlm_lock *lock)
+			     const struct lockd_lock *lock)
 {
 	u64 l_offset, l_len;
 	__be32 *p;
@@ -355,7 +355,7 @@ static void nlm4_xdr_enc_testargs(struct rpc_rqst *req,
 				  const void *data)
 {
 	const struct nlm_args *args = data;
-	const struct nlm_lock *lock = &args->lock;
+	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
 	encode_bool(xdr, lock->fl.c.flc_type == F_WRLCK);
@@ -377,7 +377,7 @@ static void nlm4_xdr_enc_lockargs(struct rpc_rqst *req,
 				  const void *data)
 {
 	const struct nlm_args *args = data;
-	const struct nlm_lock *lock = &args->lock;
+	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
 	encode_bool(xdr, args->block);
@@ -400,7 +400,7 @@ static void nlm4_xdr_enc_cancargs(struct rpc_rqst *req,
 				  const void *data)
 {
 	const struct nlm_args *args = data;
-	const struct nlm_lock *lock = &args->lock;
+	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
 	encode_bool(xdr, args->block);
@@ -419,7 +419,7 @@ static void nlm4_xdr_enc_unlockargs(struct rpc_rqst *req,
 				    const void *data)
 {
 	const struct nlm_args *args = data;
-	const struct nlm_lock *lock = &args->lock;
+	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
 	encode_nlm4_lock(xdr, lock);
fs/lockd/clntlock.c +1 -1
index 8fa30c42c92a..f797cc99f94d 100644
@@ -158,7 +158,7 @@ int nlmclnt_wait(struct nlm_wait *block, struct nlm_rqst *req, long timeout)
 /*
  * The server lockd has called us back to tell us the lock was granted
  */
-__be32 nlmclnt_grant(const struct sockaddr *addr, const struct nlm_lock *lock)
+__be32 nlmclnt_grant(const struct sockaddr *addr, const struct lockd_lock *lock)
 {
 	const struct file_lock *fl = &lock->fl;
 	const struct nfs_fh *fh = &lock->fh;
fs/lockd/clntproc.c +1 -1
index 50cfab2f31c7..1aa6597ae0b7 100644
@@ -129,7 +129,7 @@ static struct nlm_lockowner *nlmclnt_find_lockowner(struct nlm_host *host, fl_ow
 static void nlmclnt_setlockargs(struct nlm_rqst *req, struct file_lock *fl)
 {
 	struct nlm_args	*argp = &req->a_args;
-	struct nlm_lock	*lock = &argp->lock;
+	struct lockd_lock *lock = &argp->lock;
 	char *nodename = req->a_host->h_rpcclnt->cl_nodename;
 
 	nlmclnt_next_cookie(&argp->cookie);
fs/lockd/clntxdr.c +8 -8
index 2a4d28847254..efa45f12960d 100644
@@ -60,7 +60,7 @@ static s32 loff_t_to_s32(loff_t offset)
 	return res;
 }
 
-static void nlm_compute_offsets(const struct nlm_lock *lock,
+static void nlm_compute_offsets(const struct lockd_lock *lock,
 				u32 *l_offset, u32 *l_len)
 {
 	const struct file_lock *fl = &lock->fl;
@@ -236,7 +236,7 @@ static int decode_nlm_stat(struct xdr_stream *xdr,
 static void encode_nlm_holder(struct xdr_stream *xdr,
 			      const struct nlm_res *result)
 {
-	const struct nlm_lock *lock = &result->lock;
+	const struct lockd_lock *lock = &result->lock;
 	u32 l_offset, l_len;
 	__be32 *p;
 
@@ -252,7 +252,7 @@ static void encode_nlm_holder(struct xdr_stream *xdr,
 
 static int decode_nlm_holder(struct xdr_stream *xdr, struct nlm_res *result)
 {
-	struct nlm_lock *lock = &result->lock;
+	struct lockd_lock *lock = &result->lock;
 	struct file_lock *fl = &lock->fl;
 	u32 exclusive, l_offset, l_len;
 	int error;
@@ -319,7 +319,7 @@ static void encode_caller_name(struct xdr_stream *xdr, const char *name)
  *	};
  */
 static void encode_nlm_lock(struct xdr_stream *xdr,
-			    const struct nlm_lock *lock)
+			    const struct lockd_lock *lock)
 {
 	u32 l_offset, l_len;
 	__be32 *p;
@@ -356,7 +356,7 @@ static void nlm_xdr_enc_testargs(struct rpc_rqst *req,
 				 const void *data)
 {
 	const struct nlm_args *args = data;
-	const struct nlm_lock *lock = &args->lock;
+	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
 	encode_bool(xdr, lock->fl.c.flc_type == F_WRLCK);
@@ -378,7 +378,7 @@ static void nlm_xdr_enc_lockargs(struct rpc_rqst *req,
 				 const void *data)
 {
 	const struct nlm_args *args = data;
-	const struct nlm_lock *lock = &args->lock;
+	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
 	encode_bool(xdr, args->block);
@@ -401,7 +401,7 @@ static void nlm_xdr_enc_cancargs(struct rpc_rqst *req,
 				 const void *data)
 {
 	const struct nlm_args *args = data;
-	const struct nlm_lock *lock = &args->lock;
+	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
 	encode_bool(xdr, args->block);
@@ -420,7 +420,7 @@ static void nlm_xdr_enc_unlockargs(struct rpc_rqst *req,
 				   const void *data)
 {
 	const struct nlm_args *args = data;
-	const struct nlm_lock *lock = &args->lock;
+	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
 	encode_nlm_lock(xdr, lock);
fs/lockd/lockd.h +8 -8
index 119818568507..032790834c7e 100644
@@ -253,7 +253,7 @@ void		  nlmclnt_queue_block(struct nlm_wait *block);
 __be32		  nlmclnt_dequeue_block(struct nlm_wait *block);
 int		  nlmclnt_wait(struct nlm_wait *block, struct nlm_rqst *req, long timeout);
 __be32		  nlmclnt_grant(const struct sockaddr *addr,
-				const struct nlm_lock *lock);
+				const struct lockd_lock *lock);
 void		  nlmclnt_recovery(struct nlm_host *);
 int		  nlmclnt_reclaim(struct nlm_host *, struct file_lock *,
 				  struct nlm_rqst *);
@@ -313,13 +313,13 @@ typedef int	  (*nlm_host_match_fn_t)(void *cur, struct nlm_host *ref);
  */
 int		  lock_to_openmode(struct file_lock *);
 __be32		  nlmsvc_lock(struct svc_rqst *, struct nlm_file *,
-			      struct nlm_host *, struct nlm_lock *, int,
+			      struct nlm_host *, struct lockd_lock *, int,
 			      struct lockd_cookie *, int);
-__be32		  nlmsvc_unlock(struct net *net, struct nlm_file *, struct nlm_lock *);
+__be32		  nlmsvc_unlock(struct net *net, struct nlm_file *, struct lockd_lock *);
 __be32		  nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
-			struct nlm_host *host, struct nlm_lock *lock,
-			struct nlm_lock *conflock);
-__be32		  nlmsvc_cancel_blocked(struct net *net, struct nlm_file *, struct nlm_lock *);
+			struct nlm_host *host, struct lockd_lock *lock,
+			struct lockd_lock *conflock);
+__be32		  nlmsvc_cancel_blocked(struct net *net, struct nlm_file *, struct lockd_lock *);
 void		  nlmsvc_retry_blocked(struct svc_rqst *rqstp);
 void		  nlmsvc_traverse_blocks(struct nlm_host *, struct nlm_file *,
 					nlm_host_match_fn_t match);
@@ -332,10 +332,10 @@ int		  nlmsvc_dispatch(struct svc_rqst *rqstp);
  * File handling for the server personality
  */
 __be32		  nlm_lookup_file(struct svc_rqst *, struct nlm_file **,
-				  struct nlm_lock *, int);
+				  struct lockd_lock *, int);
 void		  nlm_release_file(struct nlm_file *);
 void		  nlmsvc_put_lockowner(struct nlm_lockowner *);
-void		  nlmsvc_release_lockowner(struct nlm_lock *);
+void		  nlmsvc_release_lockowner(struct lockd_lock *);
 void		  nlmsvc_mark_resources(struct net *);
 void		  nlmsvc_free_host_resources(struct nlm_host *);
 void		  nlmsvc_invalidate_all(void);
fs/lockd/svc4proc.c +15 -15
index 249ef49f1bcd..f7067fae6c86 100644
@@ -26,13 +26,13 @@
 #include "nlm4xdr_gen.h"
 
 /*
- * Wrapper structures combine xdrgen types with legacy nlm_lock.
+ * Wrapper structures combine xdrgen types with legacy lockd_lock.
  * The xdrgen field must be first so the structure can be cast
  * to its XDR type for the RPC dispatch layer.
  */
 struct nlm4_testargs_wrapper {
 	struct nlm4_testargs		xdrgen;
-	struct nlm_lock			lock;
+	struct lockd_lock		lock;
 };
 
 static_assert(offsetof(struct nlm4_testargs_wrapper, xdrgen) == 0);
@@ -40,21 +40,21 @@ static_assert(offsetof(struct nlm4_testargs_wrapper, xdrgen) == 0);
 struct nlm4_lockargs_wrapper {
 	struct nlm4_lockargs		xdrgen;
 	struct lockd_cookie		cookie;
-	struct nlm_lock			lock;
+	struct lockd_lock		lock;
 };
 
 static_assert(offsetof(struct nlm4_lockargs_wrapper, xdrgen) == 0);
 
 struct nlm4_cancargs_wrapper {
 	struct nlm4_cancargs		xdrgen;
-	struct nlm_lock			lock;
+	struct lockd_lock		lock;
 };
 
 static_assert(offsetof(struct nlm4_cancargs_wrapper, xdrgen) == 0);
 
 struct nlm4_unlockargs_wrapper {
 	struct nlm4_unlockargs		xdrgen;
-	struct nlm_lock			lock;
+	struct lockd_lock		lock;
 };
 
 static_assert(offsetof(struct nlm4_unlockargs_wrapper, xdrgen) == 0);
@@ -74,12 +74,12 @@ static_assert(offsetof(struct nlm4_notify_wrapper, xdrgen) == 0);
 
 struct nlm4_testres_wrapper {
 	struct nlm4_testres		xdrgen;
-	struct nlm_lock			lock;
+	struct lockd_lock		lock;
 };
 
 struct nlm4_shareargs_wrapper {
 	struct nlm4_shareargs		xdrgen;
-	struct nlm_lock			lock;
+	struct lockd_lock		lock;
 };
 
 static_assert(offsetof(struct nlm4_shareargs_wrapper, xdrgen) == 0);
@@ -110,7 +110,7 @@ nlm4_netobj_to_cookie(struct lockd_cookie *cookie, netobj *object)
 }
 
 static __be32
-nlm4_lock_to_nlm_lock(struct nlm_lock *lock, struct nlm4_lock *alock)
+nlm4_lock_to_lockd_lock(struct lockd_lock *lock, struct nlm4_lock *alock)
 {
 	if (alock->fh.len > NFS_MAXFHSIZE)
 		return nlm_lck_denied;
@@ -142,7 +142,7 @@ nlm4svc_lookup_host(struct svc_rqst *rqstp, string caller, bool monitored)
 
 static __be32
 nlm4svc_lookup_file(struct svc_rqst *rqstp, struct nlm_host *host,
-		    struct nlm_lock *lock, struct nlm_file **filp,
+		    struct lockd_lock *lock, struct nlm_file **filp,
 		    struct nlm4_lock *xdr_lock, unsigned char type)
 {
 	bool is_test = (rqstp->rq_proc == NLMPROC4_TEST ||
@@ -269,7 +269,7 @@ static __be32 nlm4svc_proc_test(struct svc_rqst *rqstp)
 	nlmsvc_release_lockowner(&argp->lock);
 
 	if (resp->xdrgen.stat.stat == nlm_lck_denied) {
-		struct nlm_lock *conf = &resp->lock;
+		struct lockd_lock *conf = &resp->lock;
 		struct nlm4_holder *holder = &resp->xdrgen.stat.u.holder;
 
 		holder->exclusive = (conf->fl.c.flc_type != F_RDLCK);
@@ -527,8 +527,8 @@ nlm4svc_proc_granted(struct svc_rqst *rqstp)
 
 	resp->xdrgen.cookie = argp->xdrgen.cookie;
 
-	resp->xdrgen.stat.stat = nlm4_lock_to_nlm_lock(&argp->lock,
-						       &argp->xdrgen.alock);
+	resp->xdrgen.stat.stat = nlm4_lock_to_lockd_lock(&argp->lock,
+							 &argp->xdrgen.alock);
 	if (resp->xdrgen.stat.stat)
 		goto out;
 
@@ -842,7 +842,7 @@ __nlm4svc_proc_granted_msg(struct svc_rqst *rqstp, struct nlm_res *resp)
 	if (nlm4_netobj_to_cookie(&resp->cookie, &argp->xdrgen.cookie))
 		goto out;
 
-	if (nlm4_lock_to_nlm_lock(&argp->lock, &argp->xdrgen.alock))
+	if (nlm4_lock_to_lockd_lock(&argp->lock, &argp->xdrgen.alock))
 		goto out;
 
 	resp->status = nlmclnt_grant(svc_addr(rqstp), &argp->lock);
@@ -982,7 +982,7 @@ static __be32 nlm4svc_proc_share(struct svc_rqst *rqstp)
 {
 	struct nlm4_shareargs_wrapper *argp = rqstp->rq_argp;
 	struct nlm4_shareres_wrapper *resp = rqstp->rq_resp;
-	struct nlm_lock	*lock = &argp->lock;
+	struct lockd_lock *lock = &argp->lock;
 	struct nlm_host	*host = NULL;
 	struct nlm_file	*file = NULL;
 	struct nlm4_lock xdr_lock = {
@@ -1050,7 +1050,7 @@ static __be32 nlm4svc_proc_unshare(struct svc_rqst *rqstp)
 {
 	struct nlm4_shareargs_wrapper *argp = rqstp->rq_argp;
 	struct nlm4_shareres_wrapper *resp = rqstp->rq_resp;
-	struct nlm_lock	*lock = &argp->lock;
+	struct lockd_lock *lock = &argp->lock;
 	struct nlm4_lock xdr_lock = {
 		.fh		= argp->xdrgen.share.fh,
 		.oh		= argp->xdrgen.share.oh,
fs/lockd/svclock.c +11 -11
index 7fb03042ebee..e48d31f14a65 100644
@@ -37,7 +37,7 @@ static void nlmsvc_release_block(struct nlm_block *block);
 static void	nlmsvc_insert_block(struct nlm_block *block, unsigned long);
 static void	nlmsvc_remove_block(struct nlm_block *block);
 
-static int nlmsvc_setgrantargs(struct nlm_rqst *call, struct nlm_lock *lock);
+static int nlmsvc_setgrantargs(struct nlm_rqst *call, struct lockd_lock *lock);
 static void nlmsvc_freegrantargs(struct nlm_rqst *call);
 static const struct rpc_call_ops nlmsvc_grant_ops;
 
@@ -142,7 +142,7 @@ nlmsvc_remove_block(struct nlm_block *block)
  * Find a block for a given lock
  */
 static struct nlm_block *
-nlmsvc_lookup_block(struct nlm_file *file, struct nlm_lock *lock)
+nlmsvc_lookup_block(struct nlm_file *file, struct lockd_lock *lock)
 {
 	struct nlm_block	*block;
 	struct file_lock	*fl;
@@ -221,7 +221,7 @@ nlmsvc_find_block(struct lockd_cookie *cookie)
  */
 static struct nlm_block *
 nlmsvc_create_block(struct svc_rqst *rqstp, struct nlm_host *host,
-		    struct nlm_file *file, struct nlm_lock *lock,
+		    struct nlm_file *file, struct lockd_lock *lock,
 		    struct lockd_cookie *cookie)
 {
 	struct nlm_block	*block;
@@ -399,7 +399,7 @@ static struct nlm_lockowner *nlmsvc_find_lockowner(struct nlm_host *host, pid_t
 }
 
 void
-nlmsvc_release_lockowner(struct nlm_lock *lock)
+nlmsvc_release_lockowner(struct lockd_lock *lock)
 {
 	if (lock->fl.c.flc_owner)
 		nlmsvc_put_lockowner(lock->fl.c.flc_owner);
@@ -415,7 +415,7 @@ void nlmsvc_locks_init_private(struct file_lock *fl, struct nlm_host *host,
  * Initialize arguments for GRANTED call. The nlm_rqst structure
  * has been cleared already.
  */
-static int nlmsvc_setgrantargs(struct nlm_rqst *call, struct nlm_lock *lock)
+static int nlmsvc_setgrantargs(struct nlm_rqst *call, struct lockd_lock *lock)
 {
 	locks_copy_lock(&call->a_args.lock.fl, &lock->fl);
 	memcpy(&call->a_args.lock.fh, &lock->fh, sizeof(call->a_args.lock.fh));
@@ -476,7 +476,7 @@ nlmsvc_defer_lock_rqst(struct svc_rqst *rqstp, struct nlm_block *block)
  */
 __be32
 nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
-	    struct nlm_host *host, struct nlm_lock *lock, int wait,
+	    struct nlm_host *host, struct lockd_lock *lock, int wait,
 	    struct lockd_cookie *cookie, int reclaim)
 {
 	struct inode		*inode __maybe_unused = nlmsvc_file_inode(file);
@@ -609,8 +609,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
  */
 __be32
 nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
-		struct nlm_host *host, struct nlm_lock *lock,
-		struct nlm_lock *conflock)
+		struct nlm_host *host, struct lockd_lock *lock,
+		struct lockd_lock *conflock)
 {
 	int			error;
 	__be32			ret;
@@ -669,7 +669,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
  * must be removed.
  */
 __be32
-nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)
+nlmsvc_unlock(struct net *net, struct nlm_file *file, struct lockd_lock *lock)
 {
 	int	error = 0;
 
@@ -707,7 +707,7 @@ nlmsvc_unlock(struct net *net, struct nlm_file *file, struct nlm_lock *lock)
  * The calling procedure must check whether the file can be closed.
  */
 __be32
-nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct nlm_lock *lock)
+nlmsvc_cancel_blocked(struct net *net, struct nlm_file *file, struct lockd_lock *lock)
 {
 	struct nlm_block	*block;
 	int status = 0;
@@ -848,7 +848,7 @@ static void
 nlmsvc_grant_blocked(struct nlm_block *block)
 {
 	struct nlm_file		*file = block->b_file;
-	struct nlm_lock		*lock = &block->b_call->a_args.lock;
+	struct lockd_lock	*lock = &block->b_call->a_args.lock;
 	int			mode;
 	int			error;
 	loff_t			fl_start, fl_end;
fs/lockd/svcproc.c +1 -1
index 110e186802b6..2e1dbd4e1df9 100644
@@ -67,7 +67,7 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,
 {
 	struct nlm_host		*host = NULL;
 	struct nlm_file		*file = NULL;
-	struct nlm_lock		*lock = &argp->lock;
+	struct lockd_lock	*lock = &argp->lock;
 	bool			is_test = (rqstp->rq_proc == NLMPROC_TEST ||
 					   rqstp->rq_proc == NLMPROC_TEST_MSG);
 	int			mode;
fs/lockd/svcsubs.c +1 -1
index 9da9d6e0b42e..e24bacea7e03 100644
@@ -132,7 +132,7 @@ static __be32 nlm_do_fopen(struct svc_rqst *rqstp,
  */
 __be32
 nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result,
-		struct nlm_lock *lock, int mode)
+		struct lockd_lock *lock, int mode)
 {
 	struct nlm_file	*file;
 	unsigned int	hash;
fs/lockd/trace.h +2 -2
index 7214d7e96a42..aa858d9d406d 100644
@@ -48,7 +48,7 @@ NLM_STATUS_LIST
 
 DECLARE_EVENT_CLASS(nlmclnt_lock_event,
 		TP_PROTO(
-			const struct nlm_lock *lock,
+			const struct lockd_lock *lock,
 			const struct sockaddr *addr,
 			unsigned int addrlen,
 			__be32 status
@@ -87,7 +87,7 @@ DECLARE_EVENT_CLASS(nlmclnt_lock_event,
 #define DEFINE_NLMCLNT_EVENT(name)				\
 	DEFINE_EVENT(nlmclnt_lock_event, name,			\
 			TP_PROTO(				\
-				const struct nlm_lock *lock,	\
+				const struct lockd_lock *lock,	\
 				const struct sockaddr *addr,	\
 				unsigned int addrlen,		\
 				__be32	status			\
fs/lockd/xdr.c +4 -4
index dfca8b8dab73..55868222984a 100644
@@ -69,7 +69,7 @@ svcxdr_decode_fhandle(struct xdr_stream *xdr, struct nfs_fh *fh)
 }
 
 static bool
-svcxdr_decode_lock(struct xdr_stream *xdr, struct nlm_lock *lock)
+svcxdr_decode_lock(struct xdr_stream *xdr, struct lockd_lock *lock)
 {
 	struct file_lock *fl = &lock->fl;
 	s32 start, len, end;
@@ -101,7 +101,7 @@ svcxdr_decode_lock(struct xdr_stream *xdr, struct nlm_lock *lock)
 }
 
 static bool
-svcxdr_encode_holder(struct xdr_stream *xdr, const struct nlm_lock *lock)
+svcxdr_encode_holder(struct xdr_stream *xdr, const struct lockd_lock *lock)
 {
 	const struct file_lock *fl = &lock->fl;
 	s32 start, len;
@@ -271,7 +271,7 @@ bool
 nlmsvc_decode_shareargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 {
 	struct nlm_args *argp = rqstp->rq_argp;
-	struct nlm_lock	*lock = &argp->lock;
+	struct lockd_lock *lock = &argp->lock;
 
 	memset(lock, 0, sizeof(*lock));
 	locks_init_lock(&lock->fl);
@@ -298,7 +298,7 @@ bool
 nlmsvc_decode_notify(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 {
 	struct nlm_args *argp = rqstp->rq_argp;
-	struct nlm_lock	*lock = &argp->lock;
+	struct lockd_lock *lock = &argp->lock;
 
 	if (!svcxdr_decode_string(xdr, &lock->caller, &lock->len))
 		return false;
fs/lockd/xdr.h +3 -3
index c7e0518862d7..805027d9b0fe 100644
@@ -32,7 +32,7 @@ struct svc_rqst;
 #define	nlm_lck_denied_grace_period	cpu_to_be32(NLM_LCK_DENIED_GRACE_PERIOD)
 
 /* Lock info passed via NLM */
-struct nlm_lock {
+struct lockd_lock {
 	char *			caller;
 	unsigned int		len; 	/* length of "caller" */
 	struct nfs_fh		fh;
@@ -59,7 +59,7 @@ struct lockd_cookie {
  */
 struct nlm_args {
 	struct lockd_cookie	cookie;
-	struct nlm_lock		lock;
+	struct lockd_lock	lock;
 	u32			block;
 	u32			reclaim;
 	u32			state;
@@ -74,7 +74,7 @@ struct nlm_args {
 struct nlm_res {
 	struct lockd_cookie	cookie;
 	__be32			status;
-	struct nlm_lock		lock;
+	struct lockd_lock	lock;
 };
 
 /*
Signature · 1 line
2.54.0
author maintainer
#9 lore raw

PATCH 9/38 lockd: Rename struct nlm_args to lockd_args

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

As part of the effort to enable lockd's server-side XDR functions to be generated from the NLM protocol specification (using xdrgen), the internal type names must be changed to avoid conflicts with the machine-generated type names.

Rename struct nlm_args to struct lockd_args to avoid conflicts with the NLMv3 XDR type definitions that will be introduced when svcproc.c is converted to use xdrgen.

---
 fs/lockd/clnt4xdr.c |  8 +++---
 fs/lockd/clntproc.c |  4 +--
 fs/lockd/clntxdr.c  |  8 +++---
 fs/lockd/lockd.h    |  2 +-
 fs/lockd/svcproc.c  | 80 ++++++++++++++++++++++++++---------------------------
 fs/lockd/xdr.c      | 12 ++++----
 fs/lockd/xdr.h      |  2 +-
 7 files changed, 58 insertions(+), 58 deletions(-)
fs/lockd/clnt4xdr.c +4 -4
index 8973711264cb..d0b08a12fe45 100644
@@ -354,7 +354,7 @@ static void nlm4_xdr_enc_testargs(struct rpc_rqst *req,
 				  struct xdr_stream *xdr,
 				  const void *data)
 {
-	const struct nlm_args *args = data;
+	const struct lockd_args *args = data;
 	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
@@ -376,7 +376,7 @@ static void nlm4_xdr_enc_lockargs(struct rpc_rqst *req,
 				  struct xdr_stream *xdr,
 				  const void *data)
 {
-	const struct nlm_args *args = data;
+	const struct lockd_args *args = data;
 	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
@@ -399,7 +399,7 @@ static void nlm4_xdr_enc_cancargs(struct rpc_rqst *req,
 				  struct xdr_stream *xdr,
 				  const void *data)
 {
-	const struct nlm_args *args = data;
+	const struct lockd_args *args = data;
 	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
@@ -418,7 +418,7 @@ static void nlm4_xdr_enc_unlockargs(struct rpc_rqst *req,
 				    struct xdr_stream *xdr,
 				    const void *data)
 {
-	const struct nlm_args *args = data;
+	const struct lockd_args *args = data;
 	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
fs/lockd/clntproc.c +2 -2
index 1aa6597ae0b7..abdf2a51caf2 100644
@@ -128,7 +128,7 @@ static struct nlm_lockowner *nlmclnt_find_lockowner(struct nlm_host *host, fl_ow
  */
 static void nlmclnt_setlockargs(struct nlm_rqst *req, struct file_lock *fl)
 {
-	struct nlm_args	*argp = &req->a_args;
+	struct lockd_args *argp = &req->a_args;
 	struct lockd_lock *lock = &argp->lock;
 	char *nodename = req->a_host->h_rpcclnt->cl_nodename;
 
@@ -266,7 +266,7 @@ nlmclnt_call(const struct cred *cred, struct nlm_rqst *req, u32 proc)
 {
 	struct nlm_host	*host = req->a_host;
 	struct rpc_clnt	*clnt;
-	struct nlm_args	*argp = &req->a_args;
+	struct lockd_args *argp = &req->a_args;
 	struct nlm_res	*resp = &req->a_res;
 	struct rpc_message msg = {
 		.rpc_argp	= argp,
fs/lockd/clntxdr.c +4 -4
index efa45f12960d..444a34bc799a 100644
@@ -355,7 +355,7 @@ static void nlm_xdr_enc_testargs(struct rpc_rqst *req,
 				 struct xdr_stream *xdr,
 				 const void *data)
 {
-	const struct nlm_args *args = data;
+	const struct lockd_args *args = data;
 	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
@@ -377,7 +377,7 @@ static void nlm_xdr_enc_lockargs(struct rpc_rqst *req,
 				 struct xdr_stream *xdr,
 				 const void *data)
 {
-	const struct nlm_args *args = data;
+	const struct lockd_args *args = data;
 	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
@@ -400,7 +400,7 @@ static void nlm_xdr_enc_cancargs(struct rpc_rqst *req,
 				 struct xdr_stream *xdr,
 				 const void *data)
 {
-	const struct nlm_args *args = data;
+	const struct lockd_args *args = data;
 	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
@@ -419,7 +419,7 @@ static void nlm_xdr_enc_unlockargs(struct rpc_rqst *req,
 				   struct xdr_stream *xdr,
 				   const void *data)
 {
-	const struct nlm_args *args = data;
+	const struct lockd_args *args = data;
 	const struct lockd_lock *lock = &args->lock;
 
 	encode_cookie(xdr, &args->cookie);
fs/lockd/lockd.h +1 -1
index 032790834c7e..a97676639d3e 100644
@@ -171,7 +171,7 @@ struct nlm_rqst {
 	refcount_t		a_count;
 	unsigned int		a_flags;	/* initial RPC task flags */
 	struct nlm_host *	a_host;		/* host handle */
-	struct nlm_args		a_args;		/* arguments */
+	struct lockd_args	a_args;		/* arguments */
 	struct nlm_res		a_res;		/* result */
 	struct nlm_block *	a_block;
 	unsigned int		a_retries;	/* Retry count */
fs/lockd/svcproc.c +40 -40

236 lines not on this page · raw message

fs/lockd/xdr.c +6 -6
index 55868222984a..0130cdea5642 100644
@@ -154,7 +154,7 @@ nlmsvc_decode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 bool
 nlmsvc_decode_testargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 {
-	struct nlm_args *argp = rqstp->rq_argp;
+	struct lockd_args *argp = rqstp->rq_argp;
 	u32 exclusive;
 
 	if (!svcxdr_decode_cookie(xdr, &argp->cookie))
@@ -172,7 +172,7 @@ nlmsvc_decode_testargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 bool
 nlmsvc_decode_lockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 {
-	struct nlm_args *argp = rqstp->rq_argp;
+	struct lockd_args *argp = rqstp->rq_argp;
 	u32 exclusive;
 
 	if (!svcxdr_decode_cookie(xdr, &argp->cookie))
@@ -197,7 +197,7 @@ nlmsvc_decode_lockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 bool
 nlmsvc_decode_cancargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 {
-	struct nlm_args *argp = rqstp->rq_argp;
+	struct lockd_args *argp = rqstp->rq_argp;
 	u32 exclusive;
 
 	if (!svcxdr_decode_cookie(xdr, &argp->cookie))
@@ -217,7 +217,7 @@ nlmsvc_decode_cancargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 bool
 nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 {
-	struct nlm_args *argp = rqstp->rq_argp;
+	struct lockd_args *argp = rqstp->rq_argp;
 
 	if (!svcxdr_decode_cookie(xdr, &argp->cookie))
 		return false;
@@ -270,7 +270,7 @@ nlmsvc_decode_reboot(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 bool
 nlmsvc_decode_shareargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 {
-	struct nlm_args *argp = rqstp->rq_argp;
+	struct lockd_args *argp = rqstp->rq_argp;
 	struct lockd_lock *lock = &argp->lock;
 
 	memset(lock, 0, sizeof(*lock));
@@ -297,7 +297,7 @@ nlmsvc_decode_shareargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 bool
 nlmsvc_decode_notify(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 {
-	struct nlm_args *argp = rqstp->rq_argp;
+	struct lockd_args *argp = rqstp->rq_argp;
 	struct lockd_lock *lock = &argp->lock;
 
 	if (!svcxdr_decode_string(xdr, &lock->caller, &lock->len))
fs/lockd/xdr.h +1 -1
index 805027d9b0fe..ffdcad0f8680 100644
@@ -57,7 +57,7 @@ struct lockd_cookie {
 /*
  * Generic lockd arguments for all but sm_notify
  */
-struct nlm_args {
+struct lockd_args {
 	struct lockd_cookie	cookie;
 	struct lockd_lock	lock;
 	u32			block;
Signature · 1 line
2.54.0
author maintainer
#10 lore raw

PATCH 10/38 lockd: Rename struct nlm_res to lockd_res

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

As part of the effort to enable lockd's server-side XDR functions to be generated from the NLM protocol specification (using xdrgen), the internal type names must be changed to avoid conflicts with the machine-generated type names.

Rename struct nlm_res to struct lockd_res to avoid conflicts with the NLMv3 XDR type definitions that will be introduced when svcproc.c is converted to use xdrgen.

---
 fs/lockd/clnt4xdr.c | 14 +++++++-------
 fs/lockd/clntproc.c |  6 +++---
 fs/lockd/clntxdr.c  | 16 +++++++--------
 fs/lockd/lockd.h    |  2 +-
 fs/lockd/svc4proc.c | 12 ++++++------
 fs/lockd/svcproc.c  | 56 ++++++++++++++++++++++++++---------------------------
 fs/lockd/xdr.c      | 10 +++++-----
 fs/lockd/xdr.h      |  2 +-
 8 files changed, 59 insertions(+), 59 deletions(-)
fs/lockd/clnt4xdr.c +7 -7
index d0b08a12fe45..96a4a1e6a6b6 100644
@@ -238,7 +238,7 @@ static int decode_nlm4_stat(struct xdr_stream *xdr, __be32 *stat)
  *	};
  */
 static void encode_nlm4_holder(struct xdr_stream *xdr,
-			       const struct nlm_res *result)
+			       const struct lockd_res *result)
 {
 	const struct lockd_lock *lock = &result->lock;
 	u64 l_offset, l_len;
@@ -254,7 +254,7 @@ static void encode_nlm4_holder(struct xdr_stream *xdr,
 	xdr_encode_hyper(p, l_len);
 }
 
-static int decode_nlm4_holder(struct xdr_stream *xdr, struct nlm_res *result)
+static int decode_nlm4_holder(struct xdr_stream *xdr, struct lockd_res *result)
 {
 	struct lockd_lock *lock = &result->lock;
 	struct file_lock *fl = &lock->fl;
@@ -435,7 +435,7 @@ static void nlm4_xdr_enc_res(struct rpc_rqst *req,
 			     struct xdr_stream *xdr,
 			     const void *data)
 {
-	const struct nlm_res *result = data;
+	const struct lockd_res *result = data;
 
 	encode_cookie(xdr, &result->cookie);
 	encode_nlm4_stat(xdr, result->status);
@@ -458,7 +458,7 @@ static void nlm4_xdr_enc_testres(struct rpc_rqst *req,
 				 struct xdr_stream *xdr,
 				 const void *data)
 {
-	const struct nlm_res *result = data;
+	const struct lockd_res *result = data;
 
 	encode_cookie(xdr, &result->cookie);
 	encode_nlm4_stat(xdr, result->status);
@@ -489,7 +489,7 @@ static void nlm4_xdr_enc_testres(struct rpc_rqst *req,
  *	};
  */
 static int decode_nlm4_testrply(struct xdr_stream *xdr,
-				struct nlm_res *result)
+				struct lockd_res *result)
 {
 	int error;
 
@@ -506,7 +506,7 @@ static int nlm4_xdr_dec_testres(struct rpc_rqst *req,
 				struct xdr_stream *xdr,
 				void *data)
 {
-	struct nlm_res *result = data;
+	struct lockd_res *result = data;
 	int error;
 
 	error = decode_cookie(xdr, &result->cookie);
@@ -527,7 +527,7 @@ static int nlm4_xdr_dec_res(struct rpc_rqst *req,
 			    struct xdr_stream *xdr,
 			    void *data)
 {
-	struct nlm_res *result = data;
+	struct lockd_res *result = data;
 	int error;
 
 	error = decode_cookie(xdr, &result->cookie);
fs/lockd/clntproc.c +3 -3
index abdf2a51caf2..f06faf577cea 100644
@@ -267,7 +267,7 @@ nlmclnt_call(const struct cred *cred, struct nlm_rqst *req, u32 proc)
 	struct nlm_host	*host = req->a_host;
 	struct rpc_clnt	*clnt;
 	struct lockd_args *argp = &req->a_args;
-	struct nlm_res	*resp = &req->a_res;
+	struct lockd_res *resp = &req->a_res;
 	struct rpc_message msg = {
 		.rpc_argp	= argp,
 		.rpc_resp	= resp,
@@ -523,7 +523,7 @@ nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
 {
 	const struct cred *cred = nfs_file_cred(fl->c.flc_file);
 	struct nlm_host	*host = req->a_host;
-	struct nlm_res	*resp = &req->a_res;
+	struct lockd_res *resp = &req->a_res;
 	struct nlm_wait block;
 	unsigned char flags = fl->c.flc_flags;
 	unsigned char type;
@@ -686,7 +686,7 @@ static int
 nlmclnt_unlock(struct nlm_rqst *req, struct file_lock *fl)
 {
 	struct nlm_host	*host = req->a_host;
-	struct nlm_res	*resp = &req->a_res;
+	struct lockd_res *resp = &req->a_res;
 	int status;
 	unsigned char flags = fl->c.flc_flags;
 
fs/lockd/clntxdr.c +8 -8
index 444a34bc799a..3789ecb0b984 100644
@@ -234,7 +234,7 @@ static int decode_nlm_stat(struct xdr_stream *xdr,
  *	};
  */
 static void encode_nlm_holder(struct xdr_stream *xdr,
-			      const struct nlm_res *result)
+			      const struct lockd_res *result)
 {
 	const struct lockd_lock *lock = &result->lock;
 	u32 l_offset, l_len;
@@ -250,7 +250,7 @@ static void encode_nlm_holder(struct xdr_stream *xdr,
 	*p   = cpu_to_be32(l_len);
 }
 
-static int decode_nlm_holder(struct xdr_stream *xdr, struct nlm_res *result)
+static int decode_nlm_holder(struct xdr_stream *xdr, struct lockd_res *result)
 {
 	struct lockd_lock *lock = &result->lock;
 	struct file_lock *fl = &lock->fl;
@@ -436,7 +436,7 @@ static void nlm_xdr_enc_res(struct rpc_rqst *req,
 			    struct xdr_stream *xdr,
 			    const void *data)
 {
-	const struct nlm_res *result = data;
+	const struct lockd_res *result = data;
 
 	encode_cookie(xdr, &result->cookie);
 	encode_nlm_stat(xdr, result->status);
@@ -456,7 +456,7 @@ static void nlm_xdr_enc_res(struct rpc_rqst *req,
  *	};
  */
 static void encode_nlm_testrply(struct xdr_stream *xdr,
-				const struct nlm_res *result)
+				const struct lockd_res *result)
 {
 	if (result->status == nlm_lck_denied)
 		encode_nlm_holder(xdr, result);
@@ -466,7 +466,7 @@ static void nlm_xdr_enc_testres(struct rpc_rqst *req,
 				struct xdr_stream *xdr,
 				const void *data)
 {
-	const struct nlm_res *result = data;
+	const struct lockd_res *result = data;
 
 	encode_cookie(xdr, &result->cookie);
 	encode_nlm_stat(xdr, result->status);
@@ -495,7 +495,7 @@ static void nlm_xdr_enc_testres(struct rpc_rqst *req,
  *	};
  */
 static int decode_nlm_testrply(struct xdr_stream *xdr,
-			       struct nlm_res *result)
+			       struct lockd_res *result)
 {
 	int error;
 
@@ -512,7 +512,7 @@ static int nlm_xdr_dec_testres(struct rpc_rqst *req,
 			       struct xdr_stream *xdr,
 			       void *data)
 {
-	struct nlm_res *result = data;
+	struct lockd_res *result = data;
 	int error;
 
 	error = decode_cookie(xdr, &result->cookie);
@@ -533,7 +533,7 @@ static int nlm_xdr_dec_res(struct rpc_rqst *req,
 			   struct xdr_stream *xdr,
 			   void *data)
 {
-	struct nlm_res *result = data;
+	struct lockd_res *result = data;
 	int error;
 
 	error = decode_cookie(xdr, &result->cookie);
fs/lockd/lockd.h +1 -1
index a97676639d3e..4054e97723d8 100644
@@ -172,7 +172,7 @@ struct nlm_rqst {
 	unsigned int		a_flags;	/* initial RPC task flags */
 	struct nlm_host *	a_host;		/* host handle */
 	struct lockd_args	a_args;		/* arguments */
-	struct nlm_res		a_res;		/* result */
+	struct lockd_res	a_res;		/* result */
 	struct nlm_block *	a_block;
 	unsigned int		a_retries;	/* Retry count */
 	u8			a_owner[NLMCLNT_OHSIZE];
fs/lockd/svc4proc.c +6 -6
index f7067fae6c86..1682a7c91a78 100644
@@ -562,7 +562,7 @@ static const struct rpc_call_ops nlm4svc_callback_ops = {
  */
 static __be32
 nlm4svc_callback(struct svc_rqst *rqstp, struct nlm_host *host, u32 proc,
-		 __be32 (*func)(struct svc_rqst *,  struct nlm_res *))
+		 __be32 (*func)(struct svc_rqst *,  struct lockd_res *))
 {
 	struct nlm_rqst	*call;
 	__be32 stat;
@@ -585,7 +585,7 @@ nlm4svc_callback(struct svc_rqst *rqstp, struct nlm_host *host, u32 proc,
 }
 
 static __be32
-__nlm4svc_proc_test_msg(struct svc_rqst *rqstp, struct nlm_res *resp)
+__nlm4svc_proc_test_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
 {
 	struct nlm4_testargs_wrapper *argp = rqstp->rq_argp;
 	unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
@@ -645,7 +645,7 @@ static __be32 nlm4svc_proc_test_msg(struct svc_rqst *rqstp)
 }
 
 static __be32
-__nlm4svc_proc_lock_msg(struct svc_rqst *rqstp, struct nlm_res *resp)
+__nlm4svc_proc_lock_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
 {
 	struct nlm4_lockargs_wrapper *argp = rqstp->rq_argp;
 	unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
@@ -707,7 +707,7 @@ static __be32 nlm4svc_proc_lock_msg(struct svc_rqst *rqstp)
 }
 
 static __be32
-__nlm4svc_proc_cancel_msg(struct svc_rqst *rqstp, struct nlm_res *resp)
+__nlm4svc_proc_cancel_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
 {
 	struct nlm4_cancargs_wrapper *argp = rqstp->rq_argp;
 	unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
@@ -771,7 +771,7 @@ static __be32 nlm4svc_proc_cancel_msg(struct svc_rqst *rqstp)
 }
 
 static __be32
-__nlm4svc_proc_unlock_msg(struct svc_rqst *rqstp, struct nlm_res *resp)
+__nlm4svc_proc_unlock_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
 {
 	struct nlm4_unlockargs_wrapper *argp = rqstp->rq_argp;
 	struct net *net = SVC_NET(rqstp);
@@ -834,7 +834,7 @@ static __be32 nlm4svc_proc_unlock_msg(struct svc_rqst *rqstp)
 }
 
 static __be32
-__nlm4svc_proc_granted_msg(struct svc_rqst *rqstp, struct nlm_res *resp)
+__nlm4svc_proc_granted_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
 {
 	struct nlm4_testargs_wrapper *argp = rqstp->rq_argp;
 
fs/lockd/svcproc.c +28 -28

194 lines not on this page · raw message

fs/lockd/xdr.c +5 -5
index 0130cdea5642..bcf65152a436 100644
@@ -127,7 +127,7 @@ svcxdr_encode_holder(struct xdr_stream *xdr, const struct lockd_lock *lock)
 }
 
 static bool
-svcxdr_encode_testrply(struct xdr_stream *xdr, const struct nlm_res *resp)
+svcxdr_encode_testrply(struct xdr_stream *xdr, const struct lockd_res *resp)
 {
 	if (!svcxdr_encode_stats(xdr, resp->status))
 		return false;
@@ -231,7 +231,7 @@ nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 bool
 nlmsvc_decode_res(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 {
-	struct nlm_res *resp = rqstp->rq_argp;
+	struct lockd_res *resp = rqstp->rq_argp;
 
 	if (!svcxdr_decode_cookie(xdr, &resp->cookie))
 		return false;
@@ -322,7 +322,7 @@ nlmsvc_encode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 bool
 nlmsvc_encode_testres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 {
-	struct nlm_res *resp = rqstp->rq_resp;
+	struct lockd_res *resp = rqstp->rq_resp;
 
 	return svcxdr_encode_cookie(xdr, &resp->cookie) &&
 		svcxdr_encode_testrply(xdr, resp);
@@ -331,7 +331,7 @@ nlmsvc_encode_testres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 bool
 nlmsvc_encode_res(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 {
-	struct nlm_res *resp = rqstp->rq_resp;
+	struct lockd_res *resp = rqstp->rq_resp;
 
 	return svcxdr_encode_cookie(xdr, &resp->cookie) &&
 		svcxdr_encode_stats(xdr, resp->status);
@@ -340,7 +340,7 @@ nlmsvc_encode_res(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 bool
 nlmsvc_encode_shareres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 {
-	struct nlm_res *resp = rqstp->rq_resp;
+	struct lockd_res *resp = rqstp->rq_resp;
 
 	if (!svcxdr_encode_cookie(xdr, &resp->cookie))
 		return false;
fs/lockd/xdr.h +1 -1
index ffdcad0f8680..a480df7cae31 100644
@@ -71,7 +71,7 @@ struct lockd_args {
 /*
  * Generic lockd result
  */
-struct nlm_res {
+struct lockd_res {
 	struct lockd_cookie	cookie;
 	__be32			status;
 	struct lockd_lock	lock;
Signature · 1 line
2.54.0
author maintainer
#11 lore raw

PATCH 11/38 lockd: Rename struct nlm_reboot to lockd_reboot

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

As part of the effort to enable lockd's server-side XDR functions to be generated from the NLM protocol specification (using xdrgen), the internal type names must be changed to avoid conflicts with the machine-generated type names.

Rename struct nlm_reboot to struct lockd_reboot for consistency with the other renamed internal types.

---
 fs/lockd/host.c     | 4 ++--
 fs/lockd/lockd.h    | 4 ++--
 fs/lockd/mon.c      | 2 +-
 fs/lockd/svc4proc.c | 4 ++--
 fs/lockd/svcproc.c  | 8 ++++----
 fs/lockd/xdr.c      | 2 +-
 fs/lockd/xdr.h      | 2 +-
 7 files changed, 13 insertions(+), 13 deletions(-)
fs/lockd/host.c +2 -2
index ea8a8e166f7e..d572cb27533f 100644
@@ -552,7 +552,7 @@ struct nlm_host * nlm_get_host(struct nlm_host *host)
 
 static struct nlm_host *next_host_state(struct hlist_head *cache,
 					struct nsm_handle *nsm,
-					const struct nlm_reboot *info)
+					const struct lockd_reboot *info)
 {
 	struct nlm_host *host;
 	struct hlist_head *chain;
@@ -582,7 +582,7 @@ static struct nlm_host *next_host_state(struct hlist_head *cache,
  * We were notified that the specified host has rebooted.  Release
  * all resources held by that peer.
  */
-void nlm_host_rebooted(const struct net *net, const struct nlm_reboot *info)
+void nlm_host_rebooted(const struct net *net, const struct lockd_reboot *info)
 {
 	struct nsm_handle *nsm;
 	struct nlm_host	*host;
fs/lockd/lockd.h +2 -2
index 4054e97723d8..ca389525a170 100644
@@ -285,7 +285,7 @@ struct nlm_host * nlm_get_host(struct nlm_host *);
 void		  nlm_shutdown_hosts(void);
 void		  nlm_shutdown_hosts_net(struct net *net);
 void		  nlm_host_rebooted(const struct net *net,
-					const struct nlm_reboot *);
+					const struct lockd_reboot *);
 
 /*
  * Host monitoring
@@ -299,7 +299,7 @@ struct nsm_handle *nsm_get_handle(const struct net *net,
 					const char *hostname,
 					const size_t hostname_len);
 struct nsm_handle *nsm_reboot_lookup(const struct net *net,
-					const struct nlm_reboot *info);
+					const struct lockd_reboot *info);
 void		  nsm_release(struct nsm_handle *nsm);
 
 /*
fs/lockd/mon.c +1 -1
index 3d3ee88ca4dc..a8f5ac6f0577 100644
@@ -377,7 +377,7 @@ struct nsm_handle *nsm_get_handle(const struct net *net,
  * error occurred.
  */
 struct nsm_handle *nsm_reboot_lookup(const struct net *net,
-				const struct nlm_reboot *info)
+				const struct lockd_reboot *info)
 {
 	struct nsm_handle *cached;
 	struct lockd_net *ln = net_generic(net, lockd_net_id);
fs/lockd/svc4proc.c +2 -2
index 1682a7c91a78..997f4f437997 100644
@@ -61,7 +61,7 @@ static_assert(offsetof(struct nlm4_unlockargs_wrapper, xdrgen) == 0);
 
 struct nlm4_notifyargs_wrapper {
 	struct nlm4_notifyargs		xdrgen;
-	struct nlm_reboot		reboot;
+	struct lockd_reboot		reboot;
 };
 
 static_assert(offsetof(struct nlm4_notifyargs_wrapper, xdrgen) == 0);
@@ -918,7 +918,7 @@ static __be32 nlm4svc_proc_granted_res(struct svc_rqst *rqstp)
 static __be32 nlm4svc_proc_sm_notify(struct svc_rqst *rqstp)
 {
 	struct nlm4_notifyargs_wrapper *argp = rqstp->rq_argp;
-	struct nlm_reboot *reboot = &argp->reboot;
+	struct lockd_reboot *reboot = &argp->reboot;
 
 	if (!nlm_privileged_requester(rqstp)) {
 		char buf[RPC_MAX_ADDRBUFLEN];
fs/lockd/svcproc.c +4 -4
index e033320b840f..a79c9a46db60 100644
@@ -518,7 +518,7 @@ nlmsvc_proc_free_all(struct svc_rqst *rqstp)
 static __be32
 nlmsvc_proc_sm_notify(struct svc_rqst *rqstp)
 {
-	struct nlm_reboot *argp = rqstp->rq_argp;
+	struct lockd_reboot *argp = rqstp->rq_argp;
 
 	dprintk("lockd: SM_NOTIFY     called\n");
 
@@ -732,8 +732,8 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_func = nlmsvc_proc_sm_notify,
 		.pc_decode = nlmsvc_decode_reboot,
 		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct nlm_reboot),
-		.pc_argzero = sizeof(struct nlm_reboot),
+		.pc_argsize = sizeof(struct lockd_reboot),
+		.pc_argzero = sizeof(struct lockd_reboot),
 		.pc_ressize = sizeof(struct nlm_void),
 		.pc_xdrressize = St,
 		.pc_name = "SM_NOTIFY",
@@ -816,7 +816,7 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 union nlmsvc_xdrstore {
 	struct lockd_args		args;
 	struct lockd_res		res;
-	struct nlm_reboot		reboot;
+	struct lockd_reboot		reboot;
 };
 
 /*
fs/lockd/xdr.c +1 -1
index bcf65152a436..c78c64557fea 100644
@@ -244,7 +244,7 @@ nlmsvc_decode_res(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 bool
 nlmsvc_decode_reboot(struct svc_rqst *rqstp, struct xdr_stream *xdr)
 {
-	struct nlm_reboot *argp = rqstp->rq_argp;
+	struct lockd_reboot *argp = rqstp->rq_argp;
 	__be32 *p;
 	u32 len;
 
fs/lockd/xdr.h +1 -1
index a480df7cae31..65d2d6d34310 100644
@@ -80,7 +80,7 @@ struct lockd_res {
 /*
  * statd callback when client has rebooted
  */
-struct nlm_reboot {
+struct lockd_reboot {
 	char			*mon;
 	unsigned int		len;
 	u32			state;
Signature · 1 line
2.54.0
author maintainer
#12 lore raw

PATCH 12/38 lockd: Rename struct nlm_share to lockd_share

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

As part of the effort to enable lockd's server-side XDR functions to be generated from the NLM protocol specification (using xdrgen), the internal type names must be changed to avoid conflicts with the machine-generated type names.

Rename struct nlm_share to struct lockd_share to avoid conflicts with the NLMv3 XDR type definitions that will be introduced when svcproc.c is converted to use xdrgen.

---
 fs/lockd/lockd.h    | 4 ++--
 fs/lockd/share.h    | 4 ++--
 fs/lockd/svcshare.c | 8 ++++----
 3 files changed, 8 insertions(+), 8 deletions(-)
fs/lockd/lockd.h +2 -2
index ca389525a170..5c79681b7e95 100644
@@ -179,7 +179,7 @@ struct nlm_rqst {
 	void *	a_callback_data; /* sent to nlmclnt_operations callbacks */
 };
 
-struct nlm_share;
+struct lockd_share;
 
 /*
  * This struct describes a file held open by lockd on behalf of
@@ -190,7 +190,7 @@ struct nlm_file {
 	struct nfs_fh		f_handle;	/* NFS file handle */
 	struct file *		f_file[2];	/* VFS file pointers,
 						   indexed by O_ flags */
-	struct nlm_share *	f_shares;	/* DOS shares */
+	struct lockd_share *	f_shares;	/* DOS shares */
 	struct list_head	f_blocks;	/* blocked locks */
 	unsigned int		f_locks;	/* guesstimate # of locks */
 	unsigned int		f_count;	/* reference count */
fs/lockd/share.h +2 -2
index 20ea8ee49168..1ec3ccdb2aef 100644
@@ -14,8 +14,8 @@
 /*
  * DOS share for a specific file
  */
-struct nlm_share {
-	struct nlm_share *	s_next;		/* linked list */
+struct lockd_share {
+	struct lockd_share *	s_next;		/* linked list */
 	struct nlm_host *	s_host;		/* client host */
 	struct nlm_file *	s_file;		/* shared file */
 	struct xdr_netobj	s_owner;	/* owner handle */
fs/lockd/svcshare.c +4 -4
index 53f5655c128c..5ac0ec25d62d 100644
@@ -19,7 +19,7 @@
 #include "share.h"
 
 static inline int
-nlm_cmp_owner(struct nlm_share *share, struct xdr_netobj *oh)
+nlm_cmp_owner(struct lockd_share *share, struct xdr_netobj *oh)
 {
 	return share->s_owner.len == oh->len
 	    && !memcmp(share->s_owner.data, oh->data, oh->len);
@@ -39,7 +39,7 @@ __be32
 nlmsvc_share_file(struct nlm_host *host, struct nlm_file *file,
 		  struct xdr_netobj *oh, u32 access, u32 mode)
 {
-	struct nlm_share	*share;
+	struct lockd_share	*share;
 	u8			*ohdata;
 
 	if (nlmsvc_file_cannot_lock(file))
@@ -85,7 +85,7 @@ __be32
 nlmsvc_unshare_file(struct nlm_host *host, struct nlm_file *file,
 		    struct xdr_netobj *oh)
 {
-	struct nlm_share	*share, **shpp;
+	struct lockd_share	*share, **shpp;
 
 	if (nlmsvc_file_cannot_lock(file))
 		return nlm_lck_denied_nolocks;
@@ -111,7 +111,7 @@ nlmsvc_unshare_file(struct nlm_host *host, struct nlm_file *file,
 void nlmsvc_traverse_shares(struct nlm_host *host, struct nlm_file *file,
 		nlm_host_match_fn_t match)
 {
-	struct nlm_share	*share, **shpp;
+	struct lockd_share	*share, **shpp;
 
 	shpp = &file->f_shares;
 	while ((share = *shpp) !=  NULL) {
Signature · 1 line
2.54.0
author maintainer
#13 lore raw

PATCH 13/38 lockd: Use xdrgen XDR functions for the NLMv3 NULL procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Hand-written XDR encoders and decoders are difficult to maintain and can diverge from protocol specifications. Migrating to xdrgen-generated code improves type safety and ensures the implementation matches the NLM version 3 protocol specification exactly.

Convert the NULL procedure to use nlm_svc_decode_void and nlm_svc_encode_void, generated from Documentation/sunrpc/xdr/nlm3.x. NULL has no arguments or results, so it is the first procedure converted.

NULL returns no XDR-encoded data, so pc_xdrressize is set to XDR_void. The argzero field is also set to zero since xdrgen decoders initialize all decoded values.

---
 fs/lockd/svcproc.c | 42 ++++++++++++++++++++++++++++--------------
 1 file changed, 28 insertions(+), 14 deletions(-)
fs/lockd/svcproc.c +28 -14
index a79c9a46db60..ad37f3611eea 100644
@@ -13,7 +13,16 @@
 #include <linux/sunrpc/svc_xprt.h>
 
 #include "lockd.h"
+
+/*
+ * xdr.h defines SM_PRIV_SIZE as a macro. nlm3xdr_gen.h defines
+ * it as an enum constant. Undefine the macro before including
+ * the generated header.
+ */
+#undef SM_PRIV_SIZE
+
 #include "share.h"
+#include "nlm3xdr_gen.h"
 
 #define NLMDBG_FACILITY		NLMDBG_CLIENT
 
@@ -120,13 +129,18 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct lockd_args *argp,
 	return nlm_lck_denied_nolocks;
 }
 
-/*
- * NULL: Test for presence of service
+/**
+ * nlmsvc_proc_null - NULL: Test for presence of service
+ * @rqstp: RPC transaction context
+ *
+ * Return:
+ *   %rpc_success:		RPC executed successfully
+ *
+ * RPC synopsis:
+ *   void NLM_NULL(void) = 0;
  */
-static __be32
-nlmsvc_proc_null(struct svc_rqst *rqstp)
+static __be32 nlmsvc_proc_null(struct svc_rqst *rqstp)
 {
-	dprintk("lockd: NULL          called\n");
 	return rpc_success;
 }
 
@@ -568,15 +582,15 @@ struct nlm_void			{ int dummy; };
 #define	Rg	2				/* range - offset + size */
 
 static const struct svc_procedure nlmsvc_procedures[24] = {
-	[NLMPROC_NULL] = {
-		.pc_func = nlmsvc_proc_null,
-		.pc_decode = nlmsvc_decode_void,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct nlm_void),
-		.pc_argzero = sizeof(struct nlm_void),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "NULL",
+	[NLM_NULL] = {
+		.pc_func	= nlmsvc_proc_null,
+		.pc_decode	= nlm_svc_decode_void,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= XDR_void,
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "NULL",
 	},
 	[NLMPROC_TEST] = {
 		.pc_func = nlmsvc_proc_test,
Signature · 1 line
2.54.0
author maintainer
#14 lore raw

PATCH 14/38 lockd: Use xdrgen XDR functions for the NLMv3 TEST procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

The NLM TEST procedure requires host and file lookups to check lock state, operations that will be common across multiple NLM procedures being migrated to xdrgen. Introducing the nlm3svc_lookup_host() and nlm3svc_lookup_file() helpers now keeps these common patterns in one place for subsequent conversions in this series.

This patch converts the TEST procedure to use xdrgen functions nlm_svc_decode_nlm_testargs and nlm_svc_encode_nlm_testres generated from the NLM version 3 protocol specification. The procedure handler is rewritten to use xdrgen types through wrapper structures that bridge between generated code and the legacy lockd_lock representation still used by the core lockd logic.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is not needed. The lock member of the wrapper is populated explicitly in nlm3svc_lookup_file() rather than relying on zero-initialization.

The conflicting holder's offset and length are saturated to NLM_OFFSET_MAX when constructing the reply. A conflicting lock established by an NLMv4 client or by a local process can sit beyond the NLMv3 signed 32-bit range, and copying fl_start and fl_end straight into the unsigned 32-bit XDR fields would wrap and report a bogus range. The previous hand-written encoder in svcxdr_encode_holder() used loff_t_to_s32() for the same reason, but this patch series intends to separate the concerns of data conversion (XDR) from dealing with local byte range constraints, so clamping is hoisted into the proc function.

The previous hand-written decoder in svcxdr_decode_cookie() rewrote a zero-length NLM cookie into a four-byte zero cookie, with a comment attributing the substitution to HP-UX clients. The xdrgen-generated netobj decoder performs no such rewrite, so a zero-length request cookie now round-trips unchanged into the reply. HP-UX has reached end of support, and NLM_TEST reply matching relies on the RPC XID rather than the NLM cookie, so the workaround is dropped intentionally here.

---
 fs/lockd/lockd.h   |  23 +++++++
 fs/lockd/svcproc.c | 195 +++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 206 insertions(+), 12 deletions(-)
fs/lockd/lockd.h +23 -0
index 5c79681b7e95..0be0dac59ea2 100644
@@ -422,6 +422,29 @@ static inline int nlm_compare_locks(const struct file_lock *fl1,
 	     &&(fl1->c.flc_type  == fl2->c.flc_type || fl2->c.flc_type == F_UNLCK);
 }
 
+/**
+ * lockd_set_file_lock_range3 - set the byte range of a file_lock
+ * @fl: file_lock whose length fields are to be initialized
+ * @off: starting offset of the lock, in bytes
+ * @len: length of the byte range, in bytes, or zero
+ *
+ * NLMv3 uses a (start, length) representation for lock byte ranges,
+ * while the kernel's file_lock uses (start, end). Treat a length of
+ * zero or arithmetic overflow (end wrapping negative when the sum
+ * exceeds S32_MAX) as "lock to end of file."
+ */
+static inline void
+lockd_set_file_lock_range3(struct file_lock *fl, u32 off, u32 len)
+{
+	s32 end = off + len - 1;
+
+	fl->fl_start = off;
+	if (len == 0 || end < 0)
+		fl->fl_end = OFFSET_MAX;
+	else
+		fl->fl_end = end;
+}
+
 /**
  * lockd_set_file_lock_range4 - set the byte range of a file_lock
  * @fl: file_lock whose length fields are to be initialized
fs/lockd/svcproc.c +183 -12

220 lines not on this page · raw message

Signature · 1 line
2.54.0
author maintainer
#15 lore raw

PATCH 15/38 lockd: Use xdrgen XDR functions for the NLMv3 LOCK procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

The NLM LOCK procedure requires the same host and file lookup operations established in the TEST procedure conversion. This patch extends the xdrgen migration to the LOCK procedure, leveraging the shared nlm3svc_lookup_host() and nlm3svc_lookup_file() helpers to establish consistent patterns across the series.

This patch converts the LOCK procedure to use xdrgen functions nlm_svc_decode_nlm_lockargs and nlm_svc_encode_nlm_res generated from the NLM version 3 protocol specification. The procedure handler uses xdrgen types through wrapper structures that bridge between generated code and the legacy lockd_lock representation still used by the core lockd logic.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is not needed. The cookie and lock members of the wrapper are populated explicitly in nlm_netobj_to_cookie() and nlm3svc_lookup_file() rather than relying on zero-initialization.

The hand-rolled svcxdr_decode_cookie() previously substituted a four-byte zero cookie when a zero-length cookie arrived on the wire, a compatibility shim for HP-UX clients that had been carried in fs/lockd/ since the original import. The xdrgen decoder reproduces the cookie verbatim, and nlm_netobj_to_cookie() copies whatever length the peer sent. As subsequent patches replace the remaining call sites of svcxdr_decode_cookie(), this series retires that HP-UX compat behavior on the server side.

---
 fs/lockd/svcproc.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 106 insertions(+), 12 deletions(-)
fs/lockd/svcproc.c +106 -12
index 7794e6f88a71..66bc9a2efddb 100644
@@ -51,6 +51,30 @@ struct nlm_testres_wrapper {
 
 static_assert(offsetof(struct nlm_testres_wrapper, xdrgen) == 0);
 
+struct nlm_lockargs_wrapper {
+	struct nlm_lockargs		xdrgen;
+	struct lockd_cookie		cookie;
+	struct lockd_lock		lock;
+};
+
+static_assert(offsetof(struct nlm_lockargs_wrapper, xdrgen) == 0);
+
+struct nlm_res_wrapper {
+	struct nlm_res			xdrgen;
+};
+
+static_assert(offsetof(struct nlm_res_wrapper, xdrgen) == 0);
+
+static __be32
+nlm_netobj_to_cookie(struct lockd_cookie *cookie, netobj *object)
+{
+	if (object->len > NLM_MAXCOOKIELEN)
+		return nlm_lck_denied_nolocks;
+	cookie->len = object->len;
+	memcpy(cookie->data, object->data, object->len);
+	return nlm_granted;
+}
+
 static struct nlm_host *
 nlm3svc_lookup_host(struct svc_rqst *rqstp, string caller, bool monitored)
 {
@@ -385,10 +409,79 @@ __nlmsvc_proc_lock(struct svc_rqst *rqstp, struct lockd_res *resp)
 	return rc;
 }
 
+static __be32
+nlmsvc_do_lock(struct svc_rqst *rqstp, bool monitored)
+{
+	struct nlm_lockargs_wrapper *argp = rqstp->rq_argp;
+	unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
+	struct nlm_res_wrapper *resp = rqstp->rq_resp;
+	struct nlm_file	*file = NULL;
+	struct nlm_host	*host = NULL;
+
+	resp->xdrgen.cookie = argp->xdrgen.cookie;
+
+	resp->xdrgen.stat.stat = nlm_netobj_to_cookie(&argp->cookie,
+						      &argp->xdrgen.cookie);
+	if (resp->xdrgen.stat.stat)
+		goto out;
+
+	resp->xdrgen.stat.stat = nlm_lck_denied_nolocks;
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name,
+				   monitored);
+	if (!host)
+		goto out;
+
+	resp->xdrgen.stat.stat = nlm3svc_lookup_file(rqstp, host, &argp->lock,
+						     &file, &argp->xdrgen.alock,
+						     type);
+	if (resp->xdrgen.stat.stat)
+		goto out;
+
+	resp->xdrgen.stat.stat = cast_status(nlmsvc_lock(rqstp, file, host,
+							 &argp->lock,
+							 argp->xdrgen.block,
+							 &argp->cookie,
+							 argp->xdrgen.reclaim));
+
+	nlmsvc_release_lockowner(&argp->lock);
+
+out:
+	if (file)
+		nlm_release_file(file);
+	nlmsvc_release_host(host);
+	return resp->xdrgen.stat.stat == nlm__int__drop_reply ?
+		rpc_drop_reply : rpc_success;
+}
+
+/**
+ * nlmsvc_proc_lock - LOCK: Establish a monitored lock
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *   %rpc_drop_reply:		Do not send an RPC reply.
+ *
+ * RPC synopsis:
+ *   nlm_res NLM_LOCK(nlm_lockargs) = 2;
+ *
+ * Permissible procedure status codes:
+ *   %LCK_GRANTED:		The requested lock was granted.
+ *   %LCK_DENIED:		The requested lock conflicted with existing
+ *				lock reservations for the file.
+ *   %LCK_DENIED_NOLOCKS:	The server could not allocate the resources
+ *				needed to process the request.
+ *   %LCK_BLOCKED:		The blocking request cannot be granted
+ *				immediately. The server will send an
+ *				NLM_GRANTED callback to the client when
+ *				the lock can be granted.
+ *   %LCK_DENIED_GRACE_PERIOD:	The server has recently restarted and is
+ *				re-establishing existing locks, and is not
+ *				yet ready to accept normal service requests.
+ */
 static __be32
 nlmsvc_proc_lock(struct svc_rqst *rqstp)
 {
-	return __nlmsvc_proc_lock(rqstp, rqstp->rq_resp);
+	return nlmsvc_do_lock(rqstp, true);
 }
 
 static __be32
@@ -674,7 +767,7 @@ nlmsvc_proc_nm_lock(struct svc_rqst *rqstp)
 	dprintk("lockd: NM_LOCK       called\n");
 
 	argp->monitor = 0;		/* just clean the monitor flag */
-	return nlmsvc_proc_lock(rqstp);
+	return __nlmsvc_proc_lock(rqstp, rqstp->rq_resp);
 }
 
 /*
@@ -771,15 +864,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= NLM3_nlm_testres_sz,
 		.pc_name	= "TEST",
 	},
-	[NLMPROC_LOCK] = {
-		.pc_func = nlmsvc_proc_lock,
-		.pc_decode = nlmsvc_decode_lockargs,
-		.pc_encode = nlmsvc_encode_res,
-		.pc_argsize = sizeof(struct lockd_args),
-		.pc_argzero = sizeof(struct lockd_args),
-		.pc_ressize = sizeof(struct lockd_res),
-		.pc_xdrressize = Ck+St,
-		.pc_name = "LOCK",
+	[NLM_LOCK] = {
+		.pc_func	= nlmsvc_proc_lock,
+		.pc_decode	= nlm_svc_decode_nlm_lockargs,
+		.pc_encode	= nlm_svc_encode_nlm_res,
+		.pc_argsize	= sizeof(struct nlm_lockargs_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= sizeof(struct nlm_res_wrapper),
+		.pc_xdrressize	= NLM3_nlm_res_sz,
+		.pc_name	= "LOCK",
 	},
 	[NLMPROC_CANCEL] = {
 		.pc_func = nlmsvc_proc_cancel,
@@ -998,9 +1091,10 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
  */
 union nlmsvc_xdrstore {
 	struct nlm_testargs_wrapper	testargs;
+	struct nlm_lockargs_wrapper	lockargs;
 	struct nlm_testres_wrapper	testres;
+	struct nlm_res_wrapper		res;
 	struct lockd_args		args;
-	struct lockd_res		res;
 	struct lockd_reboot		reboot;
 };
 
Signature · 1 line
2.54.0
author maintainer
#16 lore raw

PATCH 16/38 lockd: Use xdrgen XDR functions for the NLMv3 CANCEL procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

The NLM CANCEL procedure allows clients to cancel outstanding blocked lock requests. This patch continues the xdrgen migration by converting the CANCEL procedure. CANCEL reuses the nlm3svc_lookup_host() and nlm3svc_lookup_file() helpers established in the TEST procedure conversion.

This patch converts the CANCEL procedure to use xdrgen functions nlm_svc_decode_nlm_cancargs and nlm_svc_encode_nlm_res generated from the NLM version 3 protocol specification. The procedure handler uses xdrgen types through a wrapper structure that bridges between generated code and the legacy lockd_lock representation still used by the core lockd logic.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is not needed. The lock member of the wrapper is populated explicitly in nlm3svc_lookup_file() rather than relying on zero-initialization.

---
 fs/lockd/svcproc.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 71 insertions(+), 10 deletions(-)
fs/lockd/svcproc.c +71 -10
index 66bc9a2efddb..a5e40ca3f109 100644
@@ -65,6 +65,13 @@ struct nlm_res_wrapper {
 
 static_assert(offsetof(struct nlm_res_wrapper, xdrgen) == 0);
 
+struct nlm_cancargs_wrapper {
+	struct nlm_cancargs		xdrgen;
+	struct lockd_lock		lock;
+};
+
+static_assert(offsetof(struct nlm_cancargs_wrapper, xdrgen) == 0);
+
 static __be32
 nlm_netobj_to_cookie(struct lockd_cookie *cookie, netobj *object)
 {
@@ -517,10 +524,63 @@ __nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct lockd_res *resp)
 	return rpc_success;
 }
 
+/**
+ * nlmsvc_proc_cancel - CANCEL: Cancel an outstanding blocked lock request
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *   %rpc_drop_reply:		Do not send an RPC reply.
+ *
+ * RPC synopsis:
+ *   nlm_res NLM_CANCEL(nlm_cancargs) = 3;
+ *
+ * Permissible procedure status codes:
+ *   %LCK_GRANTED:		The requested lock was canceled.
+ *   %LCK_DENIED:		There was no lock to cancel.
+ *   %LCK_DENIED_GRACE_PERIOD:	The server has recently restarted and is
+ *				re-establishing existing locks, and is not
+ *				yet ready to accept normal service requests.
+ *
+ * The Linux NLM server implementation also returns:
+ *   %LCK_DENIED_NOLOCKS:	A needed resource could not be allocated.
+ */
 static __be32
 nlmsvc_proc_cancel(struct svc_rqst *rqstp)
 {
-	return __nlmsvc_proc_cancel(rqstp, rqstp->rq_resp);
+	struct nlm_cancargs_wrapper *argp = rqstp->rq_argp;
+	unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
+	struct nlm_res_wrapper *resp = rqstp->rq_resp;
+	struct net *net = SVC_NET(rqstp);
+	struct nlm_host	*host = NULL;
+	struct nlm_file	*file = NULL;
+
+	resp->xdrgen.cookie = argp->xdrgen.cookie;
+
+	resp->xdrgen.stat.stat = nlm_lck_denied_grace_period;
+	if (locks_in_grace(net))
+		goto out;
+
+	resp->xdrgen.stat.stat = nlm_lck_denied_nolocks;
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
+	if (!host)
+		goto out;
+
+	resp->xdrgen.stat.stat = nlm3svc_lookup_file(rqstp, host, &argp->lock,
+						     &file, &argp->xdrgen.alock,
+						     type);
+	if (resp->xdrgen.stat.stat)
+		goto out;
+
+	resp->xdrgen.stat.stat = nlmsvc_cancel_blocked(net, file, &argp->lock);
+	nlmsvc_release_lockowner(&argp->lock);
+
+out:
+	if (file)
+		nlm_release_file(file);
+	nlmsvc_release_host(host);
+	return resp->xdrgen.stat.stat == nlm__int__drop_reply ?
+		rpc_drop_reply : rpc_success;
 }
 
 /*
@@ -874,15 +934,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= NLM3_nlm_res_sz,
 		.pc_name	= "LOCK",
 	},
-	[NLMPROC_CANCEL] = {
-		.pc_func = nlmsvc_proc_cancel,
-		.pc_decode = nlmsvc_decode_cancargs,
-		.pc_encode = nlmsvc_encode_res,
-		.pc_argsize = sizeof(struct lockd_args),
-		.pc_argzero = sizeof(struct lockd_args),
-		.pc_ressize = sizeof(struct lockd_res),
-		.pc_xdrressize = Ck+St,
-		.pc_name = "CANCEL",
+	[NLM_CANCEL] = {
+		.pc_func	= nlmsvc_proc_cancel,
+		.pc_decode	= nlm_svc_decode_nlm_cancargs,
+		.pc_encode	= nlm_svc_encode_nlm_res,
+		.pc_argsize	= sizeof(struct nlm_cancargs_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= sizeof(struct nlm_res_wrapper),
+		.pc_xdrressize	= NLM3_nlm_res_sz,
+		.pc_name	= "CANCEL",
 	},
 	[NLMPROC_UNLOCK] = {
 		.pc_func = nlmsvc_proc_unlock,
@@ -1092,6 +1152,7 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 union nlmsvc_xdrstore {
 	struct nlm_testargs_wrapper	testargs;
 	struct nlm_lockargs_wrapper	lockargs;
+	struct nlm_cancargs_wrapper	cancargs;
 	struct nlm_testres_wrapper	testres;
 	struct nlm_res_wrapper		res;
 	struct lockd_args		args;
Signature · 1 line
2.54.0
author maintainer
#17 lore raw

PATCH 17/38 lockd: Use xdrgen XDR functions for the NLMv3 UNLOCK procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

The NLM UNLOCK procedure allows clients to release held locks, completing the basic lock lifecycle alongside TEST, LOCK, and CANCEL procedures already converted in this series.

Convert UNLOCK to use the xdrgen functions nlm_svc_decode_nlm_unlockargs and nlm_svc_encode_nlm_res generated from the NLM version 3 protocol specification, reusing the nlm3svc_lookup_host() and nlm3svc_lookup_file() helpers introduced earlier in the series. The procedure handler uses xdrgen types through a wrapper structure that bridges between generated code and the legacy lockd_lock representation still used by the core lockd logic.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is not needed. The lock member of the wrapper is populated explicitly in nlm3svc_lookup_file() rather than relying on zero-initialization.

---
 fs/lockd/svcproc.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 69 insertions(+), 10 deletions(-)
fs/lockd/svcproc.c +69 -10
index a5e40ca3f109..ccc6a633df7b 100644
@@ -72,6 +72,13 @@ struct nlm_cancargs_wrapper {
 
 static_assert(offsetof(struct nlm_cancargs_wrapper, xdrgen) == 0);
 
+struct nlm_unlockargs_wrapper {
+	struct nlm_unlockargs		xdrgen;
+	struct lockd_lock		lock;
+};
+
+static_assert(offsetof(struct nlm_unlockargs_wrapper, xdrgen) == 0);
+
 static __be32
 nlm_netobj_to_cookie(struct lockd_cookie *cookie, netobj *object)
 {
@@ -619,10 +626,61 @@ __nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct lockd_res *resp)
 	return rpc_success;
 }
 
+/**
+ * nlmsvc_proc_unlock - UNLOCK: Remove a lock
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *   %rpc_drop_reply:		Do not send an RPC reply.
+ *
+ * RPC synopsis:
+ *   nlm_res NLM_UNLOCK(nlm_unlockargs) = 4;
+ *
+ * Permissible procedure status codes:
+ *   %LCK_GRANTED:		The requested lock was released.
+ *   %LCK_DENIED_GRACE_PERIOD:	The server has recently restarted and is
+ *				re-establishing existing locks, and is not
+ *				yet ready to accept normal service requests.
+ *
+ * The Linux NLM server implementation also returns:
+ *   %LCK_DENIED_NOLOCKS:	A needed resource could not be allocated.
+ */
 static __be32
 nlmsvc_proc_unlock(struct svc_rqst *rqstp)
 {
-	return __nlmsvc_proc_unlock(rqstp, rqstp->rq_resp);
+	struct nlm_unlockargs_wrapper *argp = rqstp->rq_argp;
+	struct nlm_res_wrapper *resp = rqstp->rq_resp;
+	struct net *net = SVC_NET(rqstp);
+	struct nlm_host	*host = NULL;
+	struct nlm_file	*file = NULL;
+
+	resp->xdrgen.cookie = argp->xdrgen.cookie;
+
+	resp->xdrgen.stat.stat = nlm_lck_denied_grace_period;
+	if (locks_in_grace(net))
+		goto out;
+
+	resp->xdrgen.stat.stat = nlm_lck_denied_nolocks;
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
+	if (!host)
+		goto out;
+
+	resp->xdrgen.stat.stat = nlm3svc_lookup_file(rqstp, host, &argp->lock,
+						     &file, &argp->xdrgen.alock,
+						     F_UNLCK);
+	if (resp->xdrgen.stat.stat)
+		goto out;
+
+	resp->xdrgen.stat.stat = nlmsvc_unlock(net, file, &argp->lock);
+	nlmsvc_release_lockowner(&argp->lock);
+
+out:
+	if (file)
+		nlm_release_file(file);
+	nlmsvc_release_host(host);
+	return resp->xdrgen.stat.stat == nlm__int__drop_reply ?
+		rpc_drop_reply : rpc_success;
 }
 
 /*
@@ -944,15 +1002,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= NLM3_nlm_res_sz,
 		.pc_name	= "CANCEL",
 	},
-	[NLMPROC_UNLOCK] = {
-		.pc_func = nlmsvc_proc_unlock,
-		.pc_decode = nlmsvc_decode_unlockargs,
-		.pc_encode = nlmsvc_encode_res,
-		.pc_argsize = sizeof(struct lockd_args),
-		.pc_argzero = sizeof(struct lockd_args),
-		.pc_ressize = sizeof(struct lockd_res),
-		.pc_xdrressize = Ck+St,
-		.pc_name = "UNLOCK",
+	[NLM_UNLOCK] = {
+		.pc_func	= nlmsvc_proc_unlock,
+		.pc_decode	= nlm_svc_decode_nlm_unlockargs,
+		.pc_encode	= nlm_svc_encode_nlm_res,
+		.pc_argsize	= sizeof(struct nlm_unlockargs_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= sizeof(struct nlm_res_wrapper),
+		.pc_xdrressize	= NLM3_nlm_res_sz,
+		.pc_name	= "UNLOCK",
 	},
 	[NLMPROC_GRANTED] = {
 		.pc_func = nlmsvc_proc_granted,
@@ -1153,6 +1211,7 @@ union nlmsvc_xdrstore {
 	struct nlm_testargs_wrapper	testargs;
 	struct nlm_lockargs_wrapper	lockargs;
 	struct nlm_cancargs_wrapper	cancargs;
+	struct nlm_unlockargs_wrapper	unlockargs;
 	struct nlm_testres_wrapper	testres;
 	struct nlm_res_wrapper		res;
 	struct lockd_args		args;
Signature · 1 line
2.54.0
author maintainer
#18 lore raw

PATCH 18/38 lockd: Use xdrgen XDR functions for the NLMv3 GRANTED procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

The NLM GRANTED procedure allows servers to notify clients when a previously blocked lock request has been granted, completing the asynchronous lock request flow. This patch converts the NLMv3 GRANTED procedure to use xdrgen-generated XDR functions.

The conversion replaces the legacy decoder with the xdrgen functions nlm_svc_decode_nlm_testargs and nlm_svc_encode_nlm_res generated from the NLM version 3 protocol specification. The procedure handler accesses xdrgen types through a wrapper structure that bridges between generated code and the legacy lockd_lock representation still used by the core lockd logic.

A new helper function nlm_lock_to_lockd_lock() converts an xdrgen nlm_lock into the legacy lockd_lock format. The helper complements the existing nlm3svc_lookup_host() and nlm3svc_lookup_file() functions used throughout this series.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is not needed. The helper populates each field of the wrapper's lock member that any downstream consumer reads: fh, oh, svid, and the file_lock byte range. Because pc_argzero no longer scrubs the rq_argp slot, the shared nlmclnt_lock_event tracepoint class is updated to source its byte-range fields from lock->fl.fl_start and lock->fl.fl_end, which both the client and server populate unconditionally; the old lock_start and lock_len fields are no longer required by the trace.

---
 fs/lockd/svcproc.c | 65 +++++++++++++++++++++++++++++++++++++++++++++---------
 fs/lockd/trace.h   | 12 +++++-----
 2 files changed, 61 insertions(+), 16 deletions(-)
fs/lockd/svcproc.c +55 -10
index ccc6a633df7b..264212e44ec5 100644
@@ -89,6 +89,20 @@ nlm_netobj_to_cookie(struct lockd_cookie *cookie, netobj *object)
 	return nlm_granted;
 }
 
+static __be32
+nlm_lock_to_lockd_lock(struct lockd_lock *lock, struct nlm_lock *alock)
+{
+	if (alock->fh.len != NLM3_FHSIZE)
+		return nlm_lck_denied;
+	lock->fh.size = alock->fh.len;
+	memcpy(lock->fh.data, alock->fh.data, alock->fh.len);
+	lock->oh.len = alock->oh.len;
+	lock->oh.data = alock->oh.data;
+	lock->svid = alock->uppid;
+	lockd_set_file_lock_range3(&lock->fl, alock->l_offset, alock->l_len);
+	return nlm_granted;
+}
+
 static struct nlm_host *
 nlm3svc_lookup_host(struct svc_rqst *rqstp, string caller, bool monitored)
 {
@@ -700,10 +714,41 @@ __nlmsvc_proc_granted(struct svc_rqst *rqstp, struct lockd_res *resp)
 	return rpc_success;
 }
 
+/**
+ * nlmsvc_proc_granted - GRANTED: Blocked lock has been granted
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *
+ * RPC synopsis:
+ *   nlm_res NLM_GRANTED(nlm_testargs) = 5;
+ *
+ * Permissible procedure status codes:
+ *   %LCK_GRANTED:		The granted lock was accepted.
+ *   %LCK_DENIED:		The procedure failed, possibly due to
+ *				internal resource constraints.
+ *   %LCK_DENIED_GRACE_PERIOD:	The client host recently restarted and
+ *				its NLM is re-establishing existing locks,
+ *				so it is not yet ready to accept callbacks.
+ */
 static __be32
 nlmsvc_proc_granted(struct svc_rqst *rqstp)
 {
-	return __nlmsvc_proc_granted(rqstp, rqstp->rq_resp);
+	struct nlm_testargs_wrapper *argp = rqstp->rq_argp;
+	struct nlm_res_wrapper *resp = rqstp->rq_resp;
+
+	resp->xdrgen.cookie = argp->xdrgen.cookie;
+
+	resp->xdrgen.stat.stat = nlm_lock_to_lockd_lock(&argp->lock,
+							&argp->xdrgen.alock);
+	if (resp->xdrgen.stat.stat)
+		goto out;
+
+	resp->xdrgen.stat.stat = nlmclnt_grant(svc_addr(rqstp), &argp->lock);
+
+out:
+	return rpc_success;
 }
 
 /*
@@ -1012,15 +1057,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= NLM3_nlm_res_sz,
 		.pc_name	= "UNLOCK",
 	},
-	[NLMPROC_GRANTED] = {
-		.pc_func = nlmsvc_proc_granted,
-		.pc_decode = nlmsvc_decode_testargs,
-		.pc_encode = nlmsvc_encode_res,
-		.pc_argsize = sizeof(struct lockd_args),
-		.pc_argzero = sizeof(struct lockd_args),
-		.pc_ressize = sizeof(struct lockd_res),
-		.pc_xdrressize = Ck+St,
-		.pc_name = "GRANTED",
+	[NLM_GRANTED] = {
+		.pc_func	= nlmsvc_proc_granted,
+		.pc_decode	= nlm_svc_decode_nlm_testargs,
+		.pc_encode	= nlm_svc_encode_nlm_res,
+		.pc_argsize	= sizeof(struct nlm_testargs_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= sizeof(struct nlm_res_wrapper),
+		.pc_xdrressize	= NLM3_nlm_res_sz,
+		.pc_name	= "GRANTED",
 	},
 	[NLMPROC_TEST_MSG] = {
 		.pc_func = nlmsvc_proc_test_msg,
fs/lockd/trace.h +6 -6
index aa858d9d406d..a11d04e8c835 100644
@@ -61,8 +61,8 @@ DECLARE_EVENT_CLASS(nlmclnt_lock_event,
 			__field(u32, svid)
 			__field(u32, fh)
 			__field(unsigned long, status)
-			__field(u64, start)
-			__field(u64, len)
+			__field(loff_t, start)
+			__field(loff_t, end)
 			__sockaddr(addr, addrlen)
 		),
 
@@ -70,16 +70,16 @@ DECLARE_EVENT_CLASS(nlmclnt_lock_event,
 			__entry->oh = ~crc32_le(0xffffffff, lock->oh.data, lock->oh.len);
 			__entry->svid = lock->svid;
 			__entry->fh = nfs_fhandle_hash(&lock->fh);
-			__entry->start = lock->lock_start;
-			__entry->len = lock->lock_len;
+			__entry->start = lock->fl.fl_start;
+			__entry->end = lock->fl.fl_end;
 			__entry->status = be32_to_cpu(status);
 			__assign_sockaddr(addr, addr, addrlen);
 		),
 
 		TP_printk(
-			"addr=%pISpc oh=0x%08x svid=0x%08x fh=0x%08x start=%llu len=%llu status=%s",
+			"addr=%pISpc oh=0x%08x svid=0x%08x fh=0x%08x start=%lld end=%lld status=%s",
 			__get_sockaddr(addr), __entry->oh, __entry->svid,
-			__entry->fh, __entry->start, __entry->len,
+			__entry->fh, __entry->start, __entry->end,
 			show_nlm_status(__entry->status)
 		)
 );
Signature · 1 line
2.54.0
author maintainer
#19 lore raw

PATCH 19/38 lockd: Refactor nlmsvc_callback()

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

The xdrgen-based XDR conversion requires each RPC procedure to extract its own arguments, since xdrgen generates distinct argument structures for each procedure rather than using a single shared type.

Move the host lookup logic from nlmsvc_callback() into each of the five MSG procedure handlers (TEST_MSG, LOCK_MSG, CANCEL_MSG, UNLOCK_MSG, and GRANTED_MSG). Each handler now performs its own host lookup from rqstp->rq_argp and passes the resulting host pointer to nlmsvc_callback(). This establishes the per-procedure argument-handling pattern that the subsequent xdrgen conversion patches require.

---
 fs/lockd/svcproc.c | 72 ++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 54 insertions(+), 18 deletions(-)
fs/lockd/svcproc.c +54 -18
index 264212e44ec5..2e6afb9a19b9 100644
@@ -781,20 +781,13 @@ static const struct rpc_call_ops nlmsvc_callback_ops = {
  * because we send the callback before the reply proper. I hope this
  * doesn't break any clients.
  */
-static __be32 nlmsvc_callback(struct svc_rqst *rqstp, u32 proc,
+static __be32
+nlmsvc_callback(struct svc_rqst *rqstp, struct nlm_host *host, u32 proc,
 		__be32 (*func)(struct svc_rqst *, struct lockd_res *))
 {
-	struct lockd_args *argp = rqstp->rq_argp;
-	struct nlm_host	*host;
 	struct nlm_rqst	*call;
 	__be32 stat;
 
-	host = nlmsvc_lookup_host(rqstp,
-				  argp->lock.caller,
-				  argp->lock.len);
-	if (host == NULL)
-		return rpc_system_err;
-
 	call = nlm_alloc_call(host);
 	nlmsvc_release_host(host);
 	if (call == NULL)
@@ -814,34 +807,77 @@ static __be32 nlmsvc_callback(struct svc_rqst *rqstp, u32 proc,
 
 static __be32 nlmsvc_proc_test_msg(struct svc_rqst *rqstp)
 {
+	struct lockd_args *argp = rqstp->rq_argp;
+	struct nlm_host	*host;
+
 	dprintk("lockd: TEST_MSG      called\n");
-	return nlmsvc_callback(rqstp, NLMPROC_TEST_RES, __nlmsvc_proc_test);
+
+	host = nlmsvc_lookup_host(rqstp, argp->lock.caller, argp->lock.len);
+	if (!host)
+		return rpc_system_err;
+
+	return nlmsvc_callback(rqstp, host, NLMPROC_TEST_RES,
+			       __nlmsvc_proc_test);
 }
 
 static __be32 nlmsvc_proc_lock_msg(struct svc_rqst *rqstp)
 {
+	struct lockd_args *argp = rqstp->rq_argp;
+	struct nlm_host	*host;
+
 	dprintk("lockd: LOCK_MSG      called\n");
-	return nlmsvc_callback(rqstp, NLMPROC_LOCK_RES, __nlmsvc_proc_lock);
+
+	host = nlmsvc_lookup_host(rqstp, argp->lock.caller, argp->lock.len);
+	if (!host)
+		return rpc_system_err;
+
+	return nlmsvc_callback(rqstp, host, NLMPROC_LOCK_RES,
+			       __nlmsvc_proc_lock);
 }
 
 static __be32 nlmsvc_proc_cancel_msg(struct svc_rqst *rqstp)
 {
+	struct lockd_args *argp = rqstp->rq_argp;
+	struct nlm_host	*host;
+
 	dprintk("lockd: CANCEL_MSG    called\n");
-	return nlmsvc_callback(rqstp, NLMPROC_CANCEL_RES, __nlmsvc_proc_cancel);
+
+	host = nlmsvc_lookup_host(rqstp, argp->lock.caller, argp->lock.len);
+	if (!host)
+		return rpc_system_err;
+
+	return nlmsvc_callback(rqstp, host, NLMPROC_CANCEL_RES,
+			       __nlmsvc_proc_cancel);
 }
 
-static __be32
-nlmsvc_proc_unlock_msg(struct svc_rqst *rqstp)
+static __be32 nlmsvc_proc_unlock_msg(struct svc_rqst *rqstp)
 {
+	struct lockd_args *argp = rqstp->rq_argp;
+	struct nlm_host	*host;
+
 	dprintk("lockd: UNLOCK_MSG    called\n");
-	return nlmsvc_callback(rqstp, NLMPROC_UNLOCK_RES, __nlmsvc_proc_unlock);
+
+	host = nlmsvc_lookup_host(rqstp, argp->lock.caller, argp->lock.len);
+	if (!host)
+		return rpc_system_err;
+
+	return nlmsvc_callback(rqstp, host, NLMPROC_UNLOCK_RES,
+			       __nlmsvc_proc_unlock);
 }
 
-static __be32
-nlmsvc_proc_granted_msg(struct svc_rqst *rqstp)
+static __be32 nlmsvc_proc_granted_msg(struct svc_rqst *rqstp)
 {
+	struct lockd_args *argp = rqstp->rq_argp;
+	struct nlm_host	*host;
+
 	dprintk("lockd: GRANTED_MSG   called\n");
-	return nlmsvc_callback(rqstp, NLMPROC_GRANTED_RES, __nlmsvc_proc_granted);
+
+	host = nlmsvc_lookup_host(rqstp, argp->lock.caller, argp->lock.len);
+	if (!host)
+		return rpc_system_err;
+
+	return nlmsvc_callback(rqstp, host, NLMPROC_GRANTED_RES,
+			       __nlmsvc_proc_granted);
 }
 
 /*
Signature · 1 line
2.54.0
author maintainer
#20 lore raw

PATCH 20/38 lockd: Use xdrgen XDR functions for the NLMv3 TEST_MSG procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Continue the xdrgen migration by converting NLMv3 TEST_MSG, the async counterpart to TEST that clients use to check lock availability without blocking. The procedure now uses nlm_svc_decode_nlm_testargs and nlm_svc_encode_void, generated from the NLM version 3 protocol specification. The procedure handler reaches the xdrgen types through the nlm_testargs_wrapper structure, which bridges between generated code and the legacy lockd_lock representation.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is not needed. The lock member of the wrapper is populated explicitly in nlm3svc_lookup_file() rather than relying on zero-initialization.

The NLM async callback mechanism uses client-side functions which continue to take legacy results like struct lockd_res, preventing TEST and TEST_MSG from sharing code for now.

---
 fs/lockd/svcproc.c | 112 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 64 insertions(+), 48 deletions(-)
fs/lockd/svcproc.c +64 -48
index 2e6afb9a19b9..cd32cfc62338 100644
@@ -296,40 +296,6 @@ static __be32 nlmsvc_proc_null(struct svc_rqst *rqstp)
 	return rpc_success;
 }
 
-/*
- * TEST: Check for conflicting lock
- */
-static __be32
-__nlmsvc_proc_test(struct svc_rqst *rqstp, struct lockd_res *resp)
-{
-	struct lockd_args *argp = rqstp->rq_argp;
-	struct nlm_host	*host;
-	struct nlm_file	*file;
-	__be32 rc = rpc_success;
-
-	dprintk("lockd: TEST          called\n");
-	resp->cookie = argp->cookie;
-
-	/* Obtain client and file */
-	if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
-		return resp->status == nlm__int__drop_reply ?
-			rpc_drop_reply : rpc_success;
-
-	/* Now check for conflicting locks */
-	resp->status = cast_status(nlmsvc_testlock(rqstp, file, host,
-						   &argp->lock, &resp->lock));
-	if (resp->status == nlm__int__drop_reply)
-		rc = rpc_drop_reply;
-	else
-		dprintk("lockd: TEST          status %d vers %d\n",
-			ntohl(resp->status), rqstp->rq_vers);
-
-	nlmsvc_release_lockowner(&argp->lock);
-	nlmsvc_release_host(host);
-	nlm_release_file(file);
-	return rc;
-}
-
 /**
  * nlmsvc_proc_test - TEST: Check for conflicting lock
  * @rqstp: RPC transaction context
@@ -805,19 +771,69 @@ nlmsvc_callback(struct svc_rqst *rqstp, struct nlm_host *host, u32 proc,
 	return rpc_success;
 }
 
+static __be32
+__nlmsvc_proc_test_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
+{
+	struct nlm_testargs_wrapper *argp = rqstp->rq_argp;
+	unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
+	struct nlm_lockowner *owner;
+	struct nlm_file	*file = NULL;
+	struct nlm_host	*host = NULL;
+
+	resp->status = nlm_lck_denied_nolocks;
+	if (nlm_netobj_to_cookie(&resp->cookie, &argp->xdrgen.cookie))
+		goto out;
+
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
+	if (!host)
+		goto out;
+
+	resp->status = nlm3svc_lookup_file(rqstp, host, &argp->lock,
+					   &file, &argp->xdrgen.alock, type);
+	if (resp->status)
+		goto out;
+
+	owner = argp->lock.fl.c.flc_owner;
+	resp->status = cast_status(nlmsvc_testlock(rqstp, file, host,
+						   &argp->lock, &resp->lock));
+	nlmsvc_put_lockowner(owner);
+
+out:
+	if (file)
+		nlm_release_file(file);
+	nlmsvc_release_host(host);
+	return resp->status == nlm__int__drop_reply ? rpc_drop_reply : rpc_success;
+}
+
+/**
+ * nlmsvc_proc_test_msg - TEST_MSG: Check for conflicting lock
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *   %rpc_drop_reply:		Do not send an RPC reply.
+ *   %rpc_garbage_args:	The request arguments are malformed.
+ *   %rpc_system_err:		RPC execution failed.
+ *
+ * RPC synopsis:
+ *   void NLMPROC_TEST_MSG(nlm_testargs) = 6;
+ *
+ * The response to this request is delivered via the TEST_RES procedure.
+ */
 static __be32 nlmsvc_proc_test_msg(struct svc_rqst *rqstp)
 {
-	struct lockd_args *argp = rqstp->rq_argp;
-	struct nlm_host	*host;
+	struct nlm_testargs_wrapper *argp = rqstp->rq_argp;
+	struct nlm_host *host;
 
-	dprintk("lockd: TEST_MSG      called\n");
+	if (argp->xdrgen.cookie.len > NLM_MAXCOOKIELEN)
+		return rpc_garbage_args;
 
-	host = nlmsvc_lookup_host(rqstp, argp->lock.caller, argp->lock.len);
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
 	if (!host)
 		return rpc_system_err;
 
 	return nlmsvc_callback(rqstp, host, NLMPROC_TEST_RES,
-			       __nlmsvc_proc_test);
+			       __nlmsvc_proc_test_msg);
 }
 
 static __be32 nlmsvc_proc_lock_msg(struct svc_rqst *rqstp)
@@ -1103,15 +1119,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= NLM3_nlm_res_sz,
 		.pc_name	= "GRANTED",
 	},
-	[NLMPROC_TEST_MSG] = {
-		.pc_func = nlmsvc_proc_test_msg,
-		.pc_decode = nlmsvc_decode_testargs,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct lockd_args),
-		.pc_argzero = sizeof(struct lockd_args),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "TEST_MSG",
+	[NLM_TEST_MSG] = {
+		.pc_func	= nlmsvc_proc_test_msg,
+		.pc_decode	= nlm_svc_decode_nlm_testargs,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= sizeof(struct nlm_testargs_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "TEST_MSG",
 	},
 	[NLMPROC_LOCK_MSG] = {
 		.pc_func = nlmsvc_proc_lock_msg,
Signature · 1 line
2.54.0
author maintainer
#21 lore raw

PATCH 21/38 lockd: Use xdrgen XDR functions for the NLMv3 LOCK_MSG procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Continue the xdrgen migration by converting NLMv3 LOCK_MSG, the async counterpart to LOCK that clients use to request locks that may block. The procedure now uses nlm_svc_decode_nlm_lockargs and nlm_svc_encode_void, generated from the NLM version 3 protocol specification. The procedure handler reaches the xdrgen types through the nlm_lockargs_wrapper structure, which bridges between generated code and the legacy lockd_lock representation.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is not needed. The lock member of the wrapper is populated explicitly in nlm3svc_lookup_file() rather than relying on zero-initialization.

The NLM async callback mechanism uses client-side functions which continue to take legacy results like struct lockd_res, preventing LOCK and LOCK_MSG from sharing code for now.

---
 fs/lockd/svcproc.c | 77 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 63 insertions(+), 14 deletions(-)
fs/lockd/svcproc.c +63 -14
index cd32cfc62338..17625d43dc37 100644
@@ -836,19 +836,68 @@ static __be32 nlmsvc_proc_test_msg(struct svc_rqst *rqstp)
 			       __nlmsvc_proc_test_msg);
 }
 
+static __be32
+__nlmsvc_proc_lock_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
+{
+	struct nlm_lockargs_wrapper *argp = rqstp->rq_argp;
+	unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
+	struct nlm_file	*file = NULL;
+	struct nlm_host	*host = NULL;
+
+	resp->status = nlm_lck_denied_nolocks;
+	if (nlm_netobj_to_cookie(&resp->cookie, &argp->xdrgen.cookie))
+		goto out;
+
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, true);
+	if (!host)
+		goto out;
+
+	resp->status = nlm3svc_lookup_file(rqstp, host, &argp->lock,
+					   &file, &argp->xdrgen.alock, type);
+	if (resp->status)
+		goto out;
+
+	resp->status = cast_status(nlmsvc_lock(rqstp, file, host, &argp->lock,
+					       argp->xdrgen.block, &resp->cookie,
+					       argp->xdrgen.reclaim));
+	nlmsvc_release_lockowner(&argp->lock);
+
+out:
+	if (file)
+		nlm_release_file(file);
+	nlmsvc_release_host(host);
+	return resp->status == nlm__int__drop_reply ? rpc_drop_reply : rpc_success;
+}
+
+/**
+ * nlmsvc_proc_lock_msg - LOCK_MSG: Establish a monitored lock
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *   %rpc_drop_reply:		Do not send an RPC reply.
+ *   %rpc_garbage_args:	The request arguments are malformed.
+ *   %rpc_system_err:		RPC execution failed.
+ *
+ * RPC synopsis:
+ *   void NLMPROC_LOCK_MSG(nlm_lockargs) = 7;
+ *
+ * The response to this request is delivered via the LOCK_RES procedure.
+ */
 static __be32 nlmsvc_proc_lock_msg(struct svc_rqst *rqstp)
 {
-	struct lockd_args *argp = rqstp->rq_argp;
-	struct nlm_host	*host;
+	struct nlm_lockargs_wrapper *argp = rqstp->rq_argp;
+	struct nlm_host *host;
 
-	dprintk("lockd: LOCK_MSG      called\n");
+	if (argp->xdrgen.cookie.len > NLM_MAXCOOKIELEN)
+		return rpc_garbage_args;
 
-	host = nlmsvc_lookup_host(rqstp, argp->lock.caller, argp->lock.len);
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
 	if (!host)
 		return rpc_system_err;
 
 	return nlmsvc_callback(rqstp, host, NLMPROC_LOCK_RES,
-			       __nlmsvc_proc_lock);
+			       __nlmsvc_proc_lock_msg);
 }
 
 static __be32 nlmsvc_proc_cancel_msg(struct svc_rqst *rqstp)
@@ -1129,15 +1178,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= XDR_void,
 		.pc_name	= "TEST_MSG",
 	},
-	[NLMPROC_LOCK_MSG] = {
-		.pc_func = nlmsvc_proc_lock_msg,
-		.pc_decode = nlmsvc_decode_lockargs,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct lockd_args),
-		.pc_argzero = sizeof(struct lockd_args),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "LOCK_MSG",
+	[NLM_LOCK_MSG] = {
+		.pc_func	= nlmsvc_proc_lock_msg,
+		.pc_decode	= nlm_svc_decode_nlm_lockargs,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= sizeof(struct nlm_lockargs_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "LOCK_MSG",
 	},
 	[NLMPROC_CANCEL_MSG] = {
 		.pc_func = nlmsvc_proc_cancel_msg,
Signature · 1 line
2.54.0
author maintainer
#22 lore raw

PATCH 22/38 lockd: Use xdrgen XDR functions for the NLMv3 CANCEL_MSG procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

The CANCEL_MSG procedure is part of NLM's asynchronous lock request flow, where clients send CANCEL_MSG to cancel pending lock requests. This patch continues the xdrgen migration by converting CANCEL_MSG to use generated XDR functions.

This patch converts the CANCEL_MSG procedure to use xdrgen functions nlm_svc_decode_nlm_cancargs and nlm_svc_encode_void generated from the NLM version 3 protocol specification. The procedure handler uses xdrgen types through the nlm_cancargs_wrapper structure that bridges between generated code and the legacy lockd_lock representation.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is not needed. The lock member of the wrapper is populated explicitly in nlm3svc_lookup_file() rather than relying on zero-initialization.

The previous hand-written decoder in svcxdr_decode_cookie() rewrote a zero-length NLM cookie into a four-byte zero cookie, with a comment attributing the substitution to HP-UX clients. The xdrgen-generated netobj decoder performs no such rewrite, so a zero-length request cookie now round-trips unchanged into the CANCEL_RES reply. HP-UX has reached end of support, and CANCEL_MSG is fire-and-forget with no client-side reply matching on the NLM cookie, so the workaround is dropped intentionally here.

The NLM async callback mechanism uses client-side functions which continue to take legacy results like struct lockd_res, preventing CANCEL and CANCEL_MSG from sharing code for now.

---
 fs/lockd/svcproc.c | 114 +++++++++++++++++++++++++++++++----------------------
 1 file changed, 67 insertions(+), 47 deletions(-)
fs/lockd/svcproc.c +67 -47
index 17625d43dc37..d055079c9485 100644
@@ -478,39 +478,6 @@ nlmsvc_proc_lock(struct svc_rqst *rqstp)
 	return nlmsvc_do_lock(rqstp, true);
 }
 
-static __be32
-__nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct lockd_res *resp)
-{
-	struct lockd_args *argp = rqstp->rq_argp;
-	struct nlm_host	*host;
-	struct nlm_file	*file;
-	struct net *net = SVC_NET(rqstp);
-
-	dprintk("lockd: CANCEL        called\n");
-
-	resp->cookie = argp->cookie;
-
-	/* Don't accept requests during grace period */
-	if (locks_in_grace(net)) {
-		resp->status = nlm_lck_denied_grace_period;
-		return rpc_success;
-	}
-
-	/* Obtain client and file */
-	if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
-		return resp->status == nlm__int__drop_reply ?
-			rpc_drop_reply : rpc_success;
-
-	/* Try to cancel request. */
-	resp->status = cast_status(nlmsvc_cancel_blocked(net, file, &argp->lock));
-
-	dprintk("lockd: CANCEL        status %d\n", ntohl(resp->status));
-	nlmsvc_release_lockowner(&argp->lock);
-	nlmsvc_release_host(host);
-	nlm_release_file(file);
-	return rpc_success;
-}
-
 /**
  * nlmsvc_proc_cancel - CANCEL: Cancel an outstanding blocked lock request
  * @rqstp: RPC transaction context
@@ -900,19 +867,72 @@ static __be32 nlmsvc_proc_lock_msg(struct svc_rqst *rqstp)
 			       __nlmsvc_proc_lock_msg);
 }
 
+static __be32
+__nlmsvc_proc_cancel_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
+{
+	struct nlm_cancargs_wrapper *argp = rqstp->rq_argp;
+	unsigned char type = argp->xdrgen.exclusive ? F_WRLCK : F_RDLCK;
+	struct net *net = SVC_NET(rqstp);
+	struct nlm_file	*file = NULL;
+	struct nlm_host	*host = NULL;
+
+	resp->status = nlm_lck_denied_nolocks;
+	if (nlm_netobj_to_cookie(&resp->cookie, &argp->xdrgen.cookie))
+		goto out;
+
+	resp->status = nlm_lck_denied_grace_period;
+	if (locks_in_grace(net))
+		goto out;
+
+	resp->status = nlm_lck_denied_nolocks;
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
+	if (!host)
+		goto out;
+
+	resp->status = nlm3svc_lookup_file(rqstp, host, &argp->lock,
+					   &file, &argp->xdrgen.alock, type);
+	if (resp->status)
+		goto out;
+
+	resp->status = nlmsvc_cancel_blocked(net, file, &argp->lock);
+	nlmsvc_release_lockowner(&argp->lock);
+
+out:
+	if (file)
+		nlm_release_file(file);
+	nlmsvc_release_host(host);
+	return resp->status == nlm__int__drop_reply ? rpc_drop_reply : rpc_success;
+}
+
+/**
+ * nlmsvc_proc_cancel_msg - CANCEL_MSG: Cancel an outstanding lock request
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *   %rpc_drop_reply:		Do not send an RPC reply.
+ *   %rpc_garbage_args:	The request arguments are malformed.
+ *   %rpc_system_err:		RPC execution failed.
+ *
+ * RPC synopsis:
+ *   void NLMPROC_CANCEL_MSG(nlm_cancargs) = 8;
+ *
+ * The response to this request is delivered via the CANCEL_RES procedure.
+ */
 static __be32 nlmsvc_proc_cancel_msg(struct svc_rqst *rqstp)
 {
-	struct lockd_args *argp = rqstp->rq_argp;
-	struct nlm_host	*host;
+	struct nlm_cancargs_wrapper *argp = rqstp->rq_argp;
+	struct nlm_host *host;
 
-	dprintk("lockd: CANCEL_MSG    called\n");
+	if (argp->xdrgen.cookie.len > NLM_MAXCOOKIELEN)
+		return rpc_garbage_args;
 
-	host = nlmsvc_lookup_host(rqstp, argp->lock.caller, argp->lock.len);
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
 	if (!host)
 		return rpc_system_err;
 
 	return nlmsvc_callback(rqstp, host, NLMPROC_CANCEL_RES,
-			       __nlmsvc_proc_cancel);
+			       __nlmsvc_proc_cancel_msg);
 }
 
 static __be32 nlmsvc_proc_unlock_msg(struct svc_rqst *rqstp)
@@ -1188,15 +1208,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= XDR_void,
 		.pc_name	= "LOCK_MSG",
 	},
-	[NLMPROC_CANCEL_MSG] = {
-		.pc_func = nlmsvc_proc_cancel_msg,
-		.pc_decode = nlmsvc_decode_cancargs,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct lockd_args),
-		.pc_argzero = sizeof(struct lockd_args),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "CANCEL_MSG",
+	[NLM_CANCEL_MSG] = {
+		.pc_func	= nlmsvc_proc_cancel_msg,
+		.pc_decode	= nlm_svc_decode_nlm_cancargs,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= sizeof(struct nlm_cancargs_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "CANCEL_MSG",
 	},
 	[NLMPROC_UNLOCK_MSG] = {
 		.pc_func = nlmsvc_proc_unlock_msg,
Signature · 1 line
2.54.0
author maintainer
#23 lore raw

PATCH 23/38 lockd: Use xdrgen XDR functions for the NLMv3 UNLOCK_MSG procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Continue the xdrgen migration by converting NLMv3 UNLOCK_MSG, the async counterpart to UNLOCK that clients use to release locks without waiting for a reply. The procedure now uses nlm_svc_decode_nlm_unlockargs and nlm_svc_encode_void, generated from the NLM version 3 protocol specification. The procedure handler reaches the xdrgen types through the nlm_unlockargs_wrapper structure, which bridges between generated code and the legacy lockd_lock representation.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is not needed. The lock member of the wrapper is populated explicitly in nlm3svc_lookup_file() rather than relying on zero-initialization.

The NLM async callback mechanism uses client-side functions which continue to take legacy results like struct lockd_res, preventing UNLOCK and UNLOCK_MSG from sharing code for now.

---
 fs/lockd/svcproc.c | 116 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 66 insertions(+), 50 deletions(-)
fs/lockd/svcproc.c +66 -50
index d055079c9485..d059accfdebd 100644
@@ -537,42 +537,6 @@ nlmsvc_proc_cancel(struct svc_rqst *rqstp)
 		rpc_drop_reply : rpc_success;
 }
 
-/*
- * UNLOCK: release a lock
- */
-static __be32
-__nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct lockd_res *resp)
-{
-	struct lockd_args *argp = rqstp->rq_argp;
-	struct nlm_host	*host;
-	struct nlm_file	*file;
-	struct net *net = SVC_NET(rqstp);
-
-	dprintk("lockd: UNLOCK        called\n");
-
-	resp->cookie = argp->cookie;
-
-	/* Don't accept new lock requests during grace period */
-	if (locks_in_grace(net)) {
-		resp->status = nlm_lck_denied_grace_period;
-		return rpc_success;
-	}
-
-	/* Obtain client and file */
-	if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
-		return resp->status == nlm__int__drop_reply ?
-			rpc_drop_reply : rpc_success;
-
-	/* Now try to remove the lock */
-	resp->status = cast_status(nlmsvc_unlock(net, file, &argp->lock));
-
-	dprintk("lockd: UNLOCK        status %d\n", ntohl(resp->status));
-	nlmsvc_release_lockowner(&argp->lock);
-	nlmsvc_release_host(host);
-	nlm_release_file(file);
-	return rpc_success;
-}
-
 /**
  * nlmsvc_proc_unlock - UNLOCK: Remove a lock
  * @rqstp: RPC transaction context
@@ -935,19 +899,71 @@ static __be32 nlmsvc_proc_cancel_msg(struct svc_rqst *rqstp)
 			       __nlmsvc_proc_cancel_msg);
 }
 
+static __be32
+__nlmsvc_proc_unlock_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
+{
+	struct nlm_unlockargs_wrapper *argp = rqstp->rq_argp;
+	struct net *net = SVC_NET(rqstp);
+	struct nlm_file	*file = NULL;
+	struct nlm_host	*host = NULL;
+
+	resp->status = nlm_lck_denied_nolocks;
+	if (nlm_netobj_to_cookie(&resp->cookie, &argp->xdrgen.cookie))
+		goto out;
+
+	resp->status = nlm_lck_denied_grace_period;
+	if (locks_in_grace(net))
+		goto out;
+
+	resp->status = nlm_lck_denied_nolocks;
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
+	if (!host)
+		goto out;
+
+	resp->status = nlm3svc_lookup_file(rqstp, host, &argp->lock,
+					   &file, &argp->xdrgen.alock, F_UNLCK);
+	if (resp->status)
+		goto out;
+
+	resp->status = nlmsvc_unlock(net, file, &argp->lock);
+	nlmsvc_release_lockowner(&argp->lock);
+
+out:
+	if (file)
+		nlm_release_file(file);
+	nlmsvc_release_host(host);
+	return resp->status == nlm__int__drop_reply ? rpc_drop_reply : rpc_success;
+}
+
+/**
+ * nlmsvc_proc_unlock_msg - UNLOCK_MSG: Remove an existing lock
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *   %rpc_drop_reply:		Do not send an RPC reply.
+ *   %rpc_garbage_args:	The request arguments are malformed.
+ *   %rpc_system_err:		RPC execution failed.
+ *
+ * RPC synopsis:
+ *   void NLMPROC_UNLOCK_MSG(nlm_unlockargs) = 9;
+ *
+ * The response to this request is delivered via the UNLOCK_RES procedure.
+ */
 static __be32 nlmsvc_proc_unlock_msg(struct svc_rqst *rqstp)
 {
-	struct lockd_args *argp = rqstp->rq_argp;
-	struct nlm_host	*host;
+	struct nlm_unlockargs_wrapper *argp = rqstp->rq_argp;
+	struct nlm_host *host;
 
-	dprintk("lockd: UNLOCK_MSG    called\n");
+	if (argp->xdrgen.cookie.len > NLM_MAXCOOKIELEN)
+		return rpc_garbage_args;
 
-	host = nlmsvc_lookup_host(rqstp, argp->lock.caller, argp->lock.len);
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
 	if (!host)
 		return rpc_system_err;
 
 	return nlmsvc_callback(rqstp, host, NLMPROC_UNLOCK_RES,
-			       __nlmsvc_proc_unlock);
+			       __nlmsvc_proc_unlock_msg);
 }
 
 static __be32 nlmsvc_proc_granted_msg(struct svc_rqst *rqstp)
@@ -1218,15 +1234,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= XDR_void,
 		.pc_name	= "CANCEL_MSG",
 	},
-	[NLMPROC_UNLOCK_MSG] = {
-		.pc_func = nlmsvc_proc_unlock_msg,
-		.pc_decode = nlmsvc_decode_unlockargs,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct lockd_args),
-		.pc_argzero = sizeof(struct lockd_args),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "UNLOCK_MSG",
+	[NLM_UNLOCK_MSG] = {
+		.pc_func	= nlmsvc_proc_unlock_msg,
+		.pc_decode	= nlm_svc_decode_nlm_unlockargs,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= sizeof(struct nlm_unlockargs_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "UNLOCK_MSG",
 	},
 	[NLMPROC_GRANTED_MSG] = {
 		.pc_func = nlmsvc_proc_granted_msg,
Signature · 1 line
2.54.0
author maintainer
#24 lore raw

PATCH 24/38 lockd: Use xdrgen XDR functions for the NLMv3 GRANTED_MSG procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Continue the xdrgen migration by converting NLMv3 GRANTED_MSG, the async counterpart to GRANTED that a remote NLM uses to tell this lockd that a previously blocked client lock request has become available. The procedure now uses nlm_svc_decode_nlm_testargs and nlm_svc_encode_void, generated from the NLM version 3 protocol specification. The procedure handler reaches the xdrgen types through the nlm_testargs_wrapper structure, which bridges between generated code and the legacy lockd_lock representation.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is not needed. The lock member of the wrapper is populated explicitly in __nlmsvc_proc_granted_msg() by nlm_lock_to_lockd_lock() rather than relying on zero-initialization.

The NLM async callback mechanism uses client-side functions which continue to take legacy results like struct lockd_res, preventing GRANTED and GRANTED_MSG from sharing code for now.

---
 fs/lockd/svcproc.c | 78 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 47 insertions(+), 31 deletions(-)
fs/lockd/svcproc.c +47 -31
index d059accfdebd..21a363450d59 100644
@@ -594,23 +594,6 @@ nlmsvc_proc_unlock(struct svc_rqst *rqstp)
 		rpc_drop_reply : rpc_success;
 }
 
-/*
- * GRANTED: A server calls us to tell that a process' lock request
- * was granted
- */
-static __be32
-__nlmsvc_proc_granted(struct svc_rqst *rqstp, struct lockd_res *resp)
-{
-	struct lockd_args *argp = rqstp->rq_argp;
-
-	resp->cookie = argp->cookie;
-
-	dprintk("lockd: GRANTED       called\n");
-	resp->status = nlmclnt_grant(svc_addr(rqstp), &argp->lock);
-	dprintk("lockd: GRANTED       status %d\n", ntohl(resp->status));
-	return rpc_success;
-}
-
 /**
  * nlmsvc_proc_granted - GRANTED: Blocked lock has been granted
  * @rqstp: RPC transaction context
@@ -966,19 +949,52 @@ static __be32 nlmsvc_proc_unlock_msg(struct svc_rqst *rqstp)
 			       __nlmsvc_proc_unlock_msg);
 }
 
+static __be32
+__nlmsvc_proc_granted_msg(struct svc_rqst *rqstp, struct lockd_res *resp)
+{
+	struct nlm_testargs_wrapper *argp = rqstp->rq_argp;
+
+	resp->status = nlm_lck_denied;
+	if (nlm_netobj_to_cookie(&resp->cookie, &argp->xdrgen.cookie))
+		goto out;
+
+	if (nlm_lock_to_lockd_lock(&argp->lock, &argp->xdrgen.alock))
+		goto out;
+
+	resp->status = nlmclnt_grant(svc_addr(rqstp), &argp->lock);
+
+out:
+	return rpc_success;
+}
+
+/**
+ * nlmsvc_proc_granted_msg - GRANTED_MSG: Blocked lock has been granted
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *   %rpc_garbage_args:	The request arguments are malformed.
+ *   %rpc_system_err:		RPC execution failed.
+ *
+ * RPC synopsis:
+ *   void NLMPROC_GRANTED_MSG(nlm_testargs) = 10;
+ *
+ * The response to this request is delivered via the GRANTED_RES procedure.
+ */
 static __be32 nlmsvc_proc_granted_msg(struct svc_rqst *rqstp)
 {
-	struct lockd_args *argp = rqstp->rq_argp;
-	struct nlm_host	*host;
+	struct nlm_testargs_wrapper *argp = rqstp->rq_argp;
+	struct nlm_host *host;
 
-	dprintk("lockd: GRANTED_MSG   called\n");
+	if (argp->xdrgen.cookie.len > NLM_MAXCOOKIELEN)
+		return rpc_garbage_args;
 
-	host = nlmsvc_lookup_host(rqstp, argp->lock.caller, argp->lock.len);
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.alock.caller_name, false);
 	if (!host)
 		return rpc_system_err;
 
 	return nlmsvc_callback(rqstp, host, NLMPROC_GRANTED_RES,
-			       __nlmsvc_proc_granted);
+			       __nlmsvc_proc_granted_msg);
 }
 
 /*
@@ -1244,15 +1260,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= XDR_void,
 		.pc_name	= "UNLOCK_MSG",
 	},
-	[NLMPROC_GRANTED_MSG] = {
-		.pc_func = nlmsvc_proc_granted_msg,
-		.pc_decode = nlmsvc_decode_testargs,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct lockd_args),
-		.pc_argzero = sizeof(struct lockd_args),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "GRANTED_MSG",
+	[NLM_GRANTED_MSG] = {
+		.pc_func	= nlmsvc_proc_granted_msg,
+		.pc_decode	= nlm_svc_decode_nlm_testargs,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= sizeof(struct nlm_testargs_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "GRANTED_MSG",
 	},
 	[NLMPROC_TEST_RES] = {
 		.pc_func = nlmsvc_proc_null,
Signature · 1 line
2.54.0
author maintainer
#25 lore raw

PATCH 25/38 lockd: Use xdrgen XDR functions for the NLMv3 TEST_RES procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Continue the xdrgen migration by converting NLMv3 TEST_RES, the callback that a remote NLM uses to return async TEST results to this lockd. The procedure now uses nlm_svc_decode_nlm_testres and nlm_svc_encode_void, generated from the NLM version 3 protocol specification.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is no longer needed.

Setting pc_xdrressize to XDR_void reflects that TEST_RES, as a callback, returns no data; the previous value of St over-reserved a status word in the reply buffer.

---
 fs/lockd/svcproc.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
fs/lockd/svcproc.c +9 -9
index 21a363450d59..ed1164ff431a 100644
@@ -1270,15 +1270,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= XDR_void,
 		.pc_name	= "GRANTED_MSG",
 	},
-	[NLMPROC_TEST_RES] = {
-		.pc_func = nlmsvc_proc_null,
-		.pc_decode = nlmsvc_decode_void,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct lockd_res),
-		.pc_argzero = sizeof(struct lockd_res),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "TEST_RES",
+	[NLM_TEST_RES] = {
+		.pc_func	= nlmsvc_proc_null,
+		.pc_decode	= nlm_svc_decode_nlm_testres,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= sizeof(struct nlm_testres),
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "TEST_RES",
 	},
 	[NLMPROC_LOCK_RES] = {
 		.pc_func = nlmsvc_proc_null,
Signature · 1 line
2.54.0
author maintainer
#26 lore raw

PATCH 26/38 lockd: Use xdrgen XDR functions for the NLMv3 LOCK_RES procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Continue the xdrgen migration by converting NLMv3 LOCK_RES, the callback that a remote NLM uses to return async LOCK results to this lockd. The procedure now uses nlm_svc_decode_nlm_res and nlm_svc_encode_void, generated from the NLM version 3 protocol specification.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is no longer needed.

Setting pc_xdrressize to XDR_void reflects that LOCK_RES, as a callback, returns no data; the previous value of St over-reserved a status word in the reply buffer.

---
 fs/lockd/svcproc.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
fs/lockd/svcproc.c +9 -9
index ed1164ff431a..c86ba0b94793 100644
@@ -1280,15 +1280,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= XDR_void,
 		.pc_name	= "TEST_RES",
 	},
-	[NLMPROC_LOCK_RES] = {
-		.pc_func = nlmsvc_proc_null,
-		.pc_decode = nlmsvc_decode_void,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct lockd_res),
-		.pc_argzero = sizeof(struct lockd_res),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "LOCK_RES",
+	[NLM_LOCK_RES] = {
+		.pc_func	= nlmsvc_proc_null,
+		.pc_decode	= nlm_svc_decode_nlm_res,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= sizeof(struct nlm_res),
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "LOCK_RES",
 	},
 	[NLMPROC_CANCEL_RES] = {
 		.pc_func = nlmsvc_proc_null,
Signature · 1 line
2.54.0
author maintainer
#27 lore raw

PATCH 27/38 lockd: Use xdrgen XDR functions for the NLMv3 CANCEL_RES procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Continue the xdrgen migration by converting NLMv3 CANCEL_RES, the callback that a remote NLM uses to return async CANCEL results to this lockd. The procedure now uses nlm_svc_decode_nlm_res and nlm_svc_encode_void, generated from the NLM version 3 protocol specification.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is no longer needed.

Setting pc_xdrressize to XDR_void reflects that CANCEL_RES, as a callback, returns no data; the previous value of St over-reserved a status word in the reply buffer.

---
 fs/lockd/svcproc.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
fs/lockd/svcproc.c +9 -9
index c86ba0b94793..e7d399afbe83 100644
@@ -1290,15 +1290,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= XDR_void,
 		.pc_name	= "LOCK_RES",
 	},
-	[NLMPROC_CANCEL_RES] = {
-		.pc_func = nlmsvc_proc_null,
-		.pc_decode = nlmsvc_decode_void,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct lockd_res),
-		.pc_argzero = sizeof(struct lockd_res),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "CANCEL_RES",
+	[NLM_CANCEL_RES] = {
+		.pc_func	= nlmsvc_proc_null,
+		.pc_decode	= nlm_svc_decode_nlm_res,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= sizeof(struct nlm_res),
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "CANCEL_RES",
 	},
 	[NLMPROC_UNLOCK_RES] = {
 		.pc_func = nlmsvc_proc_null,
Signature · 1 line
2.54.0
author maintainer
#28 lore raw

PATCH 28/38 lockd: Use xdrgen XDR functions for the NLMv3 UNLOCK_RES procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Continue the xdrgen migration by converting NLMv3 UNLOCK_RES, the callback that a remote NLM uses to return async UNLOCK results to this lockd. The procedure now uses nlm_svc_decode_nlm_res and nlm_svc_encode_void, generated from the NLM version 3 protocol specification.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is no longer needed.

Setting pc_xdrressize to XDR_void reflects that UNLOCK_RES, as a callback, returns no data; the previous value of St over-reserved a status word in the reply buffer.

---
 fs/lockd/svcproc.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
fs/lockd/svcproc.c +9 -9
index e7d399afbe83..f17d3f8d85ec 100644
@@ -1300,15 +1300,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= XDR_void,
 		.pc_name	= "CANCEL_RES",
 	},
-	[NLMPROC_UNLOCK_RES] = {
-		.pc_func = nlmsvc_proc_null,
-		.pc_decode = nlmsvc_decode_void,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct lockd_res),
-		.pc_argzero = sizeof(struct lockd_res),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "UNLOCK_RES",
+	[NLM_UNLOCK_RES] = {
+		.pc_func	= nlmsvc_proc_null,
+		.pc_decode	= nlm_svc_decode_nlm_res,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= sizeof(struct nlm_res),
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "UNLOCK_RES",
 	},
 	[NLMPROC_GRANTED_RES] = {
 		.pc_func = nlmsvc_proc_granted_res,
Signature · 1 line
2.54.0
author maintainer
#29 lore raw

PATCH 29/38 lockd: Use xdrgen XDR functions for the NLMv3 GRANTED_RES procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Continue the xdrgen migration by converting NLMv3 GRANTED_RES, the callback that a remote NLM uses to return async GRANTED results to this lockd. The procedure now uses nlm_svc_decode_nlm_res and nlm_svc_encode_void, generated from the NLM version 3 protocol specification.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is no longer needed.

Setting pc_xdrressize to XDR_void reflects that GRANTED_RES, as a callback, returns no data; the previous value of St over-reserved a status word in the reply buffer.

---
 fs/lockd/svcproc.c | 60 +++++++++++++++++++++++++++++++-----------------------
 1 file changed, 34 insertions(+), 26 deletions(-)
fs/lockd/svcproc.c +34 -26
index f17d3f8d85ec..a2ac747e96ce 100644
@@ -61,6 +61,7 @@ static_assert(offsetof(struct nlm_lockargs_wrapper, xdrgen) == 0);
 
 struct nlm_res_wrapper {
 	struct nlm_res			xdrgen;
+	struct lockd_cookie		cookie;
 };
 
 static_assert(offsetof(struct nlm_res_wrapper, xdrgen) == 0);
@@ -997,6 +998,30 @@ static __be32 nlmsvc_proc_granted_msg(struct svc_rqst *rqstp)
 			       __nlmsvc_proc_granted_msg);
 }
 
+/**
+ * nlmsvc_proc_granted_res - GRANTED_RES: Lock Granted result
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *
+ * RPC synopsis:
+ *   void NLMPROC_GRANTED_RES(nlm_res) = 15;
+ */
+static __be32 nlmsvc_proc_granted_res(struct svc_rqst *rqstp)
+{
+	struct nlm_res_wrapper *argp = rqstp->rq_argp;
+
+	if (!nlmsvc_ops)
+		return rpc_success;
+
+	if (nlm_netobj_to_cookie(&argp->cookie, &argp->xdrgen.cookie))
+		return rpc_success;
+	nlmsvc_grant_reply(&argp->cookie, argp->xdrgen.stat.stat);
+
+	return rpc_success;
+}
+
 /*
  * SHARE: create a DOS share or alter existing share.
  */
@@ -1125,23 +1150,6 @@ nlmsvc_proc_sm_notify(struct svc_rqst *rqstp)
 	return rpc_success;
 }
 
-/*
- * client sent a GRANTED_RES, let's remove the associated block
- */
-static __be32
-nlmsvc_proc_granted_res(struct svc_rqst *rqstp)
-{
-	struct lockd_res *argp = rqstp->rq_argp;
-
-	if (!nlmsvc_ops)
-		return rpc_success;
-
-	dprintk("lockd: GRANTED_RES   called\n");
-
-	nlmsvc_grant_reply(&argp->cookie, argp->status);
-	return rpc_success;
-}
-
 static __be32
 nlmsvc_proc_unused(struct svc_rqst *rqstp)
 {
@@ -1310,15 +1318,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= XDR_void,
 		.pc_name	= "UNLOCK_RES",
 	},
-	[NLMPROC_GRANTED_RES] = {
-		.pc_func = nlmsvc_proc_granted_res,
-		.pc_decode = nlmsvc_decode_res,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct lockd_res),
-		.pc_argzero = sizeof(struct lockd_res),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "GRANTED_RES",
+	[NLM_GRANTED_RES] = {
+		.pc_func	= nlmsvc_proc_granted_res,
+		.pc_decode	= nlm_svc_decode_nlm_res,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= sizeof(struct nlm_res_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "GRANTED_RES",
 	},
 	[NLMPROC_NSM_NOTIFY] = {
 		.pc_func = nlmsvc_proc_sm_notify,
Signature · 1 line
2.54.0
author maintainer
#30 lore raw

PATCH 30/38 lockd: Use xdrgen XDR functions for the NLMv3 SM_NOTIFY procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Continue the xdrgen migration by converting NLMv3 SM_NOTIFY, a private callback from statd to notify lockd when a remote host has rebooted. The procedure now uses nlm_svc_decode_nlm_notifyargs and nlm_svc_encode_void, generated from the NLM version 3 protocol specification.

A new struct nlm_notifyargs_wrapper bridges between the xdrgen-generated nlm_notifyargs and the lockd_reboot structure expected by nlm_host_rebooted(). The wrapper contains both the xdrgen-decoded arguments and a reboot field for the existing API.

Setting pc_argzero to zero is safe because the generated decoder fills argp->xdrgen before the procedure runs, so the zeroing memset performed by the dispatch layer is no longer needed.

Setting pc_xdrressize to XDR_void reflects that SM_NOTIFY returns no data; the previous value of St over-reserved a status word in the reply buffer.

---
 fs/lockd/svcproc.c | 86 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 55 insertions(+), 31 deletions(-)
fs/lockd/svcproc.c +55 -31
index a2ac747e96ce..e0328dc89deb 100644
@@ -80,6 +80,13 @@ struct nlm_unlockargs_wrapper {
 
 static_assert(offsetof(struct nlm_unlockargs_wrapper, xdrgen) == 0);
 
+struct nlm_notifyargs_wrapper {
+	struct nlm_notifyargs		xdrgen;
+	struct lockd_reboot		reboot;
+};
+
+static_assert(offsetof(struct nlm_notifyargs_wrapper, xdrgen) == 0);
+
 static __be32
 nlm_netobj_to_cookie(struct lockd_cookie *cookie, netobj *object)
 {
@@ -1022,6 +1029,44 @@ static __be32 nlmsvc_proc_granted_res(struct svc_rqst *rqstp)
 	return rpc_success;
 }
 
+/**
+ * nlmsvc_proc_sm_notify - SM_NOTIFY: Peer has rebooted
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *   %rpc_system_err:		RPC execution failed.
+ *
+ * The SM_NOTIFY procedure is a private callback from Linux statd and is
+ * not part of the official NLM protocol.
+ *
+ * RPC synopsis:
+ *   void NLM_SM_NOTIFY(nlm_notifyargs) = 16;
+ */
+static __be32 nlmsvc_proc_sm_notify(struct svc_rqst *rqstp)
+{
+	struct nlm_notifyargs_wrapper *argp = rqstp->rq_argp;
+	struct lockd_reboot *reboot = &argp->reboot;
+
+	if (!nlm_privileged_requester(rqstp)) {
+		char buf[RPC_MAX_ADDRBUFLEN];
+
+		pr_warn("lockd: rejected NSM callback from %s\n",
+			svc_print_addr(rqstp, buf, sizeof(buf)));
+		return rpc_system_err;
+	}
+
+	reboot->len = argp->xdrgen.notify.name.len;
+	reboot->mon = (char *)argp->xdrgen.notify.name.data;
+	reboot->state = argp->xdrgen.notify.state;
+	memcpy(&reboot->priv.data, argp->xdrgen.private,
+	       sizeof(reboot->priv.data));
+
+	nlm_host_rebooted(SVC_NET(rqstp), reboot);
+
+	return rpc_success;
+}
+
 /*
  * SHARE: create a DOS share or alter existing share.
  */
@@ -1129,27 +1174,6 @@ nlmsvc_proc_free_all(struct svc_rqst *rqstp)
 	return rpc_success;
 }
 
-/*
- * SM_NOTIFY: private callback from statd (not part of official NLM proto)
- */
-static __be32
-nlmsvc_proc_sm_notify(struct svc_rqst *rqstp)
-{
-	struct lockd_reboot *argp = rqstp->rq_argp;
-
-	dprintk("lockd: SM_NOTIFY     called\n");
-
-	if (!nlm_privileged_requester(rqstp)) {
-		char buf[RPC_MAX_ADDRBUFLEN];
-		printk(KERN_WARNING "lockd: rejected NSM callback from %s\n",
-				svc_print_addr(rqstp, buf, sizeof(buf)));
-		return rpc_system_err;
-	}
-
-	nlm_host_rebooted(SVC_NET(rqstp), argp);
-	return rpc_success;
-}
-
 static __be32
 nlmsvc_proc_unused(struct svc_rqst *rqstp)
 {
@@ -1328,15 +1352,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= XDR_void,
 		.pc_name	= "GRANTED_RES",
 	},
-	[NLMPROC_NSM_NOTIFY] = {
-		.pc_func = nlmsvc_proc_sm_notify,
-		.pc_decode = nlmsvc_decode_reboot,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct lockd_reboot),
-		.pc_argzero = sizeof(struct lockd_reboot),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "SM_NOTIFY",
+	[NLM_SM_NOTIFY] = {
+		.pc_func	= nlmsvc_proc_sm_notify,
+		.pc_decode	= nlm_svc_decode_nlm_notifyargs,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= sizeof(struct nlm_notifyargs_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "SM_NOTIFY",
 	},
 	[17] = {
 		.pc_func = nlmsvc_proc_unused,
@@ -1418,10 +1442,10 @@ union nlmsvc_xdrstore {
 	struct nlm_lockargs_wrapper	lockargs;
 	struct nlm_cancargs_wrapper	cancargs;
 	struct nlm_unlockargs_wrapper	unlockargs;
+	struct nlm_notifyargs_wrapper	notifyargs;
 	struct nlm_testres_wrapper	testres;
 	struct nlm_res_wrapper		res;
 	struct lockd_args		args;
-	struct lockd_reboot		reboot;
 };
 
 /*
Signature · 1 line
2.54.0
author maintainer
#31 lore raw

PATCH 31/38 lockd: Convert NLMv3 server-side undefined procedures to xdrgen

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Complete the xdrgen migration of NLMv3 server-side procedures by converting the three unused procedure slots (17, 18, and 19). These slots already returned rpc_proc_unavail; they are converted here only to retire the last users of the hand-coded nlmsvc_decode_void and nlmsvc_encode_void helpers.

The three undefined procedure entries now use the xdrgen functions nlm_svc_decode_void and nlm_svc_encode_void. The nlmsvc_proc_unused function is also moved earlier in the file to follow the convention of placing procedure implementations before the procedure table.

The pc_argsize, pc_ressize, and pc_argzero fields are now set to zero since no arguments or results are processed. Setting pc_xdrressize to XDR_void reflects that these procedures return no reply payload; the previous value of St over-reserved a status word in the reply buffer.

---
 fs/lockd/svcproc.c | 66 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 36 insertions(+), 30 deletions(-)
fs/lockd/svcproc.c +36 -30
index e0328dc89deb..79c410a75156 100644
@@ -1067,6 +1067,18 @@ static __be32 nlmsvc_proc_sm_notify(struct svc_rqst *rqstp)
 	return rpc_success;
 }
 
+/**
+ * nlmsvc_proc_unused - stub for unused procedures
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_proc_unavail:	Program can't support procedure.
+ */
+static __be32 nlmsvc_proc_unused(struct svc_rqst *rqstp)
+{
+	return rpc_proc_unavail;
+}
+
 /*
  * SHARE: create a DOS share or alter existing share.
  */
@@ -1174,12 +1186,6 @@ nlmsvc_proc_free_all(struct svc_rqst *rqstp)
 	return rpc_success;
 }
 
-static __be32
-nlmsvc_proc_unused(struct svc_rqst *rqstp)
-{
-	return rpc_proc_unavail;
-}
-
 /*
  * NLM Server procedures.
  */
@@ -1363,34 +1369,34 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_name	= "SM_NOTIFY",
 	},
 	[17] = {
-		.pc_func = nlmsvc_proc_unused,
-		.pc_decode = nlmsvc_decode_void,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct nlm_void),
-		.pc_argzero = sizeof(struct nlm_void),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "UNUSED",
+		.pc_func	= nlmsvc_proc_unused,
+		.pc_decode	= nlm_svc_decode_void,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= 0,
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "UNUSED",
 	},
 	[18] = {
-		.pc_func = nlmsvc_proc_unused,
-		.pc_decode = nlmsvc_decode_void,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct nlm_void),
-		.pc_argzero = sizeof(struct nlm_void),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "UNUSED",
+		.pc_func	= nlmsvc_proc_unused,
+		.pc_decode	= nlm_svc_decode_void,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= 0,
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "UNUSED",
 	},
 	[19] = {
-		.pc_func = nlmsvc_proc_unused,
-		.pc_decode = nlmsvc_decode_void,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct nlm_void),
-		.pc_argzero = sizeof(struct nlm_void),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = St,
-		.pc_name = "UNUSED",
+		.pc_func	= nlmsvc_proc_unused,
+		.pc_decode	= nlm_svc_decode_void,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= 0,
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "UNUSED",
 	},
 	[NLMPROC_SHARE] = {
 		.pc_func = nlmsvc_proc_share,
Signature · 1 line
2.54.0
author maintainer
#32 lore raw

PATCH 32/38 lockd: Use xdrgen XDR functions for the NLMv3 SHARE procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Convert the NLMv3 SHARE procedure to use xdrgen-generated XDR functions nlm_svc_decode_nlm_shareargs and nlm_svc_encode_nlm_shareres.

This patch introduces struct nlm_shareargs_wrapper and struct nlm_shareres_wrapper to bridge between the xdrgen-generated structures and the internal lockd types. The procedure handler is updated to access arguments through the argp->xdrgen hierarchy and uses nlm3svc_lookup_host and nlm3svc_lookup_file for host and file resolution.

The .pc_argzero field is set to zero because the generated decoder fills argp->xdrgen before the procedure runs, so the zeroing memset performed by the dispatch layer is no longer needed.

---
 fs/lockd/svcproc.c | 114 ++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 78 insertions(+), 36 deletions(-)
fs/lockd/svcproc.c +78 -36
index 79c410a75156..32625ee07c35 100644
@@ -87,6 +87,19 @@ struct nlm_notifyargs_wrapper {
 
 static_assert(offsetof(struct nlm_notifyargs_wrapper, xdrgen) == 0);
 
+struct nlm_shareargs_wrapper {
+	struct nlm_shareargs		xdrgen;
+	struct lockd_lock		lock;
+};
+
+static_assert(offsetof(struct nlm_shareargs_wrapper, xdrgen) == 0);
+
+struct nlm_shareres_wrapper {
+	struct nlm_shareres		xdrgen;
+};
+
+static_assert(offsetof(struct nlm_shareres_wrapper, xdrgen) == 0);
+
 static __be32
 nlm_netobj_to_cookie(struct lockd_cookie *cookie, netobj *object)
 {
@@ -1079,42 +1092,69 @@ static __be32 nlmsvc_proc_unused(struct svc_rqst *rqstp)
 	return rpc_proc_unavail;
 }
 
-/*
- * SHARE: create a DOS share or alter existing share.
+/**
+ * nlmsvc_proc_share - SHARE: Open a file using DOS file-sharing modes
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *   %rpc_drop_reply:		Do not send an RPC reply.
+ *
+ * RPC synopsis:
+ *   nlm_shareres NLM_SHARE(nlm_shareargs) = 20;
+ *
+ * Permissible procedure status codes:
+ *   %LCK_GRANTED:		The requested share lock was granted.
+ *   %LCK_DENIED:		The requested lock conflicted with existing
+ *				lock reservations for the file.
+ *   %LCK_DENIED_GRACE_PERIOD:	The server has recently restarted and is
+ *				re-establishing existing locks, and is not
+ *				yet ready to accept normal service requests.
+ *
+ * The Linux NLM server implementation also returns:
+ *   %LCK_DENIED_NOLOCKS:	A needed resource could not be allocated.
  */
-static __be32
-nlmsvc_proc_share(struct svc_rqst *rqstp)
+static __be32 nlmsvc_proc_share(struct svc_rqst *rqstp)
 {
-	struct lockd_args *argp = rqstp->rq_argp;
-	struct lockd_res *resp = rqstp->rq_resp;
-	struct nlm_host	*host;
-	struct nlm_file	*file;
+	struct nlm_shareargs_wrapper *argp = rqstp->rq_argp;
+	struct nlm_shareres_wrapper *resp = rqstp->rq_resp;
+	struct lockd_lock *lock = &argp->lock;
+	struct nlm_host	*host = NULL;
+	struct nlm_file	*file = NULL;
+	struct nlm_lock xdr_lock = {
+		.fh		= argp->xdrgen.share.fh,
+		.oh		= argp->xdrgen.share.oh,
+		.uppid		= LOCKD_SHARE_SVID,
+	};
 
-	dprintk("lockd: SHARE         called\n");
+	resp->xdrgen.cookie = argp->xdrgen.cookie;
 
-	resp->cookie = argp->cookie;
+	resp->xdrgen.stat = nlm_lck_denied_grace_period;
+	if (locks_in_grace(SVC_NET(rqstp)) && !argp->xdrgen.reclaim)
+		goto out;
 
-	/* Don't accept new lock requests during grace period */
-	if (locks_in_grace(SVC_NET(rqstp)) && !argp->reclaim) {
-		resp->status = nlm_lck_denied_grace_period;
-		return rpc_success;
-	}
+	resp->xdrgen.stat = nlm_lck_denied_nolocks;
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.share.caller_name, false);
+	if (!host)
+		goto out;
 
-	/* Obtain client and file */
-	if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
-		return resp->status == nlm__int__drop_reply ?
-			rpc_drop_reply : rpc_success;
+	resp->xdrgen.stat = nlm3svc_lookup_file(rqstp, host, lock, &file,
+						&xdr_lock, F_RDLCK);
+	if (resp->xdrgen.stat)
+		goto out;
 
-	/* Now try to create the share */
-	resp->status = cast_status(nlmsvc_share_file(host, file, &argp->lock.oh,
-						     argp->fsm_access,
-						     argp->fsm_mode));
+	resp->xdrgen.stat = nlmsvc_share_file(host, file, &lock->oh,
+					      argp->xdrgen.share.access,
+					      argp->xdrgen.share.mode);
 
-	dprintk("lockd: SHARE         status %d\n", ntohl(resp->status));
-	nlmsvc_release_lockowner(&argp->lock);
+	nlmsvc_release_lockowner(lock);
+
+out:
+	if (file)
+		nlm_release_file(file);
 	nlmsvc_release_host(host);
-	nlm_release_file(file);
-	return rpc_success;
+	return resp->xdrgen.stat == nlm__int__drop_reply ?
+		rpc_drop_reply : rpc_success;
 }
 
 /*
@@ -1398,15 +1438,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= XDR_void,
 		.pc_name	= "UNUSED",
 	},
-	[NLMPROC_SHARE] = {
-		.pc_func = nlmsvc_proc_share,
-		.pc_decode = nlmsvc_decode_shareargs,
-		.pc_encode = nlmsvc_encode_shareres,
-		.pc_argsize = sizeof(struct lockd_args),
-		.pc_argzero = sizeof(struct lockd_args),
-		.pc_ressize = sizeof(struct lockd_res),
-		.pc_xdrressize = Ck+St+1,
-		.pc_name = "SHARE",
+	[NLM_SHARE] = {
+		.pc_func	= nlmsvc_proc_share,
+		.pc_decode	= nlm_svc_decode_nlm_shareargs,
+		.pc_encode	= nlm_svc_encode_nlm_shareres,
+		.pc_argsize	= sizeof(struct nlm_shareargs_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= sizeof(struct nlm_shareres_wrapper),
+		.pc_xdrressize	= NLM3_nlm_shareres_sz,
+		.pc_name	= "SHARE",
 	},
 	[NLMPROC_UNSHARE] = {
 		.pc_func = nlmsvc_proc_unshare,
@@ -1449,8 +1489,10 @@ union nlmsvc_xdrstore {
 	struct nlm_cancargs_wrapper	cancargs;
 	struct nlm_unlockargs_wrapper	unlockargs;
 	struct nlm_notifyargs_wrapper	notifyargs;
+	struct nlm_shareargs_wrapper	shareargs;
 	struct nlm_testres_wrapper	testres;
 	struct nlm_res_wrapper		res;
+	struct nlm_shareres_wrapper	shareres;
 	struct lockd_args		args;
 };
 
Signature · 1 line
2.54.0
author maintainer
#33 lore raw

PATCH 33/38 lockd: Use xdrgen XDR functions for the NLMv3 UNSHARE procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Convert the NLMv3 UNSHARE procedure to use xdrgen-generated XDR functions nlm_svc_decode_nlm_shareargs and nlm_svc_encode_nlm_shareres.

The procedure handler is updated to use the wrapper structures (nlm_shareargs_wrapper and nlm_shareres_wrapper) introduced by the SHARE conversion patch and accesses arguments through the argp->xdrgen hierarchy.

The .pc_argzero field is set to zero because the generated decoder fills argp->xdrgen before the procedure runs, so the zeroing memset performed by the dispatch layer is no longer needed.

---
 fs/lockd/svcproc.c | 94 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 59 insertions(+), 35 deletions(-)
fs/lockd/svcproc.c +59 -35
index 32625ee07c35..de4c15aa725c 100644
@@ -1157,41 +1157,65 @@ static __be32 nlmsvc_proc_share(struct svc_rqst *rqstp)
 		rpc_drop_reply : rpc_success;
 }
 
-/*
- * UNSHARE: Release a DOS share.
+/**
+ * nlmsvc_proc_unshare - UNSHARE: Release a share reservation
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *   %rpc_drop_reply:		Do not send an RPC reply.
+ *
+ * RPC synopsis:
+ *   nlm_shareres NLM_UNSHARE(nlm_shareargs) = 21;
+ *
+ * Permissible procedure status codes:
+ *   %LCK_GRANTED:		The share reservation was released.
+ *   %LCK_DENIED_GRACE_PERIOD:	The server has recently restarted and is
+ *				re-establishing existing locks, and is not
+ *				yet ready to accept normal service requests.
+ *
+ * The Linux NLM server implementation also returns:
+ *   %LCK_DENIED_NOLOCKS:	A needed resource could not be allocated.
  */
-static __be32
-nlmsvc_proc_unshare(struct svc_rqst *rqstp)
+static __be32 nlmsvc_proc_unshare(struct svc_rqst *rqstp)
 {
-	struct lockd_args *argp = rqstp->rq_argp;
-	struct lockd_res *resp = rqstp->rq_resp;
-	struct nlm_host	*host;
-	struct nlm_file	*file;
+	struct nlm_shareargs_wrapper *argp = rqstp->rq_argp;
+	struct nlm_shareres_wrapper *resp = rqstp->rq_resp;
+	struct lockd_lock *lock = &argp->lock;
+	struct nlm_lock xdr_lock = {
+		.fh		= argp->xdrgen.share.fh,
+		.oh		= argp->xdrgen.share.oh,
+		.uppid		= LOCKD_SHARE_SVID,
+	};
+	struct nlm_host	*host = NULL;
+	struct nlm_file	*file = NULL;
 
-	dprintk("lockd: UNSHARE       called\n");
+	resp->xdrgen.cookie = argp->xdrgen.cookie;
 
-	resp->cookie = argp->cookie;
+	resp->xdrgen.stat = nlm_lck_denied_grace_period;
+	if (locks_in_grace(SVC_NET(rqstp)))
+		goto out;
 
-	/* Don't accept requests during grace period */
-	if (locks_in_grace(SVC_NET(rqstp))) {
-		resp->status = nlm_lck_denied_grace_period;
-		return rpc_success;
-	}
+	resp->xdrgen.stat = nlm_lck_denied_nolocks;
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.share.caller_name, false);
+	if (!host)
+		goto out;
 
-	/* Obtain client and file */
-	if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
-		return resp->status == nlm__int__drop_reply ?
-			rpc_drop_reply : rpc_success;
+	resp->xdrgen.stat = nlm3svc_lookup_file(rqstp, host, lock, &file,
+						&xdr_lock, F_RDLCK);
+	if (resp->xdrgen.stat)
+		goto out;
 
-	/* Now try to unshare the file */
-	resp->status = cast_status(nlmsvc_unshare_file(host, file,
-						       &argp->lock.oh));
+	resp->xdrgen.stat = nlmsvc_unshare_file(host, file, &lock->oh);
 
-	dprintk("lockd: UNSHARE       status %d\n", ntohl(resp->status));
-	nlmsvc_release_lockowner(&argp->lock);
+	nlmsvc_release_lockowner(lock);
+
+out:
+	if (file)
+		nlm_release_file(file);
 	nlmsvc_release_host(host);
-	nlm_release_file(file);
-	return rpc_success;
+	return resp->xdrgen.stat == nlm__int__drop_reply ?
+		rpc_drop_reply : rpc_success;
 }
 
 /*
@@ -1448,15 +1472,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= NLM3_nlm_shareres_sz,
 		.pc_name	= "SHARE",
 	},
-	[NLMPROC_UNSHARE] = {
-		.pc_func = nlmsvc_proc_unshare,
-		.pc_decode = nlmsvc_decode_shareargs,
-		.pc_encode = nlmsvc_encode_shareres,
-		.pc_argsize = sizeof(struct lockd_args),
-		.pc_argzero = sizeof(struct lockd_args),
-		.pc_ressize = sizeof(struct lockd_res),
-		.pc_xdrressize = Ck+St+1,
-		.pc_name = "UNSHARE",
+	[NLM_UNSHARE] = {
+		.pc_func	= nlmsvc_proc_unshare,
+		.pc_decode	= nlm_svc_decode_nlm_shareargs,
+		.pc_encode	= nlm_svc_encode_nlm_shareres,
+		.pc_argsize	= sizeof(struct nlm_shareargs_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= sizeof(struct nlm_shareres_wrapper),
+		.pc_xdrressize	= NLM3_nlm_shareres_sz,
+		.pc_name	= "UNSHARE",
 	},
 	[NLMPROC_NM_LOCK] = {
 		.pc_func = nlmsvc_proc_nm_lock,
Signature · 1 line
2.54.0
author maintainer
#34 lore raw

PATCH 34/38 lockd: Use xdrgen XDR functions for the NLMv3 NM_LOCK procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

Now that nlmsvc_do_lock() has been introduced to handle both monitored and non-monitored lock requests, the NLMv3 NM_LOCK procedure can be converted to use xdrgen-generated XDR functions. This conversion allows the removal of __nlmsvc_proc_lock(), a helper function that was previously shared between the LOCK and NM_LOCK procedures.

Replace the NLMPROC_NM_LOCK entry in the nlmsvc_procedures array with an entry that uses xdrgen-built XDR decoders and encoders. The procedure handler is reduced to a thin wrapper around nlmsvc_do_lock() with the monitored flag set to false.

The pc_argzero=0 choice was justified for the LOCK conversion and applies unchanged here, since both procedures share the same nlm_lockargs_wrapper layout and decoder.

---
 fs/lockd/svcproc.c | 86 ++++++++++++++++++++++--------------------------------
 1 file changed, 35 insertions(+), 51 deletions(-)
fs/lockd/svcproc.c +35 -51
index de4c15aa725c..4ca0eaef2966 100644
@@ -392,38 +392,6 @@ static __be32 nlmsvc_proc_test(struct svc_rqst *rqstp)
 		rpc_drop_reply : rpc_success;
 }
 
-static __be32
-__nlmsvc_proc_lock(struct svc_rqst *rqstp, struct lockd_res *resp)
-{
-	struct lockd_args *argp = rqstp->rq_argp;
-	struct nlm_host	*host;
-	struct nlm_file	*file;
-	__be32 rc = rpc_success;
-
-	dprintk("lockd: LOCK          called\n");
-
-	resp->cookie = argp->cookie;
-
-	/* Obtain client and file */
-	if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
-		return resp->status == nlm__int__drop_reply ?
-			rpc_drop_reply : rpc_success;
-
-	/* Now try to lock the file */
-	resp->status = cast_status(nlmsvc_lock(rqstp, file, host, &argp->lock,
-					       argp->block, &argp->cookie,
-					       argp->reclaim));
-	if (resp->status == nlm__int__drop_reply)
-		rc = rpc_drop_reply;
-	else
-		dprintk("lockd: LOCK         status %d\n", ntohl(resp->status));
-
-	nlmsvc_release_lockowner(&argp->lock);
-	nlmsvc_release_host(host);
-	nlm_release_file(file);
-	return rc;
-}
-
 static __be32
 nlmsvc_do_lock(struct svc_rqst *rqstp, bool monitored)
 {
@@ -1218,18 +1186,34 @@ static __be32 nlmsvc_proc_unshare(struct svc_rqst *rqstp)
 		rpc_drop_reply : rpc_success;
 }
 
-/*
- * NM_LOCK: Create an unmonitored lock
+/**
+ * nlmsvc_proc_nm_lock - NM_LOCK: Establish a non-monitored lock
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *   %rpc_drop_reply:		Do not send an RPC reply.
+ *
+ * RPC synopsis:
+ *   nlm_res NLM_NM_LOCK(nlm_lockargs) = 22;
+ *
+ * Permissible procedure status codes:
+ *   %LCK_GRANTED:		The requested lock was granted.
+ *   %LCK_DENIED:		The requested lock conflicted with existing
+ *				lock reservations for the file.
+ *   %LCK_DENIED_NOLOCKS:	The server could not allocate the resources
+ *				needed to process the request.
+ *   %LCK_BLOCKED:		The blocking request cannot be granted
+ *				immediately. The server will send an
+ *				NLM_GRANTED callback to the client when
+ *				the lock can be granted.
+ *   %LCK_DENIED_GRACE_PERIOD:	The server has recently restarted and is
+ *				re-establishing existing locks, and is not
+ *				yet ready to accept normal service requests.
  */
-static __be32
-nlmsvc_proc_nm_lock(struct svc_rqst *rqstp)
+static __be32 nlmsvc_proc_nm_lock(struct svc_rqst *rqstp)
 {
-	struct lockd_args *argp = rqstp->rq_argp;
-
-	dprintk("lockd: NM_LOCK       called\n");
-
-	argp->monitor = 0;		/* just clean the monitor flag */
-	return __nlmsvc_proc_lock(rqstp, rqstp->rq_resp);
+	return nlmsvc_do_lock(rqstp, false);
 }
 
 /*
@@ -1482,15 +1466,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= NLM3_nlm_shareres_sz,
 		.pc_name	= "UNSHARE",
 	},
-	[NLMPROC_NM_LOCK] = {
-		.pc_func = nlmsvc_proc_nm_lock,
-		.pc_decode = nlmsvc_decode_lockargs,
-		.pc_encode = nlmsvc_encode_res,
-		.pc_argsize = sizeof(struct lockd_args),
-		.pc_argzero = sizeof(struct lockd_args),
-		.pc_ressize = sizeof(struct lockd_res),
-		.pc_xdrressize = Ck+St,
-		.pc_name = "NM_LOCK",
+	[NLM_NM_LOCK] = {
+		.pc_func	= nlmsvc_proc_nm_lock,
+		.pc_decode	= nlm_svc_decode_nlm_lockargs,
+		.pc_encode	= nlm_svc_encode_nlm_res,
+		.pc_argsize	= sizeof(struct nlm_lockargs_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= sizeof(struct nlm_res_wrapper),
+		.pc_xdrressize	= NLM3_nlm_res_sz,
+		.pc_name	= "NM_LOCK",
 	},
 	[NLMPROC_FREE_ALL] = {
 		.pc_func = nlmsvc_proc_free_all,
Signature · 1 line
2.54.0
author maintainer
#35 lore raw

PATCH 35/38 lockd: Use xdrgen XDR functions for the NLMv3 FREE_ALL procedure

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

With all other NLMv3 procedures now converted to xdrgen-generated XDR functions, the FREE_ALL procedure can be converted as well. This conversion allows the removal of nlmsvc_retrieve_args(), a 52-line helper function that was used only by FREE_ALL to retrieve client information from lockd's internal data structures.

Replace the NLMPROC_FREE_ALL entry in the nlmsvc_procedures array with an entry that uses xdrgen-built XDR decoders and encoders. The procedure handler is updated to use the new wrapper structure (nlm_notify_wrapper) and call nlm3svc_lookup_host() directly, eliminating the need for the now-removed helper function.

Setting pc_argzero to zero is safe because the generated decoder fills the argp->xdrgen subfields before the procedure runs, so the zeroing memset performed by the dispatch layer is not needed. The nlm_notify_wrapper structure has no members beyond the xdrgen substructure, so no further initialization is required.

---
 fs/lockd/svcproc.c | 113 ++++++++++++++++-------------------------------------
 1 file changed, 33 insertions(+), 80 deletions(-)
fs/lockd/svcproc.c +33 -80
index 4ca0eaef2966..ef1ae701b43b 100644
@@ -100,6 +100,12 @@ struct nlm_shareres_wrapper {
 
 static_assert(offsetof(struct nlm_shareres_wrapper, xdrgen) == 0);
 
+struct nlm_notify_wrapper {
+	struct nlm_notify		xdrgen;
+};
+
+static_assert(offsetof(struct nlm_notify_wrapper, xdrgen) == 0);
+
 static __be32
 nlm_netobj_to_cookie(struct lockd_cookie *cookie, netobj *object)
 {
@@ -240,68 +246,6 @@ static inline __be32 cast_status(__be32 status)
 }
 #endif
 
-/*
- * Obtain client and file from arguments
- */
-static __be32
-nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct lockd_args *argp,
-			struct nlm_host **hostp, struct nlm_file **filp)
-{
-	struct nlm_host		*host = NULL;
-	struct nlm_file		*file = NULL;
-	struct lockd_lock	*lock = &argp->lock;
-	bool			is_test = (rqstp->rq_proc == NLMPROC_TEST ||
-					   rqstp->rq_proc == NLMPROC_TEST_MSG);
-	int			mode;
-	__be32			error = 0;
-
-	/* nfsd callbacks must have been installed for this procedure */
-	if (!nlmsvc_ops)
-		return nlm_lck_denied_nolocks;
-
-	/* Obtain host handle */
-	if (!(host = nlmsvc_lookup_host(rqstp, lock->caller, lock->len))
-	 || (argp->monitor && nsm_monitor(host) < 0))
-		goto no_locks;
-	*hostp = host;
-
-	/* Obtain file pointer. Not used by FREE_ALL call. */
-	if (filp != NULL) {
-		mode = lock_to_openmode(&lock->fl);
-
-		if (is_test)
-			mode = O_RDWR;
-
-		error = cast_status(nlm_lookup_file(rqstp, &file, lock, mode));
-		if (error != 0)
-			goto no_locks;
-		*filp = file;
-
-		/* Set up the missing parts of the file_lock structure */
-		lock->fl.c.flc_flags = FL_POSIX;
-		if (is_test)
-			lock->fl.c.flc_file = nlmsvc_file_file(file);
-		else
-			lock->fl.c.flc_file = file->f_file[mode];
-		lock->fl.c.flc_pid = current->tgid;
-		lock->fl.fl_lmops = &nlmsvc_lock_operations;
-		nlmsvc_locks_init_private(&lock->fl, host, (pid_t)lock->svid);
-		if (!lock->fl.c.flc_owner) {
-			/* lockowner allocation has failed */
-			nlmsvc_release_host(host);
-			return nlm_lck_denied_nolocks;
-		}
-	}
-
-	return 0;
-
-no_locks:
-	nlmsvc_release_host(host);
-	if (error)
-		return error;
-	return nlm_lck_denied_nolocks;
-}
-
 /**
  * nlmsvc_proc_null - NULL: Test for presence of service
  * @rqstp: RPC transaction context
@@ -1216,21 +1160,30 @@ static __be32 nlmsvc_proc_nm_lock(struct svc_rqst *rqstp)
 	return nlmsvc_do_lock(rqstp, false);
 }
 
-/*
- * FREE_ALL: Release all locks and shares held by client
+/**
+ * nlmsvc_proc_free_all - FREE_ALL: Discard client's lock and share state
+ * @rqstp: RPC transaction context
+ *
+ * Returns:
+ *   %rpc_success:		RPC executed successfully.
+ *
+ * RPC synopsis:
+ *   void NLMPROC_FREE_ALL(nlm_notify) = 23;
  */
-static __be32
-nlmsvc_proc_free_all(struct svc_rqst *rqstp)
+static __be32 nlmsvc_proc_free_all(struct svc_rqst *rqstp)
 {
-	struct lockd_args *argp = rqstp->rq_argp;
+	struct nlm_notify_wrapper *argp = rqstp->rq_argp;
 	struct nlm_host	*host;
 
-	/* Obtain client */
-	if (nlmsvc_retrieve_args(rqstp, argp, &host, NULL))
-		return rpc_success;
+	host = nlm3svc_lookup_host(rqstp, argp->xdrgen.name, false);
+	if (!host)
+		goto out;
 
 	nlmsvc_free_host_resources(host);
+
 	nlmsvc_release_host(host);
+
+out:
 	return rpc_success;
 }
 
@@ -1476,15 +1429,15 @@ static const struct svc_procedure nlmsvc_procedures[24] = {
 		.pc_xdrressize	= NLM3_nlm_res_sz,
 		.pc_name	= "NM_LOCK",
 	},
-	[NLMPROC_FREE_ALL] = {
-		.pc_func = nlmsvc_proc_free_all,
-		.pc_decode = nlmsvc_decode_notify,
-		.pc_encode = nlmsvc_encode_void,
-		.pc_argsize = sizeof(struct lockd_args),
-		.pc_argzero = sizeof(struct lockd_args),
-		.pc_ressize = sizeof(struct nlm_void),
-		.pc_xdrressize = 0,
-		.pc_name = "FREE_ALL",
+	[NLM_FREE_ALL] = {
+		.pc_func	= nlmsvc_proc_free_all,
+		.pc_decode	= nlm_svc_decode_nlm_notify,
+		.pc_encode	= nlm_svc_encode_void,
+		.pc_argsize	= sizeof(struct nlm_notify_wrapper),
+		.pc_argzero	= 0,
+		.pc_ressize	= 0,
+		.pc_xdrressize	= XDR_void,
+		.pc_name	= "FREE_ALL",
 	},
 };
 
@@ -1498,10 +1451,10 @@ union nlmsvc_xdrstore {
 	struct nlm_unlockargs_wrapper	unlockargs;
 	struct nlm_notifyargs_wrapper	notifyargs;
 	struct nlm_shareargs_wrapper	shareargs;
+	struct nlm_notify_wrapper	notify;
 	struct nlm_testres_wrapper	testres;
 	struct nlm_res_wrapper		res;
 	struct nlm_shareres_wrapper	shareres;
-	struct lockd_args		args;
 };
 
 /*
Signature · 1 line
2.54.0
author maintainer
#36 lore raw

PATCH 36/38 lockd: Remove C macros that are no longer used

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

The conversion of all NLMv3 procedures to xdrgen-generated XDR functions is complete. The hand-rolled XDR size calculation macros (Ck, No, St, Rg) and the nlm_void structure definition served only the older implementations and are now unused.

Also removes NLMDBG_FACILITY, which was set to the client debug flag in server-side code but never referenced, and corrects a comment to specify "NLMv3 Server procedures".

---
 fs/lockd/svcproc.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
fs/lockd/svcproc.c +1 -10
index ef1ae701b43b..f62b0b39c5e9 100644
@@ -24,8 +24,6 @@
 #include "share.h"
 #include "nlm3xdr_gen.h"
 
-#define NLMDBG_FACILITY		NLMDBG_CLIENT
-
 /*
  * Size of an NFSv2 file handle, in bytes, which is 32.
  * Defined locally to avoid including uapi/linux/nfs2.h.
@@ -1188,16 +1186,9 @@ static __be32 nlmsvc_proc_free_all(struct svc_rqst *rqstp)
 }
 
 /*
- * NLM Server procedures.
+ * NLMv3 Server procedures.
  */
 
-struct nlm_void			{ int dummy; };
-
-#define	Ck	(1+XDR_QUADLEN(NLM_MAXCOOKIELEN))	/* cookie */
-#define	St	1				/* status */
-#define	No	(1+1024/4)			/* Net Obj */
-#define	Rg	2				/* range - offset + size */
-
 static const struct svc_procedure nlmsvc_procedures[24] = {
 	[NLM_NULL] = {
 		.pc_func	= nlmsvc_proc_null,
Signature · 1 line
2.54.0
author maintainer
#37 lore raw

PATCH 37/38 lockd: Remove dead code from fs/lockd/xdr.c

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

All NLMv3 server-side procedures now dispatch through xdrgen-generated encoder and decoder functions, leaving the hand-written XDR processing in fs/lockd/xdr.c with no remaining callers.

Remove fs/lockd/xdr.c, the fs/lockd/svcxdr.h header it included, the Makefile entry, and the now-unused nlmsvc_decode_* / nlmsvc_encode_* prototypes from fs/lockd/xdr.h. The structure definitions and status code macros in xdr.h are retained as they are still used by the client-side code.

---
 fs/lockd/Makefile |   2 +-
 fs/lockd/svcxdr.h | 142 ----------------------
 fs/lockd/xdr.c    | 354 ------------------------------------------------------
 fs/lockd/xdr.h    |  20 ---
 4 files changed, 1 insertion(+), 517 deletions(-)
fs/lockd/Makefile +1 -1
index 951a74e4847a..3f9569d3ba0e 100644
@@ -8,7 +8,7 @@ ccflags-y += -I$(src)			# needed for trace events
 obj-$(CONFIG_LOCKD) += lockd.o
 
 lockd-y := clntlock.o clntproc.o clntxdr.o host.o svc.o svclock.o \
-	   svcshare.o svcproc.o svcsubs.o mon.o trace.o xdr.o netlink.o \
+	   svcshare.o svcproc.o svcsubs.o mon.o trace.o netlink.o \
 	   nlm3xdr_gen.o
 lockd-$(CONFIG_LOCKD_V4) += clnt4xdr.o svc4proc.o nlm4xdr_gen.o
 lockd-$(CONFIG_PROC_FS) += procfs.o
fs/lockd/svcxdr.h deleted +0 -142

142 lines not on this page · raw message

fs/lockd/xdr.c deleted +0 -354

354 lines not on this page · raw message

fs/lockd/xdr.h +0 -20
index 65d2d6d34310..a1126cca98c6 100644
@@ -20,8 +20,6 @@ struct nsm_private {
 	unsigned char		data[SM_PRIV_SIZE];
 };
 
-struct svc_rqst;
-
 #define NLM_MAXCOOKIELEN    	32
 #define NLM_MAXSTRLEN		1024
 
@@ -63,9 +61,6 @@ struct lockd_args {
 	u32			block;
 	u32			reclaim;
 	u32			state;
-	u32			monitor;
-	u32			fsm_access;
-	u32			fsm_mode;
 };
 
 /*
@@ -87,19 +82,4 @@ struct lockd_reboot {
 	struct nsm_private	priv;
 };
 
-bool	nlmsvc_decode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr);
-bool	nlmsvc_decode_testargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
-bool	nlmsvc_decode_lockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
-bool	nlmsvc_decode_cancargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
-bool	nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
-bool	nlmsvc_decode_res(struct svc_rqst *rqstp, struct xdr_stream *xdr);
-bool	nlmsvc_decode_reboot(struct svc_rqst *rqstp, struct xdr_stream *xdr);
-bool	nlmsvc_decode_shareargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
-bool	nlmsvc_decode_notify(struct svc_rqst *rqstp, struct xdr_stream *xdr);
-
-bool	nlmsvc_encode_testres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
-bool	nlmsvc_encode_res(struct svc_rqst *rqstp, struct xdr_stream *xdr);
-bool	nlmsvc_encode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr);
-bool	nlmsvc_encode_shareres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
-
 #endif /* _LOCKD_XDR_H */
Signature · 1 line
2.54.0
author maintainer
#38 lore raw

PATCH 38/38 lockd: Unify cast_status

In reply to Chuck Lever

From: Chuck Lever <[email protected]>

cast_status folds internal lock-daemon sentinels into NLMv1/v3 wire status codes for the v3 reply path. Two variants have existed since the original kernel import: a strict allowlist under CONFIG_LOCKD_V4 and a sentinel-translation form for the !CONFIG_LOCKD_V4 build. The split was never grounded in a behavioural difference -- nlmsvc_testlock and nlmsvc_lock, which feed cast_status, return the same set of values in both configurations -- and recent xdrgen conversions have narrowed the caller set further: nlm__int__stale_fh and nlm__int__failed are now translated at their point of origin in nlm3svc_lookup_file, and the cast_status wraps around nlmsvc_cancel_blocked and nlmsvc_unlock have been dropped because those functions return only wire codes.

Collapse the two variants into one. The unified form keeps the CONFIG_LOCKD_V4 arm's allowlist, retains the nlm__int__deadlock translation, and folds anything else to nlm_lck_denied_nolocks after a pr_warn_once so an unexpected sentinel from a future refactor remains visible in the kernel log instead of being silently passed to the wire encoder.

---
 fs/lockd/svcproc.c | 23 ++---------------------
 1 file changed, 2 insertions(+), 21 deletions(-)
fs/lockd/svcproc.c +2 -21
index f62b0b39c5e9..4836887f11ef 100644
@@ -203,7 +203,6 @@ nlm3svc_lookup_file(struct svc_rqst *rqstp, struct nlm_host *host,
 	return nlm_granted;
 }
 
-#ifdef CONFIG_LOCKD_V4
 static inline __be32 cast_status(__be32 status)
 {
 	switch (status) {
@@ -218,31 +217,13 @@ static inline __be32 cast_status(__be32 status)
 		status = nlm_lck_denied;
 		break;
 	default:
+		pr_warn_once("lockd: unhandled internal status %u\n",
+			     be32_to_cpu(status));
 		status = nlm_lck_denied_nolocks;
-	}
-
-	return status;
-}
-#else
-static inline __be32 cast_status(__be32 status)
-{
-	switch (status) {
-	case nlm__int__deadlock:
-		status = nlm_lck_denied;
-		break;
-	case nlm__int__stale_fh:
-	case nlm__int__failed:
-		status = nlm_lck_denied_nolocks;
-		break;
-	default:
-		if (be32_to_cpu(status) > be32_to_cpu(nlm__int__drop_reply))
-			pr_warn_once("lockd: unhandled internal status %u\n",
-				     be32_to_cpu(status));
 		break;
 	}
 	return status;
 }
-#endif
 
 /**
  * nlmsvc_proc_null - NULL: Test for presence of service
Signature · 1 line
2.54.0
maintainer
#39 lore raw
In reply to Chuck Lever
Quoted 103 lines · Chuck Lever

This series finishes the xdrgen migration of lockd's server-side stack. The companion NLMv4 work landed earlier; here the remaining hand-written XDR in fs/lockd/xdr.c is retired in favour of code generated from a new Documentation/sunrpc/xdr/nlm3.x.

XDR helpers now do wire-format conversion only. NLMv3's 32-bit range limit on TEST conflict-holder byte ranges is clamped at the proc function rather than inside loff_t_to_s32() in the encoder. The HP-UX zero-length cookie rewrite that svcxdr_decode_cookie() has carried since the original kernel import is dropped on the server side; the generated decoder reproduces the cookie verbatim, and neither NLM_TEST reply matching nor CANCEL_MSG depends on the substitution.

A wrapper struct bridges each generated argument type with lockd's legacy lockd_lock/lockd_cookie/lockd_res internals. Each handler reaches xdrgen-decoded fields through argp->xdrgen and the legacy layout through a wrapper member that the handler populates explicitly, typically in nlm3svc_lookup_file(). The core lockd helpers and the async callback path operate on the legacy types unchanged, which is what keeps the conversion incremental.

.pc_argzero is cleared for every converted procedure: the generated decoders fill the substructure they own, so the dispatch layer's zero-memset is no longer needed. The trade-off is that any wrapper field a handler reads must be initialized explicitly. lock members are populated by nlm3svc_lookup_file(), or on the GRANTED path by the new nlm_lock_to_lockd_lock() helper.

Five NLMv4 fixes at the head of the series and three cleanup patches at the tail bracket the conversion. The six lockd_ struct renames between them are split out so that each conversion patch reads as a single concern.

---
Chuck Lever (38):
lockd: Stop warning on nlm__int__drop_reply in !V4 cast_status
lockd: Correct kernel-doc status descriptions for NLMv4 GRANTED
lockd: Drop locks_init_lock() from nlm4_lock_to_lockd_lock()
lockd: Translate nlm__int__deadlock in __nlm4svc_proc_lock_msg()
lockd: Do not monitor when looking up the LOCK_MSG callback host
Documentation: Add the RPC language description of NLM version 3
lockd: Rename struct nlm_cookie to lockd_cookie
lockd: Rename struct nlm_lock to lockd_lock
lockd: Rename struct nlm_args to lockd_args
lockd: Rename struct nlm_res to lockd_res
lockd: Rename struct nlm_reboot to lockd_reboot
lockd: Rename struct nlm_share to lockd_share
lockd: Use xdrgen XDR functions for the NLMv3 NULL procedure
lockd: Use xdrgen XDR functions for the NLMv3 TEST procedure
lockd: Use xdrgen XDR functions for the NLMv3 LOCK procedure
lockd: Use xdrgen XDR functions for the NLMv3 CANCEL procedure
lockd: Use xdrgen XDR functions for the NLMv3 UNLOCK procedure
lockd: Use xdrgen XDR functions for the NLMv3 GRANTED procedure
lockd: Refactor nlmsvc_callback()
lockd: Use xdrgen XDR functions for the NLMv3 TEST_MSG procedure
lockd: Use xdrgen XDR functions for the NLMv3 LOCK_MSG procedure
lockd: Use xdrgen XDR functions for the NLMv3 CANCEL_MSG procedure
lockd: Use xdrgen XDR functions for the NLMv3 UNLOCK_MSG procedure
lockd: Use xdrgen XDR functions for the NLMv3 GRANTED_MSG procedure
lockd: Use xdrgen XDR functions for the NLMv3 TEST_RES procedure
lockd: Use xdrgen XDR functions for the NLMv3 LOCK_RES procedure
lockd: Use xdrgen XDR functions for the NLMv3 CANCEL_RES procedure
lockd: Use xdrgen XDR functions for the NLMv3 UNLOCK_RES procedure
lockd: Use xdrgen XDR functions for the NLMv3 GRANTED_RES procedure
lockd: Use xdrgen XDR functions for the NLMv3 SM_NOTIFY procedure
lockd: Convert NLMv3 server-side undefined procedures to xdrgen
lockd: Use xdrgen XDR functions for the NLMv3 SHARE procedure
lockd: Use xdrgen XDR functions for the NLMv3 UNSHARE procedure
lockd: Use xdrgen XDR functions for the NLMv3 NM_LOCK procedure
lockd: Use xdrgen XDR functions for the NLMv3 FREE_ALL procedure
lockd: Remove C macros that are no longer used
lockd: Remove dead code from fs/lockd/xdr.c
lockd: Unify cast_status

 Documentation/sunrpc/xdr/nlm3.x    |  168 ++++
 fs/lockd/Makefile                  |   19 +-
 fs/lockd/clnt4xdr.c                |   42 +-
 fs/lockd/clntlock.c                |    2 +-
 fs/lockd/clntproc.c                |   14 +-
 fs/lockd/clntxdr.c                 |   44 +-
 fs/lockd/host.c                    |    4 +-
 fs/lockd/lockd.h                   |   57 +-
 fs/lockd/mon.c                     |    2 +-
 fs/lockd/nlm3xdr_gen.c             |  714 ++++++++++++++
 fs/lockd/nlm3xdr_gen.h             |   32 +
 fs/lockd/share.h                   |    4 +-
 fs/lockd/svc4proc.c                |   69 +-
 fs/lockd/svclock.c                 |   38 +-
 fs/lockd/svcproc.c                 | 1844 ++++++++++++++++++++++++------------
 fs/lockd/svcshare.c                |    8 +-
 fs/lockd/svcsubs.c                 |    2 +-
 fs/lockd/svcxdr.h                  |  142 ---
 fs/lockd/trace.h                   |   16 +-
 fs/lockd/xdr.c                     |  354 -------
 fs/lockd/xdr.h                     |   39 +-
 include/linux/sunrpc/xdrgen/nlm3.h |  210 ++++
 22 files changed, 2538 insertions(+), 1286 deletions(-)
Quoted 7 lines

---
base-commit: b26490baad0b7318d763b5ad6e5ca2addb20b314
change-id: 20260427-nlm4-xdrgen-35bf1c6869b8

Best regards,

Signature · 1 line
Chuck Lever <[email protected]>

I got a sketchy review from Gemini that I had Claude validate that looks valid. You may want to add the memset() it recommends:

--------------8<---------------

Analysis complete. The previous review (against b201ce7af2a2
FREE_ALL) identified the right underlying bug but attributed it to the wrong commit. Here's the corrected analysis:

Correct commit: 3de744ee4e45 — "lockd: Use xdrgen XDR functions for
the NLMv4 TEST procedure"

The regression: nlm4svc_lookup_file() (introduced in this commit)
copies only fh.len bytes of the file handle without zeroing the remainder. Combined with .pc_argzero = 0 removing the
defensive memset of the argument buffer, bytes beyond fh.len in lock-

Quoted 1 line

fh.data contain stale data from previous RPC calls. file_hash() in

fs/lockd/svcsubs.c reads a fixed 32 bytes (NFS2_FHSIZE)
regardless of actual handle length, so for handles shorter than 32
bytes the hash is non-deterministic — the same file handle can hash to different buckets on different calls, causing lock
state lookup failures.

Old code had two protections:
1. pc_argzero = sizeof(struct nlm_args) → zeroed the entire argp
before decode
2. svcxdr_decode_fhandle() → memset(fh->data + len, 0, sizeof(fh-

Quoted 1 line

data) - len)

Both are gone in the new code.

Fix: Add memset(lock->fh.data + xdr_lock->fh.len, 0, sizeof(lock-

Quoted 1 line

fh.data) - xdr_lock->fh.len) after the memcpy in

nlm4svc_lookup_file().

FINAL REGRESSIONS FOUND: 1
FINAL UNADDRESSED COMMENTS: 0 (no lore threads found) BUG FIX DETERMINATION: not a bug fix
Fixes tag check for NFSD: NO (not a bug fix)

Assisted-by Claude Code:claude-opus-4-6
author maintainer
#40 lore raw
Quoted 16 lines · Jeff Layton

I got a sketchy review from Gemini that I had Claude validate that looks valid. You may want to add the memset() it recommends:

--------------8<---------------

Analysis complete. The previous review (against b201ce7af2a2
FREE_ALL) identified the right underlying bug but attributed it to the wrong commit. Here's the corrected analysis:

Correct commit: 3de744ee4e45 — "lockd: Use xdrgen XDR functions for
the NLMv4 TEST procedure"

The regression: nlm4svc_lookup_file() (introduced in this commit)
copies only fh.len bytes of the file handle without zeroing the remainder. Combined with .pc_argzero = 0 removing the
defensive memset of the argument buffer, bytes beyond fh.len in lock-

Quoted 6 lines
Quoted 1 line

fh.data contain stale data from previous RPC calls. file_hash() in

fs/lockd/svcsubs.c reads a fixed 32 bytes (NFS2_FHSIZE)
regardless of actual handle length, so for handles shorter than 32
bytes the hash is non-deterministic — the same file handle can hash to different buckets on different calls, causing lock
state lookup failures.

This appears to be a regression introduced by the (previous) NLMv4 series, and does not affect the current NLMv3 xdrgen conversion.

I can post a fix for this later today. Note that memset() was removed as part of the xdrgen conversion because it zeroes much more memory than actually needs to be initialized.

Signature · 1 line
Chuck Lever
maintainer Reviewed-by
#41 lore raw
Quoted 25 lines · Chuck Lever
Quoted 16 lines · Jeff Layton

I got a sketchy review from Gemini that I had Claude validate that looks valid. You may want to add the memset() it recommends:

--------------8<---------------

Analysis complete. The previous review (against b201ce7af2a2
FREE_ALL) identified the right underlying bug but attributed it to the wrong commit. Here's the corrected analysis:

Correct commit: 3de744ee4e45 — "lockd: Use xdrgen XDR functions for
the NLMv4 TEST procedure"

The regression: nlm4svc_lookup_file() (introduced in this commit)
copies only fh.len bytes of the file handle without zeroing the remainder. Combined with .pc_argzero = 0 removing the
defensive memset of the argument buffer, bytes beyond fh.len in lock-

Quoted 6 lines
Quoted 1 line

fh.data contain stale data from previous RPC calls. file_hash() in

fs/lockd/svcsubs.c reads a fixed 32 bytes (NFS2_FHSIZE)
regardless of actual handle length, so for handles shorter than 32
bytes the hash is non-deterministic — the same file handle can hash to different buckets on different calls, causing lock
state lookup failures.

Quoted 7 lines

This appears to be a regression introduced by the (previous) NLMv4 series, and does not affect the current NLMv3 xdrgen conversion.

I can post a fix for this later today. Note that memset() was removed as part of the xdrgen conversion because it zeroes much more memory than actually needs to be initialized.

I couldn't quite tell. It almost sounded like the change in the original patch was safe, but this series removed some protections that made it safe to skip the zeroing? In any case it sounds like a real bug that we should probably fix, though it can be done in a later patch.

The series itself seems mostly mechanical. You can add: