From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2 4/6] btrfs-progs: check/lowmem: Repair bad imode early
Date: Thu, 5 Sep 2019 15:57:58 +0800 [thread overview]
Message-ID: <20190905075800.1633-5-wqu@suse.com> (raw)
In-Reply-To: <20190905075800.1633-1-wqu@suse.com>
For lowmem mode, if we hit a bad inode mode, normally it is reported
when we checking the DIR_INDEX/DIR_ITEM of the parent inode.
If we didn't repair at that timing, the error will be recorded even we
fixed it later.
So this patch will check for INODE_ITEM_MISMATCH error type, and if it's
really caused by invalid imode, repair it and clear the error.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
check/mode-lowmem.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 5f7f101daab1..5d0c520217fa 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -1550,6 +1550,35 @@ static int lowmem_delete_corrupted_dir_item(struct btrfs_root *root,
return ret;
}
+static int try_repair_imode(struct btrfs_root *root, u64 ino)
+{
+ struct btrfs_inode_item *iitem;
+ struct btrfs_path path;
+ struct btrfs_key key;
+ int ret;
+
+ key.objectid = ino;
+ key.type = BTRFS_INODE_ITEM_KEY;
+ key.offset = 0;
+ btrfs_init_path(&path);
+
+ ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
+ if (ret > 0)
+ ret = -ENOENT;
+ if (ret < 0)
+ goto out;
+ iitem = btrfs_item_ptr(path.nodes[0], path.slots[0],
+ struct btrfs_inode_item);
+ if (!is_valid_imode(btrfs_inode_mode(path.nodes[0], iitem))) {
+ ret = repair_imode_common(root, &path);
+ } else {
+ ret = -ENOTTY;
+ }
+out:
+ btrfs_release_path(&path);
+ return ret;
+}
+
/*
* Call repair_inode_item_missing and repair_ternary_lowmem to repair
*
@@ -1574,6 +1603,16 @@ static int repair_dir_item(struct btrfs_root *root, struct btrfs_key *di_key,
err &= ~(INODE_ITEM_MISMATCH | INODE_ITEM_MISSING);
}
+ if (err & INODE_ITEM_MISMATCH) {
+ /*
+ * INODE_ITEM mismatch can be caused by bad imode,
+ * so check if it's a bad imode, then repair if possible.
+ */
+ ret = try_repair_imode(root, ino);
+ if (!ret)
+ err &= ~INODE_ITEM_MISMATCH;
+ }
+
if (err & ~(INODE_ITEM_MISMATCH | INODE_ITEM_MISSING)) {
ret = repair_ternary_lowmem(root, dirid, ino, index, namebuf,
name_len, filetype, err);
--
2.23.0
next prev parent reply other threads:[~2019-09-05 7:58 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-05 7:57 [PATCH v2 0/6] btrfs-progs: check: Repair invalid inode mode in Qu Wenruo
2019-09-05 7:57 ` [PATCH v2 1/6] btrfs-progs: check: Export btrfs_type_to_imode Qu Wenruo
2019-09-05 7:57 ` [PATCH v2 2/6] btrfs-progs: check/common: Introduce a function to find imode using INODE_REF Qu Wenruo
2019-09-09 13:25 ` Nikolay Borisov
2019-09-09 14:24 ` Qu Wenruo
2019-09-09 14:34 ` Nikolay Borisov
2019-09-09 13:42 ` Nikolay Borisov
2019-09-09 14:26 ` Qu Wenruo
2019-09-09 14:35 ` Nikolay Borisov
2019-09-05 7:57 ` [PATCH v2 3/6] btrfs-progs: check/common: Make repair_imode_common() to handle inodes in subvolume trees Qu Wenruo
2019-09-09 14:17 ` Nikolay Borisov
2019-09-09 14:27 ` Qu Wenruo
2019-09-10 4:27 ` Su Yue
2019-09-10 16:14 ` Nikolay Borisov
2019-09-11 0:39 ` Qu Wenruo
2019-09-11 12:27 ` Nikolay Borisov
2019-09-11 12:44 ` Qu Wenruo
2019-09-05 7:57 ` Qu Wenruo [this message]
2019-09-09 14:55 ` [PATCH v2 4/6] btrfs-progs: check/lowmem: Repair bad imode early Nikolay Borisov
2019-09-10 2:35 ` Qu Wenruo
2019-09-05 7:57 ` [PATCH v2 5/6] btrfs-progs: check/original: Fix inode mode in subvolume trees Qu Wenruo
2019-09-05 7:58 ` [PATCH v2 6/6] btrfs-progs: tests/fsck: Add new images for inode mode repair functionality Qu Wenruo
2019-09-09 15:37 ` Nikolay Borisov
2019-09-09 23:22 ` 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=20190905075800.1633-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;
as well as URLs for NNTP newsgroup(s).