From patchwork Thu Oct 11 16:05:28 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: 10636947 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 E82A5112B for ; Thu, 11 Oct 2018 16:05:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCCE02BAF4 for ; Thu, 11 Oct 2018 16:05:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DACC82BB0F; Thu, 11 Oct 2018 16:05:41 +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 4885F2BB1F for ; Thu, 11 Oct 2018 16:05:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 455916B027B; Thu, 11 Oct 2018 12:05:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 42C6E6B027C; Thu, 11 Oct 2018 12:05:40 -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 31BDD6B027D; Thu, 11 Oct 2018 12:05:40 -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 E80D26B027B for ; Thu, 11 Oct 2018 12:05:39 -0400 (EDT) Received: by mail-pf1-f197.google.com with SMTP id r67-v6so8408376pfd.21 for ; Thu, 11 Oct 2018 09:05:39 -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:date:from:to:cc:subject :message-id:references:mime-version:content-disposition:in-reply-to :user-agent; bh=gkVhvhJ2FlIJCkRLGBsRJI9E1SulUdIEyvkWVq3Hd8U=; b=al5+IOuxv2sCvk4kQK+m2Pos1Bihe40bG/Uj/pvKbNPEAPEOcrTlvi0YtkGvdJ/0FM BOQ/hSbzXa1GpbseRj0NWsFOXkI7m3hu04n8wDPtdG68YS+2X/YBdkN0WEZTD6W3S/xg PSanXmgmtXmL4bqjI5W0WfJJNF56KXPztdg2a5L8A4I/SJW7PyjH2ikhb+cOcQj6UJaF sRNSXug9SH4XJxGmjVoauZqhDwlOiVHjIk0AeXTZzBpRdjsZAG78jfqiHRj/CE7d53bv oaDIjZhmHHDHz/jbRG+ccTYq04jGymPVsT5NiPpbwlWOIEn71swGqBZj7pRGFuMflO+X HPjA== X-Gm-Message-State: ABuFfohjsi1PZ0fEl30P4SfGrO+2sB1WQL4+IwOMNpkzqa1HfH4/NsoS c+WE8C9QXj0KD4IMyRyC4vXMOAK1/698/C4sRPitvVur2hVr2HW2RwcBy7mKGnMcIURz+ImpocN alBCVec1+wlsTJJvaJ78cDw3t9QL3Lac1WVHxtVabwXyM6Xnnsjvq/C3e69fMTEEBwQ== X-Received: by 2002:a17:902:64c2:: with SMTP id y2-v6mr2134119pli.35.1539273939609; Thu, 11 Oct 2018 09:05:39 -0700 (PDT) X-Google-Smtp-Source: ACcGV62wsoJrBbtsO0WdUXJ1WCM5+RmSuz7b8w58Ud7MqYkBnOvorHRb7Lp10UwedDPrerRkJDKH X-Received: by 2002:a17:902:64c2:: with SMTP id y2-v6mr2134067pli.35.1539273938773; Thu, 11 Oct 2018 09:05:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539273938; cv=none; d=google.com; s=arc-20160816; b=Os7cuctvZjhMRcy9qn5ASGg3b629qVDJAb2qjUfdScf/gT4oo6exiIcIazaTGoyKEL n2lk9aLum4jZ9YZ2gbcKsldofy64NuTVvxGdO+gyg36vy/igaBThklwEbdMAb0eNwfaN kdumHsLbB0aBZHIB4AsqJ+LN/XVFYSFuvu/DpL6OnuWAkRhdGGMsvVqv8Uan5ae7grHQ lqdLKRdo/XUpIAcCXqSjA5MIedVv9v1lvM3kZXl76h1+ctmI4ZdjE0DLi6Lu+2XIi0mm QerNo93N6NCIRGn/BDTWoQZRNDkRjqa2/+A36t7pNaXk8QXeQwwH0K4eYwRZM7qXYUPS yb4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:dkim-signature; bh=gkVhvhJ2FlIJCkRLGBsRJI9E1SulUdIEyvkWVq3Hd8U=; b=hvlU85t7LeItubpOBLkgtph3uJLsJSVXkk/F9FI7ikcPTJCHUlEsr8vSD6X3vWDBJ+ p1Fn8tAa/0gr4hI65tgXBq7zNz5MLRLwFZuB/ZMYVMaihIfgiDt6QD8T2GvnMbPkCi8q Db5Hn0c4PYUARFZkSr6/tf+1S6aWxMrWauh/0KzTIyw/XKiUDpCI5GX4Arbg+pJjrJPk 8TEAAVmbdzy36fSLyuTC+4Tn05iaBQ+sl3/490PkIa3DAywxpAFkWUsUBAs5ZGiOXOMt OT1HQ/KUeK4VdQZnnWtmjJj8NCHZu3vv0nOHXwM18OlQzagA4H4dDJVdyH4SxAJuELCV wlNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=sRNvrp1H; 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 q1-v6si31427717pfb.258.2018.10.11.09.05.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 09:05:38 -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=sRNvrp1H; 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 w9BFwrwO100523; Thu, 11 Oct 2018 16:05:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=gkVhvhJ2FlIJCkRLGBsRJI9E1SulUdIEyvkWVq3Hd8U=; b=sRNvrp1HpIdINQ7BZZoj454zbx/vW2qogr4KaN8dRCWM5kQ6JAMEK9QYrEKfvFYVQdq2 N07FcRpeOjJF2DkOFLhazhZiopEcBPe0og7JMvzTBH6x5tT+8k/DUeyfhxXFr2kMjh8D gC7LePcPZFZ0xElMdN8XvfRenBAlEmH2T3gaa81H9H9SYiv5dDoaM3Ay3QDw5W1TEq+D 51ezOVZ/zb1Q5aCoDHy7rxEJm2AC8kzTOvyk9YZp6iqbEMZ4MzoVJ0KQLYpI5aX2S2K6 9j+E8ZbLmIFneUkV81d6kpztiY4yhCaR8Qtudzat8zfZniKMS6rErsnkyWEuJOgzilEv RA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2mxmfu5g1v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Oct 2018 16:05:36 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9BG5UQ3020141 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Oct 2018 16:05:31 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9BG5UrQ016472; Thu, 11 Oct 2018 16:05:30 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 11 Oct 2018 16:05:29 +0000 Date: Thu, 11 Oct 2018 09:05:28 -0700 From: "Darrick J. Wong" To: david@fromorbit.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 Subject: [PATCH v2 17/25] vfs: enable remap callers that can handle short operations Message-ID: <20181011160528.GB28243@magnolia> References: <153923113649.5546.9840926895953408273.stgit@magnolia> <153923126628.5546.3484461137192547927.stgit@magnolia> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <153923126628.5546.3484461137192547927.stgit@magnolia> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9042 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 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-1810110154 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.). We also enable CAN_SHORTEN for fideduperange to maintain existing userspace-visible behavior where xfs/btrfs shorten the dedupe range to avoid stale post-eof data exposure. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein --- v2: fix missing WARN_ON_ONCE and update changelog --- fs/read_write.c | 17 ++++++++++------- include/linux/fs.h | 7 +++++-- mm/filemap.c | 16 ++++++++++++---- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index 6ec908f9a69b..9d33f0a14720 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; @@ -2011,7 +2014,7 @@ loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, { loff_t ret; - WARN_ON_ONCE(remap_flags & ~(RFR_SAME_DATA)); + WARN_ON_ONCE(remap_flags & ~(RFR_SAME_DATA | RFR_CAN_SHORTEN)); ret = mnt_want_write_file(dst_file); if (ret) @@ -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; }