Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5fa89fb9 authored by Michael Lyle's avatar Michael Lyle Committed by Jens Axboe
Browse files

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: default avatarMichael Lyle <mlyle@lyle.org>
Reviewed-by: default avatarColy Li <colyli@suse.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 23850102
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -179,6 +179,13 @@ static void write_dirty(struct closure *cl)
	struct dirty_io *io = container_of(cl, struct dirty_io, cl);
	struct keybuf_key *w = io->bio.bi_private;

	/*
	 * IO errors are signalled using the dirty bit on the key.
	 * If we failed to read, we should not attempt to write to the
	 * backing device.  Instead, immediately go to write_dirty_finish
	 * to clean up.
	 */
	if (KEY_DIRTY(&w->key)) {
		dirty_init(w);
		bio_set_op_attrs(&io->bio, REQ_OP_WRITE, 0);
		io->bio.bi_iter.bi_sector = KEY_START(&w->key);
@@ -186,6 +193,7 @@ static void write_dirty(struct closure *cl)
		io->bio.bi_end_io	= dirty_endio;

		closure_bio_submit(&io->bio, cl);
	}

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