diff options
author | Qu Wenruo <wqu@suse.com> | 2017-10-19 17:13:55 +0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2018-01-08 18:15:15 +0100 |
commit | 1c9c5f7fb3f6a2182d230d469b22b3b1329f24d8 (patch) | |
tree | 7bdd2d05a882a68d1883e16d2970f17152f2cff9 /mkfs/main.c | |
parent | c28418daed603d4943edc8b213b91f8d1e2b9fe3 (diff) |
btrfs-progs: mkfs: Separate shrink from rootdir
Make --shrink a separate option for --rootdir, and change the default to
off.
The shrinking behaviour is not a commonly used feature but can be useful
for creating minimal pre-filled images, in one step, without requiring
to mount.
Signed-off-by: Qu Wenruo <wqu@suse.com>
[ update changelog and error messages ]
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'mkfs/main.c')
-rw-r--r-- | mkfs/main.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/mkfs/main.c b/mkfs/main.c index e9136b10..16254ee9 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -731,9 +731,11 @@ int main(int argc, char **argv) int ssd = 0; int force_overwrite = 0; char *source_dir = NULL; - int source_dir_set = 0; + bool source_dir_set = false; + bool shrink_rootdir = false; u64 source_dir_size = 0; u64 min_dev_size; + u64 shrink_size; int dev_cnt = 0; int saved_optind; char fs_uuid[BTRFS_UUID_UNPARSED_SIZE] = { 0 }; @@ -743,6 +745,7 @@ int main(int argc, char **argv) while(1) { int c; + enum { GETOPT_VAL_SHRINK = 257 }; static const struct option long_options[] = { { "alloc-start", required_argument, NULL, 'A'}, { "byte-count", required_argument, NULL, 'b' }, @@ -760,6 +763,7 @@ int main(int argc, char **argv) { "features", required_argument, NULL, 'O' }, { "uuid", required_argument, NULL, 'U' }, { "quiet", 0, NULL, 'q' }, + { "shrink", no_argument, NULL, GETOPT_VAL_SHRINK }, { "help", no_argument, NULL, GETOPT_VAL_HELP }, { NULL, 0, NULL, 0} }; @@ -827,7 +831,7 @@ int main(int argc, char **argv) goto success; case 'r': source_dir = optarg; - source_dir_set = 1; + source_dir_set = true; break; case 'U': strncpy(fs_uuid, optarg, @@ -839,6 +843,9 @@ int main(int argc, char **argv) case 'q': verbose = 0; break; + case GETOPT_VAL_SHRINK: + shrink_rootdir = true; + break; case GETOPT_VAL_HELP: default: print_usage(c != GETOPT_VAL_HELP); @@ -861,6 +868,10 @@ int main(int argc, char **argv) error("the option -r is limited to a single device"); goto error; } + if (shrink_rootdir && !source_dir_set) { + error("the option --shrink must be used with --rootdir"); + goto error; + } if (*fs_uuid) { uuid_t dummy_uuid; @@ -1189,10 +1200,14 @@ raid_groups: error("error wihle filling filesystem: %d", ret); goto out; } - ret = btrfs_mkfs_shrink_fs(fs_info, NULL); - if (ret < 0) { - error("error while shrinking filesystem: %d", ret); - goto out; + if (shrink_rootdir) { + ret = btrfs_mkfs_shrink_fs(fs_info, &shrink_size, + shrink_rootdir); + if (ret < 0) { + error("error while shrinking filesystem: %d", + ret); + goto out; + } } } |