linux/drivers/md/bcache
Rui Hua 9db9b5f2b1 bcache: recover data from backing when data is clean
commit e393aa2446 upstream.

When we send a read request and hit the clean data in cache device, there
is a situation called cache read race in bcache(see the commit in the tail
of cache_look_up(), the following explaination just copy from there):
The bucket we're reading from might be reused while our bio is in flight,
and we could then end up reading the wrong data. We guard against this
by checking (in bch_cache_read_endio()) if the pointer is stale again;
if so, we treat it as an error (s->iop.error = -EINTR) and reread from
the backing device (but we don't pass that error up anywhere)

It should be noted that cache read race happened under normal
circumstances, not the circumstance when SSD failed, it was counted
and shown in  /sys/fs/bcache/XXX/internal/cache_read_races.

Without this patch, when we use writeback mode, we will never reread from
the backing device when cache read race happened, until the whole cache
device is clean, because the condition
(s->recoverable && (dc && !atomic_read(&dc->has_dirty))) is false in
cached_dev_read_error(). In this situation, the s->iop.error(= -EINTR)
will be passed up, at last, user will receive -EINTR when it's bio end,
this is not suitable, and wield to up-application.

In this patch, we use s->read_dirty_data to judge whether the read
request hit dirty data in cache device, it is safe to reread data from
the backing device when the read request hit clean data. This can not
only handle cache read race, but also recover data when failed read
request from cache device.

[edited by mlyle to fix up whitespace, commit log title, comment
spelling]

Fixes: d59b237959 ("bcache: only permit to recovery read error when cache device is clean")
Signed-off-by: Hua Rui <huarui.dev@gmail.com>
Reviewed-by: Michael Lyle <mlyle@lyle.org>
Reviewed-by: Coly Li <colyli@suse.de>
Signed-off-by: Michael Lyle <mlyle@lyle.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2017-12-09 22:01:46 +01:00
..
alloc.c bcache: Fix building error on MIPS 2017-12-05 11:24:34 +01:00
bcache.h bcache: fix for gc and write-back race 2017-09-27 14:39:25 +02:00
bset.c bcache: Allocate bounce buffers with GFP_NOWAIT 2014-08-04 15:23:03 -07:00
bset.h bcache: fix typo in bch_bkey_equal_header 2014-08-04 15:23:03 -07:00
btree.c bcache: Make gc wakeup sane, remove set_task_state() 2017-02-23 17:44:36 +01:00
btree.h bcache: Make gc wakeup sane, remove set_task_state() 2017-02-23 17:44:36 +01:00
closure.c bcache: update document info 2016-07-05 11:34:49 -06:00
closure.h bcache: update document info 2016-07-05 11:34:49 -06:00
debug.c block: export bio_free_pages to other modules 2016-09-22 07:48:03 -06:00
debug.h bcache: Convert debug code to btree_keys 2014-01-08 13:05:13 -08:00
extents.c bcache: Fix building error on MIPS 2017-12-05 11:24:34 +01:00
extents.h bcache: Fix a journal replay bug 2014-08-04 15:23:02 -07:00
io.c block: simplify and cleanup bvec pool handling 2016-07-20 17:37:02 -06:00
journal.c bcache: Fix building error on MIPS 2017-12-05 11:24:34 +01:00
journal.h bcache: Fix a shutdown bug 2014-02-25 18:42:49 -08:00
Kconfig bcache: Kill dead cgroup code 2014-03-18 12:22:35 -07:00
Makefile bcache: Abstract out stuff needed for sorting 2014-01-08 13:05:12 -08:00
movinggc.c block: export bio_free_pages to other modules 2016-09-22 07:48:03 -06:00
request.c bcache: recover data from backing when data is clean 2017-12-09 22:01:46 +01:00
request.h bcache: Kill dead cgroup code 2014-03-18 12:22:35 -07:00
stats.c bcache: Kill dead cgroup code 2014-03-18 12:22:35 -07:00
stats.h bcache: Break up struct search 2013-11-10 21:56:32 -08:00
super.c bcache: fix for gc and write-back race 2017-09-27 14:39:25 +02:00
sysfs.c bcache: Correct return value for sysfs attach errors 2017-09-27 14:39:25 +02:00
sysfs.h bcache: Don't export utility code, prefix with bch_ 2013-03-28 12:50:55 -06:00
trace.c bcache: Better alloc tracepoints 2014-03-18 12:22:35 -07:00
util.c bcache: fix bch_hprint crash and improve output 2017-09-27 14:39:25 +02:00
util.h bcache: remove driver private bio splitting code 2015-08-13 12:31:40 -06:00
writeback.c bcache: fix for gc and write-back race 2017-09-27 14:39:25 +02:00
writeback.h bcache: correct cache_dirty_target in __update_writeback_rate() 2017-09-27 14:39:24 +02:00