Skip to content

Commit cc3d2f5

Browse files
author
Christoph Hellwig
committed
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>
1 parent 0a1fd78 commit cc3d2f5

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

fs/xfs/xfs_mount.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,6 @@ xfs_dec_freecounter(
12571257
uint64_t delta,
12581258
bool rsvd)
12591259
{
1260-
int64_t lcounter;
12611260
uint64_t set_aside = 0;
12621261
s32 batch;
12631262
bool has_resv_pool;
@@ -1296,28 +1295,26 @@ xfs_dec_freecounter(
12961295
set_aside = xfs_fdblocks_unavailable(mp);
12971296
percpu_counter_add_batch(counter, -((int64_t)delta), batch);
12981297
if (__percpu_counter_compare(counter, set_aside,
1299-
XFS_FDBLOCKS_BATCH) >= 0) {
1300-
/* we had space! */
1301-
return 0;
1302-
}
1303-
1304-
/*
1305-
* lock up the sb for dipping into reserves before releasing the space
1306-
* that took us to ENOSPC.
1307-
*/
1308-
spin_lock(&mp->m_sb_lock);
1309-
percpu_counter_add(counter, delta);
1310-
if (!has_resv_pool || !rsvd)
1311-
goto fdblocks_enospc;
1312-
1313-
lcounter = (long long)mp->m_resblks_avail - delta;
1314-
if (lcounter >= 0) {
1315-
mp->m_resblks_avail = lcounter;
1298+
XFS_FDBLOCKS_BATCH) < 0) {
1299+
/*
1300+
* Lock up the sb for dipping into reserves before releasing the
1301+
* space that took us to ENOSPC.
1302+
*/
1303+
spin_lock(&mp->m_sb_lock);
1304+
percpu_counter_add(counter, delta);
1305+
if (!rsvd)
1306+
goto fdblocks_enospc;
1307+
if (delta > mp->m_resblks_avail) {
1308+
xfs_warn_once(mp,
1309+
"Reserve blocks depleted! Consider increasing reserve pool size.");
1310+
goto fdblocks_enospc;
1311+
}
1312+
mp->m_resblks_avail -= delta;
13161313
spin_unlock(&mp->m_sb_lock);
1317-
return 0;
13181314
}
1319-
xfs_warn_once(mp,
1320-
"Reserve blocks depleted! Consider increasing reserve pool size.");
1315+
1316+
/* we had space! */
1317+
return 0;
13211318

13221319
fdblocks_enospc:
13231320
spin_unlock(&mp->m_sb_lock);

0 commit comments

Comments
 (0)