diff options
author | Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> | 2011-07-13 23:19:45 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2011-08-01 14:32:39 -0400 |
commit | 69261c4b6a394ead1b5ca2966c908469355eb603 (patch) | |
tree | 3bd8ae6f65473887bc3aab381eea38bfb6b6e8ca /fs/btrfs | |
parent | ded91f0814a349e36b3ca0eff497f816ad518fba (diff) |
Btrfs: clean up for find_first_extent_bit()
find_first_extent_bit() and find_first_extent_bit_state() share
most of the code, and we can just make the former call the latter.
Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/extent_io.c | 64 |
1 files changed, 24 insertions, 40 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index a0811e639f5..a59ebc608cc 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
@@ -1031,46 +1031,6 @@ static int set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end) | |||
1031 | return 0; | 1031 | return 0; |
1032 | } | 1032 | } |
1033 | 1033 | ||
1034 | /* | ||
1035 | * find the first offset in the io tree with 'bits' set. zero is | ||
1036 | * returned if we find something, and *start_ret and *end_ret are | ||
1037 | * set to reflect the state struct that was found. | ||
1038 | * | ||
1039 | * If nothing was found, 1 is returned, < 0 on error | ||
1040 | */ | ||
1041 | int find_first_extent_bit(struct extent_io_tree *tree, u64 start, | ||
1042 | u64 *start_ret, u64 *end_ret, int bits) | ||
1043 | { | ||
1044 | struct rb_node *node; | ||
1045 | struct extent_state *state; | ||
1046 | int ret = 1; | ||
1047 | |||
1048 | spin_lock(&tree->lock); | ||
1049 | /* | ||
1050 | * this search will find all the extents that end after | ||
1051 | * our range starts. | ||
1052 | */ | ||
1053 | node = tree_search(tree, start); | ||
1054 | if (!node) | ||
1055 | goto out; | ||
1056 | |||
1057 | while (1) { | ||
1058 | state = rb_entry(node, struct extent_state, rb_node); | ||
1059 | if (state->end >= start && (state->state & bits)) { | ||
1060 | *start_ret = state->start; | ||
1061 | *end_ret = state->end; | ||
1062 | ret = 0; | ||
1063 | break; | ||
1064 | } | ||
1065 | node = rb_next(node); | ||
1066 | if (!node) | ||
1067 | break; | ||
1068 | } | ||
1069 | out: | ||
1070 | spin_unlock(&tree->lock); | ||
1071 | return ret; | ||
1072 | } | ||
1073 | |||
1074 | /* find the first state struct with 'bits' set after 'start', and | 1034 | /* find the first state struct with 'bits' set after 'start', and |
1075 | * return it. tree->lock must be held. NULL will returned if | 1035 | * return it. tree->lock must be held. NULL will returned if |
1076 | * nothing was found after 'start' | 1036 | * nothing was found after 'start' |
@@ -1103,6 +1063,30 @@ out: | |||
1103 | } | 1063 | } |
1104 | 1064 | ||
1105 | /* | 1065 | /* |
1066 | * find the first offset in the io tree with 'bits' set. zero is | ||
1067 | * returned if we find something, and *start_ret and *end_ret are | ||
1068 | * set to reflect the state struct that was found. | ||
1069 | * | ||
1070 | * If nothing was found, 1 is returned, < 0 on error | ||
1071 | */ | ||
1072 | int find_first_extent_bit(struct extent_io_tree *tree, u64 start, | ||
1073 | u64 *start_ret, u64 *end_ret, int bits) | ||
1074 | { | ||
1075 | struct extent_state *state; | ||
1076 | int ret = 1; | ||
1077 | |||
1078 | spin_lock(&tree->lock); | ||
1079 | state = find_first_extent_bit_state(tree, start, bits); | ||
1080 | if (state) { | ||
1081 | *start_ret = state->start; | ||
1082 | *end_ret = state->end; | ||
1083 | ret = 0; | ||
1084 | } | ||
1085 | spin_unlock(&tree->lock); | ||
1086 | return ret; | ||
1087 | } | ||
1088 | |||
1089 | /* | ||
1106 | * find a contiguous range of bytes in the file marked as delalloc, not | 1090 | * find a contiguous range of bytes in the file marked as delalloc, not |
1107 | * more than 'max_bytes'. start and end are used to return the range, | 1091 | * more than 'max_bytes'. start and end are used to return the range, |
1108 | * | 1092 | * |