summaryrefslogtreecommitdiff
path: root/net/sunrpc/rpc_pipe.c
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2005-09-23 11:08:25 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2005-09-23 12:39:00 -0400
commitf134585a7343d71f9be7f0cf97e2145f21dd10c6 (patch)
treef1eae77a5063e3748cd8deba9a13794ae0a9439c /net/sunrpc/rpc_pipe.c
parent3063d8a16643190f9e12e9c7e9f1ca56f7e7934e (diff)
Revert "[PATCH] RPC,NFS: new rpc_pipefs patch"
This reverts 17f4e6febca160a9f9dd4bdece9784577a2f4524 commit.
Diffstat (limited to 'net/sunrpc/rpc_pipe.c')
-rw-r--r--net/sunrpc/rpc_pipe.c268
1 files changed, 174 insertions, 94 deletions
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
index b382809726d..ded6c63f11e 100644
--- a/net/sunrpc/rpc_pipe.c
+++ b/net/sunrpc/rpc_pipe.c
@@ -414,6 +414,38 @@ rpc_put_mount(void)
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 *
rpc_get_inode(struct super_block *sb, int mode)
{
@@ -518,149 +550,197 @@ out_bad:
return -ENOMEM;
}
-struct dentry *
-rpc_mkdir(struct dentry *parent, char *name, struct rpc_clnt *rpc_client)
+static int
+__rpc_mkdir(struct inode *dir, struct dentry *dentry)
{
- struct inode *dir;
- struct dentry *dentry;
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;
- if (!parent)
- parent = rpc_mount->mnt_root;
+ shrink_dcache_parent(dentry);
+ if (dentry->d_inode) {
+ 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;
+}
- dir = parent->d_inode;
-
- error = rpc_get_mount();
- if (error)
- return ERR_PTR(error);
+static struct dentry *
+rpc_lookup_negative(char *path, struct nameidata *nd)
+{
+ struct dentry *dentry;
+ struct inode *dir;
+ int error;
+ if ((error = rpc_lookup_parent(path, nd)) != 0)
+ return ERR_PTR(error);
+ dir = nd->dentry->d_inode;
down(&dir->i_sem);
- dentry = lookup_one_len(name, parent, strlen(name));
+ dentry = lookup_hash(&nd->last, nd->dentry);
if (IS_ERR(dentry))
- goto out_unlock;
+ goto out_err;
if (dentry->d_inode) {
+ dput(dentry);
dentry = ERR_PTR(-EEXIST);
- goto out_dput;
+ goto out_err;
}
-
- 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;
-
- d_instantiate(dentry, inode);
- dget(dentry);
+ return dentry;
+out_err:
up(&dir->i_sem);
+ rpc_release_path(nd);
+ return dentry;
+}
- inode_dir_notify(dir, DN_CREATE);
+struct dentry *
+rpc_mkdir(char *path, struct rpc_clnt *rpc_client)
+{
+ struct nameidata nd;
+ struct dentry *dentry;
+ 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,
RPCAUTH_info, RPCAUTH_EOF);
if (error)
- goto out_depopulate;
-
- return dentry;
-
- out_depopulate:
- rpc_rmdir(dentry);
- out_dput:
- dput(dentry);
- out_unlock:
+ goto err_depopulate;
+out:
up(&dir->i_sem);
- rpc_put_mount();
+ rpc_release_path(&nd);
return dentry;
+err_depopulate:
+ rpc_depopulate(dentry);
+ __rpc_rmdir(dir, dentry);
+err_dput:
+ dput(dentry);
+ printk(KERN_WARNING "%s: %s() failed to create directory %s (errno = %d)\n",
+ __FILE__, __FUNCTION__, path, error);
+ dentry = ERR_PTR(error);
+ goto out;
}
-void
-rpc_rmdir(struct dentry *dentry)
+int
+rpc_rmdir(char *path)
{
- struct dentry *parent = dentry->d_parent;
-
- rpc_depopulate(dentry);
+ struct nameidata nd;
+ struct dentry *dentry;
+ struct inode *dir;
+ int error;
- down(&parent->d_inode->i_sem);
- if (dentry->d_inode) {
- rpc_close_pipes(dentry->d_inode);
- rpc_inode_setowner(dentry->d_inode, NULL);
- simple_rmdir(parent->d_inode, dentry);
+ 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;
}
- up(&parent->d_inode->i_sem);
-
- inode_dir_notify(parent->d_inode, DN_DELETE);
- rpc_put_mount();
+ rpc_depopulate(dentry);
+ error = __rpc_rmdir(dir, dentry);
+ dput(dentry);
+out_release:
+ up(&dir->i_sem);
+ rpc_release_path(&nd);
+ return error;
}
struct dentry *
-rpc_mkpipe(struct dentry *parent, char *name, void *private,
- struct rpc_pipe_ops *ops, int flags)
+rpc_mkpipe(char *path, void *private, struct rpc_pipe_ops *ops, int flags)
{
- struct inode *dir = parent->d_inode;
+ struct nameidata nd;
struct dentry *dentry;
- struct inode *inode;
+ struct inode *dir, *inode;
struct rpc_inode *rpci;
- int error;
-
- error = rpc_get_mount();
- if (error)
- return ERR_PTR(error);
- down(&parent->d_inode->i_sem);
- dentry = lookup_one_len(name, parent, strlen(name));
+ dentry = rpc_lookup_negative(path, &nd);
if (IS_ERR(dentry))
- goto out_unlock;
- if (dentry->d_inode) {
- dentry = ERR_PTR(-EEXIST);
- goto out_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;
- }
-
+ return dentry;
+ dir = nd.dentry->d_inode;
+ inode = rpc_get_inode(dir->i_sb, S_IFSOCK | S_IRUSR | S_IWUSR);
+ if (!inode)
+ goto err_dput;
inode->i_ino = iunique(dir->i_sb, 100);
inode->i_fop = &rpc_pipe_fops;
-
+ d_instantiate(dentry, inode);
rpci = RPC_I(inode);
rpci->private = private;
rpci->flags = flags;
rpci->ops = ops;
-
- d_instantiate(dentry, inode);
- dget(dentry);
- up(&parent->d_inode->i_sem);
-
inode_dir_notify(dir, DN_CREATE);
+out:
+ up(&dir->i_sem);
+ rpc_release_path(&nd);
return dentry;
-
- out_dput:
+err_dput:
dput(dentry);
- out_unlock:
- up(&parent->d_inode->i_sem);
- rpc_put_mount();
- return dentry;
+ dentry = ERR_PTR(-ENOMEM);
+ printk(KERN_WARNING "%s: %s() failed to create pipe %s (errno = %d)\n",
+ __FILE__, __FUNCTION__, path, -ENOMEM);
+ goto out;
}
-void
-rpc_unlink(struct dentry *dentry)
+int
+rpc_unlink(char *path)
{
- struct dentry *parent = dentry->d_parent;
+ struct nameidata nd;
+ struct dentry *dentry;
+ struct inode *dir;
+ int error;
- down(&parent->d_inode->i_sem);
+ 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;
+ }
+ d_drop(dentry);
if (dentry->d_inode) {
rpc_close_pipes(dentry->d_inode);
rpc_inode_setowner(dentry->d_inode, NULL);
- simple_unlink(parent->d_inode, dentry);
+ error = simple_unlink(dir, dentry);
}
- up(&parent->d_inode->i_sem);
-
- inode_dir_notify(parent->d_inode, DN_DELETE);
- rpc_put_mount();
+ dput(dentry);
+ inode_dir_notify(dir, DN_DELETE);
+out_release:
+ up(&dir->i_sem);
+ rpc_release_path(&nd);
+ return error;
}
/*