[PATCH] RPC,NFS: new rpc_pipefs patch
Currently rpc_mkdir/rpc_rmdir and rpc_mkpipe/mk_unlink have an API that's
a little unfortunate. They take a path relative to the rpc_pipefs root and
thus need to perform a full lookup. If you look at debugfs or usbfs they
always store the dentry for directories they created and thus can pass in
a dentry + single pathname component pair into their equivalents of the
above functions.
And in fact rpc_pipefs actually stores a dentry for all but one component so
this change not only simplifies the core rpc_pipe code but also the callers.
Unfortuntately this code path is only used by the NFS4 idmapper and
AUTH_GSSAPI for which I don't have a test enviroment. Could someone give
it a spin? It's the last bit needed before we can rework the
lookup_hash API
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 5a8f01d..63bf591 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -67,26 +67,42 @@
static int
rpc_setup_pipedir(struct rpc_clnt *clnt, char *dir_name)
{
- static uint32_t clntid;
+ static unsigned int clntid;
+ char name[128];
int error;
if (dir_name == NULL)
return 0;
- for (;;) {
- snprintf(clnt->cl_pathname, sizeof(clnt->cl_pathname),
- "%s/clnt%x", dir_name,
- (unsigned int)clntid++);
- clnt->cl_pathname[sizeof(clnt->cl_pathname) - 1] = '\0';
- clnt->cl_dentry = rpc_mkdir(clnt->cl_pathname, clnt);
- if (!IS_ERR(clnt->cl_dentry))
- return 0;
- error = PTR_ERR(clnt->cl_dentry);
- if (error != -EEXIST) {
- printk(KERN_INFO "RPC: Couldn't create pipefs entry %s, error %d\n",
- clnt->cl_pathname, error);
- return error;
- }
+
+ retry_parent:
+ clnt->__cl_parent_dentry = rpc_mkdir(NULL, dir_name, NULL);
+ if (IS_ERR(clnt->__cl_parent_dentry)) {
+ error = PTR_ERR(clnt->__cl_parent_dentry);
+ if (error == -EEXIST)
+ goto retry_parent; /* XXX(hch): WTF? */
+
+ printk(KERN_INFO "RPC: Couldn't create pipefs entry %s, error %d\n",
+ dir_name, error);
+ return error;
}
+
+
+ retry_child:
+ snprintf(name, sizeof(name), "clnt%x", clntid++);
+ name[sizeof(name) - 1] = '\0';
+
+ clnt->cl_dentry = rpc_mkdir(clnt->__cl_parent_dentry, name, clnt);
+ if (IS_ERR(clnt->cl_dentry)) {
+ error = PTR_ERR(clnt->cl_dentry);
+ if (error == -EEXIST)
+ goto retry_child;
+ printk(KERN_INFO "RPC: Couldn't create pipefs entry %s, error %d\n",
+ name, error);
+ rpc_rmdir(clnt->__cl_parent_dentry);
+ return error;
+ }
+
+ return 0;
}
/*
@@ -174,7 +190,8 @@
return clnt;
out_no_auth:
- rpc_rmdir(clnt->cl_pathname);
+ rpc_rmdir(clnt->cl_dentry);
+ rpc_rmdir(clnt->__cl_parent_dentry);
out_no_path:
if (clnt->cl_server != clnt->cl_inline_name)
kfree(clnt->cl_server);
@@ -302,8 +319,10 @@
rpc_destroy_client(clnt->cl_parent);
goto out_free;
}
- if (clnt->cl_pathname[0])
- rpc_rmdir(clnt->cl_pathname);
+ if (clnt->cl_dentry)
+ rpc_rmdir(clnt->cl_dentry);
+ if (clnt->__cl_parent_dentry)
+ rpc_rmdir(clnt->__cl_parent_dentry);
if (clnt->cl_xprt) {
xprt_destroy(clnt->cl_xprt);
clnt->cl_xprt = NULL;