Merge tag 'icc-6.7-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/djakov/icc...
[linux-2.6-microblaze.git] / fs / xfs / libxfs / xfs_defer.h
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_ATTR,
23         XFS_DEFER_OPS_TYPE_MAX,
24 };
25
26 /*
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
29  * item.
30  */
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;
38 };
39
40 void xfs_defer_add(struct xfs_trans *tp, enum xfs_defer_ops_type type,
41                 struct list_head *h);
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);
46
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;
60 };
61
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;
68
69
70 /*
71  * Deferred operation item relogging limits.
72  */
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 */
75
76 /* Resources that must be held across a transaction roll. */
77 struct xfs_defer_resources {
78         /* held buffers */
79         struct xfs_buf          *dr_bp[XFS_DEFER_OPS_NR_BUFS];
80
81         /* inodes with no unlock flags */
82         struct xfs_inode        *dr_ip[XFS_DEFER_OPS_NR_INODES];
83
84         /* number of held buffers */
85         unsigned short          dr_bufs;
86
87         /* bitmap of ordered buffers */
88         unsigned short          dr_ordered;
89
90         /* number of held inodes */
91         unsigned short          dr_inos;
92 };
93
94 /*
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.
97  */
98 struct xfs_defer_capture {
99         /* List of other capture structures. */
100         struct list_head        dfc_list;
101
102         /* Deferred ops state saved from the transaction. */
103         struct list_head        dfc_dfops;
104         unsigned int            dfc_tpflags;
105
106         /* Block reservations for the data and rt devices. */
107         unsigned int            dfc_blkres;
108         unsigned int            dfc_rtxres;
109
110         /* Log reservation saved from the transaction. */
111         unsigned int            dfc_logres;
112
113         struct xfs_defer_resources dfc_held;
114 };
115
116 /*
117  * Functions to capture a chain of deferred operations and continue them later.
118  * This doesn't normally happen except log recovery.
119  */
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_abort(struct xfs_mount *mp,
125                 struct xfs_defer_capture *d);
126 void xfs_defer_resources_rele(struct xfs_defer_resources *dres);
127
128 int __init xfs_defer_init_item_caches(void);
129 void xfs_defer_destroy_item_caches(void);
130
131 #endif /* __XFS_DEFER_H__ */