From patchwork Tue Sep 27 18:56:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaun Tancheff X-Patchwork-Id: 9352659 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4896560757 for ; Tue, 27 Sep 2016 18:56:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DBD528F0E for ; Tue, 27 Sep 2016 18:56:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 320A628EFB; Tue, 27 Sep 2016 18:56:26 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A43A928F0E for ; Tue, 27 Sep 2016 18:56:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754472AbcI0S4Z (ORCPT ); Tue, 27 Sep 2016 14:56:25 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:33316 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750899AbcI0S4X (ORCPT ); Tue, 27 Sep 2016 14:56:23 -0400 Received: by mail-io0-f195.google.com with SMTP id r145so1434888ior.0; Tue, 27 Sep 2016 11:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=hHUSMCU020FtxJFoC6epyFcGN+w1rAuu17yAl12mAew=; b=QZbuAxT4mhG2tG53Dx77kpmg4Ve7KmIZGSi64BXZM8G9E0yX65TiogUR7Xjxq/X7w4 LfNW5hiJpoIX9QvxpG3Jpcur/4tnIwxn0U6KlfuE6+mG7n50yj58Kk3wOGvWRKiEciCS Hwt2GTzFr19nxB+BYXS19jxkO5+llGIN2bZ37I177fbJgHI8DmqDl+u7kq6uHTRGVVd2 xBKzATLV/qwoNerVSH1oLqFXfDfo2VlxiG7B7iKagn1OGv4RUqjHGZ8aGRWcZW5sd8S/ ez/NwwI2Q5yzRMBxTPgRsehRGThK+kftBuXTkY6gq03Na9mKFjw9xrviO1czio2saduv B7OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=hHUSMCU020FtxJFoC6epyFcGN+w1rAuu17yAl12mAew=; b=hiFskJ637eizQ2dMxWyAYWo/6u8cw+Lcniz+qT/6ZTpdt1kSkrpDUacx2W+JyRfMcw Mn7+zYlY4Tlg9j8UosnoCy5045Wx0Qr74c3RpDYvK66fEyFjShtS4lRFgGSpFPoxPvqn Mrus9UFBgJaSqrlYL3LkQDNc7bcV30PJY+AtP9XgQREO36T7+2nRgHxemKcwcEYhJsmw z936QRYRIWBNci+/+IB57a23+72gTRD9YccKChW/j9TjSVMKRi2Pgtr8MuyCMdlpWrq8 jgtPO3WI+6jtdzd40CjyhtsifnHN/RCGo0JmeTM5BCjrFRui78s5Hb0QbyjKxh1RjU5W e+VA== X-Gm-Message-State: AE9vXwN0yAc5Tg5Rkh090DFouIBUBWZVtDo5gGQHjf1fGqvdKK1lpWLZLSpBsaA9gJF+rw== X-Received: by 10.107.139.14 with SMTP id n14mr31707322iod.166.1475002582782; Tue, 27 Sep 2016 11:56:22 -0700 (PDT) Received: from helios.aeonazure.com (173-16-223-93.client.mchsi.com. [173.16.223.93]) by smtp.gmail.com with ESMTPSA id m127sm1416698ioe.32.2016.09.27.11.56.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Sep 2016 11:56:21 -0700 (PDT) From: Shaun Tancheff To: Jens Axboe Cc: Shaun Tancheff , linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Christoph Hellwig , "Martin K . Petersen" , Hannes Reinecke , Damien Le Moal , shaun.tancheff@seagate.com Subject: [PATCH v3 7/7] blk-zoned: implement ioctls Date: Tue, 27 Sep 2016 13:56:17 -0500 Message-Id: <20160927185617.19405-1-shaun@tancheff.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <1474888209-29445-8-git-send-email-damien.lemoal@hgst.com> References: <1474888209-29445-8-git-send-email-damien.lemoal@hgst.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adds the new BLKREPORTZONE and BLKRESETZONE ioctls for respectively obtaining the zone configuration of a zoned block device and resetting the write pointer of sequential zones of a zoned block device. The BLKREPORTZONE ioctl maps directly to a single call of the function blkdev_report_zones. The zone information result is passed as an array of struct blk_zone identical to the structure used internally for processing the REQ_OP_ZONE_REPORT operation. The BLKRESETZONE ioctl maps to a single call of the blkdev_reset_zones function. Signed-off-by: Shaun Tancheff Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig --- Changes since v2: - Changed kzalloc() to kcalloc() per Christoph - Added ioctl specific bits to uapi as blkzoned.h is now added in an earlier patch. block/blk-zoned.c | 93 +++++++++++++++++++++++++++++++++++++++++++ block/ioctl.c | 4 ++ include/linux/blkdev.h | 22 ++++++++++ include/uapi/linux/blkzoned.h | 40 +++++++++++++++++++ include/uapi/linux/fs.h | 4 ++ 5 files changed, 163 insertions(+) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index bc4159d..91f7347 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -240,3 +240,96 @@ int blkdev_reset_zones(struct block_device *bdev, return 0; } EXPORT_SYMBOL_GPL(blkdev_reset_zones); + +/** + * BLKREPORTZONE ioctl processing. + * Called from blkdev_ioctl. + */ +int blkdev_report_zones_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_report rep; + struct blk_zone *zones; + int ret; + + if (!argp) + return -EINVAL; + + q = bdev_get_queue(bdev); + if (!q) + return -ENXIO; + + if (!blk_queue_is_zoned(q)) + return -ENOTTY; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (copy_from_user(&rep, argp, sizeof(struct blk_zone_report))) + return -EFAULT; + + if (!rep.nr_zones) + return -EINVAL; + + zones = kcalloc(rep.nr_zones, sizeof(struct blk_zone), GFP_KERNEL); + if (!zones) + return -ENOMEM; + + ret = blkdev_report_zones(bdev, rep.sector, + zones, &rep.nr_zones, + GFP_KERNEL); + if (ret) + goto out; + + if (copy_to_user(argp, &rep, sizeof(struct blk_zone_report))) { + ret = -EFAULT; + goto out; + } + + if (rep.nr_zones) { + if (copy_to_user(argp + sizeof(struct blk_zone_report), zones, + sizeof(struct blk_zone) * rep.nr_zones)) + ret = -EFAULT; + } + + out: + kfree(zones); + + return ret; +} + +/** + * BLKRESETZONE ioctl processing. + * Called from blkdev_ioctl. + */ +int blkdev_reset_zones_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; + + if (!argp) + return -EINVAL; + + q = bdev_get_queue(bdev); + if (!q) + return -ENXIO; + + if (!blk_queue_is_zoned(q)) + return -ENOTTY; + + if (!capable(CAP_SYS_ADMIN)) + return -EACCES; + + if (!(mode & FMODE_WRITE)) + return -EBADF; + + 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); +} diff --git a/block/ioctl.c b/block/ioctl.c index ed2397f..448f78a 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -513,6 +513,10 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, BLKDEV_DISCARD_SECURE); case BLKZEROOUT: return blk_ioctl_zeroout(bdev, mode, arg); + case BLKREPORTZONE: + return blkdev_report_zones_ioctl(bdev, mode, cmd, arg); + case BLKRESETZONE: + return blkdev_reset_zones_ioctl(bdev, mode, cmd, arg); case HDIO_GETGEO: return blkdev_getgeo(bdev, argp); case BLKRAGET: diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 6316972..0a75285 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -315,6 +315,28 @@ extern int blkdev_report_zones(struct block_device *, unsigned int *, gfp_t); extern int blkdev_reset_zones(struct block_device *, sector_t, sector_t, gfp_t); + +extern int blkdev_report_zones_ioctl(struct block_device *, fmode_t, + unsigned int, unsigned long); +extern int blkdev_reset_zones_ioctl(struct block_device *, fmode_t, + unsigned int, unsigned long); + +#else /* CONFIG_BLK_DEV_ZONED */ + +static inline int blkdev_report_zones_ioctl(struct block_device *bdev, + fmode_t mode, unsigned int cmd, + unsigned long arg) +{ + return -ENOTTY; +} + +static inline int blkdev_reset_zones_ioctl(struct block_device *bdev, + fmode_t mode, unsigned int cmd, + unsigned long arg) +{ + return -ENOTTY; +} + #endif /* CONFIG_BLK_DEV_ZONED */ struct request_queue { diff --git a/include/uapi/linux/blkzoned.h b/include/uapi/linux/blkzoned.h index a381721..40d1d7b 100644 --- a/include/uapi/linux/blkzoned.h +++ b/include/uapi/linux/blkzoned.h @@ -16,6 +16,7 @@ #define _UAPI_BLKZONED_H #include +#include /** * enum blk_zone_type - Types of zones allowed in a zoned device. @@ -100,4 +101,43 @@ struct blk_zone { __u8 reserved[36]; }; +/** + * struct blk_zone_report - BLKREPORTZONE ioctl request/reply + * + * @sector: starting sector of report + * @nr_zones: IN maximum / OUT actual + * @reserved: padding to 16 byte alignment + * @zones: Space to hold @nr_zones @zones entries on reply. + * + * The array of at most @nr_zones must follow this structure in memory. + */ +struct blk_zone_report { + __u64 sector; + __u32 nr_zones; + __u8 reserved[4]; + struct blk_zone zones[0]; +} __packed; + +/** + * 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 { + __u64 sector; + __u64 nr_sectors; +}; + +/** + * Zoned block device ioctl's: + * + * @BLKREPORTZONE: Get zone information. Takes a zone report as argument. + * The zone report will start from the zone containing the + * sector specified in the report request structure. + * @BLKRESETZONE: Reset the write pointer of 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) + #endif /* _UAPI_BLKZONED_H */ diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 3b00f7c..e0fc7f0 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -222,6 +222,10 @@ struct fsxattr { #define BLKSECDISCARD _IO(0x12,125) #define BLKROTATIONAL _IO(0x12,126) #define BLKZEROOUT _IO(0x12,127) +/* + * A jump here: 130-131 are reserved for zoned block devices + * (see uapi/linux/blkzoned.h) + */ #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1) /* bmap access */