f2fs: early check broken symlink length in the encrypted case
Subsystems (2)
Jaegeuk Kim
maintainerPATCH 1/3 f2fs: early check broken symlink length in the encrypted case
If link is broken, its len is zero, and we don't need to move forward.
--- fs/f2fs/namei.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/f2fs/namei.c +8 -2
@@ -931,7 +931,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook {struct page *cpage =NULL ;char *caddr, *paddr =NULL ; -struct f2fs_str cstr; +struct f2fs_str cstr =FSTR_INIT (NULL ,0 );struct f2fs_str pstr =FSTR_INIT (NULL ,0 );struct inode *inode =d_inode (dentry);struct f2fs_encrypted_symlink_data *sd;
@@ -952,6 +952,12 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook/* Symlink is encrypted */ sd = (struct f2fs_encrypted_symlink_data *)caddr; cstr.len =le16_to_cpu (sd->len); + +/* this is broken symlink case */ +if (cstr.len ==0 ) { + res = -ENOENT ; + goto errout; + } cstr.name =kmalloc (cstr.len,GFP_NOFS );if (!cstr.name) { res = -ENOMEM ;
@@ -960,7 +966,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cookmemcpy (cstr.name, sd->encrypted_path, cstr.len);/* this is broken symlink case */ -if (cstr.name[0 ] ==0 && cstr.len ==0 ) { +if (cstr.name[0 ] ==0 ) { res = -ENOENT ; goto errout; }
Signature · 1 line
2.5.4 (Apple Git-61)
Jaegeuk Kim
maintainerPATCH 2/3 f2fs: use i_size_read to get i_size
We need to use i_size_read() to get inode->i_size.
--- fs/f2fs/data.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/f2fs/data.c +4 -3
@@ -1386,10 +1386,11 @@ skip_write:static void f2fs_write_failed (struct address_space *mapping,loff_t to) {struct inode *inode = mapping->host; +loff_t i_size =i_size_read (inode); -if (to > inode->i_size) { -truncate_pagecache (inode, inode->i_size); -truncate_blocks (inode, inode->i_size, true); +if (to > i_size) { +truncate_pagecache (inode, i_size); +truncate_blocks (inode, i_size, true); } }
Signature · 1 line
2.5.4 (Apple Git-61)
RE: [f2fs-dev] [PATCH 2/3] f2fs: use i_size_read to get i_size
Hi Jaegeuk,
Quoted 9 lines
-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, December 29, 2015 7:32 AM
To: [email protected]; [email protected]; [email protected]
Cc: Jaegeuk Kim
Subject: [f2fs-dev] [PATCH 2/3] f2fs: usei_size_readto geti_sizeWe need to use
i_size_read()to getinode->i_size.
All callers of f2fs_write_failed should be protected by i_mutex, so no one can change i_size, do we really need to use i_size_read here?
Thanks,
Quoted 34 lines
Signed-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/data.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/f2fs/data.c +4
-4@@ -1386,10 +1386,11 @@ skip_write:static void f2fs_write_failed (struct address_space *mapping,loff_t to) {struct inode *inode = mapping->host; +loff_t i_size =i_size_read (inode); -if (to > inode->i_size) { -truncate_pagecache (inode, inode->i_size); -truncate_blocks (inode, inode->i_size, true); +if (to > i_size) { +truncate_pagecache (inode, i_size); +truncate_blocks (inode, i_size, true); } } --2.5.4 (Apple Git-61)
------------------------------------------------------------------------------
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim
maintainerRe: [f2fs-dev] [PATCH 2/3] f2fs: use i_size_read to get i_size
Hi Chao,
Quoted 10 lines · Chao Yu
Hi Jaegeuk,
Quoted 8 lines
-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, December 29, 2015 7:32 AM
To: [email protected]; [email protected]; [email protected]
Cc: Jaegeuk Kim
Subject: [f2fs-dev] [PATCH 2/3] f2fs: usei_size_readto geti_size
Quoted 4 lines
Quoted 1 line
We need to use
i_size_read()to getinode->i_size.All callers of
f2fs_write_failedshould be protected byi_mutex, so no one can changei_size, do we really need to usei_size_readhere?
Just to follow convention and avoid any confusion later. We also use i_size_read/write consistently across whole areas.
Thanks,
Quoted 37 lines
Thanks,
Quoted 34 lines
Signed-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/data.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/f2fs/data.c +4
-4@@ -1386,10 +1386,11 @@ skip_write:static void f2fs_write_failed (struct address_space *mapping,loff_t to) {struct inode *inode = mapping->host; +loff_t i_size =i_size_read (inode); -if (to > inode->i_size) { -truncate_pagecache (inode, inode->i_size); -truncate_blocks (inode, inode->i_size, true); +if (to > i_size) { +truncate_pagecache (inode, i_size); +truncate_blocks (inode, i_size, true); } } --2.5.4 (Apple Git-61)
------------------------------------------------------------------------------
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim
maintainerPATCH 3/3 f2fs: load largest extent all the time
In reply to Jaegeuk KimOtherwise, we can get mismatched largest extent information.
One example is:
1. mount f2fs w/ extent_cache
2. make a small extent
3. umount
4. mount f2fs w/o extent_cache
5. update the largest extent
6. umount
7. mount f2fs w/ extent_cache
8. get the old extent made by #2
--- fs/f2fs/extent_cache.c | 18 +++++++++++++----- fs/f2fs/f2fs.h | 2 +- fs/f2fs/inode.c | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-)
fs/f2fs/extent_cache.c +13 -5
@@ -166,20 +166,27 @@ static void __drop_largest_extent(struct inode *inode, largest->len =0 ; } -void f2fs_init_extent_tree (struct inode *inode,struct f2fs_extent *i_ext) +/* return true, if inode page is changed */ +bool f2fs_init_extent_tree (struct inode *inode,struct f2fs_extent *i_ext) {struct f2fs_sb_info *sbi =F2FS_I_SB (inode);struct extent_tree *et;struct extent_node *en;struct extent_info ei; -if (!f2fs_may_extent_tree (inode)) -return ; +if (!f2fs_may_extent_tree (inode)) { +/* drop largest extent */ +if (i_ext && i_ext->len) { + i_ext->len =0 ; +return true; + } +return false; + } et =__grab_extent_tree (inode); -if (!i_ext ||le32_to_cpu (i_ext->len) <F2FS_MIN_EXTENT_LEN ) -return ; +if (!i_ext || !i_ext->len) +return false;set_extent_info (&ei,le32_to_cpu (i_ext->fofs),le32_to_cpu (i_ext->blk),le32_to_cpu (i_ext->len));
@@ -196,6 +203,7 @@ void f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext) } out:write_unlock (&et->lock); +return false; } static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs,
fs/f2fs/f2fs.h +1 -1
@@ -2083,7 +2083,7 @@ void f2fs_leave_shrinker(struct f2fs_sb_info *);* extent_cache.c */ unsigned int f2fs_shrink_extent_tree (struct f2fs_sb_info *,int ); -void f2fs_init_extent_tree (struct inode *,struct f2fs_extent *); +bool f2fs_init_extent_tree (struct inode *,struct f2fs_extent *);unsigned int f2fs_destroy_extent_node (struct inode *);void f2fs_destroy_extent_tree (struct inode *);bool f2fs_lookup_extent_cache (struct inode *,pgoff_t ,struct extent_info *);
fs/f2fs/inode.c +2 -1
@@ -138,7 +138,8 @@ static int do_read_inode(struct inode *inode) fi->i_pino =le32_to_cpu (ri->i_pino); fi->i_dir_level = ri->i_dir_level; -f2fs_init_extent_tree (inode, &ri->i_ext); +if (f2fs_init_extent_tree (inode, &ri->i_ext)) +set_page_dirty (node_page);get_inline_info (fi, ri);
Signature · 1 line
2.5.4 (Apple Git-61)
RE: [f2fs-dev] [PATCH 3/3] f2fs: load largest extent all the time
Hi Jaegeuk,
Quoted 10 lines
-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, December 29, 2015 7:32 AM
To: [email protected]; [email protected]; [email protected]
Cc: Jaegeuk Kim
Subject: [f2fs-dev] [PATCH 3/3] f2fs: load largest extent all the timeOtherwise, we can get mismatched largest extent information.
Quoted 9 lines
One example is:
1. mount f2fs w/extent_cache
2. make a small extent
3. umount
4. mount f2fs w/oextent_cache
5. update the largest extent
6. umount
7. mount f2fs w/extent_cache
8. get the old extent made by #2
Good catch!
It's a pity to drop it since it may provide some help if we can reuse it.
Thanks,
Quoted 89 lines
Signed-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/extent_cache.c | 18 +++++++++++++----- fs/f2fs/f2fs.h | 2 +- fs/f2fs/inode.c | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-)fs/f2fs/extent_cache.c +13
-5@@ -166,20 +166,27 @@ static void __drop_largest_extent(struct inode *inode, largest->len =0 ; } -void f2fs_init_extent_tree (struct inode *inode,struct f2fs_extent *i_ext) +/* return true, if inode page is changed */ +bool f2fs_init_extent_tree (struct inode *inode,struct f2fs_extent *i_ext) {struct f2fs_sb_info *sbi =F2FS_I_SB (inode);struct extent_tree *et;struct extent_node *en;struct extent_info ei; -if (!f2fs_may_extent_tree (inode)) -return ; +if (!f2fs_may_extent_tree (inode)) { +/* drop largest extent */ +if (i_ext && i_ext->len) { + i_ext->len =0 ; +return true; + } +return false; + } et =__grab_extent_tree (inode); -if (!i_ext ||le32_to_cpu (i_ext->len) <F2FS_MIN_EXTENT_LEN ) -return ; +if (!i_ext || !i_ext->len) +return false;set_extent_info (&ei,le32_to_cpu (i_ext->fofs),le32_to_cpu (i_ext->blk),le32_to_cpu (i_ext->len));@@ -196,6 +203,7 @@ void f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext) } out:write_unlock (&et->lock); +return false; } static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs,fs/f2fs/f2fs.h +1
-1@@ -2083,7 +2083,7 @@ void f2fs_leave_shrinker(struct f2fs_sb_info *);* extent_cache.c */ unsigned int f2fs_shrink_extent_tree (struct f2fs_sb_info *,int ); -void f2fs_init_extent_tree (struct inode *,struct f2fs_extent *); +bool f2fs_init_extent_tree (struct inode *,struct f2fs_extent *);unsigned int f2fs_destroy_extent_node (struct inode *);void f2fs_destroy_extent_tree (struct inode *);bool f2fs_lookup_extent_cache (struct inode *,pgoff_t ,struct extent_info *);fs/f2fs/inode.c +2
-2@@ -138,7 +138,8 @@ static int do_read_inode(struct inode *inode) fi->i_pino =le32_to_cpu (ri->i_pino); fi->i_dir_level = ri->i_dir_level; -f2fs_init_extent_tree (inode, &ri->i_ext); +if (f2fs_init_extent_tree (inode, &ri->i_ext)) +set_page_dirty (node_page);get_inline_info (fi, ri); --2.5.4 (Apple Git-61)
------------------------------------------------------------------------------
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim
maintainerRe: [f2fs-dev] [PATCH 3/3] f2fs: load largest extent all the time
Hi Chao,
Quoted 22 lines · Chao Yu
Hi Jaegeuk,
Quoted 10 lines
-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, December 29, 2015 7:32 AM
To: [email protected]; [email protected]; [email protected]
Cc: Jaegeuk Kim
Subject: [f2fs-dev] [PATCH 3/3] f2fs: load largest extent all the timeOtherwise, we can get mismatched largest extent information.
Quoted 9 lines
One example is:
1. mount f2fs w/extent_cache
2. make a small extent
3. umount
4. mount f2fs w/oextent_cache
5. update the largest extent
6. umount
7. mount f2fs w/extent_cache
8. get the old extent made by #2
Quoted 4 lines
Good catch!
It's a pity to drop it since it may provide some help if we can reuse it.
Indeed, but I expect it's not a common case.
Thanks,
Quoted 92 lines
Thanks,
Quoted 89 lines
Signed-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/extent_cache.c | 18 +++++++++++++----- fs/f2fs/f2fs.h | 2 +- fs/f2fs/inode.c | 3 ++- 3 files changed, 16 insertions(+), 7 deletions(-)fs/f2fs/extent_cache.c +13
-5@@ -166,20 +166,27 @@ static void __drop_largest_extent(struct inode *inode, largest->len =0 ; } -void f2fs_init_extent_tree (struct inode *inode,struct f2fs_extent *i_ext) +/* return true, if inode page is changed */ +bool f2fs_init_extent_tree (struct inode *inode,struct f2fs_extent *i_ext) {struct f2fs_sb_info *sbi =F2FS_I_SB (inode);struct extent_tree *et;struct extent_node *en;struct extent_info ei; -if (!f2fs_may_extent_tree (inode)) -return ; +if (!f2fs_may_extent_tree (inode)) { +/* drop largest extent */ +if (i_ext && i_ext->len) { + i_ext->len =0 ; +return true; + } +return false; + } et =__grab_extent_tree (inode); -if (!i_ext ||le32_to_cpu (i_ext->len) <F2FS_MIN_EXTENT_LEN ) -return ; +if (!i_ext || !i_ext->len) +return false;set_extent_info (&ei,le32_to_cpu (i_ext->fofs),le32_to_cpu (i_ext->blk),le32_to_cpu (i_ext->len));@@ -196,6 +203,7 @@ void f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext) } out:write_unlock (&et->lock); +return false; } static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs,fs/f2fs/f2fs.h +1
-1@@ -2083,7 +2083,7 @@ void f2fs_leave_shrinker(struct f2fs_sb_info *);* extent_cache.c */ unsigned int f2fs_shrink_extent_tree (struct f2fs_sb_info *,int ); -void f2fs_init_extent_tree (struct inode *,struct f2fs_extent *); +bool f2fs_init_extent_tree (struct inode *,struct f2fs_extent *);unsigned int f2fs_destroy_extent_node (struct inode *);void f2fs_destroy_extent_tree (struct inode *);bool f2fs_lookup_extent_cache (struct inode *,pgoff_t ,struct extent_info *);fs/f2fs/inode.c +2
-2@@ -138,7 +138,8 @@ static int do_read_inode(struct inode *inode) fi->i_pino =le32_to_cpu (ri->i_pino); fi->i_dir_level = ri->i_dir_level; -f2fs_init_extent_tree (inode, &ri->i_ext); +if (f2fs_init_extent_tree (inode, &ri->i_ext)) +set_page_dirty (node_page);get_inline_info (fi, ri); --2.5.4 (Apple Git-61)
------------------------------------------------------------------------------
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Hi Jaegeuk,
Quoted 30 lines
-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, December 29, 2015 7:32 AM
To: [email protected]; [email protected]; [email protected]
Cc: Jaegeuk Kim
Subject: [f2fs-dev] [PATCH 1/3] f2fs: early check broken symlink length in the encrypted caseIf link is broken, its len is zero, and we don't need to move forward.
Signed-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/namei.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)fs/f2fs/namei.c +1
-1@@ -931,7 +931,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook {struct page *cpage =NULL ;char *caddr, *paddr =NULL ; -struct f2fs_str cstr; +struct f2fs_str cstr =FSTR_INIT (NULL ,0 );struct f2fs_str pstr =FSTR_INIT (NULL ,0 );struct inode *inode =d_inode (dentry);fs/f2fs/namei.c +0
-0struct f2fs_encrypted_symlink_data *sd;
fs/f2fs/namei.c static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void · line 958
Quoted 7 lines
fs/f2fs/namei.c +3
-0@@ -952,6 +952,12 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook/* Symlink is encrypted */ sd = (struct f2fs_encrypted_symlink_data *)caddr; cstr.len =le16_to_cpu (sd->len); + +/* this is broken symlink case */ +if (cstr.len ==0 ) {
This case seems rare, can we add unlikely here?
fs/f2fs/namei.c static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void · line 970
Quoted 13 lines
fs/f2fs/namei.c +3
-0+ res = -ENOENT ; + goto errout; + } cstr.name =kmalloc (cstr.len,GFP_NOFS );if (!cstr.name) {fs/f2fs/namei.c +1
-1res = -ENOMEM ;@@ -960,7 +966,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cookmemcpy (cstr.name, sd->encrypted_path, cstr.len);/* this is broken symlink case */ -if (cstr.name[0 ] ==0 && cstr.len ==0 ) { +if (cstr.name[0 ] ==0 ) {
ditto.
Thanks,
Quoted 12 lines
fs/f2fs/namei.c +0
-0res = -ENOENT ; goto errout;}
--
2.5.4 (Apple Git-61)------------------------------------------------------------------------------
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim
maintainerHi Chao,
Quoted 33 lines · Chao Yu
Hi Jaegeuk,
Quoted 31 lines
-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Tuesday, December 29, 2015 7:32 AM
To: [email protected]; [email protected]; [email protected]
Cc: Jaegeuk Kim
Subject: [f2fs-dev] [PATCH 1/3] f2fs: early check broken symlink length in the encrypted caseIf link is broken, its len is zero, and we don't need to move forward.
Signed-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/namei.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)fs/f2fs/namei.c +1
-1@@ -931,7 +931,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook {struct page *cpage =NULL ;char *caddr, *paddr =NULL ; -struct f2fs_str cstr; +struct f2fs_str cstr =FSTR_INIT (NULL ,0 );struct f2fs_str pstr =FSTR_INIT (NULL ,0 );struct inode *inode =d_inode (dentry);fs/f2fs/namei.c +0
-0struct f2fs_encrypted_symlink_data *sd;@@ -952,6 +952,12 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook
Quoted 8 lines
fs/f2fs/namei.c static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook · line 957
Quoted 6 lines
fs/f2fs/namei.c +3
-0/* Symlink is encrypted */ sd = (struct f2fs_encrypted_symlink_data *)caddr; cstr.len =le16_to_cpu (sd->len); + +/* this is broken symlink case */ +if (cstr.len ==0 ) {This case seems rare, can we add unlikely here?
Agreed.
Will change them.
Thanks,
Quoted 31 lines
Quoted 8 lines
fs/f2fs/namei.c +3
-0+ res = -ENOENT ; + goto errout; + } cstr.name =kmalloc (cstr.len,GFP_NOFS );if (!cstr.name) {fs/f2fs/namei.c +0
-0res = -ENOMEM ;fs/f2fs/namei.c static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void · line 970
Quoted 6 lines
fs/f2fs/namei.c +1
-1@@ -960,7 +966,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cookmemcpy (cstr.name, sd->encrypted_path, cstr.len);/* this is broken symlink case */ -if (cstr.name[0 ] ==0 && cstr.len ==0 ) { +if (cstr.name[0 ] ==0 ) {ditto.
Thanks,
Quoted 12 lines
fs/f2fs/namei.c +0
-0res = -ENOENT ; goto errout;}
--
2.5.4 (Apple Git-61)------------------------------------------------------------------------------
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel