maple_tree: reload mas before the second call for mas_empty_area

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.

Link: https://lkml.kernel.org/r/20241214093005.72284-1-yangerkun@huaweicloud.com
Fixes: 9b6713cc75 ("maple_tree: Add mtree_alloc_cyclic()")
Signed-off-by: Yang Erkun <yangerkun@huawei.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Chuck Lever <chuck.lever@oracle.com> says:
Cc: Liam R. Howlett <Liam.Howlett@Oracle.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
Yang Erkun 2024-12-14 17:30:05 +08:00 committed by Andrew Morton
parent c48259ba9e
commit d261e00f29

View File

@ -4346,6 +4346,7 @@ int mas_alloc_cyclic(struct ma_state *mas, unsigned long *startp,
{ {
unsigned long min = range_lo; unsigned long min = range_lo;
int ret = 0; int ret = 0;
struct ma_state m = *mas;
range_lo = max(min, *next); range_lo = max(min, *next);
ret = mas_empty_area(mas, range_lo, range_hi, 1); ret = mas_empty_area(mas, range_lo, range_hi, 1);
@ -4354,6 +4355,7 @@ int mas_alloc_cyclic(struct ma_state *mas, unsigned long *startp,
ret = 1; ret = 1;
} }
if (ret < 0 && range_lo > min) { if (ret < 0 && range_lo > min) {
*mas = m;
ret = mas_empty_area(mas, min, range_hi, 1); ret = mas_empty_area(mas, min, range_hi, 1);
if (ret == 0) if (ret == 0)
ret = 1; ret = 1;