backref.c (88ffb665c894b1929b30b09e05506ff359d9fb89) | backref.c (f73853c7168aef0e071c160979af05a148691e61) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2011 STRATO. All rights reserved. 4 */ 5 6#include <linux/mm.h> 7#include <linux/rbtree.h> 8#include <trace/events/btrfs.h> --- 989 unchanged lines hidden (view full) --- 998 return ret; 999} 1000 1001/* 1002 * add all inline backrefs for bytenr to the list 1003 * 1004 * Returns 0 on success, <0 on error, or BACKREF_FOUND_SHARED. 1005 */ | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2011 STRATO. All rights reserved. 4 */ 5 6#include <linux/mm.h> 7#include <linux/rbtree.h> 8#include <trace/events/btrfs.h> --- 989 unchanged lines hidden (view full) --- 998 return ret; 999} 1000 1001/* 1002 * add all inline backrefs for bytenr to the list 1003 * 1004 * Returns 0 on success, <0 on error, or BACKREF_FOUND_SHARED. 1005 */ |
1006static int add_inline_refs(const struct btrfs_fs_info *fs_info, 1007 struct btrfs_path *path, u64 bytenr, | 1006static int add_inline_refs(struct btrfs_backref_walk_ctx *ctx, 1007 struct btrfs_path *path, |
1008 int *info_level, struct preftrees *preftrees, 1009 struct share_check *sc) 1010{ 1011 int ret = 0; 1012 int slot; 1013 struct extent_buffer *leaf; 1014 struct btrfs_key key; 1015 struct btrfs_key found_key; --- 8 unchanged lines hidden (view full) --- 1024 */ 1025 leaf = path->nodes[0]; 1026 slot = path->slots[0]; 1027 1028 item_size = btrfs_item_size(leaf, slot); 1029 BUG_ON(item_size < sizeof(*ei)); 1030 1031 ei = btrfs_item_ptr(leaf, slot, struct btrfs_extent_item); | 1008 int *info_level, struct preftrees *preftrees, 1009 struct share_check *sc) 1010{ 1011 int ret = 0; 1012 int slot; 1013 struct extent_buffer *leaf; 1014 struct btrfs_key key; 1015 struct btrfs_key found_key; --- 8 unchanged lines hidden (view full) --- 1024 */ 1025 leaf = path->nodes[0]; 1026 slot = path->slots[0]; 1027 1028 item_size = btrfs_item_size(leaf, slot); 1029 BUG_ON(item_size < sizeof(*ei)); 1030 1031 ei = btrfs_item_ptr(leaf, slot, struct btrfs_extent_item); |
1032 1033 if (ctx->check_extent_item) { 1034 ret = ctx->check_extent_item(ctx->bytenr, ei, leaf, ctx->user_ctx); 1035 if (ret) 1036 return ret; 1037 } 1038 |
|
1032 flags = btrfs_extent_flags(leaf, ei); 1033 btrfs_item_key_to_cpu(leaf, &found_key, slot); 1034 1035 ptr = (unsigned long)(ei + 1); 1036 end = (unsigned long)ei + item_size; 1037 1038 if (found_key.type == BTRFS_EXTENT_ITEM_KEY && 1039 flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { --- 19 unchanged lines hidden (view full) --- 1059 BTRFS_REF_TYPE_ANY); 1060 if (type == BTRFS_REF_TYPE_INVALID) 1061 return -EUCLEAN; 1062 1063 offset = btrfs_extent_inline_ref_offset(leaf, iref); 1064 1065 switch (type) { 1066 case BTRFS_SHARED_BLOCK_REF_KEY: | 1039 flags = btrfs_extent_flags(leaf, ei); 1040 btrfs_item_key_to_cpu(leaf, &found_key, slot); 1041 1042 ptr = (unsigned long)(ei + 1); 1043 end = (unsigned long)ei + item_size; 1044 1045 if (found_key.type == BTRFS_EXTENT_ITEM_KEY && 1046 flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { --- 19 unchanged lines hidden (view full) --- 1066 BTRFS_REF_TYPE_ANY); 1067 if (type == BTRFS_REF_TYPE_INVALID) 1068 return -EUCLEAN; 1069 1070 offset = btrfs_extent_inline_ref_offset(leaf, iref); 1071 1072 switch (type) { 1073 case BTRFS_SHARED_BLOCK_REF_KEY: |
1067 ret = add_direct_ref(fs_info, preftrees, | 1074 ret = add_direct_ref(ctx->fs_info, preftrees, |
1068 *info_level + 1, offset, | 1075 *info_level + 1, offset, |
1069 bytenr, 1, NULL, GFP_NOFS); | 1076 ctx->bytenr, 1, NULL, GFP_NOFS); |
1070 break; 1071 case BTRFS_SHARED_DATA_REF_KEY: { 1072 struct btrfs_shared_data_ref *sdref; 1073 int count; 1074 1075 sdref = (struct btrfs_shared_data_ref *)(iref + 1); 1076 count = btrfs_shared_data_ref_count(leaf, sdref); 1077 | 1077 break; 1078 case BTRFS_SHARED_DATA_REF_KEY: { 1079 struct btrfs_shared_data_ref *sdref; 1080 int count; 1081 1082 sdref = (struct btrfs_shared_data_ref *)(iref + 1); 1083 count = btrfs_shared_data_ref_count(leaf, sdref); 1084 |
1078 ret = add_direct_ref(fs_info, preftrees, 0, offset, 1079 bytenr, count, sc, GFP_NOFS); | 1085 ret = add_direct_ref(ctx->fs_info, preftrees, 0, offset, 1086 ctx->bytenr, count, sc, GFP_NOFS); |
1080 break; 1081 } 1082 case BTRFS_TREE_BLOCK_REF_KEY: | 1087 break; 1088 } 1089 case BTRFS_TREE_BLOCK_REF_KEY: |
1083 ret = add_indirect_ref(fs_info, preftrees, offset, | 1090 ret = add_indirect_ref(ctx->fs_info, preftrees, offset, |
1084 NULL, *info_level + 1, | 1091 NULL, *info_level + 1, |
1085 bytenr, 1, NULL, GFP_NOFS); | 1092 ctx->bytenr, 1, NULL, GFP_NOFS); |
1086 break; 1087 case BTRFS_EXTENT_DATA_REF_KEY: { 1088 struct btrfs_extent_data_ref *dref; 1089 int count; 1090 u64 root; 1091 1092 dref = (struct btrfs_extent_data_ref *)(&iref->offset); 1093 count = btrfs_extent_data_ref_count(leaf, dref); --- 5 unchanged lines hidden (view full) --- 1099 if (sc && key.objectid != sc->inum && 1100 !sc->have_delayed_delete_refs) { 1101 ret = BACKREF_FOUND_SHARED; 1102 break; 1103 } 1104 1105 root = btrfs_extent_data_ref_root(leaf, dref); 1106 | 1093 break; 1094 case BTRFS_EXTENT_DATA_REF_KEY: { 1095 struct btrfs_extent_data_ref *dref; 1096 int count; 1097 u64 root; 1098 1099 dref = (struct btrfs_extent_data_ref *)(&iref->offset); 1100 count = btrfs_extent_data_ref_count(leaf, dref); --- 5 unchanged lines hidden (view full) --- 1106 if (sc && key.objectid != sc->inum && 1107 !sc->have_delayed_delete_refs) { 1108 ret = BACKREF_FOUND_SHARED; 1109 break; 1110 } 1111 1112 root = btrfs_extent_data_ref_root(leaf, dref); 1113 |
1107 ret = add_indirect_ref(fs_info, preftrees, root, 1108 &key, 0, bytenr, count, | 1114 ret = add_indirect_ref(ctx->fs_info, preftrees, root, 1115 &key, 0, ctx->bytenr, count, |
1109 sc, GFP_NOFS); 1110 1111 break; 1112 } 1113 default: 1114 WARN_ON(1); 1115 } 1116 if (ret) --- 333 unchanged lines hidden (view full) --- 1450 1451 path->slots[0]--; 1452 leaf = path->nodes[0]; 1453 slot = path->slots[0]; 1454 btrfs_item_key_to_cpu(leaf, &key, slot); 1455 if (key.objectid == ctx->bytenr && 1456 (key.type == BTRFS_EXTENT_ITEM_KEY || 1457 key.type == BTRFS_METADATA_ITEM_KEY)) { | 1116 sc, GFP_NOFS); 1117 1118 break; 1119 } 1120 default: 1121 WARN_ON(1); 1122 } 1123 if (ret) --- 333 unchanged lines hidden (view full) --- 1457 1458 path->slots[0]--; 1459 leaf = path->nodes[0]; 1460 slot = path->slots[0]; 1461 btrfs_item_key_to_cpu(leaf, &key, slot); 1462 if (key.objectid == ctx->bytenr && 1463 (key.type == BTRFS_EXTENT_ITEM_KEY || 1464 key.type == BTRFS_METADATA_ITEM_KEY)) { |
1458 ret = add_inline_refs(ctx->fs_info, path, ctx->bytenr, 1459 &info_level, &preftrees, sc); | 1465 ret = add_inline_refs(ctx, path, &info_level, 1466 &preftrees, sc); |
1460 if (ret) 1461 goto out; 1462 ret = add_keyed_refs(root, path, ctx->bytenr, info_level, 1463 &preftrees, sc); 1464 if (ret) 1465 goto out; 1466 } 1467 } --- 2087 unchanged lines hidden --- | 1467 if (ret) 1468 goto out; 1469 ret = add_keyed_refs(root, path, ctx->bytenr, info_level, 1470 &preftrees, sc); 1471 if (ret) 1472 goto out; 1473 } 1474 } --- 2087 unchanged lines hidden --- |