Commit 21875505 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Felix Blyakher

xfs: rationalize xfs_inobt_lookup*

Currenly we have a xfs_inobt_lookup* variant for each comparism direction,
and all these get all three fields of the inobt records passed, while the
common case is just looking for the inode number and we have only marginally
more callers than xfs_inobt_lookup* variants.

So opencode a direct call to xfs_btree_lookup for the single case where we
need all fields, and replace xfs_inobt_lookup* with a xfs_inobt_looku that
just takes the inode number and the direction for all other callers.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarAlex Elder <aelder@sgi.com>
Signed-off-by: default avatarFelix Blyakher <felixb@sgi.com>
parent 4254b0bb
...@@ -57,56 +57,19 @@ xfs_ialloc_cluster_alignment( ...@@ -57,56 +57,19 @@ xfs_ialloc_cluster_alignment(
} }
/* /*
* Lookup the record equal to ino in the btree given by cur. * Lookup a record by ino in the btree given by cur.
*/ */
STATIC int /* error */ STATIC int /* error */
xfs_inobt_lookup_eq( xfs_inobt_lookup(
struct xfs_btree_cur *cur, /* btree cursor */ struct xfs_btree_cur *cur, /* btree cursor */
xfs_agino_t ino, /* starting inode of chunk */ xfs_agino_t ino, /* starting inode of chunk */
__int32_t fcnt, /* free inode count */ xfs_lookup_t dir, /* <=, >=, == */
xfs_inofree_t free, /* free inode mask */
int *stat) /* success/failure */ int *stat) /* success/failure */
{ {
cur->bc_rec.i.ir_startino = ino; cur->bc_rec.i.ir_startino = ino;
cur->bc_rec.i.ir_freecount = fcnt; cur->bc_rec.i.ir_freecount = 0;
cur->bc_rec.i.ir_free = free; cur->bc_rec.i.ir_free = 0;
return xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat); return xfs_btree_lookup(cur, dir, stat);
}
/*
* Lookup the first record greater than or equal to ino
* in the btree given by cur.
*/
int /* error */
xfs_inobt_lookup_ge(
struct xfs_btree_cur *cur, /* btree cursor */
xfs_agino_t ino, /* starting inode of chunk */
__int32_t fcnt, /* free inode count */
xfs_inofree_t free, /* free inode mask */
int *stat) /* success/failure */
{
cur->bc_rec.i.ir_startino = ino;
cur->bc_rec.i.ir_freecount = fcnt;
cur->bc_rec.i.ir_free = free;
return xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat);
}
/*
* Lookup the first record less than or equal to ino
* in the btree given by cur.
*/
int /* error */
xfs_inobt_lookup_le(
struct xfs_btree_cur *cur, /* btree cursor */
xfs_agino_t ino, /* starting inode of chunk */
__int32_t fcnt, /* free inode count */
xfs_inofree_t free, /* free inode mask */
int *stat) /* success/failure */
{
cur->bc_rec.i.ir_startino = ino;
cur->bc_rec.i.ir_freecount = fcnt;
cur->bc_rec.i.ir_free = free;
return xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat);
} }
/* /*
...@@ -162,7 +125,7 @@ xfs_check_agi_freecount( ...@@ -162,7 +125,7 @@ xfs_check_agi_freecount(
int error; int error;
int i; int i;
error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i); error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i);
if (error) if (error)
return error; return error;
...@@ -431,13 +394,17 @@ xfs_ialloc_ag_alloc( ...@@ -431,13 +394,17 @@ xfs_ialloc_ag_alloc(
for (thisino = newino; for (thisino = newino;
thisino < newino + newlen; thisino < newino + newlen;
thisino += XFS_INODES_PER_CHUNK) { thisino += XFS_INODES_PER_CHUNK) {
if ((error = xfs_inobt_lookup_eq(cur, thisino, cur->bc_rec.i.ir_startino = thisino;
XFS_INODES_PER_CHUNK, XFS_INOBT_ALL_FREE, &i))) { cur->bc_rec.i.ir_freecount = XFS_INODES_PER_CHUNK;
cur->bc_rec.i.ir_free = XFS_INOBT_ALL_FREE;
error = xfs_btree_lookup(cur, XFS_LOOKUP_EQ, &i);
if (error) {
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
return error; return error;
} }
ASSERT(i == 0); ASSERT(i == 0);
if ((error = xfs_btree_insert(cur, &i))) { error = xfs_btree_insert(cur, &i);
if (error) {
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
return error; return error;
} }
...@@ -818,7 +785,7 @@ xfs_dialloc( ...@@ -818,7 +785,7 @@ xfs_dialloc(
int doneleft; /* done, to the left */ int doneleft; /* done, to the left */
int doneright; /* done, to the right */ int doneright; /* done, to the right */
error = xfs_inobt_lookup_le(cur, pagino, 0, 0, &i); error = xfs_inobt_lookup(cur, pagino, XFS_LOOKUP_LE, &i);
if (error) if (error)
goto error0; goto error0;
XFS_WANT_CORRUPTED_GOTO(i == 1, error0); XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
...@@ -904,8 +871,8 @@ xfs_dialloc( ...@@ -904,8 +871,8 @@ xfs_dialloc(
* See if the most recently allocated block has any free. * See if the most recently allocated block has any free.
*/ */
else if (be32_to_cpu(agi->agi_newino) != NULLAGINO) { else if (be32_to_cpu(agi->agi_newino) != NULLAGINO) {
error = xfs_inobt_lookup_eq(cur, be32_to_cpu(agi->agi_newino), error = xfs_inobt_lookup(cur, be32_to_cpu(agi->agi_newino),
0, 0, &i); XFS_LOOKUP_EQ, &i);
if (error) if (error)
goto error0; goto error0;
...@@ -926,7 +893,7 @@ xfs_dialloc( ...@@ -926,7 +893,7 @@ xfs_dialloc(
/* /*
* None left in the last group, search the whole AG * None left in the last group, search the whole AG
*/ */
error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i); error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i);
if (error) if (error)
goto error0; goto error0;
XFS_WANT_CORRUPTED_GOTO(i == 1, error0); XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
...@@ -1065,9 +1032,9 @@ xfs_difree( ...@@ -1065,9 +1032,9 @@ xfs_difree(
/* /*
* Look for the entry describing this inode. * Look for the entry describing this inode.
*/ */
if ((error = xfs_inobt_lookup_le(cur, agino, 0, 0, &i))) { if ((error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &i))) {
cmn_err(CE_WARN, cmn_err(CE_WARN,
"xfs_difree: xfs_inobt_lookup_le returned() an error %d on %s. Returning error.", "xfs_difree: xfs_inobt_lookup returned() an error %d on %s. Returning error.",
error, mp->m_fsname); error, mp->m_fsname);
goto error0; goto error0;
} }
...@@ -1277,10 +1244,10 @@ xfs_imap( ...@@ -1277,10 +1244,10 @@ xfs_imap(
} }
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno); cur = xfs_inobt_init_cursor(mp, tp, agbp, agno);
error = xfs_inobt_lookup_le(cur, agino, 0, 0, &i); error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &i);
if (error) { if (error) {
xfs_fs_cmn_err(CE_ALERT, mp, "xfs_imap: " xfs_fs_cmn_err(CE_ALERT, mp, "xfs_imap: "
"xfs_inobt_lookup_le() failed"); "xfs_inobt_lookup() failed");
goto error0; goto error0;
} }
......
...@@ -150,18 +150,10 @@ xfs_ialloc_pagi_init( ...@@ -150,18 +150,10 @@ xfs_ialloc_pagi_init(
xfs_agnumber_t agno); /* allocation group number */ xfs_agnumber_t agno); /* allocation group number */
/* /*
* Lookup the first record greater than or equal to ino * Lookup a record by ino in the btree given by cur.
* in the btree given by cur.
*/ */
int xfs_inobt_lookup_ge(struct xfs_btree_cur *cur, xfs_agino_t ino, int xfs_inobt_lookup(struct xfs_btree_cur *cur, xfs_agino_t ino,
__int32_t fcnt, xfs_inofree_t free, int *stat); xfs_lookup_t dir, int *stat);
/*
* Lookup the first record less than or equal to ino
* in the btree given by cur.
*/
int xfs_inobt_lookup_le(struct xfs_btree_cur *cur, xfs_agino_t ino,
__int32_t fcnt, xfs_inofree_t free, int *stat);
/* /*
* Get the data from the pointed-to record. * Get the data from the pointed-to record.
......
...@@ -444,7 +444,8 @@ xfs_bulkstat( ...@@ -444,7 +444,8 @@ xfs_bulkstat(
/* /*
* Lookup the inode chunk that this inode lives in. * Lookup the inode chunk that this inode lives in.
*/ */
error = xfs_inobt_lookup_le(cur, agino, 0, 0, &tmp); error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE,
&tmp);
if (!error && /* no I/O error */ if (!error && /* no I/O error */
tmp && /* lookup succeeded */ tmp && /* lookup succeeded */
/* got the record, should always work */ /* got the record, should always work */
...@@ -492,7 +493,7 @@ xfs_bulkstat( ...@@ -492,7 +493,7 @@ xfs_bulkstat(
/* /*
* Start of ag. Lookup the first inode chunk. * Start of ag. Lookup the first inode chunk.
*/ */
error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &tmp); error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &tmp);
icount = 0; icount = 0;
} }
/* /*
...@@ -511,8 +512,8 @@ xfs_bulkstat( ...@@ -511,8 +512,8 @@ xfs_bulkstat(
if (XFS_AGINO_TO_AGBNO(mp, agino) >= if (XFS_AGINO_TO_AGBNO(mp, agino) >=
be32_to_cpu(agi->agi_length)) be32_to_cpu(agi->agi_length))
break; break;
error = xfs_inobt_lookup_ge(cur, agino, 0, 0, error = xfs_inobt_lookup(cur, agino,
&tmp); XFS_LOOKUP_GE, &tmp);
cond_resched(); cond_resched();
} }
/* /*
...@@ -858,7 +859,8 @@ xfs_inumbers( ...@@ -858,7 +859,8 @@ xfs_inumbers(
continue; continue;
} }
cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno); cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno);
error = xfs_inobt_lookup_ge(cur, agino, 0, 0, &tmp); error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_GE,
&tmp);
if (error) { if (error) {
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR); xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
cur = NULL; cur = NULL;
......
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