f2fs: prevent writing without fallocate() for pinned files
PATCH v2 1/1 f2fs: prevent writing without fallocate() for pinned files
From: Daeho Jeong <[email protected]>
In a case writing without fallocate(), we can't guarantee it's allocated in the conventional area for zoned stroage.
Signed-off-by Daeho Jeong <[email protected]>
---
v2: covered the direct io case
--- fs/f2fs/data.c | 14 ++++++++++++-- fs/f2fs/file.c | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-)
fs/f2fs/data.c +12 -2
@@ -1584,8 +1584,11 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)/* use out-place-update for direct IO under LFS mode */ if (map->m_may_create && - (is_hole || (f2fs_lfs_mode (sbi) && flag ==F2FS_GET_BLOCK_DIO ))) { -if (unlikely (f2fs_cp_error (sbi))) { + (is_hole || (f2fs_lfs_mode (sbi) && flag ==F2FS_GET_BLOCK_DIO && + !f2fs_is_pinned_file (inode)))) { +if (unlikely (f2fs_cp_error (sbi)) || + (f2fs_is_pinned_file (inode) && is_hole && + flag !=F2FS_GET_BLOCK_PRE_DIO )) { err = -EIO ; goto sync_out; }
@@ -3378,6 +3381,8 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,f2fs_map_lock (sbi, flag); locked = true; }else if ((pos &PAGE_MASK ) >=i_size_read (inode)) { +if (f2fs_is_pinned_file (inode)) +return -EIO ;f2fs_map_lock (sbi, flag); locked = true; }
@@ -3407,6 +3412,11 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,if (!f2fs_lookup_read_extent_cache_block (inode, index, &dn.data_blkaddr)) { +if (f2fs_is_pinned_file (inode)) { + err = -EIO ; + goto out; + } +if (locked) { err =f2fs_reserve_block (&dn, index); goto out;
fs/f2fs/file.c +4 -0
@@ -4611,6 +4611,10 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter,return ret; } +/* For pinned files, it should be fallocate()-ed in advance. */ +if (f2fs_is_pinned_file (inode)) +return 0 ; +/* Do not preallocate blocks that will be written partially in 4KB. */ map.m_lblk =F2FS_BLK_ALIGN (pos); map.m_len =F2FS_BYTES_TO_BLK (pos + count);
Signature · 1 line
2.44.0.278.ge034bb2e1d-goog
Chao Yu
maintainerQuoted 8 lines · Daeho Jeong
From: Daeho Jeong <[email protected]>
In a case writing without
fallocate(), we can't guarantee it's allocated in the conventional area for zoned stroage.Signed-off-by Daeho Jeong <[email protected]>---
v2: covered the direct io case
Oh, one more missed case, mkwrite?
Thanks,
Quoted 59 lines
--- fs/f2fs/data.c | 14 ++++++++++++-- fs/f2fs/file.c | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-)fs/f2fs/data.c +12
-2@@ -1584,8 +1584,11 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)/* use out-place-update for direct IO under LFS mode */ if (map->m_may_create && - (is_hole || (f2fs_lfs_mode (sbi) && flag ==F2FS_GET_BLOCK_DIO ))) { -if (unlikely (f2fs_cp_error (sbi))) { + (is_hole || (f2fs_lfs_mode (sbi) && flag ==F2FS_GET_BLOCK_DIO && + !f2fs_is_pinned_file (inode)))) { +if (unlikely (f2fs_cp_error (sbi)) || + (f2fs_is_pinned_file (inode) && is_hole && + flag !=F2FS_GET_BLOCK_PRE_DIO )) { err = -EIO ; goto sync_out; }@@ -3378,6 +3381,8 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,f2fs_map_lock (sbi, flag); locked = true; }else if ((pos &PAGE_MASK ) >=i_size_read (inode)) { +if (f2fs_is_pinned_file (inode)) +return -EIO ;f2fs_map_lock (sbi, flag); locked = true; }@@ -3407,6 +3412,11 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi,if (!f2fs_lookup_read_extent_cache_block (inode, index, &dn.data_blkaddr)) { +if (f2fs_is_pinned_file (inode)) { + err = -EIO ; + goto out; + } +if (locked) { err =f2fs_reserve_block (&dn, index); goto out;fs/f2fs/file.c +4
-0@@ -4611,6 +4611,10 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter,return ret; } +/* For pinned files, it should be fallocate()-ed in advance. */ +if (f2fs_is_pinned_file (inode)) +return 0 ; +/* Do not preallocate blocks that will be written partially in 4KB. */ map.m_lblk =F2FS_BLK_ALIGN (pos); map.m_len =F2FS_BYTES_TO_BLK (pos + count);