Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34c061a

Browse files
Sayali LokhandeJaegeuk Kim
authored andcommitted
f2fs: Avoid double lock for cp_rwsem during checkpoint
There could be a scenario where f2fs_sync_node_pages gets called during checkpoint, which in turn tries to flush inline data and calls iput(). This results in deadlock as iput() tries to hold cp_rwsem, which is already held at the beginning by checkpoint->block_operations(). Call stack : Thread A Thread B f2fs_write_checkpoint() - block_operations(sbi) - f2fs_lock_all(sbi); - down_write(&sbi->cp_rwsem); - open() - igrab() - write() write inline data - unlink() - f2fs_sync_node_pages() - if (is_inline_node(page)) - flush_inline_data() - ilookup() page = f2fs_pagecache_get_page() if (!page) goto iput_out; iput_out: -close() -iput() iput(inode); - f2fs_evict_inode() - f2fs_truncate_blocks() - f2fs_lock_op() - down_read(&sbi->cp_rwsem); Fixes: 2049d4f ("f2fs: avoid multiple node page writes due to inline_data") Signed-off-by: Sayali Lokhande <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent baaa7eb commit 34c061a

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

fs/f2fs/checkpoint.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,11 @@ static int block_operations(struct f2fs_sb_info *sbi)
11681168
};
11691169
int err = 0, cnt = 0;
11701170

1171+
/*
1172+
* Let's flush inline_data in dirty node pages.
1173+
*/
1174+
f2fs_flush_inline_data(sbi);
1175+
11711176
retry_flush_quotas:
11721177
f2fs_lock_all(sbi);
11731178
if (__need_flush_quota(sbi)) {

fs/f2fs/f2fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,6 +3282,7 @@ void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid);
32823282
struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid);
32833283
struct page *f2fs_get_node_page_ra(struct page *parent, int start);
32843284
int f2fs_move_node_page(struct page *node_page, int gc_type);
3285+
int f2fs_flush_inline_data(struct f2fs_sb_info *sbi);
32853286
int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
32863287
struct writeback_control *wbc, bool atomic,
32873288
unsigned int *seq_id);

fs/f2fs/node.c

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,53 @@ static bool flush_dirty_inode(struct page *page)
18071807
return true;
18081808
}
18091809

1810+
int f2fs_flush_inline_data(struct f2fs_sb_info *sbi)
1811+
{
1812+
pgoff_t index = 0;
1813+
struct pagevec pvec;
1814+
int nr_pages;
1815+
int ret = 0;
1816+
1817+
pagevec_init(&pvec);
1818+
1819+
while ((nr_pages = pagevec_lookup_tag(&pvec,
1820+
NODE_MAPPING(sbi), &index, PAGECACHE_TAG_DIRTY))) {
1821+
int i;
1822+
1823+
for (i = 0; i < nr_pages; i++) {
1824+
struct page *page = pvec.pages[i];
1825+
1826+
if (!IS_DNODE(page))
1827+
continue;
1828+
1829+
lock_page(page);
1830+
1831+
if (unlikely(page->mapping != NODE_MAPPING(sbi))) {
1832+
continue_unlock:
1833+
unlock_page(page);
1834+
continue;
1835+
}
1836+
1837+
if (!PageDirty(page)) {
1838+
/* someone wrote it for us */
1839+
goto continue_unlock;
1840+
}
1841+
1842+
/* flush inline_data, if it's async context. */
1843+
if (is_inline_node(page)) {
1844+
clear_inline_node(page);
1845+
unlock_page(page);
1846+
flush_inline_data(sbi, ino_of_node(page));
1847+
continue;
1848+
}
1849+
unlock_page(page);
1850+
}
1851+
pagevec_release(&pvec);
1852+
cond_resched();
1853+
}
1854+
return ret;
1855+
}
1856+
18101857
int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
18111858
struct writeback_control *wbc,
18121859
bool do_balance, enum iostat_type io_type)
@@ -1870,8 +1917,8 @@ int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
18701917
goto continue_unlock;
18711918
}
18721919

1873-
/* flush inline_data */
1874-
if (is_inline_node(page)) {
1920+
/* flush inline_data, if it's async context. */
1921+
if (do_balance && is_inline_node(page)) {
18751922
clear_inline_node(page);
18761923
unlock_page(page);
18771924
flush_inline_data(sbi, ino_of_node(page));

0 commit comments

Comments
 (0)