c44d272
Bugzilla: N/A
c44d272
Upstream-status: queued in NFS git tree (for 3.13/3.14?)
a585abf
a585abf
rpc.gssd will naturally hold open any pipe named */clnt*/gssd that shows
a585abf
up under rpc_pipefs. That behavior gives us a reliable mechanism to tell
a585abf
whether it's actually running or not.
a585abf
a585abf
Create a new toplevel "gssd" directory in rpc_pipefs when it's mounted.
a585abf
Under that directory create another directory called "clntXX", and then
a585abf
within that a pipe called "gssd".
a585abf
a585abf
We'll never send an upcall along that pipe, and any downcall written to
a585abf
it will just return -EINVAL.
a585abf
a585abf
Signed-off-by: Jeff Layton <jlayton@redhat.com>
a585abf
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
a585abf
---
a585abf
 include/linux/sunrpc/rpc_pipe_fs.h |    3 +-
a585abf
 net/sunrpc/netns.h                 |    1 +
a585abf
 net/sunrpc/rpc_pipe.c              |   93 ++++++++++++++++++++++++++++++++++-
a585abf
 net/sunrpc/sunrpc_syms.c           |    8 +++-
a585abf
 4 files changed, 100 insertions(+), 5 deletions(-)
a585abf
a585abf
diff -up linux-3.11.9-200.fc19.x86_64/include/linux/sunrpc/rpc_pipe_fs.h.orig linux-3.11.9-200.fc19.x86_64/include/linux/sunrpc/rpc_pipe_fs.h
a585abf
--- linux-3.11.9-200.fc19.x86_64/include/linux/sunrpc/rpc_pipe_fs.h.orig	2013-09-02 16:46:10.000000000 -0400
a585abf
+++ linux-3.11.9-200.fc19.x86_64/include/linux/sunrpc/rpc_pipe_fs.h	2013-11-21 10:11:17.893026000 -0500
a585abf
@@ -64,7 +64,8 @@ enum {
a585abf
 
a585abf
 extern struct dentry *rpc_d_lookup_sb(const struct super_block *sb,
a585abf
 				      const unsigned char *dir_name);
a585abf
-extern void rpc_pipefs_init_net(struct net *net);
a585abf
+extern int rpc_pipefs_init_net(struct net *net);
a585abf
+extern void rpc_pipefs_exit_net(struct net *net);
a585abf
 extern struct super_block *rpc_get_sb_net(const struct net *net);
a585abf
 extern void rpc_put_sb_net(const struct net *net);
a585abf
 
a585abf
diff -up linux-3.11.9-200.fc19.x86_64/net/sunrpc/netns.h.orig linux-3.11.9-200.fc19.x86_64/net/sunrpc/netns.h
a585abf
--- linux-3.11.9-200.fc19.x86_64/net/sunrpc/netns.h.orig	2013-09-02 16:46:10.000000000 -0400
a585abf
+++ linux-3.11.9-200.fc19.x86_64/net/sunrpc/netns.h	2013-11-21 10:11:17.897029000 -0500
a585abf
@@ -14,6 +14,7 @@ struct sunrpc_net {
a585abf
 	struct cache_detail *rsi_cache;
a585abf
 
a585abf
 	struct super_block *pipefs_sb;
a585abf
+	struct rpc_pipe *gssd_dummy;
a585abf
 	struct mutex pipefs_sb_lock;
a585abf
 
a585abf
 	struct list_head all_clients;
a585abf
diff -up linux-3.11.9-200.fc19.x86_64/net/sunrpc/rpc_pipe.c.orig linux-3.11.9-200.fc19.x86_64/net/sunrpc/rpc_pipe.c
a585abf
--- linux-3.11.9-200.fc19.x86_64/net/sunrpc/rpc_pipe.c.orig	2013-09-02 16:46:10.000000000 -0400
a585abf
+++ linux-3.11.9-200.fc19.x86_64/net/sunrpc/rpc_pipe.c	2013-11-21 10:11:17.903026000 -0500
a585abf
@@ -38,7 +38,7 @@
a585abf
 #define NET_NAME(net)	((net == &init_net) ? " (init_net)" : "")
a585abf
 
a585abf
 static struct file_system_type rpc_pipe_fs_type;
a585abf
-
a585abf
+static const struct rpc_pipe_ops gssd_dummy_pipe_ops;
a585abf
 
a585abf
 static struct kmem_cache *rpc_inode_cachep __read_mostly;
a585abf
 
a585abf
@@ -1019,6 +1019,7 @@ enum {
a585abf
 	RPCAUTH_nfsd4_cb,
a585abf
 	RPCAUTH_cache,
a585abf
 	RPCAUTH_nfsd,
a585abf
+	RPCAUTH_gssd,
a585abf
 	RPCAUTH_RootEOF
a585abf
 };
a585abf
 
a585abf
@@ -1055,6 +1056,10 @@ static const struct rpc_filelist files[]
a585abf
 		.name = "nfsd",
a585abf
 		.mode = S_IFDIR | S_IRUGO | S_IXUGO,
a585abf
 	},
a585abf
+	[RPCAUTH_gssd] = {
a585abf
+		.name = "gssd",
a585abf
+		.mode = S_IFDIR | S_IRUGO | S_IXUGO,
a585abf
+	},
a585abf
 };
