All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Fix for infinite loop on non-empty inode but with no file extent
@ 2015-08-05  8:03 Qu Wenruo
  2015-08-05  8:03 ` [PATCH 1/3] btrfs-progs: fsck: Print correct file hole Qu Wenruo
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Qu Wenruo @ 2015-08-05  8:03 UTC (permalink / raw)
  To: linux-btrfs; +Cc: robert.munteanu

A bug reported by Robert Munteanu, which btrfsck infinite loops on an
inode with discount file extent.

This patchset includes a fix in printing file extent hole, fix the
infinite loop, and corresponding test case.

BTW, thanks Robert Munteanu a lot for its detailed debug report, makes
it super fast to reproduce the error.

Qu Wenruo (3):
  btrfs-progs: fsck: Print correct file hole
  btrfs-progs: fsck: Fix a infinite loop on discount file extent repair
  btrfs-progs: fsck-tests: Add test case for inode lost all its file    
    extent

 cmds-check.c                                            |  16 +++++++++++++++-
 .../017-missing-all-file-extent/default_case.img.xz     | Bin 0 -> 1104 bytes
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 tests/fsck-tests/017-missing-all-file-extent/default_case.img.xz

-- 
2.5.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/3] btrfs-progs: fsck: Print correct file hole
  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 ` Qu Wenruo
  2015-08-05  8:03 ` [PATCH 2/3] btrfs-progs: fsck: Fix a infinite loop on discount file extent repair Qu Wenruo
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Qu Wenruo @ 2015-08-05  8:03 UTC (permalink / raw)
  To: linux-btrfs; +Cc: robert.munteanu

If a file lost all its file extents, fsck will unable to print out the
hole.

Add an extra judgment to print out the hole range.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 cmds-check.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/cmds-check.c b/cmds-check.c
index 50bb6f3..31ed589 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -616,15 +616,20 @@ static void print_inode_error(struct btrfs_root *root, struct inode_record *rec)
 	if (errors & I_ERR_FILE_EXTENT_DISCOUNT) {
 		struct file_extent_hole *hole;
 		struct rb_node *node;
+		int found = 0;
 
 		node = rb_first(&rec->holes);
 		fprintf(stderr, "Found file extent holes:\n");
 		while (node) {
+			found = 1;
 			hole = rb_entry(node, struct file_extent_hole, node);
-			fprintf(stderr, "\tstart: %llu, len:%llu\n",
+			fprintf(stderr, "\tstart: %llu, len: %llu\n",
 				hole->start, hole->len);
 			node = rb_next(node);
 		}
+		if (!found)
+			fprintf(stderr, "\tstart: 0, len: %llu\n",
+				round_up(rec->isize, root->sectorsize));
 	}
 }
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/3] btrfs-progs: fsck: Fix a infinite loop on discount file extent repair
  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
  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
  3 siblings, 0 replies; 10+ messages in thread
From: Qu Wenruo @ 2015-08-05  8:03 UTC (permalink / raw)
  To: linux-btrfs; +Cc: robert.munteanu

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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/3] btrfs-progs: fsck-tests: Add test case for inode lost all its file extent
  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 ` [PATCH 2/3] btrfs-progs: fsck: Fix a infinite loop on discount file extent repair Qu Wenruo
@ 2015-08-05  8:03 ` Qu Wenruo
  2015-08-05 16:40 ` [PATCH 0/3] Fix for infinite loop on non-empty inode but with no " David Sterba
  3 siblings, 0 replies; 10+ messages in thread
From: Qu Wenruo @ 2015-08-05  8:03 UTC (permalink / raw)
  To: linux-btrfs; +Cc: robert.munteanu

Add test case with no file extents, but still non-zero inode size.
To test whether fsck will infinite loop.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 .../017-missing-all-file-extent/default_case.img.xz      | Bin 0 -> 1104 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 tests/fsck-tests/017-missing-all-file-extent/default_case.img.xz

