Skip to contentSkip to conversation

ext4: fix cache flish in ext4_sync_file

PATCH In review Christoph Hellwig 3 participants 3 messages Aug 31, 2009 – Sep 6, 2009 ext4 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext4: fix cache flish in ext4_sync_file

We need to flush the write cache unconditionally in ->fsync, otherwise writes into already allocated blocks can get lost. Writes into fully allocated files are very common when using disk images for virtualization, and without this fix can easily lose data after an fdatasync, which is the typical implementation for a cache flush on the virtual drive.

fs/ext4/fsync.c +2 -2
Index: linux-2.6/fs/ext4/fsync.c
===================================================================
@@ -92,9 +92,9 @@ int ext4_sync_file(struct file *file, st
 			.nr_to_write = 0, /* sys_fsync did this */
 		};
 		ret = sync_inode(inode, &wbc);
-		if (journal && (journal->j_flags & JBD2_BARRIER))
-			blkdev_issue_flush(inode->i_sb->s_bdev, NULL);
 	}
 out:
+	if (journal && (journal->j_flags & JBD2_BARRIER))
+		blkdev_issue_flush(inode->i_sb->s_bdev, NULL);
 	return ret;
 }
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Christoph Hellwig

We need to flush the write cache unconditionally in ->fsync, otherwise writes into already allocated blocks can get lost. Writes into fully allocated files are very common when using disk images for virtualization, and without this fix can easily lose data after an fdatasync, which is the typical implementation for a cache flush on the virtual drive.

Fixing my old commit, I guess ;)

Seems right to me

Quoted 20 lines

Index: linux-2.6/fs/ext4/fsync.c
===================================================================

fs/ext4/fsync.c +2 -3
@@ -92,9 +92,9 @@ int ext4_sync_file(struct file *file, st
 			.nr_to_write = 0, /* sys_fsync did this */
 		};
 		ret = sync_inode(inode, &wbc);
-		if (journal && (journal->j_flags & JBD2_BARRIER))
-			blkdev_issue_flush(inode->i_sb->s_bdev, NULL);
 	}
 out:
+	if (journal && (journal->j_flags & JBD2_BARRIER))
+		blkdev_issue_flush(inode->i_sb->s_bdev, NULL);
 	return ret;
 }
--

To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#2 lore raw
Quoted 9 lines · Eric Sandeen
Quoted 8 lines · Christoph Hellwig

We need to flush the write cache unconditionally in ->fsync, otherwise writes into already allocated blocks can get lost. Writes into fully allocated files are very common when using disk images for virtualization, and without this fix can easily lose data after an fdatasync, which is the typical implementation for a cache flush on the virtual drive.

Quoted 3 lines
Quoted 1 line

Fixing my old commit, I guess ;)

Added to the ext4 patch queue (with the "flish" corrected to "flush")

- Ted