Skip to contentSkip to conversation

sunrpc/nfs: cleanup redundant debug checks and refactor macros

PATCH Superseded Sean Chang 2 participants 8 messages Mar 20

Subsystems (4)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Sean Chang

author
#0 lore raw

v4 cover sunrpc/nfs: cleanup redundant debug checks and refactor macros

This series cleans up redundant IS_ENABLED(CONFIG_SUNRPC_DEBUG) guards across sunrpc, nfsd, and lockd, as these checks are already handled within the dprintk macros.

Additionally, it refactors the nfs_errorf() macros into a safer do-while(0) pattern and removes unused nfs_warnf() macros to improve code maintainability.

v4:
- Add a missing patch to include/linux/sunrpc/debug.h to ensure dprintk() properly handles variable referencing via no_printk().
- Remove obsolete __maybe_unused from fs/nfsd/export.c (revert ebae102897e7) as suggested by Andy Shevchenko.
- Add Reviewed-by and Tested-by tags from Andy Shevchenko.

v3:
- Added nfs_errorf refactoring and removed unused nfs_warnf macros.
- Split sunrpc and nfsd changes for better clarity.

v2:
- Follow reversed xmas tree order for variables in svc_rdma_transport.c as requested by Andy Shevchenko.
- Polish commit message: use dprintk() and remove redundant file list.
- Correct the technical claim about dprintk() type checking.

Sean Chang (5):
sunrpc: Fix dprintk type mismatch using do-while(0) nfsd/lockd: Remove redundant debug checks
svcrdma: remove redundant IS_ENABLED(CONFIG_SUNRPC_DEBUG) guards
nfs: refactor nfs_errorf macros and remove unused ones
nfsd: remove obsolete __maybe_unused from variables

 fs/lockd/svclock.c                       |  7 ------
 fs/nfs/internal.h                        | 28 +++++++++++-------------
 fs/nfsd/export.c                         |  2 +-
 fs/nfsd/nfsfh.c                          |  8 +++----
 include/linux/sunrpc/debug.h             |  8 ++-----
 net/sunrpc/xprtrdma/svc_rdma_transport.c | 25 ++++++++++-----------
 6 files changed, 30 insertions(+), 48 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v4 1/5 sunrpc: Fix dprintk type mismatch using do-while(0)

Following David Laight's suggestion, simplify the macro definitions by removing the unnecessary 'fmt' argument and using no_printk(VA_ARGS) directly.

To resolve a Sparse warning (void vs int mismatch) when dfprintk is used in conditional statements, wrap the non-debug definition in a do-while(0) block. This ensures the macro always evaluates to a void expression.

---
 include/linux/sunrpc/debug.h | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
