Skip to content

Commit d255c33

Browse files
chaseyupundiramit
authored andcommitted
f2fs: introduce FI_ATOMIC_COMMIT
commit 5fe457430e554a2f5188f13c1a2e36ad845640c5 upstream. This patch introduces a new flag to indicate inode status of doing atomic write committing, so that, we can keep atomic write status for inode during atomic committing, then we can skip GCing pages of atomic write inode, that avoids random GCed datas being mixed with current transaction, so isolation of transaction can be kept. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent f6873a1 commit d255c33

5 files changed

Lines changed: 26 additions & 9 deletions

File tree

fs/f2fs/data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2017,7 +2017,7 @@ static int f2fs_set_data_page_dirty(struct page *page)
20172017
if (!PageUptodate(page))
20182018
SetPageUptodate(page);
20192019

2020-
if (f2fs_is_atomic_file(inode)) {
2020+
if (f2fs_is_atomic_file(inode) && !f2fs_is_commit_atomic_write(inode)) {
20212021
if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
20222022
register_inmem_page(inode, page);
20232023
return 1;

fs/f2fs/f2fs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,7 @@ enum {
17061706
FI_UPDATE_WRITE, /* inode has in-place-update data */
17071707
FI_NEED_IPU, /* used for ipu per file */
17081708
FI_ATOMIC_FILE, /* indicate atomic file */
1709+
FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */
17091710
FI_VOLATILE_FILE, /* indicate volatile file */
17101711
FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */
17111712
FI_DROP_CACHE, /* drop dirty page cache */
@@ -1895,6 +1896,11 @@ static inline bool f2fs_is_atomic_file(struct inode *inode)
18951896
return is_inode_flag_set(inode, FI_ATOMIC_FILE);
18961897
}
18971898

1899+
static inline bool f2fs_is_commit_atomic_write(struct inode *inode)
1900+
{
1901+
return is_inode_flag_set(inode, FI_ATOMIC_COMMIT);
1902+
}
1903+
18981904
static inline bool f2fs_is_volatile_file(struct inode *inode)
18991905
{
19001906
return is_inode_flag_set(inode, FI_VOLATILE_FILE);

fs/f2fs/file.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,14 +1573,15 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp)
15731573
goto err_out;
15741574

15751575
if (f2fs_is_atomic_file(inode)) {
1576-
clear_inode_flag(inode, FI_ATOMIC_FILE);
15771576
ret = commit_inmem_pages(inode);
1578-
if (ret) {
1579-
set_inode_flag(inode, FI_ATOMIC_FILE);
1577+
if (ret)
15801578
goto err_out;
1581-
}
1579+
15821580
ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 0, true);
1583-
stat_dec_atomic_write(inode);
1581+
if (!ret) {
1582+
clear_inode_flag(inode, FI_ATOMIC_FILE);
1583+
stat_dec_atomic_write(inode);
1584+
}
15841585
} else {
15851586
ret = f2fs_do_sync_file(filp, 0, LLONG_MAX, 0, true);
15861587
}

fs/f2fs/gc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,9 @@ static void move_encrypted_block(struct inode *inode, block_t bidx,
569569
if (!check_valid_map(F2FS_I_SB(inode), segno, off))
570570
goto out;
571571

572+
if (f2fs_is_atomic_file(inode))
573+
goto out;
574+
572575
set_new_dnode(&dn, inode, NULL, NULL, 0);
573576
err = get_dnode_of_data(&dn, bidx, LOOKUP_NODE);
574577
if (err)
@@ -661,6 +664,9 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
661664
if (!check_valid_map(F2FS_I_SB(inode), segno, off))
662665
goto out;
663666

667+
if (f2fs_is_atomic_file(inode))
668+
goto out;
669+
664670
if (gc_type == BG_GC) {
665671
if (PageWriteback(page))
666672
goto out;

fs/f2fs/segment.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ void drop_inmem_pages(struct inode *inode)
242242
{
243243
struct f2fs_inode_info *fi = F2FS_I(inode);
244244

245-
clear_inode_flag(inode, FI_ATOMIC_FILE);
246-
stat_dec_atomic_write(inode);
247-
248245
mutex_lock(&fi->inmem_lock);
249246
__revoke_inmem_pages(inode, &fi->inmem_pages, true, false);
250247
mutex_unlock(&fi->inmem_lock);
248+
249+
clear_inode_flag(inode, FI_ATOMIC_FILE);
250+
stat_dec_atomic_write(inode);
251251
}
252252

253253
static int __commit_inmem_pages(struct inode *inode,
@@ -316,6 +316,8 @@ int commit_inmem_pages(struct inode *inode)
316316
f2fs_balance_fs(sbi, true);
317317
f2fs_lock_op(sbi);
318318

319+
set_inode_flag(inode, FI_ATOMIC_COMMIT);
320+
319321
mutex_lock(&fi->inmem_lock);
320322
err = __commit_inmem_pages(inode, &revoke_list);
321323
if (err) {
@@ -337,6 +339,8 @@ int commit_inmem_pages(struct inode *inode)
337339
}
338340
mutex_unlock(&fi->inmem_lock);
339341

342+
clear_inode_flag(inode, FI_ATOMIC_COMMIT);
343+
340344
f2fs_unlock_op(sbi);
341345
return err;
342346
}

0 commit comments

Comments
 (0)