summaryrefslogtreecommitdiffstats
path: root/sys/fs/ext2fs
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2013-07-09 01:31:04 +0000
committerpfg <pfg@FreeBSD.org>2013-07-09 01:31:04 +0000
commit6ca7bf7cd4b6756cce3b70a3ca5864d8ed4d31b2 (patch)
tree3a5728bc62c9e1cb8ba366d7a9ecd5f18f8d3d1f /sys/fs/ext2fs
parent4050bd5a8c332830247150962d76ec30ac4b1176 (diff)
downloadFreeBSD-src-6ca7bf7cd4b6756cce3b70a3ca5864d8ed4d31b2.zip
FreeBSD-src-6ca7bf7cd4b6756cce3b70a3ca5864d8ed4d31b2.tar.gz
Enhancement when writing an entire block of a file.
Merge from UFS r231313: This change first attempts the uiomove() to the newly allocated (and dirty) buffer and only zeros it if the uiomove() fails. The effect is to eliminate the gratuitous zeroing of the buffer in the usual case where the uiomove() successfully fills it. MFC after: 3 days
Diffstat (limited to 'sys/fs/ext2fs')
-rw-r--r--sys/fs/ext2fs/ext2_vnops.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/sys/fs/ext2fs/ext2_vnops.c b/sys/fs/ext2fs/ext2_vnops.c
index dc71696..bf1253e 100644
--- a/sys/fs/ext2fs/ext2_vnops.c
+++ b/sys/fs/ext2fs/ext2_vnops.c
@@ -1812,15 +1812,6 @@ ext2_write(struct vop_write_args *ap)
if (error != 0)
break;
- /*
- * If the buffer is not valid and we did not clear garbage
- * out above, we have to do so here even though the write
- * covers the entire buffer in order to avoid a mmap()/write
- * race where another process may see the garbage prior to
- * the uiomove() for a write replacing it.
- */
- if ((bp->b_flags & B_CACHE) == 0 && fs->e2fs_bsize <= xfersize)
- vfs_bio_clrbuf(bp);
if ((ioflag & (IO_SYNC|IO_INVAL)) == (IO_SYNC|IO_INVAL))
bp->b_flags |= B_NOCACHE;
if (uio->uio_offset + xfersize > ip->i_size)
@@ -1831,6 +1822,26 @@ ext2_write(struct vop_write_args *ap)
error =
uiomove((char *)bp->b_data + blkoffset, (int)xfersize, uio);
+ /*
+ * If the buffer is not already filled and we encounter an
+ * error while trying to fill it, we have to clear out any
+ * garbage data from the pages instantiated for the buffer.
+ * If we do not, a failed uiomove() during a write can leave
+ * the prior contents of the pages exposed to a userland mmap.
+ *
+ * Note that we need only clear buffers with a transfer size
+ * equal to the block size because buffers with a shorter
+ * transfer size were cleared above by the call to ext2_balloc()
+ * with the BA_CLRBUF flag set.
+ *
+ * If the source region for uiomove identically mmaps the
+ * buffer, uiomove() performed the NOP copy, and the buffer
+ * content remains valid because the page fault handler
+ * validated the pages.
+ */
+ if (error != 0 && (bp->b_flags & B_CACHE) == 0 &&
+ fs->e2fs_bsize == xfersize)
+ vfs_bio_clrbuf(bp);
if (ioflag & (IO_VMIO|IO_DIRECT)) {
bp->b_flags |= B_RELBUF;
}
OpenPOWER on IntegriCloud