• Zhang Qilong's avatar
    f2fs: fix race condition on setting FI_NO_EXTENT flag · 07725adc
    Zhang Qilong authored
    The following scenarios exist.
    process A:               process B:
    ->f2fs_drop_extent_tree  ->f2fs_update_extent_cache_range
                              ->f2fs_update_extent_tree_range
                               ->write_lock
     ->set_inode_flag
                               ->is_inode_flag_set
                               ->__free_extent_tree // Shouldn't
                                                    // have been
                                                    // cleaned up
                                                    // here
      ->write_lock
    
    In this case, the "FI_NO_EXTENT" flag is set between
    f2fs_update_extent_tree_range and is_inode_flag_set
    by other process. it leads to clearing the whole exten
    tree which should not have happened. And we fix it by
    move the setting it to the range of write_lock.
    
    Fixes:5f281fab ("f2fs: disable extent_cache for fcollapse/finsert inodes")
    Signed-off-by: default avatarZhang Qilong <zhangqilong3@huawei.com>
    Reviewed-by: default avatarChao Yu <chao@kernel.org>
    Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
    07725adc
extent_cache.c 21.7 KB