Commit df3c7244 authored by David Chinner's avatar David Chinner Committed by Tim Shimmin

[XFS] Write at EOF may not update filesize correctly.

The recent fix for preventing NULL files from being left around does not
update the file size corectly in all cases. The missing case is a write
extending the file that does not need to allocate a block.

In that case we used a read mapping of the extent which forced the use of
the read I/O completion handler instead of the write I/O completion
handle. Hence the file size was not updated on I/O completion.

SGI-PV: 965068
SGI-Modid: xfs-linux-melb:xfs-kern:28657a
Signed-off-by: default avatarDavid Chinner <dgc@sgi.com>
Signed-off-by: default avatarNathan Scott <nscott@aconex.com>
Signed-off-by: default avatarTim Shimmin <tes@sgi.com>
parent c420bc9f
...@@ -701,7 +701,7 @@ xfs_is_delayed_page( ...@@ -701,7 +701,7 @@ xfs_is_delayed_page(
else if (buffer_delay(bh)) else if (buffer_delay(bh))
acceptable = (type == IOMAP_DELAY); acceptable = (type == IOMAP_DELAY);
else if (buffer_dirty(bh) && buffer_mapped(bh)) else if (buffer_dirty(bh) && buffer_mapped(bh))
acceptable = (type == 0); acceptable = (type == IOMAP_NEW);
else else
break; break;
} while ((bh = bh->b_this_page) != head); } while ((bh = bh->b_this_page) != head);
...@@ -810,7 +810,7 @@ xfs_convert_page( ...@@ -810,7 +810,7 @@ xfs_convert_page(
page_dirty--; page_dirty--;
count++; count++;
} else { } else {
type = 0; type = IOMAP_NEW;
if (buffer_mapped(bh) && all_bh && startio) { if (buffer_mapped(bh) && all_bh && startio) {
lock_buffer(bh); lock_buffer(bh);
xfs_add_to_ioend(inode, bh, offset, xfs_add_to_ioend(inode, bh, offset,
...@@ -968,8 +968,8 @@ xfs_page_state_convert( ...@@ -968,8 +968,8 @@ xfs_page_state_convert(
bh = head = page_buffers(page); bh = head = page_buffers(page);
offset = page_offset(page); offset = page_offset(page);
flags = -1; flags = BMAPI_READ;
type = IOMAP_READ; type = IOMAP_NEW;
/* TODO: cleanup count and page_dirty */ /* TODO: cleanup count and page_dirty */
...@@ -999,14 +999,14 @@ xfs_page_state_convert( ...@@ -999,14 +999,14 @@ xfs_page_state_convert(
* *
* Third case, an unmapped buffer was found, and we are * Third case, an unmapped buffer was found, and we are
* in a path where we need to write the whole page out. * in a path where we need to write the whole page out.
*/ */
if (buffer_unwritten(bh) || buffer_delay(bh) || if (buffer_unwritten(bh) || buffer_delay(bh) ||
((buffer_uptodate(bh) || PageUptodate(page)) && ((buffer_uptodate(bh) || PageUptodate(page)) &&
!buffer_mapped(bh) && (unmapped || startio))) { !buffer_mapped(bh) && (unmapped || startio))) {
/* /*
* Make sure we don't use a read-only iomap * Make sure we don't use a read-only iomap
*/ */
if (flags == BMAPI_READ) if (flags == BMAPI_READ)
iomap_valid = 0; iomap_valid = 0;
if (buffer_unwritten(bh)) { if (buffer_unwritten(bh)) {
...@@ -1055,7 +1055,7 @@ xfs_page_state_convert( ...@@ -1055,7 +1055,7 @@ xfs_page_state_convert(
* That means it must already have extents allocated * That means it must already have extents allocated
* underneath it. Map the extent by reading it. * underneath it. Map the extent by reading it.
*/ */
if (!iomap_valid || type != IOMAP_READ) { if (!iomap_valid || flags != BMAPI_READ) {
flags = BMAPI_READ; flags = BMAPI_READ;
size = xfs_probe_cluster(inode, page, bh, size = xfs_probe_cluster(inode, page, bh,
head, 1); head, 1);
...@@ -1066,7 +1066,15 @@ xfs_page_state_convert( ...@@ -1066,7 +1066,15 @@ xfs_page_state_convert(
iomap_valid = xfs_iomap_valid(&iomap, offset); iomap_valid = xfs_iomap_valid(&iomap, offset);
} }
type = IOMAP_READ; /*
* We set the type to IOMAP_NEW in case we are doing a
* small write at EOF that is extending the file but
* without needing an allocation. We need to update the
* file size on I/O completion in this case so it is
* the same case as having just allocated a new extent
* that we are writing into for the first time.
*/
type = IOMAP_NEW;
if (!test_and_set_bit(BH_Lock, &bh->b_state)) { if (!test_and_set_bit(BH_Lock, &bh->b_state)) {
ASSERT(buffer_mapped(bh)); ASSERT(buffer_mapped(bh));
if (iomap_valid) if (iomap_valid)
......
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