From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EF43146588 for ; Mon, 22 Apr 2024 11:20:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713784842; cv=none; b=JyHgBrYyNQ+eYnlGFh+Jfoh45Ti9ytHnUQaqpEA4KJNRZOb8lHExkk1/Tgdyxj53np1zqmvU6zquY8K9nqslNilJBHAuhO9Citb2QfkavaddC0NfTUphWktV2K7bTcGh/jlIzgXPZc+UkBdMV7xrQaDlPvVEa65k7tk8bxAxUUI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713784842; c=relaxed/simple; bh=4iWujezjmpYeE3HTmZXnhueAUrxSJn4/vpYuOobdziY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=azSzdPqmeIuJnWuLxBEUkyBYCbOmYxin8LPViNEmdWDqHZKaI1XnARzIsTyrySJ32NvsLMK7OygJjj26iPIHrwgm9DgCMF9sE1cMxL0lLDmCls7aM8Kie/J7sFHTpmJHK98eHzV6gsgmLc28zY5ZjXijkIgzjYyTi+eBcyQUPY4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=iBwsdH2t; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="iBwsdH2t" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=2EPW0FDOQMsf3+Z86v83ceyLO8enkMXYSJjRbALRVu0=; b=iBwsdH2tNKiPHyLxLY091FSFdA inidsCKP4C3zszasX07yUMN4Zb+hn+GG7j12lDhjcm/WTz/SWIX3+fRj2s6+akIyYG5uetPF7zY0h 6amRA8RxOdDM0Qjz+eLKASeidGJju0hVl3wiUq9bUnRBjsh0YAaREUXNtCKmYuymOJ+7UxNXWa/7A CXCxf5i1hXufT/Zl70V4uc1LCMO4Vnwe/xCycOHoNZezj/ZyKPJwVOcQ2eHGN9yTpb3ChN4a7dq8U VFaYIDJHDLpU7x+GS8PDzd1LYXecBSj5RbaT5AI5VtbSVJl/hy+neQwXRUZ5XdEz/Qr1uqGFFQ4iZ 7psLDtCw==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1ryriy-0000000DL8Y-1yD2; Mon, 22 Apr 2024 11:20:40 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , Dave Chinner , linux-xfs@vger.kernel.org, Dave Chinner Subject: [PATCH 05/13] xfs: block deltas in xfs_trans_unreserve_and_mod_sb must be positive Date: Mon, 22 Apr 2024 13:20:11 +0200 Message-Id: <20240422112019.212467-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240422112019.212467-1-hch@lst.de> References: <20240422112019.212467-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html And to make that more clear, rearrange the code a bit and add asserts and a comment. Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_trans.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index 50d878d78a5e11..95921ad935477f 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -594,28 +594,38 @@ xfs_trans_unreserve_and_mod_sb( { struct xfs_mount *mp = tp->t_mountp; bool rsvd = (tp->t_flags & XFS_TRANS_RESERVE) != 0; - int64_t blkdelta = 0; - int64_t rtxdelta = 0; + int64_t blkdelta = tp->t_blk_res; + int64_t rtxdelta = tp->t_rtx_res; int64_t idelta = 0; int64_t ifreedelta = 0; int error; - /* calculate deltas */ - if (tp->t_blk_res > 0) - blkdelta = tp->t_blk_res; - if ((tp->t_fdblocks_delta != 0) && - (xfs_has_lazysbcount(mp) || - (tp->t_flags & XFS_TRANS_SB_DIRTY))) + /* + * Calculate the deltas. + * + * t_fdblocks_delta and t_frextents_delta can be positive or negative: + * + * - positive values indicate blocks freed in the transaction. + * - negative values indicate blocks allocated in the transaction + * + * Negative values can only happen if the transaction has a block + * reservation that covers the allocated block. The end result is + * that the calculated delta values must always be positive and we + * can only put back previous allocated or reserved blocks here. + */ + ASSERT(tp->t_blk_res || tp->t_fdblocks_delta >= 0); + if (xfs_has_lazysbcount(mp) || (tp->t_flags & XFS_TRANS_SB_DIRTY)) { blkdelta += tp->t_fdblocks_delta; + ASSERT(blkdelta >= 0); + } - if (tp->t_rtx_res > 0) - rtxdelta = tp->t_rtx_res; - if ((tp->t_frextents_delta != 0) && - (tp->t_flags & XFS_TRANS_SB_DIRTY)) + ASSERT(tp->t_rtx_res || tp->t_frextents_delta >= 0); + if (tp->t_flags & XFS_TRANS_SB_DIRTY) { rtxdelta += tp->t_frextents_delta; + ASSERT(rtxdelta >= 0); + } - if (xfs_has_lazysbcount(mp) || - (tp->t_flags & XFS_TRANS_SB_DIRTY)) { + if (xfs_has_lazysbcount(mp) || (tp->t_flags & XFS_TRANS_SB_DIRTY)) { idelta = tp->t_icount_delta; ifreedelta = tp->t_ifree_delta; } -- 2.39.2