diff options
| author | Andrew Morton <akpm@digeo.com> | 2003-03-16 07:22:47 -0800 |
|---|---|---|
| committer | Dave Jones <davej@codemonkey.org.uk> | 2003-03-16 07:22:47 -0800 |
| commit | 3bdfab20fc8add21074bfa24c1a6384ae4eda35d (patch) | |
| tree | e5f11cb5aaa21fbdddb6929eca68ea6b627b1b90 /fs/ext2 | |
| parent | 5577ba7d60583d2ee4426c80d90b47197122735c (diff) | |
[PATCH] Ext2/3 noatime and dirsync fixes
Patch from "Theodore Ts'o" <tytso@mit.edu>
I recently noticed a bug in ext2/3; newly created inodes which inherit
the noatime flag from their containing directory do not respect noatime
until the inode is flushed from the inode cache and then re-read later.
This is because the code which checks the ext2 no-atime attribute and
then sets the S_NOATIME in inode->i_flags is present in
ext2_read_inode(), but not in ext2_new_inode().
I fixed this in 2.4, and then found an even worse bug in the 2.5 code;
the DIRSYNC flag is completely ignored *except* in the case where a
directory is newly created using mkdir and its parent directory has the
DIRSYNC flag. S_DIRSYNC doesn't get set in the ext2_new_inode() or the
ext2_ioctl() paths (which is used by chattr).
This patch centralizes the code which translates the ext2 flags in the
raw ext2 inode to the appropriate flag values in inode->i_flags in a
single location. This fixes the bug, makes things cleaner, and also
removes 30 lines of code and 128 bytes of compiled x86 text in the
bargain.
Diffstat (limited to 'fs/ext2')
| -rw-r--r-- | fs/ext2/ext2.h | 1 | ||||
| -rw-r--r-- | fs/ext2/ialloc.c | 5 | ||||
| -rw-r--r-- | fs/ext2/inode.c | 26 | ||||
| -rw-r--r-- | fs/ext2/ioctl.c | 17 |
4 files changed, 21 insertions, 28 deletions
diff --git a/fs/ext2/ext2.h b/fs/ext2/ext2.h index 7850dcbe7bf1..610695289845 100644 --- a/fs/ext2/ext2.h +++ b/fs/ext2/ext2.h @@ -112,6 +112,7 @@ extern int ext2_sync_inode (struct inode *); extern void ext2_discard_prealloc (struct inode *); extern void ext2_truncate (struct inode *); extern int ext2_setattr (struct dentry *, struct iattr *); +extern void ext2_set_inode_flags(struct inode *inode); /* ioctl.c */ extern int ext2_ioctl (struct inode *, struct file *, unsigned int, diff --git a/fs/ext2/ialloc.c b/fs/ext2/ialloc.c index 345e7495176d..87b2d99f4a7c 100644 --- a/fs/ext2/ialloc.c +++ b/fs/ext2/ialloc.c @@ -545,10 +545,7 @@ repeat: ei->i_prealloc_count = 0; ei->i_dir_start_lookup = 0; ei->i_state = EXT2_STATE_NEW; - if (ei->i_flags & EXT2_SYNC_FL) - inode->i_flags |= S_SYNC; - if (ei->i_flags & EXT2_DIRSYNC_FL) - inode->i_flags |= S_DIRSYNC; + ext2_set_inode_flags(inode); inode->i_generation = EXT2_SB(sb)->s_next_generation++; insert_inode_hash(inode); diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index e47f84e305cd..c2fbefdd3613 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -1011,6 +1011,23 @@ Egdp: return ERR_PTR(-EIO); } +void ext2_set_inode_flags(struct inode *inode) +{ + unsigned int flags = EXT2_I(inode)->i_flags; + + inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC); + if (flags & EXT2_SYNC_FL) + inode->i_flags |= S_SYNC; + if (flags & EXT2_APPEND_FL) + inode->i_flags |= S_APPEND; + if (flags & EXT2_IMMUTABLE_FL) + inode->i_flags |= S_IMMUTABLE; + if (flags & EXT2_NOATIME_FL) + inode->i_flags |= S_NOATIME; + if (flags & EXT2_DIRSYNC_FL) + inode->i_flags |= S_DIRSYNC; +} + void ext2_read_inode (struct inode * inode) { struct ext2_inode_info *ei = EXT2_I(inode); @@ -1108,14 +1125,7 @@ void ext2_read_inode (struct inode * inode) le32_to_cpu(raw_inode->i_block[0])); } brelse (bh); - if (ei->i_flags & EXT2_SYNC_FL) - inode->i_flags |= S_SYNC; - if (ei->i_flags & EXT2_APPEND_FL) - inode->i_flags |= S_APPEND; - if (ei->i_flags & EXT2_IMMUTABLE_FL) - inode->i_flags |= S_IMMUTABLE; - if (ei->i_flags & EXT2_NOATIME_FL) - inode->i_flags |= S_NOATIME; + ext2_set_inode_flags(inode); return; bad_inode: diff --git a/fs/ext2/ioctl.c b/fs/ext2/ioctl.c index afff8566f3b6..101055bbf519 100644 --- a/fs/ext2/ioctl.c +++ b/fs/ext2/ioctl.c @@ -58,22 +58,7 @@ int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE; ei->i_flags = flags; - if (flags & EXT2_SYNC_FL) - inode->i_flags |= S_SYNC; - else - inode->i_flags &= ~S_SYNC; - if (flags & EXT2_APPEND_FL) - inode->i_flags |= S_APPEND; - else - inode->i_flags &= ~S_APPEND; - if (flags & EXT2_IMMUTABLE_FL) - inode->i_flags |= S_IMMUTABLE; - else - inode->i_flags &= ~S_IMMUTABLE; - if (flags & EXT2_NOATIME_FL) - inode->i_flags |= S_NOATIME; - else - inode->i_flags &= ~S_NOATIME; + ext2_set_inode_flags(inode); inode->i_ctime = CURRENT_TIME; mark_inode_dirty(inode); return 0; |
