|
@@ -34,6 +34,29 @@
|
|
|
|
|
|
#include <trace/events/ext4.h>
|
|
|
|
|
|
+/*
|
|
|
+ * If we're not journaling and this is a just-created file, we have to
|
|
|
+ * sync our parent directory (if it was freshly created) since
|
|
|
+ * otherwise it will only be written by writeback, leaving a huge
|
|
|
+ * window during which a crash may lose the file. This may apply for
|
|
|
+ * the parent directory's parent as well, and so on recursively, if
|
|
|
+ * they are also freshly created.
|
|
|
+ */
|
|
|
+static void ext4_sync_parent(struct inode *inode)
|
|
|
+{
|
|
|
+ struct dentry *dentry = NULL;
|
|
|
+
|
|
|
+ while (inode && ext4_test_inode_state(inode, EXT4_STATE_NEWENTRY)) {
|
|
|
+ ext4_clear_inode_state(inode, EXT4_STATE_NEWENTRY);
|
|
|
+ dentry = list_entry(inode->i_dentry.next,
|
|
|
+ struct dentry, d_alias);
|
|
|
+ if (!dentry || !dentry->d_parent || !dentry->d_parent->d_inode)
|
|
|
+ break;
|
|
|
+ inode = dentry->d_parent->d_inode;
|
|
|
+ sync_mapping_buffers(inode->i_mapping);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
* akpm: A new design for ext4_sync_file().
|
|
|
*
|
|
@@ -67,8 +90,12 @@ int ext4_sync_file(struct file *file, struct dentry *dentry, int datasync)
|
|
|
if (ret < 0)
|
|
|
return ret;
|
|
|
|
|
|
- if (!journal)
|
|
|
- return simple_fsync(file, dentry, datasync);
|
|
|
+ if (!journal) {
|
|
|
+ ret = simple_fsync(file, dentry, datasync);
|
|
|
+ if (!ret && !list_empty(&inode->i_dentry))
|
|
|
+ ext4_sync_parent(inode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
/*
|
|
|
* data=writeback,ordered:
|