Skip to content

Commit 2187550

Browse files
Christoph HellwigFelix Blyakher
authored andcommitted
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: Christoph Hellwig <hch@lst.de> Reviewed-by: Alex Elder <aelder@sgi.com> Signed-off-by: Felix Blyakher <felixb@sgi.com>
1 parent 4254b0b commit 2187550

File tree

3 files changed

+32
-71
lines changed

3 files changed

+32
-71
lines changed

fs/xfs/xfs_ialloc.c

Lines changed: 22 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -57,56 +57,19 @@ xfs_ialloc_cluster_alignment(
5757
}
5858

5959
/*
60-
* Lookup the record equal to ino in the btree given by cur.
60+
* Lookup a record by ino in the btree given by cur.
6161
*/
6262
STATIC int /* error */
63-
xfs_inobt_lookup_eq(
63+
xfs_inobt_lookup(
6464
struct xfs_btree_cur *cur, /* btree cursor */
6565
xfs_agino_t ino, /* starting inode of chunk */
66-
__int32_t fcnt, /* free inode count */
67-
xfs_inofree_t free, /* free inode mask */
66+
xfs_lookup_t dir, /* <=, >=, == */
6867
int *stat) /* success/failure */
6968
{
7069
cur->bc_rec.i.ir_startino = ino;
71-
cur->bc_rec.i.ir_freecount = fcnt;
72-
cur->bc_rec.i.ir_free = free;
73-
return xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat);
74-
}
75-
76-
/*
77-
* Lookup the first record greater than or equal to ino
78-
* in the btree given by cur.
79-
*/
80-
int /* error */
81-
xfs_inobt_lookup_ge(
82-
struct xfs_btree_cur *cur, /* btree cursor */
83-
xfs_agino_t ino, /* starting inode of chunk */
84-
__int32_t fcnt, /* free inode count */
85-
xfs_inofree_t free, /* free inode mask */
86-
int *stat) /* success/failure */
87-
{
88-
cur->bc_rec.i.ir_startino = ino;
89-
cur->bc_rec.i.ir_freecount = fcnt;
90-
cur->bc_rec.i.ir_free = free;
91-
return xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat);
92-
}
93-
94-
/*
95-
* Lookup the first record less than or equal to ino
96-
* in the btree given by cur.
97-
*/
98-
int /* error */
99-
xfs_inobt_lookup_le(
100-
struct xfs_btree_cur *cur, /* btree cursor */
101-
xfs_agino_t ino, /* starting inode of chunk */
102-
__int32_t fcnt, /* free inode count */
103-
xfs_inofree_t free, /* free inode mask */
104-
int *stat) /* success/failure */
105-
{
106-
cur->bc_rec.i.ir_startino = ino;
107-
cur->bc_rec.i.ir_freecount = fcnt;
108-
cur->bc_rec.i.ir_free = free;
109-
return xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat);
70+
cur->bc_rec.i.ir_freecount = 0;
71+
cur->bc_rec.i.ir_free = 0;
72+
return xfs_btree_lookup(cur, dir, stat);
11073
}
11174

11275
/*
@@ -162,7 +125,7 @@ xfs_check_agi_freecount(
162125
int error;
163126
int i;
164127

165-
error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i);
128+
error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i);
166129
if (error)
167130
return error;
168131

@@ -431,13 +394,17 @@ xfs_ialloc_ag_alloc(
431394
for (thisino = newino;
432395
thisino < newino + newlen;
433396
thisino += XFS_INODES_PER_CHUNK) {
434-
if ((error = xfs_inobt_lookup_eq(cur, thisino,
435-
XFS_INODES_PER_CHUNK, XFS_INOBT_ALL_FREE, &i))) {
397+
cur->bc_rec.i.ir_startino = thisino;
398+
cur->bc_rec.i.ir_freecount = XFS_INODES_PER_CHUNK;
399+
cur->bc_rec.i.ir_free = XFS_INOBT_ALL_FREE;
400+
error = xfs_btree_lookup(cur, XFS_LOOKUP_EQ, &i);
401+
if (error) {
436402
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
437403
return error;
438404
}
439405
ASSERT(i == 0);
440-
if ((error = xfs_btree_insert(cur, &i))) {
406+
error = xfs_btree_insert(cur, &i);
407+
if (error) {
441408
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
442409
return error;
443410
}
@@ -818,7 +785,7 @@ xfs_dialloc(
818785
int doneleft; /* done, to the left */
819786
int doneright; /* done, to the right */
820787

