[Cluster-devel] [PATCH 4/5] savemeta: Check file format version properly
Andrew Price
anprice at redhat.com
Mon May 11 14:41:24 UTC 2020
Don't continue if we don't recognise the metadata file format version.
Signed-off-by: Andrew Price <anprice at redhat.com>
---
gfs2/edit/savemeta.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index f8f3312c..7dc506a2 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -962,9 +962,12 @@ static int parse_header(char *buf, struct savemeta_header *smh)
{
struct savemeta_header *smh_be = (void *)buf;
- if (be32_to_cpu(smh_be->sh_magic) != SAVEMETA_MAGIC ||
- be32_to_cpu(smh_be->sh_format) > SAVEMETA_FORMAT) {
+ if (be32_to_cpu(smh_be->sh_magic) != SAVEMETA_MAGIC) {
printf("No valid file header found. Falling back to old format...\n");
+ return 1;
+ }
+ if (be32_to_cpu(smh_be->sh_format) > SAVEMETA_FORMAT) {
+ printf("This version of gfs2_edit is too old to restore this metadata format.\n");
return -1;
}
smh->sh_magic = be32_to_cpu(smh_be->sh_magic);
@@ -1226,9 +1229,12 @@ static int restore_init(const char *path, struct metafd *mfd, struct savemeta_he
return -1;
}
bp = restore_buf;
- if (parse_header(bp, smh) == 0) {
+ ret = parse_header(bp, smh);
+ if (ret == 0) {
bp = restore_buf + sizeof(*smh);
restore_off = sizeof(*smh);
+ } else if (ret == -1) {
+ return -1;
}
/* Scan for the position of the superblock. Required to support old formats(?). */
end = &restore_buf[256 + sizeof(struct saved_metablock) + sizeof(*sbmh)];
--
2.26.2
More information about the Cluster-devel
mailing list