@@ -497,6 +497,9 @@ xfs_rtallocate_extent_near(
* allocating one.
*/
if (maxlog >= 0) {
+ xfs_extlen_t maxavail =
+ min_t(xfs_rtblock_t, maxlen,
+ (1ULL << (maxlog + 1)) - 1);
/*
* On the positive side of the starting location.
*/
@@ -506,7 +509,7 @@ xfs_rtallocate_extent_near(
* this block.
*/
error = xfs_rtallocate_extent_block(args,
- bbno + i, minlen, maxlen, len,
+ bbno + i, minlen, maxavail, len,
&n, prod, &r);
if (error) {
return error;
@@ -553,7 +556,7 @@ xfs_rtallocate_extent_near(
continue;
error = xfs_rtallocate_extent_block(args,
bbno + j, minlen,
- maxlen, len, &n, prod,
+ maxavail, len, &n, prod,
&r);
if (error) {
return error;
@@ -575,7 +578,7 @@ xfs_rtallocate_extent_near(
* that we found.
*/
error = xfs_rtallocate_extent_block(args,
- bbno + i, minlen, maxlen, len,
+ bbno + i, minlen, maxavail, len,
&n, prod, &r);
if (error) {
return error;