summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-02-28 17:56:53 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2018-02-28 17:57:55 -0500
commit8a57b1f1d541d5fe9a0bfc665d6d3aeedd7ad355 (patch)
treed175bc1afff7c48972d4bd50d79146f3e2f2e6d4
parent1991277c8e723b018c90523949e8242692810911 (diff)
minor disk group fixes;, add background_compression option
-rw-r--r--cmd_format.c14
-rw-r--r--libbcachefs.c25
-rw-r--r--libbcachefs.h1
3 files changed, 24 insertions, 16 deletions
diff --git a/cmd_format.c b/cmd_format.c
index fff2d77..065efd9 100644
--- a/cmd_format.c
+++ b/cmd_format.c
@@ -30,19 +30,20 @@
#define OPTS \
t("bcachefs format - create a new bcachefs filesystem on one or more devices") \
-t("Usage: bcachefs format [OPTION]... <devices>") \
+t("Usage: bcachefs format [OPTION]... <devices>") \
t("") \
x('b', block_size, "size", NULL) \
x(0, btree_node_size, "size", "Default 256k") \
x(0, metadata_checksum_type, "(none|crc32c|crc64)", NULL) \
x(0, data_checksum_type, "(none|crc32c|crc64)", NULL) \
x(0, compression_type, "(none|lz4|gzip)", NULL) \
+x(0, background_compression_type, "(none|lz4|gzip)", NULL) \
x(0, replicas, "#", NULL) \
x(0, data_replicas, "#", NULL) \
x(0, metadata_replicas, "#", NULL) \
x(0, foreground_target, "target", NULL) \
x(0, background_target, "target", NULL) \
-x(0, promote_target, "target", NULL) \
+x(0, promote_target, "target", NULL) \
x(0, encrypted, NULL, "Enable whole filesystem encryption (chacha20/poly1305)")\
x(0, no_passphrase, NULL, "Don't encrypt master encryption key")\
x('e', error_action, "(continue|remount-ro|panic)", NULL) \
@@ -78,7 +79,8 @@ static void usage(void)
" --btree_node=size Btree node size, default 256k\n"
" --metadata_checksum_type=(none|crc32c|crc64)\n"
" --data_checksum_type=(none|crc32c|crc64)\n"
- " --compression_type=(none|lz4|gzip)\n"
+ " --compression_type=(none|lz4|gzip|zstd)\n"
+ " --background_compression_type=(none|lz4|gzip|zstd)\n"
" --data_replicas=# Number of data replicas\n"
" --metadata_replicas=# Number of metadata replicas\n"
" --replicas=# Sets both data and metadata replicas\n"
@@ -178,6 +180,12 @@ int cmd_format(int argc, char *argv[])
bch2_compression_types,
"compression type");
break;
+ case O_background_compression_type:
+ opts.background_compression_type =
+ read_string_list_or_die(optarg,
+ bch2_compression_types,
+ "compression type");
+ break;
case O_data_replicas:
if (kstrtouint(optarg, 10, &opts.data_replicas) ||
!opts.data_replicas ||
diff --git a/libbcachefs.c b/libbcachefs.c
index 9baaff0..cd277fa 100644
--- a/libbcachefs.c
+++ b/libbcachefs.c
@@ -128,8 +128,8 @@ static unsigned parse_target(struct dev_opts *devs, size_t nr_devs,
struct bch_sb_field_disk_groups *gi,
const char *s)
{
- struct bch_disk_group *g;
struct dev_opts *i;
+ int idx;
if (!s)
return 0;
@@ -138,15 +138,9 @@ static unsigned parse_target(struct dev_opts *devs, size_t nr_devs,
if (!strcmp(s, i->path))
return dev_to_target(i - devs);
- for (g = gi->entries;
- g < gi->entries + disk_groups_nr(gi);
- g++) {
- unsigned len = strnlen(g->label, sizeof(g->label));
-
- if (len == strlen(s) &&
- !memcmp(s, g->label, len))
- return group_to_target(g - gi->entries);
- }
+ idx = __bch2_disk_group_find(gi, s);
+ if (idx >= 0)
+ return group_to_target(idx);
die("Invalid target %s", s);
return 0;
@@ -212,6 +206,7 @@ struct bch_sb *bch2_format(struct format_opts opts,
SET_BCH_SB_META_CSUM_TYPE(sb, opts.meta_csum_type);
SET_BCH_SB_DATA_CSUM_TYPE(sb, opts.data_csum_type);
SET_BCH_SB_COMPRESSION_TYPE(sb, opts.compression_type);
+ SET_BCH_SB_BACKGROUND_COMPRESSION_TYPE(sb, opts.background_compression_type);
SET_BCH_SB_BTREE_NODE_SIZE(sb, opts.btree_node_size);
SET_BCH_SB_GC_RESERVE(sb, 8);
@@ -446,11 +441,15 @@ static void bch2_sb_print_members(struct bch_sb *sb, struct bch_sb_field *f,
uuid_unparse(m->uuid.b, member_uuid_str);
if (BCH_MEMBER_GROUP(m)) {
- if (BCH_MEMBER_GROUP(m) < disk_groups_nr(gi))
- memcpy(group, gi->entries[BCH_MEMBER_GROUP(m)].label,
+ unsigned idx = BCH_MEMBER_GROUP(m) - 1;
+
+ if (idx < disk_groups_nr(gi)) {
+ memcpy(group, gi->entries[idx].label,
BCH_SB_LABEL_SIZE);
- else
+ group[BCH_SB_LABEL_SIZE] = '\0';
+ } else {
strcpy(group, "(bad disk groups section");
+ }
}
bch2_scnprint_flag_list(data_allowed_str,
diff --git a/libbcachefs.h b/libbcachefs.h
index d27b4e8..deaa287 100644
--- a/libbcachefs.h
+++ b/libbcachefs.h
@@ -32,6 +32,7 @@ struct format_opts {
unsigned meta_csum_type;
unsigned data_csum_type;
unsigned compression_type;
+ unsigned background_compression_type;
bool encrypted;
char *passphrase;