From patchwork Wed Jan 24 02:18:03 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: 10181257 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AF96E6037F for ; Wed, 24 Jan 2018 02:18:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F80C288A7 for ; Wed, 24 Jan 2018 02:18:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94535288AE; Wed, 24 Jan 2018 02:18:07 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A9C5288A7 for ; Wed, 24 Jan 2018 02:18:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752079AbeAXCSG (ORCPT ); Tue, 23 Jan 2018 21:18:06 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:46358 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751897AbeAXCSF (ORCPT ); Tue, 23 Jan 2018 21:18:05 -0500 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 w0O27GAH066399 for ; Wed, 24 Jan 2018 02: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-2017-10-26; bh=XB3R9FUZe2F6h3ih3HV5s9hyx5GVEVey5x8homwbDw0=; b=dVB4diLBwh8Ftzgqr7amGvbqZJZ/17kpfnFTDsrTdgQFCieEQFnqhaaK4EY2yF26qDZB FotxZ7ksIaE1cT7rkFLiEzdIFPawcEOMbGmzBJVxntgUzWvd3NlU+3gL7rzEotv5Q9C+ eEY3TSZGEzhpZKGU48Mn2u6H7ziwROMN5Ds655zdkrLboAb9CwccaOssnegOTvOggBTv 2xJ7lKQhSEpixUfQMooFew1O5iDEKpYk2hDHe95Cx/aP/ha1hMVcq3OjHC3IwnbLhM+z 7Yc9dlLz/oP9Yi/pJITWvTL0ghH5YQrl+3IWN6g7UeCmGJ32hBLT8+0GjCfVD7PVMkel tA== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2fpgyjg1ge-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 24 Jan 2018 02:18:05 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w0O2I5tP030001 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 24 Jan 2018 02:18:05 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w0O2I4Ra012150 for ; Wed, 24 Jan 2018 02:18:05 GMT Received: from localhost (/10.159.232.222) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 23 Jan 2018 18:18:04 -0800 Subject: [PATCH 01/11] xfs: reflink should break pnfs leases before sharing blocks From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Tue, 23 Jan 2018 18:18:03 -0800 Message-ID: <151676028366.12349.7219306586282315379.stgit@magnolia> In-Reply-To: <151676027743.12349.3845769501491774512.stgit@magnolia> References: <151676027743.12349.3845769501491774512.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8783 signatures=668655 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 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-1711220000 definitions=main-1801240023 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Before we share blocks between files, we need to break the pnfs leases on the layout before we start slicing and dicing the block map. Signed-off-by: Darrick J. Wong Reviewed-by: Brian Foster --- fs/xfs/xfs_reflink.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 47aea2e..f89a725 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -1245,6 +1245,50 @@ xfs_reflink_remap_blocks( } /* + * Grab the exclusive iolock for a data copy from src to dest, making + * sure to abide vfs locking order (lowest pointer value goes first) and + * breaking the pnfs layout leases on dest before proceeding. The loop + * is needed because we cannot call the blocking break_layout() with the + * src iolock held, and therefore have to back out both locks. + */ +static int +xfs_iolock_two_inodes_and_break_layout( + struct inode *src, + struct inode *dest) +{ + bool src_first = src < dest; + bool src_last = src > dest; + int error; + +retry: + if (src_first) { + inode_lock(src); + inode_lock_nested(dest, I_MUTEX_NONDIR2); + } else { + inode_lock(dest); + } + + error = break_layout(dest, false); + if (error == -EWOULDBLOCK) { + inode_unlock(dest); + if (src_first) + inode_unlock(src); + error = break_layout(dest, true); + if (error) + return error; + goto retry; + } else if (error) { + inode_unlock(dest); + if (src_first) + inode_unlock(src); + return error; + } + if (src_last) + inode_lock_nested(src, I_MUTEX_NONDIR2); + return 0; +} + +/* * Link a range of blocks from one file to another. */ int @@ -1274,7 +1318,9 @@ xfs_reflink_remap_range( return -EIO; /* Lock both files against IO */ - lock_two_nondirectories(inode_in, inode_out); + ret = xfs_iolock_two_inodes_and_break_layout(inode_in, inode_out); + if (ret) + return ret; if (same_inode) xfs_ilock(src, XFS_MMAPLOCK_EXCL); else