diff options
Diffstat (limited to 'fs/btrfs/delayed-inode.c')
-rw-r--r-- | fs/btrfs/delayed-inode.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index 01e29503a54b..f1cbd028f7b3 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c | |||
@@ -297,7 +297,6 @@ struct btrfs_delayed_item *btrfs_alloc_delayed_item(u32 data_len) | |||
297 | item->data_len = data_len; | 297 | item->data_len = data_len; |
298 | item->ins_or_del = 0; | 298 | item->ins_or_del = 0; |
299 | item->bytes_reserved = 0; | 299 | item->bytes_reserved = 0; |
300 | item->block_rsv = NULL; | ||
301 | item->delayed_node = NULL; | 300 | item->delayed_node = NULL; |
302 | atomic_set(&item->refs, 1); | 301 | atomic_set(&item->refs, 1); |
303 | } | 302 | } |
@@ -593,10 +592,8 @@ static int btrfs_delayed_item_reserve_metadata(struct btrfs_trans_handle *trans, | |||
593 | 592 | ||
594 | num_bytes = btrfs_calc_trans_metadata_size(root, 1); | 593 | num_bytes = btrfs_calc_trans_metadata_size(root, 1); |
595 | ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes); | 594 | ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes); |
596 | if (!ret) { | 595 | if (!ret) |
597 | item->bytes_reserved = num_bytes; | 596 | item->bytes_reserved = num_bytes; |
598 | item->block_rsv = dst_rsv; | ||
599 | } | ||
600 | 597 | ||
601 | return ret; | 598 | return ret; |
602 | } | 599 | } |
@@ -604,10 +601,13 @@ static int btrfs_delayed_item_reserve_metadata(struct btrfs_trans_handle *trans, | |||
604 | static void btrfs_delayed_item_release_metadata(struct btrfs_root *root, | 601 | static void btrfs_delayed_item_release_metadata(struct btrfs_root *root, |
605 | struct btrfs_delayed_item *item) | 602 | struct btrfs_delayed_item *item) |
606 | { | 603 | { |
604 | struct btrfs_block_rsv *rsv; | ||
605 | |||
607 | if (!item->bytes_reserved) | 606 | if (!item->bytes_reserved) |
608 | return; | 607 | return; |
609 | 608 | ||
610 | btrfs_block_rsv_release(root, item->block_rsv, | 609 | rsv = &root->fs_info->global_block_rsv; |
610 | btrfs_block_rsv_release(root, rsv, | ||
611 | item->bytes_reserved); | 611 | item->bytes_reserved); |
612 | } | 612 | } |
613 | 613 | ||
@@ -678,6 +678,7 @@ static int btrfs_batch_insert_items(struct btrfs_trans_handle *trans, | |||
678 | INIT_LIST_HEAD(&head); | 678 | INIT_LIST_HEAD(&head); |
679 | 679 | ||
680 | next = item; | 680 | next = item; |
681 | nitems = 0; | ||
681 | 682 | ||
682 | /* | 683 | /* |
683 | * count the number of the continuous items that we can insert in batch | 684 | * count the number of the continuous items that we can insert in batch |
@@ -1013,6 +1014,7 @@ int btrfs_run_delayed_items(struct btrfs_trans_handle *trans, | |||
1013 | struct btrfs_delayed_root *delayed_root; | 1014 | struct btrfs_delayed_root *delayed_root; |
1014 | struct btrfs_delayed_node *curr_node, *prev_node; | 1015 | struct btrfs_delayed_node *curr_node, *prev_node; |
1015 | struct btrfs_path *path; | 1016 | struct btrfs_path *path; |
1017 | struct btrfs_block_rsv *block_rsv; | ||
1016 | int ret = 0; | 1018 | int ret = 0; |
1017 | 1019 | ||
1018 | path = btrfs_alloc_path(); | 1020 | path = btrfs_alloc_path(); |
@@ -1020,6 +1022,9 @@ int btrfs_run_delayed_items(struct btrfs_trans_handle *trans, | |||
1020 | return -ENOMEM; | 1022 | return -ENOMEM; |
1021 | path->leave_spinning = 1; | 1023 | path->leave_spinning = 1; |
1022 | 1024 | ||
1025 | block_rsv = trans->block_rsv; | ||
1026 | trans->block_rsv = &root->fs_info->global_block_rsv; | ||
1027 | |||
1023 | delayed_root = btrfs_get_delayed_root(root); | 1028 | delayed_root = btrfs_get_delayed_root(root); |
1024 | 1029 | ||
1025 | curr_node = btrfs_first_delayed_node(delayed_root); | 1030 | curr_node = btrfs_first_delayed_node(delayed_root); |
@@ -1044,6 +1049,7 @@ int btrfs_run_delayed_items(struct btrfs_trans_handle *trans, | |||
1044 | } | 1049 | } |
1045 | 1050 | ||
1046 | btrfs_free_path(path); | 1051 | btrfs_free_path(path); |
1052 | trans->block_rsv = block_rsv; | ||
1047 | return ret; | 1053 | return ret; |
1048 | } | 1054 | } |
1049 | 1055 | ||
@@ -1051,6 +1057,7 @@ static int __btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans, | |||
1051 | struct btrfs_delayed_node *node) | 1057 | struct btrfs_delayed_node *node) |
1052 | { | 1058 | { |
1053 | struct btrfs_path *path; | 1059 | struct btrfs_path *path; |
1060 | struct btrfs_block_rsv *block_rsv; | ||
1054 | int ret; | 1061 | int ret; |
1055 | 1062 | ||
1056 | path = btrfs_alloc_path(); | 1063 | path = btrfs_alloc_path(); |
@@ -1058,6 +1065,9 @@ static int __btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans, | |||
1058 | return -ENOMEM; | 1065 | return -ENOMEM; |
1059 | path->leave_spinning = 1; | 1066 | path->leave_spinning = 1; |
1060 | 1067 | ||
1068 | block_rsv = trans->block_rsv; | ||
1069 | trans->block_rsv = &node->root->fs_info->global_block_rsv; | ||
1070 | |||
1061 | ret = btrfs_insert_delayed_items(trans, path, node->root, node); | 1071 | ret = btrfs_insert_delayed_items(trans, path, node->root, node); |
1062 | if (!ret) | 1072 | if (!ret) |
1063 | ret = btrfs_delete_delayed_items(trans, path, node->root, node); | 1073 | ret = btrfs_delete_delayed_items(trans, path, node->root, node); |
@@ -1065,6 +1075,7 @@ static int __btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans, | |||
1065 | ret = btrfs_update_delayed_inode(trans, node->root, path, node); | 1075 | ret = btrfs_update_delayed_inode(trans, node->root, path, node); |
1066 | btrfs_free_path(path); | 1076 | btrfs_free_path(path); |
1067 | 1077 | ||
1078 | trans->block_rsv = block_rsv; | ||
1068 | return ret; | 1079 | return ret; |
1069 | } | 1080 | } |
1070 | 1081 | ||
@@ -1115,6 +1126,7 @@ static void btrfs_async_run_delayed_node_done(struct btrfs_work *work) | |||
1115 | struct btrfs_path *path; | 1126 | struct btrfs_path *path; |
1116 | struct btrfs_delayed_node *delayed_node = NULL; | 1127 | struct btrfs_delayed_node *delayed_node = NULL; |
1117 | struct btrfs_root *root; | 1128 | struct btrfs_root *root; |
1129 | struct btrfs_block_rsv *block_rsv; | ||
1118 | unsigned long nr = 0; | 1130 | unsigned long nr = 0; |
1119 | int need_requeue = 0; | 1131 | int need_requeue = 0; |
1120 | int ret; | 1132 | int ret; |
@@ -1129,10 +1141,13 @@ static void btrfs_async_run_delayed_node_done(struct btrfs_work *work) | |||
1129 | delayed_node = async_node->delayed_node; | 1141 | delayed_node = async_node->delayed_node; |
1130 | root = delayed_node->root; | 1142 | root = delayed_node->root; |
1131 | 1143 | ||
1132 | trans = btrfs_join_transaction(root, 0); | 1144 | trans = btrfs_join_transaction(root); |
1133 | if (IS_ERR(trans)) | 1145 | if (IS_ERR(trans)) |
1134 | goto free_path; | 1146 | goto free_path; |
1135 | 1147 | ||
1148 | block_rsv = trans->block_rsv; | ||
1149 | trans->block_rsv = &root->fs_info->global_block_rsv; | ||
1150 | |||
1136 | ret = btrfs_insert_delayed_items(trans, path, root, delayed_node); | 1151 | ret = btrfs_insert_delayed_items(trans, path, root, delayed_node); |
1137 | if (!ret) | 1152 | if (!ret) |
1138 | ret = btrfs_delete_delayed_items(trans, path, root, | 1153 | ret = btrfs_delete_delayed_items(trans, path, root, |
@@ -1175,6 +1190,7 @@ static void btrfs_async_run_delayed_node_done(struct btrfs_work *work) | |||
1175 | 1190 | ||
1176 | nr = trans->blocks_used; | 1191 | nr = trans->blocks_used; |
1177 | 1192 | ||
1193 | trans->block_rsv = block_rsv; | ||
1178 | btrfs_end_transaction_dmeta(trans, root); | 1194 | btrfs_end_transaction_dmeta(trans, root); |
1179 | __btrfs_btree_balance_dirty(root, nr); | 1195 | __btrfs_btree_balance_dirty(root, nr); |
1180 | free_path: | 1196 | free_path: |
@@ -1221,6 +1237,13 @@ again: | |||
1221 | return 0; | 1237 | return 0; |
1222 | } | 1238 | } |
1223 | 1239 | ||
1240 | void btrfs_assert_delayed_root_empty(struct btrfs_root *root) | ||
1241 | { | ||
1242 | struct btrfs_delayed_root *delayed_root; | ||
1243 | delayed_root = btrfs_get_delayed_root(root); | ||
1244 | WARN_ON(btrfs_first_delayed_node(delayed_root)); | ||
1245 | } | ||
1246 | |||
1224 | void btrfs_balance_delayed_items(struct btrfs_root *root) | 1247 | void btrfs_balance_delayed_items(struct btrfs_root *root) |
1225 | { | 1248 | { |
1226 | struct btrfs_delayed_root *delayed_root; | 1249 | struct btrfs_delayed_root *delayed_root; |
@@ -1572,8 +1595,7 @@ static void fill_stack_inode_item(struct btrfs_trans_handle *trans, | |||
1572 | btrfs_set_stack_inode_transid(inode_item, trans->transid); | 1595 | btrfs_set_stack_inode_transid(inode_item, trans->transid); |
1573 | btrfs_set_stack_inode_rdev(inode_item, inode->i_rdev); | 1596 | btrfs_set_stack_inode_rdev(inode_item, inode->i_rdev); |
1574 | btrfs_set_stack_inode_flags(inode_item, BTRFS_I(inode)->flags); | 1597 | btrfs_set_stack_inode_flags(inode_item, BTRFS_I(inode)->flags); |
1575 | btrfs_set_stack_inode_block_group(inode_item, | 1598 | btrfs_set_stack_inode_block_group(inode_item, 0); |
1576 | BTRFS_I(inode)->block_group); | ||
1577 | 1599 | ||
1578 | btrfs_set_stack_timespec_sec(btrfs_inode_atime(inode_item), | 1600 | btrfs_set_stack_timespec_sec(btrfs_inode_atime(inode_item), |
1579 | inode->i_atime.tv_sec); | 1601 | inode->i_atime.tv_sec); |
@@ -1595,7 +1617,7 @@ int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans, | |||
1595 | struct btrfs_root *root, struct inode *inode) | 1617 | struct btrfs_root *root, struct inode *inode) |
1596 | { | 1618 | { |
1597 | struct btrfs_delayed_node *delayed_node; | 1619 | struct btrfs_delayed_node *delayed_node; |
1598 | int ret; | 1620 | int ret = 0; |
1599 | 1621 | ||
1600 | delayed_node = btrfs_get_or_create_delayed_node(inode); | 1622 | delayed_node = btrfs_get_or_create_delayed_node(inode); |
1601 | if (IS_ERR(delayed_node)) | 1623 | if (IS_ERR(delayed_node)) |