]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - fs/xfs/libxfs/xfs_ialloc.c
xfs: fix inobt inode allocation search optimization
[mirror_ubuntu-bionic-kernel.git] / fs / xfs / libxfs / xfs_ialloc.c
index f272abff11e142cb7febbbaf4760daa528ed922f..abf5beaae907d32b484128f182bee2d1d7a7cd9e 100644 (file)
 /*
  * Allocation group level functions.
  */
-static inline int
+int
 xfs_ialloc_cluster_alignment(
        struct xfs_mount        *mp)
 {
        if (xfs_sb_version_hasalign(&mp->m_sb) &&
-           mp->m_sb.sb_inoalignmt >=
-                       XFS_B_TO_FSBT(mp, mp->m_inode_cluster_size))
+           mp->m_sb.sb_inoalignmt >= xfs_icluster_size_fsb(mp))
                return mp->m_sb.sb_inoalignmt;
        return 1;
 }
@@ -99,24 +98,15 @@ xfs_inobt_update(
        return xfs_btree_update(cur, &rec);
 }
 
-/*
- * Get the data from the pointed-to record.
- */
-int                                    /* error */
-xfs_inobt_get_rec(
-       struct xfs_btree_cur    *cur,   /* btree cursor */
-       xfs_inobt_rec_incore_t  *irec,  /* btree record */
-       int                     *stat)  /* output: success/failure */
+/* Convert on-disk btree record to incore inobt record. */
+void
+xfs_inobt_btrec_to_irec(
+       struct xfs_mount                *mp,
+       union xfs_btree_rec             *rec,
+       struct xfs_inobt_rec_incore     *irec)
 {
-       union xfs_btree_rec     *rec;
-       int                     error;
-
-       error = xfs_btree_get_rec(cur, &rec, stat);
-       if (error || *stat == 0)
-               return error;
-
        irec->ir_startino = be32_to_cpu(rec->inobt.ir_startino);
-       if (xfs_sb_version_hassparseinodes(&cur->bc_mp->m_sb)) {
+       if (xfs_sb_version_hassparseinodes(&mp->m_sb)) {
                irec->ir_holemask = be16_to_cpu(rec->inobt.ir_u.sp.ir_holemask);
                irec->ir_count = rec->inobt.ir_u.sp.ir_count;
                irec->ir_freecount = rec->inobt.ir_u.sp.ir_freecount;
@@ -131,6 +121,25 @@ xfs_inobt_get_rec(
                                be32_to_cpu(rec->inobt.ir_u.f.ir_freecount);
        }
        irec->ir_free = be64_to_cpu(rec->inobt.ir_free);
+}
+
+/*
+ * Get the data from the pointed-to record.
+ */
+int
+xfs_inobt_get_rec(
+       struct xfs_btree_cur            *cur,
+       struct xfs_inobt_rec_incore     *irec,
+       int                             *stat)
+{
+       union xfs_btree_rec             *rec;
+       int                             error;
+
+       error = xfs_btree_get_rec(cur, &rec, stat);
+       if (error || *stat == 0)
+               return error;
+
+       xfs_inobt_btrec_to_irec(cur->bc_mp, rec, irec);
 
        return 0;
 }
@@ -141,9 +150,9 @@ xfs_inobt_get_rec(
 STATIC int
 xfs_inobt_insert_rec(
        struct xfs_btree_cur    *cur,
-       __uint16_t              holemask,
-       __uint8_t               count,
-       __int32_t               freecount,
+       uint16_t                holemask,
+       uint8_t                 count,
+       int32_t                 freecount,
        xfs_inofree_t           free,
        int                     *stat)
 {
@@ -1237,13 +1246,13 @@ xfs_dialloc_ag_inobt(
 
                        /* free inodes to the left? */
                        if (useleft && trec.ir_freecount) {
-                               rec = trec;
                                xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
                                cur = tcur;
 
                                pag->pagl_leftrec = trec.ir_startino;
                                pag->pagl_rightrec = rec.ir_startino;
                                pag->pagl_pagino = pagino;
+                               rec = trec;
                                goto alloc_inode;
                        }
 
@@ -2543,8 +2552,7 @@ xfs_agi_read_verify(
            !xfs_buf_verify_cksum(bp, XFS_AGI_CRC_OFF))
                xfs_buf_ioerror(bp, -EFSBADCRC);
        else if (XFS_TEST_ERROR(!xfs_agi_verify(bp), mp,
-                               XFS_ERRTAG_IALLOC_READ_AGI,
-                               XFS_RANDOM_IALLOC_READ_AGI))
+                               XFS_ERRTAG_IALLOC_READ_AGI))
                xfs_buf_ioerror(bp, -EFSCORRUPTED);
 
        if (bp->b_error)