// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2000-2005 Silicon Graphics, Inc.
* All Rights Reserved.
*/
#include "xfs.h"
#include "xfs_fs.h"
#include "xfs_shared.h"
#include "xfs_format.h"
#include "xfs_log_format.h"
#include "xfs_trans_resv.h"
#include "xfs_bit.h"
#include "xfs_mount.h"
#include "xfs_inode.h"
#include "xfs_alloc.h"
#include "xfs_bmap.h"
#include "xfs_bmap_btree.h"
#include "xfs_bmap_util.h"
#include "xfs_trans.h"
#include "xfs_trans_space.h"
#include "xfs_icache.h"
#include "xfs_rtalloc.h"
#include "xfs_sb.h"
#include "xfs_rtbitmap.h"
#include "xfs_quota.h"
#include "xfs_log_priv.h"
#include "xfs_health.h"
/*
* Return whether there are any free extents in the size range given
* by low and high, for the bitmap block bbno.
*/
STATIC int
xfs_rtany_summary(
struct xfs_rtalloc_args *args,
int low, /* low log2 extent size */
int high, /* high log2 extent size */
xfs_fileoff_t bbno, /* bitmap block number */
int *maxlog) /* out: max log2 extent size free */
{
struct xfs_mount *mp = args->mp;
int error;
int log; /* loop counter, log2 of ext. size */
xfs_suminfo_t sum; /* summary data */
/* There are no extents at levels >= m_rsum_cache[bbno]. */
if (mp->m_rsum_cache) {
high = min(high, mp->m_rsum_cache[bbno] - 1);
if (low > high) {
*maxlog = -1;
return 0;
}
}
/*
* Loop over logs of extent sizes.
*/
for (log = high; log >= low; log--) {
/*
* Get one summary datum.
*/
error = xfs_rtget_summary(args, log, bbno, &sum);
if (error) {
return error;
}
/*
* If there are any, return success.
*/
if (sum) {
*maxlog = log;
goto out;
}
}
/*
* Found nothing, return failure.
*/
*maxlog = -1;
out:
/* There were no extents at levels > log. */
if (mp->m_rsum_cache && log + 1 < mp->m_rsum_cac