From: Darrick J. Wong <djwong@xxxxxxxxxx> 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@xxxxxxxxxx> --- lib/ext2fs/unix_io.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c index dbe748d9c43583..b98c44a84bb0af 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)