Skip to content

Commit f782088

Browse files
Brian Fosterdchinner
authored andcommitted
xfs: pass post-eof speculative prealloc blocks to bmapi
xfs_file_iomap_begin_delay() implements post-eof speculative preallocation by extending the block count of the requested delayed allocation. Now that xfs_bmapi_reserve_delalloc() has been updated to handle prealloc blocks separately and tag the inode, update xfs_file_iomap_begin_delay() to use the new parameter and rely on the former to tag the inode. Note that this patch does not change behavior. Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com>
1 parent 0260d8f commit f782088

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

fs/xfs/xfs_iomap.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,11 @@ xfs_file_iomap_begin_delay(
536536
xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset);
537537
xfs_fileoff_t maxbytes_fsb =
538538
XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes);
539-
xfs_fileoff_t end_fsb, orig_end_fsb;
539+
xfs_fileoff_t end_fsb;
540540
int error = 0, eof = 0;
541541
struct xfs_bmbt_irec got;
542542
xfs_extnum_t idx;
543+
xfs_fsblock_t prealloc_blocks = 0;
543544

544545
ASSERT(!XFS_IS_REALTIME_INODE(ip));
545546
ASSERT(!xfs_get_extsz_hint(ip));
@@ -594,56 +595,48 @@ xfs_file_iomap_begin_delay(
594595
* the lower level functions are updated.
595596
*/
596597
count = min_t(loff_t, count, 1024 * PAGE_SIZE);
597-
end_fsb = orig_end_fsb =
598-
min(XFS_B_TO_FSB(mp, offset + count), maxbytes_fsb);
598+
end_fsb = min(XFS_B_TO_FSB(mp, offset + count), maxbytes_fsb);
599599

600600
if (eof) {
601-
xfs_fsblock_t prealloc_blocks;
602-
603601
prealloc_blocks = xfs_iomap_prealloc_size(ip, offset, count, idx);
604602
if (prealloc_blocks) {
605603
xfs_extlen_t align;
606604
xfs_off_t end_offset;
605+
xfs_fileoff_t p_end_fsb;
607606

608607
end_offset = XFS_WRITEIO_ALIGN(mp, offset + count - 1);
609-
end_fsb = XFS_B_TO_FSBT(mp, end_offset) +
610-
prealloc_blocks;
608+
p_end_fsb = XFS_B_TO_FSBT(mp, end_offset) +
609+
prealloc_blocks;
611610

612611
align = xfs_eof_alignment(ip, 0);
613612
if (align)
614-
end_fsb = roundup_64(end_fsb, align);
613+
p_end_fsb = roundup_64(p_end_fsb, align);
615614

616-
end_fsb = min(end_fsb, maxbytes_fsb);
617-
ASSERT(end_fsb > offset_fsb);
615+
p_end_fsb = min(p_end_fsb, maxbytes_fsb);
616+
ASSERT(p_end_fsb > offset_fsb);
617+
prealloc_blocks = p_end_fsb - end_fsb;
618618
}
619619
}
620620

621621
retry:
622622
error = xfs_bmapi_reserve_delalloc(ip, XFS_DATA_FORK, offset_fsb,
623-
end_fsb - offset_fsb, 0, &got, &idx, eof);
623+
end_fsb - offset_fsb, prealloc_blocks, &got, &idx, eof);
624624
switch (error) {
625625
case 0:
626626
break;
627627
case -ENOSPC:
628628
case -EDQUOT:
629629
/* retry without any preallocation */
630630
trace_xfs_delalloc_enospc(ip, offset, count);
631-
if (end_fsb != orig_end_fsb) {
632-
end_fsb = orig_end_fsb;
631+
if (prealloc_blocks) {
632+
prealloc_blocks = 0;
633633
goto retry;
634634
}
635635
/*FALLTHRU*/
636636
default:
637637
goto out_unlock;
638638
}
639639

640-
/*
641-
* Tag the inode as speculatively preallocated so we can reclaim this
642-
* space on demand, if necessary.
643-
*/
644-
if (end_fsb != orig_end_fsb)
645-
xfs_inode_set_eofblocks_tag(ip);
646-
647640
trace_xfs_iomap_alloc(ip, offset, count, 0, &got);
648641
done:
649642
if (isnullstartblock(got.br_startblock))

0 commit comments

Comments
 (0)