Skip to content

Commit a165f7e

Browse files
author
Darrick J. Wong
committed
xfs: refactor attr3 leaf table size computation
Replace all the open-coded callsites with a single static inline helper. Signed-off-by: "Darrick J. Wong" <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent 3eefc0c commit a165f7e

2 files changed

Lines changed: 30 additions & 29 deletions

File tree

fs/xfs/libxfs/xfs_attr_leaf.c

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ STATIC void xfs_attr3_leaf_moveents(struct xfs_da_args *args,
7575
int move_count);
7676
STATIC int xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index);
7777

78+
/* Compute the byte offset of the end of the leaf entry array. */
79+
static inline int
80+
xfs_attr_leaf_entries_end(
81+
unsigned int hdrcount,
82+
const struct xfs_attr_leafblock *leaf)
83+
{
84+
return hdrcount * sizeof(struct xfs_attr_leaf_entry) +
85+
xfs_attr3_leaf_hdr_size(leaf);
86+
}
87+
7888
/*
7989
* attr3 block 'firstused' conversion helpers.
8090
*
@@ -1409,8 +1419,7 @@ xfs_attr3_leaf_add(
14091419
* Search through freemap for first-fit on new name length.
14101420
* (may need to figure in size of entry struct too)
14111421
*/
1412-
tablesize = (ichdr.count + 1) * sizeof(xfs_attr_leaf_entry_t)
1413-
+ xfs_attr3_leaf_hdr_size(leaf);
1422+
tablesize = xfs_attr_leaf_entries_end(ichdr.count + 1, leaf);
14141423
for (sum = 0, i = XFS_ATTR_LEAF_MAPSIZE - 1; i >= 0; i--) {
14151424
if (tablesize > ichdr.firstused) {
14161425
sum += ichdr.freemap[i].size;
@@ -1569,8 +1578,7 @@ xfs_attr3_leaf_add_work(
15691578
if (be16_to_cpu(entry->nameidx) < ichdr->firstused)
15701579
ichdr->firstused = be16_to_cpu(entry->nameidx);
15711580

1572-
new_end = ichdr->count * sizeof(struct xfs_attr_leaf_entry) +
1573-
xfs_attr3_leaf_hdr_size(leaf);
1581+
new_end = xfs_attr_leaf_entries_end(ichdr->count, leaf);
15741582
old_end = new_end - sizeof(struct xfs_attr_leaf_entry);
15751583

15761584
ASSERT(ichdr->firstused >= new_end);
@@ -1807,8 +1815,8 @@ xfs_attr3_leaf_rebalance(
18071815
/*
18081816
* leaf2 is the destination, compact it if it looks tight.
18091817
*/
1810-
max = ichdr2.firstused - xfs_attr3_leaf_hdr_size(leaf1);
1811-
max -= ichdr2.count * sizeof(xfs_attr_leaf_entry_t);
1818+
max = ichdr2.firstused -
1819+
xfs_attr_leaf_entries_end(ichdr2.count, leaf1);
18121820
if (space > max)
18131821
xfs_attr3_leaf_compact(args, &ichdr2, blk2->bp);
18141822

@@ -1836,8 +1844,8 @@ xfs_attr3_leaf_rebalance(
18361844
/*
18371845
* leaf1 is the destination, compact it if it looks tight.
18381846
*/
1839-
max = ichdr1.firstused - xfs_attr3_leaf_hdr_size(leaf1);
1840-
max -= ichdr1.count * sizeof(xfs_attr_leaf_entry_t);
1847+
max = ichdr1.firstused -
1848+
xfs_attr_leaf_entries_end(ichdr1.count, leaf1);
18411849
if (space > max)
18421850
xfs_attr3_leaf_compact(args, &ichdr1, blk1->bp);
18431851

@@ -2043,9 +2051,7 @@ xfs_attr3_leaf_toosmall(
20432051
blk = &state->path.blk[ state->path.active-1 ];
20442052
leaf = blk->bp->b_addr;
20452053
xfs_attr3_leaf_hdr_from_disk(state->args->geo, &ichdr, leaf);
2046-
bytes = xfs_attr3_leaf_hdr_size(leaf) +
2047-
ichdr.count * sizeof(xfs_attr_leaf_entry_t) +
2048-
ichdr.usedbytes;
2054+
bytes = xfs_attr_leaf_entries_end(ichdr.count, leaf) + ichdr.usedbytes;
20492055
if (bytes > (state->args->geo->blksize >> 1)) {
20502056
*action = 0; /* blk over 50%, don't try to join */
20512057
return 0;
@@ -2103,9 +2109,8 @@ xfs_attr3_leaf_toosmall(
21032109
bytes = state->args->geo->blksize -
21042110
(state->args->geo->blksize >> 2) -
21052111
ichdr.usedbytes - ichdr2.usedbytes -
2106-
((ichdr.count + ichdr2.count) *
2107-
sizeof(xfs_attr_leaf_entry_t)) -
2108-
xfs_attr3_leaf_hdr_size(leaf);
2112+
xfs_attr_leaf_entries_end(ichdr.count + ichdr2.count,
2113+
leaf);
21092114

21102115
xfs_trans_brelse(state->args->trans, bp);
21112116
if (bytes >= 0)
@@ -2167,8 +2172,7 @@ xfs_attr3_leaf_remove(
21672172

21682173
ASSERT(ichdr.count > 0 && ichdr.count < args->geo->blksize / 8);
21692174
ASSERT(args->index >= 0 && args->index < ichdr.count);
2170-
ASSERT(ichdr.firstused >= ichdr.count * sizeof(*entry) +
2171-
xfs_attr3_leaf_hdr_size(leaf));
2175+
ASSERT(ichdr.firstused >= xfs_attr_leaf_entries_end(ichdr.count, leaf));
21722176

21732177
entry = &xfs_attr3_leaf_entryp(leaf)[args->index];
21742178

@@ -2181,8 +2185,7 @@ xfs_attr3_leaf_remove(
21812185
* find smallest free region in case we need to replace it,
21822186
* adjust any map that borders the entry table,
21832187
*/
2184-
tablesize = ichdr.count * sizeof(xfs_attr_leaf_entry_t)
2185-
+ xfs_attr3_leaf_hdr_size(leaf);
2188+
tablesize = xfs_attr_leaf_entries_end(ichdr.count, leaf);
21862189
tmp = ichdr.freemap[0].size;
21872190
before = after = -1;
21882191
smallest = XFS_ATTR_LEAF_MAPSIZE - 1;
@@ -2289,8 +2292,7 @@ xfs_attr3_leaf_remove(
22892292
* Check if leaf is less than 50% full, caller may want to
22902293
* "join" the leaf with a sibling if so.
22912294
*/
2292-
tmp = ichdr.usedbytes + xfs_attr3_leaf_hdr_size(leaf) +
2293-
ichdr.count * sizeof(xfs_attr_leaf_entry_t);
2295+
tmp = ichdr.usedbytes + xfs_attr_leaf_entries_end(ichdr.count, leaf);
22942296

22952297
return tmp < args->geo->magicpct; /* leaf is < 37% full */
22962298
}
@@ -2613,11 +2615,11 @@ xfs_attr3_leaf_moveents(
26132615
ichdr_s->magic == XFS_ATTR3_LEAF_MAGIC);
26142616
ASSERT(ichdr_s->magic == ichdr_d->magic);
26152617
ASSERT(ichdr_s->count > 0 && ichdr_s->count < args->geo->blksize / 8);
2616-
ASSERT(ichdr_s->firstused >= (ichdr_s->count * sizeof(*entry_s))
2617-
+ xfs_attr3_leaf_hdr_size(leaf_s));
2618+
ASSERT(ichdr_s->firstused >=
2619+
xfs_attr_leaf_entries_end(ichdr_s->count, leaf_s));
26182620
ASSERT(ichdr_d->count < args->geo->blksize / 8);
2619-
ASSERT(ichdr_d->firstused >= (ichdr_d->count * sizeof(*entry_d))
2620-
+ xfs_attr3_leaf_hdr_size(leaf_d));
2621+
ASSERT(ichdr_d->firstused >=
2622+
xfs_attr_leaf_entries_end(ichdr_d->count, leaf_d));
26212623

26222624
ASSERT(start_s < ichdr_s->count);
26232625
ASSERT(start_d <= ichdr_d->count);
@@ -2677,8 +2679,7 @@ xfs_attr3_leaf_moveents(
26772679
ichdr_d->usedbytes += tmp;
26782680
ichdr_s->count -= 1;
26792681
ichdr_d->count += 1;
2680-
tmp = ichdr_d->count * sizeof(xfs_attr_leaf_entry_t)
2681-
+ xfs_attr3_leaf_hdr_size(leaf_d);
2682+
tmp = xfs_attr_leaf_entries_end(ichdr_d->count, leaf_d);
26822683
ASSERT(ichdr_d->firstused >= tmp);
26832684
#ifdef GROT
26842685
}
@@ -2714,8 +2715,8 @@ xfs_attr3_leaf_moveents(
27142715
/*
27152716
* Fill in the freemap information
27162717
*/
2717-
ichdr_d->freemap[0].base = xfs_attr3_leaf_hdr_size(leaf_d);
2718-
ichdr_d->freemap[0].base += ichdr_d->count * sizeof(xfs_attr_leaf_entry_t);
2718+
ichdr_d->freemap[0].base =
2719+
xfs_attr_leaf_entries_end(ichdr_d->count, leaf_d);
27192720
ichdr_d->freemap[0].size = ichdr_d->firstused - ichdr_d->freemap[0].base;
27202721
ichdr_d->freemap[1].base = 0;
27212722
ichdr_d->freemap[2].base = 0;

fs/xfs/libxfs/xfs_da_format.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ struct xfs_attr3_leafblock {
746746
#define XFS_ATTR_LEAF_NAME_ALIGN ((uint)sizeof(xfs_dablk_t))
747747

748748
static inline int
749-
xfs_attr3_leaf_hdr_size(struct xfs_attr_leafblock *leafp)
749+
xfs_attr3_leaf_hdr_size(const struct xfs_attr_leafblock *leafp)
750750
{
751751
if (leafp->hdr.info.magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC))
752752
return sizeof(struct xfs_attr3_leaf_hdr);

0 commit comments

Comments
 (0)