]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - libxfs/xfs_dir2_block.c
xfs: move local to extent inode logging into bmap helper
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_dir2_block.c
index d1ffdb391aaf7417b1cf3a0e414f6edf7613d021..eea894fd82fa872ae7070ce31c6a540ade11a8f7 100644 (file)
@@ -6,19 +6,17 @@
  */
 #include "libxfs_priv.h"
 #include "xfs_fs.h"
+#include "xfs_shared.h"
 #include "xfs_format.h"
 #include "xfs_log_format.h"
 #include "xfs_trans_resv.h"
 #include "xfs_mount.h"
-#include "xfs_da_format.h"
-#include "xfs_da_btree.h"
 #include "xfs_inode.h"
 #include "xfs_trans.h"
 #include "xfs_bmap.h"
 #include "xfs_dir2.h"
 #include "xfs_dir2_priv.h"
 #include "xfs_trace.h"
-#include "xfs_cksum.h"
 
 /*
  * Local function prototypes.
@@ -46,21 +44,19 @@ static xfs_failaddr_t
 xfs_dir3_block_verify(
        struct xfs_buf          *bp)
 {
-       struct xfs_mount        *mp = bp->b_target->bt_mount;
+       struct xfs_mount        *mp = bp->b_mount;
        struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr;
 
+       if (!xfs_verify_magic(bp, hdr3->magic))
+               return __this_address;
+
        if (xfs_sb_version_hascrc(&mp->m_sb)) {
-               if (hdr3->magic != cpu_to_be32(XFS_DIR3_BLOCK_MAGIC))
-                       return __this_address;
                if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_meta_uuid))
                        return __this_address;
                if (be64_to_cpu(hdr3->blkno) != bp->b_bn)
                        return __this_address;
                if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->lsn)))
                        return __this_address;
-       } else {
-               if (hdr3->magic != cpu_to_be32(XFS_DIR2_BLOCK_MAGIC))
-                       return __this_address;
        }
        return __xfs_dir3_data_check(NULL, bp);
 }
@@ -69,7 +65,7 @@ static void
 xfs_dir3_block_read_verify(
        struct xfs_buf  *bp)
 {
-       struct xfs_mount        *mp = bp->b_target->bt_mount;
+       struct xfs_mount        *mp = bp->b_mount;
        xfs_failaddr_t          fa;
 
        if (xfs_sb_version_hascrc(&mp->m_sb) &&
@@ -86,7 +82,7 @@ static void
 xfs_dir3_block_write_verify(
        struct xfs_buf  *bp)
 {
-       struct xfs_mount        *mp = bp->b_target->bt_mount;
+       struct xfs_mount        *mp = bp->b_mount;
        struct xfs_buf_log_item *bip = bp->b_log_item;
        struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr;
        xfs_failaddr_t          fa;
@@ -108,6 +104,8 @@ xfs_dir3_block_write_verify(
 
 const struct xfs_buf_ops xfs_dir3_block_buf_ops = {
        .name = "xfs_dir3_block",
+       .magic = { cpu_to_be32(XFS_DIR2_BLOCK_MAGIC),
+                  cpu_to_be32(XFS_DIR3_BLOCK_MAGIC) },
        .verify_read = xfs_dir3_block_read_verify,
        .verify_write = xfs_dir3_block_write_verify,
        .verify_struct = xfs_dir3_block_verify,
@@ -498,8 +496,8 @@ xfs_dir2_block_addname(
                        if (mid - lowstale)
                                memmove(&blp[lowstale], &blp[lowstale + 1],
                                        (mid - lowstale) * sizeof(*blp));
-                       lfloglow = MIN(lowstale, lfloglow);
-                       lfloghigh = MAX(mid, lfloghigh);
+                       lfloglow = min(lowstale, lfloglow);
+                       lfloghigh = max(mid, lfloghigh);
                }
                /*
                 * Move entries toward the high-numbered stale entry.
@@ -510,8 +508,8 @@ xfs_dir2_block_addname(
                        if (highstale - mid)
                                memmove(&blp[mid + 1], &blp[mid],
                                        (highstale - mid) * sizeof(*blp));
-                       lfloglow = MIN(mid, lfloglow);
-                       lfloghigh = MAX(highstale, lfloghigh);
+                       lfloglow = min(mid, lfloglow);
+                       lfloghigh = max(highstale, lfloghigh);
                }
                be32_add_cpu(&btp->stale, -1);
        }
@@ -1091,11 +1089,11 @@ xfs_dir2_sf_to_block(
         * Copy the directory into a temporary buffer.
         * Then pitch the incore inode data so we can make extents.
         */
-       sfp = kmem_alloc(ifp->if_bytes, KM_SLEEP);
+       sfp = kmem_alloc(ifp->if_bytes, 0);
        memcpy(sfp, oldsfp, ifp->if_bytes);
 
        xfs_idata_realloc(dp, -ifp->if_bytes, XFS_DATA_FORK);
-       xfs_bmap_local_to_extents_empty(dp, XFS_DATA_FORK);
+       xfs_bmap_local_to_extents_empty(tp, dp, XFS_DATA_FORK);
        dp->i_d.di_size = 0;
 
        /*