Skip to content

Commit

Permalink
bcache: disassemble the big if() checks in bch_cache_set_alloc()
Browse files Browse the repository at this point in the history
In bch_cache_set_alloc() there is a big if() checks combined by 11 items
together. When this big if() statement fails, it is difficult to tell
exactly which item fails indeed.

This patch disassembles this big if() checks into 11 single if() checks,
which makes code debug more easier.

Signed-off-by: Coly Li <colyli@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Coly Li authored and Jens Axboe committed Jul 25, 2020
1 parent c557a5f commit a42d3c6
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions drivers/md/bcache/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1873,21 +1873,43 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
iter_size = (sb->bucket_size / sb->block_size + 1) *
sizeof(struct btree_iter_set);

if (!(c->devices = kcalloc(c->nr_uuids, sizeof(void *), GFP_KERNEL)) ||
mempool_init_slab_pool(&c->search, 32, bch_search_cache) ||
mempool_init_kmalloc_pool(&c->bio_meta, 2,
sizeof(struct bbio) + sizeof(struct bio_vec) *
bucket_pages(c)) ||
mempool_init_kmalloc_pool(&c->fill_iter, 1, iter_size) ||
bioset_init(&c->bio_split, 4, offsetof(struct bbio, bio),
BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER) ||
!(c->uuids = alloc_bucket_pages(GFP_KERNEL, c)) ||
!(c->moving_gc_wq = alloc_workqueue("bcache_gc",
WQ_MEM_RECLAIM, 0)) ||
bch_journal_alloc(c) ||
bch_btree_cache_alloc(c) ||
bch_open_buckets_alloc(c) ||
bch_bset_sort_state_init(&c->sort, ilog2(c->btree_pages)))
c->devices = kcalloc(c->nr_uuids, sizeof(void *), GFP_KERNEL);
if (!c->devices)
goto err;

if (mempool_init_slab_pool(&c->search, 32, bch_search_cache))
goto err;

if (mempool_init_kmalloc_pool(&c->bio_meta, 2,
sizeof(struct bbio) +
sizeof(struct bio_vec) * bucket_pages(c)))
goto err;

if (mempool_init_kmalloc_pool(&c->fill_iter, 1, iter_size))
goto err;

if (bioset_init(&c->bio_split, 4, offsetof(struct bbio, bio),
BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER))
goto err;

c->uuids = alloc_bucket_pages(GFP_KERNEL, c);
if (!c->uuids)
goto err;

c->moving_gc_wq = alloc_workqueue("bcache_gc", WQ_MEM_RECLAIM, 0);
if (!c->moving_gc_wq)
goto err;

if (bch_journal_alloc(c))
goto err;

if (bch_btree_cache_alloc(c))
goto err;

if (bch_open_buckets_alloc(c))
goto err;

if (bch_bset_sort_state_init(&c->sort, ilog2(c->btree_pages)))
goto err;

c->congested_read_threshold_us = 2000;
Expand Down

0 comments on commit a42d3c6

Please sign in to comment.