[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <175573713060.20753.7102446050470625029.stgit@frogsfrogsfrogs>
Date: Wed, 20 Aug 2025 18:11:31 -0700
From: "Darrick J. Wong" <djwong@...nel.org>
To: tytso@....edu
Cc: John@...ves.net, bernd@...ernd.com, linux-fsdevel@...r.kernel.org,
linux-ext4@...r.kernel.org, miklos@...redi.hu, amir73il@...il.com,
joannelkoong@...il.com, neal@...pa.dev
Subject: [PATCH 14/20] cache: add a "get only if incore" flag to
cache_node_get
From: Darrick J. Wong <djwong@...nel.org>
Add a new flag to cache_node_get so that callers can specify that they
only want the cache to return an existing cache node, and not create a
new one.
Signed-off-by: "Darrick J. Wong" <djwong@...nel.org>
---
lib/support/cache.h | 5 ++++-
lib/support/cache.c | 7 +++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/lib/support/cache.h b/lib/support/cache.h
index 8d39ca5c02a285..98b2182d49a6e0 100644
--- a/lib/support/cache.h
+++ b/lib/support/cache.h
@@ -134,7 +134,10 @@ void cache_walk(struct cache *cache, cache_walk_t fn, void *data);
void cache_purge(struct cache *);
bool cache_flush(struct cache *cache);
-int cache_node_get(struct cache *, cache_key_t, struct cache_node **);
+/* don't allocate a new node */
+#define CACHE_GET_INCORE (1U << 0)
+int cache_node_get(struct cache *c, cache_key_t key, unsigned int cgflags,
+ struct cache_node **nodep);
void cache_node_put(struct cache *, struct cache_node *);
void cache_node_set_priority(struct cache *, struct cache_node *, int);
int cache_node_get_priority(struct cache_node *);
diff --git a/lib/support/cache.c b/lib/support/cache.c
index fa07b4ad8222d2..9da6c59b3b6391 100644
--- a/lib/support/cache.c
+++ b/lib/support/cache.c
@@ -403,6 +403,7 @@ int
cache_node_get(
struct cache *cache,
cache_key_t key,
+ unsigned int cgflags,
struct cache_node **nodep)
{
struct cache_hash *hash;
@@ -456,6 +457,12 @@ cache_node_get(
continue; /* what the hell, gcc? */
}
pthread_mutex_unlock(&hash->ch_mutex);
+
+ if (cgflags & CACHE_GET_INCORE) {
+ *nodep = NULL;
+ return 0;
+ }
+
/*
* not found, allocate a new entry
*/
Powered by blists - more mailing lists