From: Chuck Lever <cel@kernel.org>
To: NeilBrown <neil@brown.name>, Jeff Layton <jlayton@kernel.org>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: <linux-nfs@vger.kernel.org>
Subject: [PATCH 7/9] NFSD: Relocate nfsd_user_namespace()
Date: Sun, 12 Jul 2026 16:45:52 -0400 [thread overview]
Message-ID: <20260712204554.125308-8-cel@kernel.org> (raw)
In-Reply-To: <20260712204554.125308-1-cel@kernel.org>
Refactor: nfsd_user_namespace() currently lives in nfsd.h, so every
caller must pull in nfsd.h -- directly or transitively via state.h --
and with it the NFS protocol definitions from uapi/linux/nfs.h and
friends, even when the caller uses nothing else from nfsd.h.
Since nfsd_user_namespace() is an auth-related function, move it
to fs/nfsd/auth.c in preparation for removing '#include "nfsd.h"'
from a few places.
Signed-off-by: Chuck Lever <cel@kernel.org>
---
fs/nfsd/auth.c | 18 ++++++++++++++++++
fs/nfsd/auth.h | 6 ++++++
fs/nfsd/nfs4idmap.c | 1 +
fs/nfsd/nfs4xdr.c | 1 +
fs/nfsd/nfsd.h | 6 ------
5 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/fs/nfsd/auth.c b/fs/nfsd/auth.c
index e3b4a35caac6..5ef9a0466eda 100644
--- a/fs/nfsd/auth.c
+++ b/fs/nfsd/auth.c
@@ -88,3 +88,21 @@ int nfsd_setuser(struct svc_cred *cred, struct svc_export *exp)
return -ENOMEM;
}
+/**
+ * nfsd_user_namespace - Get user_namespace in effect for an RPC request
+ * @rqstp: RPC execution context
+ *
+ * xpt_cred is set once at transport creation and never modified. The
+ * transport itself is reference-counted during request processing, so
+ * no explicit reference on the namespace is necessary.
+ *
+ * Return: the user_namespace from the transport credential, or
+ * init_user_ns if no credential was set. The returned namespace pointer
+ * is valid for the duration of the RPC request.
+ */
+struct user_namespace *nfsd_user_namespace(const struct svc_rqst *rqstp)
+{
+ const struct cred *cred = rqstp->rq_xprt->xpt_cred;
+
+ return cred ? cred->user_ns : &init_user_ns;
+}
diff --git a/fs/nfsd/auth.h b/fs/nfsd/auth.h
index 8c5031bbbcee..832bc957980d 100644
--- a/fs/nfsd/auth.h
+++ b/fs/nfsd/auth.h
@@ -8,10 +8,16 @@
#ifndef LINUX_NFSD_AUTH_H
#define LINUX_NFSD_AUTH_H
+struct user_namespace;
+struct svc_export;
+struct svc_rqst;
+
/*
* Set the current process's fsuid/fsgid etc to those of the NFS
* client user
*/
int nfsd_setuser(struct svc_cred *cred, struct svc_export *exp);
+struct user_namespace *nfsd_user_namespace(const struct svc_rqst *rqstp);
+
#endif /* LINUX_NFSD_AUTH_H */
diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c
index 71ba61b5d0a3..e9faf8b78f74 100644
--- a/fs/nfsd/nfs4idmap.c
+++ b/fs/nfsd/nfs4idmap.c
@@ -38,6 +38,7 @@
#include <linux/slab.h>
#include <linux/sunrpc/svc_xprt.h>
#include <net/net_namespace.h>
+#include "auth.h"
#include "idmap.h"
#include "nfsd.h"
#include "netns.h"
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index aef48fb0fac2..cba2e72d616c 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -47,6 +47,7 @@
#include <uapi/linux/xattr.h>
+#include "auth.h"
#include "idmap.h"
#include "acl.h"
#include "xdr4.h"
diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
index 0503ee0e1bbe..81312b11b5c2 100644
--- a/fs/nfsd/nfsd.h
+++ b/fs/nfsd/nfsd.h
@@ -153,12 +153,6 @@ static inline int nfsd_v4client(struct svc_rqst *rq)
{
return rq && rq->rq_prog == NFS_PROGRAM && rq->rq_vers == 4;
}
-static inline struct user_namespace *
-nfsd_user_namespace(const struct svc_rqst *rqstp)
-{
- const struct cred *cred = rqstp->rq_xprt->xpt_cred;
- return cred ? cred->user_ns : &init_user_ns;
-}
/*
* NFSv4 State
--
2.54.0
next prev parent reply other threads:[~2026-07-12 20:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-12 20:45 [PATCH 0/9] Start reorganizing fs/nfsd/nfsd.h Chuck Lever
2026-07-12 20:45 ` [PATCH 1/9] NFSD: Make "stats.h" self-contained Chuck Lever
2026-07-12 20:45 ` [PATCH 2/9] NFSD: Explicitly include "stats.h" Chuck Lever
2026-07-12 20:45 ` [PATCH 3/9] NFSD: include "netns.h" Chuck Lever
2026-07-12 20:45 ` [PATCH 4/9] NFSD: Remove '#include "nfsd.h"' from fs/nfsd/cache.h Chuck Lever
2026-07-12 20:45 ` [PATCH 5/9] NFSD: Move the export.h include from nfsd.h to auth.c Chuck Lever
2026-07-12 20:45 ` [PATCH 6/9] NFSD: Move struct readdir_cd Chuck Lever
2026-07-12 20:45 ` Chuck Lever [this message]
2026-07-12 20:45 ` [PATCH 8/9] NFSD: Relocate nfsd4_set_netaddr() Chuck Lever
2026-07-12 20:45 ` [PATCH 9/9] NFSD: Relocate NFSv4 "supported attributes" to new header Chuck Lever
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260712204554.125308-8-cel@kernel.org \
--to=cel@kernel.org \
--cc=dai.ngo@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.