提交 278c995c 编写于 作者: C Christoph Hellwig 提交者: Trond Myklebust

[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: NChristoph Hellwig <hch@lst.de>
Signed-off-by: NTrond Myklebust <Trond.Myklebust@netapp.com>
上级 470056c2
...@@ -66,7 +66,6 @@ struct idmap_hashtable { ...@@ -66,7 +66,6 @@ struct idmap_hashtable {
}; };
struct idmap { struct idmap {
char idmap_path[48];
struct dentry *idmap_dentry; struct dentry *idmap_dentry;
wait_queue_head_t idmap_wq; wait_queue_head_t idmap_wq;
struct idmap_msg idmap_im; struct idmap_msg idmap_im;
...@@ -102,11 +101,8 @@ nfs_idmap_new(struct nfs4_client *clp) ...@@ -102,11 +101,8 @@ nfs_idmap_new(struct nfs4_client *clp)
memset(idmap, 0, sizeof(*idmap)); memset(idmap, 0, sizeof(*idmap));
snprintf(idmap->idmap_path, sizeof(idmap->idmap_path), idmap->idmap_dentry = rpc_mkpipe(clp->cl_rpcclient->cl_dentry,
"%s/idmap", clp->cl_rpcclient->cl_pathname); "idmap", idmap, &idmap_upcall_ops, 0);
idmap->idmap_dentry = rpc_mkpipe(idmap->idmap_path,
idmap, &idmap_upcall_ops, 0);
if (IS_ERR(idmap->idmap_dentry)) { if (IS_ERR(idmap->idmap_dentry)) {
kfree(idmap); kfree(idmap);
return; return;
...@@ -128,7 +124,7 @@ nfs_idmap_delete(struct nfs4_client *clp) ...@@ -128,7 +124,7 @@ nfs_idmap_delete(struct nfs4_client *clp)
if (!idmap) if (!idmap)
return; return;
rpc_unlink(idmap->idmap_path); rpc_unlink(idmap->idmap_dentry);
clp->cl_idmap = NULL; clp->cl_idmap = NULL;
kfree(idmap); kfree(idmap);
} }
......
...@@ -59,7 +59,7 @@ struct rpc_clnt { ...@@ -59,7 +59,7 @@ struct rpc_clnt {
int cl_nodelen; /* nodename length */ int cl_nodelen; /* nodename length */
char cl_nodename[UNX_MAXNODENAME]; 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 dentry * cl_dentry; /* inode */
struct rpc_clnt * cl_parent; /* Points to parent of clones */ struct rpc_clnt * cl_parent; /* Points to parent of clones */
struct rpc_rtt cl_rtt_default; struct rpc_rtt cl_rtt_default;
......
...@@ -41,10 +41,11 @@ RPC_I(struct inode *inode) ...@@ -41,10 +41,11 @@ RPC_I(struct inode *inode)
extern int rpc_queue_upcall(struct inode *, struct rpc_pipe_msg *); extern int rpc_queue_upcall(struct inode *, struct rpc_pipe_msg *);
extern struct dentry *rpc_mkdir(char *, struct rpc_clnt *); extern struct dentry *rpc_mkdir(struct dentry *, char *, struct rpc_clnt *);
extern int rpc_rmdir(char *); extern void rpc_rmdir(struct dentry *);
extern struct dentry *rpc_mkpipe(char *, void *, struct rpc_pipe_ops *, int flags); extern struct dentry *rpc_mkpipe(struct dentry *, char *, void *,
extern int rpc_unlink(char *); struct rpc_pipe_ops *, int flags);
extern void rpc_unlink(struct dentry *);
#endif #endif
#endif #endif
...@@ -87,7 +87,6 @@ struct gss_auth { ...@@ -87,7 +87,6 @@ struct gss_auth {
struct list_head upcalls; struct list_head upcalls;
struct rpc_clnt *client; struct rpc_clnt *client;
struct dentry *dentry; struct dentry *dentry;
char path[48];
spinlock_t lock; spinlock_t lock;
}; };
...@@ -690,10 +689,8 @@ gss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor) ...@@ -690,10 +689,8 @@ gss_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
if (err) if (err)
goto err_put_mech; goto err_put_mech;
snprintf(gss_auth->path, sizeof(gss_auth->path), "%s/%s", gss_auth->dentry = rpc_mkpipe(clnt->cl_dentry, gss_auth->mech->gm_name,
clnt->cl_pathname, clnt, &gss_upcall_ops, RPC_PIPE_WAIT_FOR_OPEN);
gss_auth->mech->gm_name);
gss_auth->dentry = rpc_mkpipe(gss_auth->path, clnt, &gss_upcall_ops, RPC_PIPE_WAIT_FOR_OPEN);
if (IS_ERR(gss_auth->dentry)) { if (IS_ERR(gss_auth->dentry)) {
err = PTR_ERR(gss_auth->dentry); err = PTR_ERR(gss_auth->dentry);
goto err_put_mech; goto err_put_mech;
...@@ -718,7 +715,7 @@ gss_destroy(struct rpc_auth *auth) ...@@ -718,7 +715,7 @@ gss_destroy(struct rpc_auth *auth)
auth, auth->au_flavor); auth, auth->au_flavor);
gss_auth = container_of(auth, struct gss_auth, rpc_auth); 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); gss_mech_put(gss_auth->mech);
rpcauth_free_credcache(auth); rpcauth_free_credcache(auth);
......
...@@ -67,26 +67,42 @@ static u32 * call_verify(struct rpc_task *task); ...@@ -67,26 +67,42 @@ static u32 * call_verify(struct rpc_task *task);
static int static int
rpc_setup_pipedir(struct rpc_clnt *clnt, char *dir_name) rpc_setup_pipedir(struct rpc_clnt *clnt, char *dir_name)
{ {
static uint32_t clntid; static unsigned int clntid;
char name[128];
int error; int error;
if (dir_name == NULL) if (dir_name == NULL)
return 0; return 0;
for (;;) {
snprintf(clnt->cl_pathname, sizeof(clnt->cl_pathname), retry_parent:
"%s/clnt%x", dir_name, clnt->__cl_parent_dentry = rpc_mkdir(NULL, dir_name, NULL);
(unsigned int)clntid++); if (IS_ERR(clnt->__cl_parent_dentry)) {
clnt->cl_pathname[sizeof(clnt->cl_pathname) - 1] = '\0'; error = PTR_ERR(clnt->__cl_parent_dentry);
clnt->cl_dentry = rpc_mkdir(clnt->cl_pathname, clnt); if (error == -EEXIST)
if (!IS_ERR(clnt->cl_dentry)) goto retry_parent; /* XXX(hch): WTF? */
return 0;
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); error = PTR_ERR(clnt->cl_dentry);
if (error != -EEXIST) { if (error == -EEXIST)
printk(KERN_INFO "RPC: Couldn't create pipefs entry %s, error %d\n", goto retry_child;
clnt->cl_pathname, error); printk(KERN_INFO "RPC: Couldn't create pipefs entry %s, error %d\n",
return error; name, error);
} rpc_rmdir(clnt->__cl_parent_dentry);
return error;
} }
return 0;
} }
/* /*
...@@ -174,7 +190,8 @@ rpc_new_client(struct rpc_xprt *xprt, char *servname, ...@@ -174,7 +190,8 @@ rpc_new_client(struct rpc_xprt *xprt, char *servname,
return clnt; return clnt;
out_no_auth: out_no_auth:
rpc_rmdir(clnt->cl_pathname); rpc_rmdir(clnt->cl_dentry);
rpc_rmdir(clnt->__cl_parent_dentry);
out_no_path: out_no_path:
if (clnt->cl_server != clnt->cl_inline_name) if (clnt->cl_server != clnt->cl_inline_name)
kfree(clnt->cl_server); kfree(clnt->cl_server);
...@@ -302,8 +319,10 @@ rpc_destroy_client(struct rpc_clnt *clnt) ...@@ -302,8 +319,10 @@ rpc_destroy_client(struct rpc_clnt *clnt)
rpc_destroy_client(clnt->cl_parent); rpc_destroy_client(clnt->cl_parent);
goto out_free; goto out_free;
} }
if (clnt->cl_pathname[0]) if (clnt->cl_dentry)
rpc_rmdir(clnt->cl_pathname); rpc_rmdir(clnt->cl_dentry);
if (clnt->__cl_parent_dentry)
rpc_rmdir(clnt->__cl_parent_dentry);
if (clnt->cl_xprt) { if (clnt->cl_xprt) {
xprt_destroy(clnt->cl_xprt); xprt_destroy(clnt->cl_xprt);
clnt->cl_xprt = NULL; clnt->cl_xprt = NULL;
......
...@@ -414,38 +414,6 @@ rpc_put_mount(void) ...@@ -414,38 +414,6 @@ rpc_put_mount(void)
simple_release_fs(&rpc_mount, &rpc_mount_count); simple_release_fs(&rpc_mount, &rpc_mount_count);
} }
static int
rpc_lookup_parent(char *path, struct nameidata *nd)
{
if (path[0] == '\0')
return -ENOENT;
if (rpc_get_mount()) {
printk(KERN_WARNING "%s: %s failed to mount "
"pseudofilesystem \n", __FILE__, __FUNCTION__);
return -ENODEV;
}
nd->mnt = mntget(rpc_mount);
nd->dentry = dget(rpc_mount->mnt_root);
nd->last_type = LAST_ROOT;
nd->flags = LOOKUP_PARENT;
nd->depth = 0;
if (path_walk(path, nd)) {
printk(KERN_WARNING "%s: %s failed to find path %s\n",
__FILE__, __FUNCTION__, path);
rpc_put_mount();
return -ENOENT;
}
return 0;
}
static void
rpc_release_path(struct nameidata *nd)
{
path_release(nd);
rpc_put_mount();
}
static struct inode * static struct inode *
rpc_get_inode(struct super_block *sb, int mode) rpc_get_inode(struct super_block *sb, int mode)
{ {
...@@ -550,197 +518,149 @@ rpc_populate(struct dentry *parent, ...@@ -550,197 +518,149 @@ rpc_populate(struct dentry *parent,
return -ENOMEM; return -ENOMEM;
} }
static int struct dentry *
__rpc_mkdir(struct inode *dir, struct dentry *dentry) rpc_mkdir(struct dentry *parent, char *name, struct rpc_clnt *rpc_client)
{ {
struct inode *dir;
struct dentry *dentry;
struct inode *inode; struct inode *inode;
inode = rpc_get_inode(dir->i_sb, S_IFDIR | S_IRUSR | S_IXUSR);
if (!inode)
goto out_err;
inode->i_ino = iunique(dir->i_sb, 100);
d_instantiate(dentry, inode);
dir->i_nlink++;
inode_dir_notify(dir, DN_CREATE);
rpc_get_mount();
return 0;
out_err:
printk(KERN_WARNING "%s: %s failed to allocate inode for dentry %s\n",
__FILE__, __FUNCTION__, dentry->d_name.name);
return -ENOMEM;
}
static int
__rpc_rmdir(struct inode *dir, struct dentry *dentry)
{
int error; int error;
shrink_dcache_parent(dentry); if (!parent)
if (dentry->d_inode) { parent = rpc_mount->mnt_root;
rpc_close_pipes(dentry->d_inode);
rpc_inode_setowner(dentry->d_inode, NULL);
}
if ((error = simple_rmdir(dir, dentry)) != 0)
return error;
if (!error) {
inode_dir_notify(dir, DN_DELETE);
d_drop(dentry);
rpc_put_mount();
}
return 0;
}
static struct dentry * dir = parent->d_inode;
rpc_lookup_negative(char *path, struct nameidata *nd)
{ error = rpc_get_mount();
struct dentry *dentry; if (error)
struct inode *dir;
int error;
if ((error = rpc_lookup_parent(path, nd)) != 0)
return ERR_PTR(error); return ERR_PTR(error);
dir = nd->dentry->d_inode;
down(&dir->i_sem); down(&dir->i_sem);
dentry = lookup_hash(&nd->last, nd->dentry); dentry = lookup_one_len(name, parent, strlen(name));
if (IS_ERR(dentry)) if (IS_ERR(dentry))
goto out_err; goto out_unlock;
if (dentry->d_inode) { if (dentry->d_inode) {
dput(dentry);
dentry = ERR_PTR(-EEXIST); dentry = ERR_PTR(-EEXIST);
goto out_err; goto out_dput;
} }
return dentry;
out_err:
up(&dir->i_sem);
rpc_release_path(nd);
return dentry;
}
inode = rpc_get_inode(dir->i_sb, S_IFDIR | S_IRUSR | S_IXUSR);
if (!inode)
goto out_dput;
inode->i_ino = iunique(dir->i_sb, 100);
dir->i_nlink++;
RPC_I(dentry->d_inode)->private = rpc_client;
struct dentry * d_instantiate(dentry, inode);
rpc_mkdir(char *path, struct rpc_clnt *rpc_client) dget(dentry);
{ up(&dir->i_sem);
struct nameidata nd;
struct dentry *dentry; inode_dir_notify(dir, DN_CREATE);
struct inode *dir;
int error;
dentry = rpc_lookup_negative(path, &nd);
if (IS_ERR(dentry))
return dentry;
dir = nd.dentry->d_inode;
if ((error = __rpc_mkdir(dir, dentry)) != 0)
goto err_dput;
RPC_I(dentry->d_inode)->private = rpc_client;
error = rpc_populate(dentry, authfiles, error = rpc_populate(dentry, authfiles,
RPCAUTH_info, RPCAUTH_EOF); RPCAUTH_info, RPCAUTH_EOF);
if (error) if (error)
goto err_depopulate; goto out_depopulate;
out:
up(&dir->i_sem);
rpc_release_path(&nd);
return dentry; return dentry;
err_depopulate:
rpc_depopulate(dentry); out_depopulate:
__rpc_rmdir(dir, dentry); rpc_rmdir(dentry);
err_dput: out_dput:
dput(dentry); dput(dentry);
printk(KERN_WARNING "%s: %s() failed to create directory %s (errno = %d)\n", out_unlock:
__FILE__, __FUNCTION__, path, error); up(&dir->i_sem);
dentry = ERR_PTR(error); rpc_put_mount();
goto out; return dentry;
} }
int void
rpc_rmdir(char *path) rpc_rmdir(struct dentry *dentry)
{ {
struct nameidata nd; struct dentry *parent = dentry->d_parent;
struct dentry *dentry;
struct inode *dir;
int error;
if ((error = rpc_lookup_parent(path, &nd)) != 0)
return error;
dir = nd.dentry->d_inode;
down(&dir->i_sem);
dentry = lookup_hash(&nd.last, nd.dentry);
if (IS_ERR(dentry)) {
error = PTR_ERR(dentry);
goto out_release;
}
rpc_depopulate(dentry); rpc_depopulate(dentry);
error = __rpc_rmdir(dir, dentry);
dput(dentry); down(&parent->d_inode->i_sem);
out_release: if (dentry->d_inode) {
up(&dir->i_sem); rpc_close_pipes(dentry->d_inode);
rpc_release_path(&nd); rpc_inode_setowner(dentry->d_inode, NULL);
return error; simple_rmdir(parent->d_inode, dentry);
}
up(&parent->d_inode->i_sem);
inode_dir_notify(parent->d_inode, DN_DELETE);
rpc_put_mount();
} }
struct dentry * struct dentry *
rpc_mkpipe(char *path, void *private, struct rpc_pipe_ops *ops, int flags) rpc_mkpipe(struct dentry *parent, char *name, void *private,
struct rpc_pipe_ops *ops, int flags)
{ {
struct nameidata nd; struct inode *dir = parent->d_inode;
struct dentry *dentry; struct dentry *dentry;
struct inode *dir, *inode; struct inode *inode;
struct rpc_inode *rpci; struct rpc_inode *rpci;
int error;
error = rpc_get_mount();
if (error)
return ERR_PTR(error);
dentry = rpc_lookup_negative(path, &nd); down(&parent->d_inode->i_sem);
dentry = lookup_one_len(name, parent, strlen(name));
if (IS_ERR(dentry)) if (IS_ERR(dentry))
return dentry; goto out_unlock;
dir = nd.dentry->d_inode; if (dentry->d_inode) {
inode = rpc_get_inode(dir->i_sb, S_IFSOCK | S_IRUSR | S_IWUSR); dentry = ERR_PTR(-EEXIST);
if (!inode) goto out_dput;
goto err_dput; }
inode = rpc_get_inode(parent->d_inode->i_sb,
S_IFSOCK | S_IRUSR | S_IWUSR);
if (!inode) {
dentry = ERR_PTR(-ENOMEM);
goto out_dput;
}
inode->i_ino = iunique(dir->i_sb, 100); inode->i_ino = iunique(dir->i_sb, 100);
inode->i_fop = &rpc_pipe_fops; inode->i_fop = &rpc_pipe_fops;
d_instantiate(dentry, inode);
rpci = RPC_I(inode); rpci = RPC_I(inode);
rpci->private = private; rpci->private = private;
rpci->flags = flags; rpci->flags = flags;
rpci->ops = ops; rpci->ops = ops;
d_instantiate(dentry, inode);
dget(dentry);
up(&parent->d_inode->i_sem);
inode_dir_notify(dir, DN_CREATE); inode_dir_notify(dir, DN_CREATE);
out:
up(&dir->i_sem);
rpc_release_path(&nd);
return dentry; return dentry;
err_dput:
out_dput:
dput(dentry); dput(dentry);
dentry = ERR_PTR(-ENOMEM); out_unlock:
printk(KERN_WARNING "%s: %s() failed to create pipe %s (errno = %d)\n", up(&parent->d_inode->i_sem);
__FILE__, __FUNCTION__, path, -ENOMEM); rpc_put_mount();
goto out; return dentry;
} }
int void
rpc_unlink(char *path) rpc_unlink(struct dentry *dentry)
{ {
struct nameidata nd; struct dentry *parent = dentry->d_parent;
struct dentry *dentry;
struct inode *dir;
int error;
if ((error = rpc_lookup_parent(path, &nd)) != 0) down(&parent->d_inode->i_sem);
return error;
dir = nd.dentry->d_inode;
down(&dir->i_sem);
dentry = lookup_hash(&nd.last, nd.dentry);
if (IS_ERR(dentry)) {
error = PTR_ERR(dentry);
goto out_release;
}
d_drop(dentry);
if (dentry->d_inode) { if (dentry->d_inode) {
rpc_close_pipes(dentry->d_inode); rpc_close_pipes(dentry->d_inode);
rpc_inode_setowner(dentry->d_inode, NULL); rpc_inode_setowner(dentry->d_inode, NULL);
error = simple_unlink(dir, dentry); simple_unlink(parent->d_inode, dentry);
} }
dput(dentry); up(&parent->d_inode->i_sem);
inode_dir_notify(dir, DN_DELETE);
out_release: inode_dir_notify(parent->d_inode, DN_DELETE);
up(&dir->i_sem); rpc_put_mount();
rpc_release_path(&nd);
return error;
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册