Skip to content

Commit 36081fd

Browse files
zhangyi089gregkh
authored andcommitted
xfs: make xfs_bmapi_convert_delalloc() to allocate the target offset
commit 2e08371 upstream. Since xfs_bmapi_convert_delalloc() only attempts to allocate the entire delalloc extent and require multiple invocations to allocate the target offset. So xfs_convert_blocks() add a loop to do this job and we call it in the write back path, but xfs_convert_blocks() isn't a common helper. Let's do it in xfs_bmapi_convert_delalloc() and drop xfs_convert_blocks(), preparing for the post EOF delalloc blocks converting in the buffered write begin path. Signed-off-by: Zhang Yi <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Chandan Babu R <[email protected]> Signed-off-by: Catherine Hoang <[email protected]> Acked-by: Darrick J. Wong <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0f726c1 commit 36081fd

File tree

2 files changed

+46
-42
lines changed

2 files changed

+46
-42
lines changed

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4537,8 +4537,8 @@ xfs_bmapi_write(
45374537
* invocations to allocate the target offset if a large enough physical extent
45384538
* is not available.
45394539
*/
4540-
int
4541-
xfs_bmapi_convert_delalloc(
4540+
static int
4541+
xfs_bmapi_convert_one_delalloc(
45424542
struct xfs_inode *ip,
45434543
int whichfork,
45444544
xfs_off_t offset,
@@ -4666,6 +4666,36 @@ xfs_bmapi_convert_delalloc(
46664666
return error;
46674667
}
46684668

4669+
/*
4670+
* Pass in a dellalloc extent and convert it to real extents, return the real
4671+
* extent that maps offset_fsb in iomap.
4672+
*/
4673+
int
4674+
xfs_bmapi_convert_delalloc(
4675+
struct xfs_inode *ip,
4676+
int whichfork,
4677+
loff_t offset,
4678+
struct iomap *iomap,
4679+
unsigned int *seq)
4680+
{
4681+
int error;
4682+
4683+
/*
4684+
* Attempt to allocate whatever delalloc extent currently backs offset
4685+
* and put the result into iomap. Allocate in a loop because it may
4686+
* take several attempts to allocate real blocks for a contiguous
4687+
* delalloc extent if free space is sufficiently fragmented.
4688+
*/
4689+
do {
4690+
error = xfs_bmapi_convert_one_delalloc(ip, whichfork, offset,
4691+
iomap, seq);
4692+
if (error)
4693+
return error;
4694+
} while (iomap->offset + iomap->length <= offset);
4695+
4696+
return 0;
4697+
}
4698+
46694699
int
46704700
xfs_bmapi_remap(
46714701
struct xfs_trans *tp,

fs/xfs/xfs_aops.c

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -233,45 +233,6 @@ xfs_imap_valid(
233233
return true;
234234
}
235235

236-
/*
237-
* Pass in a dellalloc extent and convert it to real extents, return the real
238-
* extent that maps offset_fsb in wpc->iomap.
239-
*
240-
* The current page is held locked so nothing could have removed the block
241-
* backing offset_fsb, although it could have moved from the COW to the data
242-
* fork by another thread.
243-
*/
244-
static int
245-
xfs_convert_blocks(
246-
struct iomap_writepage_ctx *wpc,
247-
struct xfs_inode *ip,
248-
int whichfork,
249-
loff_t offset)
250-
{
251-
int error;
252-
unsigned *seq;
253-
254-
if (whichfork == XFS_COW_FORK)
255-
seq = &XFS_WPC(wpc)->cow_seq;
256-
else
257-
seq = &XFS_WPC(wpc)->data_seq;
258-
259-
/*
260-
* Attempt to allocate whatever delalloc extent currently backs offset
261-
* and put the result into wpc->iomap. Allocate in a loop because it
262-
* may take several attempts to allocate real blocks for a contiguous
263-
* delalloc extent if free space is sufficiently fragmented.
264-
*/
265-
do {
266-
error = xfs_bmapi_convert_delalloc(ip, whichfork, offset,
267-
&wpc->iomap, seq);
268-
if (error)
269-
return error;
270-
} while (wpc->iomap.offset + wpc->iomap.length <= offset);
271-
272-
return 0;
273-
}
274-
275236
static int
276237
xfs_map_blocks(
277238
struct iomap_writepage_ctx *wpc,
@@ -289,6 +250,7 @@ xfs_map_blocks(
289250
struct xfs_iext_cursor icur;
290251
int retries = 0;
291252
int error = 0;
253+
unsigned int *seq;
292254

293255
if (xfs_is_shutdown(mp))
294256
return -EIO;
@@ -386,7 +348,19 @@ xfs_map_blocks(
386348
trace_xfs_map_blocks_found(ip, offset, count, whichfork, &imap);
387349
return 0;
388350
allocate_blocks:
389-
error = xfs_convert_blocks(wpc, ip, whichfork, offset);
351+
/*
352+
* Convert a dellalloc extent to a real one. The current page is held
353+
* locked so nothing could have removed the block backing offset_fsb,
354+
* although it could have moved from the COW to the data fork by another
355+
* thread.
356+
*/
357+
if (whichfork == XFS_COW_FORK)
358+
seq = &XFS_WPC(wpc)->cow_seq;
359+
else
360+
seq = &XFS_WPC(wpc)->data_seq;
361+
362+
error = xfs_bmapi_convert_delalloc(ip, whichfork, offset,
363+
&wpc->iomap, seq);
390364
if (error) {
391365
/*
392366
* If we failed to find the extent in the COW fork we might have

0 commit comments

Comments
 (0)