Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 198975
b: refs/heads/master
c: 14ece10
h: refs/heads/master
i:
  198973: 75d1447
  198971: d4ec2d1
  198967: 4f9e83c
  198959: aecdce0
  198943: 3d010c5
  198911: fb2ced2
v: v3
  • Loading branch information
Frank Mayhar authored and Theodore Ts'o committed May 17, 2010
1 parent 6de813a commit 30fdb7b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 60e6679e28518ccd67169c4a539d8cc7490eb8a6
refs/heads/master: 14ece1028b3ed53ffec1b1213ffc6acaf79ad77c
1 change: 1 addition & 0 deletions trunk/fs/ext4/ext4.h
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,7 @@ enum {
EXT4_STATE_DA_ALLOC_CLOSE, /* Alloc DA blks on close */
EXT4_STATE_EXT_MIGRATE, /* Inode is migrating */
EXT4_STATE_DIO_UNWRITTEN, /* need convert on dio done*/
EXT4_STATE_NEWENTRY, /* File just added to dir */
};

#define EXT4_INODE_BIT_FNS(name, field) \
Expand Down
31 changes: 29 additions & 2 deletions trunk/fs/ext4/fsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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().
*
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions trunk/fs/ext4/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,8 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
de->rec_len = ext4_rec_len_to_disk(blocksize, blocksize);
retval = add_dirent_to_buf(handle, dentry, inode, de, bh);
brelse(bh);
if (retval == 0)
ext4_set_inode_state(inode, EXT4_STATE_NEWENTRY);
return retval;
}

Expand Down

0 comments on commit 30fdb7b

Please sign in to comment.