From patchwork Tue Jun 7 20:02:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaun Tancheff X-Patchwork-Id: 9162437 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 4FC6660572 for ; Tue, 7 Jun 2016 20:08:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42D55282DC for ; Tue, 7 Jun 2016 20:08:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3768B2835B; Tue, 7 Jun 2016 20:08:30 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D500282DC for ; Tue, 7 Jun 2016 20:08:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162027AbcFGUIR (ORCPT ); Tue, 7 Jun 2016 16:08:17 -0400 Received: from smtp78.mediacombb.net ([68.66.77.78]:39219 "EHLO dsmdc-mail-smtp.mcomdc.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1162026AbcFGUIO (ORCPT ); Tue, 7 Jun 2016 16:08:14 -0400 Received: from helios ([173.23.250.243]) by njtocomv03.mcomdc.com with bizsmtp id 3w7a1t0055FqEsV01w7a8u; Tue, 07 Jun 2016 16:07:36 -0400 X-Outbound-Route: TO X-Authenticated-Sender: shaun@helios.aeonazure.com X-Authority-Analysis: v=2.1 cv=Yq2BRuoX c=1 sm=1 tr=0 a=OCiMecrhrNRzvyrd/uXHhg==:117 a=OCiMecrhrNRzvyrd/uXHhg==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=pD_ry4oyNxEA:10 a=3go8odswAAAA:8 a=Zz8MzU0AIlXCZ3tAjnUA:9 a=WCphLhRDQySbTNkkd-8K:22 X-Authenticated-Sender: shaun@helios.aeonazure.com Received: from shaun by helios with local (Exim 4.87) (envelope-from ) id 1bANHi-0002Qu-6y; Tue, 07 Jun 2016 15:07:34 -0500 From: Shaun Tancheff To: linux-ide@vger.kernel.org, linux-block@vger.kernel.org, linux-scsi@vger.kernel.org Cc: Shaun Tancheff , Jens Axboe , "James E . J . Bottomley" , "Martin K . Petersen" , Jeff Layton , "J . Bruce Fields" , Shaun Tancheff Subject: [PATCH v2 3/4] Add ioctl to issue ZBC/ZAC commands via block layer Date: Tue, 7 Jun 2016 15:02:31 -0500 Message-Id: <1465329752-9262-4-git-send-email-shaun@tancheff.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1465329752-9262-1-git-send-email-shaun@tancheff.com> References: <1465329752-9262-1-git-send-email-shaun@tancheff.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add New ioctl types BLKREPORT - Issue Report Zones to device. BLKOPENZONE - Issue an Zone Action: Open Zone command. BLKCLOSEZONE - Issue an Zone Action: Close Zone command. BLKRESETZONE - Issue an Zone Action: Reset Zone command. Signed-off-by: Shaun Tancheff --- V2: - Added include/uapi/linux/fs.h - Removed REQ_META flag from this patch. block/ioctl.c | 110 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/blkzoned_api.h | 6 +++ include/uapi/linux/fs.h | 1 + 3 files changed, 117 insertions(+) diff --git a/block/ioctl.c b/block/ioctl.c index ed2397f..97f45f5 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -194,6 +195,109 @@ int blkdev_reread_part(struct block_device *bdev) } EXPORT_SYMBOL(blkdev_reread_part); +static int blk_zoned_report_ioctl(struct block_device *bdev, fmode_t mode, + void __user *parg) +{ + int error = -EFAULT; + gfp_t gfp = GFP_KERNEL; + struct bdev_zone_report_io *zone_iodata = NULL; + int order = 0; + struct page *pgs = NULL; + u32 alloc_size = PAGE_SIZE; + unsigned long op_flags = 0; + u8 opt = 0; + + if (!(mode & FMODE_READ)) + return -EBADF; + + zone_iodata = (void *)get_zeroed_page(gfp); + if (!zone_iodata) { + error = -ENOMEM; + goto report_zones_out; + } + if (copy_from_user(zone_iodata, parg, sizeof(*zone_iodata))) { + error = -EFAULT; + goto report_zones_out; + } + if (zone_iodata->data.in.return_page_count > alloc_size) { + int npages; + + alloc_size = zone_iodata->data.in.return_page_count; + npages = (alloc_size + PAGE_SIZE - 1) / PAGE_SIZE; + order = ilog2(roundup_pow_of_two(npages)); + pgs = alloc_pages(gfp, order); + if (pgs) { + void *mem = page_address(pgs); + + if (!mem) { + error = -ENOMEM; + goto report_zones_out; + } + memset(mem, 0, alloc_size); + memcpy(mem, zone_iodata, sizeof(*zone_iodata)); + free_page((unsigned long)zone_iodata); + zone_iodata = mem; + } else { + /* Result requires DMA capable memory */ + pr_err("Not enough memory available for request.\n"); + error = -ENOMEM; + goto report_zones_out; + } + } + opt = zone_iodata->data.in.report_option & 0x7F; + error = blkdev_issue_zone_report(bdev, op_flags, + zone_iodata->data.in.zone_locator_lba, opt, + pgs ? pgs : virt_to_page(zone_iodata), + alloc_size, GFP_KERNEL); + + if (error) + goto report_zones_out; + + if (copy_to_user(parg, zone_iodata, alloc_size)) + error = -EFAULT; + +report_zones_out: + if (pgs) + __free_pages(pgs, order); + else if (zone_iodata) + free_page((unsigned long)zone_iodata); + return error; +} + +static int blk_zoned_action_ioctl(struct block_device *bdev, fmode_t mode, + unsigned int cmd, unsigned long arg) +{ + unsigned long op_flags = 0; + + if (!(mode & FMODE_WRITE)) + return -EBADF; + + /* + * When acting on zones we explicitly disallow using a partition. + */ + if (bdev != bdev->bd_contains) { + pr_err("%s: All zone operations disallowed on this device\n", + __func__); + return -EFAULT; + } + + switch (cmd) { + case BLKOPENZONE: + op_flags |= REQ_OPEN_ZONE; + break; + case BLKCLOSEZONE: + op_flags |= REQ_CLOSE_ZONE; + break; + case BLKRESETZONE: + op_flags |= REQ_RESET_ZONE; + break; + default: + pr_err("%s: Unknown action: %u\n", __func__, cmd); + WARN_ON(1); + } + return blkdev_issue_zone_action(bdev, op_flags, arg, GFP_KERNEL); +} + static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, unsigned long arg, unsigned long flags) { @@ -568,6 +672,12 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, case BLKTRACESETUP: case BLKTRACETEARDOWN: return blk_trace_ioctl(bdev, cmd, argp); + case BLKREPORT: + return blk_zoned_report_ioctl(bdev, mode, argp); + case BLKOPENZONE: + case BLKCLOSEZONE: + case BLKRESETZONE: + return blk_zoned_action_ioctl(bdev, mode, cmd, arg); case IOC_PR_REGISTER: return blkdev_pr_register(bdev, argp); case IOC_PR_RESERVE: diff --git a/include/uapi/linux/blkzoned_api.h b/include/uapi/linux/blkzoned_api.h index 189e925..2007b56 100644 --- a/include/uapi/linux/blkzoned_api.h +++ b/include/uapi/linux/blkzoned_api.h @@ -212,4 +212,10 @@ struct bdev_zone_report_io { } data; } __packed; +/* continuing from uapi/linux/fs.h: */ +#define BLKREPORT _IOWR(0x12, 130, struct bdev_zone_report_io) +#define BLKOPENZONE _IO(0x12, 131) +#define BLKCLOSEZONE _IO(0x12, 132) +#define BLKRESETZONE _IO(0x12, 133) + #endif /* _UAPI_BLKZONED_API_H */ diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 3b00f7c..c0b565b 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -222,6 +222,7 @@ struct fsxattr { #define BLKSECDISCARD _IO(0x12,125) #define BLKROTATIONAL _IO(0x12,126) #define BLKZEROOUT _IO(0x12,127) +/* A jump here: See blkzoned_api.h, Reserving 130 to 133. */ #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1) /* bmap access */