提交 9ca59f4c 编写于 作者: O OGAWA Hirofumi 提交者: Linus Torvalds

fat: ->i_pos race fix

i_pos is 64bits value, hence it's not atomic to update.

Important place is fat_write_inode() only, other places without lock
are just for printk().

This adds lock for "BITS_PER_LONG == 32" kernel.
Signed-off-by: NOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 2bdf67eb
...@@ -542,6 +542,20 @@ static int fat_statfs(struct dentry *dentry, struct kstatfs *buf) ...@@ -542,6 +542,20 @@ static int fat_statfs(struct dentry *dentry, struct kstatfs *buf)
return 0; return 0;
} }
static inline loff_t fat_i_pos_read(struct msdos_sb_info *sbi,
struct inode *inode)
{
loff_t i_pos;
#if BITS_PER_LONG == 32
spin_lock(&sbi->inode_hash_lock);
#endif
i_pos = MSDOS_I(inode)->i_pos;
#if BITS_PER_LONG == 32
spin_unlock(&sbi->inode_hash_lock);
#endif
return i_pos;
}
static int fat_write_inode(struct inode *inode, int wait) static int fat_write_inode(struct inode *inode, int wait)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
...@@ -551,9 +565,12 @@ static int fat_write_inode(struct inode *inode, int wait) ...@@ -551,9 +565,12 @@ static int fat_write_inode(struct inode *inode, int wait)
loff_t i_pos; loff_t i_pos;
int err; int err;
if (inode->i_ino == MSDOS_ROOT_INO)
return 0;
retry: retry:
i_pos = MSDOS_I(inode)->i_pos; i_pos = fat_i_pos_read(sbi, inode);
if (inode->i_ino == MSDOS_ROOT_INO || !i_pos) if (!i_pos)
return 0; return 0;
bh = sb_bread(sb, i_pos >> sbi->dir_per_block_bits); bh = sb_bread(sb, i_pos >> sbi->dir_per_block_bits);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册