From: Al Viro <viro@zeniv.linux.org.uk>
To: Miklos Szeredi <mszeredi@redhat.com>
Cc: linux-fsdevel@vger.kernel.org,
Amir Goldstein <amir73il@gmail.com>,
David Howells <dhowells@redhat.com>,
Yu-li Lin <yulilin@google.com>,
Chirantan Ekbote <chirantan@chromium.org>
Subject: Re: [PATCH v2 7/8] vfs: open inside ->tmpfile()
Date: Tue, 20 Sep 2022 02:50:54 +0100 [thread overview]
Message-ID: <YykcfkzECotV882O@ZenIV> (raw)
In-Reply-To: <20220919141031.1834447-8-mszeredi@redhat.com>
On Mon, Sep 19, 2022 at 04:10:30PM +0200, Miklos Szeredi wrote:
> This is in preparation for adding tmpfile support to fuse, which requires
> that the tmpfile creation and opening are done as a single operation.
>
> Replace the 'struct dentry *' argument of i_op->tmpfile with
> 'struct file *'.
>
> Call finish_open_simple() as the last thing in ->tmpfile() instances (may be
> omitted in the error case).
>
> Change d_tmpfile() argument to 'struct file *' as well to make callers more
> readable.
It really needs to add to Documentation/filesystems/porting.
> --- a/fs/hugetlbfs/inode.c
> +++ b/fs/hugetlbfs/inode.c
> @@ -889,7 +889,7 @@ static int do_hugetlbfs_mknod(struct inode *dir,
> struct dentry *dentry,
> umode_t mode,
> dev_t dev,
> - bool tmpfile)
> + struct file *tmpfile)
> {
> struct inode *inode;
> int error = -ENOSPC;
> @@ -898,7 +898,7 @@ static int do_hugetlbfs_mknod(struct inode *dir,
> if (inode) {
> dir->i_ctime = dir->i_mtime = current_time(dir);
> if (tmpfile) {
> - d_tmpfile(dentry, inode);
> + d_tmpfile(tmpfile, inode);
> } else {
> d_instantiate(dentry, inode);
> dget(dentry);/* Extra count - pin the dentry in core */
> @@ -911,7 +911,7 @@ static int do_hugetlbfs_mknod(struct inode *dir,
> static int hugetlbfs_mknod(struct user_namespace *mnt_userns, struct inode *dir,
> struct dentry *dentry, umode_t mode, dev_t dev)
> {
> - return do_hugetlbfs_mknod(dir, dentry, mode, dev, false);
> + return do_hugetlbfs_mknod(dir, dentry, mode, dev, NULL);
> }
>
> static int hugetlbfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
> @@ -932,10 +932,12 @@ static int hugetlbfs_create(struct user_namespace *mnt_userns,
> }
>
> static int hugetlbfs_tmpfile(struct user_namespace *mnt_userns,
> - struct inode *dir, struct dentry *dentry,
> + struct inode *dir, struct file *file,
> umode_t mode)
> {
> - return do_hugetlbfs_mknod(dir, dentry, mode | S_IFREG, 0, true);
> + int err = do_hugetlbfs_mknod(dir, file->f_path.dentry, mode | S_IFREG, 0, file);
> +
> + return finish_open_simple(file, err);
> }
>
> static int hugetlbfs_symlink(struct user_namespace *mnt_userns,
I would prefer to separate tmpfile from mknod in that one. And to hell
with the last argument in do_hugetlbfs_mknod(). Something like (completely
untested) patch below as prereq:
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index f7a5b5124d8a..0b458beb318c 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -885,33 +885,18 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb,
/*
* File creation. Allocate an inode, and we're done..
*/
-static int do_hugetlbfs_mknod(struct inode *dir,
- struct dentry *dentry,
- umode_t mode,
- dev_t dev,
- bool tmpfile)
+static int hugetlbfs_mknod(struct user_namespace *mnt_userns, struct inode *dir,
+ struct dentry *dentry, umode_t mode, dev_t dev)
{
struct inode *inode;
- int error = -ENOSPC;
inode = hugetlbfs_get_inode(dir->i_sb, dir, mode, dev);
- if (inode) {
- dir->i_ctime = dir->i_mtime = current_time(dir);
- if (tmpfile) {
- d_tmpfile(dentry, inode);
- } else {
- d_instantiate(dentry, inode);
- dget(dentry);/* Extra count - pin the dentry in core */
- }
- error = 0;
- }
- return error;
-}
-
-static int hugetlbfs_mknod(struct user_namespace *mnt_userns, struct inode *dir,
- struct dentry *dentry, umode_t mode, dev_t dev)
-{
- return do_hugetlbfs_mknod(dir, dentry, mode, dev, false);
+ if (!inode)
+ return -ENOSPC;
+ dir->i_ctime = dir->i_mtime = current_time(dir);
+ d_instantiate(dentry, inode);
+ dget(dentry);/* Extra count - pin the dentry in core */
+ return 0;
}
static int hugetlbfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
@@ -935,7 +920,14 @@ static int hugetlbfs_tmpfile(struct user_namespace *mnt_userns,
struct inode *dir, struct dentry *dentry,
umode_t mode)
{
- return do_hugetlbfs_mknod(dir, dentry, mode | S_IFREG, 0, true);
+ struct inode *inode;
+
+ inode = hugetlbfs_get_inode(dir->i_sb, dir, mode | S_IFREG, 0);
+ if (!inode)
+ return -ENOSPC;
+ dir->i_ctime = dir->i_mtime = current_time(dir);
+ d_tmpfile(dentry, inode);
+ return 0;
}
static int hugetlbfs_symlink(struct user_namespace *mnt_userns,
next prev parent reply other threads:[~2022-09-20 1:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-19 14:10 [PATCH v2 0/8] fuse tmpfile Miklos Szeredi
2022-09-19 14:10 ` [PATCH v2 1/8] cachefiles: tmpfile error handling cleanup Miklos Szeredi
2022-09-19 14:10 ` [PATCH v2 2/8] vfs: add tmpfile_open() helper Miklos Szeredi
2022-09-19 14:10 ` [PATCH v2 3/8] cachefiles: use " Miklos Szeredi
2022-09-19 14:10 ` [PATCH v2 4/8] ovl: " Miklos Szeredi
2022-09-20 1:33 ` Al Viro
2022-09-20 8:02 ` Miklos Szeredi
2022-09-19 14:10 ` [PATCH v2 5/8] vfs: make vfs_tmpfile() static Miklos Szeredi
2022-09-19 14:10 ` [PATCH v2 6/8] vfs: move open right after ->tmpfile() Miklos Szeredi
2022-09-20 1:40 ` Al Viro
2022-09-20 8:08 ` Miklos Szeredi
2022-09-19 14:10 ` [PATCH v2 7/8] vfs: open inside ->tmpfile() Miklos Szeredi
2022-09-20 1:50 ` Al Viro [this message]
2022-09-20 8:44 ` Miklos Szeredi
2022-09-19 14:10 ` [PATCH v2 8/8] fuse: implement ->tmpfile() Miklos Szeredi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YykcfkzECotV882O@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=amir73il@gmail.com \
--cc=chirantan@chromium.org \
--cc=dhowells@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=mszeredi@redhat.com \
--cc=yulilin@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox