aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_iomap.c
diff options
context:
space:
mode:
authorLachlan McIlroy <lachlan@sgi.com>2007-05-07 23:49:46 -0400
committerTim Shimmin <tes@sgi.com>2007-05-07 23:49:46 -0400
commitba87ea699ebd9dd577bf055ebc4a98200e337542 (patch)
tree713b7d32937372fd7c5b8647f14d0e7262fc7075 /fs/xfs/xfs_iomap.c
parent2a32963130aec5e157b58ff7dfa3dfa1afdf7ca1 (diff)
[XFS] Fix to prevent the notorious 'NULL files' problem after a crash.
The problem that has been addressed is that of synchronising updates of the file size with writes that extend a file. Without the fix the update of a file's size, as a result of a write beyond eof, is independent of when the cached data is flushed to disk. Often the file size update would be written to the filesystem log before the data is flushed to disk. When a system crashes between these two events and the filesystem log is replayed on mount the file's size will be set but since the contents never made it to disk the file is full of holes. If some of the cached data was flushed to disk then it may just be a section of the file at the end that has holes. There are existing fixes to help alleviate this problem, particularly in the case where a file has been truncated, that force cached data to be flushed to disk when the file is closed. If the system crashes while the file(s) are still open then this flushing will never occur. The fix that we have implemented is to introduce a second file size, called the in-memory file size, that represents the current file size as viewed by the user. The existing file size, called the on-disk file size, is the one that get's written to the filesystem log and we only update it when it is safe to do so. When we write to a file beyond eof we only update the in- memory file size in the write operation. Later when the I/O operation, that flushes the cached data to disk completes, an I/O completion routine will update the on-disk file size. The on-disk file size will be updated to the maximum offset of the I/O or to the value of the in-memory file size if the I/O includes eof. SGI-PV: 958522 SGI-Modid: xfs-linux-melb:xfs-kern:28322a Signed-off-by: Lachlan McIlroy <lachlan@sgi.com> Signed-off-by: David Chinner <dgc@sgi.com> Signed-off-by: Tim Shimmin <tes@sgi.com>
Diffstat (limited to 'fs/xfs/xfs_iomap.c')
-rw-r--r--fs/xfs/xfs_iomap.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index cde70e895443..3f2b9f2a7b94 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -458,7 +458,7 @@ xfs_iomap_write_direct(
458 extsz = ip->i_d.di_extsize; 458 extsz = ip->i_d.di_extsize;
459 } 459 }
460 460
461 isize = ip->i_d.di_size; 461 isize = ip->i_size;
462 if (io->io_new_size > isize) 462 if (io->io_new_size > isize)
463 isize = io->io_new_size; 463 isize = io->io_new_size;
464 464
@@ -524,7 +524,7 @@ xfs_iomap_write_direct(
524 xfs_trans_ihold(tp, ip); 524 xfs_trans_ihold(tp, ip);
525 525
526 bmapi_flag = XFS_BMAPI_WRITE; 526 bmapi_flag = XFS_BMAPI_WRITE;
527 if ((flags & BMAPI_DIRECT) && (offset < ip->i_d.di_size || extsz)) 527 if ((flags & BMAPI_DIRECT) && (offset < ip->i_size || extsz))
528 bmapi_flag |= XFS_BMAPI_PREALLOC; 528 bmapi_flag |= XFS_BMAPI_PREALLOC;
529 529
530 /* 530 /*
@@ -676,7 +676,7 @@ xfs_iomap_write_delay(
676 offset_fsb = XFS_B_TO_FSBT(mp, offset); 676 offset_fsb = XFS_B_TO_FSBT(mp, offset);
677 677
678retry: 678retry:
679 isize = ip->i_d.di_size; 679 isize = ip->i_size;
680 if (io->io_new_size > isize) 680 if (io->io_new_size > isize)
681 isize = io->io_new_size; 681 isize = io->io_new_size;
682 682
@@ -817,7 +817,7 @@ xfs_iomap_write_allocate(
817 * we dropped the ilock in the interim. 817 * we dropped the ilock in the interim.
818 */ 818 */
819 819
820 end_fsb = XFS_B_TO_FSB(mp, ip->i_d.di_size); 820 end_fsb = XFS_B_TO_FSB(mp, ip->i_size);
821 xfs_bmap_last_offset(NULL, ip, &last_block, 821 xfs_bmap_last_offset(NULL, ip, &last_block,
822 XFS_DATA_FORK); 822 XFS_DATA_FORK);
823 last_block = XFS_FILEOFF_MAX(last_block, end_fsb); 823 last_block = XFS_FILEOFF_MAX(last_block, end_fsb);