From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 11/13] restoremeta: Combine parse_header() and check_header()
Date: Thu, 23 Jan 2020 15:55:50 +0000 [thread overview]
Message-ID: <20200123155552.1080247-12-anprice@redhat.com> (raw)
In-Reply-To: <20200123155552.1080247-1-anprice@redhat.com>
Fixes an issue where smh was being left with garbage values with
old metadata files with no header.
Signed-off-by: Andrew Price <anprice@redhat.com>
---
gfs2/edit/savemeta.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 2cfa2f44..7e47b810 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -856,20 +856,19 @@ static int save_header(struct metafd *mfd, uint64_t fsbytes)
return 0;
}
-static void parse_header(char *buf, struct savemeta_header *smh)
+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) {
+ printf("No valid file header found. Falling back to old format...\n");
+ return -1;
+ }
smh->sh_magic = be32_to_cpu(smh_be->sh_magic);
smh->sh_format = be32_to_cpu(smh_be->sh_format);
smh->sh_time = be64_to_cpu(smh_be->sh_time);
smh->sh_fs_bytes = be64_to_cpu(smh_be->sh_fs_bytes);
-}
-
-static int check_header(struct savemeta_header *smh)
-{
- if (smh->sh_magic != SAVEMETA_MAGIC || smh->sh_format > SAVEMETA_FORMAT)
- return -1;
printf("Metadata saved at %s", ctime((time_t *)&smh->sh_time)); /* ctime() adds \n */
printf("File system size %.2fGB\n", smh->sh_fs_bytes / ((float)(1 << 30)));
return 0;
@@ -1155,14 +1154,10 @@ static int restore_init(const char *path, struct metafd *mfd, struct savemeta_he
return -1;
}
bp = restore_buf;
- parse_header(bp, smh);
- if (check_header(smh) != 0)
- printf("No valid file header found. Falling back to old format...\n");
- else {
+ if (parse_header(bp, smh) == 0) {
bp = restore_buf + sizeof(*smh);
restore_off = sizeof(*smh);
}
-
/* Scan for the position of the superblock. Required to support old formats(?). */
end = &restore_buf[256 + sizeof(struct saved_metablock) + sizeof(*sbmh)];
while (bp <= end) {
--
2.24.1
next prev parent reply other threads:[~2020-01-23 15:55 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-23 15:55 [Cluster-devel] [PATCH 00/13] gfs2_edit restoremeta: Add bzip2 support Andrew Price
2020-01-23 15:55 ` [Cluster-devel] [PATCH 01/13] restoremeta: Use zlib by file descriptor Andrew Price
2020-01-23 15:55 ` [Cluster-devel] [PATCH 02/13] restoremeta: Abstract out metadata file opening Andrew Price
2020-01-23 15:55 ` [Cluster-devel] [PATCH 03/13] restoremeta: Use metafd instead of gzFile for parameters Andrew Price
2020-01-23 15:55 ` [Cluster-devel] [PATCH 04/13] restoremeta: Abstract out decompression operations Andrew Price
2020-01-23 15:55 ` [Cluster-devel] [PATCH 05/13] restoremeta: Combine restore_init() and open_metadata() Andrew Price
2020-01-23 15:55 ` [Cluster-devel] [PATCH 06/13] restoremeta: Don't seek in restore_header() Andrew Price
2020-01-23 15:55 ` [Cluster-devel] [PATCH 07/13] savemeta: Remove anthropomorphize() Andrew Price
2020-01-23 15:55 ` [Cluster-devel] [PATCH 08/13] restoremeta: Remove find_highest_block() Andrew Price
2020-01-23 15:55 ` [Cluster-devel] [PATCH 09/13] restoremeta: Metadata file reading overhaul Andrew Price
2020-01-23 15:55 ` [Cluster-devel] [PATCH 10/13] restoremeta: Convert iseof function to a flag Andrew Price
2020-01-23 15:55 ` Andrew Price [this message]
2020-01-23 15:55 ` [Cluster-devel] [PATCH 12/13] restoremeta: Add bzip2 support Andrew Price
2020-01-23 15:55 ` [Cluster-devel] [PATCH 13/13] restoremeta: Skip the right number of bytes for the superblock Andrew Price
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200123155552.1080247-12-anprice@redhat.com \
--to=anprice@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).