a585abf
 
a585abf
 /*
a585abf
@@ -1068,13 +1073,25 @@ struct dentry *rpc_d_lookup_sb(const str
a585abf
 }
a585abf
 EXPORT_SYMBOL_GPL(rpc_d_lookup_sb);
a585abf
 
a585abf
-void rpc_pipefs_init_net(struct net *net)
a585abf
+int rpc_pipefs_init_net(struct net *net)
a585abf
 {
a585abf
 	struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
a585abf
 
a585abf
+	sn->gssd_dummy = rpc_mkpipe_data(&gssd_dummy_pipe_ops, 0);
a585abf
+	if (IS_ERR(sn->gssd_dummy))
a585abf
+		return PTR_ERR(sn->gssd_dummy);
a585abf
+
a585abf
 	mutex_init(&sn->pipefs_sb_lock);
a585abf
 	sn->gssd_running = 1;
a585abf
 	sn->pipe_version = -1;
a585abf
+	return 0;
a585abf
+}
a585abf
+
a585abf
+void rpc_pipefs_exit_net(struct net *net)
a585abf
+{
a585abf
+	struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
a585abf
+
a585abf
+	rpc_destroy_pipe_data(sn->gssd_dummy);
a585abf
 }
a585abf
 
a585abf
 /*
a585abf
@@ -1104,11 +1121,73 @@ void rpc_put_sb_net(const struct net *ne
a585abf
 }
a585abf
 EXPORT_SYMBOL_GPL(rpc_put_sb_net);
a585abf
 
a585abf
+static const struct rpc_filelist gssd_dummy_clnt_dir[] = {
a585abf
+	[0] = {
a585abf
+		.name = "clntXX",
a585abf
+		.mode = S_IFDIR | S_IRUGO | S_IXUGO,
a585abf
+	},
a585abf
+};
a585abf
+
a585abf
+static ssize_t
a585abf
+dummy_downcall(struct file *filp, const char __user *src, size_t len)
a585abf
+{
a585abf
+	return -EINVAL;
a585abf
+}
a585abf
+
a585abf
+static const struct rpc_pipe_ops gssd_dummy_pipe_ops = {
a585abf
+	.upcall		= rpc_pipe_generic_upcall,
a585abf
+	.downcall	= dummy_downcall,
a585abf
+};
a585abf
+
a585abf
+/**
a585abf
+ * rpc_gssd_dummy_populate - create a dummy gssd pipe
a585abf
+ * @root:	root of the rpc_pipefs filesystem
a585abf
+ * @pipe_data:	pipe data created when netns is initialized
a585abf
+ *
a585abf
+ * Create a dummy set of directories and a pipe that gssd can hold open to
a585abf
+ * indicate that it is up and running.
a585abf
+ */
a585abf
+static struct dentry *
a585abf
+rpc_gssd_dummy_populate(struct dentry *root, struct rpc_pipe *pipe_data)
a585abf
+{
a585abf
+	int ret = 0;
a585abf
+	struct dentry *gssd_dentry;
a585abf
+	struct dentry *clnt_dentry = NULL;
a585abf
+	struct dentry *pipe_dentry = NULL;
a585abf
+	struct qstr q = QSTR_INIT(files[RPCAUTH_gssd].name,
a585abf
+				  strlen(files[RPCAUTH_gssd].name));
a585abf
+
a585abf
+	/* We should never get this far if "gssd" doesn't exist */
a585abf
+	gssd_dentry = d_hash_and_lookup(root, &q);
a585abf
+	if (!gssd_dentry)
a585abf
+		return ERR_PTR(-ENOENT);
a585abf
+
a585abf
+	ret = rpc_populate(gssd_dentry, gssd_dummy_clnt_dir, 0, 1, NULL);
a585abf
+	if (ret) {
a585abf
+		pipe_dentry = ERR_PTR(ret);
a585abf
+		goto out;
a585abf
+	}
a585abf
+
a585abf
+	q.name = gssd_dummy_clnt_dir[0].name;
a585abf
+	q.len = strlen(gssd_dummy_clnt_dir[0].name);
a585abf
+	clnt_dentry = d_hash_and_lookup(gssd_dentry, &q);
a585abf
+	if (!clnt_dentry) {
a585abf
+		pipe_dentry = ERR_PTR(-ENOENT);
a585abf
+		goto out;
a585abf
+	}
a585abf
+
a585abf
+	pipe_dentry = rpc_mkpipe_dentry(clnt_dentry, "gssd", NULL, pipe_data);
a585abf
+out:
a585abf
+	dput(clnt_dentry);
a585abf
+	dput(gssd_dentry);
a585abf
+	return pipe_dentry;
a585abf
+}
a585abf
+
a585abf
 static int
