@@ -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