From patchwork Thu Aug 30 18:31:42 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: 10582533 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 4A77B139B for ; Thu, 30 Aug 2018 18:31:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 380162C3A3 for ; Thu, 30 Aug 2018 18:31:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BB5A2C3B9; Thu, 30 Aug 2018 18:31:49 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 196C32C3A3 for ; Thu, 30 Aug 2018 18:31:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728217AbeH3WfN (ORCPT ); Thu, 30 Aug 2018 18:35:13 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:55798 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeH3WfN (ORCPT ); Thu, 30 Aug 2018 18:35:13 -0400 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 w7UISspp180461 for ; Thu, 30 Aug 2018 18:31:44 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=TNX2nVylyavOUXOIzexaXr6mWDJ01UbVQAjYvODo5xs=; b=QFuXW91j1ANJzYGuB60CsqUcIdg6H08O+cLTg4v/pQr4VTEHE0QJ+q/Ffr3QUSUHocrR FjpunDG8DiP1vnvdQ8bWJ0QsmwrtgcOQnwe26/HodDo5F0AtBB8xv3RAWfGPepgjRWNq 2uSwdllNRjLgXXL/e3j/6kroNSlZaXKT0haFU/KpvN8fsVIAuP/9hE7qYGrdZTw+/jSJ NKTPVl3aeaKsKCseJkzUoOhPXVqEbTWP8h9D8knXg4X+GzG/5DmBBHyCF57b2R4FbhjX ge8LzSSUMtRqBputmNmx//LzxKTT6FKFozrEs4/p19idobHnn3Rrx5kd9IAPoPZtaesN Qg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2m2y2pxean-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:31:44 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIVhsF013735 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:31:43 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w7UIVhSJ019206 for ; Thu, 30 Aug 2018 18:31:43 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:31:43 -0700 Subject: [PATCH 01/18] xfs: make iroot_realloc a btree function From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:31:42 -0700 Message-ID: <153565390220.32612.11472362303041933747.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 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-1807170000 definitions=main-1808300185 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 For btrees that are rooted in the inode core, we have to have a function to resize the root. This is fairly specific to each btree type, so make xfs_iroot_realloc a per-btree function. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 6 +- fs/xfs/libxfs/xfs_bmap_btree.c | 137 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_bmap_btree.h | 2 + fs/xfs/libxfs/xfs_btree.c | 12 +--- fs/xfs/libxfs/xfs_btree.h | 7 ++ fs/xfs/libxfs/xfs_inode_fork.c | 130 -------------------------------------- fs/xfs/libxfs/xfs_inode_fork.h | 1 7 files changed, 153 insertions(+), 142 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 1580ac995690..f61a0afabd88 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -631,7 +631,7 @@ xfs_bmap_btree_to_extents( xfs_trans_binval(tp, cbp); if (cur->bc_bufs[0] == cbp) cur->bc_bufs[0] = NULL; - xfs_iroot_realloc(ip, -1, whichfork); + cur->bc_ops->iroot_realloc(cur, -1); ASSERT(ifp->if_broot == NULL); ASSERT((ifp->if_flags & XFS_IFBROOT) == 0); XFS_IFORK_FMT_SET(ip, whichfork, XFS_DINODE_FMT_EXTENTS); @@ -675,7 +675,7 @@ xfs_bmap_extents_to_btree( /* * Make space in the inode incore. */ - xfs_iroot_realloc(ip, 1, whichfork); + xfs_bmbt_iroot_realloc(ip, 1, whichfork); ifp->if_flags |= XFS_IFBROOT; /* @@ -778,7 +778,7 @@ xfs_bmap_extents_to_btree( err2: xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, -1L); err1: - xfs_iroot_realloc(ip, -1, whichfork); + cur->bc_ops->iroot_realloc(cur, -1); XFS_IFORK_FMT_SET(ip, whichfork, XFS_DINODE_FMT_EXTENTS); xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); diff --git a/fs/xfs/libxfs/xfs_bmap_btree.c b/fs/xfs/libxfs/xfs_bmap_btree.c index cdb74d2e2a43..4f7e566dd4bd 100644 --- a/fs/xfs/libxfs/xfs_bmap_btree.c +++ b/fs/xfs/libxfs/xfs_bmap_btree.c @@ -407,6 +407,142 @@ xfs_bmbt_diff_two_keys( be64_to_cpu(k2->bmbt.br_startoff); } +/* + * Reallocate the space for if_broot based on the number of records + * being added or deleted as indicated in rec_diff. Move the records + * and pointers in if_broot to fit the new size. When shrinking this + * will eliminate holes between the records and pointers created by + * the caller. When growing this will create holes to be filled in + * by the caller. + * + * The caller must not request to add more records than would fit in + * the on-disk inode root. If the if_broot is currently NULL, then + * if we are adding records, one will be allocated. The caller must also + * not request that the number of records go below zero, although + * it can go to zero. + * + * ip -- the inode whose if_broot area is changing + * ext_diff -- the change in the number of records, positive or negative, + * requested for the if_broot array. + */ +void +xfs_bmbt_iroot_realloc( + struct xfs_inode *ip, + int rec_diff, + int whichfork) +{ + struct xfs_mount *mp = ip->i_mount; + int cur_max; + struct xfs_ifork *ifp; + struct xfs_btree_block *new_broot; + int new_max; + size_t new_size; + char *np; + char *op; + + /* + * Handle the degenerate case quietly. + */ + if (rec_diff == 0) + return; + + ifp = XFS_IFORK_PTR(ip, whichfork); + if (rec_diff > 0) { + /* + * If there wasn't any memory allocated before, just + * allocate it now and get out. + */ + if (ifp->if_broot_bytes == 0) { + new_size = XFS_BMAP_BROOT_SPACE_CALC(mp, rec_diff); + ifp->if_broot = kmem_alloc(new_size, KM_SLEEP | KM_NOFS); + ifp->if_broot_bytes = (int)new_size; + return; + } + + /* + * If there is already an existing if_broot, then we need + * to realloc() it and shift the pointers to their new + * location. The records don't change location because + * they are kept butted up against the btree block header. + */ + cur_max = xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, 0); + new_max = cur_max + rec_diff; + new_size = XFS_BMAP_BROOT_SPACE_CALC(mp, new_max); + ifp->if_broot = kmem_realloc(ifp->if_broot, new_size, + KM_SLEEP | KM_NOFS); + op = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, ifp->if_broot, 1, + ifp->if_broot_bytes); + np = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, ifp->if_broot, 1, + (int)new_size); + ifp->if_broot_bytes = (int)new_size; + ASSERT(XFS_BMAP_BMDR_SPACE(ifp->if_broot) <= + XFS_IFORK_SIZE(ip, whichfork)); + memmove(np, op, cur_max * (uint)sizeof(xfs_fsblock_t)); + return; + } + + /* + * rec_diff is less than 0. In this case, we are shrinking the + * if_broot buffer. It must already exist. If we go to zero + * records, just get rid of the root and clear the status bit. + */ + ASSERT((ifp->if_broot != NULL) && (ifp->if_broot_bytes > 0)); + cur_max = xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, 0); + new_max = cur_max + rec_diff; + ASSERT(new_max >= 0); + if (new_max > 0) + new_size = XFS_BMAP_BROOT_SPACE_CALC(mp, new_max); + else + new_size = 0; + if (new_size > 0) { + new_broot = kmem_alloc(new_size, KM_SLEEP | KM_NOFS); + /* + * First copy over the btree block header. + */ + memcpy(new_broot, ifp->if_broot, + XFS_BMBT_BLOCK_LEN(ip->i_mount)); + } else { + new_broot = NULL; + ifp->if_flags &= ~XFS_IFBROOT; + } + + /* + * Only copy the records and pointers if there are any. + */ + if (new_max > 0) { + /* + * First copy the records. + */ + op = (char *)XFS_BMBT_REC_ADDR(mp, ifp->if_broot, 1); + np = (char *)XFS_BMBT_REC_ADDR(mp, new_broot, 1); + memcpy(np, op, new_max * (uint)sizeof(xfs_bmbt_rec_t)); + + /* + * Then copy the pointers. + */ + op = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, ifp->if_broot, 1, + ifp->if_broot_bytes); + np = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, new_broot, 1, + (int)new_size); + memcpy(np, op, new_max * (uint)sizeof(xfs_fsblock_t)); + } + kmem_free(ifp->if_broot); + ifp->if_broot = new_broot; + ifp->if_broot_bytes = (int)new_size; + if (ifp->if_broot) + ASSERT(XFS_BMAP_BMDR_SPACE(ifp->if_broot) <= + XFS_IFORK_SIZE(ip, whichfork)); +} + +STATIC void +__xfs_bmbt_iroot_realloc( + struct xfs_btree_cur *cur, + int rec_diff) +{ + return xfs_bmbt_iroot_realloc(cur->bc_private.b.ip, rec_diff, + cur->bc_private.b.whichfork); +} + static xfs_failaddr_t xfs_bmbt_verify( struct xfs_buf *bp) @@ -526,6 +662,7 @@ static const struct xfs_btree_ops xfs_bmbt_ops = { .key_diff = xfs_bmbt_key_diff, .diff_two_keys = xfs_bmbt_diff_two_keys, .buf_ops = &xfs_bmbt_buf_ops, + .iroot_realloc = __xfs_bmbt_iroot_realloc, .keys_inorder = xfs_bmbt_keys_inorder, .recs_inorder = xfs_bmbt_recs_inorder, }; diff --git a/fs/xfs/libxfs/xfs_bmap_btree.h b/fs/xfs/libxfs/xfs_bmap_btree.h index 29b407d053b4..ae347f4c4b60 100644 --- a/fs/xfs/libxfs/xfs_bmap_btree.h +++ b/fs/xfs/libxfs/xfs_bmap_btree.h @@ -108,5 +108,7 @@ extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *, extern unsigned long long xfs_bmbt_calc_size(struct xfs_mount *mp, unsigned long long len); +extern void xfs_bmbt_iroot_realloc(struct xfs_inode *ip, int rec_diff, + int whichfork); #endif /* __XFS_BMAP_BTREE_H__ */ diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index 34c6d7bd4d18..81b2fedefb95 100644 --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c @@ -3001,9 +3001,7 @@ xfs_btree_new_iroot( xfs_btree_copy_ptrs(cur, pp, &nptr, 1); - xfs_iroot_realloc(cur->bc_private.b.ip, - 1 - xfs_btree_get_numrecs(cblock), - cur->bc_private.b.whichfork); + cur->bc_ops->iroot_realloc(cur, 1 - xfs_btree_get_numrecs(cblock)); xfs_btree_setbuf(cur, level, cbp); @@ -3172,7 +3170,7 @@ xfs_btree_make_block_unfull( if (numrecs < cur->bc_ops->get_dmaxrecs(cur, level)) { /* A root block that can be made bigger. */ - xfs_iroot_realloc(ip, 1, cur->bc_private.b.whichfork); + cur->bc_ops->iroot_realloc(cur, 1); *stat = 1; } else { /* A root block that needs replacing */ @@ -3574,8 +3572,7 @@ xfs_btree_kill_iroot( index = numrecs - cur->bc_ops->get_maxrecs(cur, level); if (index) { - xfs_iroot_realloc(cur->bc_private.b.ip, index, - cur->bc_private.b.whichfork); + cur->bc_ops->iroot_realloc(cur, index); block = ifp->if_broot; } @@ -3772,8 +3769,7 @@ xfs_btree_delrec( */ if (level == cur->bc_nlevels - 1) { if (cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) { - xfs_iroot_realloc(cur->bc_private.b.ip, -1, - cur->bc_private.b.whichfork); + cur->bc_ops->iroot_realloc(cur, -1); error = xfs_btree_kill_iroot(cur); if (error) diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h index e3b3e9dce5da..59f3e42397fb 100644 --- a/fs/xfs/libxfs/xfs_btree.h +++ b/fs/xfs/libxfs/xfs_btree.h @@ -148,6 +148,13 @@ struct xfs_btree_ops { union xfs_btree_key *key1, union xfs_btree_key *key2); + /* + * Reallocate the space for if_broot based on the number of records + * being added or deleted as indicated in rec_diff. + */ + void (*iroot_realloc)(struct xfs_btree_cur *cur, + int rec_diff); + const struct xfs_buf_ops *buf_ops; /* check that k1 is lower than k2 */ diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index f9acf1d436f6..cfb68d4befc4 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -321,136 +321,6 @@ xfs_iformat_btree( return 0; } -/* - * Reallocate the space for if_broot based on the number of records - * being added or deleted as indicated in rec_diff. Move the records - * and pointers in if_broot to fit the new size. When shrinking this - * will eliminate holes between the records and pointers created by - * the caller. When growing this will create holes to be filled in - * by the caller. - * - * The caller must not request to add more records than would fit in - * the on-disk inode root. If the if_broot is currently NULL, then - * if we are adding records, one will be allocated. The caller must also - * not request that the number of records go below zero, although - * it can go to zero. - * - * ip -- the inode whose if_broot area is changing - * ext_diff -- the change in the number of records, positive or negative, - * requested for the if_broot array. - */ -void -xfs_iroot_realloc( - xfs_inode_t *ip, - int rec_diff, - int whichfork) -{ - struct xfs_mount *mp = ip->i_mount; - int cur_max; - struct xfs_ifork *ifp; - struct xfs_btree_block *new_broot; - int new_max; - size_t new_size; - char *np; - char *op; - - /* - * Handle the degenerate case quietly. - */ - if (rec_diff == 0) { - return; - } - - ifp = XFS_IFORK_PTR(ip, whichfork); - if (rec_diff > 0) { - /* - * If there wasn't any memory allocated before, just - * allocate it now and get out. - */ - if (ifp->if_broot_bytes == 0) { - new_size = XFS_BMAP_BROOT_SPACE_CALC(mp, rec_diff); - ifp->if_broot = kmem_alloc(new_size, KM_SLEEP | KM_NOFS); - ifp->if_broot_bytes = (int)new_size; - return; - } - - /* - * If there is already an existing if_broot, then we need - * to realloc() it and shift the pointers to their new - * location. The records don't change location because - * they are kept butted up against the btree block header. - */ - cur_max = xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, 0); - new_max = cur_max + rec_diff; - new_size = XFS_BMAP_BROOT_SPACE_CALC(mp, new_max); - ifp->if_broot = kmem_realloc(ifp->if_broot, new_size, - KM_SLEEP | KM_NOFS); - op = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, ifp->if_broot, 1, - ifp->if_broot_bytes); - np = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, ifp->if_broot, 1, - (int)new_size); - ifp->if_broot_bytes = (int)new_size; - ASSERT(XFS_BMAP_BMDR_SPACE(ifp->if_broot) <= - XFS_IFORK_SIZE(ip, whichfork)); - memmove(np, op, cur_max * (uint)sizeof(xfs_fsblock_t)); - return; - } - - /* - * rec_diff is less than 0. In this case, we are shrinking the - * if_broot buffer. It must already exist. If we go to zero - * records, just get rid of the root and clear the status bit. - */ - ASSERT((ifp->if_broot != NULL) && (ifp->if_broot_bytes > 0)); - cur_max = xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, 0); - new_max = cur_max + rec_diff; - ASSERT(new_max >= 0); - if (new_max > 0) - new_size = XFS_BMAP_BROOT_SPACE_CALC(mp, new_max); - else - new_size = 0; - if (new_size > 0) { - new_broot = kmem_alloc(new_size, KM_SLEEP | KM_NOFS); - /* - * First copy over the btree block header. - */ - memcpy(new_broot, ifp->if_broot, - XFS_BMBT_BLOCK_LEN(ip->i_mount)); - } else { - new_broot = NULL; - ifp->if_flags &= ~XFS_IFBROOT; - } - - /* - * Only copy the records and pointers if there are any. - */ - if (new_max > 0) { - /* - * First copy the records. - */ - op = (char *)XFS_BMBT_REC_ADDR(mp, ifp->if_broot, 1); - np = (char *)XFS_BMBT_REC_ADDR(mp, new_broot, 1); - memcpy(np, op, new_max * (uint)sizeof(xfs_bmbt_rec_t)); - - /* - * Then copy the pointers. - */ - op = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, ifp->if_broot, 1, - ifp->if_broot_bytes); - np = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, new_broot, 1, - (int)new_size); - memcpy(np, op, new_max * (uint)sizeof(xfs_fsblock_t)); - } - kmem_free(ifp->if_broot); - ifp->if_broot = new_broot; - ifp->if_broot_bytes = (int)new_size; - if (ifp->if_broot) - ASSERT(XFS_BMAP_BMDR_SPACE(ifp->if_broot) <= - XFS_IFORK_SIZE(ip, whichfork)); - return; -} - - /* * This is called when the amount of space needed for if_data * is increased or decreased. The change in size is indicated by diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h index 60361d2d74a1..8de3dc0fffb3 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.h +++ b/fs/xfs/libxfs/xfs_inode_fork.h @@ -94,7 +94,6 @@ void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *, struct xfs_inode_log_item *, int); void xfs_idestroy_fork(struct xfs_inode *, int); void xfs_idata_realloc(struct xfs_inode *, int, int); -void xfs_iroot_realloc(struct xfs_inode *, int, int); int xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int); int xfs_iextents_copy(struct xfs_inode *, struct xfs_bmbt_rec *, int); From patchwork Thu Aug 30 18:31:48 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: 10582535 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 31D2B17DB for ; Thu, 30 Aug 2018 18:31:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FC2A2C3A3 for ; Thu, 30 Aug 2018 18:31:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13D6F2C3B9; Thu, 30 Aug 2018 18:31:54 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 4CB6D2C3A3 for ; Thu, 30 Aug 2018 18:31:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728221AbeH3WfU (ORCPT ); Thu, 30 Aug 2018 18:35:20 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:58292 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeH3WfT (ORCPT ); Thu, 30 Aug 2018 18:35:19 -0400 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 w7UISkYm150419 for ; Thu, 30 Aug 2018 18:31:51 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=SMS1CImHeF7Dk2tHlJ6tWzD/6uVe95lPzrxULa5jwQU=; b=Kub4tyuM4BVdG0i8OQbMtnGSqv789HiLaQksqxwWa8YJpIFuZnT2jt2uER/xNqWA59Nw QZbKVvEfBSHkhAaQd3oc4/F5KLCFJppdn/sLQbUnKYrVREQ48eobsHLJZVC7e/AeQ+tZ pqqoXM/KlGVmvmOqFCKSZtEXki2luQB4Ugkja7KfymWINcuIuHReWOqJ6Pdr5qHiFLUu RNgDUlDxMQloiw9zp7hXMUzgi63u/iFe7CCNIUd7jm8dHSurLns7mcRoF7RgtfvOer2z CuXKU/jCWd0zOIdTSs70ryWMLaD6PuMiRzplwm6r99PKHUUnScV9HbpQ1HmVbO7aKX2A Eg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2m2xhu6evd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:31:50 +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 w7UIVobD019335 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:31:50 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIVoBn020233 for ; Thu, 30 Aug 2018 18:31:50 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:31:49 -0700 Subject: [PATCH 02/18] xfs: support storing records in the inode core root From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:31:48 -0700 Message-ID: <153565390854.32612.15669075123760228429.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 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-1807170000 definitions=main-1808300185 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 Make it so that we can actually store btree records in the inode core (i.e. enable bb_level == 0) so that the rtrmapbt can do this. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_btree.c | 196 ++++++++++++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_btree.h | 1 2 files changed, 148 insertions(+), 49 deletions(-) diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index 81b2fedefb95..4ac96c3ccb8b 100644 --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c @@ -192,6 +192,11 @@ xfs_btree_check_block( int level, /* level of the btree block */ struct xfs_buf *bp) /* buffer containing block, if any */ { + /* Don't check the inode-core root. */ + if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) && + level == cur->bc_nlevels - 1) + return 0; + if (cur->bc_flags & XFS_BTREE_LONG_PTRS) return xfs_btree_check_lblock(cur, block, level, bp); else @@ -1478,10 +1483,15 @@ xfs_btree_log_recs( int last) { - xfs_trans_buf_set_type(cur->bc_tp, bp, XFS_BLFT_BTREE_BUF); - xfs_trans_log_buf(cur->bc_tp, bp, - xfs_btree_rec_offset(cur, first), - xfs_btree_rec_offset(cur, last + 1) - 1); + if (bp) { + xfs_trans_buf_set_type(cur->bc_tp, bp, XFS_BLFT_BTREE_BUF); + xfs_trans_log_buf(cur->bc_tp, bp, + xfs_btree_rec_offset(cur, first), + xfs_btree_rec_offset(cur, last + 1) - 1); + } else { + xfs_trans_log_inode(cur->bc_tp, cur->bc_private.b.ip, + xfs_ilog_fbroot(cur->bc_private.b.whichfork)); + } } @@ -2935,8 +2945,11 @@ xfs_btree_new_iroot( struct xfs_btree_block *cblock; /* child btree block */ union xfs_btree_key *ckp; /* child key pointer */ union xfs_btree_ptr *cpp; /* child ptr pointer */ + union xfs_btree_rec *crp; union xfs_btree_key *kp; /* pointer to btree key */ union xfs_btree_ptr *pp; /* pointer to block addr */ + union xfs_btree_rec *rp; + union xfs_btree_ptr aptr; union xfs_btree_ptr nptr; /* new block addr */ int level; /* btree level */ int error; /* error return code */ @@ -2949,10 +2962,15 @@ xfs_btree_new_iroot( level = cur->bc_nlevels - 1; block = xfs_btree_get_iroot(cur); - pp = xfs_btree_ptr_addr(cur, 1, block); + ASSERT(level > 0 || (cur->bc_flags & XFS_BTREE_IROOT_RECORDS)); + if (level > 0) + aptr = *xfs_btree_ptr_addr(cur, 1, block); + else + aptr.l = cpu_to_be64(XFS_INO_TO_FSB(cur->bc_mp, + cur->bc_private.b.ip->i_ino)); /* Allocate the new block. If we can't do it, we're toast. Give up. */ - error = cur->bc_ops->alloc_block(cur, pp, &nptr, stat); + error = cur->bc_ops->alloc_block(cur, &aptr, &nptr, stat); if (error) goto error0; if (*stat == 0) @@ -2977,41 +2995,92 @@ xfs_btree_new_iroot( cblock->bb_u.s.bb_blkno = cpu_to_be64(cbp->b_bn); } - be16_add_cpu(&block->bb_level, 1); xfs_btree_set_numrecs(block, 1); cur->bc_nlevels++; cur->bc_ptrs[level + 1] = 1; - kp = xfs_btree_key_addr(cur, 1, block); - ckp = xfs_btree_key_addr(cur, 1, cblock); - xfs_btree_copy_keys(cur, ckp, kp, xfs_btree_get_numrecs(cblock)); + if (level > 0) { + /* + * We already incremented nlevels, so we have to do the + * same to bb_level or else pp will be calculated with the + * maxrecs for regular blocks and point at the wrong place. + */ + be16_add_cpu(&block->bb_level, 1); + + kp = xfs_btree_key_addr(cur, 1, block); + ckp = xfs_btree_key_addr(cur, 1, cblock); + xfs_btree_copy_keys(cur, ckp, kp, + xfs_btree_get_numrecs(cblock)); + + pp = xfs_btree_ptr_addr(cur, 1, block); + cpp = xfs_btree_ptr_addr(cur, 1, cblock); - cpp = xfs_btree_ptr_addr(cur, 1, cblock); - for (i = 0; i < be16_to_cpu(cblock->bb_numrecs); i++) { - error = xfs_btree_debug_check_ptr(cur, pp, i, level); + for (i = 0; i < be16_to_cpu(cblock->bb_numrecs); i++) { + error = xfs_btree_debug_check_ptr(cur, pp, i, level); + if (error) + goto error0; + } + + xfs_btree_copy_ptrs(cur, cpp, pp, + xfs_btree_get_numrecs(cblock)); + + error = xfs_btree_debug_check_ptr(cur, &nptr, 0, level); if (error) goto error0; - } - xfs_btree_copy_ptrs(cur, cpp, pp, xfs_btree_get_numrecs(cblock)); + xfs_btree_copy_ptrs(cur, pp, &nptr, 1); - error = xfs_btree_debug_check_ptr(cur, &nptr, 0, level); - if (error) - goto error0; + cur->bc_ops->iroot_realloc(cur, + 1 - xfs_btree_get_numrecs(cblock)); + block = xfs_btree_get_iroot(cur); + + xfs_btree_setbuf(cur, level, cbp); + + /* + * Do all this logging at the end so that + * the root is at the right level. + */ + xfs_btree_log_block(cur, cbp, XFS_BB_ALL_BITS); + xfs_btree_log_keys(cur, cbp, 1, + be16_to_cpu(cblock->bb_numrecs)); + xfs_btree_log_ptrs(cur, cbp, 1, + be16_to_cpu(cblock->bb_numrecs)); + } else { + rp = xfs_btree_rec_addr(cur, 1, block); + crp = xfs_btree_rec_addr(cur, 1, cblock); + xfs_btree_copy_recs(cur, crp, rp, + xfs_btree_get_numrecs(cblock)); - xfs_btree_copy_ptrs(cur, pp, &nptr, 1); + /* + * Trickery here: The amount of memory we need for the root + * changes when we convert a leaf to a node. Therefore, + * set the length to zero, increment the level, and set + * the length to 1 record. + */ + cur->bc_ops->iroot_realloc(cur, -xfs_btree_get_numrecs(cblock)); + block = xfs_btree_get_iroot(cur); + be16_add_cpu(&block->bb_level, 1); + cur->bc_ops->iroot_realloc(cur, 1); + block = xfs_btree_get_iroot(cur); - cur->bc_ops->iroot_realloc(cur, 1 - xfs_btree_get_numrecs(cblock)); + /* Copy pointer into the block. */ + xfs_btree_copy_ptrs(cur, xfs_btree_ptr_addr(cur, 1, block), + &nptr, 1); - xfs_btree_setbuf(cur, level, cbp); + xfs_btree_setbuf(cur, level, cbp); - /* - * Do all this logging at the end so that - * the root is at the right level. - */ - xfs_btree_log_block(cur, cbp, XFS_BB_ALL_BITS); - xfs_btree_log_keys(cur, cbp, 1, be16_to_cpu(cblock->bb_numrecs)); - xfs_btree_log_ptrs(cur, cbp, 1, be16_to_cpu(cblock->bb_numrecs)); + /* + * Do all this logging at the end so that + * the root is at the right level. + */ + xfs_btree_log_block(cur, cbp, XFS_BB_ALL_BITS); + xfs_btree_log_recs(cur, cbp, 1, + be16_to_cpu(cblock->bb_numrecs)); + + /* Write the new keys into the root block. */ + } + /* Get the keys for the new block and put them into the root. */ + xfs_btree_get_keys(cur, cblock, xfs_btree_key_addr(cur, 1, block)); *logflags |= XFS_ILOG_CORE | xfs_ilog_fbroot(cur->bc_private.b.whichfork); @@ -3513,15 +3582,15 @@ STATIC int xfs_btree_kill_iroot( struct xfs_btree_cur *cur) { - int whichfork = cur->bc_private.b.whichfork; struct xfs_inode *ip = cur->bc_private.b.ip; - struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); struct xfs_btree_block *block; struct xfs_btree_block *cblock; union xfs_btree_key *kp; union xfs_btree_key *ckp; union xfs_btree_ptr *pp; union xfs_btree_ptr *cpp; + union xfs_btree_rec *rp; + union xfs_btree_rec *crp; struct xfs_buf *cbp; int level; int index; @@ -3533,14 +3602,19 @@ xfs_btree_kill_iroot( int i; ASSERT(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE); - ASSERT(cur->bc_nlevels > 1); + ASSERT((cur->bc_flags & XFS_BTREE_IROOT_RECORDS) || + cur->bc_nlevels > 1); /* * Don't deal with the root block needs to be a leaf case. * We're just going to turn the thing back into extents anyway. */ level = cur->bc_nlevels - 1; - if (level == 1) + if (level == 1 && !(cur->bc_flags & XFS_BTREE_IROOT_RECORDS)) + goto out0; + + /* If we're already a leaf, jump out. */ + if (level == 0) goto out0; /* @@ -3571,35 +3645,59 @@ xfs_btree_kill_iroot( #endif index = numrecs - cur->bc_ops->get_maxrecs(cur, level); - if (index) { - cur->bc_ops->iroot_realloc(cur, index); - block = ifp->if_broot; - } - be16_add_cpu(&block->bb_numrecs, index); ASSERT(block->bb_numrecs == cblock->bb_numrecs); - kp = xfs_btree_key_addr(cur, 1, block); - ckp = xfs_btree_key_addr(cur, 1, cblock); - xfs_btree_copy_keys(cur, kp, ckp, numrecs); + if (be16_to_cpu(cblock->bb_level) > 0) { + if (index) { + cur->bc_ops->iroot_realloc(cur, index); + block = xfs_btree_get_iroot(cur); + } - pp = xfs_btree_ptr_addr(cur, 1, block); - cpp = xfs_btree_ptr_addr(cur, 1, cblock); + kp = xfs_btree_key_addr(cur, 1, block); + ckp = xfs_btree_key_addr(cur, 1, cblock); + xfs_btree_copy_keys(cur, kp, ckp, numrecs); - for (i = 0; i < numrecs; i++) { - error = xfs_btree_debug_check_ptr(cur, cpp, i, level - 1); - if (error) - return error; - } + pp = xfs_btree_ptr_addr(cur, 1, block); + cpp = xfs_btree_ptr_addr(cur, 1, cblock); - xfs_btree_copy_ptrs(cur, pp, cpp, numrecs); + for (i = 0; i < numrecs; i++) { + error = xfs_btree_debug_check_ptr(cur, cpp, i, level - 1); + if (error) + return error; + } + + xfs_btree_copy_ptrs(cur, pp, cpp, numrecs); + /* + * Decrement the (root) block's level after copying the + * pointers or else pp will be calculated using maxrecs + * for a regular block and won't point to the right place. + * Notice how we don't adjust nlevels until later. + */ + be16_add_cpu(&block->bb_level, -1); + } else { + /* + * Trickery here: The amount of memory we need for the root + * changes when we convert a leaf to a node. Therefore, + * set the length to zero, change the level, and set + * the length to however many records we're getting. + */ + cur->bc_ops->iroot_realloc(cur, -xfs_btree_get_numrecs(block)); + block = xfs_btree_get_iroot(cur); + be16_add_cpu(&block->bb_level, -1); + cur->bc_ops->iroot_realloc(cur, numrecs); + block = xfs_btree_get_iroot(cur); + + rp = xfs_btree_rec_addr(cur, 1, block); + crp = xfs_btree_rec_addr(cur, 1, cblock); + xfs_btree_copy_recs(cur, rp, crp, numrecs); + } error = xfs_btree_free_block(cur, cbp); if (error) return error; cur->bc_bufs[level - 1] = NULL; - be16_add_cpu(&block->bb_level, -1); xfs_trans_log_inode(cur->bc_tp, ip, XFS_ILOG_CORE | xfs_ilog_fbroot(cur->bc_private.b.whichfork)); cur->bc_nlevels--; diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h index 59f3e42397fb..d20e15d14ab2 100644 --- a/fs/xfs/libxfs/xfs_btree.h +++ b/fs/xfs/libxfs/xfs_btree.h @@ -236,6 +236,7 @@ typedef struct xfs_btree_cur #define XFS_BTREE_LASTREC_UPDATE (1<<2) /* track last rec externally */ #define XFS_BTREE_CRC_BLOCKS (1<<3) /* uses extended btree blocks */ #define XFS_BTREE_OVERLAPPING (1<<4) /* overlapping intervals */ +#define XFS_BTREE_IROOT_RECORDS (1<<5) /* iroot can store records */ #define XFS_BTREE_NOERROR 0 From patchwork Thu Aug 30 18:31:55 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: 10582539 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 6FEB917DB for ; Thu, 30 Aug 2018 18:32:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F8A42C39B for ; Thu, 30 Aug 2018 18:32:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 534612C3AF; Thu, 30 Aug 2018 18:32: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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 474932C39B for ; Thu, 30 Aug 2018 18:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727859AbeH3Wfc (ORCPT ); Thu, 30 Aug 2018 18:35:32 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:56502 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeH3Wfc (ORCPT ); Thu, 30 Aug 2018 18:35:32 -0400 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 w7UIScSo180307 for ; Thu, 30 Aug 2018 18:32:02 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=JWaZIbVORI74yVAOGW8zCHw+QVrX4nM8NBvQO6mFgxU=; b=yICt7EJZOIFu70yPyYK2Q1Kv7hMPVy8W8rphGo+7oscjUc05QLRjZWGEhrxyoFXeOoez p1b/TLwgFj4Q8/Z2ygqW/9NaZSp/0Du/40neZygW8uIlVV9FA5bLrnWjCP1K4pfpaxI+ xcA9qFzK8Nc+ecAGJwiB2sxMspTpGPt6bF6LONE96UFDtjJ+oILGk2DB3vgdov0uFM4v eEmRKaUe9dmCpK1H0SJ99Tr77thdsFZUij4iLloACzCh9/D51BviIzYDRDs6BjgPkptf 4GArCc2lX3fa3NDmROcmK5rOMpnAz0R0kxqbtbew2LYp9atfas72gdA9uCJYhyMxSDRZ hw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2m2y2pxebx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:02 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIVueu010067 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:31:56 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIVuAV012488 for ; Thu, 30 Aug 2018 18:31:56 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:31:56 -0700 Subject: [PATCH 03/18] xfs: widen xfs_rmap_irec fields to handle realtime rmapbt From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:31:55 -0700 Message-ID: <153565391508.32612.13805286023038790980.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 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-1807170000 definitions=main-1808300185 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 Change the startblock and blockcount fields of xfs_rmap_irec to be 64 bits wide. This enables us to use the same high level rmap code for either tree. We'll also collect all the resulting breakage fixes here. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_format.h | 4 +- fs/xfs/libxfs/xfs_refcount.c | 6 +-- fs/xfs/libxfs/xfs_rmap.c | 83 +++++++++++++++++++++--------------------- fs/xfs/libxfs/xfs_rmap.h | 36 +++++++++--------- fs/xfs/xfs_trace.h | 38 ++++++++++--------- 5 files changed, 83 insertions(+), 84 deletions(-) diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index d4ebf1a4f3e8..e837a8cde8af 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -1419,8 +1419,8 @@ struct xfs_rmap_rec { XFS_RMAP_BMBT_BLOCK) #define XFS_RMAP_REC_FLAGS (XFS_RMAP_UNWRITTEN) struct xfs_rmap_irec { - xfs_agblock_t rm_startblock; /* extent start block */ - xfs_extlen_t rm_blockcount; /* extent length */ + xfs_fsblock_t rm_startblock; /* extent start block */ + xfs_filblks_t rm_blockcount; /* extent length */ uint64_t rm_owner; /* extent owner */ uint64_t rm_offset; /* offset within the owner */ unsigned int rm_flags; /* state flags */ diff --git a/fs/xfs/libxfs/xfs_refcount.c b/fs/xfs/libxfs/xfs_refcount.c index 542aa1475b5f..198f0c96ccae 100644 --- a/fs/xfs/libxfs/xfs_refcount.c +++ b/fs/xfs/libxfs/xfs_refcount.c @@ -1560,8 +1560,7 @@ xfs_refcount_alloc_cow_extent( return error; /* Add rmap entry */ - return xfs_rmap_alloc_extent(tp, XFS_FSB_TO_AGNO(mp, fsb), - XFS_FSB_TO_AGBNO(mp, fsb), len, XFS_RMAP_OWN_COW); + return xfs_rmap_alloc_extent(tp, fsb, len, XFS_RMAP_OWN_COW); } /* Forget a CoW staging event in the refcount btree. */ @@ -1578,8 +1577,7 @@ xfs_refcount_free_cow_extent( return 0; /* Remove rmap entry */ - error = xfs_rmap_free_extent(tp, XFS_FSB_TO_AGNO(mp, fsb), - XFS_FSB_TO_AGBNO(mp, fsb), len, XFS_RMAP_OWN_COW); + error = xfs_rmap_free_extent(tp, fsb, len, XFS_RMAP_OWN_COW); if (error) return error; diff --git a/fs/xfs/libxfs/xfs_rmap.c b/fs/xfs/libxfs/xfs_rmap.c index 245af452840e..0372f77e019b 100644 --- a/fs/xfs/libxfs/xfs_rmap.c +++ b/fs/xfs/libxfs/xfs_rmap.c @@ -36,8 +36,8 @@ int xfs_rmap_lookup_le( struct xfs_btree_cur *cur, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, uint64_t owner, uint64_t offset, unsigned int flags, @@ -58,8 +58,8 @@ xfs_rmap_lookup_le( int xfs_rmap_lookup_eq( struct xfs_btree_cur *cur, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, uint64_t owner, uint64_t offset, unsigned int flags, @@ -105,8 +105,8 @@ xfs_rmap_update( int xfs_rmap_insert( struct xfs_btree_cur *rcur, - xfs_agblock_t agbno, - xfs_extlen_t len, + xfs_fsblock_t agbno, + xfs_filblks_t len, uint64_t owner, uint64_t offset, unsigned int flags) @@ -141,8 +141,8 @@ xfs_rmap_insert( STATIC int xfs_rmap_delete( struct xfs_btree_cur *rcur, - xfs_agblock_t agbno, - xfs_extlen_t len, + xfs_fsblock_t agbno, + xfs_filblks_t len, uint64_t owner, uint64_t offset, unsigned int flags) @@ -193,10 +193,13 @@ xfs_rmap_get_rec( int *stat) { struct xfs_mount *mp = cur->bc_mp; - xfs_agnumber_t agno = cur->bc_private.a.agno; + xfs_agnumber_t agno; union xfs_btree_rec *rec; int error; + if (cur->bc_btnum != XFS_BTNUM_RMAP) + goto out_bad_rec; + error = xfs_btree_get_rec(cur, &rec, stat); if (error || !*stat) return error; @@ -234,7 +237,7 @@ xfs_rmap_get_rec( "Reverse Mapping BTree record corruption in AG %d detected!", agno); xfs_warn(mp, - "Owner 0x%llx, flags 0x%x, start block 0x%x block count 0x%x", + "Owner 0x%llx, flags 0x%x, start block 0x%llx block count 0x%llx", irec->rm_owner, irec->rm_flags, irec->rm_startblock, irec->rm_blockcount); return -EFSCORRUPTED; @@ -280,7 +283,7 @@ xfs_rmap_find_left_neighbor_helper( int xfs_rmap_find_left_neighbor( struct xfs_btree_cur *cur, - xfs_agblock_t bno, + xfs_fsblock_t bno, uint64_t owner, uint64_t offset, unsigned int flags, @@ -358,7 +361,7 @@ xfs_rmap_lookup_le_range_helper( int xfs_rmap_lookup_le_range( struct xfs_btree_cur *cur, - xfs_agblock_t bno, + xfs_fsblock_t bno, uint64_t owner, uint64_t offset, unsigned int flags, @@ -459,8 +462,8 @@ xfs_rmap_free_check_owner( STATIC int xfs_rmap_unmap( struct xfs_btree_cur *cur, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, bool unwritten, struct xfs_owner_info *oinfo) { @@ -607,7 +610,7 @@ xfs_rmap_unmap( * Result: |rrrrr| |rrrr| * bno len */ - xfs_extlen_t orig_len = ltrec.rm_blockcount; + xfs_filblks_t orig_len = ltrec.rm_blockcount; ltrec.rm_blockcount = bno - ltrec.rm_startblock; error = xfs_rmap_update(cur, <rec); @@ -711,8 +714,8 @@ xfs_rmap_is_mergeable( STATIC int xfs_rmap_map( struct xfs_btree_cur *cur, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, bool unwritten, struct xfs_owner_info *oinfo) { @@ -930,8 +933,8 @@ xfs_rmap_alloc( STATIC int xfs_rmap_convert( struct xfs_btree_cur *cur, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, bool unwritten, struct xfs_owner_info *oinfo) { @@ -1355,8 +1358,8 @@ xfs_rmap_convert( STATIC int xfs_rmap_convert_shared( struct xfs_btree_cur *cur, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, bool unwritten, struct xfs_owner_info *oinfo) { @@ -1744,8 +1747,8 @@ xfs_rmap_convert_shared( STATIC int xfs_rmap_unmap_shared( struct xfs_btree_cur *cur, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, bool unwritten, struct xfs_owner_info *oinfo) { @@ -1862,7 +1865,7 @@ xfs_rmap_unmap_shared( * Result: |rrrrr| |rrrr| * bno len */ - xfs_extlen_t orig_len = ltrec.rm_blockcount; + xfs_filblks_t orig_len = ltrec.rm_blockcount; /* Shrink the left side of the rmap */ error = xfs_rmap_lookup_eq(cur, ltrec.rm_startblock, @@ -1906,8 +1909,8 @@ xfs_rmap_unmap_shared( STATIC int xfs_rmap_map_shared( struct xfs_btree_cur *cur, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, bool unwritten, struct xfs_owner_info *oinfo) { @@ -2174,7 +2177,7 @@ xfs_rmap_finish_one( int error = 0; xfs_agnumber_t agno; struct xfs_owner_info oinfo; - xfs_agblock_t bno; + xfs_fsblock_t bno; bool unwritten; agno = XFS_FSB_TO_AGNO(mp, startblock); @@ -2363,9 +2366,8 @@ xfs_rmap_convert_extent( int xfs_rmap_alloc_extent( struct xfs_trans *tp, - xfs_agnumber_t agno, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t fsbno, + xfs_filblks_t len, uint64_t owner) { struct xfs_bmbt_irec bmap; @@ -2373,7 +2375,7 @@ xfs_rmap_alloc_extent( if (!xfs_rmap_update_is_needed(tp->t_mountp, XFS_DATA_FORK)) return 0; - bmap.br_startblock = XFS_AGB_TO_FSB(tp->t_mountp, agno, bno); + bmap.br_startblock = fsbno; bmap.br_blockcount = len; bmap.br_startoff = 0; bmap.br_state = XFS_EXT_NORM; @@ -2385,9 +2387,8 @@ xfs_rmap_alloc_extent( int xfs_rmap_free_extent( struct xfs_trans *tp, - xfs_agnumber_t agno, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t fsbno, + xfs_filblks_t len, uint64_t owner) { struct xfs_bmbt_irec bmap; @@ -2395,7 +2396,7 @@ xfs_rmap_free_extent( if (!xfs_rmap_update_is_needed(tp->t_mountp, XFS_DATA_FORK)) return 0; - bmap.br_startblock = XFS_AGB_TO_FSB(tp->t_mountp, agno, bno); + bmap.br_startblock = fsbno; bmap.br_blockcount = len; bmap.br_startoff = 0; bmap.br_state = XFS_EXT_NORM; @@ -2435,8 +2436,8 @@ xfs_rmap_compare( int xfs_rmap_has_record( struct xfs_btree_cur *cur, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, bool *exists) { union xfs_btree_irec low; @@ -2460,8 +2461,8 @@ xfs_rmap_has_record( int xfs_rmap_record_exists( struct xfs_btree_cur *cur, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, struct xfs_owner_info *oinfo, bool *has_rmap) { @@ -2528,8 +2529,8 @@ xfs_rmap_has_other_keys_helper( int xfs_rmap_has_other_keys( struct xfs_btree_cur *cur, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, struct xfs_owner_info *oinfo, bool *has_rmap) { diff --git a/fs/xfs/libxfs/xfs_rmap.h b/fs/xfs/libxfs/xfs_rmap.h index 157dc722ad35..f92b59c6adda 100644 --- a/fs/xfs/libxfs/xfs_rmap.h +++ b/fs/xfs/libxfs/xfs_rmap.h @@ -142,14 +142,14 @@ int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp, xfs_agnumber_t agno, xfs_agblock_t bno, xfs_extlen_t len, struct xfs_owner_info *oinfo); -int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno, - xfs_extlen_t len, uint64_t owner, uint64_t offset, +int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_fsblock_t bno, + xfs_filblks_t len, uint64_t owner, uint64_t offset, unsigned int flags, int *stat); -int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno, - xfs_extlen_t len, uint64_t owner, uint64_t offset, +int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_fsblock_t bno, + xfs_filblks_t len, uint64_t owner, uint64_t offset, unsigned int flags, int *stat); -int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno, - xfs_extlen_t len, uint64_t owner, uint64_t offset, +int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_fsblock_t agbno, + xfs_filblks_t len, uint64_t owner, uint64_t offset, unsigned int flags); int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec, int *stat); @@ -192,10 +192,10 @@ int xfs_rmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip, int xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_trans *tp, struct xfs_inode *ip, int whichfork, struct xfs_bmbt_irec *imap); -int xfs_rmap_alloc_extent(struct xfs_trans *tp, xfs_agnumber_t agno, - xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner); -int xfs_rmap_free_extent(struct xfs_trans *tp, xfs_agnumber_t agno, - xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner); +int xfs_rmap_alloc_extent(struct xfs_trans *tp, xfs_fsblock_t fsbno, + xfs_filblks_t len, uint64_t owner); +int xfs_rmap_free_extent(struct xfs_trans *tp, xfs_fsblock_t fsbno, + xfs_filblks_t len, uint64_t owner); void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp, struct xfs_btree_cur *rcur, int error); @@ -204,10 +204,10 @@ int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type, xfs_fsblock_t startblock, xfs_filblks_t blockcount, xfs_exntst_t state, struct xfs_btree_cur **pcur); -int xfs_rmap_find_left_neighbor(struct xfs_btree_cur *cur, xfs_agblock_t bno, +int xfs_rmap_find_left_neighbor(struct xfs_btree_cur *cur, xfs_fsblock_t bno, uint64_t owner, uint64_t offset, unsigned int flags, struct xfs_rmap_irec *irec, int *stat); -int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno, +int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_fsblock_t bno, uint64_t owner, uint64_t offset, unsigned int flags, struct xfs_rmap_irec *irec, int *stat); int xfs_rmap_compare(const struct xfs_rmap_irec *a, @@ -215,13 +215,13 @@ int xfs_rmap_compare(const struct xfs_rmap_irec *a, union xfs_btree_rec; int xfs_rmap_btrec_to_irec(union xfs_btree_rec *rec, struct xfs_rmap_irec *irec); -int xfs_rmap_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno, - xfs_extlen_t len, bool *exists); -int xfs_rmap_record_exists(struct xfs_btree_cur *cur, xfs_agblock_t bno, - xfs_extlen_t len, struct xfs_owner_info *oinfo, +int xfs_rmap_has_record(struct xfs_btree_cur *cur, xfs_fsblock_t bno, + xfs_filblks_t len, bool *exists); +int xfs_rmap_record_exists(struct xfs_btree_cur *cur, xfs_fsblock_t bno, + xfs_filblks_t len, struct xfs_owner_info *oinfo, bool *has_rmap); -int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_agblock_t bno, - xfs_extlen_t len, struct xfs_owner_info *oinfo, +int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_fsblock_t bno, + xfs_filblks_t len, struct xfs_owner_info *oinfo, bool *has_rmap); int xfs_rmap_map_raw(struct xfs_btree_cur *cur, struct xfs_rmap_irec *rmap); diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h index d86f4e6a9cec..e87fa49ec2b7 100644 --- a/fs/xfs/xfs_trace.h +++ b/fs/xfs/xfs_trace.h @@ -2410,14 +2410,14 @@ DEFINE_BMAP_FREE_DEFERRED_EVENT(xfs_agfl_free_deferred); /* rmap tracepoints */ DECLARE_EVENT_CLASS(xfs_rmap_class, TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, - xfs_agblock_t agbno, xfs_extlen_t len, bool unwritten, + xfs_fsblock_t bno, xfs_filblks_t len, bool unwritten, struct xfs_owner_info *oinfo), - TP_ARGS(mp, agno, agbno, len, unwritten, oinfo), + TP_ARGS(mp, agno, bno, len, unwritten, oinfo), TP_STRUCT__entry( __field(dev_t, dev) __field(xfs_agnumber_t, agno) - __field(xfs_agblock_t, agbno) - __field(xfs_extlen_t, len) + __field(xfs_fsblock_t, bno) + __field(xfs_filblks_t, len) __field(uint64_t, owner) __field(uint64_t, offset) __field(unsigned long, flags) @@ -2425,7 +2425,7 @@ DECLARE_EVENT_CLASS(xfs_rmap_class, TP_fast_assign( __entry->dev = mp->m_super->s_dev; __entry->agno = agno; - __entry->agbno = agbno; + __entry->bno = bno; __entry->len = len; __entry->owner = oinfo->oi_owner; __entry->offset = oinfo->oi_offset; @@ -2433,10 +2433,10 @@ DECLARE_EVENT_CLASS(xfs_rmap_class, if (unwritten) __entry->flags |= XFS_RMAP_UNWRITTEN; ), - TP_printk("dev %d:%d agno %u agbno %u len %u owner %lld offset %llu flags 0x%lx", + TP_printk("dev %d:%d agno %d bno %llu len %llu owner %lld offset %llu flags 0x%lx", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->agno, - __entry->agbno, + __entry->bno, __entry->len, __entry->owner, __entry->offset, @@ -2445,9 +2445,9 @@ DECLARE_EVENT_CLASS(xfs_rmap_class, #define DEFINE_RMAP_EVENT(name) \ DEFINE_EVENT(xfs_rmap_class, name, \ TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, \ - xfs_agblock_t agbno, xfs_extlen_t len, bool unwritten, \ + xfs_fsblock_t bno, xfs_filblks_t len, bool unwritten, \ struct xfs_owner_info *oinfo), \ - TP_ARGS(mp, agno, agbno, len, unwritten, oinfo)) + TP_ARGS(mp, agno, bno, len, unwritten, oinfo)) /* simple AG-based error/%ip tracepoint class */ DECLARE_EVENT_CLASS(xfs_ag_error_class, @@ -2466,7 +2466,7 @@ DECLARE_EVENT_CLASS(xfs_ag_error_class, __entry->error = error; __entry->caller_ip = caller_ip; ), - TP_printk("dev %d:%d agno %u error %d caller %pS", + TP_printk("dev %d:%d agno %d error %d caller %pS", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->agno, __entry->error, @@ -2492,14 +2492,14 @@ DEFINE_AG_ERROR_EVENT(xfs_rmap_convert_state); DECLARE_EVENT_CLASS(xfs_rmapbt_class, TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, - xfs_agblock_t agbno, xfs_extlen_t len, + xfs_fsblock_t bno, xfs_filblks_t len, uint64_t owner, uint64_t offset, unsigned int flags), - TP_ARGS(mp, agno, agbno, len, owner, offset, flags), + TP_ARGS(mp, agno, bno, len, owner, offset, flags), TP_STRUCT__entry( __field(dev_t, dev) __field(xfs_agnumber_t, agno) - __field(xfs_agblock_t, agbno) - __field(xfs_extlen_t, len) + __field(xfs_fsblock_t, bno) + __field(xfs_filblks_t, len) __field(uint64_t, owner) __field(uint64_t, offset) __field(unsigned int, flags) @@ -2507,16 +2507,16 @@ DECLARE_EVENT_CLASS(xfs_rmapbt_class, TP_fast_assign( __entry->dev = mp->m_super->s_dev; __entry->agno = agno; - __entry->agbno = agbno; + __entry->bno = bno; __entry->len = len; __entry->owner = owner; __entry->offset = offset; __entry->flags = flags; ), - TP_printk("dev %d:%d agno %u agbno %u len %u owner %lld offset %llu flags 0x%x", + TP_printk("dev %d:%d agno %d bno %llu len %llu owner %lld offset %llu flags 0x%x", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->agno, - __entry->agbno, + __entry->bno, __entry->len, __entry->owner, __entry->offset, @@ -2525,9 +2525,9 @@ DECLARE_EVENT_CLASS(xfs_rmapbt_class, #define DEFINE_RMAPBT_EVENT(name) \ DEFINE_EVENT(xfs_rmapbt_class, name, \ TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, \ - xfs_agblock_t agbno, xfs_extlen_t len, \ + xfs_fsblock_t bno, xfs_filblks_t len, \ uint64_t owner, uint64_t offset, unsigned int flags), \ - TP_ARGS(mp, agno, agbno, len, owner, offset, flags)) + TP_ARGS(mp, agno, bno, len, owner, offset, flags)) #define DEFINE_RMAP_DEFERRED_EVENT DEFINE_MAP_EXTENT_DEFERRED_EVENT DEFINE_RMAP_DEFERRED_EVENT(xfs_rmap_defer); From patchwork Thu Aug 30 18:32:01 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: 10582537 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 2E879139B for ; Thu, 30 Aug 2018 18:32:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FC112C39B for ; Thu, 30 Aug 2018 18:32:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12E042C3AF; Thu, 30 Aug 2018 18:32:06 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 A6DBA2C39B for ; Thu, 30 Aug 2018 18:32:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728220AbeH3Wfc (ORCPT ); Thu, 30 Aug 2018 18:35:32 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:58594 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727859AbeH3Wfc (ORCPT ); Thu, 30 Aug 2018 18:35:32 -0400 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 w7UISek8150394 for ; Thu, 30 Aug 2018 18:32:03 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=sjIWMkEXv+mcpm7eSWan4vzZnaTce9QjiuDh8+z7m68=; b=RxZyfq7b9MRwbI6ozZvdtE6DzwotVivoDAELPF5pf3mnGSkM6w7ihZEB5ulN7uLXW233 q36W8ADoBaZxs3hv1vYOUd41rTcIzIhmCLW2XLueAoBQ3yOMjOn77i6708HtHjcEZWe0 kT08uof2hQLbKj/DdcgLz9Gr4o4kB8L0qiCq5OE4DwqeOD+TfunpnU+yyA+k/DnB3ea1 5rQFEMwcta/dEJ3hYaBZWjDKsFv6xHC4xX48sW66uGGfMLyihvObOagmWujE00PMKQq6 cPJJ5BlVGV0ctwwiRxdC1SrystYbTyR7JOerxvsWdpD6LlzugsPg0RnOQoq/vZr98vhM Uw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2m2xhu6ewv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:03 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIW26Y010788 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:03 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w7UIW2kR003416 for ; Thu, 30 Aug 2018 18:32:02 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:32:02 -0700 Subject: [PATCH 04/18] xfs: introduce realtime rmap btree definitions From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:32:01 -0700 Message-ID: <153565392140.32612.3102440697590597274.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=761 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808300185 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 Add new realtime rmap btree definitions. The realtime rmap btree will be rooted from a hidden inode, but has its own shape and therefore needs to have most of its own separate types. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_btree.c | 4 ++-- fs/xfs/libxfs/xfs_btree.h | 1 + fs/xfs/libxfs/xfs_format.h | 7 +++++++ fs/xfs/libxfs/xfs_types.h | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index 4ac96c3ccb8b..f77762777aa6 100644 --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c @@ -34,10 +34,10 @@ kmem_zone_t *xfs_btree_cur_zone; */ static const uint32_t xfs_magics[2][XFS_BTNUM_MAX] = { { XFS_ABTB_MAGIC, XFS_ABTC_MAGIC, 0, XFS_BMAP_MAGIC, XFS_IBT_MAGIC, - XFS_FIBT_MAGIC, 0 }, + XFS_FIBT_MAGIC, 0, 0 }, { XFS_ABTB_CRC_MAGIC, XFS_ABTC_CRC_MAGIC, XFS_RMAP_CRC_MAGIC, XFS_BMAP_CRC_MAGIC, XFS_IBT_CRC_MAGIC, XFS_FIBT_CRC_MAGIC, - XFS_REFC_CRC_MAGIC } + XFS_REFC_CRC_MAGIC, XFS_RTRMAP_CRC_MAGIC } }; uint32_t diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h index d20e15d14ab2..23806757dba2 100644 --- a/fs/xfs/libxfs/xfs_btree.h +++ b/fs/xfs/libxfs/xfs_btree.h @@ -62,6 +62,7 @@ union xfs_btree_rec { #define XFS_BTNUM_FINO ((xfs_btnum_t)XFS_BTNUM_FINOi) #define XFS_BTNUM_RMAP ((xfs_btnum_t)XFS_BTNUM_RMAPi) #define XFS_BTNUM_REFC ((xfs_btnum_t)XFS_BTNUM_REFCi) +#define XFS_BTNUM_RTRMAP ((xfs_btnum_t)XFS_BTNUM_RTRMAPi) uint32_t xfs_btree_magic(int crc, xfs_btnum_t btnum); diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index e837a8cde8af..6770dac9c82d 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -1445,6 +1445,13 @@ typedef __be32 xfs_rmap_ptr_t; XFS_FIBT_BLOCK(mp) + 1 : \ XFS_IBT_BLOCK(mp) + 1) +/* + * Realtime Reverse mapping btree format definitions + * + * There is a btree for the reverse map per allocation group + */ +#define XFS_RTRMAP_CRC_MAGIC 0x4d415052 /* 'MAPR' */ + /* * Reference Count Btree format definitions * diff --git a/fs/xfs/libxfs/xfs_types.h b/fs/xfs/libxfs/xfs_types.h index b9e6c89284c3..aacd52f44c56 100644 --- a/fs/xfs/libxfs/xfs_types.h +++ b/fs/xfs/libxfs/xfs_types.h @@ -106,7 +106,8 @@ typedef enum { typedef enum { XFS_BTNUM_BNOi, XFS_BTNUM_CNTi, XFS_BTNUM_RMAPi, XFS_BTNUM_BMAPi, - XFS_BTNUM_INOi, XFS_BTNUM_FINOi, XFS_BTNUM_REFCi, XFS_BTNUM_MAX + XFS_BTNUM_INOi, XFS_BTNUM_FINOi, XFS_BTNUM_REFCi, XFS_BTNUM_RTRMAPi, + XFS_BTNUM_MAX } xfs_btnum_t; struct xfs_name { From patchwork Thu Aug 30 18:32:07 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: 10582543 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 2D374139B for ; Thu, 30 Aug 2018 18:32:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A8AB2C39B for ; Thu, 30 Aug 2018 18:32:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09D7C2C3AF; Thu, 30 Aug 2018 18:32:20 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 EFC1B2C39B for ; Thu, 30 Aug 2018 18:32:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727088AbeH3Wfp (ORCPT ); Thu, 30 Aug 2018 18:35:45 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:49428 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeH3Wfp (ORCPT ); Thu, 30 Aug 2018 18:35:45 -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 w7UISd1v133713 for ; Thu, 30 Aug 2018 18:32:15 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=26bAGkT1kc75dRwxQVNOSKv5BYlQaSPWOfxubbofrSY=; b=uU2h4dhsIgak+dprOfdSSUgJf/NTbC/pxjZLo5tiLa7Lvxkwl8Ea1HPCo+/rcqTmuOAf YLIQbzuFnPmybbKo0F/7ouVWPIPP/4LOLha2iLRLI0s3J0yAag6gHfs4vgF4N7aPe8jx i2KvL0dEzdrcVXk4dH8APHIyCtc4AhNvH8kcaruU5EIc5Z4v3Szx70QaMqoF9EClYQEz kWE6Slo0qGKkoQC0WkjVhRVGSP5fNofYZxGz6gzPzmT1d5ef85/Ao6VucR8W9e0vNw8F JX4yDvGT4RCMtzDNovhJG1JmqAeE6iVWl75BW2UVvzHcV11fE+rPjMHlwHlNsQGiiCVN cg== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2m2yrqpatx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:14 +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 w7UIW8Yd021166 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:09 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIW8n6020367 for ; Thu, 30 Aug 2018 18:32:08 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:32:08 -0700 Subject: [PATCH 05/18] xfs: define the on-disk realtime rmap btree format From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:32:07 -0700 Message-ID: <153565392761.32612.8546890664401019458.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 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-1807170000 definitions=main-1808300185 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 Start filling out the rtrmap btree implementation. Start with the on-disk btree format; add everything needed to read, write and manipulate rmap btree blocks. This prepares the way for connecting the btree operations implementation. Signed-off-by: Darrick J. Wong --- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_btree.c | 1 fs/xfs/libxfs/xfs_btree.h | 3 + fs/xfs/libxfs/xfs_format.h | 48 ++++++++++ fs/xfs/libxfs/xfs_rmap.c | 21 ++++ fs/xfs/libxfs/xfs_rtrmap_btree.c | 184 ++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtrmap_btree.h | 48 ++++++++++ fs/xfs/libxfs/xfs_sb.c | 6 + fs/xfs/libxfs/xfs_shared.h | 1 fs/xfs/xfs_mount.c | 2 fs/xfs/xfs_mount.h | 3 + fs/xfs/xfs_ondisk.h | 2 12 files changed, 316 insertions(+), 4 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_rtrmap_btree.c create mode 100644 fs/xfs/libxfs/xfs_rtrmap_btree.h diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile index 5543cadd46db..c9b452646699 100644 --- a/fs/xfs/Makefile +++ b/fs/xfs/Makefile @@ -51,6 +51,7 @@ xfs-y += $(addprefix libxfs/, \ xfs_ag_resv.o \ xfs_rmap.o \ xfs_rmap_btree.o \ + xfs_rtrmap_btree.o \ xfs_refcount.o \ xfs_refcount_btree.o \ xfs_sb.o \ diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index f77762777aa6..90f9ce04b64d 100644 --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c @@ -1279,6 +1279,7 @@ xfs_btree_set_refs( xfs_buf_set_ref(bp, XFS_BMAP_BTREE_REF); break; case XFS_BTNUM_RMAP: + case XFS_BTNUM_RTRMAP: xfs_buf_set_ref(bp, XFS_RMAP_BTREE_REF); break; case XFS_BTNUM_REFC: diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h index 23806757dba2..96b0073abfa2 100644 --- a/fs/xfs/libxfs/xfs_btree.h +++ b/fs/xfs/libxfs/xfs_btree.h @@ -37,6 +37,8 @@ union xfs_btree_key { struct xfs_rmap_key rmap; struct xfs_rmap_key __rmap_bigkey[2]; struct xfs_refcount_key refc; + struct xfs_rtrmap_key rtrmap; + struct xfs_rtrmap_key __rtrmap_bigkey[2]; }; union xfs_btree_rec { @@ -46,6 +48,7 @@ union xfs_btree_rec { struct xfs_inobt_rec inobt; struct xfs_rmap_rec rmap; struct xfs_refcount_rec refc; + struct xfs_rtrmap_rec rtrmap; }; /* diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index 6770dac9c82d..ad767b27dbb3 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -1452,6 +1452,54 @@ typedef __be32 xfs_rmap_ptr_t; */ #define XFS_RTRMAP_CRC_MAGIC 0x4d415052 /* 'MAPR' */ +/* + * Data record structure + */ +struct xfs_rtrmap_rec { + __be64 rm_startblock; /* extent start block */ + __be64 rm_blockcount; /* extent length */ + __be64 rm_owner; /* extent owner */ + __be64 rm_offset; /* offset within the owner */ +}; + +/* rm_offset has the same values as the regular rmapbt. */ +#define XFS_RTRMAP_OFF_ATTR_FORK XFS_RMAP_OFF_ATTR_FORK +#define XFS_RTRMAP_OFF_BMBT_BLOCK XFS_RMAP_OFF_BMBT_BLOCK +#define XFS_RTRMAP_OFF_UNWRITTEN XFS_RMAP_OFF_UNWRITTEN + +#define XFS_RTRMAP_LEN_MAX ((uint64_t)~0U) +#define XFS_RTRMAP_OFF_FLAGS XFS_RMAP_OFF_FLAGS +#define XFS_RTRMAP_OFF_MASK XFS_RMAP_OFF_MASK + +#define XFS_RTRMAP_OFF XFS_RMAP_OFF + +#define XFS_RTRMAP_IS_BMBT_BLOCK(off) XFS_RMAP_IS_BMBT_BLOCK +#define XFS_RTRMAP_IS_ATTR_FORK(off) XFS_RMAP_IS_ATTR_FORK +#define XFS_RTRMAP_IS_UNWRITTEN(len) XFS_RMAP_IS_UNWRITTEN + +#define RTRMAPBT_STARTBLOCK_BITLEN 64 +#define RTRMAPBT_BLOCKCOUNT_BITLEN 64 +#define RTRMAPBT_OWNER_BITLEN RMAPBT_OWNER_BITLEN +#define RTRMAPBT_ATTRFLAG_BITLEN RMAPBT_ATTRFLAG_BITLEN +#define RTRMAPBT_BMBTFLAG_BITLEN RMAPBT_BMBTFLAG_BITLEN +#define RTRMAPBT_EXNTFLAG_BITLEN RMAPBT_EXNTFLAG_BITLEN +#define RTRMAPBT_UNUSED_OFFSET_BITLEN RMAPBT_UNUSED_OFFSET_BITLEN +#define RTRMAPBT_OFFSET_BITLEN RMAPBT_OFFSET_BITLEN + +/* + * Key structure + * + * We don't use the length for lookups + */ +struct xfs_rtrmap_key { + __be64 rm_startblock; /* extent start block */ + __be64 rm_owner; /* extent owner */ + __be64 rm_offset; /* offset within the owner */ +} __packed; + +/* btree pointer type */ +typedef __be64 xfs_rtrmap_ptr_t; + /* * Reference Count Btree format definitions * diff --git a/fs/xfs/libxfs/xfs_rmap.c b/fs/xfs/libxfs/xfs_rmap.c index 0372f77e019b..5294fd3464f0 100644 --- a/fs/xfs/libxfs/xfs_rmap.c +++ b/fs/xfs/libxfs/xfs_rmap.c @@ -197,19 +197,32 @@ xfs_rmap_get_rec( union xfs_btree_rec *rec; int error; - if (cur->bc_btnum != XFS_BTNUM_RMAP) - goto out_bad_rec; - error = xfs_btree_get_rec(cur, &rec, stat); if (error || !*stat) return error; + if (cur->bc_btnum == XFS_BTNUM_RTRMAP) + agno = -1; + else + agno = cur->bc_private.a.agno; + if (xfs_rmap_btrec_to_irec(rec, irec)) goto out_bad_rec; if (irec->rm_blockcount == 0) goto out_bad_rec; - if (irec->rm_startblock <= XFS_AGFL_BLOCK(mp)) { + if (cur->bc_btnum == XFS_BTNUM_RTRMAP) { + if (!xfs_verify_rtbno(mp, irec->rm_startblock)) + goto out_bad_rec; + if (irec->rm_startblock > + irec->rm_startblock + irec->rm_blockcount) + goto out_bad_rec; + if (!xfs_verify_rtbno(mp, + irec->rm_startblock + irec->rm_blockcount - 1)) + goto out_bad_rec; + if (XFS_RMAP_NON_INODE_OWNER(irec->rm_owner)) + goto out_bad_rec; + } else if (irec->rm_startblock <= XFS_AGFL_BLOCK(mp)) { if (irec->rm_owner != XFS_RMAP_OWN_FS) goto out_bad_rec; if (irec->rm_blockcount != XFS_AGFL_BLOCK(mp) + 1) diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_btree.c new file mode 100644 index 000000000000..62ff99278b3d --- /dev/null +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c @@ -0,0 +1,184 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#include "xfs.h" +#include "xfs_fs.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_log_format.h" +#include "xfs_trans_resv.h" +#include "xfs_bit.h" +#include "xfs_sb.h" +#include "xfs_mount.h" +#include "xfs_defer.h" +#include "xfs_inode.h" +#include "xfs_trans.h" +#include "xfs_alloc.h" +#include "xfs_btree.h" +#include "xfs_rtrmap_btree.h" +#include "xfs_trace.h" +#include "xfs_cksum.h" +#include "xfs_error.h" +#include "xfs_extent_busy.h" +#include "xfs_ag_resv.h" + +/* + * Realtime Reverse map btree. + * + * This is a per-ag tree used to track the owner(s) of a given extent + * in the realtime device. See the comments in xfs_rmap_btree.c for + * more information. + * + * This tree is basically the same as the regular rmap btree except that + * it doesn't live in free space, and the startblock and blockcount + * fields have been widened to 64 bits. + */ + +static struct xfs_btree_cur * +xfs_rtrmapbt_dup_cursor( + struct xfs_btree_cur *cur) +{ + struct xfs_btree_cur *new; + + new = xfs_rtrmapbt_init_cursor(cur->bc_mp, cur->bc_tp, + cur->bc_private.b.ip); + + /* Copy the flags values since init cursor doesn't get them. */ + new->bc_private.b.flags = cur->bc_private.b.flags; + + return new; +} + +static xfs_failaddr_t +xfs_rtrmapbt_verify( + struct xfs_buf *bp) +{ + struct xfs_mount *mp = bp->b_target->bt_mount; + struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp); + xfs_failaddr_t fa; + int level; + + if (block->bb_magic != cpu_to_be32(XFS_RTRMAP_CRC_MAGIC)) + return __this_address; + + if (!xfs_sb_version_hasrmapbt(&mp->m_sb)) + return __this_address; + fa = xfs_btree_lblock_v5hdr_verify(bp, XFS_RMAP_OWN_UNKNOWN); + if (fa) + return fa; + level = be16_to_cpu(block->bb_level); + if (level > mp->m_rtrmap_maxlevels) + return __this_address; + + return xfs_btree_lblock_verify(bp, mp->m_rtrmap_mxr[level != 0]); +} + +static void +xfs_rtrmapbt_read_verify( + struct xfs_buf *bp) +{ + xfs_failaddr_t fa; + + if (!xfs_btree_lblock_verify_crc(bp)) + xfs_verifier_error(bp, -EFSBADCRC, __this_address); + else { + fa = xfs_rtrmapbt_verify(bp); + if (fa) + xfs_verifier_error(bp, -EFSCORRUPTED, fa); + } + + if (bp->b_error) + trace_xfs_btree_corrupt(bp, _RET_IP_); +} + +static void +xfs_rtrmapbt_write_verify( + struct xfs_buf *bp) +{ + xfs_failaddr_t fa; + + fa = xfs_rtrmapbt_verify(bp); + if (fa) { + trace_xfs_btree_corrupt(bp, _RET_IP_); + xfs_verifier_error(bp, -EFSCORRUPTED, fa); + return; + } + xfs_btree_lblock_calc_crc(bp); + +} + +const struct xfs_buf_ops xfs_rtrmapbt_buf_ops = { + .name = "xfs_rtrmapbt", + .verify_read = xfs_rtrmapbt_read_verify, + .verify_write = xfs_rtrmapbt_write_verify, + .verify_struct = xfs_rtrmapbt_verify, +}; + +static const struct xfs_btree_ops xfs_rtrmapbt_ops = { + .rec_len = sizeof(struct xfs_rtrmap_rec), + .key_len = 2 * sizeof(struct xfs_rtrmap_key), + + .dup_cursor = xfs_rtrmapbt_dup_cursor, + .buf_ops = &xfs_rtrmapbt_buf_ops, +}; + +/* + * Allocate a new allocation btree cursor. + */ +struct xfs_btree_cur * +xfs_rtrmapbt_init_cursor( + struct xfs_mount *mp, + struct xfs_trans *tp, + struct xfs_inode *ip) +{ + struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK); + struct xfs_btree_cur *cur; + + cur = kmem_zone_zalloc(xfs_btree_cur_zone, KM_NOFS); + cur->bc_tp = tp; + cur->bc_mp = mp; + cur->bc_btnum = XFS_BTNUM_RTRMAP; + cur->bc_flags = XFS_BTREE_LONG_PTRS | XFS_BTREE_ROOT_IN_INODE | + XFS_BTREE_CRC_BLOCKS | XFS_BTREE_IROOT_RECORDS | + XFS_BTREE_OVERLAPPING; + cur->bc_blocklog = mp->m_sb.sb_blocklog; + cur->bc_ops = &xfs_rtrmapbt_ops; + cur->bc_nlevels = be16_to_cpu(ifp->if_broot->bb_level) + 1; + cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_rmap_2); + + cur->bc_private.b.forksize = XFS_IFORK_SIZE(ip, XFS_DATA_FORK); + cur->bc_private.b.ip = ip; + cur->bc_private.b.allocated = 0; + cur->bc_private.b.flags = 0; + cur->bc_private.b.whichfork = XFS_DATA_FORK; + + return cur; +} + +/* + * Calculate number of records in an rmap btree block. + */ +int +xfs_rtrmapbt_maxrecs( + int blocklen, + bool leaf) +{ + blocklen -= XFS_RTRMAP_BLOCK_LEN; + + if (leaf) + return blocklen / sizeof(struct xfs_rtrmap_rec); + return blocklen / + (2 * sizeof(struct xfs_rtrmap_key) + sizeof(xfs_rtrmap_ptr_t)); +} + +/* Compute the maximum height of an rmap btree. */ +void +xfs_rtrmapbt_compute_maxlevels( + struct xfs_mount *mp) +{ + mp->m_rtrmap_maxlevels = xfs_btree_compute_maxlevels(mp->m_rtrmap_mnr, + mp->m_sb.sb_rblocks); + ASSERT(mp->m_rtrmap_maxlevels <= XFS_BTREE_MAXLEVELS); +} diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.h b/fs/xfs/libxfs/xfs_rtrmap_btree.h new file mode 100644 index 000000000000..4b32823a2ec6 --- /dev/null +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2018 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#ifndef __XFS_RTRMAP_BTREE_H__ +#define __XFS_RTRMAP_BTREE_H__ + +struct xfs_buf; +struct xfs_btree_cur; +struct xfs_mount; + +/* rmaps only exist on crc enabled filesystems */ +#define XFS_RTRMAP_BLOCK_LEN XFS_BTREE_LBLOCK_CRC_LEN + +/* + * Record, key, and pointer address macros for btree blocks. + * + * (note that some of these may appear unused, but they are used in userspace) + */ +#define XFS_RTRMAP_REC_ADDR(block, index) \ + ((struct xfs_rtrmap_rec *) \ + ((char *)(block) + XFS_RTRMAP_BLOCK_LEN + \ + (((index) - 1) * sizeof(struct xfs_rtrmap_rec)))) + +#define XFS_RTRMAP_KEY_ADDR(block, index) \ + ((struct xfs_rtrmap_key *) \ + ((char *)(block) + XFS_RTRMAP_BLOCK_LEN + \ + ((index) - 1) * 2 * sizeof(struct xfs_rtrmap_key))) + +#define XFS_RTRMAP_HIGH_KEY_ADDR(block, index) \ + ((struct xfs_rtrmap_key *) \ + ((char *)(block) + XFS_RTRMAP_BLOCK_LEN + \ + sizeof(struct xfs_rtrmap_key) + \ + ((index) - 1) * 2 * sizeof(struct xfs_rtrmap_key))) + +#define XFS_RTRMAP_PTR_ADDR(block, index, maxrecs) \ + ((xfs_rtrmap_ptr_t *) \ + ((char *)(block) + XFS_RTRMAP_BLOCK_LEN + \ + (maxrecs) * 2 * sizeof(struct xfs_rtrmap_key) + \ + ((index) - 1) * sizeof(xfs_rtrmap_ptr_t))) + +struct xfs_btree_cur *xfs_rtrmapbt_init_cursor(struct xfs_mount *mp, + struct xfs_trans *tp, struct xfs_inode *ip); +int xfs_rtrmapbt_maxrecs(int blocklen, bool leaf); +void xfs_rtrmapbt_compute_maxlevels(struct xfs_mount *mp); + +#endif /* __XFS_RTRMAP_BTREE_H__ */ diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index 081f46e30556..733bb7e5409c 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -30,6 +30,7 @@ #include "xfs_refcount_btree.h" #include "xfs_da_format.h" #include "xfs_da_btree.h" +#include "xfs_rtrmap_btree.h" /* * Physical superblock buffer manipulations. Shared with libxfs in userspace. @@ -834,6 +835,11 @@ xfs_sb_mount_common( mp->m_rmap_mnr[0] = mp->m_rmap_mxr[0] / 2; mp->m_rmap_mnr[1] = mp->m_rmap_mxr[1] / 2; + mp->m_rtrmap_mxr[0] = xfs_rtrmapbt_maxrecs(sbp->sb_blocksize, true); + mp->m_rtrmap_mxr[1] = xfs_rtrmapbt_maxrecs(sbp->sb_blocksize, false); + mp->m_rtrmap_mnr[0] = mp->m_rtrmap_mxr[0] / 2; + mp->m_rtrmap_mnr[1] = mp->m_rtrmap_mxr[1] / 2; + mp->m_refc_mxr[0] = xfs_refcountbt_maxrecs(sbp->sb_blocksize, true); mp->m_refc_mxr[1] = xfs_refcountbt_maxrecs(sbp->sb_blocksize, false); mp->m_refc_mnr[0] = mp->m_refc_mxr[0] / 2; diff --git a/fs/xfs/libxfs/xfs_shared.h b/fs/xfs/libxfs/xfs_shared.h index 1c5debe748f0..f34e2740d9dd 100644 --- a/fs/xfs/libxfs/xfs_shared.h +++ b/fs/xfs/libxfs/xfs_shared.h @@ -27,6 +27,7 @@ extern const struct xfs_buf_ops xfs_agf_buf_ops; extern const struct xfs_buf_ops xfs_agfl_buf_ops; extern const struct xfs_buf_ops xfs_allocbt_buf_ops; extern const struct xfs_buf_ops xfs_rmapbt_buf_ops; +extern const struct xfs_buf_ops xfs_rtrmapbt_buf_ops; extern const struct xfs_buf_ops xfs_refcountbt_buf_ops; extern const struct xfs_buf_ops xfs_attr3_leaf_buf_ops; extern const struct xfs_buf_ops xfs_attr3_rmt_buf_ops; diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 611f8e188170..bd70a67ec3c6 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -34,6 +34,7 @@ #include "xfs_refcount_btree.h" #include "xfs_reflink.h" #include "xfs_extent_busy.h" +#include "xfs_rtrmap_btree.h" static DEFINE_MUTEX(xfs_uuid_table_mutex); @@ -744,6 +745,7 @@ xfs_mountfs( xfs_bmap_compute_maxlevels(mp, XFS_ATTR_FORK); xfs_ialloc_compute_maxlevels(mp); xfs_rmapbt_compute_maxlevels(mp); + xfs_rtrmapbt_compute_maxlevels(mp); xfs_refcountbt_compute_maxlevels(mp); xfs_set_maxicount(mp); diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index c12e59d3425d..5a4df6b860e2 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -112,12 +112,15 @@ typedef struct xfs_mount { uint m_inobt_mnr[2]; /* min inobt btree records */ uint m_rmap_mxr[2]; /* max rmap btree records */ uint m_rmap_mnr[2]; /* min rmap btree records */ + uint m_rtrmap_mxr[2]; /* max rtrmap btree records */ + uint m_rtrmap_mnr[2]; /* min rtrmap btree records */ uint m_refc_mxr[2]; /* max refc btree records */ uint m_refc_mnr[2]; /* min refc btree records */ uint m_ag_maxlevels; /* XFS_AG_MAXLEVELS */ uint m_bm_maxlevels[2]; /* XFS_BM_MAXLEVELS */ uint m_in_maxlevels; /* max inobt btree levels. */ uint m_rmap_maxlevels; /* max rmap btree levels */ + uint m_rtrmap_maxlevels; /* max rtrmap btree level */ uint m_refc_maxlevels; /* max refcount btree level */ xfs_extlen_t m_ag_prealloc_blocks; /* reserved ag blocks */ uint m_alloc_set_aside; /* space we can't use */ diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h index d3e04d20d8d4..23c9b6f047c5 100644 --- a/fs/xfs/xfs_ondisk.h +++ b/fs/xfs/xfs_ondisk.h @@ -41,6 +41,8 @@ xfs_check_ondisk_structs(void) XFS_CHECK_STRUCT_SIZE(struct xfs_refcount_rec, 12); XFS_CHECK_STRUCT_SIZE(struct xfs_rmap_key, 20); XFS_CHECK_STRUCT_SIZE(struct xfs_rmap_rec, 24); + XFS_CHECK_STRUCT_SIZE(struct xfs_rtrmap_key, 24); + XFS_CHECK_STRUCT_SIZE(struct xfs_rtrmap_rec, 32); XFS_CHECK_STRUCT_SIZE(struct xfs_timestamp, 8); XFS_CHECK_STRUCT_SIZE(xfs_alloc_key_t, 8); XFS_CHECK_STRUCT_SIZE(xfs_alloc_ptr_t, 4); From patchwork Thu Aug 30 18:32:14 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: 10582541 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 8EDAB17DB for ; Thu, 30 Aug 2018 18:32:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EAF02C39B for ; Thu, 30 Aug 2018 18:32:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72D0C2C3AF; Thu, 30 Aug 2018 18:32:18 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 258032C39B for ; Thu, 30 Aug 2018 18:32:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727840AbeH3Wfp (ORCPT ); Thu, 30 Aug 2018 18:35:45 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:57018 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727088AbeH3Wfo (ORCPT ); Thu, 30 Aug 2018 18:35:44 -0400 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 w7UISel4180333 for ; Thu, 30 Aug 2018 18:32:16 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=PXYjuTZ+UAkFla5QG3cm0olVXfEmk2qhEedGsGXBRxE=; b=RdVAIZjJTO32p0UYordUxM+WzRRxxTGcy8owbCuo4O/rXnAVEEGRAarmzRwDMkj/59vH k+tIMx0c1hdYiCri0Owu0ssYASevK+28WIQr3lSxasLSZblOBlJyzOVlAF2qgvjH5h8k KuGM2o+FUqBYLHJU4OkPXppHileG80SUEa7aG4I/YP8CR1iKeXCYeQROohvn3pynIojz R6K/WuUDWAv5NwtZCB4nMbfnWTwKxtP3m5hYlokbCFQoosPXKCwmzKb+h++8MbswyvD0 V+CbNqot2t3RJnn6HYesM9rTR3gpDU/x9KhXz6DLdmpa6120AytmKigvHUDOs5axFTgy Cg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2m2y2pxecn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:16 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIWF4k015927 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:15 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIWFc3020400 for ; Thu, 30 Aug 2018 18:32:15 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:32:14 -0700 Subject: [PATCH 06/18] xfs: realtime rmap btree transaction reservations From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:32:14 -0700 Message-ID: <153565393394.32612.114159822497813499.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=844 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808300185 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 Make sure that there's enough log reservation to handle mapping and unmapping realtime extents. We have to reserve enough space to handle a split in the rtrmapbt to add the record and a second split in the regular rmapbt to record the rtrmapbt split. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_trans_resv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_trans_resv.c b/fs/xfs/libxfs/xfs_trans_resv.c index f99a7aefe418..33922646ec65 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.c +++ b/fs/xfs/libxfs/xfs_trans_resv.c @@ -74,7 +74,8 @@ xfs_allocfree_log_count( blocks = num_ops * 2 * (2 * mp->m_ag_maxlevels - 1); if (xfs_sb_version_hasrmapbt(&mp->m_sb)) - blocks += num_ops * (2 * mp->m_rmap_maxlevels - 1); + blocks += max(num_ops * (2 * mp->m_rmap_maxlevels - 1), + num_ops * (2 * mp->m_rtrmap_maxlevels - 1)); if (xfs_sb_version_hasreflink(&mp->m_sb)) blocks += num_ops * (2 * mp->m_refc_maxlevels - 1); From patchwork Thu Aug 30 18:32:20 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: 10582545 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 7AA0D17DB for ; Thu, 30 Aug 2018 18:32:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AF202C39B for ; Thu, 30 Aug 2018 18:32:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D3D02C3AF; Thu, 30 Aug 2018 18:32:25 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 9DC3B2C39B for ; Thu, 30 Aug 2018 18:32:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727722AbeH3Wfv (ORCPT ); Thu, 30 Aug 2018 18:35:51 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:49660 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeH3Wfv (ORCPT ); Thu, 30 Aug 2018 18:35:51 -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 w7UISrcB134077 for ; Thu, 30 Aug 2018 18:32:22 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=BBY/8legZuEVk12NiEy5oi2QhJeFsthgwgJXxJ4krDo=; b=ZptRPm912iHHzgfdNhlArtDigCasqMQ1rBv8ARUMYUMBMs8y1c7mEIK4GAbUP5S+e3aQ k5t0kddkVjhIb8+SJkjLgqw0v2jnpxvLoMFEXUBO838o/dxxygW2frrxaUbFFE4X0Cw8 82OgLwMPbDDampmb79PyBHJMvzid7dLKkg807bsn3HDReQO9M1d2fIeCu2FW692fZsOn XimI8AOg9/LmjvmFBmU65jCHcVdLe8uT/wbmQc1r6Ujwb+8QEV8hemw2Zk7WZvkpEcEE LwZIXdRSonKlQ0yHzVknjKU5aFKCTvAsBSbfo4rMVfqXNzKudbymDslTZ8LFIPQ/X3xg lA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2m2yrqpaum-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:22 +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 w7UIWLxk021928 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:21 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w7UIWLCk003635 for ; Thu, 30 Aug 2018 18:32:21 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:32:20 -0700 Subject: [PATCH 07/18] xfs: add realtime rmap btree operations From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:32:20 -0700 Message-ID: <153565394004.32612.3279319394035721642.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=4 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-1808300185 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 Implement the generic btree operations needed to manipulate rtrmap btree blocks. This is different from the regular rmapbt in that we allocate space from the filesystem at large, and are neither constrained to the free space nor any particular AG. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_rtrmap_btree.c | 314 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 314 insertions(+) diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_btree.c index 62ff99278b3d..4529dbc6545c 100644 --- a/fs/xfs/libxfs/xfs_rtrmap_btree.c +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c @@ -17,12 +17,14 @@ #include "xfs_trans.h" #include "xfs_alloc.h" #include "xfs_btree.h" +#include "xfs_rmap.h" #include "xfs_rtrmap_btree.h" #include "xfs_trace.h" #include "xfs_cksum.h" #include "xfs_error.h" #include "xfs_extent_busy.h" #include "xfs_ag_resv.h" +#include "xfs_bmap.h" /* * Realtime Reverse map btree. @@ -51,6 +53,270 @@ xfs_rtrmapbt_dup_cursor( return new; } +STATIC int +xfs_rtrmapbt_alloc_block( + struct xfs_btree_cur *cur, + union xfs_btree_ptr *start, + union xfs_btree_ptr *new, + int *stat) +{ + struct xfs_alloc_arg args; + int error; + + memset(&args, 0, sizeof(args)); + args.tp = cur->bc_tp; + args.mp = cur->bc_mp; + args.fsbno = cur->bc_tp->t_firstblock; + xfs_rmap_ino_bmbt_owner(&args.oinfo, cur->bc_private.b.ip->i_ino, + cur->bc_private.b.whichfork); + + if (args.fsbno == NULLFSBLOCK) { + args.fsbno = be64_to_cpu(start->l); + args.type = XFS_ALLOCTYPE_START_BNO; + /* + * Make sure there is sufficient room left in the AG to + * complete a full tree split for an extent insert. If + * we are converting the middle part of an extent then + * we may need space for two tree splits. + * + * We are relying on the caller to make the correct block + * reservation for this operation to succeed. If the + * reservation amount is insufficient then we may fail a + * block allocation here and corrupt the filesystem. + */ + args.minleft = args.tp->t_blk_res; + } else if (cur->bc_tp->t_flags & XFS_TRANS_LOWMODE) { + args.type = XFS_ALLOCTYPE_START_BNO; + } else { + args.type = XFS_ALLOCTYPE_NEAR_BNO; + } + + args.minlen = args.maxlen = args.prod = 1; + args.wasdel = 0; + error = xfs_alloc_vextent(&args); + if (error) + goto error0; + + if (args.fsbno == NULLFSBLOCK && args.minleft) { + /* + * Could not find an AG with enough free space to satisfy + * a full btree split. Try again without minleft and if + * successful activate the lowspace algorithm. + */ + args.fsbno = 0; + args.type = XFS_ALLOCTYPE_FIRST_AG; + args.minleft = 0; + error = xfs_alloc_vextent(&args); + if (error) + goto error0; + cur->bc_tp->t_flags |= XFS_TRANS_LOWMODE; + } + if (args.fsbno == NULLFSBLOCK) { + *stat = 0; + return 0; + } + ASSERT(args.len == 1); + cur->bc_private.b.allocated++; + cur->bc_private.b.ip->i_d.di_nblocks++; + xfs_trans_log_inode(args.tp, cur->bc_private.b.ip, XFS_ILOG_CORE); + + new->l = cpu_to_be64(args.fsbno); + + *stat = 1; + return 0; + + error0: + return error; +} + +STATIC int +xfs_rtrmapbt_free_block( + struct xfs_btree_cur *cur, + struct xfs_buf *bp) +{ + struct xfs_mount *mp = cur->bc_mp; + struct xfs_inode *ip = cur->bc_private.b.ip; + struct xfs_trans *tp = cur->bc_tp; + xfs_fsblock_t fsbno = XFS_DADDR_TO_FSB(mp, XFS_BUF_ADDR(bp)); + struct xfs_owner_info oinfo; + + xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, cur->bc_private.b.whichfork); + xfs_bmap_add_free(cur->bc_tp, fsbno, 1, &oinfo); + ip->i_d.di_nblocks--; + + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); + return 0; +} + +/* + * Calculate number of records in the in-core realtime rmap btree inode root. + */ +STATIC int +xfs_rtrmapbt_broot_maxrecs( + int blocklen, + bool leaf) +{ + blocklen -= XFS_RTRMAP_BLOCK_LEN; + + if (leaf) + return blocklen / sizeof(struct xfs_rtrmap_rec); + return blocklen / (2 * sizeof(struct xfs_rtrmap_key) + + sizeof(xfs_rtrmap_ptr_t)); +} + +STATIC int +xfs_rtrmapbt_get_minrecs( + struct xfs_btree_cur *cur, + int level) +{ + struct xfs_ifork *ifp; + + if (level == cur->bc_nlevels - 1) { + ifp = XFS_IFORK_PTR(cur->bc_private.b.ip, + cur->bc_private.b.whichfork); + + return xfs_rtrmapbt_broot_maxrecs(ifp->if_broot_bytes, + level == 0) / 2; + } + + return cur->bc_mp->m_rtrmap_mnr[level != 0]; +} + +STATIC int +xfs_rtrmapbt_get_maxrecs( + struct xfs_btree_cur *cur, + int level) +{ + struct xfs_ifork *ifp; + + if (level == cur->bc_nlevels - 1) { + ifp = XFS_IFORK_PTR(cur->bc_private.b.ip, + cur->bc_private.b.whichfork); + + return xfs_rtrmapbt_broot_maxrecs(ifp->if_broot_bytes, + level == 0); + } + + return cur->bc_mp->m_rtrmap_mxr[level != 0]; +} + +STATIC void +xfs_rtrmapbt_init_key_from_rec( + union xfs_btree_key *key, + union xfs_btree_rec *rec) +{ + key->rtrmap.rm_startblock = rec->rtrmap.rm_startblock; + key->rtrmap.rm_owner = rec->rtrmap.rm_owner; + key->rtrmap.rm_offset = rec->rtrmap.rm_offset; +} + +STATIC void +xfs_rtrmapbt_init_high_key_from_rec( + union xfs_btree_key *key, + union xfs_btree_rec *rec) +{ + uint64_t off; + int adj; + + adj = be64_to_cpu(rec->rtrmap.rm_blockcount) - 1; + + key->rtrmap.rm_startblock = rec->rtrmap.rm_startblock; + be64_add_cpu(&key->rtrmap.rm_startblock, adj); + key->rtrmap.rm_owner = rec->rtrmap.rm_owner; + key->rtrmap.rm_offset = rec->rtrmap.rm_offset; + if (XFS_RMAP_NON_INODE_OWNER(be64_to_cpu(rec->rtrmap.rm_owner)) || + XFS_RMAP_IS_BMBT_BLOCK(be64_to_cpu(rec->rtrmap.rm_offset))) + return; + off = be64_to_cpu(key->rtrmap.rm_offset); + off = (XFS_RMAP_OFF(off) + adj) | (off & ~XFS_RMAP_OFF_MASK); + key->rtrmap.rm_offset = cpu_to_be64(off); +} + +STATIC void +xfs_rtrmapbt_init_rec_from_cur( + struct xfs_btree_cur *cur, + union xfs_btree_rec *rec) +{ + rec->rtrmap.rm_startblock = cpu_to_be64(cur->bc_rec.r.rm_startblock); + rec->rtrmap.rm_blockcount = cpu_to_be64(cur->bc_rec.r.rm_blockcount); + rec->rtrmap.rm_owner = cpu_to_be64(cur->bc_rec.r.rm_owner); + rec->rtrmap.rm_offset = cpu_to_be64( + xfs_rmap_irec_offset_pack(&cur->bc_rec.r)); +} + +STATIC void +xfs_rtrmapbt_init_ptr_from_cur( + struct xfs_btree_cur *cur, + union xfs_btree_ptr *ptr) +{ + ptr->l = 0; +} + +STATIC int64_t +xfs_rtrmapbt_key_diff( + struct xfs_btree_cur *cur, + union xfs_btree_key *key) +{ + struct xfs_rmap_irec *rec = &cur->bc_rec.r; + struct xfs_rtrmap_key *kp = &key->rtrmap; + __u64 x, y; + + x = be64_to_cpu(kp->rm_startblock); + y = rec->rm_startblock; + if (x > y) + return 1; + else if (y > x) + return -1; + + x = be64_to_cpu(kp->rm_owner); + y = rec->rm_owner; + if (x > y) + return 1; + else if (y > x) + return -1; + + x = XFS_RMAP_OFF(be64_to_cpu(kp->rm_offset)); + y = rec->rm_offset; + if (x > y) + return 1; + else if (y > x) + return -1; + return 0; +} + +STATIC int64_t +xfs_rtrmapbt_diff_two_keys( + struct xfs_btree_cur *cur, + union xfs_btree_key *k1, + union xfs_btree_key *k2) +{ + struct xfs_rtrmap_key *kp1 = &k1->rtrmap; + struct xfs_rtrmap_key *kp2 = &k2->rtrmap; + __u64 x, y; + + x = be64_to_cpu(kp1->rm_startblock); + y = be64_to_cpu(kp2->rm_startblock); + if (x > y) + return 1; + else if (y > x) + return -1; + + x = be64_to_cpu(kp1->rm_owner); + y = be64_to_cpu(kp2->rm_owner); + if (x > y) + return 1; + else if (y > x) + return -1; + + x = XFS_RMAP_OFF(be64_to_cpu(kp1->rm_offset)); + y = XFS_RMAP_OFF(be64_to_cpu(kp2->rm_offset)); + if (x > y) + return 1; + else if (y > x) + return -1; + return 0; +} + static xfs_failaddr_t xfs_rtrmapbt_verify( struct xfs_buf *bp) @@ -116,12 +382,60 @@ const struct xfs_buf_ops xfs_rtrmapbt_buf_ops = { .verify_struct = xfs_rtrmapbt_verify, }; +STATIC int +xfs_rtrmapbt_keys_inorder( + struct xfs_btree_cur *cur, + union xfs_btree_key *k1, + union xfs_btree_key *k2) +{ + if (be64_to_cpu(k1->rtrmap.rm_startblock) < + be64_to_cpu(k2->rtrmap.rm_startblock)) + return 1; + if (be64_to_cpu(k1->rtrmap.rm_owner) < + be64_to_cpu(k2->rtrmap.rm_owner)) + return 1; + if (XFS_RMAP_OFF(be64_to_cpu(k1->rtrmap.rm_offset)) <= + XFS_RMAP_OFF(be64_to_cpu(k2->rtrmap.rm_offset))) + return 1; + return 0; +} + +STATIC int +xfs_rtrmapbt_recs_inorder( + struct xfs_btree_cur *cur, + union xfs_btree_rec *r1, + union xfs_btree_rec *r2) +{ + if (be64_to_cpu(r1->rtrmap.rm_startblock) < + be64_to_cpu(r2->rtrmap.rm_startblock)) + return 1; + if (XFS_RMAP_OFF(be64_to_cpu(r1->rtrmap.rm_offset)) < + XFS_RMAP_OFF(be64_to_cpu(r2->rtrmap.rm_offset))) + return 1; + if (be64_to_cpu(r1->rtrmap.rm_owner) <= + be64_to_cpu(r2->rtrmap.rm_owner)) + return 1; + return 0; +} + static const struct xfs_btree_ops xfs_rtrmapbt_ops = { .rec_len = sizeof(struct xfs_rtrmap_rec), .key_len = 2 * sizeof(struct xfs_rtrmap_key), .dup_cursor = xfs_rtrmapbt_dup_cursor, + .alloc_block = xfs_rtrmapbt_alloc_block, + .free_block = xfs_rtrmapbt_free_block, + .get_minrecs = xfs_rtrmapbt_get_minrecs, + .get_maxrecs = xfs_rtrmapbt_get_maxrecs, + .init_key_from_rec = xfs_rtrmapbt_init_key_from_rec, + .init_high_key_from_rec = xfs_rtrmapbt_init_high_key_from_rec, + .init_rec_from_cur = xfs_rtrmapbt_init_rec_from_cur, + .init_ptr_from_cur = xfs_rtrmapbt_init_ptr_from_cur, + .key_diff = xfs_rtrmapbt_key_diff, .buf_ops = &xfs_rtrmapbt_buf_ops, + .diff_two_keys = xfs_rtrmapbt_diff_two_keys, + .keys_inorder = xfs_rtrmapbt_keys_inorder, + .recs_inorder = xfs_rtrmapbt_recs_inorder, }; /* From patchwork Thu Aug 30 18:32:26 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: 10582547 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 C64EA17DB for ; Thu, 30 Aug 2018 18:32:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B28542C3C0 for ; Thu, 30 Aug 2018 18:32:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4B422C3BC; Thu, 30 Aug 2018 18:32: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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 5681C2C3BC for ; Thu, 30 Aug 2018 18:32:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727862AbeH3WgG (ORCPT ); Thu, 30 Aug 2018 18:36:06 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:50032 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeH3WgG (ORCPT ); Thu, 30 Aug 2018 18:36:06 -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 w7UISc1i133688 for ; Thu, 30 Aug 2018 18:32: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=T9rrarMB7c5VmJ9FuRLsfO97GKIC2PgSvhL1jc0tMqs=; b=c9HVnwmJpd+GmYhF6bVRXCE1rwcMUbcnOWNrLqCxTjnjfBy3y216DjDpQ/Nxl0XCV2PT m0TKycqwNmdUYY5kLktEYib1shWQ3vyurpDuV6LWAVpnRjbL1zeLyghMDIdYGQ2aVoQ7 o8qAcqZyi+PK6lUHZpm3ozq9aqc7ps/MrkRGw1MzeWnpdmRZYhPm8Pp8fKUTuIedvqka 5/JniKvNx4RHMKbcSinVx/Vz1F7D6NuP1Jqyw5f4d6JR1jn9OFYEEHRKsoamFeeJ9r7s hBFp4YRh/RAq7AzoEgQYA6GndgNUj1CZIAEcoB/46jHTY+jc29mv9K2EC+YTBmMDl8jV ow== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2m2yrqpavc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:34 +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 w7UIWXk5022711 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:33 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w7UIWXkX003696 for ; Thu, 30 Aug 2018 18:32:33 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:32:33 -0700 Subject: [PATCH 08/18] xfs: prepare rmap functions to deal with rtrmapbt From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:32:26 -0700 Message-ID: <153565394627.32612.1259918116338310148.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 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-1807170000 definitions=main-1808300185 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 Prepare the high-level rmap functions to deal with the new realtime rmapbt and its slightly different conventions. Provide the ability to talk to either rmapbt or rtrmapbt formats from the same high level code. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_rmap.c | 178 +++++++++++++++++++++++++++------------------- fs/xfs/libxfs/xfs_rmap.h | 2 - fs/xfs/scrub/rmap.c | 2 - 3 files changed, 108 insertions(+), 74 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rmap.c b/fs/xfs/libxfs/xfs_rmap.c index 5294fd3464f0..c75d3ba34613 100644 --- a/fs/xfs/libxfs/xfs_rmap.c +++ b/fs/xfs/libxfs/xfs_rmap.c @@ -29,6 +29,24 @@ #include "xfs_inode.h" #include "xfs_ialloc.h" +/* By convention, the rtrmapbt's "AG" number is NULLAGNUMBER. */ +static xfs_agnumber_t +xfs_rmap_cur_agno( + struct xfs_btree_cur *cur) +{ + return (cur->bc_flags & XFS_BTREE_LONG_PTRS) ? + NULLAGNUMBER : cur->bc_private.a.agno; +} + +/* Return the maximum length of an rmap record. */ +static xfs_filblks_t +xfs_rmap_len_max( + struct xfs_btree_cur *cur) +{ + return (cur->bc_flags & XFS_BTREE_LONG_PTRS) ? + XFS_RTRMAP_LEN_MAX : XFS_RMAP_LEN_MAX; +} + /* * Lookup the first record less than or equal to [bno, len, owner, offset] * in the btree given by cur. @@ -86,19 +104,27 @@ xfs_rmap_update( union xfs_btree_rec rec; int error; - trace_xfs_rmap_update(cur->bc_mp, cur->bc_private.a.agno, + trace_xfs_rmap_update(cur->bc_mp, xfs_rmap_cur_agno(cur), irec->rm_startblock, irec->rm_blockcount, irec->rm_owner, irec->rm_offset, irec->rm_flags); - rec.rmap.rm_startblock = cpu_to_be32(irec->rm_startblock); - rec.rmap.rm_blockcount = cpu_to_be32(irec->rm_blockcount); - rec.rmap.rm_owner = cpu_to_be64(irec->rm_owner); - rec.rmap.rm_offset = cpu_to_be64( - xfs_rmap_irec_offset_pack(irec)); + if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { + rec.rtrmap.rm_startblock = cpu_to_be64(irec->rm_startblock); + rec.rtrmap.rm_blockcount = cpu_to_be64(irec->rm_blockcount); + rec.rtrmap.rm_owner = cpu_to_be64(irec->rm_owner); + rec.rtrmap.rm_offset = cpu_to_be64( + xfs_rmap_irec_offset_pack(irec)); + } else { + rec.rmap.rm_startblock = cpu_to_be32(irec->rm_startblock); + rec.rmap.rm_blockcount = cpu_to_be32(irec->rm_blockcount); + rec.rmap.rm_owner = cpu_to_be64(irec->rm_owner); + rec.rmap.rm_offset = cpu_to_be64( + xfs_rmap_irec_offset_pack(irec)); + } error = xfs_btree_update(cur, &rec); if (error) trace_xfs_rmap_update_error(cur->bc_mp, - cur->bc_private.a.agno, error, _RET_IP_); + xfs_rmap_cur_agno(cur), error, _RET_IP_); return error; } @@ -114,7 +140,7 @@ xfs_rmap_insert( int i; int error; - trace_xfs_rmap_insert(rcur->bc_mp, rcur->bc_private.a.agno, agbno, + trace_xfs_rmap_insert(rcur->bc_mp, xfs_rmap_cur_agno(rcur), agbno, len, owner, offset, flags); error = xfs_rmap_lookup_eq(rcur, agbno, len, owner, offset, flags, &i); @@ -134,7 +160,7 @@ xfs_rmap_insert( done: if (error) trace_xfs_rmap_insert_error(rcur->bc_mp, - rcur->bc_private.a.agno, error, _RET_IP_); + xfs_rmap_cur_agno(rcur), error, _RET_IP_); return error; } @@ -150,7 +176,7 @@ xfs_rmap_delete( int i; int error; - trace_xfs_rmap_delete(rcur->bc_mp, rcur->bc_private.a.agno, agbno, + trace_xfs_rmap_delete(rcur->bc_mp, xfs_rmap_cur_agno(rcur), agbno, len, owner, offset, flags); error = xfs_rmap_lookup_eq(rcur, agbno, len, owner, offset, flags, &i); @@ -165,22 +191,31 @@ xfs_rmap_delete( done: if (error) trace_xfs_rmap_delete_error(rcur->bc_mp, - rcur->bc_private.a.agno, error, _RET_IP_); + xfs_rmap_cur_agno(rcur), error, _RET_IP_); return error; } /* Convert an internal btree record to an rmap record. */ int xfs_rmap_btrec_to_irec( + struct xfs_btree_cur *cur, union xfs_btree_rec *rec, struct xfs_rmap_irec *irec) { irec->rm_flags = 0; - irec->rm_startblock = be32_to_cpu(rec->rmap.rm_startblock); - irec->rm_blockcount = be32_to_cpu(rec->rmap.rm_blockcount); - irec->rm_owner = be64_to_cpu(rec->rmap.rm_owner); - return xfs_rmap_irec_offset_unpack(be64_to_cpu(rec->rmap.rm_offset), - irec); + if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { + irec->rm_startblock = be64_to_cpu(rec->rtrmap.rm_startblock); + irec->rm_blockcount = be64_to_cpu(rec->rtrmap.rm_blockcount); + irec->rm_owner = be64_to_cpu(rec->rtrmap.rm_owner); + return xfs_rmap_irec_offset_unpack( + be64_to_cpu(rec->rtrmap.rm_offset), irec); + } else { + irec->rm_startblock = be32_to_cpu(rec->rmap.rm_startblock); + irec->rm_blockcount = be32_to_cpu(rec->rmap.rm_blockcount); + irec->rm_owner = be64_to_cpu(rec->rmap.rm_owner); + return xfs_rmap_irec_offset_unpack( + be64_to_cpu(rec->rmap.rm_offset), irec); + } } /* @@ -206,7 +241,7 @@ xfs_rmap_get_rec( else agno = cur->bc_private.a.agno; - if (xfs_rmap_btrec_to_irec(rec, irec)) + if (xfs_rmap_btrec_to_irec(cur, rec, irec)) goto out_bad_rec; if (irec->rm_blockcount == 0) @@ -272,7 +307,7 @@ xfs_rmap_find_left_neighbor_helper( struct xfs_find_left_neighbor_info *info = priv; trace_xfs_rmap_find_left_neighbor_candidate(cur->bc_mp, - cur->bc_private.a.agno, rec->rm_startblock, + xfs_rmap_cur_agno(cur), rec->rm_startblock, rec->rm_blockcount, rec->rm_owner, rec->rm_offset, rec->rm_flags); @@ -324,7 +359,7 @@ xfs_rmap_find_left_neighbor( info.stat = stat; trace_xfs_rmap_find_left_neighbor_query(cur->bc_mp, - cur->bc_private.a.agno, bno, 0, owner, offset, flags); + xfs_rmap_cur_agno(cur), bno, 0, owner, offset, flags); error = xfs_rmap_query_range(cur, &info.high, &info.high, xfs_rmap_find_left_neighbor_helper, &info); @@ -332,7 +367,7 @@ xfs_rmap_find_left_neighbor( error = 0; if (*stat) trace_xfs_rmap_find_left_neighbor_result(cur->bc_mp, - cur->bc_private.a.agno, irec->rm_startblock, + xfs_rmap_cur_agno(cur), irec->rm_startblock, irec->rm_blockcount, irec->rm_owner, irec->rm_offset, irec->rm_flags); return error; @@ -348,7 +383,7 @@ xfs_rmap_lookup_le_range_helper( struct xfs_find_left_neighbor_info *info = priv; trace_xfs_rmap_lookup_le_range_candidate(cur->bc_mp, - cur->bc_private.a.agno, rec->rm_startblock, + xfs_rmap_cur_agno(cur), rec->rm_startblock, rec->rm_blockcount, rec->rm_owner, rec->rm_offset, rec->rm_flags); @@ -397,14 +432,14 @@ xfs_rmap_lookup_le_range( info.stat = stat; trace_xfs_rmap_lookup_le_range(cur->bc_mp, - cur->bc_private.a.agno, bno, 0, owner, offset, flags); + xfs_rmap_cur_agno(cur), bno, 0, owner, offset, flags); error = xfs_rmap_query_range(cur, &info.high, &info.high, xfs_rmap_lookup_le_range_helper, &info); if (error == XFS_BTREE_QUERY_RANGE_ABORT) error = 0; if (*stat) trace_xfs_rmap_lookup_le_range_result(cur->bc_mp, - cur->bc_private.a.agno, irec->rm_startblock, + xfs_rmap_cur_agno(cur), irec->rm_startblock, irec->rm_blockcount, irec->rm_owner, irec->rm_offset, irec->rm_flags); return error; @@ -495,7 +530,7 @@ xfs_rmap_unmap( (flags & XFS_RMAP_BMBT_BLOCK); if (unwritten) flags |= XFS_RMAP_UNWRITTEN; - trace_xfs_rmap_unmap(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_unmap(mp, xfs_rmap_cur_agno(cur), bno, len, unwritten, oinfo); /* @@ -513,7 +548,7 @@ xfs_rmap_unmap( goto out_error; XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error); trace_xfs_rmap_lookup_le_range_result(cur->bc_mp, - cur->bc_private.a.agno, ltrec.rm_startblock, + xfs_rmap_cur_agno(cur), ltrec.rm_startblock, ltrec.rm_blockcount, ltrec.rm_owner, ltrec.rm_offset, ltrec.rm_flags); ltoff = ltrec.rm_offset; @@ -568,7 +603,7 @@ xfs_rmap_unmap( if (ltrec.rm_startblock == bno && ltrec.rm_blockcount == len) { /* exact match, simply remove the record from rmap tree */ - trace_xfs_rmap_delete(mp, cur->bc_private.a.agno, + trace_xfs_rmap_delete(mp, xfs_rmap_cur_agno(cur), ltrec.rm_startblock, ltrec.rm_blockcount, ltrec.rm_owner, ltrec.rm_offset, ltrec.rm_flags); @@ -643,7 +678,7 @@ xfs_rmap_unmap( else cur->bc_rec.r.rm_offset = offset + len; cur->bc_rec.r.rm_flags = flags; - trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, + trace_xfs_rmap_insert(mp, xfs_rmap_cur_agno(cur), cur->bc_rec.r.rm_startblock, cur->bc_rec.r.rm_blockcount, cur->bc_rec.r.rm_owner, @@ -655,11 +690,11 @@ xfs_rmap_unmap( } out_done: - trace_xfs_rmap_unmap_done(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_unmap_done(mp, xfs_rmap_cur_agno(cur), bno, len, unwritten, oinfo); out_error: if (error) - trace_xfs_rmap_unmap_error(mp, cur->bc_private.a.agno, + trace_xfs_rmap_unmap_error(mp, xfs_rmap_cur_agno(cur), error, _RET_IP_); return error; } @@ -750,7 +785,7 @@ xfs_rmap_map( (flags & XFS_RMAP_BMBT_BLOCK); if (unwritten) flags |= XFS_RMAP_UNWRITTEN; - trace_xfs_rmap_map(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_map(mp, xfs_rmap_cur_agno(cur), bno, len, unwritten, oinfo); ASSERT(!xfs_rmap_should_skip_owner_update(oinfo)); @@ -769,7 +804,7 @@ xfs_rmap_map( goto out_error; XFS_WANT_CORRUPTED_GOTO(mp, have_lt == 1, out_error); trace_xfs_rmap_lookup_le_range_result(cur->bc_mp, - cur->bc_private.a.agno, ltrec.rm_startblock, + xfs_rmap_cur_agno(cur), ltrec.rm_startblock, ltrec.rm_blockcount, ltrec.rm_owner, ltrec.rm_offset, ltrec.rm_flags); @@ -797,7 +832,7 @@ xfs_rmap_map( XFS_WANT_CORRUPTED_GOTO(mp, bno + len <= gtrec.rm_startblock, out_error); trace_xfs_rmap_find_right_neighbor_result(cur->bc_mp, - cur->bc_private.a.agno, gtrec.rm_startblock, + xfs_rmap_cur_agno(cur), gtrec.rm_startblock, gtrec.rm_blockcount, gtrec.rm_owner, gtrec.rm_offset, gtrec.rm_flags); if (!xfs_rmap_is_mergeable(>rec, owner, flags)) @@ -824,8 +859,8 @@ xfs_rmap_map( if (have_gt && bno + len == gtrec.rm_startblock && (ignore_off || offset + len == gtrec.rm_offset) && - (unsigned long)ltrec.rm_blockcount + len + - gtrec.rm_blockcount <= XFS_RMAP_LEN_MAX) { + ltrec.rm_blockcount + len + gtrec.rm_blockcount <= + xfs_rmap_len_max(cur)) { /* * right edge also contiguous, delete right record * and merge into left record. @@ -836,7 +871,7 @@ xfs_rmap_map( * result: |rrrrrrrrrrrrrrrrrrrrrrrrrrrrr| */ ltrec.rm_blockcount += gtrec.rm_blockcount; - trace_xfs_rmap_delete(mp, cur->bc_private.a.agno, + trace_xfs_rmap_delete(mp, xfs_rmap_cur_agno(cur), gtrec.rm_startblock, gtrec.rm_blockcount, gtrec.rm_owner, @@ -884,7 +919,7 @@ xfs_rmap_map( cur->bc_rec.r.rm_owner = owner; cur->bc_rec.r.rm_offset = offset; cur->bc_rec.r.rm_flags = flags; - trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_insert(mp, xfs_rmap_cur_agno(cur), bno, len, owner, offset, flags); error = xfs_btree_insert(cur, &i); if (error) @@ -892,11 +927,11 @@ xfs_rmap_map( XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error); } - trace_xfs_rmap_map_done(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_map_done(mp, xfs_rmap_cur_agno(cur), bno, len, unwritten, oinfo); out_error: if (error) - trace_xfs_rmap_map_error(mp, cur->bc_private.a.agno, + trace_xfs_rmap_map_error(mp, xfs_rmap_cur_agno(cur), error, _RET_IP_); return error; } @@ -970,7 +1005,7 @@ xfs_rmap_convert( (flags & (XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK)))); oldext = unwritten ? XFS_RMAP_UNWRITTEN : 0; new_endoff = offset + len; - trace_xfs_rmap_convert(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_convert(mp, xfs_rmap_cur_agno(cur), bno, len, unwritten, oinfo); /* @@ -988,7 +1023,7 @@ xfs_rmap_convert( goto done; XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done); trace_xfs_rmap_lookup_le_range_result(cur->bc_mp, - cur->bc_private.a.agno, PREV.rm_startblock, + xfs_rmap_cur_agno(cur), PREV.rm_startblock, PREV.rm_blockcount, PREV.rm_owner, PREV.rm_offset, PREV.rm_flags); @@ -1024,7 +1059,7 @@ xfs_rmap_convert( LEFT.rm_startblock + LEFT.rm_blockcount <= bno, done); trace_xfs_rmap_find_left_neighbor_result(cur->bc_mp, - cur->bc_private.a.agno, LEFT.rm_startblock, + xfs_rmap_cur_agno(cur), LEFT.rm_startblock, LEFT.rm_blockcount, LEFT.rm_owner, LEFT.rm_offset, LEFT.rm_flags); if (LEFT.rm_startblock + LEFT.rm_blockcount == bno && @@ -1054,7 +1089,7 @@ xfs_rmap_convert( XFS_WANT_CORRUPTED_GOTO(mp, bno + len <= RIGHT.rm_startblock, done); trace_xfs_rmap_find_right_neighbor_result(cur->bc_mp, - cur->bc_private.a.agno, RIGHT.rm_startblock, + xfs_rmap_cur_agno(cur), RIGHT.rm_startblock, RIGHT.rm_blockcount, RIGHT.rm_owner, RIGHT.rm_offset, RIGHT.rm_flags); if (bno + len == RIGHT.rm_startblock && @@ -1068,11 +1103,11 @@ xfs_rmap_convert( RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG)) == (RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG | RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG) && - (unsigned long)LEFT.rm_blockcount + len + - RIGHT.rm_blockcount > XFS_RMAP_LEN_MAX) + LEFT.rm_blockcount + len + RIGHT.rm_blockcount > + xfs_rmap_len_max(cur)) state &= ~RMAP_RIGHT_CONTIG; - trace_xfs_rmap_convert_state(mp, cur->bc_private.a.agno, state, + trace_xfs_rmap_convert_state(mp, xfs_rmap_cur_agno(cur), state, _RET_IP_); /* reset the cursor back to PREV */ @@ -1096,7 +1131,7 @@ xfs_rmap_convert( if (error) goto done; XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done); - trace_xfs_rmap_delete(mp, cur->bc_private.a.agno, + trace_xfs_rmap_delete(mp, xfs_rmap_cur_agno(cur), RIGHT.rm_startblock, RIGHT.rm_blockcount, RIGHT.rm_owner, RIGHT.rm_offset, RIGHT.rm_flags); @@ -1108,7 +1143,7 @@ xfs_rmap_convert( if (error) goto done; XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done); - trace_xfs_rmap_delete(mp, cur->bc_private.a.agno, + trace_xfs_rmap_delete(mp, xfs_rmap_cur_agno(cur), PREV.rm_startblock, PREV.rm_blockcount, PREV.rm_owner, PREV.rm_offset, PREV.rm_flags); @@ -1132,7 +1167,7 @@ xfs_rmap_convert( * Setting all of a previous oldext extent to newext. * The left neighbor is contiguous, the right is not. */ - trace_xfs_rmap_delete(mp, cur->bc_private.a.agno, + trace_xfs_rmap_delete(mp, xfs_rmap_cur_agno(cur), PREV.rm_startblock, PREV.rm_blockcount, PREV.rm_owner, PREV.rm_offset, PREV.rm_flags); @@ -1160,7 +1195,7 @@ xfs_rmap_convert( if (error) goto done; XFS_WANT_CORRUPTED_GOTO(mp, i == 1, done); - trace_xfs_rmap_delete(mp, cur->bc_private.a.agno, + trace_xfs_rmap_delete(mp, xfs_rmap_cur_agno(cur), RIGHT.rm_startblock, RIGHT.rm_blockcount, RIGHT.rm_owner, RIGHT.rm_offset, RIGHT.rm_flags); @@ -1233,7 +1268,7 @@ xfs_rmap_convert( NEW.rm_blockcount = len; NEW.rm_flags = newext; cur->bc_rec.r = NEW; - trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, bno, + trace_xfs_rmap_insert(mp, xfs_rmap_cur_agno(cur), bno, len, owner, offset, newext); error = xfs_btree_insert(cur, &i); if (error) @@ -1284,7 +1319,7 @@ xfs_rmap_convert( NEW.rm_blockcount = len; NEW.rm_flags = newext; cur->bc_rec.r = NEW; - trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, bno, + trace_xfs_rmap_insert(mp, xfs_rmap_cur_agno(cur), bno, len, owner, offset, newext); error = xfs_btree_insert(cur, &i); if (error) @@ -1312,7 +1347,7 @@ xfs_rmap_convert( NEW = PREV; NEW.rm_blockcount = offset - PREV.rm_offset; cur->bc_rec.r = NEW; - trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, + trace_xfs_rmap_insert(mp, xfs_rmap_cur_agno(cur), NEW.rm_startblock, NEW.rm_blockcount, NEW.rm_owner, NEW.rm_offset, NEW.rm_flags); @@ -1333,7 +1368,7 @@ xfs_rmap_convert( /* new middle extent - newext */ cur->bc_rec.r.rm_flags &= ~XFS_RMAP_UNWRITTEN; cur->bc_rec.r.rm_flags |= newext; - trace_xfs_rmap_insert(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_insert(mp, xfs_rmap_cur_agno(cur), bno, len, owner, offset, newext); error = xfs_btree_insert(cur, &i); if (error) @@ -1354,12 +1389,12 @@ xfs_rmap_convert( ASSERT(0); } - trace_xfs_rmap_convert_done(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_convert_done(mp, xfs_rmap_cur_agno(cur), bno, len, unwritten, oinfo); done: if (error) trace_xfs_rmap_convert_error(cur->bc_mp, - cur->bc_private.a.agno, error, _RET_IP_); + xfs_rmap_cur_agno(cur), error, _RET_IP_); return error; } @@ -1395,7 +1430,7 @@ xfs_rmap_convert_shared( (flags & (XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK)))); oldext = unwritten ? XFS_RMAP_UNWRITTEN : 0; new_endoff = offset + len; - trace_xfs_rmap_convert(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_convert(mp, xfs_rmap_cur_agno(cur), bno, len, unwritten, oinfo); /* @@ -1451,7 +1486,7 @@ xfs_rmap_convert_shared( XFS_WANT_CORRUPTED_GOTO(mp, bno + len <= RIGHT.rm_startblock, done); trace_xfs_rmap_find_right_neighbor_result(cur->bc_mp, - cur->bc_private.a.agno, RIGHT.rm_startblock, + xfs_rmap_cur_agno(cur), RIGHT.rm_startblock, RIGHT.rm_blockcount, RIGHT.rm_owner, RIGHT.rm_offset, RIGHT.rm_flags); if (xfs_rmap_is_mergeable(&RIGHT, owner, newext)) @@ -1463,11 +1498,11 @@ xfs_rmap_convert_shared( RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG)) == (RMAP_LEFT_FILLING | RMAP_LEFT_CONTIG | RMAP_RIGHT_FILLING | RMAP_RIGHT_CONTIG) && - (unsigned long)LEFT.rm_blockcount + len + - RIGHT.rm_blockcount > XFS_RMAP_LEN_MAX) + LEFT.rm_blockcount + len + RIGHT.rm_blockcount > + xfs_rmap_len_max(cur)) state &= ~RMAP_RIGHT_CONTIG; - trace_xfs_rmap_convert_state(mp, cur->bc_private.a.agno, state, + trace_xfs_rmap_convert_state(mp, xfs_rmap_cur_agno(cur), state, _RET_IP_); /* * Switch out based on the FILLING and CONTIG state bits. @@ -1734,12 +1769,12 @@ xfs_rmap_convert_shared( ASSERT(0); } - trace_xfs_rmap_convert_done(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_convert_done(mp, xfs_rmap_cur_agno(cur), bno, len, unwritten, oinfo); done: if (error) trace_xfs_rmap_convert_error(cur->bc_mp, - cur->bc_private.a.agno, error, _RET_IP_); + xfs_rmap_cur_agno(cur), error, _RET_IP_); return error; } @@ -1777,7 +1812,7 @@ xfs_rmap_unmap_shared( xfs_owner_info_unpack(oinfo, &owner, &offset, &flags); if (unwritten) flags |= XFS_RMAP_UNWRITTEN; - trace_xfs_rmap_unmap(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_unmap(mp, xfs_rmap_cur_agno(cur), bno, len, unwritten, oinfo); /* @@ -1901,12 +1936,12 @@ xfs_rmap_unmap_shared( goto out_error; } - trace_xfs_rmap_unmap_done(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_unmap_done(mp, xfs_rmap_cur_agno(cur), bno, len, unwritten, oinfo); out_error: if (error) trace_xfs_rmap_unmap_error(cur->bc_mp, - cur->bc_private.a.agno, error, _RET_IP_); + xfs_rmap_cur_agno(cur), error, _RET_IP_); return error; } @@ -1941,7 +1976,7 @@ xfs_rmap_map_shared( xfs_owner_info_unpack(oinfo, &owner, &offset, &flags); if (unwritten) flags |= XFS_RMAP_UNWRITTEN; - trace_xfs_rmap_map(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_map(mp, xfs_rmap_cur_agno(cur), bno, len, unwritten, oinfo); /* Is there a left record that abuts our range? */ @@ -1964,7 +1999,7 @@ xfs_rmap_map_shared( goto out_error; XFS_WANT_CORRUPTED_GOTO(mp, have_gt == 1, out_error); trace_xfs_rmap_find_right_neighbor_result(cur->bc_mp, - cur->bc_private.a.agno, gtrec.rm_startblock, + xfs_rmap_cur_agno(cur), gtrec.rm_startblock, gtrec.rm_blockcount, gtrec.rm_owner, gtrec.rm_offset, gtrec.rm_flags); @@ -2054,12 +2089,12 @@ xfs_rmap_map_shared( goto out_error; } - trace_xfs_rmap_map_done(mp, cur->bc_private.a.agno, bno, len, + trace_xfs_rmap_map_done(mp, xfs_rmap_cur_agno(cur), bno, len, unwritten, oinfo); out_error: if (error) trace_xfs_rmap_map_error(cur->bc_mp, - cur->bc_private.a.agno, error, _RET_IP_); + xfs_rmap_cur_agno(cur), error, _RET_IP_); return error; } @@ -2107,7 +2142,7 @@ xfs_rmap_query_range_helper( struct xfs_rmap_irec irec; int error; - error = xfs_rmap_btrec_to_irec(rec, &irec); + error = xfs_rmap_btrec_to_irec(cur, rec, &irec); if (error) return error; return query->fn(cur, &irec, query->priv); @@ -2203,13 +2238,12 @@ xfs_rmap_finish_one( if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_RMAP_FINISH_ONE)) return -EIO; - /* * If we haven't gotten a cursor or the cursor AG doesn't match * the startblock, get one now. */ rcur = *pcur; - if (rcur != NULL && rcur->bc_private.a.agno != agno) { + if (rcur != NULL && xfs_rmap_cur_agno(rcur) != agno) { xfs_rmap_finish_one_cleanup(tp, rcur, 0); rcur = NULL; *pcur = NULL; diff --git a/fs/xfs/libxfs/xfs_rmap.h b/fs/xfs/libxfs/xfs_rmap.h index f92b59c6adda..74f02830edb3 100644 --- a/fs/xfs/libxfs/xfs_rmap.h +++ b/fs/xfs/libxfs/xfs_rmap.h @@ -213,7 +213,7 @@ int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_fsblock_t bno, int xfs_rmap_compare(const struct xfs_rmap_irec *a, const struct xfs_rmap_irec *b); union xfs_btree_rec; -int xfs_rmap_btrec_to_irec(union xfs_btree_rec *rec, +int xfs_rmap_btrec_to_irec(struct xfs_btree_cur *cur, union xfs_btree_rec *rec, struct xfs_rmap_irec *irec); int xfs_rmap_has_record(struct xfs_btree_cur *cur, xfs_fsblock_t bno, xfs_filblks_t len, bool *exists); diff --git a/fs/xfs/scrub/rmap.c b/fs/xfs/scrub/rmap.c index c6a1c59ef25e..32dc329e5411 100644 --- a/fs/xfs/scrub/rmap.c +++ b/fs/xfs/scrub/rmap.c @@ -112,7 +112,7 @@ xchk_rmapbt_rec( bool is_attr; int error; - error = xfs_rmap_btrec_to_irec(rec, &irec); + error = xfs_rmap_btrec_to_irec(bs->cur, rec, &irec); if (!xchk_btree_process_error(bs->sc, bs->cur, 0, &error)) goto out; From patchwork Thu Aug 30 18:32:38 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: 10582549 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 47E81139B for ; Thu, 30 Aug 2018 18:32:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 386302C3BC for ; Thu, 30 Aug 2018 18:32:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CB752C3C4; Thu, 30 Aug 2018 18:32:44 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 7988A2C3BC for ; Thu, 30 Aug 2018 18:32:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727819AbeH3WgK (ORCPT ); Thu, 30 Aug 2018 18:36:10 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:58112 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeH3WgK (ORCPT ); Thu, 30 Aug 2018 18:36:10 -0400 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 w7UISg4t180367 for ; Thu, 30 Aug 2018 18:32:42 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=InRMw+n8IwGUIRVEXVjTNWhWGlcbmRaGKSVctwXcXxk=; b=j+QMKZy8Mjm8bdaBGMO2hzfJPfi2Du8r65aZV0fgjVWUqVL79LpTOyZ41KThXM1SJk+R YyD4ZYofjGDgm7I0kHeNhJy9qXVsfif7snXuyVA+w6oysllTJT2kcIojsmUGXWjUuZ/2 VM8uhslpdgGHS+r3fywpdfSANZiH9kK7G1fSQFPXOkAi04w8K2D/AahR+DQQzoqGB17A kR+lv2CBYM++e0RIKtzn4Pc/qscIPenQF00yPVg73gYSyC0unTpEgTYal0/3J25Hbhd1 RlLQNYC0hl2doDon6M+0Tg2snDxEtIgoMd/GTzPHisKjvX1vqDW9bPOQL4sMSGNZ21cY Bw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2m2y2pxeem-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:41 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIWelk012814 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:40 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIWdWt020699 for ; Thu, 30 Aug 2018 18:32:40 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:32:39 -0700 Subject: [PATCH 09/18] xfs: add a realtime flag to the rmap update log redo items From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:32:38 -0700 Message-ID: <153565395882.32612.8872147427964717639.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 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-1807170000 definitions=main-1808300185 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 Extend the rmap update (RUI) log items with a new realtime flag that indicates that the updates apply against the realtime rmapbt. We'll wire up the actual rmap code later. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_log_format.h | 4 +++- fs/xfs/libxfs/xfs_refcount.c | 4 ++-- fs/xfs/libxfs/xfs_rmap.c | 24 +++++++++++++++--------- fs/xfs/libxfs/xfs_rmap.h | 5 +++-- fs/xfs/xfs_rmap_item.c | 4 +++- fs/xfs/xfs_trans.h | 2 +- fs/xfs/xfs_trans_rmap.c | 9 +++++++-- 7 files changed, 34 insertions(+), 18 deletions(-) diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h index e5f97c69b320..c8184a0d9290 100644 --- a/fs/xfs/libxfs/xfs_log_format.h +++ b/fs/xfs/libxfs/xfs_log_format.h @@ -637,11 +637,13 @@ struct xfs_map_extent { #define XFS_RMAP_EXTENT_ATTR_FORK (1U << 31) #define XFS_RMAP_EXTENT_BMBT_BLOCK (1U << 30) #define XFS_RMAP_EXTENT_UNWRITTEN (1U << 29) +#define XFS_RMAP_EXTENT_REALTIME (1U << 28) #define XFS_RMAP_EXTENT_FLAGS (XFS_RMAP_EXTENT_TYPE_MASK | \ XFS_RMAP_EXTENT_ATTR_FORK | \ XFS_RMAP_EXTENT_BMBT_BLOCK | \ - XFS_RMAP_EXTENT_UNWRITTEN) + XFS_RMAP_EXTENT_UNWRITTEN | \ + XFS_RMAP_EXTENT_REALTIME) /* * This is the structure used to lay out an rui log item in the diff --git a/fs/xfs/libxfs/xfs_refcount.c b/fs/xfs/libxfs/xfs_refcount.c index 198f0c96ccae..9e07350159bd 100644 --- a/fs/xfs/libxfs/xfs_refcount.c +++ b/fs/xfs/libxfs/xfs_refcount.c @@ -1560,7 +1560,7 @@ xfs_refcount_alloc_cow_extent( return error; /* Add rmap entry */ - return xfs_rmap_alloc_extent(tp, fsb, len, XFS_RMAP_OWN_COW); + return xfs_rmap_alloc_extent(tp, fsb, len, XFS_RMAP_OWN_COW, false); } /* Forget a CoW staging event in the refcount btree. */ @@ -1577,7 +1577,7 @@ xfs_refcount_free_cow_extent( return 0; /* Remove rmap entry */ - error = xfs_rmap_free_extent(tp, fsb, len, XFS_RMAP_OWN_COW); + error = xfs_rmap_free_extent(tp, fsb, len, XFS_RMAP_OWN_COW, false); if (error) return error; diff --git a/fs/xfs/libxfs/xfs_rmap.c b/fs/xfs/libxfs/xfs_rmap.c index c75d3ba34613..377d4c31d69f 100644 --- a/fs/xfs/libxfs/xfs_rmap.c +++ b/fs/xfs/libxfs/xfs_rmap.c @@ -2331,11 +2331,12 @@ __xfs_rmap_add( enum xfs_rmap_intent_type type, uint64_t owner, int whichfork, - struct xfs_bmbt_irec *bmap) + struct xfs_bmbt_irec *bmap, + bool realtime) { struct xfs_rmap_intent *ri; - trace_xfs_rmap_defer(tp->t_mountp, + trace_xfs_rmap_defer(tp->t_mountp, realtime ? NULLAGNUMBER : XFS_FSB_TO_AGNO(tp->t_mountp, bmap->br_startblock), type, XFS_FSB_TO_AGBNO(tp->t_mountp, bmap->br_startblock), @@ -2350,6 +2351,7 @@ __xfs_rmap_add( ri->ri_owner = owner; ri->ri_whichfork = whichfork; ri->ri_bmap = *bmap; + ri->ri_realtime = realtime; xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_RMAP, &ri->ri_list); return 0; @@ -2368,7 +2370,7 @@ xfs_rmap_map_extent( return __xfs_rmap_add(tp, xfs_is_reflink_inode(ip) ? XFS_RMAP_MAP_SHARED : XFS_RMAP_MAP, ip->i_ino, - whichfork, PREV); + whichfork, PREV, XFS_IS_REALTIME_INODE(ip)); } /* Unmap an extent out of a file. */ @@ -2384,7 +2386,7 @@ xfs_rmap_unmap_extent( return __xfs_rmap_add(tp, xfs_is_reflink_inode(ip) ? XFS_RMAP_UNMAP_SHARED : XFS_RMAP_UNMAP, ip->i_ino, - whichfork, PREV); + whichfork, PREV, XFS_IS_REALTIME_INODE(ip)); } /* @@ -2406,7 +2408,7 @@ xfs_rmap_convert_extent( return __xfs_rmap_add(tp, xfs_is_reflink_inode(ip) ? XFS_RMAP_CONVERT_SHARED : XFS_RMAP_CONVERT, ip->i_ino, - whichfork, PREV); + whichfork, PREV, XFS_IS_REALTIME_INODE(ip)); } /* Schedule the creation of an rmap for non-file data. */ @@ -2415,7 +2417,8 @@ xfs_rmap_alloc_extent( struct xfs_trans *tp, xfs_fsblock_t fsbno, xfs_filblks_t len, - uint64_t owner) + uint64_t owner, + bool isrt) { struct xfs_bmbt_irec bmap; @@ -2427,7 +2430,8 @@ xfs_rmap_alloc_extent( bmap.br_startoff = 0; bmap.br_state = XFS_EXT_NORM; - return __xfs_rmap_add(tp, XFS_RMAP_ALLOC, owner, XFS_DATA_FORK, &bmap); + return __xfs_rmap_add(tp, XFS_RMAP_ALLOC, owner, XFS_DATA_FORK, &bmap, + isrt); } /* Schedule the deletion of an rmap for non-file data. */ @@ -2436,7 +2440,8 @@ xfs_rmap_free_extent( struct xfs_trans *tp, xfs_fsblock_t fsbno, xfs_filblks_t len, - uint64_t owner) + uint64_t owner, + bool isrt) { struct xfs_bmbt_irec bmap; @@ -2448,7 +2453,8 @@ xfs_rmap_free_extent( bmap.br_startoff = 0; bmap.br_state = XFS_EXT_NORM; - return __xfs_rmap_add(tp, XFS_RMAP_FREE, owner, XFS_DATA_FORK, &bmap); + return __xfs_rmap_add(tp, XFS_RMAP_FREE, owner, XFS_DATA_FORK, &bmap, + isrt); } /* Compare rmap records. Returns -1 if a < b, 1 if a > b, and 0 if equal. */ diff --git a/fs/xfs/libxfs/xfs_rmap.h b/fs/xfs/libxfs/xfs_rmap.h index 74f02830edb3..a4d3146e5619 100644 --- a/fs/xfs/libxfs/xfs_rmap.h +++ b/fs/xfs/libxfs/xfs_rmap.h @@ -182,6 +182,7 @@ struct xfs_rmap_intent { uint64_t ri_owner; int ri_whichfork; struct xfs_bmbt_irec ri_bmap; + bool ri_realtime; }; /* functions for updating the rmapbt based on bmbt map/unmap operations */ @@ -193,9 +194,9 @@ int xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_trans *tp, struct xfs_inode *ip, int whichfork, struct xfs_bmbt_irec *imap); int xfs_rmap_alloc_extent(struct xfs_trans *tp, xfs_fsblock_t fsbno, - xfs_filblks_t len, uint64_t owner); + xfs_filblks_t len, uint64_t owner, bool isrt); int xfs_rmap_free_extent(struct xfs_trans *tp, xfs_fsblock_t fsbno, - xfs_filblks_t len, uint64_t owner); + xfs_filblks_t len, uint64_t owner, bool isrt); void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp, struct xfs_btree_cur *rcur, int error); diff --git a/fs/xfs/xfs_rmap_item.c b/fs/xfs/xfs_rmap_item.c index 127dc9c32a54..2fe98a300d0e 100644 --- a/fs/xfs/xfs_rmap_item.c +++ b/fs/xfs/xfs_rmap_item.c @@ -415,6 +415,7 @@ xfs_rui_recover( xfs_exntst_t state; struct xfs_trans *tp; struct xfs_btree_cur *rcur = NULL; + bool rt; ASSERT(!test_bit(XFS_RUI_RECOVERED, &ruip->rui_flags)); @@ -469,6 +470,7 @@ xfs_rui_recover( XFS_EXT_UNWRITTEN : XFS_EXT_NORM; whichfork = (rmap->me_flags & XFS_RMAP_EXTENT_ATTR_FORK) ? XFS_ATTR_FORK : XFS_DATA_FORK; + rt = !!(rmap->me_flags & XFS_RMAP_EXTENT_REALTIME); switch (rmap->me_flags & XFS_RMAP_EXTENT_TYPE_MASK) { case XFS_RMAP_EXTENT_MAP: type = XFS_RMAP_MAP; @@ -501,7 +503,7 @@ xfs_rui_recover( error = xfs_trans_log_finish_rmap_update(tp, rudp, type, rmap->me_owner, whichfork, rmap->me_startoff, rmap->me_startblock, - rmap->me_len, state, &rcur); + rmap->me_len, state, rt, &rcur); if (error) goto abort_error; diff --git a/fs/xfs/xfs_trans.h b/fs/xfs/xfs_trans.h index aded200c59a8..a2b83c6d71ab 100644 --- a/fs/xfs/xfs_trans.h +++ b/fs/xfs/xfs_trans.h @@ -256,7 +256,7 @@ int xfs_trans_log_finish_rmap_update(struct xfs_trans *tp, struct xfs_rud_log_item *rudp, enum xfs_rmap_intent_type type, uint64_t owner, int whichfork, xfs_fileoff_t startoff, xfs_fsblock_t startblock, xfs_filblks_t blockcount, - xfs_exntst_t state, struct xfs_btree_cur **pcur); + xfs_exntst_t state, bool rt, struct xfs_btree_cur **pcur); /* refcount updates */ enum xfs_refcount_intent_type; diff --git a/fs/xfs/xfs_trans_rmap.c b/fs/xfs/xfs_trans_rmap.c index 05b00e40251f..abc673c63dfb 100644 --- a/fs/xfs/xfs_trans_rmap.c +++ b/fs/xfs/xfs_trans_rmap.c @@ -23,13 +23,16 @@ xfs_trans_set_rmap_flags( struct xfs_map_extent *rmap, enum xfs_rmap_intent_type type, int whichfork, - xfs_exntst_t state) + xfs_exntst_t state, + bool rt) { rmap->me_flags = 0; if (state == XFS_EXT_UNWRITTEN) rmap->me_flags |= XFS_RMAP_EXTENT_UNWRITTEN; if (whichfork == XFS_ATTR_FORK) rmap->me_flags |= XFS_RMAP_EXTENT_ATTR_FORK; + if (rt) + rmap->me_flags |= XFS_RMAP_EXTENT_REALTIME; switch (type) { case XFS_RMAP_MAP: rmap->me_flags |= XFS_RMAP_EXTENT_MAP; @@ -88,6 +91,7 @@ xfs_trans_log_finish_rmap_update( xfs_fsblock_t startblock, xfs_filblks_t blockcount, xfs_exntst_t state, + bool rt, struct xfs_btree_cur **pcur) { int error; @@ -176,7 +180,7 @@ xfs_rmap_update_log_item( map->me_startoff = rmap->ri_bmap.br_startoff; map->me_len = rmap->ri_bmap.br_blockcount; xfs_trans_set_rmap_flags(map, rmap->ri_type, rmap->ri_whichfork, - rmap->ri_bmap.br_state); + rmap->ri_bmap.br_state, rmap->ri_realtime); } /* Get an RUD so we can process all the deferred rmap updates. */ @@ -208,6 +212,7 @@ xfs_rmap_update_finish_item( rmap->ri_bmap.br_startblock, rmap->ri_bmap.br_blockcount, rmap->ri_bmap.br_state, + rmap->ri_realtime, (struct xfs_btree_cur **)state); kmem_free(rmap); return error; From patchwork Thu Aug 30 18:32:45 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: 10582551 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 087DB139B for ; Thu, 30 Aug 2018 18:32:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF40F2C0A6 for ; Thu, 30 Aug 2018 18:32:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2EF82C3BC; Thu, 30 Aug 2018 18:32:54 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 8D6802C0A6 for ; Thu, 30 Aug 2018 18:32:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727149AbeH3WgV (ORCPT ); Thu, 30 Aug 2018 18:36:21 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:50512 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeH3WgV (ORCPT ); Thu, 30 Aug 2018 18:36:21 -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 w7UISgew133735 for ; Thu, 30 Aug 2018 18:32:52 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=d5dmfgTStEXqSaTusQU7EtjJ4hYMvfNWFzcnQsTZ3lI=; b=c2HIdPnqCbtVMMWczCLZDtDby/JABuWght3CJViGqRTWU0x5k20qwieERrKOmtH0msfh 5xoRHzx7BmvioVxQUjfYoGwQu4ZW1OUrJQI62bl/w7cm8l3g0fVrTQrrZNY34siugqvO vlrmjv4AkHSqhDLWJKTtIUenVqmI6Mg3n0vMRHI343QLphpKnYa0nMJqdunykKaQHaZm PON12zWWDv4pqd59JEQ8HDKEb6drdbUdgpQfsfTwJyFp2jX6gc8oaFEqn2xxmhaq4iF6 aTBhTMMlF9y/7h6SA21MkcfRXN32l8u8je8CtDyA7tZIe6AfuYumJQLpe2z/DwWxmZvu ow== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2m2yrqpaw4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:52 +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 w7UIWkcr027227 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:46 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIWk9o012930 for ; Thu, 30 Aug 2018 18:32:46 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:32:45 -0700 Subject: [PATCH 10/18] xfs: add realtime rmap btree block detection to log recovery From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:32:45 -0700 Message-ID: <153565396501.32612.14802251387614910570.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=754 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808300185 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 Identify rtrmapbt blocks in the log correctly so that we can validate them during log recovery. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_log_recover.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index db6d380ffa8d..f269c96cb0ab 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c @@ -2302,6 +2302,7 @@ xlog_recover_get_buf_lsn( uuid = &btb->bb_u.s.bb_uuid; break; } + case XFS_RTRMAP_CRC_MAGIC: case XFS_BMAP_CRC_MAGIC: case XFS_BMAP_MAGIC: { struct xfs_btree_block *btb = blk; @@ -2464,6 +2465,9 @@ xlog_recover_validate_buf_type( case XFS_BMAP_MAGIC: bp->b_ops = &xfs_bmbt_buf_ops; break; + case XFS_RTRMAP_CRC_MAGIC: + bp->b_ops = &xfs_rtrmapbt_buf_ops; + break; case XFS_RMAP_CRC_MAGIC: bp->b_ops = &xfs_rmapbt_buf_ops; break; From patchwork Thu Aug 30 18:32:51 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: 10582553 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 4C67D139B for ; Thu, 30 Aug 2018 18:33:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C5662B548 for ; Thu, 30 Aug 2018 18:33:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 306CC2C3BC; Thu, 30 Aug 2018 18:33:01 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 6CE1C2B548 for ; Thu, 30 Aug 2018 18:33:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727622AbeH3Wg1 (ORCPT ); Thu, 30 Aug 2018 18:36:27 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:59396 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeH3Wg1 (ORCPT ); Thu, 30 Aug 2018 18:36:27 -0400 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 w7UIShoh150412 for ; Thu, 30 Aug 2018 18:32:58 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=AqdS+Rprt6/f3EMDjP5/qtniDi52G6HiZrtOm4VDf6Y=; b=ddDvXt8InTg8SvLTi1+6GRYSe6KZk0O7M0KVb7jJeTuPqnI8Uomc0RQqE18HW5ThCKGK jsuO+dNwTCJDx2eTb0acrvFPNvqfzjt7FR/uPZhqzZmcx+YqKVTbitP7aJZ12y2DeOiQ mhQd9GniUD8411stWSnpyI73+JxmU91FrFPtFnaFg7M0TVxPoC+3LRKScN/ywzyD+ont CXSB6sTj8g69PUq53v0QQw+XA95uFhDmawz5PWbf6YJu5I+i3CqmVxjRO3brBZFAe25Y OTbgSrzQmpLRstVkMlAXtvjTht1D4+qRsnbIZP6t2V4UVU1wYoC5WRWIQC32+p0q8UNb wg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2m2xhu6f1s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:58 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIWqOH013505 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:52 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIWqqA020876 for ; Thu, 30 Aug 2018 18:32:52 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:32:51 -0700 Subject: [PATCH 11/18] xfs: add realtime reverse map inode to superblock From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:32:51 -0700 Message-ID: <153565397113.32612.16430496768209026040.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=779 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808300185 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 Add a field to the superblock to record the rt rmapbt inode and load it at mount time. The rtrmapbt inode will have a unique extent format code, which means that we also have to update the inode validation and flush routines to look for it. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_format.h | 10 +++++++++- fs/xfs/libxfs/xfs_inode_buf.c | 6 ++++++ fs/xfs/libxfs/xfs_inode_fork.c | 11 +++++++++++ fs/xfs/libxfs/xfs_rtrmap_btree.c | 2 +- fs/xfs/libxfs/xfs_sb.c | 2 ++ fs/xfs/libxfs/xfs_types.c | 1 + fs/xfs/xfs_inode.c | 9 ++++++++- fs/xfs/xfs_inode_item.c | 2 ++ fs/xfs/xfs_log_recover.c | 14 +++++++++++++- fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_ondisk.h | 2 +- fs/xfs/xfs_rtalloc.c | 21 +++++++++++++++++++++ 12 files changed, 76 insertions(+), 5 deletions(-) diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index ad767b27dbb3..bb5ea9d46c07 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -174,6 +174,7 @@ typedef struct xfs_sb { xfs_ino_t sb_pquotino; /* project quota inode */ xfs_lsn_t sb_lsn; /* last write sequence */ uuid_t sb_meta_uuid; /* metadata file system unique id */ + xfs_ino_t sb_rrmapino; /* realtime reverse map inode */ /* must be padded to 64 bit alignment */ } xfs_sb_t; @@ -261,6 +262,7 @@ typedef struct xfs_dsb { __be64 sb_pquotino; /* project quota inode */ __be64 sb_lsn; /* last write sequence */ uuid_t sb_meta_uuid; /* metadata file system unique id */ + __be64 sb_rrmapino; /* realtime reverse map inode */ /* must be padded to 64 bit alignment */ } xfs_dsb_t; @@ -544,6 +546,11 @@ static inline bool xfs_sb_version_hasrmapbt(struct xfs_sb *sbp) (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_RMAPBT); } +static inline bool xfs_sb_version_hasrtrmapbt(struct xfs_sb *sbp) +{ + return sbp->sb_rblocks > 0 && xfs_sb_version_hasrmapbt(sbp); +} + static inline bool xfs_sb_version_hasreflink(struct xfs_sb *sbp) { return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 && @@ -926,7 +933,8 @@ typedef enum xfs_dinode_fmt { XFS_DINODE_FMT_LOCAL, /* bulk data */ XFS_DINODE_FMT_EXTENTS, /* struct xfs_bmbt_rec */ XFS_DINODE_FMT_BTREE, /* struct xfs_bmdr_block */ - XFS_DINODE_FMT_UUID /* added long ago, but never used */ + XFS_DINODE_FMT_UUID, /* added long ago, but never used */ + XFS_DINODE_FMT_RMAP, /* reverse mapping btree */ } xfs_dinode_fmt_t; /* diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c index 30d1d60f1d46..e33e3fa22b14 100644 --- a/fs/xfs/libxfs/xfs_inode_buf.c +++ b/fs/xfs/libxfs/xfs_inode_buf.c @@ -480,6 +480,12 @@ xfs_dinode_verify( return __this_address; break; case S_IFREG: + if (dip->di_format == XFS_DINODE_FMT_RMAP) { + if (ino != mp->m_sb.sb_rrmapino) + return __this_address; + break; + } + /* fall through */ case S_IFLNK: case S_IFDIR: fa = xfs_dinode_verify_fork(dip, mp, XFS_DATA_FORK); diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index cfb68d4befc4..d1401cbdd266 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -76,6 +76,13 @@ xfs_iformat_fork( case XFS_DINODE_FMT_BTREE: error = xfs_iformat_btree(ip, dip, XFS_DATA_FORK); break; + case XFS_DINODE_FMT_RMAP: + if (!xfs_sb_version_hasrtrmapbt(&ip->i_mount->m_sb)) + return -EFSCORRUPTED; + if (ip->i_ino != ip->i_mount->m_sb.sb_rrmapino) + return -EFSCORRUPTED; + /* to be implemented later */ + break; default: return -EFSCORRUPTED; } @@ -525,6 +532,10 @@ xfs_iflush_fork( } break; + case XFS_DINODE_FMT_RMAP: + /* to be implemented later */ + break; + default: ASSERT(0); break; diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_btree.c index 4529dbc6545c..ce9932397aa1 100644 --- a/fs/xfs/libxfs/xfs_rtrmap_btree.c +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c @@ -331,7 +331,7 @@ xfs_rtrmapbt_verify( if (!xfs_sb_version_hasrmapbt(&mp->m_sb)) return __this_address; - fa = xfs_btree_lblock_v5hdr_verify(bp, XFS_RMAP_OWN_UNKNOWN); + fa = xfs_btree_lblock_v5hdr_verify(bp, mp->m_sb.sb_rrmapino); if (fa) return fa; level = be16_to_cpu(block->bb_level); diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index 733bb7e5409c..e21fc6e0d2aa 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -522,6 +522,7 @@ __xfs_sb_from_disk( uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid); else uuid_copy(&to->sb_meta_uuid, &from->sb_uuid); + to->sb_rrmapino = be64_to_cpu(from->sb_rrmapino); /* Convert on-disk flags to in-memory flags? */ if (convert_xquota) xfs_sb_quota_from_disk(to); @@ -665,6 +666,7 @@ xfs_sb_to_disk( to->sb_lsn = cpu_to_be64(from->sb_lsn); if (xfs_sb_version_hasmetauuid(from)) uuid_copy(&to->sb_meta_uuid, &from->sb_meta_uuid); + to->sb_rrmapino = cpu_to_be64(from->sb_rrmapino); } } diff --git a/fs/xfs/libxfs/xfs_types.c b/fs/xfs/libxfs/xfs_types.c index 33a5ca346baf..3679ca947954 100644 --- a/fs/xfs/libxfs/xfs_types.c +++ b/fs/xfs/libxfs/xfs_types.c @@ -142,6 +142,7 @@ xfs_internal_inum( xfs_ino_t ino) { return ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino || + ino == mp->m_sb.sb_rrmapino || (xfs_sb_version_hasquota(&mp->m_sb) && xfs_is_quota_inode(&mp->m_sb, ino)); } diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 0e142787138c..f53e9488e796 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -3524,7 +3524,14 @@ xfs_iflush_int( __func__, ip->i_ino, be16_to_cpu(dip->di_magic), dip); goto corrupt_out; } - if (S_ISREG(VFS_I(ip)->i_mode)) { + if (ip->i_ino == mp->m_sb.sb_rrmapino) { + if (ip->i_d.di_format != XFS_DINODE_FMT_RMAP) { + xfs_alert_tag(mp, XFS_PTAG_IFLUSH, + "%s: Bad rtrmap inode %llu, ptr 0x%p", + __func__, ip->i_ino, ip); + goto corrupt_out; + } + } else if (S_ISREG(VFS_I(ip)->i_mode)) { if (XFS_TEST_ERROR( (ip->i_d.di_format != XFS_DINODE_FMT_EXTENTS) && (ip->i_d.di_format != XFS_DINODE_FMT_BTREE), diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c index fa1c4fe2ffbf..1d2eb7bf9e04 100644 --- a/fs/xfs/xfs_inode_item.c +++ b/fs/xfs/xfs_inode_item.c @@ -46,6 +46,7 @@ xfs_inode_item_data_fork_size( } break; case XFS_DINODE_FMT_BTREE: + case XFS_DINODE_FMT_RMAP: if ((iip->ili_fields & XFS_ILOG_DBROOT) && ip->i_df.if_broot_bytes > 0) { *nbytes += ip->i_df.if_broot_bytes; @@ -166,6 +167,7 @@ xfs_inode_item_format_data_fork( } break; case XFS_DINODE_FMT_BTREE: + case XFS_DINODE_FMT_RMAP: iip->ili_fields &= ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT | XFS_ILOG_DEV); diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index f269c96cb0ab..95af44487b6c 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c @@ -3123,7 +3123,19 @@ xlog_recover_inode_pass2( /* Take the opportunity to reset the flush iteration count */ ldip->di_flushiter = 0; - if (unlikely(S_ISREG(ldip->di_mode))) { + if (in_f->ilf_ino == mp->m_sb.sb_rrmapino) { + if (ldip->di_format != XFS_DINODE_FMT_RMAP) { + XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(3)", + XFS_ERRLEVEL_LOW, mp, ldip, + sizeof(*ldip)); + xfs_alert(mp, + "%s: Bad rtrmapbt inode log record, rec ptr 0x%p, " + "ino ptr = 0x%p, ino bp = 0x%p, ino %Ld", + __func__, item, dip, bp, in_f->ilf_ino); + error = -EFSCORRUPTED; + goto out_release; + } + } else if (unlikely(S_ISREG(ldip->di_mode))) { if ((ldip->di_format != XFS_DINODE_FMT_EXTENTS) && (ldip->di_format != XFS_DINODE_FMT_BTREE)) { XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(3)", diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index 5a4df6b860e2..712bec475c5d 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -91,6 +91,7 @@ typedef struct xfs_mount { uint m_rsumsize; /* size of rt summary, bytes */ struct xfs_inode *m_rbmip; /* pointer to bitmap inode */ struct xfs_inode *m_rsumip; /* pointer to summary inode */ + struct xfs_inode *m_rrmapip; /* pointer to rmap inode */ struct xfs_inode *m_rootip; /* pointer to root directory */ struct xfs_quotainfo *m_quotainfo; /* disk quota information */ xfs_buftarg_t *m_ddev_targp; /* saves taking the address */ diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h index 23c9b6f047c5..0840ec7e58aa 100644 --- a/fs/xfs/xfs_ondisk.h +++ b/fs/xfs/xfs_ondisk.h @@ -33,7 +33,7 @@ xfs_check_ondisk_structs(void) XFS_CHECK_STRUCT_SIZE(struct xfs_dinode, 176); XFS_CHECK_STRUCT_SIZE(struct xfs_disk_dquot, 104); XFS_CHECK_STRUCT_SIZE(struct xfs_dqblk, 136); - XFS_CHECK_STRUCT_SIZE(struct xfs_dsb, 264); + XFS_CHECK_STRUCT_SIZE(struct xfs_dsb, 272); XFS_CHECK_STRUCT_SIZE(struct xfs_dsymlink_hdr, 56); XFS_CHECK_STRUCT_SIZE(struct xfs_inobt_key, 4); XFS_CHECK_STRUCT_SIZE(struct xfs_inobt_rec, 16); diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 926ed314ffba..1ac69ff79a22 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -1211,6 +1211,25 @@ xfs_rtmount_inodes( return error; } ASSERT(mp->m_rsumip != NULL); + + /* If we have rmap and a realtime device, look for the rtrmapbt. */ + if (xfs_sb_version_hasrmapbt(&mp->m_sb) && mp->m_sb.sb_rblocks > 0) { + ASSERT(sbp->sb_rrmapino != NULLFSINO); + error = xfs_iget(mp, NULL, sbp->sb_rrmapino, 0, 0, + &mp->m_rrmapip); + if (error) { + if (mp->m_rrmapip) + xfs_irele(mp->m_rrmapip); + return error; + } + ASSERT(mp->m_rrmapip != NULL); + if (mp->m_rrmapip->i_d.di_format != XFS_DINODE_FMT_RMAP) { + xfs_irele(mp->m_rrmapip); + mp->m_rrmapip = NULL; + return -EFSCORRUPTED; + } + } + return 0; } @@ -1218,6 +1237,8 @@ void xfs_rtunmount_inodes( struct xfs_mount *mp) { + if (mp->m_rrmapip) + xfs_irele(mp->m_rrmapip); if (mp->m_rbmip) xfs_irele(mp->m_rbmip); if (mp->m_rsumip) From patchwork Thu Aug 30 18:32:57 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: 10582555 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 501E617DB for ; Thu, 30 Aug 2018 18:33:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FC3E2B548 for ; Thu, 30 Aug 2018 18:33:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33DD12C3BC; Thu, 30 Aug 2018 18:33:05 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 3214F2B548 for ; Thu, 30 Aug 2018 18:33:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727502AbeH3Wgb (ORCPT ); Thu, 30 Aug 2018 18:36:31 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:50794 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeH3Wgb (ORCPT ); Thu, 30 Aug 2018 18:36:31 -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 w7UISnI7134057 for ; Thu, 30 Aug 2018 18:33:00 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=ldMkZZx9d1CNOzN6Qn9PlX7Jt9JVcU8f/pWtZNIpHo4=; b=g/IWxYcC4wp9TScuhqda1tTZFuMdJIMCBdZWQXRNaWbzN9B44V3VYbBfp9XB0tNRKW2J nl3yqZ2YyvNDpiU+pZzev1mqd2LCSyW2Tk5RRwS8V3oSBtYXIgMrv6KlctxBIp+SP0eC O112br0zCLJvnvLnOy5ir/abRqnvPfW26YOJUht2ey4GigRkUBFFWRiDIt58p/oSVDAG vbePFxkyS/PJ22N+2YBe2KymOmSn0YT0AAoImNDZoz6OrxlyD4nV2oUh4robyzKead08 4lBDRwaCSfbZ8MI4nOQBEmG8v+UanFNroNpruQjkYd8lKm0e6hHlR8328ithqabVLlbA zw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2m2yrqpaxk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:33:00 +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 w7UIWwVV028203 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:32:59 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIWwcr013001 for ; Thu, 30 Aug 2018 18:32:58 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:32:58 -0700 Subject: [PATCH 12/18] xfs: wire up a new inode fork type for the realtime rmap From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:32:57 -0700 Message-ID: <153565397727.32612.13869252968606257828.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 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-1807170000 definitions=main-1808300185 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 Plumb in the pieces we need to embed the root of the realtime rmap btree in an inode's data fork, complete with new fork type and on-disk interpretation functions. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_format.h | 8 + fs/xfs/libxfs/xfs_inode_fork.c | 48 +++++++ fs/xfs/libxfs/xfs_rtrmap_btree.c | 246 ++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtrmap_btree.h | 51 ++++++++ 4 files changed, 351 insertions(+), 2 deletions(-) diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index bb5ea9d46c07..dcd790f61895 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -1460,6 +1460,14 @@ typedef __be32 xfs_rmap_ptr_t; */ #define XFS_RTRMAP_CRC_MAGIC 0x4d415052 /* 'MAPR' */ +/* + * rtrmap root header, on-disk form only. + */ +struct xfs_rtrmap_root { + __be16 bb_level; /* 0 is a leaf */ + __be16 bb_numrecs; /* current # of data records */ +}; + /* * Data record structure */ diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index d1401cbdd266..65859a518def 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -25,12 +25,14 @@ #include "xfs_dir2_priv.h" #include "xfs_attr_leaf.h" #include "xfs_shared.h" +#include "xfs_rtrmap_btree.h" kmem_zone_t *xfs_ifork_zone; STATIC int xfs_iformat_local(xfs_inode_t *, xfs_dinode_t *, int, int); STATIC int xfs_iformat_extents(xfs_inode_t *, xfs_dinode_t *, int); STATIC int xfs_iformat_btree(xfs_inode_t *, xfs_dinode_t *, int); +STATIC int xfs_iformat_rmap(struct xfs_inode *ip, struct xfs_dinode *dip); /* * Copy inode type and data and attr format specific information from the @@ -81,7 +83,7 @@ xfs_iformat_fork( return -EFSCORRUPTED; if (ip->i_ino != ip->i_mount->m_sb.sb_rrmapino) return -EFSCORRUPTED; - /* to be implemented later */ + error = xfs_iformat_rmap(ip, dip); break; default: return -EFSCORRUPTED; @@ -328,6 +330,37 @@ xfs_iformat_btree( return 0; } +/* The file is a reverse mapping tree. */ +STATIC int +xfs_iformat_rmap( + struct xfs_inode *ip, + struct xfs_dinode *dip) +{ + struct xfs_rtrmap_root *dfp; + struct xfs_ifork *ifp; + /* REFERENCED */ + int size; + int whichfork = XFS_DATA_FORK; + + ifp = XFS_IFORK_PTR(ip, whichfork); + dfp = (struct xfs_rtrmap_root *)XFS_DFORK_PTR(dip, whichfork); + size = XFS_RTRMAP_BROOT_SPACE(dfp); + + ifp->if_broot_bytes = size; + ifp->if_broot = kmem_alloc(size, KM_SLEEP | KM_NOFS); + ASSERT(ifp->if_broot != NULL); + /* + * Copy and convert from the on-disk structure + * to the in-memory structure. + */ + xfs_rtrmapbt_from_disk(ip, dfp, + XFS_DFORK_SIZE(dip, ip->i_mount, whichfork), + ifp->if_broot, size); + ifp->if_flags = XFS_IFBROOT; + + return 0; +} + /* * This is called when the amount of space needed for if_data * is increased or decreased. The change in size is indicated by @@ -533,7 +566,18 @@ xfs_iflush_fork( break; case XFS_DINODE_FMT_RMAP: - /* to be implemented later */ + ASSERT(whichfork == XFS_DATA_FORK); + ASSERT(ip->i_ino == mp->m_sb.sb_rrmapino); + if ((iip->ili_fields & brootflag[whichfork]) && + (ifp->if_broot_bytes > 0)) { + ASSERT(ifp->if_broot != NULL); + ASSERT(XFS_RTRMAP_ROOT_SPACE(ifp->if_broot) <= + XFS_IFORK_SIZE(ip, whichfork)); + xfs_rtrmapbt_to_disk(mp, ifp->if_broot, + ifp->if_broot_bytes, + (struct xfs_rtrmap_root *)cp, + XFS_DFORK_SIZE(dip, mp, whichfork)); + } break; default: diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_btree.c index ce9932397aa1..d04630cb9fd0 100644 --- a/fs/xfs/libxfs/xfs_rtrmap_btree.c +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c @@ -200,6 +200,42 @@ xfs_rtrmapbt_get_maxrecs( return cur->bc_mp->m_rtrmap_mxr[level != 0]; } +/* + * Calculate number of records in a realtime rmap btree inode root. + */ +STATIC int +xfs_rtrmapbt_root_maxrecs( + int blocklen, + bool leaf) +{ + blocklen -= sizeof(struct xfs_rtrmap_root); + + if (leaf) + return blocklen / sizeof(struct xfs_rtrmap_rec); + return blocklen / (2 * sizeof(struct xfs_rtrmap_key) + + sizeof(xfs_rtrmap_ptr_t)); +} + +/* + * Get the maximum records we could store in the on-disk format. + * + * For non-root nodes this is equivalent to xfs_bmbt_get_maxrecs, but + * for the root node this checks the available space in the dinode fork + * so that we can resize the in-memory buffer to match it. After a + * resize to the maximum size this function returns the same value + * as xfs_bmbt_get_maxrecs for the root node, too. + */ +STATIC int +xfs_rtrmapbt_get_dmaxrecs( + struct xfs_btree_cur *cur, + int level) +{ + if (level != cur->bc_nlevels - 1) + return cur->bc_mp->m_rtrmap_mxr[level != 0]; + return xfs_rtrmapbt_root_maxrecs(cur->bc_private.b.forksize, + level == 0); +} + STATIC void xfs_rtrmapbt_init_key_from_rec( union xfs_btree_key *key, @@ -317,6 +353,125 @@ xfs_rtrmapbt_diff_two_keys( return 0; } +/* + * Reallocate the space for if_broot based on the number of records + * being added or deleted as indicated in rec_diff. Move the records + * and pointers in if_broot to fit the new size. When shrinking this + * will eliminate holes between the records and pointers created by + * the caller. When growing this will create holes to be filled in + * by the caller. + * + * The caller must not request to add more records than would fit in + * the on-disk inode root. If the if_broot is currently NULL, then + * if we are adding records, one will be allocated. The caller must also + * not request that the number of records go below zero, although + * it can go to zero. + */ +STATIC void +xfs_rtrmapbt_iroot_realloc( + struct xfs_btree_cur *cur, + int rec_diff) +{ + struct xfs_inode *ip = cur->bc_private.b.ip; + int whichfork = cur->bc_private.b.whichfork; + int cur_max; + struct xfs_ifork *ifp; + struct xfs_btree_block *new_broot; + struct xfs_btree_block *broot; + int new_max; + size_t new_size; + char *np; + char *op; + int level; + + /* + * Handle the degenerate case quietly. + */ + if (rec_diff == 0) + return; + + ifp = XFS_IFORK_PTR(ip, whichfork); + if (rec_diff > 0) { + /* + * If there wasn't any memory allocated before, just + * allocate it now and get out. + */ + if (ifp->if_broot_bytes == 0) { + new_size = XFS_RTRMAP_BROOT_SPACE_CALC(rec_diff, + cur->bc_nlevels - 1); + ifp->if_broot = kmem_alloc(new_size, + KM_SLEEP | KM_NOFS); + ifp->if_broot_bytes = (int)new_size; + return; + } + + /* + * If there is already an existing if_broot, then we need + * to realloc() it and shift the pointers to their new + * location. The records don't change location because + * they are kept butted up against the btree block header. + */ + broot = (struct xfs_btree_block *)ifp->if_broot; + level = be16_to_cpu(broot->bb_level); + cur_max = xfs_rtrmapbt_maxrecs(ifp->if_broot_bytes, level == 0); + new_max = cur_max + rec_diff; + new_size = XFS_RTRMAP_BROOT_SPACE_CALC(new_max, level); + ifp->if_broot = kmem_realloc(ifp->if_broot, new_size, + KM_SLEEP | KM_NOFS); + if (level > 0) { + op = (char *)XFS_RTRMAP_BROOT_PTR_ADDR(ifp->if_broot, + 1, ifp->if_broot_bytes); + np = (char *)XFS_RTRMAP_BROOT_PTR_ADDR(ifp->if_broot, + 1, (int)new_size); + memmove(np, op, cur_max * sizeof(xfs_fsblock_t)); + } + ifp->if_broot_bytes = (int)new_size; + ASSERT(XFS_RTRMAP_ROOT_SPACE(ifp->if_broot) <= + XFS_IFORK_SIZE(ip, whichfork)); + return; + } + + /* + * rec_diff is less than 0. In this case, we are shrinking the + * if_broot buffer. It must already exist. If we go to zero + * records, just get rid of the root and clear the status bit. + */ + ASSERT((ifp->if_broot != NULL) && (ifp->if_broot_bytes > 0)); + broot = (struct xfs_btree_block *)ifp->if_broot; + level = be16_to_cpu(broot->bb_level); + cur_max = xfs_rtrmapbt_maxrecs(ifp->if_broot_bytes, level == 0); + new_max = cur_max + rec_diff; + if (new_max < 0) + new_max = 0; + new_size = XFS_RTRMAP_BROOT_SPACE_CALC(new_max, level); + new_broot = kmem_alloc(new_size, KM_SLEEP | KM_NOFS); + memcpy(new_broot, ifp->if_broot, XFS_RTRMAP_BLOCK_LEN); + + /* Copy the records or keys and pointers. */ + if (level > 0) { + op = (char *)XFS_RTRMAP_KEY_ADDR(ifp->if_broot, 1); + np = (char *)XFS_RTRMAP_KEY_ADDR(new_broot, 1); + memcpy(np, op, new_max * 2 * sizeof(struct xfs_rtrmap_key)); + + op = (char *)XFS_RTRMAP_BROOT_PTR_ADDR(ifp->if_broot, 1, + ifp->if_broot_bytes); + np = (char *)XFS_RTRMAP_BROOT_PTR_ADDR(new_broot, 1, + (int)new_size); + memcpy(np, op, new_max * sizeof(xfs_fsblock_t)); + } else { + op = (char *)XFS_RTRMAP_REC_ADDR(ifp->if_broot, 1); + np = (char *)XFS_RTRMAP_REC_ADDR(new_broot, 1); + memcpy(np, op, new_max * sizeof(struct xfs_rtrmap_rec)); + } + + kmem_free(ifp->if_broot); + ifp->if_broot = new_broot; + ifp->if_broot_bytes = (int)new_size; + if (ifp->if_broot) + ASSERT(XFS_RTRMAP_ROOT_SPACE(ifp->if_broot) <= + XFS_IFORK_SIZE(ip, whichfork)); +} + static xfs_failaddr_t xfs_rtrmapbt_verify( struct xfs_buf *bp) @@ -427,12 +582,14 @@ static const struct xfs_btree_ops xfs_rtrmapbt_ops = { .free_block = xfs_rtrmapbt_free_block, .get_minrecs = xfs_rtrmapbt_get_minrecs, .get_maxrecs = xfs_rtrmapbt_get_maxrecs, + .get_dmaxrecs = xfs_rtrmapbt_get_dmaxrecs, .init_key_from_rec = xfs_rtrmapbt_init_key_from_rec, .init_high_key_from_rec = xfs_rtrmapbt_init_high_key_from_rec, .init_rec_from_cur = xfs_rtrmapbt_init_rec_from_cur, .init_ptr_from_cur = xfs_rtrmapbt_init_ptr_from_cur, .key_diff = xfs_rtrmapbt_key_diff, .buf_ops = &xfs_rtrmapbt_buf_ops, + .iroot_realloc = xfs_rtrmapbt_iroot_realloc, .diff_two_keys = xfs_rtrmapbt_diff_two_keys, .keys_inorder = xfs_rtrmapbt_keys_inorder, .recs_inorder = xfs_rtrmapbt_recs_inorder, @@ -496,3 +653,92 @@ xfs_rtrmapbt_compute_maxlevels( mp->m_sb.sb_rblocks); ASSERT(mp->m_rtrmap_maxlevels <= XFS_BTREE_MAXLEVELS); } + +/* + * Convert on-disk form of btree root to in-memory form. + */ +void +xfs_rtrmapbt_from_disk( + struct xfs_inode *ip, + struct xfs_rtrmap_root *dblock, + int dblocklen, + struct xfs_btree_block *rblock, + int rblocklen) +{ + struct xfs_mount *mp = ip->i_mount; + int dmxr; + struct xfs_rtrmap_key *fkp; + __be64 *fpp; + struct xfs_rtrmap_key *tkp; + __be64 *tpp; + struct xfs_rtrmap_rec *frp; + struct xfs_rtrmap_rec *trp; + + xfs_btree_init_block_int(mp, rblock, XFS_BUF_DADDR_NULL, + XFS_BTNUM_RTRMAP, 0, 0, ip->i_ino, + XFS_BTREE_LONG_PTRS | XFS_BTREE_CRC_BLOCKS); + + rblock->bb_level = dblock->bb_level; + rblock->bb_numrecs = dblock->bb_numrecs; + + if (be16_to_cpu(rblock->bb_level) > 0) { + dmxr = xfs_rtrmapbt_maxrecs(dblocklen, 0); + fkp = XFS_RTRMAP_ROOT_KEY_ADDR(dblock, 1); + tkp = XFS_RTRMAP_KEY_ADDR(rblock, 1); + fpp = XFS_RTRMAP_ROOT_PTR_ADDR(dblock, 1, dmxr); + tpp = XFS_RTRMAP_BROOT_PTR_ADDR(rblock, 1, rblocklen); + dmxr = be16_to_cpu(dblock->bb_numrecs); + memcpy(tkp, fkp, 2 * sizeof(*fkp) * dmxr); + memcpy(tpp, fpp, sizeof(*fpp) * dmxr); + } else { + frp = XFS_RTRMAP_ROOT_REC_ADDR(dblock, 1); + trp = XFS_RTRMAP_REC_ADDR(rblock, 1); + dmxr = be16_to_cpu(dblock->bb_numrecs); + memcpy(trp, frp, sizeof(*frp) * dmxr); + } +} + +/* + * Convert in-memory form of btree root to on-disk form. + */ +void +xfs_rtrmapbt_to_disk( + struct xfs_mount *mp, + struct xfs_btree_block *rblock, + int rblocklen, + struct xfs_rtrmap_root *dblock, + int dblocklen) +{ + int dmxr; + struct xfs_rtrmap_key *fkp; + __be64 *fpp; + struct xfs_rtrmap_key *tkp; + __be64 *tpp; + struct xfs_rtrmap_rec *frp; + struct xfs_rtrmap_rec *trp; + + ASSERT(rblock->bb_magic == cpu_to_be32(XFS_RTRMAP_CRC_MAGIC)); + ASSERT(uuid_equal(&rblock->bb_u.l.bb_uuid, &mp->m_sb.sb_meta_uuid)); + ASSERT(rblock->bb_u.l.bb_blkno == cpu_to_be64(XFS_BUF_DADDR_NULL)); + ASSERT(rblock->bb_u.l.bb_leftsib == cpu_to_be64(NULLFSBLOCK)); + ASSERT(rblock->bb_u.l.bb_rightsib == cpu_to_be64(NULLFSBLOCK)); + + dblock->bb_level = rblock->bb_level; + dblock->bb_numrecs = rblock->bb_numrecs; + + if (be16_to_cpu(rblock->bb_level) > 0) { + dmxr = xfs_rtrmapbt_maxrecs(dblocklen, 0); + fkp = XFS_RTRMAP_KEY_ADDR(rblock, 1); + tkp = XFS_RTRMAP_ROOT_KEY_ADDR(dblock, 1); + fpp = XFS_RTRMAP_BROOT_PTR_ADDR(rblock, 1, rblocklen); + tpp = XFS_RTRMAP_ROOT_PTR_ADDR(dblock, 1, dmxr); + dmxr = be16_to_cpu(rblock->bb_numrecs); + memcpy(tkp, fkp, 2 * sizeof(*fkp) * dmxr); + memcpy(tpp, fpp, sizeof(*fpp) * dmxr); + } else { + frp = XFS_RTRMAP_REC_ADDR(rblock, 1); + trp = XFS_RTRMAP_ROOT_REC_ADDR(dblock, 1); + dmxr = be16_to_cpu(rblock->bb_numrecs); + memcpy(trp, frp, sizeof(*frp) * dmxr); + } +} diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.h b/fs/xfs/libxfs/xfs_rtrmap_btree.h index 4b32823a2ec6..321be07d1cd1 100644 --- a/fs/xfs/libxfs/xfs_rtrmap_btree.h +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.h @@ -40,9 +40,60 @@ struct xfs_mount; (maxrecs) * 2 * sizeof(struct xfs_rtrmap_key) + \ ((index) - 1) * sizeof(xfs_rtrmap_ptr_t))) +/* Macros for handling the inode root */ + +#define XFS_RTRMAP_ROOT_REC_ADDR(block, index) \ + ((struct xfs_rtrmap_rec *) \ + ((char *)(block) + \ + sizeof(struct xfs_rtrmap_root) + \ + ((index) - 1) * sizeof(struct xfs_rtrmap_rec))) + +#define XFS_RTRMAP_ROOT_KEY_ADDR(block, index) \ + ((struct xfs_rtrmap_key *) \ + ((char *)(block) + \ + sizeof(struct xfs_rtrmap_root) + \ + ((index) - 1) * 2 * sizeof(struct xfs_rtrmap_key))) + +#define XFS_RTRMAP_ROOT_PTR_ADDR(block, index, maxrecs) \ + ((xfs_rtrmap_ptr_t *) \ + ((char *)(block) + \ + sizeof(struct xfs_rtrmap_root) + \ + (maxrecs) * 2 * sizeof(struct xfs_rtrmap_key) + \ + ((index) - 1) * sizeof(xfs_rtrmap_ptr_t))) + +#define XFS_RTRMAP_BROOT_PTR_ADDR(bb, i, sz) \ + XFS_RTRMAP_PTR_ADDR(bb, i, xfs_rtrmapbt_maxrecs(sz, 0)) + +#define XFS_RTRMAP_BROOT_SPACE_CALC(nrecs, level) \ + (int)(XFS_RTRMAP_BLOCK_LEN + ((level) > 0 ? \ + ((nrecs) * (2 * sizeof(struct xfs_rtrmap_key) + \ + sizeof(xfs_rtrmap_ptr_t))) : \ + ((nrecs) * sizeof(struct xfs_rtrmap_rec)))) + +#define XFS_RTRMAP_BROOT_SPACE(bb) \ + (XFS_RTRMAP_BROOT_SPACE_CALC(be16_to_cpu((bb)->bb_numrecs), \ + be16_to_cpu((bb)->bb_level))) + +#define XFS_RTRMAP_ROOT_SPACE_CALC(nrecs, level) \ + (int)(sizeof(struct xfs_rtrmap_root) + ((level) > 0 ? \ + ((nrecs) * (2 * sizeof(struct xfs_rtrmap_key) + \ + sizeof(xfs_rtrmap_ptr_t))) : \ + ((nrecs) * sizeof(struct xfs_rtrmap_rec)))) + +#define XFS_RTRMAP_ROOT_SPACE(bb) \ + (XFS_RTRMAP_ROOT_SPACE_CALC(be16_to_cpu((bb)->bb_numrecs), \ + be16_to_cpu((bb)->bb_level))) + struct xfs_btree_cur *xfs_rtrmapbt_init_cursor(struct xfs_mount *mp, struct xfs_trans *tp, struct xfs_inode *ip); int xfs_rtrmapbt_maxrecs(int blocklen, bool leaf); void xfs_rtrmapbt_compute_maxlevels(struct xfs_mount *mp); +void xfs_rtrmapbt_from_disk(struct xfs_inode *ip, + struct xfs_rtrmap_root *dblock, int dblocklen, + struct xfs_btree_block *rblock, int rblocklen); +void xfs_rtrmapbt_to_disk(struct xfs_mount *mp, + struct xfs_btree_block *rblock, int rblocklen, + struct xfs_rtrmap_root *dblock, int dblocklen); + #endif /* __XFS_RTRMAP_BTREE_H__ */ From patchwork Thu Aug 30 18:33: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: 10582557 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 715DE17DB for ; Thu, 30 Aug 2018 18:33:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5864F2B548 for ; Thu, 30 Aug 2018 18:33:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B8B32C3BC; Thu, 30 Aug 2018 18:33:13 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 9C5632B548 for ; Thu, 30 Aug 2018 18:33:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727488AbeH3Wgj (ORCPT ); Thu, 30 Aug 2018 18:36:39 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51158 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbeH3Wgj (ORCPT ); Thu, 30 Aug 2018 18:36:39 -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 w7UISre0134074 for ; Thu, 30 Aug 2018 18:33:10 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=tF2fbqUacUeebSEBxX6j0kRRlKa/sega3dGsADtY+E0=; b=etWE5hQ78/FHXtV/6Dm9aW7hHOEaOE6IbRv9LsWr1bRvtM+wQ0tDS74NJC+CUewPLWEh AVGLXTWCEGhkRrcqsetNrXc/YF2XD7VzxOBcTWRTH+8sBQ9MdJUhqS9ZQKnbIjCn1xF4 z88KJNiVJV6kxqUI7QQ5zghM0zWuDvVPQo/42bpcwwr19lVBIrMd9qOfJUkSGq5/wIto vYIkIfBvHBPoarMvZ3m+AbnCoC59c5mjysBUNZD5U9o7tWAhlnDIbLy6Z1E60umS5n7B p/lgl9dnABPNVwqkbN09RoHKVaS6iqw3Uxv4CiQq62SYQTIxjBSvcD5V3m4EuVqjsbz8 Fw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2m2yrqpb0h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:33:10 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIX5GH014610 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:33:05 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIX4aU013017 for ; Thu, 30 Aug 2018 18:33:04 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:33:04 -0700 Subject: [PATCH 13/18] xfs: wire up rmap map and unmap to the realtime rmapbt From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:33:03 -0700 Message-ID: <153565398352.32612.13948504508159977830.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 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-1807170000 definitions=main-1808300185 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 Connect the map and unmap reverse-mapping operations to the realtime rmapbt via the deferred operation callbacks. This enables us to perform rmap operations against the correct btree. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_rmap.c | 62 ++++++++++++++++++++++++++++++---------------- fs/xfs/libxfs/xfs_rmap.h | 2 + fs/xfs/xfs_log_recover.c | 6 ++-- fs/xfs/xfs_rmap_item.c | 11 +++++++- fs/xfs/xfs_rmap_item.h | 2 + fs/xfs/xfs_trans_rmap.c | 2 + 6 files changed, 56 insertions(+), 29 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rmap.c b/fs/xfs/libxfs/xfs_rmap.c index 377d4c31d69f..7151c284a415 100644 --- a/fs/xfs/libxfs/xfs_rmap.c +++ b/fs/xfs/libxfs/xfs_rmap.c @@ -28,6 +28,7 @@ #include "xfs_bmap.h" #include "xfs_inode.h" #include "xfs_ialloc.h" +#include "xfs_rtrmap_btree.h" /* By convention, the rtrmapbt's "AG" number is NULLAGNUMBER. */ static xfs_agnumber_t @@ -2190,13 +2191,14 @@ xfs_rmap_finish_one_cleanup( struct xfs_btree_cur *rcur, int error) { - struct xfs_buf *agbp; + struct xfs_buf *agbp = NULL; if (rcur == NULL) return; - agbp = rcur->bc_private.a.agbp; + if (!(rcur->bc_flags & XFS_BTREE_LONG_PTRS)) + agbp = rcur->bc_private.a.agbp; xfs_btree_del_cursor(rcur, error); - if (error) + if (error && agbp) xfs_trans_brelse(tp, agbp); } @@ -2217,20 +2219,21 @@ xfs_rmap_finish_one( xfs_fsblock_t startblock, xfs_filblks_t blockcount, xfs_exntst_t state, + bool realtime, struct xfs_btree_cur **pcur) { struct xfs_mount *mp = tp->t_mountp; struct xfs_btree_cur *rcur; struct xfs_buf *agbp = NULL; + int lockmode; int error = 0; xfs_agnumber_t agno; struct xfs_owner_info oinfo; xfs_fsblock_t bno; bool unwritten; - agno = XFS_FSB_TO_AGNO(mp, startblock); - ASSERT(agno != NULLAGNUMBER); - bno = XFS_FSB_TO_AGBNO(mp, startblock); + agno = realtime ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp, startblock); + bno = realtime ? startblock : XFS_FSB_TO_AGBNO(mp, startblock); trace_xfs_rmap_deferred(mp, agno, type, bno, owner, whichfork, startoff, blockcount, state); @@ -2249,31 +2252,44 @@ xfs_rmap_finish_one( *pcur = NULL; } if (rcur == NULL) { - /* - * Refresh the freelist before we start changing the - * rmapbt, because a shape change could cause us to - * allocate blocks. - */ - error = xfs_free_extent_fix_freelist(tp, agno, &agbp); - if (error) - return error; - if (!agbp) - return -EFSCORRUPTED; - - rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, agno); - if (!rcur) { - error = -ENOMEM; - goto out_cur; + if (realtime) { + lockmode = XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP; + xfs_ilock(mp->m_rrmapip, lockmode); + xfs_trans_ijoin(tp, mp->m_rrmapip, lockmode); + rcur = xfs_rtrmapbt_init_cursor(mp, tp, mp->m_rrmapip); + if (!rcur) { + error = -ENOMEM; + goto out_cur; + } + rcur->bc_private.b.flags = 0; + } else { + /* + * Refresh the freelist before we start changing the + * rmapbt, because a shape change could cause us to + * allocate blocks. + */ + error = xfs_free_extent_fix_freelist(tp, agno, &agbp); + if (error) + return error; + if (!agbp) + return -EFSCORRUPTED; + + rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, agno); + if (!rcur) { + error = -ENOMEM; + goto out_cur; + } } } *pcur = rcur; xfs_rmap_ino_owner(&oinfo, owner, whichfork, startoff); unwritten = state == XFS_EXT_UNWRITTEN; - bno = XFS_FSB_TO_AGBNO(rcur->bc_mp, startblock); switch (type) { case XFS_RMAP_ALLOC: + ASSERT(!realtime); + /* fall through */ case XFS_RMAP_MAP: error = xfs_rmap_map(rcur, bno, blockcount, unwritten, &oinfo); break; @@ -2282,6 +2298,8 @@ xfs_rmap_finish_one( &oinfo); break; case XFS_RMAP_FREE: + ASSERT(!realtime); + /* fall through */ case XFS_RMAP_UNMAP: error = xfs_rmap_unmap(rcur, bno, blockcount, unwritten, &oinfo); diff --git a/fs/xfs/libxfs/xfs_rmap.h b/fs/xfs/libxfs/xfs_rmap.h index a4d3146e5619..88075a8db153 100644 --- a/fs/xfs/libxfs/xfs_rmap.h +++ b/fs/xfs/libxfs/xfs_rmap.h @@ -203,7 +203,7 @@ void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp, int xfs_rmap_finish_one(struct xfs_trans *tp, enum xfs_rmap_intent_type type, uint64_t owner, int whichfork, xfs_fileoff_t startoff, xfs_fsblock_t startblock, xfs_filblks_t blockcount, - xfs_exntst_t state, struct xfs_btree_cur **pcur); + xfs_exntst_t state, bool realtime, struct xfs_btree_cur **pcur); int xfs_rmap_find_left_neighbor(struct xfs_btree_cur *cur, xfs_fsblock_t bno, uint64_t owner, uint64_t offset, unsigned int flags, diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index 95af44487b6c..34451a777709 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c @@ -4709,7 +4709,7 @@ xlog_recover_cancel_efi( /* Recover the RUI if necessary. */ STATIC int xlog_recover_process_rui( - struct xfs_mount *mp, + struct xfs_trans *parent_tp, struct xfs_ail *ailp, struct xfs_log_item *lip) { @@ -4724,7 +4724,7 @@ xlog_recover_process_rui( return 0; spin_unlock(&ailp->ail_lock); - error = xfs_rui_recover(mp, ruip); + error = xfs_rui_recover(parent_tp, ruip); spin_lock(&ailp->ail_lock); return error; @@ -4953,7 +4953,7 @@ xlog_recover_process_intents( error = xlog_recover_process_efi(log->l_mp, ailp, lip); break; case XFS_LI_RUI: - error = xlog_recover_process_rui(log->l_mp, ailp, lip); + error = xlog_recover_process_rui(parent_tp, ailp, lip); break; case XFS_LI_CUI: error = xlog_recover_process_cui(parent_tp, ailp, lip); diff --git a/fs/xfs/xfs_rmap_item.c b/fs/xfs/xfs_rmap_item.c index 2fe98a300d0e..bc4d1e7ae602 100644 --- a/fs/xfs/xfs_rmap_item.c +++ b/fs/xfs/xfs_rmap_item.c @@ -401,7 +401,7 @@ xfs_rud_init( */ int xfs_rui_recover( - struct xfs_mount *mp, + struct xfs_trans *parent_tp, struct xfs_rui_log_item *ruip) { int i; @@ -415,6 +415,7 @@ xfs_rui_recover( xfs_exntst_t state; struct xfs_trans *tp; struct xfs_btree_cur *rcur = NULL; + struct xfs_mount *mp = parent_tp->t_mountp; bool rt; ASSERT(!test_bit(XFS_RUI_RECOVERED, &ruip->rui_flags)); @@ -462,6 +463,12 @@ xfs_rui_recover( mp->m_rmap_maxlevels, 0, XFS_TRANS_RESERVE, &tp); if (error) return error; + /* + * Recovery stashes all deferred ops during intent processing and + * finishes them on completion. Transfer current dfops state to this + * transaction and transfer the result back before we return. + */ + xfs_defer_move(tp, parent_tp); rudp = xfs_trans_get_rud(tp, ruip); for (i = 0; i < ruip->rui_format.rui_nextents; i++) { @@ -511,10 +518,12 @@ xfs_rui_recover( xfs_rmap_finish_one_cleanup(tp, rcur, error); set_bit(XFS_RUI_RECOVERED, &ruip->rui_flags); + xfs_defer_move(parent_tp, tp); error = xfs_trans_commit(tp); return error; abort_error: + xfs_defer_move(parent_tp, tp); xfs_rmap_finish_one_cleanup(tp, rcur, error); xfs_trans_cancel(tp); return error; diff --git a/fs/xfs/xfs_rmap_item.h b/fs/xfs/xfs_rmap_item.h index 7e482baa27f5..6e61d13f3c3c 100644 --- a/fs/xfs/xfs_rmap_item.h +++ b/fs/xfs/xfs_rmap_item.h @@ -84,6 +84,6 @@ int xfs_rui_copy_format(struct xfs_log_iovec *buf, struct xfs_rui_log_format *dst_rui_fmt); void xfs_rui_item_free(struct xfs_rui_log_item *); void xfs_rui_release(struct xfs_rui_log_item *); -int xfs_rui_recover(struct xfs_mount *mp, struct xfs_rui_log_item *ruip); +int xfs_rui_recover(struct xfs_trans *parent_tp, struct xfs_rui_log_item *ruip); #endif /* __XFS_RMAP_ITEM_H__ */ diff --git a/fs/xfs/xfs_trans_rmap.c b/fs/xfs/xfs_trans_rmap.c index abc673c63dfb..6aed8841a63f 100644 --- a/fs/xfs/xfs_trans_rmap.c +++ b/fs/xfs/xfs_trans_rmap.c @@ -97,7 +97,7 @@ xfs_trans_log_finish_rmap_update( int error; error = xfs_rmap_finish_one(tp, type, owner, whichfork, startoff, - startblock, blockcount, state, pcur); + startblock, blockcount, state, rt, pcur); /* * Mark the transaction dirty, even on error. This ensures the From patchwork Thu Aug 30 18:33:09 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: 10582559 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 86A09139B for ; Thu, 30 Aug 2018 18:33:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 785CB2B548 for ; Thu, 30 Aug 2018 18:33:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CA2F2C03A; Thu, 30 Aug 2018 18:33:14 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 4BF5F2C3C4 for ; Thu, 30 Aug 2018 18:33:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726727AbeH3Wgk (ORCPT ); Thu, 30 Aug 2018 18:36:40 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:59668 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727359AbeH3Wgk (ORCPT ); Thu, 30 Aug 2018 18:36:40 -0400 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 w7UISxp5150573 for ; Thu, 30 Aug 2018 18:33:11 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=2vHAJhaRCj0vyHhqJGY19q++o2EAPgbI4VXj3MkF5nE=; b=ioeZuCg8mJyDX3wXh2TqGvzblMd3E0blHPYUH5pz0QfsLXAVQ9J72Lf1twk1wEMOA1KC EHaJMnQZpd5ipFVBc6yYYIdBAZ1GeoJN66BkNY1Bc3eL/yM/PmD2PksMknT8lJwkU8hm +baH0E8ePHb2SPoSbUHu6sGkX9VJSZNcjWMFiu96Nhb4pbW5KXzEI+UJAoEtu5FkHa40 SaWeaJ6xFmeqZ2T3kKIwPfeD4deQEBNmKqhX8sN/MiZFIf+vu6lGFBEjQJjOsu+0EXgd pfxcZf1mirSlkRKFsiJZufDsxrwSmgUBFgTXeXRyzrQjhrzrl0dEVjHwJtWAGwjw9gb8 Xg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2m2xhu6f3s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:33:11 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIXBna015095 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:33:11 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w7UIXA9m019933 for ; Thu, 30 Aug 2018 18:33:10 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:33:10 -0700 Subject: [PATCH 14/18] xfs: enable realtime rmap btree From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:33:09 -0700 Message-ID: <153565398972.32612.16225058597323951052.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=706 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808300185 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 Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_super.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index b73eb01f95f3..0b54e74b87ef 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1798,13 +1798,6 @@ xfs_fs_fill_super( goto out_filestream_unmount; } - if (xfs_sb_version_hasrmapbt(&mp->m_sb) && mp->m_sb.sb_rblocks) { - xfs_alert(mp, - "reverse mapping btree not compatible with realtime device!"); - error = -EINVAL; - goto out_filestream_unmount; - } - error = xfs_mountfs(mp); if (error) goto out_filestream_unmount; From patchwork Thu Aug 30 18:33:15 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: 10582561 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 F0A8D17DB for ; Thu, 30 Aug 2018 18:33:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E01FE2B548 for ; Thu, 30 Aug 2018 18:33:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D48FE2C3BC; Thu, 30 Aug 2018 18:33:19 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 755992B548 for ; Thu, 30 Aug 2018 18:33:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727359AbeH3Wgq (ORCPT ); Thu, 30 Aug 2018 18:36:46 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:59672 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727054AbeH3Wgq (ORCPT ); Thu, 30 Aug 2018 18:36:46 -0400 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 w7UIScPF180304 for ; Thu, 30 Aug 2018 18:33:17 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=ODuNPc87C1szHuWV4zfnhauZ1mJkS32DFOlBablxXIU=; b=qUElthCP0F9/qkYoGlTfxmdilf2IutotfyaFTvaW0rtY6Dno0mhm0PUVskgxW0eU8xzH a7b2KRYkqj+4u3jdgbCtULjbzuQb8JSfU6xn0hluOivmXVWWKmeNdNHkHPrtt/UEGmRQ DVV8cpPRIlZ5lAM+5m0/wR8JnT81XDXRMlVczBMkYtaY/8w11IiD0YaskCsyyWeEGStF 8LegEusiFloAI2Ac/XqSt+Z2g4e0i+MtAoAQiTRqB/BTs5/xBJeeTnuzLIroZCbIwM/8 OqQRh1NhAsnsWkuFAbZOL0j9CJJgdcq79cZt6t0mBhXM9gtVN3X6tLpOaSx1fXvLwfUZ +Q== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2m2y2pxejc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:33:17 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIXGiY029351 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:33:17 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIXGCe020999 for ; Thu, 30 Aug 2018 18:33:16 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:33:16 -0700 Subject: [PATCH 15/18] xfs: wire up getfsmap to the realtime reverse mapping btree From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:33:15 -0700 Message-ID: <153565399579.32612.7669386581471553880.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=956 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808300185 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 Connect the getfsmap ioctl to the realtime rmapbt. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_fsmap.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c index 3d76a9e35870..b63435b1df2e 100644 --- a/fs/xfs/xfs_fsmap.c +++ b/fs/xfs/xfs_fsmap.c @@ -28,6 +28,7 @@ #include "xfs_refcount_btree.h" #include "xfs_alloc_btree.h" #include "xfs_rtalloc.h" +#include "xfs_rtrmap_btree.h" /* Convert an xfs_fsmap to an fsmap. */ void @@ -550,7 +551,65 @@ xfs_getfsmap_rtdev_rtbitmap( return __xfs_getfsmap_rtdev(tp, keys, xfs_getfsmap_rtdev_rtbitmap_query, info); } -#endif /* CONFIG_XFS_RT */ + +/* Transform a absolute-startblock rmap (rtdev, logdev) into a fsmap */ +STATIC int +xfs_getfsmap_rtdev_helper( + struct xfs_btree_cur *cur, + struct xfs_rmap_irec *rec, + void *priv) +{ + struct xfs_mount *mp = cur->bc_mp; + struct xfs_getfsmap_info *info = priv; + xfs_daddr_t rec_daddr; + + rec_daddr = XFS_FSB_TO_BB(mp, rec->rm_startblock); + + return xfs_getfsmap_helper(cur->bc_tp, info, rec, rec_daddr); +} + +/* Actually query the rtrmap btree. */ +STATIC int +xfs_getfsmap_rtdev_rmapbt_query( + struct xfs_trans *tp, + struct xfs_getfsmap_info *info) +{ + struct xfs_mount *mp = tp->t_mountp; + struct xfs_btree_cur *bt_cur; + int error; + + /* Query the rtrmapbt */ + xfs_ilock(mp->m_rrmapip, XFS_ILOCK_SHARED); + bt_cur = xfs_rtrmapbt_init_cursor(mp, tp, mp->m_rrmapip); + error = xfs_rmap_query_range(bt_cur, &info->low, &info->high, + xfs_getfsmap_rtdev_helper, info); + if (error) + goto err; + + /* Report any gaps at the end of the rtrmapbt */ + info->last = true; + error = xfs_getfsmap_rtdev_helper(bt_cur, &info->high, info); + if (error) + goto err; + +err: + xfs_btree_del_cursor(bt_cur, error); + xfs_iunlock(mp->m_rrmapip, XFS_ILOCK_SHARED); + return error; +} + +/* Execute a getfsmap query against the realtime device rmapbt. */ +STATIC int +xfs_getfsmap_rtdev_rmapbt( + struct xfs_trans *tp, + struct xfs_fsmap *keys, + struct xfs_getfsmap_info *info) +{ + info->missing_owner = XFS_FMR_OWN_FREE; + return __xfs_getfsmap_rtdev(tp, keys, xfs_getfsmap_rtdev_rmapbt_query, + info); +} +#endif /* Execute a getfsmap query against the regular data device. */ STATIC int @@ -854,7 +913,10 @@ xfs_getfsmap( #ifdef CONFIG_XFS_RT if (mp->m_rtdev_targp) { handlers[2].dev = new_encode_dev(mp->m_rtdev_targp->bt_dev); - handlers[2].fn = xfs_getfsmap_rtdev_rtbitmap; + if (use_rmap) + handlers[2].fn = xfs_getfsmap_rtdev_rmapbt; + else + handlers[2].fn = xfs_getfsmap_rtdev_rtbitmap; } #endif /* CONFIG_XFS_RT */ From patchwork Thu Aug 30 18:33:21 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: 10582565 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 DB9E8139B for ; Thu, 30 Aug 2018 18:33:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBDAC2C03A for ; Thu, 30 Aug 2018 18:33:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C07AD2C3C7; Thu, 30 Aug 2018 18:33:33 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 9F4F32C3C6 for ; Thu, 30 Aug 2018 18:33:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727054AbeH3WhA (ORCPT ); Thu, 30 Aug 2018 18:37:00 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51784 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727521AbeH3Wg7 (ORCPT ); Thu, 30 Aug 2018 18:36:59 -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 w7UISg3V133736 for ; Thu, 30 Aug 2018 18:33:30 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=IsAs9Z1Q7k6WWqNvSVCjszV6lnO5azdmJXZgnwpGPoc=; b=BXlHlaoGJe+p/H6spzGxRXNctaJgyqDGnG5UL8pxYh+eOXtoVkKrrWUojJnAn9hrDRD2 C9X8t9qXWGsJh3PMwH6RqVfDjpNJeGC/3uG+CwDUsuC5mak1NIYiCmrjqjjnQccKZt7Q kv37EjXGyjEcZGreYqFjIIgsZLRn42LDN5rTIjb5wBDElabNfOdOyd3O+3E+971duc6P meRZxK3ip0zM+EJaednbaKkqnkWEFwBoCSi36/VfBKLRZ4U2CoQBGlN3FAgzR0hSUX0s LiS+hY5sGmORR+Nd4DCnefeRFCx/FoCHxNq4lrUM4kHZQdobaEuSnE8FUTe808hnovXB hQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2m2yrqpb25-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:33:30 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIXOi4026482 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:33:24 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w7UIXNIj020094 for ; Thu, 30 Aug 2018 18:33:23 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:33:23 -0700 Subject: [PATCH 16/18] xfs: scrub the realtime rmapbt From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:33:21 -0700 Message-ID: <153565400192.32612.147987129357562666.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 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-1807170000 definitions=main-1808300185 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 Check the realtime reverse mapping btree against the rtbitmap, and modify the rtbitmap scrub to check against the rtrmapbt. Signed-off-by: Darrick J. Wong --- fs/xfs/Makefile | 5 ++ fs/xfs/libxfs/xfs_fs.h | 3 + fs/xfs/scrub/bmap.c | 1 fs/xfs/scrub/common.h | 6 +++ fs/xfs/scrub/rtrmap.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/scrub.c | 7 +++ fs/xfs/scrub/scrub.h | 6 +++ 7 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 fs/xfs/scrub/rtrmap.c diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile index c9b452646699..8aa72dc8be83 100644 --- a/fs/xfs/Makefile +++ b/fs/xfs/Makefile @@ -159,7 +159,10 @@ xfs-y += $(addprefix scrub/, \ symlink.o \ ) -xfs-$(CONFIG_XFS_RT) += scrub/rtbitmap.o +xfs-$(CONFIG_XFS_RT) += $(addprefix scrub/, \ + rtbitmap.o \ + rtrmap.o \ + ) xfs-$(CONFIG_XFS_QUOTA) += scrub/quota.o # online repair diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h index 0f0e2948866c..11d8217cf005 100644 --- a/fs/xfs/libxfs/xfs_fs.h +++ b/fs/xfs/libxfs/xfs_fs.h @@ -503,9 +503,10 @@ struct xfs_scrub_metadata { #define XFS_SCRUB_TYPE_GQUOTA 22 /* group quotas */ #define XFS_SCRUB_TYPE_PQUOTA 23 /* project quotas */ #define XFS_SCRUB_TYPE_FSCOUNTERS 24 /* fs summary counters */ +#define XFS_SCRUB_TYPE_RTRMAPBT 25 /* realtime reverse mapping btree */ /* Number of scrub subcommands. */ -#define XFS_SCRUB_TYPE_NR 25 +#define XFS_SCRUB_TYPE_NR 26 /* i: Repair this metadata. */ #define XFS_SCRUB_IFLAG_REPAIR (1 << 0) diff --git a/fs/xfs/scrub/bmap.c b/fs/xfs/scrub/bmap.c index 6659f41e7b4c..b62845d016d2 100644 --- a/fs/xfs/scrub/bmap.c +++ b/fs/xfs/scrub/bmap.c @@ -648,6 +648,7 @@ xchk_bmap( case XFS_DINODE_FMT_UUID: case XFS_DINODE_FMT_DEV: case XFS_DINODE_FMT_LOCAL: + case XFS_DINODE_FMT_RMAP: /* No mappings to check. */ goto out; case XFS_DINODE_FMT_EXTENTS: diff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h index 97da298abedd..6bccffddc832 100644 --- a/fs/xfs/scrub/common.h +++ b/fs/xfs/scrub/common.h @@ -89,12 +89,18 @@ int xchk_setup_parent(struct xfs_scrub *sc, struct xfs_inode *ip); #ifdef CONFIG_XFS_RT int xchk_setup_rt(struct xfs_scrub *sc, struct xfs_inode *ip); +int xchk_setup_rtrmapbt(struct xfs_scrub *sc, struct xfs_inode *ip); #else static inline int xchk_setup_rt(struct xfs_scrub *sc, struct xfs_inode *ip) { return -ENOENT; } +static inline int +xchk_setup_rtrmapbt(struct xfs_scrub *sc, struct xfs_inode *ip) +{ + return -ENOENT; +} #endif #ifdef CONFIG_XFS_QUOTA int xchk_setup_quota(struct xfs_scrub *sc, struct xfs_inode *ip); diff --git a/fs/xfs/scrub/rtrmap.c b/fs/xfs/scrub/rtrmap.c new file mode 100644 index 000000000000..6dde3c026918 --- /dev/null +++ b/fs/xfs/scrub/rtrmap.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#include "xfs.h" +#include "xfs_fs.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_trans_resv.h" +#include "xfs_mount.h" +#include "xfs_defer.h" +#include "xfs_btree.h" +#include "xfs_bit.h" +#include "xfs_log_format.h" +#include "xfs_trans.h" +#include "xfs_sb.h" +#include "xfs_rmap.h" +#include "xfs_rmap_btree.h" +#include "xfs_rtrmap_btree.h" +#include "xfs_inode.h" +#include "xfs_rtalloc.h" +#include "scrub/xfs_scrub.h" +#include "scrub/scrub.h" +#include "scrub/common.h" +#include "scrub/btree.h" +#include "scrub/trace.h" + +/* Set us up with the realtime metadata and AG headers locked. */ +int +xchk_setup_rtrmapbt( + struct xfs_scrub *sc, + struct xfs_inode *ip) +{ + struct xfs_mount *mp = sc->mp; + int lockmode; + int error = 0; + + if (sc->sm->sm_agno || sc->sm->sm_ino || sc->sm->sm_gen) + return -EINVAL; + + error = xchk_setup_fs(sc, ip); + if (error) + return error; + + lockmode = XFS_ILOCK_EXCL; + xfs_ilock(mp->m_rrmapip, lockmode); + xfs_trans_ijoin(sc->tp, mp->m_rrmapip, lockmode); + + lockmode = XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP; + xfs_ilock(mp->m_rbmip, lockmode); + xfs_trans_ijoin(sc->tp, mp->m_rbmip, lockmode); + + return 0; +} + +/* Realtime reverse mapping. */ + +/* Scrub a realtime rmapbt record. */ +STATIC int +xchk_rtrmapbt_helper( + struct xchk_btree *bs, + union xfs_btree_rec *rec) +{ + struct xfs_mount *mp = bs->cur->bc_mp; + struct xfs_rmap_irec irec; + bool non_inode; + bool is_bmbt; + bool is_attr; + int error; + + error = xfs_rmap_btrec_to_irec(bs->cur, rec, &irec); + if (!xchk_btree_process_error(bs->sc, bs->cur, 0, &error)) + goto out; + + if (irec.rm_startblock + irec.rm_blockcount <= irec.rm_startblock || + (!xfs_verify_rtbno(mp, irec.rm_startblock) || + !xfs_verify_rtbno(mp, irec.rm_startblock + + irec.rm_blockcount - 1))) + xchk_btree_set_corrupt(bs->sc, bs->cur, 0); + + non_inode = XFS_RMAP_NON_INODE_OWNER(irec.rm_owner); + is_bmbt = irec.rm_flags & XFS_RMAP_BMBT_BLOCK; + is_attr = irec.rm_flags & XFS_RMAP_ATTR_FORK; + + if (is_bmbt || non_inode || is_attr) + xchk_btree_set_corrupt(bs->sc, bs->cur, 0); + +out: + return error; +} + +/* Scrub the realtime rmap btree. */ +int +xchk_rtrmapbt( + struct xfs_scrub *sc) +{ + struct xfs_owner_info oinfo; + struct xfs_mount *mp = sc->mp; + struct xfs_btree_cur *cur; + int error; + + cur = xfs_rtrmapbt_init_cursor(mp, sc->tp, mp->m_rrmapip); + xfs_rmap_ino_bmbt_owner(&oinfo, mp->m_sb.sb_rrmapino, XFS_DATA_FORK); + error = xchk_btree(sc, cur, xchk_rtrmapbt_helper, &oinfo, NULL); + xfs_btree_del_cursor(cur, error); + + return error; +} diff --git a/fs/xfs/scrub/scrub.c b/fs/xfs/scrub/scrub.c index 047261cedd4b..b7910238d4a4 100644 --- a/fs/xfs/scrub/scrub.c +++ b/fs/xfs/scrub/scrub.c @@ -361,6 +361,13 @@ static const struct xchk_meta_ops meta_scrub_ops[] = { .scrub = xchk_fscounters, .repair = xrep_fscounters, }, + [XFS_SCRUB_TYPE_RTRMAPBT] = { /* realtime rmapbt */ + .type = ST_FS, + .setup = xchk_setup_rtrmapbt, + .scrub = xchk_rtrmapbt, + .has = xfs_sb_version_hasrtrmapbt, + .repair = xrep_notsupported, + }, }; /* This isn't a stable feature, warn once per day. */ diff --git a/fs/xfs/scrub/scrub.h b/fs/xfs/scrub/scrub.h index 1ce261f648f3..470785292b46 100644 --- a/fs/xfs/scrub/scrub.h +++ b/fs/xfs/scrub/scrub.h @@ -99,6 +99,7 @@ int xchk_parent(struct xfs_scrub *sc); #ifdef CONFIG_XFS_RT int xchk_rtbitmap(struct xfs_scrub *sc); int xchk_rtsummary(struct xfs_scrub *sc); +int xchk_rtrmapbt(struct xfs_scrub *sc); #else static inline int xchk_rtbitmap(struct xfs_scrub *sc) @@ -110,6 +111,11 @@ xchk_rtsummary(struct xfs_scrub *sc) { return -ENOENT; } +static inline int +xchk_rtrmapbt(struct xfs_scrub *sc) +{ + return -ENOENT; +} #endif #ifdef CONFIG_XFS_QUOTA int xchk_quota(struct xfs_scrub *sc); From patchwork Thu Aug 30 18:33:28 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: 10582563 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 4E17E17DB for ; Thu, 30 Aug 2018 18:33:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F82C2C03A for ; Thu, 30 Aug 2018 18:33:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 333552C3CC; Thu, 30 Aug 2018 18:33:33 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 28F222C03A for ; Thu, 30 Aug 2018 18:33:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727688AbeH3Wg7 (ORCPT ); Thu, 30 Aug 2018 18:36:59 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51786 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727054AbeH3Wg7 (ORCPT ); Thu, 30 Aug 2018 18:36:59 -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 w7UISec4133725 for ; Thu, 30 Aug 2018 18:33:30 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=8ol8crnZevN8CYPSbIS1hJ/1cTMqaIHpqNzf1E8rCKQ=; b=zbKs+eIBsjK5Ov3unOSE1Syc84Kvz+B9iAt6FQtB3OVjwiRVCmmpBujW2ev3ekatDmr3 dX/VdXm94KQJl8i9+l1EXjccnY6U377L87VfvXG0j0SBDNaasPmslMVP+Z2U4iaKtzHw 57MdoSVm2Nncpipgq3/QxUuCb/x8QgGQXOt3GAiQ3ZB9JnkIZBFTM4pjuY90JMAX9Niy lacdwxcwkbVSMeb2RbT42imkwaqLAmDYVYPQ3gk4U1kAV9i0CIObfb6ey9H5Orc0hWou fDrkefQusDPN5Yjd6RkHQsLnyU6ipwgq2s0cSXorvEHQ5xxhsQ0/RlGGVbUndvF8Ayxe 3Q== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2m2yrqpb28-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:33:30 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIXUm6016231 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:33:30 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w7UIXTWd020127 for ; Thu, 30 Aug 2018 18:33:29 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:33:29 -0700 Subject: [PATCH 17/18] xfs: cross-reference realtime bitmap to realtime rmapbt scrubber From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:33:28 -0700 Message-ID: <153565400876.32612.8730648788010963281.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 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-1807170000 definitions=main-1808300185 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 When we're checking the realtime rmapbt, cross-reference the entries with the realtime bitmap too. Signed-off-by: Darrick J. Wong --- fs/xfs/scrub/rtrmap.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/xfs/scrub/rtrmap.c b/fs/xfs/scrub/rtrmap.c index 6dde3c026918..0685a647d373 100644 --- a/fs/xfs/scrub/rtrmap.c +++ b/fs/xfs/scrub/rtrmap.c @@ -56,6 +56,16 @@ xchk_setup_rtrmapbt( /* Realtime reverse mapping. */ +/* Cross-reference with other metadata. */ +STATIC void +xchk_rtrmapbt_xref( + struct xfs_scrub *sc, + struct xfs_rmap_irec *irec) +{ + xchk_xref_is_used_rt_space(sc, irec->rm_startblock, + irec->rm_blockcount); +} + /* Scrub a realtime rmapbt record. */ STATIC int xchk_rtrmapbt_helper( @@ -86,6 +96,10 @@ xchk_rtrmapbt_helper( if (is_bmbt || non_inode || is_attr) xchk_btree_set_corrupt(bs->sc, bs->cur, 0); + if (bs->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) + goto out; + + xchk_rtrmapbt_xref(bs->sc, &irec); out: return error; } From patchwork Thu Aug 30 18:33:34 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: 10582567 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 238A2139B for ; Thu, 30 Aug 2018 18:33:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 131602C03A for ; Thu, 30 Aug 2018 18:33:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 077F12C3C6; Thu, 30 Aug 2018 18:33:46 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 5E3F42C03A for ; Thu, 30 Aug 2018 18:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727521AbeH3WhM (ORCPT ); Thu, 30 Aug 2018 18:37:12 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:60152 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727337AbeH3WhM (ORCPT ); Thu, 30 Aug 2018 18:37:12 -0400 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 w7UIXhOL154875 for ; Thu, 30 Aug 2018 18:33:43 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=XXutRHHdSSEuWlbdB1oGDdjvzzc8Jqt7JhFibUHvxng=; b=fLnrcRBhsN/bBYqNQf0qChVIYmS8whbTvwXwFA9hBNau0z5gZwiF86zelk2gl4Rnwid3 UwkDvPvA5sFBCc96ZHkfqvagX2cywtJutCd5FWf9fgW3TnRr+BbLW/JFd52J9vpeXWcx NRWRwUdzJX8I48pfF00jML0TgZXEo43neUnmQZaAjws/RoQuR0B4YTdoJzLM78N8BLQD guNA1YVz0IlGqNDVxeK5LUgf7MOQhl7t5KA9HCUQ0kh9EBMKWAsYKK3OzATpxGKbFjMs 5P49lgQ8WXkVATPY3xOZ6Y7zQFc99kEm+W+1C4wxBMz8rIG5iRfuLClrqSjWfPWjtBsI YQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2m2xhu6f5w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:33:43 +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 w7UIXaew030308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 30 Aug 2018 18:33:36 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w7UIXaBk013345 for ; Thu, 30 Aug 2018 18:33:36 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 30 Aug 2018 11:33:35 -0700 Subject: [PATCH 18/18] xfs: cross-reference the realtime rmapbt From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 30 Aug 2018 11:33:34 -0700 Message-ID: <153565401479.32612.6994922368754344692.stgit@magnolia> In-Reply-To: <153565389576.32612.11057291402738397706.stgit@magnolia> References: <153565389576.32612.11057291402738397706.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9001 signatures=668708 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-1807170000 definitions=main-1808300186 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 When we're scrubbing the realtime metadata, cross-reference the rtrmapt. Signed-off-by: Darrick J. Wong --- fs/xfs/scrub/bmap.c | 10 ++++++++++ fs/xfs/scrub/common.c | 22 ++++++++++++++++++++++ fs/xfs/scrub/common.h | 1 + fs/xfs/scrub/rmap.c | 16 ++++++++-------- fs/xfs/scrub/rtbitmap.c | 30 ++++++++++++++++++++++++++++++ fs/xfs/scrub/scrub.h | 12 ++++++------ 6 files changed, 77 insertions(+), 14 deletions(-) diff --git a/fs/xfs/scrub/bmap.c b/fs/xfs/scrub/bmap.c index b62845d016d2..2a7eff7a9b96 100644 --- a/fs/xfs/scrub/bmap.c +++ b/fs/xfs/scrub/bmap.c @@ -249,11 +249,21 @@ xchk_bmap_rt_extent_xref( struct xfs_btree_cur *cur, struct xfs_bmbt_irec *irec) { + int error; + if (info->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) return; + error = xchk_rt_init(info->sc, &info->sc->sa); + if (!xchk_fblock_process_error(info->sc, info->whichfork, + irec->br_startoff, &error)) + return; + xchk_xref_is_used_rt_space(info->sc, irec->br_startblock, irec->br_blockcount); + xchk_bmap_xref_rmap(info, irec, irec->br_startblock); + + xchk_ag_free(info->sc, &info->sc->sa); } /* Cross-reference a single datadev extent record. */ diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c index d0f9b53a7ceb..204b572d0ce4 100644 --- a/fs/xfs/scrub/common.c +++ b/fs/xfs/scrub/common.c @@ -32,6 +32,7 @@ #include "xfs_trans_priv.h" #include "xfs_attr.h" #include "xfs_reflink.h" +#include "xfs_rtrmap_btree.h" #include "scrub/xfs_scrub.h" #include "scrub/scrub.h" #include "scrub/common.h" @@ -574,6 +575,27 @@ xchk_perag_get( sa->pag = xfs_perag_get(mp, sa->agno); } +/* + * For scrubbing a realtime file, grab the rtrmapt. We follow the same + * resource release rules as xfs_scrub_ag_init. + */ +int +xchk_rt_init( + struct xfs_scrub *sc, + struct xchk_ag *sa) +{ + memset(sa, 0, sizeof(*sa)); + sa->agno = NULLAGNUMBER; + if (xfs_sb_version_hasrmapbt(&sc->mp->m_sb)) { + ASSERT(xfs_isilocked(sc->mp->m_rrmapip, + XFS_ILOCK_EXCL | XFS_ILOCK_SHARED)); + sa->rmap_cur = xfs_rtrmapbt_init_cursor(sc->mp, sc->tp, + sc->mp->m_rrmapip); + } + + return 0; +} + /* Per-scrubber setup functions */ /* diff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h index 6bccffddc832..4fcc2ccd2401 100644 --- a/fs/xfs/scrub/common.h +++ b/fs/xfs/scrub/common.h @@ -113,6 +113,7 @@ xchk_setup_quota(struct xfs_scrub *sc, struct xfs_inode *ip) #endif int xchk_setup_fscounters(struct xfs_scrub *sc, struct xfs_inode *ip); +int xchk_rt_init(struct xfs_scrub *sc, struct xchk_ag *sa); void xchk_ag_free(struct xfs_scrub *sc, struct xchk_ag *sa); int xchk_ag_init(struct xfs_scrub *sc, xfs_agnumber_t agno, struct xchk_ag *sa); diff --git a/fs/xfs/scrub/rmap.c b/fs/xfs/scrub/rmap.c index 32dc329e5411..32df9ed77b74 100644 --- a/fs/xfs/scrub/rmap.c +++ b/fs/xfs/scrub/rmap.c @@ -189,8 +189,8 @@ xchk_rmapbt( static inline void xchk_xref_check_owner( struct xfs_scrub *sc, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, struct xfs_owner_info *oinfo, bool should_have_rmap) { @@ -212,8 +212,8 @@ xchk_xref_check_owner( void xchk_xref_is_owned_by( struct xfs_scrub *sc, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, struct xfs_owner_info *oinfo) { xchk_xref_check_owner(sc, bno, len, oinfo, true); @@ -223,8 +223,8 @@ xchk_xref_is_owned_by( void xchk_xref_is_not_owned_by( struct xfs_scrub *sc, - xfs_agblock_t bno, - xfs_extlen_t len, + xfs_fsblock_t bno, + xfs_filblks_t len, struct xfs_owner_info *oinfo) { xchk_xref_check_owner(sc, bno, len, oinfo, false); @@ -234,8 +234,8 @@ xchk_xref_is_not_owned_by( void xchk_xref_has_no_owner( struct xfs_scrub *sc, - xfs_agblock_t bno, - xfs_extlen_t len) + xfs_fsblock_t bno, + xfs_filblks_t len) { bool has_rmap; int error; diff --git a/fs/xfs/scrub/rtbitmap.c b/fs/xfs/scrub/rtbitmap.c index 665d4bbb17cc..08041fc51fa1 100644 --- a/fs/xfs/scrub/rtbitmap.c +++ b/fs/xfs/scrub/rtbitmap.c @@ -15,12 +15,16 @@ #include "xfs_log_format.h" #include "xfs_trans.h" #include "xfs_sb.h" +#include "xfs_inode.h" #include "xfs_alloc.h" #include "xfs_rtalloc.h" #include "xfs_inode.h" +#include "xfs_rmap.h" +#include "xfs_rtrmap_btree.h" #include "scrub/xfs_scrub.h" #include "scrub/scrub.h" #include "scrub/common.h" +#include "scrub/btree.h" #include "scrub/trace.h" /* Set us up with the realtime metadata locked. */ @@ -39,11 +43,31 @@ xchk_setup_rt( sc->ip = sc->mp->m_rbmip; xfs_ilock(sc->ip, sc->ilock_flags); + if (xfs_sb_version_hasrmapbt(&sc->mp->m_sb)) { + unsigned int lockmode = XFS_ILOCK_EXCL; + + xfs_ilock(sc->mp->m_rrmapip, lockmode); + xfs_trans_ijoin(sc->tp, sc->mp->m_rrmapip, lockmode); + } + return 0; } /* Realtime bitmap. */ +/* Cross-reference rtbitmap entries with other metadata. */ +STATIC void +xchk_rtbitmap_xref( + struct xfs_scrub *sc, + xfs_rtblock_t startblock, + xfs_rtblock_t blockcount) +{ + if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) + return; + + xchk_xref_has_no_owner(sc, startblock, blockcount); +} + /* Scrub a free extent record from the realtime bitmap. */ STATIC int xchk_rtbitmap_rec( @@ -62,6 +86,8 @@ xchk_rtbitmap_rec( !xfs_verify_rtbno(sc->mp, startblock) || !xfs_verify_rtbno(sc->mp, startblock + blockcount - 1)) xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0); + + xchk_rtbitmap_xref(sc, startblock, blockcount); return 0; } @@ -77,6 +103,10 @@ xchk_rtbitmap( if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)) return error; + error = xchk_rt_init(sc, &sc->sa); + if (error) + return error; + error = xfs_rtalloc_query_all(sc->tp, xchk_rtbitmap_rec, sc); if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, 0, &error)) goto out; diff --git a/fs/xfs/scrub/scrub.h b/fs/xfs/scrub/scrub.h index 470785292b46..87eed5bc6c80 100644 --- a/fs/xfs/scrub/scrub.h +++ b/fs/xfs/scrub/scrub.h @@ -135,12 +135,12 @@ void xchk_xref_is_not_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno, xfs_extlen_t len); void xchk_xref_is_inode_chunk(struct xfs_scrub *sc, xfs_agblock_t agbno, xfs_extlen_t len); -void xchk_xref_is_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno, - xfs_extlen_t len, struct xfs_owner_info *oinfo); -void xchk_xref_is_not_owned_by(struct xfs_scrub *sc, xfs_agblock_t agbno, - xfs_extlen_t len, struct xfs_owner_info *oinfo); -void xchk_xref_has_no_owner(struct xfs_scrub *sc, xfs_agblock_t agbno, - xfs_extlen_t len); +void xchk_xref_is_owned_by(struct xfs_scrub *sc, xfs_fsblock_t bno, + xfs_filblks_t len, struct xfs_owner_info *oinfo); +void xchk_xref_is_not_owned_by(struct xfs_scrub *sc, xfs_fsblock_t bno, + xfs_filblks_t len, struct xfs_owner_info *oinfo); +void xchk_xref_has_no_owner(struct xfs_scrub *sc, xfs_fsblock_t bno, + xfs_filblks_t len); void xchk_xref_is_cow_staging(struct xfs_scrub *sc, xfs_agblock_t bno, xfs_extlen_t len); void xchk_xref_is_not_shared(struct xfs_scrub *sc, xfs_agblock_t bno,