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 1/4] ovl: do not open non-data lower file for fsync
Date: Fri, 4 Oct 2024 12:23:39 +0200 [thread overview]
Message-ID: <20241004102342.179434-2-amir73il@gmail.com> (raw)
In-Reply-To: <20241004102342.179434-1-amir73il@gmail.com>
ovl_fsync() with !datasync opens a backing file from the top most dentry
in the stack, checks if this dentry is non-upper and skips the fsync.
In case of an overlay dentry stack with lower data and lower metadata
above it, but without an upper metadata above it, the backing file is
opened from the top most lower metadata dentry and never used.
Fix the helper ovl_real_fdget_meta() to return an empty struct fd in
that case to avoid the unneeded backing file open.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/overlayfs/file.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 4504493b20be..3d64d00ef981 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -90,17 +90,19 @@ static int ovl_change_flags(struct file *file, unsigned int flags)
}
static int ovl_real_fdget_meta(const struct file *file, struct fd *real,
- bool allow_meta)
+ bool upper_meta)
{
struct dentry *dentry = file_dentry(file);
struct file *realfile = file->private_data;
struct path realpath;
int err;
- real->word = (unsigned long)realfile;
+ real->word = 0;
- if (allow_meta) {
- ovl_path_real(dentry, &realpath);
+ if (upper_meta) {
+ ovl_path_upper(dentry, &realpath);
+ if (!realpath.dentry)
+ return 0;
} else {
/* lazy lookup and verify of lowerdata */
err = ovl_verify_lowerdata(dentry);
@@ -395,7 +397,7 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync)
return ret;
ret = ovl_real_fdget_meta(file, &real, !datasync);
- if (ret)
+ if (ret || fd_empty(real))
return ret;
/* Don't sync lower file for fear of receiving EROFS error */
--
2.34.1
next prev parent reply other threads:[~2024-10-04 10:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-04 10:23 [PATCH 0/4] Stash overlay real upper file in backing_file Amir Goldstein
2024-10-04 10:23 ` Amir Goldstein [this message]
2024-10-04 22:16 ` [PATCH 1/4] ovl: do not open non-data lower file for fsync Al Viro
2024-10-04 22:28 ` Al Viro
2024-10-05 1:35 ` Al Viro
2024-10-05 6:30 ` Amir Goldstein
2024-10-05 19:49 ` Al Viro
2024-10-06 8:03 ` Amir Goldstein
2024-10-04 10:23 ` [PATCH 2/4] ovl: stash upper real file in backing_file struct Amir Goldstein
2024-10-04 10:23 ` [PATCH 3/4] ovl: convert ovl_real_fdget_meta() callers to ovl_real_file_meta() Amir Goldstein
2024-10-04 22:23 ` Al Viro
2024-10-05 12:37 ` Amir Goldstein
2024-10-04 10:23 ` [PATCH 4/4] ovl: convert ovl_real_fdget() callers to ovl_real_file() Amir Goldstein
2024-10-04 22:25 ` 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=20241004102342.179434-2-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).