>From 36bdb502360461a8426821a37728aef3a3b8c738 Mon Sep 17 00:00:00 2001 From: Kirill A. Shutemov Date: Mon, 20 Dec 2010 04:03:52 +0200 Subject: [PATCH] sunrpc: introduce get_rpc_pipefs() Get rpc_pipefs mount point by path. Signed-off-by: Kirill A. Shutemov --- include/linux/sunrpc/rpc_pipe_fs.h | 2 + net/sunrpc/rpc_pipe.c | 51 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 0 deletions(-) diff --git a/include/linux/sunrpc/rpc_pipe_fs.h b/include/linux/sunrpc/rpc_pipe_fs.h index b09bfa5..922057c 100644 --- a/include/linux/sunrpc/rpc_pipe_fs.h +++ b/include/linux/sunrpc/rpc_pipe_fs.h @@ -46,6 +46,8 @@ RPC_I(struct inode *inode) extern struct vfsmount *init_rpc_pipefs; +struct vfsmount *get_rpc_pipefs(const char *path); + extern int rpc_queue_upcall(struct inode *, struct rpc_pipe_msg *); struct rpc_clnt; diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c index b1e299b..4e09a90 100644 --- a/net/sunrpc/rpc_pipe.c +++ b/net/sunrpc/rpc_pipe.c @@ -16,6 +16,9 @@ #include #include #include +#include +#include +#include #include #include @@ -931,6 +934,54 @@ static const struct super_operations s_ops = { #define RPCAUTH_GSSMAGIC 0x67596969 +static int check_rpc_pipefs(struct vfsmount *mnt, void *arg) +{ + struct vfsmount **rpcmount = arg; + struct path path = { + .mnt = mnt, + .dentry = mnt->mnt_root, + }; + + if (!mnt->mnt_sb) + return 0; + if (mnt->mnt_sb->s_magic != RPCAUTH_GSSMAGIC) + return 0; + + if (!path_is_under(&path, ¤t->fs->root)) + return 0; + + *rpcmount = mntget(mnt); + return 1; +} + +struct vfsmount *get_rpc_pipefs(const char *p) +{ + int error; + struct vfsmount *rpcmount = ERR_PTR(-EINVAL); + struct path path; + + if (!p) { + iterate_mounts(check_rpc_pipefs, &rpcmount, + current->nsproxy->mnt_ns->root); + + if (IS_ERR(rpcmount) && (current->nsproxy->mnt_ns == + init_task.nsproxy->mnt_ns)) + return mntget(init_rpc_pipefs); + + return rpcmount; + } + + error = kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); + if (error) + return ERR_PTR(error); + + check_rpc_pipefs(path.mnt, &rpcmount); + path_put(&path); + + return rpcmount; +} +EXPORT_SYMBOL_GPL(get_rpc_pipefs); + /* * We have a single directory with 1 node in it. */ -- 1.7.3.4