From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Alexander Larsson <alexl@redhat.com>, linux-unionfs@vger.kernel.org
Subject: [PATCH v2 12/13] ovl: prepare for lazy lookup of lowerdata inode
Date: Thu, 27 Apr 2023 16:05:38 +0300 [thread overview]
Message-ID: <20230427130539.2798797-13-amir73il@gmail.com> (raw)
In-Reply-To: <20230427130539.2798797-1-amir73il@gmail.com>
Make the code handle the case of numlower > 1 and missing lowerdata
dentry gracefully.
Missing lowerdata dentry is an indication for lazy lookup of lowerdata
and in that case the lowerdata_redirect path is stored in ovl_inode.
Following commits will defer lookup and perform the lazy lookup on
access.
Reviewed-by: Alexander Larsson <alexl@redhat.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/overlayfs/file.c | 7 +++++++
fs/overlayfs/inode.c | 18 ++++++++++++++----
fs/overlayfs/super.c | 11 +++++++++++
fs/overlayfs/util.c | 2 +-
4 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 7c04f033aadd..951683a66ff6 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -115,6 +115,9 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real,
ovl_path_real(dentry, &realpath);
else
ovl_path_realdata(dentry, &realpath);
+ /* TODO: lazy lookup of lowerdata */
+ if (!realpath.dentry)
+ return -EIO;
/* Has it been copied up since we'd opened it? */
if (unlikely(file_inode(real->file) != d_inode(realpath.dentry))) {
@@ -158,6 +161,10 @@ static int ovl_open(struct inode *inode, struct file *file)
file->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
ovl_path_realdata(dentry, &realpath);
+ /* TODO: lazy lookup of lowerdata */
+ if (!realpath.dentry)
+ return -EIO;
+
realfile = ovl_open_realfile(file, &realpath);
if (IS_ERR(realfile))
return PTR_ERR(realfile);
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index a7529b6a86e6..ebbe13bccc97 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -240,15 +240,22 @@ int ovl_getattr(struct mnt_idmap *idmap, const struct path *path,
/*
* If lower is not same as lowerdata or if there was
* no origin on upper, we can end up here.
+ * With lazy lowerdata lookup, guess lowerdata blocks
+ * from size to avoid lowerdata lookup on stat(2).
*/
struct kstat lowerdatastat;
u32 lowermask = STATX_BLOCKS;
ovl_path_lowerdata(dentry, &realpath);
- err = vfs_getattr(&realpath, &lowerdatastat,
- lowermask, flags);
- if (err)
- goto out;
+ if (realpath.dentry) {
+ err = vfs_getattr(&realpath, &lowerdatastat,
+ lowermask, flags);
+ if (err)
+ goto out;
+ } else {
+ lowerdatastat.blocks =
+ round_up(stat->size, stat->blksize) >> 9;
+ }
stat->blocks = lowerdatastat.blocks;
}
}
@@ -710,6 +717,9 @@ static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
struct inode *realinode = ovl_inode_realdata(inode);
const struct cred *old_cred;
+ if (!realinode)
+ return -EIO;
+
if (!realinode->i_op->fiemap)
return -EOPNOTSUPP;
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index b960b9d84b66..ad9a68bec565 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -81,6 +81,14 @@ static struct dentry *ovl_d_real(struct dentry *dentry,
if (real && !inode && ovl_has_upperdata(d_inode(dentry)))
return real;
+ /*
+ * XXX: We may need lazy lookup of lowerdata for !inode case to return
+ * the real lowerdata dentry. The only current caller of d_real() with
+ * NULL inode is d_real_inode() from trace_uprobe and this caller is
+ * likely going to be followed reading from the file, before placing
+ * uprobes on offset within the file, so lowerdata should be available
+ * when setting the uprobe.
+ */
lower = ovl_dentry_lowerdata(dentry);
if (!lower)
goto bug;
@@ -103,6 +111,9 @@ static int ovl_revalidate_real(struct dentry *d, unsigned int flags, bool weak)
{
int ret = 1;
+ if (!d)
+ return 1;
+
if (weak) {
if (d->d_flags & DCACHE_OP_WEAK_REVALIDATE)
ret = d->d_op->d_weak_revalidate(d, flags);
diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
index ad93a3132495..9b7c0163734a 100644
--- a/fs/overlayfs/util.c
+++ b/fs/overlayfs/util.c
@@ -159,7 +159,7 @@ void ovl_dentry_init_flags(struct dentry *dentry, struct dentry *upperdentry,
if (upperdentry)
flags |= upperdentry->d_flags;
- for (i = 0; i < ovl_numlower(oe); i++)
+ for (i = 0; i < ovl_numlower(oe) && lowerstack[i].dentry; i++)
flags |= lowerstack[i].dentry->d_flags;
spin_lock(&dentry->d_lock);
--
2.34.1
next prev parent reply other threads:[~2023-04-27 13:06 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-27 13:05 [PATCH v2 00/13] Overlayfs lazy lookup of lowerdata Amir Goldstein
2023-04-27 13:05 ` [PATCH v2 01/13] ovl: update of dentry revalidate flags after copy up Amir Goldstein
2023-04-27 13:05 ` [PATCH v2 02/13] ovl: use OVL_E() and OVL_E_FLAGS() accessors Amir Goldstein
2023-04-27 13:05 ` [PATCH v2 03/13] ovl: use ovl_numlower() and ovl_lowerstack() accessors Amir Goldstein
2023-04-27 13:05 ` [PATCH v2 04/13] ovl: factor out ovl_free_entry() and ovl_stack_*() helpers Amir Goldstein
2023-04-27 13:05 ` [PATCH v2 05/13] ovl: move ovl_entry into ovl_inode Amir Goldstein
2023-04-27 13:05 ` [PATCH v2 06/13] ovl: deduplicate lowerpath and lowerstack[] Amir Goldstein
2023-04-27 13:05 ` [PATCH v2 07/13] ovl: deduplicate lowerdata " Amir Goldstein
2023-04-27 13:05 ` [PATCH v2 08/13] ovl: remove unneeded goto instructions Amir Goldstein
2023-04-27 13:05 ` [PATCH v2 09/13] ovl: introduce data-only lower layers Amir Goldstein
2023-05-14 19:13 ` Amir Goldstein
2023-05-16 10:18 ` Amir Goldstein
2023-04-27 13:05 ` [PATCH v2 10/13] ovl: implement lookup in data-only layers Amir Goldstein
2023-04-27 13:05 ` [PATCH v2 11/13] ovl: prepare to store lowerdata redirect for lazy lowerdata lookup Amir Goldstein
2023-04-27 13:05 ` Amir Goldstein [this message]
2023-04-27 13:05 ` [PATCH v2 13/13] ovl: implement lazy lookup of lowerdata in data-only layers Amir Goldstein
2023-05-24 17:12 ` [PATCH v2 00/13] Overlayfs lazy lookup of lowerdata Amir Goldstein
2023-05-25 15:21 ` Alexander Larsson
2023-05-25 16:03 ` Amir Goldstein
2023-05-25 16:59 ` Giuseppe Scrivano
2023-05-25 17:27 ` Gao Xiang
2023-05-25 18:03 ` Gao Xiang
2023-05-26 5:12 ` Amir Goldstein
2023-05-26 11:36 ` Alexander Larsson
2023-05-26 18:27 ` Gao Xiang
2023-05-27 14:04 ` Amir Goldstein
2023-05-27 14:30 ` Gao Xiang
2023-05-29 7:22 ` Alexander Larsson
2023-05-30 14:08 ` Miklos Szeredi
2023-05-30 14:15 ` Amir Goldstein
2023-06-09 7:24 ` Miklos Szeredi
2023-06-09 10:54 ` Amir Goldstein
2023-06-09 13:42 ` Amir Goldstein
2023-06-09 13:52 ` Miklos Szeredi
2023-06-17 17:40 ` Amir Goldstein
2023-06-17 19:19 ` Miklos Szeredi
2023-05-30 16:19 ` Christian Brauner
2023-06-09 8:17 ` Alexander Larsson
2023-06-09 9:44 ` Christian Brauner
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=20230427130539.2798797-13-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=alexl@redhat.com \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
/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