From patchwork Fri Jun 21 13:07:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matias Bjorling X-Patchwork-Id: 11012549 X-Patchwork-Delegate: snitzer@redhat.com 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 61532112C for ; Mon, 24 Jun 2019 07:43:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 505962884B for ; Mon, 24 Jun 2019 07:43:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4434D28974; Mon, 24 Jun 2019 07:43: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 mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 70C552884B for ; Mon, 24 Jun 2019 07:43:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AEFDB882F5; Mon, 24 Jun 2019 07:43:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F72A5D9C5; Mon, 24 Jun 2019 07:43:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5DCDE206D6; Mon, 24 Jun 2019 07:43:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5LD7qXT014241 for ; Fri, 21 Jun 2019 09:07:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC18019CB1; Fri, 21 Jun 2019 13:07:52 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E586118AAB for ; Fri, 21 Jun 2019 13:07:50 +0000 (UTC) Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 83109307D854 for ; Fri, 21 Jun 2019 13:07:31 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id k18so5881432ljc.11 for ; Fri, 21 Jun 2019 06:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2vhySjd6HyAQGz86wftxAId7gw5oA1TV6yT5lbqXCs8=; b=d3qDl7gtl1j+Hk3gb4K9KzB8LgwmlfJO9/Yo2ozFsDzcLkQTT7WxQR8Xj2jQC6naSF 1d5MH4Hg/i/lDsXxqSx1YKJCpvMaAYROYH+kzVZGWYebgZj+2M7XyZwqiyv6R8pMQijt QekloHa3XLx2rYBXWeh0hYlfYHO5RtIHnNrPiaHKmAeHsIJgszBNpLpg2c9pc3h0pucO jKelgmr4Hzo2RjY35WGuQwDh5TCTVbTZdWWx5PdBA+O2x8WkagZji9/C2bRtzvl4yKRK mUI21721hUJvD7/oFR2F/14ymv0qkzuNyn7SsvGbT8OqoY6IitKrsaFZRSQMDusYuH2Q /XPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2vhySjd6HyAQGz86wftxAId7gw5oA1TV6yT5lbqXCs8=; b=t20biouE0GkFYJVRwqElwEVJvFXwZtLRlEzedcBCVaJcjf42EbHx0hW6kzuzkiZ0ug 9ecHS2O3AcXPW4qLEP5Jgl5iq3WuT72JNNuTfCTzVs3znvg59OaKCmgMwamB1+COtU1c RtoySlX69Srzu5wmNxLR3z2fZn3i4vT5n2lgADVL3qxamnUyerWh1q/rRjsW+1wpifDU 8LDp79hoZj5liLshdsE2t20B0UBD+RZXxnHYqV8mNDv/rMRlFQMYU8fazBhW+XHTB0AZ EMnacEWp5TkrEi/SAlOF3jFmOZt6+AKYWXBqKkWvjw4ZYzNhmInpFvn7F46sstGIxk4/ VlZg== X-Gm-Message-State: APjAAAUelUlRgOnQDgzzSJf0xU+Z4IZJtGclUN18liK60FaLEb5ARpWd ks8sfjS6ly/Vgzgn1IR+1OI7MHL9QvI= X-Google-Smtp-Source: APXvYqyaj5zE2Q4iZD1SSrYtvHM9/oy8VgGciJ2+N1JfUErT2t/do01rXTFk51qdeIQwjDJN9L3VMA== X-Received: by 2002:a2e:650a:: with SMTP id z10mr32642486ljb.28.1561122449940; Fri, 21 Jun 2019 06:07:29 -0700 (PDT) Received: from skyninja.webspeed.dk (2-111-91-225-cable.dk.customer.tdc.net. [2.111.91.225]) by smtp.gmail.com with ESMTPSA id r2sm387100lfi.51.2019.06.21.06.07.28 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 21 Jun 2019 06:07:29 -0700 (PDT) From: =?utf-8?q?Matias_Bj=C3=B8rling?= To: axboe@fb.com, hch@lst.de, damien.lemoal@wdc.com, chaitanya.kulkarni@wdc.com, dmitry.fomichev@wdc.com, ajay.joshi@wdc.com, aravind.ramesh@wdc.com, martin.petersen@oracle.com, James.Bottomley@HansenPartnership.com, agk@redhat.com, snitzer@redhat.com Date: Fri, 21 Jun 2019 15:07:08 +0200 Message-Id: <20190621130711.21986-2-mb@lightnvm.io> In-Reply-To: <20190621130711.21986-1-mb@lightnvm.io> References: <20190621130711.21986-1-mb@lightnvm.io> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 21 Jun 2019 13:07:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 21 Jun 2019 13:07:32 +0000 (UTC) for IP:'209.85.208.196' DOMAIN:'mail-lj1-f196.google.com' HELO:'mail-lj1-f196.google.com' FROM:'mb@lightnvm.io' RCPT:'' X-RedHat-Spam-Score: 0.191 (DKIM_INVALID, DKIM_SIGNED, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE) 209.85.208.196 mail-lj1-f196.google.com 209.85.208.196 mail-lj1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Mon, 24 Jun 2019 03:43:21 -0400 Cc: linux-block@vger.kernel.org, dm-devel@redhat.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, =?utf-8?q?Matias_?= =?utf-8?q?Bj=C3=B8rling?= Subject: [dm-devel] [PATCH 1/4] block: add zone open, close and finish support X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 24 Jun 2019 07:43:57 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP From: Ajay Joshi Zoned block devices allows one to control zone transitions by using explicit commands. The available transitions are: * Open zone: Transition a zone to open state. * Close zone: Transition a zone to closed state. * Finish zone: Transition a zone to full state. Allow kernel to issue these transitions by introducing blkdev_zones_mgmt_op() and add three new request opcodes: * REQ_IO_ZONE_OPEN, REQ_IO_ZONE_CLOSE, and REQ_OP_ZONE_FINISH Allow user-space to issue the transitions through the following ioctls: * BLKOPENZONE, BLKCLOSEZONE, and BLKFINISHZONE. Signed-off-by: Ajay Joshi Signed-off-by: Aravind Ramesh Signed-off-by: Matias Bjørling Reviewed-by: Minwoo Im Reviewed-by: Javier González --- block/blk-core.c | 3 ++ block/blk-zoned.c | 51 ++++++++++++++++++++++--------- block/ioctl.c | 5 ++- include/linux/blk_types.h | 27 +++++++++++++++-- include/linux/blkdev.h | 57 ++++++++++++++++++++++++++++++----- include/uapi/linux/blkzoned.h | 17 +++++++++-- 6 files changed, 133 insertions(+), 27 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 8340f69670d8..c0f0dbad548d 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -897,6 +897,9 @@ generic_make_request_checks(struct bio *bio) goto not_supported; break; case REQ_OP_ZONE_RESET: + case REQ_OP_ZONE_OPEN: + case REQ_OP_ZONE_CLOSE: + case REQ_OP_ZONE_FINISH: if (!blk_queue_is_zoned(q)) goto not_supported; break; diff --git a/block/blk-zoned.c b/block/blk-zoned.c index ae7e91bd0618..d0c933593b93 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -201,20 +201,22 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector, EXPORT_SYMBOL_GPL(blkdev_report_zones); /** - * blkdev_reset_zones - Reset zones write pointer + * blkdev_zones_mgmt_op - Perform the specified operation on the zone(s) * @bdev: Target block device - * @sector: Start sector of the first zone to reset - * @nr_sectors: Number of sectors, at least the length of one zone + * @op: Operation to be performed on the zone(s) + * @sector: Start sector of the first zone to operate on + * @nr_sectors: Number of sectors, at least the length of one zone and + * must be zone size aligned. * @gfp_mask: Memory allocation flags (for bio_alloc) * * Description: - * Reset the write pointer of the zones contained in the range + * Perform the specified operation contained in the range * @sector..@sector+@nr_sectors. Specifying the entire disk sector range * is valid, but the specified range should not contain conventional zones. */ -int blkdev_reset_zones(struct block_device *bdev, - sector_t sector, sector_t nr_sectors, - gfp_t gfp_mask) +int blkdev_zones_mgmt_op(struct block_device *bdev, enum req_opf op, + sector_t sector, sector_t nr_sectors, + gfp_t gfp_mask) { struct request_queue *q = bdev_get_queue(bdev); sector_t zone_sectors; @@ -226,6 +228,9 @@ int blkdev_reset_zones(struct block_device *bdev, if (!blk_queue_is_zoned(q)) return -EOPNOTSUPP; + if (!op_is_zone_mgmt_op(op)) + return -EOPNOTSUPP; + if (bdev_read_only(bdev)) return -EPERM; @@ -248,7 +253,7 @@ int blkdev_reset_zones(struct block_device *bdev, bio = blk_next_bio(bio, 0, gfp_mask); bio->bi_iter.bi_sector = sector; bio_set_dev(bio, bdev); - bio_set_op_attrs(bio, REQ_OP_ZONE_RESET, 0); + bio_set_op_attrs(bio, op, 0); sector += zone_sectors; @@ -264,7 +269,7 @@ int blkdev_reset_zones(struct block_device *bdev, return ret; } -EXPORT_SYMBOL_GPL(blkdev_reset_zones); +EXPORT_SYMBOL_GPL(blkdev_zones_mgmt_op); /* * BLKREPORTZONE ioctl processing. @@ -329,15 +334,16 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, } /* - * BLKRESETZONE ioctl processing. + * Zone operation (open, close, finish or reset) ioctl processing. * Called from blkdev_ioctl. */ -int blkdev_reset_zones_ioctl(struct block_device *bdev, fmode_t mode, - unsigned int cmd, unsigned long arg) +int blkdev_zones_mgmt_op_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg) { void __user *argp = (void __user *)arg; struct request_queue *q; struct blk_zone_range zrange; + enum req_opf op; if (!argp) return -EINVAL; @@ -358,8 +364,25 @@ int blkdev_reset_zones_ioctl(struct block_device *bdev, fmode_t mode, if (copy_from_user(&zrange, argp, sizeof(struct blk_zone_range))) return -EFAULT; - return blkdev_reset_zones(bdev, zrange.sector, zrange.nr_sectors, - GFP_KERNEL); + switch (cmd) { + case BLKRESETZONE: + op = REQ_OP_ZONE_RESET; + break; + case BLKOPENZONE: + op = REQ_OP_ZONE_OPEN; + break; + case BLKCLOSEZONE: + op = REQ_OP_ZONE_CLOSE; + break; + case BLKFINISHZONE: + op = REQ_OP_ZONE_FINISH; + break; + default: + return -ENOTTY; + } + + return blkdev_zones_mgmt_op(bdev, op, zrange.sector, zrange.nr_sectors, + GFP_KERNEL); } static inline unsigned long *blk_alloc_zone_bitmap(int node, diff --git a/block/ioctl.c b/block/ioctl.c index 15a0eb80ada9..df7fe54db158 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -532,7 +532,10 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, case BLKREPORTZONE: return blkdev_report_zones_ioctl(bdev, mode, cmd, arg); case BLKRESETZONE: - return blkdev_reset_zones_ioctl(bdev, mode, cmd, arg); + case BLKOPENZONE: + case BLKCLOSEZONE: + case BLKFINISHZONE: + return blkdev_zones_mgmt_op_ioctl(bdev, mode, cmd, arg); case BLKGETZONESZ: return put_uint(arg, bdev_zone_sectors(bdev)); case BLKGETNRZONES: diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 95202f80676c..067ef9242275 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -284,13 +284,20 @@ enum req_opf { REQ_OP_DISCARD = 3, /* securely erase sectors */ REQ_OP_SECURE_ERASE = 5, - /* reset a zone write pointer */ - REQ_OP_ZONE_RESET = 6, /* write the same sector many times */ REQ_OP_WRITE_SAME = 7, /* write the zero filled sector many times */ REQ_OP_WRITE_ZEROES = 9, + /* reset a zone write pointer */ + REQ_OP_ZONE_RESET = 16, + /* Open zone(s) */ + REQ_OP_ZONE_OPEN = 17, + /* Close zone(s) */ + REQ_OP_ZONE_CLOSE = 18, + /* Finish zone(s) */ + REQ_OP_ZONE_FINISH = 19, + /* SCSI passthrough using struct scsi_request */ REQ_OP_SCSI_IN = 32, REQ_OP_SCSI_OUT = 33, @@ -375,6 +382,22 @@ static inline void bio_set_op_attrs(struct bio *bio, unsigned op, bio->bi_opf = op | op_flags; } +/* + * Check if the op is zoned operation. + */ +static inline bool op_is_zone_mgmt_op(enum req_opf op) +{ + switch (op) { + case REQ_OP_ZONE_RESET: + case REQ_OP_ZONE_OPEN: + case REQ_OP_ZONE_CLOSE: + case REQ_OP_ZONE_FINISH: + return true; + default: + return false; + } +} + static inline bool op_is_write(unsigned int op) { return (op & 1); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 592669bcc536..943084f9dc9c 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -348,14 +348,15 @@ extern unsigned int blkdev_nr_zones(struct block_device *bdev); extern int blkdev_report_zones(struct block_device *bdev, sector_t sector, struct blk_zone *zones, unsigned int *nr_zones, gfp_t gfp_mask); -extern int blkdev_reset_zones(struct block_device *bdev, sector_t sectors, - sector_t nr_sectors, gfp_t gfp_mask); extern int blk_revalidate_disk_zones(struct gendisk *disk); extern int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg); -extern int blkdev_reset_zones_ioctl(struct block_device *bdev, fmode_t mode, - unsigned int cmd, unsigned long arg); +extern int blkdev_zones_mgmt_op_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg); +extern int blkdev_zones_mgmt_op(struct block_device *bdev, enum req_opf op, + sector_t sector, sector_t nr_sectors, + gfp_t gfp_mask); #else /* CONFIG_BLK_DEV_ZONED */ @@ -376,15 +377,57 @@ static inline int blkdev_report_zones_ioctl(struct block_device *bdev, return -ENOTTY; } -static inline int blkdev_reset_zones_ioctl(struct block_device *bdev, - fmode_t mode, unsigned int cmd, - unsigned long arg) +static inline int blkdev_zones_mgmt_op_ioctl(struct block_device *bdev, + fmode_t mode, unsigned int cmd, + unsigned long arg) +{ + return -ENOTTY; +} + +static inline int blkdev_zones_mgmt_op(struct block_device *bdev, + enum req_opf op, + sector_t sector, sector_t nr_sectors, + gfp_t gfp_mask) { return -ENOTTY; } #endif /* CONFIG_BLK_DEV_ZONED */ +static inline int blkdev_reset_zones(struct block_device *bdev, + sector_t sector, sector_t nr_sectors, + gfp_t gfp_mask) +{ + return blkdev_zones_mgmt_op(bdev, REQ_OP_ZONE_RESET, + sector, nr_sectors, gfp_mask); +} + +static inline int blkdev_open_zones(struct block_device *bdev, + sector_t sector, sector_t nr_sectors, + gfp_t gfp_mask) +{ + return blkdev_zones_mgmt_op(bdev, REQ_OP_ZONE_OPEN, + sector, nr_sectors, gfp_mask); +} + +static inline int blkdev_close_zones(struct block_device *bdev, + sector_t sector, sector_t nr_sectors, + gfp_t gfp_mask) +{ + return blkdev_zones_mgmt_op(bdev, REQ_OP_ZONE_CLOSE, + sector, nr_sectors, + gfp_mask); +} + +static inline int blkdev_finish_zones(struct block_device *bdev, + sector_t sector, sector_t nr_sectors, + gfp_t gfp_mask) +{ + return blkdev_zones_mgmt_op(bdev, REQ_OP_ZONE_FINISH, + sector, nr_sectors, + gfp_mask); +} + struct request_queue { /* * Together with queue_head for cacheline sharing diff --git a/include/uapi/linux/blkzoned.h b/include/uapi/linux/blkzoned.h index 498eec813494..701e0692b8d3 100644 --- a/include/uapi/linux/blkzoned.h +++ b/include/uapi/linux/blkzoned.h @@ -120,9 +120,11 @@ struct blk_zone_report { }; /** - * struct blk_zone_range - BLKRESETZONE ioctl request - * @sector: starting sector of the first zone to issue reset write pointer - * @nr_sectors: Total number of sectors of 1 or more zones to reset + * struct blk_zone_range - BLKRESETZONE/BLKOPENZONE/ + * BLKCLOSEZONE/BLKFINISHZONE ioctl + * request + * @sector: starting sector of the first zone to operate on + * @nr_sectors: Total number of sectors of all zones to operate on */ struct blk_zone_range { __u64 sector; @@ -139,10 +141,19 @@ struct blk_zone_range { * sector range. The sector range must be zone aligned. * @BLKGETZONESZ: Get the device zone size in number of 512 B sectors. * @BLKGETNRZONES: Get the total number of zones of the device. + * @BLKOPENZONE: Open the zones in the specified sector range. The + * sector range must be zone aligned. + * @BLKCLOSEZONE: Close the zones in the specified sector range. The + * sector range must be zone aligned. + * @BLKFINISHZONE: Finish the zones in the specified sector range. The + * sector range must be zone aligned. */ #define BLKREPORTZONE _IOWR(0x12, 130, struct blk_zone_report) #define BLKRESETZONE _IOW(0x12, 131, struct blk_zone_range) #define BLKGETZONESZ _IOR(0x12, 132, __u32) #define BLKGETNRZONES _IOR(0x12, 133, __u32) +#define BLKOPENZONE _IOW(0x12, 134, struct blk_zone_range) +#define BLKCLOSEZONE _IOW(0x12, 135, struct blk_zone_range) +#define BLKFINISHZONE _IOW(0x12, 136, struct blk_zone_range) #endif /* _UAPI_BLKZONED_H */