diff options
Diffstat (limited to 'fs/btrfs/ctree.c')
-rw-r--r-- | fs/btrfs/ctree.c | 68 |
1 files changed, 12 insertions, 56 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index eea5da7a2b9a..ecd25a1b4e51 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -1138,6 +1138,7 @@ __tree_mod_log_rewind(struct extent_buffer *eb, u64 time_seq, | |||
1138 | switch (tm->op) { | 1138 | switch (tm->op) { |
1139 | case MOD_LOG_KEY_REMOVE_WHILE_FREEING: | 1139 | case MOD_LOG_KEY_REMOVE_WHILE_FREEING: |
1140 | BUG_ON(tm->slot < n); | 1140 | BUG_ON(tm->slot < n); |
1141 | /* Fallthrough */ | ||
1141 | case MOD_LOG_KEY_REMOVE_WHILE_MOVING: | 1142 | case MOD_LOG_KEY_REMOVE_WHILE_MOVING: |
1142 | case MOD_LOG_KEY_REMOVE: | 1143 | case MOD_LOG_KEY_REMOVE: |
1143 | btrfs_set_node_key(eb, &tm->key, tm->slot); | 1144 | btrfs_set_node_key(eb, &tm->key, tm->slot); |
@@ -1222,7 +1223,7 @@ tree_mod_log_rewind(struct btrfs_fs_info *fs_info, struct extent_buffer *eb, | |||
1222 | 1223 | ||
1223 | __tree_mod_log_rewind(eb_rewin, time_seq, tm); | 1224 | __tree_mod_log_rewind(eb_rewin, time_seq, tm); |
1224 | WARN_ON(btrfs_header_nritems(eb_rewin) > | 1225 | WARN_ON(btrfs_header_nritems(eb_rewin) > |
1225 | BTRFS_NODEPTRS_PER_BLOCK(fs_info->fs_root)); | 1226 | BTRFS_NODEPTRS_PER_BLOCK(fs_info->tree_root)); |
1226 | 1227 | ||
1227 | return eb_rewin; | 1228 | return eb_rewin; |
1228 | } | 1229 | } |
@@ -1441,7 +1442,7 @@ int btrfs_comp_cpu_keys(struct btrfs_key *k1, struct btrfs_key *k2) | |||
1441 | */ | 1442 | */ |
1442 | int btrfs_realloc_node(struct btrfs_trans_handle *trans, | 1443 | int btrfs_realloc_node(struct btrfs_trans_handle *trans, |
1443 | struct btrfs_root *root, struct extent_buffer *parent, | 1444 | struct btrfs_root *root, struct extent_buffer *parent, |
1444 | int start_slot, int cache_only, u64 *last_ret, | 1445 | int start_slot, u64 *last_ret, |
1445 | struct btrfs_key *progress) | 1446 | struct btrfs_key *progress) |
1446 | { | 1447 | { |
1447 | struct extent_buffer *cur; | 1448 | struct extent_buffer *cur; |
@@ -1461,8 +1462,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, | |||
1461 | struct btrfs_disk_key disk_key; | 1462 | struct btrfs_disk_key disk_key; |
1462 | 1463 | ||
1463 | parent_level = btrfs_header_level(parent); | 1464 | parent_level = btrfs_header_level(parent); |
1464 | if (cache_only && parent_level != 1) | ||
1465 | return 0; | ||
1466 | 1465 | ||
1467 | WARN_ON(trans->transaction != root->fs_info->running_transaction); | 1466 | WARN_ON(trans->transaction != root->fs_info->running_transaction); |
1468 | WARN_ON(trans->transid != root->fs_info->generation); | 1467 | WARN_ON(trans->transid != root->fs_info->generation); |
@@ -1508,10 +1507,6 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, | |||
1508 | else | 1507 | else |
1509 | uptodate = 0; | 1508 | uptodate = 0; |
1510 | if (!cur || !uptodate) { | 1509 | if (!cur || !uptodate) { |
1511 | if (cache_only) { | ||
1512 | free_extent_buffer(cur); | ||
1513 | continue; | ||
1514 | } | ||
1515 | if (!cur) { | 1510 | if (!cur) { |
1516 | cur = read_tree_block(root, blocknr, | 1511 | cur = read_tree_block(root, blocknr, |
1517 | blocksize, gen); | 1512 | blocksize, gen); |
@@ -4825,8 +4820,8 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path) | |||
4825 | 4820 | ||
4826 | /* | 4821 | /* |
4827 | * A helper function to walk down the tree starting at min_key, and looking | 4822 | * A helper function to walk down the tree starting at min_key, and looking |
4828 | * for nodes or leaves that are either in cache or have a minimum | 4823 | * for nodes or leaves that are have a minimum transaction id. |
4829 | * transaction id. This is used by the btree defrag code, and tree logging | 4824 | * This is used by the btree defrag code, and tree logging |
4830 | * | 4825 | * |
4831 | * This does not cow, but it does stuff the starting key it finds back | 4826 | * This does not cow, but it does stuff the starting key it finds back |
4832 | * into min_key, so you can call btrfs_search_slot with cow=1 on the | 4827 | * into min_key, so you can call btrfs_search_slot with cow=1 on the |
@@ -4847,7 +4842,7 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path) | |||
4847 | */ | 4842 | */ |
4848 | int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, | 4843 | int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key, |
4849 | struct btrfs_key *max_key, | 4844 | struct btrfs_key *max_key, |
4850 | struct btrfs_path *path, int cache_only, | 4845 | struct btrfs_path *path, |
4851 | u64 min_trans) | 4846 | u64 min_trans) |
4852 | { | 4847 | { |
4853 | struct extent_buffer *cur; | 4848 | struct extent_buffer *cur; |
@@ -4887,15 +4882,12 @@ again: | |||
4887 | if (sret && slot > 0) | 4882 | if (sret && slot > 0) |
4888 | slot--; | 4883 | slot--; |
4889 | /* | 4884 | /* |
4890 | * check this node pointer against the cache_only and | 4885 | * check this node pointer against the min_trans parameters. |
4891 | * min_trans parameters. If it isn't in cache or is too | 4886 | * If it is too old, old, skip to the next one. |
4892 | * old, skip to the next one. | ||
4893 | */ | 4887 | */ |
4894 | while (slot < nritems) { | 4888 | while (slot < nritems) { |
4895 | u64 blockptr; | 4889 | u64 blockptr; |
4896 | u64 gen; | 4890 | u64 gen; |
4897 | struct extent_buffer *tmp; | ||
4898 | struct btrfs_disk_key disk_key; | ||
4899 | 4891 | ||
4900 | blockptr = btrfs_node_blockptr(cur, slot); | 4892 | blockptr = btrfs_node_blockptr(cur, slot); |
4901 | gen = btrfs_node_ptr_generation(cur, slot); | 4893 | gen = btrfs_node_ptr_generation(cur, slot); |
@@ -4903,27 +4895,7 @@ again: | |||
4903 | slot++; | 4895 | slot++; |
4904 | continue; | 4896 | continue; |
4905 | } | 4897 | } |
4906 | if (!cache_only) | 4898 | break; |
4907 | break; | ||
4908 | |||
4909 | if (max_key) { | ||
4910 | btrfs_node_key(cur, &disk_key, slot); | ||
4911 | if (comp_keys(&disk_key, max_key) >= 0) { | ||
4912 | ret = 1; | ||
4913 | goto out; | ||
4914 | } | ||
4915 | } | ||
4916 | |||
4917 | tmp = btrfs_find_tree_block(root, blockptr, | ||
4918 | btrfs_level_size(root, level - 1)); | ||
4919 | |||
4920 | if (tmp && btrfs_buffer_uptodate(tmp, gen, 1) > 0) { | ||
4921 | free_extent_buffer(tmp); | ||
4922 | break; | ||
4923 | } | ||
4924 | if (tmp) | ||
4925 | free_extent_buffer(tmp); | ||
4926 | slot++; | ||
4927 | } | 4899 | } |
4928 | find_next_key: | 4900 | find_next_key: |
4929 | /* | 4901 | /* |
@@ -4934,7 +4906,7 @@ find_next_key: | |||
4934 | path->slots[level] = slot; | 4906 | path->slots[level] = slot; |
4935 | btrfs_set_path_blocking(path); | 4907 | btrfs_set_path_blocking(path); |
4936 | sret = btrfs_find_next_key(root, path, min_key, level, | 4908 | sret = btrfs_find_next_key(root, path, min_key, level, |
4937 | cache_only, min_trans); | 4909 | min_trans); |
4938 | if (sret == 0) { | 4910 | if (sret == 0) { |
4939 | btrfs_release_path(path); | 4911 | btrfs_release_path(path); |
4940 | goto again; | 4912 | goto again; |
@@ -5399,8 +5371,7 @@ out: | |||
5399 | /* | 5371 | /* |
5400 | * this is similar to btrfs_next_leaf, but does not try to preserve | 5372 | * this is similar to btrfs_next_leaf, but does not try to preserve |
5401 | * and fixup the path. It looks for and returns the next key in the | 5373 | * and fixup the path. It looks for and returns the next key in the |
5402 | * tree based on the current path and the cache_only and min_trans | 5374 | * tree based on the current path and the min_trans parameters. |
5403 | * parameters. | ||
5404 | * | 5375 | * |
5405 | * 0 is returned if another key is found, < 0 if there are any errors | 5376 | * 0 is returned if another key is found, < 0 if there are any errors |
5406 | * and 1 is returned if there are no higher keys in the tree | 5377 | * and 1 is returned if there are no higher keys in the tree |
@@ -5409,8 +5380,7 @@ out: | |||
5409 | * calling this function. | 5380 | * calling this function. |
5410 | */ | 5381 | */ |
5411 | int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, | 5382 | int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, |
5412 | struct btrfs_key *key, int level, | 5383 | struct btrfs_key *key, int level, u64 min_trans) |
5413 | int cache_only, u64 min_trans) | ||
5414 | { | 5384 | { |
5415 | int slot; | 5385 | int slot; |
5416 | struct extent_buffer *c; | 5386 | struct extent_buffer *c; |
@@ -5461,22 +5431,8 @@ next: | |||
5461 | if (level == 0) | 5431 | if (level == 0) |
5462 | btrfs_item_key_to_cpu(c, key, slot); | 5432 | btrfs_item_key_to_cpu(c, key, slot); |
5463 | else { | 5433 | else { |
5464 | u64 blockptr = btrfs_node_blockptr(c, slot); | ||
5465 | u64 gen = btrfs_node_ptr_generation(c, slot); | 5434 | u64 gen = btrfs_node_ptr_generation(c, slot); |
5466 | 5435 | ||
5467 | if (cache_only) { | ||
5468 | struct extent_buffer *cur; | ||
5469 | cur = btrfs_find_tree_block(root, blockptr, | ||
5470 | btrfs_level_size(root, level - 1)); | ||
5471 | if (!cur || | ||
5472 | btrfs_buffer_uptodate(cur, gen, 1) <= 0) { | ||
5473 | slot++; | ||
5474 | if (cur) | ||
5475 | free_extent_buffer(cur); | ||
5476 | goto next; | ||
5477 | } | ||
5478 | free_extent_buffer(cur); | ||
5479 | } | ||
5480 | if (gen < min_trans) { | 5436 | if (gen < min_trans) { |
5481 | slot++; | 5437 | slot++; |
5482 | goto next; | 5438 | goto next; |