^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2016 Oracle. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Author: Darrick J. Wong <darrick.wong@oracle.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef __XFS_REFCOUNT_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define __XFS_REFCOUNT_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) extern int xfs_refcount_lookup_le(struct xfs_btree_cur *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) xfs_agblock_t bno, int *stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) extern int xfs_refcount_lookup_ge(struct xfs_btree_cur *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) xfs_agblock_t bno, int *stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) extern int xfs_refcount_lookup_eq(struct xfs_btree_cur *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) xfs_agblock_t bno, int *stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) extern int xfs_refcount_get_rec(struct xfs_btree_cur *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct xfs_refcount_irec *irec, int *stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) enum xfs_refcount_intent_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) XFS_REFCOUNT_INCREASE = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) XFS_REFCOUNT_DECREASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) XFS_REFCOUNT_ALLOC_COW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) XFS_REFCOUNT_FREE_COW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct xfs_refcount_intent {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct list_head ri_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) enum xfs_refcount_intent_type ri_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) xfs_fsblock_t ri_startblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) xfs_extlen_t ri_blockcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) void xfs_refcount_increase_extent(struct xfs_trans *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct xfs_bmbt_irec *irec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) void xfs_refcount_decrease_extent(struct xfs_trans *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct xfs_bmbt_irec *irec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) extern void xfs_refcount_finish_one_cleanup(struct xfs_trans *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct xfs_btree_cur *rcur, int error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) extern int xfs_refcount_finish_one(struct xfs_trans *tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) enum xfs_refcount_intent_type type, xfs_fsblock_t startblock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) xfs_extlen_t blockcount, xfs_fsblock_t *new_fsb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) xfs_extlen_t *new_len, struct xfs_btree_cur **pcur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) extern int xfs_refcount_find_shared(struct xfs_btree_cur *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) xfs_agblock_t agbno, xfs_extlen_t aglen, xfs_agblock_t *fbno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) xfs_extlen_t *flen, bool find_end_of_shared);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) void xfs_refcount_alloc_cow_extent(struct xfs_trans *tp, xfs_fsblock_t fsb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) xfs_extlen_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) void xfs_refcount_free_cow_extent(struct xfs_trans *tp, xfs_fsblock_t fsb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) xfs_extlen_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) extern int xfs_refcount_recover_cow_leftovers(struct xfs_mount *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) xfs_agnumber_t agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * While we're adjusting the refcounts records of an extent, we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * to keep an eye on the number of extents we're dirtying -- run too
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * many in a single transaction and we'll exceed the transaction's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * reservation and crash the fs. Each record adds 12 bytes to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * log (plus any key updates) so we'll conservatively assume 32 bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * per record. We must also leave space for btree splits on both ends
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * of the range and space for the CUD and a new CUI.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define XFS_REFCOUNT_ITEM_OVERHEAD 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static inline xfs_fileoff_t xfs_refcount_max_unmap(int log_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return (log_res * 3 / 4) / XFS_REFCOUNT_ITEM_OVERHEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) extern int xfs_refcount_has_record(struct xfs_btree_cur *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) xfs_agblock_t bno, xfs_extlen_t len, bool *exists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) union xfs_btree_rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) extern void xfs_refcount_btrec_to_irec(union xfs_btree_rec *rec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct xfs_refcount_irec *irec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) extern int xfs_refcount_insert(struct xfs_btree_cur *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct xfs_refcount_irec *irec, int *stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #endif /* __XFS_REFCOUNT_H__ */