From: Miklos Szeredi <mszeredi@redhat.com>
To: linux-unionfs@vger.kernel.org
Cc: Amir Goldstein <amir73il@gmail.com>, linux-fsdevel@vger.kernel.org
Subject: [PATCH 3/4] ovl: only lock readdir for accessing the cache
Date: Thu, 7 Mar 2024 12:02:07 +0100 [thread overview]
Message-ID: <20240307110217.203064-3-mszeredi@redhat.com> (raw)
In-Reply-To: <20240307110217.203064-1-mszeredi@redhat.com>
The only reason parallel readdirs cannot run on the same inode is shared
access to the readdir cache.
Move lock/unlock to only protect the cache. Exception is the refcount
which now uses atomic ops.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
fs/overlayfs/readdir.c | 34 ++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c
index edee9f86f469..b98e0d17f40e 100644
--- a/fs/overlayfs/readdir.c
+++ b/fs/overlayfs/readdir.c
@@ -245,8 +245,10 @@ static void ovl_cache_put(struct ovl_dir_file *od, struct inode *inode)
struct ovl_dir_cache *cache = od->cache;
if (refcount_dec_and_test(&cache->refcount)) {
+ ovl_inode_lock(inode);
if (ovl_dir_cache(inode) == cache)
ovl_set_dir_cache(inode, NULL);
+ ovl_inode_unlock(inode);
ovl_cache_free(&cache->entries);
kfree(cache);
@@ -733,12 +735,18 @@ static int ovl_iterate_real(struct file *file, struct dir_context *ctx)
}
if (ovl_is_impure_dir(file)) {
+ ovl_inode_lock(file_inode(file));
rdt.cache = ovl_cache_get_impure(&file->f_path);
- if (IS_ERR(rdt.cache))
+ if (IS_ERR(rdt.cache)) {
+ ovl_inode_unlock(file_inode(file));
return PTR_ERR(rdt.cache);
+ }
}
err = iterate_dir(od->realfile, &rdt.ctx);
+
+ if (rdt.cache)
+ ovl_inode_unlock(file_inode(file));
ctx->pos = rdt.ctx.pos;
return err;
@@ -758,7 +766,6 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)
if (!ctx->pos)
ovl_dir_reset(file);
- ovl_inode_lock(file_inode(file));
if (od->is_real) {
/*
* If parent is merge, then need to adjust d_ino for '..', if
@@ -773,9 +780,10 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)
} else {
err = iterate_dir(od->realfile, ctx);
}
- goto out;
+ goto out_revert;
}
+ ovl_inode_lock(file_inode(file));
if (!od->cache) {
struct ovl_dir_cache *cache;
@@ -808,6 +816,7 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)
err = 0;
out:
ovl_inode_unlock(file_inode(file));
+out_revert:
revert_creds(old_cred);
return err;
}
@@ -817,7 +826,6 @@ static loff_t ovl_dir_llseek(struct file *file, loff_t offset, int origin)
loff_t res;
struct ovl_dir_file *od = file->private_data;
- ovl_inode_lock(file_inode(file));
if (!file->f_pos)
ovl_dir_reset(file);
@@ -834,21 +842,22 @@ static loff_t ovl_dir_llseek(struct file *file, loff_t offset, int origin)
case SEEK_SET:
break;
default:
- goto out_unlock;
+ goto out;
}
if (offset < 0)
- goto out_unlock;
+ goto out;
if (offset != file->f_pos) {
file->f_pos = offset;
- if (od->cache)
+ if (od->cache) {
+ ovl_inode_lock(file_inode(file));
ovl_seek_cursor(od, offset);
+ ovl_inode_unlock(file_inode(file));
+ }
}
res = offset;
}
-out_unlock:
- ovl_inode_unlock(file_inode(file));
-
+out:
return res;
}
@@ -930,11 +939,8 @@ static int ovl_dir_release(struct inode *inode, struct file *file)
{
struct ovl_dir_file *od = file->private_data;
- if (od->cache) {
- ovl_inode_lock(inode);
+ if (od->cache)
ovl_cache_put(od, inode);
- ovl_inode_unlock(inode);
- }
fput(od->realfile);
if (od->upperfile)
fput(od->upperfile);
--
2.44.0
next prev parent reply other threads:[~2024-03-07 11:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-07 11:02 [PATCH 1/4] ovl: use refcount_t in readdir Miklos Szeredi
2024-03-07 11:02 ` [PATCH 2/4] ovl: get rid of iterate wrapper Miklos Szeredi
2024-03-07 11:02 ` Miklos Szeredi [this message]
2024-03-07 13:11 ` [PATCH 3/4] ovl: only lock readdir for accessing the cache Amir Goldstein
2024-03-07 14:09 ` Miklos Szeredi
2024-03-07 16:13 ` Miklos Szeredi
2024-03-07 17:31 ` Amir Goldstein
2024-03-11 13:52 ` Christian Brauner
2024-03-07 11:02 ` [PATCH 4/4] ovl: clean up struct ovl_dir_cache use outside readdir.c 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=20240307110217.203064-3-mszeredi@redhat.com \
--to=mszeredi@redhat.com \
--cc=amir73il@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
/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).