extent_map.c (190662b2128dd648749e197f5563e9f6bbb5e05c) extent_map.c (1832a6d5ee3b1af61001cadba9e10da9e91af4a4)
1#include <linux/bitops.h>
2#include <linux/slab.h>
3#include <linux/bio.h>
4#include <linux/mm.h>
5#include <linux/gfp.h>
6#include <linux/pagemap.h>
7#include <linux/page-flags.h>
8#include <linux/module.h>

--- 1117 unchanged lines hidden (view full) ---

1126 break;
1127 }
1128out:
1129 write_unlock_irq(&tree->lock);
1130 return found;
1131}
1132
1133u64 count_range_bits(struct extent_map_tree *tree,
1#include <linux/bitops.h>
2#include <linux/slab.h>
3#include <linux/bio.h>
4#include <linux/mm.h>
5#include <linux/gfp.h>
6#include <linux/pagemap.h>
7#include <linux/page-flags.h>
8#include <linux/module.h>

--- 1117 unchanged lines hidden (view full) ---

1126 break;
1127 }
1128out:
1129 write_unlock_irq(&tree->lock);
1130 return found;
1131}
1132
1133u64 count_range_bits(struct extent_map_tree *tree,
1134 u64 *start, u64 max_bytes, unsigned long bits)
1134 u64 *start, u64 search_end, u64 max_bytes,
1135 unsigned long bits)
1135{
1136 struct rb_node *node;
1137 struct extent_state *state;
1138 u64 cur_start = *start;
1139 u64 total_bytes = 0;
1140 int found = 0;
1141
1136{
1137 struct rb_node *node;
1138 struct extent_state *state;
1139 u64 cur_start = *start;
1140 u64 total_bytes = 0;
1141 int found = 0;
1142
1143 if (search_end <= cur_start) {
1144 printk("search_end %Lu start %Lu\n", search_end, cur_start);
1145 WARN_ON(1);
1146 return 0;
1147 }
1148
1142 write_lock_irq(&tree->lock);
1149 write_lock_irq(&tree->lock);
1143 if (bits == EXTENT_DIRTY) {
1144 *start = 0;
1150 if (cur_start == 0 && bits == EXTENT_DIRTY) {
1145 total_bytes = tree->dirty_bytes;
1146 goto out;
1147 }
1148 /*
1149 * this search will find all the extents that end after
1150 * our range starts.
1151 */
1152 node = tree_search(&tree->state, cur_start);
1153 if (!node || IS_ERR(node)) {
1154 goto out;
1155 }
1156
1157 while(1) {
1158 state = rb_entry(node, struct extent_state, rb_node);
1151 total_bytes = tree->dirty_bytes;
1152 goto out;
1153 }
1154 /*
1155 * this search will find all the extents that end after
1156 * our range starts.
1157 */
1158 node = tree_search(&tree->state, cur_start);
1159 if (!node || IS_ERR(node)) {
1160 goto out;
1161 }
1162
1163 while(1) {
1164 state = rb_entry(node, struct extent_state, rb_node);
1159 if ((state->state & bits)) {
1160 total_bytes += state->end - state->start + 1;
1165 if (state->start > search_end)
1166 break;
1167 if (state->end >= cur_start && (state->state & bits)) {
1168 total_bytes += min(search_end, state->end) + 1 -
1169 max(cur_start, state->start);
1161 if (total_bytes >= max_bytes)
1162 break;
1163 if (!found) {
1164 *start = state->start;
1165 found = 1;
1166 }
1167 }
1168 node = rb_next(node);
1169 if (!node)
1170 break;
1171 }
1172out:
1173 write_unlock_irq(&tree->lock);
1174 return total_bytes;
1175}
1170 if (total_bytes >= max_bytes)
1171 break;
1172 if (!found) {
1173 *start = state->start;
1174 found = 1;
1175 }
1176 }
1177 node = rb_next(node);
1178 if (!node)
1179 break;
1180 }
1181out:
1182 write_unlock_irq(&tree->lock);
1183 return total_bytes;
1184}
1176
1177/*
1178 * helper function to lock both pages and extents in the tree.
1179 * pages must be locked first.
1180 */
1181int lock_range(struct extent_map_tree *tree, u64 start, u64 end)
1182{
1183 unsigned long index = start >> PAGE_CACHE_SHIFT;
1184 unsigned long end_index = end >> PAGE_CACHE_SHIFT;

--- 2002 unchanged lines hidden ---
1185/*
1186 * helper function to lock both pages and extents in the tree.
1187 * pages must be locked first.
1188 */
1189int lock_range(struct extent_map_tree *tree, u64 start, u64 end)
1190{
1191 unsigned long index = start >> PAGE_CACHE_SHIFT;
1192 unsigned long end_index = end >> PAGE_CACHE_SHIFT;

--- 2002 unchanged lines hidden ---