Skip to content

Commit dfd02e4

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix to preallocate block only aligned to 4K
In write_begin(), we skip checking dnode block for preallocating block when whole block needs to be updated since we preallocated its block in f2fs_preallocate_blocks, for partial updated block, we will still try to lock its node and do preallocation in write_begin(), so in f2fs_preallocate_blocks we should not preallocate its block. But previously, the calculation of preallocating block number is incorrect, fix it. Signed-off-by: Chao Yu <[email protected]> [Jaegeuk Kim: fix a bug] Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 6a7a3ae commit dfd02e4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

fs/f2fs/data.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,12 @@ ssize_t f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
626626
ssize_t ret = 0;
627627

628628
map.m_lblk = F2FS_BLK_ALIGN(iocb->ki_pos);
629-
map.m_len = F2FS_BYTES_TO_BLK(iov_iter_count(from));
629+
map.m_len = F2FS_BYTES_TO_BLK(iocb->ki_pos + iov_iter_count(from));
630+
if (map.m_len > map.m_lblk)
631+
map.m_len -= map.m_lblk;
632+
else
633+
map.m_len = 0;
634+
630635
map.m_next_pgofs = NULL;
631636

632637
if (f2fs_encrypted_inode(inode))
@@ -672,6 +677,9 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
672677
bool allocated = false;
673678
block_t blkaddr;
674679

680+
if (!maxblocks)
681+
return 0;
682+
675683
map->m_len = 0;
676684
map->m_flags = 0;
677685

0 commit comments

Comments
 (0)