fat (exportfs): rebuild inode if ilookup() fails
PATCH v4 2/4 fat (exportfs): rebuild inode if ilookup() fails
From: Namjae Jeon <[email protected]>
Assign i_pos to kstat->ino and re-introduce fat_encode_fh() and include i_pos value in the file handle.Use the i_pos value to find the directory entry of the inode and subsequently rebuild the inode if the cache lookups fail.
Since this involves accessing the FAT media,it is better to do this only if the 'nfs' mount option is enabled with nostale_ro. Also introduce a helper fat_get_blknr_offset() for use in __fat_write_inode() and fat_nfs_get_inode()
--- fs/fat/fat.h | 10 ++++++ fs/fat/file.c | 4 +++ fs/fat/inode.c | 13 ++++---- fs/fat/nfs.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 115 insertions(+), 13 deletions(-)
fs/fat/fat.h +10 -0
@@ -214,6 +214,13 @@ static inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus) + sbi->data_start; } +static inline void fat_get_blknr_offset (struct msdos_sb_info *sbi, +loff_t i_pos,sector_t *blknr,int *offset) +{ + *blknr = i_pos >> sbi->dir_per_block_bits; + *offset = i_pos & (sbi->dir_per_block -1 ); +} +static inline void fat16_towchar (wchar_t *dst,const __u8 *src,size_t len) {#ifdef __BIG_ENDIAN
@@ -339,6 +346,7 @@ extern int fat_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);/* fat/inode.c */ +extern loff_t fat_i_pos_read (struct msdos_sb_info *sbi,struct inode *inode);extern void fat_attach (struct inode *inode,loff_t i_pos);extern void fat_detach (struct inode *inode);extern struct inode *fat_iget (struct super_block *sb,loff_t i_pos);
@@ -382,6 +390,8 @@ void fat_cache_destroy(void);/* fat/nfs.c */ struct fid ; +extern int fat_encode_fh (struct inode *inode,__u32 *fh,int *lenp, +struct inode *parent);extern struct dentry *fat_fh_to_dentry (struct super_block *sb,struct fid *fid,int fh_len,int fh_type); extern struct dentry *fat_fh_to_parent(struct super_block *sb, struct fid *fid,
fs/fat/file.c +4 -0
@@ -306,6 +306,10 @@ int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)struct inode *inode = dentry->d_inode;generic_fillattr (inode, stat); stat->blksize =MSDOS_SB (inode->i_sb)->cluster_size; +if (MSDOS_SB (inode->i_sb)->options.nfs ==FAT_NFS_NOSTALE_RO ) { +/* Use i_pos for ino. This is used as fileid of nfs. */ + stat->ino =fat_i_pos_read (MSDOS_SB (inode->i_sb), inode); + }return 0 ; }EXPORT_SYMBOL_GPL (fat_getattr);
fs/fat/inode.c +7 -6
@@ -596,7 +596,7 @@ static int fat_statfs(struct dentry *dentry, struct kstatfs *buf)return 0 ; } -static inline loff_t fat_i_pos_read (struct msdos_sb_info *sbi, +loff_t fat_i_pos_read (struct msdos_sb_info *sbi,struct inode *inode) {loff_t i_pos;
@@ -616,8 +616,8 @@ static int __fat_write_inode(struct inode *inode, int wait)struct msdos_sb_info *sbi =MSDOS_SB (sb);struct buffer_head *bh;struct msdos_dir_entry *raw_entry; -loff_t i_pos; -int err; +loff_t i_pos, blocknr; +int offset, err;if (inode->i_ino ==MSDOS_ROOT_INO )return 0 ;
@@ -627,7 +627,8 @@ retry:if (!i_pos)return 0 ; - bh =sb_bread (sb, i_pos >> sbi->dir_per_block_bits); +fat_get_blknr_offset (sbi, i_pos, &blocknr, &offset); + bh =sb_bread (sb, blocknr);if (!bh) {fat_msg (sb,KERN_ERR ,"unable to read inode block " "for updating (i_pos %lld)" , i_pos);
@@ -640,8 +641,7 @@ retry: goto retry; } - raw_entry = &((struct msdos_dir_entry *) (bh->b_data)) - [i_pos & (sbi->dir_per_block -1 )]; + raw_entry = &((struct msdos_dir_entry *) (bh->b_data))[offset];if (S_ISDIR (inode->i_mode)) raw_entry->size =0 ;else
@@ -703,6 +703,7 @@ static const struct super_operations fat_sops = { };static const struct export_operations fat_export_ops = { + .encode_fh = fat_encode_fh, .fh_to_dentry = fat_fh_to_dentry, .fh_to_parent = fat_fh_to_parent, .get_parent = fat_get_parent,
fs/fat/nfs.c +94 -7
137 lines not on this page · raw message
Signature · 1 line
1.7.9.5
OGAWA Hirofumi
maintainerfs/fat/fat.h static inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus) · line 223
Quoted 13 lines · Namjae Jeon
fs/fat/fat.h +7
-0@@ -214,6 +214,13 @@ static inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus) + sbi->data_start; } +static inline void fat_get_blknr_offset (struct msdos_sb_info *sbi, +loff_t i_pos,sector_t *blknr,int *offset) +{ + *blknr = i_pos >> sbi->dir_per_block_bits; + *offset = i_pos & (sbi->dir_per_block -1 ); +} +
Let's separate fat_get_blknr_offset() cleanup and others.
Quoted 1 line
fs/fat/fat.h +1
-0+extern loff_t fat_i_pos_read (struct msdos_sb_info *sbi,struct inode *inode);
[...]
fs/fat/fat.h
Quoted 5 lines
fs/fat/fat.h +1
-1-static inline loff_t fat_i_pos_read (struct msdos_sb_info *sbi, +loff_t fat_i_pos_read (struct msdos_sb_info *sbi,struct inode *inode) {loff_t i_pos;
Let's move fat_i_pos_read() to fat.h to make consists with fat_get_blknr_offset().
Quoted 10 lines
static const struct
export_operationsfat_export_ops= {fs/fat/fat.h +1
-0+ .encode_fh = fat_encode_fh, .fh_to_dentry = fat_fh_to_dentry, .fh_to_parent = fat_fh_to_parent, .get_parent = fat_get_parent,fs/fat/nfs.c +0
-0
fs/fat/nfs.c line 23
Quoted 10 lines
fs/fat/nfs.c +7
-0@@ -14,6 +14,14 @@#include <linux/exportfs.h> #include "fat.h" +struct fat_fid { +u32 ino; +u32 gen; +u64 i_pos; +u32 parent_ino; +u32 parent_gen; +} __packed;
This is sizeof(fat_fid)/sizoef(u32) == 6. IIRC, nfsv2 is not supporting FH > 6, true?
Quoted 21 lines
fs/fat/nfs.c +21
-0+int +fat_encode_fh (struct inode *inode,__u32 *fh,int *lenp,struct inode *parent) +{ +int len = *lenp; +struct msdos_sb_info *sbi =MSDOS_SB (inode->i_sb); +struct fat_fid *fid = (struct fat_fid *) fh; +loff_t i_pos; +int type =FILEID_INO32_GEN ; + +if (parent && (len <5 )) { + *lenp =5 ; +return 255 ; + }else if (len <3 ) { + *lenp =3 ; +return 255 ; + } + + i_pos =fat_i_pos_read (sbi, inode); + *lenp =3 ; + fid->ino = inode->i_ino; + fid->gen = inode->i_generation;
fs/fat/nfs.c static struct inode *fat_nfs_get_inode(struct super_block *sb, · line 121
Quoted 10 lines
fs/fat/nfs.c +10
-0+ fid->i_pos = i_pos; +if (parent) { + fid->parent_ino = parent->i_ino; + fid->parent_gen = parent->i_generation; + type =FILEID_INO32_GEN_PARENT ; + *lenp =5 ; + } + +return type; +}
I was also thinking to use same FH though, because of limitation of FH size. It looks like to be better to separate with "stale_rw".
So, how about to separate at export_operations level?
I.e. (move export_operations to fat/nfs.c)
For stale_rw,
const struct export_operations fat_export_ops = {
.fh_to_dentry = fat_fh_to_dentry,
.fh_to_parent = fat_fh_to_parent,
.get_parent = fat_get_parent,
}For nostale_ro,
const struct export_operations fat_export_ops = {
.fh_to_dentry = fat_encode_fh,
.fh_to_dentry = fat_fh_to_dentry,
.fh_to_parent = fat_fh_to_parent,
.get_parent = fat_get_parent,
}And we have to think about FH format. I guess we don't need to inode->i_ino for nostale_ro.
Maximum i_pos is 40bits, and i_gen is 32bit. So, inode and parent inode fits to FH of 5 len, we have to pack those though.
I.e.
struct fat_fid {
u32 i_gen;
u32 i_pos_low;
u16 i_pos_hi;
u16 parent_i_pos_hi;
u32 parent_i_pos_low;
u32 parent_i_gen;
} __packed;And define FILEID_FAT_WITHOUT_PARENT and FILEID_FAT_WITH_PARENT.
User of i_ino is only ilookup, right? So, we can add fat_ilookup() for it.
struct inode *fat_ilookup(struct super_block *sb, u64 ino)
{
if (stale_rw)
return ilookup(sb, ino);
return fat_iget(sb, i_pos);
}And I noticed we need lock for fat_build_inode() for nostale_ro. Because fat_nfs_get_inode() doesn't hold i_mutex of parent dir, right? So, add lock to fat_build_inode()
static inline void fat_build_inode_lock(struct msdos_sb_info *sbi)
{
if (sbi->options.nfs == FAT_NFS_NOSTALE_RO)
mutex_lock(&sbi->nfs_build_inode_lock);
}static inline void fat_build_inode_unlock(struct msdos_sb_info *sbi)
{
if (sbi->options.nfs == FAT_NFS_NOSTALE_RO)
mutex_unlock(&sbi->nfs_build_inode_lock);
}Signature · 1 line
OGAWA Hirofumi <[email protected]>
Hi. OGAWA.
2012/10/13 OGAWA Hirofumi <[email protected]>:
Quoted 8 lines
Quoted 6 lines · Namjae Jeon
fs/fat/fat.h +0
-0@@ -214,6 +214,13 @@ static inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus) + sbi->data_start; }
Quoted 9 lines
fs/fat/fat.h static inline sector_t fat_clus_to_blknr(struct msdos_sb_info *sbi, int clus) · line 223
Quoted 7 lines
fs/fat/fat.h +7
-0+static inline void fat_get_blknr_offset (struct msdos_sb_info *sbi, +loff_t i_pos,sector_t *blknr,int *offset) +{ + *blknr = i_pos >> sbi->dir_per_block_bits; + *offset = i_pos & (sbi->dir_per_block -1 ); +} +Let's separate
fat_get_blknr_offset()cleanup and others.
Okay.
Quoted 5 lines
Quoted 2 lines
fs/fat/fat.h +1
-0+extern loff_t fat_i_pos_read (struct msdos_sb_info *sbi,struct inode *inode);[...]
Quoted 8 lines
fs/fat/fat.h
Quoted 5 lines
fs/fat/fat.h +1
-1-static inline loff_t fat_i_pos_read (struct msdos_sb_info *sbi, +loff_t fat_i_pos_read (struct msdos_sb_info *sbi,struct inode *inode) {loff_t i_pos;Let's move
fat_i_pos_read()tofat.hto make consists withfat_get_blknr_offset().
Okay.
Quoted 14 lines
Quoted 14 lines
static const struct
export_operationsfat_export_ops= {fs/fat/fat.h +1
-0+ .encode_fh = fat_encode_fh, .fh_to_dentry = fat_fh_to_dentry, .fh_to_parent = fat_fh_to_parent, .get_parent = fat_get_parent,fs/fat/nfs.c +0
-0@@ -14,6 +14,14 @@#include <linux/exportfs.h> #include "fat.h"
Quoted 10 lines
fs/fat/nfs.c line 23
Quoted 7 lines
fs/fat/nfs.c +7
-0+struct fat_fid { +u32 ino; +u32 gen; +u64 i_pos; +u32 parent_ino; +u32 parent_gen; +} __packed;This is sizeof(fat_fid)/sizoef(u32) == 6. IIRC, nfsv2 is not supporting FH > 6, true?
I will check and share the result.
Quoted 36 lines
Quoted 22 lines
fs/fat/nfs.c +21
-0+int +fat_encode_fh (struct inode *inode,__u32 *fh,int *lenp,struct inode *parent) +{ +int len = *lenp; +struct msdos_sb_info *sbi =MSDOS_SB (inode->i_sb); +struct fat_fid *fid = (struct fat_fid *) fh; +loff_t i_pos; +int type =FILEID_INO32_GEN ; + +if (parent && (len <5 )) { + *lenp =5 ; +return 255 ; + }else if (len <3 ) { + *lenp =3 ; +return 255 ; + } + + i_pos =fat_i_pos_read (sbi, inode); + *lenp =3 ; + fid->ino = inode->i_ino; + fid->gen = inode->i_generation;fs/fat/nfs.c static struct inode *fat_nfs_get_inode(struct super_block *sb, · line 121
Quoted 10 lines
fs/fat/nfs.c +10
-0+ fid->i_pos = i_pos; +if (parent) { + fid->parent_ino = parent->i_ino; + fid->parent_gen = parent->i_generation; + type =FILEID_INO32_GEN_PARENT ; + *lenp =5 ; + } + +return type; +}I was also thinking to use same FH though, because of limitation of FH size. It looks like to be better to separate with "
stale_rw".
Quoted 1 line
So, how about to separate at
export_operationslevel?
Good idea!
Quoted 37 lines
I.e. (move
export_operationstofat/nfs.c)For
stale_rw,const struct
export_operationsfat_export_ops= {.fh_to_dentry = fat_fh_to_dentry, .fh_to_parent = fat_fh_to_parent, .get_parent = fat_get_parent,}
For
nostale_ro,const struct
export_operationsfat_export_ops= {.fh_to_dentry = fat_encode_fh, .fh_to_dentry = fat_fh_to_dentry, .fh_to_parent = fat_fh_to_parent, .get_parent = fat_get_parent,}
And we have to think about FH format. I guess we don't need to
inode->i_inofornostale_ro.Maximum
i_posis 40bits, andi_genis 32bit. So, inode and parent inode fits to FH of 5 len, we have to pack those though.I.e.
struct fat_fid { u32 i_gen; u32 i_pos_low; u16 i_pos_hi; u16 parent_i_pos_hi; u32 parent_i_pos_low; u32 parent_i_gen; } __packed;
Quoted 3 lines
And define
FILEID_FAT_WITHOUT_PARENTandFILEID_FAT_WITH_PARENT.User of
i_inois only ilookup, right? So, we can addfat_ilookup()for it.
Okay.
Quoted 19 lines
struct inode *fat_ilookup(struct
super_block*sb, u64 ino){ if (stale_rw) return ilookup(sb, ino); return fat_iget(sb, i_pos); }And I noticed we need lock for
fat_build_inode()fornostale_ro. Becausefat_nfs_get_inode()doesn't holdi_mutexof parent dir, right? So, add lock tofat_build_inode()static inline void
fat_build_inode_lock(struct msdos_sb_info *sbi){ if (sbi->options.nfs == FAT_NFS_NOSTALE_RO) mutex_lock(&sbi->nfs_build_inode_lock); }
Quoted 5 lines
static inline void
fat_build_inode_unlock(struct msdos_sb_info *sbi){ if (sbi->options.nfs == FAT_NFS_NOSTALE_RO) mutex_unlock(&sbi->nfs_build_inode_lock); }
Thanks for specific review and suggestion. :)
I will change the patches as your suggestion.
Hum.. And currently these patch-set was pushed to -mm tree and linux-next. I am confusing I should request to revert these patch-set or make new patches base on these patch-set....
Thanks.
Quoted 2 lines
--
OGAWA Hirofumi <[email protected]>