From patchwork Wed Oct 17 22:46:12 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: 10646377 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 822DF157A for ; Wed, 17 Oct 2018 22:46:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7241F288C7 for ; Wed, 17 Oct 2018 22:46:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6668D288E4; Wed, 17 Oct 2018 22:46:20 +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 C87B7288C7 for ; Wed, 17 Oct 2018 22:46:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AA4D6B0286; Wed, 17 Oct 2018 18:46:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 85A196B0287; Wed, 17 Oct 2018 18:46:18 -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 724656B0288; Wed, 17 Oct 2018 18:46:18 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f71.google.com (mail-yw1-f71.google.com [209.85.161.71]) by kanga.kvack.org (Postfix) with ESMTP id 3E9376B0286 for ; Wed, 17 Oct 2018 18:46:18 -0400 (EDT) Received: by mail-yw1-f71.google.com with SMTP id h38-v6so17814341ywk.20 for ; Wed, 17 Oct 2018 15:46:18 -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=/+V3iC/KzQAzJs+XcKeeWtH75caGTwIlDYVj0kBbFn4=; b=iIhWQ9PBx5qvn5hVfzNNaCBE2Jo03tOV++ZOuIBgRS1D9LvIg6ZzfMZiv3DC3DW6xV tGDr4fH7SS6bXgmAaE4UFgxFE+yhM1+uWv05cCArR2TyLiMQWcEohTz3/3QPh7iYTMZG XNdw759CgwktEp3ZwZd1jfuxKPOzwv3RdO0UqLVAuVKE2Qa1a5F5WCUN95PbaxErWlj+ yv5/StEZbcqTanomO2WVz4EdN6+SjFE3h6qwYMnzFxW1o55VvLyfaZ4IzlRzfHTSzWex mGjG5YwXVYvy0EEnEGPwzGGhcjeUjGL3JvOFkN4HlcikETxvAlVQkWGxrMjO/yLj1mcS Tz3w== X-Gm-Message-State: ABuFfoinAEa4vGLGyDEdHskQICHdp9OEYQZrmjGOtF8Pv7kTPxTdvmbP 1A3+dQ0VFqVEwlzr7CR370vc7WzU50cNKY3KP7MpRVtcaD68kexK1uFfEC9kHhjlFkEeD9g8roU IgQAhdYAy6uKgvbl+dWOWmKsW7q278GYrCKPNjE6laMYahUYy1OtjTMJ22/C8bo2/xw== X-Received: by 2002:a0d:f0c1:: with SMTP id z184-v6mr16415481ywe.479.1539816377967; Wed, 17 Oct 2018 15:46:17 -0700 (PDT) X-Google-Smtp-Source: ACcGV61fyY2jelAwFuVS6QbC/0HGA3jPTC0g9Dc7/a+VY4I3PaA6LBJEZg9cvfxBKUfCB9RWS1+i X-Received: by 2002:a0d:f0c1:: with SMTP id z184-v6mr16415459ywe.479.1539816377182; Wed, 17 Oct 2018 15:46:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539816377; cv=none; d=google.com; s=arc-20160816; b=HPsq6RB/JgS8BfCqTEJyewfPozjy41cN408XtOOcs5l4sPy7NvQvG0z74vJyqpCNaF 4aBzoAqVTRX4Li4R97nrM8eUrOMa2PSoBFr+zLFTL/DjundcziemlHtQiZpcVj5VdyuB /PfgMGdzT77wAkUvaGj/hgxnCwNp7B/Zl+l40tRtB1aLxWEYJIhp+EeSgDY4LyvMVzQ6 9EUBddtd7NAaIfHWWpXL4PfjpRhsjqOaLNHIaYXedHgWbhX/822Bykq/VTwyaw9yWH5B JHj6L1u+WYJs22/FMw2pe2nG9+kMTXN7uuDBwXG7x+UfBnWGyVNmYjFzRg+p3rV02LNs c/KA== 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=/+V3iC/KzQAzJs+XcKeeWtH75caGTwIlDYVj0kBbFn4=; b=qdmdcEK8QyHVa7P3GnI4xFpUfCU5LyL480EFak9zMktUepzI3Z8pwxaXkyorgdJC/1 VP87vS1D3Okm5Okb9L5PDRSpF8MGVrVjFmZlDxJ0gEskEiCbI/Qj2Zq72TcF0zpMLyqx dlD7jQ6fmt+neDtYPg7U3TVZeOVZa7VbUeg2ywlC3I7q7glkx7QlLhEhwUBZHKqG5xYq UQD6w0UMUFdu48XxMmzGc35wYKTSzCv6I/IKorbAAttBaXVTlGBuKH69AQ7QRQXy4P+v Ap5uq6wotUwH5joWC49vLU/nw0rLZV0D7UHThVnDxPyUOXW8LGMoiq8Az2FccyDYbZNs r99g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=uoXJgQkl; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from aserp2120.oracle.com (aserp2120.oracle.com. [141.146.126.78]) by mx.google.com with ESMTPS id m6-v6si6678408yba.340.2018.10.17.15.46.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 15:46:17 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 as permitted sender) client-ip=141.146.126.78; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=uoXJgQkl; spf=pass (google.com: domain of darrick.wong@oracle.com designates 141.146.126.78 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 (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9HMhsPe048507; Wed, 17 Oct 2018 22:46:15 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=/+V3iC/KzQAzJs+XcKeeWtH75caGTwIlDYVj0kBbFn4=; b=uoXJgQkld0ERp2GU78syXOKb+ZPcIP88Z0GKImAICtHXkmu+mppw/hf0AwiP0UU3x+I4 V2TuzmmJ8tB9ku7NAADfX7X66+0nDrsnv3Q2YrPfKEOoOiAHTe2OD0aQgwj3sDoK+8yk lmneATPTJ5PhVqJO1FNgO314UjhweAjH7e1b9D6HTIpCm48OVH28EiLYpTa4HXK5k4I8 JSCqGzNj0NMJHvDeBgF5ENXqDYRSmQnAkfzq7Wu9jv1VJgm/ZLVRFWUeDMF0H/mA4d0e 1ALBw8lF6psym86LpSLwZnlwWHB1rJEWkjFhKMOx1jWAXrhSHQ0ONAlmYxvUn/voydoY Ww== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2n38nq9sxk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Oct 2018 22:46:15 +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 w9HMkEJD010683 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Oct 2018 22:46:15 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9HMkE6b031612; Wed, 17 Oct 2018 22:46:14 GMT Received: from localhost (/10.159.132.177) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 17 Oct 2018 15:46:13 -0700 Subject: [PATCH 16/29] 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, 17 Oct 2018 15:46:12 -0700 Message-ID: <153981637217.5568.7500888859511338974.stgit@magnolia> In-Reply-To: <153981625504.5568.2708520119290577378.stgit@magnolia> References: <153981625504.5568.2708520119290577378.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9049 signatures=668683 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-1810170188 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 --- fs/read_write.c | 28 ++++++++++++++++++++-------- include/linux/fs.h | 4 +++- mm/filemap.c | 11 +++++++---- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index ea30666013b0..c0bcc1a20650 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), + REMAP_FILE_CAN_SHORTEN); if (cloned > 0) { ret = cloned; goto done; @@ -1721,6 +1722,8 @@ static int remap_verify_area(struct file *file, loff_t pos, loff_t len, * can't meaningfully compare post-EOF contents. * * For clone we only link a partial EOF block above the destination file's EOF. + * + * Shorten the request if possible. */ static int generic_remap_check_len(struct inode *inode_in, struct inode *inode_out, @@ -1729,16 +1732,24 @@ static int generic_remap_check_len(struct inode *inode_in, unsigned int remap_flags) { u64 blkmask = i_blocksize(inode_in) - 1; + loff_t new_len = *len; if ((*len & blkmask) == 0) return 0; - if (remap_flags & REMAP_FILE_DEDUP) - *len &= ~blkmask; - else if (pos_out + *len < i_size_read(inode_out)) - return -EINVAL; + if ((remap_flags & REMAP_FILE_DEDUP) || + pos_out + *len < i_size_read(inode_out)) + new_len &= ~blkmask; - return 0; + if (new_len == *len) + return 0; + + if (remap_flags & REMAP_FILE_CAN_SHORTEN) { + *len = new_len; + return 0; + } + + return (remap_flags & REMAP_FILE_DEDUP) ? -EBADE : -EINVAL; } /* @@ -2014,7 +2025,8 @@ loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, { loff_t ret; - WARN_ON_ONCE(remap_flags & ~(REMAP_FILE_DEDUP)); + WARN_ON_ONCE(remap_flags & ~(REMAP_FILE_DEDUP | + REMAP_FILE_CAN_SHORTEN)); ret = mnt_want_write_file(dst_file); if (ret) @@ -2115,7 +2127,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); + REMAP_FILE_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 ea2c2f673ecb..0b750e3f8f20 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1726,14 +1726,16 @@ struct block_device_operations; * If it is called with len == 0 that means "remap to end of source file". * * REMAP_FILE_DEDUP: only remap if contents identical (i.e. deduplicate) + * REMAP_FILE_CAN_SHORTEN: caller can handle a shortened request */ #define REMAP_FILE_DEDUP (1 << 0) +#define REMAP_FILE_CAN_SHORTEN (1 << 1) /* * These flags should be taken care of by the implementation (possibly using * vfs helpers) but can be ignored by the implementation. */ -#define REMAP_FILE_ADVISORY (0) +#define REMAP_FILE_ADVISORY (REMAP_FILE_CAN_SHORTEN) struct iov_iter; diff --git a/mm/filemap.c b/mm/filemap.c index 1e93269efafe..0731869541ce 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3052,8 +3052,7 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, bcount = ALIGN(size_in, bs) - pos_in; } else { if (!IS_ALIGNED(count, bs)) - return -EINVAL; - + count = ALIGN_DOWN(count, bs); bcount = count; } @@ -3063,10 +3062,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 & REMAP_FILE_CAN_SHORTEN)) return -EINVAL; + *req_count = count; return 0; }