[PATCH 20/21] fat: ->i_pos race fix

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: OGAWA Hirofumi
Date: Wednesday, October 15, 2008 - 6:58 am

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: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---

 fs/fat/inode.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff -puN fs/fat/inode.c~fat_i_pos-race-fix fs/fat/inode.c
--- linux-2.6/fs/fat/inode.c~fat_i_pos-race-fix	2008-09-29 19:04:03.000000000 +0900
+++ linux-2.6-hirofumi/fs/fat/inode.c	2008-09-29 19:04:03.000000000 +0900
@@ -542,6 +542,20 @@ static int fat_statfs(struct dentry *den
 	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)
 {
 	struct super_block *sb = inode->i_sb;
@@ -551,9 +565,12 @@ static int fat_write_inode(struct inode 
 	loff_t i_pos;
 	int err;
 
+	if (inode->i_ino == MSDOS_ROOT_INO)
+		return 0;
+
 retry:
-	i_pos = MSDOS_I(inode)->i_pos;
-	if (inode->i_ino == MSDOS_ROOT_INO || !i_pos)
+	i_pos = fat_i_pos_read(sbi, inode);
+	if (!i_pos)
 		return 0;
 
 	bh = sb_bread(sb, i_pos >> sbi->dir_per_block_bits);
_
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 01/21] fat: document additional vfat mount options, OGAWA Hirofumi, (Wed Oct 15, 6:57 am)
[PATCH 02/21] fat: move fs/vfat/* and fs/msdos/* to fs/fat, OGAWA Hirofumi, (Wed Oct 15, 6:57 am)
[PATCH 06/21] fat: cleanup fat_parse_long() error handling, OGAWA Hirofumi, (Wed Oct 15, 6:57 am)
[PATCH 05/21] fat: use generic_file_llseek() for directory, OGAWA Hirofumi, (Wed Oct 15, 6:57 am)
[PATCH 04/21] fat: Fix and cleanup timestamp conversion, OGAWA Hirofumi, (Wed Oct 15, 6:57 am)
[PATCH 03/21] fat: split include/msdos_fs.h, OGAWA Hirofumi, (Wed Oct 15, 6:57 am)
[PATCH 09/21] fat: use fat_detach() in fat_clear_inode(), OGAWA Hirofumi, (Wed Oct 15, 6:57 am)
[PATCH 08/21] fat: Fix fat_ent_update_ptr() for FAT12, OGAWA Hirofumi, (Wed Oct 15, 6:57 am)
[PATCH 07/21] fat: improve fat_hash(), OGAWA Hirofumi, (Wed Oct 15, 6:57 am)
[PATCH 13/21] fat: Cleanup msdos_lookup(), OGAWA Hirofumi, (Wed Oct 15, 6:57 am)
[PATCH 12/21] fat: Kill d_invalidate() in vfat_lookup(), OGAWA Hirofumi, (Wed Oct 15, 6:57 am)
[PATCH 11/21] fat: Fix/Cleanup dcache handling for vfat, OGAWA Hirofumi, (Wed Oct 15, 6:57 am)
[PATCH 17/21] fat: Fix _fat_bmap() race, OGAWA Hirofumi, (Wed Oct 15, 6:58 am)
[PATCH 16/21] fat: Fix ATTR_RO for directory, OGAWA Hirofumi, (Wed Oct 15, 6:58 am)
[PATCH 14/21] fat: Cleanup FAT attribute stuff, OGAWA Hirofumi, (Wed Oct 15, 6:58 am)
[PATCH 21/21] fat: i_blocks warning fix, OGAWA Hirofumi, (Wed Oct 15, 6:58 am)
[PATCH 20/21] fat: ->i_pos race fix, OGAWA Hirofumi, (Wed Oct 15, 6:58 am)
[PATCH 19/21] fat: mmu_private race fix, OGAWA Hirofumi, (Wed Oct 15, 6:58 am)
[PATCH 18/21] fat: Add printf attribute to fat_fs_panic(), OGAWA Hirofumi, (Wed Oct 15, 6:58 am)