f2fs: support revoking atomic written pages
Subsystems (2)
PATCH 2/2 f2fs: support revoking atomic written pages
f2fs support atomic write with following semantics:
1. open db file
2. ioctl start atomic write
3. (write db file) * n
4. ioctl commit atomic write
5. close db file
With this flow we can avoid file becoming corrupted when abnormal power cut, because we hold data of transaction in referenced pages linked in inmem_pages list of inode, but without setting them dirty, so these data won't be persisted unless we commit them in step 4.
But we should still hold journal db file in memory by using volatile write, because our semantics of 'atomic write support' is incomplete, in step 4, we could fail to submit all dirty data of transaction, once partial dirty data was committed in storage, then after a checkpoint & abnormal power-cut, db file will be corrupted forever.
So this patch tries to improve atomic write flow by adding a revoking flow, once inner error occurs in committing, this gives another chance to try to revoke these partial submitted data of current transaction, it makes committing operation more like aotmical one.
If we're not lucky, once revoking operation was failed, EAGAIN will be reported to user for suggesting doing the recovery with held journal file, or retrying current transaction again.
--- fs/f2fs/data.c | 1 + fs/f2fs/f2fs.h | 4 +- fs/f2fs/file.c | 2 +- fs/f2fs/recovery.c | 2 +- fs/f2fs/segment.c | 118 +++++++++++++++++++++++++++++++------------- fs/f2fs/segment.h | 1 + include/trace/events/f2fs.h | 1 + 7 files changed, 93 insertions(+), 36 deletions(-)
fs/f2fs/data.c +1 -0
@@ -1073,6 +1073,7 @@ int do_write_data_page(struct f2fs_io_info *fio)return err; fio->blk_addr = dn.data_blkaddr; + fio->old_blkaddr = dn.data_blkaddr;/* This page is already truncated */ if (fio->blk_addr ==NULL_ADDR ) {
fs/f2fs/f2fs.h +3 -1
@@ -686,6 +686,7 @@ enum page_type {META_FLUSH ,INMEM ,/* the below types are used by tracepoints only. */ INMEM_DROP , +INMEM_REVOKE ,IPU , OPU, };
@@ -695,6 +696,7 @@ struct f2fs_io_info {enum page_type type;/* contains DATA/NODE/META/META_FLUSH */ int rw;/* contains R/RS/W/WS with REQ_META/REQ_PRIO */ block_t blk_addr;/* block address to be written */ +block_t old_blkaddr;/* old block address before Cow */ struct page *page;/* page to be written */ struct page *encrypted_page;/* encrypted page */ };
@@ -1853,7 +1855,7 @@ 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 f2fs_replace_block (struct f2fs_sb_info *,struct dnode_of_data *, -block_t ,block_t ,unsigned char ,bool ); +block_t ,block_t ,unsigned char ,bool ,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 ,bool );
fs/f2fs/file.c +1 -1
@@ -883,7 +883,7 @@ static int __exchange_data_block(struct inode *inode, pgoff_t src,get_node_info (sbi, dn.nid, &ni);f2fs_replace_block (sbi, &dn, dn.data_blkaddr, new_addr, - ni.version, true); + ni.version, true, false);f2fs_put_dnode (&dn); }else {struct page *psrc, *pdst;
fs/f2fs/recovery.c +1 -1
@@ -465,7 +465,7 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,/* write dummy data page */ f2fs_replace_block (sbi, &dn, src, dest, - ni.version, false); + ni.version, false, false); recovered++; } }
fs/f2fs/segment.c +85 -33
194 lines not on this page · raw message
fs/f2fs/segment.h +1 -0
@@ -191,6 +191,7 @@ struct segment_allocation {struct inmem_pages {struct list_head list;struct page *page; +block_t old_addr;/* for revoking when fail to commit */ };struct sit_info {
include/trace/events/f2fs.h +1 -0
@@ -52,6 +52,7 @@ TRACE_DEFINE_ENUM(CP_DISCARD); { META_FLUSH, "META_FLUSH" }, \ { INMEM, "INMEM" }, \ { INMEM_DROP, "INMEM_DROP" }, \ + { INMEM_REVOKE, "INMEM_REVOKE" }, \ { IPU, "IN-PLACE" }, \ { OPU, "OUT-OF-PLACE" })
Signature · 1 line
2.7.0.2.g1b0b6dd