From patchwork Wed Oct 17 22:47:20 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: 10646487 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 CFFDB157A for ; Wed, 17 Oct 2018 22:47:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C19B9288CA for ; Wed, 17 Oct 2018 22:47:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B62C8288E7; Wed, 17 Oct 2018 22:47:26 +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 2FBAF288CA for ; Wed, 17 Oct 2018 22:47:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D15E6B0295; Wed, 17 Oct 2018 18:47:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 885CC6B0297; Wed, 17 Oct 2018 18:47:24 -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 6AF226B0298; Wed, 17 Oct 2018 18:47:24 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yw1-f72.google.com (mail-yw1-f72.google.com [209.85.161.72]) by kanga.kvack.org (Postfix) with ESMTP id 390336B0295 for ; Wed, 17 Oct 2018 18:47:24 -0400 (EDT) Received: by mail-yw1-f72.google.com with SMTP id b70-v6so17905945ywh.3 for ; Wed, 17 Oct 2018 15:47:24 -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=jBhmb/N7l//SEdkHcVUE3iIqA8iaNxSFon2zX2S1w8g=; b=m4+FdQzH1sUTbVcW3RctoNwjnrLdsjp7lf9Px+hnHpjUfU6SaL/PMWUVQDhnU/ww+o 9tlvaL7rX/FyzsVLRorQ8EtxnFvWFa/mbDLcAkktX9eSTk40jTWNNQEh7+Xk9QBvKRQk xfaPQdU/bg5QVw5rPjnk589wxPlanoDLJGuPGAcVg/dVYA2UZ4GMRf30uO+x1eGWzWZt s5wPdETgeEeP9vo7MYsOB+IpUwJAXerACSJIBKZAU57abYMZlPFE5zcw5YmO1j2/Ys7g FD45knTsE9DcrxJfwvHmOqMeYS6K0AMebKRtOHL8Z/yUa982x22LjUAJiJleEj3F5UnZ Ghlw== X-Gm-Message-State: ABuFfohpRtrYqBz0BH4QOcB7qo30Gv4h6Yjg1MjpQgkUeDAybjSFCCLk 8Ug97FiuKgA9fD4mVLXtDyGzTRGE/XpD7XNWfqutp8A6tdiMkbpwxwxp0x/IYXpJ0irc7OjWec4 5kgfjXL9ALjnkh5UdfLcV+Ex9fAwV/agWceHKmJLiJYKlRBW+uowPtCIyKh7b25M1MA== X-Received: by 2002:a25:e443:: with SMTP id b64-v6mr11717633ybh.396.1539816443940; Wed, 17 Oct 2018 15:47:23 -0700 (PDT) X-Google-Smtp-Source: ACcGV62Geocj4zpbReYcmna7pO4/O0wYORuZ9h4HOqBWcx3gj3OAzg0aelpBxImuj+CyQNqUfiY2 X-Received: by 2002:a25:e443:: with SMTP id b64-v6mr11717604ybh.396.1539816443222; Wed, 17 Oct 2018 15:47:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539816443; cv=none; d=google.com; s=arc-20160816; b=k9YICeeCDkTibSTJ8CuBear/shF4GSAlXBDQJ74x6wpJkSo6YtiSIImgCokxiCkl4Z 4OECe/7vAYYX23EREJ8H976leA4x5zGJugrZRx+TwJmz8JMBdbJr2Dxt+VEfmye6SLMy OZ7vQbo2thWxh7COl563Vhjnj3S1FYRhJ/jVQm1Yn2W7vSSctw11gDEd4H3+YKvtTi+P SCwMl5lOBGPfhwjke6hUTdkKazbL4xAq9K1sDYt5AJovBay6Yjkga7wAMmYKKqBc7lw9 12tkHgj50Bnd2c2KhDunJMaSZRxpBG/PRMwq6gw06yMZKMvkZrx4B+HPu3j5/Ebb3MtL JpMg== 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=jBhmb/N7l//SEdkHcVUE3iIqA8iaNxSFon2zX2S1w8g=; b=UqxoZlGRutXiluR88JDPyp3Hm53W/QwaEKSM0ns8tTfS955KXt0GaKaoGkEydcsiZ6 my/cFTHWPr8qR+PBsZCJyqopf32VaPceuy2o/rhWJb5D3cze4JfngWNXHIDtfyIJKgJo k9YMfLvZI295LNUiHoKjsa52A8hECjzlKdp3nQHDw0wcMeVkIv40ni5/2YfobNiPcTF2 aFqrLb6bSDFFjNaD187DmtnElfjJlS44PCwy8Zt6ckpktZpmBSHaSYeoQ3BOlIG/LgMF NkD1M4uRzQyFdDPmuoaFymWMS4AfBlXqk6z66abkmWuJP+lsKFGnG6DAtXqNshbz4hkl IInA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=wfwOTMXn; 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 w6-v6si7192458ywl.199.2018.10.17.15.47.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 15:47:23 -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=wfwOTMXn; 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 w9HMhlRu048467; Wed, 17 Oct 2018 22:47:22 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=jBhmb/N7l//SEdkHcVUE3iIqA8iaNxSFon2zX2S1w8g=; b=wfwOTMXn49H6rQz0BKn+Qzw8yNcqwuWtvlfuAAJvFbiwKBukNM/MR6Vw5fYGNEgWxqmT jS/FC2vlm34p8uvG7rXSW026I4ErIYQeDgB7jYJw+HtPdS4fQL25ys40TL5j3iBe4gax 4eRsseZqvqzfOn6A76nP20CFOhhVYyayVGesKMtQHlxM3enw11eTo6zNWZXxvmcy8jo3 8ZP9y89ZVzCj/QC6gbBeFnV81vc+bY0/zQg8Yqzhs7r3Sf7wZURzSZbsrEIJClF7ZF6v u3jHSwjFvAlFSB3G7kq9uaWJixVQ5EkRcuoDjafZa+hdeC2qxzUxI7L26kmU0Jx+lPHS Ng== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2n38nq9t4j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Oct 2018 22:47:22 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9HMlLmE008918 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Oct 2018 22:47:21 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9HMlLgW032583; Wed, 17 Oct 2018 22:47:21 GMT Received: from localhost (/10.159.132.177) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 17 Oct 2018 15:47:21 -0700 Subject: [PATCH 26/29] 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: Wed, 17 Oct 2018 15:47:20 -0700 Message-ID: <153981644001.5568.18043005268118852272.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=852 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 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 | 17 ++++++++++++----- fs/xfs/xfs_reflink.h | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 38fde4e11714..7d42ab8fe6e1 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_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) 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 79dec457f7fb..4abb2aea8f31 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1122,13 +1122,15 @@ xfs_reflink_remap_blocks( loff_t pos_in, struct xfs_inode *dest, loff_t pos_out, - loff_t remap_len) + loff_t remap_len, + loff_t *remapped) { struct xfs_bmbt_irec imap; xfs_fileoff_t srcoff; xfs_fileoff_t destoff; xfs_filblks_t len; xfs_filblks_t range_len; + xfs_filblks_t remapped_len = 0; xfs_off_t new_isize = pos_out + remap_len; int nimaps; int error = 0; @@ -1175,10 +1177,13 @@ xfs_reflink_remap_blocks( srcoff += range_len; destoff += range_len; len -= range_len; + remapped_len += range_len; } if (error) trace_xfs_reflink_remap_blocks_error(dest, error, _RET_IP_); + *remapped = min_t(loff_t, remap_len, + XFS_FSB_TO_B(src->i_mount, remapped_len)); return error; } @@ -1387,7 +1392,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, @@ -1401,8 +1406,9 @@ xfs_reflink_remap_range( struct inode *inode_out = file_inode(file_out); struct xfs_inode *dest = XFS_I(inode_out); struct xfs_mount *mp = src->i_mount; + loff_t remapped = 0; xfs_extlen_t cowextsize; - ssize_t ret; + int ret; if (!xfs_sb_version_hasreflink(&mp->m_sb)) return -EOPNOTSUPP; @@ -1418,7 +1424,8 @@ xfs_reflink_remap_range( trace_xfs_reflink_remap_range(src, pos_in, len, dest, pos_out); - ret = xfs_reflink_remap_blocks(src, pos_in, dest, pos_out, len); + ret = xfs_reflink_remap_blocks(src, pos_in, dest, pos_out, len, + &remapped); if (ret) goto out_unlock; @@ -1441,7 +1448,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,