linux/drivers/md/bcache
Tang Junhui ab733741f6 bcache: treat stale && dirty keys as bad keys
commit 58ac323084 upstream.

Stale && dirty keys can be produced in the follow way:
After writeback in write_dirty_finish(), dirty keys k1 will
replace by clean keys k2
==>ret = bch_btree_insert(dc->disk.c, &keys, NULL, &w->key);
==>btree_insert_fn(struct btree_op *b_op, struct btree *b)
==>static int bch_btree_insert_node(struct btree *b,
       struct btree_op *op,
       struct keylist *insert_keys,
       atomic_t *journal_ref,
Then two steps:
A) update k1 to k2 in btree node memory;
   bch_btree_insert_keys(b, op, insert_keys, replace_key)
B) Write the bset(contains k2) to cache disk by a 30s delay work
   bch_btree_leaf_dirty(b, journal_ref).
But before the 30s delay work write the bset to cache device,
these things happened:
A) GC works, and reclaim the bucket k2 point to;
B) Allocator works, and invalidate the bucket k2 point to,
   and increase the gen of the bucket, and place it into free_inc
   fifo;
C) Until now, the 30s delay work still does not finish work,
   so in the disk, the key still is k1, it is dirty and stale
   (its gen is smaller than the gen of the bucket). and then the
   machine power off suddenly happens;
D) When the machine power on again, after the btree reconstruction,
   the stale dirty key appear.

In bch_extent_bad(), when expensive_debug_checks is off, it would
treat the dirty key as good even it is stale keys, and it would
cause bellow probelms:
A) In read_dirty() it would cause machine crash:
   BUG_ON(ptr_stale(dc->disk.c, &w->key, 0));
B) It could be worse when reads hits stale dirty keys, it would
   read old incorrect data.

This patch tolerate the existence of these stale && dirty keys,
and treat them as bad key in bch_extent_bad().

(Coly Li: fix indent which was modified by sender's email client)

Signed-off-by: Tang Junhui <tang.junhui.linux@gmail.com>
Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
History 2019-07-09 22:03:57 +01:00
..
alloc.c bcache: check ca->alloc_thread initialized before wake up it 2018-02-13 18:42:07 +00:00
bcache.h bcache: add separate workqueue for journal_write to avoid deadlock 2018-12-16 22:09:27 +00:00
bset.c bcache: Fix another compiler warning on m68k 2014-02-18 08:55:05 -08:00
bset.h bcache: Add bch_keylist_init_single() 2014-03-18 12:22:36 -07:00
btree.c bcache: fix miss key refill->end in writeback 2019-02-11 17:53:29 +00:00
btree.h bcache: Kill unused freelist 2014-03-18 12:23:36 -07:00
closure.c bcache: kill closure locking code 2014-01-08 13:05:08 -08:00
closure.h bcache: don't embed 'return' statements in closure macros 2018-12-16 22:09:26 +00:00
debug.c bcache: Convert debug code to btree_keys 2014-01-08 13:05:13 -08:00
debug.h bcache: Convert debug code to btree_keys 2014-01-08 13:05:13 -08:00
extents.c bcache: treat stale && dirty keys as bad keys 2019-07-09 22:03:57 +01:00
extents.h bcache: Convert debug code to btree_keys 2014-01-08 13:05:13 -08:00
io.c bcache: don't embed 'return' statements in closure macros 2018-12-16 22:09:26 +00:00
journal.c bcache: add separate workqueue for journal_write to avoid deadlock 2018-12-16 22:09:27 +00: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 bcache: stop moving_gc marking buckets that can't be moved. 2014-03-18 12:22:34 -07:00
request.c bcache: fix wrong cache_misses statistics 2019-02-11 17:53:29 +00: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: add separate workqueue for journal_write to avoid deadlock 2018-12-16 22:09:27 +00:00
sysfs.c bcache: Correct return value for sysfs attach errors 2017-11-26 13:50:34 +00: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-11-26 13:50:35 +00:00
util.h bcache: Convert debug code to btree_keys 2014-01-08 13:05:13 -08:00
writeback.c bcache: initialize dirty stripes in flash_dev_run() 2017-11-26 13:50:35 +00:00
writeback.h bcache: never writeback a discard operation 2019-07-09 22:03:56 +01:00