forked from Mirrors/btrfs-progs
btrfs-progs: btrfstune: rework option handling
Simplify the code, gather the incompat flag bits and set them at once. Signed-off-by: David Sterba <dsterba@suse.cz>master
parent
d020af5235
commit
c476696b82
53
btrfstune.c
53
btrfstune.c
|
@ -40,6 +40,7 @@ static int update_seeding_flag(struct btrfs_root *root, int set_flag)
|
||||||
struct btrfs_trans_handle *trans;
|
struct btrfs_trans_handle *trans;
|
||||||
struct btrfs_super_block *disk_super;
|
struct btrfs_super_block *disk_super;
|
||||||
u64 super_flags;
|
u64 super_flags;
|
||||||
|
int ret;
|
||||||
|
|
||||||
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);
|
||||||
|
@ -64,41 +65,26 @@ static int update_seeding_flag(struct btrfs_root *root, int set_flag)
|
||||||
|
|
||||||
trans = btrfs_start_transaction(root, 1);
|
trans = btrfs_start_transaction(root, 1);
|
||||||
btrfs_set_super_flags(disk_super, super_flags);
|
btrfs_set_super_flags(disk_super, super_flags);
|
||||||
btrfs_commit_transaction(trans, root);
|
ret = btrfs_commit_transaction(trans, root);
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int enable_extrefs_flag(struct btrfs_root *root)
|
static int set_super_incompat_flags(struct btrfs_root *root, u64 flags)
|
||||||
{
|
{
|
||||||
struct btrfs_trans_handle *trans;
|
struct btrfs_trans_handle *trans;
|
||||||
struct btrfs_super_block *disk_super;
|
struct btrfs_super_block *disk_super;
|
||||||
u64 super_flags;
|
u64 super_flags;
|
||||||
|
int ret;
|
||||||
|
|
||||||
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 |= flags;
|
||||||
trans = btrfs_start_transaction(root, 1);
|
trans = btrfs_start_transaction(root, 1);
|
||||||
btrfs_set_super_incompat_flags(disk_super, super_flags);
|
btrfs_set_super_incompat_flags(disk_super, super_flags);
|
||||||
btrfs_commit_transaction(trans, root);
|
ret = btrfs_commit_transaction(trans, root);
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
|
||||||
|
|
||||||
static int enable_skinny_metadata(struct btrfs_root *root)
|
|
||||||
{
|
|
||||||
struct btrfs_trans_handle *trans;
|
|
||||||
struct btrfs_super_block *disk_super;
|
|
||||||
u64 super_flags;
|
|
||||||
|
|
||||||
disk_super = root->fs_info->super_copy;
|
|
||||||
super_flags = btrfs_super_incompat_flags(disk_super);
|
|
||||||
super_flags |= BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA;
|
|
||||||
trans = btrfs_start_transaction(root, 1);
|
|
||||||
btrfs_set_super_incompat_flags(disk_super, super_flags);
|
|
||||||
btrfs_commit_transaction(trans, root);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int change_header_uuid(struct btrfs_root *root, struct extent_buffer *eb)
|
static int change_header_uuid(struct btrfs_root *root, struct extent_buffer *eb)
|
||||||
|
@ -417,13 +403,12 @@ int main(int argc, char *argv[])
|
||||||
enum btrfs_open_ctree_flags ctree_flags = OPEN_CTREE_WRITES;
|
enum btrfs_open_ctree_flags ctree_flags = OPEN_CTREE_WRITES;
|
||||||
int success = 0;
|
int success = 0;
|
||||||
int total = 0;
|
int total = 0;
|
||||||
int extrefs_flag = 0;
|
|
||||||
int seeding_flag = 0;
|
int seeding_flag = 0;
|
||||||
u64 seeding_value = 0;
|
u64 seeding_value = 0;
|
||||||
int skinny_flag = 0;
|
|
||||||
int random_fsid = 0;
|
int random_fsid = 0;
|
||||||
char *new_fsid_str = NULL;
|
char *new_fsid_str = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
u64 super_flags = 0;
|
||||||
|
|
||||||
optind = 1;
|
optind = 1;
|
||||||
while(1) {
|
while(1) {
|
||||||
|
@ -436,10 +421,10 @@ int main(int argc, char *argv[])
|
||||||
seeding_value = arg_strtou64(optarg);
|
seeding_value = arg_strtou64(optarg);
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
extrefs_flag = 1;
|
super_flags |= BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF;
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
skinny_flag = 1;
|
super_flags |= BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
force = 1;
|
force = 1;
|
||||||
|
@ -471,8 +456,7 @@ int main(int argc, char *argv[])
|
||||||
"ERROR: Random fsid can't be used with specified fsid\n");
|
"ERROR: Random fsid can't be used with specified fsid\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!(seeding_flag + extrefs_flag + skinny_flag) &&
|
if (!super_flags && !seeding_flag && !(random_fsid || new_fsid_str)) {
|
||||||
!(random_fsid || new_fsid_str)) {
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ERROR: At least one option should be assigned.\n");
|
"ERROR: At least one option should be assigned.\n");
|
||||||
print_usage();
|
print_usage();
|
||||||
|
@ -531,15 +515,10 @@ int main(int argc, char *argv[])
|
||||||
total++;
|
total++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extrefs_flag) {
|
if (super_flags) {
|
||||||
enable_extrefs_flag(root);
|
ret = set_super_incompat_flags(root, super_flags);
|
||||||
success++;
|
if (!ret)
|
||||||
total++;
|
success++;
|
||||||
}
|
|
||||||
|
|
||||||
if (skinny_flag) {
|
|
||||||
enable_skinny_metadata(root);
|
|
||||||
success++;
|
|
||||||
total++;
|
total++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue