| .. | .. |
|---|
| 12 | 12 | #include "ctree.h" |
|---|
| 13 | 13 | |
|---|
| 14 | 14 | 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, |
|---|
| 22 | 21 | }; |
|---|
| 23 | 22 | |
|---|
| 24 | 23 | #define BTRFS_TRANS_HAVE_FREE_BGS 0 |
|---|
| .. | .. |
|---|
| 39 | 38 | */ |
|---|
| 40 | 39 | atomic_t num_writers; |
|---|
| 41 | 40 | refcount_t use_count; |
|---|
| 42 | | - atomic_t pending_ordered; |
|---|
| 43 | 41 | |
|---|
| 44 | 42 | unsigned long flags; |
|---|
| 45 | 43 | |
|---|
| .. | .. |
|---|
| 51 | 49 | time64_t start_time; |
|---|
| 52 | 50 | wait_queue_head_t writer_wait; |
|---|
| 53 | 51 | wait_queue_head_t commit_wait; |
|---|
| 54 | | - wait_queue_head_t pending_wait; |
|---|
| 55 | 52 | struct list_head pending_snapshots; |
|---|
| 56 | | - struct list_head pending_chunks; |
|---|
| 53 | + struct list_head dev_update_list; |
|---|
| 57 | 54 | struct list_head switch_commits; |
|---|
| 58 | 55 | struct list_head dirty_bgs; |
|---|
| 59 | 56 | |
|---|
| .. | .. |
|---|
| 74 | 71 | */ |
|---|
| 75 | 72 | struct list_head io_bgs; |
|---|
| 76 | 73 | struct list_head dropped_roots; |
|---|
| 74 | + struct extent_io_tree pinned_extents; |
|---|
| 77 | 75 | |
|---|
| 78 | 76 | /* |
|---|
| 79 | 77 | * we need to make sure block group deletion doesn't race with |
|---|
| .. | .. |
|---|
| 82 | 80 | */ |
|---|
| 83 | 81 | struct mutex cache_write_mutex; |
|---|
| 84 | 82 | spinlock_t dirty_bgs_lock; |
|---|
| 85 | | - unsigned int num_dirty_bgs; |
|---|
| 86 | 83 | /* Protected by spin lock fs_info->unused_bgs_lock. */ |
|---|
| 87 | 84 | struct list_head deleted_bgs; |
|---|
| 88 | 85 | spinlock_t dropped_roots_lock; |
|---|
| 89 | 86 | struct btrfs_delayed_ref_root delayed_refs; |
|---|
| 90 | 87 | 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; |
|---|
| 91 | 95 | }; |
|---|
| 92 | 96 | |
|---|
| 93 | 97 | #define __TRANS_FREEZABLE (1U << 0) |
|---|
| .. | .. |
|---|
| 108 | 112 | #define TRANS_EXTWRITERS (__TRANS_START | __TRANS_ATTACH) |
|---|
| 109 | 113 | |
|---|
| 110 | 114 | #define BTRFS_SEND_TRANS_STUB ((void *)1) |
|---|
| 115 | +#define BTRFS_DIO_SYNC_STUB ((void *)2) |
|---|
| 111 | 116 | |
|---|
| 112 | 117 | struct btrfs_trans_handle { |
|---|
| 113 | 118 | u64 transid; |
|---|
| .. | .. |
|---|
| 119 | 124 | struct btrfs_block_rsv *orig_rsv; |
|---|
| 120 | 125 | refcount_t use_count; |
|---|
| 121 | 126 | 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 | + */ |
|---|
| 122 | 131 | short aborted; |
|---|
| 123 | 132 | bool adding_csums; |
|---|
| 124 | 133 | bool allocating_chunk; |
|---|
| 125 | 134 | bool can_flush_pending_bgs; |
|---|
| 126 | 135 | bool reloc_reserved; |
|---|
| 127 | | - bool sync; |
|---|
| 128 | 136 | bool dirty; |
|---|
| 129 | 137 | struct btrfs_root *root; |
|---|
| 130 | 138 | struct btrfs_fs_info *fs_info; |
|---|
| 131 | 139 | struct list_head new_bgs; |
|---|
| 132 | 140 | }; |
|---|
| 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))) |
|---|
| 133 | 149 | |
|---|
| 134 | 150 | struct btrfs_pending_snapshot { |
|---|
| 135 | 151 | struct dentry *dentry; |
|---|
| .. | .. |
|---|
| 143 | 159 | struct btrfs_block_rsv block_rsv; |
|---|
| 144 | 160 | /* extra metadata reservation for relocation */ |
|---|
| 145 | 161 | int error; |
|---|
| 162 | + /* Preallocated anonymous block device number */ |
|---|
| 163 | + dev_t anon_dev; |
|---|
| 146 | 164 | bool readonly; |
|---|
| 147 | 165 | struct list_head list; |
|---|
| 148 | 166 | }; |
|---|
| 149 | 167 | |
|---|
| 150 | 168 | static inline void btrfs_set_inode_last_trans(struct btrfs_trans_handle *trans, |
|---|
| 151 | | - struct inode *inode) |
|---|
| 169 | + struct btrfs_inode *inode) |
|---|
| 152 | 170 | { |
|---|
| 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); |
|---|
| 158 | 176 | } |
|---|
| 159 | 177 | |
|---|
| 160 | 178 | /* |
|---|
| .. | .. |
|---|
| 185 | 203 | unsigned int num_items); |
|---|
| 186 | 204 | struct btrfs_trans_handle *btrfs_start_transaction_fallback_global_rsv( |
|---|
| 187 | 205 | struct btrfs_root *root, |
|---|
| 188 | | - unsigned int num_items, |
|---|
| 189 | | - int min_factor); |
|---|
| 206 | + unsigned int num_items); |
|---|
| 190 | 207 | 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); |
|---|
| 192 | 209 | struct btrfs_trans_handle *btrfs_join_transaction_nostart(struct btrfs_root *root); |
|---|
| 193 | 210 | struct btrfs_trans_handle *btrfs_attach_transaction(struct btrfs_root *root); |
|---|
| 194 | 211 | struct btrfs_trans_handle *btrfs_attach_transaction_barrier( |
|---|
| .. | .. |
|---|
| 201 | 218 | int btrfs_commit_transaction(struct btrfs_trans_handle *trans); |
|---|
| 202 | 219 | int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans, |
|---|
| 203 | 220 | 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 | | -} |
|---|
| 218 | 221 | int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans); |
|---|
| 219 | 222 | int btrfs_should_end_transaction(struct btrfs_trans_handle *trans); |
|---|
| 220 | 223 | void btrfs_throttle(struct btrfs_fs_info *fs_info); |
|---|
| .. | .. |
|---|
| 222 | 225 | struct btrfs_root *root); |
|---|
| 223 | 226 | int btrfs_write_marked_extents(struct btrfs_fs_info *fs_info, |
|---|
| 224 | 227 | 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); |
|---|
| 227 | 228 | int btrfs_wait_tree_log_extents(struct btrfs_root *root, int mark); |
|---|
| 228 | 229 | int btrfs_transaction_blocked(struct btrfs_fs_info *info); |
|---|
| 229 | 230 | int btrfs_transaction_in_commit(struct btrfs_fs_info *info); |
|---|
| .. | .. |
|---|
| 231 | 232 | void btrfs_apply_pending_changes(struct btrfs_fs_info *fs_info); |
|---|
| 232 | 233 | void btrfs_add_dropped_root(struct btrfs_trans_handle *trans, |
|---|
| 233 | 234 | struct btrfs_root *root); |
|---|
| 235 | +void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans); |
|---|
| 234 | 236 | |
|---|
| 235 | 237 | #endif |
|---|