LCOV - code coverage report
Current view: top level - fs/xfs/libxfs - xfs_bmap_btree.h (source / functions) Hit Total Coverage
Test: fstests of 6.5.0-rc4-xfsa @ Mon Jul 31 20:08:27 PDT 2023 Lines: 27 29 93.1 %
Date: 2023-07-31 20:08:27 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: GPL-2.0 */
       2             : /*
       3             :  * Copyright (c) 2000,2002-2005 Silicon Graphics, Inc.
       4             :  * All Rights Reserved.
       5             :  */
       6             : #ifndef __XFS_BMAP_BTREE_H__
       7             : #define __XFS_BMAP_BTREE_H__
       8             : 
       9             : struct xfs_btree_cur;
      10             : struct xfs_btree_block;
      11             : struct xfs_mount;
      12             : struct xfs_inode;
      13             : struct xfs_trans;
      14             : struct xbtree_ifakeroot;
      15             : 
      16             : /*
      17             :  * Maximum number of bmap btree levels.
      18             :  */
      19             : #define XFS_BM_MAXLEVELS(mp,w)          ((mp)->m_bm_maxlevels[(w)])
      20             : 
      21             : /*
      22             :  * Prototypes for xfs_bmap.c to call.
      23             :  */
      24             : extern void xfs_bmdr_to_bmbt(struct xfs_inode *, xfs_bmdr_block_t *, int,
      25             :                         struct xfs_btree_block *, int);
      26             : 
      27             : void xfs_bmbt_disk_set_all(struct xfs_bmbt_rec *r, struct xfs_bmbt_irec *s);
      28             : extern xfs_filblks_t xfs_bmbt_disk_get_blockcount(const struct xfs_bmbt_rec *r);
      29             : extern xfs_fileoff_t xfs_bmbt_disk_get_startoff(const struct xfs_bmbt_rec *r);
      30             : void xfs_bmbt_disk_get_all(const struct xfs_bmbt_rec *r,
      31             :                 struct xfs_bmbt_irec *s);
      32             : 
      33             : extern void xfs_bmbt_to_bmdr(struct xfs_mount *, struct xfs_btree_block *, int,
      34             :                         xfs_bmdr_block_t *, int);
      35             : 
      36             : extern int xfs_bmbt_get_maxrecs(struct xfs_btree_cur *, int level);
      37             : extern int xfs_bmdr_maxrecs(int blocklen, int leaf);
      38             : unsigned int xfs_bmbt_maxrecs(struct xfs_mount *mp, unsigned int blocklen,
      39             :                 bool leaf);
      40             : 
      41             : extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip,
      42             :                                  int whichfork, xfs_ino_t new_owner,
      43             :                                  struct list_head *buffer_list);
      44             : 
      45             : extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *,
      46             :                 struct xfs_trans *, struct xfs_inode *, int);
      47             : struct xfs_btree_cur *xfs_bmbt_stage_cursor(struct xfs_mount *mp,
      48             :                 struct xfs_inode *ip, struct xbtree_ifakeroot *ifake);
      49             : void xfs_bmbt_commit_staged_btree(struct xfs_btree_cur *cur,
      50             :                 struct xfs_trans *tp, int whichfork);
      51             : 
      52             : extern unsigned long long xfs_bmbt_calc_size(struct xfs_mount *mp,
      53             :                 unsigned long long len);
      54             : 
      55             : unsigned int xfs_bmbt_maxlevels_ondisk(void);
      56             : 
      57             : int __init xfs_bmbt_init_cur_cache(void);
      58             : void xfs_bmbt_destroy_cur_cache(void);
      59             : 
      60             : /*
      61             :  * Btree block header size depends on a superblock flag.
      62             :  */
      63             : static inline size_t
      64             : xfs_bmbt_block_len(struct xfs_mount *mp)
      65             : {
      66 >11572*10^7 :         return xfs_has_crc(mp) ?
      67 >11573*10^7 :                         XFS_BTREE_LBLOCK_CRC_LEN : XFS_BTREE_LBLOCK_LEN;
      68             : }
      69             : 
      70             : /* Addresses of key, pointers, and records within an incore bmbt block. */
      71             : 
      72             : static inline struct xfs_bmbt_rec *
      73             : xfs_bmbt_rec_addr(
      74             :         struct xfs_mount        *mp,
      75             :         struct xfs_btree_block  *block,
      76             :         unsigned int            index)
      77             : {
      78 >10846*10^7 :         return (struct xfs_bmbt_rec *)
      79 >10797*10^7 :                 ((char *)block + xfs_bmbt_block_len(mp) +
      80 >10797*10^7 :                  (index - 1) * sizeof(struct xfs_bmbt_rec));
      81             : }
      82             : 
      83             : static inline struct xfs_bmbt_key *
      84             : xfs_bmbt_key_addr(
      85             :         struct xfs_mount        *mp,
      86             :         struct xfs_btree_block  *block,
      87             :         unsigned int            index)
      88             : {
      89   513690728 :         return (struct xfs_bmbt_key *)
      90   497261124 :                 ((char *)block + xfs_bmbt_block_len(mp) +
      91   497261124 :                  (index - 1) * sizeof(struct xfs_bmbt_key *));
      92             : }
      93             : 
      94             : static inline xfs_bmbt_ptr_t *
      95             : xfs_bmbt_ptr_addr(
      96             :         struct xfs_mount        *mp,
      97             :         struct xfs_btree_block  *block,
      98             :         unsigned int            index,
      99             :         unsigned int            maxrecs)
     100             : {
     101  6249054609 :         return (xfs_bmbt_ptr_t *)
     102             :                 ((char *)block + xfs_bmbt_block_len(mp) +
     103   431858998 :                  maxrecs * sizeof(struct xfs_bmbt_key) +
     104  5515360897 :                  (index - 1) * sizeof(xfs_bmbt_ptr_t));
     105             : }
     106             : 
     107             : /* Addresses of key, pointers, and records within an ondisk bmbt block. */
     108             : 
     109             : static inline struct xfs_bmbt_rec *
     110             : xfs_bmdr_rec_addr(
     111             :         struct xfs_bmdr_block   *block,
     112             :         unsigned int            index)
     113             : {
     114             :         return (struct xfs_bmbt_rec *)
     115             :                 ((char *)(block + 1) +
     116             :                  (index - 1) * sizeof(struct xfs_bmbt_rec));
     117             : }
     118             : 
     119             : static inline struct xfs_bmbt_key *
     120             : xfs_bmdr_key_addr(
     121             :         struct xfs_bmdr_block   *block,
     122             :         unsigned int            index)
     123             : {
     124    14837915 :         return (struct xfs_bmbt_key *)
     125           0 :                 ((char *)(block + 1) +
     126           0 :                  (index - 1) * sizeof(struct xfs_bmbt_key));
     127             : }
     128             : 
     129             : static inline xfs_bmbt_ptr_t *
     130             : xfs_bmdr_ptr_addr(
     131             :         struct xfs_bmdr_block   *block,
     132             :         unsigned int            index,
     133             :         unsigned int            maxrecs)
     134             : {
     135    14837915 :         return (xfs_bmbt_ptr_t *)
     136             :                 ((char *)(block + 1) +
     137    14837915 :                  maxrecs * sizeof(struct xfs_bmbt_key) +
     138             :                  (index - 1) * sizeof(xfs_bmbt_ptr_t));
     139             : }
     140             : 
     141             : /*
     142             :  * Address of pointers within the incore btree root.
     143             :  *
     144             :  * These are to be used when we know the size of the block and
     145             :  * we don't have a cursor.
     146             :  */
     147             : static inline xfs_bmbt_ptr_t *
     148   301834811 : xfs_bmap_broot_ptr_addr(
     149             :         struct xfs_mount        *mp,
     150             :         struct xfs_btree_block  *bb,
     151             :         unsigned int            i,
     152             :         unsigned int            sz)
     153             : {
     154   316729368 :         return xfs_bmbt_ptr_addr(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, false));
     155             : }
     156             : 
     157             : /*
     158             :  * Compute the space required for the incore btree root containing the given
     159             :  * number of records.
     160             :  */
     161             : static inline size_t
     162    14287680 : xfs_bmap_broot_space_calc(
     163             :         struct xfs_mount        *mp,
     164             :         unsigned int            level,
     165             :         unsigned int            nrecs)
     166             : {
     167    14287680 :         ASSERT(level > 0);
     168             : 
     169             :         /*
     170             :          * If the bmbt root block is empty, we should be converting the fork
     171             :          * to extents format.  Hence, the size is zero.
     172             :          */
     173    14287680 :         if (nrecs == 0)
     174             :                 return 0;
     175             : 
     176    14287680 :         return xfs_bmbt_block_len(mp) + \
     177    14287680 :                (nrecs * (sizeof(struct xfs_bmbt_key) + sizeof(xfs_bmbt_ptr_t)));
     178             : }
     179             : 
     180             : /*
     181             :  * Compute the space required for the incore btree root given the ondisk
     182             :  * btree root block.
     183             :  */
     184             : static inline size_t
     185    12629493 : xfs_bmap_broot_space(
     186             :         struct xfs_mount        *mp,
     187             :         struct xfs_bmdr_block   *bb)
     188             : {
     189    12629493 :         return xfs_bmap_broot_space_calc(mp, 1, be16_to_cpu(bb->bb_numrecs));
     190             : }
     191             : 
     192             : /* Compute the space required for the ondisk root block. */
     193             : static inline size_t
     194             : xfs_bmdr_space_calc(unsigned int nrecs)
     195             : {
     196    14420646 :         return sizeof(struct xfs_bmdr_block) +
     197    25315660 :                (nrecs * (sizeof(struct xfs_bmbt_key) + sizeof(xfs_bmbt_ptr_t)));
     198             : }
     199             : 
     200             : /*
     201             :  * Compute the space required for the ondisk root block given an incore root
     202             :  * block.
     203             :  */
     204             : static inline size_t
     205     1791155 : xfs_bmap_bmdr_space(struct xfs_btree_block *bb)
     206             : {
     207     1791155 :         return xfs_bmdr_space_calc(be16_to_cpu(bb->bb_numrecs));
     208             : }
     209             : 
     210             : void xfs_bmbt_iroot_alloc(struct xfs_inode *ip, int whichfork);
     211             : 
     212             : #endif  /* __XFS_BMAP_BTREE_H__ */

Generated by: LCOV version 1.14