Commit f73def90 authored by Darrick J. Wong's avatar Darrick J. Wong

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: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent 88ee2f48
...@@ -749,8 +749,7 @@ xfs_btree_get_block( ...@@ -749,8 +749,7 @@ xfs_btree_get_block(
int level, /* level in btree */ int level, /* level in btree */
struct xfs_buf **bpp) /* buffer containing the block */ struct xfs_buf **bpp) /* buffer containing the block */
{ {
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE && if (xfs_btree_at_iroot(cur, level)) {
level == cur->bc_nlevels - 1) {
*bpp = NULL; *bpp = NULL;
return xfs_btree_get_iroot(cur); return xfs_btree_get_iroot(cur);
} }
...@@ -992,8 +991,7 @@ xfs_btree_readahead( ...@@ -992,8 +991,7 @@ xfs_btree_readahead(
* No readahead needed if we are at the root level and the * No readahead needed if we are at the root level and the
* btree root is stored in the inode. * btree root is stored in the inode.
*/ */
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE && if (xfs_btree_at_iroot(cur, lev))
lev == cur->bc_nlevels - 1)
return 0; return 0;
if ((cur->bc_levels[lev].ra | lr) == cur->bc_levels[lev].ra) if ((cur->bc_levels[lev].ra | lr) == cur->bc_levels[lev].ra)
...@@ -1814,8 +1812,7 @@ xfs_btree_lookup_get_block( ...@@ -1814,8 +1812,7 @@ xfs_btree_lookup_get_block(
int error = 0; int error = 0;
/* special case the root block if in an inode */ /* special case the root block if in an inode */
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE && if (xfs_btree_at_iroot(cur, level)) {
level == cur->bc_nlevels - 1) {
*blkp = xfs_btree_get_iroot(cur); *blkp = xfs_btree_get_iroot(cur);
return 0; return 0;
} }
...@@ -2350,8 +2347,7 @@ xfs_btree_lshift( ...@@ -2350,8 +2347,7 @@ xfs_btree_lshift(
int error; /* error return value */ int error; /* error return value */
int i; int i;
if ((cur->bc_ops->type == XFS_BTREE_TYPE_INODE) && if (xfs_btree_at_iroot(cur, level))
level == cur->bc_nlevels - 1)
goto out0; goto out0;
/* Set up variables for this block as "right". */ /* Set up variables for this block as "right". */
...@@ -2546,8 +2542,7 @@ xfs_btree_rshift( ...@@ -2546,8 +2542,7 @@ xfs_btree_rshift(
int error; /* error return value */ int error; /* error return value */
int i; /* loop counter */ int i; /* loop counter */
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE && if (xfs_btree_at_iroot(cur, level))
level == cur->bc_nlevels - 1)
goto out0; goto out0;
/* Set up variables for this block as "left". */ /* Set up variables for this block as "left". */
...@@ -3246,8 +3241,7 @@ xfs_btree_make_block_unfull( ...@@ -3246,8 +3241,7 @@ xfs_btree_make_block_unfull(
{ {
int error = 0; int error = 0;
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE && if (xfs_btree_at_iroot(cur, level)) {
level == cur->bc_nlevels - 1) {
struct xfs_inode *ip = cur->bc_ino.ip; struct xfs_inode *ip = cur->bc_ino.ip;
if (numrecs < cur->bc_ops->get_dmaxrecs(cur, level)) { if (numrecs < cur->bc_ops->get_dmaxrecs(cur, level)) {
...@@ -3856,27 +3850,25 @@ xfs_btree_delrec( ...@@ -3856,27 +3850,25 @@ xfs_btree_delrec(
* Try to get rid of the next level down. If we can't then there's * Try to get rid of the next level down. If we can't then there's
* nothing left to do. * nothing left to do.
*/ */
if (level == cur->bc_nlevels - 1) { if (xfs_btree_at_iroot(cur, level)) {
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE) { xfs_iroot_realloc(cur->bc_ino.ip, -1, cur->bc_ino.whichfork);
xfs_iroot_realloc(cur->bc_ino.ip, -1,
cur->bc_ino.whichfork);
error = xfs_btree_kill_iroot(cur); error = xfs_btree_kill_iroot(cur);
if (error) if (error)
goto error0; goto error0;
error = xfs_btree_dec_cursor(cur, level, stat); error = xfs_btree_dec_cursor(cur, level, stat);
if (error) if (error)
goto error0; goto error0;
*stat = 1; *stat = 1;
return 0; return 0;
} }
/* /*
* If this is the root level, and there's only one entry left, * If this is the root level, and there's only one entry left, and it's
* and it's NOT the leaf level, then we can get rid of this * NOT the leaf level, then we can get rid of this level.
* level. */
*/ if (level == cur->bc_nlevels - 1) {
if (numrecs == 1 && level > 0) { if (numrecs == 1 && level > 0) {
union xfs_btree_ptr *pp; union xfs_btree_ptr *pp;
/* /*
......
...@@ -747,4 +747,14 @@ void xfs_btree_destroy_cur_caches(void); ...@@ -747,4 +747,14 @@ void xfs_btree_destroy_cur_caches(void);
int xfs_btree_goto_left_edge(struct xfs_btree_cur *cur); int xfs_btree_goto_left_edge(struct xfs_btree_cur *cur);
/* Does this level of the cursor point to the inode root (and not a block)? */
static inline bool
xfs_btree_at_iroot(
const struct xfs_btree_cur *cur,
int level)
{
return cur->bc_ops->type == XFS_BTREE_TYPE_INODE &&
level == cur->bc_nlevels - 1;
}
#endif /* __XFS_BTREE_H__ */ #endif /* __XFS_BTREE_H__ */
...@@ -398,8 +398,7 @@ xfs_btree_bload_prep_block( ...@@ -398,8 +398,7 @@ xfs_btree_bload_prep_block(
struct xfs_btree_block *new_block; struct xfs_btree_block *new_block;
int ret; int ret;
if (cur->bc_ops->type == XFS_BTREE_TYPE_INODE && if (xfs_btree_at_iroot(cur, level)) {
level == cur->bc_nlevels - 1) {
struct xfs_ifork *ifp = xfs_btree_ifork_ptr(cur); struct xfs_ifork *ifp = xfs_btree_ifork_ptr(cur);
size_t new_size; size_t new_size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment