Now that the VFS tracks an inode whose Merkle tree is under construction via I_VERITY_BUILDING and handles the concurrent-enable guard in the generic fs-verity enable path, drop the inode runtime flags that duplicated this state. Replace f2fs own helper f2fs_verity_in_progress() with fsverity_is_building(), and remove the and FI_VERITY_IN_PROGRESS flags. It's fine to remove IS_ENABLED() guard as fsverity_is_building() has stub. Signed-off-by: Andrey Albershteyn --- fs/f2fs/data.c | 10 +++++----- fs/f2fs/f2fs.h | 7 ------- fs/f2fs/verity.c | 12 +++--------- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 7c5aa95b7da8..c75e61af21f7 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3356,7 +3356,7 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted, goto redirty_out; if (folio->index < end_index || - f2fs_verity_in_progress(inode) || + fsverity_is_building(inode) || compr_blocks) goto write; @@ -3889,7 +3889,7 @@ void f2fs_write_failed(struct inode *inode, loff_t to) return; /* In the fs-verity case, f2fs_end_enable_verity() does the truncate */ - if (to > i_size && !f2fs_verity_in_progress(inode)) { + if (to > i_size && !fsverity_is_building(inode)) { f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); filemap_invalidate_lock(inode->i_mapping); @@ -4205,7 +4205,7 @@ static int f2fs_write_begin(const struct kiocb *iocb, return 0; if (!(pos & (PAGE_SIZE - 1)) && (pos + len) >= i_size_read(inode) && - !f2fs_verity_in_progress(inode)) { + !fsverity_is_building(inode)) { folio_zero_segment(folio, len, folio_size(folio)); return 0; } @@ -4279,7 +4279,7 @@ static int f2fs_write_end(const struct kiocb *iocb, f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); if (pos + copied > i_size_read(inode) && - !f2fs_verity_in_progress(inode)) + !fsverity_is_building(inode)) f2fs_i_size_write(inode, pos + copied); return copied; } @@ -4294,7 +4294,7 @@ static int f2fs_write_end(const struct kiocb *iocb, folio_set_f2fs_atomic(folio); if (pos + copied > i_size_read(inode) && - !f2fs_verity_in_progress(inode)) { + !fsverity_is_building(inode)) { f2fs_i_size_write(inode, pos + copied); if (f2fs_is_atomic_file(inode)) f2fs_i_size_write(F2FS_I(inode)->cow_inode, diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 6941891d7cae..c0fca6229170 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -926,7 +926,6 @@ enum { FI_EXTRA_ATTR, /* indicate file has extra attribute */ FI_PROJ_INHERIT, /* indicate file inherits projectid */ FI_PIN_FILE, /* indicate file should not be gced */ - FI_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ FI_COMPRESSED_FILE, /* indicate file's data can be compressed */ FI_COMPRESS_CORRUPT, /* indicate compressed cluster is corrupted */ FI_MMAP_FILE, /* indicate file was mmapped */ @@ -3536,12 +3535,6 @@ static inline void clear_inode_flag(struct inode *inode, int flag) __mark_inode_dirty_flag(inode, flag, false); } -static inline bool f2fs_verity_in_progress(struct inode *inode) -{ - return IS_ENABLED(CONFIG_FS_VERITY) && - is_inode_flag_set(inode, FI_VERITY_IN_PROGRESS); -} - static inline void set_acl_inode(struct inode *inode, umode_t mode) { F2FS_I(inode)->i_acl_mode = mode; diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c index 4a2cea4288f9..f31a71295e47 100644 --- a/fs/f2fs/verity.c +++ b/fs/f2fs/verity.c @@ -94,9 +94,6 @@ static int f2fs_begin_enable_verity(struct file *filp) struct inode *inode = file_inode(filp); int err; - if (f2fs_verity_in_progress(inode)) - return -EBUSY; - if (f2fs_is_atomic_file(inode)) return -EOPNOTSUPP; @@ -113,7 +110,6 @@ static int f2fs_begin_enable_verity(struct file *filp) if (err) return err; - set_inode_flag(inode, FI_VERITY_IN_PROGRESS); return 0; } @@ -143,8 +139,8 @@ static int f2fs_end_enable_verity(struct file *filp, const void *desc, goto cleanup; /* - * Write all pages (both data and verity metadata). Note that this must - * happen before clearing FI_VERITY_IN_PROGRESS; otherwise pages beyond + * Write all pages (both data and verity metadata). Note that this must + * happen before I_VERITY_BUILDING is cleared; otherwise pages beyond * i_size won't be written properly. For crash consistency, this also * must happen before the verity inode flag gets persisted. */ @@ -164,14 +160,13 @@ static int f2fs_end_enable_verity(struct file *filp, const void *desc, f2fs_set_inode_flags(inode); f2fs_mark_inode_dirty_sync(inode, true); - clear_inode_flag(inode, FI_VERITY_IN_PROGRESS); return 0; cleanup: /* * Verity failed to be enabled, so clean up by truncating any verity * metadata that was written beyond i_size (both from cache and from - * disk) and clearing FI_VERITY_IN_PROGRESS. + * disk). * * Taking i_gc_rwsem[WRITE] is needed to stop f2fs garbage collection * from re-instantiating cached pages we are truncating (since unlike @@ -186,7 +181,6 @@ static int f2fs_end_enable_verity(struct file *filp, const void *desc, set_sbi_flag(sbi, SBI_NEED_FSCK); } f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); - clear_inode_flag(inode, FI_VERITY_IN_PROGRESS); return err ?: err2; } -- 2.54.0