f2fs: fix up f2fs_get_parent issue to retrieve correct parent inode number
Subsystems (2)
PATCH 1/1 f2fs: fix up f2fs_get_parent issue to retrieve correct parent inode number
From: Namjae Jeon <[email protected]>
Test Case:
[NFS Client]
ls -lR .
[NFS Server]
while [ 1 ]
do
echo 3 > /proc/sys/vm/drop_caches
done
Error on NFS Client: "No such file or directory"
When cache is dropped at the server, it results in lookup failure at the NFS client due to non-connection with the parent. The default path is it initiates a lookup by calculating the hash value for the name, even though the hash values stored on the disk for "." and ".." is maintained as zero, which results in failure from find_in_block due to not matching HASH values. Fix up, by using the correct hashing values for these entries.
--- fs/f2fs/dir.c | 4 ++-- fs/f2fs/hash.c | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-)
fs/f2fs/dir.c +2 -2
@@ -540,13 +540,13 @@ int f2fs_make_empty(struct inode *inode, struct inode *parent) de = &dentry_blk->dentry[0 ]; de->name_len =cpu_to_le16 (1 ); - de->hash_code =0 ; + de->hash_code =f2fs_dentry_hash ("." ,1 ); de->ino =cpu_to_le32 (inode->i_ino);memcpy (dentry_blk->filename[0 ],"." ,1 );set_de_type (de, inode); de = &dentry_blk->dentry[1 ]; - de->hash_code =0 ; + de->hash_code =f2fs_dentry_hash (".." ,2 ); de->name_len =cpu_to_le16 (2 ); de->ino =cpu_to_le32 (parent->i_ino);memcpy (dentry_blk->filename[1 ],".." ,2 );
fs/f2fs/hash.c +4 -0
@@ -76,6 +76,10 @@ f2fs_hash_t f2fs_dentry_hash(const char *name, int len)const char *p;__u32 in[8 ], buf[4 ]; +/* dot and dotdot dentries should have zero-value hash code */ +if (!memcmp (name,"." ,1 ) || !memcmp (name,".." ,2 )) +return 0 ; +/* Initialize the default seed for the hash checksum functions */ buf[0 ] =0x67452301 ; buf[1 ] =0xefcdab89 ;
Signature · 1 line
1.7.9.5
fs/f2fs/hash.c f2fs_hash_t f2fs_dentry_hash(const char *name, int len) · line 81
Quoted 3 lines · Namjae Jeon
fs/f2fs/hash.c +3
-0+/* dot and dotdot dentries should have zero-value hash code */ +if (!memcmp (name,"." ,1 ) || !memcmp (name,".." ,2 )) +return 0 ;
That looks suspicious. If memcmp(name, "..", 2) == 0 then always memcmp(name, ".", 1) == 0. Why two tests ?
Fubo.
Quoted 8 lines · Fubo Chen
fs/f2fs/hash.c f2fs_hash_t f2fs_dentry_hash(const char *name, int len) · line 81
Quoted 3 lines · Namjae Jeon
fs/f2fs/hash.c +3
-0+/* dot and dotdot dentries should have zero-value hash code */ +if (!memcmp (name,"." ,1 ) || !memcmp (name,".." ,2 )) +return 0 ;That looks suspicious. If
memcmp(name, "..", 2)== 0 then alwaysmemcmp(name, ".", 1)== 0. Why two tests ?
It is not the case vice versa, so you still need to do two checks. You need to distinguish dot(.), dotdot(..) and something with dot at the beginning (for example - .o)
Quoted 7 lines
Fubo.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
--
Leon Romanovsky | Independent Linux Consultant
www.leon.nu | [email protected]
Quoted 7 lines · Leon Romanovsky
Quoted 6 lines · Fubo Chen
Quoted 3 lines · Namjae Jeon
fs/f2fs/hash.c +3
-0+/* dot and dotdot dentries should have zero-value hash code */ +if (!memcmp (name,"." ,1 ) || !memcmp (name,".." ,2 )) +return 0 ;
Quoted 6 lines
Quoted 2 lines
That looks suspicious. If
memcmp(name, "..", 2)== 0 then alwaysmemcmp(name, ".", 1)== 0. Why two tests ?It is not the case vice versa, so you still need to do two checks. You need to distinguish dot(.), dotdot(..) and something with dot at the beginning (for example - .o)
Thanks for replying. I understand that the intention is what you explained. But to me the code says something else: "if the first byte of name is a dot, return 0". Did I see that correctly ?
Fubo.
Quoted 11 lines · Fubo Chen
Quoted 10 lines · Leon Romanovsky
Quoted 8 lines · Fubo Chen
fs/f2fs/hash.c f2fs_hash_t f2fs_dentry_hash(const char *name, int len) · line 81
Quoted 3 lines · Namjae Jeon
fs/f2fs/hash.c +3
-0+/* dot and dotdot dentries should have zero-value hash code */ +if (!memcmp (name,"." ,1 ) || !memcmp (name,".." ,2 )) +return 0 ;That looks suspicious. If
memcmp(name, "..", 2)== 0 then alwaysmemcmp(name, ".", 1)== 0. Why two tests ?
Quoted 7 lines
Quoted 3 lines
It is not the case vice versa, so you still need to do two checks. You need to distinguish dot(.), dotdot(..) and something with dot at the beginning (for example - .o)
Thanks for replying. I understand that the intention is what you explained. But to me the code says something else: "if the first byte of name is a dot, return 0". Did I see that correctly ?
Excellent catch, I agree with you It will also return 0 for every file which starts from the dot.
The right solution must take name length into account.
Quoted 2 lines
Fubo.
Signature · 2 lines
Leon Romanovsky | Independent Linux Consultant
www.leon.nu | [email protected]2012/12/13, Leon Romanovsky <[email protected]>:
Quoted 18 lines · Fubo Chen
Quoted 17 lines · Leon Romanovsky
Quoted 15 lines · Fubo Chen
Quoted 10 lines
fs/f2fs/hash.c f2fs_hash_t f2fs_dentry_hash(const char *name, int len) · line 81
Quoted 4 lines · Namjae Jeon
+ /* dot and dotdot dentries should have zero-value hash code
*/fs/f2fs/hash.c +2
-0+if (!memcmp (name,"." ,1 ) || !memcmp (name,".." ,2 )) +return 0 ;That looks suspicious. If
memcmp(name, "..", 2)== 0 then alwaysmemcmp(name, ".", 1)== 0. Why two tests ?It is not the case vice versa, so you still need to do two checks. You need to distinguish dot(.), dotdot(..) and something with dot at the beginning (for example - .o)
Quoted 6 lines
Quoted 3 lines
Thanks for replying. I understand that the intention is what you explained. But to me the code says something else: "if the first byte of name is a dot, return 0". Did I see that correctly ?
Excellent catch, I agree with you It will also return 0 for every file which starts from the dot.
The right solution must take name length into account.
Hi.
Agree. I will change it on v2 patch.
Thanks for review.
Quoted 10 lines
Quoted 3 lines
Fubo.
--
Leon Romanovsky | Independent Linux Consultant
www.leon.nu | [email protected]
2012-12-13 (목), 07:44 +0900, Namjae Jeon:
Quoted 22 lines
2012/12/13, Leon Romanovsky <[email protected]>:
Quoted 21 lines · Fubo Chen
Quoted 20 lines · Leon Romanovsky
Quoted 9 lines · Fubo Chen
Quoted 8 lines
Quoted 4 lines · Namjae Jeon
+ /* dot and dotdot dentries should have zero-value hash code
*/fs/f2fs/hash.c +2
-0+if (!memcmp (name,"." ,1 ) || !memcmp (name,".." ,2 )) +return 0 ;Quoted 6 lines
Quoted 2 lines
That looks suspicious. If
memcmp(name, "..", 2)== 0 then alwaysmemcmp(name, ".", 1)== 0. Why two tests ?It is not the case vice versa, so you still need to do two checks. You need to distinguish dot(.), dotdot(..) and something with dot at the beginning (for example - .o)
Thanks for replying. I understand that the intention is what you explained. But to me the code says something else: "if the first byte of name is a dot, return 0". Did I see that correctly ?
Quoted 6 lines
Quoted 3 lines
Excellent catch, I agree with you It will also return 0 for every file which starts from the dot.
The right solution must take name length into account.Hi.
Agree. I will change it on v2 patch.
Thanks for review.
Nice catch!
I made a mistake initially before. Sorry Namjae.
Thanks to all of you.
Signature · 2 lines
Jaegeuk Kim Samsung