]> Git Repo - linux.git/blob - fs/xfs/libxfs/xfs_defer.h
Linux 6.14-rc3
[linux.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 <[email protected]>
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  * Save a log intent item and a list of extents, so that we can replay
15  * whatever action had to happen to the extent list and file the log done
16  * item.
17  */
18 struct xfs_defer_pending {
19         struct list_head                dfp_list;       /* pending items */
20         struct list_head                dfp_work;       /* work items */
21         struct xfs_log_item             *dfp_intent;    /* log intent item */
22         struct xfs_log_item             *dfp_done;      /* log done item */
23         const struct xfs_defer_op_type  *dfp_ops;
24         unsigned int                    dfp_count;      /* # extent items */
25         unsigned int                    dfp_flags;
26 };
27
28 /*
29  * Create a log intent item for this deferred item, but don't actually finish
30  * the work.  Caller must clear this before the final transaction commit.
31  */
32 #define XFS_DEFER_PAUSED        (1U << 0)
33
34 #define XFS_DEFER_PENDING_STRINGS \
35         { XFS_DEFER_PAUSED,     "paused" }
36
37 void xfs_defer_item_pause(struct xfs_trans *tp, struct xfs_defer_pending *dfp);
38 void xfs_defer_item_unpause(struct xfs_trans *tp, struct xfs_defer_pending *dfp);
39
40 struct xfs_defer_pending *xfs_defer_add(struct xfs_trans *tp, struct list_head *h,
41                 const struct xfs_defer_op_type *ops);
42 int xfs_defer_finish_noroll(struct xfs_trans **tp);
43 int xfs_defer_finish(struct xfs_trans **tp);
44 int xfs_defer_finish_one(struct xfs_trans *tp, struct xfs_defer_pending *dfp);
45 void xfs_defer_cancel(struct xfs_trans *);
46 void xfs_defer_move(struct xfs_trans *dtp, struct xfs_trans *stp);
47
48 /* Description of a deferred type. */
49 struct xfs_defer_op_type {
50         const char              *name;
51         unsigned int            max_items;
52         struct xfs_log_item *(*create_intent)(struct xfs_trans *tp,
53                         struct list_head *items, unsigned int count, bool sort);
54         void (*abort_intent)(struct xfs_log_item *intent);
55         struct xfs_log_item *(*create_done)(struct xfs_trans *tp,
56                         struct xfs_log_item *intent, unsigned int count);
57         int (*finish_item)(struct xfs_trans *tp, struct xfs_log_item *done,
58                         struct list_head *item, struct xfs_btree_cur **state);
59         void (*finish_cleanup)(struct xfs_trans *tp,
60                         struct xfs_btree_cur *state, int error);
61         void (*cancel_item)(struct list_head *item);
62         int (*recover_work)(struct xfs_defer_pending *dfp,
63                             struct list_head *capture_list);
64         struct xfs_log_item *(*relog_intent)(struct xfs_trans *tp,
65                         struct xfs_log_item *intent,
66                         struct xfs_log_item *done_item);
67 };
68
69 extern const struct xfs_defer_op_type xfs_bmap_update_defer_type;
70 extern const struct xfs_defer_op_type xfs_refcount_update_defer_type;
71 extern const struct xfs_defer_op_type xfs_rtrefcount_update_defer_type;
72 extern const struct xfs_defer_op_type xfs_rmap_update_defer_type;
73 extern const struct xfs_defer_op_type xfs_rtrmap_update_defer_type;
74 extern const struct xfs_defer_op_type xfs_extent_free_defer_type;
75 extern const struct xfs_defer_op_type xfs_agfl_free_defer_type;
76 extern const struct xfs_defer_op_type xfs_rtextent_free_defer_type;
77 extern const struct xfs_defer_op_type xfs_attr_defer_type;
78 extern const struct xfs_defer_op_type xfs_exchmaps_defer_type;
79
80 /*
81  * Deferred operation item relogging limits.
82  */
83
84 /*
85  * Rename w/ parent pointers can require up to 5 inodes with deferred ops to
86  * be joined to the transaction: src_dp, target_dp, src_ip, target_ip, and wip.
87  * These inodes are locked in sorted order by their inode numbers
88  */
89 #define XFS_DEFER_OPS_NR_INODES 5
90 #define XFS_DEFER_OPS_NR_BUFS   2       /* join up to two buffers */
91
92 /* Resources that must be held across a transaction roll. */
93 struct xfs_defer_resources {
94         /* held buffers */
95         struct xfs_buf          *dr_bp[XFS_DEFER_OPS_NR_BUFS];
96
97         /* inodes with no unlock flags */
98         struct xfs_inode        *dr_ip[XFS_DEFER_OPS_NR_INODES];
99
100         /* number of held buffers */
101         unsigned short          dr_bufs;
102
103         /* bitmap of ordered buffers */
104         unsigned short          dr_ordered;
105
106         /* number of held inodes */
107         unsigned short          dr_inos;
108 };
109
110 /*
111  * This structure enables a dfops user to detach the chain of deferred
112  * operations from a transaction so that they can be continued later.
113  */
114 struct xfs_defer_capture {
115         /* List of other capture structures. */
116         struct list_head        dfc_list;
117
118         /* Deferred ops state saved from the transaction. */
119         struct list_head        dfc_dfops;
120         unsigned int            dfc_tpflags;
121
122         /* Block reservations for the data and rt devices. */
123         unsigned int            dfc_blkres;
124         unsigned int            dfc_rtxres;
125
126         /* Log reservation saved from the transaction. */
127         unsigned int            dfc_logres;
128
129         struct xfs_defer_resources dfc_held;
130 };
131
132 /*
133  * Functions to capture a chain of deferred operations and continue them later.
134  * This doesn't normally happen except log recovery.
135  */
136 int xfs_defer_ops_capture_and_commit(struct xfs_trans *tp,
137                 struct list_head *capture_list);
138 void xfs_defer_ops_continue(struct xfs_defer_capture *d, struct xfs_trans *tp,
139                 struct xfs_defer_resources *dres);
140 void xfs_defer_ops_capture_abort(struct xfs_mount *mp,
141                 struct xfs_defer_capture *d);
142 void xfs_defer_resources_rele(struct xfs_defer_resources *dres);
143
144 void xfs_defer_start_recovery(struct xfs_log_item *lip,
145                 struct list_head *r_dfops, const struct xfs_defer_op_type *ops);
146 void xfs_defer_cancel_recovery(struct xfs_mount *mp,
147                 struct xfs_defer_pending *dfp);
148 int xfs_defer_finish_recovery(struct xfs_mount *mp,
149                 struct xfs_defer_pending *dfp, struct list_head *capture_list);
150
151 static inline void
152 xfs_defer_add_item(
153         struct xfs_defer_pending        *dfp,
154         struct list_head                *work)
155 {
156         list_add_tail(work, &dfp->dfp_work);
157         dfp->dfp_count++;
158 }
159
160 int __init xfs_defer_init_item_caches(void);
161 void xfs_defer_destroy_item_caches(void);
162
163 void xfs_defer_add_barrier(struct xfs_trans *tp);
164
165 #endif /* __XFS_DEFER_H__ */
This page took 0.033212 seconds and 4 git commands to generate.