Commit 6ac7248e authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Alex Elder

xfs: a few small tweaks for overwrites in xfs_vm_writepage

Don't trylock the buffer.  We are the only one ever locking it for a
regular file address space, and trylock was only copied from the
generic code which did it due to the old buffer based writeout in
jbd.  Also make sure to only write out the buffer if the iomap
actually is valid, because we wouldn't have a proper mapping
otherwise.  In practice we will never get an invalid mapping here as
the page lock guarantees truncate doesn't race with us, but better
be safe than sorry.  Also make sure we allocate a new ioend when
crossing boundaries between mappings, just like we do for delalloc
and unwritten extents.  Again this currently doesn't matter as the
I/O end handler only cares for the boundaries for unwritten extents,
but this makes the code fully correct and the same as for
delalloc/unwritten extents.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Signed-off-by: default avatarAlex Elder <aelder@sgi.com>
parent 221cb251
...@@ -1051,6 +1051,8 @@ xfs_vm_writepage( ...@@ -1051,6 +1051,8 @@ xfs_vm_writepage(
type = IO_NEW; type = IO_NEW;
do { do {
int new_ioend = 0;
if (offset >= end_offset) if (offset >= end_offset)
break; break;
if (!buffer_uptodate(bh)) if (!buffer_uptodate(bh))
...@@ -1071,8 +1073,6 @@ xfs_vm_writepage( ...@@ -1071,8 +1073,6 @@ xfs_vm_writepage(
imap_valid = xfs_imap_valid(inode, &imap, offset); imap_valid = xfs_imap_valid(inode, &imap, offset);
if (buffer_unwritten(bh) || buffer_delay(bh)) { if (buffer_unwritten(bh) || buffer_delay(bh)) {
int new_ioend = 0;
if (buffer_unwritten(bh)) { if (buffer_unwritten(bh)) {
if (type != IO_UNWRITTEN) { if (type != IO_UNWRITTEN) {
type = IO_UNWRITTEN; type = IO_UNWRITTEN;
...@@ -1124,6 +1124,7 @@ xfs_vm_writepage( ...@@ -1124,6 +1124,7 @@ xfs_vm_writepage(
imap_valid = 0; imap_valid = 0;
} }
if (!imap_valid) { if (!imap_valid) {
new_ioend = 1;
size = xfs_probe_cluster(inode, page, bh, head); size = xfs_probe_cluster(inode, page, bh, head);
err = xfs_map_blocks(inode, offset, size, err = xfs_map_blocks(inode, offset, size,
&imap, flags); &imap, flags);
...@@ -1142,14 +1143,12 @@ xfs_vm_writepage( ...@@ -1142,14 +1143,12 @@ xfs_vm_writepage(
* that we are writing into for the first time. * that we are writing into for the first time.
*/ */
type = IO_NEW; type = IO_NEW;
if (trylock_buffer(bh)) { if (imap_valid) {
if (imap_valid)
all_bh = 1; all_bh = 1;
lock_buffer(bh);
xfs_add_to_ioend(inode, bh, offset, type, xfs_add_to_ioend(inode, bh, offset, type,
&ioend, !imap_valid); &ioend, new_ioend);
count++; count++;
} else {
imap_valid = 0;
} }
} else if (PageUptodate(page)) { } else if (PageUptodate(page)) {
ASSERT(buffer_mapped(bh)); ASSERT(buffer_mapped(bh));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment