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

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0+
       2             : /*
       3             :  * Copyright (C) 2016 Oracle.  All Rights Reserved.
       4             :  * Author: Darrick J. Wong <darrick.wong@oracle.com>
       5             :  */
       6             : #ifndef __XFS_RMAP_H__
       7             : #define __XFS_RMAP_H__
       8             : 
       9             : struct xfs_perag;
      10             : 
      11             : static inline void
      12             : xfs_rmap_ino_bmbt_owner(
      13             :         struct xfs_owner_info   *oi,
      14             :         xfs_ino_t               ino,
      15             :         int                     whichfork)
      16             : {
      17    16311461 :         oi->oi_owner = ino;
      18    16311461 :         oi->oi_offset = 0;
      19    16311461 :         oi->oi_flags = XFS_OWNER_INFO_BMBT_BLOCK;
      20    16311461 :         if (whichfork == XFS_ATTR_FORK)
      21       68880 :                 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
      22             : }
      23             : 
      24             : static inline void
      25             : xfs_rmap_ino_owner(
      26             :         struct xfs_owner_info   *oi,
      27             :         xfs_ino_t               ino,
      28             :         int                     whichfork,
      29             :         xfs_fileoff_t           offset)
      30             : {
      31   617741062 :         oi->oi_owner = ino;
      32   617741062 :         oi->oi_offset = offset;
      33   617741062 :         oi->oi_flags = 0;
      34   617741062 :         if (whichfork == XFS_ATTR_FORK)
      35     7773608 :                 oi->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
      36             : }
      37             : 
      38             : static inline bool
      39             : xfs_rmap_should_skip_owner_update(
      40             :         const struct xfs_owner_info     *oi)
      41             : {
      42   303915230 :         return oi->oi_owner == XFS_RMAP_OWN_NULL;
      43             : }
      44             : 
      45             : /* Reverse mapping functions. */
      46             : 
      47             : struct xfs_buf;
      48             : 
      49             : static inline __u64
      50  5856085438 : xfs_rmap_irec_offset_pack(
      51             :         const struct xfs_rmap_irec      *irec)
      52             : {
      53  5856085438 :         __u64                   x;
      54             : 
      55  5856085438 :         x = XFS_RMAP_OFF(irec->rm_offset);
      56  5856085438 :         if (irec->rm_flags & XFS_RMAP_ATTR_FORK)
      57  1397316030 :                 x |= XFS_RMAP_OFF_ATTR_FORK;
      58  5856085438 :         if (irec->rm_flags & XFS_RMAP_BMBT_BLOCK)
      59  1396195221 :                 x |= XFS_RMAP_OFF_BMBT_BLOCK;
      60  5856085438 :         if (irec->rm_flags & XFS_RMAP_UNWRITTEN)
      61  1678375601 :                 x |= XFS_RMAP_OFF_UNWRITTEN;
      62  5856085438 :         return x;
      63             : }
      64             : 
      65             : static inline xfs_failaddr_t
      66 86379779998 : xfs_rmap_irec_offset_unpack(
      67             :         __u64                   offset,
      68             :         struct xfs_rmap_irec    *irec)
      69             : {
      70 86379779998 :         if (offset & ~(XFS_RMAP_OFF_MASK | XFS_RMAP_OFF_FLAGS))
      71           0 :                 return __this_address;
      72             : 
      73 86379779998 :         irec->rm_offset = XFS_RMAP_OFF(offset);
      74 86379779998 :         irec->rm_flags = 0;
      75 86379779998 :         if (offset & XFS_RMAP_OFF_ATTR_FORK)
      76  1472076418 :                 irec->rm_flags |= XFS_RMAP_ATTR_FORK;
      77 86379779998 :         if (offset & XFS_RMAP_OFF_BMBT_BLOCK)
      78  1309160389 :                 irec->rm_flags |= XFS_RMAP_BMBT_BLOCK;
      79 86379779998 :         if (offset & XFS_RMAP_OFF_UNWRITTEN)
      80 15411781323 :                 irec->rm_flags |= XFS_RMAP_UNWRITTEN;
      81             :         return NULL;
      82             : }
      83             : 
      84             : static inline void
      85             : xfs_owner_info_unpack(
      86             :         const struct xfs_owner_info     *oinfo,
      87             :         uint64_t                        *owner,
      88             :         uint64_t                        *offset,
      89             :         unsigned int                    *flags)
      90             : {
      91   530014447 :         unsigned int                    r = 0;
      92             : 
      93   530014447 :         *owner = oinfo->oi_owner;
      94   530014447 :         *offset = oinfo->oi_offset;
      95   530014447 :         if (oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK)
      96     6303902 :                 r |= XFS_RMAP_ATTR_FORK;
      97   530014447 :         if (oinfo->oi_flags & XFS_OWNER_INFO_BMBT_BLOCK)
      98     4796374 :                 r |= XFS_RMAP_BMBT_BLOCK;
      99   530014447 :         *flags = r;
     100             : }
     101             : 
     102             : static inline void
     103             : xfs_owner_info_pack(
     104             :         struct xfs_owner_info   *oinfo,
     105             :         uint64_t                owner,
     106             :         uint64_t                offset,
     107             :         unsigned int            flags)
     108             : {
     109    52623668 :         oinfo->oi_owner = owner;
     110    52623668 :         oinfo->oi_offset = XFS_RMAP_OFF(offset);
     111    52623668 :         oinfo->oi_flags = 0;
     112    52623668 :         if (flags & XFS_RMAP_ATTR_FORK)
     113       77893 :                 oinfo->oi_flags |= XFS_OWNER_INFO_ATTR_FORK;
     114    52623668 :         if (flags & XFS_RMAP_BMBT_BLOCK)
     115      978485 :                 oinfo->oi_flags |= XFS_OWNER_INFO_BMBT_BLOCK;
     116             : }
     117             : 
     118             : int xfs_rmap_alloc(struct xfs_trans *tp, struct xfs_buf *agbp,
     119             :                    struct xfs_perag *pag, xfs_agblock_t bno, xfs_extlen_t len,
     120             :                    const struct xfs_owner_info *oinfo);
     121             : int xfs_rmap_free(struct xfs_trans *tp, struct xfs_buf *agbp,
     122             :                   struct xfs_perag *pag, xfs_agblock_t bno, xfs_extlen_t len,
     123             :                   const struct xfs_owner_info *oinfo);
     124             : 
     125             : int xfs_rmap_lookup_le(struct xfs_btree_cur *cur, xfs_agblock_t bno,
     126             :                 uint64_t owner, uint64_t offset, unsigned int flags,
     127             :                 struct xfs_rmap_irec *irec, int *stat);
     128             : int xfs_rmap_lookup_eq(struct xfs_btree_cur *cur, xfs_agblock_t bno,
     129             :                 xfs_extlen_t len, uint64_t owner, uint64_t offset,
     130             :                 unsigned int flags, int *stat);
     131             : int xfs_rmap_insert(struct xfs_btree_cur *rcur, xfs_agblock_t agbno,
     132             :                 xfs_extlen_t len, uint64_t owner, uint64_t offset,
     133             :                 unsigned int flags);
     134             : int xfs_rmap_get_rec(struct xfs_btree_cur *cur, struct xfs_rmap_irec *irec,
     135             :                 int *stat);
     136             : 
     137             : typedef int (*xfs_rmap_query_range_fn)(
     138             :         struct xfs_btree_cur            *cur,
     139             :         const struct xfs_rmap_irec      *rec,
     140             :         void                            *priv);
     141             : 
     142             : int xfs_rmap_query_range(struct xfs_btree_cur *cur,
     143             :                 const struct xfs_rmap_irec *low_rec,
     144             :                 const struct xfs_rmap_irec *high_rec,
     145             :                 xfs_rmap_query_range_fn fn, void *priv);
     146             : int xfs_rmap_query_all(struct xfs_btree_cur *cur, xfs_rmap_query_range_fn fn,
     147             :                 void *priv);
     148             : 
     149             : enum xfs_rmap_intent_type {
     150             :         XFS_RMAP_MAP,
     151             :         XFS_RMAP_MAP_SHARED,
     152             :         XFS_RMAP_UNMAP,
     153             :         XFS_RMAP_UNMAP_SHARED,
     154             :         XFS_RMAP_CONVERT,
     155             :         XFS_RMAP_CONVERT_SHARED,
     156             :         XFS_RMAP_ALLOC,
     157             :         XFS_RMAP_FREE,
     158             : };
     159             : 
     160             : struct xfs_rmap_intent {
     161             :         struct list_head                        ri_list;
     162             :         enum xfs_rmap_intent_type               ri_type;
     163             :         int                                     ri_whichfork;
     164             :         uint64_t                                ri_owner;
     165             :         struct xfs_bmbt_irec                    ri_bmap;
     166             :         struct xfs_perag                        *ri_pag;
     167             : };
     168             : 
     169             : void xfs_rmap_update_get_group(struct xfs_mount *mp,
     170             :                 struct xfs_rmap_intent *ri);
     171             : 
     172             : /* functions for updating the rmapbt based on bmbt map/unmap operations */
     173             : void xfs_rmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip,
     174             :                 int whichfork, struct xfs_bmbt_irec *imap);
     175             : void xfs_rmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip,
     176             :                 int whichfork, struct xfs_bmbt_irec *imap);
     177             : void xfs_rmap_convert_extent(struct xfs_mount *mp, struct xfs_trans *tp,
     178             :                 struct xfs_inode *ip, int whichfork,
     179             :                 struct xfs_bmbt_irec *imap);
     180             : void xfs_rmap_alloc_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
     181             :                 xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
     182             : void xfs_rmap_free_extent(struct xfs_trans *tp, xfs_agnumber_t agno,
     183             :                 xfs_agblock_t bno, xfs_extlen_t len, uint64_t owner);
     184             : 
     185             : void xfs_rmap_finish_one_cleanup(struct xfs_trans *tp,
     186             :                 struct xfs_btree_cur *rcur, int error);
     187             : int xfs_rmap_finish_one(struct xfs_trans *tp, struct xfs_rmap_intent *ri,
     188             :                 struct xfs_btree_cur **pcur);
     189             : int __xfs_rmap_finish_intent(struct xfs_btree_cur *rcur,
     190             :                 enum xfs_rmap_intent_type op, xfs_agblock_t bno,
     191             :                 xfs_extlen_t len, const struct xfs_owner_info *oinfo,
     192             :                 bool unwritten);
     193             : 
     194             : int xfs_rmap_lookup_le_range(struct xfs_btree_cur *cur, xfs_agblock_t bno,
     195             :                 uint64_t owner, uint64_t offset, unsigned int flags,
     196             :                 struct xfs_rmap_irec *irec, int *stat);
     197             : int xfs_rmap_compare(const struct xfs_rmap_irec *a,
     198             :                 const struct xfs_rmap_irec *b);
     199             : union xfs_btree_rec;
     200             : xfs_failaddr_t xfs_rmap_btrec_to_irec(const union xfs_btree_rec *rec,
     201             :                 struct xfs_rmap_irec *irec);
     202             : xfs_failaddr_t xfs_rmap_check_perag_irec(struct xfs_perag *pag,
     203             :                 const struct xfs_rmap_irec *irec);
     204             : xfs_failaddr_t xfs_rmap_check_irec(struct xfs_btree_cur *cur,
     205             :                 const struct xfs_rmap_irec *irec);
     206             : 
     207             : int xfs_rmap_has_records(struct xfs_btree_cur *cur, xfs_agblock_t bno,
     208             :                 xfs_extlen_t len, enum xbtree_recpacking *outcome);
     209             : 
     210             : struct xfs_rmap_matches {
     211             :         /* Number of owner matches. */
     212             :         unsigned long long      matches;
     213             : 
     214             :         /* Number of non-owner matches. */
     215             :         unsigned long long      non_owner_matches;
     216             : 
     217             :         /* Number of non-owner matches that conflict with the owner matches. */
     218             :         unsigned long long      bad_non_owner_matches;
     219             : };
     220             : 
     221             : int xfs_rmap_count_owners(struct xfs_btree_cur *cur, xfs_agblock_t bno,
     222             :                 xfs_extlen_t len, const struct xfs_owner_info *oinfo,
     223             :                 struct xfs_rmap_matches *rmatch);
     224             : int xfs_rmap_has_other_keys(struct xfs_btree_cur *cur, xfs_agblock_t bno,
     225             :                 xfs_extlen_t len, const struct xfs_owner_info *oinfo,
     226             :                 bool *has_other);
     227             : int xfs_rmap_map_raw(struct xfs_btree_cur *cur, struct xfs_rmap_irec *rmap);
     228             : 
     229             : extern const struct xfs_owner_info XFS_RMAP_OINFO_SKIP_UPDATE;
     230             : extern const struct xfs_owner_info XFS_RMAP_OINFO_ANY_OWNER;
     231             : extern const struct xfs_owner_info XFS_RMAP_OINFO_FS;
     232             : extern const struct xfs_owner_info XFS_RMAP_OINFO_LOG;
     233             : extern const struct xfs_owner_info XFS_RMAP_OINFO_AG;
     234             : extern const struct xfs_owner_info XFS_RMAP_OINFO_INOBT;
     235             : extern const struct xfs_owner_info XFS_RMAP_OINFO_INODES;
     236             : extern const struct xfs_owner_info XFS_RMAP_OINFO_REFC;
     237             : extern const struct xfs_owner_info XFS_RMAP_OINFO_COW;
     238             : 
     239             : extern struct kmem_cache        *xfs_rmap_intent_cache;
     240             : 
     241             : int __init xfs_rmap_intent_init_cache(void);
     242             : void xfs_rmap_intent_destroy_cache(void);
     243             : 
     244             : /*
     245             :  * Parameters for tracking reverse mapping changes.  The hook function arg
     246             :  * parameter is enum xfs_rmap_intent_type, and the rest is below.
     247             :  */
     248             : struct xfs_rmap_update_params {
     249             :         xfs_agblock_t                   startblock;
     250             :         xfs_extlen_t                    blockcount;
     251             :         struct xfs_owner_info           oinfo;
     252             :         bool                            unwritten;
     253             : };
     254             : 
     255             : #ifdef CONFIG_XFS_LIVE_HOOKS
     256             : 
     257             : struct xfs_rmap_hook {
     258             :         struct xfs_hook                 update_hook;
     259             : };
     260             : 
     261             : void xfs_rmap_hook_disable(void);
     262             : void xfs_rmap_hook_enable(void);
     263             : 
     264             : int xfs_rmap_hook_add(struct xfs_perag *pag, struct xfs_rmap_hook *hook);
     265             : void xfs_rmap_hook_del(struct xfs_perag *pag, struct xfs_rmap_hook *hook);
     266             : #endif
     267             : 
     268             : #endif  /* __XFS_RMAP_H__ */

Generated by: LCOV version 1.14