From patchwork Wed Oct 18 11:37:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 736874 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF3B4C46CA1 for ; Wed, 18 Oct 2023 11:38:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235172AbjJRLiZ (ORCPT ); Wed, 18 Oct 2023 07:38:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235236AbjJRLiP (ORCPT ); Wed, 18 Oct 2023 07:38:15 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A67BED76; Wed, 18 Oct 2023 04:38:03 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S9TJs0nwjzRt83; Wed, 18 Oct 2023 19:34:21 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by kwepemm000012.china.huawei.com (7.193.23.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 18 Oct 2023 19:38:00 +0800 From: Wenchao Hao To: "Martin K . Petersen" , Bart Van Assche CC: "James E . J . Bottomley" , , , , Wenchao Hao Subject: [PATCH v3 1/2] scsi: core: cleanup scsi_dev_queue_ready() Date: Wed, 18 Oct 2023 19:37:45 +0800 Message-ID: <20231018113746.1940197-2-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20231018113746.1940197-1-haowenchao2@huawei.com> References: <20231018113746.1940197-1-haowenchao2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm000012.china.huawei.com (7.193.23.142) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This is just a cleanup for scsi_dev_queue_ready() to avoid redundant goto and if statement, it did not change the origin logic. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_lib.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index aca57c3ab626..cf3864f72093 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1251,28 +1251,26 @@ static inline int scsi_dev_queue_ready(struct request_queue *q, int token; token = sbitmap_get(&sdev->budget_map); - if (atomic_read(&sdev->device_blocked)) { - if (token < 0) - goto out; + if (token < 0) + return -1; - if (scsi_device_busy(sdev) > 1) - goto out_dec; + if (!atomic_read(&sdev->device_blocked)) + return token; - /* - * unblock after device_blocked iterates to zero - */ - if (atomic_dec_return(&sdev->device_blocked) > 0) - goto out_dec; - SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, - "unblocking device at zero depth\n")); + /* + * Only unblock if no other commands are pending and + * if device_blocked has decreased to zero + */ + if (scsi_device_busy(sdev) > 1 || + atomic_dec_return(&sdev->device_blocked) > 0) { + sbitmap_put(&sdev->budget_map, token); + return -1; } + SCSI_LOG_MLQUEUE(3, sdev_printk(KERN_INFO, sdev, + "unblocking device at zero depth\n")); + return token; -out_dec: - if (token >= 0) - sbitmap_put(&sdev->budget_map, token); -out: - return -1; } /* From patchwork Wed Oct 18 11:37:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 736873 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A8ECCDB47E for ; Wed, 18 Oct 2023 11:38:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231375AbjJRLi3 (ORCPT ); Wed, 18 Oct 2023 07:38:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235197AbjJRLiQ (ORCPT ); Wed, 18 Oct 2023 07:38:16 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76BA810C1; Wed, 18 Oct 2023 04:38:04 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4S9TKz2WF6z15NQC; Wed, 18 Oct 2023 19:35:19 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by kwepemm000012.china.huawei.com (7.193.23.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 18 Oct 2023 19:38:01 +0800 From: Wenchao Hao To: "Martin K . Petersen" , Bart Van Assche CC: "James E . J . Bottomley" , , , , Wenchao Hao Subject: [PATCH v3 2/2] scsi: Add comment of target_destroy in scsi_host_template Date: Wed, 18 Oct 2023 19:37:46 +0800 Message-ID: <20231018113746.1940197-3-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20231018113746.1940197-1-haowenchao2@huawei.com> References: <20231018113746.1940197-1-haowenchao2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm000012.china.huawei.com (7.193.23.142) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Add comment to tell callback function target_destroy of scsi_host_template must not sleep. Signed-off-by: Wenchao Hao --- include/scsi/scsi_host.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 49f768d0ff37..2c61dd30d766 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -245,6 +245,9 @@ struct scsi_host_template { * midlayer calls this point so that the driver may deallocate * and terminate any references to the target. * + * Note: This callback is called with the host lock held and hence + * must not sleep. + * * Status: OPTIONAL */ void (* target_destroy)(struct scsi_target *);