From patchwork Thu Oct 11 04:15:19 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: 10636029 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 BE3FB933 for ; Thu, 11 Oct 2018 04:15:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A35632787C for ; Thu, 11 Oct 2018 04:15:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 976B82A61E; Thu, 11 Oct 2018 04:15:32 +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 0E67A2A63B for ; Thu, 11 Oct 2018 04:15:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A0396B0299; Thu, 11 Oct 2018 00:15:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 04DB86B029B; Thu, 11 Oct 2018 00:15:30 -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 DE5236B029C; Thu, 11 Oct 2018 00:15:30 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by kanga.kvack.org (Postfix) with ESMTP id A9ADF6B0299 for ; Thu, 11 Oct 2018 00:15:30 -0400 (EDT) Received: by mail-qk1-f200.google.com with SMTP id d200-v6so6969350qkc.22 for ; Wed, 10 Oct 2018 21:15:30 -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=8E8puuvfkew1Gv1w0ptnyI/ykA53ICgvrrj5w/bTXjY=; b=PbdHpeeTXrCpIMj+CozYGVWjqVr+XkRFZh0wvp1ZldQhoUdyF5Bp0C2EDrId1ollFJ C/a13p14izZzSvx6O8SOK2tUC7IsFQAyMJBpZUfNKTkl2rsUktFinavRylFzl30m/brq xPs5I7N21y2ILIVswlR+zxS9v3wZM4gd3IR/copj7YehstBkbFaS3oRJ0jw8x+zMEj99 T24Ms8R8a+gjUArFQpK9VrToIGcoSE2aMsOni5afRzdS9jb4OFyKQJWc6xXmw2WDuv8y 6hK4BxLk8LJlzzberemlKC3Tdh0dsNIPh9BGVUpCY9gHTyxoyoD/CJ3hJHcfCaEo8aoj ywNg== X-Gm-Message-State: ABuFfoikL8JL99crXxvtofquH0DqnEGBaxyZVOLzEqueji7fDVoY+FRV 1pPH1rHpoTIVTtd2xpYhTgkCxcciIKa2cJKf0n/jJBcCrtAmT+S8UdHd5usLSDwYcHSCmEwGS3H uFE7CpGIHHc367aotUFjoivSC1xWMlxkas61Z1TCdZ5sNpuVGiP7LN0Ib1l9ePsN9ZQ== X-Received: by 2002:aed:3f08:: with SMTP id p8-v6mr29936633qtf.185.1539231330477; Wed, 10 Oct 2018 21:15:30 -0700 (PDT) X-Google-Smtp-Source: ACcGV60r8GFWIeAY57wLHA2QHhFTmJmTshc6a5Bsf0lHsZHw1vqCq8naI75qTpY10/EPaVHriA8s X-Received: by 2002:aed:3f08:: with SMTP id p8-v6mr29936594qtf.185.1539231329877; Wed, 10 Oct 2018 21:15:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539231329; cv=none; d=google.com; s=arc-20160816; b=F46NL5y94BC5tIhYU497tsB5HTNwVzM9BcoZd2+ZqpCsqx2k61QkUwAJ+NNsggC/hr 9maQ9QUX4fZQNh30DEk1SyrE5EceEcbSpuMXzVk7xb+geItuLict+0VmALXvkv3YC8JH fXM2/b0nbppPmnbpMMUErJMNDKqL0DYjGUFHmM5y+U48bNxYVc1KwY3VsqbwzDp1wDQY pPxhZCxrMc2nT4MH01NiWN+eWCnppYo7gjR/tME/VVqllI8CeMi4Yoa3t3SWY5kGmIga cWNaVeS4Jg6KAOZnK9TB9xzuUjLCjkUF2bPodtjhUJ9hAXMdNHuSdUQG0Dv1TnY8f957 J1DA== 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=8E8puuvfkew1Gv1w0ptnyI/ykA53ICgvrrj5w/bTXjY=; b=u0X1ojuBd+AE9YS+mGfPXGfF0RgAKc+x1TULDIhlgxvUEQpHTBp5D7gTmwaPbGgS00 waSVcGd9RGO8WWPRw3P3zakZd/feIkVNGFOVbLaNHizzdy82zXMoJxqK8qlXFaUjoMP7 EZHZvrsq1b63NJElIT4OfALWMBVutPijVWPhblWZOgr6tznP3NbMz7qv1HtjpDIE7wJj 9mh4nYcO5ft35G4JKJrD33FSCw1/uYXILxvXzf3ZIGNq7rcha/K7AXgFqgfUwpGMyEuT LiT+b8587f3i554i3MFgDqS8wvr61NPSD/bfY8Hpazv8C10oo4cE58rAspVXXkad4ZXw nGNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=KbyvslqU; 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 w198-v6si12864052qkb.168.2018.10.10.21.15.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 21:15:29 -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=KbyvslqU; 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 w9B4E1DO039425; Thu, 11 Oct 2018 04:15:28 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=8E8puuvfkew1Gv1w0ptnyI/ykA53ICgvrrj5w/bTXjY=; b=KbyvslqUqTtRk/Zf8mKvhGTL1xO3UwGmNlzmvzJnnPhtgy0I0s3/v1Fzf8kfxvTWGa7A Fx0q33hy3x98ufYU+cUIOoILdBN4SNqcHug2EEGz+N/kpzdU/9HaYYLObKPJXg1hLjLT Fy19D2S5wtCnHiNwtT9t3w/KA/w/SFz7PYY0MXWUA8Pr+HoKQU5xrmrlCRKaRid0LBpN GEIEeRgyhUzwntaeX2gGssynu74xKGP84xFcC2OzdPmbhsWg8EYVrXFBsVoxbA5XEbjb BdxCA8t+0cXlU64bg3cQf6ev+B18wzszcG24fkVkue2AUsuiOnLIH0YzIUxNbEENkEBP WA== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2mxmfu1g7v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Oct 2018 04:15:28 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9B4FMCV022731 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Oct 2018 04:15:22 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9B4FLdT011619; Thu, 11 Oct 2018 04:15:21 GMT Received: from localhost (/10.159.132.249) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 11 Oct 2018 04:15:21 +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: Wed, 10 Oct 2018 21:15:19 -0700 Message-ID: <153923131946.5546.5209673711907751253.stgit@magnolia> In-Reply-To: <153923113649.5546.9840926895953408273.stgit@magnolia> References: <153923113649.5546.9840926895953408273.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9042 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-1810110040 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 | 19 ++++++++++++++----- fs/xfs/xfs_reflink.h | 2 +- 3 files changed, 16 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..12a1fe92454e 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; @@ -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,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; @@ -1424,11 +1427,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; @@ -1451,7 +1460,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,