From patchwork Mon Apr 4 05:06:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaun Tancheff X-Patchwork-Id: 8737391 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5DC65C0553 for ; Mon, 4 Apr 2016 05:06:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8868C201EF for ; Mon, 4 Apr 2016 05:06:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8549020204 for ; Mon, 4 Apr 2016 05:06:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752105AbcDDFGt (ORCPT ); Mon, 4 Apr 2016 01:06:49 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36387 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751968AbcDDFGq (ORCPT ); Mon, 4 Apr 2016 01:06:46 -0400 Received: by mail-pf0-f196.google.com with SMTP id q129so20128333pfb.3; Sun, 03 Apr 2016 22:06:46 -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=yA/UmyBZHhcE9g8BMGvteoXDIL7dIZC0SYHjSS9bL5A=; b=Oy0hkln3kfae4WTIKg/i0WW99+Y1QQ1TbEXYlGU/An5qRRwzPKAcJQQg0fbCRr6PwW 8f4XVmFlblcbTgPagxH+txH3oEs/MVcL2tdrxOQpwhP3i97N68TGJBVzXcCMcUFaIfrY N//A0XwP4q27OehGBbNU84JW3Ovlm5lKhZZmWCy3khl7UshIa6/CpUkktLI5hinIJwwD noLPYMcU2wEc1LYMZad35+3G1vT44C7zvoi+AxzrdLJAW3xcDQ8ExBVC8IzduTMYDAdT /wn4NhJHjQih0fj1Xn6Blgj9mGu0m9vRF7IuoMVcuOHcQydvDSYIazcpi+nIZkqBmkaf PxWg== 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=yA/UmyBZHhcE9g8BMGvteoXDIL7dIZC0SYHjSS9bL5A=; b=CDbA9WH53p+H0uDIbwQ7B/PdEzWZGJGTz4lPi02c2JI3UBTxvHXaURU0Q2A71jDLrr kkFeBNW/LE6t4mLnYWZ+pdWOmGsEzmtAsxihmZ2TMH0fTmaws9UQIhb3QzkNrP/iqwtK gZXQKpcSoArkPuCpTgxaT+ONcAEh+PJEk5yjtPGgetM6iRrUfzguWqxau36/x7g9PKmc 7orAv/zkscjVCdFJEBeUjYnXYG3zhtUBxLAvK/QVPQx+bSXZveMtwjWnZw5AODVR6t2Z VfOpQUSmxQxQsh84BhJbuRDNmJcdPQOUu+cmhkjTkX5OT+WpfAkk4H3rGYel4CRqfevI G3DQ== X-Gm-Message-State: AD7BkJKiWaOusj4GEbSMGR/DQZ4FisqzGhlx8K6ujZTLcJ2Lbxk6qDIQMjpVQ0NncnSDog== X-Received: by 10.98.80.70 with SMTP id e67mr18007016pfb.136.1459746406162; Sun, 03 Apr 2016 22:06:46 -0700 (PDT) Received: from localhost.localdomain ([103.47.135.1]) by smtp.gmail.com with ESMTPSA id k65sm35804188pfb.30.2016.04.03.22.06.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 03 Apr 2016 22:06:45 -0700 (PDT) From: Shaun Tancheff To: linux-ide@vger.kernel.org, dm-devel@redhat.com, linux-block@vger.kernel.org, linux-scsi@vger.kernel.org Cc: Jens Axboe , Shaun Tancheff , Shaun Tancheff Subject: [PATCH 05/12] Add ioctl to issue ZBC/ZAC commands via block layer Date: Mon, 4 Apr 2016 12:06:09 +0700 Message-Id: <1459746376-27983-6-git-send-email-shaun@tancheff.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1459746376-27983-1-git-send-email-shaun@tancheff.com> References: <1459746376-27983-1-git-send-email-shaun@tancheff.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.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 --- block/ioctl.c | 113 ++++++++++++++++++++++++++++++++++++++ include/uapi/linux/blkzoned_api.h | 6 ++ 2 files changed, 119 insertions(+) diff --git a/block/ioctl.c b/block/ioctl.c index d8996bb..825848f 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -195,6 +196,112 @@ 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 bi_rw = 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; + if (zone_iodata->data.in.report_option & ZOPT_USE_ATA_PASS) + bi_rw |= REQ_META; + + error = blkdev_issue_zone_report(bdev, bi_rw, + 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 cmd, unsigned long arg) +{ + unsigned long bi_rw = 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: + bi_rw |= REQ_OPEN_ZONE; + break; + case BLKCLOSEZONE: + bi_rw |= REQ_CLOSE_ZONE; + break; + case BLKRESETZONE: + bi_rw |= REQ_RESET_ZONE; + break; + default: + pr_err("%s: Unknown action: %u\n", __func__, cmd); + WARN_ON(1); + } + return blkdev_issue_zone_action(bdev, bi_rw, arg, GFP_KERNEL); +} + static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, unsigned long arg, unsigned long flags) { @@ -598,6 +705,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 BLKDAXGET: return put_int(arg, !!(bdev->bd_inode->i_flags & S_DAX)); break; 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 */