@@ -491,6 +491,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.
*/
@@ -500,7 +503,7 @@ xfs_rtallocate_extent_near(
* this block.
*/
error = xfs_rtallocate_extent_block(mp, tp,
- bbno + i, minlen, maxlen, len, &n,
+ bbno + i, minlen, maxavail, len, &n,
rtbufc, prod, &r);
if (error) {
return error;
@@ -545,7 +548,7 @@ xfs_rtallocate_extent_near(
if (maxlog >= 0)
continue;
error = xfs_rtallocate_extent_block(mp,
- tp, bbno + j, minlen, maxlen,
+ tp, bbno + j, minlen, maxavail,
len, &n, rtbufc, prod, &r);
if (error) {
return error;
@@ -567,7 +570,7 @@ xfs_rtallocate_extent_near(
* that we found.
*/
error = xfs_rtallocate_extent_block(mp, tp,
- bbno + i, minlen, maxlen, len, &n,
+ bbno + i, minlen, maxavail, len, &n,
rtbufc, prod, &r);
if (error) {
return error;