include/linux/sunrpc/debug.h +2 -6
index ab61bed2f7af..f6f2a106eeaf 100644
@@ -38,8 +38,6 @@ extern unsigned int		nlm_debug;
 do {									\
 	ifdebug(fac)							\
 		__sunrpc_printk(fmt, ##__VA_ARGS__);			\
-	else								\
-		no_printk(fmt, ##__VA_ARGS__);				\
 } while (0)
 
 # define dfprintk_rcu(fac, fmt, ...)					\
@@ -48,15 +46,13 @@ do {									\
 		rcu_read_lock();					\
 		__sunrpc_printk(fmt, ##__VA_ARGS__);			\
 		rcu_read_unlock();					\
-	} else {							\
-		no_printk(fmt, ##__VA_ARGS__);				\
 	}								\
 } while (0)
 
 #else
 # define ifdebug(fac)		if (0)
-# define dfprintk(fac, fmt, ...)	no_printk(fmt, ##__VA_ARGS__)
-# define dfprintk_rcu(fac, fmt, ...)	no_printk(fmt, ##__VA_ARGS__)
+# define dfprintk(fac, ...)		no_printk(__VA_ARGS__)
+# define dfprintk_rcu(fac, ...)	no_printk(__VA_ARGS__)
 #endif
 
 /*
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v4 2/5 nfsd/lockd: Remove redundant debug checks

In reply to Sean Chang

Remove unnecessary IS_ENABLED(CONFIG_SUNRPC_DEBUG) guards and #ifdefs in nfsfh.c and svclock.c.

Verification with .lst files under -O2 confirms that the compiler successfully performs "dead code elimination". Even when variables (like char buf[] in nfsfh.c) or static helper functions (like nlmdbg_cookie2a() in svclock.c) are declared without #ifdef, they are completely optimized out (no stack allocation, no symbol references in the final executable) as they are only referenced within no_printk().

---
 fs/lockd/svclock.c | 7 -------
 fs/nfsd/nfsfh.c    | 8 +++-----
 2 files changed, 3 insertions(+), 12 deletions(-)
fs/lockd/svclock.c +0 -7
index ee23f5802af1..9b978a087b3c 100644
@@ -47,7 +47,6 @@ static const struct rpc_call_ops nlmsvc_grant_ops;
 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)
 {
 	/*
@@ -74,12 +73,6 @@ static const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
 
 	return buf;
 }
-#else
-static inline const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
-{
-	return "???";
-}
-#endif
 
 /*
  * Insert a blocked lock into the global list
fs/nfsd/nfsfh.c +3 -5
index 68b629fbaaeb..91514326d1b4 100644
@@ -105,12 +105,10 @@ static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
 {
 	/* Check if the request originated from a secure port. */
 	if (rqstp && !nfsd_originating_port_ok(rqstp, cred, exp)) {
-		if (IS_ENABLED(CONFIG_SUNRPC_DEBUG)) {
-			char buf[RPC_MAX_ADDRBUFLEN];
+		char buf[RPC_MAX_ADDRBUFLEN];
 
-			dprintk("nfsd: request from insecure port %s!\n",
-			        svc_print_addr(rqstp, buf, sizeof(buf)));
-		}
+		dprintk("nfsd: request from insecure port %s!\n",
+			svc_print_addr(rqstp, buf, sizeof(buf)));
 		return nfserr_perm;
 	}
 
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH v4 3/5 svcrdma: remove redundant IS_ENABLED(CONFIG_SUNRPC_DEBUG) guards

In reply to Sean Chang

Remove redundant IS_ENABLED(CONFIG_SUNRPC_DEBUG) guards in svc_rdma_accept(). Since dprintk() already evaluates to a no-op (via no_printk) when debugging is disabled, these explicit guards are unnecessary.

Verification with .lst files under -O2 confirms that the compiler successfully performs "dead code elimination". Even when variables (like 'sap' in this case) are declared outside of #ifdef, they are completely optimized out (no stack allocation, no symbol references in the final executable) as they are only referenced within dprintk().

---
 net/sunrpc/xprtrdma/svc_rdma_transport.c | 25 +++++++++++-------------
 1 file changed, 11 insertions(+), 14 deletions(-)
net/sunrpc/xprtrdma/svc_rdma_transport.c +11 -14
index f2d72181a6fe..0759444bda50 100644
@@ -413,6 +413,7 @@ static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
 	struct rpcrdma_connect_private pmsg;
 	struct ib_qp_init_attr qp_attr;
 	struct ib_device *dev;
+	struct sockaddr *sap;
 	int ret = 0;
 
 	listen_rdma = container_of(xprt, struct svcxprt_rdma, sc_xprt);
@@ -559,20 +560,16 @@ static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
 		goto errout;
 	}
 
-	if (IS_ENABLED(CONFIG_SUNRPC_DEBUG)) {
-		struct sockaddr *sap;
-
-		dprintk("svcrdma: new connection accepted on device %s:\n", dev->name);
-		sap = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.src_addr;
-		dprintk("    local address   : %pIS:%u\n", sap, rpc_get_port(sap));
-		sap = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.dst_addr;
-		dprintk("    remote address  : %pIS:%u\n", sap, rpc_get_port(sap));
-		dprintk("    max_sge         : %d\n", newxprt->sc_max_send_sges);
-		dprintk("    sq_depth        : %d\n", newxprt->sc_sq_depth);
-		dprintk("    rdma_rw_ctxs    : %d\n", ctxts);
-		dprintk("    max_requests    : %d\n", newxprt->sc_max_requests);
-		dprintk("    ord             : %d\n", conn_param.initiator_depth);
-	}
+	dprintk("svcrdma: new connection accepted on device %s:\n", dev->name);
+	sap = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.src_addr;
+	dprintk("    local address   : %pIS:%u\n", sap, rpc_get_port(sap));
+	sap = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.dst_addr;
+	dprintk("    remote address  : %pIS:%u\n", sap, rpc_get_port(sap));
+	dprintk("    max_sge         : %d\n", newxprt->sc_max_send_sges);
+	dprintk("    sq_depth        : %d\n", newxprt->sc_sq_depth);
+	dprintk("    rdma_rw_ctxs    : %d\n", ctxts);
+	dprintk("    max_requests    : %d\n", newxprt->sc_max_requests);
+	dprintk("    ord             : %d\n", conn_param.initiator_depth);
 
 	return &newxprt->sc_xprt;
 
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH v4 4/5 nfs: refactor nfs_errorf macros and remove unused ones

In reply to Sean Chang

refactor nfs_errorf() and nfs_ferrorf() to the standard do-while(0) pattern for safer macro expansion and kernel style compliance.

additionally, remove nfs_warnf() and nfs_fwarnf() as git grep confirms they have no callers in the current tree.

---
 fs/nfs/internal.h | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)
fs/nfs/internal.h +13 -15
index 63e09dfc27a8..59ab43542390 100644
@@ -161,13 +161,19 @@ enum nfs_lock_status {
 	NFS_LOCK_NOLOCK		= 2,
 };
 
-#define nfs_errorf(fc, fmt, ...) ((fc)->log.log ?		\
-	errorf(fc, fmt, ## __VA_ARGS__) :			\
-	({ dprintk(fmt "\n", ## __VA_ARGS__); }))
-
-#define nfs_ferrorf(fc, fac, fmt, ...) ((fc)->log.log ?		\
-	errorf(fc, fmt, ## __VA_ARGS__) :			\
-	({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); }))
+#define nfs_errorf(fc, fmt, ...) do { \
+	if ((fc)->log.log) \
+		errorf(fc, fmt, ## __VA_ARGS__); \
+	else \
+		dprintk(fmt "\n", ## __VA_ARGS__); \
+} while (0)
+
+#define nfs_ferrorf(fc, fac, fmt, ...) do { \
+	if ((fc)->log.log) \
+		errorf(fc, fmt, ## __VA_ARGS__); \
+	else \
+		dfprintk(fac, fmt "\n", ## __VA_ARGS__); \
+} while (0)
 
 #define nfs_invalf(fc, fmt, ...) ((fc)->log.log ?		\
 	invalf(fc, fmt, ## __VA_ARGS__) :			\
@@ -177,14 +183,6 @@ enum nfs_lock_status {
 	invalf(fc, fmt, ## __VA_ARGS__) :			\
 	({ dfprintk(fac, fmt "\n", ## __VA_ARGS__);  -EINVAL; }))
 
-#define nfs_warnf(fc, fmt, ...) ((fc)->log.log ?		\
-	warnf(fc, fmt, ## __VA_ARGS__) :			\
-	({ dprintk(fmt "\n", ## __VA_ARGS__); }))
-
-#define nfs_fwarnf(fc, fac, fmt, ...) ((fc)->log.log ?		\
-	warnf(fc, fmt, ## __VA_ARGS__) :			\
-	({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); }))
-
 static inline struct nfs_fs_context *nfs_fc2context(const struct fs_context *fc)
 {
 	return fc->fs_private;
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v4 4/5] nfs: refactor nfs_errorf macros and remove unused ones

Quoted 4 lines · Sean Chang

refactor nfs_errorf() and nfs_ferrorf() to the standard do-while(0) pattern for safer macro expansion and kernel style compliance.

additionally, remove nfs_warnf() and nfs_fwarnf() as git grep

git grep

Quoted 1 line

confirms they have no callers in the current tree.

You can also add that they were never actually used from the day of introduction by the commit ce8866f0913f ("NFS: Attach supplementary error information to fs_context.").

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#6 lore raw

PATCH v4 5/5 nfsd: remove obsolete __maybe_unused from variables

In reply to Sean Chang

Now that dprintk() has been refactored to use no_printk(), variables used only for debugging are properly referenced by the compiler even when CONFIG_SUNRPC_DEBUG is disabled.

Therefore, the __maybe_unused attributes added in commit ebae102897e7 ("nfsd: Mark variable __maybe_unused to avoid W=1 build break") are no longer necessary. This patch removes them to clean up the code.

---
 fs/nfsd/export.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfsd/export.c +1 -1
index 8fdbba7cad96..8116e5bcbe00 100644
@@ -1025,7 +1025,7 @@ exp_rootfh(struct net *net, struct auth_domain *clp, char *name,
 {
 	struct svc_export	*exp;
 	struct path		path;
-	struct inode		*inode __maybe_unused;
+	struct inode		*inode;
 	struct svc_fh		fh;
 	int			err;
 	struct nfsd_net		*nn = net_generic(net, nfsd_net_id);
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v4 5/5] nfsd: remove obsolete __maybe_unused from variables

Quoted 7 lines · Sean Chang

Now that dprintk() has been refactored to use no_printk(), variables used only for debugging are properly referenced by the compiler even when CONFIG_SUNRPC_DEBUG is disabled.

Therefore, the __maybe_unused attributes added in commit ebae102897e7 ("nfsd: Mark variable __maybe_unused to avoid W=1 build break") are no longer necessary. This patch removes them to clean up the code.

Just make it a revert: proper Subject like 'Revert: "..."' and the Git added line "This reverts ...".

Signature · 2 lines
With Best Regards,
Andy Shevchenko