Skip to content

Commit

Permalink
maple_tree: reload mas before the second call for mas_empty_area
Browse files Browse the repository at this point in the history
Change the LONG_MAX in simple_offset_add to 1024, and do latter:

[root@fedora ~]# mkdir /tmp/dir
[root@fedora ~]# for i in {1..1024}; do touch /tmp/dir/$i; done
touch: cannot touch '/tmp/dir/1024': Device or resource busy
[root@fedora ~]# rm /tmp/dir/123
[root@fedora ~]# touch /tmp/dir/1024
[root@fedora ~]# rm /tmp/dir/100
[root@fedora ~]# touch /tmp/dir/1025
touch: cannot touch '/tmp/dir/1025': Device or resource busy

After we delete file 100, actually this is a empty entry, but the latter
create failed unexpected.

mas_alloc_cyclic has two chance to find empty entry.  First find the entry
with range range_lo and range_hi, if no empty entry exist, and range_lo >
min, retry find with range min and range_hi.  However, the first call
mas_empty_area may mark mas as EBUSY, and the second call for
mas_empty_area will return false directly.  Fix this by reload mas before
second call for mas_empty_area.

[[email protected]: fix mas_alloc_cyclic() second search]
  Link: https://lore.kernel.org/all/[email protected]/
  Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Fixes: 9b6713c ("maple_tree: Add mtree_alloc_cyclic()")
Signed-off-by: Yang Erkun <[email protected]>
Signed-off-by: Liam R. Howlett <[email protected]>
Cc: Christian Brauner <[email protected]>
Cc: Chuck Lever <[email protected]> says:
Cc: Liam R. Howlett <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Yang Erkun authored and akpm00 committed Dec 31, 2024
1 parent 158cdce commit 1fd8bc7
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/maple_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -4354,6 +4354,7 @@ int mas_alloc_cyclic(struct ma_state *mas, unsigned long *startp,
ret = 1;
}
if (ret < 0 && range_lo > min) {
mas_reset(mas);
ret = mas_empty_area(mas, min, range_hi, 1);
if (ret == 0)
ret = 1;
Expand Down

0 comments on commit 1fd8bc7

Please sign in to comment.