Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753499AbbEFFIy (ORCPT ); Wed, 6 May 2015 01:08:54 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:9358 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752781AbbEFFIx (ORCPT ); Wed, 6 May 2015 01:08:53 -0400 X-AuditID: cbfee61b-f79536d000000f1f-c5-5549a1e39927 From: Chao Yu To: Jaegeuk Kim , Changman Lee Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/3] f2fs: introduce f2fs_replace_block() for reuse Date: Wed, 06 May 2015 13:08:06 +0800 Message-id: <004701d087ba$bdfbb180$39f31480$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdCHun9p/Rw9UDlCQj2mmrkwXwpSig== Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrILMWRmVeSWpSXmKPExsVy+t9jQd3HCz1DDZ4c0ba4tq+RyeLJ+lnM FpcWuVtc3jWHzYHFY9OqTjaP3Qs+M3n0bVnF6PF5k1wASxSXTUpqTmZZapG+XQJXxsHlugVv 5Sp6Z6g3MC6V7GLk5JAQMJF4fuARE4QtJnHh3nq2LkYuDiGB6YwSG5Y1skA4rxgldj85xA5S xSagIrG84z9Yh4iAl8Sk/SdYQGxmAQ+Jxo7vrCC2sICbxOmZ+xhBbBYBVYnfkx+C2bwClhJH b29kh7AFJX5MvgfVqyWxfudxJghbXmLzmrfMEBcpSOw4+5oRYpeexLGLF6BqxCU2HrnFMoFR YBaSUbOQjJqFZNQsJC0LGFlWMYqmFiQXFCel5xrpFSfmFpfmpesl5+duYgQH9DPpHYyrGiwO MQpwMCrx8N6I9gwVYk0sK67MPcQowcGsJMI7xR0oxJuSWFmVWpQfX1Sak1p8iFGag0VJnHeO rlyokEB6YklqdmpqQWoRTJaJg1OqgZGbz256U1SBdcU5qUiHxhkS3sE8VX0uxrwnjEzEGyct zbT/5Fuc+NXsl0OjufMVxdhXJqXSBtx1q5MSC7+/iZz342rYNoEcJevoBd9kKo/ukVrdZDX5 g9ilrjNGPEuWid9gPOG0LT29bcsdix/6Z3h9Z2/iOCFtcOq+N8OjCwFBAm7fGLJVlFiKMxIN tZiLihMBlbjxomQCAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4077 Lines: 122 Introduce a generic function replace_block base on recover_data_page, and export it. So with it we can operate file's meta data which is in CP/SSA area when we invoke fallocate with FALLOC_FL_COLLAPSE_RANGE flag. Signed-off-by: Chao Yu --- v3: * rename replace_block() to f2fs_replace_block() for readability. * fix incorrect usage of @recover_curseg in f2fs_replace_block(). * recover old next blkaddr of current segment for fcollapse. fs/f2fs/f2fs.h | 4 ++-- fs/f2fs/recovery.c | 2 +- fs/f2fs/segment.c | 31 ++++++++++++++++++++++++------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 5fff184..160945f 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1638,8 +1638,8 @@ void write_meta_page(struct f2fs_sb_info *, struct page *); void write_node_page(unsigned int, struct f2fs_io_info *); void write_data_page(struct dnode_of_data *, struct f2fs_io_info *); void rewrite_data_page(struct f2fs_io_info *); -void recover_data_page(struct f2fs_sb_info *, struct page *, - struct f2fs_summary *, block_t, block_t); +void f2fs_replace_block(struct f2fs_sb_info *, struct f2fs_summary *, + block_t, block_t, bool); void allocate_data_block(struct f2fs_sb_info *, struct page *, block_t, block_t *, struct f2fs_summary *, int); void f2fs_wait_on_page_writeback(struct page *, enum page_type); diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index b80d9d4..f77a1be 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -412,7 +412,7 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, set_summary(&sum, dn.nid, dn.ofs_in_node, ni.version); /* write dummy data page */ - recover_data_page(sbi, NULL, &sum, src, dest); + f2fs_replace_block(sbi, &sum, src, dest, false); dn.data_blkaddr = dest; set_data_blkaddr(&dn); f2fs_update_extent_cache(&dn); diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 667bbf2..bdf487a 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1279,32 +1279,41 @@ void rewrite_data_page(struct f2fs_io_info *fio) f2fs_submit_page_mbio(fio); } -void recover_data_page(struct f2fs_sb_info *sbi, - struct page *page, struct f2fs_summary *sum, - block_t old_blkaddr, block_t new_blkaddr) +void f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, + block_t old_blkaddr, block_t new_blkaddr, + bool recover_curseg) { struct sit_info *sit_i = SIT_I(sbi); struct curseg_info *curseg; unsigned int segno, old_cursegno; struct seg_entry *se; int type; + unsigned short old_blkoff; segno = GET_SEGNO(sbi, new_blkaddr); se = get_seg_entry(sbi, segno); type = se->type; - if (se->valid_blocks == 0 && !IS_CURSEG(sbi, segno)) { - if (old_blkaddr == NULL_ADDR) - type = CURSEG_COLD_DATA; - else + if (!recover_curseg) { + /* for recovery flow */ + if (se->valid_blocks == 0 && !IS_CURSEG(sbi, segno)) { + if (old_blkaddr == NULL_ADDR) + type = CURSEG_COLD_DATA; + else + type = CURSEG_WARM_DATA; + } + } else { + if (!IS_CURSEG(sbi, segno)) type = CURSEG_WARM_DATA; } + curseg = CURSEG_I(sbi, type); mutex_lock(&curseg->curseg_mutex); mutex_lock(&sit_i->sentry_lock); old_cursegno = curseg->segno; + old_blkoff = curseg->next_blkoff; /* change the current segment */ if (segno != curseg->segno) { @@ -1318,6 +1327,14 @@ void recover_data_page(struct f2fs_sb_info *sbi, refresh_sit_entry(sbi, old_blkaddr, new_blkaddr); locate_dirty_segment(sbi, old_cursegno); + if (recover_curseg) { + if (old_cursegno != curseg->segno) { + curseg->next_segno = old_cursegno; + change_curseg(sbi, type, true); + } + curseg->next_blkoff = old_blkoff; + } + mutex_unlock(&sit_i->sentry_lock); mutex_unlock(&curseg->curseg_mutex); } -- 2.3.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/