]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
minor disk group fixes;, add background_compression option
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 28 Feb 2018 22:56:53 +0000 (17:56 -0500)
committerKent Overstreet <kent.overstreet@gmail.com>
Wed, 28 Feb 2018 22:57:55 +0000 (17:57 -0500)
cmd_format.c
libbcachefs.c
libbcachefs.h

index fff2d77bb813d85009788923b848d342f7899f0d..065efd9df17bd0dc8509de821e005127872c5880 100644 (file)
 
 #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 ||
index 9baaff046cc36c324a05e941154991b7155fc70e..cd277fa72586c42527f517e30b148d6945352a9a 100644 (file)
@@ -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,
index d27b4e8f3cd353a8a0eea44d41ef3c1e03ff27dd..deaa28751c4c6324f17097bdccacd98249936aab 100644 (file)
@@ -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;