[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <175573713041.20753.2528481564012056345.stgit@frogsfrogsfrogs>
Date: Wed, 20 Aug 2025 18:11:15 -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 13/20] cache: return results of a cache flush
From: Darrick J. Wong <djwong@...nel.org>
Modify cache_flush to return whether or not there were errors whilst
flushing the cache.
Signed-off-by: "Darrick J. Wong" <djwong@...nel.org>
---
lib/support/cache.h | 4 ++--
lib/support/cache.c | 11 +++++++----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/lib/support/cache.h b/lib/support/cache.h
index e8f1c82ef7869c..8d39ca5c02a285 100644
--- a/lib/support/cache.h
+++ b/lib/support/cache.h
@@ -58,7 +58,7 @@ typedef void *cache_key_t;
typedef void (*cache_walk_t)(struct cache *c, struct cache_node *cn, void *d);
typedef struct cache_node * (*cache_node_alloc_t)(struct cache *c, cache_key_t k);
-typedef int (*cache_node_flush_t)(struct cache *c, struct cache_node *cn);
+typedef bool (*cache_node_flush_t)(struct cache *c, struct cache_node *cn);
typedef void (*cache_node_relse_t)(struct cache *c, struct cache_node *cn);
typedef unsigned int (*cache_node_hash_t)(cache_key_t, unsigned int,
unsigned int);
@@ -132,7 +132,7 @@ int cache_init(int flags, unsigned int size,
void cache_destroy(struct cache *cache);
void cache_walk(struct cache *cache, cache_walk_t fn, void *data);
void cache_purge(struct cache *);
-void cache_flush(struct cache *);
+bool cache_flush(struct cache *cache);
int cache_node_get(struct cache *, cache_key_t, struct cache_node **);
void cache_node_put(struct cache *, struct cache_node *);
diff --git a/lib/support/cache.c b/lib/support/cache.c
index 49568ffa6de2e4..fa07b4ad8222d2 100644
--- a/lib/support/cache.c
+++ b/lib/support/cache.c
@@ -631,18 +631,19 @@ cache_purge(
}
/*
- * Flush all nodes in the cache to disk.
+ * Flush all nodes in the cache to disk. Returns true if the flush succeeded.
*/
-void
+bool
cache_flush(
struct cache *cache)
{
struct cache_hash *hash;
struct cache_node *node;
int i;
+ bool still_dirty = false;
if (!cache->flush)
- return;
+ return true;
for (i = 0; i < cache->c_hashsize; i++) {
hash = &cache->c_hash[i];
@@ -650,11 +651,13 @@ cache_flush(
pthread_mutex_lock(&hash->ch_mutex);
list_for_each_entry(node, &hash->ch_list, cn_hash) {
pthread_mutex_lock(&node->cn_mutex);
- cache->flush(cache, node);
+ still_dirty |= cache->flush(cache, node);
pthread_mutex_unlock(&node->cn_mutex);
}
pthread_mutex_unlock(&hash->ch_mutex);
}
+
+ return !still_dirty;
}
#define HASH_REPORT (3 * HASH_CACHE_RATIO)
Powered by blists - more mailing lists