From patchwork Sun Oct 21 16:17:57 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: 10651239 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 71A5313A9 for ; Sun, 21 Oct 2018 16:18:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6017B287B7 for ; Sun, 21 Oct 2018 16:18:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54883287C6; Sun, 21 Oct 2018 16:18:09 +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 C36B5287B7 for ; Sun, 21 Oct 2018 16:18:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF2A86B0289; Sun, 21 Oct 2018 12:18:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AA0026B028B; Sun, 21 Oct 2018 12:18:07 -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 918B86B028C; Sun, 21 Oct 2018 12:18:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by kanga.kvack.org (Postfix) with ESMTP id 5BDE06B0289 for ; Sun, 21 Oct 2018 12:18:07 -0400 (EDT) Received: by mail-yb1-f197.google.com with SMTP id h10-v6so4627112ybc.14 for ; Sun, 21 Oct 2018 09:18:07 -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=nuKxOvx+akuLGnQJDI34Ie6h9sbCVLkKriw5Ben1sYDHN9I2kSt6lTWq+tytHbPtbG nAHOcvT/DYQt8FYhB2pGLCr/BS4JLAsS5/6TMkZ7swQjRgO7oOe3jGXDruI/cSfTqu8D 66n8lJl+nRu6mBvcD2Iv/WGFXokiQaUciip8sTZK0oZoyZ+TDLNzaNR22nrkQsKROmID KxfwSIT+WNUNzEIctSqdntzjKpo8E/m1YoCmQOmScdc24LtgB2e+wY7DTIlNxmwXVbp+ oYrMDWkTW9YR73fJhpnwDMdYq9PEoKsafAjL5Bhpj7y4hUAvi5RvQSg/cdNHchEY6o3b EnBg== X-Gm-Message-State: ABuFfoiwgyrAaYYa+QdS68m3O26EeDqTR9u/751HTA3yWpDS6U1B+bW0 JZ89VoSl28uQxXLOcednEtuNpeAmt8nI1HWfZFexUvkWEkjVkqXsGta/o5UZfDVug+ZKnG03XU5 OvIjmGjDPSyHixB8WrHHAxMvCSjR+4xNXO7Mt/yUCgBwYdYhRyk804wUkROoaskw/mQ== X-Received: by 2002:a81:39c5:: with SMTP id g188-v6mr29187587ywa.408.1540138687096; Sun, 21 Oct 2018 09:18:07 -0700 (PDT) X-Google-Smtp-Source: ACcGV60v9LgsAsuJE0MhsbEtucGv6CsCm47ijoSd0nrIfPM7PmBA+s2lkRioiyLnBxxT5paKOfQA X-Received: by 2002:a81:39c5:: with SMTP id g188-v6mr29187539ywa.408.1540138686378; Sun, 21 Oct 2018 09:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540138686; cv=none; d=google.com; s=arc-20160816; b=Xa9F4Haibf6CEa+3cC/EbLpLwkEy9W3FPQdzHFEkCIDUSmLPJ5kmMa/1YSXTF2SG4R PMAYBq8IR+QYbBDdfnIaGa5NsMm1cd5sa09p8kdGkHEEqNh6jtBPpliMPM9MPGTNddW/ Wbx1+eK/9DB7IE06/cbpQyXmd6tCDtmC8OzTmABwXb12/1OacWwkrv3p3JcBfcIoRNIm wov69zr+uJfx+DZY1z13eflPUaa/7QrgvZ1uhDREyyiupkgesgh9m9TzpcBDnCyJ4vCe lrm89xImunjExraP03ka+fZIdkugqOELfoyFTZZAqol1qp0vACZh3oC3wafEgJhWl271 K+OQ== 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=J+s2ZYrhYURpDQ3BxNFVBmipEbeS+tcJTV8FALOSjX6QNwYbKE2ALMnHnoAxtMyBF+ fhuUm9lJ1rCg0smM/BTJbWBtSyqtEXAoCsNfmFCfVIPqF8qI4tgd0s8To6o3E++X9Dxh /ws61ZtCLJOMWR3Oio9YSW+9PaakSYWgeZlJkzFU03oWJq8LJjmFxZ6E1356WJ8wp+eL 4jtvsjKk2OsYaRw+fGXpIGvGUe0rgjaenZhNhxPHK59lG5sMUpVXotpDjrDmVWRBou4e FhRWIV6S0JX9rreQOclrmKu7WV1hjQ1neVork2PjihloYW7tKZ9NHfAl73G5tARUzV2k xNog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=rFr3O4uU; 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 186-v6si9545696ybb.447.2018.10.21.09.18.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Oct 2018 09:18:06 -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=rFr3O4uU; 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 w9LGEMks155132; Sun, 21 Oct 2018 16:18:05 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=rFr3O4uUYl5F957T+le4lmrP2or8osZt8RblSUTrVCcXiX1cYVK10JKixDPDfftzv6lB Q6NokYaIYMmqRHrHxlL4RKVQP4kMCwTI4lOFemGVdb2pGN8mMVuVLxb6kDxkZy+3La2i 7OTI4cY7zI+oncaChJfyIzAmXaPIvMoR2WVXjUei134KgMeJd5PAAeF1zsqkiqVrZs0W 7tzB7WdOpc0NvpOCCYGdscvhHNb/JGoz7+AKF/LqAmO9LfcwP9ecprvMqsnzA9Y8p+Iy 9gfHJyUMGfcWZIH0QIR/+o0WItl8H9/RHep7/2IIAI7UHwNuCEZda8HuG+TEc4yiqSmj vA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2n7vapjysm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 21 Oct 2018 16:18:05 +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 w9LGHxPG007062 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 21 Oct 2018 16:17:59 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9LGHxSA024891; Sun, 21 Oct 2018 16:17:59 GMT Received: from localhost (/10.159.225.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 21 Oct 2018 09:17:58 -0700 Subject: [PATCH 25/28] 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: Sun, 21 Oct 2018 09:17:57 -0700 Message-ID: <154013867727.29026.14417615066515846065.stgit@magnolia> In-Reply-To: <154013850285.29026.16168387526580596209.stgit@magnolia> References: <154013850285.29026.16168387526580596209.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9053 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=856 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810210151 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 Reviewed-by: Dave Chinner --- 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,