821-
error = xfs_inobt_lookup_le(cur, pagino, 0, 0, &i);
788+
error = xfs_inobt_lookup(cur, pagino, XFS_LOOKUP_LE, &i);
822789
if (error)
823790
goto error0;
824791
XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
@@ -904,8 +871,8 @@ xfs_dialloc(
904871
* See if the most recently allocated block has any free.
905872
*/
906873
else if (be32_to_cpu(agi->agi_newino) != NULLAGINO) {
907-
error = xfs_inobt_lookup_eq(cur, be32_to_cpu(agi->agi_newino),
908-
0, 0, &i);
874+
error = xfs_inobt_lookup(cur, be32_to_cpu(agi->agi_newino),
875+
XFS_LOOKUP_EQ, &i);
909876
if (error)
910877
goto error0;
911878

@@ -926,7 +893,7 @@ xfs_dialloc(
926893
/*
927894
* None left in the last group, search the whole AG
928895
*/
929-
error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &i);
896+
error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &i);
930897
if (error)
931898
goto error0;
932899
XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
@@ -1065,9 +1032,9 @@ xfs_difree(
10651032
/*
10661033
* Look for the entry describing this inode.
10671034
*/
1068-
if ((error = xfs_inobt_lookup_le(cur, agino, 0, 0, &i))) {
1035+
if ((error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &i))) {
10691036
cmn_err(CE_WARN,
1070-
"xfs_difree: xfs_inobt_lookup_le returned() an error %d on %s. Returning error.",
1037+
"xfs_difree: xfs_inobt_lookup returned() an error %d on %s. Returning error.",
10711038
error, mp->m_fsname);
10721039
goto error0;
10731040
}
@@ -1277,10 +1244,10 @@ xfs_imap(
12771244
}
12781245

12791246
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno);
1280-
error = xfs_inobt_lookup_le(cur, agino, 0, 0, &i);
1247+
error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &i);
12811248
if (error) {
12821249
xfs_fs_cmn_err(CE_ALERT, mp, "xfs_imap: "
1283-
"xfs_inobt_lookup_le() failed");
1250+
"xfs_inobt_lookup() failed");
12841251
goto error0;
12851252
}
12861253

fs/xfs/xfs_ialloc.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,10 @@ xfs_ialloc_pagi_init(
150150
xfs_agnumber_t agno); /* allocation group number */
151151

152152
/*
153-
* Lookup the first record greater than or equal to ino
154-
* in the btree given by cur.
153+
* Lookup a record by ino in the btree given by cur.
155154
*/
156-
int xfs_inobt_lookup_ge(struct xfs_btree_cur *cur, xfs_agino_t ino,
157-
__int32_t fcnt, xfs_inofree_t free, int *stat);
158-
159-
/*
160-
* Lookup the first record less than or equal to ino
161-
* in the btree given by cur.
162-
*/
163-
int xfs_inobt_lookup_le(struct xfs_btree_cur *cur, xfs_agino_t ino,
164-
__int32_t fcnt, xfs_inofree_t free, int *stat);
155+
int xfs_inobt_lookup(struct xfs_btree_cur *cur, xfs_agino_t ino,
156+
xfs_lookup_t dir, int *stat);
165157

166158
/*
167159
* Get the data from the pointed-to record.

fs/xfs/xfs_itable.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ xfs_bulkstat(
444444
/*
445445
* Lookup the inode chunk that this inode lives in.
446446
*/
447-
error = xfs_inobt_lookup_le(cur, agino, 0, 0, &tmp);
447+
error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE,
448+
&tmp);
448449
if (!error && /* no I/O error */
449450
tmp && /* lookup succeeded */
450451
/* got the record, should always work */
@@ -492,7 +493,7 @@ xfs_bulkstat(
492493
/*
493494
* Start of ag. Lookup the first inode chunk.
494495
*/
495-
error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &tmp);
496+
error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &tmp);
496497
icount = 0;
497498
}
498499
/*
@@ -511,8 +512,8 @@ xfs_bulkstat(
511512
if (XFS_AGINO_TO_AGBNO(mp, agino) >=
512513
be32_to_cpu(agi->agi_length))
513514
break;
514-
error = xfs_inobt_lookup_ge(cur, agino, 0, 0,
515-
&tmp);
515+
error = xfs_inobt_lookup(cur, agino,
516+
XFS_LOOKUP_GE, &tmp);
516517
cond_resched();
517518
}
518519
/*
@@ -858,7 +859,8 @@ xfs_inumbers(
858859
continue;
859860
}
860861
cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno);
861-
error = xfs_inobt_lookup_ge(cur, agino, 0, 0, &tmp);
862+
error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_GE,
863+
&tmp);
862864
if (error) {
863865
xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
864866
cur = NULL;

0 commit comments

Comments
 (0)