backref.c (580f0a678ebeba85d30b6a7f22ce32c472263c72) backref.c (7ef81ac86c8a44ab9f4e6e04e1f4c9ea53615b8a)
1/*
2 * Copyright (C) 2011 STRATO. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

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

204 ref->parent = parent;
205 ref->wanted_disk_byte = wanted_disk_byte;
206 list_add_tail(&ref->list, head);
207
208 return 0;
209}
210
211static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
1/*
2 * Copyright (C) 2011 STRATO. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

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

204 ref->parent = parent;
205 ref->wanted_disk_byte = wanted_disk_byte;
206 list_add_tail(&ref->list, head);
207
208 return 0;
209}
210
211static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
212 struct ulist *parents, int level,
213 struct btrfs_key *key_for_search, u64 time_seq,
214 u64 wanted_disk_byte,
215 const u64 *extent_item_pos)
212 struct ulist *parents, struct __prelim_ref *ref,
213 int level, u64 time_seq, const u64 *extent_item_pos)
216{
217 int ret = 0;
218 int slot;
219 struct extent_buffer *eb;
220 struct btrfs_key key;
214{
215 int ret = 0;
216 int slot;
217 struct extent_buffer *eb;
218 struct btrfs_key key;
219 struct btrfs_key *key_for_search = &ref->key_for_search;
221 struct btrfs_file_extent_item *fi;
222 struct extent_inode_elem *eie = NULL, *old = NULL;
223 u64 disk_byte;
220 struct btrfs_file_extent_item *fi;
221 struct extent_inode_elem *eie = NULL, *old = NULL;
222 u64 disk_byte;
223 u64 wanted_disk_byte = ref->wanted_disk_byte;
224 u64 count = 0;
224
225 if (level != 0) {
226 eb = path->nodes[level];
227 ret = ulist_add(parents, eb->start, 0, GFP_NOFS);
228 if (ret < 0)
229 return ret;
230 return 0;
231 }
232
233 /*
234 * We normally enter this function with the path already pointing to
235 * the first item to check. But sometimes, we may enter it with
236 * slot==nritems. In that case, go to the next leaf before we continue.
237 */
238 if (path->slots[0] >= btrfs_header_nritems(path->nodes[0]))
239 ret = btrfs_next_old_leaf(root, path, time_seq);
240
225
226 if (level != 0) {
227 eb = path->nodes[level];
228 ret = ulist_add(parents, eb->start, 0, GFP_NOFS);
229 if (ret < 0)
230 return ret;
231 return 0;
232 }
233
234 /*
235 * We normally enter this function with the path already pointing to
236 * the first item to check. But sometimes, we may enter it with
237 * slot==nritems. In that case, go to the next leaf before we continue.
238 */
239 if (path->slots[0] >= btrfs_header_nritems(path->nodes[0]))
240 ret = btrfs_next_old_leaf(root, path, time_seq);
241
241 while (!ret) {
242 while (!ret && count < ref->count) {
242 eb = path->nodes[0];
243 slot = path->slots[0];
244
245 btrfs_item_key_to_cpu(eb, &key, slot);
246
247 if (key.objectid != key_for_search->objectid ||
248 key.type != BTRFS_EXTENT_DATA_KEY)
249 break;
250
251 fi = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item);
252 disk_byte = btrfs_file_extent_disk_bytenr(eb, fi);
253
254 if (disk_byte == wanted_disk_byte) {
255 eie = NULL;
256 old = NULL;
243 eb = path->nodes[0];
244 slot = path->slots[0];
245
246 btrfs_item_key_to_cpu(eb, &key, slot);
247
248 if (key.objectid != key_for_search->objectid ||
249 key.type != BTRFS_EXTENT_DATA_KEY)
250 break;
251
252 fi = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item);
253 disk_byte = btrfs_file_extent_disk_bytenr(eb, fi);
254
255 if (disk_byte == wanted_disk_byte) {
256 eie = NULL;
257 old = NULL;
258 count++;
257 if (extent_item_pos) {
258 ret = check_extent_in_eb(&key, eb, fi,
259 *extent_item_pos,
260 &eie);
261 if (ret < 0)
262 break;
263 }
264 if (ret > 0)

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

329 if (WARN_ON(!level)) {
330 ret = 1;
331 goto out;
332 }
333 level--;
334 eb = path->nodes[level];
335 }
336
259 if (extent_item_pos) {
260 ret = check_extent_in_eb(&key, eb, fi,
261 *extent_item_pos,
262 &eie);
263 if (ret < 0)
264 break;
265 }
266 if (ret > 0)

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

331 if (WARN_ON(!level)) {
332 ret = 1;
333 goto out;
334 }
335 level--;
336 eb = path->nodes[level];
337 }
338
337 ret = add_all_parents(root, path, parents, level, &ref->key_for_search,
338 time_seq, ref->wanted_disk_byte,
339 extent_item_pos);
339 ret = add_all_parents(root, path, parents, ref, level, time_seq,
340 extent_item_pos);
340out:
341 path->lowest_level = 0;
342 btrfs_release_path(path);
343 return ret;
344}
345
346/*
347 * resolve all indirect backrefs from the list

--- 1496 unchanged lines hidden ---
341out:
342 path->lowest_level = 0;
343 btrfs_release_path(path);
344 return ret;
345}
346
347/*
348 * resolve all indirect backrefs from the list

--- 1496 unchanged lines hidden ---