hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/btrfs/transaction.h
....@@ -12,13 +12,12 @@
1212 #include "ctree.h"
1313
1414 enum btrfs_trans_state {
15
- TRANS_STATE_RUNNING = 0,
16
- TRANS_STATE_BLOCKED = 1,
17
- TRANS_STATE_COMMIT_START = 2,
18
- TRANS_STATE_COMMIT_DOING = 3,
19
- TRANS_STATE_UNBLOCKED = 4,
20
- TRANS_STATE_COMPLETED = 5,
21
- TRANS_STATE_MAX = 6,
15
+ TRANS_STATE_RUNNING,
16
+ TRANS_STATE_COMMIT_START,
17
+ TRANS_STATE_COMMIT_DOING,
18
+ TRANS_STATE_UNBLOCKED,
19
+ TRANS_STATE_COMPLETED,
20
+ TRANS_STATE_MAX,
2221 };
2322
2423 #define BTRFS_TRANS_HAVE_FREE_BGS 0
....@@ -39,7 +38,6 @@
3938 */
4039 atomic_t num_writers;
4140 refcount_t use_count;
42
- atomic_t pending_ordered;
4341
4442 unsigned long flags;
4543
....@@ -51,9 +49,8 @@
5149 time64_t start_time;
5250 wait_queue_head_t writer_wait;
5351 wait_queue_head_t commit_wait;
54
- wait_queue_head_t pending_wait;
5552 struct list_head pending_snapshots;
56
- struct list_head pending_chunks;
53
+ struct list_head dev_update_list;
5754 struct list_head switch_commits;
5855 struct list_head dirty_bgs;
5956
....@@ -74,6 +71,7 @@
7471 */
7572 struct list_head io_bgs;
7673 struct list_head dropped_roots;
74
+ struct extent_io_tree pinned_extents;
7775
7876 /*
7977 * we need to make sure block group deletion doesn't race with
....@@ -82,12 +80,18 @@
8280 */
8381 struct mutex cache_write_mutex;
8482 spinlock_t dirty_bgs_lock;
85
- unsigned int num_dirty_bgs;
8683 /* Protected by spin lock fs_info->unused_bgs_lock. */
8784 struct list_head deleted_bgs;
8885 spinlock_t dropped_roots_lock;
8986 struct btrfs_delayed_ref_root delayed_refs;
9087 struct btrfs_fs_info *fs_info;
88
+
89
+ /*
90
+ * Number of ordered extents the transaction must wait for before
91
+ * committing. These are ordered extents started by a fast fsync.
92
+ */
93
+ atomic_t pending_ordered;
94
+ wait_queue_head_t pending_wait;
9195 };
9296
9397 #define __TRANS_FREEZABLE (1U << 0)
....@@ -108,6 +112,7 @@
108112 #define TRANS_EXTWRITERS (__TRANS_START | __TRANS_ATTACH)
109113
110114 #define BTRFS_SEND_TRANS_STUB ((void *)1)
115
+#define BTRFS_DIO_SYNC_STUB ((void *)2)
111116
112117 struct btrfs_trans_handle {
113118 u64 transid;
....@@ -119,17 +124,28 @@
119124 struct btrfs_block_rsv *orig_rsv;
120125 refcount_t use_count;
121126 unsigned int type;
127
+ /*
128
+ * Error code of transaction abort, set outside of locks and must use
129
+ * the READ_ONCE/WRITE_ONCE access
130
+ */
122131 short aborted;
123132 bool adding_csums;
124133 bool allocating_chunk;
125134 bool can_flush_pending_bgs;
126135 bool reloc_reserved;
127
- bool sync;
128136 bool dirty;
129137 struct btrfs_root *root;
130138 struct btrfs_fs_info *fs_info;
131139 struct list_head new_bgs;
132140 };
141
+
142
+/*
143
+ * The abort status can be changed between calls and is not protected by locks.
144
+ * This accepts btrfs_transaction and btrfs_trans_handle as types. Once it's
145
+ * set to a non-zero value it does not change, so the macro should be in checks
146
+ * but is not necessary for further reads of the value.
147
+ */
148
+#define TRANS_ABORTED(trans) (unlikely(READ_ONCE((trans)->aborted)))
133149
134150 struct btrfs_pending_snapshot {
135151 struct dentry *dentry;
....@@ -143,18 +159,20 @@
143159 struct btrfs_block_rsv block_rsv;
144160 /* extra metadata reservation for relocation */
145161 int error;
162
+ /* Preallocated anonymous block device number */
163
+ dev_t anon_dev;
146164 bool readonly;
147165 struct list_head list;
148166 };
149167
150168 static inline void btrfs_set_inode_last_trans(struct btrfs_trans_handle *trans,
151
- struct inode *inode)
169
+ struct btrfs_inode *inode)
152170 {
153
- spin_lock(&BTRFS_I(inode)->lock);
154
- BTRFS_I(inode)->last_trans = trans->transaction->transid;
155
- BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid;
156
- BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->root->last_log_commit;
157
- spin_unlock(&BTRFS_I(inode)->lock);
171
+ spin_lock(&inode->lock);
172
+ inode->last_trans = trans->transaction->transid;
173
+ inode->last_sub_trans = inode->root->log_transid;
174
+ inode->last_log_commit = inode->last_sub_trans - 1;
175
+ spin_unlock(&inode->lock);
158176 }
159177
160178 /*
....@@ -185,10 +203,9 @@
185203 unsigned int num_items);
186204 struct btrfs_trans_handle *btrfs_start_transaction_fallback_global_rsv(
187205 struct btrfs_root *root,
188
- unsigned int num_items,
189
- int min_factor);
206
+ unsigned int num_items);
190207 struct btrfs_trans_handle *btrfs_join_transaction(struct btrfs_root *root);
191
-struct btrfs_trans_handle *btrfs_join_transaction_nolock(struct btrfs_root *root);
208
+struct btrfs_trans_handle *btrfs_join_transaction_spacecache(struct btrfs_root *root);
192209 struct btrfs_trans_handle *btrfs_join_transaction_nostart(struct btrfs_root *root);
193210 struct btrfs_trans_handle *btrfs_attach_transaction(struct btrfs_root *root);
194211 struct btrfs_trans_handle *btrfs_attach_transaction_barrier(
....@@ -201,20 +218,6 @@
201218 int btrfs_commit_transaction(struct btrfs_trans_handle *trans);
202219 int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
203220 int wait_for_unblock);
204
-
205
-/*
206
- * Try to commit transaction asynchronously, so this is safe to call
207
- * even holding a spinlock.
208
- *
209
- * It's done by informing transaction_kthread to commit transaction without
210
- * waiting for commit interval.
211
- */
212
-static inline void btrfs_commit_transaction_locksafe(
213
- struct btrfs_fs_info *fs_info)
214
-{
215
- set_bit(BTRFS_FS_NEED_ASYNC_COMMIT, &fs_info->flags);
216
- wake_up_process(fs_info->transaction_kthread);
217
-}
218221 int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans);
219222 int btrfs_should_end_transaction(struct btrfs_trans_handle *trans);
220223 void btrfs_throttle(struct btrfs_fs_info *fs_info);
....@@ -222,8 +225,6 @@
222225 struct btrfs_root *root);
223226 int btrfs_write_marked_extents(struct btrfs_fs_info *fs_info,
224227 struct extent_io_tree *dirty_pages, int mark);
225
-int btrfs_wait_extents(struct btrfs_fs_info *fs_info,
226
- struct extent_io_tree *dirty_pages);
227228 int btrfs_wait_tree_log_extents(struct btrfs_root *root, int mark);
228229 int btrfs_transaction_blocked(struct btrfs_fs_info *info);
229230 int btrfs_transaction_in_commit(struct btrfs_fs_info *info);
....@@ -231,5 +232,6 @@
231232 void btrfs_apply_pending_changes(struct btrfs_fs_info *fs_info);
232233 void btrfs_add_dropped_root(struct btrfs_trans_handle *trans,
233234 struct btrfs_root *root);
235
+void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans);
234236
235237 #endif