From patchwork Wed Oct 10 00:14:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10633659 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 67B6916B1 for ; Wed, 10 Oct 2018 00:14:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55F39284C9 for ; Wed, 10 Oct 2018 00:14:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E93728F95; Wed, 10 Oct 2018 00:14:18 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCFB9284C9 for ; Wed, 10 Oct 2018 00:14:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 191176B0287; Tue, 9 Oct 2018 20:14:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 141D86B0288; Tue, 9 Oct 2018 20:14:16 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 00A516B0289; Tue, 9 Oct 2018 20:14:15 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by kanga.kvack.org (Postfix) with ESMTP id AFFCA6B0287 for ; Tue, 9 Oct 2018 20:14:15 -0400 (EDT) Received: by mail-pl1-f197.google.com with SMTP id b23-v6so2634955pls.8 for ; Tue, 09 Oct 2018 17:14:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=Nn9zgG7G0RlSFSy0VLmRndBF9S+1SvCJgEndO9+GibM=; b=OjNSyogL6D/7EV4/rnPHYWYcYU5AoqFq9Pq8TOMU0AGwRE9Vs7qHPVfv15rIqbcMkl S65o3zbRsSxccfSsV7KnSLzQ3Hd9pan/t/DDZRmE4nPL9AEq2fo10cOrPmYE2p4szClu AX2ASSHBgGO/WfMCc4FqBUPqhFD9M+eWhMHHdGPotvcEJcmeO7JCGgU9hFSJ8Ei6EcQ3 FePz+jir1FX3PaZ8JuVeVmC8wL64yhyMXyzm0gguTE4wGdlkQA8IWtmyGzakTTBlZuy8 Hw9hWnJMQTVr31qo06CO7lFG362csy+dGejMeL520hVy0LIaQg4kLv/tZS/3r6EpnYSy QPrg== X-Gm-Message-State: ABuFfoiiwymbRUuWcM/7YqjAB8DZub9l43oCm3ebM3/cDikFgq65ieAj dd1fkM8QyQ/eDenETM6mm+eJEfvEcZGC4DmuILyXFkildsuOY2kWg53Fi9BMTAIXZ9hv7Z30qRw mooev/jIyir4+xAMVM1jFGzB6HCKVTVSGWxCgPe61c3Lb0aJGsjpB4KlkZCkiW78X6w== X-Received: by 2002:a62:3047:: with SMTP id w68-v6mr7837712pfw.19.1539130455393; Tue, 09 Oct 2018 17:14:15 -0700 (PDT) X-Google-Smtp-Source: ACcGV62QUJpC6eciYqBB/8JAiP+CH1iYCfDNd1jr/XGB4GdCYaSix11Cjt9qoG0Yp1/UbkDPmGIV X-Received: by 2002:a62:3047:: with SMTP id w68-v6mr7837665pfw.19.1539130454671; Tue, 09 Oct 2018 17:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539130454; cv=none; d=google.com; s=arc-20160816; b=SozqBBciirNjCu5IqpY1TgV5jg/Pu8MyoSumTuWLbFlqibAY7lRb2INrdCvs0ysseF 7ehd0hkEUP+jkBL6qIw9xHNBmKe3+nyrMZvuG11WtBZ5nkzHrf9TYg4eZ/0yCghSfQUV WwFu5C+fXM9GZ4xCAJBb/4H37LOXrgqUHzWQbX5kuTj7Gt46ezROYLUB3xrC6op781Gk ky9sMHhSXq4jpROnNW+6StPQblx4KyA8VfFcBeyXrGiU1p+eT72jJw8WV/1pJgHPP0Hz SIEf6Z5QY72jtmjmEX9cdKv1tjvVA4pQb8qwga7GPyFLu5Av5qWPDi7f7QlCMB66+pE1 7VpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=Nn9zgG7G0RlSFSy0VLmRndBF9S+1SvCJgEndO9+GibM=; b=CxlGafD3YZes7HFb35QEwdDby1PHLOV1aYlQx8ksM8kr2LuFwGTaVfNcdinC4g5dQ+ veZZ/EXXRtMhIEoT2nZJOAQ/8WbO/dF2edQ27D4ZQUy+p04ATEc7wBaFMaoelldGDOse jYkfL6KgMA3y/3snu07gju1XseLcFi12c2RqHzHATETaJMaNCoEESah6P8a2TKnABE9a qkZhZfAS/BDVt/GL88OSmzLDMX0ZmoismQy2AehHkXjOaZNGDQSs0AN8qBRaYpBFZQhE b2sz0jdkedxjVANZYU2kLG2F7rO7YWnA+lfK4JrnSrMEdkvMQpZ54MQ0sIrA4hvN0HeY qOEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=2eDQHC6W; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2120.oracle.com (userp2120.oracle.com. [156.151.31.85]) by mx.google.com with ESMTPS id b127-v6si22140174pga.153.2018.10.09.17.14.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 17:14:14 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 as permitted sender) client-ip=156.151.31.85; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=2eDQHC6W; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9A0EDxM086695; Wed, 10 Oct 2018 00:14:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=Nn9zgG7G0RlSFSy0VLmRndBF9S+1SvCJgEndO9+GibM=; b=2eDQHC6WJ553rjahcYxaCchlOIZC2rsx002DnL+bErYIlutVXMEJPwUYWKR035gC1hTZ 7J0ZhaDWpqg99hxravevj4NxQ/IleUd0yvHkdP14aJCff2HSgCc6I5l63KbCUR2NUH0r S0uU9UdpgYNIQyjaC/qCb/bFOeMtbTV9zuxZdbRhL89ZjAl61gmNPHVMHzyaleYoli3T BnEoXWc9mXsUSsVpa+W24QzqouzA+yuBX0cTZ+Q0mtBR8m+SLBBzrogEXzVROwR9FIBM S7ApEHPqtFJiwbvj9x2Kuie3THLJv2mC1Z+jacGDkKTS0UfF4PKEkDuFqbRcLDRRjtxg sQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2mxnpr0p8k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Oct 2018 00:14:13 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9A0E6Bc032377 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Oct 2018 00:14:07 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9A0E6fg004026; Wed, 10 Oct 2018 00:14:06 GMT Received: from localhost (/10.159.249.114) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 10 Oct 2018 00:14:05 +0000 Subject: [PATCH 18/25] vfs: enable remap callers that can handle short operations From: "Darrick J. Wong" To: david@fromorbit.com, darrick.wong@oracle.com Cc: sandeen@redhat.com, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com Date: Tue, 09 Oct 2018 17:14:04 -0700 Message-ID: <153913044431.32295.9717425324455762449.stgit@magnolia> In-Reply-To: <153913023835.32295.13962696655740190941.stgit@magnolia> References: <153913023835.32295.13962696655740190941.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9041 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=860 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810100001 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Plumb in a remap flag that enables the filesystem remap handler to shorten remapping requests for callers that can handle it. Now copy_file_range can report partial success (in case we run up against alignment problems, resource limits, etc.). Signed-off-by: Darrick J. Wong --- fs/read_write.c | 3 ++- include/linux/fs.h | 2 ++ mm/filemap.c | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index a628fd9a47cf..8ed0aed81649 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1593,7 +1593,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, cloned = file_in->f_op->remap_file_range(file_in, pos_in, file_out, pos_out, - min_t(loff_t, MAX_RW_COUNT, len), 0); + min_t(loff_t, MAX_RW_COUNT, len), + RFR_CAN_SHORTEN); if (cloned >= 0) { ret = cloned; goto done; diff --git a/include/linux/fs.h b/include/linux/fs.h index 9f90dcd4df3b..e0494d719ebc 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1726,9 +1726,11 @@ struct block_device_operations; * * RFR_IDENTICAL_DATA: only remap if contents identical (i.e. deduplicate) * RFR_TO_SRC_EOF: remap to the end of the source file + * RFR_CAN_SHORTEN: caller can handle a shortened request */ #define RFR_IDENTICAL_DATA (1 << 0) #define RFR_TO_SRC_EOF (1 << 1) +#define RFR_CAN_SHORTEN (1 << 2) struct iov_iter; diff --git a/mm/filemap.c b/mm/filemap.c index 2522737483de..2179d0204ee6 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3064,8 +3064,12 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, if (pos_in + count == size_in) { bcount = ALIGN(size_in, bs) - pos_in; } else { - if (!IS_ALIGNED(count, bs)) - return -EINVAL; + if (!IS_ALIGNED(count, bs)) { + if (remap_flags & RFR_CAN_SHORTEN) + count = ALIGN_DOWN(count, bs); + else + return -EINVAL; + } bcount = count; } @@ -3076,10 +3080,14 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, pos_out < pos_in + bcount) return -EINVAL; - /* For now we don't support changing the length. */ - if (*req_count != count) + /* + * We shortened the request but the caller can't deal with that, so + * bounce the request back to userspace. + */ + if (*req_count != count && !(remap_flags & RFR_CAN_SHORTEN)) return -EINVAL; + *req_count = count; return 0; }