aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs
diff options
context:
space:
mode:
authorWang Shilong <wangsl.fnst@cn.fujitsu.com>2014-01-12 08:38:33 -0500
committerChris Mason <clm@fb.com>2014-01-28 16:20:33 -0500
commitade2e0b3eeca941a5cd486bac21599ff87f288c8 (patch)
tree02f0384a1cb911766a1ebc07ce5ce963d94cbfd6 /fs/btrfs
parent7c76edb77c23db673a83793686b4a53e2eec4de4 (diff)
Btrfs: fix to search previous metadata extent item since skinny metadata
There is a bug that using btrfs_previous_item() to search metadata extent item. This is because in btrfs_previous_item(), we need type match, however, since skinny metada was introduced by josef, we may mix this two types. So just use btrfs_previous_item() is not working right. To keep btrfs_previous_item() like normal tree search, i introduce another function btrfs_previous_extent_item(). Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com> Signed-off-by: Josef Bacik <jbacik@fb.com> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r--fs/btrfs/ctree.c43
-rw-r--r--fs/btrfs/ctree.h2
-rw-r--r--fs/btrfs/scrub.c3
3 files changed, 46 insertions, 2 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 9e9de68eb813..30f5b11d7dd3 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -5955,3 +5955,46 @@ int btrfs_previous_item(struct btrfs_root *root,
5955 } 5955 }
5956 return 1; 5956 return 1;
5957} 5957}
5958
5959/*
5960 * search in extent tree to find a previous Metadata/Data extent item with
5961 * min objecitd.
5962 *
5963 * returns 0 if something is found, 1 if nothing was found and < 0 on error
5964 */
5965int btrfs_previous_extent_item(struct btrfs_root *root,
5966 struct btrfs_path *path, u64 min_objectid)
5967{
5968 struct btrfs_key found_key;
5969 struct extent_buffer *leaf;
5970 u32 nritems;
5971 int ret;
5972
5973 while (1) {
5974 if (path->slots[0] == 0) {
5975 btrfs_set_path_blocking(path);
5976 ret = btrfs_prev_leaf(root, path);
5977 if (ret != 0)
5978 return ret;
5979 } else {
5980 path->slots[0]--;
5981 }
5982 leaf = path->nodes[0];
5983 nritems = btrfs_header_nritems(leaf);
5984 if (nritems == 0)
5985 return 1;
5986 if (path->slots[0] == nritems)
5987 path->slots[0]--;
5988
5989 btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
5990 if (found_key.objectid < min_objectid)
5991 break;
5992 if (found_key.type == BTRFS_EXTENT_ITEM_KEY ||
5993 found_key.type == BTRFS_METADATA_ITEM_KEY)
5994 return 0;
5995 if (found_key.objectid == min_objectid &&
5996 found_key.type < BTRFS_EXTENT_ITEM_KEY)
5997 break;
5998 }
5999 return 1;
6000}
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index ca6bcc33d033..3708fd7ee83a 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3334,6 +3334,8 @@ int btrfs_comp_cpu_keys(struct btrfs_key *k1, struct btrfs_key *k2);
3334int btrfs_previous_item(struct btrfs_root *root, 3334int btrfs_previous_item(struct btrfs_root *root,
3335 struct btrfs_path *path, u64 min_objectid, 3335 struct btrfs_path *path, u64 min_objectid,
3336 int type); 3336 int type);
3337int btrfs_previous_extent_item(struct btrfs_root *root,
3338 struct btrfs_path *path, u64 min_objectid);
3337void btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path, 3339void btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path,
3338 struct btrfs_key *new_key); 3340 struct btrfs_key *new_key);
3339struct extent_buffer *btrfs_root_node(struct btrfs_root *root); 3341struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index e0677e42d66d..51c342b9f5ef 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -2385,8 +2385,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
2385 goto out; 2385 goto out;
2386 2386
2387 if (ret > 0) { 2387 if (ret > 0) {
2388 ret = btrfs_previous_item(root, path, 0, 2388 ret = btrfs_previous_extent_item(root, path, 0);
2389 BTRFS_EXTENT_ITEM_KEY);
2390 if (ret < 0) 2389 if (ret < 0)
2391 goto out; 2390 goto out;
2392 if (ret > 0) { 2391 if (ret > 0) {