Commit 3204d33c authored by Josef Bacik's avatar Josef Bacik Committed by Chris Mason

Btrfs: add a flags field to btrfs_transaction

I want to set some per transaction flags, so instead of adding yet another int
lets just convert the current two int indicators to flags and add a flags field
for future use.  Thanks,
Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent 0b670dc4
...@@ -4066,7 +4066,8 @@ int btrfs_check_data_free_space(struct inode *inode, u64 bytes, u64 write_bytes) ...@@ -4066,7 +4066,8 @@ int btrfs_check_data_free_space(struct inode *inode, u64 bytes, u64 write_bytes)
if (IS_ERR(trans)) if (IS_ERR(trans))
return PTR_ERR(trans); return PTR_ERR(trans);
if (have_pinned_space >= 0 || if (have_pinned_space >= 0 ||
trans->transaction->have_free_bgs || test_bit(BTRFS_TRANS_HAVE_FREE_BGS,
&trans->transaction->flags) ||
need_commit > 0) { need_commit > 0) {
ret = btrfs_commit_transaction(trans, root); ret = btrfs_commit_transaction(trans, root);
if (ret) if (ret)
...@@ -8938,7 +8939,7 @@ int btrfs_inc_block_group_ro(struct btrfs_root *root, ...@@ -8938,7 +8939,7 @@ int btrfs_inc_block_group_ro(struct btrfs_root *root,
* back off and let this transaction commit * back off and let this transaction commit
*/ */
mutex_lock(&root->fs_info->ro_block_group_mutex); mutex_lock(&root->fs_info->ro_block_group_mutex);
if (trans->transaction->dirty_bg_run) { if (test_bit(BTRFS_TRANS_DIRTY_BG_RUN, &trans->transaction->flags)) {
u64 transid = trans->transid; u64 transid = trans->transid;
mutex_unlock(&root->fs_info->ro_block_group_mutex); mutex_unlock(&root->fs_info->ro_block_group_mutex);
......
...@@ -239,10 +239,9 @@ static noinline int join_transaction(struct btrfs_root *root, unsigned int type) ...@@ -239,10 +239,9 @@ static noinline int join_transaction(struct btrfs_root *root, unsigned int type)
* commit the transaction. * commit the transaction.
*/ */
atomic_set(&cur_trans->use_count, 2); atomic_set(&cur_trans->use_count, 2);
cur_trans->have_free_bgs = 0;
atomic_set(&cur_trans->pending_ordered, 0); atomic_set(&cur_trans->pending_ordered, 0);
cur_trans->flags = 0;
cur_trans->start_time = get_seconds(); cur_trans->start_time = get_seconds();
cur_trans->dirty_bg_run = 0;
memset(&cur_trans->delayed_refs, 0, sizeof(cur_trans->delayed_refs)); memset(&cur_trans->delayed_refs, 0, sizeof(cur_trans->delayed_refs));
...@@ -1837,7 +1836,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, ...@@ -1837,7 +1836,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
if (!cur_trans->dirty_bg_run) { if (!test_bit(BTRFS_TRANS_DIRTY_BG_RUN, &cur_trans->flags)) {
int run_it = 0; int run_it = 0;
/* this mutex is also taken before trying to set /* this mutex is also taken before trying to set
...@@ -1846,18 +1845,17 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, ...@@ -1846,18 +1845,17 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
* after a extents from that block group have been * after a extents from that block group have been
* allocated for cache files. btrfs_set_block_group_ro * allocated for cache files. btrfs_set_block_group_ro
* will wait for the transaction to commit if it * will wait for the transaction to commit if it
* finds dirty_bg_run = 1 * finds BTRFS_TRANS_DIRTY_BG_RUN set.
* *
* The dirty_bg_run flag is also used to make sure only * The BTRFS_TRANS_DIRTY_BG_RUN flag is also used to make sure
* one process starts all the block group IO. It wouldn't * only one process starts all the block group IO. It wouldn't
* hurt to have more than one go through, but there's no * hurt to have more than one go through, but there's no
* real advantage to it either. * real advantage to it either.
*/ */
mutex_lock(&root->fs_info->ro_block_group_mutex); mutex_lock(&root->fs_info->ro_block_group_mutex);
if (!cur_trans->dirty_bg_run) { if (!test_and_set_bit(BTRFS_TRANS_DIRTY_BG_RUN,
&cur_trans->flags))
run_it = 1; run_it = 1;
cur_trans->dirty_bg_run = 1;
}
mutex_unlock(&root->fs_info->ro_block_group_mutex); mutex_unlock(&root->fs_info->ro_block_group_mutex);
if (run_it) if (run_it)
...@@ -2127,7 +2125,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, ...@@ -2127,7 +2125,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
btrfs_finish_extent_commit(trans, root); btrfs_finish_extent_commit(trans, root);
if (cur_trans->have_free_bgs) if (test_bit(BTRFS_TRANS_HAVE_FREE_BGS, &cur_trans->flags))
btrfs_clear_space_info_full(root->fs_info); btrfs_clear_space_info_full(root->fs_info);
root->fs_info->last_trans_committed = cur_trans->transid; root->fs_info->last_trans_committed = cur_trans->transid;
......
...@@ -32,6 +32,9 @@ enum btrfs_trans_state { ...@@ -32,6 +32,9 @@ enum btrfs_trans_state {
TRANS_STATE_MAX = 6, TRANS_STATE_MAX = 6,
}; };
#define BTRFS_TRANS_HAVE_FREE_BGS 0
#define BTRFS_TRANS_DIRTY_BG_RUN 1
struct btrfs_transaction { struct btrfs_transaction {
u64 transid; u64 transid;
/* /*
...@@ -48,10 +51,7 @@ struct btrfs_transaction { ...@@ -48,10 +51,7 @@ struct btrfs_transaction {
atomic_t use_count; atomic_t use_count;
atomic_t pending_ordered; atomic_t pending_ordered;
/* unsigned long flags;
* true if there is free bgs operations in this transaction
*/
int have_free_bgs;
/* Be protected by fs_info->trans_lock when we want to change it. */ /* Be protected by fs_info->trans_lock when we want to change it. */
enum btrfs_trans_state state; enum btrfs_trans_state state;
...@@ -81,7 +81,6 @@ struct btrfs_transaction { ...@@ -81,7 +81,6 @@ struct btrfs_transaction {
spinlock_t dropped_roots_lock; spinlock_t dropped_roots_lock;
struct btrfs_delayed_ref_root delayed_refs; struct btrfs_delayed_ref_root delayed_refs;
int aborted; int aborted;
int dirty_bg_run;
}; };
#define __TRANS_FREEZABLE (1U << 0) #define __TRANS_FREEZABLE (1U << 0)
......
...@@ -1462,7 +1462,7 @@ static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans, ...@@ -1462,7 +1462,7 @@ static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans,
btrfs_std_error(root->fs_info, ret, btrfs_std_error(root->fs_info, ret,
"Failed to remove dev extent item"); "Failed to remove dev extent item");
} else { } else {
trans->transaction->have_free_bgs = 1; set_bit(BTRFS_TRANS_HAVE_FREE_BGS, &trans->transaction->flags);
} }
out: out:
btrfs_free_path(path); btrfs_free_path(path);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment