Skip to content

Commit fc1abdc

Browse files
author
Al Viro
committed
rpc_pipe: saner primitive for creating subdirectories
All users of __rpc_mkdir() have the same form - start_creating(), followed, in case of success, by __rpc_mkdir() and unlocking parent. Combine that into a single helper, expanding __rpc_mkdir() into it, along with the call of __rpc_create_common() in it. Don't mess with d_drop() + d_add() - just d_instantiate() and be done with that. The reason __rpc_create_common() goes for that dance is that dentry it gets might or might not be hashed; here we know it's hashed. Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 41a6b9e commit fc1abdc

1 file changed

Lines changed: 39 additions & 28 deletions

File tree

net/sunrpc/rpc_pipe.c

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -524,21 +524,6 @@ static int __rpc_create(struct inode *dir, struct dentry *dentry,
524524
return 0;
525525
}
526526

527-
static int __rpc_mkdir(struct inode *dir, struct dentry *dentry,
528-
umode_t mode,
529-
const struct file_operations *i_fop,
530-
void *private)
531-
{
532-
int err;
533-
534-
err = __rpc_create_common(dir, dentry, S_IFDIR | mode, i_fop, private);
535-
if (err)
536-
return err;
537-
inc_nlink(dir);
538-
fsnotify_mkdir(dir, dentry);
539-
return 0;
540-
}
541-
542527
static void
543528
init_pipe(struct rpc_pipe *pipe)
544529
{
@@ -594,6 +579,35 @@ static int __rpc_mkpipe_dentry(struct inode *dir, struct dentry *dentry,
594579
return 0;
595580
}
596581

582+
static struct dentry *rpc_new_dir(struct dentry *parent,
583+
const char *name,
584+
umode_t mode,
585+
void *private)
586+
{
587+
struct dentry *dentry = simple_start_creating(parent, name);
588+
struct inode *dir = parent->d_inode;
589+
struct inode *inode;
590+
591+
if (IS_ERR(dentry))
592+
return dentry;
593+
594+
inode = rpc_get_inode(dir->i_sb, S_IFDIR | mode);
595+
if (unlikely(!inode)) {
596+
dput(dentry);
597+
inode_unlock(dir);
598+
return ERR_PTR(-ENOMEM);
599+
}
600+
601+
inode->i_ino = iunique(dir->i_sb, 100);
602+
rpc_inode_setowner(inode, private);
603+
inc_nlink(dir);
604+
d_instantiate(dentry, inode);
605+
fsnotify_mkdir(dir, dentry);
606+
inode_unlock(dir);
607+
608+
return dentry;
609+
}
610+
597611
static int rpc_populate(struct dentry *parent,
598612
const struct rpc_filelist *files,
599613
int start, int eof,
@@ -604,26 +618,28 @@ static int rpc_populate(struct dentry *parent,
604618
int i, err;
605619

606620
for (i = start; i < eof; i++) {
607-
dentry = simple_start_creating(parent, files[i].name);
608-
err = PTR_ERR(dentry);
609-
if (IS_ERR(dentry))
610-
goto out_bad;
611621
switch (files[i].mode & S_IFMT) {
612622
default:
613623
BUG();
614624
case S_IFREG:
625+
dentry = simple_start_creating(parent, files[i].name);
626+
err = PTR_ERR(dentry);
627+
if (IS_ERR(dentry))
628+
goto out_bad;
615629
err = __rpc_create(dir, dentry,
616630
files[i].mode,
617631
files[i].i_fop,
618632
private);
619633
inode_unlock(dir);
620634
break;
621635
case S_IFDIR:
622-
err = __rpc_mkdir(dir, dentry,
636+
dentry = rpc_new_dir(parent,
637+
files[i].name,
623638
files[i].mode,
624-
NULL,
625639
private);
626-
inode_unlock(dir);
640+
err = PTR_ERR(dentry);
641+
if (IS_ERR(dentry))
642+
goto out_bad;
627643
}
628644
if (err != 0)
629645
goto out_bad;
@@ -640,16 +656,11 @@ static struct dentry *rpc_mkdir_populate(struct dentry *parent,
640656
int (*populate)(struct dentry *, void *), void *args_populate)
641657
{
642658
struct dentry *dentry;
643-
struct inode *dir = d_inode(parent);
644659
int error;
645660

646-
dentry = simple_start_creating(parent, name);
661+
dentry = rpc_new_dir(parent, name, mode, private);
647662
if (IS_ERR(dentry))
648663
return dentry;
649-
error = __rpc_mkdir(dir, dentry, mode, NULL, private);
650-
inode_unlock(dir);
651-
if (error != 0)
652-
return ERR_PTR(error);
653664
if (populate != NULL) {
654665
error = populate(dentry, args_populate);
655666
if (error) {

0 commit comments

Comments
 (0)