]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: add an entries pointer to struct xfs_dir3_icleaf_hdr
authorChristoph Hellwig <hch@lst.de>
Wed, 22 Jan 2020 16:29:41 +0000 (11:29 -0500)
committerEric Sandeen <sandeen@redhat.com>
Wed, 22 Jan 2020 16:29:41 +0000 (11:29 -0500)
Source kernel commit: 787b0893ad1e315ea014dc3f0e01a5bc9236c623

All callers of the ->node_tree_p dir operation already have a struct
xfs_dir3_icleaf_hdr from a previous call to xfs_da_leaf_hdr_from_disk at
hand, or just need slight changes to the calling conventions to do so.
Add a pointer to the entries to struct xfs_dir3_icleaf_hdr to clean up
this pattern.  To make this possible the xfs_dir3_leaf_log_ents function
grow a new argument to pass the xfs_dir3_icleaf_hdr that call callers
already have, and xfs_dir2_leaf_lookup_int returns the
xfs_dir3_icleaf_hdr to the callers so that they can later use it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
db/check.c
db/metadump.c
libxfs/xfs_da_btree.c
libxfs/xfs_da_format.c
libxfs/xfs_dir2.h
libxfs/xfs_dir2_block.c
libxfs/xfs_dir2_leaf.c
libxfs/xfs_dir2_node.c
libxfs/xfs_dir2_priv.h
repair/dir2.c
repair/phase6.c

