dm-log-writes records write completions even when the underlying device
reports an I/O error.  The log can then contain data for writes that did
not actually reach the backing device.

That makes replay and diagnostics disagree with the state of the lower
device after an error.

Only record completed writes after the lower layer reports success.

Assisted-by: Codex:gpt-5.5-cyber-preview
Signed-off-by: Samuel Moelius <[email protected]>
---
 drivers/md/dm-log-writes.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/md/dm-log-writes.c b/drivers/md/dm-log-writes.c
index c72e07c3f5a0..e5c4b9df5d9d 100644
--- a/drivers/md/dm-log-writes.c
+++ b/drivers/md/dm-log-writes.c
@@ -775,6 +775,13 @@ static int normal_end_io(struct dm_target *ti, struct bio 
*bio,
                unsigned long flags;
 
                spin_lock_irqsave(&lc->blocks_lock, flags);
+               if (*error) {
+                       if (block->flags & LOG_FLUSH_FLAG)
+                               list_splice_init(&block->list, 
&lc->unflushed_blocks);
+                       spin_unlock_irqrestore(&lc->blocks_lock, flags);
+                       free_pending_block(lc, block);
+                       return DM_ENDIO_DONE;
+               }
                if (block->flags & LOG_FLUSH_FLAG) {
                        list_splice_tail_init(&block->list, 
&lc->logging_blocks);
                        list_add_tail(&block->list, &lc->logging_blocks);
-- 
2.43.0


Reply via email to