From patchwork Wed Nov 2 03:06:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinlong Chen X-Patchwork-Id: 14006 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3361571wru; Tue, 1 Nov 2022 20:09:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6+klB7uYd/oPjbhUaRwj3Z+V+b+B+J11PYwCeNj/fsHMmJbij+679ZTKpCiBQA0abLvy7t X-Received: by 2002:a63:1861:0:b0:462:4961:9a8f with SMTP id 33-20020a631861000000b0046249619a8fmr20071424pgy.372.1667358563905; Tue, 01 Nov 2022 20:09:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667358563; cv=none; d=google.com; s=arc-20160816; b=WCrs6LBxkZ4P3x2DUas06oIuucAyoSYwU8Yx6t3j+x2Bozu6ZwYmYa3HAIKSj5s/j7 uVw3gphcd+TVkD5eJAKO7f8+awNE1r6JwxNCoDyCNaSVKokHt6cxco21f2WnrdAh9pIc RoXKnQJysSarMEd47WhYzLjENpQbHDr4yrZK5XQCyDSmCA9HyUKB1x25Jvbs/vjORWpV 8jasOO9Y1sYEZX2rJ2PhZQErheVIkpvFqSlgGXeKbtZpt28IVrFMXpVpif9PZt2cFTtr j426B/mauf7e1nOsOQ2jBMHdcJl4D8Tbwc2/g7XTZFxPPPmc623qvsfr4UQTrYZnWFmI yYNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=suAXK830rUf8u1KXzy+z+6h+5TKjCJJHqaBa3yv7rkk=; b=cVYHgt2j1vOODWRODp6+f5vaSwPRIf/logJ4ZHTL25cyPm1LO5l64sZI3uG++vmMMO 9cqQY7oLJi4YyvMl6GK9o2YNuRikUEdCpGn6afpAHxFhGFLZfYtjo2OT6wW1jP9EFdWX zumHbrSst+ep5UjXGJ8RaQwqmiSVAvH/C+grDlo8QU2cq3uq0VI2j0/1YbZtDmJjfopy TD9MhPpgjafgqrfz6rVSNlkwESG+PE0jVy1jU4Igliqaq2Un2LeTCLrUtck4+gXUrTRU ACqL3J3OFOm8U8jjaSM+/HdDeH2mo4LTg0m2A1NP5F4tMwf8xzYG4XHqQOc3Qz/4Ugh9 wODw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l31-20020a635b5f000000b00460b572d264si14285982pgm.579.2022.11.01.20.09.11; Tue, 01 Nov 2022 20:09:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230302AbiKBDGw (ORCPT + 99 others); Tue, 1 Nov 2022 23:06:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230159AbiKBDGX (ORCPT ); Tue, 1 Nov 2022 23:06:23 -0400 Received: from zju.edu.cn (spam.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EC73E23EB1; Tue, 1 Nov 2022 20:06:22 -0700 (PDT) Received: from localhost.localdomain (unknown [10.14.30.251]) by mail-app2 (Coremail) with SMTP id by_KCgA3PSGf3mFjz_9cBw--.7456S3; Wed, 02 Nov 2022 11:06:16 +0800 (CST) From: Jinlong Chen To: axboe@kernel.dk Cc: hch@lst.de, chaitanyak@nvidia.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, nickyc975@zju.edu.cn Subject: [PATCH v3 1/2] blk-mq: improve error handling in blk_mq_alloc_rq_map() Date: Wed, 2 Nov 2022 11:06:04 +0800 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: by_KCgA3PSGf3mFjz_9cBw--.7456S3 X-Coremail-Antispam: 1UD129KBjvdXoW7GF43Gw13Ar1UCw4UuryxGrg_yoWkZwc_Cr y0kw1vvFyUAr1Fkw4q9r15Ar97CanakF40vFWDK3srJ3s7GanrAa9xZrnxJrZ7Ww4xWFWx Gw1kZr1Fkr15tjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb-8Fc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wAFIxvE14AK wVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20x vE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26rxl6s0DM28EF7xvwVC2z280 aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2vYz4IE04k24VAvwV AKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj 6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr 0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkF7I0En4kS14v2 6r126r1DMxAIw28IcxkI7VAKI48JMxAIw28IcVCjz48v1sIEY20_GFWkJr1UJwCFx2IqxV CFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r10 6r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxV WUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG 6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr 1UYxBIdaVFxhVjvjDU0xZFpf9x0JUvg4fUUUUU= X-CM-SenderInfo: qssqjiaqqzq6lmxovvfxof0/1tbiAgoCB1ZdtcNVXAAMs1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748352173913436008?= X-GMAIL-MSGID: =?utf-8?q?1748352173913436008?= Use goto-style error handling like we do elsewhere in the kernel. Signed-off-by: Jinlong Chen Reviewed-by: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig --- block/blk-mq.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 623e8a506539..453ad445a6bd 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3274,21 +3274,22 @@ static struct blk_mq_tags *blk_mq_alloc_rq_map(struct blk_mq_tag_set *set, tags->rqs = kcalloc_node(nr_tags, sizeof(struct request *), GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY, node); - if (!tags->rqs) { - blk_mq_free_tags(tags); - return NULL; - } + if (!tags->rqs) + goto err_free_tags; tags->static_rqs = kcalloc_node(nr_tags, sizeof(struct request *), GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY, node); - if (!tags->static_rqs) { - kfree(tags->rqs); - blk_mq_free_tags(tags); - return NULL; - } + if (!tags->static_rqs) + goto err_free_rqs; return tags; + +err_free_rqs: + kfree(tags->rqs); +err_free_tags: + blk_mq_free_tags(tags); + return NULL; } static int blk_mq_init_request(struct blk_mq_tag_set *set, struct request *rq, From patchwork Wed Nov 2 03:06:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinlong Chen X-Patchwork-Id: 14005 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3361569wru; Tue, 1 Nov 2022 20:09:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5yfr53z9+WMJ1QZHAl0TeHMa/wC9M8rDNbB7aQ7/EricVAeSbuDMDDTa+KxdXRJ/sjLSmC X-Received: by 2002:a63:7909:0:b0:458:1ba6:ec80 with SMTP id u9-20020a637909000000b004581ba6ec80mr19985452pgc.414.1667358563509; Tue, 01 Nov 2022 20:09:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667358563; cv=none; d=google.com; s=arc-20160816; b=oClaWWECKXLnRwEdJdjvpQQ6p/fN8T4ImelKDr0pYqHaTGwranpzwfeQW1boZpQnqt 0bqqOWXHnuYvhBWvHsUreCNFnoJdYq+UsZxX/+AkNdQ6WoCMD/rvVu66x5TOapAVM3Sg q9SMJGyNXjHPotpvRvaDKJiY2q74DW2gy/MVM7DzmQ4qLAT79SV9aUYGCLouXokcLaja dOPoxQFWpZYJLaSllnYkdBMLl7RKHi4WVsCMNyluUvcLe9iUzt/H2BkvlRcSVBEefmPz OWngyZ4BYNIl4ekRcHVaE8nYCpq3YRCBMRYGRLltzwqJoVADCPIy+70CCwLvRdZmQ0yn daQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oJaFX61pFHcWFt+iEveXJVYl24WHCzrlm1We3OXZeEY=; b=CaXyaxQ1LO4Z1Y1HhLkYNE1sNdGxuIsf/gSVWUuWzNjTrX3K2H0l2FKqYZnCrrloGW jbkVEPJXC0LXIfdFhEGir7ju4E1sSCUkYwwf/HFlHDOMiowd6msaiCQeFYVPLAvatwuo 7IRgZB8q0LEEGe3kUbYIjHvdbpXK+lifsD4Q8Xp6UIT1g9lhiFjJ1AZbvntBW5vkv07H bz9J1gL2VB+zMu9LDQ+boQPg5dnkw3cjDN4JREGvvawop9DTtC5raFul9Gas9VIjNiE6 b6wRquDb/urOMi/IvEmA8Z6n5vw7g2/bZJCrCWr1NKoluD3FdB6Y67rHpGuPS9f/4IHh 3Pqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a9-20020a170902ecc900b00176db576db9si16505986plh.275.2022.11.01.20.09.11; Tue, 01 Nov 2022 20:09:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230150AbiKBDG4 (ORCPT + 99 others); Tue, 1 Nov 2022 23:06:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230161AbiKBDGY (ORCPT ); Tue, 1 Nov 2022 23:06:24 -0400 Received: from zju.edu.cn (spam.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EC54123E93; Tue, 1 Nov 2022 20:06:22 -0700 (PDT) Received: from localhost.localdomain (unknown [10.14.30.251]) by mail-app2 (Coremail) with SMTP id by_KCgA3PSGf3mFjz_9cBw--.7456S4; Wed, 02 Nov 2022 11:06:17 +0800 (CST) From: Jinlong Chen To: axboe@kernel.dk Cc: hch@lst.de, chaitanyak@nvidia.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, nickyc975@zju.edu.cn Subject: [PATCH v3 2/2] blk-mq: use if-else instead of goto in blk_mq_alloc_cached_request() Date: Wed, 2 Nov 2022 11:06:05 +0800 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: by_KCgA3PSGf3mFjz_9cBw--.7456S4 X-Coremail-Antispam: 1UD129KBjvJXoW7AF4Dtw4DWry3ZFW7Cw4xtFb_yoW8Gry5pF sxJa4qvFWFgF1xuF4rAa1fJF4rCF1rGF9rC34fAwn5Z3y5Gr4Utr1fArWFqFWSyFZ3CFWx Kr4DCas5uF18XrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUva1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW0oVCq3wA2z4x0Y4vEx4A2 jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAac4AC62xK8xCEY4 vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv 7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r 1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0E wIxGrwCF04k20xvE74AGY7Cv6cx26r4fKr1UJr1l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2 IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v2 6r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2 IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv 67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyT uYvjfUOlksUUUUU X-CM-SenderInfo: qssqjiaqqzq6lmxovvfxof0/1tbiAgQCB1ZdtcNYxwAAsh X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748352173371304027?= X-GMAIL-MSGID: =?utf-8?q?1748352173371304027?= if-else is more readable than goto here. Signed-off-by: Jinlong Chen Reviewed-by: Christoph Hellwig Reviewed-by: Chaitanya Kulkarni Reviewed-by: Christoph Hellwig --- block/blk-mq.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 453ad445a6bd..6ffca7af5b6f 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -544,25 +544,26 @@ static struct request *blk_mq_alloc_cached_request(struct request_queue *q, if (!plug) return NULL; + if (rq_list_empty(plug->cached_rq)) { if (plug->nr_ios == 1) return NULL; rq = blk_mq_rq_cache_fill(q, plug, opf, flags); - if (rq) - goto got_it; - return NULL; - } - rq = rq_list_peek(&plug->cached_rq); - if (!rq || rq->q != q) - return NULL; + if (!rq) + return NULL; + } else { + rq = rq_list_peek(&plug->cached_rq); + if (!rq || rq->q != q) + return NULL; - if (blk_mq_get_hctx_type(opf) != rq->mq_hctx->type) - return NULL; - if (op_is_flush(rq->cmd_flags) != op_is_flush(opf)) - return NULL; + if (blk_mq_get_hctx_type(opf) != rq->mq_hctx->type) + return NULL; + if (op_is_flush(rq->cmd_flags) != op_is_flush(opf)) + return NULL; + + plug->cached_rq = rq_list_next(rq); + } - plug->cached_rq = rq_list_next(rq); -got_it: rq->cmd_flags = opf; INIT_LIST_HEAD(&rq->queuelist); return rq;