1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2016 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
6 #ifndef __XFS_DEFER_H__
7 #define __XFS_DEFER_H__
10 struct xfs_defer_op_type;
11 struct xfs_defer_capture;
14 * Header for deferred operation list.
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_ATTR,
23 XFS_DEFER_OPS_TYPE_MAX,
27 * Save a log intent item and a list of extents, so that we can replay
28 * whatever action had to happen to the extent list and file the log done
31 struct xfs_defer_pending {
32 struct list_head dfp_list; /* pending items */
33 struct list_head dfp_work; /* work items */
34 struct xfs_log_item *dfp_intent; /* log intent item */
35 struct xfs_log_item *dfp_done; /* log done item */
36 unsigned int dfp_count; /* # extent items */
37 enum xfs_defer_ops_type dfp_type;
40 void xfs_defer_add(struct xfs_trans *tp, enum xfs_defer_ops_type type,
42 int xfs_defer_finish_noroll(struct xfs_trans **tp);
43 int xfs_defer_finish(struct xfs_trans **tp);
44 void xfs_defer_cancel(struct xfs_trans *);
45 void xfs_defer_move(struct xfs_trans *dtp, struct xfs_trans *stp);
47 /* Description of a deferred type. */
48 struct xfs_defer_op_type {
49 struct xfs_log_item *(*create_intent)(struct xfs_trans *tp,
50 struct list_head *items, unsigned int count, bool sort);
51 void (*abort_intent)(struct xfs_log_item *intent);
52 struct xfs_log_item *(*create_done)(struct xfs_trans *tp,
53 struct xfs_log_item *intent, unsigned int count);
54 int (*finish_item)(struct xfs_trans *tp, struct xfs_log_item *done,
55 struct list_head *item, struct xfs_btree_cur **state);
56 void (*finish_cleanup)(struct xfs_trans *tp,
57 struct xfs_btree_cur *state, int error);
58 void (*cancel_item)(struct list_head *item);
59 unsigned int max_items;
62 extern const struct xfs_defer_op_type xfs_bmap_update_defer_type;
63 extern const struct xfs_defer_op_type xfs_refcount_update_defer_type;
64 extern const struct xfs_defer_op_type xfs_rmap_update_defer_type;
65 extern const struct xfs_defer_op_type xfs_extent_free_defer_type;
66 extern const struct xfs_defer_op_type xfs_agfl_free_defer_type;
67 extern const struct xfs_defer_op_type xfs_attr_defer_type;
71 * Deferred operation item relogging limits.
73 #define XFS_DEFER_OPS_NR_INODES 2 /* join up to two inodes */
74 #define XFS_DEFER_OPS_NR_BUFS 2 /* join up to two buffers */
76 /* Resources that must be held across a transaction roll. */
77 struct xfs_defer_resources {
79 struct xfs_buf *dr_bp[XFS_DEFER_OPS_NR_BUFS];
81 /* inodes with no unlock flags */
82 struct xfs_inode *dr_ip[XFS_DEFER_OPS_NR_INODES];
84 /* number of held buffers */
85 unsigned short dr_bufs;
87 /* bitmap of ordered buffers */
88 unsigned short dr_ordered;
90 /* number of held inodes */
91 unsigned short dr_inos;
95 * This structure enables a dfops user to detach the chain of deferred
96 * operations from a transaction so that they can be continued later.
98 struct xfs_defer_capture {
99 /* List of other capture structures. */
100 struct list_head dfc_list;
102 /* Deferred ops state saved from the transaction. */
103 struct list_head dfc_dfops;
104 unsigned int dfc_tpflags;
106 /* Block reservations for the data and rt devices. */
107 unsigned int dfc_blkres;
108 unsigned int dfc_rtxres;
110 /* Log reservation saved from the transaction. */
111 unsigned int dfc_logres;
113 struct xfs_defer_resources dfc_held;
117 * Functions to capture a chain of deferred operations and continue them later.
118 * This doesn't normally happen except log recovery.
120 int xfs_defer_ops_capture_and_commit(struct xfs_trans *tp,
121 struct list_head *capture_list);
122 void xfs_defer_ops_continue(struct xfs_defer_capture *d, struct xfs_trans *tp,
123 struct xfs_defer_resources *dres);
124 void xfs_defer_ops_capture_free(struct xfs_mount *mp,
125 struct xfs_defer_capture *d);
126 void xfs_defer_resources_rele(struct xfs_defer_resources *dres);
128 int __init xfs_defer_init_item_caches(void);
129 void xfs_defer_destroy_item_caches(void);
131 #endif /* __XFS_DEFER_H__ */