From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org, dsterba@suse.cz
Subject: [PATCH 1/4] btrfs-progs: mode-lowmem: Fix false alert about orphan inode
Date: Mon, 5 Feb 2018 14:47:11 +0800 [thread overview]
Message-ID: <20180205064714.15659-1-wqu@suse.com> (raw)
Btrfs can delay inode deletion and in that case btrfs will unlink the
victim inode from its parent dir, and insert a marker to info btrfs to
delete it later.
In that case, such victim inode will have nlinks == 0, but is still
completely valid.
Original mode won't report such problem, but lowmem mode doesn't check
the ORPHAN_ITEM key for such inode, and can report false alert like:
------
ERROR: root 257 INODE[28891726] is orphan item
------
Fix such false alert by checking orphan item for inode whose nlink is 0.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
check/mode-lowmem.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c
index 62bcf3d2e126..b11a6d77d102 100644
--- a/check/mode-lowmem.c
+++ b/check/mode-lowmem.c
@@ -1861,6 +1861,24 @@ out:
return ret;
}
+static bool has_orphan_item(struct btrfs_root *root, u64 ino)
+{
+ struct btrfs_path path;
+ struct btrfs_key key;
+ int ret;
+
+ btrfs_init_path(&path);
+ key.objectid = BTRFS_ORPHAN_OBJECTID;
+ key.type = BTRFS_ORPHAN_ITEM_KEY;
+ key.offset = ino;
+
+ ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
+ btrfs_release_path(&path);
+ if (ret == 0)
+ return true;
+ return false;
+}
+
/*
* Check INODE_ITEM and related ITEMs (the same inode number)
* 1. check link count
@@ -1890,6 +1908,7 @@ static int check_inode_item(struct btrfs_root *root, struct btrfs_path *path,
u64 extent_size = 0;
unsigned int dir;
unsigned int nodatasum;
+ bool is_orphan = false;
int slot;
int ret;
int err = 0;
@@ -2040,10 +2059,11 @@ out:
root->objectid, inode_id, nlink, refs);
}
} else if (!nlink) {
- if (repair)
+ is_orphan = has_orphan_item(root, inode_id);
+ if (!is_orphan && repair)
ret = repair_inode_orphan_item_lowmem(root,
path, inode_id);
- if (!repair || ret) {
+ if (!is_orphan && (!repair || ret)) {
err |= ORPHAN_ITEM;
error("root %llu INODE[%llu] is orphan item",
root->objectid, inode_id);
--
2.16.1
next reply other threads:[~2018-02-05 6:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-05 6:47 Qu Wenruo [this message]
2018-02-05 6:47 ` [PATCH 2/4] btrfs-progs: fsck-tests: Add test case with valid orphan inode Qu Wenruo
2018-02-05 6:47 ` [PATCH 3/4] btrfs-progs: gitignore: Ignore *.restored test image Qu Wenruo
2018-02-05 6:47 ` [PATCH 4/4] btrfs-progs: gitignore: Ignore patches Qu Wenruo
2018-02-05 7:00 ` [PATCH 1/4] btrfs-progs: mode-lowmem: Fix false alert about orphan inode Su Yue
2018-03-12 18:09 ` David Sterba
2018-03-12 18:19 ` 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=20180205064714.15659-1-wqu@suse.com \
--to=wqu@suse.com \
--cc=dsterba@suse.cz \
--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).