Commit 3a646fd7 authored by Dongbo Cao's avatar Dongbo Cao Committed by Jens Axboe

bcache: panic fix for making cache device

when the nbuckets of cache device is smaller than 1024, making cache
device will trigger BUG_ON in kernel, add a condition to avoid this.
Reported-by: default avatarnitroxis <n@nxs.re>
Signed-off-by: default avatarDongbo Cao <cdbdyx@163.com>
Signed-off-by: default avatarColy Li <colyli@suse.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent f6027bca
...@@ -2071,6 +2071,11 @@ static int cache_alloc(struct cache *ca) ...@@ -2071,6 +2071,11 @@ static int cache_alloc(struct cache *ca)
*/ */
btree_buckets = ca->sb.njournal_buckets ?: 8; btree_buckets = ca->sb.njournal_buckets ?: 8;
free = roundup_pow_of_two(ca->sb.nbuckets) >> 10; free = roundup_pow_of_two(ca->sb.nbuckets) >> 10;
if (!free) {
ret = -EPERM;
err = "ca->sb.nbuckets is too small";
goto err_free;
}
if (!init_fifo(&ca->free[RESERVE_BTREE], btree_buckets, if (!init_fifo(&ca->free[RESERVE_BTREE], btree_buckets,
GFP_KERNEL)) { GFP_KERNEL)) {
...@@ -2148,6 +2153,7 @@ static int cache_alloc(struct cache *ca) ...@@ -2148,6 +2153,7 @@ static int cache_alloc(struct cache *ca)
err_prio_alloc: err_prio_alloc:
free_fifo(&ca->free[RESERVE_BTREE]); free_fifo(&ca->free[RESERVE_BTREE]);
err_btree_alloc: err_btree_alloc:
err_free:
module_put(THIS_MODULE); module_put(THIS_MODULE);
if (err) if (err)
pr_notice("error %s: %s", ca->cache_dev_name, err); pr_notice("error %s: %s", ca->cache_dev_name, err);
...@@ -2177,6 +2183,8 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page, ...@@ -2177,6 +2183,8 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page,
blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
if (ret == -ENOMEM) if (ret == -ENOMEM)
err = "cache_alloc(): -ENOMEM"; err = "cache_alloc(): -ENOMEM";
else if (ret == -EPERM)
err = "cache_alloc(): cache device is too small";
else else
err = "cache_alloc(): unknown error"; err = "cache_alloc(): unknown error";
goto err; goto err;
......
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