From patchwork Wed Oct 10 00:14:52 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: 10633753 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 7BE3546E4 for ; Wed, 10 Oct 2018 00:14:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 69BA6284C9 for ; Wed, 10 Oct 2018 00:14:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D99228FA5; Wed, 10 Oct 2018 00:14:59 +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 C7BF028F95 for ; Wed, 10 Oct 2018 00:14:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 564A06B0294; Tue, 9 Oct 2018 20:14:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 512046B0296; Tue, 9 Oct 2018 20:14:57 -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 403246B0297; Tue, 9 Oct 2018 20:14:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by kanga.kvack.org (Postfix) with ESMTP id F21896B0294 for ; Tue, 9 Oct 2018 20:14:56 -0400 (EDT) Received: by mail-pf1-f199.google.com with SMTP id z12-v6so3208311pfl.17 for ; Tue, 09 Oct 2018 17:14:56 -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=f7AqhFJetFEwQ5b/c717/4+wkcz+RzMOOXOAxSGyAlM=; b=BI5FTX3PKMUkCx+EJqa12Lmrv74BC4tSKAttN2DD6+TSthNjChBsGyNULuh3SZ+MQk E+H5sEwHfe89Rkbpsvj72h0KqceQmerHA3k8mTk1E0oBRCQdWfco5/EX5reZQ3Q8CJ+l 2YjcO77oH4XsRRpx98Dier9wRA0V/aTGiNwmqY9/X1W0VxcWIaV08MgksOtWE/Mfa0P0 S6PTIeY3jsJcs9alZUDvhQp9q4iU34DITwv6neAejKI+DzeTYWLNN9sMynQ3x1qn09eR DJ52z66Dlc6E+O9H5o+NYJvVWPkd9FMZy+spICTjkt9/pci9Z1nJtGq29nqy8IgqL5me Hggw== X-Gm-Message-State: ABuFfoh29cPAI/Dvf5iTOQItlxoRDF/1S4AyKYbHfBBPxM3VfsT/MZKj K55Qr/pLFMYIDNHXQrmUt8fLNIo1GdW2cE0hHZL3elFzvtncXjvRilELvG5ri/4fnMjKo7OX/HW uh+bIZBmcTHgJADY3T1an4a115rXUIhVreGJIbJX08WasjzF+fkIHLLXTdXlvGYOVtQ== X-Received: by 2002:a62:6dc3:: with SMTP id i186-v6mr22128924pfc.218.1539130496602; Tue, 09 Oct 2018 17:14:56 -0700 (PDT) X-Google-Smtp-Source: ACcGV632SizcSAI7OSmOgw4MDYqyXs8o35acpg3udkeLnmt/KjpuXE08ES0clN3Bou9SZiZi9po+ X-Received: by 2002:a62:6dc3:: with SMTP id i186-v6mr22128874pfc.218.1539130495775; Tue, 09 Oct 2018 17:14:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539130495; cv=none; d=google.com; s=arc-20160816; b=Bo+0pmmeD13YSeIkFoTC1F1Dfzec10F3CHXOtYzOeai9CAouPeT055Ts1bDuxYwJqs Xk29cW8MI8ROaUTlFmt/SKEVX6gYKdLwkKS8//2+bf4uiY6n4nVNzpNQuY4X+m4dgDcE eUiZzUOeLXPWY4FzlaX3k6A6DSaviM9UmjfVBgZXlmewlZBr8K/p7dPC4GwYUabeglzc ErdNu+yLaagIFc9AasAzRl95AKssvPqsAY34oTbeFbTqWfv6jQ0HRxYXt7lMRWedgFYK 93L8mWgL+NA+ihxsC/A2AYKd3OPpEAro2hHscbUDwn7hSXLbTAMlSzZo71pvff2LUqEh o3RQ== 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=f7AqhFJetFEwQ5b/c717/4+wkcz+RzMOOXOAxSGyAlM=; b=Fn9HnH6IvTscdjZM8m1M+BH16o25b9BQmb13eaj6NOL/06242O0hAQdgmAe8GcooWR KLP9iCLo1ASpJtNL2HC+Be7lokoHRn+Ds7uIXDPK/zROIvornrncIbVYqIjPo9DP9u5e 1haXaL6fsSr05ePIiUGeZqxAhDe+cJoPDjj6fkPO3/1tEroHGqf4PqNLUskQUvFSx7iY FxvNp7CLXosdn80uYUqZARn+YZhtH9QT1ArAmjOoVB+rvhxTpU66AoK/KesKLhQ6ITzH iyN5aBRF7MMOhd/piqYoLrD8twlUNKi9w9jT2551peg+MDDAmCRvOrQojhrm3yDWjSM2 QQFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=mmHPzpKY; 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 k2-v6si20251131pgo.32.2018.10.09.17.14.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 17:14:55 -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=mmHPzpKY; 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 w9A0DfJi123123; Wed, 10 Oct 2018 00:14:55 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=f7AqhFJetFEwQ5b/c717/4+wkcz+RzMOOXOAxSGyAlM=; b=mmHPzpKYU83v7qFtgpn9PPGXpW31Tq8Rh0Iwnrz7fupE0p5gTJMjuM33co2UPCHgmbjr KmsWkiLB/g+nQyU+kurFux60elfgIc3CephqzQ4WfHdjueVRQKyCaXhnjsWZnz6Pf2HY mMTElm7hFNVlhH4cGyDYcK7Y22ZhJcAYDxAwShK9h2DDJN9jy4IxY14pC8rOcNgkEfFO 8i3TTw+mN19Bh4G8UUppaYPdby2vvyq0XAZPP1mnDwm9rFECBpNeytuAhF2Fnrjkr9tV 6HXjSJF0NRuUhPS3ePXe5yjtDFy27wr2/JWzJoDzbULV2yo9vgR5qivGnyTDwxUOUjX5 +w== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2mxmftrvua-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Oct 2018 00:14:55 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w9A0Es5e006907 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Oct 2018 00:14:54 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9A0ErHZ004470; Wed, 10 Oct 2018 00:14:53 GMT Received: from localhost (/10.159.249.114) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 10 Oct 2018 00:14:53 +0000 Subject: [PATCH 25/25] xfs: support returning partial reflink results 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:52 -0700 Message-ID: <153913049195.32295.13614911442275409372.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=882 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 Back when the XFS reflink code only supported clone_file_range, we were only able to return zero or negative error codes to userspace. However, now that copy_file_range (which returns bytes copied) can use XFS' clone_file_range, we have the opportunity to return partial results. For example, if userspace sends a 1GB clone request and we run out of space halfway through, we at least can tell userspace that we completed 512M of that request like a regular write. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 7 ++----- fs/xfs/xfs_reflink.c | 19 ++++++++++++++----- fs/xfs/xfs_reflink.h | 2 +- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 6f4205846451..a15057be1994 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -928,11 +928,8 @@ xfs_file_remap_range( loff_t len, unsigned int flags) { - int ret; - - ret = xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out, - len, false); - return ret < 0 ? ret : len; + return xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out, + len, flags); } STATIC int diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 0f4678920240..b33107a35330 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1123,6 +1123,7 @@ xfs_reflink_remap_blocks( struct xfs_inode *dest, xfs_fileoff_t destoff, xfs_filblks_t len, + xfs_filblks_t *remapped, xfs_off_t new_isize) { struct xfs_bmbt_irec imap; @@ -1130,6 +1131,7 @@ xfs_reflink_remap_blocks( int error = 0; xfs_filblks_t range_len; + *remapped = 0; /* drange = (destoff, destoff + len); srange = (srcoff, srcoff + len) */ while (len) { uint lock_mode; @@ -1168,6 +1170,7 @@ xfs_reflink_remap_blocks( srcoff += range_len; destoff += range_len; len -= range_len; + *remapped += range_len; } return 0; @@ -1349,7 +1352,7 @@ xfs_reflink_remap_prep( /* * Link a range of blocks from one file to another. */ -int +loff_t xfs_reflink_remap_range( struct file *file_in, loff_t pos_in, @@ -1364,9 +1367,9 @@ xfs_reflink_remap_range( struct xfs_inode *dest = XFS_I(inode_out); struct xfs_mount *mp = src->i_mount; xfs_fileoff_t sfsbno, dfsbno; - xfs_filblks_t fsblen; + xfs_filblks_t fsblen, remapped = 0; xfs_extlen_t cowextsize; - ssize_t ret; + int ret; if (!xfs_sb_version_hasreflink(&mp->m_sb)) return -EOPNOTSUPP; @@ -1382,11 +1385,17 @@ xfs_reflink_remap_range( trace_xfs_reflink_remap_range(src, pos_in, len, dest, pos_out); + if (len == 0) { + ret = 0; + goto out_unlock; + } + dfsbno = XFS_B_TO_FSBT(mp, pos_out); sfsbno = XFS_B_TO_FSBT(mp, pos_in); fsblen = XFS_B_TO_FSB(mp, len); ret = xfs_reflink_remap_blocks(src, sfsbno, dest, dfsbno, fsblen, - pos_out + len); + &remapped, pos_out + len); + remapped = min_t(int64_t, len, XFS_FSB_TO_B(mp, remapped)); if (ret) goto out_unlock; @@ -1409,7 +1418,7 @@ xfs_reflink_remap_range( xfs_reflink_remap_unlock(file_in, file_out); if (ret) trace_xfs_reflink_remap_range_error(dest, ret, _RET_IP_); - return ret; + return remapped > 0 ? remapped : ret; } /* diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h index c3c46c276fe1..cbc26ff79a8f 100644 --- a/fs/xfs/xfs_reflink.h +++ b/fs/xfs/xfs_reflink.h @@ -27,7 +27,7 @@ extern int xfs_reflink_cancel_cow_range(struct xfs_inode *ip, xfs_off_t offset, extern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset, xfs_off_t count); extern int xfs_reflink_recover_cow(struct xfs_mount *mp); -extern int xfs_reflink_remap_range(struct file *file_in, loff_t pos_in, +extern loff_t xfs_reflink_remap_range(struct file *file_in, loff_t pos_in, struct file *file_out, loff_t pos_out, loff_t len, unsigned int remap_flags); extern int xfs_reflink_inode_has_shared_extents(struct xfs_trans *tp,