~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/xfs/scrub/agb_bitmap.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Copyright (C) 2018-2023 Oracle.  All Rights Reserved.
  4  * Author: Darrick J. Wong <djwong@kernel.org>
  5  */
  6 #include "xfs.h"
  7 #include "xfs_shared.h"
  8 #include "xfs_bit.h"
  9 #include "xfs_format.h"
 10 #include "xfs_trans_resv.h"
 11 #include "xfs_mount.h"
 12 #include "xfs_btree.h"
 13 #include "bitmap.h"
 14 #include "scrub/agb_bitmap.h"
 15 
 16 /*
 17  * Record all btree blocks seen while iterating all records of a btree.
 18  *
 19  * We know that the btree query_all function starts at the left edge and walks
 20  * towards the right edge of the tree.  Therefore, we know that we can walk up
 21  * the btree cursor towards the root; if the pointer for a given level points
 22  * to the first record/key in that block, we haven't seen this block before;
 23  * and therefore we need to remember that we saw this block in the btree.
 24  *
 25  * So if our btree is:
 26  *
 27  *    4
 28  *  / | \
 29  * 1  2  3
 30  *
 31  * Pretend for this example that each leaf block has 100 btree records.  For
 32  * the first btree record, we'll observe that bc_levels[0].ptr == 1, so we
 33  * record that we saw block 1.  Then we observe that bc_levels[1].ptr == 1, so
 34  * we record block 4.  The list is [1, 4].
 35  *
 36  * For the second btree record, we see that bc_levels[0].ptr == 2, so we exit
 37  * the loop.  The list remains [1, 4].
 38  *
 39  * For the 101st btree record, we've moved onto leaf block 2.  Now
 40  * bc_levels[0].ptr == 1 again, so we record that we saw block 2.  We see that
 41  * bc_levels[1].ptr == 2, so we exit the loop.  The list is now [1, 4, 2].
 42  *
 43  * For the 102nd record, bc_levels[0].ptr == 2, so we continue.
 44  *
 45  * For the 201st record, we've moved on to leaf block 3.
 46  * bc_levels[0].ptr == 1, so we add 3 to the list.  Now it is [1, 4, 2, 3].
 47  *
 48  * For the 300th record we just exit, with the list being [1, 4, 2, 3].
 49  */
 50 
 51 /* Mark a btree block to the agblock bitmap. */
 52 STATIC int
 53 xagb_bitmap_visit_btblock(
 54         struct xfs_btree_cur    *cur,
 55         int                     level,
 56         void                    *priv)
 57 {
 58         struct xagb_bitmap      *bitmap = priv;
 59         struct xfs_buf          *bp;
 60         xfs_fsblock_t           fsbno;
 61         xfs_agblock_t           agbno;
 62 
 63         xfs_btree_get_block(cur, level, &bp);
 64         if (!bp)
 65                 return 0;
 66 
 67         fsbno = XFS_DADDR_TO_FSB(cur->bc_mp, xfs_buf_daddr(bp));
 68         agbno = XFS_FSB_TO_AGBNO(cur->bc_mp, fsbno);
 69 
 70         return xagb_bitmap_set(bitmap, agbno, 1);
 71 }
 72 
 73 /* Mark all (per-AG) btree blocks in the agblock bitmap. */
 74 int
 75 xagb_bitmap_set_btblocks(
 76         struct xagb_bitmap      *bitmap,
 77         struct xfs_btree_cur    *cur)
 78 {
 79         return xfs_btree_visit_blocks(cur, xagb_bitmap_visit_btblock,
 80                         XFS_BTREE_VISIT_ALL, bitmap);
 81 }
 82 
 83 /*
 84  * Record all the buffers pointed to by the btree cursor.  Callers already
 85  * engaged in a btree walk should call this function to capture the list of
 86  * blocks going from the leaf towards the root.
 87  */
 88 int
 89 xagb_bitmap_set_btcur_path(
 90         struct xagb_bitmap      *bitmap,
 91         struct xfs_btree_cur    *cur)
 92 {
 93         int                     i;
 94         int                     error;
 95 
 96         for (i = 0; i < cur->bc_nlevels && cur->bc_levels[i].ptr == 1; i++) {
 97                 error = xagb_bitmap_visit_btblock(cur, i, bitmap);
 98                 if (error)
 99                         return error;
100         }
101 
102         return 0;
103 }
104 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php