Skip to content

Commit 3cae210

Browse files
Qu WenruoChris Mason
authored andcommitted
btrfs: Cleanup for using BTRFS_SETGET_STACK instead of raw convert
Some codes still use the cpu_to_lexx instead of the BTRFS_SETGET_STACK_FUNCS declared in ctree.h. Also added some BTRFS_SETGET_STACK_FUNCS for btrfs_header btrfs_timespec and other structures. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Reviewed-by: Miao Xie <miaoxie@cn.fujitsu.com> Reviewed-by: David Sterba <dsterba@suse.cz> Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
1 parent 1e7bac1 commit 3cae210

9 files changed

Lines changed: 150 additions & 113 deletions

File tree

‎fs/btrfs/check-integrity.c‎

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ static int btrfsic_process_superblock_dev_mirror(
813813
(bh->b_data + (dev_bytenr & 4095));
814814

815815
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 ||
817817
memcmp(device->uuid, super_tmp->dev_item.uuid, BTRFS_UUID_SIZE) ||
818818
btrfs_super_nodesize(super_tmp) != state->metablock_size ||
819819
btrfs_super_leafsize(super_tmp) != state->metablock_size ||
@@ -880,20 +880,20 @@ static int btrfsic_process_superblock_dev_mirror(
880880
tmp_disk_key.offset = 0;
881881
switch (pass) {
882882
case 0:
883-
tmp_disk_key.objectid =
884-
cpu_to_le64(BTRFS_ROOT_TREE_OBJECTID);
883+
btrfs_set_disk_key_objectid(&tmp_disk_key,
884+
BTRFS_ROOT_TREE_OBJECTID);
885885
additional_string = "initial root ";
886886
next_bytenr = btrfs_super_root(super_tmp);
887887
break;
888888
case 1:
889-
tmp_disk_key.objectid =
890-
cpu_to_le64(BTRFS_CHUNK_TREE_OBJECTID);
889+
btrfs_set_disk_key_objectid(&tmp_disk_key,
890+
BTRFS_CHUNK_TREE_OBJECTID);
891891
additional_string = "initial chunk ";
892892
next_bytenr = btrfs_super_chunk_root(super_tmp);
893893
break;
894894
case 2:
895-
tmp_disk_key.objectid =
896-
cpu_to_le64(BTRFS_TREE_LOG_OBJECTID);
895+
btrfs_set_disk_key_objectid(&tmp_disk_key,
896+
BTRFS_TREE_LOG_OBJECTID);
897897
additional_string = "initial log ";
898898
next_bytenr = btrfs_super_log_root(super_tmp);
899899
if (0 == next_bytenr)
@@ -1003,7 +1003,7 @@ static int btrfsic_process_metablock(
10031003
(struct btrfs_leaf *)sf->hdr;
10041004

10051005
if (-1 == sf->i) {
1006-
sf->nr = le32_to_cpu(leafhdr->header.nritems);
1006+
sf->nr = btrfs_stack_header_nritems(&leafhdr->header);
10071007

10081008
if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE)
10091009
printk(KERN_INFO
@@ -1013,9 +1013,11 @@ static int btrfsic_process_metablock(
10131013
sf->block_ctx->start,
10141014
sf->nr,
10151015
(unsigned long long)
1016-
le64_to_cpu(leafhdr->header.generation),
1016+
btrfs_stack_header_generation(
1017+
&leafhdr->header),
10171018
(unsigned long long)
1018-
le64_to_cpu(leafhdr->header.owner));
1019+
btrfs_stack_header_owner(
1020+
&leafhdr->header));
10191021
}
10201022

10211023
continue_with_current_leaf_stack_frame:
@@ -1047,10 +1049,10 @@ static int btrfsic_process_metablock(
10471049
&disk_item,
10481050
disk_item_offset,
10491051
sizeof(struct btrfs_item));
1050-
item_offset = le32_to_cpu(disk_item.offset);
1051-
item_size = le32_to_cpu(disk_item.size);
1052+
item_offset = btrfs_stack_item_offset(&disk_item);
1053+
item_size = btrfs_stack_item_offset(&disk_item);
10521054
disk_key = &disk_item.key;
1053-
type = disk_key->type;
1055+
type = btrfs_disk_key_type(disk_key);
10541056

10551057
if (BTRFS_ROOT_ITEM_KEY == type) {
10561058
struct btrfs_root_item root_item;
@@ -1066,7 +1068,7 @@ static int btrfsic_process_metablock(
10661068
sf->block_ctx, &root_item,
10671069
root_item_offset,
10681070
item_size);
1069-
next_bytenr = le64_to_cpu(root_item.bytenr);
1071+
next_bytenr = btrfs_root_bytenr(&root_item);
10701072

10711073
sf->error =
10721074
btrfsic_create_link_to_next_block(
@@ -1081,8 +1083,8 @@ static int btrfsic_process_metablock(
10811083
&sf->num_copies,
10821084
&sf->mirror_num,
10831085
disk_key,
1084-
le64_to_cpu(root_item.
1085-
generation));
1086+
btrfs_root_generation(
1087+
&root_item));
10861088
if (sf->error)
10871089
goto one_stack_frame_backwards;
10881090

@@ -1130,7 +1132,7 @@ static int btrfsic_process_metablock(
11301132
struct btrfs_node *const nodehdr = (struct btrfs_node *)sf->hdr;
11311133

11321134
if (-1 == sf->i) {
1133-
sf->nr = le32_to_cpu(nodehdr->header.nritems);
1135+
sf->nr = btrfs_stack_header_nritems(&nodehdr->header);
11341136

11351137
if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE)
11361138
printk(KERN_INFO "node %llu level %d items %d"
@@ -1139,9 +1141,11 @@ static int btrfsic_process_metablock(
11391141
sf->block_ctx->start,
11401142
nodehdr->header.level, sf->nr,
11411143
(unsigned long long)
1142-
le64_to_cpu(nodehdr->header.generation),
1144+
btrfs_stack_header_generation(
1145+
&nodehdr->header),
11431146
(unsigned long long)
1144-
le64_to_cpu(nodehdr->header.owner));
1147+
btrfs_stack_header_owner(
1148+
&nodehdr->header));
11451149
}
11461150

11471151
continue_with_current_node_stack_frame:
@@ -1168,7 +1172,7 @@ static int btrfsic_process_metablock(
11681172
btrfsic_read_from_block_data(
11691173
sf->block_ctx, &key_ptr, key_ptr_offset,
11701174
sizeof(struct btrfs_key_ptr));
1171-
next_bytenr = le64_to_cpu(key_ptr.blockptr);
1175+
next_bytenr = btrfs_stack_key_blockptr(&key_ptr);
11721176

11731177
sf->error = btrfsic_create_link_to_next_block(
11741178
state,
@@ -1182,7 +1186,7 @@ static int btrfsic_process_metablock(
11821186
&sf->num_copies,
11831187
&sf->mirror_num,
11841188
&key_ptr.key,
1185-
le64_to_cpu(key_ptr.generation));
1189+
btrfs_stack_key_generation(&key_ptr));
11861190
if (sf->error)
11871191
goto one_stack_frame_backwards;
11881192

@@ -1444,12 +1448,13 @@ static int btrfsic_handle_extent_data(
14441448
file_extent_item_offset,
14451449
offsetof(struct btrfs_file_extent_item, disk_num_bytes));
14461450
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) {
14481452
if (state->print_mask & BTRFSIC_PRINT_MASK_VERY_VERBOSE)
14491453
printk(KERN_INFO "extent_data: type %u, disk_bytenr = %llu\n",
14501454
file_extent_item.type,
14511455
(unsigned long long)
1452-
le64_to_cpu(file_extent_item.disk_bytenr));
1456+
btrfs_stack_file_extent_disk_bytenr(
1457+
&file_extent_item));
14531458
return 0;
14541459
}
14551460

@@ -1463,19 +1468,20 @@ static int btrfsic_handle_extent_data(
14631468
btrfsic_read_from_block_data(block_ctx, &file_extent_item,
14641469
file_extent_item_offset,
14651470
sizeof(struct btrfs_file_extent_item));
1466-
next_bytenr = le64_to_cpu(file_extent_item.disk_bytenr) +
1467-
le64_to_cpu(file_extent_item.offset);
1468-
generation = le64_to_cpu(file_extent_item.generation);
1469-
num_bytes = le64_to_cpu(file_extent_item.num_bytes);
1470-
generation = le64_to_cpu(file_extent_item.generation);
1471+
next_bytenr = btrfs_stack_file_extent_disk_bytenr(&file_extent_item) +
1472+
btrfs_stack_file_extent_offset(&file_extent_item);
1473+
generation = btrfs_stack_file_extent_generation(&file_extent_item);
1474+
num_bytes = btrfs_stack_file_extent_num_bytes(&file_extent_item);
1475+
generation = btrfs_stack_file_extent_generation(&file_extent_item);
14711476

14721477
if (state->print_mask & BTRFSIC_PRINT_MASK_VERY_VERBOSE)
14731478
printk(KERN_INFO "extent_data: type %u, disk_bytenr = %llu,"
14741479
" offset = %llu, num_bytes = %llu\n",
14751480
file_extent_item.type,
14761481
(unsigned long long)
1477-
le64_to_cpu(file_extent_item.disk_bytenr),
1478-
(unsigned long long)le64_to_cpu(file_extent_item.offset),
1482+
btrfs_stack_file_extent_disk_bytenr(&file_extent_item),
1483+
(unsigned long long)
1484+
btrfs_stack_file_extent_offset(&file_extent_item),
14791485
(unsigned long long)num_bytes);
14801486
while (num_bytes > 0) {
14811487
u32 chunk_len;
@@ -1896,8 +1902,8 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
18961902
struct list_head *tmp_ref_to;
18971903

18981904
if (block->is_superblock) {
1899-
bytenr = le64_to_cpu(((struct btrfs_super_block *)
1900-
mapped_datav[0])->bytenr);
1905+
bytenr = btrfs_super_bytenr((struct btrfs_super_block *)
1906+
mapped_datav[0]);
19011907
if (num_pages * PAGE_CACHE_SIZE <
19021908
BTRFS_SUPER_INFO_SIZE) {
19031909
printk(KERN_INFO
@@ -1923,8 +1929,9 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
19231929
return;
19241930
}
19251931
processed_len = state->metablock_size;
1926-
bytenr = le64_to_cpu(((struct btrfs_header *)
1927-
mapped_datav[0])->bytenr);
1932+
bytenr = btrfs_stack_header_bytenr(
1933+
(struct btrfs_header *)
1934+
mapped_datav[0]);
19281935
btrfsic_cmp_log_and_dev_bytenr(state, bytenr,
19291936
dev_state,
19301937
dev_bytenr);
@@ -1992,13 +1999,13 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
19921999
block->mirror_num,
19932000
(unsigned long long)block->generation,
19942001
(unsigned long long)
1995-
le64_to_cpu(block->disk_key.objectid),
2002+
btrfs_disk_key_objectid(&block->disk_key),
19962003
block->disk_key.type,
19972004
(unsigned long long)
1998-
le64_to_cpu(block->disk_key.offset),
2005+
btrfs_disk_key_offset(&block->disk_key),
19992006
(unsigned long long)
2000-
le64_to_cpu(((struct btrfs_header *)
2001-
mapped_datav[0])->generation),
2007+
btrfs_stack_header_generation(
2008+
(struct btrfs_header *) mapped_datav[0]),
20022009
(unsigned long long)
20032010
state->max_superblock_generation);
20042011
btrfsic_dump_tree(state);
@@ -2015,8 +2022,9 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
20152022
block->mirror_num,
20162023
(unsigned long long)block->generation,
20172024
(unsigned long long)
2018-
le64_to_cpu(((struct btrfs_header *)
2019-
mapped_datav[0])->generation));
2025+
btrfs_stack_header_generation(
2026+
(struct btrfs_header *)
2027+
mapped_datav[0]));
20202028
/* it would not be safe to go on */
20212029
btrfsic_dump_tree(state);
20222030
goto continue_loop;
@@ -2184,8 +2192,9 @@ static void btrfsic_process_written_block(struct btrfsic_dev_state *dev_state,
21842192
block_ctx.pagev = NULL;
21852193
} else {
21862194
processed_len = state->metablock_size;
2187-
bytenr = le64_to_cpu(((struct btrfs_header *)
2188-
mapped_datav[0])->bytenr);
2195+
bytenr = btrfs_stack_header_bytenr(
2196+
(struct btrfs_header *)
2197+
mapped_datav[0]);
21892198
btrfsic_cmp_log_and_dev_bytenr(state, bytenr, dev_state,
21902199
dev_bytenr);
21912200
if (state->print_mask & BTRFSIC_PRINT_MASK_VERBOSE)
@@ -2434,13 +2443,14 @@ static int btrfsic_process_written_superblock(
24342443
const char *additional_string = NULL;
24352444
struct btrfs_disk_key tmp_disk_key;
24362445

2437-
tmp_disk_key.type = BTRFS_ROOT_ITEM_KEY;
2438-
tmp_disk_key.offset = 0;
2446+
btrfs_set_disk_key_objectid(&tmp_disk_key,
2447+
BTRFS_ROOT_ITEM_KEY);
2448+
btrfs_set_disk_key_objectid(&tmp_disk_key, 0);
24392449

24402450
switch (pass) {
24412451
case 0:
2442-
tmp_disk_key.objectid =
2443-
cpu_to_le64(BTRFS_ROOT_TREE_OBJECTID);
2452+
btrfs_set_disk_key_objectid(&tmp_disk_key,
2453+
BTRFS_ROOT_TREE_OBJECTID);
24442454
additional_string = "root ";
24452455
next_bytenr = btrfs_super_root(super_hdr);
24462456
if (state->print_mask &
@@ -2449,8 +2459,8 @@ static int btrfsic_process_written_superblock(
24492459
(unsigned long long)next_bytenr);
24502460
break;
24512461
case 1:
2452-
tmp_disk_key.objectid =
2453-
cpu_to_le64(BTRFS_CHUNK_TREE_OBJECTID);
2462+
btrfs_set_disk_key_objectid(&tmp_disk_key,
2463+
BTRFS_CHUNK_TREE_OBJECTID);
24542464
additional_string = "chunk ";
24552465
next_bytenr = btrfs_super_chunk_root(super_hdr);
24562466
if (state->print_mask &
@@ -2459,8 +2469,8 @@ static int btrfsic_process_written_superblock(
24592469
(unsigned long long)next_bytenr);
24602470
break;
24612471
case 2:
2462-
tmp_disk_key.objectid =
2463-
cpu_to_le64(BTRFS_TREE_LOG_OBJECTID);
2472+
btrfs_set_disk_key_objectid(&tmp_disk_key,
2473+
BTRFS_TREE_LOG_OBJECTID);
24642474
additional_string = "log ";
24652475
next_bytenr = btrfs_super_log_root(super_hdr);
24662476
if (0 == next_bytenr)

‎fs/btrfs/ctree.h‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,23 @@ BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
22402240
BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
22412241
BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
22422242
BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2243+
BTRFS_SETGET_STACK_FUNCS(stack_inode_generation, struct btrfs_inode_item,
2244+
generation, 64);
2245+
BTRFS_SETGET_STACK_FUNCS(stack_inode_sequence, struct btrfs_inode_item,
2246+
sequence, 64);
2247+
BTRFS_SETGET_STACK_FUNCS(stack_inode_transid, struct btrfs_inode_item,
2248+
transid, 64);
2249+
BTRFS_SETGET_STACK_FUNCS(stack_inode_size, struct btrfs_inode_item, size, 64);
2250+
BTRFS_SETGET_STACK_FUNCS(stack_inode_nbytes, struct btrfs_inode_item,
2251+
nbytes, 64);
2252+
BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group, struct btrfs_inode_item,
2253+
block_group, 64);
2254+
BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink, struct btrfs_inode_item, nlink, 32);
2255+
BTRFS_SETGET_STACK_FUNCS(stack_inode_uid, struct btrfs_inode_item, uid, 32);
2256+
BTRFS_SETGET_STACK_FUNCS(stack_inode_gid, struct btrfs_inode_item, gid, 32);
2257+
BTRFS_SETGET_STACK_FUNCS(stack_inode_mode, struct btrfs_inode_item, mode, 32);
2258+
BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev, struct btrfs_inode_item, rdev, 64);
2259+
BTRFS_SETGET_STACK_FUNCS(stack_inode_flags, struct btrfs_inode_item, flags, 64);
22432260

22442261
static inline struct btrfs_timespec *
22452262
btrfs_inode_atime(struct btrfs_inode_item *inode_item)
@@ -2267,6 +2284,8 @@ btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
22672284

22682285
BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
22692286
BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
2287+
BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec, sec, 64);
2288+
BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec, nsec, 32);
22702289

22712290
/* struct btrfs_dev_extent */
22722291
BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
@@ -2348,6 +2367,10 @@ BTRFS_SETGET_FUNCS(ref_count_v0, struct btrfs_extent_ref_v0, count, 32);
23482367
/* struct btrfs_node */
23492368
BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
23502369
BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
2370+
BTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr,
2371+
blockptr, 64);
2372+
BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr,
2373+
generation, 64);
23512374

23522375
static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
23532376
{
@@ -2404,6 +2427,8 @@ static inline void btrfs_set_node_key(struct extent_buffer *eb,
24042427
/* struct btrfs_item */
24052428
BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
24062429
BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
2430+
BTRFS_SETGET_STACK_FUNCS(stack_item_offset, struct btrfs_item, offset, 32);
2431+
BTRFS_SETGET_STACK_FUNCS(stack_item_size, struct btrfs_item, size, 32);
24072432

24082433
static inline unsigned long btrfs_item_nr_offset(int nr)
24092434
{
@@ -2466,6 +2491,13 @@ BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
24662491
BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
24672492
BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
24682493
BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
2494+
BTRFS_SETGET_STACK_FUNCS(stack_dir_type, struct btrfs_dir_item, type, 8);
2495+
BTRFS_SETGET_STACK_FUNCS(stack_dir_data_len, struct btrfs_dir_item,
2496+
data_len, 16);
2497+
BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item,
2498+
name_len, 16);
2499+
BTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item,
2500+
transid, 64);
24692501

24702502
static inline void btrfs_dir_item_key(struct extent_buffer *eb,
24712503
struct btrfs_dir_item *item,
@@ -2568,6 +2600,12 @@ BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
25682600
BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
25692601
BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
25702602
BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
2603+
BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header,
2604+
generation, 64);
2605+
BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64);
2606+
BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header,
2607+
nritems, 32);
2608+
BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64);
25712609

25722610
static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
25732611
{
@@ -2830,6 +2868,7 @@ BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
28302868
csum_type, 16);
28312869
BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
28322870
cache_generation, 64);
2871+
BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64);
28332872

28342873
static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
28352874
{
@@ -2847,6 +2886,14 @@ static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
28472886

28482887
/* struct btrfs_file_extent_item */
28492888
BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
2889+
BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_bytenr,
2890+
struct btrfs_file_extent_item, disk_bytenr, 64);
2891+
BTRFS_SETGET_STACK_FUNCS(stack_file_extent_offset,
2892+
struct btrfs_file_extent_item, offset, 64);
2893+
BTRFS_SETGET_STACK_FUNCS(stack_file_extent_generation,
2894+
struct btrfs_file_extent_item, generation, 64);
2895+
BTRFS_SETGET_STACK_FUNCS(stack_file_extent_num_bytes,
2896+
struct btrfs_file_extent_item, num_bytes, 64);
28502897

28512898
static inline unsigned long
28522899
btrfs_file_extent_inline_start(struct btrfs_file_extent_item *e)

0 commit comments

Comments
 (0)