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 1/4] ovl: use refcount_t in readdir
Date: Thu, 7 Mar 2024 12:02:05 +0100 [thread overview]
Message-ID: <20240307110217.203064-1-mszeredi@redhat.com> (raw)
At this point this is just a cleanup, since the refcount is also protected
by overlayfs inode lock.
This will change in a following patch.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
fs/overlayfs/readdir.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c
index 0ca8af060b0c..b894a97f8ef8 100644
--- a/fs/overlayfs/readdir.c
+++ b/fs/overlayfs/readdir.c
@@ -13,6 +13,7 @@
#include <linux/security.h>
#include <linux/cred.h>
#include <linux/ratelimit.h>
+#include <linux/refcount.h>
#include "overlayfs.h"
struct ovl_cache_entry {
@@ -30,7 +31,7 @@ struct ovl_cache_entry {
};
struct ovl_dir_cache {
- long refcount;
+ refcount_t refcount;
u64 version;
struct list_head entries;
struct rb_root root;
@@ -243,9 +244,7 @@ static void ovl_cache_put(struct ovl_dir_file *od, struct inode *inode)
{
struct ovl_dir_cache *cache = od->cache;
- WARN_ON(cache->refcount <= 0);
- cache->refcount--;
- if (!cache->refcount) {
+ if (refcount_dec_and_test(&cache->refcount)) {
if (ovl_dir_cache(inode) == cache)
ovl_set_dir_cache(inode, NULL);
@@ -405,8 +404,7 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)
cache = ovl_dir_cache(inode);
if (cache && ovl_inode_version_get(inode) == cache->version) {
- WARN_ON(!cache->refcount);
- cache->refcount++;
+ refcount_inc(&cache->refcount);
return cache;
}
ovl_set_dir_cache(d_inode(dentry), NULL);
@@ -415,7 +413,7 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)
if (!cache)
return ERR_PTR(-ENOMEM);
- cache->refcount = 1;
+ refcount_set(&cache->refcount, 1);
INIT_LIST_HEAD(&cache->entries);
cache->root = RB_ROOT;
--
2.44.0
next 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 Miklos Szeredi [this message]
2024-03-07 11:02 ` [PATCH 2/4] ovl: get rid of iterate wrapper Miklos Szeredi
2024-03-07 11:02 ` [PATCH 3/4] ovl: only lock readdir for accessing the cache Miklos Szeredi
2024-03-07 13:11 ` 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-1-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).