From: Josef Bacik <josef@toxicpanda.com>
To: Miklos Szeredi <miklos@szeredi.hu>,
Amir Goldstein <amir73il@gmail.com>,
Christian Brauner <brauner@kernel.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
Christoph Hellwig <hch@infradead.org>,
Chris Mason <mason@kernel.org>,
Chengguang Xu <cgxu519@mykernel.net>,
linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, Josef Bacik <josef@toxicpanda.com>
Subject: [PATCH v2 07/10] ovl: look up overlay inodes with a key structure
Date: Thu, 29 Oct 2026 01:09:21 +0000 [thread overview]
Message-ID: <20261029-b4-ovl-containerized-sync-v2-7-4e9f08e4a052@toxicpanda.com> (raw)
In-Reply-To: <20261029-b4-ovl-containerized-sync-v2-0-4e9f08e4a052@toxicpanda.com>
A following patch adds fake overlay inodes, which are hashed by the same
real inode as an overlay inode or a trap inode. Pass a key with the real
inode and the kind of inode to ovl_inode_test() and ovl_inode_set(), so
that all lookups share one test function.
No functional change intended.
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
fs/overlayfs/inode.c | 57 ++++++++++++++++++++++++++++++++++++++----------
fs/overlayfs/overlayfs.h | 5 +++++
2 files changed, 51 insertions(+), 11 deletions(-)
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index 5895ee5aa771..88cec47d0bc8 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -1069,17 +1069,50 @@ struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev)
return inode;
}
+/*
+ * An overlay inode is hashed by a real inode. A real inode can have a fake
+ * overlay inode next to its overlay inode or its trap inode.
+ */
+struct ovl_inode_key {
+ struct inode *real;
+ bool fake;
+};
+
static int ovl_inode_test(struct inode *inode, void *data)
{
- return inode->i_private == data;
+ struct ovl_inode_key *key = data;
+
+ return inode->i_private == key->real &&
+ ovl_test_flag(OVL_FAKE, inode) == key->fake;
}
static int ovl_inode_set(struct inode *inode, void *data)
{
- inode->i_private = data;
+ struct ovl_inode_key *key = data;
+
+ inode->i_private = key->real;
+ if (key->fake)
+ ovl_set_flag(OVL_FAKE, inode);
return 0;
}
+static struct inode *ovl_ilookup(struct super_block *sb, struct inode *real,
+ bool fake)
+{
+ struct ovl_inode_key key = { .real = real, .fake = fake };
+
+ return ilookup5(sb, (unsigned long)real, ovl_inode_test, &key);
+}
+
+static struct inode *ovl_iget_locked(struct super_block *sb, struct inode *real,
+ bool fake)
+{
+ struct ovl_inode_key key = { .real = real, .fake = fake };
+
+ return iget5_locked(sb, (unsigned long)real, ovl_inode_test,
+ ovl_inode_set, &key);
+}
+
static bool ovl_verify_inode(struct inode *inode, struct dentry *lowerdentry,
struct dentry *upperdentry, bool strict)
{
@@ -1123,7 +1156,7 @@ struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real,
{
struct inode *inode, *key = d_inode(real);
- inode = ilookup5(sb, (unsigned long) key, ovl_inode_test, key);
+ inode = ovl_ilookup(sb, key, false);
if (!inode)
return NULL;
@@ -1142,7 +1175,7 @@ bool ovl_lookup_trap_inode(struct super_block *sb, struct dentry *dir)
struct inode *trap;
bool res;
- trap = ilookup5(sb, (unsigned long) key, ovl_inode_test, key);
+ trap = ovl_ilookup(sb, key, false);
if (!trap)
return false;
@@ -1166,8 +1199,7 @@ struct inode *ovl_get_trap_inode(struct super_block *sb, struct dentry *dir)
if (!d_is_dir(dir))
return ERR_PTR(-ENOTDIR);
- trap = iget5_locked(sb, (unsigned long) key, ovl_inode_test,
- ovl_inode_set, key);
+ trap = ovl_iget_locked(sb, key, false);
if (!trap)
return ERR_PTR(-ENOMEM);
@@ -1218,12 +1250,15 @@ static bool ovl_hash_bylower(struct super_block *sb, struct dentry *upper,
}
static struct inode *ovl_iget5(struct super_block *sb, struct inode *newinode,
- struct inode *key)
+ struct inode *real)
{
- return newinode ? inode_insert5(newinode, (unsigned long) key,
- ovl_inode_test, ovl_inode_set, key) :
- iget5_locked(sb, (unsigned long) key,
- ovl_inode_test, ovl_inode_set, key);
+ struct ovl_inode_key key = { .real = real };
+
+ if (!newinode)
+ return ovl_iget_locked(sb, real, false);
+
+ return inode_insert5(newinode, (unsigned long)real, ovl_inode_test,
+ ovl_inode_set, &key);
}
struct inode *ovl_get_inode(struct super_block *sb,
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index d3a897e46ccb..f884e6695d2c 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -66,6 +66,11 @@ enum ovl_inode_flag {
OVL_CONST_INO,
OVL_HAS_DIGEST,
OVL_VERIFIED_DIGEST,
+ /*
+ * A fake inode: not the overlay inode or the trap inode of the real
+ * inode that it is hashed by.
+ */
+ OVL_FAKE,
};
enum ovl_entry_flag {
--
2.55.0
next prev parent reply other threads:[~2026-10-29 1:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 1:09 [PATCH v2 00/10] ovl: only sync what was written through the overlay Josef Bacik
2026-10-29 1:09 ` [PATCH v2 01/10] ovl: setup overlayfs' private bdi Josef Bacik
2026-10-29 1:09 ` [PATCH v2 02/10] ovl: make the root inode appear hashed Josef Bacik
2026-10-29 1:09 ` [PATCH v2 03/10] ovl: mark the overlay inode dirty on modification Josef Bacik
2026-10-29 1:09 ` [PATCH v2 04/10] ovl: implement overlayfs' own ->write_inode operation Josef Bacik
2026-10-29 1:09 ` [PATCH v2 05/10] ovl: cache dirty overlayfs' inode Josef Bacik
2026-10-29 1:09 ` [PATCH v2 06/10] ovl: handle lazytime on the upper filesystem Josef Bacik
2026-10-29 1:09 ` Josef Bacik [this message]
2026-10-29 1:09 ` [PATCH v2 08/10] ovl: pass the ovl_fs to ovl_do_rename_rd() Josef Bacik
2026-10-29 1:09 ` [PATCH v2 09/10] ovl: put modified upper inodes on the dirty list Josef Bacik
2026-10-29 1:09 ` [PATCH v2 10/10] ovl: implement containerized syncfs for overlayfs Josef Bacik
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=20261029-b4-ovl-containerized-sync-v2-7-4e9f08e4a052@toxicpanda.com \
--to=josef@toxicpanda.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=cgxu519@mykernel.net \
--cc=hch@infradead.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=mason@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
all inboxes | Powered by JetHome®