From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/4] btrfs-progs: check: Remove the ability to rebuild root overwritting existing tree blocks
Date: Thu, 5 Jul 2018 15:37:28 +0800 [thread overview]
Message-ID: <20180705073731.18459-2-wqu@suse.com> (raw)
In-Reply-To: <20180705073731.18459-1-wqu@suse.com>
We have function btrfs_fsck_reinit_root() to reinit csum or extent tree.
However this function allows us to let it overwrite existing tree blocks
using @overwrite parameter.
Such behavior is pretty dangerous while no caller is using this feature
explicitly.
So just remove @overwrite parameter and allow btrfs_fsck_reinit_root()
to error out when it fails to allocate tree block.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
check/main.c | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)
diff --git a/check/main.c b/check/main.c
index 8db300abb825..c8c347236543 100644
--- a/check/main.c
+++ b/check/main.c
@@ -8379,7 +8379,7 @@ static int do_check_chunks_and_extents(struct btrfs_fs_info *fs_info)
}
static int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans,
- struct btrfs_root *root, int overwrite)
+ struct btrfs_root *root)
{
struct extent_buffer *c;
struct extent_buffer *old = root->node;
@@ -8389,21 +8389,13 @@ static int btrfs_fsck_reinit_root(struct btrfs_trans_handle *trans,
level = 0;
- if (overwrite) {
- c = old;
- extent_buffer_get(c);
- goto init;
- }
c = btrfs_alloc_free_block(trans, root,
root->fs_info->nodesize,
root->root_key.objectid,
&disk_key, level, 0, 0);
- if (IS_ERR(c)) {
- c = old;
- extent_buffer_get(c);
- overwrite = 1;
- }
-init:
+ if (IS_ERR(c))
+ return PTR_ERR(c);
+
memset_extent_buffer(c, 0, 0, sizeof(struct btrfs_header));
btrfs_set_header_level(c, level);
btrfs_set_header_bytenr(c, c->start);
@@ -8422,9 +8414,7 @@ init:
/*
* this case can happen in the following case:
*
- * 1.overwrite previous root.
- *
- * 2.reinit reloc data root, this is because we skip pin
+ * reinit reloc data root, this is because we skip pin
* down reloc data tree before which means we can allocate
* same block bytenr here.
*/
@@ -8609,7 +8599,7 @@ reinit_data_reloc:
goto out;
}
record_root_in_trans(trans, root);
- ret = btrfs_fsck_reinit_root(trans, root, 0);
+ ret = btrfs_fsck_reinit_root(trans, root);
if (ret)
goto out;
ret = btrfs_make_root_dir(trans, root, BTRFS_FIRST_FREE_OBJECTID);
@@ -8675,7 +8665,7 @@ again:
}
/* Ok we can allocate now, reinit the extent root */
- ret = btrfs_fsck_reinit_root(trans, fs_info->extent_root, 0);
+ ret = btrfs_fsck_reinit_root(trans, fs_info->extent_root);
if (ret) {
fprintf(stderr, "extent root initialization failed\n");
/*
@@ -9764,7 +9754,7 @@ int cmd_check(int argc, char **argv)
if (init_csum_tree) {
printf("Reinitialize checksum tree\n");
- ret = btrfs_fsck_reinit_root(trans, info->csum_root, 0);
+ ret = btrfs_fsck_reinit_root(trans, info->csum_root);
if (ret) {
error("checksum tree initialization failed: %d",
ret);
--
2.18.0
next prev parent reply other threads:[~2018-07-05 7:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-05 7:37 [PATCH 0/4] Some random fuzz test fixes Qu Wenruo
2018-07-05 7:37 ` Qu Wenruo [this message]
2018-07-05 8:50 ` [PATCH 1/4] btrfs-progs: check: Remove the ability to rebuild root overwritting existing tree blocks Gu, Jinxiang
2018-07-05 9:41 ` Qu Wenruo
2018-07-06 1:53 ` Gu, Jinxiang
2018-08-02 19:36 ` David Sterba
2018-07-05 7:37 ` [PATCH 2/4] btrfs-progs: transaction: Error out other than panic when committing transaction Qu Wenruo
2018-07-05 9:33 ` Gu, Jinxiang
2018-07-05 7:37 ` [PATCH 3/4] btrfs-progs: check/original: Avoid infinite loop when failed to repair inode Qu Wenruo
2018-07-06 3:22 ` Gu, Jinxiang
2018-07-05 7:37 ` [PATCH 4/4] btrfs-progs: check/original: Don't overwrite return value when we failed to repair Qu Wenruo
2018-07-06 4:57 ` Gu, Jinxiang
2018-08-02 20:03 ` [PATCH 0/4] Some random fuzz test fixes David Sterba
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=20180705073731.18459-2-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;
as well as URLs for NNTP newsgroup(s).