]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - libxfs/xfs_alloc.c
Merge back recent changes from xfs kernel headers.
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_alloc.c
index 6af093941ff73ea26aa83c22d32a79e90250a6e1..1ad83c977e7264e5158da011a6d57a71592332e9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2000-2005 Silicon Graphics, Inc.  All Rights Reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of version 2 of the GNU General Public License as
@@ -536,8 +536,8 @@ xfs_alloc_ag_vextent(
                        xfs_trans_mod_sb(args->tp,
                                args->wasdel ? XFS_TRANS_SB_RES_FDBLOCKS :
                                        XFS_TRANS_SB_FDBLOCKS, -slen);
-               XFS_STATS_INC(xfsstats.xs_allocx);
-               XFS_STATS_ADD(xfsstats.xs_allocb, args->len);
+               XFS_STATS_INC(xs_allocx);
+               XFS_STATS_ADD(xs_allocb, args->len);
        }
        return 0;
 }
@@ -572,7 +572,7 @@ xfs_alloc_ag_vextent_exact(
         * Allocate/initialize a cursor for the by-number freespace btree.
         */
        bno_cur = xfs_btree_init_cursor(args->mp, args->tp, args->agbp,
-               args->agno, XFS_BTNUM_BNO, 0, 0);
+               args->agno, XFS_BTNUM_BNO, NULL, 0);
        /*
         * Lookup bno and minlen in the btree (minlen is irrelevant, really).
         * Look for the closest free block <= bno, it must contain bno
@@ -628,7 +628,7 @@ xfs_alloc_ag_vextent_exact(
         * Allocate/initialize a cursor for the by-size btree.
         */
        cnt_cur = xfs_btree_init_cursor(args->mp, args->tp, args->agbp,
-               args->agno, XFS_BTNUM_CNT, 0, 0);
+               args->agno, XFS_BTNUM_CNT, NULL, 0);
        ASSERT(args->agbno + args->len <=
                INT_GET(XFS_BUF_TO_AGF(args->agbp)->agf_length,
                        ARCH_CONVERT));
@@ -687,21 +687,15 @@ xfs_alloc_ag_vextent_near(
        /*
         * Randomly don't execute the first algorithm.
         */
-       static int      seed;           /* randomizing seed value */
        int             dofirst;        /* set to do first algorithm */
-       timespec_t      now;            /* current time */
 
-       if (!seed) {
-               nanotime(&now);
-               seed = (int)now.tv_sec ^ (int)now.tv_nsec;
-       }
        dofirst = random() & 1;
 #endif
        /*
         * Get a cursor for the by-size btree.
         */
        cnt_cur = xfs_btree_init_cursor(args->mp, args->tp, args->agbp,
-               args->agno, XFS_BTNUM_CNT, 0, 0);
+               args->agno, XFS_BTNUM_CNT, NULL, 0);
        ltlen = 0;
        bno_cur_lt = bno_cur_gt = NULL;
        /*
@@ -829,7 +823,7 @@ xfs_alloc_ag_vextent_near(
                 * Set up a cursor for the by-bno tree.
                 */
                bno_cur_lt = xfs_btree_init_cursor(args->mp, args->tp,
-                       args->agbp, args->agno, XFS_BTNUM_BNO, 0, 0);
+                       args->agbp, args->agno, XFS_BTNUM_BNO, NULL, 0);
                /*
                 * Fix up the btree entries.
                 */
@@ -857,7 +851,7 @@ xfs_alloc_ag_vextent_near(
         * Allocate and initialize the cursor for the leftward search.
         */
        bno_cur_lt = xfs_btree_init_cursor(args->mp, args->tp, args->agbp,
-               args->agno, XFS_BTNUM_BNO, 0, 0);
+               args->agno, XFS_BTNUM_BNO, NULL, 0);
        /*
         * Lookup <= bno to find the leftward search's starting point.
         */
@@ -869,7 +863,7 @@ xfs_alloc_ag_vextent_near(
                 * search.
                 */
                bno_cur_gt = bno_cur_lt;
-               bno_cur_lt = 0;
+               bno_cur_lt = NULL;
        }
        /*
         * Found something.  Duplicate the cursor for the rightward search.
@@ -1214,7 +1208,7 @@ xfs_alloc_ag_vextent_size(
         * Allocate and initialize a cursor for the by-size btree.
         */
        cnt_cur = xfs_btree_init_cursor(args->mp, args->tp, args->agbp,
-               args->agno, XFS_BTNUM_CNT, 0, 0);
+               args->agno, XFS_BTNUM_CNT, NULL, 0);
        bno_cur = NULL;
        /*
         * Look for an entry >= maxlen+alignment-1 blocks.
@@ -1319,7 +1313,7 @@ xfs_alloc_ag_vextent_size(
         * Allocate and initialize a cursor for the by-block tree.
         */
        bno_cur = xfs_btree_init_cursor(args->mp, args->tp, args->agbp,
-               args->agno, XFS_BTNUM_BNO, 0, 0);
+               args->agno, XFS_BTNUM_BNO, NULL, 0);
        if ((error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen,
                        rbno, rlen, XFSA_FIXUP_CNT_OK)))
                goto error0;
