From patchwork Tue Dec 8 06:21:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 7794601 Return-Path: X-Original-To: patchwork-linux-fsdevel@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 25296BEEE1 for ; Tue, 8 Dec 2015 06:22:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 349852054B for ; Tue, 8 Dec 2015 06:22:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 21DB0204B5 for ; Tue, 8 Dec 2015 06:22:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932968AbbLHGVp (ORCPT ); Tue, 8 Dec 2015 01:21:45 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:24779 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932952AbbLHGVo (ORCPT ); Tue, 8 Dec 2015 01:21:44 -0500 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id tB86LEYe006932 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Dec 2015 06:21:14 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id tB86LD0r003658 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 8 Dec 2015 06:21:13 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id tB86LDJW016672; Tue, 8 Dec 2015 06:21:13 GMT Received: from localhost (/24.21.154.84) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 07 Dec 2015 22:21:13 -0800 Subject: [PATCH v5 2/2] block: create ioctl to discard-or-zeroout a range of blocks From: "Darrick J. Wong" To: axboe@kernel.dk, hch@infradead.org, darrick.wong@oracle.com Cc: martin.petersen@oracle.com, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, shane.seymour@hpe.com, bfields@fieldses.org, linux-fsdevel@vger.kernel.org, jlayton@poochiereds.net Date: Mon, 07 Dec 2015 22:21:11 -0800 Message-ID: <20151208062111.21427.30921.stgit@birch.djwong.org> In-Reply-To: <20151208062104.21427.91134.stgit@birch.djwong.org> References: <20151208062104.21427.91134.stgit@birch.djwong.org> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Create a new ioctl to expose the block layer's newfound ability to issue either a zeroing discard, a WRITE SAME with a zero page, or a regular write with the zero page. This BLKZEROOUT2 ioctl takes {start, length, flags} as parameters. So far, the only flag available is to enable the zeroing discard part -- without it, the call invokes the old BLKZEROOUT behavior. start and length have the same meaning as in BLKZEROOUT. This new ioctl also invalidates the page cache correctly on account of the previous patch in the series. v3: Add extra padding for future expansion, and check the padding is zero. v4: Check the start/len arguments for overflows prior to feeding the page cache bogus numbers (that it'll ignore anyway). v5: Refactor the 4.4 refactoring of the ioctl code into separate functions. Separate patches for invalidation and new ioctl. Signed-off-by: Darrick J. Wong Reviewed-by: Martin K. Petersen Reviewed-by: Christoph Hellwig --- block/ioctl.c | 57 ++++++++++++++++++++++++++++++++++++----------- include/uapi/linux/fs.h | 9 +++++++ 2 files changed, 53 insertions(+), 13 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/block/ioctl.c b/block/ioctl.c index d06646d..f6d7b5d 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -221,24 +221,20 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, return blkdev_issue_discard(bdev, start, len, GFP_KERNEL, flags); } -static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, - unsigned long arg) +static int __blk_ioctl_zeroout(struct block_device *bdev, + unsigned long long start, + unsigned long long len, + unsigned int flags) { - uint64_t range[2]; struct address_space *mapping; - uint64_t start, end, len; + unsigned long long end; + bool discard = false; int ret; - if (!(mode & FMODE_WRITE)) - return -EBADF; - - if (copy_from_user(range, (void __user *)arg, sizeof(range))) - return -EFAULT; - - start = range[0]; - len = range[1]; end = start + len - 1; + if (flags & ~BLKZEROOUT2_DISCARD_OK) + return -EINVAL; if (start & 511) return -EINVAL; if (len & 511) @@ -252,8 +248,10 @@ static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, mapping = bdev->bd_inode->i_mapping; truncate_inode_pages_range(mapping, start, end); + if (flags & BLKZEROOUT2_DISCARD_OK) + discard = true; ret = blkdev_issue_zeroout(bdev, start >> 9, len >> 9, GFP_KERNEL, - false); + discard); if (ret) return ret; @@ -266,6 +264,37 @@ static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, end >> PAGE_CACHE_SHIFT); } +static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode, + unsigned long arg) +{ + uint64_t range[2]; + + if (!(mode & FMODE_WRITE)) + return -EBADF; + + if (copy_from_user(range, (void __user *)arg, sizeof(range))) + return -EFAULT; + + return __blk_ioctl_zeroout(bdev, range[0], range[1], 0); +} + +static int blk_ioctl_zeroout2(struct block_device *bdev, fmode_t mode, + unsigned long arg) +{ + struct blkzeroout2 p; + + if (!(mode & FMODE_WRITE)) + return -EBADF; + + if (copy_from_user(&p, (void __user *)arg, sizeof(p))) + return -EFAULT; + + if (p.padding || p.padding2) + return -EINVAL; + + return __blk_ioctl_zeroout(bdev, p.start, p.length, p.flags); +} + static int put_ushort(unsigned long arg, unsigned short val) { return put_user(val, (unsigned short __user *)arg); @@ -530,6 +559,8 @@ 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 BLKZEROOUT2: + return blk_ioctl_zeroout2(bdev, mode, arg); case HDIO_GETGEO: return blkdev_getgeo(bdev, argp); case BLKRAGET: diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index f15d980..6decbac 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -152,6 +152,15 @@ struct inodes_stat_t { #define BLKSECDISCARD _IO(0x12,125) #define BLKROTATIONAL _IO(0x12,126) #define BLKZEROOUT _IO(0x12,127) +struct blkzeroout2 { + __u64 start; + __u64 length; + __u32 flags; + __u32 padding; + __u64 padding2; +}; +#define BLKZEROOUT2_DISCARD_OK 1 +#define BLKZEROOUT2 _IOR(0x12, 127, struct blkzeroout2) #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ #define FIBMAP _IO(0x00,1) /* bmap access */