From patchwork Tue Jan 12 04:26:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 12012341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8000FC433DB for ; Tue, 12 Jan 2021 04:27:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 514AA22D2A for ; Tue, 12 Jan 2021 04:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730220AbhALE1q (ORCPT ); Mon, 11 Jan 2021 23:27:46 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:6643 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730197AbhALE1p (ORCPT ); Mon, 11 Jan 2021 23:27:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610426418; x=1641962418; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=88Lp0y2hIyhYG8It0MWl/SOspuKedN/u1kjgeCCanzg=; b=ILiOzTBz2Jlf2Fp5mSCpEYLM+MVy2KE4QAhYOkTzgYfsByNbmHUIpojB yeGZ2VhvKLXdCuhsddHcZ4RUeyKZa867WN+wo2EgetONj+86aoNB+rJva LpWNFOmhKxXvkRT1EoxowikJLXE67eYl4TmhFSjQgcxMjFTLPSLzdPoya lcOPzY4yr93m60W5xXeu5T/kX7hBnt+pIVcLBXZF1uQYo1ShEiURkUsEl ieyrns6zJKWiXXz6cm1LJXjnDXjVAHNU2P2TG7ZgLaPQ9WLlHAtAgpOgz NqrgCj3J9nlTv7Y2ysLPY6wgEIB3wf4HkZphFlJ0aqTN1oS7IaKLvYvON w==; IronPort-SDR: tQZHPldbDQRGUdIFgscvMVgLhzrEqvCPPKrsBmsMkayMSh1Cch69JZKW+MnUYMA7FQmR9uGGsb dMdYiBQ024TqlrOuMuTWYMJdy4nlPshKE77u9MbMRF3oBtHu82q/sZrIgHawOn9IK71i/WzdNS 4K8qou+Z994yWeyYojWJYXzHDCD0Kz5dyKPZU7tEQDy2YOQDaln6JauXHEYHzveJRJFtrHkz1I xHSh57uPTIP+58F3Nw6KEiSyd0dDQpRTfQ9NkkX/bViEAv7oXD3gw2poF9zi7wCo8WwOBQSk7k GT4= X-IronPort-AV: E=Sophos;i="5.79,340,1602518400"; d="scan'208";a="261100110" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Jan 2021 12:38:39 +0800 IronPort-SDR: gdhAheiuG8avzS+OHvGnLsz76Xt9pbnNTGzo2omdKn9hZJ7cocHLK1G0jkqgm5OUzkc+NjnBWR zRHRXseqXE/MQBsyiXQfBSCCxg0fQFgCl4F7Tjj2gU7+MJngrvmiK9YFKcYjYjn+jGVs/rW6+g MiDUW288gfl4AScS3dNhLchm9X1P3O6EKx8OTrlOX4G2udMfxxU1NngFC8Iv8mQJ2yU1k5hWSi xPeMGaRcaBpYkHBzChZqlmwkDOQDOO0pSHUyoDHK/HYkJ6dyrfjAKueo5Quh2QS6+56fe5jCaw GOlt5taUuxL2OdmPEfe/9p1e Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2021 20:09:33 -0800 IronPort-SDR: z9UEULbt+pn4EiVfrtpVYsW4uNE3iQHb/kMaXpXrBGK5OJsYzeRp8/hluQMcJj+0oxxb4BOTbx xvXDFYSk7usjy+NsJx+AIjnABMWluqNdvJtxanQhSkRgwFQ4QONUbof8F+2EKSGyu0Mon9pjaa 0rVURICapY2zI2/O5zVoA830o5l7BDqAfRmxT80F1QnkfY8SsV42ZCfFy+74SA1zsH4m3PCfyM 0Ng4P/kMJOr7Wet+ZDCOW2Vb7mhGjyrKTrk416ogQExjh1DYMSV4MbHRyVEEMceeb8SkLzH/Lu ROk= WDCIronportException: Internal Received: from vm.labspan.wdc.com (HELO vm.sc.wdc.com) ([10.6.137.102]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Jan 2021 20:26:39 -0800 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Cc: hch@lst.de, sagi@grimberg.me, damien.lemoal@wdc.com, Chaitanya Kulkarni Subject: [PATCH V9 1/9] block: export bio_add_hw_pages() Date: Mon, 11 Jan 2021 20:26:15 -0800 Message-Id: <20210112042623.6316-2-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> References: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org To implement the NVMe Zone Append command on the NVMeOF target side for generic Zoned Block Devices with NVMe Zoned Namespaces interface, we need to build the bios with hardware limitations, i.e. we use bio_add_hw_page() with queue_max_zone_append_sectors() instead of bio_add_page(). Without this API being exported NVMeOF target will require to use bio_add_hw_page() caller bio_iov_iter_get_pages(). That results in extra work which is inefficient. Export the API so that NVMeOF ZBD over ZNS backend can use it to build Zone Append bios. Signed-off-by: Chaitanya Kulkarni Reviewed-by: Damien Le Moal --- block/bio.c | 1 + block/blk.h | 4 ---- include/linux/blkdev.h | 4 ++++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/block/bio.c b/block/bio.c index 1f2cc1fbe283..5cbd56b54f98 100644 --- a/block/bio.c +++ b/block/bio.c @@ -826,6 +826,7 @@ int bio_add_hw_page(struct request_queue *q, struct bio *bio, bio->bi_iter.bi_size += len; return len; } +EXPORT_SYMBOL(bio_add_hw_page); /** * bio_add_pc_page - attempt to add page to passthrough bio diff --git a/block/blk.h b/block/blk.h index 7550364c326c..200030b2d74f 100644 --- a/block/blk.h +++ b/block/blk.h @@ -351,8 +351,4 @@ int bdev_resize_partition(struct block_device *bdev, int partno, sector_t start, sector_t length); int disk_expand_part_tbl(struct gendisk *disk, int target); -int bio_add_hw_page(struct request_queue *q, struct bio *bio, - struct page *page, unsigned int len, unsigned int offset, - unsigned int max_sectors, bool *same_page); - #endif /* BLK_INTERNAL_H */ diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 070de09425ad..028ccc9bdf8d 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -2005,6 +2005,10 @@ struct block_device *I_BDEV(struct inode *inode); struct block_device *bdgrab(struct block_device *bdev); void bdput(struct block_device *); +int bio_add_hw_page(struct request_queue *q, struct bio *bio, + struct page *page, unsigned int len, unsigned int offset, + unsigned int max_sectors, bool *same_page); + #ifdef CONFIG_BLOCK void invalidate_bdev(struct block_device *bdev); int truncate_bdev_range(struct block_device *bdev, fmode_t mode, loff_t lstart, From patchwork Tue Jan 12 04:26:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 12012343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C243C433E0 for ; Tue, 12 Jan 2021 04:27:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CBDA22D2A for ; Tue, 12 Jan 2021 04:27:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730223AbhALE1z (ORCPT ); Mon, 11 Jan 2021 23:27:55 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:42623 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726488AbhALE1z (ORCPT ); Mon, 11 Jan 2021 23:27:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610425675; x=1641961675; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+dzMfelXKXKTtvlSdWk9DFOOoxVVf6e3u02T42xzOzM=; b=m3qLDUDSTylXMRUV/syV7FhNHqYCK63njIcTu37JGi9LYTTndgm8E4l0 vITzFu6W/+XeusAZnsGFLvJBOlSG8JTXSxxcbEWm7oSi135S4HOxL743E yyEo+kOgqhM4TUXb9enxTW1JzgJr6QH2Xk1YFwtg4Dg8wnP4gKhbxfm90 xgg53RQWWNcD+J8VCjJwdauGRljbYx1dDZzbkjg46mShscrjkE+K0EP3o ZkTE1FOGOpn0MXkvS1m6ewHnrcHwsY+iXrh+niZLLnMxG1+as7xnDfGTC L7wnqs6v2flZ1Avz3AZvMbEAhtUnqDPkKzClO5LoTmykXrYv1MxJ60O1i g==; IronPort-SDR: 7FGhWyqfYaObv5ON45zAIoI6Vkfm7uavj2A2H6velOZVjZBvBL6GDQymz7ZSXY4skIr7etxFHM 2s8g3zU62p+IZ0TG5W5LySSf9gqLbe6ij2e9qRUt49R/+wgxNNWRZtGIasRZBEBf9s1qsd7O7E rgci1aoWIgnOn9f2E41kS8YH2DdgZo2zHrchzyHwQerjznWk+7ftc0tD2B0E2baW1WpPkTu3CV KfQLQfERUqByA1umOpHXnGudpoURQf93RKRj4r2GPYNu7Lnbj/oB7Km8CHnCyrQp26UyM/0cww mII= X-IronPort-AV: E=Sophos;i="5.79,340,1602518400"; d="scan'208";a="267504787" 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; 12 Jan 2021 12:26:49 +0800 IronPort-SDR: lg4u8IOroxriMYnGtsTVload1teXtVaqN3DjzFk3ydi4oDz9zVyM69yxXA6jjoB0Oc6GQV6NVF WoBDOwK1b344AUUDotal6pJHrRxEv6oWglcZeYEn5iTkwzsql6Ni511RGdo2eeqzEhnLxL7tYC qGM1kctA/AUavhcsfj+PHTDUPtYNkVaM0R5Pb+UzTS7yeUq0teGLbxkRd1jdJ0uHVA09gQ3TuZ Uq46MQy89dD2F5e/uzu5KZAu44ncJFeBGacuYoSYuiXWylVbQH76qyoIc9rumU7bquykq/vI7V ej0auU8/Hct78cJ+gVL7HSs+ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2021 20:11:35 -0800 IronPort-SDR: TL3SMAN4xBZTCWgOcB7qrMyfXMq+v+dIkYcgd8fk8wm/f0XrOO7oKqKfN6qbvV81ui7rbbUL+D jYYVBqeZTPdsnA0SWeIOLBJ+vgFR9dOG+Ey7HKAa5NBWHp1R6VVemmMlhFYk/KVecLUqCwrzn1 OZ6Um8+0/xsCkbYy/nU7ojODUrrkPU1I/AVyHghuDphaFIJ9bPd96jTIp1w1+xGLfR9+dPXBnj SOiXrsH9cstotShUvkwy4s/4L7nFk6+j06UVVjRaFG/QB/DqUGzPOU+AwASS9WDIKc9i1oUCEU U8E= WDCIronportException: Internal Received: from vm.labspan.wdc.com (HELO vm.sc.wdc.com) ([10.6.137.102]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Jan 2021 20:26:49 -0800 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Cc: hch@lst.de, sagi@grimberg.me, damien.lemoal@wdc.com, Chaitanya Kulkarni Subject: [PATCH V9 2/9] nvmet: add lba to sect conversion helpers Date: Mon, 11 Jan 2021 20:26:16 -0800 Message-Id: <20210112042623.6316-3-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> References: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org In this preparation patch, we add helpers to convert lbas to sectors & sectors to lba. This is needed to eliminate code duplication in the ZBD backend. Use these helpers in the block device backend. Signed-off-by: Chaitanya Kulkarni Reviewed-by: Damien Le Moal --- drivers/nvme/target/io-cmd-bdev.c | 8 +++----- drivers/nvme/target/nvmet.h | 10 ++++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index 125dde3f410e..23095bdfce06 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -256,8 +256,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req) if (is_pci_p2pdma_page(sg_page(req->sg))) op |= REQ_NOMERGE; - sector = le64_to_cpu(req->cmd->rw.slba); - sector <<= (req->ns->blksize_shift - 9); + sector = nvmet_lba_to_sect(req->ns, req->cmd->rw.slba); if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) { bio = &req->b.inline_bio; @@ -345,7 +344,7 @@ static u16 nvmet_bdev_discard_range(struct nvmet_req *req, int ret; ret = __blkdev_issue_discard(ns->bdev, - le64_to_cpu(range->slba) << (ns->blksize_shift - 9), + nvmet_lba_to_sect(ns, range->slba), le32_to_cpu(range->nlb) << (ns->blksize_shift - 9), GFP_KERNEL, 0, bio); if (ret && ret != -EOPNOTSUPP) { @@ -414,8 +413,7 @@ static void nvmet_bdev_execute_write_zeroes(struct nvmet_req *req) if (!nvmet_check_transfer_len(req, 0)) return; - sector = le64_to_cpu(write_zeroes->slba) << - (req->ns->blksize_shift - 9); + sector = nvmet_lba_to_sect(req->ns, write_zeroes->slba); nr_sector = (((sector_t)le16_to_cpu(write_zeroes->length) + 1) << (req->ns->blksize_shift - 9)); diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 592763732065..8776dd1a0490 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -603,4 +603,14 @@ static inline bool nvmet_ns_has_pi(struct nvmet_ns *ns) return ns->pi_type && ns->metadata_size == sizeof(struct t10_pi_tuple); } +static inline __le64 nvmet_sect_to_lba(struct nvmet_ns *ns, sector_t sect) +{ + return cpu_to_le64(sect >> (ns->blksize_shift - SECTOR_SHIFT)); +} + +static inline sector_t nvmet_lba_to_sect(struct nvmet_ns *ns, __le64 lba) +{ + return le64_to_cpu(lba) << (ns->blksize_shift - SECTOR_SHIFT); +} + #endif /* _NVMET_H */ From patchwork Tue Jan 12 04:26:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 12012345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71573C433E0 for ; Tue, 12 Jan 2021 04:28:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3892922D06 for ; Tue, 12 Jan 2021 04:28:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730244AbhALE2G (ORCPT ); Mon, 11 Jan 2021 23:28:06 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:45032 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726488AbhALE2F (ORCPT ); Mon, 11 Jan 2021 23:28:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610425684; x=1641961684; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5oJdIDGlpsP6n3kwAZZVN2mir1iK0wjOoG2w4OEl0H0=; b=H4Zg9ko8X4KWWFMJDsGVmNzov55P+y4fYk+HK2C795k+TkXuYrgMjvpW a4CKr4LhdKpqeeFWucO0hjreA+KbU/BS3BRwelaIQ5uf9MnrP7qBGKjg4 NNP74IvfJ/MkJxIpkKwQWRYdRtmNLYyrtRTNKJRqVrYlIzShMPMIIPxxR /uXCbOAbKPrGENgZ1TqASAqWDsa0NOheAi0U5pSru/XMcOPmWIMTsiIAV qi+2Hr+Hx474ZtPw1QzFUKNWObrmvlkx5zEWRRmtdAwOvR35rfZhNi6uT VR4Xn1YEjMDTlT701TdW/zbhMWWf57V7KNDKgtj86SNNVrE8QtxfFtu/y w==; IronPort-SDR: 3zAwU/N415il4CRQdRplPz12XVI2S+hR8RmOOgxZhJtnxP2WG+BD83ytWjAx/tpVYFynzr1Mts lwiRbsS2sdvJayaLegHZYqHt4ScI+2hvBTtO+hSzlXyoABWpy++vZ4KMdc0XN+DJmG1xGXOJvg hh+LFMzHp1iTj8MrGKy48yX7WoH0JwDjMZ7Er/qkjHlNxH/vLvelxOaPhZw04DiL7rBrIcTCxt iGPF2nh8W+raATnwcLA9vZkibUlMf0j3Kq07tcrXN2oIdEQEYd/EyjTlQWcxPLdsvFwAkzMDwV G60= X-IronPort-AV: E=Sophos;i="5.79,340,1602518400"; d="scan'208";a="157206004" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jan 2021 12:26:59 +0800 IronPort-SDR: TO+BnsI22XRb3zWeDv1z2th1n4Ht3HPOPSsdK1FKN6esBmrNqwhX9B9tLJ8NSKQLt47iNJIWOP Vlz9Sb+3FGw34I8CWokGhWpJlmrVJi74QSDH6jAOBJbZIVx/c13MoPOLlQbZIv52y+At2HYRTT fUax0CEYnYfmfNrstzsmsodRFAAJLe26aqdSpJoC+AfinUlmsO3vnH1vjo30Cnrhl2ce09euVs EC6/81UCvfNcLyBSDmgyDRAk/q3KexDxJQfz/x8wGlcorMubguvyg/PfcEeGZO77c7Ankvizkl cfx5v++0o854xMQG6CFb36WF Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2021 20:11:44 -0800 IronPort-SDR: 5tcbuCrnima+qrRYPl+XXvfBdfZMMg8R9+BujLNi9Hdn3yz2inYcmxD9JrRBkW0JTIipRG3L3P zso2NlDuXJ+8aoQBJRpAp+eLpgpKGSPMWCikVrgLAJZ726CheY34uiFjNTCxwG9jBIYgQ6XVYb aoza38PReyXrBY9L4EdHSAndGz0tMFW6L2/QjKb6V6pv8uk7q3PoUdMfvb65ifMGeCoIXSm8dw ROMMhPwEykcTRPdnnfAy8Nb5Vyt545rYdUGMSTX7YvK+Q9ljtn2fnVNxFfTL5aAlx1MfP7Tqk4 OgE= WDCIronportException: Internal Received: from vm.labspan.wdc.com (HELO vm.sc.wdc.com) ([10.6.137.102]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Jan 2021 20:26:59 -0800 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Cc: hch@lst.de, sagi@grimberg.me, damien.lemoal@wdc.com, Chaitanya Kulkarni Subject: [PATCH V9 3/9] nvmet: add NVM command set identifier support Date: Mon, 11 Jan 2021 20:26:17 -0800 Message-Id: <20210112042623.6316-4-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> References: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org NVMe TP 4056 allows controller to support different command sets. NVMeoF target currently only supports namespaces that contain traditional logical blocks that may be randomly read and written. In some applications there is value in exposing namespaces that contain logical blocks that have special access rules (e.g. sequentially write required namespace such as Zoned Namespace (ZNS)). In order to support the Zoned Block Devices (ZBD) backend, controller needs to have support for ZNS Command Set Identifier (CSI). In this preparation patch, we adjust the code such that it can now support different command sets. We update the namespace data structure to store the CSI value which defaults to NVME_CSI_NVM which represents traditional logical blocks namespace type. The CSI support is required to implement the ZBD backend over NVMe ZNS interface, since ZNS commands belongs to the different command set than the default one. Signed-off-by: Chaitanya Kulkarni --- drivers/nvme/target/admin-cmd.c | 39 ++++++++++++++++++++++----------- drivers/nvme/target/core.c | 13 ++++++++++- drivers/nvme/target/nvmet.h | 1 + 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c index 220edacfccfb..a50b7bcac67a 100644 --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c @@ -175,19 +175,26 @@ static void nvmet_execute_get_log_cmd_effects_ns(struct nvmet_req *req) if (!log) goto out; - log->acs[nvme_admin_get_log_page] = cpu_to_le32(1 << 0); - log->acs[nvme_admin_identify] = cpu_to_le32(1 << 0); - log->acs[nvme_admin_abort_cmd] = cpu_to_le32(1 << 0); - log->acs[nvme_admin_set_features] = cpu_to_le32(1 << 0); - log->acs[nvme_admin_get_features] = cpu_to_le32(1 << 0); - log->acs[nvme_admin_async_event] = cpu_to_le32(1 << 0); - log->acs[nvme_admin_keep_alive] = cpu_to_le32(1 << 0); - - log->iocs[nvme_cmd_read] = cpu_to_le32(1 << 0); - log->iocs[nvme_cmd_write] = cpu_to_le32(1 << 0); - log->iocs[nvme_cmd_flush] = cpu_to_le32(1 << 0); - log->iocs[nvme_cmd_dsm] = cpu_to_le32(1 << 0); - log->iocs[nvme_cmd_write_zeroes] = cpu_to_le32(1 << 0); + switch (req->cmd->get_log_page.csi) { + case NVME_CSI_NVM: + log->acs[nvme_admin_get_log_page] = cpu_to_le32(1 << 0); + log->acs[nvme_admin_identify] = cpu_to_le32(1 << 0); + log->acs[nvme_admin_abort_cmd] = cpu_to_le32(1 << 0); + log->acs[nvme_admin_set_features] = cpu_to_le32(1 << 0); + log->acs[nvme_admin_get_features] = cpu_to_le32(1 << 0); + log->acs[nvme_admin_async_event] = cpu_to_le32(1 << 0); + log->acs[nvme_admin_keep_alive] = cpu_to_le32(1 << 0); + + log->iocs[nvme_cmd_read] = cpu_to_le32(1 << 0); + log->iocs[nvme_cmd_write] = cpu_to_le32(1 << 0); + log->iocs[nvme_cmd_flush] = cpu_to_le32(1 << 0); + log->iocs[nvme_cmd_dsm] = cpu_to_le32(1 << 0); + log->iocs[nvme_cmd_write_zeroes] = cpu_to_le32(1 << 0); + break; + default: + status = NVME_SC_INVALID_LOG_PAGE; + break; + } status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log)); @@ -606,6 +613,7 @@ static u16 nvmet_copy_ns_identifier(struct nvmet_req *req, u8 type, u8 len, static void nvmet_execute_identify_desclist(struct nvmet_req *req) { + u16 nvme_cis_nvm = NVME_CSI_NVM; u16 status = 0; off_t off = 0; @@ -631,6 +639,11 @@ static void nvmet_execute_identify_desclist(struct nvmet_req *req) goto out; } + status = nvmet_copy_ns_identifier(req, NVME_NIDT_CSI, NVME_NIDT_CSI_LEN, + &nvme_cis_nvm, &off); + if (status) + goto out; + if (sg_zero_buffer(req->sg, req->sg_cnt, NVME_IDENTIFY_DATA_SIZE - off, off) != NVME_IDENTIFY_DATA_SIZE - off) status = NVME_SC_INTERNAL | NVME_SC_DNR; diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index 8ce4d59cc9e7..672e4009f8d6 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -681,6 +681,7 @@ struct nvmet_ns *nvmet_ns_alloc(struct nvmet_subsys *subsys, u32 nsid) uuid_gen(&ns->uuid); ns->buffered_io = false; + ns->csi = NVME_CSI_NVM; return ns; } @@ -1103,6 +1104,16 @@ static inline u8 nvmet_cc_iocqes(u32 cc) return (cc >> NVME_CC_IOCQES_SHIFT) & 0xf; } +static inline bool nvmet_cc_css_check(u8 cc_css) +{ + switch (cc_css <<= NVME_CC_CSS_SHIFT) { + case NVME_CC_CSS_NVM: + return true; + default: + return false; + } +} + static void nvmet_start_ctrl(struct nvmet_ctrl *ctrl) { lockdep_assert_held(&ctrl->lock); @@ -1111,7 +1122,7 @@ static void nvmet_start_ctrl(struct nvmet_ctrl *ctrl) nvmet_cc_iocqes(ctrl->cc) != NVME_NVM_IOCQES || nvmet_cc_mps(ctrl->cc) != 0 || nvmet_cc_ams(ctrl->cc) != 0 || - nvmet_cc_css(ctrl->cc) != 0) { + !nvmet_cc_css_check(nvmet_cc_css(ctrl->cc))) { ctrl->csts = NVME_CSTS_CFS; return; } diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 8776dd1a0490..476b3cd91c65 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -81,6 +81,7 @@ struct nvmet_ns { struct pci_dev *p2p_dev; int pi_type; int metadata_size; + u8 csi; }; static inline struct nvmet_ns *to_nvmet_ns(struct config_item *item) From patchwork Tue Jan 12 04:26:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 12012347 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3C90C433E0 for ; Tue, 12 Jan 2021 04:28:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 778D122D2A for ; Tue, 12 Jan 2021 04:28:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730255AbhALE2P (ORCPT ); Mon, 11 Jan 2021 23:28:15 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:18338 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730254AbhALE2O (ORCPT ); Mon, 11 Jan 2021 23:28:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610425693; x=1641961693; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8nr69gFH9bSiGWWY4mlJkYxXq5QtwWGjTXZF/Q33xjM=; b=hR9GYiKdVVubjTICo86tUTCW4yn8eIB95R5D3l0BhAwXWwm0n7ShLK+j G0b9x77gMbEjuv+mJ28M5r2+lTuk6IN3853viEXfLCEHt8fojHRq1kzXV Vz/ldVt5nLX7XGJoqNC5bIUyky7uOdSxJBj8ZG1U6Vh5plOsbO2IipEb+ vo9fdWHC6gIMXqQucauTIQ2kB4aYf4PtpEh5356EkdfjJrWuniNqy40CC DFpjdHmZlKPVPItw4sWFmC9YuDyhoinqDxXNtxsmyrtfg1okkTuVrS/fT YwsxG99McPIOEeC7xTi8AZ3satIGLf/RjZcH3EWNxVTDKdRKRyFMGKUoq Q==; IronPort-SDR: Tf5JGKLIBlEd47pOlj4EspJfbfj3ylpY85TH0d6j86AlU8pGcuNKWXL9pyY8cS27UixdY+LMf1 SVgKqR8dSdvSppTZLZ1UI9J91sM15Rzo3I2CCCOCbqdPflh0WNTsITPBobfTO00tkPgslWiJHQ BHAfD1ftmrnL9RwRfw/MrDfdEyQiZsk8s+kLo8PJ628pcVZZ00ECUE2gIqedpEIzCXlEVbUNiC JD5QP+2UzueeRPhK4ruuYHCqAqiwFZN1hxOJ2cB2jrghXLAj3VF8406K905fGh7Q8mwgBILGAv QnU= X-IronPort-AV: E=Sophos;i="5.79,340,1602518400"; d="scan'208";a="161648558" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jan 2021 12:27:08 +0800 IronPort-SDR: qMbJ9lHFKtBXqtJhb6yziol8nKbapUgX83Jqtvn5TDsx4VH8UcX14dLXZTIQgxJFYzFo85WKnQ bGrMmYJJdmpMwR/3YE/vLZLeye4Gdm5x0KtRj0oJpE2YycPh7hcHA8V/gMFtuY52tzM1BljnQV /GPXJZGKL1LJECYA9jNpgasiuV+Bt7HAG3SCU+7gNJ/x4Oy49e4qZhcQtACbjTV0O2ye+CCGXH qnVyB+JKKvgq88JG0k4GeYCeWpXGQ78CyrAWUWv/+YtrFwnX4JgveLtNl+5MVn/fXeDuHys09m sl99e+wR4KNFjFuD4RJUqpQt Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2021 20:11:54 -0800 IronPort-SDR: JKv1UpYiuwliFUl8CBoAEsbyvG3U1/jceLE615tK35bnnBgUj5qwZ189Pgc+2h+gbsfE4EA7Y7 bOpDYH2YjR4PpCYt2MCuGPslKudA3KGBkVCJhUFV7o5E/9ijwTUJoBrstvSVly7/S4vgMKorSn Dc9oJhbhZxRUiAFOy/AzWoN2UY8Xp+C+D5zEVwfyd6NbSKzFEo5rsyclK2Tmyh96amXxvRAiEI DKgvtazY1JONCZ4ep0zojSaWM59XQHkDqfCybxyKbBvZ9jIWmWolfXUBGlkOmsXVBqnBW9E84D /no= WDCIronportException: Internal Received: from vm.labspan.wdc.com (HELO vm.sc.wdc.com) ([10.6.137.102]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Jan 2021 20:27:08 -0800 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Cc: hch@lst.de, sagi@grimberg.me, damien.lemoal@wdc.com, Chaitanya Kulkarni Subject: [PATCH V9 4/9] nvmet: add ZBD over ZNS backend support Date: Mon, 11 Jan 2021 20:26:18 -0800 Message-Id: <20210112042623.6316-5-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> References: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org NVMe TP 4053 – Zoned Namespaces (ZNS) allows host software to communicate with a non-volatile memory subsystem using zones for NVMe protocol based controllers. NVMeOF already support the ZNS NVMe Protocol compliant devices on the target in the passthru mode. There are Generic zoned block devices like Shingled Magnetic Recording (SMR) HDDs that are not based on the NVMe protocol. This patch adds ZNS backend to support the ZBDs for NVMeOF target. This support includes implementing the new command set NVME_CSI_ZNS, adding different command handlers for ZNS command set such as NVMe Identify Controller, NVMe Identify Namespace, NVMe Zone Append, NVMe Zone Management Send and NVMe Zone Management Receive. With new command set identifier we also update the target command effects logs to reflect the ZNS compliant commands. Signed-off-by: Chaitanya Kulkarni --- drivers/nvme/target/Makefile | 1 + drivers/nvme/target/admin-cmd.c | 28 +++ drivers/nvme/target/core.c | 3 + drivers/nvme/target/io-cmd-bdev.c | 33 ++- drivers/nvme/target/nvmet.h | 38 ++++ drivers/nvme/target/zns.c | 342 ++++++++++++++++++++++++++++++ 6 files changed, 437 insertions(+), 8 deletions(-) create mode 100644 drivers/nvme/target/zns.c diff --git a/drivers/nvme/target/Makefile b/drivers/nvme/target/Makefile index ebf91fc4c72e..9837e580fa7e 100644 --- a/drivers/nvme/target/Makefile +++ b/drivers/nvme/target/Makefile @@ -12,6 +12,7 @@ obj-$(CONFIG_NVME_TARGET_TCP) += nvmet-tcp.o nvmet-y += core.o configfs.o admin-cmd.o fabrics-cmd.o \ discovery.o io-cmd-file.o io-cmd-bdev.o nvmet-$(CONFIG_NVME_TARGET_PASSTHRU) += passthru.o +nvmet-$(CONFIG_BLK_DEV_ZONED) += zns.o nvme-loop-y += loop.o nvmet-rdma-y += rdma.o nvmet-fc-y += fc.o diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c index a50b7bcac67a..bdf09d8faa48 100644 --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c @@ -191,6 +191,15 @@ static void nvmet_execute_get_log_cmd_effects_ns(struct nvmet_req *req) log->iocs[nvme_cmd_dsm] = cpu_to_le32(1 << 0); log->iocs[nvme_cmd_write_zeroes] = cpu_to_le32(1 << 0); break; + case NVME_CSI_ZNS: + if (IS_ENABLED(CONFIG_BLK_DEV_ZONED)) { + u32 *iocs = log->iocs; + + iocs[nvme_cmd_zone_append] = cpu_to_le32(1 << 0); + iocs[nvme_cmd_zone_mgmt_send] = cpu_to_le32(1 << 0); + iocs[nvme_cmd_zone_mgmt_recv] = cpu_to_le32(1 << 0); + } + break; default: status = NVME_SC_INVALID_LOG_PAGE; break; @@ -644,6 +653,17 @@ static void nvmet_execute_identify_desclist(struct nvmet_req *req) if (status) goto out; + if (IS_ENABLED(CONFIG_BLK_DEV_ZONED)) { + u16 nvme_cis_zns = NVME_CSI_ZNS; + + if (req->ns->csi == NVME_CSI_ZNS) + status = nvmet_copy_ns_identifier(req, NVME_NIDT_CSI, + NVME_NIDT_CSI_LEN, + &nvme_cis_zns, &off); + if (status) + goto out; + } + if (sg_zero_buffer(req->sg, req->sg_cnt, NVME_IDENTIFY_DATA_SIZE - off, off) != NVME_IDENTIFY_DATA_SIZE - off) status = NVME_SC_INTERNAL | NVME_SC_DNR; @@ -660,8 +680,16 @@ static void nvmet_execute_identify(struct nvmet_req *req) switch (req->cmd->identify.cns) { case NVME_ID_CNS_NS: return nvmet_execute_identify_ns(req); + case NVME_ID_CNS_CS_NS: + if (req->cmd->identify.csi == NVME_CSI_ZNS) + return nvmet_execute_identify_cns_cs_ns(req); + break; case NVME_ID_CNS_CTRL: return nvmet_execute_identify_ctrl(req); + case NVME_ID_CNS_CS_CTRL: + if (req->cmd->identify.csi == NVME_CSI_ZNS) + return nvmet_execute_identify_cns_cs_ctrl(req); + break; case NVME_ID_CNS_NS_ACTIVE_LIST: return nvmet_execute_identify_nslist(req); case NVME_ID_CNS_NS_DESC_LIST: diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index 672e4009f8d6..17d5da062a5a 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -1107,6 +1107,7 @@ static inline u8 nvmet_cc_iocqes(u32 cc) static inline bool nvmet_cc_css_check(u8 cc_css) { switch (cc_css <<= NVME_CC_CSS_SHIFT) { + case NVME_CC_CSS_CSI: case NVME_CC_CSS_NVM: return true; default: @@ -1173,6 +1174,8 @@ static void nvmet_init_cap(struct nvmet_ctrl *ctrl) { /* command sets supported: NVMe command set: */ ctrl->cap = (1ULL << 37); + if (IS_ENABLED(CONFIG_BLK_DEV_ZONED)) + ctrl->cap |= (1ULL << 43); /* CC.EN timeout in 500msec units: */ ctrl->cap |= (15ULL << 24); /* maximum queue entries supported: */ diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index 23095bdfce06..6178ef643962 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -63,6 +63,14 @@ static void nvmet_bdev_ns_enable_integrity(struct nvmet_ns *ns) } } +void nvmet_bdev_ns_disable(struct nvmet_ns *ns) +{ + if (ns->bdev) { + blkdev_put(ns->bdev, FMODE_WRITE | FMODE_READ); + ns->bdev = NULL; + } +} + int nvmet_bdev_ns_enable(struct nvmet_ns *ns) { int ret; @@ -86,15 +94,15 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns) if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY_T10)) nvmet_bdev_ns_enable_integrity(ns); - return 0; -} - -void nvmet_bdev_ns_disable(struct nvmet_ns *ns) -{ - if (ns->bdev) { - blkdev_put(ns->bdev, FMODE_WRITE | FMODE_READ); - ns->bdev = NULL; + if (IS_ENABLED(CONFIG_BLK_DEV_ZONED) && bdev_is_zoned(ns->bdev)) { + if (!nvmet_bdev_zns_enable(ns)) { + nvmet_bdev_ns_disable(ns); + return -EINVAL; + } + ns->csi = NVME_CSI_ZNS; } + + return 0; } void nvmet_bdev_ns_revalidate(struct nvmet_ns *ns) @@ -448,6 +456,15 @@ u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req) case nvme_cmd_write_zeroes: req->execute = nvmet_bdev_execute_write_zeroes; return 0; + case nvme_cmd_zone_append: + req->execute = nvmet_bdev_execute_zone_append; + return 0; + case nvme_cmd_zone_mgmt_recv: + req->execute = nvmet_bdev_execute_zone_mgmt_recv; + return 0; + case nvme_cmd_zone_mgmt_send: + req->execute = nvmet_bdev_execute_zone_mgmt_send; + return 0; default: pr_err("unhandled cmd %d on qid %d\n", cmd->common.opcode, req->sq->qid); diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 476b3cd91c65..7361665585a2 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -252,6 +252,10 @@ struct nvmet_subsys { unsigned int admin_timeout; unsigned int io_timeout; #endif /* CONFIG_NVME_TARGET_PASSTHRU */ + +#ifdef CONFIG_BLK_DEV_ZONED + u8 zasl; +#endif /* CONFIG_BLK_DEV_ZONED */ }; static inline struct nvmet_subsys *to_subsys(struct config_item *item) @@ -614,4 +618,38 @@ static inline sector_t nvmet_lba_to_sect(struct nvmet_ns *ns, __le64 lba) return le64_to_cpu(lba) << (ns->blksize_shift - SECTOR_SHIFT); } +#ifdef CONFIG_BLK_DEV_ZONED +bool nvmet_bdev_zns_enable(struct nvmet_ns *ns); +void nvmet_execute_identify_cns_cs_ctrl(struct nvmet_req *req); +void nvmet_execute_identify_cns_cs_ns(struct nvmet_req *req); +void nvmet_bdev_execute_zone_mgmt_recv(struct nvmet_req *req); +void nvmet_bdev_execute_zone_mgmt_send(struct nvmet_req *req); +void nvmet_bdev_execute_zone_append(struct nvmet_req *req); +#else /* CONFIG_BLK_DEV_ZONED */ +static inline bool nvmet_bdev_zns_enable(struct nvmet_ns *ns) +{ + return false; +} +static inline void +nvmet_execute_identify_cns_cs_ctrl(struct nvmet_req *req) +{ +} +static inline void +nvmet_execute_identify_cns_cs_ns(struct nvmet_req *req) +{ +} +static inline void +nvmet_bdev_execute_zone_mgmt_recv(struct nvmet_req *req) +{ +} +static inline void +nvmet_bdev_execute_zone_mgmt_send(struct nvmet_req *req) +{ +} +static inline void +nvmet_bdev_execute_zone_append(struct nvmet_req *req) +{ +} +#endif /* CONFIG_BLK_DEV_ZONED */ + #endif /* _NVMET_H */ diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c new file mode 100644 index 000000000000..2a71f56e568d --- /dev/null +++ b/drivers/nvme/target/zns.c @@ -0,0 +1,342 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * NVMe ZNS-ZBD command implementation. + * Copyright (c) 2020-2021 HGST, a Western Digital Company. + */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include +#include +#include "nvmet.h" + +/* + * We set the Memory Page Size Minimum (MPSMIN) for target controller to 0 + * which gets added by 12 in the nvme_enable_ctrl() which results in 2^12 = 4k + * as page_shift value. When calculating the ZASL use shift by 12. + */ +#define NVMET_MPSMIN_SHIFT 12 + +static u16 nvmet_bdev_zns_checks(struct nvmet_req *req) +{ + u16 status = NVME_SC_SUCCESS; + + if (!bdev_is_zoned(req->ns->bdev)) { + status = NVME_SC_INVALID_NS | NVME_SC_DNR; + goto out; + } + + if (req->cmd->zmr.zra != NVME_ZRA_ZONE_REPORT) { + status = NVME_SC_INVALID_FIELD; + goto out; + } + + if (req->cmd->zmr.zrasf != NVME_ZRASF_ZONE_REPORT_ALL) { + status = NVME_SC_INVALID_FIELD; + goto out; + } + + if (req->cmd->zmr.pr != NVME_REPORT_ZONE_PARTIAL) + status = NVME_SC_INVALID_FIELD; + +out: + return status; +} + +/* + * ZNS related command implementation and helpers. + */ + +static inline u8 nvmet_zasl(unsigned int zone_append_sects) +{ + /* + * Zone Append Size Limit is the value experessed in the units + * of minimum memory page size (i.e. 12) and is reported power of 2. + */ + return ilog2((zone_append_sects << 9) >> NVMET_MPSMIN_SHIFT); +} + +static inline bool nvmet_zns_update_zasl(struct nvmet_ns *ns) +{ + struct request_queue *q = ns->bdev->bd_disk->queue; + u8 zasl = nvmet_zasl(queue_max_zone_append_sectors(q)); + + if (ns->subsys->zasl) + return ns->subsys->zasl < zasl ? false : true; + + ns->subsys->zasl = zasl; + return true; +} + + +static int nvmet_bdev_validate_zns_zones_cb(struct blk_zone *z, + unsigned int idx, void *data) +{ + if (z->type == BLK_ZONE_TYPE_CONVENTIONAL) + return -EOPNOTSUPP; + return 0; +} + +static bool nvmet_bdev_has_conv_zones(struct block_device *bdev) +{ + int ret; + + if (bdev->bd_disk->queue->conv_zones_bitmap) + return true; + + ret = blkdev_report_zones(bdev, 0, blkdev_nr_zones(bdev->bd_disk), + nvmet_bdev_validate_zns_zones_cb, NULL); + + return ret < 0 ? true : false; +} + +bool nvmet_bdev_zns_enable(struct nvmet_ns *ns) +{ + if (nvmet_bdev_has_conv_zones(ns->bdev)) + return false; + + /* + * For ZBC and ZAC devices, writes into sequential zones must be aligned + * to the device physical block size. So use this value as the logical + * block size to avoid errors. + */ + ns->blksize_shift = blksize_bits(bdev_physical_block_size(ns->bdev)); + + if (!nvmet_zns_update_zasl(ns)) + return false; + + return !(get_capacity(ns->bdev->bd_disk) & + (bdev_zone_sectors(ns->bdev) - 1)); +} + +/* + * ZNS related Admin and I/O command handlers. + */ +void nvmet_execute_identify_cns_cs_ctrl(struct nvmet_req *req) +{ + u8 zasl = req->sq->ctrl->subsys->zasl; + struct nvmet_ctrl *ctrl = req->sq->ctrl; + struct nvme_id_ctrl_zns *id; + u16 status; + + id = kzalloc(sizeof(*id), GFP_KERNEL); + if (!id) { + status = NVME_SC_INTERNAL; + goto out; + } + + if (ctrl->ops->get_mdts) + id->zasl = min_t(u8, ctrl->ops->get_mdts(ctrl), zasl); + else + id->zasl = zasl; + + status = nvmet_copy_to_sgl(req, 0, id, sizeof(*id)); + + kfree(id); +out: + nvmet_req_complete(req, status); +} + +void nvmet_execute_identify_cns_cs_ns(struct nvmet_req *req) +{ + struct nvme_id_ns_zns *id_zns; + u16 status = NVME_SC_SUCCESS; + u64 zsze; + + if (le32_to_cpu(req->cmd->identify.nsid) == NVME_NSID_ALL) { + req->error_loc = offsetof(struct nvme_identify, nsid); + status = NVME_SC_INVALID_NS | NVME_SC_DNR; + goto out; + } + + id_zns = kzalloc(sizeof(*id_zns), GFP_KERNEL); + if (!id_zns) { + status = NVME_SC_INTERNAL; + goto out; + } + + req->ns = nvmet_find_namespace(req->sq->ctrl, req->cmd->identify.nsid); + if (!req->ns) { + status = NVME_SC_INTERNAL; + goto done; + } + + if (!bdev_is_zoned(req->ns->bdev)) { + req->error_loc = offsetof(struct nvme_identify, nsid); + status = NVME_SC_INVALID_NS | NVME_SC_DNR; + goto done; + } + + nvmet_ns_revalidate(req->ns); + zsze = (bdev_zone_sectors(req->ns->bdev) << 9) >> + req->ns->blksize_shift; + id_zns->lbafe[0].zsze = cpu_to_le64(zsze); + id_zns->mor = cpu_to_le32(bdev_max_open_zones(req->ns->bdev)); + id_zns->mar = cpu_to_le32(bdev_max_active_zones(req->ns->bdev)); + +done: + status = nvmet_copy_to_sgl(req, 0, id_zns, sizeof(*id_zns)); + kfree(id_zns); +out: + nvmet_req_complete(req, status); +} + +struct nvmet_report_zone_data { + struct nvmet_ns *ns; + struct nvme_zone_report *rz; +}; + +static int nvmet_bdev_report_zone_cb(struct blk_zone *z, unsigned int idx, + void *data) +{ + struct nvmet_report_zone_data *report_zone_data = data; + struct nvme_zone_descriptor *entries = report_zone_data->rz->entries; + struct nvmet_ns *ns = report_zone_data->ns; + + entries[idx].zcap = nvmet_sect_to_lba(ns, z->capacity); + entries[idx].zslba = nvmet_sect_to_lba(ns, z->start); + entries[idx].wp = nvmet_sect_to_lba(ns, z->wp); + entries[idx].za = z->reset ? 1 << 2 : 0; + entries[idx].zt = z->type; + entries[idx].zs = z->cond << 4; + + return 0; +} + +void nvmet_bdev_execute_zone_mgmt_recv(struct nvmet_req *req) +{ + sector_t sect = nvmet_lba_to_sect(req->ns, req->cmd->zmr.slba); + u32 bufsize = (le32_to_cpu(req->cmd->zmr.numd) + 1) << 2; + struct nvmet_report_zone_data data = { .ns = req->ns }; + unsigned int nr_zones; + int reported_zones; + u16 status; + + nr_zones = (bufsize - sizeof(struct nvme_zone_report)) / + sizeof(struct nvme_zone_descriptor); + + status = nvmet_bdev_zns_checks(req); + if (status) + goto out; + + data.rz = __vmalloc(bufsize, GFP_KERNEL | __GFP_NORETRY | __GFP_ZERO); + if (!data.rz) { + status = NVME_SC_INTERNAL; + goto out; + } + + reported_zones = blkdev_report_zones(req->ns->bdev, sect, nr_zones, + nvmet_bdev_report_zone_cb, + &data); + if (reported_zones < 0) { + status = NVME_SC_INTERNAL; + goto out_free_report_zones; + } + + data.rz->nr_zones = cpu_to_le64(reported_zones); + + status = nvmet_copy_to_sgl(req, 0, data.rz, bufsize); + +out_free_report_zones: + kvfree(data.rz); +out: + nvmet_req_complete(req, status); +} + +void nvmet_bdev_execute_zone_mgmt_send(struct nvmet_req *req) +{ + sector_t sect = nvmet_lba_to_sect(req->ns, req->cmd->zms.slba); + sector_t nr_sect = bdev_zone_sectors(req->ns->bdev); + u16 status = NVME_SC_SUCCESS; + enum req_opf op; + int ret; + + if (req->cmd->zms.select_all) + nr_sect = get_capacity(req->ns->bdev->bd_disk); + + switch (req->cmd->zms.zsa) { + case NVME_ZONE_OPEN: + op = REQ_OP_ZONE_OPEN; + break; + case NVME_ZONE_CLOSE: + op = REQ_OP_ZONE_CLOSE; + break; + case NVME_ZONE_FINISH: + op = REQ_OP_ZONE_FINISH; + break; + case NVME_ZONE_RESET: + op = REQ_OP_ZONE_RESET; + break; + default: + status = NVME_SC_INVALID_FIELD; + goto out; + } + + ret = blkdev_zone_mgmt(req->ns->bdev, op, sect, nr_sect, GFP_KERNEL); + if (ret) + status = NVME_SC_INTERNAL; +out: + nvmet_req_complete(req, status); +} + +void nvmet_bdev_execute_zone_append(struct nvmet_req *req) +{ + sector_t sect = nvmet_lba_to_sect(req->ns, req->cmd->rw.slba); + struct request_queue *q = req->ns->bdev->bd_disk->queue; + unsigned int max_sects = queue_max_zone_append_sectors(q); + u16 status = NVME_SC_SUCCESS; + unsigned int total_len = 0; + struct scatterlist *sg; + int ret = 0, sg_cnt; + struct bio *bio; + + if (!nvmet_check_transfer_len(req, nvmet_rw_data_len(req))) + return; + + if (!req->sg_cnt) { + nvmet_req_complete(req, 0); + return; + } + + if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) { + bio = &req->b.inline_bio; + bio_init(bio, req->inline_bvec, ARRAY_SIZE(req->inline_bvec)); + } else { + bio = bio_alloc(GFP_KERNEL, req->sg_cnt); + } + + bio_set_dev(bio, req->ns->bdev); + bio->bi_iter.bi_sector = sect; + bio->bi_opf = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE; + if (req->cmd->rw.control & cpu_to_le16(NVME_RW_FUA)) + bio->bi_opf |= REQ_FUA; + + for_each_sg(req->sg, sg, req->sg_cnt, sg_cnt) { + struct page *p = sg_page(sg); + unsigned int l = sg->length; + unsigned int o = sg->offset; + bool same_page = false; + + ret = bio_add_hw_page(q, bio, p, l, o, max_sects, &same_page); + if (ret != sg->length) { + status = NVME_SC_INTERNAL; + goto out_bio_put; + } + if (same_page) + put_page(p); + + total_len += sg->length; + } + + if (total_len != nvmet_rw_data_len(req)) { + status = NVME_SC_INTERNAL | NVME_SC_DNR; + goto out_bio_put; + } + + ret = submit_bio_wait(bio); + req->cqe->result.u64 = nvmet_sect_to_lba(req->ns, + bio->bi_iter.bi_sector); + +out_bio_put: + if (bio != &req->b.inline_bio) + bio_put(bio); + nvmet_req_complete(req, ret < 0 ? NVME_SC_INTERNAL : status); +} From patchwork Tue Jan 12 04:26:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 12012349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6726AC433E6 for ; Tue, 12 Jan 2021 04:28:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3CC7022D06 for ; Tue, 12 Jan 2021 04:28:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730260AbhALE20 (ORCPT ); Mon, 11 Jan 2021 23:28:26 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:18350 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730254AbhALE2Z (ORCPT ); Mon, 11 Jan 2021 23:28:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610425704; x=1641961704; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1y14BfiDYeW2GPW7aJ8piMTbIb+XExWNPhFvc+apnpU=; b=EsemmD+EL/cb3O4sYJ/eB7LGSir2IoiUZDN/IJbIcPFp8nwZHNXdAex+ O/JAcrVv+0DIKGPoX5r9v0Sr1yDK5EEnYZ/5KoEZ2BSxNFOlPwZwSj0f3 ZExb0y9pMYM/5SUJoBXOs5nza8Nn6wSs51IGpo4xNq8HiiajKv3vDqveu 0aEVIGTPkTMVvU5eITE0I8jm1ycklBq+MywM4HyleAXmkWeEiuhfJECsa IVjgsBGRwOxhvelbfHzOrk+/6KgCAZwv1N6xc3/MPbBpt3IzBYZVYJBzU N0Hp08kBWAGPK1H0rsEIuBDc89bypnU/K/2OQBSD4dQ29xtYc+gFUJPRM A==; IronPort-SDR: ro0uy/f9cOAfv5y/wUFXDk1fTeD79HRDdQYSUgq3YRbZtXh5tmuIKxZle/JYdwOabrGwqdDkUl Sue1JT0fXxqV30JuC2hdqdfzON1mM5ApnMH222OeoL6jxfHDRBpaW6lSl+NHY3IIyCYLRh59Bc jdsBuRxLPXbDwts0S8oDWI/ie5VwMDlyEtbnPFtIsnrQ+GQGPunWoLn92oiQ+dOODKGQF8CmOj luXkNg13kppHvSGaOirji31OGojioXIzgBt6TwpNPDWo3hmv03lTgFvdUQUvWUfShvo25Ihqq+ 39E= X-IronPort-AV: E=Sophos;i="5.79,340,1602518400"; d="scan'208";a="161648574" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jan 2021 12:27:19 +0800 IronPort-SDR: DU35T9zezmQ6fqL6cD3zNE5w2fV8vuZ63JsmKIQzFwcag5BY2DoC0zxDnsRLCO1CAbVL46Dr8Z +jtDudTr3ZQPC+pUUN3gV0JuV3799VUvMou+9TVC61EFQKPTce97pyl3pdaOtH8Bblxhcvdahe YLRyBdZhyk34I3zMTGqO6D7dCvP6iME782n2OHGad9QibvNdSfOba5B2+njrwOHyNVU6w+i/zL u8nPHTa07JoKv+1RuSkxV2wNhTjqwS7RwM/cjvuAfKl2faCpH3jFY/XZjJb1gm+d5nWhD9VMIk CKByPJkmhAd7gd/zeKVDyjz3 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2021 20:12:04 -0800 IronPort-SDR: /flRgfgEnclXEjUnsPCzykTMB6SVPr/WHeUP13AUvcf13rGSctTSMm8CVb3LrJHcjTiCxZMChp aLs0bHvbCsCPSITm4RaSKZIB+XEOsehGNeRTrMr94C3wG8ou9stLPSJjBfUKuCcJTG5AbqvNgr Ek0ynMeqcljeX8fgt8QhviT1d+tY/M9xdPvDZnLjHBKc96Qbg0kv+3IJPntmiFHIZ7iI9PZt9y gicBp66ZLpO9hIfq3htvt9H1yS3JynCsnLQmY9pHILIBU+AgEl1k3RwrNE7SLyqLCQv+/1bJMG 7jE= WDCIronportException: Internal Received: from vm.labspan.wdc.com (HELO vm.sc.wdc.com) ([10.6.137.102]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Jan 2021 20:27:19 -0800 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Cc: hch@lst.de, sagi@grimberg.me, damien.lemoal@wdc.com, Chaitanya Kulkarni Subject: [PATCH V9 5/9] nvmet: add bio get helper for different backends Date: Mon, 11 Jan 2021 20:26:19 -0800 Message-Id: <20210112042623.6316-6-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> References: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org With the addition of the zns backend now we have three different backends with inline bio optimization. That leads to having duplicate code for allocating or initializing the bio in all three backends: generic bdev, passsthru, and generic zns. Add a helper function to reduce the duplicate code such that helper function accepts the bi_end_io callback which gets initialize for the non-inline bio_alloc() case. This is due to the special case needed for the passthru backend non-inline bio allocation bio_alloc() where we set the bio->bi_end_io = bio_put, having this parameter avoids the extra branch in the passthru fast path. For rest of the backends, we set the same bi_end_io callback for inline and non-inline cases, that is for generic bdev we set to nvmet_bio_done() and for generic zns we set to NULL.                             Signed-off-by: Chaitanya Kulkarni --- drivers/nvme/target/io-cmd-bdev.c | 7 +------ drivers/nvme/target/nvmet.h | 16 ++++++++++++++++ drivers/nvme/target/passthru.c | 8 +------- drivers/nvme/target/zns.c | 8 +------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index 6178ef643962..72746e29cb0d 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -266,12 +266,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req) sector = nvmet_lba_to_sect(req->ns, req->cmd->rw.slba); - if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) { - bio = &req->b.inline_bio; - bio_init(bio, req->inline_bvec, ARRAY_SIZE(req->inline_bvec)); - } else { - bio = bio_alloc(GFP_KERNEL, min(sg_cnt, BIO_MAX_PAGES)); - } + bio = nvmet_req_bio_get(req, NULL); bio_set_dev(bio, req->ns->bdev); bio->bi_iter.bi_sector = sector; bio->bi_private = req; diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 7361665585a2..3fc84f79cce1 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -652,4 +652,20 @@ nvmet_bdev_execute_zone_append(struct nvmet_req *req) } #endif /* CONFIG_BLK_DEV_ZONED */ +static inline struct bio *nvmet_req_bio_get(struct nvmet_req *req, + bio_end_io_t *bi_end_io) +{ + struct bio *bio; + + if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) { + bio = &req->b.inline_bio; + bio_init(bio, req->inline_bvec, ARRAY_SIZE(req->inline_bvec)); + return bio; + } + + bio = bio_alloc(GFP_KERNEL, req->sg_cnt); + bio->bi_end_io = bi_end_io; + return bio; +} + #endif /* _NVMET_H */ diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c index b9776fc8f08f..54f765b566ee 100644 --- a/drivers/nvme/target/passthru.c +++ b/drivers/nvme/target/passthru.c @@ -194,13 +194,7 @@ static int nvmet_passthru_map_sg(struct nvmet_req *req, struct request *rq) if (req->sg_cnt > BIO_MAX_PAGES) return -EINVAL; - if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) { - bio = &req->p.inline_bio; - bio_init(bio, req->inline_bvec, ARRAY_SIZE(req->inline_bvec)); - } else { - bio = bio_alloc(GFP_KERNEL, min(req->sg_cnt, BIO_MAX_PAGES)); - bio->bi_end_io = bio_put; - } + bio = nvmet_req_bio_get(req, bio_put); bio->bi_opf = req_op(rq); for_each_sg(req->sg, sg, req->sg_cnt, i) { diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c index 2a71f56e568d..c32e93a3c7e1 100644 --- a/drivers/nvme/target/zns.c +++ b/drivers/nvme/target/zns.c @@ -296,13 +296,7 @@ void nvmet_bdev_execute_zone_append(struct nvmet_req *req) return; } - if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) { - bio = &req->b.inline_bio; - bio_init(bio, req->inline_bvec, ARRAY_SIZE(req->inline_bvec)); - } else { - bio = bio_alloc(GFP_KERNEL, req->sg_cnt); - } - + bio = nvmet_req_bio_get(req, NULL); bio_set_dev(bio, req->ns->bdev); bio->bi_iter.bi_sector = sect; bio->bi_opf = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE; From patchwork Tue Jan 12 04:26:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 12012351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF771C433DB for ; Tue, 12 Jan 2021 04:28:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BBE7122D05 for ; Tue, 12 Jan 2021 04:28:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730413AbhALE2f (ORCPT ); Mon, 11 Jan 2021 23:28:35 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:60620 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730406AbhALE2f (ORCPT ); Mon, 11 Jan 2021 23:28:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610425715; x=1641961715; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b7JlLdLhTEJHSJkJ2Ot7J3cXNRNUJqtnFvAN4lx8PoE=; b=dE3uWV6TSdd+FCFGvPPTuNkW3Z/IfxTgnXuFxXAflsKzAvpLr5WV3J1g /GNEBCvf5vIh17dQoV1Iqbrev51nrKaeKJf/IJa/nVMTpeCp/1Cp/Q/iV nN1eFZ4NLgxECigg3GmXT1GnsO2B9KeUlp6uJmcJdoBUc3iYGzrEau9SK pm6EIQf893zeqFWWes5wV8Q+1ELZQvCLFE/Qz0osxwiB0TSTwovvycNap OHx21MOnGh+JyON5InRtCUbCo0ecfzG2BoNJQmxf0rktoN64BeQpR5K/3 VeBXoQsEDK9z/8yJVyVPsQCqCbAq7JlXVOe99GEXgfSdDg79wLCxLz/qn Q==; IronPort-SDR: VOIw82T3DeXshPYcAmQGoE7TOSLrJKmxJWPEeEnmIV8gCN3h2MbwALdAABsv5QrWsQ8GT7nf9A lLVL37k1nSYy9VITc7hssC7DTp/2sZy4AwruTA4yeTmxMQtaMV9UaUJ4CNFluoxMigQa4PyoYu s61dRh5z9uQdlD/XEyhKnc+1ejuX3rWrjMXFIiS+1kiKr+0WmrqfyqQx5syt2HQafvMdXUj/rK S3cd+9p0fqK6kvQI/W2pTJv8VLowOCI+LG28QuQZwNV0xzTp336iORIhRHlIO0lOiT91+IMLN/ 05g= X-IronPort-AV: E=Sophos;i="5.79,340,1602518400"; d="scan'208";a="158381152" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Jan 2021 12:27:29 +0800 IronPort-SDR: Ns/zCeppbo4+D88zZtNZL9vGwZjbBmgSyMhJPdWRXrKvxQkw2J1PYGZoobGuAuLl5weY0hNvVr aR/JJAUpU6bTihXun+bvWkMYJuUqfDxLrysv4xfsk/iMdmExsegm70Vc9UFP9KlLq3Ti/QLA+/ KnaXGeei7yhyX0dnh7YV8jhvF7L4ln6QcIUEINx64dwB2OHrCR373jyYalzjY0nLmvRRKMEhSc zxLbfRozZqMHDVCx5Il7HrSWZD1u3POi+e+4pXuKLSXqSlfWkOhOeAN2D8HAstxSxOdk6xqMjD iLhj7PwTWiPphKLUbJgNXYXZ Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2021 20:10:22 -0800 IronPort-SDR: o/sg1RlO55nBZvuaf2UOWUKg+CwrJQNyX5ExWX1SiQ1CQgy3BqgOm1LU6PVb42JWsHrs1QDrz3 J4uJFV4zVQf6HISX5Eyak8w1215IcPdF0qV6tiyMi7rmneB27b5IacvY31BmKRQmfMifwJdI6O ilxFN4yx2Lcch6etVa3iripRW7bx1OkyKCMAqN0sVauyJcMtAb19GNvzUQFF7IAq+s35HG8MzY OyGtGIawg02tKIBBBAuIliFJgPfrBuIYFc4kVsoQYs7Xf1YHt4zwOXnUpOZml5byXfy6e9HCE5 GNM= WDCIronportException: Internal Received: from vm.labspan.wdc.com (HELO vm.sc.wdc.com) ([10.6.137.102]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Jan 2021 20:27:29 -0800 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Cc: hch@lst.de, sagi@grimberg.me, damien.lemoal@wdc.com, Chaitanya Kulkarni Subject: [PATCH V9 6/9] nvmet: add bio init helper for different backends Date: Mon, 11 Jan 2021 20:26:20 -0800 Message-Id: <20210112042623.6316-7-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> References: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org With the addition of the zns backend now we have two different backends with the same bio initialization code. That leads to having duplicate code in two backends: generic bdev and generic zns. Add a helper function to reduce the duplicate code such that helper function initializes the various bio initialization parameters such as bio block device, op flags, sector, end io callback, and private member, Signed-off-by: Chaitanya Kulkarni Reviewed-by: Damien Le Moal --- drivers/nvme/target/io-cmd-bdev.c | 6 +----- drivers/nvme/target/nvmet.h | 11 +++++++++++ drivers/nvme/target/zns.c | 6 +++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index 72746e29cb0d..b1fb0bb1f39f 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -267,11 +267,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req) sector = nvmet_lba_to_sect(req->ns, req->cmd->rw.slba); bio = nvmet_req_bio_get(req, NULL); - bio_set_dev(bio, req->ns->bdev); - bio->bi_iter.bi_sector = sector; - bio->bi_private = req; - bio->bi_end_io = nvmet_bio_done; - bio->bi_opf = op; + nvmet_bio_init(bio, req->ns->bdev, op, sector, req, nvmet_bio_done); blk_start_plug(&plug); if (req->metadata_len) diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 3fc84f79cce1..1ec9e1b35c67 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -668,4 +668,15 @@ static inline struct bio *nvmet_req_bio_get(struct nvmet_req *req, return bio; } +static inline void nvmet_bio_init(struct bio *bio, struct block_device *bdev, + unsigned int op, sector_t sect, void *private, + bio_end_io_t *bi_end_io) +{ + bio_set_dev(bio, bdev); + bio->bi_opf = op; + bio->bi_iter.bi_sector = sect; + bio->bi_private = private; + bio->bi_end_io = bi_end_io; +} + #endif /* _NVMET_H */ diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c index c32e93a3c7e1..92213bed0006 100644 --- a/drivers/nvme/target/zns.c +++ b/drivers/nvme/target/zns.c @@ -281,6 +281,7 @@ void nvmet_bdev_execute_zone_append(struct nvmet_req *req) { sector_t sect = nvmet_lba_to_sect(req->ns, req->cmd->rw.slba); struct request_queue *q = req->ns->bdev->bd_disk->queue; + unsigned int op = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE; unsigned int max_sects = queue_max_zone_append_sectors(q); u16 status = NVME_SC_SUCCESS; unsigned int total_len = 0; @@ -297,9 +298,8 @@ void nvmet_bdev_execute_zone_append(struct nvmet_req *req) } bio = nvmet_req_bio_get(req, NULL); - bio_set_dev(bio, req->ns->bdev); - bio->bi_iter.bi_sector = sect; - bio->bi_opf = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE; + nvmet_bio_init(bio, req->ns->bdev, op, sect, NULL, NULL); + if (req->cmd->rw.control & cpu_to_le16(NVME_RW_FUA)) bio->bi_opf |= REQ_FUA; From patchwork Tue Jan 12 04:26:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 12012357 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBC8DC433DB for ; Tue, 12 Jan 2021 04:29:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A6A2822D06 for ; Tue, 12 Jan 2021 04:29:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730715AbhALE3Q (ORCPT ); Mon, 11 Jan 2021 23:29:16 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:60620 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730695AbhALE3Q (ORCPT ); Mon, 11 Jan 2021 23:29:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610425755; x=1641961755; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R91N4OJCuometnQDJ1w4j46SwlbKLZn5XO72xfDzsGA=; b=RefBlu6yjzIJtQNzpKSpiP+s6vDZseSfEyiVY50OdhSFmHd1YQVvbpnR hegJYJhEdoMWpw3fvGxi07dbwqh+gVoMvnrrCzPEghyXszw6bEkLiwwCU 4ccFCH7i6oH9dpDk8MeaKAKUE2OTCbZDdCrAVF361f2gVMivCdfhER/dr iJvX3P36GNqprygacHcdrLHZVyu1H1gx55tqFb34H1fKFGyTqTQA1s1Jr vRXhNBsNExi+l3vOmM8847zr31NJZAIzIvvfYRSkEWsw+p9pKGdLn3uEi X6nV7Ms1q92n1/RhLK89KJkpe0J3ui7dDitNooS13oZb7upITPy+uoBux g==; IronPort-SDR: o6nLi8viqlLvWOWA5y9+W3dGK+ug3OpNTqPjEzWa/PIbpxL0NQiSsuE2Ah0oPa8kIFRLV80G+I bf8s0wsAm3lpx4Re6HHVwiN4ojQOXguLRby+4JGMTb8+p+a2NTpLJlFG0ccIlKD48dNKaEhRcb lDrLECC4Dao/H5LakRPC4DA5VKXcn2BZEimd+GeTLv8sHUowjUveZMyycMIE/MSv4s4zzVd6o7 LxN0pJmNruhm8QZJQrCDrkBZOwZEt/HDsJsh+tnbsvX4jYVaDSdYvPQFsLPLeJUBC7rAdLY6nh HLU= X-IronPort-AV: E=Sophos;i="5.79,340,1602518400"; d="scan'208";a="158381165" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Jan 2021 12:27:40 +0800 IronPort-SDR: V+t/B5TQGMJgALLGoW7b44cmQmnFDbWh6vnicHXyWus0aml3m+xpd1sh4dWoE2Dl8McVQyQofX JQRbv2JNK/lAfCvLX11HGVLExj544H/zgeS0lnAfPAZnwG/hxyleLJSI9KWuTm5GgOsTgGRSJz OOWecvoBh06gBQEND73CB08eT+ki9nPNEUbbIwIHzzKBvtZ/BhrMq6uFZknqAlncSVMlQUB1vw +T/BuKCXM7F4lOGwEBgt0ZUWlyn9V+DhYU6MhGkQIwWFIqMrQqxYJtYezrYlHihmqkrpbizIQh e9BkssxBk15KA/IeF1zq2CbE Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2021 20:12:25 -0800 IronPort-SDR: cxxBy+WvCfwIT1aN0fSwJRc2u0a0ZFgDTUxwy0EBRvjkwF5bLgRJxyGovX/xmoU5rD13K1GVW3 bdxsbX9+S3UcDkMCpCGjBKXhrIFLsNudnpIbh02UZKb+rDNvC7X94PBTsTVMXU4IcTzEW2MnfD tMQTA/NR6PSxweczXJaZ4CuWvi3jCPUyPVqrWCAKzkWUwzWWBE2H7mhRd+UczzKAfmny0o7SUc DZGVO0+0N9KD5Y8dTLMYYtCGL12zKvk7hNnQFP2nqENoLuup5VbnhyugiO/z/cJ8vcXYCdyjMq NPc= WDCIronportException: Internal Received: from vm.labspan.wdc.com (HELO vm.sc.wdc.com) ([10.6.137.102]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Jan 2021 20:27:40 -0800 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Cc: hch@lst.de, sagi@grimberg.me, damien.lemoal@wdc.com, Chaitanya Kulkarni Subject: [PATCH V9 7/9] nvmet: add bio put helper for different backends Date: Mon, 11 Jan 2021 20:26:21 -0800 Message-Id: <20210112042623.6316-8-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> References: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org With the addition of zns backend now we have three different backends with inline bio optimization. That leads to having duplicate code in for freeing the bio in all three backends: generic bdev, passsthru and generic zns. Add a helper function to avoid the duplicate code and update the respective backends. Signed-off-by: Chaitanya Kulkarni --- drivers/nvme/target/io-cmd-bdev.c | 3 +-- drivers/nvme/target/nvmet.h | 6 ++++++ drivers/nvme/target/passthru.c | 3 +-- drivers/nvme/target/zns.c | 3 +-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index b1fb0bb1f39f..562c2dd9c08c 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -172,8 +172,7 @@ static void nvmet_bio_done(struct bio *bio) struct nvmet_req *req = bio->bi_private; nvmet_req_complete(req, blk_to_nvme_status(req, bio->bi_status)); - if (bio != &req->b.inline_bio) - bio_put(bio); + nvmet_req_bio_put(req, bio); } #ifdef CONFIG_BLK_DEV_INTEGRITY diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 1ec9e1b35c67..93ebc9ae3fe4 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -679,4 +679,10 @@ static inline void nvmet_bio_init(struct bio *bio, struct block_device *bdev, bio->bi_end_io = bi_end_io; } +static inline void nvmet_req_bio_put(struct nvmet_req *req, struct bio *bio) +{ + if (bio != &req->b.inline_bio) + bio_put(bio); +} + #endif /* _NVMET_H */ diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c index 54f765b566ee..a4a73d64c603 100644 --- a/drivers/nvme/target/passthru.c +++ b/drivers/nvme/target/passthru.c @@ -200,8 +200,7 @@ static int nvmet_passthru_map_sg(struct nvmet_req *req, struct request *rq) for_each_sg(req->sg, sg, req->sg_cnt, i) { if (bio_add_pc_page(rq->q, bio, sg_page(sg), sg->length, sg->offset) < sg->length) { - if (bio != &req->p.inline_bio) - bio_put(bio); + nvmet_req_bio_put(req, bio); return -EINVAL; } } diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c index 92213bed0006..bba1d6957b6a 100644 --- a/drivers/nvme/target/zns.c +++ b/drivers/nvme/target/zns.c @@ -330,7 +330,6 @@ void nvmet_bdev_execute_zone_append(struct nvmet_req *req) bio->bi_iter.bi_sector); out_bio_put: - if (bio != &req->b.inline_bio) - bio_put(bio); + nvmet_req_bio_put(req, bio); nvmet_req_complete(req, ret < 0 ? NVME_SC_INTERNAL : status); } From patchwork Tue Jan 12 04:26:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 12012353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12E6DC433E0 for ; Tue, 12 Jan 2021 04:28:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DED3E22D06 for ; Tue, 12 Jan 2021 04:28:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730427AbhALE2g (ORCPT ); Mon, 11 Jan 2021 23:28:36 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:42623 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730406AbhALE2g (ORCPT ); Mon, 11 Jan 2021 23:28:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610425715; x=1641961715; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mkVK7yH9lL1rJQMlF1XEDeT3WD/vS4iMg1KelSLXgKo=; b=R0EGhMKhW3P6cvw1JGyEOZEcec//OypYzSVTMcCccjdDU0ZXeDGrhM9F IbwYF7FhGYp5QAsZyd0fT7x7NsRniOZYx+ZhpDmS9anHw1GMVWVorgvwq +2dZJAVFjll7ktTPEhNQ+au6KN/hf+tsjqb32xEfpM+ZYzLTb6jAyl7ed nt57dSoK1z07Gy2X0rI3EGn9xKMQVJI5fNGqeVizyAGXCekMEpLYFDoM8 GuJeZgpWtb49bY1ApLvUZ+7H+7h20C7vRUPhTFeObaMeb20DIT7g/90TM 8raIZm1g+J5UBwibF+bBPjYj76JDrQJIWuFbMUXmYiIDci3vYVdWFky1N A==; IronPort-SDR: 5b9MU5Q5q4rrz/a5qBsumGFuOsJnPkbMhtUq9d69WzXsEKW0DJLqCwRO/aMHWZerMnpNYcqIFe YCNlXyy62DLe1XIkSaqb4ghjZnccbuovWHEwLph9G31UoBz79/w1THCgiq5ISzXueoNBK2cIHz DTzVu2nCNfHJK5wAGJ5ouCeHvctpBtCEaMzPFwcbnzZsEdWlwcjdvfkgDnGvxel0s8l5dO2b+d W5ffLJ4g0KSwuVGuqxe7b4Pj/Ei7Wcb5uwAalunqw6aqAdWNMna+WB9Diy6j8btM3sB46a4rch dSQ= X-IronPort-AV: E=Sophos;i="5.79,340,1602518400"; d="scan'208";a="267504904" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Jan 2021 12:27:50 +0800 IronPort-SDR: ijmTf2tYNr+QorbWdBKDMdGmCEuUTIC1pRqsjZfCo4Vkt5x5cY6wXuKzMurQBTLEEcCKlNK+BB bX6PGo5KdIzaZ/jVnFosdsa8jD6S6D13B5pitIksrU+oopvfzJvrmihTCFfqoeuk0dAPGxoNwD May6qqtyWCdHJ3Co/EA7y34tVr4y0a5uQGpQLsP5cUNKjaqKqby/Xr+OTOrvIrp61CRbr/XfE7 brNmYA7rUiz/XwCs8FF071veIuMrdPiJeSNm0aTnkuVu4J4t01UgJd41BskhT8ZFOQEKCV2DUy y1EBTGU0Q6h5Kiar8Im9fpqu Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2021 20:10:44 -0800 IronPort-SDR: 7tCkuG4QOhKS272Hg88kxZohCM1ZnvsSJQI7gWspgz0AH+5wZl3u7NrxobRGnuMs04fmuGPvvU Segbqb1mC8uBV6gsLous42UXP4pdxVrse2TnqzuC203ErZ+gJrsLKPbs5JGkXultFjFrYfkOhn vejhVy8M6c0F7LiEa1V9VHr3YF9qPGsCo4XDuXD4Lderd3Xi7BUaSBvEGo2c3c4UKesnThw57q uGhDxWSWqNetmDy6ZBG8hH4tS83izbk1HT00rhjFrIddDWIYFoAzxLz9XE65s8HuB4NKXfLFR1 EEs= WDCIronportException: Internal Received: from vm.labspan.wdc.com (HELO vm.sc.wdc.com) ([10.6.137.102]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Jan 2021 20:27:50 -0800 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Cc: hch@lst.de, sagi@grimberg.me, damien.lemoal@wdc.com, Chaitanya Kulkarni Subject: [PATCH V9 8/9] nvmet: add common I/O length check helper Date: Mon, 11 Jan 2021 20:26:22 -0800 Message-Id: <20210112042623.6316-9-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> References: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org With the addition of zns backend now we have three different backends with which checks for the nvmet request's transfer len and nvmet request's sg_cnt. That leads to having duplicate code in for three backends: generic bdev, file and generic zns. Add a helper function to avoid the duplicate code and update the respective backends. Signed-off-by: Chaitanya Kulkarni --- drivers/nvme/target/io-cmd-bdev.c | 8 +------- drivers/nvme/target/io-cmd-file.c | 7 +------ drivers/nvme/target/nvmet.h | 14 ++++++++++++++ drivers/nvme/target/zns.c | 7 +------ 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index 562c2dd9c08c..c23a719513b0 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -240,16 +240,10 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req) int op, i, rc; struct sg_mapping_iter prot_miter; unsigned int iter_flags; - unsigned int total_len = nvmet_rw_data_len(req) + req->metadata_len; - if (!nvmet_check_transfer_len(req, total_len)) + if (!nvmet_continue_io(req, nvmet_rw_data_len(req) + req->metadata_len)) return; - if (!req->sg_cnt) { - nvmet_req_complete(req, 0); - return; - } - if (req->cmd->rw.opcode == nvme_cmd_write) { op = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE; if (req->cmd->rw.control & cpu_to_le16(NVME_RW_FUA)) diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c index 0abbefd9925e..e7caff221b7b 100644 --- a/drivers/nvme/target/io-cmd-file.c +++ b/drivers/nvme/target/io-cmd-file.c @@ -241,14 +241,9 @@ static void nvmet_file_execute_rw(struct nvmet_req *req) { ssize_t nr_bvec = req->sg_cnt; - if (!nvmet_check_transfer_len(req, nvmet_rw_data_len(req))) + if (!nvmet_continue_io(req, nvmet_rw_data_len(req))) return; - if (!req->sg_cnt || !nr_bvec) { - nvmet_req_complete(req, 0); - return; - } - if (nr_bvec > NVMET_MAX_INLINE_BIOVEC) req->f.bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), GFP_KERNEL); diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 93ebc9ae3fe4..f4f9d622df0d 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -685,4 +685,18 @@ static inline void nvmet_req_bio_put(struct nvmet_req *req, struct bio *bio) bio_put(bio); } +static inline bool nvmet_continue_io(struct nvmet_req *req, + unsigned int total_len) +{ + if (!nvmet_check_transfer_len(req, total_len)) + return false; + + if (!req->sg_cnt) { + nvmet_req_complete(req, 0); + return false; + } + + return true; +} + #endif /* _NVMET_H */ diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c index bba1d6957b6a..149bc8ce7010 100644 --- a/drivers/nvme/target/zns.c +++ b/drivers/nvme/target/zns.c @@ -289,14 +289,9 @@ void nvmet_bdev_execute_zone_append(struct nvmet_req *req) int ret = 0, sg_cnt; struct bio *bio; - if (!nvmet_check_transfer_len(req, nvmet_rw_data_len(req))) + if (!nvmet_continue_io(req, nvmet_rw_data_len(req))) return; - if (!req->sg_cnt) { - nvmet_req_complete(req, 0); - return; - } - bio = nvmet_req_bio_get(req, NULL); nvmet_bio_init(bio, req->ns->bdev, op, sect, NULL, NULL); From patchwork Tue Jan 12 04:26:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chaitanya Kulkarni X-Patchwork-Id: 12012355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24549C433E0 for ; Tue, 12 Jan 2021 04:28:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E90B222D05 for ; Tue, 12 Jan 2021 04:28:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730468AbhALE2q (ORCPT ); Mon, 11 Jan 2021 23:28:46 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:45032 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730406AbhALE2q (ORCPT ); Mon, 11 Jan 2021 23:28:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1610425725; x=1641961725; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qwXyOBMpSjhNvMX3TuA4Swa6BZth8f79ppVgwTS1V1A=; b=adnrgVlULXIP860VcPmFeP4UWSRPFUswuFer37DzQYecX/AgADgPH9Zc XVXBC/4O083Ol754SHuJS9Klt4h448K5BruNuEEHJvRBdiH112z17Gy5c rD93scLscogWcmy7hmsfPBOihEUUAPygTRngAIcdJboXAZFJM7e1wv61M 6lc14OUECqrbbvr4H4aw4k5w/ze/N9YlKoUHRT7TTiAyS9FS1MfOyfGCi wo1RfhfUi6tSU4WuG2oVPw37r8yDlfDZDXWKdlIPw/eFsoh+nzKhQ1FvW HSgufeHnsefBUUrdJmABDdyJ0OXZH/XX2xO3lRtASHJ5PcAET8cqcxUyW g==; IronPort-SDR: kE/Vj64jz1TnDQQsxUqq1JJ40Gpme5Hjr2rhupmPjoQcbG4roWnDcYFWpUmwFI3mKsclS6XLYT ZXnSkqmu2koctNw0TxPXCJoZpm/W4TwLVsxtIgruxgYTRkPWupr/z5TDIX3f/U4CCyz4BnjifN SEWlRtEamu9vC6Ck5IuaA20S2kx6KIZLziWqe7sp9j+rOInMONeg+1yCjL1s+eA9PdNIuFgMkZ z4VEN3MoQaWgTdtX9OvLoUlBUH2LKJ8O0p+iaGiPy+odMxDK3zYN5e7AyCfty5/H1uN01Ppseh 8u8= X-IronPort-AV: E=Sophos;i="5.79,340,1602518400"; d="scan'208";a="157206089" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 12 Jan 2021 12:28:00 +0800 IronPort-SDR: O0QnDN7CPAX1A4glJWh3YMhLWNK9lBnxqtFs+4r4/qU8YLVABxZdaOvZd51PiM5QNPwtGFid9r dc3nNj+B8/XfDaxmL8/lct9nH1gXVoVq7YVZYt4g9hUh0qepEoQOjq0FJKHGSL5Ij9g9nFBLgF tNOAuu/Q0zYevR09CKOPz/dmrUGn18RjtwcnjtCJpsaXLLCmrlovxG5lbCkQg8rIfpPjO+/kY+ k/VW94NLr/B72BGWrbA/YPCNdkP9c72z7XKGDi1OJ/DfuJvBZAGfVWBqvXY07CbEu7nnWN7eZf e9pqEk28TH8sxi02nB6irv85 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jan 2021 20:10:53 -0800 IronPort-SDR: ENoUV6ViD+OhN4SyMyEOGFgI1dfOUK26uYgQuHPz0wjpqBXCXRofaWIQj9QJ1FEOdiBsp/jLbq dWvFH7tbkuwLeUOngPa6+3Irn8pa/s/qNgi2Y2McntxGmIeS/BLyrWeOjRQ3KI6gtx/4DUOlw3 c10XoWgTBpgKuVT8DRRbvmh6ip62q/G3tQqoiBlZS+sLMzfWi3+IDg/be2kFeDtr5lDCcjM0rG cieMweCeSYmMbjjrNtYIxm5v6vb7pDPEKACiGlxSu1DXvAoQCI2TPlk3i05ornGsBMNF4jSOGT 4mc= WDCIronportException: Internal Received: from vm.labspan.wdc.com (HELO vm.sc.wdc.com) ([10.6.137.102]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Jan 2021 20:28:00 -0800 From: Chaitanya Kulkarni To: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org Cc: hch@lst.de, sagi@grimberg.me, damien.lemoal@wdc.com, Chaitanya Kulkarni Subject: [PATCH V9 9/9] nvmet: call nvmet_bio_done() for zone append Date: Mon, 11 Jan 2021 20:26:23 -0800 Message-Id: <20210112042623.6316-10-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> References: <20210112042623.6316-1-chaitanya.kulkarni@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The function nvmet_bdev_execute_zone_append() does exactly same thing for completion of the bio that is done in the nvmet_bio_done(), completing the request & calling nvmet_bio_put()_to put non online bio. Export the function nvmet_bio_done() and use that in the nvmet_bdev_execute_zone_append() for the request completion and bio processing. Set the bio->private after the call to submit_bio_wait() to nvmet request. The call to nvmet_bio_done() also updates error log page via call to blk_to_nvme_status() from nvmet_bio_done(). Signed-off-by: Chaitanya Kulkarni --- drivers/nvme/target/io-cmd-bdev.c | 2 +- drivers/nvme/target/nvmet.h | 1 + drivers/nvme/target/zns.c | 10 ++++------ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index c23a719513b0..72a22351da2a 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -167,7 +167,7 @@ static u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts) return status; } -static void nvmet_bio_done(struct bio *bio) +void nvmet_bio_done(struct bio *bio) { struct nvmet_req *req = bio->bi_private; diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index f4f9d622df0d..ab84ab75b952 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -535,6 +535,7 @@ void nvmet_ns_changed(struct nvmet_subsys *subsys, u32 nsid); void nvmet_bdev_ns_revalidate(struct nvmet_ns *ns); int nvmet_file_ns_revalidate(struct nvmet_ns *ns); void nvmet_ns_revalidate(struct nvmet_ns *ns); +void nvmet_bio_done(struct bio *bio); static inline u32 nvmet_rw_data_len(struct nvmet_req *req) { diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c index 149bc8ce7010..da4be0231428 100644 --- a/drivers/nvme/target/zns.c +++ b/drivers/nvme/target/zns.c @@ -283,7 +283,6 @@ void nvmet_bdev_execute_zone_append(struct nvmet_req *req) struct request_queue *q = req->ns->bdev->bd_disk->queue; unsigned int op = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE; unsigned int max_sects = queue_max_zone_append_sectors(q); - u16 status = NVME_SC_SUCCESS; unsigned int total_len = 0; struct scatterlist *sg; int ret = 0, sg_cnt; @@ -306,7 +305,7 @@ void nvmet_bdev_execute_zone_append(struct nvmet_req *req) ret = bio_add_hw_page(q, bio, p, l, o, max_sects, &same_page); if (ret != sg->length) { - status = NVME_SC_INTERNAL; + bio->bi_status = BLK_STS_IOERR; goto out_bio_put; } if (same_page) @@ -316,15 +315,14 @@ void nvmet_bdev_execute_zone_append(struct nvmet_req *req) } if (total_len != nvmet_rw_data_len(req)) { - status = NVME_SC_INTERNAL | NVME_SC_DNR; + bio->bi_status = BLK_STS_IOERR; goto out_bio_put; } ret = submit_bio_wait(bio); req->cqe->result.u64 = nvmet_sect_to_lba(req->ns, bio->bi_iter.bi_sector); - out_bio_put: - nvmet_req_bio_put(req, bio); - nvmet_req_complete(req, ret < 0 ? NVME_SC_INTERNAL : status); + bio->bi_private = req; + nvmet_bio_done(bio); }