Skip to content

Commit 089ec2f

Browse files
Christoph Hellwigdjwong
authored andcommitted
xfs: simplify xfs_rtallocate_extent
We can deduce the allocation type from the bno argument, and do the return without prod much simpler internally. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> [darrick: fix the macro for the non-rt build] Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
1 parent 410d17f commit 089ec2f

File tree

3 files changed

+13
-27
lines changed

3 files changed

+13
-27
lines changed

fs/xfs/xfs_bmap_util.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ int
8888
xfs_bmap_rtalloc(
8989
struct xfs_bmalloca *ap) /* bmap alloc argument struct */
9090
{
91-
xfs_alloctype_t atype = 0; /* type for allocation routines */
9291
int error; /* error return value */
9392
xfs_mount_t *mp; /* mount point structure */
9493
xfs_extlen_t prod = 0; /* product factor for allocators */
@@ -155,18 +154,14 @@ xfs_bmap_rtalloc(
155154
/*
156155
* Realtime allocation, done through xfs_rtallocate_extent.
157156
*/
158-
atype = ap->blkno == 0 ? XFS_ALLOCTYPE_ANY_AG : XFS_ALLOCTYPE_NEAR_BNO;
159157
do_div(ap->blkno, mp->m_sb.sb_rextsize);
160158
rtb = ap->blkno;
161159
ap->length = ralen;
162-
if ((error = xfs_rtallocate_extent(ap->tp, ap->blkno, 1, ap->length,
163-
&ralen, atype, ap->wasdel, prod, &rtb)))
164-
return error;
165-
if (rtb == NULLFSBLOCK && prod > 1 &&
166-
(error = xfs_rtallocate_extent(ap->tp, ap->blkno, 1,
167-
ap->length, &ralen, atype,
168-
ap->wasdel, 1, &rtb)))
160+
error = xfs_rtallocate_extent(ap->tp, ap->blkno, 1, ap->length,
161+
&ralen, ap->wasdel, prod, &rtb);
162+
if (error)
169163
return error;
164+
170165
ap->blkno = rtb;
171166
if (ap->blkno != NULLFSBLOCK) {
172167
ap->blkno *= mp->m_sb.sb_rextsize;

fs/xfs/xfs_rtalloc.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,6 @@ xfs_rtallocate_extent(
10931093
xfs_extlen_t minlen, /* minimum length to allocate */
10941094
xfs_extlen_t maxlen, /* maximum length to allocate */
10951095
xfs_extlen_t *len, /* out: actual length allocated */
1096-
xfs_alloctype_t type, /* allocation type XFS_ALLOCTYPE... */
10971096
int wasdel, /* was a delayed allocation extent */
10981097
xfs_extlen_t prod, /* extent product factor */
10991098
xfs_rtblock_t *rtblock) /* out: start block allocated */
@@ -1123,27 +1122,16 @@ xfs_rtallocate_extent(
11231122
}
11241123
}
11251124

1125+
retry:
11261126
sumbp = NULL;
1127-
/*
1128-
* Allocate by size, or near another block, or exactly at some block.
1129-
*/
1130-
switch (type) {
1131-
case XFS_ALLOCTYPE_ANY_AG:
1127+
if (bno == 0) {
11321128
error = xfs_rtallocate_extent_size(mp, tp, minlen, maxlen, len,
11331129
&sumbp, &sb, prod, &r);
1134-
break;
1135-
case XFS_ALLOCTYPE_NEAR_BNO:
1130+
} else {
11361131
error = xfs_rtallocate_extent_near(mp, tp, bno, minlen, maxlen,
11371132
len, &sumbp, &sb, prod, &r);
1138-
break;
1139-
case XFS_ALLOCTYPE_THIS_BNO:
1140-
error = xfs_rtallocate_extent_exact(mp, tp, bno, minlen, maxlen,
1141-
len, &sumbp, &sb, prod, &r);
1142-
break;
1143-
default:
1144-
error = -EIO;
1145-
ASSERT(0);
11461133
}
1134+
11471135
if (error)
11481136
return error;
11491137

@@ -1158,7 +1146,11 @@ xfs_rtallocate_extent(
11581146
xfs_trans_mod_sb(tp, XFS_TRANS_SB_RES_FREXTENTS, -slen);
11591147
else
11601148
xfs_trans_mod_sb(tp, XFS_TRANS_SB_FREXTENTS, -slen);
1149+
} else if (prod > 1) {
1150+
prod = 1;
1151+
goto retry;
11611152
}
1153+
11621154
*rtblock = r;
11631155
return 0;
11641156
}

fs/xfs/xfs_rtalloc.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ xfs_rtallocate_extent(
4040
xfs_extlen_t minlen, /* minimum length to allocate */
4141
xfs_extlen_t maxlen, /* maximum length to allocate */
4242
xfs_extlen_t *len, /* out: actual length allocated */
43-
xfs_alloctype_t type, /* allocation type XFS_ALLOCTYPE... */
4443
int wasdel, /* was a delayed allocation extent */
4544
xfs_extlen_t prod, /* extent product factor */
4645
xfs_rtblock_t *rtblock); /* out: start block allocated */
@@ -122,7 +121,7 @@ int xfs_rtfree_range(struct xfs_mount *mp, struct xfs_trans *tp,
122121

123122

124123
#else
125-
# define xfs_rtallocate_extent(t,b,min,max,l,a,f,p,rb) (ENOSYS)
124+
# define xfs_rtallocate_extent(t,b,min,max,l,f,p,rb) (ENOSYS)
126125
# define xfs_rtfree_extent(t,b,l) (ENOSYS)
127126
# define xfs_rtpick_extent(m,t,l,rb) (ENOSYS)
128127
# define xfs_growfs_rt(mp,in) (ENOSYS)

0 commit comments

Comments
 (0)