btrfs-progs: Cleanup for using BTRFS_SETGET_STACK instead of raw convert
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Wed, 26 Jun 2013 05:27:08 +0000 (13:27 +0800)
committerDavid Sterba <dsterba@suse.cz>
Fri, 9 Aug 2013 12:32:32 +0000 (14:32 +0200)
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 and
btrfs_super.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
btrfs-convert.c
btrfs-find-root.c
btrfs-image.c
btrfs-show-super.c
ctree.h
disk-io.c
utils.c
volumes.c

index 399856f..cb96790 100644 (file)
@@ -1802,7 +1802,7 @@ static int prepare_system_chunk_sb(struct btrfs_super_block *super)
        btrfs_set_stack_chunk_num_stripes(chunk, 1);
        btrfs_set_stack_chunk_sub_stripes(chunk, 0);
        chunk->stripe.devid = super->dev_item.devid;
-       chunk->stripe.offset = cpu_to_le64(0);
+       btrfs_set_stack_stripe_offset(&chunk->stripe, 0);
        memcpy(chunk->stripe.dev_uuid, super->dev_item.uuid, BTRFS_UUID_SIZE);
        btrfs_set_super_sys_array_size(super, sizeof(*key) + sizeof(*chunk));
        return 0;
index 9b3d7df..989535f 100644 (file)
@@ -141,10 +141,10 @@ static int search_iobuf(struct btrfs_root *root, void *iobuf,
                u64 h_byte, h_level, h_gen, h_owner;
 
 //             printf("searching %Lu\n", offset + block_off);
-               h_byte = le64_to_cpu(header->bytenr);
-               h_owner = le64_to_cpu(header->owner);
+               h_byte = btrfs_stack_header_bytenr(header);
+               h_owner = btrfs_stack_header_owner(header);
                h_level = header->level;
-               h_gen = le64_to_cpu(header->generation);
+               h_gen = btrfs_stack_header_generation(header);
 
                if (h_owner != objectid)
                        goto next;
index 82aa4f3..634a714 100644 (file)
@@ -1336,7 +1336,7 @@ static void update_super_old(u8 *buffer)
        btrfs_set_stack_chunk_num_stripes(chunk, 1);
        btrfs_set_stack_chunk_sub_stripes(chunk, 0);
        chunk->stripe.devid = super->dev_item.devid;
-       chunk->stripe.offset = cpu_to_le64(0);
+       btrfs_set_stack_stripe_offset(&chunk->stripe, 0);
        memcpy(chunk->stripe.dev_uuid, super->dev_item.uuid, BTRFS_UUID_SIZE);
        btrfs_set_super_sys_array_size(super, sizeof(*key) + sizeof(*chunk));
        csum_block(buffer, 4096);
index c815469..c2e844d 100644 (file)
@@ -186,7 +186,7 @@ static void dump_superblock(struct btrfs_super_block *sb)
        s = (char *) &sb->magic;
        for (i = 0; i < 8; i++)
                putchar(isprint(s[i]) ? s[i] : '.');
-       if (sb->magic == cpu_to_le64(BTRFS_MAGIC))
+       if (btrfs_super_magic(sb) == BTRFS_MAGIC)
                printf(" [match]\n");
        else
                printf(" [DON'T MATCH]\n");
diff --git a/ctree.h b/ctree.h
index 704e990..4e7c1a7 100644 (file)
--- a/ctree.h
+++ b/ctree.h
@@ -1729,6 +1729,12 @@ BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
+BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64);
+BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header, nritems,
+                        32);
+BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64);
+BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header,
+                        generation, 64);
 
 static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
 {
@@ -1937,6 +1943,7 @@ BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
                         cache_generation, 64);
 BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
                         uuid_tree_generation, 64);
+BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64);
 
 static inline int btrfs_super_csum_size(struct btrfs_super_block *s)
 {
index 13dbe27..9cfbea1 100644 (file)
--- a/disk-io.c
+++ b/disk-io.c
@@ -1137,7 +1137,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
                        return -1;
 
                if (btrfs_super_bytenr(&buf) != sb_bytenr ||
-                   buf.magic != cpu_to_le64(BTRFS_MAGIC))
+                   btrfs_super_magic(&buf) != BTRFS_MAGIC)
                        return -1;
 
                memcpy(sb, &buf, sizeof(*sb));
@@ -1153,9 +1153,9 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
                if (btrfs_super_bytenr(&buf) != bytenr )
                        continue;
                /* if magic is NULL, the device was removed */
-               if (buf.magic == 0 && i == 0) 
+               if (btrfs_super_magic(&buf) == 0 && i == 0)
                        return -1;
-               if (buf.magic != cpu_to_le64(BTRFS_MAGIC))
+               if (btrfs_super_magic(&buf) != BTRFS_MAGIC)
                        continue;
 
                if (!fsid_is_initialized) {
diff --git a/utils.c b/utils.c
index 7b4cd74..1eeda0f 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -115,7 +115,7 @@ int make_btrfs(int fd, const char *device, const char *label,
 
        btrfs_set_super_bytenr(&super, blocks[0]);
        btrfs_set_super_num_devices(&super, 1);
-       super.magic = cpu_to_le64(BTRFS_MAGIC);
+       btrfs_set_super_magic(&super, BTRFS_MAGIC);
        btrfs_set_super_generation(&super, 1);
        btrfs_set_super_root(&super, blocks[1]);
        btrfs_set_super_chunk_root(&super, blocks[3]);
@@ -1139,7 +1139,7 @@ int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
 
        ret = 0;
        disk_super = (struct btrfs_super_block *)buf;
-       if (disk_super->magic != cpu_to_le64(BTRFS_MAGIC))
+       if (btrfs_super_magic(disk_super) != BTRFS_MAGIC)
                goto brelse;
 
        if (!memcmp(disk_super->fsid, root->fs_info->super_copy->fsid,
index 10fdc48..cb7adef 100644 (file)
--- a/volumes.c
+++ b/volumes.c
@@ -239,7 +239,7 @@ int btrfs_scan_one_device(int fd, const char *path,
                ret = -EIO;
                goto error_brelse;
        }
-       devid = le64_to_cpu(disk_super->dev_item.devid);
+       devid = btrfs_stack_device_id(&disk_super->dev_item);
        if (btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_METADUMP)
                *total_devs = 1;
        else