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_DEFER_H__ 7 #define __XFS_DEFER_H__ 8 9 struct xfs_btree_cur; 10 struct xfs_defer_op_type; 11 struct xfs_defer_capture; 12 13 /* 14 * Header for deferred operation list. 15 */ 16 enum xfs_defer_ops_type { 17 XFS_DEFER_OPS_TYPE_BMAP, 18 XFS_DEFER_OPS_TYPE_REFCOUNT, 19 XFS_DEFER_OPS_TYPE_RMAP, 20 XFS_DEFER_OPS_TYPE_FREE, 21 XFS_DEFER_OPS_TYPE_AGFL_FREE, 22 XFS_DEFER_OPS_TYPE_MAX, 23 }; 24 25 /* 26 * Save a log intent item and a list of extents, so that we can replay 27 * whatever action had to happen to the extent list and file the log done 28 * item. 29 */ 30 struct xfs_defer_pending { 31 struct list_head dfp_list; /* pending items */ 32 struct list_head dfp_work; /* work items */ 33 struct xfs_log_item *dfp_intent; /* log intent item */ 34 struct xfs_log_item *dfp_done; /* log done item */ 35 unsigned int dfp_count; /* # extent items */ 36 enum xfs_defer_ops_type dfp_type; 37 }; 38 39 void xfs_defer_add(struct xfs_trans *tp, enum xfs_defer_ops_type type, 40 struct list_head *h); 41 int xfs_defer_finish_noroll(struct xfs_trans **tp); 42 int xfs_defer_finish(struct xfs_trans **tp); 43 void xfs_defer_cancel(struct xfs_trans *); 44 void xfs_defer_move(struct xfs_trans *dtp, struct xfs_trans *stp); 45 46 /* Description of a deferred type. */ 47 struct xfs_defer_op_type { 48 struct xfs_log_item *(*create_intent)(struct xfs_trans *tp, 49 struct list_head *items, unsigned int count, bool sort); 50 void (*abort_intent)(struct xfs_log_item *intent); 51 struct xfs_log_item *(*create_done)(struct xfs_trans *tp, 52 struct xfs_log_item *intent, unsigned int count); 53 int (*finish_item)(struct xfs_trans *tp, struct xfs_log_item *done, 54 struct list_head *item, struct xfs_btree_cur **state); 55 void (*finish_cleanup)(struct xfs_trans *tp, 56 struct xfs_btree_cur *state, int error); 57 void (*cancel_item)(struct list_head *item); 58 unsigned int max_items; 59 }; 60 61 extern const struct xfs_defer_op_type xfs_bmap_update_defer_type; 62 extern const struct xfs_defer_op_type xfs_refcount_update_defer_type; 63 extern const struct xfs_defer_op_type xfs_rmap_update_defer_type; 64 extern const struct xfs_defer_op_type xfs_extent_free_defer_type; 65 extern const struct xfs_defer_op_type xfs_agfl_free_defer_type; 66 67 /* 68 * Deferred operation item relogging limits. 69 */ 70 #define XFS_DEFER_OPS_NR_INODES 2 /* join up to two inodes */ 71 #define XFS_DEFER_OPS_NR_BUFS 2 /* join up to two buffers */ 72 73 /* Resources that must be held across a transaction roll. */ 74 struct xfs_defer_resources { 75 /* held buffers */ 76 struct xfs_buf *dr_bp[XFS_DEFER_OPS_NR_BUFS]; 77 78 /* inodes with no unlock flags */ 79 struct xfs_inode *dr_ip[XFS_DEFER_OPS_NR_INODES]; 80 81 /* number of held buffers */ 82 unsigned short dr_bufs; 83 84 /* bitmap of ordered buffers */ 85 unsigned short dr_ordered; 86 87 /* number of held inodes */ 88 unsigned short dr_inos; 89 }; 90 91 /* 92 * This structure enables a dfops user to detach the chain of deferred 93 * operations from a transaction so that they can be continued later. 94 */ 95 struct xfs_defer_capture { 96 /* List of other capture structures. */ 97 struct list_head dfc_list; 98 99 /* Deferred ops state saved from the transaction. */ 100 struct list_head dfc_dfops; 101 unsigned int dfc_tpflags; 102 103 /* Block reservations for the data and rt devices. */ 104 unsigned int dfc_blkres; 105 unsigned int dfc_rtxres; 106 107 /* Log reservation saved from the transaction. */ 108 unsigned int dfc_logres; 109 110 struct xfs_defer_resources dfc_held; 111 }; 112 113 /* 114 * Functions to capture a chain of deferred operations and continue them later. 115 * This doesn't normally happen except log recovery. 116 */ 117 int xfs_defer_ops_capture_and_commit(struct xfs_trans *tp, 118 struct list_head *capture_list); 119 void xfs_defer_ops_continue(struct xfs_defer_capture *d, struct xfs_trans *tp, 120 struct xfs_defer_resources *dres); 121 void xfs_defer_ops_capture_free(struct xfs_mount *mp, 122 struct xfs_defer_capture *d); 123 void xfs_defer_resources_rele(struct xfs_defer_resources *dres); 124 125 int __init xfs_defer_init_item_caches(void); 126 void xfs_defer_destroy_item_caches(void); 127 128 #endif /* __XFS_DEFER_H__ */ 129