Unverified Commit b8bd7598 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!14112 xfs: Fix data overflow

Merge Pull Request from: @ci-robot 
 
PR sync from: Zizhi Wo <wozizhi@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/FSXKZXOWNUF3CRK55MBI63UYO7IJKERL/ 
*** BLURB HERE ***

Zizhi Wo (2):
  Revert "xfs: split xfs_mod_freecounter"
  xfs: Fix data overflow in xfs_mod_fdblocks()


-- 
2.46.1
 
https://gitee.com/openeuler/kernel/issues/IB7V02 
 
Link:https://gitee.com/openeuler/kernel/pulls/14112

 

Reviewed-by: default avatarZhang Peng <zhangpeng362@huawei.com>
Signed-off-by: default avatarZhang Peng <zhangpeng362@huawei.com>
parents 1a1806f7 82b452b0
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -967,7 +967,9 @@ xfs_ag_shrink_space(
	 * Disable perag reservations so it doesn't cause the allocation request
	 * to fail. We'll reestablish reservation before we return.
	 */
	xfs_ag_resv_free(pag);
	error = xfs_ag_resv_free(pag);
	if (error)
		return error;

	/* internal log shouldn't also show up in the free space btrees */
	error = xfs_alloc_vextent_exact_bno(&args,
+18 −6
Original line number Diff line number Diff line
@@ -126,13 +126,14 @@ xfs_ag_resv_needed(
}

/* Clean out a reservation */
static void
static int
__xfs_ag_resv_free(
	struct xfs_perag		*pag,
	enum xfs_ag_resv_type		type)
{
	struct xfs_ag_resv		*resv;
	xfs_extlen_t			oldresv;
	int				error;

	trace_xfs_ag_resv_free(pag, type, 0);

@@ -148,19 +149,30 @@ __xfs_ag_resv_free(
		oldresv = resv->ar_orig_reserved;
	else
		oldresv = resv->ar_reserved;
	xfs_add_fdblocks(pag->pag_mount, oldresv);
	error = xfs_mod_fdblocks(pag->pag_mount, oldresv, true);
	resv->ar_reserved = 0;
	resv->ar_asked = 0;
	resv->ar_orig_reserved = 0;

	if (error)
		trace_xfs_ag_resv_free_error(pag->pag_mount, pag->pag_agno,
				error, _RET_IP_);
	return error;
}

/* Free a per-AG reservation. */
void
int
xfs_ag_resv_free(
	struct xfs_perag		*pag)
{
	__xfs_ag_resv_free(pag, XFS_AG_RESV_RMAPBT);
	__xfs_ag_resv_free(pag, XFS_AG_RESV_METADATA);
	int				error;
	int				err2;

	error = __xfs_ag_resv_free(pag, XFS_AG_RESV_RMAPBT);
	err2 = __xfs_ag_resv_free(pag, XFS_AG_RESV_METADATA);
	if (err2 && !error)
		error = err2;
	return error;
}

static int
@@ -204,7 +216,7 @@ __xfs_ag_resv_init(
	if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_AG_RESV_FAIL))
		error = -ENOSPC;
	else
		error = xfs_dec_fdblocks(mp, hidden_space, true);
		error = xfs_mod_fdblocks(mp, -(int64_t)hidden_space, true);
	if (error) {
		trace_xfs_ag_resv_init_error(pag->pag_mount, pag->pag_agno,
				error, _RET_IP_);
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
#ifndef __XFS_AG_RESV_H__
#define	__XFS_AG_RESV_H__

void xfs_ag_resv_free(struct xfs_perag *pag);
int xfs_ag_resv_free(struct xfs_perag *pag);
int xfs_ag_resv_init(struct xfs_perag *pag, struct xfs_trans *tp);

bool xfs_ag_resv_critical(struct xfs_perag *pag, enum xfs_ag_resv_type type);
+2 −2
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ xfs_prealloc_blocks(
}

/*
 * The number of blocks per AG that we withhold from xfs_dec_fdblocks to
 * The number of blocks per AG that we withhold from xfs_mod_fdblocks to
 * guarantee that we can refill the AGFL prior to allocating space in a nearly
 * full AG.  Although the space described by the free space btrees, the
 * blocks used by the freesp btrees themselves, and the blocks owned by the
@@ -89,7 +89,7 @@ xfs_prealloc_blocks(
 * until the fs goes down, we subtract this many AG blocks from the incore
 * fdblocks to ensure user allocation does not overcommit the space the
 * filesystem needs for the AGFLs.  The rmap btree uses a per-AG reservation to
 * withhold space from xfs_dec_fdblocks, so we do not account for that here.
 * withhold space from xfs_mod_fdblocks, so we do not account for that here.
 */
#define XFS_ALLOCBT_AGFL_RESERVE	4

+10 −11
Original line number Diff line number Diff line
@@ -1941,10 +1941,9 @@ xfs_bmap_add_extent_delay_real(
	}

	/* adjust for changes in reserved delayed indirect blocks */
	if (da_new < da_old)
		xfs_add_fdblocks(mp, da_old - da_new);
	else if (da_new > da_old)
		error = xfs_dec_fdblocks(mp, da_new - da_old, true);
	if (da_new != da_old)
		error = xfs_mod_fdblocks(mp, (int64_t)(da_old - da_new),
				true);

	xfs_bmap_check_leaf_extents(bma->cur, bma->ip, whichfork);
done:
@@ -2622,8 +2621,8 @@ xfs_bmap_add_extent_hole_delay(
	}
	if (oldlen != newlen) {
		ASSERT(oldlen > newlen);
		xfs_add_fdblocks(ip->i_mount, oldlen - newlen);

		xfs_mod_fdblocks(ip->i_mount, (int64_t)(oldlen - newlen),
				 false);
		/*
		 * Nothing to do for disk quota accounting here.
		 */
@@ -4029,11 +4028,11 @@ xfs_bmapi_reserve_delalloc(
	indlen = (xfs_extlen_t)xfs_bmap_worst_indlen(ip, alen);
	ASSERT(indlen > 0);

	error = xfs_dec_fdblocks(mp, alen, false);
	error = xfs_mod_fdblocks(mp, -((int64_t)alen), false);
	if (error)
		goto out_unreserve_quota;

	error = xfs_dec_fdblocks(mp, indlen, false);
	error = xfs_mod_fdblocks(mp, -((int64_t)indlen), false);
	if (error)
		goto out_unreserve_blocks;

@@ -4061,7 +4060,7 @@ xfs_bmapi_reserve_delalloc(
	return 0;

out_unreserve_blocks:
	xfs_add_fdblocks(mp, alen);
	xfs_mod_fdblocks(mp, alen, false);
out_unreserve_quota:
	if (XFS_IS_QUOTA_ON(mp))
		xfs_quota_unreserve_blkres(ip, alen);
@@ -4920,7 +4919,7 @@ xfs_bmap_del_extent_delay(
		uint64_t	rtexts = del->br_blockcount;

		do_div(rtexts, mp->m_sb.sb_rextsize);
		xfs_add_frextents(mp, rtexts);
		xfs_mod_frextents(mp, rtexts);
	}

	/*
@@ -5008,7 +5007,7 @@ xfs_bmap_del_extent_delay(
	if (!isrt)
		da_diff += del->br_blockcount;
	if (da_diff) {
		xfs_add_fdblocks(mp, da_diff);
		xfs_mod_fdblocks(mp, da_diff, false);
		xfs_mod_delalloc(mp, -da_diff);
	}
	return error;
Loading