Skip to content

Commit f73def9

Browse files
author
Darrick J. Wong
committed
xfs: create predicate to determine if cursor is at inode root level
Create a predicate to decide if the given cursor and level point to the root block in the inode immediate area instead of a disk block, and get rid of the open-coded logic everywhere. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent 88ee2f4 commit f73def9

3 files changed

Lines changed: 33 additions & 32 deletions

File tree

fs/xfs/libxfs/xfs_btree.c

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,7 @@ xfs_btree_get_block(
749749
int level, /* level in btree */
750750
struct xfs_buf **bpp) /* buffer containing the block */
751751
{
752-
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE &&
753-
level == cur->bc_nlevels - 1) {
752+
if (xfs_btree_at_iroot(cur, level)) {
754753
*bpp = NULL;
755754
return xfs_btree_get_iroot(cur);
756755
}
@@ -992,8 +991,7 @@ xfs_btree_readahead(
992991
* No readahead needed if we are at the root level and the
993992
* btree root is stored in the inode.
994993
*/
995-
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE &&
996-
lev == cur->bc_nlevels - 1)
994+
if (xfs_btree_at_iroot(cur, lev))
997995
return 0;
998996

999997
if ((cur->bc_levels[lev].ra | lr) == cur->bc_levels[lev].ra)
@@ -1814,8 +1812,7 @@ xfs_btree_lookup_get_block(
18141812
int error = 0;
18151813

18161814
/* special case the root block if in an inode */
1817-
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE &&
1818-
level == cur->bc_nlevels - 1) {
1815+
if (xfs_btree_at_iroot(cur, level)) {
18191816
*blkp = xfs_btree_get_iroot(cur);
18201817
return 0;
18211818
}
@@ -2350,8 +2347,7 @@ xfs_btree_lshift(
23502347
int error; /* error return value */
23512348
int i;
23522349

2353-
if ((cur->bc_ops->type == XFS_BTREE_TYPE_INODE) &&
2354-
level == cur->bc_nlevels - 1)
2350+
if (xfs_btree_at_iroot(cur, level))
23552351
goto out0;
23562352

23572353
/* Set up variables for this block as "right". */
@@ -2546,8 +2542,7 @@ xfs_btree_rshift(
25462542
int error; /* error return value */
25472543
int i; /* loop counter */
25482544

2549-
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE &&
2550-
level == cur->bc_nlevels - 1)
2545+
if (xfs_btree_at_iroot(cur, level))
25512546
goto out0;
25522547

25532548
/* Set up variables for this block as "left". */
@@ -3246,8 +3241,7 @@ xfs_btree_make_block_unfull(
32463241
{
32473242
int error = 0;
32483243

3249-
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE &&
3250-
level == cur->bc_nlevels - 1) {
3244+
if (xfs_btree_at_iroot(cur, level)) {
32513245
struct xfs_inode *ip = cur->bc_ino.ip;
32523246

32533247
if (numrecs < cur->bc_ops->get_dmaxrecs(cur, level)) {
@@ -3856,27 +3850,25 @@ xfs_btree_delrec(
38563850
* Try to get rid of the next level down. If we can't then there's
38573851
* nothing left to do.
38583852
*/
3859-
if (level == cur->bc_nlevels - 1) {
3860-
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE) {
3861-
xfs_iroot_realloc(cur->bc_ino.ip, -1,
3862-
cur->bc_ino.whichfork);
3853+
if (xfs_btree_at_iroot(cur, level)) {
3854+
xfs_iroot_realloc(cur->bc_ino.ip, -1, cur->bc_ino.whichfork);
38633855

3864-
error = xfs_btree_kill_iroot(cur);
3865-
if (error)
3866-
goto error0;
3856+
error = xfs_btree_kill_iroot(cur);
3857+
if (error)
3858+
goto error0;
38673859

3868-
error = xfs_btree_dec_cursor(cur, level, stat);
3869-
if (error)
3870-
goto error0;
3871-
*stat = 1;
3872-
return 0;
3873-
}
3860+
error = xfs_btree_dec_cursor(cur, level, stat);
3861+
if (error)
3862+
goto error0;
3863+
*stat = 1;
3864+
return 0;
3865+
}
38743866

3875-
/*
3876-
* If this is the root level, and there's only one entry left,
3877-
* and it's NOT the leaf level, then we can get rid of this
3878-
* level.
3879-
*/
3867+
/*
3868+
* If this is the root level, and there's only one entry left, and it's
3869+
* NOT the leaf level, then we can get rid of this level.
3870+
*/
3871+
if (level == cur->bc_nlevels - 1) {
38803872
if (numrecs == 1 && level > 0) {
38813873
union xfs_btree_ptr *pp;
38823874
/*

fs/xfs/libxfs/xfs_btree.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,4 +747,14 @@ void xfs_btree_destroy_cur_caches(void);
747747

748748
int xfs_btree_goto_left_edge(struct xfs_btree_cur *cur);
749749

750+
/* Does this level of the cursor point to the inode root (and not a block)? */
751+
static inline bool
752+
xfs_btree_at_iroot(
753+
const struct xfs_btree_cur *cur,
754+
int level)
755+
{
756+
return cur->bc_ops->type == XFS_BTREE_TYPE_INODE &&
757+
level == cur->bc_nlevels - 1;
758+
}
759+
750760
#endif /* __XFS_BTREE_H__ */

fs/xfs/libxfs/xfs_btree_staging.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,7 @@ xfs_btree_bload_prep_block(
398398
struct xfs_btree_block *new_block;
399399
int ret;
400400

401-
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE &&
402-
level == cur->bc_nlevels - 1) {
401+
if (xfs_btree_at_iroot(cur, level)) {
403402
struct xfs_ifork *ifp = xfs_btree_ifork_ptr(cur);
404403
size_t new_size;
405404

0 commit comments

Comments
 (0)