diff options
Diffstat (limited to 'fs/btrfs/check-integrity.c')
-rw-r--r-- | fs/btrfs/check-integrity.c | 110 |
1 files changed, 60 insertions, 50 deletions
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c index 1431a6965017..1f706e93e622 100644 --- a/fs/btrfs/check-integrity.c +++ b/fs/btrfs/check-integrity.c | |||
@@ -813,7 +813,7 @@ static int btrfsic_process_superblock_dev_mirror( | |||
813 | (bh->b_data + (dev_bytenr & 4095)); | 813 | (bh->b_data + (dev_bytenr & 4095)); |
814 | 814 | ||
815 | if (btrfs_super_bytenr(super_tmp) != dev_bytenr || | 815 | if (btrfs_super_bytenr(super_tmp) != dev_bytenr || |
816 | super_tmp->magic != cpu_to_le64(BTRFS_MAGIC) || | 816 | btrfs_super_magic(super_tmp) != BTRFS_MAGIC || |
817 | memcmp(device->uuid, super_tmp->dev_item.uuid, BTRFS_UUID_SIZE) || | 817 | memcmp(device->uuid, super_tmp->dev_item.uuid, BTRFS_UUID_SIZE) || |
818 | btrfs_super_nodesize(super_tmp) != state->metablock_size || | 818 | btrfs_super_nodesize(super_tmp) != state->metablock_size || |
819 | btrfs_super_leafsize(super_tmp) != state->metablock_size || | 819 | btrfs_super_leafsize(super_tmp) != state->metablock_size || |
@@ -880,20 +880,20 @@ static int btrfsic_process_superblock_dev_mirror( | |||
880 | tmp_disk_key.offset = 0; | 880 | tmp_disk_key.offset = 0; |
881 | switch (pass) { | 881 | switch (pass) { |
882 | case 0: | 882 | case 0: |
883 | tmp_disk_key.objectid = | 883 | btrfs_set_disk_key_objectid(&tmp_disk_key, |
884 | cpu_to_le64(BTRFS_ROOT_TREE_OBJECTID); | 884 | BTRFS_ROOT_TREE_OBJECTID); |
885 | additional_string = "initial root "; | 885 | additional_string = "initial root "; |
886 | next_bytenr = btrfs_super_root(super_tmp); | 886 | next_bytenr = btrfs_super_root(super_tmp); |
887 | break; | 887 | break; |
888 | case 1: | 888 | case 1: |
889 | tmp_disk_key.objectid = | 889 | btrfs_set_disk_key_objectid(&tmp_disk_key, |
890 | cpu_to_le64(BTRFS_CHUNK_TREE_OBJECTID); | 890 | BTRFS_CHUNK_TREE_OBJECTID); |
891 | additional_string = "initial chunk "; | 891 | additional_string = "initial chunk "; |
892 | next_bytenr = btrfs_super_chunk_root(super_tmp); | 892 | next_bytenr = btrfs_super_chunk_root(super_tmp); |
893 | break; | 893 | break; |
894 | case 2: | 894 | case 2: |
895 | tmp_disk_key.objectid = | 895 | btrfs_set_disk_key_objectid(&tmp_disk_key, |
896 | cpu_to_le64(BTRFS_TREE_LOG_OBJECTID); | 896 | BTRFS_TREE_LOG_OBJECTID); |
897 | additional_string = "initial log "; | 897 | additional_string = "initial log "; |
898 | next_bytenr = btrfs_super_log_root(super_tmp); | 898 | next_bytenr = btrfs_super_log_root(super_tmp); |
899 | if (0 == next_bytenr) | 899 | if (0 == next_bytenr) |
@@ -1003,7 +1003,7 @@ continue_with_new_stack_frame: | |||
1003 | (struct btrfs_leaf *)sf->hdr; | 1003 | (struct btrfs_leaf *)sf->hdr; |
1004 | 1004 | ||
1005 | if (-1 == sf->i) { | 1005 | if (-1 == sf->i) { |
1006 | sf->nr = le32_to_cpu(leafhdr->header.nritems); | 1006 | sf->nr = btrfs_stack_header_nritems(&leafhdr->header); |
1007 | 1007 | ||
1008 | if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE) | 1008 | if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE) |
1009 | printk(KERN_INFO | 1009 | printk(KERN_INFO |
@@ -1013,9 +1013,11 @@ continue_with_new_stack_frame: | |||
1013 | sf->block_ctx->start, | 1013 | sf->block_ctx->start, |
1014 | sf->nr, | 1014 | sf->nr, |
1015 | (unsigned long long) | 1015 | (unsigned long long) |
1016 | le64_to_cpu(leafhdr->header.generation), | 1016 | btrfs_stack_header_generation( |
1017 | &leafhdr->header), | ||
1017 | (unsigned long long) | 1018 | (unsigned long long) |
1018 | le64_to_cpu(leafhdr->header.owner)); | 1019 | btrfs_stack_header_owner( |
1020 | &leafhdr->header)); | ||
1019 | } | 1021 | } |
1020 | 1022 | ||
1021 | continue_with_current_leaf_stack_frame: | 1023 | continue_with_current_leaf_stack_frame: |
@@ -1047,10 +1049,10 @@ leaf_item_out_of_bounce_error: | |||
1047 | &disk_item, | 1049 | &disk_item, |
1048 | disk_item_offset, | 1050 | disk_item_offset, |
1049 | sizeof(struct btrfs_item)); | 1051 | sizeof(struct btrfs_item)); |
1050 | item_offset = le32_to_cpu(disk_item.offset); | 1052 | item_offset = btrfs_stack_item_offset(&disk_item); |
1051 | item_size = le32_to_cpu(disk_item.size); | 1053 | item_size = btrfs_stack_item_offset(&disk_item); |
1052 | disk_key = &disk_item.key; | 1054 | disk_key = &disk_item.key; |
1053 | type = disk_key->type; | 1055 | type = btrfs_disk_key_type(disk_key); |
1054 | 1056 | ||
1055 | if (BTRFS_ROOT_ITEM_KEY == type) { | 1057 | if (BTRFS_ROOT_ITEM_KEY == type) { |
1056 | struct btrfs_root_item root_item; | 1058 | struct btrfs_root_item root_item; |
@@ -1066,7 +1068,7 @@ leaf_item_out_of_bounce_error: | |||
1066 | sf->block_ctx, &root_item, | 1068 | sf->block_ctx, &root_item, |
1067 | root_item_offset, | 1069 | root_item_offset, |
1068 | item_size); | 1070 | item_size); |
1069 | next_bytenr = le64_to_cpu(root_item.bytenr); | 1071 | next_bytenr = btrfs_root_bytenr(&root_item); |
1070 | 1072 | ||
1071 | sf->error = | 1073 | sf->error = |
1072 | btrfsic_create_link_to_next_block( | 1074 | btrfsic_create_link_to_next_block( |
@@ -1081,8 +1083,8 @@ leaf_item_out_of_bounce_error: | |||
1081 | &sf->num_copies, | 1083 | &sf->num_copies, |
1082 | &sf->mirror_num, | 1084 | &sf->mirror_num, |
1083 | disk_key, | 1085 | disk_key, |
1084 | le64_to_cpu(root_item. | 1086 | btrfs_root_generation( |
1085 | generation)); | 1087 | &root_item)); |
1086 | if (sf->error) | 1088 | if (sf->error) |
1087 | goto one_stack_frame_backwards; | 1089 | goto one_stack_frame_backwards; |
1088 | 1090 | ||
@@ -1130,7 +1132,7 @@ leaf_item_out_of_bounce_error: | |||
1130 | struct btrfs_node *const nodehdr = (struct btrfs_node *)sf->hdr; | 1132 | struct btrfs_node *const nodehdr = (struct btrfs_node *)sf->hdr; |
1131 | 1133 | ||
1132 | if (-1 == sf->i) { | 1134 | if (-1 == sf->i) { |
1133 | sf->nr = le32_to_cpu(nodehdr->header.nritems); | 1135 | sf->nr = btrfs_stack_header_nritems(&nodehdr->header); |
1134 | 1136 | ||
1135 | if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE) | 1137 | if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE) |
1136 | printk(KERN_INFO "node %llu level %d items %d" | 1138 | printk(KERN_INFO "node %llu level %d items %d" |
@@ -1139,9 +1141,11 @@ leaf_item_out_of_bounce_error: | |||
1139 | sf->block_ctx->start, | 1141 | sf->block_ctx->start, |
1140 | nodehdr->header.level, sf->nr, | 1142 | nodehdr->header.level, sf->nr, |
1141 | (unsigned long long) | 1143 | (unsigned long long) |
1142 | le64_to_cpu(nodehdr->header.generation), | 1144 | btrfs_stack_header_generation( |
1145 | &nodehdr->header), | ||
1143 | (unsigned long long) | 1146 | (unsigned long long) |
1144 | le64_to_cpu(nodehdr->header.owner)); | 1147 | btrfs_stack_header_owner( |
1148 | &nodehdr->header)); | ||
1145 | } | 1149 | } |
1146 | 1150 | ||
1147 | continue_with_current_node_stack_frame: | 1151 | continue_with_current_node_stack_frame: |
@@ -1168,7 +1172,7 @@ continue_with_current_node_stack_frame: | |||
1168 | btrfsic_read_from_block_data( | 1172 | btrfsic_read_from_block_data( |
1169 | sf->block_ctx, &key_ptr, key_ptr_offset, | 1173 | sf->block_ctx, &key_ptr, key_ptr_offset, |
1170 | sizeof(struct btrfs_key_ptr)); | 1174 | sizeof(struct btrfs_key_ptr)); |
1171 | next_bytenr = le64_to_cpu(key_ptr.blockptr); | 1175 | next_bytenr = btrfs_stack_key_blockptr(&key_ptr); |
1172 | 1176 | ||
1173 | sf->error = btrfsic_create_link_to_next_block( | 1177 | sf->error = btrfsic_create_link_to_next_block( |
1174 | state, | 1178 | state, |
@@ -1182,7 +1186,7 @@ continue_with_current_node_stack_frame: | |||
1182 | &sf->num_copies, | 1186 | &sf->num_copies, |
1183 | &sf->mirror_num, | 1187 | &sf->mirror_num, |
1184 | &key_ptr.key, | 1188 | &key_ptr.key, |
1185 | le64_to_cpu(key_ptr.generation)); | 1189 | btrfs_stack_key_generation(&key_ptr)); |
1186 | if (sf->error) | 1190 | if (sf->error) |
1187 | goto one_stack_frame_backwards; | 1191 | goto one_stack_frame_backwards; |
1188 | 1192 | ||
@@ -1444,12 +1448,13 @@ static int btrfsic_handle_extent_data( | |||
1444 | file_extent_item_offset, | 1448 | file_extent_item_offset, |
1445 | offsetof(struct btrfs_file_extent_item, disk_num_bytes)); | 1449 | offsetof(struct btrfs_file_extent_item, disk_num_bytes)); |
1446 | if (BTRFS_FILE_EXTENT_REG != file_extent_item.type || | 1450 | if (BTRFS_FILE_EXTENT_REG != file_extent_item.type || |
1447 | ((u64)0) == le64_to_cpu(file_extent_item.disk_bytenr)) { | 1451 | btrfs_stack_file_extent_disk_bytenr(&file_extent_item) == 0) { |
1448 | if (state->print_mask & BTRFSIC_PRINT_MASK_VERY_VERBOSE) | 1452 | if (state->print_mask & BTRFSIC_PRINT_MASK_VERY_VERBOSE) |
1449 | printk(KERN_INFO "extent_data: type %u, disk_bytenr = %llu\n", | 1453 | printk(KERN_INFO "extent_data: type %u, disk_bytenr = %llu\n", |
1450 | file_extent_item.type, | 1454 | file_extent_item.type, |
1451 | (unsigned long long) | 1455 | (unsigned long long) |
1452 | le64_to_cpu(file_extent_item.disk_bytenr)); | 1456 | btrfs_stack_file_extent_disk_bytenr( |
1457 | &file_extent_item)); | ||
1453 | return 0; | 1458 | return 0; |
1454 | } | 1459 | } |
1455 | 1460 | ||
@@ -1463,19 +1468,20 @@ static int btrfsic_handle_extent_data( | |||
1463 | btrfsic_read_from_block_data(block_ctx, &file_extent_item, | 1468 | btrfsic_read_from_block_data(block_ctx, &file_extent_item, |
1464 | file_extent_item_offset, | 1469 | file_extent_item_offset, |
1465 | sizeof(struct btrfs_file_extent_item)); | 1470 | sizeof(struct btrfs_file_extent_item)); |
1466 | next_bytenr = le64_to_cpu(file_extent_item.disk_bytenr) + | 1471 | next_bytenr = btrfs_stack_file_extent_disk_bytenr(&file_extent_item) + |
1467 | le64_to_cpu(file_extent_item.offset); | 1472 | btrfs_stack_file_extent_offset(&file_extent_item); |
1468 | generation = le64_to_cpu(file_extent_item.generation); | 1473 | generation = btrfs_stack_file_extent_generation(&file_extent_item); |
1469 | num_bytes = le64_to_cpu(file_extent_item.num_bytes); | 1474 | num_bytes = btrfs_stack_file_extent_num_bytes(&file_extent_item); |
1470 | generation = le64_to_cpu(file_extent_item.generation); | 1475 | generation = btrfs_stack_file_extent_generation(&file_extent_item); |
1471 | 1476 | ||
1472 | if (state->print_mask & BTRFSIC_PRINT_MASK_VERY_VERBOSE) | 1477 | if (state->print_mask & BTRFSIC_PRINT_MASK_VERY_VERBOSE) |
1473 | printk(KERN_INFO "extent_data: type %u, disk_bytenr = %llu," | 1478 | printk(KERN_INFO "extent_data: type %u, disk_bytenr = %llu," |
1474 | " offset = %llu, num_bytes = %llu\n", | 1479 | " offset = %llu, num_bytes = %llu\n", |
1475 | file_extent_item.type, | 1480 | file_extent_item.type, |
1476 | (unsigned long long) | 1481 | (unsigned long long) |
1477 | le64_to_cpu(file_extent_item.disk_bytenr), | 1482 | btrfs_stack_file_extent_disk_bytenr(&file_extent_item), |
1478 | (unsigned long long)le64_to_cpu(file_extent_item.offset), | 1483 | (unsigned long long) |
1484 | btrfs_stack_file_extent_offset(&file_extent_item), | ||
1479 | (unsigned long long)num_bytes); | 1485 | (unsigned long long)num_bytes); |
1480 | while (num_bytes > 0) { | 1486 | while (num_bytes > 0) { |
1481 | u32 chunk_len; | 1487 | u32 chunk_len; |
@@ -1896,8 +1902,8 @@ again: | |||
1896 | struct list_head *tmp_ref_to; | 1902 | struct list_head *tmp_ref_to; |
1897 | 1903 | ||
1898 | if (block->is_superblock) { | 1904 | if (block->is_superblock) { |
1899 | bytenr = le64_to_cpu(((struct btrfs_super_block *) | 1905 | bytenr = btrfs_super_bytenr((struct btrfs_super_block *) |
1900 | mapped_datav[0])->bytenr); | 1906 | mapped_datav[0]); |
1901 | if (num_pages * PAGE_CACHE_SIZE < | 1907 | if (num_pages * PAGE_CACHE_SIZE < |
1902 | BTRFS_SUPER_INFO_SIZE) { | 1908 | BTRFS_SUPER_INFO_SIZE) { |
1903 | printk(KERN_INFO | 1909 | printk(KERN_INFO |
@@ -1923,8 +1929,9 @@ again: | |||
1923 | return; | 1929 | return; |
1924 | } | 1930 | } |
1925 | processed_len = state->metablock_size; | 1931 | processed_len = state->metablock_size; |
1926 | bytenr = le64_to_cpu(((struct btrfs_header *) | 1932 | bytenr = btrfs_stack_header_bytenr( |
1927 | mapped_datav[0])->bytenr); | 1933 | (struct btrfs_header *) |
1934 | mapped_datav[0]); | ||
1928 | btrfsic_cmp_log_and_dev_bytenr(state, bytenr, | 1935 | btrfsic_cmp_log_and_dev_bytenr(state, bytenr, |
1929 | dev_state, | 1936 | dev_state, |
1930 | dev_bytenr); | 1937 | dev_bytenr); |
@@ -1992,13 +1999,13 @@ again: | |||
1992 | block->mirror_num, | 1999 | block->mirror_num, |
1993 | (unsigned long long)block->generation, | 2000 | (unsigned long long)block->generation, |
1994 | (unsigned long long) | 2001 | (unsigned long long) |
1995 | le64_to_cpu(block->disk_key.objectid), | 2002 | btrfs_disk_key_objectid(&block->disk_key), |
1996 | block->disk_key.type, | 2003 | block->disk_key.type, |
1997 | (unsigned long long) | 2004 | (unsigned long long) |
1998 | le64_to_cpu(block->disk_key.offset), | 2005 | btrfs_disk_key_offset(&block->disk_key), |
1999 | (unsigned long long) | 2006 | (unsigned long long) |
2000 | le64_to_cpu(((struct btrfs_header *) | 2007 | btrfs_stack_header_generation( |
2001 | mapped_datav[0])->generation), | 2008 | (struct btrfs_header *) mapped_datav[0]), |
2002 | (unsigned long long) | 2009 | (unsigned long long) |
2003 | state->max_superblock_generation); | 2010 | state->max_superblock_generation); |
2004 | btrfsic_dump_tree(state); | 2011 | btrfsic_dump_tree(state); |
@@ -2015,8 +2022,9 @@ again: | |||
2015 | block->mirror_num, | 2022 | block->mirror_num, |
2016 | (unsigned long long)block->generation, | 2023 | (unsigned long long)block->generation, |
2017 | (unsigned long long) | 2024 | (unsigned long long) |
2018 | le64_to_cpu(((struct btrfs_header *) | 2025 | btrfs_stack_header_generation( |
2019 | mapped_datav[0])->generation)); | 2026 | (struct btrfs_header *) |
2027 | mapped_datav[0])); | ||
2020 | /* it would not be safe to go on */ | 2028 | /* it would not be safe to go on */ |
2021 | btrfsic_dump_tree(state); | 2029 | btrfsic_dump_tree(state); |
2022 | goto continue_loop; | 2030 | goto continue_loop; |
@@ -2184,8 +2192,9 @@ again: | |||
2184 | block_ctx.pagev = NULL; | 2192 | block_ctx.pagev = NULL; |
2185 | } else { | 2193 | } else { |
2186 | processed_len = state->metablock_size; | 2194 | processed_len = state->metablock_size; |
2187 | bytenr = le64_to_cpu(((struct btrfs_header *) | 2195 | bytenr = btrfs_stack_header_bytenr( |
2188 | mapped_datav[0])->bytenr); | 2196 | (struct btrfs_header *) |
2197 | mapped_datav[0]); | ||
2189 | btrfsic_cmp_log_and_dev_bytenr(state, bytenr, dev_state, | 2198 | btrfsic_cmp_log_and_dev_bytenr(state, bytenr, dev_state, |
2190 | dev_bytenr); | 2199 | dev_bytenr); |
2191 | if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE) | 2200 | if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE) |
@@ -2434,13 +2443,14 @@ static int btrfsic_process_written_superblock( | |||
2434 | const char *additional_string = NULL; | 2443 | const char *additional_string = NULL; |
2435 | struct btrfs_disk_key tmp_disk_key; | 2444 | struct btrfs_disk_key tmp_disk_key; |
2436 | 2445 | ||
2437 | tmp_disk_key.type = BTRFS_ROOT_ITEM_KEY; | 2446 | btrfs_set_disk_key_objectid(&tmp_disk_key, |
2438 | tmp_disk_key.offset = 0; | 2447 | BTRFS_ROOT_ITEM_KEY); |
2448 | btrfs_set_disk_key_objectid(&tmp_disk_key, 0); | ||
2439 | 2449 | ||
2440 | switch (pass) { | 2450 | switch (pass) { |
2441 | case 0: | 2451 | case 0: |
2442 | tmp_disk_key.objectid = | 2452 | btrfs_set_disk_key_objectid(&tmp_disk_key, |
2443 | cpu_to_le64(BTRFS_ROOT_TREE_OBJECTID); | 2453 | BTRFS_ROOT_TREE_OBJECTID); |
2444 | additional_string = "root "; | 2454 | additional_string = "root "; |
2445 | next_bytenr = btrfs_super_root(super_hdr); | 2455 | next_bytenr = btrfs_super_root(super_hdr); |
2446 | if (state->print_mask & | 2456 | if (state->print_mask & |
@@ -2449,8 +2459,8 @@ static int btrfsic_process_written_superblock( | |||
2449 | (unsigned long long)next_bytenr); | 2459 | (unsigned long long)next_bytenr); |
2450 | break; | 2460 | break; |
2451 | case 1: | 2461 | case 1: |
2452 | tmp_disk_key.objectid = | 2462 | btrfs_set_disk_key_objectid(&tmp_disk_key, |
2453 | cpu_to_le64(BTRFS_CHUNK_TREE_OBJECTID); | 2463 | BTRFS_CHUNK_TREE_OBJECTID); |
2454 | additional_string = "chunk "; | 2464 | additional_string = "chunk "; |
2455 | next_bytenr = btrfs_super_chunk_root(super_hdr); | 2465 | next_bytenr = btrfs_super_chunk_root(super_hdr); |
2456 | if (state->print_mask & | 2466 | if (state->print_mask & |
@@ -2459,8 +2469,8 @@ static int btrfsic_process_written_superblock( | |||
2459 | (unsigned long long)next_bytenr); | 2469 | (unsigned long long)next_bytenr); |
2460 | break; | 2470 | break; |
2461 | case 2: | 2471 | case 2: |
2462 | tmp_disk_key.objectid = | 2472 | btrfs_set_disk_key_objectid(&tmp_disk_key, |
2463 | cpu_to_le64(BTRFS_TREE_LOG_OBJECTID); | 2473 | BTRFS_TREE_LOG_OBJECTID); |
2464 | additional_string = "log "; | 2474 | additional_string = "log "; |
2465 | next_bytenr = btrfs_super_log_root(super_hdr); | 2475 | next_bytenr = btrfs_super_log_root(super_hdr); |
2466 | if (0 == next_bytenr) | 2476 | if (0 == next_bytenr) |