Skip to content

Commit

Permalink
[PATCH] RPC,NFS: new rpc_pipefs patch
Browse files Browse the repository at this point in the history
 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>
  • Loading branch information
Christoph Hellwig authored and Trond Myklebust committed Sep 23, 2005
1 parent 470056c commit 278c995
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 209 deletions.
10 changes: 3 additions & 7 deletions fs/nfs/idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ struct idmap_hashtable {
};

struct idmap {
char idmap_path[48];
struct dentry *idmap_dentry;
wait_queue_head_t idmap_wq;
struct idmap_msg idmap_im;
Expand Down Expand Up @@ -102,11 +101,8 @@ nfs_idmap_new(struct nfs4_client *clp)

memset(idmap, 0, sizeof(*idmap));

snprintf(idmap->idmap_path, sizeof(idmap->idmap_path),
"%s/idmap", clp->cl_rpcclient->cl_pathname);

idmap->idmap_dentry = rpc_mkpipe(idmap->idmap_path,
idmap, &idmap_upcall_ops, 0);
idmap->idmap_dentry = rpc_mkpipe(clp->cl_rpcclient->cl_dentry,
"idmap", idmap, &idmap_upcall_ops, 0);
if (IS_ERR(idmap->idmap_dentry)) {
kfree(idmap);
return;
Expand All @@ -128,7 +124,7 @@ nfs_idmap_delete(struct nfs4_client *clp)

if (!idmap)
return;
rpc_unlink(idmap->idmap_path);
rpc_unlink(idmap->idmap_dentry);
clp->cl_idmap = NULL;
kfree(idmap);
}
Expand Down
2 changes: 1 addition & 1 deletion include/linux/sunrpc/clnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct rpc_clnt {

int cl_nodelen; /* nodename length */
char cl_nodename[UNX_MAXNODENAME];
char cl_pathname[30];/* Path in rpc_pipe_fs */
struct dentry * __cl_parent_dentry;
struct dentry * cl_dentry; /* inode */
struct rpc_clnt * cl_parent; /* Points to parent of clones */
struct rpc_rtt cl_rtt_default;
Expand Down
9 changes: 5 additions & 4 deletions include/linux/sunrpc/rpc_pipe_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ RPC_I(struct inode *inode)

extern int rpc_queue_upcall(struct inode *, struct rpc_pipe_msg *);

extern struct dentry *rpc_mkdir(char *, struct rpc_clnt *);
extern int rpc_rmdir(char *);
extern struct dentry *rpc_mkpipe(char *, void *, struct rpc_pipe_ops *, int flags);
extern int rpc_unlink(char *);
extern struct dentry *rpc_mkdir(struct dentry *, char *, struct rpc_clnt *);
extern void rpc_rmdir(struct dentry *);
extern struct dentry *rpc_mkpipe(struct dentry *, char *, void *,
struct rpc_pipe_ops *, int flags);
extern void rpc_unlink(struct dentry *);

#endif
#endif
9 changes: 3 additions & 6 deletions net/sunrpc/auth_gss/auth_gss.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ struct gss_auth {
struct list_head upcalls;
struct rpc_clnt *client;
struct dentry *dentry;
char path[48];
spinlock_t lock;
};

Expand Down Expand Up @@ -690,10 +689,8 @@ gss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
if (err)
goto err_put_mech;

snprintf(gss_auth->path, sizeof(gss_auth->path), "%s/%s",
clnt->cl_pathname,
gss_auth->mech->gm_name);
gss_auth->dentry = rpc_mkpipe(gss_auth->path, clnt, &gss_upcall_ops, RPC_PIPE_WAIT_FOR_OPEN);
gss_auth->dentry = rpc_mkpipe(clnt->cl_dentry, gss_auth->mech->gm_name,
clnt, &gss_upcall_ops, RPC_PIPE_WAIT_FOR_OPEN);
if (IS_ERR(gss_auth->dentry)) {
err = PTR_ERR(gss_auth->dentry);
goto err_put_mech;
Expand All @@ -718,7 +715,7 @@ gss_destroy(struct rpc_auth *auth)
auth, auth->au_flavor);

gss_auth = container_of(auth, struct gss_auth, rpc_auth);
rpc_unlink(gss_auth->path);
rpc_unlink(gss_auth->dentry);
gss_mech_put(gss_auth->mech);

rpcauth_free_credcache(auth);
Expand Down
53 changes: 36 additions & 17 deletions net/sunrpc/clnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,42 @@ static u32 * call_verify(struct rpc_task *task);
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;

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) {
printk(KERN_INFO "RPC: Couldn't create pipefs entry %s, error %d\n",
clnt->cl_pathname, error);
return error;
}
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;
}

/*
Expand Down Expand Up @@ -174,7 +190,8 @@ rpc_new_client(struct rpc_xprt *xprt, char *servname,
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);
Expand Down Expand Up @@ -302,8 +319,10 @@ rpc_destroy_client(struct rpc_clnt *clnt)
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;
Expand Down
Loading

0 comments on commit 278c995

Please sign in to comment.