Received: by 2002:a4a:301c:0:0:0:0:0 with SMTP id q28-v6csp427539oof; Mon, 24 Sep 2018 23:10:31 -0700 (PDT) X-Google-Smtp-Source: ACcGV62IY7GlV/W6JGeSEs2PSeOhscLal+3MKUQvZbW5oN5eOzmwFN69BtPAg50puQ9hMfBe+SLN X-Received: by 2002:a62:444d:: with SMTP id r74-v6mr1958243pfa.96.1537855831792; Mon, 24 Sep 2018 23:10:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537855831; cv=none; d=google.com; s=arc-20160816; b=bF+5fovdz1O7bGzVJCrz20eaA5p0QhUCwBMkF0BOkhqt5uC1sFnBHc8ZO0NM9WQ3Es 1pFFCkYXJKwYG0Io+z32nhXt/5eD8iDZmcTclcVG6ttyyZ3zPU/ASOhw8nN5tmt5rY0h VnGF7TbOa1HoICJaM1AXcRlTlOO3i0t2IzQ83+iE70SBGn4mDZBPPkRz0kSu1iahvZU6 K6Wc9vte72AbBVx2GuCBPiVoanbcoYv2u7S/3xViX2gTGP1FGn9eDVRzsZfCHpLR3+38 qAlg+WOdXxJCa9+IE6Ali2pJImjbjzO8/3J8IXNmVPDdmEvI8pie8BDBUwHwmZoxMtaA HHHQ== 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=yPyv5Bvghocd6c4uPzv0nC3ZJCF7rm8dWKCcZNhb2hU=; b=IvPT2iZrvum/cnlzNVtqRvLlLYGNzARIxQ5o3oG3TZ/8Cuuovy753icnCdzIjg5Zux oGKlsh2PaLvpH52t8wTKKcusKIPcuVwHLudEim2Xty+mpC8FdMp0VSBLjFwiPjC6cdF+ 26w/+Ew9B+NbatEE3tPSEzEOg9psQnC4AtrgnkjSu+ca9/E1+4UDv86vhx5sPYwtCsV1 ai0g1yzIki+zfNBDkLKlg0URWs+ccf2/QPA8FR6HjIc0BqNdY7zhzIJk7bFkc/x/mR2p 1m1LOsVoKUlPCAn8a6MkFb+epR1ep4d6DoJ0Xral6cTbhD8JR2S8aqGiL2CuL/wbWi0+ sGMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=FYMo2dyK; 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 y3-v6si1441688pgg.266.2018.09.24.23.10.15; Mon, 24 Sep 2018 23:10:31 -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=FYMo2dyK; 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 S1727320AbeIYMQD (ORCPT + 99 others); Tue, 25 Sep 2018 08:16:03 -0400 Received: from m12-15.163.com ([220.181.12.15]:54655 "EHLO m12-15.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725843AbeIYMQD (ORCPT ); Tue, 25 Sep 2018 08:16:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=yPyv5Bvghocd6c4uPz v0nC3ZJCF7rm8dWKCcZNhb2hU=; b=FYMo2dyKFhNcyWnC70YTF9RPYWvLNeTOW4 mknRVZUaMmGafFx7f+7Q2/VAnGjX7GiNILzKhhi2zsF1DBeWpMhUG+/3i/ltQA/g myNM1CUcaS5xZ/UFFVzAr6w8chQOeGUlcU3qqSnsKnyqI2pIsZPjua9IES4dRnrb nqbJkgw0k= Received: from localhost.localdomain (unknown [117.136.0.174]) by smtp11 (Coremail) with SMTP id D8CowADHYdA20albK3grIQ--.53064S4; Tue, 25 Sep 2018 14:09:59 +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 1/2] split original if-condition code into separate ones Date: Tue, 25 Sep 2018 14:09:44 +0800 Message-Id: <20180925060945.6731-1-cdbdyx@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: D8CowADHYdA20albK3grIQ--.53064S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxCF48Kw4xKr45Aw4kuF4UArb_yoWrJw13pF WfJryYkF4rtw17ZrnxGr4vgan8AayIganrWryfZ3Wa9rn09r1Y9r4vyr1YvrW7urZ8Jay3 JrZ0yw4kJrn8taUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2rWrUUUUU= X-Originating-IP: [117.136.0.174] X-CM-SenderInfo: xfgev5r06rljoofrz/1tbiGRjM3FXlgI4RPwAAsB Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org to make it clearly to debug. Signed-off-by: Dongbo Cao --- drivers/md/bcache/super.c | 81 +++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 15 deletions(-) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index fa4058e4..0c0f6d8f 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -2017,6 +2017,8 @@ static int cache_alloc(struct cache *ca) size_t free; size_t btree_buckets; struct bucket *b; + int ret = -ENOMEM; + const char *err = NULL; __module_get(THIS_MODULE); kobject_init(&ca->kobj, &bch_cache_ktype); @@ -2034,27 +2036,76 @@ static int cache_alloc(struct cache *ca) */ btree_buckets = ca->sb.njournal_buckets ?: 8; free = roundup_pow_of_two(ca->sb.nbuckets) >> 10; - - if (!init_fifo(&ca->free[RESERVE_BTREE], btree_buckets, GFP_KERNEL) || - !init_fifo_exact(&ca->free[RESERVE_PRIO], prio_buckets(ca), GFP_KERNEL) || - !init_fifo(&ca->free[RESERVE_MOVINGGC], free, GFP_KERNEL) || - !init_fifo(&ca->free[RESERVE_NONE], free, GFP_KERNEL) || - !init_fifo(&ca->free_inc, free << 2, GFP_KERNEL) || - !init_heap(&ca->heap, free << 3, GFP_KERNEL) || - !(ca->buckets = vzalloc(array_size(sizeof(struct bucket), - ca->sb.nbuckets))) || - !(ca->prio_buckets = kzalloc(array3_size(sizeof(uint64_t), - prio_buckets(ca), 2), - GFP_KERNEL)) || - !(ca->disk_buckets = alloc_bucket_pages(GFP_KERNEL, ca))) - return -ENOMEM; + + if (!init_fifo(&ca->free[RESERVE_BTREE], btree_buckets, + GFP_KERNEL)) { + err = "ca->free[RESERVE_BTREE] alloc failed"; + goto err_btree_alloc; + } + if (!init_fifo_exact(&ca->free[RESERVE_PRIO], prio_buckets(ca), + GFP_KERNEL)) { + err = "ca->free[RESERVE_PRIO] alloc failed"; + goto err_prio_alloc; + } + if (!init_fifo(&ca->free[RESERVE_MOVINGGC], free, GFP_KERNEL)) { + err = "ca->free[RESERVE_MOVINGGC] alloc failed"; + goto err_movinggc_alloc; + } + if (!init_fifo(&ca->free[RESERVE_NONE], free, GFP_KERNEL)) { + err = "ca->free[RESERVE_NONE] alloc failed"; + goto err_none_alloc; + } + if (!init_fifo(&ca->free_inc, free << 2, GFP_KERNEL)) { + err = "ca->free_inc alloc failed"; + goto err_free_inc_alloc; + } + if (!init_heap(&ca->heap, free << 3, GFP_KERNEL)) { + err = "ca->heap alloc failed"; + goto err_heap_alloc; + } + if (!(ca->buckets = vzalloc(array_size(sizeof(struct bucket), + ca->sb.nbuckets)))) { + err = "ca->buckets alloc failed"; + goto err_buckets_alloc; + } + if (!(ca->prio_buckets = kzalloc(array3_size(sizeof(uint64_t), + prio_buckets(ca), 2), + GFP_KERNEL))) { + err = "ca->prio_buckets alloc failed"; + goto err_prio_buckets_alloc; + } + if (!(ca->disk_buckets = alloc_bucket_pages(GFP_KERNEL, ca))) { + err = "ca->disk_buckets alloc failed"; + goto err_disk_buckets_alloc; + } ca->prio_last_buckets = ca->prio_buckets + prio_buckets(ca); for_each_bucket(b, ca) atomic_set(&b->pin, 0); - return 0; + +err_disk_buckets_alloc: + kfree(ca->prio_buckets); +err_prio_buckets_alloc: + vfree(ca->buckets); +err_buckets_alloc: + free_heap(&ca->heap); +err_heap_alloc: + free_fifo(&ca->free_inc); +err_free_inc_alloc: + free_fifo(&ca->free[RESERVE_NONE]); +err_none_alloc: + free_fifo(&ca->free[RESERVE_MOVINGGC]); +err_movinggc_alloc: + free_fifo(&ca->free[RESERVE_PRIO]); +err_prio_alloc: + free_fifo(&ca->free[RESERVE_BTREE]); +err_btree_alloc: + module_put(THIS_MODULE); + if (err) + pr_notice("error %s: %s", ca->cache_dev_name, err); + return ret; } static int register_cache(struct cache_sb *sb, struct page *sb_page, -- 2.17.1