xfs: fix extent busy updating
PATCH 1/1 xfs: fix extent busy updating
In xfs_extent_busy_update_extent() case 6 and 7, whenever bno is modified on extent busy, the relavent length has to be modified accordingly.
--- fs/xfs/xfs_extent_busy.c | 1 + 1 file changed, 1 insertion(+)
fs/xfs/xfs_extent_busy.c +1 -0
@@ -236,6 +236,7 @@ xfs_extent_busy_update_extent(* */ busyp->bno = fend; + busyp->length = bend - fend; }else if (bbno < fbno) {/* * Case 8:
Signature · 1 line
2.21.0 (Apple Git-122.2)
Quoted 13 lines · Wengang Wang
In
xfs_extent_busy_update_extent()case 6 and 7, whenever bno is modified on extent busy, the relavent length has to be modified accordingly.Signed-off-by Wengang Wang <[email protected]>--- fs/xfs/xfs_extent_busy.c | 1 + 1 file changed, 1 insertion(+)fs/xfs/xfs_extent_busy.c +0
-0
fs/xfs/xfs_extent_busy.c xfs_extent_busy_update_extent( · line 239
Quoted 4 lines
fs/xfs/xfs_extent_busy.c +1
-0@@ -236,6 +236,7 @@ xfs_extent_busy_update_extent(* */ busyp->bno = fend; + busyp->length = bend - fend;
Looks correct to me, but how did you find this? Is there some sort of test case we could attach to this?
--D
Quoted 6 lines
fs/xfs/xfs_extent_busy.c +0
-0}else if (bbno < fbno) {/* * Case 8: Signature · 1 line
2.21.0 (Apple Git-122.2)
Darrick,
Quoted 11 lines · Darrick J. Wong
Quoted 8 lines · Wengang Wang
In
xfs_extent_busy_update_extent()case 6 and 7, whenever bno is modified on extent busy, the relavent length has to be modified accordingly.Signed-off-by Wengang Wang <[email protected]>---
fs/xfs/xfs_extent_busy.c| 1 +1 file changed, 1 insertion(+)
Quoted 11 lines
fs/xfs/xfs_extent_busy.c xfs_extent_busy_update_extent( · line 239
Quoted 9 lines
fs/xfs/xfs_extent_busy.c +1
-0@@ -236,6 +236,7 @@ xfs_extent_busy_update_extent(* */ busyp->bno = fend; + busyp->length = bend - fend;Looks correct to me, but how did you find this?
I was working with a UEK5 XFS bug where busy blocks (contained in extent busy) are allocated to regular files unexpectedly. When I was trying to fix that problem (still reuse busy blocks for directories), the problem here is exposed.
Quoted 2 lines
Is there some sort of
test case we could attach to this?
Hm.. I can only reproduce this with my patch. Well, the idea is that, for example,
1) we have an extent busy in the busy tree: (bno=100, len=200)
2) allocate blocks for directories from above extent busy (multiple times)
3) after the allocations, above extent busy finally becomes (bno=300, len=200) though it should become (bno=300, len=0) and should be removed from the busy tree.
4) the block 300 (in that AG) is used as metadata (directory blocks containing dir entries) and then that block is freed
5) insert the new extent busy (bno=300, len=1) to the busy tree,
in function xfs_extent_busy_insert():
61 while (*rbp) {
62 parent = *rbp;
63 busyp = rb_entry(parent, struct xfs_extent_busy, rb_node);
64
65 if (new->bno < busyp->bno) {
66 rbp = &(*rbp)->rb_left;
67 ASSERT(new->bno + new->length <= busyp->bno);
68 } else if (new->bno > busyp->bno) {
69 rbp = &(*rbp)->rb_right;
70 ASSERT(bno >= busyp->bno + busyp->length);
71 } else {
72 ASSERT(0);
73 }
74 }
Note that node (bno=300, len=200) already exists in the tree, the code hits line 72, the “else” case, and enters infinite loop.
thanks,
wengang
Quoted 9 lines
--D
Quoted 6 lines
fs/xfs/xfs_extent_busy.c +0
-0}else if (bbno < fbno) {/* * Case 8: Signature · 1 line
2.21.0 (Apple Git-122.2)
Darrick J. Wong
Reviewed-byQuoted 59 lines · Wengang Wang
Darrick,
Quoted 11 lines · Darrick J. Wong
Quoted 8 lines · Wengang Wang
In
xfs_extent_busy_update_extent()case 6 and 7, whenever bno is modified on extent busy, the relavent length has to be modified accordingly.Signed-off-by Wengang Wang <[email protected]>---
fs/xfs/xfs_extent_busy.c| 1 +1 file changed, 1 insertion(+)Quoted 11 lines
fs/xfs/xfs_extent_busy.c xfs_extent_busy_update_extent( · line 239
Quoted 9 lines
fs/xfs/xfs_extent_busy.c +1
-0@@ -236,6 +236,7 @@ xfs_extent_busy_update_extent(* */ busyp->bno = fend; + busyp->length = bend - fend;Looks correct to me, but how did you find this?
I was working with a UEK5 XFS bug where busy blocks (contained in extent busy) are allocated to regular files unexpectedly. When I was trying to fix that problem (still reuse busy blocks for directories), the problem here is exposed.
Quoted 2 lines
Is there some sort of
test case we could attach to this?Hm.. I can only reproduce this with my patch. Well, the idea is that, for example,
1) we have an extent busy in the busy tree: (bno=100, len=200)
2) allocate blocks for directories from above extent busy (multiple times)
3) after the allocations, above extent busy finally becomes (bno=300, len=200) though it should become (bno=300, len=0) and should be removed from the busy tree.
4) the block 300 (in that AG) is used as metadata (directory blocks containing dir entries) and then that block is freed
5) insert the new extent busy (bno=300, len=1) to the busy tree,
in functionxfs_extent_busy_insert():61 while (*rbp) {
62 parent = *rbp;
63 busyp =rb_entry(parent, struct xfs_extent_busy, rb_node);
64
65 if (new->bno<busyp->bno) {
66 rbp = &(*rbp)->rb_left;
67ASSERT(new->bno + new->length <= busyp->bno);
68 } else if (new->bno>busyp->bno) {
69 rbp = &(*rbp)->rb_right;
70ASSERT(bno >= busyp->bno + busyp->length);
71 } else {
72 ASSERT(0);
73 }
74 }
Quoted 2 lines
Note that node (bno=300, len=200) already exists in the tree, the code hits line 72, the “else” case, and enters infinite loop.
Hm. I /think/ it would be possible but fairly difficult to write an fstest -- you'd have to create a storage with a very slow DISCARD command, mount the fs with -o discard, fill the fs, free all the blocks, make a large directory structure, and then rmdir the directory. Those last three steps would have to happen before the discards finish.
Uh... do you think that's worth the effort? I don't think the kernel even has a dm driver to simulate a device with only slow discards.
In the meantime,
--D
Quoted 14 lines
thanks,
wengangQuoted 9 lines
--D
Quoted 6 lines
fs/xfs/xfs_extent_busy.c +0
-0}else if (bbno < fbno) {/* * Case 8: Signature · 1 line
2.21.0 (Apple Git-122.2)