diff mbox series

[v2,08/11] btrfs-progs: add option for checksum type to mkfs

Message ID 20190826114853.14860-9-jthumshirn@suse.de (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: support xxhash64 checksums | expand

Commit Message

Johannes Thumshirn Aug. 26, 2019, 11:48 a.m. UTC
Add an option to mkfs to specify which checksum algorithm will be used for
the filesystem.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 convert/common.c |  2 +-
 mkfs/common.c    |  2 +-
 mkfs/common.h    |  2 ++
 mkfs/main.c      | 21 ++++++++++++++++++++-
 4 files changed, 24 insertions(+), 3 deletions(-)

Comments

Nikolay Borisov Aug. 27, 2019, 1:03 p.m. UTC | #1
On 26.08.19 г. 14:48 ч., Johannes Thumshirn wrote:
> Add an option to mkfs to specify which checksum algorithm will be used for
> the filesystem.
> 
> Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
>  convert/common.c |  2 +-
>  mkfs/common.c    |  2 +-
>  mkfs/common.h    |  2 ++
>  mkfs/main.c      | 21 ++++++++++++++++++++-
>  4 files changed, 24 insertions(+), 3 deletions(-)
> 
> diff --git a/convert/common.c b/convert/common.c
> index 7936f8f10b29..8f5fdbf507a4 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 9762391a8d2b..4a417bd7a306 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/common.h b/mkfs/common.h
> index 28912906d0a9..1ca71a4fcce5 100644
> --- a/mkfs/common.h
> +++ b/mkfs/common.h
> @@ -53,6 +53,8 @@ struct btrfs_mkfs_config {
>  	u64 features;
>  	/* Size of the filesystem in bytes */
>  	u64 num_bytes;
> +	/* checksum algorithm to use */
> +	enum btrfs_csum_type csum_type;
>  
>  	/* Output fields, set during creation */
>  
> diff --git a/mkfs/main.c b/mkfs/main.c
> index 8dbec0717b89..075e7e331ab4 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -346,6 +346,7 @@ static void print_usage(int ret)
>  	printf("\t--shrink                (with --rootdir) shrink the filled filesystem to minimal size\n");
>  	printf("\t-K|--nodiscard          do not perform whole device TRIM\n");
>  	printf("\t-f|--force              force overwrite of existing filesystem\n");
> +	printf("\t-C|--checksum           checksum algorithm to use (default: crc32c)\n");
>  	printf("  general:\n");
>  	printf("\t-q|--quiet              no messages except errors\n");
>  	printf("\t-V|--version            print the mkfs.btrfs version and exit\n");
> @@ -380,6 +381,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);
> @@ -826,6 +839,7 @@ 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();
>  
> @@ -835,6 +849,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
>  		static const struct option long_options[] = {
>  			{ "alloc-start", required_argument, NULL, 'A'},
>  			{ "byte-count", required_argument, NULL, 'b' },
> +			{ "checksum", required_argument, NULL, 'C' },
>  			{ "force", no_argument, NULL, 'f' },
>  			{ "leafsize", required_argument, NULL, 'l' },
>  			{ "label", required_argument, NULL, 'L'},
> @@ -854,7 +869,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
>  			{ NULL, 0, NULL, 0}
>  		};
>  
> -		c = getopt_long(argc, argv, "A:b:fl:n:s:m:d:L:O:r:U:VMKq",
> +		c = getopt_long(argc, argv, "A:b:C:fl:n:s:m:d:L:O:r:U:VMKq",
>  				long_options, NULL);
>  		if (c < 0)
>  			break;
> @@ -932,6 +947,9 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
>  			case GETOPT_VAL_SHRINK:
>  				shrink_rootdir = true;
>  				break;
> +			case 'C':
> +				csum_type = parse_csum_type(optarg);
> +				break;
>  			case GETOPT_VAL_HELP:
>  			default:
>  				print_usage(c != GETOPT_VAL_HELP);
> @@ -1170,6 +1188,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) {
>
diff mbox series

Patch

diff --git a/convert/common.c b/convert/common.c
index 7936f8f10b29..8f5fdbf507a4 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 9762391a8d2b..4a417bd7a306 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/common.h b/mkfs/common.h
index 28912906d0a9..1ca71a4fcce5 100644
--- a/mkfs/common.h
+++ b/mkfs/common.h
@@ -53,6 +53,8 @@  struct btrfs_mkfs_config {
 	u64 features;
 	/* Size of the filesystem in bytes */
 	u64 num_bytes;
+	/* checksum algorithm to use */
+	enum btrfs_csum_type csum_type;
 
 	/* Output fields, set during creation */
 
diff --git a/mkfs/main.c b/mkfs/main.c
index 8dbec0717b89..075e7e331ab4 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -346,6 +346,7 @@  static void print_usage(int ret)
 	printf("\t--shrink                (with --rootdir) shrink the filled filesystem to minimal size\n");
 	printf("\t-K|--nodiscard          do not perform whole device TRIM\n");
 	printf("\t-f|--force              force overwrite of existing filesystem\n");
+	printf("\t-C|--checksum           checksum algorithm to use (default: crc32c)\n");
 	printf("  general:\n");
 	printf("\t-q|--quiet              no messages except errors\n");
 	printf("\t-V|--version            print the mkfs.btrfs version and exit\n");
@@ -380,6 +381,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);
@@ -826,6 +839,7 @@  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();
 
@@ -835,6 +849,7 @@  int BOX_MAIN(mkfs)(int argc, char **argv)
 		static const struct option long_options[] = {
 			{ "alloc-start", required_argument, NULL, 'A'},
 			{ "byte-count", required_argument, NULL, 'b' },
+			{ "checksum", required_argument, NULL, 'C' },
 			{ "force", no_argument, NULL, 'f' },
 			{ "leafsize", required_argument, NULL, 'l' },
 			{ "label", required_argument, NULL, 'L'},
@@ -854,7 +869,7 @@  int BOX_MAIN(mkfs)(int argc, char **argv)
 			{ NULL, 0, NULL, 0}
 		};
 
-		c = getopt_long(argc, argv, "A:b:fl:n:s:m:d:L:O:r:U:VMKq",
+		c = getopt_long(argc, argv, "A:b:C:fl:n:s:m:d:L:O:r:U:VMKq",
 				long_options, NULL);
 		if (c < 0)
 			break;
@@ -932,6 +947,9 @@  int BOX_MAIN(mkfs)(int argc, char **argv)
 			case GETOPT_VAL_SHRINK:
 				shrink_rootdir = true;
 				break;
+			case 'C':
+				csum_type = parse_csum_type(optarg);
+				break;
 			case GETOPT_VAL_HELP:
 			default:
 				print_usage(c != GETOPT_VAL_HELP);
@@ -1170,6 +1188,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) {