summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2025-02-09 07:33:43 +0300
committerChristoph Hellwig <hch@lst.de>2025-03-03 18:15:48 +0300
commitcc3d2f55c43affde7195867afb7b0ee45dd8019b (patch)
treee473118f51aacf9721d2e8bef56d1d04eaca29af
parent0a1fd78080c8c9a5582e82100bd91b87ae5ac57c (diff)
downloadlinux-cc3d2f55c43affde7195867afb7b0ee45dd8019b.tar.xz
xfs: reflow xfs_dec_freecounter
Let the successful allocation be the main path through the function with exception handling in branches to make the code easier to follow. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
-rw-r--r--fs/xfs/xfs_mount.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index b69356582b86..ba6e60dc3a45 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -1257,7 +1257,6 @@ xfs_dec_freecounter(
uint64_t delta,
bool rsvd)
{
- int64_t lcounter;
uint64_t set_aside = 0;
s32 batch;
bool has_resv_pool;
@@ -1296,28 +1295,26 @@ xfs_dec_freecounter(
set_aside = xfs_fdblocks_unavailable(mp);
percpu_counter_add_batch(counter, -((int64_t)delta), batch);
if (__percpu_counter_compare(counter, set_aside,
- XFS_FDBLOCKS_BATCH) >= 0) {
- /* we had space! */
- return 0;
- }
-
- /*
- * lock up the sb for dipping into reserves before releasing the space
- * that took us to ENOSPC.
- */
- spin_lock(&mp->m_sb_lock);
- percpu_counter_add(counter, delta);
- if (!has_resv_pool || !rsvd)
- goto fdblocks_enospc;
-
- lcounter = (long long)mp->m_resblks_avail - delta;
- if (lcounter >= 0) {
- mp->m_resblks_avail = lcounter;
+ XFS_FDBLOCKS_BATCH) < 0) {
+ /*
+ * Lock up the sb for dipping into reserves before releasing the
+ * space that took us to ENOSPC.
+ */
+ spin_lock(&mp->m_sb_lock);
+ percpu_counter_add(counter, delta);
+ if (!rsvd)
+ goto fdblocks_enospc;
+ if (delta > mp->m_resblks_avail) {
+ xfs_warn_once(mp,
+"Reserve blocks depleted! Consider increasing reserve pool size.");
+ goto fdblocks_enospc;
+ }
+ mp->m_resblks_avail -= delta;
spin_unlock(&mp->m_sb_lock);
- return 0;
}
- xfs_warn_once(mp,
-"Reserve blocks depleted! Consider increasing reserve pool size.");
+
+ /* we had space! */
+ return 0;
fdblocks_enospc:
spin_unlock(&mp->m_sb_lock);