Skip to content

Commit 2e08371

Browse files
zhangyi089Chandan Babu R
authored andcommitted
xfs: make xfs_bmapi_convert_delalloc() to allocate the target offset
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]>
1 parent fc8d0ba commit 2e08371

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
@@ -4590,8 +4590,8 @@ xfs_bmapi_write(
45904590
* invocations to allocate the target offset if a large enough physical extent
45914591
* is not available.
45924592
*/
4593-
int
4594-
xfs_bmapi_convert_delalloc(
4593+
static int
4594+
xfs_bmapi_convert_one_delalloc(
45954595
struct xfs_inode *ip,
45964596
int whichfork,
45974597
xfs_off_t offset,
@@ -4724,6 +4724,36 @@ xfs_bmapi_convert_delalloc(
47244724
return error;
47254725
}
47264726

4727+
/*
4728+
* Pass in a dellalloc extent and convert it to real extents, return the real
4729+
* extent that maps offset_fsb in iomap.
4730+
*/
4731+
int
4732+
xfs_bmapi_convert_delalloc(
4733+
struct xfs_inode *ip,
4734+
int whichfork,
4735+
loff_t offset,
4736+
struct iomap *iomap,
4737+
unsigned int *seq)
4738+
{
4739+
int error;
4740+
4741+
/*
4742+
* Attempt to allocate whatever delalloc extent currently backs offset
4743+
* and put the result into iomap. Allocate in a loop because it may
4744+
* take several attempts to allocate real blocks for a contiguous
4745+
* delalloc extent if free space is sufficiently fragmented.
4746+
*/
4747+
do {
4748+
error = xfs_bmapi_convert_one_delalloc(ip, whichfork, offset,
4749+
iomap, seq);
4750+
if (error)
4751+
return error;
4752+
} while (iomap->offset + iomap->length <= offset);
4753+
4754+
return 0;
4755+
}
4756+
47274757
int
47284758
xfs_bmapi_remap(
47294759
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,
@@ -290,6 +251,7 @@ xfs_map_blocks(
290251
struct xfs_iext_cursor icur;
291252
int retries = 0;
292253
int error = 0;
254+
unsigned int *seq;
293255

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

0 commit comments

Comments
 (0)