|
@@ -1222,13 +1222,81 @@ iput_out:
|
|
iput(inode);
|
|
iput(inode);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static struct page *last_fsync_dnode(struct f2fs_sb_info *sbi, nid_t ino)
|
|
|
|
+{
|
|
|
|
+ pgoff_t index, end;
|
|
|
|
+ struct pagevec pvec;
|
|
|
|
+ struct page *last_page = NULL;
|
|
|
|
+
|
|
|
|
+ pagevec_init(&pvec, 0);
|
|
|
|
+ index = 0;
|
|
|
|
+ end = ULONG_MAX;
|
|
|
|
+
|
|
|
|
+ while (index <= end) {
|
|
|
|
+ int i, nr_pages;
|
|
|
|
+ nr_pages = pagevec_lookup_tag(&pvec, NODE_MAPPING(sbi), &index,
|
|
|
|
+ PAGECACHE_TAG_DIRTY,
|
|
|
|
+ min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
|
|
|
|
+ if (nr_pages == 0)
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ for (i = 0; i < nr_pages; i++) {
|
|
|
|
+ struct page *page = pvec.pages[i];
|
|
|
|
+
|
|
|
|
+ if (unlikely(f2fs_cp_error(sbi))) {
|
|
|
|
+ f2fs_put_page(last_page, 0);
|
|
|
|
+ pagevec_release(&pvec);
|
|
|
|
+ return ERR_PTR(-EIO);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!IS_DNODE(page) || !is_cold_node(page))
|
|
|
|
+ continue;
|
|
|
|
+ if (ino_of_node(page) != ino)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ lock_page(page);
|
|
|
|
+
|
|
|
|
+ if (unlikely(page->mapping != NODE_MAPPING(sbi))) {
|
|
|
|
+continue_unlock:
|
|
|
|
+ unlock_page(page);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (ino_of_node(page) != ino)
|
|
|
|
+ goto continue_unlock;
|
|
|
|
+
|
|
|
|
+ if (!PageDirty(page)) {
|
|
|
|
+ /* someone wrote it for us */
|
|
|
|
+ goto continue_unlock;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (last_page)
|
|
|
|
+ f2fs_put_page(last_page, 0);
|
|
|
|
+
|
|
|
|
+ get_page(page);
|
|
|
|
+ last_page = page;
|
|
|
|
+ unlock_page(page);
|
|
|
|
+ }
|
|
|
|
+ pagevec_release(&pvec);
|
|
|
|
+ cond_resched();
|
|
|
|
+ }
|
|
|
|
+ return last_page;
|
|
|
|
+}
|
|
|
|
+
|
|
int fsync_node_pages(struct f2fs_sb_info *sbi, nid_t ino,
|
|
int fsync_node_pages(struct f2fs_sb_info *sbi, nid_t ino,
|
|
- struct writeback_control *wbc)
|
|
|
|
|
|
+ struct writeback_control *wbc, bool atomic)
|
|
{
|
|
{
|
|
pgoff_t index, end;
|
|
pgoff_t index, end;
|
|
struct pagevec pvec;
|
|
struct pagevec pvec;
|
|
int ret = 0;
|
|
int ret = 0;
|
|
|
|
+ struct page *last_page = NULL;
|
|
|
|
+ bool marked = false;
|
|
|
|
|
|
|
|
+ if (atomic) {
|
|
|
|
+ last_page = last_fsync_dnode(sbi, ino);
|
|
|
|
+ if (IS_ERR_OR_NULL(last_page))
|
|
|
|
+ return PTR_ERR_OR_ZERO(last_page);
|
|
|
|
+ }
|
|
|
|
+retry:
|
|
pagevec_init(&pvec, 0);
|
|
pagevec_init(&pvec, 0);
|
|
index = 0;
|
|
index = 0;
|
|
end = ULONG_MAX;
|
|
end = ULONG_MAX;
|
|
@@ -1245,6 +1313,7 @@ int fsync_node_pages(struct f2fs_sb_info *sbi, nid_t ino,
|
|
struct page *page = pvec.pages[i];
|
|
struct page *page = pvec.pages[i];
|
|
|
|
|
|
if (unlikely(f2fs_cp_error(sbi))) {
|
|
if (unlikely(f2fs_cp_error(sbi))) {
|
|
|
|
+ f2fs_put_page(last_page, 0);
|
|
pagevec_release(&pvec);
|
|
pagevec_release(&pvec);
|
|
return -EIO;
|
|
return -EIO;
|
|
}
|
|
}
|
|
@@ -1264,33 +1333,54 @@ continue_unlock:
|
|
if (ino_of_node(page) != ino)
|
|
if (ino_of_node(page) != ino)
|
|
goto continue_unlock;
|
|
goto continue_unlock;
|
|
|
|
|
|
- if (!PageDirty(page)) {
|
|
|
|
|
|
+ if (!PageDirty(page) && page != last_page) {
|
|
/* someone wrote it for us */
|
|
/* someone wrote it for us */
|
|
goto continue_unlock;
|
|
goto continue_unlock;
|
|
}
|
|
}
|
|
|
|
|
|
f2fs_wait_on_page_writeback(page, NODE, true);
|
|
f2fs_wait_on_page_writeback(page, NODE, true);
|
|
BUG_ON(PageWriteback(page));
|
|
BUG_ON(PageWriteback(page));
|
|
- if (!clear_page_dirty_for_io(page))
|
|
|
|
- goto continue_unlock;
|
|
|
|
|
|
|
|
- set_fsync_mark(page, 1);
|
|
|
|
- if (IS_INODE(page))
|
|
|
|
- set_dentry_mark(page,
|
|
|
|
|
|
+ if (!atomic || page == last_page) {
|
|
|
|
+ set_fsync_mark(page, 1);
|
|
|
|
+ if (IS_INODE(page))
|
|
|
|
+ set_dentry_mark(page,
|
|
need_dentry_mark(sbi, ino));
|
|
need_dentry_mark(sbi, ino));
|
|
|
|
+ /* may be written by other thread */
|
|
|
|
+ if (!PageDirty(page))
|
|
|
|
+ set_page_dirty(page);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!clear_page_dirty_for_io(page))
|
|
|
|
+ goto continue_unlock;
|
|
|
|
|
|
ret = NODE_MAPPING(sbi)->a_ops->writepage(page, wbc);
|
|
ret = NODE_MAPPING(sbi)->a_ops->writepage(page, wbc);
|
|
if (ret) {
|
|
if (ret) {
|
|
unlock_page(page);
|
|
unlock_page(page);
|
|
|
|
+ f2fs_put_page(last_page, 0);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if (page == last_page) {
|
|
|
|
+ f2fs_put_page(page, 0);
|
|
|
|
+ marked = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
pagevec_release(&pvec);
|
|
pagevec_release(&pvec);
|
|
cond_resched();
|
|
cond_resched();
|
|
|
|
|
|
- if (ret)
|
|
|
|
|
|
+ if (ret || marked)
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+ if (!ret && atomic && !marked) {
|
|
|
|
+ f2fs_msg(sbi->sb, KERN_DEBUG,
|
|
|
|
+ "Retry to write fsync mark: ino=%u, idx=%lx",
|
|
|
|
+ ino, last_page->index);
|
|
|
|
+ lock_page(last_page);
|
|
|
|
+ set_page_dirty(last_page);
|
|
|
|
+ unlock_page(last_page);
|
|
|
|
+ goto retry;
|
|
|
|
+ }
|
|
return ret ? -EIO: 0;
|
|
return ret ? -EIO: 0;
|
|
}
|
|
}
|
|
|
|
|