Skip to content

Commit 2a9b99d

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: pass the actual offset and len to allocate to xfs_bmapi_allocate
xfs_bmapi_allocate currently overwrites offset and len when converting delayed allocations, and duplicates the length cap done for non-delalloc allocations. Move all that logic into the callers to avoid duplication and to make the calling conventions more obvious. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent 9d06960 commit 2a9b99d

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4185,21 +4185,11 @@ xfs_bmapi_allocate(
41854185
int error;
41864186

41874187
ASSERT(bma->length > 0);
4188+
ASSERT(bma->length <= XFS_MAX_BMBT_EXTLEN);
41884189

4189-
/*
4190-
* For the wasdelay case, we could also just allocate the stuff asked
4191-
* for in this bmap call but that wouldn't be as good.
4192-
*/
41934190
if (bma->wasdel) {
4194-
bma->length = (xfs_extlen_t)bma->got.br_blockcount;
4195-
bma->offset = bma->got.br_startoff;
41964191
if (!xfs_iext_peek_prev_extent(ifp, &bma->icur, &bma->prev))
41974192
bma->prev.br_startoff = NULLFILEOFF;
4198-
} else {
4199-
bma->length = XFS_FILBLKS_MIN(bma->length, XFS_MAX_BMBT_EXTLEN);
4200-
if (!bma->eof)
4201-
bma->length = XFS_FILBLKS_MIN(bma->length,
4202-
bma->got.br_startoff - bma->offset);
42034193
}
42044194

42054195
if (bma->flags & XFS_BMAPI_CONTIG)
@@ -4533,6 +4523,15 @@ xfs_bmapi_write(
45334523
*/
45344524
bma.length = XFS_FILBLKS_MIN(len, XFS_MAX_BMBT_EXTLEN);
45354525

4526+
if (wasdelay) {
4527+
bma.offset = bma.got.br_startoff;
4528+
bma.length = bma.got.br_blockcount;
4529+
} else {
4530+
if (!eof)
4531+
bma.length = XFS_FILBLKS_MIN(bma.length,
4532+
bma.got.br_startoff - bno);
4533+
}
4534+
45364535
ASSERT(bma.length > 0);
45374536
error = xfs_bmapi_allocate(&bma);
45384537
if (error) {
@@ -4686,11 +4685,16 @@ xfs_bmapi_convert_one_delalloc(
46864685
bma.tp = tp;
46874686
bma.ip = ip;
46884687
bma.wasdel = true;
4689-
bma.offset = bma.got.br_startoff;
4690-
bma.length = max_t(xfs_filblks_t, bma.got.br_blockcount,
4691-
XFS_MAX_BMBT_EXTLEN);
46924688
bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork);
46934689

4690+
/*
4691+
* Always allocate convert from the start of the delalloc extent even if
4692+
* that is outside the passed in range to create large contiguous
4693+
* extents on disk.
4694+
*/
4695+
bma.offset = bma.got.br_startoff;
4696+
bma.length = bma.got.br_blockcount;
4697+
46944698
/*
46954699
* When we're converting the delalloc reservations backing dirty pages
46964700
* in the page cache, we must be careful about how we create the new

0 commit comments

Comments
 (0)