btrfs-progs: separate super_copy out of fs_info

Allocate fs_info::super_copy dynamically of full BTRFS_SUPER_INFO_SIZE
and use it directly for saving superblock to disk.

This fixes incorrect superblock checksum after mkfs.

Signed-off-by: David Sterba <dsterba@suse.cz>
master
David Sterba 2013-03-06 17:32:51 +01:00
parent fc61b53da8
commit dd21bc16ad
13 changed files with 81 additions and 77 deletions

View File

@ -64,8 +64,8 @@ int main(int ac, char **av)
return 1; return 1;
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
btrfs_set_super_log_root(&root->fs_info->super_copy, 0); btrfs_set_super_log_root(root->fs_info->super_copy, 0);
btrfs_set_super_log_root_level(&root->fs_info->super_copy, 0); btrfs_set_super_log_root_level(root->fs_info->super_copy, 0);
btrfs_commit_transaction(trans, root); btrfs_commit_transaction(trans, root);
close_ctree(root); close_ctree(root);
return ret; return ret;

View File

@ -40,7 +40,7 @@ int update_seeding_flag(struct btrfs_root *root, int set_flag)
struct btrfs_super_block *disk_super; struct btrfs_super_block *disk_super;
u64 super_flags; u64 super_flags;
disk_super = &root->fs_info->super_copy; disk_super = root->fs_info->super_copy;
super_flags = btrfs_super_flags(disk_super); super_flags = btrfs_super_flags(disk_super);
if (set_flag) { if (set_flag) {
if (super_flags & BTRFS_SUPER_FLAG_SEEDING) { if (super_flags & BTRFS_SUPER_FLAG_SEEDING) {
@ -71,7 +71,7 @@ int enable_extrefs_flag(struct btrfs_root *root)
struct btrfs_super_block *disk_super; struct btrfs_super_block *disk_super;
u64 super_flags; u64 super_flags;
disk_super = &root->fs_info->super_copy; disk_super = root->fs_info->super_copy;
super_flags = btrfs_super_incompat_flags(disk_super); super_flags = btrfs_super_incompat_flags(disk_super);
super_flags |= BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF; super_flags |= BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF;
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);

View File

@ -973,7 +973,7 @@ static u64 count_csum_range(struct btrfs_root *root, u64 start, u64 len)
size_t size; size_t size;
u64 found = 0; u64 found = 0;
u64 csum_end; u64 csum_end;
u16 csum_size = btrfs_super_csum_size(&root->fs_info->super_copy); u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
btrfs_init_path(&path); btrfs_init_path(&path);
@ -3613,7 +3613,7 @@ int cmd_check(int argc, char **argv)
if (info == NULL) if (info == NULL)
return 1; return 1;
uuid_unparse(info->super_copy.fsid, uuidbuf); uuid_unparse(info->super_copy->fsid, uuidbuf);
printf("Checking filesystem on %s\nUUID: %s\n", argv[optind], uuidbuf); printf("Checking filesystem on %s\nUUID: %s\n", argv[optind], uuidbuf);
if (!extent_buffer_uptodate(info->tree_root->node) || if (!extent_buffer_uptodate(info->tree_root->node) ||

View File

@ -1261,7 +1261,7 @@ static int create_ext2_image(struct btrfs_root *root, ext2_filsys ext2_fs,
u64 total_bytes; u64 total_bytes;
u32 sectorsize = root->sectorsize; u32 sectorsize = root->sectorsize;
total_bytes = btrfs_super_total_bytes(&fs_info->super_copy); total_bytes = btrfs_super_total_bytes(fs_info->super_copy);
first_free = BTRFS_SUPER_INFO_OFFSET + sectorsize * 2 - 1; first_free = BTRFS_SUPER_INFO_OFFSET + sectorsize * 2 - 1;
first_free &= ~((u64)sectorsize - 1); first_free &= ~((u64)sectorsize - 1);
@ -1527,7 +1527,7 @@ static int create_chunk_mapping(struct btrfs_trans_handle *trans,
btrfs_init_path(&path); btrfs_init_path(&path);
total_bytes = btrfs_super_total_bytes(&root->fs_info->super_copy); total_bytes = btrfs_super_total_bytes(root->fs_info->super_copy);
chunk_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; chunk_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
BUG_ON(list_empty(&info->fs_devices->devices)); BUG_ON(list_empty(&info->fs_devices->devices));
@ -1691,13 +1691,13 @@ static int init_btrfs(struct btrfs_root *root)
memcpy(&location, &root->root_key, sizeof(location)); memcpy(&location, &root->root_key, sizeof(location));
location.offset = (u64)-1; location.offset = (u64)-1;
ret = btrfs_insert_dir_item(trans, fs_info->tree_root, "default", 7, ret = btrfs_insert_dir_item(trans, fs_info->tree_root, "default", 7,
btrfs_super_root_dir(&fs_info->super_copy), btrfs_super_root_dir(fs_info->super_copy),
&location, BTRFS_FT_DIR, 0); &location, BTRFS_FT_DIR, 0);
if (ret) if (ret)
goto err; goto err;
ret = btrfs_insert_inode_ref(trans, fs_info->tree_root, "default", 7, ret = btrfs_insert_inode_ref(trans, fs_info->tree_root, "default", 7,
location.objectid, location.objectid,
btrfs_super_root_dir(&fs_info->super_copy), 0); btrfs_super_root_dir(fs_info->super_copy), 0);
if (ret) if (ret)
goto err; goto err;
btrfs_set_root_dirid(&fs_info->fs_root->root_item, btrfs_set_root_dirid(&fs_info->fs_root->root_item,
@ -2227,7 +2227,7 @@ static int fixup_chunk_mapping(struct btrfs_root *root)
btrfs_release_path(chunk_root, &path); btrfs_release_path(chunk_root, &path);
/* fixup the system chunk array in super block */ /* fixup the system chunk array in super block */
btrfs_set_super_sys_array_size(&info->super_copy, 0); btrfs_set_super_sys_array_size(info->super_copy, 0);
key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; key.objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
key.offset = 0; key.offset = 0;
@ -2425,11 +2425,11 @@ static int may_rollback(struct btrfs_root *root)
int num_stripes; int num_stripes;
int ret; int ret;
if (btrfs_super_num_devices(&info->super_copy) != 1) if (btrfs_super_num_devices(info->super_copy) != 1)
goto fail; goto fail;
bytenr = BTRFS_SUPER_INFO_OFFSET; bytenr = BTRFS_SUPER_INFO_OFFSET;
total_bytes = btrfs_super_total_bytes(&root->fs_info->super_copy); total_bytes = btrfs_super_total_bytes(root->fs_info->super_copy);
while (1) { while (1) {
ret = btrfs_map_block(&info->mapping_tree, WRITE, bytenr, ret = btrfs_map_block(&info->mapping_tree, WRITE, bytenr,
@ -2659,7 +2659,7 @@ next_extent:
goto fail; goto fail;
} }
/* create a system chunk that maps the whole device */ /* create a system chunk that maps the whole device */
ret = prepare_system_chunk_sb(&root->fs_info->super_copy); ret = prepare_system_chunk_sb(root->fs_info->super_copy);
if (ret) { if (ret) {
fprintf(stderr, "unable to update system chunk\n"); fprintf(stderr, "unable to update system chunk\n");
goto fail; goto fail;

View File

@ -923,7 +923,7 @@ struct btrfs_fs_info {
u64 alloc_start; u64 alloc_start;
struct btrfs_trans_handle *running_transaction; struct btrfs_trans_handle *running_transaction;
struct btrfs_super_block super_copy; struct btrfs_super_block *super_copy;
struct mutex fs_mutex; struct mutex fs_mutex;
u64 super_bytenr; u64 super_bytenr;

View File

@ -372,14 +372,14 @@ no_node:
return 0; return 0;
if (root_backups) if (root_backups)
print_old_roots(&info->super_copy); print_old_roots(info->super_copy);
printf("total bytes %llu\n", printf("total bytes %llu\n",
(unsigned long long)btrfs_super_total_bytes(&info->super_copy)); (unsigned long long)btrfs_super_total_bytes(info->super_copy));
printf("bytes used %llu\n", printf("bytes used %llu\n",
(unsigned long long)btrfs_super_bytes_used(&info->super_copy)); (unsigned long long)btrfs_super_bytes_used(info->super_copy));
uuidbuf[36] = '\0'; uuidbuf[36] = '\0';
uuid_unparse(info->super_copy.fsid, uuidbuf); uuid_unparse(info->super_copy->fsid, uuidbuf);
printf("uuid %s\n", uuidbuf); printf("uuid %s\n", uuidbuf);
printf("%s\n", BTRFS_BUILD_VERSION); printf("%s\n", BTRFS_BUILD_VERSION);
return 0; return 0;

View File

@ -106,7 +106,7 @@ int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
int verify) int verify)
{ {
u16 csum_size = u16 csum_size =
btrfs_super_csum_size(&root->fs_info->super_copy); btrfs_super_csum_size(root->fs_info->super_copy);
return csum_tree_block_size(buf, csum_size, verify); return csum_tree_block_size(buf, csum_size, verify);
} }
@ -840,6 +840,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
} }
memset(fs_info, 0, sizeof(*fs_info)); memset(fs_info, 0, sizeof(*fs_info));
fs_info->super_copy = calloc(1, BTRFS_SUPER_INFO_SIZE);
fs_info->tree_root = tree_root; fs_info->tree_root = tree_root;
fs_info->extent_root = extent_root; fs_info->extent_root = extent_root;
fs_info->chunk_root = chunk_root; fs_info->chunk_root = chunk_root;
@ -875,7 +876,7 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
goto out_cleanup; goto out_cleanup;
fs_info->super_bytenr = sb_bytenr; fs_info->super_bytenr = sb_bytenr;
disk_super = &fs_info->super_copy; disk_super = fs_info->super_copy;
ret = btrfs_read_dev_super(fs_devices->latest_bdev, ret = btrfs_read_dev_super(fs_devices->latest_bdev,
disk_super, sb_bytenr); disk_super, sb_bytenr);
if (ret) { if (ret) {
@ -1164,10 +1165,6 @@ int write_dev_supers(struct btrfs_root *root, struct btrfs_super_block *sb,
u64 bytenr; u64 bytenr;
u32 crc; u32 crc;
int i, ret; int i, ret;
void *buf;
buf = calloc(1, BTRFS_SUPER_INFO_SIZE);
BUG_ON(!buf);
if (root->fs_info->super_bytenr != BTRFS_SUPER_INFO_OFFSET) { if (root->fs_info->super_bytenr != BTRFS_SUPER_INFO_OFFSET) {
btrfs_set_super_bytenr(sb, root->fs_info->super_bytenr); btrfs_set_super_bytenr(sb, root->fs_info->super_bytenr);
@ -1176,11 +1173,15 @@ int write_dev_supers(struct btrfs_root *root, struct btrfs_super_block *sb,
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE); BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
btrfs_csum_final(crc, (char *)&sb->csum[0]); btrfs_csum_final(crc, (char *)&sb->csum[0]);
memcpy(buf, sb, sizeof(*sb)); /*
ret = pwrite64(device->fd, buf, BTRFS_SUPER_INFO_SIZE, * super_copy is BTRFS_SUPER_INFO_SIZE bytes and is
root->fs_info->super_bytenr); * zero filled, we can use it directly
*/
ret = pwrite64(device->fd, root->fs_info->super_copy,
BTRFS_SUPER_INFO_SIZE,
root->fs_info->super_bytenr);
BUG_ON(ret != BTRFS_SUPER_INFO_SIZE); BUG_ON(ret != BTRFS_SUPER_INFO_SIZE);
goto out; return 0;
} }
for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) { for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
@ -1195,12 +1196,15 @@ int write_dev_supers(struct btrfs_root *root, struct btrfs_super_block *sb,
BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE); BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE);
btrfs_csum_final(crc, (char *)&sb->csum[0]); btrfs_csum_final(crc, (char *)&sb->csum[0]);
memcpy(buf, sb, sizeof(*sb)); /*
ret = pwrite64(device->fd, buf, BTRFS_SUPER_INFO_SIZE, bytenr); * super_copy is BTRFS_SUPER_INFO_SIZE bytes and is
* zero filled, we can use it directly
*/
ret = pwrite64(device->fd, root->fs_info->super_copy,
BTRFS_SUPER_INFO_SIZE, bytenr);
BUG_ON(ret != BTRFS_SUPER_INFO_SIZE); BUG_ON(ret != BTRFS_SUPER_INFO_SIZE);
} }
out:
free(buf);
return 0; return 0;
} }
@ -1214,7 +1218,7 @@ int write_all_supers(struct btrfs_root *root)
int ret; int ret;
u64 flags; u64 flags;
sb = &root->fs_info->super_copy; sb = root->fs_info->super_copy;
dev_item = &sb->dev_item; dev_item = &sb->dev_item;
list_for_each(cur, head) { list_for_each(cur, head) {
dev = list_entry(cur, struct btrfs_device, dev_list); dev = list_entry(cur, struct btrfs_device, dev_list);
@ -1251,17 +1255,17 @@ int write_ctree_super(struct btrfs_trans_handle *trans,
if (root->fs_info->readonly) if (root->fs_info->readonly)
return 0; return 0;
btrfs_set_super_generation(&root->fs_info->super_copy, btrfs_set_super_generation(root->fs_info->super_copy,
trans->transid); trans->transid);
btrfs_set_super_root(&root->fs_info->super_copy, btrfs_set_super_root(root->fs_info->super_copy,
tree_root->node->start); tree_root->node->start);
btrfs_set_super_root_level(&root->fs_info->super_copy, btrfs_set_super_root_level(root->fs_info->super_copy,
btrfs_header_level(tree_root->node)); btrfs_header_level(tree_root->node));
btrfs_set_super_chunk_root(&root->fs_info->super_copy, btrfs_set_super_chunk_root(root->fs_info->super_copy,
chunk_root->node->start); chunk_root->node->start);
btrfs_set_super_chunk_root_level(&root->fs_info->super_copy, btrfs_set_super_chunk_root_level(root->fs_info->super_copy,
btrfs_header_level(chunk_root->node)); btrfs_header_level(chunk_root->node));
btrfs_set_super_chunk_root_generation(&root->fs_info->super_copy, btrfs_set_super_chunk_root_generation(root->fs_info->super_copy,
btrfs_header_generation(chunk_root->node)); btrfs_header_generation(chunk_root->node));
ret = write_all_supers(root); ret = write_all_supers(root);

View File

@ -1830,12 +1830,12 @@ static int update_block_group(struct btrfs_trans_handle *trans,
u64 end; u64 end;
/* block accounting for super block */ /* block accounting for super block */
old_val = btrfs_super_bytes_used(&info->super_copy); old_val = btrfs_super_bytes_used(info->super_copy);
if (alloc) if (alloc)
old_val += num_bytes; old_val += num_bytes;
else else
old_val -= num_bytes; old_val -= num_bytes;
btrfs_set_super_bytes_used(&info->super_copy, old_val); btrfs_set_super_bytes_used(info->super_copy, old_val);
/* block accounting for root item */ /* block accounting for root item */
old_val = btrfs_root_used(&root->root_item); old_val = btrfs_root_used(&root->root_item);
@ -3216,7 +3216,7 @@ int btrfs_make_block_groups(struct btrfs_trans_handle *trans,
extent_root = root->fs_info->extent_root; extent_root = root->fs_info->extent_root;
block_group_cache = &root->fs_info->block_group_cache; block_group_cache = &root->fs_info->block_group_cache;
chunk_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID; chunk_objectid = BTRFS_FIRST_CHUNK_TREE_OBJECTID;
total_bytes = btrfs_super_total_bytes(&root->fs_info->super_copy); total_bytes = btrfs_super_total_bytes(root->fs_info->super_copy);
group_align = 64 * root->sectorsize; group_align = 64 * root->sectorsize;
cur_start = 0; cur_start = 0;
@ -3451,7 +3451,7 @@ int btrfs_fix_block_accounting(struct btrfs_trans_handle *trans,
} }
path.slots[0]++; path.slots[0]++;
} }
btrfs_set_super_bytes_used(&root->fs_info->super_copy, bytes_used); btrfs_set_super_bytes_used(root->fs_info->super_copy, bytes_used);
btrfs_release_path(root, &path); btrfs_release_path(root, &path);
return 0; return 0;
} }

View File

@ -134,7 +134,7 @@ struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
struct extent_buffer *leaf; struct extent_buffer *leaf;
u64 csum_offset = 0; u64 csum_offset = 0;
u16 csum_size = u16 csum_size =
btrfs_super_csum_size(&root->fs_info->super_copy); btrfs_super_csum_size(root->fs_info->super_copy);
int csums_in_item; int csums_in_item;
file_key.objectid = BTRFS_EXTENT_CSUM_OBJECTID; file_key.objectid = BTRFS_EXTENT_CSUM_OBJECTID;
@ -206,7 +206,7 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
u32 nritems; u32 nritems;
u32 ins_size; u32 ins_size;
u16 csum_size = u16 csum_size =
btrfs_super_csum_size(&root->fs_info->super_copy); btrfs_super_csum_size(root->fs_info->super_copy);
path = btrfs_alloc_path(); path = btrfs_alloc_path();
BUG_ON(!path); BUG_ON(!path);
@ -352,7 +352,7 @@ static noinline int truncate_one_csum(struct btrfs_trans_handle *trans,
{ {
struct extent_buffer *leaf; struct extent_buffer *leaf;
u16 csum_size = u16 csum_size =
btrfs_super_csum_size(&root->fs_info->super_copy); btrfs_super_csum_size(root->fs_info->super_copy);
u64 csum_end; u64 csum_end;
u64 end_byte = bytenr + len; u64 end_byte = bytenr + len;
u32 blocksize = root->sectorsize; u32 blocksize = root->sectorsize;
@ -411,7 +411,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,
struct extent_buffer *leaf; struct extent_buffer *leaf;
int ret; int ret;
u16 csum_size = u16 csum_size =
btrfs_super_csum_size(&root->fs_info->super_copy); btrfs_super_csum_size(root->fs_info->super_copy);
int blocksize = root->sectorsize; int blocksize = root->sectorsize;
root = root->fs_info->csum_root; root = root->fs_info->csum_root;

View File

@ -147,7 +147,7 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device)
goto out_cleanup; goto out_cleanup;
fs_info->super_bytenr = BTRFS_SUPER_INFO_OFFSET; fs_info->super_bytenr = BTRFS_SUPER_INFO_OFFSET;
disk_super = &fs_info->super_copy; disk_super = fs_info->super_copy;
ret = btrfs_read_dev_super(fs_devices->latest_bdev, ret = btrfs_read_dev_super(fs_devices->latest_bdev,
disk_super, BTRFS_SUPER_INFO_OFFSET); disk_super, BTRFS_SUPER_INFO_OFFSET);
if (ret) { if (ret) {
@ -234,10 +234,10 @@ out:
static int search_iobuf(struct btrfs_root *root, void *iobuf, static int search_iobuf(struct btrfs_root *root, void *iobuf,
size_t iobuf_size, off_t offset) size_t iobuf_size, off_t offset)
{ {
u64 gen = btrfs_super_generation(&root->fs_info->super_copy); u64 gen = btrfs_super_generation(root->fs_info->super_copy);
u64 objectid = search_objectid; u64 objectid = search_objectid;
u32 size = btrfs_super_nodesize(&root->fs_info->super_copy); u32 size = btrfs_super_nodesize(root->fs_info->super_copy);
u8 level = root->fs_info->super_copy.root_level; u8 level = root->fs_info->super_copy->root_level;
size_t block_off = 0; size_t block_off = 0;
while (block_off < iobuf_size) { while (block_off < iobuf_size) {
@ -322,8 +322,8 @@ static int find_root(struct btrfs_root *root)
int ret = 1; int ret = 1;
printf("Super think's the tree root is at %Lu, chunk root %Lu\n", printf("Super think's the tree root is at %Lu, chunk root %Lu\n",
btrfs_super_root(&root->fs_info->super_copy), btrfs_super_root(root->fs_info->super_copy),
btrfs_super_chunk_root(&root->fs_info->super_copy)); btrfs_super_chunk_root(root->fs_info->super_copy));
err = btrfs_next_metadata(&root->fs_info->mapping_tree, err = btrfs_next_metadata(&root->fs_info->mapping_tree,
&metadata_offset, &metadata_size); &metadata_offset, &metadata_size);
@ -336,7 +336,7 @@ static int find_root(struct btrfs_root *root)
u64 type; u64 type;
if (offset > if (offset >
btrfs_super_total_bytes(&root->fs_info->super_copy)) { btrfs_super_total_bytes(root->fs_info->super_copy)) {
printf("Went past the fs size, exiting"); printf("Went past the fs size, exiting");
break; break;
} }
@ -426,7 +426,7 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
csum_size = btrfs_super_csum_size(&root->fs_info->super_copy); csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
ret = find_root(root); ret = find_root(root);
close_ctree(root); close_ctree(root);
return ret; return ret;

12
mkfs.c
View File

@ -67,7 +67,7 @@ static int make_root_dir(struct btrfs_root *root, int mixed)
int ret; int ret;
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
bytes_used = btrfs_super_bytes_used(&root->fs_info->super_copy); bytes_used = btrfs_super_bytes_used(root->fs_info->super_copy);
root->fs_info->system_allocs = 1; root->fs_info->system_allocs = 1;
ret = btrfs_make_block_group(trans, root, bytes_used, ret = btrfs_make_block_group(trans, root, bytes_used,
@ -129,7 +129,7 @@ static int make_root_dir(struct btrfs_root *root, int mixed)
location.offset = (u64)-1; location.offset = (u64)-1;
ret = btrfs_insert_dir_item(trans, root->fs_info->tree_root, ret = btrfs_insert_dir_item(trans, root->fs_info->tree_root,
"default", 7, "default", 7,
btrfs_super_root_dir(&root->fs_info->super_copy), btrfs_super_root_dir(root->fs_info->super_copy),
&location, BTRFS_FT_DIR, 0); &location, BTRFS_FT_DIR, 0);
if (ret) if (ret)
goto err; goto err;
@ -208,7 +208,7 @@ static int create_raid_groups(struct btrfs_trans_handle *trans,
int data_profile_opt, u64 metadata_profile, int data_profile_opt, u64 metadata_profile,
int metadata_profile_opt, int mixed, int ssd) int metadata_profile_opt, int mixed, int ssd)
{ {
u64 num_devices = btrfs_super_num_devices(&root->fs_info->super_copy); u64 num_devices = btrfs_super_num_devices(root->fs_info->super_copy);
u64 allowed = 0; u64 allowed = 0;
u64 devices_for_raid = num_devices; u64 devices_for_raid = num_devices;
int ret; int ret;
@ -1650,7 +1650,7 @@ raid_groups:
ret = create_data_reloc_tree(trans, root); ret = create_data_reloc_tree(trans, root);
BUG_ON(ret); BUG_ON(ret);
super = &root->fs_info->super_copy; super = root->fs_info->super_copy;
flags = btrfs_super_incompat_flags(super); flags = btrfs_super_incompat_flags(super);
flags |= BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF; flags |= BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF;
@ -1661,7 +1661,7 @@ raid_groups:
if ((data_profile | metadata_profile) & if ((data_profile | metadata_profile) &
(BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID6)) { (BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID6)) {
struct btrfs_super_block *super = &root->fs_info->super_copy; struct btrfs_super_block *super = root->fs_info->super_copy;
u64 flags = btrfs_super_incompat_flags(super); u64 flags = btrfs_super_incompat_flags(super);
flags |= BTRFS_FEATURE_INCOMPAT_RAID56; flags |= BTRFS_FEATURE_INCOMPAT_RAID56;
@ -1672,7 +1672,7 @@ raid_groups:
printf("fs created label %s on %s\n\tnodesize %u leafsize %u " printf("fs created label %s on %s\n\tnodesize %u leafsize %u "
"sectorsize %u size %s\n", "sectorsize %u size %s\n",
label, first_file, nodesize, leafsize, sectorsize, label, first_file, nodesize, leafsize, sectorsize,
pretty_buf = pretty_sizes(btrfs_super_total_bytes(&root->fs_info->super_copy))); pretty_buf = pretty_sizes(btrfs_super_total_bytes(root->fs_info->super_copy)));
free(pretty_buf); free(pretty_buf);
printf("%s\n", BTRFS_BUILD_VERSION); printf("%s\n", BTRFS_BUILD_VERSION);

10
utils.c
View File

@ -473,7 +473,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
u32 sectorsize) u32 sectorsize)
{ {
struct btrfs_super_block *disk_super; struct btrfs_super_block *disk_super;
struct btrfs_super_block *super = &root->fs_info->super_copy; struct btrfs_super_block *super = root->fs_info->super_copy;
struct btrfs_device *device; struct btrfs_device *device;
struct btrfs_dev_item *dev_item; struct btrfs_dev_item *dev_item;
char *buf; char *buf;
@ -624,7 +624,7 @@ int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
btrfs_set_stack_timespec_nsec(&inode_item.otime, 0); btrfs_set_stack_timespec_nsec(&inode_item.otime, 0);
if (root->fs_info->tree_root == root) if (root->fs_info->tree_root == root)
btrfs_set_super_root_dir(&root->fs_info->super_copy, objectid); btrfs_set_super_root_dir(root->fs_info->super_copy, objectid);
ret = btrfs_insert_inode(trans, root, objectid, &inode_item); ret = btrfs_insert_inode(trans, root, objectid, &inode_item);
if (ret) if (ret)
@ -1088,7 +1088,7 @@ int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
if (disk_super->magic != cpu_to_le64(BTRFS_MAGIC)) if (disk_super->magic != cpu_to_le64(BTRFS_MAGIC))
goto brelse; goto brelse;
if (!memcmp(disk_super->fsid, root->fs_info->super_copy.fsid, if (!memcmp(disk_super->fsid, root->fs_info->super_copy->fsid,
BTRFS_FSID_SIZE)) BTRFS_FSID_SIZE))
ret = 1; ret = 1;
brelse: brelse:
@ -1191,7 +1191,7 @@ static int set_label_unmounted(const char *dev, const char *label)
return -1; return -1;
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
snprintf(root->fs_info->super_copy.label, BTRFS_LABEL_SIZE, "%s", snprintf(root->fs_info->super_copy->label, BTRFS_LABEL_SIZE, "%s",
label); label);
btrfs_commit_transaction(trans, root); btrfs_commit_transaction(trans, root);
@ -1243,7 +1243,7 @@ static int get_label_unmounted(const char *dev)
if(!root) if(!root)
return -1; return -1;
fprintf(stdout, "%s\n", root->fs_info->super_copy.label); fprintf(stdout, "%s\n", root->fs_info->super_copy->label);
/* Now we close it since we are done. */ /* Now we close it since we are done. */
close_ctree(root); close_ctree(root);

View File

@ -604,7 +604,7 @@ int btrfs_add_system_chunk(struct btrfs_trans_handle *trans,
struct btrfs_key *key, struct btrfs_key *key,
struct btrfs_chunk *chunk, int item_size) struct btrfs_chunk *chunk, int item_size)
{ {
struct btrfs_super_block *super_copy = &root->fs_info->super_copy; struct btrfs_super_block *super_copy = root->fs_info->super_copy;
struct btrfs_disk_key disk_key; struct btrfs_disk_key disk_key;
u32 array_size; u32 array_size;
u8 *ptr; u8 *ptr;
@ -708,7 +708,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
} }
if (type & BTRFS_BLOCK_GROUP_RAID1) { if (type & BTRFS_BLOCK_GROUP_RAID1) {
num_stripes = min_t(u64, 2, num_stripes = min_t(u64, 2,
btrfs_super_num_devices(&info->super_copy)); btrfs_super_num_devices(info->super_copy));
if (num_stripes < 2) if (num_stripes < 2)
return -ENOSPC; return -ENOSPC;
min_stripes = 2; min_stripes = 2;
@ -718,11 +718,11 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
min_stripes = 2; min_stripes = 2;
} }
if (type & (BTRFS_BLOCK_GROUP_RAID0)) { if (type & (BTRFS_BLOCK_GROUP_RAID0)) {
num_stripes = btrfs_super_num_devices(&info->super_copy); num_stripes = btrfs_super_num_devices(info->super_copy);
min_stripes = 2; min_stripes = 2;
} }
if (type & (BTRFS_BLOCK_GROUP_RAID10)) { if (type & (BTRFS_BLOCK_GROUP_RAID10)) {
num_stripes = btrfs_super_num_devices(&info->super_copy); num_stripes = btrfs_super_num_devices(info->super_copy);
if (num_stripes < 4) if (num_stripes < 4)
return -ENOSPC; return -ENOSPC;
num_stripes &= ~(u32)1; num_stripes &= ~(u32)1;
@ -730,24 +730,24 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
min_stripes = 4; min_stripes = 4;
} }
if (type & (BTRFS_BLOCK_GROUP_RAID5)) { if (type & (BTRFS_BLOCK_GROUP_RAID5)) {
num_stripes = btrfs_super_num_devices(&info->super_copy); num_stripes = btrfs_super_num_devices(info->super_copy);
if (num_stripes < 2) if (num_stripes < 2)
return -ENOSPC; return -ENOSPC;
min_stripes = 2; min_stripes = 2;
stripe_len = find_raid56_stripe_len(num_stripes - 1, stripe_len = find_raid56_stripe_len(num_stripes - 1,
btrfs_super_stripesize(&info->super_copy)); btrfs_super_stripesize(info->super_copy));
} }
if (type & (BTRFS_BLOCK_GROUP_RAID6)) { if (type & (BTRFS_BLOCK_GROUP_RAID6)) {
num_stripes = btrfs_super_num_devices(&info->super_copy); num_stripes = btrfs_super_num_devices(info->super_copy);
if (num_stripes < 3) if (num_stripes < 3)
return -ENOSPC; return -ENOSPC;
min_stripes = 3; min_stripes = 3;
stripe_len = find_raid56_stripe_len(num_stripes - 2, stripe_len = find_raid56_stripe_len(num_stripes - 2,
btrfs_super_stripesize(&info->super_copy)); btrfs_super_stripesize(info->super_copy));
} }
/* we don't want a chunk larger than 10% of the FS */ /* we don't want a chunk larger than 10% of the FS */
percent_max = div_factor(btrfs_super_total_bytes(&info->super_copy), 1); percent_max = div_factor(btrfs_super_total_bytes(info->super_copy), 1);
max_chunk_size = min(percent_max, max_chunk_size); max_chunk_size = min(percent_max, max_chunk_size);
again: again:
@ -1652,7 +1652,7 @@ int btrfs_read_super_device(struct btrfs_root *root, struct extent_buffer *buf)
int btrfs_read_sys_array(struct btrfs_root *root) int btrfs_read_sys_array(struct btrfs_root *root)
{ {
struct btrfs_super_block *super_copy = &root->fs_info->super_copy; struct btrfs_super_block *super_copy = root->fs_info->super_copy;
struct extent_buffer *sb; struct extent_buffer *sb;
struct btrfs_disk_key *disk_key; struct btrfs_disk_key *disk_key;
struct btrfs_chunk *chunk; struct btrfs_chunk *chunk;