From patchwork Wed Oct 17 22:47:33 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: 10646515 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 2E4E3157A for ; Wed, 17 Oct 2018 22:47:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EC23288C7 for ; Wed, 17 Oct 2018 22:47:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 129C8288E4; Wed, 17 Oct 2018 22:47: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 6148C288C7 for ; Wed, 17 Oct 2018 22:47:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DCE36B0299; Wed, 17 Oct 2018 18:47:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 28D606B029B; Wed, 17 Oct 2018 18:47:38 -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 155AE6B029C; Wed, 17 Oct 2018 18:47:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) by kanga.kvack.org (Postfix) with ESMTP id DBFCF6B029B for ; Wed, 17 Oct 2018 18:47:37 -0400 (EDT) Received: by mail-yb1-f200.google.com with SMTP id h139-v6so15693470ybg.7 for ; Wed, 17 Oct 2018 15:47: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=16P3zwKvrT99XdZtAWDX1lXYkN0QjMaraaBIuWhVyNg=; b=jZ6FnlGsRO3DAWAnGFePlUMNnxu9lNkunHhpFEujyQPc2crVtlUvkH0V0syiPXCSy/ RrafWVguE30oIdJo1Uj4h8TX+4XPLannmsCQsJIj8xp+Zsy65tpcCsPTfq23O+sUTFKa m/9tm69RhgQtY4/Atabn69+1AmUCNc+mIn/1wlHqQSnuZCJidUSsiBoobTOOxUxK1Yg/ ojpPBjy0ak2UyRI0oWMzZpWqFm5NBpSQxcm8zmSa17f593b9wRbjKziLLfserN2l98dH s6BsVnwLaWS+efYYbFW1Ks9Orz+/Ehb+DeW8UujYnHFLiC5TbCA6BnspDc2VvlVBnEDy Jj/Q== X-Gm-Message-State: ABuFfoiZ99L/6gjYNkIpA89mv2jnsiIFL9LK72X/4sTgfWgkkruzvCMe CiKP32n/t+ozSbuMtph6X6X3Jq2z4gacSZvtmS/zqX3OFpEE1+0Kq5b3MBp3dA2xecnwHiFNqJy mV35fkWaB2Za4o14OBiICnwyG9eqT/lReSBvgvhTDR4pkC8MNBneweHjZMxySEWNDGw== X-Received: by 2002:a25:4c02:: with SMTP id z2-v6mr16755055yba.68.1539816457633; Wed, 17 Oct 2018 15:47:37 -0700 (PDT) X-Google-Smtp-Source: ACcGV62rJ7zSn4ocaCUIZ8dsbhCNt902nn5e7lQVpxIhRgTCUSFuX1TdmnntMGAma6kE5B0zU9x+ X-Received: by 2002:a25:4c02:: with SMTP id z2-v6mr16755026yba.68.1539816456765; Wed, 17 Oct 2018 15:47:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539816456; cv=none; d=google.com; s=arc-20160816; b=LwtPx5bEmadYvxwOybsGmAeDwqozwrIxqrGDs3pZtaZFlHlogqsDZSqze0Q4skbe15 VmCA4RxkC8KxAlHNe1B9McalHcBa386yJauIynw7kOMgcxaUN0qv4vQPNkVhb2t06pDR JJC7YhOXjCq6wA9gavP40sOkd2OQRrwdmsF75iBMqUmmVg8xhcl3RCL7NNRN2B+irITi GaBla4wk2FGQxaFj+/MqLGil1kq/Dq4aF3pmfKbRZvN4WOVfup/mV7maKMDWQL8w0lMv Ho+4pWCivs5RVguXNmLhoUFDz354falyn3Ch+NPgYKXw6DPzzePQWhcAO8F/MKr7r8m4 u85A== 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=16P3zwKvrT99XdZtAWDX1lXYkN0QjMaraaBIuWhVyNg=; b=f2TEwfxU8o1NtTMaPnbaa9wcfPafg1G2u8U6wn9fybpA68/2EuKP6cfriey4WhLt6v 6xaCTEYJYl0bL+JmkiAvqjIhZPNpVsxYRV+QTMJWyV3T+snicA/A1FyXeIWkfhdDOj21 cskbOk89kaBMj9xLxecoY7P2+bt2xOWFODgKsxPT+cxA+28me5mNNCXCjHTNUV1EK4ER uhudJ2B77q2KxPY6sx7CSHb60r+7mbqSIRu0E/ULndS14DbN0nD4KTgqAUDSuW0VCB5V pA78vG8zWgu3o9zTpTO5fG2Eru2I/O35ZSylo69HM+0dlK6hyvutW3/FhmMlgSiKJUrd mNIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=Uk+CdsWO; 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 t96-v6si6792796ybi.379.2018.10.17.15.47.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 15:47:36 -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=Uk+CdsWO; 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 w9HMiDGk048890; Wed, 17 Oct 2018 22:47: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=16P3zwKvrT99XdZtAWDX1lXYkN0QjMaraaBIuWhVyNg=; b=Uk+CdsWOnlx6Vq2OEDO5DJVNNoO7+FerZZx4hOqq3mXHpCDM41OBcQGETNpIhXvUcvap h9DKzUu94QoPg8n+jP9YlIufM3cFZsAz2AAVz9CsOEnPLb6GF9Xde/l1C0Fh1ktXTyon AkS6CAIpW7aX8mdJC3BoDtJ7HWyBNqrKrZNB7hRAEwmdhk7rLhqpMmq3KTN+OCS2aFqv 4HGp0CnLjO6/4wsmCc4BFaTF49dFJdeu8zWIqjHmdli27Xpn/GfT4+zmVOjffk6Iax3V qeGBAQtSvyj0Gvip04GhSv5NlPkcwp/44WsTQOKRVlCZJi3Z5eo2i9pV/KUKkV10ccR7 ZA== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2n38nq9t5c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Oct 2018 22:47:35 +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 w9HMlZrV009654 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Oct 2018 22:47:35 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9HMlZhk032721; Wed, 17 Oct 2018 22:47:35 GMT Received: from localhost (/10.159.132.177) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 17 Oct 2018 15:47:35 -0700 Subject: [PATCH 28/29] xfs: remove xfs_reflink_remap_range 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:33 -0700 Message-ID: <153981645357.5568.13554065440987931594.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=999 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 Since xfs_file_remap_range is a thin wrapper, move the contents of xfs_reflink_remap_range into the shell. This cuts down on the vfs calls being made from internal xfs code. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 65 ++++++++++++++++++++++++++++++++++++++++------ fs/xfs/xfs_reflink.c | 70 +++----------------------------------------------- fs/xfs/xfs_reflink.h | 10 +++++++ 3 files changed, 70 insertions(+), 75 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 7d42ab8fe6e1..53c9ab8fb777 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -919,20 +919,67 @@ xfs_file_fallocate( return error; } -STATIC loff_t + +loff_t xfs_file_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) + struct file *file_in, + loff_t pos_in, + struct file *file_out, + loff_t pos_out, + loff_t len, + unsigned int remap_flags) { + struct inode *inode_in = file_inode(file_in); + struct xfs_inode *src = XFS_I(inode_in); + 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; + int ret; + if (remap_flags & ~(REMAP_FILE_DEDUP | REMAP_FILE_ADVISORY)) return -EINVAL; - return xfs_reflink_remap_range(file_in, pos_in, file_out, pos_out, - len, remap_flags); + if (!xfs_sb_version_hasreflink(&mp->m_sb)) + return -EOPNOTSUPP; + + if (XFS_FORCED_SHUTDOWN(mp)) + return -EIO; + + /* Prepare and then clone file data. */ + ret = xfs_reflink_remap_prep(file_in, pos_in, file_out, pos_out, + &len, remap_flags); + if (ret < 0 || len == 0) + return ret; + + trace_xfs_reflink_remap_range(src, pos_in, len, dest, pos_out); + + ret = xfs_reflink_remap_blocks(src, pos_in, dest, pos_out, len, + &remapped); + if (ret) + goto out_unlock; + + /* + * Carry the cowextsize hint from src to dest if we're sharing the + * entire source file to the entire destination file, the source file + * has a cowextsize hint, and the destination file does not. + */ + cowextsize = 0; + if (pos_in == 0 && len == i_size_read(inode_in) && + (src->i_d.di_flags2 & XFS_DIFLAG2_COWEXTSIZE) && + pos_out == 0 && len >= i_size_read(inode_out) && + !(dest->i_d.di_flags2 & XFS_DIFLAG2_COWEXTSIZE)) + cowextsize = src->i_d.di_cowextsize; + + ret = xfs_reflink_update_dest(dest, pos_out + len, cowextsize, + remap_flags); + +out_unlock: + xfs_reflink_remap_unlock(file_in, file_out); + if (ret) + trace_xfs_reflink_remap_range_error(dest, ret, _RET_IP_); + return remapped > 0 ? remapped : ret; } STATIC int diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index bccc66316cc4..84f372f7ea04 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -916,7 +916,7 @@ xfs_reflink_set_inode_flag( /* * Update destination inode size & cowextsize hint, if necessary. */ -STATIC int +int xfs_reflink_update_dest( struct xfs_inode *dest, xfs_off_t newlen, @@ -1116,7 +1116,7 @@ xfs_reflink_remap_extent( /* * Iteratively remap one file's extents (and holes) to another's. */ -STATIC int +int xfs_reflink_remap_blocks( struct xfs_inode *src, loff_t pos_in, @@ -1232,7 +1232,7 @@ xfs_iolock_two_inodes_and_break_layout( } /* Unlock both inodes after they've been prepped for a range clone. */ -STATIC void +void xfs_reflink_remap_unlock( struct file *file_in, struct file *file_out) @@ -1300,7 +1300,7 @@ xfs_reflink_zero_posteof( * stale data in the destination file. Hence we reject these clone attempts with * -EINVAL in this case. */ -STATIC int +int xfs_reflink_remap_prep( struct file *file_in, loff_t pos_in, @@ -1370,68 +1370,6 @@ xfs_reflink_remap_prep( return ret; } -/* - * Link a range of blocks from one file to another. - */ -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) -{ - struct inode *inode_in = file_inode(file_in); - struct xfs_inode *src = XFS_I(inode_in); - 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; - int ret; - - if (!xfs_sb_version_hasreflink(&mp->m_sb)) - return -EOPNOTSUPP; - - if (XFS_FORCED_SHUTDOWN(mp)) - return -EIO; - - /* Prepare and then clone file data. */ - ret = xfs_reflink_remap_prep(file_in, pos_in, file_out, pos_out, - &len, remap_flags); - if (ret < 0 || len == 0) - return ret; - - trace_xfs_reflink_remap_range(src, pos_in, len, dest, pos_out); - - ret = xfs_reflink_remap_blocks(src, pos_in, dest, pos_out, len, - &remapped); - if (ret) - goto out_unlock; - - /* - * Carry the cowextsize hint from src to dest if we're sharing the - * entire source file to the entire destination file, the source file - * has a cowextsize hint, and the destination file does not. - */ - cowextsize = 0; - if (pos_in == 0 && len == i_size_read(inode_in) && - (src->i_d.di_flags2 & XFS_DIFLAG2_COWEXTSIZE) && - pos_out == 0 && len >= i_size_read(inode_out) && - !(dest->i_d.di_flags2 & XFS_DIFLAG2_COWEXTSIZE)) - cowextsize = src->i_d.di_cowextsize; - - ret = xfs_reflink_update_dest(dest, pos_out + len, cowextsize, - remap_flags); - -out_unlock: - xfs_reflink_remap_unlock(file_in, file_out); - if (ret) - trace_xfs_reflink_remap_range_error(dest, ret, _RET_IP_); - return remapped > 0 ? remapped : ret; -} - /* * The user wants to preemptively CoW all shared blocks in this file, * which enables us to turn off the reflink flag. Iterate all diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h index cbc26ff79a8f..28a84edda889 100644 --- a/fs/xfs/xfs_reflink.h +++ b/fs/xfs/xfs_reflink.h @@ -36,5 +36,15 @@ extern int xfs_reflink_clear_inode_flag(struct xfs_inode *ip, struct xfs_trans **tpp); extern int xfs_reflink_unshare(struct xfs_inode *ip, xfs_off_t offset, xfs_off_t len); +extern int xfs_reflink_remap_prep(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_remap_blocks(struct xfs_inode *src, loff_t pos_in, + struct xfs_inode *dest, loff_t pos_out, loff_t remap_len, + loff_t *remapped); +extern int xfs_reflink_update_dest(struct xfs_inode *dest, xfs_off_t newlen, + xfs_extlen_t cowextsize, unsigned int remap_flags); +extern void xfs_reflink_remap_unlock(struct file *file_in, + struct file *file_out); #endif /* __XFS_REFLINK_H */