]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Get current metadata version from sysfs
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 Dec 2022 02:41:34 +0000 (21:41 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 Dec 2022 02:41:34 +0000 (21:41 -0500)
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>
cmd_format.c
libbcachefs.h

index 9feb3345b56c1486bdc7eeccf86e48dac1683e18..26a1cd9f725837cb50b5b82d42339b91453220b7 100644 (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");
 
index 17e8eef3d9998d037c2787e2c431647e5e17e933..4bb51bd89e45bddfd15fe51c9f40645e687c1883 100644 (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,
        };
 }