From patchwork Tue Jul 9 19:21:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 11037431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4176814E5 for ; Tue, 9 Jul 2019 19:21:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3357D287C8 for ; Tue, 9 Jul 2019 19:21:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 278E62887D; Tue, 9 Jul 2019 19:21:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9AF8287C8 for ; Tue, 9 Jul 2019 19:21:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726957AbfGITVn (ORCPT ); Tue, 9 Jul 2019 15:21:43 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:2861 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726133AbfGITVn (ORCPT ); Tue, 9 Jul 2019 15:21:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1562700102; x=1594236102; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=NDg4Jdfauokh0z2Y50ewAb5U2547jMbyxmfgWJh/EV0=; b=g69pc8czJ7vuhULBXRic2eM4qspYOEwB2qzHlSGFeR78iD6LnreNDXV/ 6D/MFL/trpuY/yezWmzU09rbCLs/HZPxF17YMqkLHKoZmXxRaAar5S7+Q 75/NZ4l6bPG5bTj+q/o9uihPeOWc5aM/Ztr/dD53auu0r386LR4aGuUnQ TEuPUqA4UDT1D15keosP803f3MUq8NmWqLwYqZLBmPT0mRyrDHQRS45Ay MPGDN9vzDFXe1e4Sj/bDt44qIi+FMjpHiJ3uwbfdCKl/b+xQY+lAWW21Z rIXRFVhK1awQzHZGzz/9VAPlFkG4bIJyYxz5apK1p8slPPk4A0vLYVOko w==; IronPort-SDR: kU4dJA6KcZw51Mi2BTue0a/T1QL2qHCWleXsntW+x7vo+sXD5CUpGa+n7X2DicrFnQzKHwRsmR Il+DrhT37my5ldX26il/a4gL/4nXOOB7+hApR3qcnExdNlldj0p7mqxxasa+CXQC3lUZR5vDti hJr0Dw6nJKKmj7/ZGm38H3dymKht4N2ZKX15v0/Rcb+f+Ukbbtkk6HEF39AIuXBFqqM/9k8Hg/ t3IGdhm3JDvTvm6a9wmfxvx7+d9NXwwIQrvTIFtSVj+J10ojzEroED0Tjy1am3+kSFh3Rugeav d90= X-IronPort-AV: E=Sophos;i="5.63,471,1557158400"; d="scan'208";a="117396982" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jul 2019 03:21:42 +0800 IronPort-SDR: sZ8K8jNUySjVAfpkbWS2/Ml0Ivv6uCDMlHNsNgi5KdIpECVda88c4aawxQrrPrXnn0d0HQG9p5 YzEUFrZKlqckWRlL0GYrRnyL8RxZW/Bw8FBmIzt5IsHOWlk/pSWxfK6MZtutaEH73O/OryMIpL jk/v/vcEB0KCCpRN+6ViGcxujJa4DUrMloyziHY1ykBGyMpGYtOdkjvMXZ1oah5fcv4EaSOokK RYHIyYTYkNtoaOVsKn/GAhe/Q0ttVdmfMOKvzstGkqMx4EdyWSi41SYO7T1Z9+AcZcsut6ehbO EgGP/fXSlsP8+2hbmL/zieG2 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 09 Jul 2019 12:20:28 -0700 IronPort-SDR: I2OsZLs1ia12FbJ0Ve5BfBMVoGGxT28o6jWS0ZPWfTGm5FjAd02SlgRtFj99ewSgDtRBwBRw3q kz6hU/i8L2IyrpNdqu5UNQaNR7UY+LwlS8owoBP/hsEfiX0zv9Hz8pWN8I2RSbYLj8tgCl2opt EYOj/tgBjjoQel62fgd7pcmviat1CicVu2Xprh25d2zwtnh8DdEwb7sj9dcsW0jABdKBiJ2ogT wEXV4KYLCP3AGAsqUZ1JceFE8/yqjSb5fvS0cNP8zqydxrAcBHH9h47Zo7hTCRpstXDOpAVz+Y XKw= Received: from cvenusqemu.hgst.com ([10.202.66.73]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Jul 2019 12:21:42 -0700 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org Cc: hch@lst.de, Chaitanya Kulkarni Subject: [PATCH V2 1/6] null_blk: move duplicate code to callers Date: Tue, 9 Jul 2019 12:21:27 -0700 Message-Id: <20190709192132.24723-2-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190709192132.24723-1-chaitanya.kulkarni@wdc.com> References: <20190709192132.24723-1-chaitanya.kulkarni@wdc.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a preparation patch which moves the duplicate code for sectors and nr_sectors calculations for bio vs request mode into their respective callers (null_queue_bio(), null_qeueue_req()). Now the core function only deals with the respective actions and commands instead of having to calculte the bio vs req operations and different sector related variables. We also move the flush command handling at the top which significantly simplifies the rest of the code. Signed-off-by: Chaitanya Kulkarni --- drivers/block/null_blk_main.c | 66 +++++++++++------------------------ 1 file changed, 21 insertions(+), 45 deletions(-) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 99328ded60d1..b3be08edea43 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1133,7 +1133,8 @@ static void null_restart_queue_async(struct nullb *nullb) blk_mq_start_stopped_hw_queues(q, true); } -static blk_status_t null_handle_cmd(struct nullb_cmd *cmd) +static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, + sector_t nr_sectors, enum req_opf op) { struct nullb_device *dev = cmd->nq->dev; struct nullb *nullb = dev->nullb; @@ -1156,60 +1157,31 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd) } } + if (op == REQ_OP_FLUSH) { + cmd->error = errno_to_blk_status(null_handle_flush(nullb)); + goto out; + } if (nullb->dev->badblocks.shift != -1) { int bad_sectors; - sector_t sector, size, first_bad; - bool is_flush = true; - - if (dev->queue_mode == NULL_Q_BIO && - bio_op(cmd->bio) != REQ_OP_FLUSH) { - is_flush = false; - sector = cmd->bio->bi_iter.bi_sector; - size = bio_sectors(cmd->bio); - } - if (dev->queue_mode != NULL_Q_BIO && - req_op(cmd->rq) != REQ_OP_FLUSH) { - is_flush = false; - sector = blk_rq_pos(cmd->rq); - size = blk_rq_sectors(cmd->rq); - } - if (!is_flush && badblocks_check(&nullb->dev->badblocks, sector, - size, &first_bad, &bad_sectors)) { + sector_t first_bad; + + if (badblocks_check(&nullb->dev->badblocks, sector, nr_sectors, + &first_bad, &bad_sectors)) { cmd->error = BLK_STS_IOERR; goto out; } } if (dev->memory_backed) { - if (dev->queue_mode == NULL_Q_BIO) { - if (bio_op(cmd->bio) == REQ_OP_FLUSH) - err = null_handle_flush(nullb); - else - err = null_handle_bio(cmd); - } else { - if (req_op(cmd->rq) == REQ_OP_FLUSH) - err = null_handle_flush(nullb); - else - err = null_handle_rq(cmd); - } + if (dev->queue_mode == NULL_Q_BIO) + err = null_handle_bio(cmd); + else + err = null_handle_rq(cmd); } + cmd->error = errno_to_blk_status(err); if (!cmd->error && dev->zoned) { - sector_t sector; - unsigned int nr_sectors; - enum req_opf op; - - if (dev->queue_mode == NULL_Q_BIO) { - op = bio_op(cmd->bio); - sector = cmd->bio->bi_iter.bi_sector; - nr_sectors = cmd->bio->bi_iter.bi_size >> 9; - } else { - op = req_op(cmd->rq); - sector = blk_rq_pos(cmd->rq); - nr_sectors = blk_rq_sectors(cmd->rq); - } - if (op == REQ_OP_WRITE) null_zone_write(cmd, sector, nr_sectors); else if (op == REQ_OP_ZONE_RESET) @@ -1280,6 +1252,8 @@ static struct nullb_queue *nullb_to_queue(struct nullb *nullb) static blk_qc_t null_queue_bio(struct request_queue *q, struct bio *bio) { + sector_t sector = bio->bi_iter.bi_sector; + sector_t nr_sectors = bio_sectors(bio); struct nullb *nullb = q->queuedata; struct nullb_queue *nq = nullb_to_queue(nullb); struct nullb_cmd *cmd; @@ -1287,7 +1261,7 @@ static blk_qc_t null_queue_bio(struct request_queue *q, struct bio *bio) cmd = alloc_cmd(nq, 1); cmd->bio = bio; - null_handle_cmd(cmd); + null_handle_cmd(cmd, sector, nr_sectors, bio_op(bio)); return BLK_QC_T_NONE; } @@ -1321,6 +1295,8 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx, { struct nullb_cmd *cmd = blk_mq_rq_to_pdu(bd->rq); struct nullb_queue *nq = hctx->driver_data; + sector_t nr_sectors = blk_rq_sectors(bd->rq); + sector_t sector = blk_rq_pos(bd->rq); might_sleep_if(hctx->flags & BLK_MQ_F_BLOCKING); @@ -1349,7 +1325,7 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx, if (should_timeout_request(bd->rq)) return BLK_STS_OK; - return null_handle_cmd(cmd); + return null_handle_cmd(cmd, sector, nr_sectors, req_op(bd->rq)); } static const struct blk_mq_ops null_mq_ops = { From patchwork Tue Jul 9 19:21:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 11037433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA1E21395 for ; Tue, 9 Jul 2019 19:21:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D254287C8 for ; Tue, 9 Jul 2019 19:21:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91FE52887D; Tue, 9 Jul 2019 19:21:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E134287C8 for ; Tue, 9 Jul 2019 19:21:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727608AbfGITVs (ORCPT ); Tue, 9 Jul 2019 15:21:48 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:63323 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726133AbfGITVs (ORCPT ); Tue, 9 Jul 2019 15:21:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1562700108; x=1594236108; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=qTE8enHLzqH4ca+dq1xEYRK9TO6PQQjULTVfQGS6ZVM=; b=WiE6J7l2u/XpiH5qJrxcQ8CJ17P1lmCiNJa1btrzk/KvYSELmWEYQfsN TQHOPfv/029m0S/1A+AUJMPEXjJ+u/NuC2tY4bfkG3vKodE99psP7KP/1 Sf1VBQ9eK4Pa3Z2FWKvWDYmzgmBmPwmG6X3PIzkj6t+PIrwFB8D1kDzBg 1G8q1WAqRXNC5hM2OU6rF3uUG2JgLEp0gHNmlcFPU9K6P3e4OWQ7y62h6 7sWhgGDhwQVJL3a0PQLfp1BGTY+PuvGkPCa87agtOtOpbhDFH2UzsoJ15 5lcSslg2ZGSWuCKwkoDpEqIkt7Q2tu5e6bFVHoPyzhpCfxftnpPsmJfjs A==; IronPort-SDR: nh4qCIMuyO3JbgXJfv2amjKYwnDzWCO5cXw94LTG+0rJd9VBjyZmv2wMBM8lUAdyzVJ+92eOq4 RWhM+lZ5ixMQfVDIo9pJCFVUckUuwMCGTPiXaHnWJOszPOQBT4DvTojL13rxxenmfUX/9Kv5yn UKTxZMvUdyXOQ246qaUjpufO4vqS1e2LFS/fnYke9uk5J1i+mHccyNImnJkkgpQY7pXztrb3Oz w4fZWDibNuOKVA2/Vvt8kE4awkuxvlhOunO+5d6exizE6bYLMSUc5dTVQGpQPo1Tp1aFHNakfv 8xE= X-IronPort-AV: E=Sophos;i="5.63,471,1557158400"; d="scan'208";a="114198797" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jul 2019 03:21:47 +0800 IronPort-SDR: WCI0+jFpLLoX8h0GllL6PEf2zAhIImGKtnWnw8HV/NEqwEtRinnKeallcGtIJm55vx83CCq2Dx t88YbdAf0XHxF4fFZM/qlaRRARbKQwEqCFF6Cc3hPsGj3xgLY5DcXFSjEQaPCVdFjXgEwcntXY DAj63lPeygu8Z5wrXnasysoyJJCD0RBYu+sNu+9Zq6C2xkUVs22H/HX0yXXoKlnQDmrGEBk43A wdKQVLmuxp/UYuXyo+pUDojrxkeL2x5/Mf3gLco91QoX3gI+Ch5itJtjAtcQO4H7jc34MbxCXz rNl6WD46vsOrL2lu2bUyvEtW Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 09 Jul 2019 12:20:34 -0700 IronPort-SDR: RvvxTnNCmVe4eiZneO+4y8GfUHMJIOENi3CBe4NOUnpaZQY6+btsijgUHqSuCxkomfCuX8DpFc khGX2VHQ8RCpxlGb1J83wXc/JtPi/Fm6S2wTGGF88r3t5wpYvkDNAJfAYUwTDYhyd/VgrudMxF GhjKu9wOqivtT5FH+3VmYfBx+3FdjcMrTa5Ww11+qviw1BUHZTXlciQhIjcoS1B7dZZu+Nso8C yplLaASkKUKI2ZGNhHh7mn2hwu2LtcGy6aB3gawycUfdJ9hAR7ehRbDaqJfl82PVrpjtkj5LeL a80= Received: from cvenusqemu.hgst.com ([10.202.66.73]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Jul 2019 12:21:48 -0700 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org Cc: hch@lst.de, Chaitanya Kulkarni Subject: [PATCH V2 2/6] null_blk: create a helper for throttling Date: Tue, 9 Jul 2019 12:21:28 -0700 Message-Id: <20190709192132.24723-3-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190709192132.24723-1-chaitanya.kulkarni@wdc.com> References: <20190709192132.24723-1-chaitanya.kulkarni@wdc.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch creates a helper for handling throttling code in the null_handle_cmd(). Signed-off-by: Chaitanya Kulkarni --- drivers/block/null_blk_main.c | 39 ++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index b3be08edea43..4447c9729827 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1133,28 +1133,39 @@ static void null_restart_queue_async(struct nullb *nullb) blk_mq_start_stopped_hw_queues(q, true); } +static inline blk_status_t null_handle_throttled(struct nullb_cmd *cmd) +{ + struct nullb_device *dev = cmd->nq->dev; + struct nullb *nullb = dev->nullb; + blk_status_t sts = BLK_STS_OK; + struct request *rq = cmd->rq; + + if (!hrtimer_active(&nullb->bw_timer)) + hrtimer_restart(&nullb->bw_timer); + + if (atomic_long_sub_return(blk_rq_bytes(rq), &nullb->cur_bytes) < 0) { + null_stop_queue(nullb); + /* race with timer */ + if (atomic_long_read(&nullb->cur_bytes) > 0) + null_restart_queue_async(nullb); + /* requeue request */ + sts = BLK_STS_DEV_RESOURCE; + } + return sts; +} + static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, sector_t nr_sectors, enum req_opf op) { struct nullb_device *dev = cmd->nq->dev; struct nullb *nullb = dev->nullb; + blk_status_t sts; int err = 0; if (test_bit(NULLB_DEV_FL_THROTTLED, &dev->flags)) { - struct request *rq = cmd->rq; - - if (!hrtimer_active(&nullb->bw_timer)) - hrtimer_restart(&nullb->bw_timer); - - if (atomic_long_sub_return(blk_rq_bytes(rq), - &nullb->cur_bytes) < 0) { - null_stop_queue(nullb); - /* race with timer */ - if (atomic_long_read(&nullb->cur_bytes) > 0) - null_restart_queue_async(nullb); - /* requeue request */ - return BLK_STS_DEV_RESOURCE; - } + sts = null_handle_throttled(cmd); + if (sts != BLK_STS_OK) + return sts; } if (op == REQ_OP_FLUSH) { From patchwork Tue Jul 9 19:21:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 11037435 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D75F14E5 for ; Tue, 9 Jul 2019 19:21:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F62F287C8 for ; Tue, 9 Jul 2019 19:21:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31F1F2887D; Tue, 9 Jul 2019 19:21:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AC97287C8 for ; Tue, 9 Jul 2019 19:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727691AbfGITVz (ORCPT ); Tue, 9 Jul 2019 15:21:55 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:64981 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726133AbfGITVy (ORCPT ); Tue, 9 Jul 2019 15:21:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1562700114; x=1594236114; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=qXxaN3EnOKWt+mVXH2Ti5lEftO4p56AMv4vb1RapLbM=; b=ZOZpfIp7sXVlqMfUg1p2p5En5j0KOfTJXUfY+Uf8npWMzA96WmYQ148U sSQW25c+8sT6O1n9X63CnFwPqmRb3YwMkfSNKLMl4mUGb/fgjFpOwZvI6 ruf7N1xhB0U0HxnH7CFlYFXjExvwZ7R2Musij3Oj+EFFkGFJLcTEMVmiY XgXgMzqrWhnr9t0uRDWtW+odiveEnoS4/PEAqNmkvfwuc+GPZWtcHLhUF te2pchg33P1bt3bnxigyepo2MHonl2h/oMHYfIRdtPZInFvqbWKVMjhpN PXFNbVw9g7QmwiCOWx0jWuoUn/dDmw5ct2kkVal6lZRBXVvPbAHjfM1FK A==; IronPort-SDR: Nnb6mH+gPNN8pWC0JVq8DHP1QZIL4gh8tPn3sp385DVn809tfSmtfQCo4rpKoLTITrDJFybQEx FTC3WXLEvJZXXuLQHrBE3ydG4mS2T+b0IPFe6cTqe9q5W0ac6POT17LbKZjrqR9fVplBfr8DJ8 rqxi4+jSLWBFD1xLQD6COQzW9lYQQYsshwl40t4rS4s0q8AuptFsR3TEtER9k4ebKp8Xvm7avT BhC4Ekqz41EptPSB733c3H+XdUJFV048DWpW81vNw6cRxEz3xjPMQDyf5WKzW5Kzce6NMEO1fG ETM= X-IronPort-AV: E=Sophos;i="5.63,471,1557158400"; d="scan'208";a="218988593" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jul 2019 03:21:54 +0800 IronPort-SDR: cE6ZdB2y9pY1fFR/ESmhFAZEXiIH1bWspuBeqy9Sr+bHFkNEb7tD+Gh0XG05bPu265mxJGPRST VWHMrXQQYpozongJ5wF0RkD+bdGK6j7knuH8xtn2TxmzRSra7n3pdrqYXMd27t5UTWQ1F2Cqu/ 4mX1bDkrveJniHSZMMrPWEKWNrfE8S7V5ELGM4zJ2Ph06brrXuCfldwBEjgJvgu9pIcGgFialV sUbEL1Y/lU3ZjmAMeUMikYmBWy9uiFwI6XryspC4Vc/MKCHqHo0z4+B+LInqDv8NQDCRud3TBV fsKXfErfGVJH2gBc3LO5U1lW Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 09 Jul 2019 12:20:40 -0700 IronPort-SDR: cpPWiYVd9DeURlfFXUIgrvPznauuXn/2DqSeyanRG8SIqBHmtPeHW4B+V8ctcHeeEPI6I6yMlV LkPrPqtO2tn+BEUUyiCtknSHdb57L0g1OrEx1XTKRgmKERzfcNYYzyr11MKUD7oOCc5QGSwWav KeSRIGUQ3Qvhzp02ZZ/wNTVzAwpeRbGPV+lAbthwqvVPrJNRhxxg+eG3zn34WCH7YHFlc+NMzf 1TxxC60f39TLJc12nHL6MaBSYFCPsdy0ARsdU3u+PsbDWcYlUbkMNSHsRGCf4FE0gK17GZcQlS T7k= Received: from cvenusqemu.hgst.com ([10.202.66.73]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Jul 2019 12:21:54 -0700 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org Cc: hch@lst.de, Chaitanya Kulkarni Subject: [PATCH V2 3/6] null_blk: create a helper for badblocks Date: Tue, 9 Jul 2019 12:21:29 -0700 Message-Id: <20190709192132.24723-4-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190709192132.24723-1-chaitanya.kulkarni@wdc.com> References: <20190709192132.24723-1-chaitanya.kulkarni@wdc.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch creates a helper for handling badblocks code in the null_handle_cmd(). Signed-off-by: Chaitanya Kulkarni --- drivers/block/null_blk_main.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 4447c9729827..51ddd8d3a6ff 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1154,6 +1154,20 @@ static inline blk_status_t null_handle_throttled(struct nullb_cmd *cmd) return sts; } +static inline blk_status_t null_handle_badblocks(struct nullb_cmd *cmd, + sector_t sector, + sector_t nr_sectors) +{ + struct badblocks *bb = &cmd->nq->dev->badblocks; + sector_t first_bad; + int bad_sectors; + + if (badblocks_check(bb, sector, nr_sectors, &first_bad, &bad_sectors)) + return BLK_STS_IOERR; + + return BLK_STS_OK; +} + static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, sector_t nr_sectors, enum req_opf op) { @@ -1172,15 +1186,11 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, cmd->error = errno_to_blk_status(null_handle_flush(nullb)); goto out; } - if (nullb->dev->badblocks.shift != -1) { - int bad_sectors; - sector_t first_bad; - if (badblocks_check(&nullb->dev->badblocks, sector, nr_sectors, - &first_bad, &bad_sectors)) { - cmd->error = BLK_STS_IOERR; + if (nullb->dev->badblocks.shift != -1) { + cmd->error = null_handle_badblocks(cmd, sector, nr_sectors); + if (cmd->error != BLK_STS_OK) goto out; - } } if (dev->memory_backed) { From patchwork Tue Jul 9 19:21:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 11037439 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB59E1395 for ; Tue, 9 Jul 2019 19:22:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD312287C8 for ; Tue, 9 Jul 2019 19:22:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1CF12887D; Tue, 9 Jul 2019 19:22:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C633287C8 for ; Tue, 9 Jul 2019 19:22:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727697AbfGITWI (ORCPT ); Tue, 9 Jul 2019 15:22:08 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:43547 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726133AbfGITWH (ORCPT ); Tue, 9 Jul 2019 15:22:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1562700128; x=1594236128; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=ytpWZszUqzeUhrU8DV5JxJn9zpbttH7vVOaguydt/co=; b=IRxaN5kYD8w38mOR1hX0K/tZAssYWNnCaoZxacKQ6LOTIEoR4+YmUtcL KqnCaNPe3zPbHeft3C2hmHsM9ZgBO1ofC7qj/74Wt8vFYwGTjYCpi4nOJ YDF1XyfkufPxuGqppf3ykR9py9ntAH/WAvBsRucIbCJRpmOnwOAkWySLj y4DryCqBmqb+2eqRLkISjHlVB1o5FcZGzGTbuBlVn6q/HJsJHVWQt2jSV rB+Th8jG68GbZu5gm3kKIiG99tD6VJk3F9wnjK6ZZL8cleLNgHwxcxJyA sWwUaDWuPkglv5olVtireT//78hGIf0jYiBZ0I1OW2b31XVxPNcl24Lh5 w==; IronPort-SDR: 69bY4ud+tbBkZFroL4Wt4FhFr627YELeB6zZ2pd4qBNr/yroWyoEwYp0kX7ZdSa/omqI9z9pyA ZqAQLv0L4MiZ15S8Kses6r7VBXZeA+dwXuV7ZfuCWH/bAR/hrwqLWjs7bSuoYOC3fD3xD5/gDl cMlptL7DUpz6lU1jFtEJueLGQM7eDr/fm6cWGfS2ws7v1A5MZhRnTNL92itMel7E8E8W6hLBp9 ycAX7721h1sHwIcvIyqmxaVJ21eEm+rX0H177P+zmEQGoQ9hI3SZRJd/+tfZAZ4jwm4tvT+G7P nGw= X-IronPort-AV: E=Sophos;i="5.63,471,1557158400"; d="scan'208";a="112586188" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jul 2019 03:22:00 +0800 IronPort-SDR: zmHG7aOdkHRK1+V8DA10wr5+UaSkqKS6qVsrqJp/nRUKzgB2MHTtpnENJaTOQQHL83fVaNycag XEz1zkP46WkjN7sgBpxHCCbsVi0qPKRO/D51zsmRKXiHobjw97q5ZbvrihhsaV8rktwrKo5zKZ dJ5Ku6tm1uU2rIZNN2memkvKcg5bfxfAbho3Ue2KHkuOEniwTDkIlVAEqvmhSEaGw8WxOPKHr2 WvgmqPnA5seVkyDr46aRnR3mpSNYkJc66Tay5eveDelrd9EGVaWZibV165UZcwtY3MMaQMMYrV shKdvMQv6imDf4OyD9Z5j12Q Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 09 Jul 2019 12:20:46 -0700 IronPort-SDR: ljXeTsRS54v63TrgRoWZO2WRjkTnedRL6DjV20s2o25GG1Vzx07f0otGYjtL0Fek+18s4CWbMZ H88hsucaUBXyYVZ6yYABWCLMP5YZaTIPF2DVqeNJLRHq1fLcE9658g09lCcbngZduge9PGHwVs 5BdUBCcj5yKZZb4688QSmOLQcF0lM272Sfd5ZxHlIIbfawcUbtH+VNkciYfPgN31qL2j2iotiq OYFT7Q5XjZV5I9rlec0dIT8hZ9dfFHw30vkbE3etT5wuFU4Crljy/hGIq903mNP1EukIgHywUC tHA= Received: from cvenusqemu.hgst.com ([10.202.66.73]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Jul 2019 12:22:00 -0700 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org Cc: hch@lst.de, Chaitanya Kulkarni Subject: [PATCH V2 4/6] null_blk: create a helper for mem-backed ops Date: Tue, 9 Jul 2019 12:21:30 -0700 Message-Id: <20190709192132.24723-5-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190709192132.24723-1-chaitanya.kulkarni@wdc.com> References: <20190709192132.24723-1-chaitanya.kulkarni@wdc.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch creates a helper for handling requests when null_blk is memory backed in the null_handle_cmd(). Although the helper is very simple right now, it makes the code flow consistent with the rest of code in the null_handle_cmd() and provides a uniform code structure for future code. Signed-off-by: Chaitanya Kulkarni --- drivers/block/null_blk_main.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 51ddd8d3a6ff..7c503626a15c 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1168,13 +1168,26 @@ static inline blk_status_t null_handle_badblocks(struct nullb_cmd *cmd, return BLK_STS_OK; } +static inline blk_status_t null_handle_memory_backed(struct nullb_cmd *cmd, + enum req_opf op) +{ + struct nullb_device *dev = cmd->nq->dev; + int err; + + if (dev->queue_mode == NULL_Q_BIO) + err = null_handle_bio(cmd); + else + err = null_handle_rq(cmd); + + return errno_to_blk_status(err); +} + static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, sector_t nr_sectors, enum req_opf op) { struct nullb_device *dev = cmd->nq->dev; struct nullb *nullb = dev->nullb; blk_status_t sts; - int err = 0; if (test_bit(NULLB_DEV_FL_THROTTLED, &dev->flags)) { sts = null_handle_throttled(cmd); @@ -1193,14 +1206,8 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, goto out; } - if (dev->memory_backed) { - if (dev->queue_mode == NULL_Q_BIO) - err = null_handle_bio(cmd); - else - err = null_handle_rq(cmd); - } - - cmd->error = errno_to_blk_status(err); + if (dev->memory_backed) + cmd->error = null_handle_memory_backed(cmd, op); if (!cmd->error && dev->zoned) { if (op == REQ_OP_WRITE) From patchwork Tue Jul 9 19:21:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 11037437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54A8F14E5 for ; Tue, 9 Jul 2019 19:22:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 469C0287C8 for ; Tue, 9 Jul 2019 19:22:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AEE82887D; Tue, 9 Jul 2019 19:22:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A69E5287C8 for ; Tue, 9 Jul 2019 19:22:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726585AbfGITWH (ORCPT ); Tue, 9 Jul 2019 15:22:07 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:6039 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726133AbfGITWH (ORCPT ); Tue, 9 Jul 2019 15:22:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1562700126; x=1594236126; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=vka4gF+q3n34jM3TSnV4rsQD0pK1SOSpD7LRw7fJHTk=; b=rPkRgFVcxB42vx73dvVBeBAhF4hvw5cbbWayh1kRb+5VyRODb1U0u/PO 7wzgG9MyDFNgb1KPCQ1oUrSyyCTl/cc9R8fw3ORo0x8VgwM86tvRHRzv1 qDTrDGgRdakWi+dArL17ma0fP9juwt8qx1yAwAzVfi+Ue69NBj73r6Dtt p3s9tXonCVLJKu6dvA/N/MFP7WUcyButdUhOrVfSIXEe4Q4NnTEXbZ9gy Ftk0ZY9pk6vBLKZ39FOJINBwPAGiDYg3EnOr9mBYUYia/ryolnNG+VzNB rvZG4gqs5M9jWfpdX4KxFB0YzbbQ4sssuQiS4zaX+tCoD2JZvPNGoWrdJ g==; IronPort-SDR: UcYW8qVBRYkTv0TAiZlDqbE897NtmqtSWvlwyEeL34h7dPhLRanLW0hmJ46iV34FlEgfTWBII6 Ap1PmIUjVmDg7o8raQogccgLR36p7f4Mg3ZizPSaljBDc4Jp6tja5oaqYjRdGYthDYMJEcFLiY qVGimS7O8j9qs8XEmdRyw4GQBciHV5Fp+BCs5Tz7ujxmbsgXmjfLqE6naB5hDl3ckD1Ew/qrvp hCW50dZ+4VQX1wo8MBhrr7ZF2zJKm1WlvmX01+Q7sRfbop7wpb++REaDGJxi1MKSlPv0GPmDvA 8PQ= X-IronPort-AV: E=Sophos;i="5.63,471,1557158400"; d="scan'208";a="113750754" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jul 2019 03:22:06 +0800 IronPort-SDR: TBXsQRgzGX6yqlW6OLQgTRz7peh0nJgpqewbYabjEq7K8DeK06J7dh8Hsg/1Cfn3N5ioccv+zB p7ENJiUYX3PdLn6IxnNlDC891HbrlMGFTcSQDLfc2oZy4BdDkQfShpZo1noICjmzSrPs+XtOy8 q5cPe/JHRaDiNiMn7JnYoa4c1ZKjc4IItbVaAJCrK771RM98dq3ailfZM9PfSdR9o4xhz5iak7 h6dVpSaDvUXhMxWUN/2SNqaewSvEDRp0u/Y91eF9gGL8nJPG8wIVFZ7kCfm8vA/EPv5pYbhLX1 ldjsLi+FgACND1NXpAwFKcOL Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 09 Jul 2019 12:20:52 -0700 IronPort-SDR: +jtQ0NeqSwr1KLmICk4efLmnVD5S8oNjUqIzuv4/Wpc9iRR7ra24nFYxGRr1Kn/fHdyx9kGMAK yx83r07ig4+LFDYaq3iA8WWrCoTChOwK6ikXdYci5uV8xzE/Q4ZDgObgrnpwkBpYLNFxqf2bbB +ef2wfWdAmjoEqR/Mxj2XC01uEJm3uBxIqwAcLoPZN6FIar5nYSkGEiYScSGra2/hT1JWlxKsZ 6D8sciezMOBzJ4yzUOKMzXxlKV9vWT5x+oqzvNH+2YNbsP7Zgh7PLjTnn3hlmw2lphoTH8XOL6 a0E= Received: from cvenusqemu.hgst.com ([10.202.66.73]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Jul 2019 12:22:06 -0700 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org Cc: hch@lst.de, Chaitanya Kulkarni Subject: [PATCH V2 5/6] null_blk: create a helper for zoned devices Date: Tue, 9 Jul 2019 12:21:31 -0700 Message-Id: <20190709192132.24723-6-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190709192132.24723-1-chaitanya.kulkarni@wdc.com> References: <20190709192132.24723-1-chaitanya.kulkarni@wdc.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch creates a helper function for handling zoned block device operations. This patch also restructured the code for null_blk_zoned.c and uses the pattern to return blk_status_t and catch the error in the function null_handle_cmd() into cmd->error variable instead of setting it up in the deeper layer just like the way it is done for flush, badblocks and memory backed case in the null_handle_cmd(). Signed-off-by: Chaitanya Kulkarni --- drivers/block/null_blk.h | 20 ++++++++++++++------ drivers/block/null_blk_main.c | 29 +++++++++++++++++++++++------ drivers/block/null_blk_zoned.c | 29 ++++++++++++----------------- 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/drivers/block/null_blk.h b/drivers/block/null_blk.h index 34b22d6523ba..3681b992f7ea 100644 --- a/drivers/block/null_blk.h +++ b/drivers/block/null_blk.h @@ -91,9 +91,9 @@ void null_zone_exit(struct nullb_device *dev); int null_zone_report(struct gendisk *disk, sector_t sector, struct blk_zone *zones, unsigned int *nr_zones, gfp_t gfp_mask); -void null_zone_write(struct nullb_cmd *cmd, sector_t sector, - unsigned int nr_sectors); -void null_zone_reset(struct nullb_cmd *cmd, sector_t sector); +blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector, + unsigned int nr_sectors); +blk_status_t null_zone_reset(struct nullb_cmd *cmd, sector_t sector); #else static inline int null_zone_init(struct nullb_device *dev) { @@ -107,10 +107,18 @@ static inline int null_zone_report(struct gendisk *disk, sector_t sector, { return -EOPNOTSUPP; } -static inline void null_zone_write(struct nullb_cmd *cmd, sector_t sector, - unsigned int nr_sectors) + +static inline blk_status_t null_zone_write(struct nullb_cmd *cmd, + sector_t sector, + unsigned int nr_sectors) +{ + return BLK_STS_NOTSUPP; +} + +static inline blk_status_t null_zone_reset(struct nullb_cmd *cmd, + sector_t sector) { + return BLK_STS_NOTSUPP; } -static inline void null_zone_reset(struct nullb_cmd *cmd, sector_t sector) {} #endif /* CONFIG_BLK_DEV_ZONED */ #endif /* __NULL_BLK_H */ diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 7c503626a15c..8ec3753aaf9b 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1182,6 +1182,26 @@ static inline blk_status_t null_handle_memory_backed(struct nullb_cmd *cmd, return errno_to_blk_status(err); } +static inline blk_status_t null_handle_zoned(struct nullb_cmd *cmd, + enum req_opf op, sector_t sector, + sector_t nr_sectors) +{ + blk_status_t sts = BLK_STS_OK; + + switch (op) { + case REQ_OP_WRITE: + sts = null_zone_write(cmd, sector, nr_sectors); + break; + case REQ_OP_ZONE_RESET: + sts = null_zone_reset(cmd, sector); + break; + default: + break; + } + + return sts; +} + static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, sector_t nr_sectors, enum req_opf op) { @@ -1209,12 +1229,9 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, if (dev->memory_backed) cmd->error = null_handle_memory_backed(cmd, op); - if (!cmd->error && dev->zoned) { - if (op == REQ_OP_WRITE) - null_zone_write(cmd, sector, nr_sectors); - else if (op == REQ_OP_ZONE_RESET) - null_zone_reset(cmd, sector); - } + if (!cmd->error && dev->zoned) + cmd->error = null_handle_zoned(cmd, op, sector, nr_sectors); + out: /* Complete IO by inline, softirq or timer */ switch (dev->irqmode) { diff --git a/drivers/block/null_blk_zoned.c b/drivers/block/null_blk_zoned.c index fca0c97ff1aa..111b9ae6af6c 100644 --- a/drivers/block/null_blk_zoned.c +++ b/drivers/block/null_blk_zoned.c @@ -85,8 +85,8 @@ int null_zone_report(struct gendisk *disk, sector_t sector, return 0; } -void null_zone_write(struct nullb_cmd *cmd, sector_t sector, - unsigned int nr_sectors) +blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector, + unsigned int nr_sectors) { struct nullb_device *dev = cmd->nq->dev; unsigned int zno = null_zone_no(dev, sector); @@ -95,15 +95,12 @@ void null_zone_write(struct nullb_cmd *cmd, sector_t sector, switch (zone->cond) { case BLK_ZONE_COND_FULL: /* Cannot write to a full zone */ - cmd->error = BLK_STS_IOERR; - break; + return BLK_STS_IOERR; case BLK_ZONE_COND_EMPTY: case BLK_ZONE_COND_IMP_OPEN: /* Writes must be at the write pointer position */ - if (sector != zone->wp) { - cmd->error = BLK_STS_IOERR; - break; - } + if (sector != zone->wp) + return BLK_STS_IOERR; if (zone->cond == BLK_ZONE_COND_EMPTY) zone->cond = BLK_ZONE_COND_IMP_OPEN; @@ -111,27 +108,25 @@ void null_zone_write(struct nullb_cmd *cmd, sector_t sector, zone->wp += nr_sectors; if (zone->wp == zone->start + zone->len) zone->cond = BLK_ZONE_COND_FULL; - break; + return BLK_STS_OK; case BLK_ZONE_COND_NOT_WP: - break; + return BLK_STS_OK; default: /* Invalid zone condition */ - cmd->error = BLK_STS_IOERR; - break; + return BLK_STS_IOERR; } } -void null_zone_reset(struct nullb_cmd *cmd, sector_t sector) +blk_status_t null_zone_reset(struct nullb_cmd *cmd, sector_t sector) { struct nullb_device *dev = cmd->nq->dev; unsigned int zno = null_zone_no(dev, sector); struct blk_zone *zone = &dev->zones[zno]; - if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) { - cmd->error = BLK_STS_IOERR; - return; - } + if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) + return BLK_STS_IOERR; zone->cond = BLK_ZONE_COND_EMPTY; zone->wp = zone->start; + return BLK_STS_OK; } From patchwork Tue Jul 9 19:21:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 11037441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 935321395 for ; Tue, 9 Jul 2019 19:22:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84CFE287C8 for ; Tue, 9 Jul 2019 19:22:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 790832887D; Tue, 9 Jul 2019 19:22:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 210D3287C8 for ; Tue, 9 Jul 2019 19:22:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726133AbfGITWL (ORCPT ); Tue, 9 Jul 2019 15:22:11 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:63366 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727787AbfGITWL (ORCPT ); Tue, 9 Jul 2019 15:22:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1562700131; x=1594236131; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=gg1RQqZox7MSG1EY1vzn6USs2m3IemJZS3jkF39bG7g=; b=qDGjfDnO+kjJA9V7tv7VMxb8Llc8+K6m2JBsAwAk1ZT43Ngpn3kM0BES oFZtCE8m72y+n6ZQqYZVTyNPnCQUAcwr0QprdgcNDqn7NZNGzsFnZhdge giUctT7yitVc9dwSPogOZuAubjqFFEnsM7CKwjTdkBdbccCe+6F6JKU5N WTMqf+UX7FDSI1nPDRF4FFjrRMP/98jkwekt+0793fSkfGMKLXmJKucIz P9mQZDSDHpbgmPFykqukKIHf7Y41tK5lRHENA4tGadbBbEsuqiIc7UxyF ndVag+HaYTH/bP6SB3cI39kYnRfK4pksKKWAfTd4nyDxDJTpVfjmmr9L3 g==; IronPort-SDR: YpRHI6caJQwjWQoApXGBqaPwVvqTLfdOOd8hvRwROGqjja/waNnYpkpQLICCfbHZ/DSHGCQ2hs EkCEbgBOlvG2iYX8aOmI1zsInniegRTu0IOKkcgGsTnnpn5IHRc/NS96FkwdW8Fq1zpl8cM+6r YbTWff9FTc//Diu5fVGaepxt2qABWgDj/CemmOZaHgXDNlJ2Iw+TuSIHeb7Ixo5EJK/gKAGeNJ QEay38KVwRzF6Sl5HFt1aCgU8ZqdWVgIskF4sL1lmUTSbUzhM6zwgYhoKhMZi3XznG6KdPa75Z CaU= X-IronPort-AV: E=Sophos;i="5.63,471,1557158400"; d="scan'208";a="114198824" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Jul 2019 03:22:11 +0800 IronPort-SDR: 7Oc6RIRXmgSsvjDVDYkvv/7BeUxbI5734CqnE2bxxFeS2iw2xlfhtsI7CU90a3lc4XltG1JyaY quxfwdZHw8GyFt5MRVknA3hyu6X2n30gIbwj+dWH8Flh/G2Ig2farYArYh/lzJoEeIsJV8auic lP8/vo3adyFkY5Mv7kxOp7g9D9+kGmpibSdLQPj6hufG+JI61OsImWE/xBPcdcyzWWWi+giWRX d9JO6s/b2qcoaS2SQZH2QQ6R4B6WcUapIReQHdONjBRsQMuFBLyEKxTH0Zt3EJeU9DIsWzzn9D UEyb7Vk0SNkEsgK7T+F8GRmE Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 09 Jul 2019 12:20:57 -0700 IronPort-SDR: h+XBQAHf1vBsdEeyLrebeAOjXI//MEA9hzO3EFKvl4sJe3uhdRiBy5mpgL/5PptdwxJ061qVw3 C17b3qL2bBTQ73T3NKtzWGUK8xQJEu1igl+GIBDG13Oq/+GTVh2VQciUsYJwRfiTaHmXgGKt1S XOIPlHLQE9Pt/J09GTv6taJi8zC2Vfw+XZRYE4+UIY6K2wTao3OZxSeaVRG4I5aohMDl3Bw7OT FborN/hdx9nNMwrzSfuXlW1Xbz+BcbT3e/YUibPIBDmwpnCHKK6hbS4zaDEViGEgZF9Ty6nYGx ks0= Received: from cvenusqemu.hgst.com ([10.202.66.73]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Jul 2019 12:22:11 -0700 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org Cc: hch@lst.de, Chaitanya Kulkarni Subject: [PATCH V2 6/6] null_blk: create a helper for req completion Date: Tue, 9 Jul 2019 12:21:32 -0700 Message-Id: <20190709192132.24723-7-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20190709192132.24723-1-chaitanya.kulkarni@wdc.com> References: <20190709192132.24723-1-chaitanya.kulkarni@wdc.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch creates a helper function for handling the request completion in the null_handle_cmd(). Reviewed-by: Christoph Hellwig Signed-off-by: Chaitanya Kulkarni --- drivers/block/null_blk_main.c | 49 +++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 8ec3753aaf9b..e9bd599516cc 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1202,6 +1202,32 @@ static inline blk_status_t null_handle_zoned(struct nullb_cmd *cmd, return sts; } +static inline void nullb_handle_cmd_completion(struct nullb_cmd *cmd) +{ + /* Complete IO by inline, softirq or timer */ + switch (cmd->nq->dev->irqmode) { + case NULL_IRQ_SOFTIRQ: + switch (cmd->nq->dev->queue_mode) { + case NULL_Q_MQ: + blk_mq_complete_request(cmd->rq); + break; + case NULL_Q_BIO: + /* + * XXX: no proper submitting cpu information available. + */ + end_cmd(cmd); + break; + } + break; + case NULL_IRQ_NONE: + end_cmd(cmd); + break; + case NULL_IRQ_TIMER: + null_cmd_end_timer(cmd); + break; + } +} + static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, sector_t nr_sectors, enum req_opf op) { @@ -1233,28 +1259,7 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector, cmd->error = null_handle_zoned(cmd, op, sector, nr_sectors); out: - /* Complete IO by inline, softirq or timer */ - switch (dev->irqmode) { - case NULL_IRQ_SOFTIRQ: - switch (dev->queue_mode) { - case NULL_Q_MQ: - blk_mq_complete_request(cmd->rq); - break; - case NULL_Q_BIO: - /* - * XXX: no proper submitting cpu information available. - */ - end_cmd(cmd); - break; - } - break; - case NULL_IRQ_NONE: - end_cmd(cmd); - break; - case NULL_IRQ_TIMER: - null_cmd_end_timer(cmd); - break; - } + nullb_handle_cmd_completion(cmd); return BLK_STS_OK; }