From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>, Al Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>,
linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org
Subject: [PATCH v3 4/5] ovl: convert ovl_real_fdget_path() callers to ovl_real_file_path()
Date: Mon, 7 Oct 2024 16:19:24 +0200 [thread overview]
Message-ID: <20241007141925.327055-5-amir73il@gmail.com> (raw)
In-Reply-To: <20241007141925.327055-1-amir73il@gmail.com>
Stop using struct fd to return a real file from ovl_real_fdget_path(),
because we no longer return a temporary file object and the callers
always get a borrowed file reference.
Rename the helper to ovl_real_file_path(), return a borrowed reference
of the real file that is referenced from the overlayfs file or an error.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/overlayfs/file.c | 66 +++++++++++++++++++++++++--------------------
1 file changed, 37 insertions(+), 29 deletions(-)
diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 525bcddb49e5..b6d6ccc39dad 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -100,16 +100,14 @@ static bool ovl_is_real_file(const struct file *realfile,
return file_inode(realfile) == d_inode(realpath->dentry);
}
-static int ovl_real_fdget_path(const struct file *file, struct fd *real,
- struct path *realpath)
+static struct file *ovl_real_file_path(const struct file *file,
+ struct path *realpath)
{
struct ovl_file *of = file->private_data;
struct file *realfile = of->realfile;
- real->word = 0;
-
if (WARN_ON_ONCE(!realpath->dentry))
- return -EIO;
+ return ERR_PTR(-EIO);
/*
* If the realfile that we want is not where the data used to be at
@@ -124,7 +122,7 @@ static int ovl_real_fdget_path(const struct file *file, struct fd *real,
if (!upperfile) { /* Nobody opened upperfile yet */
upperfile = ovl_open_realfile(file, realpath);
if (IS_ERR(upperfile))
- return PTR_ERR(upperfile);
+ return upperfile;
/* Store the upperfile for later */
old = cmpxchg_release(&of->upperfile, NULL, upperfile);
@@ -138,20 +136,23 @@ static int ovl_real_fdget_path(const struct file *file, struct fd *real,
* been corrupting the upper layer.
*/
if (WARN_ON_ONCE(!ovl_is_real_file(upperfile, realpath)))
- return -EIO;
+ return ERR_PTR(-EIO);
realfile = upperfile;
}
/* Did the flags change since open? */
- if (unlikely((file->f_flags ^ realfile->f_flags) & ~OVL_OPEN_FLAGS))
- return ovl_change_flags(realfile, file->f_flags);
+ if (unlikely((file->f_flags ^ realfile->f_flags) & ~OVL_OPEN_FLAGS)) {
+ int err = ovl_change_flags(realfile, file->f_flags);
- real->word = (unsigned long)realfile;
- return 0;
+ if (err)
+ return ERR_PTR(err);
+ }
+
+ return realfile;
}
-static int ovl_real_fdget(const struct file *file, struct fd *real)
+static struct file *ovl_real_file(const struct file *file)
{
struct dentry *dentry = file_dentry(file);
struct path realpath;
@@ -159,23 +160,33 @@ static int ovl_real_fdget(const struct file *file, struct fd *real)
if (d_is_dir(dentry)) {
struct file *f = ovl_dir_real_file(file, false);
- if (IS_ERR(f))
- return PTR_ERR(f);
- real->word = (unsigned long)f;
- return 0;
+
+ if (WARN_ON_ONCE(!f))
+ return ERR_PTR(-EIO);
+ return f;
}
/* lazy lookup and verify of lowerdata */
err = ovl_verify_lowerdata(dentry);
if (err)
- return err;
+ return ERR_PTR(err);
ovl_path_realdata(dentry, &realpath);
- return ovl_real_fdget_path(file, real, &realpath);
+ return ovl_real_file_path(file, &realpath);
}
-static int ovl_upper_fdget(const struct file *file, struct fd *real, bool data)
+static int ovl_real_fdget(const struct file *file, struct fd *real)
+{
+ struct file *f = ovl_real_file(file);
+
+ if (IS_ERR(f))
+ return PTR_ERR(f);
+ real->word = (unsigned long)f;
+ return 0;
+}
+
+static struct file *ovl_upper_file(const struct file *file, bool data)
{
struct dentry *dentry = file_dentry(file);
struct path realpath;
@@ -186,12 +197,11 @@ static int ovl_upper_fdget(const struct file *file, struct fd *real, bool data)
else
type = ovl_path_real(dentry, &realpath);
- real->word = 0;
/* Not interested in lower nor in upper meta if data was requested */
if (!OVL_TYPE_UPPER(type) || (data && OVL_TYPE_MERGE(type)))
- return 0;
+ return NULL;
- return ovl_real_fdget_path(file, real, &realpath);
+ return ovl_real_file_path(file, &realpath);
}
static int ovl_open(struct inode *inode, struct file *file)
@@ -452,7 +462,7 @@ static ssize_t ovl_splice_write(struct pipe_inode_info *pipe, struct file *out,
static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync)
{
- struct fd real;
+ struct file *upperfile;
const struct cred *old_cred;
int ret;
@@ -461,16 +471,14 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync)
return ret;
/* Don't sync lower file for fear of receiving EROFS error */
- ret = ovl_upper_fdget(file, &real, datasync);
- if (ret || fd_empty(real))
- return ret;
+ upperfile = ovl_upper_file(file, datasync);
+ if (IS_ERR_OR_NULL(upperfile))
+ return PTR_ERR(upperfile);
old_cred = ovl_override_creds(file_inode(file)->i_sb);
- ret = vfs_fsync_range(fd_file(real), start, end, datasync);
+ ret = vfs_fsync_range(upperfile, start, end, datasync);
revert_creds(old_cred);
- fdput(real);
-
return ret;
}
--
2.34.1
next prev parent reply other threads:[~2024-10-07 14:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-07 14:19 [PATCH v3 0/5] Store overlay real upper file in ovl_file Amir Goldstein
2024-10-07 14:19 ` [PATCH v3 1/5] ovl: do not open non-data lower file for fsync Amir Goldstein
2024-10-07 14:39 ` Al Viro
2024-10-07 15:56 ` Amir Goldstein
2024-10-07 17:04 ` Al Viro
2024-10-07 16:55 ` Al Viro
2024-10-07 17:13 ` Al Viro
2024-10-07 14:19 ` [PATCH v3 2/5] ovl: allocate a container struct ovl_file for ovl private context Amir Goldstein
2024-10-07 14:43 ` Al Viro
2024-10-07 14:55 ` Miklos Szeredi
2024-10-07 14:19 ` [PATCH v3 3/5] ovl: store upper real file in ovl_file struct Amir Goldstein
2024-10-07 14:19 ` Amir Goldstein [this message]
2024-10-07 14:19 ` [PATCH v3 5/5] ovl: convert ovl_real_fdget() callers to ovl_real_file() Amir Goldstein
2024-10-17 4:52 ` [PATCH v3 0/5] Store overlay real upper file in ovl_file Al Viro
2024-10-17 8:18 ` Amir Goldstein
2024-10-17 13:52 ` Miklos Szeredi
2024-10-17 18:13 ` Al Viro
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=20241007141925.327055-5-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).