mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-09 00:00:04 +03:00
Add format options for --no-initialize and specifying the metadata version
These are only to be used for tests.
This commit is contained in:
parent
8a69e01aeb
commit
d3dc47271b
17
cmd_format.c
17
cmd_format.c
@ -41,6 +41,8 @@ x('g', group, required_argument) \
|
|||||||
x(0, discard, no_argument) \
|
x(0, discard, no_argument) \
|
||||||
x(0, data_allowed, required_argument) \
|
x(0, data_allowed, required_argument) \
|
||||||
x(0, durability, required_argument) \
|
x(0, durability, required_argument) \
|
||||||
|
x(0, version, required_argument) \
|
||||||
|
x(0, no_initialize, no_argument) \
|
||||||
x('f', force, no_argument) \
|
x('f', force, no_argument) \
|
||||||
x('q', quiet, no_argument) \
|
x('q', quiet, no_argument) \
|
||||||
x('h', help, no_argument)
|
x('h', help, no_argument)
|
||||||
@ -112,7 +114,7 @@ int cmd_format(int argc, char *argv[])
|
|||||||
darray(char *) device_paths;
|
darray(char *) device_paths;
|
||||||
struct format_opts opts = format_opts_default();
|
struct format_opts opts = format_opts_default();
|
||||||
struct dev_opts dev_opts = dev_opts_default(), *dev;
|
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;
|
unsigned v;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
@ -183,6 +185,13 @@ int cmd_format(int argc, char *argv[])
|
|||||||
dev_opts.durability > BCH_REPLICAS_MAX)
|
dev_opts.durability > BCH_REPLICAS_MAX)
|
||||||
die("invalid durability");
|
die("invalid durability");
|
||||||
break;
|
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:
|
case O_no_opt:
|
||||||
darray_append(device_paths, optarg);
|
darray_append(device_paths, optarg);
|
||||||
dev_opts.path = optarg;
|
dev_opts.path = optarg;
|
||||||
@ -206,8 +215,10 @@ int cmd_format(int argc, char *argv[])
|
|||||||
if (darray_empty(devices))
|
if (darray_empty(devices))
|
||||||
die("Please supply a device");
|
die("Please supply a device");
|
||||||
|
|
||||||
if (opts.encrypted && !no_passphrase)
|
if (opts.encrypted && !no_passphrase) {
|
||||||
opts.passphrase = read_passphrase_twice("Enter passphrase: ");
|
opts.passphrase = read_passphrase_twice("Enter passphrase: ");
|
||||||
|
initialize = false;
|
||||||
|
}
|
||||||
|
|
||||||
darray_foreach(dev, devices)
|
darray_foreach(dev, devices)
|
||||||
dev->fd = open_for_format(dev->path, force);
|
dev->fd = open_for_format(dev->path, force);
|
||||||
@ -229,7 +240,7 @@ int cmd_format(int argc, char *argv[])
|
|||||||
|
|
||||||
darray_free(devices);
|
darray_free(devices);
|
||||||
|
|
||||||
if (!opts.passphrase) {
|
if (initialize) {
|
||||||
/*
|
/*
|
||||||
* Start the filesystem once, to allocate the journal and create
|
* Start the filesystem once, to allocate the journal and create
|
||||||
* the root directory:
|
* the root directory:
|
||||||
|
@ -202,8 +202,8 @@ struct bch_sb *bch2_format(struct bch_opt_strs fs_opt_strs,
|
|||||||
if (bch2_sb_realloc(&sb, 0))
|
if (bch2_sb_realloc(&sb, 0))
|
||||||
die("insufficient memory");
|
die("insufficient memory");
|
||||||
|
|
||||||
sb.sb->version = le16_to_cpu(bcachefs_metadata_version_current);
|
sb.sb->version = le16_to_cpu(opts.version);
|
||||||
sb.sb->version_min = le16_to_cpu(bcachefs_metadata_version_current);
|
sb.sb->version_min = le16_to_cpu(opts.version);
|
||||||
sb.sb->magic = BCACHE_MAGIC;
|
sb.sb->magic = BCACHE_MAGIC;
|
||||||
sb.sb->block_size = cpu_to_le16(fs_opts.block_size);
|
sb.sb->block_size = cpu_to_le16(fs_opts.block_size);
|
||||||
sb.sb->user_uuid = opts.uuid;
|
sb.sb->user_uuid = opts.uuid;
|
||||||
|
@ -30,6 +30,7 @@ void bch2_opts_usage(unsigned);
|
|||||||
struct format_opts {
|
struct format_opts {
|
||||||
char *label;
|
char *label;
|
||||||
uuid_le uuid;
|
uuid_le uuid;
|
||||||
|
unsigned version;
|
||||||
|
|
||||||
unsigned encoded_extent_max;
|
unsigned encoded_extent_max;
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ struct format_opts {
|
|||||||
static inline struct format_opts format_opts_default()
|
static inline struct format_opts format_opts_default()
|
||||||
{
|
{
|
||||||
return (struct format_opts) {
|
return (struct format_opts) {
|
||||||
|
.version = bcachefs_metadata_version_current,
|
||||||
.encoded_extent_max = 128,
|
.encoded_extent_max = 128,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user