Skip to content

Commit bb22caf

Browse files
Tang Junhuiaxboe
authored andcommitted
bcache: add a comment in journal bucket reading
Journal bucket is a circular buffer, the bucket can be like YYYNNNYY, which means the first valid journal in the 7th bucket, and the latest valid journal in third bucket, in this case, if we do not try we the zero index first, We may get a valid journal in the 7th bucket, then we call find_next_bit(bitmap,ca->sb.njournal_buckets, l + 1) to get the first invalid bucket after the 7th bucket, because all these buckets is valid, so no bit 1 in bitmap, thus find_next_bit() function would return with ca->sb.njournal_buckets (8). So, after that, bcache only read journal in 7th and 8the bucket, the first to the third buckets are lost. So, it is important to let developer know that, we need to try the zero index at first in the hash-search, and avoid any breaks in future's code modification. [ML: Fixed whitespace & formatting & file permissions] Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn> Signed-off-by: Michael Lyle <mlyle@lyle.org> Reviewed-by: Michael Lyle <mlyle@lyle.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 26c0a26 commit bb22caf

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎drivers/md/bcache/journal.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ int bch_journal_read(struct cache_set *c, struct list_head *list)
170170
* find a sequence of buckets with valid journal entries
171171
*/
172172
for (i = 0; i < ca->sb.njournal_buckets; i++) {
173+
/*
174+
* We must try the index l with ZERO first for
175+
* correctness due to the scenario that the journal
176+
* bucket is circular buffer which might have wrapped
177+
*/
173178
l = (i * 2654435769U) % ca->sb.njournal_buckets;
174179

175180
if (test_bit(l, bitmap))

0 commit comments

Comments
 (0)