Commit 60f02a0
UPSTREAM: f2fs: atomic: fix to avoid racing w/ GC
Case #1:
SQLite App GC Thread Kworker Shrinker
- f2fs_ioc_start_atomic_write
- f2fs_ioc_commit_atomic_write
- f2fs_commit_atomic_write
- filemap_write_and_wait_range
: write atomic_file's data to cow_inode
echo 3 > drop_caches
to drop atomic_file's
cache.
- f2fs_gc
- gc_data_segment
- move_data_page
- set_page_dirty
- writepages
- f2fs_do_write_data_page
: overwrite atomic_file's data
to cow_inode
- f2fs_down_write(&fi->i_gc_rwsem[WRITE])
- __f2fs_commit_atomic_write
- f2fs_up_write(&fi->i_gc_rwsem[WRITE])
Case #2:
SQLite App GC Thread Kworker
- f2fs_ioc_start_atomic_write
- __writeback_single_inode
- do_writepages
- f2fs_write_cache_pages
- f2fs_write_single_data_page
- f2fs_do_write_data_page
: write atomic_file's data to cow_inode
- f2fs_gc
- gc_data_segment
- move_data_page
- set_page_dirty
- writepages
- f2fs_do_write_data_page
: overwrite atomic_file's data to cow_inode
- f2fs_ioc_commit_atomic_write
In above cases racing in between atomic_write and GC, previous
data in atomic_file may be overwrited to cow_file, result in
data corruption.
This patch introduces PAGE_PRIVATE_ATOMIC_WRITE bit flag in page.private,
and use it to indicate that there is last dirty data in atomic file,
and the data should be writebacked into cow_file, if the flag is not
tagged in page, we should never write data across files.
Fixes: 3db1de0 ("f2fs: change the current atomic write way")
Cc: Daeho Jeong <daehojeong@google.com>
Change-Id: I7e6c2a790b7f57c41d3a955cd9ba519d4dba12f9
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
(cherry picked from commit 1a0bd28)1 parent aa2602f commit 60f02a0
2 files changed
Lines changed: 16 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2672 | 2672 | | |
2673 | 2673 | | |
2674 | 2674 | | |
| 2675 | + | |
2675 | 2676 | | |
2676 | 2677 | | |
2677 | 2678 | | |
2678 | | - | |
| 2679 | + | |
| 2680 | + | |
| 2681 | + | |
2679 | 2682 | | |
2680 | 2683 | | |
2681 | 2684 | | |
| |||
2774 | 2777 | | |
2775 | 2778 | | |
2776 | 2779 | | |
| 2780 | + | |
| 2781 | + | |
2777 | 2782 | | |
2778 | 2783 | | |
2779 | 2784 | | |
| |||
3743 | 3748 | | |
3744 | 3749 | | |
3745 | 3750 | | |
| 3751 | + | |
| 3752 | + | |
| 3753 | + | |
3746 | 3754 | | |
3747 | 3755 | | |
3748 | 3756 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1423 | 1423 | | |
1424 | 1424 | | |
1425 | 1425 | | |
1426 | | - | |
| 1426 | + | |
| 1427 | + | |
1427 | 1428 | | |
1428 | 1429 | | |
1429 | 1430 | | |
| |||
1433 | 1434 | | |
1434 | 1435 | | |
1435 | 1436 | | |
| 1437 | + | |
1436 | 1438 | | |
1437 | 1439 | | |
1438 | 1440 | | |
| |||
2403 | 2405 | | |
2404 | 2406 | | |
2405 | 2407 | | |
| 2408 | + | |
2406 | 2409 | | |
2407 | 2410 | | |
2408 | 2411 | | |
2409 | 2412 | | |
| 2413 | + | |
2410 | 2414 | | |
2411 | 2415 | | |
2412 | 2416 | | |
2413 | 2417 | | |
| 2418 | + | |
2414 | 2419 | | |
2415 | 2420 | | |
2416 | 2421 | | |
| |||
2442 | 2447 | | |
2443 | 2448 | | |
2444 | 2449 | | |
| 2450 | + | |
2445 | 2451 | | |
2446 | 2452 | | |
2447 | 2453 | | |
| |||
0 commit comments