From: Al Viro Date: Sun, 23 Mar 2025 00:10:44 +0000 (-0400) Subject: rpc_pipe: saner primitive for creating regular files X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c1da75895c037822546c24a10fa45d4bef6fb79;p=thirdparty%2Flinux.git 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 Signed-off-by: Al Viro --- diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c index c3f269aadcaf5..8f88c75c9b30d 100644 --- a/net/sunrpc/rpc_pipe.c +++ b/net/sunrpc/rpc_pipe.c @@ -510,20 +510,6 @@ out_err: return -ENOMEM; } -static int __rpc_create(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_IFREG | mode, i_fop, private); - if (err) - return err; - fsnotify_create(dir, dentry); - return 0; -} - static void init_pipe(struct rpc_pipe *pipe) { @@ -579,6 +565,35 @@ static int __rpc_mkpipe_dentry(struct inode *dir, struct dentry *dentry, return 0; } +static int rpc_new_file(struct dentry *parent, + const char *name, + umode_t mode, + const struct file_operations *i_fop, + void *private) +{ + struct dentry *dentry = simple_start_creating(parent, name); + struct inode *dir = parent->d_inode; + struct inode *inode; + + if (IS_ERR(dentry)) + return PTR_ERR(dentry); + + inode = rpc_get_inode(dir->i_sb, S_IFREG | mode); + if (unlikely(!inode)) { + dput(dentry); + inode_unlock(dir); + return -ENOMEM; + } + inode->i_ino = iunique(dir->i_sb, 100); + if (i_fop) + inode->i_fop = i_fop; + rpc_inode_setowner(inode, private); + d_instantiate(dentry, inode); + fsnotify_create(dir, dentry); + inode_unlock(dir); + return 0; +} + static struct dentry *rpc_new_dir(struct dentry *parent, const char *name, umode_t mode, @@ -613,7 +628,6 @@ static int rpc_populate(struct dentry *parent, int start, int eof, void *private) { - struct inode *dir = d_inode(parent); struct dentry *dentry; int i, err; @@ -622,27 +636,24 @@ static int rpc_populate(struct dentry *parent, default: BUG(); case S_IFREG: - dentry = simple_start_creating(parent, files[i].name); - err = PTR_ERR(dentry); - if (IS_ERR(dentry)) - goto out_bad; - err = __rpc_create(dir, dentry, + err = rpc_new_file(parent, + files[i].name, files[i].mode, files[i].i_fop, private); - inode_unlock(dir); + if (err) + goto out_bad; break; case S_IFDIR: dentry = rpc_new_dir(parent, files[i].name, files[i].mode, private); - err = PTR_ERR(dentry); - if (IS_ERR(dentry)) + if (IS_ERR(dentry)) { + err = PTR_ERR(dentry); goto out_bad; + } } - if (err != 0) - goto out_bad; } return 0; out_bad: