]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: simplify xfs_dialloc_select_ag() return values
authorDave Chinner <dchinner@redhat.com>
Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Fri, 15 Oct 2021 20:28:26 +0000 (16:28 -0400)
Source kernel commit: 4268547305c91b35ae7871374078de788a822ed1

The only caller of xfs_dialloc_select_ag() will always return
-ENOSPC to it's caller if the agbp returned from
xfs_dialloc_select_ag() is NULL. IOWs, failure to find a candidate
AGI we can allocate inodes from is always an ENOSPC condition, so
move this logic up into xfs_dialloc_select_ag() so we can simplify
the return logic in this function.

xfs_dialloc_select_ag() now only ever returns 0 with a locked
agbp, or an error with no agbp.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_ialloc.c

index b6652be3a8962c9d924a035001b642c5ea9d0b75..15785417ab311f62a3fe7a3452e2e4b256edfed4 100644 (file)
@@ -1712,7 +1712,7 @@ xfs_dialloc_roll(
  * This function will ensure that the selected AG has free inodes available to
  * allocate from. The selected AGI will be returned locked to the caller, and it
  * will allocate more free inodes if required. If no free inodes are found or
- * can be allocated, no AGI will be returned.
+ * can be allocated, -ENOSPC be returned.
  */
 int
 xfs_dialloc_select_ag(
@@ -1725,7 +1725,6 @@ xfs_dialloc_select_ag(
        struct xfs_buf          *agbp;
        xfs_agnumber_t          agno;
        int                     error;
-       bool                    noroom = false;
        xfs_agnumber_t          start_agno;
        struct xfs_perag        *pag;
        struct xfs_ino_geometry *igeo = M_IGEO(mp);
@@ -1739,7 +1738,7 @@ xfs_dialloc_select_ag(
         */
        start_agno = xfs_ialloc_ag_select(*tpp, parent, mode);
        if (start_agno == NULLAGNUMBER)
-               return 0;
+               return -ENOSPC;
 
        /*
         * If we have already hit the ceiling of inode blocks then clear
@@ -1752,7 +1751,6 @@ xfs_dialloc_select_ag(
        if (igeo->maxicount &&
            percpu_counter_read_positive(&mp->m_icount) + igeo->ialloc_inos
                                                        > igeo->maxicount) {
-               noroom = true;
                okalloc = false;
        }
 
@@ -1789,10 +1787,8 @@ xfs_dialloc_select_ag(
                if (error)
                        break;
 
-               if (pag->pagi_freecount) {
-                       xfs_perag_put(pag);
+               if (pag->pagi_freecount)
                        goto found_ag;
-               }
 
                if (!okalloc)
                        goto nextag_relse_buffer;
@@ -1800,9 +1796,6 @@ xfs_dialloc_select_ag(
                error = xfs_ialloc_ag_alloc(*tpp, agbp, pag);
                if (error < 0) {
                        xfs_trans_brelse(*tpp, agbp);
-
-                       if (error == -ENOSPC)
-                               error = 0;
                        break;
                }
 
@@ -1813,12 +1806,11 @@ xfs_dialloc_select_ag(
                         * allocate one of the new inodes.
                         */
                        ASSERT(pag->pagi_freecount > 0);
-                       xfs_perag_put(pag);
 
                        error = xfs_dialloc_roll(tpp, agbp);
                        if (error) {
                                xfs_buf_relse(agbp);
-                               return error;
+                               break;
                        }
                        goto found_ag;
                }
@@ -1826,16 +1818,17 @@ xfs_dialloc_select_ag(
 nextag_relse_buffer:
                xfs_trans_brelse(*tpp, agbp);
 nextag:
-               xfs_perag_put(pag);
                if (++agno == mp->m_sb.sb_agcount)
                        agno = 0;
                if (agno == start_agno)
-                       return noroom ? -ENOSPC : 0;
+                       break;
+               xfs_perag_put(pag);
        }
 
        xfs_perag_put(pag);
-       return error;
+       return error ? error : -ENOSPC;
 found_ag:
+       xfs_perag_put(pag);
        *IO_agbp = agbp;
        return 0;
 }