From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: <robert.munteanu@gmail.com>
Subject: [PATCH 2/3] btrfs-progs: fsck: Fix a infinite loop on discount file extent repair
Date: Wed, 5 Aug 2015 16:03:13 +0800 [thread overview]
Message-ID: <1438761794-32738-3-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1438761794-32738-1-git-send-email-quwenruo@cn.fujitsu.com>
For a special case, discount file extent repair function will cause
infinite loop.
The case is, if the file loses all its file extent, we won't have a hole
to fill, causing repair function doing nothing, and since the
I_ERR_DISCOUNT doesn't disappear, the fsck will do infinite loop.
For such case, just puch hole to fill all the range to fix it.
Reported-by: Robert Munteanu <robert.munteanu@gmail.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
cmds-check.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/cmds-check.c b/cmds-check.c
index 31ed589..4fa8709 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -2665,11 +2665,13 @@ static int repair_inode_discount_extent(struct btrfs_trans_handle *trans,
{
struct rb_node *node;
struct file_extent_hole *hole;
+ int found = 0;
int ret = 0;
node = rb_first(&rec->holes);
while (node) {
+ found = 1;
hole = rb_entry(node, struct file_extent_hole, node);
ret = btrfs_punch_hole(trans, root, rec->ino,
hole->start, hole->len);
@@ -2683,6 +2685,13 @@ static int repair_inode_discount_extent(struct btrfs_trans_handle *trans,
rec->errors &= ~I_ERR_FILE_EXTENT_DISCOUNT;
node = rb_first(&rec->holes);
}
+ /* special case for a file losing all its file extent */
+ if (!found) {
+ ret = btrfs_punch_hole(trans, root, rec->ino, 0,
+ round_up(rec->isize, root->sectorsize));
+ if (ret < 0)
+ goto out;
+ }
printf("Fixed discount file extents for inode: %llu in root: %llu\n",
rec->ino, root->objectid);
out:
--
2.5.0
next prev parent reply other threads:[~2015-08-05 8:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-05 8:03 [PATCH 0/3] Fix for infinite loop on non-empty inode but with no file extent Qu Wenruo
2015-08-05 8:03 ` [PATCH 1/3] btrfs-progs: fsck: Print correct file hole Qu Wenruo
2015-08-05 8:03 ` Qu Wenruo [this message]
2015-08-05 8:03 ` [PATCH 3/3] btrfs-progs: fsck-tests: Add test case for inode lost all its file extent Qu Wenruo
2015-08-05 16:40 ` [PATCH 0/3] Fix for infinite loop on non-empty inode but with no " David Sterba
2015-08-07 13:05 ` Robert Munteanu
2015-08-07 14:00 ` David Sterba
2015-08-07 14:17 ` Robert Munteanu
2015-08-07 14:19 ` David Sterba
2015-08-07 14:23 ` Robert Munteanu
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=1438761794-32738-3-git-send-email-quwenruo@cn.fujitsu.com \
--to=quwenruo@cn.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=robert.munteanu@gmail.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).