Skip to content

Commit

Permalink
ext3: Flush disk caches on fsync when needed
Browse files Browse the repository at this point in the history
In case we fsync() a file and inode is not dirty, we don't force a transaction
to disk and hence don't flush disk caches. Thus file data could be just in disk
caches and not on persistent storage. Fix the problem by flushing disk caches
if we didn't force a transaction commit.

Signed-off-by: Jan Kara <jack@suse.cz>
  • Loading branch information
Jan Kara committed Sep 16, 2009
1 parent 4f003fd commit 56fcad2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion fs/ext3/fsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include <linux/time.h>
#include <linux/blkdev.h>
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/writeback.h>
Expand Down Expand Up @@ -73,7 +74,7 @@ int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync)
}

if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
goto out;
goto flush;

/*
* The VFS has written the file data. If the inode is unaltered
Expand All @@ -85,7 +86,16 @@ int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync)
.nr_to_write = 0, /* sys_fsync did this */
};
ret = sync_inode(inode, &wbc);
goto out;
}
flush:
/*
* In case we didn't commit a transaction, we have to flush
* disk caches manually so that data really is on persistent
* storage
*/
if (test_opt(inode->i_sb, BARRIER))
blkdev_issue_flush(inode->i_sb->s_bdev, NULL);
out:
return ret;
}

0 comments on commit 56fcad2

Please sign in to comment.