diff --git a/tests/fsck-tests/017-missing-all-file-extent/default_case.img.xz b/tests/fsck-tests/017-missing-all-file-extent/default_case.img.xz
new file mode 100644
index 0000000000000000000000000000000000000000..10cd4c786e1223d1d00eaeab81941b142135d97c
GIT binary patch
literal 1104
zcmV-W1h4!3H+ooF000E$*0e?f03iVu0001VFXf})lm7${T>wRyj;C3^v%$$4d1rE0
zjjaER49m*J$Ny#wkkW^{#)(qVu6jW@U&${Z!$pUxwR_2<M^&H7KU2hve~sxWXa?I<
z%Nm>WQokys>I=scC%OAq$m&Z!a?Xa@3%R}h@8vWy-xl~qOuWtRg-R5!%XR;99;~oq
zdk{P`R>yx4e(-g_fYI=#ZDobJ@0`2Gi5Z==2t%tsj$0@PK$0}7L`88Br(*1nkpN>K
z_XxR>VtghToWQcwSZMnTkBh=v`!_jtFZnBcHm1>wf5wOm9i*QuB{`*iwt$@={jV)*
z%}T2!cPnR{zgSI}F-k1(>|ItD#YU*lQ5caPRu;$454g#EI<MlP+@`=aT*A@LADD7u
zk@V7c2kM}eBPO^Qu;ANX4!roj9d3LYnAteNtD<3soCJnDoNp54HZ4ZeX@naau}+a^
zy|#?-`{(08Rl!wH-SY4?>wetPi2Qb(f`c45RskYyF)v;1`SlF<lxU5!p|~;ics;3^
zBX%=|JUR^Ky(ynC=M7)sv&k~E4@16W$NYHYzCJ3;@@${p?4~ysw=fq^vz(x(PtElF
zwf3WM-8M{A?g(sW#s;uPp5)F}4lhgs%K1q1nFGU`)GD9qPGir}B%j3$a3;A?Gq|tS
zaDXnqJ{7yrj8iPECu)i;L_ouU|17}`kpGA2x2A0_<=e3S$bZ7H^DTsDQRGOZb@F;q
z%#Y6-P@=P|nbod(i7Gd3Lvl9v<Vzd!)uy)eEr2h(pFvf<GR9gMp7SL=Ww6;c&>vzs
zSIkg93uy516A@onIsCrvlQqwJlV~$<z#z)3I_GDFsRim|mp%_0{a_wo&v_H$C4TDq
zwn7^>-kcft_F)4WPt0OV+n3W`nZ4>OC`z1a<gtXhR}#S0IqeJw$Lsxl>4BHy`9hHs
zBtPA?RQYVy53b&CXwhyaxL;{eBnLK1F~EqXTP1;aSvcM5-y;6(p2G02#<C0S{EE=g
zW>1iR3fbSs^zRyjGTuc(qgYeJO3yRzBq+JtviiuggemrKK5?gVyt|AD#<jSXzU4VQ
zfop5yezs3WSr<m8QE|MhpJ<H!92~QSYE^Eq1p4jh$Idi{1`R>B5>jNvfrJ7h*)M7<
zoMsb>cB?RsO4>P-LyY62_cY6mGWv~hlA;J%`X3cfL4vfPWRRidP0rp|UFe_14^R2I
z{a1+AOJXzAm=7pkt%~NC1$Zx&1R?`MOxJIC_dRjwdc8K9d6>3f6rzoibNqCnp{u$U
z+A~#XVza7Y=CSF*ohfxwwN9we2j*qrOWm@Z+eMws1MlfN_ibWsO<9Z^OTT^VoVw{S
zPt09il30LPI_!MVdj_{j0W`{}1|)2jXtn*D`NB+JQbn9BfB*m@w2urGUN=kt0jmgr
Wr~&{`ruvAn#Ao{g000001X)^bF)Hl<

literal 0
HcmV?d00001

-- 
2.5.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Fix for infinite loop on non-empty inode but with no file extent
  2015-08-05  8:03 [PATCH 0/3] Fix for infinite loop on non-empty inode but with no file extent Qu Wenruo
                   ` (2 preceding siblings ...)
  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 ` David Sterba
  2015-08-07 13:05   ` Robert Munteanu
  3 siblings, 1 reply; 10+ messages in thread
From: David Sterba @ 2015-08-05 16:40 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: linux-btrfs, robert.munteanu

On Wed, Aug 05, 2015 at 04:03:11PM +0800, Qu Wenruo wrote:
> A bug reported by Robert Munteanu, which btrfsck infinite loops on an
> inode with discount file extent.
> 
> This patchset includes a fix in printing file extent hole, fix the
> infinite loop, and corresponding test case.
> 
> BTW, thanks Robert Munteanu a lot for its detailed debug report, makes
> it super fast to reproduce the error.
> 
> Qu Wenruo (3):
>   btrfs-progs: fsck: Print correct file hole
>   btrfs-progs: fsck: Fix a infinite loop on discount file extent repair
>   btrfs-progs: fsck-tests: Add test case for inode lost all its file    
>     extent

Applied, thank you both.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Fix for infinite loop on non-empty inode but with no file extent
  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
  0 siblings, 1 reply; 10+ messages in thread
From: Robert Munteanu @ 2015-08-07 13:05 UTC (permalink / raw)
  To: dsterba, Qu Wenruo, Btrfs BTRFS, Robert Munteanu

>> Qu Wenruo (3):
>>   btrfs-progs: fsck: Print correct file hole
>>   btrfs-progs: fsck: Fix a infinite loop on discount file extent repair
>>   btrfs-progs: fsck-tests: Add test case for inode lost all its file
>>     extent
>
> Applied, thank you both.

I tried to find a git repo with these patches applied but failed.
Based on the information at [0] I looked at

  http://git.kernel.org/cgit/linux/kernel/git/kdave/btrfs-progs.git
  http://git.kernel.org/cgit/linux/kernel/git/mason/btrfs-progs.git

but did not find them.

How can I build a version of btrfsprogs with these patches applied?

Thanks,

Robert

[0]: https://btrfs.wiki.kernel.org/index.php/Btrfs_source_repositories#btrfs-progs_git_repository

-- 
http://robert.muntea.nu/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Fix for infinite loop on non-empty inode but with no file extent
  2015-08-07 13:05   ` Robert Munteanu
@ 2015-08-07 14:00     ` David Sterba
  2015-08-07 14:17       ` Robert Munteanu
  0 siblings, 1 reply; 10+ messages in thread
From: David Sterba @ 2015-08-07 14:00 UTC (permalink / raw)
  To: Robert Munteanu; +Cc: Qu Wenruo, Btrfs BTRFS

On Fri, Aug 07, 2015 at 04:05:44PM +0300, Robert Munteanu wrote:
> >> Qu Wenruo (3):
> >>   btrfs-progs: fsck: Print correct file hole
> >>   btrfs-progs: fsck: Fix a infinite loop on discount file extent repair
> >>   btrfs-progs: fsck-tests: Add test case for inode lost all its file
> >>     extent
> >
> > Applied, thank you both.
> 
> I tried to find a git repo with these patches applied but failed.
> Based on the information at [0] I looked at
> 
>   http://git.kernel.org/cgit/linux/kernel/git/kdave/btrfs-progs.git
>   http://git.kernel.org/cgit/linux/kernel/git/mason/btrfs-progs.git
> 
> but did not find them.
> 
> How can I build a version of btrfsprogs with these patches applied?

The patches are collected to the branch named devel. The branch master
is updated only at release time so the recent patches cannot be found
there.

> [0]: https://btrfs.wiki.kernel.org/index.php/Btrfs_source_repositories#btrfs-progs_git_repository

Given that you came from the wiki and still was not able to find the
answer, I'll update it. Thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Fix for infinite loop on non-empty inode but with no file extent
  2015-08-07 14:00     ` David Sterba
@ 2015-08-07 14:17       ` Robert Munteanu
  2015-08-07 14:19         ` David Sterba
  0 siblings, 1 reply; 10+ messages in thread
From: Robert Munteanu @ 2015-08-07 14:17 UTC (permalink / raw)
  To: dsterba, Robert Munteanu, Qu Wenruo, Btrfs BTRFS

On Fri, Aug 7, 2015 at 5:00 PM, David Sterba <dsterba@suse.cz> wrote:
> On Fri, Aug 07, 2015 at 04:05:44PM +0300, Robert Munteanu wrote:
>> >> Qu Wenruo (3):
>> >>   btrfs-progs: fsck: Print correct file hole
>> >>   btrfs-progs: fsck: Fix a infinite loop on discount file extent repair
>> >>   btrfs-progs: fsck-tests: Add test case for inode lost all its file
>> >>     extent
>> >
>> > Applied, thank you both.
>>
>> I tried to find a git repo with these patches applied but failed.
>> Based on the information at [0] I looked at
>>
>>   http://git.kernel.org/cgit/linux/kernel/git/kdave/btrfs-progs.git
>>   http://git.kernel.org/cgit/linux/kernel/git/mason/btrfs-progs.git
>>
>> but did not find them.
>>
>> How can I build a version of btrfsprogs with these patches applied?
>
> The patches are collected to the branch named devel. The branch master
> is updated only at release time so the recent patches cannot be found
> there.
>
>> [0]: https://btrfs.wiki.kernel.org/index.php/Btrfs_source_repositories#btrfs-progs_git_repository
>
> Given that you came from the wiki and still was not able to find the
> answer, I'll update it. Thanks.

Thanks for the update. Reading it looks to me like the patches should be at

  http://repo.or.cz/w/btrfs-progs-unstable/devel.git/shortlog/refs/heads/devel

but they don't seem to be . Am I long in the wrong place again :-) ?

Thanks,

Robert



-- 
http://robert.muntea.nu/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Fix for infinite loop on non-empty inode but with no file extent
  2015-08-07 14:17       ` Robert Munteanu
@ 2015-08-07 14:19         ` David Sterba
  2015-08-07 14:23           ` Robert Munteanu
  0 siblings, 1 reply; 10+ messages in thread
From: David Sterba @ 2015-08-07 14:19 UTC (permalink / raw)
  To: Robert Munteanu; +Cc: Qu Wenruo, Btrfs BTRFS

On Fri, Aug 07, 2015 at 05:17:34PM +0300, Robert Munteanu wrote:
> Thanks for the update. Reading it looks to me like the patches should be at
> 
>   http://repo.or.cz/w/btrfs-progs-unstable/devel.git/shortlog/refs/heads/devel
> 
> but they don't seem to be . Am I long in the wrong place again :-) ?

Doh, I forgot to push the branch, sorry.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] Fix for infinite loop on non-empty inode but with no file extent
  2015-08-07 14:19         ` David Sterba
@ 2015-08-07 14:23           ` Robert Munteanu
  0 siblings, 0 replies; 10+ messages in thread
From: Robert Munteanu @ 2015-08-07 14:23 UTC (permalink / raw)
  To: dsterba, Robert Munteanu, Qu Wenruo, Btrfs BTRFS

On Fri, Aug 7, 2015 at 5:19 PM, David Sterba <dsterba@suse.cz> wrote:
> On Fri, Aug 07, 2015 at 05:17:34PM +0300, Robert Munteanu wrote:
>> Thanks for the update. Reading it looks to me like the patches should be at
>>
>>   http://repo.or.cz/w/btrfs-progs-unstable/devel.git/shortlog/refs/heads/devel
>>
>> but they don't seem to be . Am I long in the wrong place again :-) ?
>
> Doh, I forgot to push the branch, sorry.

Got them now, thank you.

Robert

-- 
http://robert.muntea.nu/

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-08-07 14:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/3] btrfs-progs: fsck: Fix a infinite loop on discount file extent repair Qu Wenruo
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.