]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - cmd_format.c
use futex instead of pthread cond variable for schedule
[bcachefs-tools-debian] / cmd_format.c
index fbe75d08bdd5e950cd6e8aefd870a1c868c83539..42e8d1a63148f5eac9ea53d6d0d377e614c47e55 100644 (file)
@@ -24,9 +24,9 @@
 #include "cmds.h"
 #include "libbcachefs.h"
 #include "crypto.h"
-#include "opts.h"
-#include "super-io.h"
-#include "util.h"
+#include "libbcachefs/opts.h"
+#include "libbcachefs/super-io.h"
+#include "libbcachefs/util.h"
 
 #define OPTS                                                                   \
 t("bcachefs format - create a new bcachefs filesystem on one or more devices") \
@@ -37,6 +37,7 @@ 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,   replicas,               "#",                    NULL)                   \
 x(0,   data_replicas,          "#",                    NULL)                   \
 x(0,   metadata_replicas,      "#",                    NULL)                   \
 x(0,   encrypted,              NULL,                   "Enable whole filesystem encryption (chacha20/poly1305)")\
@@ -77,6 +78,7 @@ static void usage(void)
             "      --compression_type=(none|lz4|gzip)\n"
             "      --data_replicas=#       Number of data replicas\n"
             "      --metadata_replicas=#   Number of metadata replicas\n"
+            "      --replicas=#            Sets both data and metadata replicas\n"
             "      --encrypted             Enable whole filesystem encryption (chacha20/poly1305)\n"
             "      --no_passphrase         Don't encrypt master encryption key\n"
             "      --error_action=(continue|readonly|panic)\n"
@@ -175,14 +177,20 @@ int cmd_format(int argc, char *argv[])
                        break;
                case O_data_replicas:
                        if (kstrtouint(optarg, 10, &opts.data_replicas) ||
-                           dev_opts.tier >= BCH_REPLICAS_MAX)
+                           opts.data_replicas >= BCH_REPLICAS_MAX)
                                die("invalid replicas");
                        break;
                case O_metadata_replicas:
                        if (kstrtouint(optarg, 10, &opts.meta_replicas) ||
-                           dev_opts.tier >= BCH_REPLICAS_MAX)
+                           opts.meta_replicas >= BCH_REPLICAS_MAX)
                                die("invalid replicas");
                        break;
+               case O_replicas:
+                       if (kstrtouint(optarg, 10, &opts.data_replicas) ||
+                           opts.data_replicas >= BCH_REPLICAS_MAX)
+                               die("invalid replicas");
+                       opts.meta_replicas = opts.data_replicas;
+                       break;
                case O_encrypted:
                        opts.encrypted = true;
                        break;
@@ -261,7 +269,7 @@ int cmd_format(int argc, char *argv[])
                bch2_format(opts, devices.item, darray_size(devices));
 
        if (!quiet)
-               bch2_super_print(sb, HUMAN_READABLE);
+               bch2_sb_print(sb, false, 1 << BCH_SB_FIELD_members, HUMAN_READABLE);
        free(sb);
 
        if (opts.passphrase) {
@@ -272,18 +280,61 @@ int cmd_format(int argc, char *argv[])
        return 0;
 }
 
+static void show_super_usage(void)
+{
+       puts("bcachefs show-super \n"
+            "Usage: bcachefs show-super [OPTION].. device\n"
+            "\n"
+            "Options:\n"
+            "  -f, --fields=(fields)       list of sections to print\n"
+            "  -l, --layout                print superblock layout\n"
+            "  -h, --help                  display this help and exit\n"
+            "Report bugs to <linux-bcache@vger.kernel.org>");
+       exit(EXIT_SUCCESS);
+}
+
 int cmd_show_super(int argc, char *argv[])
 {
-       struct bch_sb_handle sb;
-       const char *err;
+       static const struct option longopts[] = {
+               { "fields",                     1, NULL, 'f' },
+               { "layout",                     0, NULL, 'l' },
+               { "help",                       0, NULL, 'h' },
+               { NULL }
+       };
+       unsigned fields = 1 << BCH_SB_FIELD_members;
+       bool print_layout = false;
+       int opt;
+
+       while ((opt = getopt_long(argc, argv, "f:lh", longopts, NULL)) != -1)
+               switch (opt) {
+               case 'f':
+                       fields = !strcmp(optarg, "all")
+                               ? ~0
+                               : read_flag_list_or_die(optarg,
+                                       bch2_sb_fields, "superblock field");
+                       break;
+               case 'l':
+                       print_layout = true;
+                       break;
+               case 'h':
+                       show_super_usage();
+                       break;
+               }
+       args_shift(optind);
 
-       if (argc != 2)
-               die("please supply a single device");
+       char *dev = arg_pop();
+       if (!dev)
+               die("please supply a device");
+       if (argc)
+               die("too many arguments");
 
-       err = bch2_read_super(argv[1], bch2_opts_empty(), &sb);
-       if (err)
-               die("Error opening %s: %s", argv[1], err);
+       struct bch_opts opts = bch2_opts_empty();
+       struct bch_sb_handle sb;
+       int ret = bch2_read_super(dev, &opts, &sb);
+       if (ret)
+               die("Error opening %s: %s", dev, strerror(-ret));
 
-       bch2_super_print(sb.sb, HUMAN_READABLE);
+       bch2_sb_print(sb.sb, print_layout, fields, HUMAN_READABLE);
+       bch2_free_super(&sb);
        return 0;
 }