1 From: Chris Mason <mason@suse.com>
2 Subject: ext2 should force the FS readonly for metadata write errors
5 During fsync we should check for write errors to the block device in order to make
6 sure all metadata writes have been properly written to the disk. Without this check
7 writes that happen through the normal async mechanisms might hit errors without
8 reporting them back to the application.
10 Acked-by: Jeff Mahoney <jeffm@suse.com>
13 fs/ext2/fsync.c | 17 +++++++++++++++++
14 1 file changed, 17 insertions(+)
21 #include <linux/buffer_head.h> /* for sync_mapping_buffers() */
22 +#include <linux/pagemap.h>
27 int ext2_sync_file(struct file *file, struct dentry *dentry, int datasync)
29 struct inode *inode = dentry->d_inode;
30 + struct super_block *sb = inode->i_sb;
34 ret = sync_mapping_buffers(inode->i_mapping);
36 + /* it might make more sense to ext2_error on -EIO from
37 + * sync_mapping_buffers as well, but those errors are isolated to just
38 + * this file. We can safely return -EIO to fsync and let the app know
39 + * they have a problem.
41 + * AS_EIO indicates a failure to write a metadata page, but we have no
42 + * way of knowing which one. It's best to force readonly and let fsck
43 + * figure it all out.
45 + if (test_and_clear_bit(AS_EIO, &sb->s_bdev->bd_inode->i_mapping->flags)) {
46 + ext2_error(sb, "ext2_sync_file", "metadata io error");
50 if (!(inode->i_state & I_DIRTY))
52 if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))