Received: by 2002:a4a:301c:0:0:0:0:0 with SMTP id q28-v6csp579174oof; Tue, 25 Sep 2018 01:42:31 -0700 (PDT) X-Google-Smtp-Source: ACcGV63auO9eN/m01Rem9hi/UkK0Is8lThCZZqFxSBNJkZl8mBVaikwT25HtZktoNtauzK6e5XKD X-Received: by 2002:a62:5c03:: with SMTP id q3-v6mr2571862pfb.182.1537864951022; Tue, 25 Sep 2018 01:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537864950; cv=none; d=google.com; s=arc-20160816; b=I8bITetfNzrn7X4AuxZYXzHpXC0ngmG+Oh8xvWhupKOi0xK1XdEnR2NdEfNFpR2uf3 eh7SD5PUzpNh06vEVfube79W9dRnS7+uA2pnh4T5rDJq+d5vshjdKtDEJYP/2y2Nw81+ ntx9duZA3VtlZr+LYsdM9BWQZWh5i9VFl4bhkHjvJiJ7gmAkb3O7IYM9Qj7NAhe510eQ GkC/VGWR+qJMla3ze5EDNJlvIf+9sYOMbEE0rvYNSdrdw/9JPuI9GLbgKx8ERIE8Wd1N /v1IRoVbxrh04G6bgg+JxyeSBY//ewbKq1Vtzon0JavvVA5Q2rFRnX0bXcoMaYPSmhUK AtGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=joEwteYbQavuRdJIkPmVRvkOVSv36H3+qWdhQVo4GHA=; b=cHrgPiPdo8136c6aIJ0gz5If9tSWXlDF2QCohmIsIZnT1CyI6O4GR9zwBfZRVP+wbh zxhdzdbfgN+dDL/mdExVGZ2wqZj4phaDUFJMmIzdm2xBCbrBrQ9v0OnixJ/tT6QDpEyI 6l0krcw5D8N4NWJlIuuxPe7Lo19Pjfmnla+8ryOhg71Iiy78495WGCqF4tVF11XU6TWx 1ppHZUoB9HQu5qziPQqHj4UIg5HH43Gm+vme1n5iwqg+neYa8m2Mq01YH0VDlBZjYlAn 66dbMke9FpFU0VVs39HtObwiLHcrEplFMZjvVnfDc59jb47moIukSuL+Pj2acw92GiY6 ROSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=W47ty21G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w10-v6si1780711pfk.162.2018.09.25.01.42.14; Tue, 25 Sep 2018 01:42:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=W47ty21G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727650AbeIYOsf (ORCPT + 99 others); Tue, 25 Sep 2018 10:48:35 -0400 Received: from m12-15.163.com ([220.181.12.15]:34556 "EHLO m12-15.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726031AbeIYOsf (ORCPT ); Tue, 25 Sep 2018 10:48:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=joEwteYbQavuRdJIkP mVRvkOVSv36H3+qWdhQVo4GHA=; b=W47ty21G48DfBWjVYx4eXScHhPcQ94qc0N B6FWK2cbCQReKLZx6x12Rd0CkvQ5m8CH4RhAL9t0Y1KeuwGcjibmbmHUxEl0K0wR xRJd4eSeEoSMcAcgwqHmzejQRXQnKCxDqW4OBf7DyCOybrQkHfwn1ETf7pt7nkqU cq4WbmliI= Received: from localhost.localdomain (unknown [117.136.0.174]) by smtp11 (Coremail) with SMTP id D8CowAD3_x_I9KlbfoA4IQ--.20159S4; Tue, 25 Sep 2018 16:41:44 +0800 (CST) From: Dongbo Cao To: colyli@suse.de Cc: kent.overstreet@gmail.com, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, Dongbo Cao Subject: [PATCH 3/3] split original if condition code in function bch_cache_set_alloc Date: Tue, 25 Sep 2018 16:41:42 +0800 Message-Id: <20180925084142.8764-1-cdbdyx@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: D8CowAD3_x_I9KlbfoA4IQ--.20159S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxCF45WF1DCry8JF45CryrCrg_yoWruF48pF Zru34fArWrXw43tr1Yyr409F95C3yIgayUW3y7X34rZrsIkr1rKr1vyry5ZrW5AFZrGa13 CFn5K348ur1DJaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2GQDUUUUU= X-Originating-IP: [117.136.0.174] X-CM-SenderInfo: xfgev5r06rljoofrz/1tbiNRfM3FrPMemFpAAAse Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org remove bch_cache_set_unregister because we have not registerd right now Signed-off-by: Dongbo Cao --- drivers/md/bcache/super.c | 102 ++++++++++++++++++++++++++++++-------- 1 file changed, 82 insertions(+), 20 deletions(-) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 47d122ed..13a128eb 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -1658,9 +1658,13 @@ void bch_cache_set_unregister(struct cache_set *c) struct cache_set *bch_cache_set_alloc(struct cache_sb *sb) { int iter_size; + const char *err = NULL; + struct cache_set *c = kzalloc(sizeof(struct cache_set), GFP_KERNEL); - if (!c) - return NULL; + if (!c) { + err = "cache_set alloc failed"; + goto err_cache_set_alloc; + } __module_get(THIS_MODULE); closure_init(&c->cl, NULL); @@ -1715,22 +1719,55 @@ 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))) - goto err; + if (!(c->devices = kcalloc(c->nr_uuids, sizeof(void *), GFP_KERNEL))) { + err = "c->devices alloc failed"; + goto err_devices_alloc; + } + if (mempool_init_slab_pool(&c->search, 32, bch_search_cache)) { + err = "c->search alloc failed"; + goto err_search_alloc; + } + if (mempool_init_kmalloc_pool(&c->bio_meta, 2, + sizeof(struct bbio) + sizeof(struct bio_vec) * + bucket_pages(c))) { + err = "c->bio_meta alloc failed"; + goto err_bio_meta_alloc; + } + if (mempool_init_kmalloc_pool(&c->fill_iter, 1, iter_size)) { + err = "c->fill_iter alloc failed"; + goto err_fill_iter_alloc; + } + if (bioset_init(&c->bio_split, 4, offsetof(struct bbio, bio), + BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER)) { + err = "c->bio_split init failed"; + goto err_bio_split_init; + } + if (!(c->uuids = alloc_bucket_pages(GFP_KERNEL, c))) { + err = "c->uuids alloc failed"; + goto err_uuids_alloc; + } + if (!(c->moving_gc_wq = alloc_workqueue("bcache_gc", + WQ_MEM_RECLAIM, 0))) { + err = "c->moving_gc_wq alloc failed"; + goto err_moving_gc_wq_alloc; + } + if (bch_journal_alloc(c)) { + err = "bch_journal_alloc failed"; + goto err_bch_journal_alloc; + + } + if (bch_btree_cache_alloc(c)) { + err = "bch_btree_cache_alloc failed"; + goto err_bch_btree_cache_alloc; + } + if (bch_open_buckets_alloc(c)) { + err = "bch_open_buckets_alloc failed"; + goto err_bch_open_buckets_alloc; + } + if (bch_bset_sort_state_init(&c->sort, ilog2(c->btree_pages))) { + err = "bch_bset_sort_state_init failed"; + goto err_bch_bset_sort_state_init; + } c->congested_read_threshold_us = 2000; c->congested_write_threshold_us = 20000; @@ -1738,8 +1775,33 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb) WARN_ON(test_and_clear_bit(CACHE_SET_IO_DISABLE, &c->flags)); return c; -err: - bch_cache_set_unregister(c); + +err_bch_bset_sort_state_init: + bch_open_buckets_free(c); +err_bch_open_buckets_alloc: + bch_btree_cache_free(c); +err_bch_btree_cache_alloc: + bch_journal_free(c); +err_bch_journal_alloc: + destroy_workqueue(c->moving_gc_wq); +err_moving_gc_wq_alloc: + free_pages((unsigned long) c->uuids, ilog2(bucket_pages(c))); +err_uuids_alloc: + bioset_exit(&c->bio_split); +err_bio_split_init: + mempool_exit(&c->fill_iter); +err_fill_iter_alloc: + mempool_exit(&c->bio_meta); +err_bio_meta_alloc: + mempool_exit(&c->search); +err_search_alloc: + kfree(c->devices); +err_devices_alloc: + kfree(c); + module_put(THIS_MODULE); +err_cache_set_alloc: + if (err) + pr_notice("error cache set %s: %s", c->sb.set_uuid, err); return NULL; } -- 2.17.1