From patchwork Thu Oct 11 04:14:26 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: 10635931 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 3470614DB for ; Thu, 11 Oct 2018 04:14:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 182F42787C for ; Thu, 11 Oct 2018 04:14:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C97F2A61E; Thu, 11 Oct 2018 04:14:46 +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 78D152787C for ; Thu, 11 Oct 2018 04:14:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 707166B028C; Thu, 11 Oct 2018 00:14:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6B6886B028D; Thu, 11 Oct 2018 00:14:44 -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 5CD896B028E; Thu, 11 Oct 2018 00:14:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id 1EA5C6B028C for ; Thu, 11 Oct 2018 00:14:44 -0400 (EDT) Received: by mail-pf1-f197.google.com with SMTP id z12-v6so6710116pfl.17 for ; Wed, 10 Oct 2018 21:14:44 -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=9Oy/QAfur+gc2YE69PqaCVfOP0qAmnW7K6awiLQrXfA=; b=SJ/6f0K8050w0eOjXwhdFJCRFqgpeLe6CBIcKsZadIWTntBqDhIgs38fnSwV7vX0sM z+Q5/lBPwRMHyLSpbYJKsGOyzqmZEwHa4JcK4/dig181l6ZFDv6OVZMNeNeLjj0Zg24S ZIMgad5CgCkQsDp6gj8h4yEVBkuxvLYEWy6worg21mo8iE9iFoB0ss0W9fHdxiWIh++D b4mTalgKWSZdjGiV8d61pfkFqVQoCWLgmE85aYlfTZxjwVK4rmCuooIHmEoth7LyW6Nd lZDrOkz6wNHKz3t+pl+Lj+ogc6PHtBd2P/cUDEQto36yVYnJRZ/m9IoFUs1qzl58ThBr Xd2g== X-Gm-Message-State: ABuFfohmRDGw8RW+0V2TirWKJZ4UUY4zi49elfVRzS5OrtZA++GGobAx ft0/BPAXkrNs5AKOsOlmIzSG7kDdtdlZ2x2XLLzkYbZy3SdiAPvMsuIDZ9+ptGARI2r2Xz3/5gE Av+4rIyxsyEYec5Y8jKoXSK+mrB0yh7AjCx3QbVKLHKD6mXoHmE7oK0mYupkYOhOPRw== X-Received: by 2002:a63:a119:: with SMTP id b25-v6mr32034936pgf.186.1539231283794; Wed, 10 Oct 2018 21:14:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV611zHyLbT8gdkwEFAJu7C9AYrOXICLdNRdAUDBVE2ukcNtozSAerQvx9uZJJurhXcyuaqG0 X-Received: by 2002:a63:a119:: with SMTP id b25-v6mr32034919pgf.186.1539231283053; Wed, 10 Oct 2018 21:14:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539231283; cv=none; d=google.com; s=arc-20160816; b=M+LyDBVyZBiXGfyhmsq05dhRvZiw4yL3scSZLSQwp0sCOJlkyGU+XFL4Wbj/EF5K+H +jgDvluaOGWH2wSK71FKITr7hpBUUfeznjUKDnQVNRwGg2fv6JmWM752JhXRs612KzQA VVFyvC6p29OMEHwubqiSGQ32/OVGuqj5LCKH4Q0A1wsi/gXALw4fkz2XkBBlTEDPMSfO mN8cAZ6AvFph8vfFy92MKYLxB/l44Jc3QlKWiTJhe9/EnQzfyKdtDm4w7r2ezICiKt2Z UWPB4IimS0qGSNsSMLr0troucWaiu/RKCZPXBitLFfTe9dAbkgaR8H5mt1eDuZiyWatj lMtw== 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=9Oy/QAfur+gc2YE69PqaCVfOP0qAmnW7K6awiLQrXfA=; b=dPxonadO9Ouqr4PNMlHDAIjxGaFDEizm81uPmw3HhrliOYyyIFGIyNEQETodHOZq9o wpNspHQzokZYVquYxhevFEl1Ifl6Dz/7soDTdD1+Z3rM1geukevIiMv5rFZqrYV7HXoD 4NJ60Z9d5vWjOvzWegNuqKYySKwRlAfMoHGZ39INWBuDcY2kgavQ/MRi0TwTAId1lXQ6 Ilo8r0WTonnz4UqBepfBuD3Qao/fhG7sI1FyNq5k19o3wzrl2iY4E+uhvxAvILXB5sPO fT74goD90O0Zwuq0EFLnHHaXVw9+6DohaMi1HED+cb2gs1DXchM2oUnfYQy+M/Rj0TK3 CKSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=tY1B9peQ; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2130.oracle.com (userp2130.oracle.com. [156.151.31.86]) by mx.google.com with ESMTPS id h1-v6si23212124pgs.493.2018.10.10.21.14.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 21:14:43 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) client-ip=156.151.31.86; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=tY1B9peQ; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 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 (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9B4EMt7039889; Thu, 11 Oct 2018 04:14:40 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=9Oy/QAfur+gc2YE69PqaCVfOP0qAmnW7K6awiLQrXfA=; b=tY1B9peQVMRogGaH1hofNx9pVnXzlmoAlr1e2PjJNUFT233d0dx649aDxbwo518aDv45 xpKRckn1VOw02g+SjcyB8TRgr8roiTglMglJXVUieXPGZ9lN+nKIvpFDRiT+bKbRFLTy zytVpYdiAuu6toXlN59H0STXxO78Yu0KNf6phYAiAq3zB0BZuOfTsIRFa2j90E92Pdvr 9THTd97zSxzGlRRJrClDFHZUT9y1d4cWGzY7guhmS0r/7d7ukEwFdh12e7JyGNpWF2C2 oxFOW0BmTIBRQxCtejDNQJsGIcgVSa/OygGpPedEOK8tK9Ueu+xL7g6HLykaEfqtFFBx ZQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2mxmfu1g48-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Oct 2018 04:14:40 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9B4EXXj007016 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Oct 2018 04:14:33 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9B4EXoG012323; Thu, 11 Oct 2018 04:14:33 GMT Received: from localhost (/10.159.132.249) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 11 Oct 2018 04:14:33 +0000 Subject: [PATCH 17/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, Amir Goldstein , 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: Wed, 10 Oct 2018 21:14:26 -0700 Message-ID: <153923126628.5546.3484461137192547927.stgit@magnolia> In-Reply-To: <153923113649.5546.9840926895953408273.stgit@magnolia> References: <153923113649.5546.9840926895953408273.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9042 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810110040 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 Reviewed-by: Amir Goldstein --- fs/read_write.c | 15 +++++++++------ include/linux/fs.h | 7 +++++-- mm/filemap.c | 16 ++++++++++++---- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 6ec908f9a69b..3713893b7e38 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; @@ -1804,16 +1805,18 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in, * If the user is attempting to remap a partial EOF block and * it's inside the destination EOF then reject it. * - * We don't support shortening requests, so we can only reject - * them. + * If possible, shorten the request instead of rejecting it. */ if (is_dedupe) ret = -EBADE; else if (pos_out + *len < i_size_read(inode_out)) ret = -EINVAL; - if (ret) - return ret; + if (ret) { + if (!(remap_flags & RFR_CAN_SHORTEN)) + return ret; + *len &= ~blkmask; + } } return 1; @@ -2112,7 +2115,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) deduped = vfs_dedupe_file_range_one(file, off, dst_file, info->dest_offset, len, - 0); + RFR_CAN_SHORTEN); if (deduped == -EBADE) info->status = FILE_DEDUPE_RANGE_DIFFERS; else if (deduped < 0) diff --git a/include/linux/fs.h b/include/linux/fs.h index b9c314f9d5a4..57cb56bbc30a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1726,14 +1726,17 @@ struct block_device_operations; * * RFR_SAME_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_SAME_DATA (1 << 0) #define RFR_TO_SRC_EOF (1 << 1) +#define RFR_CAN_SHORTEN (1 << 2) -#define RFR_VALID_FLAGS (RFR_SAME_DATA | RFR_TO_SRC_EOF) +#define RFR_VALID_FLAGS (RFR_SAME_DATA | RFR_TO_SRC_EOF | \ + RFR_CAN_SHORTEN) /* Implemented by the VFS, so these are advisory. */ -#define RFR_VFS_FLAGS (RFR_TO_SRC_EOF) +#define RFR_VFS_FLAGS (RFR_TO_SRC_EOF | RFR_CAN_SHORTEN) /* * Filesystem remapping implementations should call this helper on their diff --git a/mm/filemap.c b/mm/filemap.c index 369cfd164e90..bccbd3621238 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3051,8 +3051,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; } @@ -3063,10 +3067,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; }