Skip to content

Commit 5fa89fb

Browse files
mlyleaxboe
authored andcommitted
bcache: don't write back data if reading it failed
If an IO operation fails, and we didn't successfully read data from the cache, don't writeback invalid/partial data to the backing disk. Signed-off-by: Michael Lyle <mlyle@lyle.org> Reviewed-by: Coly Li <colyli@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 2385010 commit 5fa89fb

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎drivers/md/bcache/writeback.c‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,21 @@ static void write_dirty(struct closure *cl)
179179
struct dirty_io *io = container_of(cl, struct dirty_io, cl);
180180
struct keybuf_key *w = io->bio.bi_private;
181181

182-
dirty_init(w);
183-
bio_set_op_attrs(&io->bio, REQ_OP_WRITE, 0);
184-
io->bio.bi_iter.bi_sector = KEY_START(&w->key);
185-
bio_set_dev(&io->bio, io->dc->bdev);
186-
io->bio.bi_end_io = dirty_endio;
182+
/*
183+
* IO errors are signalled using the dirty bit on the key.
184+
* If we failed to read, we should not attempt to write to the
185+
* backing device. Instead, immediately go to write_dirty_finish
186+
* to clean up.
187+
*/
188+
if (KEY_DIRTY(&w->key)) {
189+
dirty_init(w);
190+
bio_set_op_attrs(&io->bio, REQ_OP_WRITE, 0);
191+
io->bio.bi_iter.bi_sector = KEY_START(&w->key);
192+
bio_set_dev(&io->bio, io->dc->bdev);
193+
io->bio.bi_end_io = dirty_endio;
187194

188-
closure_bio_submit(&io->bio, cl);
195+
closure_bio_submit(&io->bio, cl);
196+
}
189197

190198
continue_at(cl, write_dirty_finish, io->dc->writeback_write_wq);
191199
}

0 commit comments

Comments
 (0)