From patchwork Thu Jan 18 07:42:39 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: 10172419 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 67574602DC for ; Thu, 18 Jan 2018 07:42:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 564B320501 for ; Thu, 18 Jan 2018 07:42:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B306205AF; Thu, 18 Jan 2018 07:42:45 +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 D949620501 for ; Thu, 18 Jan 2018 07:42:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753377AbeARHmo (ORCPT ); Thu, 18 Jan 2018 02:42:44 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:49694 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754736AbeARHmn (ORCPT ); Thu, 18 Jan 2018 02:42:43 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0I7fwTI075010; Thu, 18 Jan 2018 07:42:41 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=ysviATpcRiQ62lHJvpheccQXoue0Nj3Y6ikzaO5B9OI=; b=IUnZqNn2M2tMSOVKD0f3lDqNhwSLI9IhCDNr+mbW96M3fPNX/UCugFItjnT5RmIUGcXR 4vZ1xvn8juGHpedK9IUlsxvyG0VVdMkj10f3ftPSljogO9knrN18rve2B3U/NBIlEJuz jPaKh9luwiFC31gCGKUgT1Als/VG7EB/oIT5gHRn+11Yw5b8dzn6XqjBuOc7+v9IMlpW /NZKJggzG0Fa5DGHkOSRpOLmvdhuncShj1jfXfKvQR/UkSIqS4WkOBxUoinx9/H7qk2E UPRITtU3IIFKqm7nd3smWTl5YTnX+Hfr2rGqHkCCk4Ez/0SpOT/VhGuzC7bwwiZ/Vg+v dg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2fjq8ar15p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Jan 2018 07:42:41 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w0I7geal009944 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 18 Jan 2018 07:42:40 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w0I7gen6018198; Thu, 18 Jan 2018 07:42:40 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 17 Jan 2018 23:42:40 -0800 Subject: [PATCH 2/2] xfs: try to unshare extents before granting pnfs leases From: "Darrick J. Wong" To: hch@lst.de, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Wed, 17 Jan 2018 23:42:39 -0800 Message-ID: <151626135947.25794.13152244142083119314.stgit@magnolia> In-Reply-To: <151626134674.25794.7913544634631149739.stgit@magnolia> References: <151626134674.25794.7913544634631149739.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8777 signatures=668653 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=606 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801180111 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 Try to unshare an extent before granting a lease to pnfs; if this isn't possible, then bail out. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_pnfs.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) -- 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_pnfs.c b/fs/xfs/xfs_pnfs.c index aa6c5c1..a76140d 100644 --- a/fs/xfs/xfs_pnfs.c +++ b/fs/xfs/xfs_pnfs.c @@ -19,6 +19,7 @@ #include "xfs_shared.h" #include "xfs_bit.h" #include "xfs_pnfs.h" +#include "xfs_reflink.h" /* * Ensure that we do not have any outstanding pNFS layouts that can be used by @@ -110,13 +111,6 @@ xfs_fs_map_blocks( return -ENXIO; /* - * The pNFS block layout spec actually supports reflink like - * functionality, but the Linux pNFS server doesn't implement it yet. - */ - if (xfs_is_reflink_inode(ip)) - return -ENXIO; - - /* * Lock out any other I/O before we flush and invalidate the pagecache, * and then hand out a layout to the remote system. This is very * similar to direct I/O, except that the synchronization is much more @@ -125,6 +119,14 @@ xfs_fs_map_blocks( */ xfs_ilock(ip, XFS_IOLOCK_EXCL); + /* Try to unshare the blocks if we want write access */ + xfs_ilock(ip, XFS_MMAPLOCK_EXCL); + if (write) { + error = xfs_reflink_unshare(ip, offset, length); + if (error) + goto out_unlock; + } + error = -EINVAL; limit = mp->m_super->s_maxbytes; if (!write) @@ -140,7 +142,7 @@ xfs_fs_map_blocks( goto out_unlock; error = invalidate_inode_pages2(inode->i_mapping); if (WARN_ON_ONCE(error)) - return error; + goto out_unlock; end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + length); offset_fsb = XFS_B_TO_FSBT(mp, offset); @@ -176,18 +178,32 @@ xfs_fs_map_blocks( * present even after a server crash. */ flags |= XFS_PREALLOC_SET | XFS_PREALLOC_SYNC; + } else { + bool shared, trimmed; + + /* Make sure the extent really isn't shared. */ + error = xfs_reflink_trim_around_shared(ip, &imap, + &shared, &trimmed); + if (error) + goto out_unlock; + if (shared || trimmed) { + error = -ENXIO; + goto out_unlock; + } } error = xfs_update_prealloc_flags(ip, flags); if (error) goto out_unlock; } + xfs_iunlock(ip, XFS_MMAPLOCK_EXCL); xfs_iunlock(ip, XFS_IOLOCK_EXCL); xfs_bmbt_to_iomap(ip, iomap, &imap); *device_generation = mp->m_generation; return error; out_unlock: + xfs_iunlock(ip, XFS_MMAPLOCK_EXCL); xfs_iunlock(ip, XFS_IOLOCK_EXCL); return error; }