Skip to content

Commit cfc0eed

Browse files
ethanwu-synokdave
authored andcommitted
btrfs: backref, only search backref entries from leaves of the same root
We could have some nodes/leaves in subvolume whose owner are not the that subvolume. In this way, when we resolve normal backrefs of that subvolume, we should avoid collecting those references from these blocks. Reviewed-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: ethanwu <ethanwu@synology.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent ed58f2e commit cfc0eed

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

fs/btrfs/backref.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,14 @@ static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
443443
* slot == nritems.
444444
* 2. We are searching for normal backref but bytenr of this leaf
445445
* matches shared data backref
446+
* 3. The leaf owner is not equal to the root we are searching
447+
*
446448
* For these cases, go to the next leaf before we continue.
447449
*/
448450
eb = path->nodes[0];
449451
if (path->slots[0] >= btrfs_header_nritems(eb) ||
450-
is_shared_data_backref(preftrees, eb->start)) {
452+
is_shared_data_backref(preftrees, eb->start) ||
453+
ref->root_id != btrfs_header_owner(eb)) {
451454
if (time_seq == SEQ_LAST)
452455
ret = btrfs_next_leaf(root, path);
453456
else
@@ -466,9 +469,12 @@ static int add_all_parents(struct btrfs_root *root, struct btrfs_path *path,
466469

467470
/*
468471
* We are searching for normal backref but bytenr of this leaf
469-
* matches shared data backref.
472+
* matches shared data backref, OR
473+
* the leaf owner is not equal to the root we are searching for
470474
*/
471-
if (slot == 0 && is_shared_data_backref(preftrees, eb->start)) {
475+
if (slot == 0 &&
476+
(is_shared_data_backref(preftrees, eb->start) ||
477+
ref->root_id != btrfs_header_owner(eb))) {
472478
if (time_seq == SEQ_LAST)
473479
ret = btrfs_next_leaf(root, path);
474480
else

0 commit comments

Comments
 (0)