Skip to content

Commit

Permalink
f2fs: use cow inode data when updating atomic write
Browse files Browse the repository at this point in the history
Need to use cow inode data content instead of the one in the original
inode, when we try to write the already updated atomic write files.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
  • Loading branch information
Daeho Jeong authored and Jaegeuk Kim committed Apr 24, 2023
1 parent 2e2c6e9 commit 591fc34
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions fs/f2fs/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -3491,7 +3491,7 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index,

static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,
struct page *page, loff_t pos, unsigned int len,
block_t *blk_addr, bool *node_changed)
block_t *blk_addr, bool *node_changed, bool *use_cow)
{
struct inode *inode = page->mapping->host;
struct inode *cow_inode = F2FS_I(inode)->cow_inode;
Expand All @@ -3505,10 +3505,12 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi,

/* Look for the block in COW inode first */
err = __find_data_block(cow_inode, index, blk_addr);
if (err)
if (err) {
return err;
else if (*blk_addr != NULL_ADDR)
} else if (*blk_addr != NULL_ADDR) {
*use_cow = true;
return 0;
}

if (is_inode_flag_set(inode, FI_ATOMIC_REPLACE))
goto reserve_block;
Expand Down Expand Up @@ -3538,6 +3540,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
struct page *page = NULL;
pgoff_t index = ((unsigned long long) pos) >> PAGE_SHIFT;
bool need_balance = false;
bool use_cow = false;
block_t blkaddr = NULL_ADDR;
int err = 0;

Expand Down Expand Up @@ -3597,7 +3600,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,

if (f2fs_is_atomic_file(inode))
err = prepare_atomic_write_begin(sbi, page, pos, len,
&blkaddr, &need_balance);
&blkaddr, &need_balance, &use_cow);
else
err = prepare_write_begin(sbi, page, pos, len,
&blkaddr, &need_balance);
Expand Down Expand Up @@ -3637,7 +3640,9 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
goto fail;
}
err = f2fs_submit_page_read(inode, page, blkaddr, 0, true);
err = f2fs_submit_page_read(use_cow ?
F2FS_I(inode)->cow_inode : inode, page,
blkaddr, 0, true);
if (err)
goto fail;

Expand Down

0 comments on commit 591fc34

Please sign in to comment.