BTRFS_BLOCK_GROUP_DATA);
if (ret == -ENOSPC) {
fprintf(stderr,
- "no space to alloc data/metadata chunk\n");
+ "no space to allocate data/metadata chunk\n");
goto err;
}
BUG_ON(ret);
&chunk_start, &chunk_size,
BTRFS_BLOCK_GROUP_METADATA);
if (ret == -ENOSPC) {
- fprintf(stderr, "no space to alloc metadata chunk\n");
+ fprintf(stderr, "no space to allocate metadata chunk\n");
goto err;
}
BUG_ON(ret);
&chunk_start, &chunk_size,
BTRFS_BLOCK_GROUP_DATA);
if (ret == -ENOSPC) {
- fprintf(stderr, "no space to alloc data chunk\n");
+ fprintf(stderr, "no space to allocate data chunk\n");
goto err;
}
BUG_ON(ret);
u64 metadata_profile, int mixed,
struct mkfs_allocation *allocation)
{
- u64 num_devices = btrfs_super_num_devices(root->fs_info->super_copy);
int ret;
if (metadata_profile) {
BUG_ON(ret);
}
- if (!mixed && num_devices > 1 && data_profile) {
+ if (!mixed && data_profile) {
ret = create_one_raid_group(trans, root,
BTRFS_BLOCK_GROUP_DATA |
data_profile, allocation);
static u64 parse_profile(char *s)
{
- if (strcmp(s, "raid0") == 0) {
+ if (strcasecmp(s, "raid0") == 0) {
return BTRFS_BLOCK_GROUP_RAID0;
} else if (strcasecmp(s, "raid1") == 0) {
return BTRFS_BLOCK_GROUP_RAID1;
u64 objectid, const char *path_name)
{
int ret;
- u64 sectorsize = root->sectorsize;
- char *buf = malloc(sectorsize);
+ char buf[PATH_MAX];
- ret = readlink(path_name, buf, sectorsize);
+ ret = readlink(path_name, buf, sizeof(buf));
if (ret <= 0) {
fprintf(stderr, "readlink failed for %s\n", path_name);
goto fail;
}
- if (ret >= sectorsize) {
+ if (ret >= sizeof(buf)) {
fprintf(stderr, "symlink too long for %s\n", path_name);
ret = -1;
goto fail;
ret = btrfs_insert_inline_extent(trans, root, objectid, 0,
buf, ret + 1);
fail:
- free(buf);
return ret;
}
size_of_data = minimum_data_chunk_size;
ret = btrfs_alloc_data_chunk(trans, root->fs_info->extent_root,
- &chunk_start, size_of_data, data_type);
+ &chunk_start, size_of_data, data_type, 0);
BUG_ON(ret);
ret = btrfs_make_block_group(trans, root->fs_info->extent_root, 0,
data_type, BTRFS_FIRST_CHUNK_TREE_OBJECTID,
* This ignores symlinks with unreadable targets and subdirs that can't
* be read. It's a best-effort to give a rough estimate of the size of
* a subdir. It doesn't guarantee that prepopulating btrfs from this
- * tree won't still run out of space.
- *
- * The rounding up to 4096 is questionable. Previous code used du -B 4096.
+ * tree won't still run out of space.
*/
static u64 global_total_size;
+static u64 fs_block_size;
static int ftw_add_entry_size(const char *fpath, const struct stat *st,
int type)
{
if (type == FTW_F || type == FTW_D)
- global_total_size += round_up(st->st_size, 4096);
+ global_total_size += round_up(st->st_size, fs_block_size);
return 0;
}
allocated_meta_size / default_chunk_size;
global_total_size = 0;
+ fs_block_size = sectorsize;
ret = ftw(dir_name, ftw_add_entry_size, 10);
dir_size = global_total_size;
if (ret < 0) {
return total_size;
}
-static int zero_output_file(int out_fd, u64 size, u32 sectorsize)
+static int zero_output_file(int out_fd, u64 size)
{
int loop_num;
u64 location = 0;
static int is_ssd(const char *file)
{
blkid_probe probe;
- char wholedisk[32];
+ char wholedisk[PATH_MAX];
char sysfs_path[PATH_MAX];
dev_t devno;
int fd;
* 1) Empty chunk
* Temp chunk is always empty.
*
- * 2) profile dismatch with mkfs profile.
+ * 2) profile mismatch with mkfs profile.
* Temp chunk is always in SINGLE
*
* 3) Size differs with mkfs_alloc
if (is_temp_block_group(path->nodes[0], bgi,
data_profile, meta_profile,
sys_profile)) {
+ u64 flags = btrfs_disk_block_group_flags(path->nodes[0],
+ bgi);
+
ret = btrfs_free_block_group(trans, fs_info,
found_key.objectid, found_key.offset);
if (ret < 0)
goto out;
+
+ if ((flags & BTRFS_BLOCK_GROUP_TYPE_MASK) ==
+ BTRFS_BLOCK_GROUP_DATA)
+ alloc->data -= found_key.offset;
+ else if ((flags & BTRFS_BLOCK_GROUP_TYPE_MASK) ==
+ BTRFS_BLOCK_GROUP_METADATA)
+ alloc->metadata -= found_key.offset;
+ else if ((flags & BTRFS_BLOCK_GROUP_TYPE_MASK) ==
+ BTRFS_BLOCK_GROUP_SYSTEM)
+ alloc->system -= found_key.offset;
+ else if ((flags & BTRFS_BLOCK_GROUP_TYPE_MASK) ==
+ (BTRFS_BLOCK_GROUP_METADATA |
+ BTRFS_BLOCK_GROUP_DATA))
+ alloc->mixed -= found_key.offset;
}
btrfs_release_path(path);
key.objectid = found_key.objectid + found_key.offset;
return ret;
}
-int main(int ac, char **av)
+int main(int argc, char **argv)
{
char *file;
struct btrfs_root *root;
{ NULL, 0, NULL, 0}
};
- c = getopt_long(ac, av, "A:b:fl:n:s:m:d:L:O:r:U:VMKq",
+ c = getopt_long(argc, argv, "A:b:fl:n:s:m:d:L:O:r:U:VMKq",
long_options, NULL);
if (c < 0)
break;
}
sectorsize = max(sectorsize, (u32)sysconf(_SC_PAGESIZE));
+ stripesize = sectorsize;
saved_optind = optind;
- dev_cnt = ac - optind;
+ dev_cnt = argc - optind;
if (dev_cnt == 0)
print_usage(1);
}
while (dev_cnt-- > 0) {
- file = av[optind++];
+ file = argv[optind++];
if (is_block_device(file) == 1)
if (test_dev_for_mkfs(file, force_overwrite))
exit(1);
}
optind = saved_optind;
- dev_cnt = ac - optind;
+ dev_cnt = argc - optind;
- file = av[optind++];
+ file = argv[optind++];
ssd = is_ssd(file);
/*
for (i = saved_optind; i < saved_optind + dev_cnt; i++) {
char *path;
- path = av[i];
+ path = argv[i];
ret = test_minimum_size(path, nodesize);
if (ret < 0) {
fprintf(stderr, "Failed to check size for '%s': %s\n",
}
}
ret = test_num_disk_vs_raid(metadata_profile, data_profile,
- dev_cnt, mixed);
+ dev_cnt, mixed, ssd);
if (ret)
exit(1);
strerror(errno));
exit(1);
}
- ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count,
- block_count, discard);
+ ret = btrfs_prepare_device(fd, file, &dev_block_count,
+ block_count,
+ (zero_end ? PREP_DEVICE_ZERO_END : 0) |
+ (discard ? PREP_DEVICE_DISCARD : 0) |
+ (verbose ? PREP_DEVICE_VERBOSE : 0));
if (ret) {
close(fd);
exit(1);
&num_of_meta_chunks, &size_of_data);
if(block_count < source_dir_size)
block_count = source_dir_size;
- ret = zero_output_file(fd, block_count, sectorsize);
+ ret = zero_output_file(fd, block_count);
if (ret) {
fprintf(stderr, "unable to zero the output file\n");
exit(1);
if (group_profile_max_safe_loss(metadata_profile) <
group_profile_max_safe_loss(data_profile)){
fprintf(stderr,
- "WARNING: metatdata has lower redundancy than data!\n\n");
+ "WARNING: metadata has lower redundancy than data!\n\n");
}
mkfs_cfg.label = label;
mkfs_cfg.stripesize = stripesize;
mkfs_cfg.features = features;
- ret = make_btrfs(fd, &mkfs_cfg);
+ ret = make_btrfs(fd, &mkfs_cfg, NULL);
if (ret) {
fprintf(stderr, "error during mkfs: %s\n", strerror(-ret));
exit(1);
goto raid_groups;
while (dev_cnt-- > 0) {
- file = av[optind++];
+ file = argv[optind++];
/*
* open without O_EXCL so that the problem should not
close(fd);
continue;
}
- ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count,
- block_count, discard);
+ ret = btrfs_prepare_device(fd, file, &dev_block_count,
+ block_count,
+ (verbose ? PREP_DEVICE_VERBOSE : 0) |
+ (zero_end ? PREP_DEVICE_ZERO_END : 0) |
+ (discard ? PREP_DEVICE_DISCARD : 0));
if (ret) {
close(fd);
exit(1);