linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] ovl: use refcount_t in readdir
@ 2024-03-07 11:02 Miklos Szeredi
  2024-03-07 11:02 ` [PATCH 2/4] ovl: get rid of iterate wrapper Miklos Szeredi
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Miklos Szeredi @ 2024-03-07 11:02 UTC (permalink / raw)
  To: linux-unionfs; +Cc: Amir Goldstein, linux-fsdevel

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


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-03-11 13:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [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

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).