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