Skip to content

Commit 3fdd89b

Browse files
Daeho JeongJaegeuk Kim
authored andcommitted
f2fs: prevent writing without fallocate() for pinned files
In a case writing without fallocate(), we can't guarantee it's allocated in the conventional area for zoned stroage. To make it consistent across storage devices, we disallow it regardless of storage device types. Signed-off-by: Daeho Jeong <daehojeong@google.com> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 16778ae commit 3fdd89b

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

fs/f2fs/file.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
5858
struct inode *inode = file_inode(vmf->vma->vm_file);
5959
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
6060
struct dnode_of_data dn;
61-
bool need_alloc = true;
61+
bool need_alloc = !f2fs_is_pinned_file(inode);
6262
int err = 0;
6363
vm_fault_t ret;
6464

@@ -115,19 +115,18 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
115115
goto out_sem;
116116
}
117117

118+
set_new_dnode(&dn, inode, NULL, NULL, 0);
118119
if (need_alloc) {
119120
/* block allocation */
120-
set_new_dnode(&dn, inode, NULL, NULL, 0);
121121
err = f2fs_get_block_locked(&dn, page->index);
122-
}
123-
124-
#ifdef CONFIG_F2FS_FS_COMPRESSION
125-
if (!need_alloc) {
126-
set_new_dnode(&dn, inode, NULL, NULL, 0);
122+
} else {
127123
err = f2fs_get_dnode_of_data(&dn, page->index, LOOKUP_NODE);
128124
f2fs_put_dnode(&dn);
125+
if (f2fs_is_pinned_file(inode) &&
126+
!__is_valid_data_blkaddr(dn.data_blkaddr))
127+
err = -EIO;
129128
}
130-
#endif
129+
131130
if (err) {
132131
unlock_page(page);
133132
goto out_sem;
@@ -3260,7 +3259,7 @@ static int f2fs_ioc_set_pin_file(struct file *filp, unsigned long arg)
32603259
goto done;
32613260
}
32623261

3263-
if (f2fs_sb_has_blkzoned(sbi) && F2FS_HAS_BLOCKS(inode)) {
3262+
if (F2FS_HAS_BLOCKS(inode)) {
32643263
ret = -EFBIG;
32653264
goto out;
32663265
}
@@ -4823,6 +4822,8 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
48234822
bool dio;
48244823
bool may_need_sync = true;
48254824
int preallocated;
4825+
const loff_t pos = iocb->ki_pos;
4826+
const ssize_t count = iov_iter_count(from);
48264827
ssize_t ret;
48274828

48284829
if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) {
@@ -4844,6 +4845,12 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
48444845
inode_lock(inode);
48454846
}
48464847

4848+
if (f2fs_is_pinned_file(inode) &&
4849+
!f2fs_overwrite_io(inode, pos, count)) {
4850+
ret = -EIO;
4851+
goto out_unlock;
4852+
}
4853+
48474854
ret = f2fs_write_checks(iocb, from);
48484855
if (ret <= 0)
48494856
goto out_unlock;

0 commit comments

Comments
 (0)