Subject: Clarify module API boundaries
Subsystems (2)
Chuck Lever
maintainerv4 cover Subject: Clarify module API boundaries
From: Chuck Lever <[email protected]>
The patches in this series refactor the lockd code base to clearly separate its public API from internal implementation and NLM protocol details.
As context, the patches in this series are pre-requisite to the XDR changes posted earlier:
https://lore.kernel.org/linux-nfs/[email protected]/T/#t
The lockd subsystem currently exposes internal implementation headers through include/linux/lockd/, creating implicit API contracts that complicate maintenance. External consumers such as NFSD and the NFS client have developed dependencies on internal structures like struct nlm_host, and wire protocol constants leak into high-level module interfaces.
These patches work to establish clean architectural boundaries. The public API in include/linux/lockd/ is reduced to bind.h and nlm.h, which define the contract between lockd and its consumers. Private implementation details including XDR definitions, share management, and host structures are relocated to fs/lockd/ where they belong. Layering violations are corrected: the NFS client now uses accessor helpers instead of dereferencing internal structures, and nlm_fopen() returns errno values instead of wire protocol codes.
These changes enable subsequent work to modernize the NLMv4 XDR layer using xdrgen without risk of breaking external consumers. This work appears in the remaining patches in this series, which are presented here only to provide context for the API adjustments. No need to review those closely just yet.
The series is based on the public nfsd-testing branch.
---
Changes since v3:
- Address a build failure due to header reorganization
Changes since v2:
- Serialize client-side NLM shutdown to avoid UAF and NPD
- Address a build failure due to header reorganization
- Rename internal status code nlm_drop_reply
Changes since v1:
- Refine the pre-requisite header adjustments
- Reduce stack consumption by moving large structures to wrappers
- Additional extensive clean up
Chuck Lever (14):
lockd: Simplify cast_status() in svcproc.c
lockd: Relocate and rename nlm_drop_reply
lockd: Introduce nlm__int__deadlock
lockd: Have nlm_fopen() return errno values
lockd: Relocate nlmsvc_unlock API declarations
NFS: Use nlmclnt_shutdown_rpc_clnt() to safely shut down NLM
lockd: Move xdr4.h from include/linux/lockd/ to fs/lockd/
lockd: Move share.h from include/linux/lockd/ to fs/lockd/
lockd: Relocate include/linux/lockd/lockd.h
lockd: Remove lockd/debug.h
lockd: Move xdr.h from include/linux/lockd/ to fs/lockd/
lockd: Make linux/lockd/nlm.h an internal header
lockd: Move nlm4svc_set_file_lock_range()
lockd: Relocate svc_version definitions to XDR layer
fs/lockd/clnt4xdr.c | 7 +-
fs/lockd/clntlock.c | 2 +-
fs/lockd/clntproc.c | 2 +-
fs/lockd/clntxdr.c | 3 +-
fs/lockd/host.c | 31 +++++++-
{include/linux => fs}/lockd/lockd.h | 94 +++++++++++++++++-----
fs/lockd/mon.c | 2 +-
{include/linux => fs}/lockd/nlm.h | 8 +-
{include/linux => fs}/lockd/share.h | 8 +-
fs/lockd/svc.c | 50 +++---------
fs/lockd/svc4proc.c | 77 ++++++++++++++----
fs/lockd/svclock.c | 16 ++--
fs/lockd/svcproc.c | 119 ++++++++++++++++++++--------
fs/lockd/svcshare.c | 5 +-
fs/lockd/svcsubs.c | 32 ++++++--
fs/lockd/trace.h | 3 +-
fs/lockd/xdr.c | 3 +-
{include/linux => fs}/lockd/xdr.h | 15 +---
fs/lockd/xdr4.c | 16 +---
{include/linux => fs}/lockd/xdr4.h | 16 +---
fs/nfs/nfs3proc.c | 1 +
fs/nfs/sysfs.c | 4 +-
fs/nfsd/lockd.c | 50 +++++++-----
fs/nfsd/nfsctl.c | 2 +-
include/linux/lockd/bind.h | 26 +++---
include/linux/lockd/debug.h | 40 ----------
26 files changed, 368 insertions(+), 264 deletions(-)
rename {include/linux => fs}/lockd/lockd.h (85%)
rename {include/linux => fs}/lockd/nlm.h (91%)
rename {include/linux => fs}/lockd/share.h (85%)
rename {include/linux => fs}/lockd/xdr.h (91%)
rename {include/linux => fs}/lockd/xdr4.h (80%)
delete mode 100644 include/linux/lockd/debug.hSignature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 1/14 lockd: Simplify cast_status() in svcproc.c
From: Chuck Lever <[email protected]>
Clean up: The svcproc.c file handles only NLM v1 and v3 requests. NLMv4 requests are routed to a separate procedure table in svc4proc.c, so rqstp->rq_vers can never be 4 in this context.
Remove the unused vers parameter and the dead "vers != 4" check from cast_to_nlm(). This eliminates the need for the macro wrapper.
--- fs/lockd/svcproc.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-)
fs/lockd/svcproc.c +19 -21
@@ -17,32 +17,30 @@#define NLMDBG_FACILITY NLMDBG_CLIENT#ifdef CONFIG_LOCKD_V4 -static __be32 -cast_to_nlm (__be32 status,u32 vers) +static inline __be32 cast_status (__be32 status) { -/* Note: status is assumed to be in network byte order !!! */ -if (vers !=4 ){ -switch (status) { -case nlm_granted: -case nlm_lck_denied: -case nlm_lck_denied_nolocks: -case nlm_lck_blocked: -case nlm_lck_denied_grace_period: -case nlm_drop_reply: -break ; -case nlm4_deadlock: - status = nlm_lck_denied; -break ; -default : - status = nlm_lck_denied_nolocks; - } +switch (status) { +case nlm_granted: +case nlm_lck_denied: +case nlm_lck_denied_nolocks: +case nlm_lck_blocked: +case nlm_lck_denied_grace_period: +case nlm_drop_reply: +break ; +case nlm4_deadlock: + status = nlm_lck_denied; +break ; +default : + status = nlm_lck_denied_nolocks; } -return (status); +return status; } -#define cast_status (status) (cast_to_nlm(status, rqstp->rq_vers))#else -#define cast_status (status) (status) +static inline __be32 cast_status (__be32 status) +{ +return status; +}#endif /*
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 2/14 lockd: Relocate and rename nlm_drop_reply
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
The nlm_drop_reply status code is internal to the kernel's lockd implementation and must never appear on the wire. Its previous location in xdr.h grouped it with legitimate NLM protocol status codes, obscuring this critical distinction.
Relocate the definition to lockd.h with a comment block for internal status codes, and rename to nlm__int__drop_reply to make its internal-only nature explicit. This prepares for adding additional internal status codes in subsequent patches.
--- fs/lockd/svc4proc.c | 22 ++++++++++++++-------- fs/lockd/svclock.c | 4 ++-- fs/lockd/svcproc.c | 24 +++++++++++++++--------- fs/nfsd/lockd.c | 2 +- include/linux/lockd/lockd.h | 6 ++++++ include/linux/lockd/xdr.h | 2 -- 6 files changed, 38 insertions(+), 22 deletions(-)
fs/lockd/svc4proc.c +14 -8
@@ -104,12 +104,13 @@ __nlm4svc_proc_test(struct svc_rqst *rqstp, struct nlm_res *resp)/* Obtain client and file */ if ((resp->status =nlm4svc_retrieve_args (rqstp, argp, &host, &file))) -return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; +return resp->status == nlm__int__drop_reply ? + rpc_drop_reply : rpc_success;/* Now check for conflicting locks */ resp->status =nlmsvc_testlock (rqstp, file, host, &argp->lock, &resp->lock); -if (resp->status == nlm_drop_reply) +if (resp->status == nlm__int__drop_reply) rc = rpc_drop_reply;else dprintk ("lockd: TEST4 status %d\n" ,ntohl (resp->status));
@@ -140,13 +141,14 @@ __nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_res *resp)/* Obtain client and file */ if ((resp->status =nlm4svc_retrieve_args (rqstp, argp, &host, &file))) -return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; +return resp->status == nlm__int__drop_reply ? + rpc_drop_reply : rpc_success;/* Now try to lock the file */ resp->status =nlmsvc_lock (rqstp, file, host, &argp->lock, argp->block, &argp->cookie, argp->reclaim); -if (resp->status == nlm_drop_reply) +if (resp->status == nlm__int__drop_reply) rc = rpc_drop_reply;else dprintk ("lockd: LOCK status %d\n" ,ntohl (resp->status));
@@ -182,7 +184,8 @@ __nlm4svc_proc_cancel(struct svc_rqst *rqstp, struct nlm_res *resp)/* Obtain client and file */ if ((resp->status =nlm4svc_retrieve_args (rqstp, argp, &host, &file))) -return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; +return resp->status == nlm__int__drop_reply ? + rpc_drop_reply : rpc_success;/* Try to cancel request. */ resp->status =nlmsvc_cancel_blocked (SVC_NET (rqstp), file, &argp->lock);
@@ -222,7 +225,8 @@ __nlm4svc_proc_unlock(struct svc_rqst *rqstp, struct nlm_res *resp)/* Obtain client and file */ if ((resp->status =nlm4svc_retrieve_args (rqstp, argp, &host, &file))) -return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; +return resp->status == nlm__int__drop_reply ? + rpc_drop_reply : rpc_success;/* Now try to remove the lock */ resp->status =nlmsvc_unlock (SVC_NET (rqstp), file, &argp->lock);
@@ -369,7 +373,8 @@ nlm4svc_proc_share(struct svc_rqst *rqstp)/* Obtain client and file */ if ((resp->status =nlm4svc_retrieve_args (rqstp, argp, &host, &file))) -return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; +return resp->status == nlm__int__drop_reply ? + rpc_drop_reply : rpc_success;/* Now try to create the share */ resp->status =nlmsvc_share_file (host, file, argp);
@@ -404,7 +409,8 @@ nlm4svc_proc_unshare(struct svc_rqst *rqstp)/* Obtain client and file */ if ((resp->status =nlm4svc_retrieve_args (rqstp, argp, &host, &file))) -return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; +return resp->status == nlm__int__drop_reply ? + rpc_drop_reply : rpc_success;/* Now try to lock the file */ resp->status =nlmsvc_unshare_file (host, file, argp);
fs/lockd/svclock.c +2 -2
@@ -463,7 +463,7 @@ nlmsvc_defer_lock_rqst(struct svc_rqst *rqstp, struct nlm_block *block) block->b_deferred_req = rqstp->rq_chandle.defer (block->b_cache_req);if (block->b_deferred_req !=NULL ) - status = nlm_drop_reply; + status = nlm__int__drop_reply; }dprintk ("lockd: nlmsvc_defer_lock_rqst block %p flags %d status %d\n" , block, block->b_flags,ntohl (status));
@@ -531,7 +531,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, ret = nlm_lck_denied; goto out; } - ret = nlm_drop_reply; + ret = nlm__int__drop_reply; goto out; }
fs/lockd/svcproc.c +15 -9
@@ -25,7 +25,7 @@ static inline __be32 cast_status(__be32 status)case nlm_lck_denied_nolocks:case nlm_lck_blocked:case nlm_lck_denied_grace_period: -case nlm_drop_reply: +case nlm__int__drop_reply:break ;case nlm4_deadlock: status = nlm_lck_denied;
@@ -122,12 +122,13 @@ __nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_res *resp)/* Obtain client and file */ if ((resp->status =nlmsvc_retrieve_args (rqstp, argp, &host, &file))) -return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; +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_drop_reply) +if (resp->status == nlm__int__drop_reply) rc = rpc_drop_reply;else dprintk("lockd: TEST status %d vers %d\n",
@@ -159,13 +160,14 @@ __nlmsvc_proc_lock(struct svc_rqst *rqstp, struct nlm_res *resp)/* Obtain client and file */ if ((resp->status =nlmsvc_retrieve_args (rqstp, argp, &host, &file))) -return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; +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_drop_reply) +if (resp->status == nlm__int__drop_reply) rc = rpc_drop_reply;else dprintk ("lockd: LOCK status %d\n" ,ntohl (resp->status));
@@ -202,7 +204,8 @@ __nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct nlm_res *resp)/* Obtain client and file */ if ((resp->status =nlmsvc_retrieve_args (rqstp, argp, &host, &file))) -return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; +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));
@@ -243,7 +246,8 @@ __nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct nlm_res *resp)/* Obtain client and file */ if ((resp->status =nlmsvc_retrieve_args (rqstp, argp, &host, &file))) -return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; +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));
@@ -400,7 +404,8 @@ nlmsvc_proc_share(struct svc_rqst *rqstp)/* Obtain client and file */ if ((resp->status =nlmsvc_retrieve_args (rqstp, argp, &host, &file))) -return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; +return resp->status == nlm__int__drop_reply ? + rpc_drop_reply : rpc_success;/* Now try to create the share */ resp->status =cast_status (nlmsvc_share_file (host, file, argp));
@@ -435,7 +440,8 @@ nlmsvc_proc_unshare(struct svc_rqst *rqstp)/* Obtain client and file */ if ((resp->status =nlmsvc_retrieve_args (rqstp, argp, &host, &file))) -return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success; +return resp->status == nlm__int__drop_reply ? + rpc_drop_reply : rpc_success;/* Now try to unshare the file */ resp->status =cast_status (nlmsvc_unshare_file (host, file, argp));
fs/nfsd/lockd.c +1 -1
@@ -71,7 +71,7 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp,* to callback when the delegation is returned but might * not have a proper lock request to block on. */ -return nlm_drop_reply; +return nlm__int__drop_reply;case nfserr_stale:return nlm_stale_fh;default :
include/linux/lockd/lockd.h +6 -0
@@ -38,6 +38,12 @@*/ #define LOCKD_DFLT_TIMEO 10 +/* +* Internal-use status codes, not to be placed on the wire. +* Version handlers translate these to appropriate wire values. +*/ +#define nlm__int__drop_reply cpu_to_be32(30000) +/* * Lockd host handle (used both by the client and server personality). */
include/linux/lockd/xdr.h +0 -2
@@ -33,8 +33,6 @@ struct svc_rqst;#define nlm_lck_blocked cpu_to_be32(NLM_LCK_BLOCKED)#define nlm_lck_denied_grace_period cpu_to_be32(NLM_LCK_DENIED_GRACE_PERIOD) -#define nlm_drop_reply cpu_to_be32(30000) -/* Lock info passed via NLM */ struct nlm_lock {char * caller;
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 3/14 lockd: Introduce nlm__int__deadlock
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
The use of CONFIG_LOCKD_V4 in combination with a later cast_status() in the NLMv3 code is difficult to reason about. Instead, replace the use of nlm_deadlock with an implementation-defined status value that version-specific code translates appropriately.
The new approach establishes a translation boundary: generic lockd code returns nlm__int__deadlock when posix_lock_file() yields -EDEADLK. Version-specific handlers (svc4proc.c for NLMv4, svcproc.c for NLMv3) translate this internal status to the appropriate wire protocol value. NLMv4 maps to nlm4_deadlock; NLMv3 maps to nlm_lck_denied (since NLMv3 lacks a deadlock-specific status code).
Later this modification will also remove the need to include NLMv4 headers in NLMv3 and generic code.
--- fs/lockd/svc4proc.c | 10 ++++++++-- fs/lockd/svclock.c | 8 +------- fs/lockd/svcproc.c | 4 +++- include/linux/lockd/lockd.h | 1 + 4 files changed, 13 insertions(+), 10 deletions(-)
fs/lockd/svc4proc.c +8 -2
@@ -148,10 +148,16 @@ __nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_res *resp) resp->status =nlmsvc_lock (rqstp, file, host, &argp->lock, argp->block, &argp->cookie, argp->reclaim); -if (resp->status == nlm__int__drop_reply) +switch (resp->status) { +case nlm__int__drop_reply: rc = rpc_drop_reply; -else +break ; +case nlm__int__deadlock: + resp->status = nlm4_deadlock; + fallthrough; +default :dprintk ("lockd: LOCK status %d\n" ,ntohl (resp->status)); + }nlmsvc_release_lockowner (&argp->lock);nlmsvc_release_host (host);
fs/lockd/svclock.c +1 -7
@@ -33,12 +33,6 @@#define NLMDBG_FACILITY NLMDBG_SVCLOCK -#ifdef CONFIG_LOCKD_V4 -#define nlm_deadlock nlm4_deadlock -#else -#define nlm_deadlock nlm_lck_denied -#endif -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);
@@ -589,7 +583,7 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file, goto out;case -EDEADLK :nlmsvc_remove_block (block); - ret = nlm_deadlock; + ret = nlm__int__deadlock; goto out;default :/* includes ENOLCK */ nlmsvc_remove_block (block);
fs/lockd/svcproc.c +3 -1
@@ -27,7 +27,7 @@ static inline __be32 cast_status(__be32 status)case nlm_lck_denied_grace_period:case nlm__int__drop_reply:break ; -case nlm4_deadlock: +case nlm__int__deadlock: status = nlm_lck_denied;break ;default :
@@ -39,6 +39,8 @@ static inline __be32 cast_status(__be32 status)#else static inline __be32 cast_status (__be32 status) { +if (status == nlm__int__deadlock) + status = nlm_lck_denied;return status; }#endif
include/linux/lockd/lockd.h +1 -0
@@ -43,6 +43,7 @@* Version handlers translate these to appropriate wire values. */ #define nlm__int__drop_reply cpu_to_be32(30000) +#define nlm__int__deadlock cpu_to_be32(30001)/* * Lockd host handle (used both by the client and server personality).
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 4/14 lockd: Have nlm_fopen() return errno values
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
The nlm_fopen() function is part of the API between nfsd and lockd.
Currently its return value is an on-the-wire NLM status code. But that forces NFSD to include NLM wire protocol definitions despite having no other dependency on the NLM wire protocol.
In addition, a CONFIG_LOCKD_V4 Kconfig symbol appears in the middle of NFSD source code.
Refactor: Let's not use on-the-wire values as part of a high-level API between two Linux kernel modules. That's what we have errno for, right?
And, instead of simply moving the CONFIG_LOCKD_V4 check, we can get rid of it entirely and let the decision of what actual NLM status code goes on the wire to be left up to NLM version-specific code.
--- fs/lockd/svc4proc.c | 18 ++++++++++--- fs/lockd/svcproc.c | 14 ++++++++++- fs/lockd/svcsubs.c | 27 +++++++++++++++----- fs/nfsd/lockd.c | 50 +++++++++++++++++++++---------------- include/linux/lockd/bind.h | 8 +++--- include/linux/lockd/lockd.h | 2 ++ 6 files changed, 82 insertions(+), 37 deletions(-)
fs/lockd/svc4proc.c +15 -3
@@ -73,9 +73,21 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp, no_locks:nlmsvc_release_host (host); -if (error) -return error; -return nlm_lck_denied_nolocks; +switch (error) { +case nlm_granted: +return nlm_lck_denied_nolocks; +case nlm__int__stale_fh: +return nlm4_stale_fh; +case nlm__int__failed: +return nlm4_failed; +default : +if (be32_to_cpu (error) >=30000 ) { +pr_warn_once ("lockd: unhandled internal status %u\n" , +be32_to_cpu (error)); +return nlm4_failed; + } +return error; + } }/*
fs/lockd/svcproc.c +13 -1
@@ -39,8 +39,20 @@ static inline __be32 cast_status(__be32 status)#else static inline __be32 cast_status (__be32 status) { -if (status == nlm__int__deadlock) +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) >=30000 ) +pr_warn_once ("lockd: unhandled internal status %u\n" , +be32_to_cpu (status)); +break ; + }return status; }#endif
fs/lockd/svcsubs.c +21 -6
@@ -87,14 +87,29 @@ static __be32 nlm_do_fopen(struct svc_rqst *rqstp, struct nlm_file *file, int mode) {struct file **fp = &file->f_file[mode]; -__be32 nfserr; +__be32 nlmerr = nlm_granted; +int error;if (*fp) -return 0 ; - nfserr = nlmsvc_ops->fopen (rqstp, &file->f_handle, fp, mode); -if (nfserr) -dprintk ("lockd: open failed (error %d)\n" , nfserr); -return nfserr; +return nlmerr; + + error = nlmsvc_ops->fopen (rqstp, &file->f_handle, fp, mode); +if (error) { +dprintk ("lockd: open failed (errno %d)\n" , error); +switch (error) { +case -EWOULDBLOCK : + nlmerr = nlm__int__drop_reply; +break ; +case -ESTALE : + nlmerr = nlm__int__stale_fh; +break ; +default : + nlmerr = nlm__int__failed; +break ; + } + } + +return nlmerr; }/*
fs/nfsd/lockd.c +28 -22
84 lines not on this page · raw message
include/linux/lockd/bind.h +3 -5
@@ -26,11 +26,9 @@ struct rpc_clnt;* This is the set of functions for lockd->nfsd communication */ struct nlmsvc_binding { -__be32 (*fopen)(struct svc_rqst *, -struct nfs_fh *, -struct file **, -int mode); -void (*fclose)(struct file *); +int (*fopen)(struct svc_rqst *rqstp,struct nfs_fh *f, +struct file **filp,int flags); +void (*fclose)(struct file *filp); };extern const struct nlmsvc_binding *nlmsvc_ops;
include/linux/lockd/lockd.h +2 -0
@@ -44,6 +44,8 @@*/ #define nlm__int__drop_reply cpu_to_be32(30000)#define nlm__int__deadlock cpu_to_be32(30001) +#define nlm__int__stale_fh cpu_to_be32(30002) +#define nlm__int__failed cpu_to_be32(30003)/* * Lockd host handle (used both by the client and server personality).
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 5/14 lockd: Relocate nlmsvc_unlock API declarations
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
The nlmsvc_unlock_all_by_sb() and nlmsvc_unlock_all_by_ip() functions are part of lockd's external API, consumed by other kernel subsystems. Their declarations currently reside in linux/lockd/lockd.h alongside internal implementation details, which blurs the boundary between lockd's public interface and its private internals.
Moving these declarations to linux/lockd/bind.h groups them with other external API functions and makes the separation explicit. This clarifies which functions are intended for external use and reduces the risk of internal implementation details leaking into the public API surface.
Build-tested with allyesconfig; no functional changes.
--- fs/nfsd/nfsctl.c | 2 +- include/linux/lockd/bind.h | 7 +++++++ include/linux/lockd/lockd.h | 6 ------ 3 files changed, 8 insertions(+), 7 deletions(-)
fs/nfsd/nfsctl.c +1 -1
@@ -11,7 +11,7 @@#include <linux/fs_context.h> #include <linux/sunrpc/svcsock.h> -#include <linux/lockd/lockd.h> +#include <linux/lockd/bind.h> #include <linux/sunrpc/addr.h> #include <linux/sunrpc/gss_api.h> #include <linux/sunrpc/rpc_pipe_fs.h>
include/linux/lockd/bind.h +7 -0
@@ -21,6 +21,7 @@struct svc_rqst ;struct rpc_task ;struct rpc_clnt ; +struct super_block ;/* * This is the set of functions for lockd->nfsd communication
@@ -80,4 +81,10 @@ extern int nlmclnt_proc(struct nlm_host *host, int cmd, struct file_lock *fl, voextern int lockd_up (struct net *net,const struct cred *cred);extern void lockd_down (struct net *net); +/* +* Cluster failover support +*/ +int nlmsvc_unlock_all_by_sb (struct super_block *sb); +int nlmsvc_unlock_all_by_ip (struct sockaddr *server_addr); +#endif /* LINUX_LOCKD_BIND_H */
include/linux/lockd/lockd.h +0 -6
@@ -311,12 +311,6 @@ void nlmsvc_mark_resources(struct net *);void nlmsvc_free_host_resources (struct nlm_host *);void nlmsvc_invalidate_all (void ); -/* -* Cluster failover support -*/ -int nlmsvc_unlock_all_by_sb (struct super_block *sb); -int nlmsvc_unlock_all_by_ip (struct sockaddr *server_addr); -static inline struct file *nlmsvc_file_file (const struct nlm_file *file) { return file->f_file[O_RDONLY] ?
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 6/14 NFS: Use nlmclnt_shutdown_rpc_clnt() to safely shut down NLM
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
A race condition exists in shutdown_store() when writing to the sysfs "shutdown" file concurrently with nlm_shutdown_hosts_net(). Without synchronization, the following sequence can occur:
1. shutdown_store() reads server->nlm_host (non-NULL)
2. nlm_shutdown_hosts_net() acquires nlm_host_mutex, calls rpc_shutdown_client(), sets h_rpcclnt to NULL, and potentially frees the host via nlm_gc_hosts()
3. shutdown_store() dereferences the now-stale or freed host
Introduce nlmclnt_shutdown_rpc_clnt(), which acquires nlm_host_mutex before accessing h_rpcclnt. This synchronizes with nlm_shutdown_hosts_net() and ensures the rpc_clnt pointer remains valid during the shutdown operation.
This change also improves API layering: NFS client code no longer needs to include the internal lockd header to access nlm_host fields. The new helper resides in bind.h alongside other public lockd interfaces.
--- fs/lockd/host.c | 29 +++++++++++++++++++++++++++++ fs/nfs/sysfs.c | 4 ++-- include/linux/lockd/bind.h | 1 + 3 files changed, 32 insertions(+), 2 deletions(-)
fs/lockd/host.c +29 -0
@@ -306,6 +306,35 @@ void nlmclnt_release_host(struct nlm_host *host) } } +/* Callback for rpc_cancel_tasks() - matches all tasks for cancellation */ +static bool nlmclnt_match_all (const struct rpc_task *task,const void *data) +{ +return true; +} + +/** +* nlmclnt_shutdown_rpc_clnt - safely shut down NLM client RPC operations +* @host: nlm_host to shut down +* +* Cancels outstanding RPC tasks and marks the client as shut down. +* Synchronizes with nlmclnt_release_host() via nlm_host_mutex to prevent +* races between shutdown and host destruction. Safe to call if h_rpcclnt +* is NULL or already shut down. +*/ +void nlmclnt_shutdown_rpc_clnt (struct nlm_host *host) +{ +struct rpc_clnt *clnt; + +mutex_lock (&nlm_host_mutex); + clnt = host->h_rpcclnt; +if (clnt) { + clnt->cl_shutdown =1 ; +rpc_cancel_tasks (clnt, -EIO , nlmclnt_match_all,NULL ); + } +mutex_unlock (&nlm_host_mutex); +} +EXPORT_SYMBOL_GPL (nlmclnt_shutdown_rpc_clnt); +/** * nlmsvc_lookup_host - Find an NLM host handle matching a remote client * @rqstp: incoming NLM request
fs/nfs/sysfs.c +2 -2
@@ -12,7 +12,7 @@#include <linux/string.h> #include <linux/nfs_fs.h> #include <linux/rcupdate.h> -#include <linux/lockd/lockd.h> +#include <linux/lockd/bind.h> #include "internal.h" #include "nfs4_fs.h"
@@ -285,7 +285,7 @@ shutdown_store(struct kobject *kobj, struct kobj_attribute *attr,shutdown_client (server->client_acl);if (server->nlm_host) -shutdown_client (server->nlm_host->h_rpcclnt); +nlmclnt_shutdown_rpc_clnt (server->nlm_host); out:shutdown_nfs_client (server->nfs_client);return count;
include/linux/lockd/bind.h +1 -0
@@ -57,6 +57,7 @@ struct nlmclnt_initdata {extern struct nlm_host *nlmclnt_init (const struct nlmclnt_initdata *nlm_init);extern void nlmclnt_done (struct nlm_host *host);extern struct rpc_clnt *nlmclnt_rpc_clnt (struct nlm_host *host); +extern void nlmclnt_shutdown_rpc_clnt (struct nlm_host *host);/* * NLM client operations provide a means to modify RPC processing of NLM
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 7/14 lockd: Move xdr4.h from include/linux/lockd/ to fs/lockd/
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
The xdr4.h header declares NLMv4-specific XDR encoder/decoder functions and error codes that are used exclusively within the lockd subsystem. Moving it from include/linux/lockd/ to fs/lockd/ clarifies the intended scope of these declarations and prevents external code from depending on lockd-internal interfaces.
This change reduces the public API surface of the lockd module and makes it easier to refactor NLMv4 internals without risk of breaking out-of-tree consumers. The header's contents are implementation details of the NLMv4 wire protocol handling, not a contract with other kernel subsystems.
---
fs/lockd/clnt4xdr.c | 2 ++
fs/lockd/svc4proc.c | 2 ++
fs/lockd/xdr4.c | 1 +
{include/linux => fs}/lockd/xdr4.h | 15 +++------------
include/linux/lockd/bind.h | 3 ---
include/linux/lockd/lockd.h | 7 ++++---
6 files changed, 12 insertions(+), 18 deletions(-)
rename {include/linux => fs}/lockd/xdr4.h (84%)fs/lockd/clnt4xdr.c +2 -0
@@ -17,6 +17,8 @@#include <uapi/linux/nfs3.h> +#include "xdr4.h" +#define NLMDBG_FACILITY NLMDBG_XDR#if (NLMCLNT_OHSIZE >XDR_MAX_NETOBJ )
fs/lockd/svc4proc.c +2 -0
@@ -14,6 +14,8 @@#include <linux/lockd/share.h> #include <linux/sunrpc/svc_xprt.h> +#include "xdr4.h" +#define NLMDBG_FACILITY NLMDBG_CLIENT/*
fs/lockd/xdr4.c +1 -0
@@ -19,6 +19,7 @@#include <linux/lockd/lockd.h> #include "svcxdr.h" +#include "xdr4.h" static inline s64 loff_t_to_s64 (loff_t offset)
fs/lockd/xdr4.h renamed from include/linux/lockd/xdr4.h +3 -12
@@ -1,19 +1,12 @@/* SPDX-License-Identifier: GPL-2.0 */ /* -* linux/include/linux/lockd/xdr4.h -* * XDR types for the NLM protocol * * Copyright (C) 1996 Olaf Kirch <[email protected]> */ -#ifndef LOCKD_XDR4_H -#define LOCKD_XDR4_H - -#include <linux/fs.h> -#include <linux/nfs.h> -#include <linux/sunrpc/xdr.h> -#include <linux/lockd/xdr.h> +#ifndef _LOCKD_XDR4_H +#define _LOCKD_XDR4_H/* error codes new to NLMv4 */ #define nlm4_deadlock cpu_to_be32(NLM_DEADLCK)
@@ -38,6 +31,4 @@ bool nlm4svc_encode_res(struct svc_rqst *rqstp, struct xdr_stream *xdr);bool nlm4svc_encode_void (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nlm4svc_encode_shareres (struct svc_rqst *rqstp,struct xdr_stream *xdr); -extern const struct rpc_version nlm_version4; - -#endif /* LOCKD_XDR4_H */ +#endif /* _LOCKD_XDR4_H */
include/linux/lockd/bind.h +0 -3
@@ -13,9 +13,6 @@#include <linux/lockd/nlm.h> /* need xdr-encoded error codes too, so... */ #include <linux/lockd/xdr.h> -#ifdef CONFIG_LOCKD_V4 -#include <linux/lockd/xdr4.h> -#endif /* Dummy declarations */ struct svc_rqst ;
include/linux/lockd/lockd.h +4 -3
@@ -22,9 +22,6 @@#include <linux/utsname.h> #include <linux/lockd/bind.h> #include <linux/lockd/xdr.h> -#ifdef CONFIG_LOCKD_V4 -#include <linux/lockd/xdr4.h> -#endif #include <linux/lockd/debug.h> #include <linux/sunrpc/svc.h>
@@ -235,6 +232,10 @@ int nlmclnt_reclaim(struct nlm_host *, struct file_lock *, struct nlm_rqst *);void nlmclnt_next_cookie (struct nlm_cookie *); +#ifdef CONFIG_LOCKD_V4 +extern const struct rpc_version nlm_version4; +#endif +/* * Host cache */
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 8/14 lockd: Move share.h from include/linux/lockd/ to fs/lockd/
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
The share.h header defines struct nlm_share and declares the DOS share management functions used by the NLM server to implement NLM_SHARE and NLM_UNSHARE operations. These interfaces are used exclusively within the lockd subsystem. A git grep search confirms no external code references them.
Relocating this header from include/linux/lockd/ to fs/lockd/ narrows the public API surface of the lockd module. Out-of-tree code cannot depend on these internal interfaces after this change. Future refactoring of the share management implementation thus requires no consideration of external consumers.
---
{include/linux => fs}/lockd/share.h | 8 +++-----
fs/lockd/svc4proc.c | 2 +-
fs/lockd/svcproc.c | 3 ++-
fs/lockd/svcshare.c | 3 ++-
fs/lockd/svcsubs.c | 3 ++-
include/linux/lockd/lockd.h | 2 ++
6 files changed, 12 insertions(+), 9 deletions(-)
rename {include/linux => fs}/lockd/share.h (85%)fs/lockd/share.h renamed from include/linux/lockd/share.h +3 -5
@@ -1,14 +1,12 @@/* SPDX-License-Identifier: GPL-2.0 */ /* -* linux/include/linux/lockd/share.h -* * DOS share management for lockd. * * Copyright (C) 1996, Olaf Kirch <[email protected]> */ -#ifndef LINUX_LOCKD_SHARE_H -#define LINUX_LOCKD_SHARE_H +#ifndef _LOCKD_SHARE_H +#define _LOCKD_SHARE_H/* * DOS share for a specific file
@@ -29,4 +27,4 @@ __be32 nlmsvc_unshare_file(struct nlm_host *, struct nlm_file *,void nlmsvc_traverse_shares (struct nlm_host *,struct nlm_file *,nlm_host_match_fn_t ); -#endif /* LINUX_LOCKD_SHARE_H */ +#endif /* _LOCKD_SHARE_H */
fs/lockd/svc4proc.c +1 -1
@@ -11,9 +11,9 @@#include <linux/types.h> #include <linux/time.h> #include <linux/lockd/lockd.h> -#include <linux/lockd/share.h> #include <linux/sunrpc/svc_xprt.h> +#include "share.h" #include "xdr4.h" #define NLMDBG_FACILITY NLMDBG_CLIENT
fs/lockd/svcproc.c +2 -1
@@ -11,9 +11,10 @@#include <linux/types.h> #include <linux/time.h> #include <linux/lockd/lockd.h> -#include <linux/lockd/share.h> #include <linux/sunrpc/svc_xprt.h> +#include "share.h" +#define NLMDBG_FACILITY NLMDBG_CLIENT#ifdef CONFIG_LOCKD_V4
fs/lockd/svcshare.c +2 -1
@@ -15,7 +15,8 @@#include <linux/sunrpc/clnt.h> #include <linux/sunrpc/svc.h> #include <linux/lockd/lockd.h> -#include <linux/lockd/share.h> + +#include "share.h" static inline int nlm_cmp_owner (struct nlm_share *share,struct xdr_netobj *oh)
fs/lockd/svcsubs.c +2 -1
@@ -16,11 +16,12 @@#include <linux/sunrpc/svc.h> #include <linux/sunrpc/addr.h> #include <linux/lockd/lockd.h> -#include <linux/lockd/share.h> #include <linux/module.h> #include <linux/mount.h> #include <uapi/linux/nfs2.h> +#include "share.h" +#define NLMDBG_FACILITY NLMDBG_SVCSUBS
include/linux/lockd/lockd.h +2 -0
@@ -155,6 +155,8 @@ struct nlm_rqst {void * a_callback_data;/* sent to nlmclnt_operations callbacks */ }; +struct nlm_share ; +/* * This struct describes a file held open by lockd on behalf of * an NFS client.
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 9/14 lockd: Relocate include/linux/lockd/lockd.h
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
Headers placed in include/linux/ form part of the kernel's internal API and signal to subsystem maintainers that other parts of the kernel may depend on them. By moving lockd.h into fs/lockd/, lockd becomes a more self-contained module whose internal interfaces are clearly distinguished from its public contract with the rest of the kernel. This relocation addresses a long-standing XXX comment in the header itself that acknowledged the file's misplacement. Future changes to lockd internals can now proceed with confidence that external consumers are not inadvertently coupled to implementation details.
---
fs/lockd/clnt4xdr.c | 3 ++-
fs/lockd/clntlock.c | 2 +-
fs/lockd/clntproc.c | 2 +-
fs/lockd/clntxdr.c | 3 ++-
fs/lockd/host.c | 2 +-
{include/linux => fs}/lockd/lockd.h | 12 +++---------
fs/lockd/mon.c | 2 +-
fs/lockd/svc.c | 2 +-
fs/lockd/svc4proc.c | 2 +-
fs/lockd/svclock.c | 3 ++-
fs/lockd/svcproc.c | 2 +-
fs/lockd/svcshare.c | 2 +-
fs/lockd/svcsubs.c | 2 +-
fs/lockd/trace.h | 3 ++-
fs/lockd/xdr.c | 3 +--
fs/lockd/xdr4.c | 2 +-
16 files changed, 22 insertions(+), 25 deletions(-)
rename {include/linux => fs}/lockd/lockd.h (98%)fs/lockd/clnt4xdr.c +2 -1
@@ -13,7 +13,8 @@#include <linux/sunrpc/xdr.h> #include <linux/sunrpc/clnt.h> #include <linux/sunrpc/stats.h> -#include <linux/lockd/lockd.h> + +#include "lockd.h" #include <uapi/linux/nfs3.h>
fs/lockd/clntlock.c +1 -1
@@ -15,9 +15,9 @@#include <linux/sunrpc/addr.h> #include <linux/sunrpc/svc.h> #include <linux/sunrpc/svc_xprt.h> -#include <linux/lockd/lockd.h> #include <linux/kthread.h> +#include "lockd.h" #include "trace.h" #define NLMDBG_FACILITY NLMDBG_CLIENT
fs/lockd/clntproc.c +1 -1
@@ -18,8 +18,8 @@#include <linux/freezer.h> #include <linux/sunrpc/clnt.h> #include <linux/sunrpc/svc.h> -#include <linux/lockd/lockd.h> +#include "lockd.h" #include "trace.h" #define NLMDBG_FACILITY NLMDBG_CLIENT
fs/lockd/clntxdr.c +2 -1
@@ -15,7 +15,8 @@#include <linux/sunrpc/xdr.h> #include <linux/sunrpc/clnt.h> #include <linux/sunrpc/stats.h> -#include <linux/lockd/lockd.h> + +#include "lockd.h" #include <uapi/linux/nfs2.h>
fs/lockd/host.c +1 -1
@@ -16,13 +16,13 @@#include <linux/sunrpc/clnt.h> #include <linux/sunrpc/addr.h> #include <linux/sunrpc/svc.h> -#include <linux/lockd/lockd.h> #include <linux/mutex.h> #include <linux/sunrpc/svc_xprt.h> #include <net/ipv6.h> +#include "lockd.h" #include "netns.h" #define NLMDBG_FACILITY NLMDBG_HOSTCACHE
fs/lockd/lockd.h renamed from include/linux/lockd/lockd.h +3 -9
@@ -1,16 +1,10 @@/* SPDX-License-Identifier: GPL-2.0 */ /* -* linux/include/linux/lockd/lockd.h -* -* General-purpose lockd include file. -* * Copyright (C) 1996 Olaf Kirch <[email protected]> */ -#ifndef LINUX_LOCKD_LOCKD_H -#define LINUX_LOCKD_LOCKD_H - -/* XXX: a lot of this should really be under fs/lockd. */ +#ifndef _LOCKD_LOCKD_H +#define _LOCKD_LOCKD_H#include <linux/exportfs.h> #include <linux/in.h>
@@ -398,4 +392,4 @@ static inline int nlm_compare_locks(const struct file_lock *fl1,extern const struct lock_manager_operations nlmsvc_lock_operations; -#endif /* LINUX_LOCKD_LOCKD_H */ +#endif /* _LOCKD_LOCKD_H */
fs/lockd/mon.c +1 -1
@@ -16,10 +16,10 @@#include <linux/sunrpc/addr.h> #include <linux/sunrpc/xprtsock.h> #include <linux/sunrpc/svc.h> -#include <linux/lockd/lockd.h> #include <linux/unaligned.h> +#include "lockd.h" #include "netns.h" #define NLMDBG_FACILITY NLMDBG_MONITOR
fs/lockd/svc.c +1 -1
@@ -36,9 +36,9 @@#include <net/ip.h> #include <net/addrconf.h> #include <net/ipv6.h> -#include <linux/lockd/lockd.h> #include <linux/nfs.h> +#include "lockd.h" #include "netns.h" #include "procfs.h" #include "netlink.h"
fs/lockd/svc4proc.c +1 -1
@@ -10,9 +10,9 @@#include <linux/types.h> #include <linux/time.h> -#include <linux/lockd/lockd.h> #include <linux/sunrpc/svc_xprt.h> +#include "lockd.h" #include "share.h" #include "xdr4.h"
fs/lockd/svclock.c +2 -1
@@ -29,7 +29,8 @@#include <linux/sunrpc/clnt.h> #include <linux/sunrpc/svc_xprt.h> #include <linux/lockd/nlm.h> -#include <linux/lockd/lockd.h> + +#include "lockd.h" #define NLMDBG_FACILITY NLMDBG_SVCLOCK
fs/lockd/svcproc.c +1 -1
@@ -10,9 +10,9 @@#include <linux/types.h> #include <linux/time.h> -#include <linux/lockd/lockd.h> #include <linux/sunrpc/svc_xprt.h> +#include "lockd.h" #include "share.h" #define NLMDBG_FACILITY NLMDBG_CLIENT
fs/lockd/svcshare.c +1 -1
@@ -14,8 +14,8 @@#include <linux/sunrpc/clnt.h> #include <linux/sunrpc/svc.h> -#include <linux/lockd/lockd.h> +#include "lockd.h" #include "share.h" static inline int
fs/lockd/svcsubs.c +1 -1
@@ -15,11 +15,11 @@#include <linux/mutex.h> #include <linux/sunrpc/svc.h> #include <linux/sunrpc/addr.h> -#include <linux/lockd/lockd.h> #include <linux/module.h> #include <linux/mount.h> #include <uapi/linux/nfs2.h> +#include "lockd.h" #include "share.h" #define NLMDBG_FACILITY NLMDBG_SVCSUBS
fs/lockd/trace.h +2 -1
@@ -8,7 +8,8 @@#include <linux/tracepoint.h> #include <linux/crc32.h> #include <linux/nfs.h> -#include <linux/lockd/lockd.h> + +#include "lockd.h" #ifdef CONFIG_LOCKD_V4 #define NLM_STATUS_LIST \
fs/lockd/xdr.c +1 -2
@@ -15,13 +15,12 @@#include <linux/sunrpc/clnt.h> #include <linux/sunrpc/svc.h> #include <linux/sunrpc/stats.h> -#include <linux/lockd/lockd.h> #include <uapi/linux/nfs2.h> +#include "lockd.h" #include "svcxdr.h" -static inline loff_t s32_to_loff_t (__s32 offset) {
fs/lockd/xdr4.c +1 -1
@@ -16,8 +16,8 @@#include <linux/sunrpc/clnt.h> #include <linux/sunrpc/svc.h> #include <linux/sunrpc/stats.h> -#include <linux/lockd/lockd.h> +#include "lockd.h" #include "svcxdr.h" #include "xdr4.h"
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 10/14 lockd: Remove lockd/debug.h
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
The lockd include structure has unnecessary indirection. The header include/linux/lockd/debug.h is consumed only by fs/lockd/lockd.h, creating an extra compilation dependency and making the code harder to navigate.
Fold the debug.h definitions directly into lockd.h and remove the now-redundant header. This reduces the include tree depth and makes the debug-related definitions easier to find when working on lockd internals.
Build-tested with lockd built as module and built-in.
--- fs/lockd/lockd.h | 24 +++++++++++++++++++++- include/linux/lockd/debug.h | 40 ------------------------------------- 2 files changed, 23 insertions(+), 41 deletions(-) delete mode 100644 include/linux/lockd/debug.h
fs/lockd/lockd.h +23 -1
@@ -16,9 +16,31 @@#include <linux/utsname.h> #include <linux/lockd/bind.h> #include <linux/lockd/xdr.h> -#include <linux/lockd/debug.h> +#include <linux/sunrpc/debug.h> #include <linux/sunrpc/svc.h> +/* +* Enable lockd debugging. +* Requires CONFIG_SUNRPC_DEBUG. +*/ +#undef ifdebug +#if IS_ENABLED (CONFIG_SUNRPC_DEBUG ) +# define ifdebug (flag) if (unlikely(nlm_debug & NLMDBG_##flag)) +#else +# define ifdebug (flag) if (0) +#endif + +#define NLMDBG_SVC 0x0001 +#define NLMDBG_CLIENT 0x0002 +#define NLMDBG_CLNTLOCK 0x0004 +#define NLMDBG_SVCLOCK 0x0008 +#define NLMDBG_MONITOR 0x0010 +#define NLMDBG_CLNTSUBS 0x0020 +#define NLMDBG_SVCSUBS 0x0040 +#define NLMDBG_HOSTCACHE 0x0080 +#define NLMDBG_XDR 0x0100 +#define NLMDBG_ALL 0x7fff +/* * Version string */
include/linux/lockd/debug.h deleted +0 -40
@@ -1,40 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* -* linux/include/linux/lockd/debug.h -* -* Debugging stuff. -* -* Copyright (C) 1996 Olaf Kirch <[email protected]> -*/ - -#ifndef LINUX_LOCKD_DEBUG_H -#define LINUX_LOCKD_DEBUG_H - -#include <linux/sunrpc/debug.h> - -/* -* Enable lockd debugging. -* Requires RPC_DEBUG. -*/ -#undef ifdebug -#if IS_ENABLED (CONFIG_SUNRPC_DEBUG ) -# define ifdebug (flag) if (unlikely(nlm_debug & NLMDBG_##flag)) -#else -# define ifdebug (flag) if (0) -#endif - -/* -* Debug flags -*/ -#define NLMDBG_SVC 0x0001 -#define NLMDBG_CLIENT 0x0002 -#define NLMDBG_CLNTLOCK 0x0004 -#define NLMDBG_SVCLOCK 0x0008 -#define NLMDBG_MONITOR 0x0010 -#define NLMDBG_CLNTSUBS 0x0020 -#define NLMDBG_SVCSUBS 0x0040 -#define NLMDBG_HOSTCACHE 0x0080 -#define NLMDBG_XDR 0x0100 -#define NLMDBG_ALL 0x7fff - -#endif /* LINUX_LOCKD_DEBUG_H */
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 11/14 lockd: Move xdr.h from include/linux/lockd/ to fs/lockd/
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
The lockd subsystem unnecessarily exposes internal NLM XDR type definitions through the global include path. These definitions are not used by any code outside fs/lockd/, making them inappropriate for include/linux/lockd/.
Moving xdr.h to fs/lockd/ narrows the API surface and clarifies that these types are internal implementation details. The comment in linux/lockd/bind.h stating xdr.h was needed for "xdr-encoded error codes" is stale: no lockd API consumers use those codes.
Forward declarations for struct nfs_fh and struct file_lock are added to bind.h because their definitions were previously pulled in transitively through xdr.h. Additionally, nfs3proc.c needs an explicit include of filelock.h for FL_CLOSE.
Built and tested with lockd client/server operations. No functional change.
---
fs/lockd/lockd.h | 2 +-
{include/linux => fs}/lockd/xdr.h | 8 +++-----
fs/nfs/nfs3proc.c | 1 +
include/linux/lockd/bind.h | 5 ++---
4 files changed, 7 insertions(+), 9 deletions(-)
rename {include/linux => fs}/lockd/xdr.h (96%)fs/lockd/lockd.h +1 -1
@@ -15,7 +15,7 @@#include <linux/refcount.h> #include <linux/utsname.h> #include <linux/lockd/bind.h> -#include <linux/lockd/xdr.h> +#include "xdr.h" #include <linux/sunrpc/debug.h> #include <linux/sunrpc/svc.h>
fs/lockd/xdr.h renamed from include/linux/lockd/xdr.h +3 -5
@@ -1,14 +1,12 @@/* SPDX-License-Identifier: GPL-2.0 */ /* -* linux/include/linux/lockd/xdr.h -* * XDR types for the NLM protocol * * Copyright (C) 1996 Olaf Kirch <[email protected]> */ -#ifndef LOCKD_XDR_H -#define LOCKD_XDR_H +#ifndef _LOCKD_XDR_H +#define _LOCKD_XDR_H#include <linux/fs.h> #include <linux/filelock.h>
@@ -110,4 +108,4 @@ 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 */ +#endif /* _LOCKD_XDR_H */
fs/nfs/nfs3proc.c +1 -0
@@ -16,6 +16,7 @@#include <linux/nfs3.h> #include <linux/nfs_fs.h> #include <linux/nfs_page.h> +#include <linux/filelock.h> #include <linux/lockd/bind.h> #include <linux/nfs_mount.h> #include <linux/freezer.h>
include/linux/lockd/bind.h +2 -3
@@ -11,10 +11,9 @@#define LINUX_LOCKD_BIND_H #include <linux/lockd/nlm.h> -/* need xdr-encoded error codes too, so... */ -#include <linux/lockd/xdr.h> -/* Dummy declarations */ +struct file_lock ; +struct nfs_fh ;struct svc_rqst ;struct rpc_task ;struct rpc_clnt ;
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 12/14 lockd: Make linux/lockd/nlm.h an internal header
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
The NLM protocol constants and status codes in nlm.h are needed only by lockd's internal implementation. NFS client code and NFSD interact with lockd through the stable API in bind.h and have no direct use for protocol-level definitions.
Exposing these definitions globally via bind.h creates unnecessary coupling between lockd internals and its consumers. Moving nlm.h from include/linux/lockd/ to fs/lockd/ clarifies the API boundary:bind.h provides the lockd service interface, while nlm.h remains available only to code within fs/lockd/ that implements the protocol.
---
fs/lockd/lockd.h | 1 +
{include/linux => fs}/lockd/nlm.h | 8 +++-----
fs/lockd/svclock.c | 1 -
include/linux/lockd/bind.h | 2 --
4 files changed, 4 insertions(+), 8 deletions(-)
rename {include/linux => fs}/lockd/nlm.h (91%)fs/lockd/lockd.h +1 -0
@@ -14,6 +14,7 @@#include <linux/kref.h> #include <linux/refcount.h> #include <linux/utsname.h> +#include "nlm.h" #include <linux/lockd/bind.h> #include "xdr.h" #include <linux/sunrpc/debug.h>
fs/lockd/nlm.h renamed from include/linux/lockd/nlm.h +3 -5
@@ -1,14 +1,12 @@/* SPDX-License-Identifier: GPL-2.0 */ /* -* linux/include/linux/lockd/nlm.h -* * Declarations for the Network Lock Manager protocol. * * Copyright (C) 1996, Olaf Kirch <[email protected]> */ -#ifndef LINUX_LOCKD_NLM_H -#define LINUX_LOCKD_NLM_H +#ifndef _LOCKD_NLM_H +#define _LOCKD_NLM_H/* Maximum file offset in file_lock.fl_end */
@@ -55,4 +53,4 @@ enum {#define NLMPROC_NM_LOCK 22#define NLMPROC_FREE_ALL 23 -#endif /* LINUX_LOCKD_NLM_H */ +#endif /* _LOCKD_NLM_H */
fs/lockd/svclock.c +0 -1
@@ -28,7 +28,6 @@#include <linux/sched.h> #include <linux/sunrpc/clnt.h> #include <linux/sunrpc/svc_xprt.h> -#include <linux/lockd/nlm.h> #include "lockd.h"
include/linux/lockd/bind.h +0 -2
@@ -10,8 +10,6 @@#ifndef LINUX_LOCKD_BIND_H #define LINUX_LOCKD_BIND_H -#include <linux/lockd/nlm.h> -struct file_lock ;struct nfs_fh ;struct svc_rqst ;
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 13/14 lockd: Move nlm4svc_set_file_lock_range()
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
Both client-side and server-side NLMv4 code convert lock byte ranges from the wire format (start, length) to the kernel's file_lock format (start, end). The current nlm4svc_set_file_lock_range() performs this conversion, but the "svc" prefix incorrectly suggests server-only use, and client code must include server-internal headers to access it.
Rename to lockd_set_file_lock_range4() and relocate to the shared lockd.h header, making it accessible to both client and server code. This eliminates the need for client code to include xdr4.h, reducing coupling between the XDR implementation files.
While relocating the function, add input validation: clamp the starting offset to OFFSET_MAX before use. Without this, a malformed lock request with off > OFFSET_MAX results in fl_start > fl_end, violating file_lock invariants and potentially causing incorrect lock conflict detection.
--- fs/lockd/clnt4xdr.c | 2 +- fs/lockd/lockd.h | 25 +++++++++++++++++++++++++ fs/lockd/xdr4.c | 13 +------------ fs/lockd/xdr4.h | 1 - 4 files changed, 27 insertions(+), 14 deletions(-)
fs/lockd/clnt4xdr.c +1 -1
@@ -287,7 +287,7 @@ static int decode_nlm4_holder(struct xdr_stream *xdr, struct nlm_res *result) fl->c.flc_type = exclusive !=0 ?F_WRLCK :F_RDLCK ; p =xdr_decode_hyper (p, &l_offset);xdr_decode_hyper (p, &l_len); -nlm4svc_set_file_lock_range (fl, l_offset, l_len); +lockd_set_file_lock_range4 (fl, l_offset, l_len); error =0 ; out:return error;
fs/lockd/lockd.h +25 -0
@@ -413,6 +413,31 @@ 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_range4 - 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 +* +* The NLMv4 protocol represents lock byte ranges as (start, length), +* where length zero means "lock to end of file." The kernel's file_lock +* structure uses (start, end) representation. Convert from NLMv4 format +* to file_lock format, clamping the starting offset and treating +* arithmetic overflow as "lock to EOF." +*/ +static inline void +lockd_set_file_lock_range4 (struct file_lock *fl,u64 off,u64 len) +{ +u64 clamped_off = (off >OFFSET_MAX ) ?OFFSET_MAX : off; +s64 end = clamped_off + len -1 ; + + fl->fl_start = clamped_off; +if (len ==0 || end <0 ) + fl->fl_end =OFFSET_MAX ; +else + fl->fl_end = end; +} +extern const struct lock_manager_operations nlmsvc_lock_operations;#endif /* _LOCKD_LOCKD_H */
fs/lockd/xdr4.c +1 -12
@@ -34,17 +34,6 @@ loff_t_to_s64(loff_t offset)return res; } -void nlm4svc_set_file_lock_range (struct file_lock *fl,u64 off,u64 len) -{ -s64 end = off + len -1 ; - - fl->fl_start = off; -if (len ==0 || end <0 ) - fl->fl_end =OFFSET_MAX ; -else - fl->fl_end = end; -} -/* * NLM file handles are defined by specification to be a variable-length * XDR opaque no longer than 1024 bytes. However, this implementation
@@ -91,7 +80,7 @@ svcxdr_decode_lock(struct xdr_stream *xdr, struct nlm_lock *lock)locks_init_lock (fl); fl->c.flc_type =F_RDLCK ; -nlm4svc_set_file_lock_range (fl, lock->lock_start, lock->lock_len); +lockd_set_file_lock_range4 (fl, lock->lock_start, lock->lock_len);return true; }
fs/lockd/xdr4.h +0 -1
@@ -15,7 +15,6 @@#define nlm4_fbig cpu_to_be32(NLM_FBIG)#define nlm4_failed cpu_to_be32(NLM_FAILED) -void nlm4svc_set_file_lock_range (struct file_lock *fl,u64 off,u64 len);bool nlm4svc_decode_void (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nlm4svc_decode_testargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);bool nlm4svc_decode_lockargs (struct svc_rqst *rqstp,struct xdr_stream *xdr);
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v4 14/14 lockd: Relocate svc_version definitions to XDR layer
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
Public RPC server interfaces become cluttered when internal XDR implementation details leak into them. The procedure count, maximum XDR buffer size, and per-CPU call counters serve no purpose outside the code that encodes and decodes NLM protocol messages. Exposing these values through global headers creates unnecessary coupling between the RPC dispatch logic and the XDR layer.
Relocating the svc_version structure definitions confines this implementation information to the files where XDR encoding and decoding occur. In svc.c, the buffer size computation now reads vs_xdrsize from the version structures rather than relying on a preprocessor constant. This calculation occurs at service initialization, after the linker has resolved the version structure definitions. The dispatch function becomes non-static because both the version structures and the dispatcher reside in different translation units.
The NLMSVC_XDRSIZE macro is removed from xdr.h because buffer size is now computed from the union of XDR argument and result structures, matching the pattern used in other RPC services. Version 1 and 3 share the same procedure table but maintain separate counter arrays. Version 4 remains separate due to its distinct procedure definitions.
--- fs/lockd/lockd.h | 6 ++++-- fs/lockd/svc.c | 48 +++++++++++---------------------------------- fs/lockd/svc4proc.c | 23 +++++++++++++++++++++- fs/lockd/svcproc.c | 38 ++++++++++++++++++++++++++++++++++- fs/lockd/xdr.h | 5 ----- 5 files changed, 74 insertions(+), 46 deletions(-)
fs/lockd/lockd.h +4 -2
@@ -221,9 +221,10 @@ struct nlm_block {* Global variables */ extern const struct rpc_program nlm_program; -extern const struct svc_procedure nlmsvc_procedures[24 ]; +extern const struct svc_version nlmsvc_version1; +extern const struct svc_version nlmsvc_version3;#ifdef CONFIG_LOCKD_V4 -extern const struct svc_procedure nlmsvc_procedures4[24 ]; +extern const struct svc_version nlmsvc_version4;#endif extern int nlmsvc_grace_period;extern unsigned long nlm_timeout;
@@ -318,6 +319,7 @@ void nlmsvc_traverse_blocks(struct nlm_host *, struct nlm_file *,void nlmsvc_grant_reply (struct nlm_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);/* * File handling for the server personality
fs/lockd/svc.c +11 -37
78 lines not on this page · raw message
fs/lockd/svc4proc.c +22 -1
@@ -530,7 +530,7 @@ struct nlm_void { int dummy; };#define St 1/* status */ #define Rg 4/* range (offset + length) */ -const struct svc_procedure nlmsvc_procedures4[24 ] = { +static const struct svc_procedure nlm4svc_procedures[24 ] = { [NLMPROC_NULL ] = { .pc_func = nlm4svc_proc_null, .pc_decode = nlm4svc_decode_void,
@@ -772,3 +772,24 @@ const struct svc_procedure nlmsvc_procedures4[24] = { .pc_name = "FREE_ALL", }, }; + +/* +* Storage requirements for XDR arguments and results +*/ +union nlm4svc_xdrstore { +struct nlm_args args; +struct nlm_res res; +struct nlm_reboot reboot; +}; + +static DEFINE_PER_CPU_ALIGNED(unsigned long, + nlm4svc_call_counters[ARRAY_SIZE(nlm4svc_procedures)]); + +const struct svc_version nlmsvc_version4 = { + .vs_vers =4 , + .vs_nproc =ARRAY_SIZE (nlm4svc_procedures), + .vs_proc = nlm4svc_procedures, + .vs_count = nlm4svc_call_counters, + .vs_dispatch = nlmsvc_dispatch, + .vs_xdrsize =sizeof (union nlm4svc_xdrstore ), +};
fs/lockd/svcproc.c +37 -1
@@ -555,7 +555,7 @@ struct nlm_void { int dummy; };#define No (1+1024/4)/* Net Obj */ #define Rg 2/* range - offset + size */ -const struct svc_procedure nlmsvc_procedures[24 ] = { +static const struct svc_procedure nlmsvc_procedures[24 ] = { [NLMPROC_NULL ] = { .pc_func = nlmsvc_proc_null, .pc_decode = nlmsvc_decode_void,
@@ -797,3 +797,39 @@ const struct svc_procedure nlmsvc_procedures[24] = { .pc_name = "FREE_ALL", }, }; + +/* +* Storage requirements for XDR arguments and results +*/ +union nlmsvc_xdrstore { +struct nlm_args args; +struct nlm_res res; +struct nlm_reboot reboot; +}; + +/* +* NLMv1 defines only procedures 1 - 15. Linux lockd also implements +* procedures 0 (NULL) and 16 (SM_NOTIFY). +*/ +static DEFINE_PER_CPU_ALIGNED(unsigned long, nlm1svc_call_counters[17]); + +const struct svc_version nlmsvc_version1 = { + .vs_vers =1 , + .vs_nproc =17 , + .vs_proc = nlmsvc_procedures, + .vs_count = nlm1svc_call_counters, + .vs_dispatch = nlmsvc_dispatch, + .vs_xdrsize =sizeof (union nlmsvc_xdrstore ), +}; + +static DEFINE_PER_CPU_ALIGNED(unsigned long, + nlm3svc_call_counters[ARRAY_SIZE(nlmsvc_procedures)]); + +const struct svc_version nlmsvc_version3 = { + .vs_vers =3 , + .vs_nproc =ARRAY_SIZE (nlmsvc_procedures), + .vs_proc = nlmsvc_procedures, + .vs_count = nlm3svc_call_counters, + .vs_dispatch = nlmsvc_dispatch, + .vs_xdrsize =sizeof (union nlmsvc_xdrstore ), +};
fs/lockd/xdr.h +0 -5
@@ -88,11 +88,6 @@ struct nlm_reboot {struct nsm_private priv; }; -/* -* Contents of statd callback when monitored host rebooted -*/ -#define NLMSVC_XDRSIZE sizeof(struct nlm_args) -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);
Signature · 1 line
2.52.0
kernel test robot
build botRe: [PATCH v4 11/14] lockd: Move xdr.h from include/linux/lockd/ to fs/lockd/
In reply to Chuck Leverkernel test robot noticed the following build errors:
Hi Chuck,
kernel test robot noticed the following build errors:
[auto build test ERROR on trondmy-nfs/linux-next]
[also build test ERROR on brauner-vfs/vfs.all linus/master v6.19-rc7 next-20260128] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Chuck-Lever/lockd-Simplify-cast_status-in-svcproc-c/20260128-232322 base: git://git.linux-nfs.org/projects/trondmy/linux-nfs.git linux-next patch link: https://lore.kernel.org/r/20260128151935.1646063-12-cel%40kernel.org patch subject: [PATCH v4 11/14] lockd: Move xdr.h from include/linux/lockd/ to fs/lockd/ config: arm-randconfig-r112-20260129 (https://download.01.org/0day-ci/archive/20260129/[email protected]/config) compiler: arm-linux-gnueabi-gcc (GCC) 12.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260129/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
fs/nfs/proc.c: In function 'nfs_lock_check_bounds':
>> fs/nfs/proc.c:677:26: error: invalid use of undefined type 'const struct file_lock'
677 | start = (__s32)fl->fl_start;
| ^~
fs/nfs/proc.c:678:32: error: invalid use of undefined type 'const struct file_lock'
678 | if ((loff_t)start != fl->fl_start)
| ^~
fs/nfs/proc.c:681:15: error: invalid use of undefined type 'const struct file_lock'
681 | if (fl->fl_end != OFFSET_MAX) {
| ^~
fs/nfs/proc.c:682:32: error: invalid use of undefined type 'const struct file_lock'
682 | end = (__s32)fl->fl_end;
| ^~
fs/nfs/proc.c:683:38: error: invalid use of undefined type 'const struct file_lock'
683 | if ((loff_t)end != fl->fl_end)
| ^~vim +677 fs/nfs/proc.c
^1da177e4c3f41 Linus Torvalds 2005-04-16 670
2116271a347d11 Trond Myklebust 2008-05-20 671 /* Helper functions for NFS lock bounds checking */
2116271a347d11 Trond Myklebust 2008-05-20 672 #define NFS_LOCK32_OFFSET_MAX ((__s32)0x7fffffffUL)
2116271a347d11 Trond Myklebust 2008-05-20 673 static int nfs_lock_check_bounds(const struct file_lock *fl)
2116271a347d11 Trond Myklebust 2008-05-20 674 {
2116271a347d11 Trond Myklebust 2008-05-20 675 __s32 start, end;
2116271a347d11 Trond Myklebust 2008-05-20 676
2116271a347d11 Trond Myklebust 2008-05-20 @677 start = (__s32)fl->fl_start;
2116271a347d11 Trond Myklebust 2008-05-20 678 if ((loff_t)start != fl->fl_start)
2116271a347d11 Trond Myklebust 2008-05-20 679 goto out_einval;
2116271a347d11 Trond Myklebust 2008-05-20 680
2116271a347d11 Trond Myklebust 2008-05-20 681 if (fl->fl_end != OFFSET_MAX) {
2116271a347d11 Trond Myklebust 2008-05-20 682 end = (__s32)fl->fl_end;
2116271a347d11 Trond Myklebust 2008-05-20 683 if ((loff_t)end != fl->fl_end)
2116271a347d11 Trond Myklebust 2008-05-20 684 goto out_einval;
2116271a347d11 Trond Myklebust 2008-05-20 685 } else
2116271a347d11 Trond Myklebust 2008-05-20 686 end = NFS_LOCK32_OFFSET_MAX;
2116271a347d11 Trond Myklebust 2008-05-20 687
2116271a347d11 Trond Myklebust 2008-05-20 688 if (start < 0 || start > end)
2116271a347d11 Trond Myklebust 2008-05-20 689 goto out_einval;
2116271a347d11 Trond Myklebust 2008-05-20 690 return 0;
2116271a347d11 Trond Myklebust 2008-05-20 691 out_einval:
2116271a347d11 Trond Myklebust 2008-05-20 692 return -EINVAL;
2116271a347d11 Trond Myklebust 2008-05-20 693 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 694 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki