Skip to content

Commit 5c1da75

Browse files
author
Al Viro
committed
rpc_pipe: saner primitive for creating regular files
rpc_new_file(); similar to rpc_new_dir(), except that here we pass file_operations as well. Callers don't care about dentry, just return 0 or -E... Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent fc1abdc commit 5c1da75

1 file changed

Lines changed: 36 additions & 25 deletions

File tree

net/sunrpc/rpc_pipe.c

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -510,20 +510,6 @@ static int __rpc_create_common(struct inode *dir, struct dentry *dentry,
510510
return -ENOMEM;
511511
}
512512

513-
static int __rpc_create(struct inode *dir, struct dentry *dentry,
514-
umode_t mode,
515-
const struct file_operations *i_fop,
516-
void *private)
517-
{
518-
int err;
519-
520-
err = __rpc_create_common(dir, dentry, S_IFREG | mode, i_fop, private);
521-
if (err)
522-
return err;
523-
fsnotify_create(dir, dentry);
524-
return 0;
525-
}
526-
527513
static void
528514
init_pipe(struct rpc_pipe *pipe)
529515
{
@@ -579,6 +565,35 @@ static int __rpc_mkpipe_dentry(struct inode *dir, struct dentry *dentry,
579565
return 0;
580566
}
581567

568+
static int rpc_new_file(struct dentry *parent,
569+
const char *name,
570+
umode_t mode,
571+
const struct file_operations *i_fop,
572+
void *private)
573+
{
574+
struct dentry *dentry = simple_start_creating(parent, name);
575+
struct inode *dir = parent->d_inode;
576+
struct inode *inode;
577+
578+
if (IS_ERR(dentry))
579+
return PTR_ERR(dentry);
580+
581+
inode = rpc_get_inode(dir->i_sb, S_IFREG | mode);
582+
if (unlikely(!inode)) {
583+
dput(dentry);
584+
inode_unlock(dir);
585+
return -ENOMEM;
586+
}
587+
inode->i_ino = iunique(dir->i_sb, 100);
588+
if (i_fop)
589+
inode->i_fop = i_fop;
590+
rpc_inode_setowner(inode, private);
591+
d_instantiate(dentry, inode);
592+
fsnotify_create(dir, dentry);
593+
inode_unlock(dir);
594+
return 0;
595+
}
596+
582597
static struct dentry *rpc_new_dir(struct dentry *parent,
583598
const char *name,
584599
umode_t mode,
@@ -613,7 +628,6 @@ static int rpc_populate(struct dentry *parent,
613628
int start, int eof,
614629
void *private)
615630
{
616-
struct inode *dir = d_inode(parent);
617631
struct dentry *dentry;
618632
int i, err;
619633

@@ -622,27 +636,24 @@ static int rpc_populate(struct dentry *parent,
622636
default:
623637
BUG();
624638
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;
629-
err = __rpc_create(dir, dentry,
639+
err = rpc_new_file(parent,
640+
files[i].name,
630641
files[i].mode,
631642
files[i].i_fop,
632643
private);
633-
inode_unlock(dir);
644+
if (err)
645+
goto out_bad;
634646
break;
635647
case S_IFDIR:
636648
dentry = rpc_new_dir(parent,
637649
files[i].name,
638650
files[i].mode,
639651
private);
640-
err = PTR_ERR(dentry);
641-
if (IS_ERR(dentry))
652+
if (IS_ERR(dentry)) {
653+
err = PTR_ERR(dentry);
642654
goto out_bad;
655+
}
643656
}
644-
if (err != 0)
645-
goto out_bad;
646657
}
647658
return 0;
648659
out_bad:

0 commit comments

Comments
 (0)