btrfs-progs: mkfs, deprecate leafsize and clean up the code

Using the --leafsize will issue a warning. Replace leafsize with
nodesize in the mkfs-related code.

Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
David Sterba 2015-02-02 15:51:15 +01:00
parent 445ed1f11c
commit a297698edc
4 changed files with 71 additions and 75 deletions

View File

@ -2298,7 +2298,7 @@ static int do_convert(const char *devname, int datacsum, int packing, int noxatt
fprintf(stderr, "filetype feature is missing\n");
goto fail;
}
if (btrfs_check_node_or_leaf_size(nodesize, blocksize))
if (btrfs_check_nodesize(nodesize, blocksize))
goto fail;
blocks_per_node = nodesize / blocksize;
ret = -blocks_per_node;
@ -2322,7 +2322,7 @@ static int do_convert(const char *devname, int datacsum, int packing, int noxatt
goto fail;
}
ret = make_btrfs(fd, devname, ext2_fs->super->s_volume_name,
NULL, blocks, total_bytes, nodesize, nodesize,
NULL, blocks, total_bytes, nodesize,
blocksize, blocksize, 0);
if (ret) {
fprintf(stderr, "unable to create initial ctree: %s\n",

42
mkfs.c
View File

@ -1207,17 +1207,16 @@ int main(int ac, char **av)
u64 alloc_start = 0;
u64 metadata_profile = 0;
u64 data_profile = 0;
u32 leafsize = max_t(u32, sysconf(_SC_PAGESIZE),
u32 nodesize = max_t(u32, sysconf(_SC_PAGESIZE),
BTRFS_MKFS_DEFAULT_NODE_SIZE);
u32 sectorsize = 4096;
u32 nodesize = leafsize;
u32 stripesize = 4096;
int zero_end = 1;
int fd;
int ret;
int i;
int mixed = 0;
int leaf_forced = 0;
int nodesize_forced = 0;
int data_profile_opt = 0;
int metadata_profile_opt = 0;
int discard = 1;
@ -1273,10 +1272,11 @@ int main(int ac, char **av)
data_profile_opt = 1;
break;
case 'l':
fprintf(stderr,
"WARNING: --leafsize is deprecated, use --nodesize\n");
case 'n':
nodesize = parse_size(optarg);
leafsize = parse_size(optarg);
leaf_forced = 1;
nodesize_forced = 1;
break;
case 'L':
label = parse_label(optarg);
@ -1337,9 +1337,7 @@ int main(int ac, char **av)
}
}
sectorsize = max(sectorsize, (u32)sysconf(_SC_PAGESIZE));
if (btrfs_check_node_or_leaf_size(leafsize, sectorsize))
exit(1);
if (btrfs_check_node_or_leaf_size(nodesize, sectorsize))
if (btrfs_check_nodesize(nodesize, sectorsize))
exit(1);
saved_optind = optind;
dev_cnt = ac - optind;
@ -1405,7 +1403,7 @@ int main(int ac, char **av)
BTRFS_BLOCK_GROUP_RAID0 : 0; /* raid0 or single */
}
} else {
u32 best_leafsize = max_t(u32, sysconf(_SC_PAGESIZE), sectorsize);
u32 best_nodesize = max_t(u32, sysconf(_SC_PAGESIZE), sectorsize);
if (metadata_profile_opt || data_profile_opt) {
if (metadata_profile != data_profile) {
@ -1415,34 +1413,33 @@ int main(int ac, char **av)
}
}
if (!leaf_forced) {
leafsize = best_leafsize;
nodesize = best_leafsize;
if (btrfs_check_node_or_leaf_size(leafsize, sectorsize))
if (!nodesize_forced) {
nodesize = best_nodesize;
if (btrfs_check_nodesize(nodesize, sectorsize))
exit(1);
}
if (leafsize != sectorsize) {
if (nodesize != sectorsize) {
fprintf(stderr, "Error: mixed metadata/data block groups "
"require metadata blocksizes equal to the sectorsize\n");
exit(1);
}
}
/* Check device/block_count after the leafsize is determined */
if (block_count && block_count < btrfs_min_dev_size(leafsize)) {
/* Check device/block_count after the nodesize is determined */
if (block_count && block_count < btrfs_min_dev_size(nodesize)) {
fprintf(stderr,
"Size '%llu' is too small to make a usable filesystem\n",
block_count);
fprintf(stderr,
"Minimum size for btrfs filesystem is %llu\n",
btrfs_min_dev_size(leafsize));
btrfs_min_dev_size(nodesize));
exit(1);
}
for (i = saved_optind; i < saved_optind + dev_cnt; i++) {
char *path;
path = av[i];
ret = test_minimum_size(path, leafsize);
ret = test_minimum_size(path, nodesize);
if (ret < 0) {
fprintf(stderr, "Failed to check size for '%s': %s\n",
path, strerror(-ret));
@ -1454,7 +1451,7 @@ int main(int ac, char **av)
path);
fprintf(stderr,
"Minimum size for each btrfs device is %llu.\n",
btrfs_min_dev_size(leafsize));
btrfs_min_dev_size(nodesize));
exit(1);
}
}
@ -1524,7 +1521,7 @@ int main(int ac, char **av)
blocks[0] = BTRFS_SUPER_INFO_OFFSET;
for (i = 1; i < 7; i++) {
blocks[i] = BTRFS_SUPER_INFO_OFFSET + 1024 * 1024 +
leafsize * i;
nodesize * i;
}
/*
@ -1542,8 +1539,7 @@ int main(int ac, char **av)
process_fs_features(features);
ret = make_btrfs(fd, file, label, fs_uuid, blocks, dev_block_count,
nodesize, leafsize,
sectorsize, stripesize, features);
nodesize, sectorsize, stripesize, features);
if (ret) {
fprintf(stderr, "error during mkfs: %s\n", strerror(-ret));
exit(1);
@ -1621,7 +1617,7 @@ raid_groups:
printf("fs created label %s on %s\n\tnodesize %u leafsize %u "
"sectorsize %u size %s\n",
label, first_file, nodesize, leafsize, sectorsize,
label, first_file, nodesize, nodesize, sectorsize,
pretty_size(btrfs_super_total_bytes(root->fs_info->super_copy)));
btrfs_commit_transaction(trans, root);

96
utils.c
View File

@ -171,7 +171,7 @@ int test_uuid_unique(char *fs_uuid)
int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
u64 blocks[7], u64 num_bytes, u32 nodesize,
u32 leafsize, u32 sectorsize, u32 stripesize, u64 features)
u32 sectorsize, u32 stripesize, u64 features)
{
struct btrfs_super_block super;
struct extent_buffer *buf = NULL;
@ -225,9 +225,9 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
btrfs_set_super_root(&super, blocks[1]);
btrfs_set_super_chunk_root(&super, blocks[3]);
btrfs_set_super_total_bytes(&super, num_bytes);
btrfs_set_super_bytes_used(&super, 6 * leafsize);
btrfs_set_super_bytes_used(&super, 6 * nodesize);
btrfs_set_super_sectorsize(&super, sectorsize);
btrfs_set_super_leafsize(&super, leafsize);
btrfs_set_super_leafsize(&super, nodesize);
btrfs_set_super_nodesize(&super, nodesize);
btrfs_set_super_stripesize(&super, stripesize);
btrfs_set_super_csum_type(&super, BTRFS_CSUM_TYPE_CRC32);
@ -237,11 +237,11 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
if (label)
strncpy(super.label, label, BTRFS_LABEL_SIZE - 1);
buf = malloc(sizeof(*buf) + max(sectorsize, leafsize));
buf = malloc(sizeof(*buf) + max(sectorsize, nodesize));
/* create the tree of root objects */
memset(buf->data, 0, leafsize);
buf->len = leafsize;
memset(buf->data, 0, nodesize);
buf->len = nodesize;
btrfs_set_header_bytenr(buf, blocks[1]);
btrfs_set_header_nritems(buf, 4);
btrfs_set_header_generation(buf, 1);
@ -260,10 +260,10 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
btrfs_set_stack_inode_generation(inode_item, 1);
btrfs_set_stack_inode_size(inode_item, 3);
btrfs_set_stack_inode_nlink(inode_item, 1);
btrfs_set_stack_inode_nbytes(inode_item, leafsize);
btrfs_set_stack_inode_nbytes(inode_item, nodesize);
btrfs_set_stack_inode_mode(inode_item, S_IFDIR | 0755);
btrfs_set_root_refs(&root_item, 1);
btrfs_set_root_used(&root_item, leafsize);
btrfs_set_root_used(&root_item, nodesize);
btrfs_set_root_generation(&root_item, 1);
memset(&disk_key, 0, sizeof(disk_key));
@ -271,7 +271,7 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
btrfs_set_disk_key_offset(&disk_key, 0);
nritems = 0;
itemoff = __BTRFS_LEAF_DATA_SIZE(leafsize) - sizeof(root_item);
itemoff = __BTRFS_LEAF_DATA_SIZE(nodesize) - sizeof(root_item);
btrfs_set_root_bytenr(&root_item, blocks[2]);
btrfs_set_disk_key_objectid(&disk_key, BTRFS_EXTENT_TREE_OBJECTID);
btrfs_set_item_key(buf, &disk_key, nritems);
@ -320,17 +320,17 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
ret = pwrite(fd, buf->data, leafsize, blocks[1]);
if (ret != leafsize) {
ret = pwrite(fd, buf->data, nodesize, blocks[1]);
if (ret != nodesize) {
ret = (ret < 0 ? -errno : -EIO);
goto out;
}
/* create the items for the extent tree */
memset(buf->data+sizeof(struct btrfs_header), 0,
leafsize-sizeof(struct btrfs_header));
memset(buf->data + sizeof(struct btrfs_header), 0,
nodesize - sizeof(struct btrfs_header));
nritems = 0;
itemoff = __BTRFS_LEAF_DATA_SIZE(leafsize);
itemoff = __BTRFS_LEAF_DATA_SIZE(nodesize);
for (i = 1; i < 7; i++) {
item_size = sizeof(struct btrfs_extent_item);
if (!skinny_metadata)
@ -349,7 +349,7 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
} else {
btrfs_set_disk_key_type(&disk_key,
BTRFS_EXTENT_ITEM_KEY);
btrfs_set_disk_key_offset(&disk_key, leafsize);
btrfs_set_disk_key_offset(&disk_key, nodesize);
}
btrfs_set_item_key(buf, &disk_key, nritems);
btrfs_set_item_offset(buf, btrfs_item_nr(nritems),
@ -379,18 +379,18 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
btrfs_set_header_owner(buf, BTRFS_EXTENT_TREE_OBJECTID);
btrfs_set_header_nritems(buf, nritems);
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
ret = pwrite(fd, buf->data, leafsize, blocks[2]);
if (ret != leafsize) {
ret = pwrite(fd, buf->data, nodesize, blocks[2]);
if (ret != nodesize) {
ret = (ret < 0 ? -errno : -EIO);
goto out;
}
/* create the chunk tree */
memset(buf->data+sizeof(struct btrfs_header), 0,
leafsize-sizeof(struct btrfs_header));
memset(buf->data + sizeof(struct btrfs_header), 0,
nodesize - sizeof(struct btrfs_header));
nritems = 0;
item_size = sizeof(*dev_item);
itemoff = __BTRFS_LEAF_DATA_SIZE(leafsize) - item_size;
itemoff = __BTRFS_LEAF_DATA_SIZE(nodesize) - item_size;
/* first device 1 (there is no device 0) */
btrfs_set_disk_key_objectid(&disk_key, BTRFS_DEV_ITEMS_OBJECTID);
@ -466,17 +466,17 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
btrfs_set_header_owner(buf, BTRFS_CHUNK_TREE_OBJECTID);
btrfs_set_header_nritems(buf, nritems);
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
ret = pwrite(fd, buf->data, leafsize, blocks[3]);
if (ret != leafsize) {
ret = pwrite(fd, buf->data, nodesize, blocks[3]);
if (ret != nodesize) {
ret = (ret < 0 ? -errno : -EIO);
goto out;
}
/* create the device tree */
memset(buf->data+sizeof(struct btrfs_header), 0,
leafsize-sizeof(struct btrfs_header));
memset(buf->data + sizeof(struct btrfs_header), 0,
nodesize - sizeof(struct btrfs_header));
nritems = 0;
itemoff = __BTRFS_LEAF_DATA_SIZE(leafsize) -
itemoff = __BTRFS_LEAF_DATA_SIZE(nodesize) -
sizeof(struct btrfs_dev_extent);
btrfs_set_disk_key_objectid(&disk_key, 1);
@ -505,33 +505,33 @@ int make_btrfs(int fd, const char *device, const char *label, char *fs_uuid,
btrfs_set_header_owner(buf, BTRFS_DEV_TREE_OBJECTID);
btrfs_set_header_nritems(buf, nritems);
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
ret = pwrite(fd, buf->data, leafsize, blocks[4]);
if (ret != leafsize) {
ret = pwrite(fd, buf->data, nodesize, blocks[4]);
if (ret != nodesize) {
ret = (ret < 0 ? -errno : -EIO);
goto out;
}
/* create the FS root */
memset(buf->data+sizeof(struct btrfs_header), 0,
leafsize-sizeof(struct btrfs_header));
memset(buf->data + sizeof(struct btrfs_header), 0,
nodesize - sizeof(struct btrfs_header));
btrfs_set_header_bytenr(buf, blocks[5]);
btrfs_set_header_owner(buf, BTRFS_FS_TREE_OBJECTID);
btrfs_set_header_nritems(buf, 0);
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
ret = pwrite(fd, buf->data, leafsize, blocks[5]);
if (ret != leafsize) {
ret = pwrite(fd, buf->data, nodesize, blocks[5]);
if (ret != nodesize) {
ret = (ret < 0 ? -errno : -EIO);
goto out;
}
/* finally create the csum root */
memset(buf->data+sizeof(struct btrfs_header), 0,
leafsize-sizeof(struct btrfs_header));
memset(buf->data + sizeof(struct btrfs_header), 0,
nodesize - sizeof(struct btrfs_header));
btrfs_set_header_bytenr(buf, blocks[6]);
btrfs_set_header_owner(buf, BTRFS_CSUM_TREE_OBJECTID);
btrfs_set_header_nritems(buf, 0);
csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
ret = pwrite(fd, buf->data, leafsize, blocks[6]);
if (ret != leafsize) {
ret = pwrite(fd, buf->data, nodesize, blocks[6]);
if (ret != nodesize) {
ret = (ret < 0 ? -errno : -EIO);
goto out;
}
@ -783,7 +783,7 @@ int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
btrfs_set_stack_inode_generation(&inode_item, trans->transid);
btrfs_set_stack_inode_size(&inode_item, 0);
btrfs_set_stack_inode_nlink(&inode_item, 1);
btrfs_set_stack_inode_nbytes(&inode_item, root->leafsize);
btrfs_set_stack_inode_nbytes(&inode_item, root->nodesize);
btrfs_set_stack_inode_mode(&inode_item, S_IFDIR | 0755);
btrfs_set_stack_timespec_sec(&inode_item.atime, now);
btrfs_set_stack_timespec_nsec(&inode_item.atime, 0);
@ -2594,7 +2594,7 @@ int find_mount_root(const char *path, char **mount_root)
return ret;
}
int test_minimum_size(const char *file, u32 leafsize)
int test_minimum_size(const char *file, u32 nodesize)
{
int fd;
struct stat statbuf;
@ -2606,7 +2606,7 @@ int test_minimum_size(const char *file, u32 leafsize)
close(fd);
return -errno;
}
if (btrfs_device_size(fd, &statbuf) < btrfs_min_dev_size(leafsize)) {
if (btrfs_device_size(fd, &statbuf) < btrfs_min_dev_size(nodesize)) {
close(fd);
return 1;
}
@ -2789,22 +2789,22 @@ int btrfs_tree_search2_ioctl_supported(int fd)
return v2_supported;
}
int btrfs_check_node_or_leaf_size(u32 size, u32 sectorsize)
int btrfs_check_nodesize(u32 nodesize, u32 sectorsize)
{
if (size < sectorsize) {
if (nodesize < sectorsize) {
fprintf(stderr,
"ERROR: Illegal nodesize (or leafsize) %u (smaller than %u)\n",
size, sectorsize);
"ERROR: Illegal nodesize %u (smaller than %u)\n",
nodesize, sectorsize);
return -1;
} else if (size > BTRFS_MAX_METADATA_BLOCKSIZE) {
} else if (nodesize > BTRFS_MAX_METADATA_BLOCKSIZE) {
fprintf(stderr,
"ERROR: Illegal nodesize (or leafsize) %u (larger than %u)\n",
size, BTRFS_MAX_METADATA_BLOCKSIZE);
"ERROR: Illegal nodesize %u (larger than %u)\n",
nodesize, BTRFS_MAX_METADATA_BLOCKSIZE);
return -1;
} else if (size & (sectorsize - 1)) {
} else if (nodesize & (sectorsize - 1)) {
fprintf(stderr,
"ERROR: Illegal nodesize (or leafsize) %u (not aligned to %u)\n",
size, sectorsize);
"ERROR: Illegal nodesize %u (not aligned to %u)\n",
nodesize, sectorsize);
return -1;
}
return 0;

View File

@ -82,7 +82,7 @@ void units_set_base(unsigned *units, unsigned base);
int make_btrfs(int fd, const char *device, const char *label,
char *fs_uuid, u64 blocks[6], u64 num_bytes, u32 nodesize,
u32 leafsize, u32 sectorsize, u32 stripesize, u64 features);
u32 sectorsize, u32 stripesize, u64 features);
int btrfs_make_root_dir(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid);
int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
@ -210,6 +210,6 @@ static inline u64 div_factor(u64 num, int factor)
}
int btrfs_tree_search2_ioctl_supported(int fd);
int btrfs_check_node_or_leaf_size(u32 size, u32 sectorsize);
int btrfs_check_nodesize(u32 nodesize, u32 sectorsize);
#endif