[PATCH 7/9] NFSD: Relocate nfsd_user_namespace()
Chuck Lever <[email protected]>
| Newsgroups | gmane.linux.nfs |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> --- 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