From: Darrick J. Wong Date: Wed, 21 May 2025 22:35:10 +0000 (-0700) Subject: libext2fs: fix unix io manager invalidation X-Git-Tag: v1.47.3-rc1~63 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3f148554686027f087e16dd45735d02e9bc803c1;p=thirdparty%2Fe2fsprogs.git libext2fs: fix unix io manager invalidation 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 Link: https://lore.kernel.org/r/174786677566.1383760.15330012260577982100.stgit@frogsfrogsfrogs Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c index 6acce405..0ab9de67 100644 --- a/lib/ext2fs/unix_io.c +++ b/lib/ext2fs/unix_io.c @@ -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)