]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: fix unix io manager invalidation
authorDarrick J. Wong <djwong@kernel.org>
Wed, 21 May 2025 22:35:10 +0000 (15:35 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 23 May 2025 05:10:10 +0000 (01:10 -0400)
flush_cached_blocks does not invalidate clean blocks from the block
cache.  From reading all the call sites, it looks like they all actually
want the cache to be empty on successful return, so adjust the
implementation to do this.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Link: https://lore.kernel.org/r/174786677566.1383760.15330012260577982100.stgit@frogsfrogsfrogs
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/unix_io.c

index 6acce40530764db05a4f649bec86e325511973f1..0ab9de67857c28381d29cd8a5462e416a1224773 100644 (file)
@@ -670,20 +670,24 @@ static errcode_t flush_cached_blocks(io_channel channel,
        if ((flags & FLUSH_NOLOCK) == 0)
                mutex_lock(data, CACHE_MTX);
        for (i=0, cache = data->cache; i < data->cache_size; i++, cache++) {
-               if (!cache->in_use || !cache->dirty)
+               if (!cache->in_use)
                        continue;
-               retval = raw_write_blk(channel, data,
-                                      cache->block, 1, cache->buf,
-                                      RAW_WRITE_NO_HANDLER);
-               if (retval) {
-                       cache->write_err = 1;
-                       errors_found = 1;
-                       retval2 = retval;
-               } else {
-                       cache->dirty = 0;
-                       cache->write_err = 0;
-                       if (flags & FLUSH_INVALIDATE)
-                               cache->in_use = 0;
+               if (cache->dirty) {
+                       retval = raw_write_blk(channel, data,
+                                              cache->block, 1, cache->buf,
+                                              RAW_WRITE_NO_HANDLER);
+                       if (retval) {
+                               cache->write_err = 1;
+                               errors_found = 1;
+                               retval2 = retval;
+                       } else {
+                               cache->dirty = 0;
+                               cache->write_err = 0;
+                               if (flags & FLUSH_INVALIDATE)
+                                       cache->in_use = 0;
+                       }
+               } else if (flags & FLUSH_INVALIDATE) {
+                       cache->in_use = 0;
                }
        }
        if ((flags & FLUSH_NOLOCK) == 0)