summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-03-21 16:12:26 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2021-03-21 16:21:51 -0400
commitd3dc47271bc7a82b96e6441129058831835c0677 (patch)
tree147a295b1f447c1ccbb0a0ad9ad0533da057e257
parent8a69e01aeb2fab6ca9a12cf11e7bad49951db4d4 (diff)
Add format options for --no-initialize and specifying the metadata version
These are only to be used for tests.
-rw-r--r--cmd_format.c17
-rw-r--r--libbcachefs.c4
-rw-r--r--libbcachefs.h2
3 files changed, 18 insertions, 5 deletions
diff --git a/cmd_format.c b/cmd_format.c
index 673c63a7..bcd69783 100644
--- a/cmd_format.c
+++ b/cmd_format.c
@@ -41,6 +41,8 @@ x('g', group, required_argument) \
x(0, discard, no_argument) \
x(0, data_allowed, required_argument) \
x(0, durability, required_argument) \
+x(0, version, required_argument) \
+x(0, no_initialize, no_argument) \
x('f', force, no_argument) \
x('q', quiet, no_argument) \
x('h', help, no_argument)
@@ -112,7 +114,7 @@ int cmd_format(int argc, char *argv[])
darray(char *) device_paths;
struct format_opts opts = format_opts_default();
struct dev_opts dev_opts = dev_opts_default(), *dev;
- bool force = false, no_passphrase = false, quiet = false;
+ bool force = false, no_passphrase = false, quiet = false, initialize = true;
unsigned v;
int opt;
@@ -183,6 +185,13 @@ int cmd_format(int argc, char *argv[])
dev_opts.durability > BCH_REPLICAS_MAX)
die("invalid durability");
break;
+ case O_version:
+ if (kstrtouint(optarg, 10, &opts.version))
+ die("invalid version");
+ break;
+ case O_no_initialize:
+ initialize = false;
+ break;
case O_no_opt:
darray_append(device_paths, optarg);
dev_opts.path = optarg;
@@ -206,8 +215,10 @@ int cmd_format(int argc, char *argv[])
if (darray_empty(devices))
die("Please supply a device");
- if (opts.encrypted && !no_passphrase)
+ if (opts.encrypted && !no_passphrase) {
opts.passphrase = read_passphrase_twice("Enter passphrase: ");
+ initialize = false;
+ }
darray_foreach(dev, devices)
dev->fd = open_for_format(dev->path, force);
@@ -229,7 +240,7 @@ int cmd_format(int argc, char *argv[])
darray_free(devices);
- if (!opts.passphrase) {
+ if (initialize) {
/*
* Start the filesystem once, to allocate the journal and create
* the root directory:
diff --git a/libbcachefs.c b/libbcachefs.c
index 518c9624..9e7bc7d4 100644
--- a/libbcachefs.c
+++ b/libbcachefs.c
@@ -202,8 +202,8 @@ struct bch_sb *bch2_format(struct bch_opt_strs fs_opt_strs,
if (bch2_sb_realloc(&sb, 0))
die("insufficient memory");
- sb.sb->version = le16_to_cpu(bcachefs_metadata_version_current);
- sb.sb->version_min = le16_to_cpu(bcachefs_metadata_version_current);
+ sb.sb->version = le16_to_cpu(opts.version);
+ sb.sb->version_min = le16_to_cpu(opts.version);
sb.sb->magic = BCACHE_MAGIC;
sb.sb->block_size = cpu_to_le16(fs_opts.block_size);
sb.sb->user_uuid = opts.uuid;
diff --git a/libbcachefs.h b/libbcachefs.h
index 6ae24e9f..abc25ba0 100644
--- a/libbcachefs.h
+++ b/libbcachefs.h
@@ -30,6 +30,7 @@ void bch2_opts_usage(unsigned);
struct format_opts {
char *label;
uuid_le uuid;
+ unsigned version;
unsigned encoded_extent_max;
@@ -40,6 +41,7 @@ struct format_opts {
static inline struct format_opts format_opts_default()
{
return (struct format_opts) {
+ .version = bcachefs_metadata_version_current,
.encoded_extent_max = 128,
};
}