diff options
author | mckusick <mckusick@FreeBSD.org> | 2001-12-13 05:07:48 +0000 |
---|---|---|
committer | mckusick <mckusick@FreeBSD.org> | 2001-12-13 05:07:48 +0000 |
commit | d375501d045647dacd0383cd7eadb9aef5430dd5 (patch) | |
tree | a98ceef299b1c81f7b5aaeec89abdf242330b72b /sys/ufs/ffs/ffs_inode.c | |
parent | 2eaaa91f6f2e878a476fbf3758ffba37cdf38d4b (diff) | |
download | FreeBSD-src-d375501d045647dacd0383cd7eadb9aef5430dd5.zip FreeBSD-src-d375501d045647dacd0383cd7eadb9aef5430dd5.tar.gz |
When a file is partially truncated, we first check to see if the
new file end will land in the middle of a file hole. Since the last
block of a file must always be allocated, the hole is filled by
allocating a block at that location. If the hole being filled is
a direct block, then the truncation may eventually reduce the
full sized block down to a fragment. When running with soft
updates, it is necessary to FSYNC the file after allocating the
block and before creating the fragment to avoid triggering a
soft updates inconsistency when the block unexpectedly shrinks.
Found by: Matthew Dillon <dillon@apollo.backplane.com>
MFC after: 1 week
Diffstat (limited to 'sys/ufs/ffs/ffs_inode.c')
-rw-r--r-- | sys/ufs/ffs/ffs_inode.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/sys/ufs/ffs/ffs_inode.c b/sys/ufs/ffs/ffs_inode.c index d0cd063..9014a60 100644 --- a/sys/ufs/ffs/ffs_inode.c +++ b/sys/ufs/ffs/ffs_inode.c @@ -250,6 +250,18 @@ ffs_truncate(vp, length, flags, cred, td) if (error) { return (error); } + /* + * When we are doing soft updates and the UFS_BALLOC + * above fills in a direct block hole with a full sized + * block that will be truncated down to a fragment below, + * we must flush out the block dependency with an FSYNC + * so that we do not get a soft updates inconsistency + * when we create the fragment below. + */ + if (DOINGSOFTDEP(ovp) && lbn < NDADDR && + fragroundup(fs, blkoff(fs, length)) < fs->fs_bsize && + (error = VOP_FSYNC(ovp, cred, MNT_WAIT, td)) != 0) + return (error); oip->i_size = length; size = blksize(fs, oip, lbn); if (ovp->v_type != VDIR) |