SUNRPC: Clean up file creation code in rpc_pipefs
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
@@ -539,6 +539,68 @@ rpc_get_inode(struct super_block *sb, umode_t mode)
|
|||||||
return inode;
|
return inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int __rpc_create_common(struct inode *dir, struct dentry *dentry,
|
||||||
|
umode_t mode,
|
||||||
|
const struct file_operations *i_fop,
|
||||||
|
void *private)
|
||||||
|
{
|
||||||
|
struct inode *inode;
|
||||||
|
|
||||||
|
BUG_ON(!d_unhashed(dentry));
|
||||||
|
inode = rpc_get_inode(dir->i_sb, mode);
|
||||||
|
if (!inode)
|
||||||
|
goto out_err;
|
||||||
|
inode->i_ino = iunique(dir->i_sb, 100);
|
||||||
|
if (i_fop)
|
||||||
|
inode->i_fop = i_fop;
|
||||||
|
if (private)
|
||||||
|
rpc_inode_setowner(inode, private);
|
||||||
|
d_add(dentry, inode);
|
||||||
|
return 0;
|
||||||
|
out_err:
|
||||||
|
printk(KERN_WARNING "%s: %s failed to allocate inode for dentry %s\n",
|
||||||
|
__FILE__, __func__, dentry->d_name.name);
|
||||||
|
dput(dentry);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __rpc_mkdir(struct inode *dir, struct dentry *dentry,
|
||||||
|
umode_t mode,
|
||||||
|
const struct file_operations *i_fop,
|
||||||
|
void *private)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = __rpc_create_common(dir, dentry, S_IFDIR | mode, i_fop, private);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
inc_nlink(dir);
|
||||||
|
fsnotify_mkdir(dir, dentry);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __rpc_mkpipe(struct inode *dir, struct dentry *dentry,
|
||||||
|
umode_t mode,
|
||||||
|
const struct file_operations *i_fop,
|
||||||
|
void *private,
|
||||||
|
const struct rpc_pipe_ops *ops,
|
||||||
|
int flags)
|
||||||
|
{
|
||||||
|
struct rpc_inode *rpci;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = __rpc_create_common(dir, dentry, S_IFIFO | mode, i_fop, private);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
rpci = RPC_I(dentry->d_inode);
|
||||||
|
rpci->nkern_readwriters = 1;
|
||||||
|
rpci->private = private;
|
||||||
|
rpci->flags = flags;
|
||||||
|
rpci->ops = ops;
|
||||||
|
fsnotify_create(dir, dentry);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* FIXME: This probably has races.
|
* FIXME: This probably has races.
|
||||||
*/
|
*/
|
||||||
@@ -628,25 +690,6 @@ out_bad:
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
__rpc_mkdir(struct inode *dir, struct dentry *dentry)
|
|
||||||
{
|
|
||||||
struct inode *inode;
|
|
||||||
|
|
||||||
inode = rpc_get_inode(dir->i_sb, S_IFDIR | S_IRUGO | S_IXUGO);
|
|
||||||
if (!inode)
|
|
||||||
goto out_err;
|
|
||||||
inode->i_ino = iunique(dir->i_sb, 100);
|
|
||||||
d_instantiate(dentry, inode);
|
|
||||||
inc_nlink(dir);
|
|
||||||
fsnotify_mkdir(dir, dentry);
|
|
||||||
return 0;
|
|
||||||
out_err:
|
|
||||||
printk(KERN_WARNING "%s: %s failed to allocate inode for dentry %s\n",
|
|
||||||
__FILE__, __func__, dentry->d_name.name);
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
__rpc_rmdir(struct inode *dir, struct dentry *dentry)
|
__rpc_rmdir(struct inode *dir, struct dentry *dentry)
|
||||||
{
|
{
|
||||||
@@ -717,9 +760,9 @@ rpc_mkdir(char *path, struct rpc_clnt *rpc_client)
|
|||||||
if (IS_ERR(dentry))
|
if (IS_ERR(dentry))
|
||||||
return dentry;
|
return dentry;
|
||||||
dir = nd.path.dentry->d_inode;
|
dir = nd.path.dentry->d_inode;
|
||||||
if ((error = __rpc_mkdir(dir, dentry)) != 0)
|
error = __rpc_mkdir(dir, dentry, S_IRUGO | S_IXUGO, NULL, rpc_client);
|
||||||
goto err_dput;
|
if (error != 0)
|
||||||
RPC_I(dentry->d_inode)->private = rpc_client;
|
goto out_err;
|
||||||
error = rpc_populate(dentry, authfiles,
|
error = rpc_populate(dentry, authfiles,
|
||||||
RPCAUTH_info, RPCAUTH_EOF);
|
RPCAUTH_info, RPCAUTH_EOF);
|
||||||
if (error)
|
if (error)
|
||||||
@@ -732,8 +775,7 @@ out:
|
|||||||
err_depopulate:
|
err_depopulate:
|
||||||
rpc_depopulate(dentry, RPCAUTH_info, RPCAUTH_EOF);
|
rpc_depopulate(dentry, RPCAUTH_info, RPCAUTH_EOF);
|
||||||
__rpc_rmdir(dir, dentry);
|
__rpc_rmdir(dir, dentry);
|
||||||
err_dput:
|
out_err:
|
||||||
dput(dentry);
|
|
||||||
printk(KERN_WARNING "%s: %s() failed to create directory %s (errno = %d)\n",
|
printk(KERN_WARNING "%s: %s() failed to create directory %s (errno = %d)\n",
|
||||||
__FILE__, __func__, path, error);
|
__FILE__, __func__, path, error);
|
||||||
dentry = ERR_PTR(error);
|
dentry = ERR_PTR(error);
|
||||||
@@ -787,9 +829,9 @@ struct dentry *rpc_mkpipe(struct dentry *parent, const char *name,
|
|||||||
int flags)
|
int flags)
|
||||||
{
|
{
|
||||||
struct dentry *dentry;
|
struct dentry *dentry;
|
||||||
struct inode *dir, *inode;
|
struct inode *dir = parent->d_inode;
|
||||||
struct rpc_inode *rpci;
|
|
||||||
umode_t umode = S_IFIFO | S_IRUSR | S_IWUSR;
|
umode_t umode = S_IFIFO | S_IRUSR | S_IWUSR;
|
||||||
|
int err;
|
||||||
|
|
||||||
if (ops->upcall == NULL)
|
if (ops->upcall == NULL)
|
||||||
umode &= ~S_IRUGO;
|
umode &= ~S_IRUGO;
|
||||||
@@ -801,7 +843,7 @@ struct dentry *rpc_mkpipe(struct dentry *parent, const char *name,
|
|||||||
return dentry;
|
return dentry;
|
||||||
dir = parent->d_inode;
|
dir = parent->d_inode;
|
||||||
if (dentry->d_inode) {
|
if (dentry->d_inode) {
|
||||||
rpci = RPC_I(dentry->d_inode);
|
struct rpc_inode *rpci = RPC_I(dentry->d_inode);
|
||||||
if (rpci->private != private ||
|
if (rpci->private != private ||
|
||||||
rpci->ops != ops ||
|
rpci->ops != ops ||
|
||||||
rpci->flags != flags) {
|
rpci->flags != flags) {
|
||||||
@@ -811,28 +853,20 @@ struct dentry *rpc_mkpipe(struct dentry *parent, const char *name,
|
|||||||
rpci->nkern_readwriters++;
|
rpci->nkern_readwriters++;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
inode = rpc_get_inode(dir->i_sb, umode);
|
|
||||||
if (!inode)
|
err = __rpc_mkpipe(dir, dentry, umode, &rpc_pipe_fops,
|
||||||
goto err_dput;
|
private, ops, flags);
|
||||||
inode->i_ino = iunique(dir->i_sb, 100);
|
if (err)
|
||||||
inode->i_fop = &rpc_pipe_fops;
|
goto out_err;
|
||||||
d_instantiate(dentry, inode);
|
|
||||||
rpci = RPC_I(inode);
|
|
||||||
rpci->private = private;
|
|
||||||
rpci->flags = flags;
|
|
||||||
rpci->ops = ops;
|
|
||||||
rpci->nkern_readwriters = 1;
|
|
||||||
fsnotify_create(dir, dentry);
|
|
||||||
dget(dentry);
|
dget(dentry);
|
||||||
out:
|
out:
|
||||||
mutex_unlock(&dir->i_mutex);
|
mutex_unlock(&dir->i_mutex);
|
||||||
return dentry;
|
return dentry;
|
||||||
err_dput:
|
out_err:
|
||||||
dput(dentry);
|
dentry = ERR_PTR(err);
|
||||||
dentry = ERR_PTR(-ENOMEM);
|
|
||||||
printk(KERN_WARNING "%s: %s() failed to create pipe %s/%s (errno = %d)\n",
|
printk(KERN_WARNING "%s: %s() failed to create pipe %s/%s (errno = %d)\n",
|
||||||
__FILE__, __func__, parent->d_name.name, name,
|
__FILE__, __func__, parent->d_name.name, name,
|
||||||
-ENOMEM);
|
err);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(rpc_mkpipe);
|
EXPORT_SYMBOL_GPL(rpc_mkpipe);
|
||||||
|
Reference in New Issue
Block a user