a585abf
 rpc_fill_super(struct super_block *sb, void *data, int silent)
a585abf
 {
a585abf
 	struct inode *inode;
a585abf
-	struct dentry *root;
a585abf
+	struct dentry *root, *gssd_dentry;
a585abf
 	struct net *net = data;
a585abf
 	struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
a585abf
 	int err;
a585abf
@@ -1126,6 +1205,13 @@ rpc_fill_super(struct super_block *sb, v
a585abf
 		return -ENOMEM;
a585abf
 	if (rpc_populate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF, NULL))
a585abf
 		return -ENOMEM;
a585abf
+
a585abf
+	gssd_dentry = rpc_gssd_dummy_populate(root, sn->gssd_dummy);
a585abf
+	if (IS_ERR(gssd_dentry)) {
a585abf
+		__rpc_depopulate(root, files, RPCAUTH_lockd, RPCAUTH_RootEOF);
a585abf
+		return PTR_ERR(gssd_dentry);
a585abf
+	}
a585abf
+
a585abf
 	dprintk("RPC:       sending pipefs MOUNT notification for net %p%s\n",
a585abf
 		net, NET_NAME(net));
a585abf
 	mutex_lock(&sn->pipefs_sb_lock);
a585abf
@@ -1140,6 +1226,7 @@ rpc_fill_super(struct super_block *sb, v
a585abf
 	return 0;
a585abf
 
a585abf
 err_depopulate:
a585abf
+	dput(gssd_dentry);
a585abf
 	blocking_notifier_call_chain(&rpc_pipefs_notifier_list,
a585abf
 					   RPC_PIPEFS_UMOUNT,
a585abf
 					   sb);
a585abf
diff -up linux-3.11.9-200.fc19.x86_64/net/sunrpc/sunrpc_syms.c.orig linux-3.11.9-200.fc19.x86_64/net/sunrpc/sunrpc_syms.c
a585abf
--- linux-3.11.9-200.fc19.x86_64/net/sunrpc/sunrpc_syms.c.orig	2013-09-02 16:46:10.000000000 -0400
a585abf
+++ linux-3.11.9-200.fc19.x86_64/net/sunrpc/sunrpc_syms.c	2013-11-21 10:11:17.908026000 -0500
a585abf
@@ -44,12 +44,17 @@ static __net_init int sunrpc_init_net(st
a585abf
 	if (err)
a585abf
 		goto err_unixgid;
a585abf
 
a585abf
-	rpc_pipefs_init_net(net);
a585abf
+	err = rpc_pipefs_init_net(net);
a585abf
+	if (err)
a585abf
+		goto err_pipefs;
a585abf
+
a585abf
 	INIT_LIST_HEAD(&sn->all_clients);
a585abf
 	spin_lock_init(&sn->rpc_client_lock);
a585abf
 	spin_lock_init(&sn->rpcb_clnt_lock);
a585abf
 	return 0;
a585abf
 
a585abf
+err_pipefs:
a585abf
+	unix_gid_cache_destroy(net);
a585abf
 err_unixgid:
a585abf
 	ip_map_cache_destroy(net);
a585abf
 err_ipmap:
a585abf
@@ -60,6 +65,7 @@ err_proc:
a585abf
 
a585abf
 static __net_exit void sunrpc_exit_net(struct net *net)
a585abf
 {
a585abf
+	rpc_pipefs_exit_net(net);
a585abf
 	unix_gid_cache_destroy(net);
a585abf
 	ip_map_cache_destroy(net);
a585abf
 	rpc_proc_exit(net);
a585abf