From patchwork Sat Oct 13 00:08:32 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: 10639723 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 D40951508 for ; Sat, 13 Oct 2018 00:08:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBC192B7F4 for ; Sat, 13 Oct 2018 00:08:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B00B12B877; Sat, 13 Oct 2018 00:08:40 +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 28F3A2B7F4 for ; Sat, 13 Oct 2018 00:08:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08E056B0290; Fri, 12 Oct 2018 20:08:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 03E476B0292; Fri, 12 Oct 2018 20:08:37 -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 DF4DA6B0293; Fri, 12 Oct 2018 20:08:37 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id A12C36B0290 for ; Fri, 12 Oct 2018 20:08:37 -0400 (EDT) Received: by mail-pf1-f200.google.com with SMTP id r72-v6so9473875pfj.3 for ; Fri, 12 Oct 2018 17:08:37 -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=j1f7F7pQmBhjlVszrIyTzR7x7TmBVWaeEtlT+nNj2qg=; b=A4Sz6CDYJYWnv+gLo9zb+CFV7PA2ei4gGJRPM2u5Adc1N9S7W4ATPEr4/d1NPmLq3o T6Van7UqF3yW7h0lpTYg7I+4E1HWA7sePaBsndJ4GwF8J4ZV6y8Vm1OQ66QyXCuUejnu EAdzpdpsd5WA0cKuMpbahPPoObfBpIQC+eZcSiOAxkbNwJHXnogiKxJ2aiDr9QgUr84Z NfMmAOrlxNGU+W8PWJ+UU9FFS9AbgvGUgurr6PEV+OKSeTOmZIR+TZmxc8hxuzbvwKaz uqd8WaFKjhlfVXTHCc2I6fs865VXF4vJ9Vcp6N07awpaYEvP0sy/FIG2eVNDxFxBS8Hb x8yA== X-Gm-Message-State: ABuFfohgsPLcvHBnHBjqdzCYXswILqMsVoS7zeGe+xtQcBFTgbhCN2Q2 /DYImW7VyMagSnfyrGTBQLr0DcyiWjxbLN2YvgGyCdHR9YL/7TaIfXh9ZTJ43Qi7zebtJqEpZof 2e4SCqYkvRQyoJOFa/VPHXwrSByFt+CZeWZEdm/z9jFCa/QLB7S3JzG9Qpqsne2ef+A== X-Received: by 2002:a62:2e02:: with SMTP id u2-v6mr8396579pfu.134.1539389317336; Fri, 12 Oct 2018 17:08:37 -0700 (PDT) X-Google-Smtp-Source: ACcGV63dSPw5EsIUJL7jVolfrl+HsfVLE5OMGy1Hi3rGLZotF6V8Da2cMurHgvHDl7lcHf3eAsA6 X-Received: by 2002:a62:2e02:: with SMTP id u2-v6mr8396499pfu.134.1539389315959; Fri, 12 Oct 2018 17:08:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539389315; cv=none; d=google.com; s=arc-20160816; b=hrL1XBAwzNLngRL5nt0CD2h3w2h3kvmbyECDJGmPGmM4VLAgnsysdbxYEIryb5tYRL 2vRksamEgaj5jN98mMv2E2FOHO7cNLvT+RGaxzA5QvXUV9Vey0fEgyr5Q05iLSZDNbR2 dnSgxdC0UXFgb2FK5ZbBICQOSq2jKXvu0CfC3a7pgCK8DUVRYDdwd/1N8NGWc9xexkl1 zyJYYyQ6IsSCARSW+aNoBOKcJVVrOHccn5Mqp9dWXYwC6rqX/7Lc4X/ERNqkm7gON+R1 O6ep8gs5Lt9wCKz2Tg80Xt4hBQ5kMJjmnUtwX5XgRnoLqzSe3yusMf8JfJF9gijvDL9B yPJg== 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=j1f7F7pQmBhjlVszrIyTzR7x7TmBVWaeEtlT+nNj2qg=; b=J2ICqUhk93kfRg7Y7c8JHUnQr3iYD4R43wZpH5rBrRtN/ncd5RhVcHqd9xEicE1WDD vCWRkvlv2NWZy3CLfe56uSVVFX7yisCsuEuf/oJfX6KP5uRACFo8UCT+isBv/+H+a3Sx +DIOoxT9g5zgG0EhYKI8yd8ToMz8pPVgv2o/PaOazG/Pc75CKgsGN9+uogUt02zU1s6Y vJ+d4Y+KvwwM5CT4l3Bu/XhBxY5Ck/zIrXhdjNMZMIBQ0M27noRIGkosQBy31lwz3lQ6 lxnI8B116NbiY2nq1y6o4QaFuAS7qOkAGNLEuFtuGfQcFeKfj11Yx6oeVVskKdEk74CJ y7dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=sTyoOz5D; 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 d7-v6si2465858plo.418.2018.10.12.17.08.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 17:08:35 -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=sTyoOz5D; 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 w9D03xtF104705; Sat, 13 Oct 2018 00:08:35 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=j1f7F7pQmBhjlVszrIyTzR7x7TmBVWaeEtlT+nNj2qg=; b=sTyoOz5DFRwE8hHpFLjJAntrQ/eP82020PpQF3A1xT0QhtpbxfK/IwemWapeHNbPqbdy w+MVAhh3wpTLfewOos41Q9+83VHaLYZCG31DaxtdczGPN4Y/YMNRLyUt0MOF1fCmdncq 5qO6QKeAXCyUcn1EROOqX1jMZfo6ljoKQDQ3W7ibgjgdjScKEku0Ns+WvDUWgQWme78J hJtToPlQ8RPOUsMR+dd8QKZ61bAPhsUqWtLuu1KCwfBusdMeW9tGD7idviFM45f+sE6C 6PG+J/VTGSv/31l3EV3lhLlQFzoV+Qcg5RPKXw719XP4Lqi9PQCgrG2n2ae4FMDDCQlT +A== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2mxnprnfnb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 13 Oct 2018 00:08:35 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9D08YjH027225 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 13 Oct 2018 00:08:34 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9D08YdJ020284; Sat, 13 Oct 2018 00:08:34 GMT Received: from localhost (/10.159.251.254) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 13 Oct 2018 00:08:33 +0000 Subject: [PATCH 24/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: Fri, 12 Oct 2018 17:08:32 -0700 Message-ID: <153938931226.8361.7365948775364411156.stgit@magnolia> In-Reply-To: <153938912912.8361.13446310416406388958.stgit@magnolia> References: <153938912912.8361.13446310416406388958.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9044 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=848 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810130000 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 | 5 +---- fs/xfs/xfs_reflink.c | 20 +++++++++++++++----- fs/xfs/xfs_reflink.h | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index bc9e94bcb7a3..b2b15b8dc4a1 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -928,14 +928,11 @@ xfs_file_remap_range( loff_t len, unsigned int remap_flags) { - int ret; - if (!remap_check_flags(remap_flags, RFR_SAME_DATA)) return -EINVAL; - ret = xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out, + return xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out, len, remap_flags); - return ret < 0 ? ret : len; } STATIC int diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index e1592e751cc2..66a8ddb9c058 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_len, 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_len = 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_len += range_len; } return 0; @@ -1391,7 +1394,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, @@ -1406,9 +1409,10 @@ 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, remappedfsb = 0; + loff_t remapped_bytes = 0; xfs_extlen_t cowextsize; - ssize_t ret; + int ret; if (!xfs_sb_version_hasreflink(&mp->m_sb)) return -EOPNOTSUPP; @@ -1424,11 +1428,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); + &remappedfsb, pos_out + len); + remapped_bytes = min_t(int64_t, len, XFS_FSB_TO_B(mp, remappedfsb)); if (ret) goto out_unlock; @@ -1451,7 +1461,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_bytes > 0 ? remapped_bytes : 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,