fat (exportfs): rebuild directory-inode if fat_dget() fails
Subsystems (2)
PATCH v5 7/8 fat (exportfs): rebuild directory-inode if fat_dget() fails
From: Namjae Jeon <[email protected]>
This patch enables rebuilding of directory inodes which are not present in the cache.This is done by traversing the disk clusters to find the directory entry of the parent directory and using its i_pos to build the inode.
Do this only if the "nostale_ro" nfs mount option is specified.
--- fs/fat/nfs.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-)
fs/fat/nfs.c +118 -1
@@ -211,6 +211,120 @@ static struct dentry *fat_fh_to_parent_nostale(struct super_block *sb, }/* +* Read the directory entries of 'search_clus' and find the entry +* which contains 'match_ipos' for the starting cluster.If the entry +* is found, rebuild its inode. +*/ +static struct inode *fat_traverse_cluster (struct super_block *sb, +int search_clus,int match_ipos) +{ +struct msdos_sb_info *sbi =MSDOS_SB (sb); +struct buffer_head *bh; +sector_t blknr; +int parent_ipos, search_ipos; +int i; +struct msdos_dir_entry *de; +struct inode *inode =NULL ; +int iterations = sbi->cluster_size >> sb->s_blocksize_bits; + blknr =fat_clus_to_blknr (sbi, search_clus); + +do { + bh =sb_bread (sb, blknr); +if (!bh) { +fat_msg (sb,KERN_ERR , +"NFS:unable to read block(%llu) while traversing cluster(%d)" , + (llu )blknr, search_clus); + inode =ERR_PTR (-EIO ); + goto out; + } + de = (struct msdos_dir_entry *)bh->b_data; +for (i =0 ; i < sbi->dir_per_block; i++) { +if (de[i].name[0 ] ==FAT_ENT_FREE ) { +/*Reached end of directory*/ +brelse (bh); + inode =ERR_PTR (-ENODATA ); + goto out; + } +if (de[i].name[0 ] ==DELETED_FLAG ) +continue ; +if (de[i].attr ==ATTR_EXT ) +continue ; +if (!(de[i].attr &ATTR_DIR )) +continue ; +else { + search_ipos =fat_get_start (sbi, &de[i]); +if (search_ipos == match_ipos) { +/*Success.Now build the inode*/ + parent_ipos = (loff_t )i + + (blknr << sbi->dir_per_block_bits); + inode =fat_build_inode (sb, &de[i], + parent_ipos); +brelse (bh); + goto out; + } + } + } +brelse (bh); + blknr +=1 ; + }while (--iterations >0 ); +out: +return inode; +} + +/* +* Rebuild the parent for a directory that is not connected +* to the filesystem root +*/ +static +struct inode *fat_rebuild_parent (struct super_block *sb,int parent_logstart) +{ +int search_clus, clus_to_match; +struct msdos_dir_entry *de; +struct inode *parent; +struct fat_entry fatent; +struct msdos_sb_info *sbi =MSDOS_SB (sb); +sector_t blknr =fat_clus_to_blknr (sbi, parent_logstart); +struct buffer_head *parent_bh =sb_bread (sb, blknr); + +if (!parent_bh) { +fat_msg (sb,KERN_ERR , +"NFS:unable to read cluster of parent directory" ); +return NULL ; + } + de = (struct msdos_dir_entry *) parent_bh->b_data; + clus_to_match =fat_get_start (sbi, &de[0 ]); + search_clus =fat_get_start (sbi, &de[1 ]); +if (!search_clus) { +if (sbi->fat_bits ==32 ) + search_clus = sbi->root_cluster; +else +/* sbi->root_cluster is valid only for FAT32. +* Compute search_cluster such that when +* fat_traverse_cluster() is called for FAT 12/16, +* fat_clus_to_blknr() in it gives us sbi->dir_start +*/ + search_clus = ((int )(sbi->dir_start - sbi->data_start) + >>ilog2 (sbi->sec_per_clus)) + +FAT_START_ENT ; + } +brelse (parent_bh); +do { + parent =fat_traverse_cluster (sb, + search_clus, clus_to_match); +if (IS_ERR (parent) || parent) +break ; +fatent_init (&fatent); + search_clus =fat_ent_read (sb, &fatent, search_clus); +fatent_brelse (&fatent); +if (search_clus <0 || search_clus ==FAT_ENT_FREE ) +break ; + }while (search_clus !=FAT_ENT_EOF ); + +return parent; + +} + +/* * Find the parent for a directory that is not currently connected to * the filesystem root. *
@@ -222,10 +336,13 @@ static struct dentry *fat_get_parent(struct dentry *child_dir)struct buffer_head *bh =NULL ;struct msdos_dir_entry *de;struct inode *parent_inode =NULL ; +struct msdos_sb_info *sbi =MSDOS_SB (sb);if (!fat_get_dotdot_entry (child_dir->d_inode, &bh, &de)) { -int parent_logstart =fat_get_start (MSDOS_SB (sb), de); +int parent_logstart =fat_get_start (sbi, de); parent_inode =fat_dget (sb, parent_logstart); +if (!parent_inode && sbi->options.nfs ==FAT_NFS_NOSTALE_RO ) + parent_inode =fat_rebuild_parent (sb, parent_logstart); }brelse (bh);
Signature · 1 line
1.7.9.5
OGAWA Hirofumi
maintainerQuoted 7 lines · Namjae Jeon
From: Namjae Jeon <[email protected]>
This patch enables rebuilding of directory inodes which are not present in the cache.This is done by traversing the disk clusters to find the directory entry of the parent directory and using its
i_posto build the inode.
Do this only if the "nostale_ro" nfs mount option is specified.
This became much better than before. However, we have to consolidate the code with fat_search_long() finally.
E.g. this version is having the issue already fixed. If there is corruption in fat cluster-chain, it lead to infinite loop. fat_get_cluster() checks infinite loop by limit.
Quoted 146 lines
Signed-off-by Namjae Jeon <[email protected]>Signed-off-by Ravishankar N <[email protected]>Signed-off-by Amit Sahrawat <[email protected]>--- fs/fat/nfs.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-)fs/fat/nfs.c +118
-1@@ -211,6 +211,120 @@ static struct dentry *fat_fh_to_parent_nostale(struct super_block *sb, }/* +* Read the directory entries of 'search_clus' and find the entry +* which contains 'match_ipos' for the starting cluster.If the entry +* is found, rebuild its inode. +*/ +static struct inode *fat_traverse_cluster (struct super_block *sb, +int search_clus,int match_ipos) +{ +struct msdos_sb_info *sbi =MSDOS_SB (sb); +struct buffer_head *bh; +sector_t blknr; +int parent_ipos, search_ipos; +int i; +struct msdos_dir_entry *de; +struct inode *inode =NULL ; +int iterations = sbi->cluster_size >> sb->s_blocksize_bits; + blknr =fat_clus_to_blknr (sbi, search_clus); + +do { + bh =sb_bread (sb, blknr); +if (!bh) { +fat_msg (sb,KERN_ERR , +"NFS:unable to read block(%llu) while traversing cluster(%d)" , + (llu )blknr, search_clus); + inode =ERR_PTR (-EIO ); + goto out; + } + de = (struct msdos_dir_entry *)bh->b_data; +for (i =0 ; i < sbi->dir_per_block; i++) { +if (de[i].name[0 ] ==FAT_ENT_FREE ) { +/*Reached end of directory*/ +brelse (bh); + inode =ERR_PTR (-ENODATA ); + goto out; + } +if (de[i].name[0 ] ==DELETED_FLAG ) +continue ; +if (de[i].attr ==ATTR_EXT ) +continue ; +if (!(de[i].attr &ATTR_DIR )) +continue ; +else { + search_ipos =fat_get_start (sbi, &de[i]); +if (search_ipos == match_ipos) { +/*Success.Now build the inode*/ + parent_ipos = (loff_t )i + + (blknr << sbi->dir_per_block_bits); + inode =fat_build_inode (sb, &de[i], + parent_ipos); +brelse (bh); + goto out; + } + } + } +brelse (bh); + blknr +=1 ; + }while (--iterations >0 ); +out: +return inode; +} + +/* +* Rebuild the parent for a directory that is not connected +* to the filesystem root +*/ +static +struct inode *fat_rebuild_parent (struct super_block *sb,int parent_logstart) +{ +int search_clus, clus_to_match; +struct msdos_dir_entry *de; +struct inode *parent; +struct fat_entry fatent; +struct msdos_sb_info *sbi =MSDOS_SB (sb); +sector_t blknr =fat_clus_to_blknr (sbi, parent_logstart); +struct buffer_head *parent_bh =sb_bread (sb, blknr); + +if (!parent_bh) { +fat_msg (sb,KERN_ERR , +"NFS:unable to read cluster of parent directory" ); +return NULL ; + } + de = (struct msdos_dir_entry *) parent_bh->b_data; + clus_to_match =fat_get_start (sbi, &de[0 ]); + search_clus =fat_get_start (sbi, &de[1 ]); +if (!search_clus) { +if (sbi->fat_bits ==32 ) + search_clus = sbi->root_cluster; +else +/* sbi->root_cluster is valid only for FAT32. +* Compute search_cluster such that when +* fat_traverse_cluster() is called for FAT 12/16, +* fat_clus_to_blknr() in it gives us sbi->dir_start +*/ + search_clus = ((int )(sbi->dir_start - sbi->data_start) + >>ilog2 (sbi->sec_per_clus)) + +FAT_START_ENT ; + } +brelse (parent_bh); +do { + parent =fat_traverse_cluster (sb, + search_clus, clus_to_match); +if (IS_ERR (parent) || parent) +break ; +fatent_init (&fatent); + search_clus =fat_ent_read (sb, &fatent, search_clus); +fatent_brelse (&fatent); +if (search_clus <0 || search_clus ==FAT_ENT_FREE ) +break ; + }while (search_clus !=FAT_ENT_EOF ); + +return parent; + +} + +/* * Find the parent for a directory that is not currently connected to * the filesystem root. * @@ -222,10 +336,13 @@ static struct dentry *fat_get_parent(struct dentry *child_dir)struct buffer_head *bh =NULL ;struct msdos_dir_entry *de;struct inode *parent_inode =NULL ; +struct msdos_sb_info *sbi =MSDOS_SB (sb);if (!fat_get_dotdot_entry (child_dir->d_inode, &bh, &de)) { -int parent_logstart =fat_get_start (MSDOS_SB (sb), de); +int parent_logstart =fat_get_start (sbi, de); parent_inode =fat_dget (sb, parent_logstart); +if (!parent_inode && sbi->options.nfs ==FAT_NFS_NOSTALE_RO ) + parent_inode =fat_rebuild_parent (sb, parent_logstart); }brelse (bh);
Signature · 1 line
OGAWA Hirofumi <[email protected]>
2012/12/3, OGAWA Hirofumi <[email protected]>:
Quoted 10 lines
Quoted 7 lines · Namjae Jeon
From: Namjae Jeon <[email protected]>
This patch enables rebuilding of directory inodes which are not present in the cache.This is done by traversing the disk clusters to find the directory entry of the parent directory and using its
i_posto build the inode.
Do this only if the "nostale_ro" nfs mount option is specified.
Quoted 6 lines
This became much better than before. However, we have to consolidate the code with
fat_search_long()finally.E.g. this version is having the issue already fixed. If there is corruption in fat cluster-chain, it lead to infinite loop.
fat_get_cluster()checks infinite loop by limit.
since, the focus this time was for NFS functionality for FAT (removing ESTALE error). The changes were made in that context.
Later, we can make the changes as part of code reorganizing which can be controlled via. Separate patches which do not have any impact on default functionality and verification can be carried out in that scope.
Quoted 3 lines
OGAWA Hirofumi <[email protected]>
OGAWA Hirofumi
maintainerQuoted 17 lines · Namjae Jeon
2012/12/3, OGAWA Hirofumi <[email protected]>:
Quoted 10 lines
Quoted 7 lines · Namjae Jeon
From: Namjae Jeon <[email protected]>
This patch enables rebuilding of directory inodes which are not present in the cache.This is done by traversing the disk clusters to find the directory entry of the parent directory and using its
i_posto build the inode.
Do this only if the "nostale_ro" nfs mount option is specified.Quoted 6 lines
This became much better than before. However, we have to consolidate the code with
fat_search_long()finally.E.g. this version is having the issue already fixed. If there is corruption in fat cluster-chain, it lead to infinite loop.
fat_get_cluster()checks infinite loop by limit.
Quoted 7 lines
since, the focus this time was for NFS functionality for FAT (removing ESTALE error). The changes were made in that context.
Later, we can make the changes as part of code reorganizing which can be controlled via. Separate patches which do not have any impact on default functionality and verification can be carried out in that scope.
Right. But non-production code shouldn't go into linus tree. I meant, we can test this patch series, but not yet production quality.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
2012/12/4, OGAWA Hirofumi <[email protected]>:
Quoted 23 lines
Quoted 21 lines · Namjae Jeon
2012/12/3, OGAWA Hirofumi <[email protected]>:
Quoted 11 lines
Quoted 8 lines · Namjae Jeon
From: Namjae Jeon <[email protected]>
This patch enables rebuilding of directory inodes which are not present in the cache.This is done by traversing the disk clusters to find the directory entry of the parent directory and using its
i_posto build the
inode.
Do this only if the "nostale_ro" nfs mount option is specified.Quoted 6 lines
This became much better than before. However, we have to consolidate the code with
fat_search_long()finally.E.g. this version is having the issue already fixed. If there is corruption in fat cluster-chain, it lead to infinite loop.
fat_get_cluster()checks infinite loop by limit.since, the focus this time was for NFS functionality for FAT (removing ESTALE error). The changes were made in that context.
Quoted 7 lines
Quoted 4 lines
Later, we can make the changes as part of code reorganizing which can be controlled via. Separate patches which do not have any impact on default functionality and verification can be carried out in that scope.
Right. But non-production code shouldn't go into linus tree. I meant, we can test this patch series, but not yet production quality.
Is there any other thing which seems potential issue than offsetof()? if yes, which problem didn't lead to production quality do you think ?
+#define FAT_FID_SIZE_WITHOUT_PARENT (offsetof(struct fat_fid, \
+ parent_i_pos_hi)/4)
Since this expression does not result proper integer value, so will it be correct to directly put the value like
+#define FAT_FID_SIZE_WITHOUT_PARENT 3
Thanks!
Quoted 3 lines
--
OGAWA Hirofumi <[email protected]>
OGAWA Hirofumi
maintainerQuoted 21 lines · Namjae Jeon
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
This became much better than before. However, we have to consolidate the code with
fat_search_long()finally.E.g. this version is having the issue already fixed. If there is corruption in fat cluster-chain, it lead to infinite loop.
fat_get_cluster()checks infinite loop by limit.since, the focus this time was for NFS functionality for FAT (removing ESTALE error). The changes were made in that context.
Quoted 7 lines
Quoted 4 lines
Later, we can make the changes as part of code reorganizing which can be controlled via. Separate patches which do not have any impact on default functionality and verification can be carried out in that scope.
Right. But non-production code shouldn't go into linus tree. I meant, we can test this patch series, but not yet production quality.
Is there any other thing which seems potential issue than
offsetof()? if yes, which problem didn't lead to production quality do you think ?(quoted diff) +2
-0+#define FAT_FID_SIZE_WITHOUT_PARENT (offsetof(struct fat_fid, \ + parent_i_pos_hi)/4)
Quoted 3 lines
Since this expression does not result proper integer value, so will it be correct to directly put the value like
+#defineFAT_FID_SIZE_WITHOUT_PARENT3
The issue is what I explained in the above "E.g.".
Directory traversal logic should be consolidate with fat_search_log(). Otherwise, like this nfs implement, we will introduce already-fixed-problem again. And we will be bothered to fix same issue in future.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
2012/12/5, OGAWA Hirofumi <[email protected]>:
Quoted 30 lines
Quoted 22 lines · Namjae Jeon
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
This became much better than before. However, we have to consolidate the
code withfat_search_long()finally.E.g. this version is having the issue already fixed. If there is corruption in fat cluster-chain, it lead to infinite loop.
fat_get_cluster()checks infinite loop by limit.since, the focus this time was for NFS functionality for FAT (removing ESTALE error). The changes were made in that context.
Quoted 7 lines
Quoted 4 lines
Later, we can make the changes as part of code reorganizing which can be controlled via. Separate patches which do not have any impact on default functionality and verification can be carried out in that scope.
Right. But non-production code shouldn't go into linus tree. I meant, we can test this patch series, but not yet production quality.
Is there any other thing which seems potential issue than
offsetof()? if yes, which problem didn't lead to production quality do you think ?(quoted diff) +2
-0+#define FAT_FID_SIZE_WITHOUT_PARENT (offsetof(struct fat_fid, \ + parent_i_pos_hi)/4)Quoted 3 lines
Since this expression does not result proper integer value, so will it be correct to directly put the value like
+#defineFAT_FID_SIZE_WITHOUT_PARENT3The issue is what I explained in the above "E.g.".
Quoted 3 lines
Directory traversal logic should be consolidate with
fat_search_log(). Otherwise, like this nfs implement, we will introduce already-fixed-problem again. And we will be bothered to fix same issue in future.
Okay, We will check how we can consolidate the 2 paths to avoid any issue.
Thanks OGAWA!
Quoted 3 lines
--
OGAWA Hirofumi <[email protected]>
2012/12/5, Namjae Jeon <[email protected]>:
Quoted 32 lines
2012/12/5, OGAWA Hirofumi <[email protected]>:
Quoted 31 lines
Quoted 23 lines · Namjae Jeon
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
This became much better than before. However, we have to consolidate the
code withfat_search_long()finally.E.g. this version is having the issue already fixed. If there is corruption in fat cluster-chain, it lead to infinite loop.
fat_get_cluster()checks infinite loop by limit.since, the focus this time was for NFS functionality for FAT (removing ESTALE error). The changes were made in that context.
Quoted 8 lines
Quoted 4 lines
Later, we can make the changes as part of code reorganizing which can be controlled via. Separate patches which do not have any impact on default functionality and verification can be carried out in that scope.
Right. But non-production code shouldn't go into linus tree. I meant, we
can test this patch series, but not yet production quality.Is there any other thing which seems potential issue than
offsetof()? if yes, which problem didn't lead to production quality do you think ?(quoted diff) +2
-0+#define FAT_FID_SIZE_WITHOUT_PARENT (offsetof(struct fat_fid, \ + parent_i_pos_hi)/4)Quoted 3 lines
Since this expression does not result proper integer value, so will it be correct to directly put the value like
+#defineFAT_FID_SIZE_WITHOUT_PARENT3The issue is what I explained in the above "E.g.".
Quoted 5 lines
Quoted 4 lines
Directory traversal logic should be consolidate with
fat_search_log(). Otherwise, like this nfs implement, we will introduce already-fixed-problem
again. And we will be bothered to fix same issue in future.Okay, We will check how we can consolidate the 2 paths to avoid any issue.
Hi OGAWA.
On checking fat_search_long() logic, it is observed that it performs name based lookup of the entries in a given directory.
In fat_get_parent(), we do not have such information to use the existing API to reconstruct the parent inode.
Could you give me some hint or guide to consolidate smoothly fat_search_long and current traverse_logic ?
Thanks.
Quoted 6 lines
Thanks OGAWA!
Quoted 3 lines
--
OGAWA Hirofumi <[email protected]>
OGAWA Hirofumi
maintainerQuoted 9 lines · Namjae Jeon
Quoted 1 line
Okay, We will check how we can consolidate the 2 paths to avoid any issue.
Hi OGAWA.
On checking
fat_search_long()logic, it is observed that it performs name based lookup of the entries in a given directory.
Infat_get_parent(), we do not have such information to use the existing API to reconstruct the parent inode.
Could you give me some hint or guide to consolidate smoothlyfat_search_longand currenttraverse_logic?
Hm, start with copy of fat_search_long() and refactoring it. With it, we will be able to avoid the fixed bugs.
After that, we might be able to merge those somehow. Well, I'm not pretty sure without doing it actually though.
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
2012/12/20, OGAWA Hirofumi <[email protected]>:
Quoted 13 lines
Quoted 10 lines · Namjae Jeon
Quoted 2 lines
Okay, We will check how we can consolidate the 2 paths to avoid any issue.
Hi OGAWA.
On checking
fat_search_long()logic, it is observed that it performs name based lookup of the entries in a given directory.
Infat_get_parent(), we do not have such information to use the existing API to reconstruct the parent inode.
Could you give me some hint or guide to consolidate smoothlyfat_search_longand currenttraverse_logic?
Quoted 5 lines
Hm, start with copy of
fat_search_long()and refactoring it. With it, we will be able to avoid the fixed bugs.After that, we might be able to merge those somehow. Well, I'm not pretty sure without doing it actually though.
Hi OGAWA.
When we checked to merge it with fat_search_long, we really did not find any possibility of code reusing for fat_traverse_cluster. It will not be proper ? In case of fat_search_long()-> it is performing a name based lookup in a particular directory. While for reconnection with parent from NFS ? we do not have the name of the parent directory. We are relying on ‘i_pos’ ? on disk position of directory entry.
So, on first request for lookup for “..” (i.e if we call fat_search_long(child_dir->d_inode, MSDOS_DOTDOT,2,slot_info) it will return the directory entry for “..” itself. From this entry we can read the “log start” which is the starting cluster of the parent directory, but instead we need the “directory entry” where this is stored.
So, from this level we need to go further one level up and read the parent ->parent-> cluster. After reading that cluster, we need to do a lookup of the “required ipos” in this directory block. i.e., if the path is A/B/C ? and we call the get_parent() from ‘C’. We need to read the directory block contents of ‘A’ and from those ‘directory entries' compare the log_start with the log_start value of B, which was obtained by doing a lookup “..” in C.
So, Instead of it, we suggest we fix the “infinite-loop” condition in fat_traverse_logic and retain the code.
of course, we will test it with corrupted FATfs.
Please share your thoughts on this.
Thanks.
Quoted 5 lines
Thanks.
--
OGAWA Hirofumi <[email protected]>
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
2012/12/21, Namjae Jeon <[email protected]>:
Quoted 19 lines
2012/12/20, OGAWA Hirofumi <[email protected]>:
Quoted 18 lines
Quoted 10 lines · Namjae Jeon
Quoted 2 lines
Okay, We will check how we can consolidate the 2 paths to avoid any issue.
Hi OGAWA.
On checking
fat_search_long()logic, it is observed that it performs name based lookup of the entries in a given directory.
Infat_get_parent(), we do not have such information to use the existing API to reconstruct the parent inode.
Could you give me some hint or guide to consolidate smoothlyfat_search_longand currenttraverse_logic?Hm, start with copy of
fat_search_long()and refactoring it. With it, we will be able to avoid the fixed bugs.After that, we might be able to merge those somehow. Well, I'm not pretty sure without doing it actually though.
Hi OGAWA.
When we checked to merge it with fat_search_long, we really did not find any possibility of code reusing for fat_traverse_cluster. It will not be proper. In case of fat_search_long()-> it is performing a name based lookup in a particular directory.
While for reconnection with parent from NFS, we do not have the name of the parent directory. We are relying on ‘i_pos’ on disk position of directory entry.
So, on first request for lookup for “..” (i.e if we call fat_search_long(child_dir->d_inode, MSDOS_DOTDOT,2,slot_info) it will return the directory entry for “..” itself. From this entry we can read the “log start” which is the starting cluster of the parent directory, but instead we need the “directory entry” where this is stored.
So, from this level we need to go further one level up and read the parent ->parent-> cluster. After reading that cluster, we need to do a lookup of the “required ipos” in this directory block. i.e., if the path is A/B/C and we call the get_parent() from ‘C’. We need to read the directory block contents of ‘A’ and from those ‘directory entries' compare the log_start with the log_start value of B, which was obtained by doing a lookup “..” in C.
So, Instead of it, we suggest we fix the “infinite-loop” condition in fat_traverse_logic and retain the code.
of course, we will test it with corrupted FATfs.
Please share your thoughts on this.
Thanks.
Quoted 6 lines
Quoted 5 lines
Thanks.
--
OGAWA Hirofumi <[email protected]>
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
OGAWA Hirofumi
maintainerQuoted 23 lines · Namjae Jeon
Quoted 5 lines
Quoted 5 lines
Hm, start with copy of
fat_search_long()and refactoring it. With it, we will be able to avoid the fixed bugs.After that, we might be able to merge those somehow. Well, I'm not pretty sure without doing it actually though.
Hi OGAWA.
When we checked to merge it with
fat_search_long, we really did not find any possibility of code reusing forfat_traverse_cluster. It will not be proper. In case of fat_search_long()-> it is performing a name based lookup in a particular directory.
While for reconnection with parent from NFS, we do not have the name of the parent directory. We are relying on ‘i_pos’ on disk position of directory entry.
So, on first request for lookup for “..” (i.e if we callfat_search_long(child_dir->d_inode, MSDOS_DOTDOT,2,slot_info)it will return the directory entry for “..” itself. From this entry we can read the “log start” which is the starting cluster of the parent directory, but instead we need the “directory entry” where this is stored.
So, from this level we need to go further one level up and read the parent ->parent-> cluster. After reading that cluster, we need to do a lookup of the “required ipos” in this directory block.
Quoted 8 lines
i.e., if the path is A/B/C and we call the
get_parent()from ‘C’. We need to read the directory block contents of ‘A’ and from those ‘directory entries' compare thelog_startwith thelog_startvalue of B, which was obtained by doing a lookup “..” in C.
So, Instead of it, we suggest we fix the “infinite-loop” condition infat_traverse_logicand retain the code.
of course, we will test it with corrupted FATfs.
Please share your thoughts on this.
Yes, we can't use fat_search_long() as is, of course. However, we can share the basic algorithm and code.
The both are doing,
1) traverse the blocks chained by ->i_start.
2) get the record (dirent) from blocks.
3) check the detail of record
The difference is only (3), right? I know, the code has many differences though. The actual logic are almost same.
And see, e.g., fat_get_cluster() is checking several unexpected state. We have to care about corrupting data. It is not only "infinite-loop" case. And why I'm saying it is better to share code.
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
2012/12/21, OGAWA Hirofumi <[email protected]>:
Quoted 44 lines
Quoted 24 lines · Namjae Jeon
Quoted 6 lines
Quoted 6 lines
Hm, start with copy of
fat_search_long()and refactoring it. With it, we
will be able to avoid the fixed bugs.After that, we might be able to merge those somehow. Well, I'm not pretty sure without doing it actually though.
Hi OGAWA.
When we checked to merge it with
fat_search_long, we really did not find any possibility of code reusing forfat_traverse_cluster. It will not be proper. In case of fat_search_long()-> it is performing a name based lookup in a particular directory.
While for reconnection with parent from NFS, we do not have the name of the parent directory. We are relying on ‘i_pos’ on disk position of directory entry.
So, on first request for lookup for “..” (i.e if we callfat_search_long(child_dir->d_inode, MSDOS_DOTDOT,2,slot_info)it will return the directory entry for “..” itself. From this entry we can read the “log start” which is the starting cluster of the parent directory, but instead we need the “directory entry” where this is stored.
So, from this level we need to go further one level up and read the parent ->parent-> cluster. After reading that cluster, we need to do a lookup of the “required ipos” in this directory block.Quoted 8 lines
i.e., if the path is A/B/C and we call the
get_parent()from ‘C’. We need to read the directory block contents of ‘A’ and from those ‘directory entries' compare thelog_startwith thelog_startvalue of B, which was obtained by doing a lookup “..” in C.
So, Instead of it, we suggest we fix the “infinite-loop” condition infat_traverse_logicand retain the code.
of course, we will test it with corrupted FATfs.
Please share your thoughts on this.Yes, we can't use
fat_search_long()as is, of course. However, we can share the basic algorithm and code.The both are doing,
1) traverse the blocks chained by ->i_start.
2) get the record (dirent) from blocks.
3) check the detail of record
Quoted 6 lines
The difference is only (3), right? I know, the code has many differences though. The actual logic are almost same.
And see, e.g.,
fat_get_cluster()is checking several unexpected state. We have to care about corrupting data. It is not only "infinite-loop" case. And why I'm saying it is better to share code.
Regarding unexpected conditions,
When we compare the unexpected conditions in fat_get_cluster:
We get these as conditions which can arise:fat_end_read() returns:
1) < 0
2) FAT_ENT_FREE
3) FAT_ENT_EOF
And the last is
4) Preventing the infinite looping of cluster chain.
Our patch is already covering the cases:
case 1) , 2) => if (search_clus < 0 || search_clus == FAT_ENT_FREE) about case 3) => while (search_clus != FAT_ENT_EOF);
while for Case 4:
We can make changes like this:
@@ -179,8 +179,9 @@ struct dentry *fat_get_parent(struct dentry *child_dir)
struct inode *parent_inode = NULL;
struct msdos_sb_info *sbi = MSDOS_SB(sb);
int parent_logstart;
- int search_clus, clus_to_match;
+ int search_clus, clus_to_match, clus_count = 0;
sector_t blknr;+ const int limit = sb->s_maxbytes >> MSDOS_SB(sb)->cluster_bits;
if (!fat_get_dotdot_entry(child_dir->d_inode, &dotdot_bh, &de)) {
parent_logstart = fat_get_start(sbi, de);
@@ -223,6 +224,14 @@ struct dentry *fat_get_parent(struct dentry *child_dir)
search_clus, clus_to_match);
if (IS_ERR(parent_inode) || parent_inode)
break;
+ if (++clus_count > limit) {
+ fat_fs_error_ratelimit(sb,
+ "%s: detected the cluster chain loop"
+ " while reading directory entries from"
+ " cluster %d", __func__, search_clus);
+ parent_inode = ERR_PTR(-EIO);
+ break;
+ }
fatent_init(&fatent);
search_clus = fat_ent_read(sb, &fatent,
search_clus);Signature · 5 lines
1.7.7.6 Are we missing anything more in this? Thanks.
Quoted 5 lines
Thanks.
--
OGAWA Hirofumi <[email protected]>
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
OGAWA Hirofumi
maintainerQuoted 49 lines · Namjae Jeon
Quoted 9 lines
Yes, we can't use
fat_search_long()as is, of course. However, we can share the basic algorithm and code.The both are doing,
1) traverse the blocks chained by ->i_start.
2) get the record (dirent) from blocks.
3) check the detail of recordQuoted 6 lines
The difference is only (3), right? I know, the code has many differences though. The actual logic are almost same.
And see, e.g.,
fat_get_cluster()is checking several unexpected state. We have to care about corrupting data. It is not only "infinite-loop" case. And why I'm saying it is better to share code.Regarding unexpected conditions,
When we compare the unexpected conditions infat_get_cluster:
We get these as conditions which can arise:fat_end_read()returns:
1) < 0
2)FAT_ENT_FREE
3)FAT_ENT_EOF
And the last is
4) Preventing the infinite looping of cluster chain.Our patch is already covering the cases:
case 1) , 2) => if (search_clus< 0 ||search_clus==FAT_ENT_FREE) about case 3) => while (search_clus!=FAT_ENT_EOF);while for Case 4:
We can make changes like this:(quoted diff) +3
-1@@ -179,8 +179,9 @@ struct dentry *fat_get_parent(struct dentry *child_dir) struct inode *parent_inode = NULL; struct msdos_sb_info *sbi = MSDOS_SB(sb); int parent_logstart; - int search_clus, clus_to_match; + int search_clus, clus_to_match, clus_count = 0; sector_t blknr; + const int limit = sb->s_maxbytes >> MSDOS_SB(sb)->cluster_bits; if (!fat_get_dotdot_entry(child_dir->d_inode, &dotdot_bh, &de)) { parent_logstart = fat_get_start(sbi, de);@@ -223,6 +224,14 @@ struct dentry *fat_get_parent(struct dentry *child_dir) search_clus, clus_to_match); if (IS_ERR(parent_inode) || parent_inode) break; + if (++clus_count > limit) {
Review struct dentry *fat_get_parent(struct dentry *child_dir) · line 237
Quoted 10 lines
(quoted diff) +7
-0+ fat_fs_error_ratelimit(sb, + "%s: detected the cluster chain loop" + " while reading directory entries from" + " cluster %d", __func__, search_clus); + parent_inode = ERR_PTR(-EIO); + break; + } fatent_init(&fatent); search_clus = fat_ent_read(sb, &fatent, search_clus);
and it is copy of fat_get_cluster(), right? It would be sane as start though, it is true to increase maintain cost, and it makes more similar to fat_search_long() path. It is why I said, copy at first, and refactoring after that.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
OGAWA Hirofumi
maintainerQuoted 58 lines · OGAWA Hirofumi
Quoted 56 lines · Namjae Jeon
Quoted 9 lines
Yes, we can't use
fat_search_long()as is, of course. However, we can share the basic algorithm and code.The both are doing,
1) traverse the blocks chained by ->i_start.
2) get the record (dirent) from blocks.
3) check the detail of recordQuoted 6 lines
The difference is only (3), right? I know, the code has many differences though. The actual logic are almost same.
And see, e.g.,
fat_get_cluster()is checking several unexpected state. We have to care about corrupting data. It is not only "infinite-loop" case. And why I'm saying it is better to share code.Regarding unexpected conditions,
When we compare the unexpected conditions infat_get_cluster:
We get these as conditions which can arise:fat_end_read()returns:
1) < 0
2)FAT_ENT_FREE
3)FAT_ENT_EOF
And the last is
4) Preventing the infinite looping of cluster chain.Our patch is already covering the cases:
case 1) , 2) => if (search_clus< 0 ||search_clus==FAT_ENT_FREE) about case 3) => while (search_clus!=FAT_ENT_EOF);while for Case 4:
We can make changes like this:(quoted diff) +10
-1@@ -179,8 +179,9 @@ struct dentry *fat_get_parent(struct dentry *child_dir) struct inode *parent_inode = NULL; struct msdos_sb_info *sbi = MSDOS_SB(sb); int parent_logstart; - int search_clus, clus_to_match; + int search_clus, clus_to_match, clus_count = 0; sector_t blknr; + const int limit = sb->s_maxbytes >> MSDOS_SB(sb)->cluster_bits; if (!fat_get_dotdot_entry(child_dir->d_inode, &dotdot_bh, &de)) { parent_logstart = fat_get_start(sbi, de);@@ -223,6 +224,14 @@ struct dentry *fat_get_parent(struct dentry *child_dir) search_clus, clus_to_match); if (IS_ERR(parent_inode) || parent_inode) break; + if (++clus_count > limit) { + fat_fs_error_ratelimit(sb, + "%s: detected the cluster chain loop" + " while reading directory entries from" + " cluster %d", __func__, search_clus); + parent_inode = ERR_PTR(-EIO); + break; + }
Quoted 8 lines
Review struct dentry *fat_get_parent(struct dentry *child_dir) · line 237
Quoted 3 lines
(quoted diff) +0
-0fatent_init(&fatent); search_clus = fat_ent_read(sb, &fatent, search_clus);and it is copy of
fat_get_cluster(), right? It would be sane as start though, it is true to increase maintain cost, and it makes more similar tofat_search_long()path. It is why I said, copy at first, and refactoring after that.
BTW, fat_search_long() was wrong as similar function. Actually it would be fat_scan(), because we don't care longname entry.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
Quoted 3 lines
BTW,
fat_search_long()was wrong as similar function. Actually it would befat_scan(), because we don't care longname entry.
Hi OGAWA.
We rewrite patch as your suggestion using dummy inode. Would please you review below patch code ?
Thanks.
--------------------------------------------------------------------------------------------
Subject: [PATCH] fat (exportfs): rebuild directory-inode if fat_dget()
fails
This patch enables rebuilding of directory inodes which are not present in the cache.This is done by traversing the disk clusters to find the directory entry of the parent directory and using its i_pos to build the inode.
Do this only if the "nostale_ro" nfs mount option is specified.
--- fs/fat/dir.c | 23 +++++++++++++++++++++++ fs/fat/fat.h | 3 +++ fs/fat/inode.c | 2 +- fs/fat/nfs.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 78 insertions(+), 2 deletions(-)
fs/fat/dir.c +23 -0
@@ -975,6 +975,29 @@ int fat_scan(struct inode *dir, const unsigned char *name,EXPORT_SYMBOL_GPL (fat_scan); +/* +* Scans a directory for a given logstart. +* Returns an error code or zero. +*/ +int fat_scan_logstart (struct inode *dir,int i_logstart, +struct fat_slot_info *sinfo) +{ +struct super_block *sb = dir->i_sb; + + sinfo->slot_off =0 ; + sinfo->bh =NULL ; +while (fat_get_short_entry (dir, &sinfo->slot_off, &sinfo->bh, + &sinfo->de) >=0 ) { +if (fat_get_start (MSDOS_SB (sb), sinfo->de) == i_logstart) { + sinfo->slot_off -=sizeof (*sinfo->de); + sinfo->nr_slots =1 ; + sinfo->i_pos =fat_make_i_pos (sb, sinfo->bh, sinfo->de); +return 0 ; + } + } +return -ENOENT ; +} +static int __fat_remove_entries (struct inode *dir,loff_t pos,int nr_slots) {struct super_block *sb = dir->i_sb;
fs/fat/fat.h +2 -0
@@ -291,6 +291,8 @@ extern int fat_dir_empty(struct inode *dir);extern int fat_subdirs (struct inode *dir);extern int fat_scan (struct inode *dir,const unsigned char *name,struct fat_slot_info *sinfo); +extern int fat_scan_logstart (struct inode *dir,int i_logstart, +struct fat_slot_info *sinfo);extern int fat_get_dotdot_entry (struct inode *dir,struct buffer_head **bh,struct msdos_dir_entry **de);extern int fat_alloc_new_dir (struct inode *dir,struct timespec *ts);
@@ -370,6 +372,7 @@ extern int fat_fill_super(struct super_block *sb,
void *data, int silent,
extern int fat_flush_inodes(struct super_block *sb, struct inode *i1,
struct inode *i2);
+extern int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de);
static inline unsigned long fat_dir_hash(int logstart)
{
return hash_32(logstart, FAT_HASH_BITS);
fs/fat/inode.c +1 -1
@@ -384,7 +384,7 @@ static int fat_calc_dir_size(struct inode *inode) }/* doesn't deal with root inode */ -static int fat_fill_inode (struct inode *inode,struct msdos_dir_entry *de) +int fat_fill_inode (struct inode *inode,struct msdos_dir_entry *de) {struct msdos_sb_info *sbi =MSDOS_SB (inode->i_sb);int error;
fs/fat/nfs.c +0 -0
@@ -213,6 +213,53 @@ static struct dentry
*fat_fh_to_parent_nostale(struct super_block *sb,
}
/*
+ * Rebuild the parent for a directory that is not connected
+ * to the filesystem root
+ */
+static
+struct inode *fat_rebuild_parent(struct super_block *sb, int parent_logstart) +{
+ int search_clus, clus_to_match;
+ struct msdos_dir_entry *de;
+ struct inode *parent = NULL;
+ struct inode *dummy_grand_parent = NULL;
+ struct fat_slot_info sinfo;
+ struct msdos_sb_info *sbi = MSDOS_SB(sb);
+ sector_t blknr = fat_clus_to_blknr(sbi, parent_logstart);
+ struct buffer_head *parent_bh = sb_bread(sb, blknr);
+ if (!parent_bh) {
+ fat_msg(sb, KERN_ERR,
+ "unable to read cluster of parent directory");
+ return NULL;
+ }
+
+ de = (struct msdos_dir_entry *) parent_bh->b_data;
+ clus_to_match = fat_get_start(sbi, &de[0]);
+ search_clus = fat_get_start(sbi, &de[1]);
+
+ dummy_grand_parent = fat_dget(sb, search_clus);
+ if (!dummy_grand_parent) {
+ dummy_grand_parent = new_inode(sb);
+ if (!dummy_grand_parent) {
+ brelse(parent_bh);
+ return parent;
+ }
+
+ dummy_grand_parent->i_ino = iunique(sb, MSDOS_ROOT_INO);
+ fat_fill_inode(dummy_grand_parent, &de[1]);
+ MSDOS_I(dummy_grand_parent)->i_pos = -1;
+ }
+
+ if (!fat_scan_logstart(dummy_grand_parent, clus_to_match, &sinfo))
+ parent = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
+
+ brelse(parent_bh);
+ iput(dummy_grand_parent);
+
+ return parent;
+}
+
+/*
* Find the parent for a directory that is not currently connected to
* the filesystem root.
*
@@ -224,10 +271,13 @@ static struct dentry *fat_get_parent(struct dentry *child_dir)
struct buffer_head *bh = NULL;
struct msdos_dir_entry *de;
struct inode *parent_inode = NULL;
+ struct msdos_sb_info *sbi = MSDOS_SB(sb);
if (!fat_get_dotdot_entry(child_dir->d_inode, &bh, &de)) {
- int parent_logstart = fat_get_start(MSDOS_SB(sb), de);
+ int parent_logstart = fat_get_start(sbi, de);
parent_inode = fat_dget(sb, parent_logstart);
+ if (!parent_inode && sbi->options.nfs == FAT_NFS_NOSTALE_RO)
+ parent_inode = fat_rebuild_parent(sb, parent_logstart);
}
brelse(bh);
Signature · 1 line
1.7.7.6
Quoted 3 lines
--
OGAWA Hirofumi <[email protected]>
OGAWA Hirofumi
maintainerQuoted 2 lines · Namjae Jeon
We rewrite patch as your suggestion using dummy inode. Would please you review below patch code ?
Looks like good as initial. Clean and shorter.
Next is, we have to think about race. I.e. if real inode was made, what happens? Is there no race?
Thanks.
Quoted 160 lines
Subject: [PATCH] fat (exportfs): rebuild directory-inode if
fat_dget()
failsThis patch enables rebuilding of directory inodes which are not present in the cache.This is done by traversing the disk clusters to find the directory entry of the parent directory and using its
i_posto build the inode.Do this only if the "
nostale_ro" nfs mount option is specified.--- fs/fat/dir.c | 23 +++++++++++++++++++++++ fs/fat/fat.h | 3 +++ fs/fat/inode.c | 2 +- fs/fat/nfs.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 78 insertions(+), 2 deletions(-)fs/fat/dir.c +23
-0@@ -975,6 +975,29 @@ int fat_scan(struct inode *dir, const unsigned char *name,EXPORT_SYMBOL_GPL (fat_scan); +/* +* Scans a directory for a given logstart. +* Returns an error code or zero. +*/ +int fat_scan_logstart (struct inode *dir,int i_logstart, +struct fat_slot_info *sinfo) +{ +struct super_block *sb = dir->i_sb; + + sinfo->slot_off =0 ; + sinfo->bh =NULL ; +while (fat_get_short_entry (dir, &sinfo->slot_off, &sinfo->bh, + &sinfo->de) >=0 ) { +if (fat_get_start (MSDOS_SB (sb), sinfo->de) == i_logstart) { + sinfo->slot_off -=sizeof (*sinfo->de); + sinfo->nr_slots =1 ; + sinfo->i_pos =fat_make_i_pos (sb, sinfo->bh, sinfo->de); +return 0 ; + } + } +return -ENOENT ; +} +static int __fat_remove_entries (struct inode *dir,loff_t pos,int nr_slots) {struct super_block *sb = dir->i_sb;fs/fat/fat.h +3
-0@@ -291,6 +291,8 @@ extern int fat_dir_empty(struct inode *dir);extern int fat_subdirs (struct inode *dir);extern int fat_scan (struct inode *dir,const unsigned char *name,struct fat_slot_info *sinfo); +extern int fat_scan_logstart (struct inode *dir,int i_logstart, +struct fat_slot_info *sinfo);extern int fat_get_dotdot_entry (struct inode *dir,struct buffer_head **bh,struct msdos_dir_entry **de);extern int fat_alloc_new_dir (struct inode *dir,struct timespec *ts);@@ -370,6 +372,7 @@ extern int fat_fill_super(struct super_block *sb, void *data, int silent, extern int fat_flush_inodes(struct super_block *sb, struct inode *i1,struct inode *i2); +extern int fat_fill_inode (struct inode *inode,struct msdos_dir_entry *de);static inline unsigned long fat_dir_hash (int logstart) {fs/fat/fat.h +0
-0return hash_32 (logstart,FAT_HASH_BITS );fs/fat/inode.c +1
-1@@ -384,7 +384,7 @@ static int fat_calc_dir_size(struct inode *inode) }/* doesn't deal with root inode */ -static int fat_fill_inode (struct inode *inode,struct msdos_dir_entry *de) +int fat_fill_inode (struct inode *inode,struct msdos_dir_entry *de) {struct msdos_sb_info *sbi =MSDOS_SB (inode->i_sb);int error;fs/fat/nfs.c +47
-0@@ -213,6 +213,53 @@ static struct dentry *fat_fh_to_parent_nostale(struct super_block *sb, }/* +* Rebuild the parent for a directory that is not connected +* to the filesystem root +*/ +static +struct inode *fat_rebuild_parent (struct super_block *sb,int parent_logstart) +{ +int search_clus, clus_to_match; +struct msdos_dir_entry *de; +struct inode *parent =NULL ; +struct inode *dummy_grand_parent =NULL ; +struct fat_slot_info sinfo; +struct msdos_sb_info *sbi =MSDOS_SB (sb); +sector_t blknr =fat_clus_to_blknr (sbi, parent_logstart); +struct buffer_head *parent_bh =sb_bread (sb, blknr); +if (!parent_bh) { +fat_msg (sb,KERN_ERR , +"unable to read cluster of parent directory" ); +return NULL ; + } + + de = (struct msdos_dir_entry *) parent_bh->b_data; + clus_to_match =fat_get_start (sbi, &de[0 ]); + search_clus =fat_get_start (sbi, &de[1 ]); + + dummy_grand_parent =fat_dget (sb, search_clus); +if (!dummy_grand_parent) { + dummy_grand_parent =new_inode (sb); +if (!dummy_grand_parent) { +brelse (parent_bh); +return parent; + } + + dummy_grand_parent->i_ino =iunique (sb,MSDOS_ROOT_INO ); +fat_fill_inode (dummy_grand_parent, &de[1 ]); +MSDOS_I (dummy_grand_parent)->i_pos =-1 ; + } + +if (!fat_scan_logstart (dummy_grand_parent, clus_to_match, &sinfo)) + parent =fat_build_inode (sb, sinfo.de, sinfo.i_pos); + +brelse (parent_bh); +iput (dummy_grand_parent); + +return parent; +} + +/* * Find the parent for a directory that is not currently connected to * the filesystem root. *
fs/fat/nfs.c +4
-1@@ -224,10 +271,13 @@ static struct dentry *fat_get_parent(struct dentry *child_dir)struct buffer_head *bh =NULL ;struct msdos_dir_entry *de;struct inode *parent_inode =NULL ; +struct msdos_sb_info *sbi =MSDOS_SB (sb);if (!fat_get_dotdot_entry (child_dir->d_inode, &bh, &de)) { -int parent_logstart =fat_get_start (MSDOS_SB (sb), de); +int parent_logstart =fat_get_start (sbi, de); parent_inode =fat_dget (sb, parent_logstart); +if (!parent_inode && sbi->options.nfs ==FAT_NFS_NOSTALE_RO ) + parent_inode =fat_rebuild_parent (sb, parent_logstart); }brelse (bh);
Signature · 1 line
OGAWA Hirofumi <[email protected]>
2013/1/20, OGAWA Hirofumi <[email protected]>:
Quoted 9 lines
Quoted 2 lines · Namjae Jeon
We rewrite patch as your suggestion using dummy inode. Would please you review below patch code ?
Looks like good as initial. Clean and shorter.
Next is, we have to think about race. I.e. if real inode was made, what happens? Is there no race?
Hi OGAWA.
Although checking several routines to check hang case you said, I didn't find anything.
And There is no any race on test result also. Am I missing something ? Let me know your opinion.
Thanks.
Quoted 174 lines
Thanks.
Quoted 157 lines
Subject: [PATCH] fat (exportfs): rebuild directory-inode if
fat_dget()
failsThis patch enables rebuilding of directory inodes which are not present in the cache.This is done by traversing the disk clusters to find the directory entry of the parent directory and using its
i_posto build the inode.Do this only if the "
nostale_ro" nfs mount option is specified.--- fs/fat/dir.c | 23 +++++++++++++++++++++++ fs/fat/fat.h | 3 +++ fs/fat/inode.c | 2 +- fs/fat/nfs.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 78 insertions(+), 2 deletions(-)fs/fat/dir.c +23
-0@@ -975,6 +975,29 @@ int fat_scan(struct inode *dir, const unsigned char *name,EXPORT_SYMBOL_GPL (fat_scan); +/* +* Scans a directory for a given logstart. +* Returns an error code or zero. +*/ +int fat_scan_logstart (struct inode *dir,int i_logstart, +struct fat_slot_info *sinfo) +{ +struct super_block *sb = dir->i_sb; + + sinfo->slot_off =0 ; + sinfo->bh =NULL ; +while (fat_get_short_entry (dir, &sinfo->slot_off, &sinfo->bh, + &sinfo->de) >=0 ) { +if (fat_get_start (MSDOS_SB (sb), sinfo->de) == i_logstart) { + sinfo->slot_off -=sizeof (*sinfo->de); + sinfo->nr_slots =1 ; + sinfo->i_pos =fat_make_i_pos (sb, sinfo->bh, sinfo->de); +return 0 ; + } + } +return -ENOENT ; +} +static int __fat_remove_entries (struct inode *dir,loff_t pos,int nr_slots){
fs/fat/dir.c +0
-0struct super_block *sb = dir->i_sb;fs/fat/fat.h +2
-0@@ -291,6 +291,8 @@ extern int fat_dir_empty(struct inode *dir);extern int fat_subdirs (struct inode *dir);extern int fat_scan (struct inode *dir,const unsigned char *name,struct fat_slot_info *sinfo); +extern int fat_scan_logstart (struct inode *dir,int i_logstart, +struct fat_slot_info *sinfo);extern int fat_get_dotdot_entry (struct inode *dir,struct buffer_head **bh,struct msdos_dir_entry **de);extern int
fat_alloc_new_dir(struct inode *dir, struct timespec *ts);fs/fat/fat.h +1
-0@@ -370,6 +372,7 @@ extern int fat_fill_super(struct super_block *sb, void *data, int silent, extern int fat_flush_inodes(struct super_block *sb, struct inode *i1,struct inode *i2); +extern int fat_fill_inode (struct inode *inode,struct msdos_dir_entry *de);static inline unsigned long fat_dir_hash (int logstart){
fs/fat/fat.h +0
-0return hash_32 (logstart,FAT_HASH_BITS );fs/fat/inode.c +1
-1@@ -384,7 +384,7 @@ static int fat_calc_dir_size(struct inode *inode) }/* doesn't deal with root inode */ -static int fat_fill_inode (struct inode *inode,struct msdos_dir_entry *de) +int fat_fill_inode (struct inode *inode,struct msdos_dir_entry *de) {struct msdos_sb_info *sbi =MSDOS_SB (inode->i_sb);fs/fat/inode.c +0
-0int error;fs/fat/nfs.c +47
-0@@ -213,6 +213,53 @@ static struct dentry *fat_fh_to_parent_nostale(struct super_block *sb, }/* +* Rebuild the parent for a directory that is not connected +* to the filesystem root +*/ +static +struct inode *fat_rebuild_parent (struct super_block *sb,int parent_logstart) +{ +int search_clus, clus_to_match; +struct msdos_dir_entry *de; +struct inode *parent =NULL ; +struct inode *dummy_grand_parent =NULL ; +struct fat_slot_info sinfo; +struct msdos_sb_info *sbi =MSDOS_SB (sb); +sector_t blknr =fat_clus_to_blknr (sbi, parent_logstart); +struct buffer_head *parent_bh =sb_bread (sb, blknr); +if (!parent_bh) { +fat_msg (sb,KERN_ERR , +"unable to read cluster of parent directory" ); +return NULL ; + } + + de = (struct msdos_dir_entry *) parent_bh->b_data; + clus_to_match =fat_get_start (sbi, &de[0 ]); + search_clus =fat_get_start (sbi, &de[1 ]); + + dummy_grand_parent =fat_dget (sb, search_clus); +if (!dummy_grand_parent) { + dummy_grand_parent =new_inode (sb); +if (!dummy_grand_parent) { +brelse (parent_bh); +return parent; + } + + dummy_grand_parent->i_ino =iunique (sb,MSDOS_ROOT_INO ); +fat_fill_inode (dummy_grand_parent, &de[1 ]); +MSDOS_I (dummy_grand_parent)->i_pos =-1 ; + } + +if (!fat_scan_logstart (dummy_grand_parent, clus_to_match, &sinfo)) + parent =fat_build_inode (sb, sinfo.de, sinfo.i_pos); + +brelse (parent_bh); +iput (dummy_grand_parent); + +return parent; +} + +/* * Find the parent for a directory that is not currently connected to * the filesystem root.
*fs/fat/nfs.c +0
-0@@ -224,10 +271,13 @@ static struct dentry *fat_get_parent(struct dentry *child_dir)struct buffer_head *bh =NULL ;struct msdos_dir_entry *de;struct inode *parent_inode =NULL ;fs/fat/nfs.c static struct dentry *fat_get_parent(struct · line 283
Quoted 10 lines
fs/fat/nfs.c +4
-1+struct msdos_sb_info *sbi =MSDOS_SB (sb);if (!fat_get_dotdot_entry (child_dir->d_inode, &bh, &de)) { -int parent_logstart =fat_get_start (MSDOS_SB (sb), de); +int parent_logstart =fat_get_start (sbi, de); parent_inode =fat_dget (sb, parent_logstart); +if (!parent_inode && sbi->options.nfs ==FAT_NFS_NOSTALE_RO ) + parent_inode =fat_rebuild_parent (sb, parent_logstart); }brelse (bh);--
OGAWA Hirofumi <[email protected]>
OGAWA Hirofumi
maintainerQuoted 8 lines · Namjae Jeon
2013/1/20, OGAWA Hirofumi <[email protected]>:
Quoted 7 lines
Quoted 2 lines · Namjae Jeon
We rewrite patch as your suggestion using dummy inode. Would please you review below patch code ?
Looks like good as initial. Clean and shorter.
Quoted 8 lines
Quoted 2 lines
Next is, we have to think about race. I.e. if real inode was made, what happens? Is there no race?
Hi OGAWA.
Although checking several routines to check hang case you said, I didn't find anything.
And There is no any race on test result also. Am I missing something ? Let me know your opinion.
Hm, it's read-only. So, there may not be race for now, I'm sure there is race on write path though.
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
2013/1/26, OGAWA Hirofumi <[email protected]>:
Quoted 14 lines
Quoted 12 lines · Namjae Jeon
2013/1/20, OGAWA Hirofumi <[email protected]>:
Quoted 9 lines
Quoted 2 lines · Namjae Jeon
We rewrite patch as your suggestion using dummy inode. Would please you review below patch code ?
Looks like good as initial. Clean and shorter.
Next is, we have to think about race. I.e. if real inode was made, what happens? Is there no race?
Hi OGAWA.
Quoted 7 lines
Quoted 4 lines
Although checking several routines to check hang case you said, I didn't find anything.
And There is no any race on test result also. Am I missing something ? Let me know your opinion.Hm, it's read-only. So, there may not be race for now, I'm sure there is race on write path though.
Yes, right. We checked/tested on read-only.
Maybe have you found race with rename and unlink ? If yes, I think we can fix this issue with lock like this.
+ mutex_lock(&MSDOS_SB(sb)->s_lock);
parent_inode = fat_rebuild_parent(sb, parent_logstart);+ mutex_unlock(&MSDOS_SB(sb)->s_lock);
Let me know your opinion.
Thanks.
Quoted 5 lines
Thanks.
--
OGAWA Hirofumi <[email protected]>
OGAWA Hirofumi
maintainerQuoted 11 lines · Namjae Jeon
Quoted 7 lines
Quoted 4 lines
Although checking several routines to check hang case you said, I didn't find anything.
And There is no any race on test result also. Am I missing something ? Let me know your opinion.Hm, it's read-only. So, there may not be race for now, I'm sure there is race on write path though.
Yes, right. We checked/tested on read-only.
Maybe have you found race with rename and unlink ? If yes, I think we can fix this issue with lock like this.
Review
Quoted 3 lines
(quoted diff) +2
-0+ mutex_lock(&MSDOS_SB(sb)->s_lock); parent_inode = fat_rebuild_parent(sb, parent_logstart); + mutex_unlock(&MSDOS_SB(sb)->s_lock);
It is any changes to directory. ->s_lock is not preferred. We need only per-directory lock (i.e. dir->i_mutex).
To do this, we need more bigger changes though. E.g. register temporary inode to central list. Then, find it when building real inode. If found temporary, grab it, and make update it as real inode.
Yes, this is a bit complex. But we would need something like this for write support.
Thanks.
Signature · 1 line
OGAWA Hirofumi <[email protected]>
2013/1/28, OGAWA Hirofumi <[email protected]>:
Quoted 21 lines
Quoted 7 lines · Namjae Jeon
Quoted 7 lines
Quoted 4 lines
Although checking several routines to check hang case you said, I didn't find anything.
And There is no any race on test result also. Am I missing something ? Let me know your opinion.Hm, it's read-only. So, there may not be race for now, I'm sure there is race on write path though.
Quoted 8 lines
Yes, right. We checked/tested on read-only.
Maybe have you found race with rename and unlink ? If yes, I think we can fix this issue with lock like this.+ mutex_lock(&MSDOS_SB(sb)->s_lock);
parent_inode= fat_rebuild_parent(sb,parent_logstart);
+ mutex_unlock(&MSDOS_SB(sb)->s_lock);It is any changes to directory. ->s_lock is not preferred. We need only per-directory lock (i.e.
dir->i_mutex).
Quoted 6 lines
To do this, we need more bigger changes though. E.g. register temporary inode to central list. Then, find it when building real inode. If found temporary, grab it, and make update it as real inode.
Yes, this is a bit complex. But we would need something like this for write support.
First Thanks for review and help. We will try to fix it as your suggestion now for the Write path.
There is one suggestion. As per discussion before, your suggestion was that, we will merge read-only support for FAT exportfs first. And the current patch set has no issues for read-only.
So If you accept, Can I try to re-send current patch-set (read-only) first? And we will then additionally start to fix issues related with write path step by step.
Let me know your opinion.
Thanks OGAWA!
Quoted 5 lines
Thanks.
--
OGAWA Hirofumi <[email protected]>