From d6642da44d61e2f2173ddd03fe58747f4a67f018 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Tue, 11 Jun 2024 09:58:54 -0700 Subject: [PATCH] Prevent downgrade of format version Don't let change-format-version decrease the format version. It doesn't have the machinery to go back and migrate newer structures to older structures that would be compatible with code expecting the older version. Signed-off-by: Bryant G. Duffy-Ly [zab@versity.com: split from initial patch with other changes] Signed-off-by: Zach Brown --- utils/src/change_format_version.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/utils/src/change_format_version.c b/utils/src/change_format_version.c index 071e6303..1e5e1507 100644 --- a/utils/src/change_format_version.c +++ b/utils/src/change_format_version.c @@ -119,6 +119,16 @@ static int do_change_fmt_vers(struct change_fmt_vers_args *args) goto out; } + if (le64_to_cpu(meta_super->fmt_vers) > args->fmt_vers || + le64_to_cpu(data_super->fmt_vers) > args->fmt_vers) { + ret = -EPERM; + printf("Downgrade of Meta Format Version: %llu and Data Format Version: %llu to Format Version: %llu is not allowed\n", + le64_to_cpu(meta_super->fmt_vers), + le64_to_cpu(data_super->fmt_vers), + args->fmt_vers); + goto out; + } + if (le64_to_cpu(meta_super->fmt_vers) != args->fmt_vers) { meta_super->fmt_vers = cpu_to_le64(args->fmt_vers);