LCOV - code coverage report
Current view: top level - fs/xfs/libxfs - xfs_inode_fork.h (source / functions) Hit Total Coverage
Test: fstests of 6.5.0-rc3-achx @ Mon Jul 31 20:08:12 PDT 2023 Lines: 42 49 85.7 %
Date: 2023-07-31 20:08:12 Functions: 8 8 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0
       2             : /*
       3             :  * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
       4             :  * All Rights Reserved.
       5             :  */
       6             : #ifndef __XFS_INODE_FORK_H__
       7             : #define __XFS_INODE_FORK_H__
       8             : 
       9             : struct xfs_inode_log_item;
      10             : struct xfs_dinode;
      11             : 
      12             : /*
      13             :  * File incore extent information, present for each of data & attr forks.
      14             :  */
      15             : struct xfs_ifork {
      16             :         int64_t                 if_bytes;       /* bytes in if_u1 */
      17             :         struct xfs_btree_block  *if_broot;      /* file's incore btree root */
      18             :         unsigned int            if_seq;         /* fork mod counter */
      19             :         int                     if_height;      /* height of the extent tree */
      20             :         union {
      21             :                 void            *if_root;       /* extent tree root */
      22             :                 char            *if_data;       /* inline file data */
      23             :         } if_u1;
      24             :         xfs_extnum_t            if_nextents;    /* # of extents in this fork */
      25             :         short                   if_broot_bytes; /* bytes allocated for root */
      26             :         int8_t                  if_format;      /* format of this fork */
      27             :         uint8_t                 if_needextents; /* extents have not been read */
      28             : };
      29             : 
      30             : /*
      31             :  * Worst-case increase in the fork extent count when we're adding a single
      32             :  * extent to a fork and there's no possibility of splitting an existing mapping.
      33             :  */
      34             : #define XFS_IEXT_ADD_NOSPLIT_CNT        (1)
      35             : 
      36             : /*
      37             :  * Punching out an extent from the middle of an existing extent can cause the
      38             :  * extent count to increase by 1.
      39             :  * i.e. | Old extent | Hole | Old extent |
      40             :  */
      41             : #define XFS_IEXT_PUNCH_HOLE_CNT         (1)
      42             : 
      43             : /*
      44             :  * Adding/removing an xattr can cause XFS_DA_NODE_MAXDEPTH extents to
      45             :  * be added. One extra extent for dabtree in case a local attr is
      46             :  * large enough to cause a double split.  It can also cause extent
      47             :  * count to increase proportional to the size of a remote xattr's
      48             :  * value.
      49             :  */
      50             : #define XFS_IEXT_ATTR_MANIP_CNT(rmt_blks) \
      51             :         (XFS_DA_NODE_MAXDEPTH + max(1, rmt_blks))
      52             : 
      53             : /*
      54             :  * A write to a sub-interval of an existing unwritten extent causes the original
      55             :  * extent to be split into 3 extents
      56             :  * i.e. | Unwritten | Real | Unwritten |
      57             :  * Hence extent count can increase by 2.
      58             :  */
      59             : #define XFS_IEXT_WRITE_UNWRITTEN_CNT    (2)
      60             : 
      61             : 
      62             : /*
      63             :  * Moving an extent to data fork can cause a sub-interval of an existing extent
      64             :  * to be unmapped. This will increase extent count by 1. Mapping in the new
      65             :  * extent can increase the extent count by 1 again i.e.
      66             :  * | Old extent | New extent | Old extent |
      67             :  * Hence number of extents increases by 2.
      68             :  */
      69             : #define XFS_IEXT_REFLINK_END_COW_CNT    (2)
      70             : 
      71             : /*
      72             :  * Removing an initial range of source/donor file's extent and adding a new
      73             :  * extent (from donor/source file) in its place will cause extent count to
      74             :  * increase by 1.
      75             :  */
      76             : #define XFS_IEXT_SWAP_RMAP_CNT          (1)
      77             : 
      78             : /*
      79             :  * Fork handling.
      80             :  */
      81             : #define XFS_IFORK_MAXEXT(ip, w) \
      82             :         (xfs_inode_fork_size(ip, w) / sizeof(xfs_bmbt_rec_t))
      83             : 
      84             : static inline bool xfs_ifork_has_extents(struct xfs_ifork *ifp)
      85             : {
      86 10703913518 :         return ifp->if_format == XFS_DINODE_FMT_EXTENTS ||
      87             :                 ifp->if_format == XFS_DINODE_FMT_BTREE;
      88             : }
      89             : 
      90             : static inline xfs_extnum_t xfs_ifork_nextents(struct xfs_ifork *ifp)
      91             : {
      92 >15223*10^7 :         if (!ifp)
      93             :                 return 0;
      94 >15223*10^7 :         return ifp->if_nextents;
      95             : }
      96             : 
      97             : static inline int8_t xfs_ifork_format(struct xfs_ifork *ifp)
      98             : {
      99  6239136115 :         if (!ifp)
     100             :                 return XFS_DINODE_FMT_EXTENTS;
     101  6239136115 :         return ifp->if_format;
     102             : }
     103             : 
     104   542088877 : static inline xfs_extnum_t xfs_iext_max_nextents(bool has_large_extent_counts,
     105             :                                 int whichfork)
     106             : {
     107   542088877 :         switch (whichfork) {
     108   353050831 :         case XFS_DATA_FORK:
     109             :         case XFS_COW_FORK:
     110   353050831 :                 if (has_large_extent_counts)
     111   352427604 :                         return XFS_MAX_EXTCNT_DATA_FORK_LARGE;
     112             :                 return XFS_MAX_EXTCNT_DATA_FORK_SMALL;
     113             : 
     114   189038046 :         case XFS_ATTR_FORK:
     115   189038046 :                 if (has_large_extent_counts)
     116   189033518 :                         return XFS_MAX_EXTCNT_ATTR_FORK_LARGE;
     117             :                 return XFS_MAX_EXTCNT_ATTR_FORK_SMALL;
     118             : 
     119           0 :         default:
     120           0 :                 ASSERT(0);
     121           0 :                 return 0;
     122             :         }
     123             : }
     124             : 
     125             : static inline xfs_extnum_t
     126  1662186827 : xfs_dfork_data_extents(
     127             :         struct xfs_dinode       *dip)
     128             : {
     129  3324373654 :         if (xfs_dinode_has_large_extent_counts(dip))
     130  1662181413 :                 return be64_to_cpu(dip->di_big_nextents);
     131             : 
     132        5414 :         return be32_to_cpu(dip->di_nextents);
     133             : }
     134             : 
     135             : static inline xfs_extnum_t
     136  1604677169 : xfs_dfork_attr_extents(
     137             :         struct xfs_dinode       *dip)
     138             : {
     139  3209354338 :         if (xfs_dinode_has_large_extent_counts(dip))
     140  1604674439 :                 return be32_to_cpu(dip->di_big_anextents);
     141             : 
     142        2730 :         return be16_to_cpu(dip->di_anextents);
     143             : }
     144             : 
     145             : static inline xfs_extnum_t
     146   886947639 : xfs_dfork_nextents(
     147             :         struct xfs_dinode       *dip,
     148             :         int                     whichfork)
     149             : {
     150   886947639 :         switch (whichfork) {
     151   470514078 :         case XFS_DATA_FORK:
     152   470514078 :                 return xfs_dfork_data_extents(dip);
     153   416433561 :         case XFS_ATTR_FORK:
     154   416433561 :                 return xfs_dfork_attr_extents(dip);
     155           0 :         default:
     156           0 :                 ASSERT(0);
     157           0 :                 break;
     158             :         }
     159             : 
     160           0 :         return 0;
     161             : }
     162             : 
     163             : void xfs_ifork_zap_attr(struct xfs_inode *ip);
     164             : void xfs_ifork_init_attr(struct xfs_inode *ip, enum xfs_dinode_fmt format,
     165             :                 xfs_extnum_t nextents);
     166             : struct xfs_ifork *xfs_iext_state_to_fork(struct xfs_inode *ip, int state);
     167             : 
     168             : int             xfs_iformat_data_fork(struct xfs_inode *, struct xfs_dinode *);
     169             : int             xfs_iformat_attr_fork(struct xfs_inode *, struct xfs_dinode *);
     170             : void            xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *,
     171             :                                 struct xfs_inode_log_item *, int);
     172             : void            xfs_idestroy_fork(struct xfs_ifork *ifp);
     173             : void            xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff,
     174             :                                 int whichfork);
     175             : void            xfs_iroot_realloc(struct xfs_inode *, int, int);
     176             : int             xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int);
     177             : int             xfs_iextents_copy(struct xfs_inode *, struct xfs_bmbt_rec *,
     178             :                                   int);
     179             : void            xfs_init_local_fork(struct xfs_inode *ip, int whichfork,
     180             :                                 const void *data, int64_t size);
     181             : 
     182             : xfs_extnum_t    xfs_iext_count(struct xfs_ifork *ifp);
     183             : void            xfs_iext_insert_raw(struct xfs_ifork *ifp,
     184             :                         struct xfs_iext_cursor *cur,
     185             :                         struct xfs_bmbt_irec *irec);
     186             : void            xfs_iext_insert(struct xfs_inode *, struct xfs_iext_cursor *cur,
     187             :                         struct xfs_bmbt_irec *, int);
     188             : void            xfs_iext_remove(struct xfs_inode *, struct xfs_iext_cursor *,
     189             :                         int);
     190             : void            xfs_iext_destroy(struct xfs_ifork *);
     191             : 
     192             : bool            xfs_iext_lookup_extent(struct xfs_inode *ip,
     193             :                         struct xfs_ifork *ifp, xfs_fileoff_t bno,
     194             :                         struct xfs_iext_cursor *cur,
     195             :                         struct xfs_bmbt_irec *gotp);
     196             : bool            xfs_iext_lookup_extent_before(struct xfs_inode *ip,
     197             :                         struct xfs_ifork *ifp, xfs_fileoff_t *end,
     198             :                         struct xfs_iext_cursor *cur,
     199             :                         struct xfs_bmbt_irec *gotp);
     200             : bool            xfs_iext_get_extent(struct xfs_ifork *ifp,
     201             :                         struct xfs_iext_cursor *cur,
     202             :                         struct xfs_bmbt_irec *gotp);
     203             : void            xfs_iext_update_extent(struct xfs_inode *ip, int state,
     204             :                         struct xfs_iext_cursor *cur,
     205             :                         struct xfs_bmbt_irec *gotp);
     206             : 
     207             : void            xfs_iext_first(struct xfs_ifork *, struct xfs_iext_cursor *);
     208             : void            xfs_iext_last(struct xfs_ifork *, struct xfs_iext_cursor *);
     209             : void            xfs_iext_next(struct xfs_ifork *, struct xfs_iext_cursor *);
     210             : void            xfs_iext_prev(struct xfs_ifork *, struct xfs_iext_cursor *);
     211             : 
     212  1284874539 : static inline bool xfs_iext_next_extent(struct xfs_ifork *ifp,
     213             :                 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
     214             : {
     215  1284874539 :         xfs_iext_next(ifp, cur);
     216  1284725439 :         return xfs_iext_get_extent(ifp, cur, gotp);
     217             : }
     218             : 
     219   103099686 : static inline bool xfs_iext_prev_extent(struct xfs_ifork *ifp,
     220             :                 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
     221             : {
     222   103099686 :         xfs_iext_prev(ifp, cur);
     223   102960446 :         return xfs_iext_get_extent(ifp, cur, gotp);
     224             : }
     225             : 
     226             : /*
     227             :  * Return the extent after cur in gotp without updating the cursor.
     228             :  */
     229   435705207 : static inline bool xfs_iext_peek_next_extent(struct xfs_ifork *ifp,
     230             :                 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
     231             : {
     232   435705207 :         struct xfs_iext_cursor ncur = *cur;
     233             : 
     234   435705207 :         xfs_iext_next(ifp, &ncur);
     235   435666900 :         return xfs_iext_get_extent(ifp, &ncur, gotp);
     236             : }
     237             : 
     238             : /*
     239             :  * Return the extent before cur in gotp without updating the cursor.
     240             :  */
     241   694947489 : static inline bool xfs_iext_peek_prev_extent(struct xfs_ifork *ifp,
     242             :                 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
     243             : {
     244   694947489 :         struct xfs_iext_cursor ncur = *cur;
     245             : 
     246   694947489 :         xfs_iext_prev(ifp, &ncur);
     247   694954762 :         return xfs_iext_get_extent(ifp, &ncur, gotp);
     248             : }
     249             : 
     250             : #define for_each_xfs_iext(ifp, ext, got)                \
     251             :         for (xfs_iext_first((ifp), (ext));              \
     252             :              xfs_iext_get_extent((ifp), (ext), (got));  \
     253             :              xfs_iext_next((ifp), (ext)))
     254             : 
     255             : extern struct kmem_cache        *xfs_ifork_cache;
     256             : 
     257             : extern void xfs_ifork_init_cow(struct xfs_inode *ip);
     258             : 
     259             : int xfs_ifork_verify_local_data(struct xfs_inode *ip);
     260             : int xfs_ifork_verify_local_attr(struct xfs_inode *ip);
     261             : int xfs_iext_count_may_overflow(struct xfs_inode *ip, int whichfork,
     262             :                 int nr_to_add);
     263             : int xfs_iext_count_upgrade(struct xfs_trans *tp, struct xfs_inode *ip,
     264             :                 uint nr_to_add);
     265             : bool xfs_ifork_is_realtime(struct xfs_inode *ip, int whichfork);
     266             : 
     267             : /* returns true if the fork has extents but they are not read in yet. */
     268             : static inline bool xfs_need_iread_extents(const struct xfs_ifork *ifp)
     269             : {
     270             :         /* see xfs_iformat_{data,attr}_fork() for needextents semantics */
     271 24990295678 :         return smp_load_acquire(&ifp->if_needextents) != 0;
     272             : }
     273             : 
     274             : #endif  /* __XFS_INODE_FORK_H__ */

Generated by: LCOV version 1.14