From 56198f3a9df4ef413d15959a78c1d5ad30191739 Mon Sep 17 00:00:00 2001 From: Johannes Thumshirn Date: Tue, 3 Sep 2019 17:00:42 +0200 Subject: [PATCH] btrfs-progs: mkfs: new option to specify checksum type Add an option to mkfs to specify which checksum algorithm will be used for the filesystem. Currently only crc32c is supported. The option name is -c, presumably one of the comonly used options so it gets the lowercase option. Signed-off-by: Johannes Thumshirn Signed-off-by: David Sterba --- convert/common.c | 2 +- mkfs/common.c | 2 +- mkfs/main.c | 25 ++++++++++++++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/convert/common.c b/convert/common.c index 8cae507e..2e2318a5 100644 --- a/convert/common.c +++ b/convert/common.c @@ -135,7 +135,7 @@ static int setup_temp_super(int fd, struct btrfs_mkfs_config *cfg, super->__unused_leafsize = cpu_to_le32(cfg->nodesize); btrfs_set_super_nodesize(super, cfg->nodesize); btrfs_set_super_stripesize(super, cfg->stripesize); - btrfs_set_super_csum_type(super, BTRFS_CSUM_TYPE_CRC32); + btrfs_set_super_csum_type(super, cfg->csum_type); btrfs_set_super_chunk_root(super, chunk_bytenr); btrfs_set_super_cache_generation(super, -1); btrfs_set_super_incompat_flags(super, cfg->features); diff --git a/mkfs/common.c b/mkfs/common.c index 9762391a..4a417bd7 100644 --- a/mkfs/common.c +++ b/mkfs/common.c @@ -202,7 +202,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg) super.__unused_leafsize = cpu_to_le32(cfg->nodesize); btrfs_set_super_nodesize(&super, cfg->nodesize); btrfs_set_super_stripesize(&super, cfg->stripesize); - btrfs_set_super_csum_type(&super, BTRFS_CSUM_TYPE_CRC32); + btrfs_set_super_csum_type(&super, cfg->csum_type); btrfs_set_super_chunk_root_generation(&super, 1); btrfs_set_super_cache_generation(&super, -1); btrfs_set_super_incompat_flags(&super, cfg->features); diff --git a/mkfs/main.c b/mkfs/main.c index aa13adea..11e4242f 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -341,6 +341,8 @@ static void print_usage(int ret) printf("\t-m|--metadata PROFILE metadata profile, values like for data profile\n"); printf("\t-M|--mixed mix metadata and data together\n"); printf(" features:\n"); + printf("\t--csum TYPE\n"); + printf("\t--checksum TYPE checksum algorithm to use (default: crc32c)\n"); printf("\t-n|--nodesize SIZE size of btree nodes\n"); printf("\t-s|--sectorsize SIZE data block size (may not be mountable by current kernel)\n"); printf("\t-O|--features LIST comma separated list of filesystem features (use '-O list-all' to list features)\n"); @@ -386,6 +388,18 @@ static u64 parse_profile(const char *s) return 0; } +static enum btrfs_csum_type parse_csum_type(const char *s) +{ + if (strcasecmp(s, "crc32c") == 0) { + return BTRFS_CSUM_TYPE_CRC32; + } else { + error("unknown csum type %s", s); + exit(1); + } + /* not reached */ + return 0; +} + static char *parse_label(const char *input) { int len = strlen(input); @@ -832,15 +846,20 @@ int BOX_MAIN(mkfs)(int argc, char **argv) u64 features = BTRFS_MKFS_DEFAULT_FEATURES; struct mkfs_allocation allocation = { 0 }; struct btrfs_mkfs_config mkfs_cfg; + enum btrfs_csum_type csum_type = BTRFS_CSUM_TYPE_CRC32; crc32c_optimization_init(); while(1) { int c; - enum { GETOPT_VAL_SHRINK = 257 }; + enum { GETOPT_VAL_SHRINK = 257, GETOPT_VAL_CHECKSUM }; static const struct option long_options[] = { { "alloc-start", required_argument, NULL, 'A'}, { "byte-count", required_argument, NULL, 'b' }, + { "csum", required_argument, NULL, + GETOPT_VAL_CHECKSUM }, + { "checksum", required_argument, NULL, + GETOPT_VAL_CHECKSUM }, { "force", no_argument, NULL, 'f' }, { "leafsize", required_argument, NULL, 'l' }, { "label", required_argument, NULL, 'L'}, @@ -938,6 +957,9 @@ int BOX_MAIN(mkfs)(int argc, char **argv) case GETOPT_VAL_SHRINK: shrink_rootdir = true; break; + case GETOPT_VAL_CHECKSUM: + csum_type = parse_csum_type(optarg); + break; case GETOPT_VAL_HELP: default: print_usage(c != GETOPT_VAL_HELP); @@ -1177,6 +1199,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) mkfs_cfg.sectorsize = sectorsize; mkfs_cfg.stripesize = stripesize; mkfs_cfg.features = features; + mkfs_cfg.csum_type = csum_type; ret = make_btrfs(fd, &mkfs_cfg); if (ret) {