LCOV - code coverage report
Current view: top level - fs/xfs/libxfs - xfs_refcount.h (source / functions) Hit Total Coverage
Test: fstests of 6.5.0-rc4-xfsx @ Mon Jul 31 20:08:34 PDT 2023 Lines: 8 9 88.9 %
Date: 2023-07-31 20:08:34 Functions: 1 1 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_REFCOUNT_H__
       7             : #define __XFS_REFCOUNT_H__
       8             : 
       9             : struct xfs_trans;
      10             : struct xfs_mount;
      11             : struct xfs_perag;
      12             : struct xfs_btree_cur;
      13             : struct xfs_bmbt_irec;
      14             : struct xfs_refcount_irec;
      15             : struct xfs_rtgroup;
      16             : 
      17             : extern int xfs_refcount_lookup_le(struct xfs_btree_cur *cur,
      18             :                 enum xfs_refc_domain domain, xfs_agblock_t bno, int *stat);
      19             : extern int xfs_refcount_lookup_ge(struct xfs_btree_cur *cur,
      20             :                 enum xfs_refc_domain domain, xfs_agblock_t bno, int *stat);
      21             : extern int xfs_refcount_lookup_eq(struct xfs_btree_cur *cur,
      22             :                 enum xfs_refc_domain domain, xfs_agblock_t bno, int *stat);
      23             : extern int xfs_refcount_get_rec(struct xfs_btree_cur *cur,
      24             :                 struct xfs_refcount_irec *irec, int *stat);
      25             : 
      26             : static inline uint32_t
      27             : xfs_refcount_encode_startblock(
      28             :         xfs_agblock_t           startblock,
      29             :         enum xfs_refc_domain    domain)
      30             : {
      31 69085251476 :         uint32_t                start;
      32             : 
      33             :         /*
      34             :          * low level btree operations need to handle the generic btree range
      35             :          * query functions (which set rc_domain == -1U), so we check that the
      36             :          * domain is /not/ shared.
      37             :          */
      38 69085251476 :         start = startblock & ~XFS_REFC_COWFLAG;
      39 69085251476 :         if (domain != XFS_REFC_DOMAIN_SHARED)
      40 18284135306 :                 start |= XFS_REFC_COWFLAG;
      41             : 
      42 69085251476 :         return start;
      43             : }
      44             : 
      45             : enum xfs_refcount_intent_type {
      46             :         XFS_REFCOUNT_INCREASE = 1,
      47             :         XFS_REFCOUNT_DECREASE,
      48             :         XFS_REFCOUNT_ALLOC_COW,
      49             :         XFS_REFCOUNT_FREE_COW,
      50             : };
      51             : 
      52             : #define XFS_REFCOUNT_INTENT_STRINGS \
      53             :         { XFS_REFCOUNT_INCREASE,        "incr" }, \
      54             :         { XFS_REFCOUNT_DECREASE,        "decr" }, \
      55             :         { XFS_REFCOUNT_ALLOC_COW,       "alloc_cow" }, \
      56             :         { XFS_REFCOUNT_FREE_COW,        "free_cow" }
      57             : 
      58             : struct xfs_refcount_intent {
      59             :         struct list_head                        ri_list;
      60             :         union {
      61             :                 struct xfs_perag                *ri_pag;
      62             :                 struct xfs_rtgroup              *ri_rtg;
      63             :         };
      64             :         enum xfs_refcount_intent_type           ri_type;
      65             :         xfs_extlen_t                            ri_blockcount;
      66             :         xfs_fsblock_t                           ri_startblock;
      67             :         bool                                    ri_realtime;
      68             : };
      69             : 
      70             : /* Check that the refcount is appropriate for the record domain. */
      71             : static inline bool
      72  5279571012 : xfs_refcount_check_domain(
      73             :         const struct xfs_refcount_irec  *irec)
      74             : {
      75  5279571012 :         if (irec->rc_domain == XFS_REFC_DOMAIN_COW && irec->rc_refcount != 1)
      76             :                 return false;
      77  5279573352 :         if (irec->rc_domain == XFS_REFC_DOMAIN_SHARED && irec->rc_refcount < 2)
      78           0 :                 return false;
      79             :         return true;
      80             : }
      81             : 
      82             : void xfs_refcount_update_get_group(struct xfs_mount *mp,
      83             :                 struct xfs_refcount_intent *ri);
      84             : 
      85             : void xfs_refcount_increase_extent(struct xfs_trans *tp, bool isrt,
      86             :                 struct xfs_bmbt_irec *irec);
      87             : void xfs_refcount_decrease_extent(struct xfs_trans *tp, bool isrt,
      88             :                 struct xfs_bmbt_irec *irec);
      89             : 
      90             : extern void xfs_refcount_finish_one_cleanup(struct xfs_trans *tp,
      91             :                 struct xfs_btree_cur *rcur, int error);
      92             : extern int xfs_refcount_finish_one(struct xfs_trans *tp,
      93             :                 struct xfs_refcount_intent *ri, struct xfs_btree_cur **pcur);
      94             : 
      95             : extern int xfs_refcount_find_shared(struct xfs_btree_cur *cur,
      96             :                 xfs_agblock_t agbno, xfs_extlen_t aglen, xfs_agblock_t *fbno,
      97             :                 xfs_extlen_t *flen, bool find_end_of_shared);
      98             : 
      99             : void xfs_refcount_alloc_cow_extent(struct xfs_trans *tp, bool isrt,
     100             :                 xfs_fsblock_t fsb, xfs_extlen_t len);
     101             : void xfs_refcount_free_cow_extent(struct xfs_trans *tp, bool isrt,
     102             :                 xfs_fsblock_t fsb, xfs_extlen_t len);
     103             : int xfs_refcount_recover_cow_leftovers(struct xfs_mount *mp,
     104             :                 struct xfs_perag *pag);
     105             : int xfs_refcount_recover_rtcow_leftovers(struct xfs_mount *mp,
     106             :                 struct xfs_rtgroup *rtg);
     107             : 
     108             : /*
     109             :  * While we're adjusting the refcounts records of an extent, we have
     110             :  * to keep an eye on the number of extents we're dirtying -- run too
     111             :  * many in a single transaction and we'll exceed the transaction's
     112             :  * reservation and crash the fs.  Each record adds 12 bytes to the
     113             :  * log (plus any key updates) so we'll conservatively assume 32 bytes
     114             :  * per record.  We must also leave space for btree splits on both ends
     115             :  * of the range and space for the CUD and a new CUI.
     116             :  *
     117             :  * Each EFI that we attach to the transaction is assumed to consume ~32 bytes.
     118             :  * This is a low estimate for an EFI tracking a single extent (16 bytes for the
     119             :  * EFI header, 16 for the extent, and 12 for the xlog op header), but the
     120             :  * estimate is acceptable if there's more than one extent being freed.
     121             :  * In the worst case of freeing every other block during a refcount decrease
     122             :  * operation, we amortize the space used for one EFI log item across 16
     123             :  * extents.
     124             :  */
     125             : #define XFS_REFCOUNT_ITEM_OVERHEAD      32
     126             : 
     127             : extern int xfs_refcount_has_records(struct xfs_btree_cur *cur,
     128             :                 enum xfs_refc_domain domain, xfs_agblock_t bno,
     129             :                 xfs_extlen_t len, enum xbtree_recpacking *outcome);
     130             : union xfs_btree_rec;
     131             : extern void xfs_refcount_btrec_to_irec(const union xfs_btree_rec *rec,
     132             :                 struct xfs_refcount_irec *irec);
     133             : xfs_failaddr_t xfs_refcount_check_perag_irec(struct xfs_perag *pag,
     134             :                 const struct xfs_refcount_irec *irec);
     135             : xfs_failaddr_t xfs_refcount_check_rtgroup_irec(struct xfs_rtgroup *rtg,
     136             :                 const struct xfs_refcount_irec *irec);
     137             : xfs_failaddr_t xfs_refcount_check_irec(struct xfs_btree_cur *cur,
     138             :                 const struct xfs_refcount_irec *irec);
     139             : extern int xfs_refcount_insert(struct xfs_btree_cur *cur,
     140             :                 struct xfs_refcount_irec *irec, int *stat);
     141             : 
     142             : extern struct kmem_cache        *xfs_refcount_intent_cache;
     143             : 
     144             : int __init xfs_refcount_intent_init_cache(void);
     145             : void xfs_refcount_intent_destroy_cache(void);
     146             : 
     147             : typedef int (*xfs_refcount_query_range_fn)(
     148             :         struct xfs_btree_cur            *cur,
     149             :         const struct xfs_refcount_irec  *rec,
     150             :         void                            *priv);
     151             : 
     152             : int xfs_refcount_query_range(struct xfs_btree_cur *cur,
     153             :                 const struct xfs_refcount_irec *low_rec,
     154             :                 const struct xfs_refcount_irec *high_rec,
     155             :                 xfs_refcount_query_range_fn fn, void *priv);
     156             : 
     157             : #endif  /* __XFS_REFCOUNT_H__ */

Generated by: LCOV version 1.14