f2fs: fix to update largest extent under lock
authorChao Yu <yuchao0@huawei.com>
Tue, 11 Oct 2016 14:57:05 +0000 (22:57 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 23 Nov 2016 20:10:55 +0000 (12:10 -0800)
In order to avoid racing problem, make largest extent cache being updated
under lock.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/inode.c

index d7369895a78a26059b65865f4a4e307fcd4aabf0..1fbebcb33a9df0a338e8d16ff53a43d4155c222a 100644 (file)
@@ -252,6 +252,7 @@ retry:
 int update_inode(struct inode *inode, struct page *node_page)
 {
        struct f2fs_inode *ri;
+       struct extent_tree *et = F2FS_I(inode)->extent_tree;
 
        f2fs_inode_synced(inode);
 
@@ -267,11 +268,13 @@ int update_inode(struct inode *inode, struct page *node_page)
        ri->i_size = cpu_to_le64(i_size_read(inode));
        ri->i_blocks = cpu_to_le64(inode->i_blocks);
 
-       if (F2FS_I(inode)->extent_tree)
-               set_raw_extent(&F2FS_I(inode)->extent_tree->largest,
-                                                       &ri->i_ext);
-       else
+       if (et) {
+               read_lock(&et->lock);
+               set_raw_extent(&et->largest, &ri->i_ext);
+               read_unlock(&et->lock);
+       } else {
                memset(&ri->i_ext, 0, sizeof(ri->i_ext));
+       }
        set_raw_inline(inode, ri);
 
        ri->i_atime = cpu_to_le64(inode->i_atime.tv_sec);