Skip to content

Commit 8fceb4e

Browse files
Namjae Jeontorvalds
authored andcommitted
fat (exportfs): rebuild inode if ilookup() fails
If the cache lookups fail,use the i_pos value to find the directory entry of the inode and rebuild the inode.Since this involves accessing the FAT media, do this only if the nostale_ro nfs mount option is specified. Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com> Signed-off-by: Ravishankar N <ravi.n1@samsung.com> Signed-off-by: Amit Sahrawat <a.sahrawat@samsung.com> Acked-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ea3983a commit 8fceb4e

3 files changed

Lines changed: 52 additions & 5 deletions

File tree

‎fs/fat/fat.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct msdos_sb_info {
7575
unsigned long root_cluster; /* first cluster of the root directory */
7676
unsigned long fsinfo_sector; /* sector number of FAT32 fsinfo */
7777
struct mutex fat_lock;
78+
struct mutex nfs_build_inode_lock;
7879
struct mutex s_lock;
7980
unsigned int prev_free; /* previously allocated cluster number */
8081
unsigned int free_clusters; /* -1 if undefined */

‎fs/fat/inode.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,25 @@ static int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de)
443443
return 0;
444444
}
445445

446+
static inline void fat_lock_build_inode(struct msdos_sb_info *sbi)
447+
{
448+
if (sbi->options.nfs == FAT_NFS_NOSTALE_RO)
449+
mutex_lock(&sbi->nfs_build_inode_lock);
450+
}
451+
452+
static inline void fat_unlock_build_inode(struct msdos_sb_info *sbi)
453+
{
454+
if (sbi->options.nfs == FAT_NFS_NOSTALE_RO)
455+
mutex_unlock(&sbi->nfs_build_inode_lock);
456+
}
457+
446458
struct inode *fat_build_inode(struct super_block *sb,
447459
struct msdos_dir_entry *de, loff_t i_pos)
448460
{
449461
struct inode *inode;
450462
int err;
451463

464+
fat_lock_build_inode(MSDOS_SB(sb));
452465
inode = fat_iget(sb, i_pos);
453466
if (inode)
454467
goto out;
@@ -468,6 +481,7 @@ struct inode *fat_build_inode(struct super_block *sb,
468481
fat_attach(inode, i_pos);
469482
insert_inode_hash(inode);
470483
out:
484+
fat_unlock_build_inode(MSDOS_SB(sb));
471485
return inode;
472486
}
473487

@@ -1247,6 +1261,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
12471261
sb->s_magic = MSDOS_SUPER_MAGIC;
12481262
sb->s_op = &fat_sops;
12491263
sb->s_export_op = &fat_export_ops;
1264+
mutex_init(&sbi->nfs_build_inode_lock);
12501265
ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
12511266
DEFAULT_RATELIMIT_BURST);
12521267

‎fs/fat/nfs.c‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,50 @@ static struct inode *fat_dget(struct super_block *sb, int i_logstart)
5050
return inode;
5151
}
5252

53+
static struct inode *fat_ilookup(struct super_block *sb, u64 ino, loff_t i_pos)
54+
{
55+
if (MSDOS_SB(sb)->options.nfs == FAT_NFS_NOSTALE_RO)
56+
return fat_iget(sb, i_pos);
57+
58+
else {
59+
if ((ino < MSDOS_ROOT_INO) || (ino == MSDOS_FSINFO_INO))
60+
return NULL;
61+
return ilookup(sb, ino);
62+
}
63+
}
64+
5365
static struct inode *__fat_nfs_get_inode(struct super_block *sb,
5466
u64 ino, u32 generation, loff_t i_pos)
5567
{
56-
struct inode *inode;
57-
58-
if ((ino < MSDOS_ROOT_INO) || (ino == MSDOS_FSINFO_INO))
59-
return NULL;
68+
struct inode *inode = fat_ilookup(sb, ino, i_pos);
6069

61-
inode = ilookup(sb, ino);
6270
if (inode && generation && (inode->i_generation != generation)) {
6371
iput(inode);
6472
inode = NULL;
6573
}
74+
if (inode == NULL && MSDOS_SB(sb)->options.nfs == FAT_NFS_NOSTALE_RO) {
75+
struct buffer_head *bh = NULL;
76+
struct msdos_dir_entry *de ;
77+
sector_t blocknr;
78+
int offset;
79+
fat_get_blknr_offset(MSDOS_SB(sb), i_pos, &blocknr, &offset);
80+
bh = sb_bread(sb, blocknr);
81+
if (!bh) {
82+
fat_msg(sb, KERN_ERR,
83+
"unable to read block(%llu) for building NFS inode",
84+
(llu)blocknr);
85+
return inode;
86+
}
87+
de = (struct msdos_dir_entry *)bh->b_data;
88+
/* If a file is deleted on server and client is not updated
89+
* yet, we must not build the inode upon a lookup call.
90+
*/
91+
if (IS_FREE(de[offset].name))
92+
inode = NULL;
93+
else
94+
inode = fat_build_inode(sb, &de[offset], i_pos);
95+
brelse(bh);
96+
}
6697

6798
return inode;
6899
}

0 commit comments

Comments
 (0)