aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2022-12-21 21:41:34 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2022-12-21 21:41:34 -0500
commit0417560649434fc985896c84527fbdadbb06aa42 (patch)
tree22d77368c67b5182e0ced9afa77ab138287c3133
parente314b39c63fbfc2522c4b96e4031f9fc8e07e267 (diff)
downloadbcachefs-tools-0417560649434fc985896c84527fbdadbb06aa42.tar.gz
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>
-rw-r--r--cmd_format.c3
-rw-r--r--libbcachefs.h6
2 files changed, 8 insertions, 1 deletions
diff --git a/cmd_format.c b/cmd_format.c
index 9feb3345..26a1cd9f 100644
--- a/cmd_format.c
+++ b/cmd_format.c
@@ -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");
diff --git a/libbcachefs.h b/libbcachefs.h
index 17e8eef3..4bb51bd8 100644
--- a/libbcachefs.h
+++ b/libbcachefs.h
@@ -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,
};
}