Skip to content

Commit ac8ee54

Browse files
Christoph Hellwigdjwong
authored andcommitted
xfs: allow writeback on pages without buffer heads
Disable the IOMAP_F_BUFFER_HEAD flag on file systems with a block size equal to the page size, and deal with pages without buffer heads in writeback. Thanks to the previous refactoring this is basically trivial now. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
1 parent 8e1f065 commit ac8ee54

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

fs/xfs/xfs_aops.c

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ xfs_find_daxdev_for_inode(
7979
return mp->m_ddev_targp->bt_daxdev;
8080
}
8181

82+
static void
83+
xfs_finish_page_writeback(
84+
struct inode *inode,
85+
struct bio_vec *bvec,
86+
int error)
87+
{
88+
if (error) {
89+
SetPageError(bvec->bv_page);
90+
mapping_set_error(inode->i_mapping, -EIO);
91+
}
92+
end_page_writeback(bvec->bv_page);
93+
}
94+
8295
/*
8396
* We're now finished for good with this page. Update the page state via the
8497
* associated buffer_heads, paying attention to the start and end offsets that
@@ -91,7 +104,7 @@ xfs_find_daxdev_for_inode(
91104
* and buffers potentially freed after every call to end_buffer_async_write.
92105
*/
93106
static void
94-
xfs_finish_page_writeback(
107+
xfs_finish_buffer_writeback(
95108
struct inode *inode,
96109
struct bio_vec *bvec,
97110
int error)
@@ -166,9 +179,12 @@ xfs_destroy_ioend(
166179
next = bio->bi_private;
167180

168181
/* walk each page on bio, ending page IO on them */
169-
bio_for_each_segment_all(bvec, bio, i)
170-
xfs_finish_page_writeback(inode, bvec, error);
171-
182+
bio_for_each_segment_all(bvec, bio, i) {
183+
if (page_has_buffers(bvec->bv_page))
184+
xfs_finish_buffer_writeback(inode, bvec, error);
185+
else
186+
xfs_finish_page_writeback(inode, bvec, error);
187+
}
172188
bio_put(bio);
173189
}
174190

@@ -792,42 +808,51 @@ xfs_writepage_map(
792808
{
793809
LIST_HEAD(submit_list);
794810
struct xfs_ioend *ioend, *next;
795-
struct buffer_head *bh;
811+
struct buffer_head *bh = NULL;
796812
ssize_t len = i_blocksize(inode);
797813
uint64_t file_offset; /* file offset of page */
798814
unsigned poffset; /* offset into page */
799815
int error = 0;
800816
int count = 0;
801817

818+
if (page_has_buffers(page))
819+
bh = page_buffers(page);
820+
802821
/*
803822
* Walk the blocks on the page, and if we run off the end of the current
804823
* map or find the current map invalid, grab a new one. We only use
805824
* bufferheads here to check per-block state - they no longer control
806825
* the iteration through the page. This allows us to replace the
807826
* bufferhead with some other state tracking mechanism in future.
808827
*/
809-
file_offset = page_offset(page);
810-
bh = page_buffers(page);
811-
for (poffset = 0;
828+
for (poffset = 0, file_offset = page_offset(page);
812829
poffset < PAGE_SIZE;
813-
poffset += len, file_offset += len, bh = bh->b_this_page) {
830+
poffset += len, file_offset += len) {
814831
/* past the range we are writing, so nothing more to write. */
815832
if (file_offset >= end_offset)
816833
break;
817834

818-
if (!buffer_uptodate(bh)) {
835+
if (bh && !buffer_uptodate(bh)) {
819836
if (PageUptodate(page))
820837
ASSERT(buffer_mapped(bh));
838+
bh = bh->b_this_page;
821839
continue;
822840
}
823841

824842
error = xfs_map_blocks(wpc, inode, file_offset);
825843
if (error)
826844
break;
827-
if (wpc->io_type == XFS_IO_HOLE)
845+
846+
if (wpc->io_type == XFS_IO_HOLE) {
847+
if (bh)
848+
bh = bh->b_this_page;
828849
continue;
850+
}
829851

830-
xfs_map_at_offset(inode, bh, &wpc->imap, file_offset);
852+
if (bh) {
853+
xfs_map_at_offset(inode, bh, &wpc->imap, file_offset);
854+
bh = bh->b_this_page;
855+
}
831856
xfs_add_to_ioend(inode, file_offset, page, wpc, wbc,
832857
&submit_list);
833858
count++;
@@ -925,8 +950,6 @@ xfs_do_writepage(
925950

926951
trace_xfs_writepage(inode, page, 0, 0);
927952

928-
ASSERT(page_has_buffers(page));
929-
930953
/*
931954
* Refuse to write the page out if we are called from reclaim context.
932955
*

fs/xfs/xfs_iomap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,8 @@ xfs_file_iomap_begin(
10321032
if (XFS_FORCED_SHUTDOWN(mp))
10331033
return -EIO;
10341034

1035-
iomap->flags |= IOMAP_F_BUFFER_HEAD;
1035+
if (i_blocksize(inode) < PAGE_SIZE)
1036+
iomap->flags |= IOMAP_F_BUFFER_HEAD;
10361037

10371038
if (((flags & (IOMAP_WRITE | IOMAP_DIRECT)) == IOMAP_WRITE) &&
10381039
!IS_DAX(inode) && !xfs_get_extsz_hint(ip)) {

0 commit comments

Comments
 (0)