Get current metadata version from sysfs

This changes the default version for the format command to be the
currently supported version, via
/sys/modules/bcachefs/parameters/version.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2022-12-21 21:41:34 -05:00
parent e314b39c63
commit 0417560649
2 changed files with 8 additions and 1 deletions

View File

@ -219,6 +219,9 @@ int cmd_format(int argc, char *argv[])
break;
}
if (opts.version != bcachefs_metadata_version_current)
initialize = false;
if (!devices.nr)
die("Please supply a device");

View File

@ -41,8 +41,12 @@ struct format_opts {
static inline struct format_opts format_opts_default()
{
unsigned version = !access( "/sys/module/bcachefs/parameters/version", R_OK)
? read_file_u64(AT_FDCWD, "/sys/module/bcachefs/parameters/version")
: bcachefs_metadata_version_current;
return (struct format_opts) {
.version = bcachefs_metadata_version_current,
.version = version,
.superblock_size = SUPERBLOCK_SIZE_DEFAULT,
};
}