From: WenRuo Qu <wqu@suse.com>
To: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Cc: WenRuo Qu <wqu@suse.com>
Subject: [PATCH v2 04/14] btrfs-progs: image: Verify the superblock before restore
Date: Tue, 2 Jul 2019 10:07:24 +0000 [thread overview]
Message-ID: <20190702100650.2746-5-wqu@suse.com> (raw)
In-Reply-To: <20190702100650.2746-1-wqu@suse.com>
This patch will export disk-io.c::check_super() as btrfs_check_super()
and use it in btrfs-image for extra verification.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
disk-io.c | 6 +++---
disk-io.h | 1 +
image/main.c | 5 +++++
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/disk-io.c b/disk-io.c
index 151eb3b5a278..ffe4a8c58060 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1347,7 +1347,7 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
* - number of devices - something sane
* - sys array size - maximum
*/
-static int check_super(struct btrfs_super_block *sb, unsigned sbflags)
+int btrfs_check_super(struct btrfs_super_block *sb, unsigned sbflags)
{
u8 result[BTRFS_CSUM_SIZE];
u32 crc;
@@ -1547,7 +1547,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
if (btrfs_super_bytenr(buf) != sb_bytenr)
return -EIO;
- ret = check_super(buf, sbflags);
+ ret = btrfs_check_super(buf, sbflags);
if (ret < 0)
return ret;
memcpy(sb, buf, BTRFS_SUPER_INFO_SIZE);
@@ -1572,7 +1572,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
/* if magic is NULL, the device was removed */
if (btrfs_super_magic(buf) == 0 && i == 0)
break;
- if (check_super(buf, sbflags))
+ if (btrfs_check_super(buf, sbflags))
continue;
if (!fsid_is_initialized) {
diff --git a/disk-io.h b/disk-io.h
index ddf3a3803ed5..c97aa2344ac9 100644
--- a/disk-io.h
+++ b/disk-io.h
@@ -171,6 +171,7 @@ static inline int close_ctree(struct btrfs_root *root)
int write_all_supers(struct btrfs_fs_info *fs_info);
int write_ctree_super(struct btrfs_trans_handle *trans);
+int btrfs_check_super(struct btrfs_super_block *sb, unsigned sbflags);
int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
unsigned sbflags);
int btrfs_map_bh_to_logical(struct btrfs_root *root, struct extent_buffer *bh,
diff --git a/image/main.c b/image/main.c
index c45d506812b2..f155794cfc19 100644
--- a/image/main.c
+++ b/image/main.c
@@ -1983,6 +1983,11 @@ static int build_chunk_tree(struct mdrestore_struct *mdres,
pthread_mutex_lock(&mdres->mutex);
super = (struct btrfs_super_block *)buffer;
+ ret = btrfs_check_super(super, 0);
+ if (ret < 0) {
+ error("invalid superblock");
+ return ret;
+ }
chunk_root_bytenr = btrfs_super_chunk_root(super);
mdres->nodesize = btrfs_super_nodesize(super);
if (btrfs_super_incompat_flags(super) &
--
2.22.0
next prev parent reply other threads:[~2019-07-02 10:24 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-02 10:07 [PATCH v2 00/14] btrfs-progs: image: Enhance and bug fixes WenRuo Qu
2019-07-02 10:07 ` [PATCH v2 01/14] btrfs-progs: image: Use SZ_* to replace intermediate size WenRuo Qu
2019-07-02 10:07 ` [PATCH v2 02/14] btrfs-progs: image: Fix an indent misalign WenRuo Qu
2019-07-02 10:07 ` [PATCH v2 03/14] btrfs-progs: image: Fix an access-beyond-boundary bug when there are 32 online CPUs WenRuo Qu
2019-07-02 10:07 ` WenRuo Qu [this message]
2019-07-02 10:07 ` [PATCH v2 05/14] btrfs-progs: image: Introduce framework for more dump versions WenRuo Qu
2019-07-02 10:07 ` [PATCH v2 06/14] btrfs-progs: image: Introduce -d option to dump data WenRuo Qu
2019-07-02 10:07 ` [PATCH v2 07/14] btrfs-progs: image: Allow restore to record system chunk ranges for later usage WenRuo Qu
2019-07-02 10:07 ` [PATCH v2 08/14] btrfs-progs: image: Introduce helper to determine if a tree block is in the range of system chunks WenRuo Qu
2019-07-02 10:07 ` [PATCH v2 09/14] btrfs-progs: image: Rework how we search chunk tree blocks WenRuo Qu
2019-07-02 10:07 ` [PATCH v2 10/14] btrfs-progs: image: Reduce memory requirement for decompression WenRuo Qu
2019-07-02 10:07 ` [PATCH v2 11/14] btrfs-progs: image: Don't waste memory when we're just extracting super block WenRuo Qu
2019-07-02 10:07 ` [PATCH v2 12/14] btrfs-progs: image: Reduce memory usage for chunk tree search WenRuo Qu
2019-07-02 10:07 ` [PATCH v2 13/14] btrfs-progs: image: Output error message for chunk tree build error WenRuo Qu
2019-07-02 10:08 ` [PATCH v2 14/14] btrfs-progs: image: Fix error output to show correct return value WenRuo Qu
2019-07-04 2:13 ` [PATCH v2 00/14] btrfs-progs: image: Enhance and bug fixes Anand Jain
2019-07-04 2:54 ` Qu Wenruo
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=20190702100650.2746-5-wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/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