index 51c1663f92706d28d7712828ccd7b86a3f33775d..f8a246c5001f335ef5cb89fca2aedb73c035a1c0 100644 (file)
@@ -3261,8 +3261,11 @@ process_leaf_node_dir_v2_int(
        xfs_da_intnode_t        *node;
        int                     stale;
        struct xfs_da3_icnode_hdr nodehdr;
+       struct xfs_dir3_icleaf_hdr leafhdr;
 
        leaf = iocur_top->data;
+       libxfs_dir2_leaf_hdr_from_disk(mp, &leafhdr, leaf);
+
        switch (be16_to_cpu(leaf->hdr.info.magic)) {
        case XFS_DIR3_LEAF1_MAGIC:
        case XFS_DIR3_LEAFN_MAGIC:
@@ -3338,7 +3341,7 @@ process_leaf_node_dir_v2_int(
                error++;
                return;
        }
-       lep = M_DIROPS(mp)->leaf_ents_p(leaf);
+       lep = leafhdr.ents;
        for (i = stale = 0; i < xfs_dir3_leaf_ents_count(leaf); i++) {
                if (be32_to_cpu(lep[i].address) == XFS_DIR2_NULL_DATAPTR)
                        stale++;
index 8c14c5cb8fd2a3c7a841fba2f6f632ac5416d26b..3c82b940583157cfcfa7a6f7504ab9777d7eac8e 100644 (file)
@@ -1478,12 +1478,10 @@ process_dir_leaf_block(
        case XFS_DIR3_LEAF1_MAGIC: {
                struct xfs_dir2_leaf_tail       *ltp;
                __be16                          *lbp;
-               struct xfs_dir2_leaf_entry      *ents;
                char                            *free; /* end of ents */
 
                /* Zero out space from end of ents[] to bests */
-               ents = M_DIROPS(mp)->leaf_ents_p(leaf);
-               free = (char *)&ents[leafhdr.count];
+               free = (char *)&leafhdr.ents[leafhdr.count];
                ltp = xfs_dir2_leaf_tail_p(mp->m_dir_geo, leaf);
                lbp = xfs_dir2_leaf_bests_p(ltp);
                memset(free, 0, (char *)lbp - free);
@@ -1492,13 +1490,11 @@ process_dir_leaf_block(
        }
        case XFS_DIR2_LEAFN_MAGIC:
        case XFS_DIR3_LEAFN_MAGIC: {
-               struct xfs_dir2_leaf_entry      *ents;
                char                            *free;
                int                             used;
 
                /* Zero out space from end of ents[] to end of block */
-               ents = M_DIROPS(mp)->leaf_ents_p(leaf);
-               free = (char *)&ents[leafhdr.count];
+               free = (char *)&leafhdr.ents[leafhdr.count];
                used = free - (char*)leaf;
                memset(free, 0, mp->m_dir_geo->blksize - used);
                iocur_top->need_crc = 1;
index ab3b319cb2b1e9d909853c0484b28bc2cc107650..c33114d606f133c7d1c9fec909e227d061cae8ad 100644 (file)
@@ -637,15 +637,14 @@ xfs_da3_root_split(
                xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DA_NODE_BUF);
        } else {
                struct xfs_dir3_icleaf_hdr leafhdr;
-               struct xfs_dir2_leaf_entry *ents;
 
                leaf = (xfs_dir2_leaf_t *)oldroot;
                xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, leaf);
-               ents = dp->d_ops->leaf_ents_p(leaf);
 
                ASSERT(leafhdr.magic == XFS_DIR2_LEAFN_MAGIC ||
                       leafhdr.magic == XFS_DIR3_LEAFN_MAGIC);
-               size = (int)((char *)&ents[leafhdr.count] - (char *)leaf);
+               size = (int)((char *)&leafhdr.ents[leafhdr.count] -
+                       (char *)leaf);
                level = 0;
 
                /*
@@ -2294,7 +2293,7 @@ xfs_da3_swap_lastblock(
                dead_leaf2 = (xfs_dir2_leaf_t *)dead_info;
                xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr,
                                            dead_leaf2);
-               ents = dp->d_ops->leaf_ents_p(dead_leaf2);
+               ents = leafhdr.ents;
                dead_level = 0;
                dead_hash = be32_to_cpu(ents[leafhdr.count - 1].hashval);
        } else {
index 65629290604169328a05d99caac00c5352a0d737..fe888239e0d432993ef5ed7d8953ba386af65881 100644 (file)
@@ -411,12 +411,6 @@ xfs_dir2_max_leaf_ents(struct xfs_da_geometry *geo)
                (uint)sizeof(struct xfs_dir2_leaf_entry);
 }
 
-static struct xfs_dir2_leaf_entry *
-xfs_dir2_leaf_ents_p(struct xfs_dir2_leaf *lp)
-{
-       return lp->__ents;
-}
-
 static int
 xfs_dir3_max_leaf_ents(struct xfs_da_geometry *geo)
 {
@@ -424,12 +418,6 @@ xfs_dir3_max_leaf_ents(struct xfs_da_geometry *geo)
                (uint)sizeof(struct xfs_dir2_leaf_entry);
 }
 
-static struct xfs_dir2_leaf_entry *
-xfs_dir3_leaf_ents_p(struct xfs_dir2_leaf *lp)
-{
-       return ((struct xfs_dir3_leaf *)lp)->__ents;
-}
-
 /*
  * Directory free space block operations
  */
@@ -584,7 +572,6 @@ static const struct xfs_dir_ops xfs_dir2_ops = {
 
        .leaf_hdr_size = sizeof(struct xfs_dir2_leaf_hdr),
        .leaf_max_ents = xfs_dir2_max_leaf_ents,
-       .leaf_ents_p = xfs_dir2_leaf_ents_p,
 
        .free_hdr_size = sizeof(struct xfs_dir2_free_hdr),
        .free_hdr_to_disk = xfs_dir2_free_hdr_to_disk,
@@ -627,7 +614,6 @@ static const struct xfs_dir_ops xfs_dir2_ftype_ops = {
 
        .leaf_hdr_size = sizeof(struct xfs_dir2_leaf_hdr),
        .leaf_max_ents = xfs_dir2_max_leaf_ents,
-       .leaf_ents_p = xfs_dir2_leaf_ents_p,
 
        .free_hdr_size = sizeof(struct xfs_dir2_free_hdr),
        .free_hdr_to_disk = xfs_dir2_free_hdr_to_disk,
@@ -670,7 +656,6 @@ static const struct xfs_dir_ops xfs_dir3_ops = {
 
        .leaf_hdr_size = sizeof(struct xfs_dir3_leaf_hdr),
        .leaf_max_ents = xfs_dir3_max_leaf_ents,
-       .leaf_ents_p = xfs_dir3_leaf_ents_p,
 
        .free_hdr_size = sizeof(struct xfs_dir3_free_hdr),
        .free_hdr_to_disk = xfs_dir3_free_hdr_to_disk,
index 15a1a72dc12675c89cd46a48f26e8e2acbfdd4c8..b46657974134e285811cfa4e3213792cb283927a 100644 (file)
@@ -74,8 +74,6 @@ struct xfs_dir_ops {
 
        int     leaf_hdr_size;
        int     (*leaf_max_ents)(struct xfs_da_geometry *geo);
-       struct xfs_dir2_leaf_entry *
-               (*leaf_ents_p)(struct xfs_dir2_leaf *lp);
 
        int     free_hdr_size;
        void    (*free_hdr_to_disk)(struct xfs_dir2_free *to,
index fb615cdd6838bf35fd855f900ba189491c290ec8..d74cb7e51a1d645e88ee4418a80e8a4246d6de43 100644 (file)
@@ -911,7 +911,6 @@ xfs_dir2_leaf_to_block(
        __be16                  *tagp;          /* end of entry (tag) */
        int                     to;             /* block/leaf to index */
        xfs_trans_t             *tp;            /* transaction pointer */
-       struct xfs_dir2_leaf_entry *ents;
        struct xfs_dir3_icleaf_hdr leafhdr;
 
        trace_xfs_dir2_leaf_to_block(args);
@@ -921,7 +920,6 @@ xfs_dir2_leaf_to_block(
        mp = dp->i_mount;
        leaf = lbp->b_addr;
        xfs_dir2_leaf_hdr_from_disk(mp, &leafhdr, leaf);
-       ents = dp->d_ops->leaf_ents_p(leaf);
        ltp = xfs_dir2_leaf_tail_p(args->geo, leaf);
 
        ASSERT(leafhdr.magic == XFS_DIR2_LEAF1_MAGIC ||
@@ -1001,9 +999,10 @@ xfs_dir2_leaf_to_block(
         */
        lep = xfs_dir2_block_leaf_p(btp);
        for (from = to = 0; from < leafhdr.count; from++) {
-               if (ents[from].address == cpu_to_be32(XFS_DIR2_NULL_DATAPTR))
+               if (leafhdr.ents[from].address ==
+                   cpu_to_be32(XFS_DIR2_NULL_DATAPTR))
                        continue;
-               lep[to++] = ents[from];
+               lep[to++] = leafhdr.ents[from];
        }
        ASSERT(to == be32_to_cpu(btp->count));
        xfs_dir2_block_log_leaf(tp, dbp, 0, be32_to_cpu(btp->count) - 1);
index ba44dc16ddc0657bd8dcd8629ab60666ad095dcf..7a22972d6ca888cdf5135b8af6081de00ebe5744 100644 (file)
@@ -22,7 +22,8 @@
  * Local function declarations.
  */
 static int xfs_dir2_leaf_lookup_int(xfs_da_args_t *args, struct xfs_buf **lbpp,
-                                   int *indexp, struct xfs_buf **dbpp);
+                                   int *indexp, struct xfs_buf **dbpp,
+                                   struct xfs_dir3_icleaf_hdr *leafhdr);
 static void xfs_dir3_leaf_log_bests(struct xfs_da_args *args,
                                    struct xfs_buf *bp, int first, int last);
 static void xfs_dir3_leaf_log_tail(struct xfs_da_args *args,
@@ -42,6 +43,7 @@ xfs_dir2_leaf_hdr_from_disk(
                to->magic = be16_to_cpu(from3->hdr.info.hdr.magic);
                to->count = be16_to_cpu(from3->hdr.count);
                to->stale = be16_to_cpu(from3->hdr.stale);
+               to->ents = from3->__ents;
 
                ASSERT(to->magic == XFS_DIR3_LEAF1_MAGIC ||
                       to->magic == XFS_DIR3_LEAFN_MAGIC);
@@ -51,6 +53,7 @@ xfs_dir2_leaf_hdr_from_disk(
                to->magic = be16_to_cpu(from->hdr.info.magic);
                to->count = be16_to_cpu(from->hdr.count);
                to->stale = be16_to_cpu(from->hdr.stale);
+               to->ents = from->__ents;
 
                ASSERT(to->magic == XFS_DIR2_LEAF1_MAGIC ||
                       to->magic == XFS_DIR2_LEAFN_MAGIC);
@@ -137,7 +140,6 @@ xfs_dir3_leaf_check_int(
        struct xfs_dir3_icleaf_hdr *hdr,
        struct xfs_dir2_leaf    *leaf)
 {
-       struct xfs_dir2_leaf_entry *ents;
        xfs_dir2_leaf_tail_t    *ltp;
        int                     stale;
        int                     i;
@@ -156,7 +158,6 @@ xfs_dir3_leaf_check_int(
                hdr = &leafhdr;
        }
 
-       ents = ops->leaf_ents_p(leaf);
        ltp = xfs_dir2_leaf_tail_p(geo, leaf);
 
        /*
@@ -170,17 +171,17 @@ xfs_dir3_leaf_check_int(
        /* Leaves and bests don't overlap in leaf format. */
        if ((hdr->magic == XFS_DIR2_LEAF1_MAGIC ||
             hdr->magic == XFS_DIR3_LEAF1_MAGIC) &&
-           (char *)&ents[hdr->count] > (char *)xfs_dir2_leaf_bests_p(ltp))
+           (char *)&hdr->ents[hdr->count] > (char *)xfs_dir2_leaf_bests_p(ltp))
                return __this_address;
 
        /* Check hash value order, count stale entries.  */
        for (i = stale = 0; i < hdr->count; i++) {
                if (i + 1 < hdr->count) {
-                       if (be32_to_cpu(ents[i].hashval) >
-                                       be32_to_cpu(ents[i + 1].hashval))
+                       if (be32_to_cpu(hdr->ents[i].hashval) >
+                                       be32_to_cpu(hdr->ents[i + 1].hashval))
                                return __this_address;
                }
-               if (ents[i].address == cpu_to_be32(XFS_DIR2_NULL_DATAPTR))
+               if (hdr->ents[i].address == cpu_to_be32(XFS_DIR2_NULL_DATAPTR))
                        stale++;
        }
        if (hdr->stale != stale)
@@ -402,7 +403,6 @@ xfs_dir2_block_to_leaf(
        int                     needscan;       /* need to rescan bestfree */
        xfs_trans_t             *tp;            /* transaction pointer */
        struct xfs_dir2_data_free *bf;
-       struct xfs_dir2_leaf_entry *ents;
        struct xfs_dir3_icleaf_hdr leafhdr;
 
        trace_xfs_dir2_block_to_leaf(args);
@@ -432,7 +432,6 @@ xfs_dir2_block_to_leaf(
        btp = xfs_dir2_block_tail_p(args->geo, hdr);
        blp = xfs_dir2_block_leaf_p(btp);
        bf = dp->d_ops->data_bestfree_p(hdr);
-       ents = dp->d_ops->leaf_ents_p(leaf);
 
        /*
         * Set the counts in the leaf header.
@@ -447,8 +446,9 @@ xfs_dir2_block_to_leaf(
         * Could compact these but I think we always do the conversion
         * after squeezing out stale entries.
         */
-       memcpy(ents, blp, be32_to_cpu(btp->count) * sizeof(xfs_dir2_leaf_entry_t));
-       xfs_dir3_leaf_log_ents(args, lbp, 0, leafhdr.count - 1);
+       memcpy(leafhdr.ents, blp,
+               be32_to_cpu(btp->count) * sizeof(struct xfs_dir2_leaf_entry));
+       xfs_dir3_leaf_log_ents(args, &leafhdr, lbp, 0, leafhdr.count - 1);
        needscan = 0;
        needlog = 1;
        /*
@@ -663,8 +663,8 @@ xfs_dir2_leaf_addname(
        index = xfs_dir2_leaf_search_hash(args, lbp);
        leaf = lbp->b_addr;
        ltp = xfs_dir2_leaf_tail_p(args->geo, leaf);
-       ents = dp->d_ops->leaf_ents_p(leaf);
        xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, leaf);
+       ents = leafhdr.ents;
        bestsp = xfs_dir2_leaf_bests_p(ltp);
        length = dp->d_ops->data_entsize(args->namelen);
 
@@ -910,7 +910,7 @@ xfs_dir2_leaf_addname(
         */
        xfs_dir2_leaf_hdr_to_disk(dp->i_mount, leaf, &leafhdr);
        xfs_dir3_leaf_log_header(args, lbp);
-       xfs_dir3_leaf_log_ents(args, lbp, lfloglow, lfloghigh);
+       xfs_dir3_leaf_log_ents(args, &leafhdr, lbp, lfloglow, lfloghigh);
        xfs_dir3_leaf_check(dp, lbp);
        xfs_dir3_data_check(dp, dbp);
        return 0;
@@ -930,7 +930,6 @@ xfs_dir3_leaf_compact(
        xfs_dir2_leaf_t *leaf;          /* leaf structure */
        int             loglow;         /* first leaf entry to log */
        int             to;             /* target leaf index */
-       struct xfs_dir2_leaf_entry *ents;
        struct xfs_inode *dp = args->dp;
 
        leaf = bp->b_addr;
@@ -940,9 +939,9 @@ xfs_dir3_leaf_compact(
        /*
         * Compress out the stale entries in place.
         */
-       ents = dp->d_ops->leaf_ents_p(leaf);
        for (from = to = 0, loglow = -1; from < leafhdr->count; from++) {
-               if (ents[from].address == cpu_to_be32(XFS_DIR2_NULL_DATAPTR))
+               if (leafhdr->ents[from].address ==
+                   cpu_to_be32(XFS_DIR2_NULL_DATAPTR))
                        continue;
                /*
                 * Only actually copy the entries that are different.
@@ -950,7 +949,7 @@ xfs_dir3_leaf_compact(
                if (from > to) {
                        if (loglow == -1)
                                loglow = to;
-                       ents[to] = ents[from];
+                       leafhdr->ents[to] = leafhdr->ents[from];
                }
                to++;
        }
@@ -964,7 +963,7 @@ xfs_dir3_leaf_compact(
        xfs_dir2_leaf_hdr_to_disk(dp->i_mount, leaf, leafhdr);
        xfs_dir3_leaf_log_header(args, bp);
        if (loglow != -1)
-               xfs_dir3_leaf_log_ents(args, bp, loglow, to - 1);
+               xfs_dir3_leaf_log_ents(args, leafhdr, bp, loglow, to - 1);
 }
 
 /*
@@ -1093,6 +1092,7 @@ xfs_dir3_leaf_log_bests(
 void
 xfs_dir3_leaf_log_ents(
        struct xfs_da_args      *args,
+       struct xfs_dir3_icleaf_hdr *hdr,
        struct xfs_buf          *bp,
        int                     first,
        int                     last)
@@ -1100,16 +1100,14 @@ xfs_dir3_leaf_log_ents(
        xfs_dir2_leaf_entry_t   *firstlep;      /* pointer to first entry */
        xfs_dir2_leaf_entry_t   *lastlep;       /* pointer to last entry */
        struct xfs_dir2_leaf    *leaf = bp->b_addr;
-       struct xfs_dir2_leaf_entry *ents;
 
        ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC) ||
               leaf->hdr.info.magic == cpu_to_be16(XFS_DIR3_LEAF1_MAGIC) ||
               leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC) ||
               leaf->hdr.info.magic == cpu_to_be16(XFS_DIR3_LEAFN_MAGIC));
 
-       ents = args->dp->d_ops->leaf_ents_p(leaf);
-       firstlep = &ents[first];
-       lastlep = &ents[last];
+       firstlep = &hdr->ents[first];
+       lastlep = &hdr->ents[last];
        xfs_trans_log_buf(args->trans, bp,
                (uint)((char *)firstlep - (char *)leaf),
                (uint)((char *)lastlep - (char *)leaf + sizeof(*lastlep) - 1));
@@ -1171,28 +1169,27 @@ xfs_dir2_leaf_lookup(
        int                     error;          /* error return code */
        int                     index;          /* found entry index */
        struct xfs_buf          *lbp;           /* leaf buffer */
-       xfs_dir2_leaf_t         *leaf;          /* leaf structure */
        xfs_dir2_leaf_entry_t   *lep;           /* leaf entry */
        xfs_trans_t             *tp;            /* transaction pointer */
-       struct xfs_dir2_leaf_entry *ents;
+       struct xfs_dir3_icleaf_hdr leafhdr;
 
        trace_xfs_dir2_leaf_lookup(args);
 
        /*
         * Look up name in the leaf block, returning both buffers and index.
         */
-       if ((error = xfs_dir2_leaf_lookup_int(args, &lbp, &index, &dbp))) {
+       error = xfs_dir2_leaf_lookup_int(args, &lbp, &index, &dbp, &leafhdr);
+       if (error)
                return error;
-       }
+
        tp = args->trans;
        dp = args->dp;
        xfs_dir3_leaf_check(dp, lbp);
-       leaf = lbp->b_addr;
-       ents = dp->d_ops->leaf_ents_p(leaf);
+
        /*
         * Get to the leaf entry and contained data entry address.
         */
-       lep = &ents[index];
+       lep = &leafhdr.ents[index];
 
        /*
         * Point to the data entry.
@@ -1222,7 +1219,8 @@ xfs_dir2_leaf_lookup_int(
        xfs_da_args_t           *args,          /* operation arguments */
        struct xfs_buf          **lbpp,         /* out: leaf buffer */
        int                     *indexp,        /* out: index in leaf block */
-       struct xfs_buf          **dbpp)         /* out: data buffer */
+       struct xfs_buf          **dbpp,         /* out: data buffer */
+       struct xfs_dir3_icleaf_hdr *leafhdr)
 {
        xfs_dir2_db_t           curdb = -1;     /* current data block number */
        struct xfs_buf          *dbp = NULL;    /* data buffer */
@@ -1238,8 +1236,6 @@ xfs_dir2_leaf_lookup_int(
        xfs_trans_t             *tp;            /* transaction pointer */
        xfs_dir2_db_t           cidb = -1;      /* case match data block no. */
        enum xfs_dacmp          cmp;            /* name compare result */
-       struct xfs_dir2_leaf_entry *ents;
-       struct xfs_dir3_icleaf_hdr leafhdr;
 
        dp = args->dp;
        tp = args->trans;
@@ -1252,8 +1248,7 @@ xfs_dir2_leaf_lookup_int(
        *lbpp = lbp;
        leaf = lbp->b_addr;
        xfs_dir3_leaf_check(dp, lbp);
-       ents = dp->d_ops->leaf_ents_p(leaf);
-       xfs_dir2_leaf_hdr_from_disk(mp, &leafhdr, leaf);
+       xfs_dir2_leaf_hdr_from_disk(mp, leafhdr, leaf);
 
        /*
         * Look for the first leaf entry with our hash value.
@@ -1263,8 +1258,9 @@ xfs_dir2_leaf_lookup_int(
         * Loop over all the entries with the right hash value
         * looking to match the name.
         */
-       for (lep = &ents[index];
-            index < leafhdr.count && be32_to_cpu(lep->hashval) == args->hashval;
+       for (lep = &leafhdr->ents[index];
+            index < leafhdr->count &&
+                       be32_to_cpu(lep->hashval) == args->hashval;
             lep++, index++) {
                /*
                 * Skip over stale leaf entries.
@@ -1370,7 +1366,6 @@ xfs_dir2_leaf_removename(
        int                     needscan;       /* need to rescan data frees */
        xfs_dir2_data_off_t     oldbest;        /* old value of best free */
        struct xfs_dir2_data_free *bf;          /* bestfree table */
-       struct xfs_dir2_leaf_entry *ents;
        struct xfs_dir3_icleaf_hdr leafhdr;
 
        trace_xfs_dir2_leaf_removename(args);
@@ -1378,20 +1373,20 @@ xfs_dir2_leaf_removename(
        /*
         * Lookup the leaf entry, get the leaf and data blocks read in.
         */
-       if ((error = xfs_dir2_leaf_lookup_int(args, &lbp, &index, &dbp))) {
+       error = xfs_dir2_leaf_lookup_int(args, &lbp, &index, &dbp, &leafhdr);
+       if (error)
                return error;
-       }
+
        dp = args->dp;
        leaf = lbp->b_addr;
        hdr = dbp->b_addr;
        xfs_dir3_data_check(dp, dbp);
        bf = dp->d_ops->data_bestfree_p(hdr);
-       xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, leaf);
-       ents = dp->d_ops->leaf_ents_p(leaf);
+
        /*
         * Point to the leaf entry, use that to point to the data entry.
         */
-       lep = &ents[index];
+       lep = &leafhdr.ents[index];
        db = xfs_dir2_dataptr_to_db(args->geo, be32_to_cpu(lep->address));
        dep = (xfs_dir2_data_entry_t *)((char *)hdr +
                xfs_dir2_dataptr_to_off(args->geo, be32_to_cpu(lep->address)));
@@ -1417,7 +1412,7 @@ xfs_dir2_leaf_removename(
        xfs_dir3_leaf_log_header(args, lbp);
 
        lep->address = cpu_to_be32(XFS_DIR2_NULL_DATAPTR);
-       xfs_dir3_leaf_log_ents(args, lbp, index, index);
+       xfs_dir3_leaf_log_ents(args, &leafhdr, lbp, index, index);
 
        /*
         * Scan the freespace in the data block again if necessary,
@@ -1506,26 +1501,24 @@ xfs_dir2_leaf_replace(
        int                     error;          /* error return code */
        int                     index;          /* index of leaf entry */
        struct xfs_buf          *lbp;           /* leaf buffer */
-       xfs_dir2_leaf_t         *leaf;          /* leaf structure */
        xfs_dir2_leaf_entry_t   *lep;           /* leaf entry */
        xfs_trans_t             *tp;            /* transaction pointer */
-       struct xfs_dir2_leaf_entry *ents;
+       struct xfs_dir3_icleaf_hdr leafhdr;
 
        trace_xfs_dir2_leaf_replace(args);
 
        /*
         * Look up the entry.
         */
-       if ((error = xfs_dir2_leaf_lookup_int(args, &lbp, &index, &dbp))) {
+       error = xfs_dir2_leaf_lookup_int(args, &lbp, &index, &dbp, &leafhdr);
+       if (error)
                return error;
-       }
+
        dp = args->dp;
-       leaf = lbp->b_addr;
-       ents = dp->d_ops->leaf_ents_p(leaf);
        /*
         * Point to the leaf entry, get data address from it.
         */
-       lep = &ents[index];
+       lep = &leafhdr.ents[index];
        /*
         * Point to the data entry.
         */
@@ -1559,21 +1552,17 @@ xfs_dir2_leaf_search_hash(
        xfs_dahash_t            hashwant;       /* hash value looking for */
        int                     high;           /* high leaf index */
        int                     low;            /* low leaf index */
-       xfs_dir2_leaf_t         *leaf;          /* leaf structure */
        xfs_dir2_leaf_entry_t   *lep;           /* leaf entry */
        int                     mid=0;          /* current leaf index */
-       struct xfs_dir2_leaf_entry *ents;
        struct xfs_dir3_icleaf_hdr leafhdr;
 
-       leaf = lbp->b_addr;
-       ents = args->dp->d_ops->leaf_ents_p(leaf);
-       xfs_dir2_leaf_hdr_from_disk(args->dp->i_mount, &leafhdr, leaf);
+       xfs_dir2_leaf_hdr_from_disk(args->dp->i_mount, &leafhdr, lbp->b_addr);
 
        /*
         * Note, the table cannot be empty, so we have to go through the loop.
         * Binary search the leaf entries looking for our hash value.
         */
-       for (lep = ents, low = 0, high = leafhdr.count - 1,
+       for (lep = leafhdr.ents, low = 0, high = leafhdr.count - 1,
                hashwant = args->hashval;
             low <= high; ) {
                mid = (low + high) >> 1;
index 86b08f8d288c63a0767e6a3072cc7f9172bdc98b..d4b1f2311624a715354b15b98947d7e53cb53632 100644 (file)
@@ -438,7 +438,7 @@ xfs_dir2_leafn_add(
        trace_xfs_dir2_leafn_add(args, index);
 
        xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, leaf);
-       ents = dp->d_ops->leaf_ents_p(leaf);
+       ents = leafhdr.ents;
 
        /*
         * Quick check just to make sure we are not going to index
@@ -496,7 +496,7 @@ xfs_dir2_leafn_add(
 
        xfs_dir2_leaf_hdr_to_disk(dp->i_mount, leaf, &leafhdr);
        xfs_dir3_leaf_log_header(args, bp);
-       xfs_dir3_leaf_log_ents(args, bp, lfloglow, lfloghigh);
+       xfs_dir3_leaf_log_ents(args, &leafhdr, bp, lfloglow, lfloghigh);
        xfs_dir3_leaf_check(dp, bp);
        return 0;
 }
@@ -531,11 +531,9 @@ xfs_dir2_leaf_lasthash(
        struct xfs_buf  *bp,                    /* leaf buffer */
        int             *count)                 /* count of entries in leaf */
 {
-       struct xfs_dir2_leaf    *leaf = bp->b_addr;
-       struct xfs_dir2_leaf_entry *ents;
        struct xfs_dir3_icleaf_hdr leafhdr;
 
-       xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, leaf);
+       xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, bp->b_addr);
 
        ASSERT(leafhdr.magic == XFS_DIR2_LEAFN_MAGIC ||
               leafhdr.magic == XFS_DIR3_LEAFN_MAGIC ||
@@ -546,9 +544,7 @@ xfs_dir2_leaf_lasthash(
                *count = leafhdr.count;
        if (!leafhdr.count)
                return 0;
-
-       ents = dp->d_ops->leaf_ents_p(leaf);
-       return be32_to_cpu(ents[leafhdr.count - 1].hashval);
+       return be32_to_cpu(leafhdr.ents[leafhdr.count - 1].hashval);
 }
 
 /*
@@ -577,7 +573,6 @@ xfs_dir2_leafn_lookup_for_addname(
        xfs_dir2_db_t           newdb;          /* new data block number */
        xfs_dir2_db_t           newfdb;         /* new free block number */
        xfs_trans_t             *tp;            /* transaction pointer */
-       struct xfs_dir2_leaf_entry *ents;
        struct xfs_dir3_icleaf_hdr leafhdr;
 
        dp = args->dp;
@@ -585,7 +580,6 @@ xfs_dir2_leafn_lookup_for_addname(
        mp = dp->i_mount;
        leaf = bp->b_addr;
        xfs_dir2_leaf_hdr_from_disk(mp, &leafhdr, leaf);
-       ents = dp->d_ops->leaf_ents_p(leaf);
 
        xfs_dir3_leaf_check(dp, bp);
        ASSERT(leafhdr.count > 0);
@@ -609,7 +603,7 @@ xfs_dir2_leafn_lookup_for_addname(
        /*
         * Loop over leaf entries with the right hash value.
         */
-       for (lep = &ents[index];
+       for (lep = &leafhdr.ents[index];
             index < leafhdr.count && be32_to_cpu(lep->hashval) == args->hashval;
             lep++, index++) {
                /*
@@ -729,7 +723,6 @@ xfs_dir2_leafn_lookup_for_entry(
        xfs_dir2_db_t           newdb;          /* new data block number */
        xfs_trans_t             *tp;            /* transaction pointer */
        enum xfs_dacmp          cmp;            /* comparison result */
-       struct xfs_dir2_leaf_entry *ents;
        struct xfs_dir3_icleaf_hdr leafhdr;
 
        dp = args->dp;
@@ -737,7 +730,6 @@ xfs_dir2_leafn_lookup_for_entry(
        mp = dp->i_mount;
        leaf = bp->b_addr;
        xfs_dir2_leaf_hdr_from_disk(mp, &leafhdr, leaf);
-       ents = dp->d_ops->leaf_ents_p(leaf);
 
        xfs_dir3_leaf_check(dp, bp);
        if (leafhdr.count <= 0) {
@@ -759,7 +751,7 @@ xfs_dir2_leafn_lookup_for_entry(
        /*
         * Loop over leaf entries with the right hash value.
         */
-       for (lep = &ents[index];
+       for (lep = &leafhdr.ents[index];
             index < leafhdr.count && be32_to_cpu(lep->hashval) == args->hashval;
             lep++, index++) {
                /*
@@ -914,7 +906,7 @@ xfs_dir3_leafn_moveents(
        if (start_d < dhdr->count) {
                memmove(&dents[start_d + count], &dents[start_d],
                        (dhdr->count - start_d) * sizeof(xfs_dir2_leaf_entry_t));
-               xfs_dir3_leaf_log_ents(args, bp_d, start_d + count,
+               xfs_dir3_leaf_log_ents(args, dhdr, bp_d, start_d + count,
                                       count + dhdr->count - 1);
        }
        /*
@@ -936,7 +928,7 @@ xfs_dir3_leafn_moveents(
         */
        memcpy(&dents[start_d], &sents[start_s],
                count * sizeof(xfs_dir2_leaf_entry_t));
-       xfs_dir3_leaf_log_ents(args, bp_d, start_d, start_d + count - 1);
+       xfs_dir3_leaf_log_ents(args, dhdr, bp_d, start_d, start_d + count - 1);
 
        /*
         * If there are source entries after the ones we copied,
@@ -945,7 +937,8 @@ xfs_dir3_leafn_moveents(
        if (start_s + count < shdr->count) {
                memmove(&sents[start_s], &sents[start_s + count],
                        count * sizeof(xfs_dir2_leaf_entry_t));
-               xfs_dir3_leaf_log_ents(args, bp_s, start_s, start_s + count - 1);
+               xfs_dir3_leaf_log_ents(args, shdr, bp_s, start_s,
+                                      start_s + count - 1);
        }
 
        /*
@@ -976,8 +969,8 @@ xfs_dir2_leafn_order(
 
        xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &hdr1, leaf1);
        xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &hdr2, leaf2);
-       ents1 = dp->d_ops->leaf_ents_p(leaf1);
-       ents2 = dp->d_ops->leaf_ents_p(leaf2);
+       ents1 = hdr1.ents;
+       ents2 = hdr2.ents;
 
        if (hdr1.count > 0 && hdr2.count > 0 &&
            (be32_to_cpu(ents2[0].hashval) < be32_to_cpu(ents1[0].hashval) ||
@@ -1029,8 +1022,8 @@ xfs_dir2_leafn_rebalance(
        leaf2 = blk2->bp->b_addr;
        xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &hdr1, leaf1);
        xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &hdr2, leaf2);
-       ents1 = dp->d_ops->leaf_ents_p(leaf1);
-       ents2 = dp->d_ops->leaf_ents_p(leaf2);
+       ents1 = hdr1.ents;
+       ents2 = hdr2.ents;
 
        oldsum = hdr1.count + hdr2.count;
 #if defined(DEBUG) || defined(XFS_WARN)
@@ -1218,7 +1211,6 @@ xfs_dir2_leafn_remove(
        xfs_trans_t             *tp;            /* transaction pointer */
        struct xfs_dir2_data_free *bf;          /* bestfree table */
        struct xfs_dir3_icleaf_hdr leafhdr;
-       struct xfs_dir2_leaf_entry *ents;
 
        trace_xfs_dir2_leafn_remove(args, index);
 
@@ -1226,12 +1218,11 @@ xfs_dir2_leafn_remove(
        tp = args->trans;
        leaf = bp->b_addr;
        xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, leaf);
-       ents = dp->d_ops->leaf_ents_p(leaf);
 
        /*
         * Point to the entry we're removing.
         */
-       lep = &ents[index];
+       lep = &leafhdr.ents[index];
 
        /*
         * Extract the data block and offset from the entry.
@@ -1250,7 +1241,7 @@ xfs_dir2_leafn_remove(
        xfs_dir3_leaf_log_header(args, bp);
 
        lep->address = cpu_to_be32(XFS_DIR2_NULL_DATAPTR);
-       xfs_dir3_leaf_log_ents(args, bp, index, index);
+       xfs_dir3_leaf_log_ents(args, &leafhdr, bp, index, index);
 
        /*
         * Make the data entry free.  Keep track of the longest freespace
@@ -1347,7 +1338,7 @@ xfs_dir2_leafn_remove(
         * to justify trying to join it with a neighbor.
         */
        *rval = (dp->d_ops->leaf_hdr_size +
-                (uint)sizeof(ents[0]) * (leafhdr.count - leafhdr.stale)) <
+                (uint)sizeof(leafhdr.ents) * (leafhdr.count - leafhdr.stale)) <
                args->geo->magicpct;
        return 0;
 }
@@ -1448,7 +1439,7 @@ xfs_dir2_leafn_toosmall(
        blk = &state->path.blk[state->path.active - 1];
        leaf = blk->bp->b_addr;
        xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, leaf);
-       ents = dp->d_ops->leaf_ents_p(leaf);
+       ents = leafhdr.ents;
        xfs_dir3_leaf_check(dp, blk->bp);
 
        count = leafhdr.count - leafhdr.stale;
@@ -1511,7 +1502,7 @@ xfs_dir2_leafn_toosmall(
 
                leaf = bp->b_addr;
                xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &hdr2, leaf);
-               ents = dp->d_ops->leaf_ents_p(leaf);
+               ents = hdr2.ents;
                count += hdr2.count - hdr2.stale;
                bytes -= count * sizeof(ents[0]);
 
@@ -1575,8 +1566,8 @@ xfs_dir2_leafn_unbalance(
 
        xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &savehdr, save_leaf);
        xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &drophdr, drop_leaf);
-       sents = dp->d_ops->leaf_ents_p(save_leaf);
-       dents = dp->d_ops->leaf_ents_p(drop_leaf);
+       sents = savehdr.ents;
+       dents = drophdr.ents;
 
        /*
         * If there are any stale leaf entries, take this opportunity
@@ -2158,8 +2149,6 @@ xfs_dir2_node_replace(
        int                     i;              /* btree level */
        xfs_ino_t               inum;           /* new inode number */
        int                     ftype;          /* new file type */
-       xfs_dir2_leaf_t         *leaf;          /* leaf structure */
-       xfs_dir2_leaf_entry_t   *lep;           /* leaf entry being changed */
        int                     rval;           /* internal return value */
        xfs_da_state_t          *state;         /* btree cursor */
 
@@ -2191,16 +2180,17 @@ xfs_dir2_node_replace(
         * and locked it.  But paranoia is good.
         */
        if (rval == -EEXIST) {
-               struct xfs_dir2_leaf_entry *ents;
+               struct xfs_dir3_icleaf_hdr      leafhdr;
+
                /*
                 * Find the leaf entry.
                 */
                blk = &state->path.blk[state->path.active - 1];
                ASSERT(blk->magic == XFS_DIR2_LEAFN_MAGIC);
-               leaf = blk->bp->b_addr;
-               ents = args->dp->d_ops->leaf_ents_p(leaf);
-               lep = &ents[blk->index];
                ASSERT(state->extravalid);
+
+               xfs_dir2_leaf_hdr_from_disk(state->mp, &leafhdr,
+                                           blk->bp->b_addr);
                /*
                 * Point to the data entry.
                 */
@@ -2210,7 +2200,7 @@ xfs_dir2_node_replace(
                dep = (xfs_dir2_data_entry_t *)
                      ((char *)hdr +
                       xfs_dir2_dataptr_to_off(args->geo,
-                                              be32_to_cpu(lep->address)));
+                               be32_to_cpu(leafhdr.ents[blk->index].address)));
                ASSERT(inum != be64_to_cpu(dep->inumber));
                /*
                 * Fill in the new inode number and log the entry.
index af96e3faefaf6d1d265ac4f6c7206fd9134c2980..1f068812c453a4cbb102a3c42f4767a8021441ce 100644 (file)
@@ -18,6 +18,12 @@ struct xfs_dir3_icleaf_hdr {
        uint16_t                magic;
        uint16_t                count;
        uint16_t                stale;
+
+       /*
+        * Pointer to the on-disk format entries, which are behind the
+        * variable size (v4 vs v5) header in the on-disk block.
+        */
+       struct xfs_dir2_leaf_entry *ents;
 };
 
 struct xfs_dir3_icfree_hdr {
@@ -85,7 +91,8 @@ extern void xfs_dir3_leaf_compact_x1(struct xfs_dir3_icleaf_hdr *leafhdr,
 extern int xfs_dir3_leaf_get_buf(struct xfs_da_args *args, xfs_dir2_db_t bno,
                struct xfs_buf **bpp, uint16_t magic);
 extern void xfs_dir3_leaf_log_ents(struct xfs_da_args *args,
-               struct xfs_buf *bp, int first, int last);
+               struct xfs_dir3_icleaf_hdr *hdr, struct xfs_buf *bp, int first,
+               int last);
 extern void xfs_dir3_leaf_log_header(struct xfs_da_args *args,
                struct xfs_buf *bp);
 extern int xfs_dir2_leaf_lookup(struct xfs_da_args *args);
index b4c2be220afb75a7d60a68792f23e47a252fb9fd..47f9e036ed54bbcb98f425269a54faf74416c99f 100644 (file)
@@ -1039,7 +1039,7 @@ process_leaf_block_dir2(
        struct xfs_dir3_icleaf_hdr leafhdr;
 
        libxfs_dir2_leaf_hdr_from_disk(mp, &leafhdr, leaf);
-       ents = M_DIROPS(mp)->leaf_ents_p(leaf);
+       ents = leafhdr.ents;
 
        for (i = stale = 0; i < leafhdr.count; i++) {
                if ((char *)&ents[i] >= (char *)leaf + mp->m_dir_geo->blksize) {
index 958a8aa75f28c31e751467d40025dc2f1259f3e7..0d722cc8d6b1265f4384e5e20960ec6184a8ecf6 100644 (file)
@@ -2058,7 +2058,7 @@ longform_dir2_check_leaf(
 
        leaf = bp->b_addr;
        libxfs_dir2_leaf_hdr_from_disk(mp, &leafhdr, leaf);
-       ents = M_DIROPS(mp)->leaf_ents_p(leaf);
+       ents = leafhdr.ents;
        ltp = xfs_dir2_leaf_tail_p(mp->m_dir_geo, leaf);
        bestsp = xfs_dir2_leaf_bests_p(ltp);
        if (!(leafhdr.magic == XFS_DIR2_LEAF1_MAGIC ||
@@ -2155,7 +2155,7 @@ longform_dir2_check_node(
                }
                leaf = bp->b_addr;
                libxfs_dir2_leaf_hdr_from_disk(mp, &leafhdr, leaf);
-               ents = M_DIROPS(mp)->leaf_ents_p(leaf);
+               ents = leafhdr.ents;
                if (!(leafhdr.magic == XFS_DIR2_LEAFN_MAGIC ||
                      leafhdr.magic == XFS_DIR3_LEAFN_MAGIC ||
                      leafhdr.magic == XFS_DA_NODE_MAGIC ||