Skip to content

Commit

Permalink
bcache: Fix for when no journal entries are found
Browse files Browse the repository at this point in the history
The journal replay code didn't handle this case, causing it to go into
an infinite loop...

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v3.10
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Kent Overstreet authored and Linus Torvalds committed Sep 24, 2013
1 parent aee6f1c commit c426c4f
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions drivers/md/bcache/journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ int bch_journal_read(struct cache_set *c, struct list_head *list,
bitmap_zero(bitmap, SB_JOURNAL_BUCKETS);
pr_debug("%u journal buckets", ca->sb.njournal_buckets);

/* Read journal buckets ordered by golden ratio hash to quickly
/*
* Read journal buckets ordered by golden ratio hash to quickly
* find a sequence of buckets with valid journal entries
*/
for (i = 0; i < ca->sb.njournal_buckets; i++) {
Expand All @@ -166,18 +167,20 @@ int bch_journal_read(struct cache_set *c, struct list_head *list,
goto bsearch;
}

/* If that fails, check all the buckets we haven't checked
/*
* If that fails, check all the buckets we haven't checked
* already
*/
pr_debug("falling back to linear search");

for (l = 0; l < ca->sb.njournal_buckets; l++) {
if (test_bit(l, bitmap))
continue;

for (l = find_first_zero_bit(bitmap, ca->sb.njournal_buckets);
l < ca->sb.njournal_buckets;
l = find_next_zero_bit(bitmap, ca->sb.njournal_buckets, l + 1))
if (read_bucket(l))
goto bsearch;
}

if (list_empty(list))
continue;
bsearch:
/* Binary search */
m = r = find_next_bit(bitmap, ca->sb.njournal_buckets, l + 1);
Expand All @@ -197,10 +200,12 @@ int bch_journal_read(struct cache_set *c, struct list_head *list,
r = m;
}

/* Read buckets in reverse order until we stop finding more
/*
* Read buckets in reverse order until we stop finding more
* journal entries
*/
pr_debug("finishing up");
pr_debug("finishing up: m %u njournal_buckets %u",
m, ca->sb.njournal_buckets);
l = m;

while (1) {
Expand Down Expand Up @@ -228,9 +233,10 @@ int bch_journal_read(struct cache_set *c, struct list_head *list,
}
}

c->journal.seq = list_entry(list->prev,
struct journal_replay,
list)->j.seq;
if (!list_empty(list))
c->journal.seq = list_entry(list->prev,
struct journal_replay,
list)->j.seq;

return 0;
#undef read_bucket
Expand Down

0 comments on commit c426c4f

Please sign in to comment.