]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: reflow xfs_dec_freecounter
authorChristoph Hellwig <hch@lst.de>
Fri, 31 Jan 2025 06:23:35 +0000 (07:23 +0100)
committerChristoph Hellwig <hch@lst.de>
Mon, 3 Feb 2025 04:49:07 +0000 (05:49 +0100)
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>
fs/xfs/xfs_mount.c

index 26793d4f2707e18208c2c1c457234b4dae22e744..65123f4ffc2a6ca20ab653b7d02d9694dd8e2b69 100644 (file)
@@ -1329,28 +1329,29 @@ xfs_dec_freecounter(
        set_aside = xfs_freecounter_unavailable(mp, ctr);
        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 (!rsvd)
-               goto fdblocks_enospc;
+                       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;
+
+               lcounter = (long long)mp->m_resblks[ctr].avail - delta;
+               if (lcounter < 0) {
+                       xfs_warn_once(mp,
+"Reserve blocks depleted! Consider increasing reserve pool size.");
+                       goto fdblocks_enospc;
+               }
 
-       lcounter = (long long)mp->m_resblks[ctr].avail - delta;
-       if (lcounter >= 0) {
                mp->m_resblks[ctr].avail = lcounter;
                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);