@@ -1381,7 +1375,8 @@ xfs_alloc_ag_vextent_small(
        else if (args->minlen == 1 && args->alignment == 1 && !args->isfl &&
                 (INT_GET(XFS_BUF_TO_AGF(args->agbp)->agf_flcount,
                        ARCH_CONVERT) > args->minleft)) {
-               if ((error = xfs_alloc_get_freelist(args->tp, args->agbp, &fbno)))
+               error = xfs_alloc_get_freelist(args->tp, args->agbp, &fbno);
+               if (error)
                        goto error0;
                if (fbno != NULLAGBLOCK) {
                        if (args->userdata) {
@@ -1466,7 +1461,7 @@ xfs_free_ag_extent(
        /*
         * Allocate and initialize a cursor for the by-block btree.
         */
-       bno_cur = xfs_btree_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_BNO, 0,
+       bno_cur = xfs_btree_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_BNO, NULL,
                0);
        cnt_cur = NULL;
        /*
@@ -1526,7 +1521,7 @@ xfs_free_ag_extent(
        /*
         * Now allocate and initialize a cursor for the by-size tree.
         */
-       cnt_cur = xfs_btree_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_CNT, 0,
+       cnt_cur = xfs_btree_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_CNT, NULL,
                0);
        /*
         * Have both left and right contiguous neighbors.
@@ -1681,8 +1676,8 @@ xfs_free_ag_extent(
                xfs_alloc_log_agf(tp, agbp, XFS_AGF_FREEBLKS);
                if (!isfl)
                        xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, (long)len);
-               XFS_STATS_INC(xfsstats.xs_freex);
-               XFS_STATS_ADD(xfsstats.xs_freeb, len);
+               XFS_STATS_INC(xs_freex);
+               XFS_STATS_ADD(xs_freeb, len);
        }
        TRACE_FREE(haveleft ?
                        (haveright ? "both" : "left") :
@@ -1923,7 +1918,7 @@ xfs_alloc_get_freelist(
        /*
         * Freelist is empty, give up.
         */
-       if (INT_ISZERO(agf->agf_flcount, ARCH_CONVERT)) {
+       if (!agf->agf_flcount) {
                *bnop = NULLAGBLOCK;
                return 0;
        }
@@ -1942,7 +1937,7 @@ xfs_alloc_get_freelist(
        INT_MOD(agf->agf_flfirst, ARCH_CONVERT, 1);
        xfs_trans_brelse(tp, agflbp);
        if (INT_GET(agf->agf_flfirst, ARCH_CONVERT) == XFS_AGFL_SIZE(mp))
-               INT_ZERO(agf->agf_flfirst, ARCH_CONVERT);
+               agf->agf_flfirst = 0;
        pag = &mp->m_perag[INT_GET(agf->agf_seqno, ARCH_CONVERT)];
        INT_MOD(agf->agf_flcount, ARCH_CONVERT, -1);
        xfs_trans_agflist_delta(tp, -1);
@@ -2042,7 +2037,7 @@ xfs_alloc_put_freelist(
        agfl = XFS_BUF_TO_AGFL(agflbp);
        INT_MOD(agf->agf_fllast, ARCH_CONVERT, 1);
        if (INT_GET(agf->agf_fllast, ARCH_CONVERT) == XFS_AGFL_SIZE(mp))
-               INT_ZERO(agf->agf_fllast, ARCH_CONVERT);
+               agf->agf_fllast = 0;
        pag = &mp->m_perag[INT_GET(agf->agf_seqno, ARCH_CONVERT)];
        INT_MOD(agf->agf_flcount, ARCH_CONVERT, 1);
        xfs_trans_agflist_delta(tp, 1);
@@ -2161,6 +2156,7 @@ xfs_alloc_vextent(
        xfs_alloctype_t type;   /* input allocation type */
        int             bump_rotor = 0;
        int             no_min = 0;
+       xfs_agnumber_t  rotorstep = xfs_rotorstep; /* inode32 agf stepper */
 
        mp = args->mp;
        type = args->otype = args->type;
@@ -2224,7 +2220,9 @@ xfs_alloc_vextent(
                 */
                if ((args->userdata  == XFS_ALLOC_INITIAL_USER_DATA) &&
                    (mp->m_flags & XFS_MOUNT_32BITINODES)) {
-                       args->fsbno = XFS_AGB_TO_FSB(mp, mp->m_agfrotor, 0);
+                       args->fsbno = XFS_AGB_TO_FSB(mp,
+                                       ((mp->m_agfrotor / rotorstep) %
+                                       mp->m_sb.sb_agcount), 0);
                        bump_rotor = 1;
                }
                args->agbno = XFS_FSB_TO_AGBNO(mp, args->fsbno);
@@ -2240,7 +2238,8 @@ xfs_alloc_vextent(
                        /*
                         * Start with the last place we left off.
                         */
-                       args->agno = sagno = mp->m_agfrotor;
+                       args->agno = sagno = (mp->m_agfrotor / rotorstep) %
+                                       mp->m_sb.sb_agcount;
                        args->type = XFS_ALLOCTYPE_THIS_AG;
                        flags = XFS_ALLOC_FLAG_TRYLOCK;
                } else if (type == XFS_ALLOCTYPE_FIRST_AG) {
@@ -2314,8 +2313,14 @@ xfs_alloc_vextent(
                        }
                }
                up_read(&mp->m_peraglock);
-               if (bump_rotor || (type == XFS_ALLOCTYPE_ANY_AG))
-                       mp->m_agfrotor = (args->agno + 1) % mp->m_sb.sb_agcount;
+               if (bump_rotor || (type == XFS_ALLOCTYPE_ANY_AG)) {
+                       if (args->agno == sagno)
+                               mp->m_agfrotor = (mp->m_agfrotor + 1) %
+                                       (mp->m_sb.sb_agcount * rotorstep);
+                       else
+                               mp->m_agfrotor = (args->agno * rotorstep + 1) %
+                                       (mp->m_sb.sb_agcount * rotorstep);
+               }
                break;
        default:
                ASSERT(0);