bcache: fix fifo index swapping condition in journal_pin_cmp()
authorColy Li <colyli@suse.de>
Wed, 13 Nov 2019 08:03:15 +0000 (16:03 +0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 13 Nov 2019 22:42:49 +0000 (15:42 -0700)
commitc0e0954e909c17b43d176ab219fc598964616ae6
tree0f16001bfb90ec3539dc6fa0498d2d4a61b1c1d9
parente2a7b9f4a19d3ecb8833ecba9e111e118e17f36c
bcache: fix fifo index swapping condition in journal_pin_cmp()

Fifo structure journal.pin is implemented by a cycle buffer, if the back
index reaches highest location of the cycle buffer, it will be swapped
to 0. Once the swapping happens, it means a smaller fifo index might be
associated to a newer journal entry. So the btree node with oldest
journal entry won't be selected in bch_btree_leaf_dirty() to reference
the dirty B+tree leaf node. This problem may cause bcache journal won't
protect unflushed oldest B+tree dirty leaf node in power failure, and
this B+tree leaf node is possible to beinconsistent after reboot from
power failure.

This patch fixes the fifo index comparing logic in journal_pin_cmp(),
to avoid potential corrupted B+tree leaf node when the back index of
journal pin is swapped.

Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/btree.c
drivers/md/bcache/journal.h