Commit c426c4fd authored by Kent Overstreet's avatar Kent Overstreet Committed by Linus Torvalds

bcache: Fix for when no journal entries are found

The journal replay code didn't handle this case, causing it to go into
an infinite loop...
Signed-off-by: default avatarKent Overstreet <kmo@daterainc.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v3.10
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent aee6f1cf
...@@ -153,7 +153,8 @@ int bch_journal_read(struct cache_set *c, struct list_head *list, ...@@ -153,7 +153,8 @@ int bch_journal_read(struct cache_set *c, struct list_head *list,
bitmap_zero(bitmap, SB_JOURNAL_BUCKETS); bitmap_zero(bitmap, SB_JOURNAL_BUCKETS);
pr_debug("%u journal buckets", ca->sb.njournal_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 * find a sequence of buckets with valid journal entries
*/ */
for (i = 0; i < ca->sb.njournal_buckets; i++) { for (i = 0; i < ca->sb.njournal_buckets; i++) {
...@@ -166,18 +167,20 @@ int bch_journal_read(struct cache_set *c, struct list_head *list, ...@@ -166,18 +167,20 @@ int bch_journal_read(struct cache_set *c, struct list_head *list,
goto bsearch; 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 * already
*/ */
pr_debug("falling back to linear search"); pr_debug("falling back to linear search");
for (l = 0; l < ca->sb.njournal_buckets; l++) { for (l = find_first_zero_bit(bitmap, ca->sb.njournal_buckets);
if (test_bit(l, bitmap)) l < ca->sb.njournal_buckets;
continue; l = find_next_zero_bit(bitmap, ca->sb.njournal_buckets, l + 1))
if (read_bucket(l)) if (read_bucket(l))
goto bsearch; goto bsearch;
}
if (list_empty(list))
continue;
bsearch: bsearch:
/* Binary search */ /* Binary search */
m = r = find_next_bit(bitmap, ca->sb.njournal_buckets, l + 1); m = r = find_next_bit(bitmap, ca->sb.njournal_buckets, l + 1);
...@@ -197,10 +200,12 @@ int bch_journal_read(struct cache_set *c, struct list_head *list, ...@@ -197,10 +200,12 @@ int bch_journal_read(struct cache_set *c, struct list_head *list,
r = m; r = m;
} }
/* Read buckets in reverse order until we stop finding more /*
* Read buckets in reverse order until we stop finding more
* journal entries * journal entries
*/ */
pr_debug("finishing up"); pr_debug("finishing up: m %u njournal_buckets %u",
m, ca->sb.njournal_buckets);
l = m; l = m;
while (1) { while (1) {
...@@ -228,9 +233,10 @@ int bch_journal_read(struct cache_set *c, struct list_head *list, ...@@ -228,9 +233,10 @@ int bch_journal_read(struct cache_set *c, struct list_head *list,
} }
} }
c->journal.seq = list_entry(list->prev, if (!list_empty(list))
struct journal_replay, c->journal.seq = list_entry(list->prev,
list)->j.seq; struct journal_replay,
list)->j.seq;
return 0; return 0;
#undef read_bucket #undef read_bucket
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment