From patchwork Fri Jul 6 03:12:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shan Hai X-Patchwork-Id: 10510535 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 CF09C6024A for ; Fri, 6 Jul 2018 03:12:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF65B20008 for ; Fri, 6 Jul 2018 03:12:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3C8A20134; Fri, 6 Jul 2018 03:12:48 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, 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 487C420008 for ; Fri, 6 Jul 2018 03:12:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753806AbeGFDMr (ORCPT ); Thu, 5 Jul 2018 23:12:47 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:40462 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753827AbeGFDMq (ORCPT ); Thu, 5 Jul 2018 23:12:46 -0400 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 w66390uc147520 for ; Fri, 6 Jul 2018 03:12:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=ogCVa+cFitWOJzOrG4jkWtfHMVha6OpavqzHo/v9Heo=; b=X10LeZ75blQLsMmG19A2E1QhVi4s/Zwhi/0YqoxzUrOs64HfY416W4oghZs5TYEIEDCk Y2qDx5Ez0Q9xZs4KLueUZUFEuVcn7V9aXLmQq5YyhJEnvuNPivkVKFB4YeV1MYTskRca L9iP3tt1Zu+FSQa9lvOpHWaJcxMq0eoaV4sel+JD9obmGTCqJ0XQqetRjKPECYimwVdH E8pJxi6mhCuVUqvJalP79Adz95pYX4DIxp691DQC3UPpCxs81mLVCH7LrmTQ/QtXS/EJ t9kqohE12SDTmwx/P0ywFpvTg7Yh5tU8M5vJfXz+75/5/S1nTNTet9dG3RyrMeBC+eJj FA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2k0dnjqym1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 06 Jul 2018 03:12:46 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w663CjRa006243 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 6 Jul 2018 03:12:45 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w663Cj7n017443 for ; Fri, 6 Jul 2018 03:12:45 GMT Received: from shai-ThinkPad-L460.cn.oracle.com (/10.182.70.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Jul 2018 20:12:44 -0700 From: Shan Hai To: linux-xfs@vger.kernel.org Subject: [PATCH RFC 2/8] xfs: introduce extents to local conversion helper Date: Fri, 6 Jul 2018 11:12:23 +0800 Message-Id: <1530846750-6686-3-git-send-email-shan.hai@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530846750-6686-1-git-send-email-shan.hai@oracle.com> References: <1530846750-6686-1-git-send-email-shan.hai@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8945 signatures=668704 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 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-1806210000 definitions=main-1807060032 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 Delete the extents from xfs inode, copy the data into the data fork, convert the inode from extents to local format and specify log the core and data fork of the inode. Signed-off-by: Shan Hai --- fs/xfs/libxfs/xfs_bmap.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++- fs/xfs/libxfs/xfs_bmap.h | 4 ++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 7205268b30bc..bea6dc254a7d 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) 2000-2006 Silicon Graphics, Inc. + * Copyright (c) 2018 Oracle. * All Rights Reserved. */ #include "xfs.h" @@ -213,7 +214,7 @@ xfs_default_attroffset( * attribute fork from local to extent format - we reset it where * possible to make space available for inline data fork extents. */ -STATIC void +void xfs_bmap_forkoff_reset( xfs_inode_t *ip, int whichfork) @@ -5141,6 +5142,63 @@ xfs_bmap_del_extent_real( } /* + * Convert an inode from extents to the local format. + * Free all the extents of the inode and reset it to the local + * format. Copy the contents of the inode's blocks to the inode's + * literal area. + */ +int +xfs_bmap_extents_to_local( + xfs_trans_t *tp, + xfs_inode_t *ip, + struct xfs_defer_ops *dfops, + int *logflagsp, + int whichfork, + struct page *page) +{ + xfs_ifork_t *ifp = XFS_IFORK_PTR(ip, whichfork); + xfs_fileoff_t isize = i_size_read(VFS_I(ip)); + struct xfs_bmbt_irec got, del; + struct xfs_iext_cursor icur; + int error = 0; + int tmp_logflags; + char *kaddr = NULL; + + ASSERT(whichfork != XFS_COW_FORK); + ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_EXTENTS); + + if (xfs_iext_count(ifp) == 0) + goto init_local_fork; + + for_each_xfs_iext(ifp, &icur, &got) { + del = got; + if (isnullstartblock(got.br_startblock)) { + error = xfs_bmap_del_extent_delay(ip, + whichfork, &icur, &got, &del); + if (error) + goto out; + } else { + error = xfs_bmap_del_extent_real(ip, tp, &icur, dfops, + NULL, &del, &tmp_logflags, whichfork, 0); + if (error) + goto out; + *logflagsp |= tmp_logflags; + } + } +init_local_fork: + kaddr = kmap_atomic(page); + xfs_init_local_fork(ip, whichfork, kaddr, isize); + kunmap_atomic(kaddr); + ip->i_d.di_format = XFS_DINODE_FMT_LOCAL; + XFS_IFORK_NEXT_SET(ip, whichfork, 0); + ip->i_d.di_size = isize; + *logflagsp |= (XFS_ILOG_DDATA | XFS_ILOG_CORE); +out: + return error; +} + + +/* * Unmap (remove) blocks from a file. * If nexts is nonzero then the number of extents to remove is limited to * that value. If not all extents in the block range can be removed then diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h index 9b49ddf99c41..22cd2642f1cd 100644 --- a/fs/xfs/libxfs/xfs_bmap.h +++ b/fs/xfs/libxfs/xfs_bmap.h @@ -271,6 +271,10 @@ int xfs_bmap_map_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops, struct xfs_inode *ip, struct xfs_bmbt_irec *imap); int xfs_bmap_unmap_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops, struct xfs_inode *ip, struct xfs_bmbt_irec *imap); +int xfs_bmap_extents_to_local(struct xfs_trans *tp, struct xfs_inode *ip, + struct xfs_defer_ops *dfops, int *flags, int whichfork, + struct page *page); +void xfs_bmap_forkoff_reset(struct xfs_inode *ip, int whichfork); static inline int xfs_bmap_fork_to_state(int whichfork) {