Skip to content

Commit a117bf4

Browse files
author
Al Viro
committed
rpc_mkpipe_dentry(): switch to simple_start_creating()
... and make sure we set the fs-private part of inode up before attaching it to dentry. Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 5c1da75 commit a117bf4

1 file changed

Lines changed: 29 additions & 54 deletions

File tree

net/sunrpc/rpc_pipe.c

Lines changed: 29 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -485,31 +485,6 @@ rpc_get_inode(struct super_block *sb, umode_t mode)
485485
return inode;
486486
}
487487

488-
static int __rpc_create_common(struct inode *dir, struct dentry *dentry,
489-
umode_t mode,
490-
const struct file_operations *i_fop,
491-
void *private)
492-
{
493-
struct inode *inode;
494-
495-
d_drop(dentry);
496-
inode = rpc_get_inode(dir->i_sb, mode);
497-
if (!inode)
498-
goto out_err;
499-
inode->i_ino = iunique(dir->i_sb, 100);
500-
if (i_fop)
501-
inode->i_fop = i_fop;
502-
if (private)
503-
rpc_inode_setowner(inode, private);
504-
d_add(dentry, inode);
505-
return 0;
506-
out_err:
507-
printk(KERN_WARNING "%s: %s failed to allocate inode for dentry %pd\n",
508-
__FILE__, __func__, dentry);
509-
dput(dentry);
510-
return -ENOMEM;
511-
}
512-
513488
static void
514489
init_pipe(struct rpc_pipe *pipe)
515490
{
@@ -546,25 +521,6 @@ struct rpc_pipe *rpc_mkpipe_data(const struct rpc_pipe_ops *ops, int flags)
546521
}
547522
EXPORT_SYMBOL_GPL(rpc_mkpipe_data);
548523

549-
static int __rpc_mkpipe_dentry(struct inode *dir, struct dentry *dentry,
550-
umode_t mode,
551-
const struct file_operations *i_fop,
552-
void *private,
553-
struct rpc_pipe *pipe)
554-
{
555-
struct rpc_inode *rpci;
556-
int err;
557-
558-
err = __rpc_create_common(dir, dentry, S_IFIFO | mode, i_fop, private);
559-
if (err)
560-
return err;
561-
rpci = RPC_I(d_inode(dentry));
562-
rpci->private = private;
563-
rpci->pipe = pipe;
564-
fsnotify_create(dir, dentry);
565-
return 0;
566-
}
567-
568524
static int rpc_new_file(struct dentry *parent,
569525
const char *name,
570526
umode_t mode,
@@ -704,8 +660,10 @@ static struct dentry *rpc_mkdir_populate(struct dentry *parent,
704660
int rpc_mkpipe_dentry(struct dentry *parent, const char *name,
705661
void *private, struct rpc_pipe *pipe)
706662
{
707-
struct dentry *dentry;
708663
struct inode *dir = d_inode(parent);
664+
struct dentry *dentry;
665+
struct inode *inode;
666+
struct rpc_inode *rpci;
709667
umode_t umode = S_IFIFO | 0600;
710668
int err;
711669

@@ -715,16 +673,33 @@ int rpc_mkpipe_dentry(struct dentry *parent, const char *name,
715673
umode &= ~0222;
716674

717675
dentry = simple_start_creating(parent, name);
718-
if (IS_ERR(dentry))
719-
return PTR_ERR(dentry);
720-
err = __rpc_mkpipe_dentry(dir, dentry, umode, &rpc_pipe_fops,
721-
private, pipe);
722-
if (unlikely(err))
723-
pr_warn("%s() failed to create pipe %pd/%s (errno = %d)\n",
724-
__func__, parent, name, err);
725-
else
726-
pipe->dentry = dentry;
676+
if (IS_ERR(dentry)) {
677+
err = PTR_ERR(dentry);
678+
goto failed;
679+
}
680+
681+
inode = rpc_get_inode(dir->i_sb, umode);
682+
if (unlikely(!inode)) {
683+
dput(dentry);
684+
inode_unlock(dir);
685+
err = -ENOMEM;
686+
goto failed;
687+
}
688+
inode->i_ino = iunique(dir->i_sb, 100);
689+
inode->i_fop = &rpc_pipe_fops;
690+
rpci = RPC_I(inode);
691+
rpci->private = private;
692+
rpci->pipe = pipe;
693+
rpc_inode_setowner(inode, private);
694+
d_instantiate(dentry, inode);
695+
pipe->dentry = dentry;
696+
fsnotify_create(dir, dentry);
727697
inode_unlock(dir);
698+
return 0;
699+
700+
failed:
701+
pr_warn("%s() failed to create pipe %pd/%s (errno = %d)\n",
702+
__func__, parent, name, err);
728703
return err;
729704
}
730705
EXPORT_SYMBOL_GPL(rpc_mkpipe_dentry);

0 commit comments

Comments
 (0)