Skip to content

Commit 26e5eed

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: reorder the minlen and prod calculations in xfs_bmap_rtalloc
xfs_bmap_rtalloc is a bit of a mess in terms of calculating the locally need variables. Reorder them a bit so that related code is located next to each other - the raminlen calculation moves up next to where the maximum len is calculated, and all the prod calculation is move into a single place and rearranged so that the real prod calculation only happens when it actually is needed. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
1 parent a39f5cc commit 26e5eed

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

fs/xfs/xfs_rtalloc.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,6 @@ xfs_bmap_rtalloc(
13751375

13761376
align = xfs_get_extsz_hint(ap->ip);
13771377
retry:
1378-
prod = xfs_extlen_to_rtxlen(mp, align);
13791378
error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev,
13801379
align, 1, ap->eof, 0,
13811380
ap->conv, &ap->offset, &ap->length);
@@ -1393,13 +1392,6 @@ xfs_bmap_rtalloc(
13931392
if (ap->offset != orig_offset)
13941393
minlen += orig_offset - ap->offset;
13951394

1396-
/*
1397-
* If the offset & length are not perfectly aligned
1398-
* then kill prod, it will just get us in trouble.
1399-
*/
1400-
div_u64_rem(ap->offset, align, &mod);
1401-
if (mod || ap->length % align)
1402-
prod = 1;
14031395
/*
14041396
* Set ralen to be the actual requested length in rtextents.
14051397
*
@@ -1410,6 +1402,7 @@ xfs_bmap_rtalloc(
14101402
* adjust the starting point to match it.
14111403
*/
14121404
ralen = xfs_extlen_to_rtxlen(mp, min(ap->length, XFS_MAX_BMBT_EXTLEN));
1405+
raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen));
14131406

14141407
/*
14151408
* Lock out modifications to both the RT bitmap and summary inodes
@@ -1438,7 +1431,16 @@ xfs_bmap_rtalloc(
14381431
start = 0;
14391432
}
14401433

1441-
raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen));
1434+
/*
1435+
* Only bother calculating a real prod factor if offset & length are
1436+
* perfectly aligned, otherwise it will just get us in trouble.
1437+
*/
1438+
div_u64_rem(ap->offset, align, &mod);
1439+
if (mod || ap->length % align)
1440+
prod = 1;
1441+
else
1442+
prod = xfs_extlen_to_rtxlen(mp, align);
1443+
14421444
error = xfs_rtallocate_extent(ap->tp, start, raminlen, ralen, &ralen,
14431445
ap->wasdel, prod, &rtx);
14441446
if (error == -ENOSPC) {

0 commit comments

Comments
 (0)