Skip to content

Commit 8c8f7c4

Browse files
chaseyugregkh
authored andcommitted
f2fs: fix to update last i_size if fallocate partially succeeds
[ Upstream commit 88f2cfc ] In the case of expanding pinned file, map.m_lblk and map.m_len will update in each round of section allocation, so in error path, last i_size will be calculated with wrong m_lblk and m_len, fix it. Fixes: f5a53ed ("f2fs: support aligned pinned file") Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 74d2b0e commit 8c8f7c4

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

‎fs/f2fs/file.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,9 +1616,10 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
16161616
struct f2fs_map_blocks map = { .m_next_pgofs = NULL,
16171617
.m_next_extent = NULL, .m_seg_type = NO_CHECK_TYPE,
16181618
.m_may_create = true };
1619-
pgoff_t pg_end;
1619+
pgoff_t pg_start, pg_end;
16201620
loff_t new_size = i_size_read(inode);
16211621
loff_t off_end;
1622+
block_t expanded = 0;
16221623
int err;
16231624

16241625
err = inode_newsize_ok(inode, (len + offset));
@@ -1631,11 +1632,12 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
16311632

16321633
f2fs_balance_fs(sbi, true);
16331634

1635+
pg_start = ((unsigned long long)offset) >> PAGE_SHIFT;
16341636
pg_end = ((unsigned long long)offset + len) >> PAGE_SHIFT;
16351637
off_end = (offset + len) & (PAGE_SIZE - 1);
16361638

1637-
map.m_lblk = ((unsigned long long)offset) >> PAGE_SHIFT;
1638-
map.m_len = pg_end - map.m_lblk;
1639+
map.m_lblk = pg_start;
1640+
map.m_len = pg_end - pg_start;
16391641
if (off_end)
16401642
map.m_len++;
16411643

@@ -1645,18 +1647,15 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
16451647
if (f2fs_is_pinned_file(inode)) {
16461648
block_t sec_blks = BLKS_PER_SEC(sbi);
16471649
block_t sec_len = roundup(map.m_len, sec_blks);
1648-
block_t done = 0;
16491650

16501651
map.m_len = sec_blks;
16511652
next_alloc:
16521653
if (has_not_enough_free_secs(sbi, 0,
16531654
GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))) {
16541655
down_write(&sbi->gc_lock);
16551656
err = f2fs_gc(sbi, true, false, false, NULL_SEGNO);
1656-
if (err && err != -ENODATA && err != -EAGAIN) {
1657-
map.m_len = done;
1657+
if (err && err != -ENODATA && err != -EAGAIN)
16581658
goto out_err;
1659-
}
16601659
}
16611660

16621661
down_write(&sbi->pin_sem);
@@ -1670,24 +1669,25 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
16701669

16711670
up_write(&sbi->pin_sem);
16721671

1673-
done += map.m_len;
1672+
expanded += map.m_len;
16741673
sec_len -= map.m_len;
16751674
map.m_lblk += map.m_len;
16761675
if (!err && sec_len)
16771676
goto next_alloc;
16781677

1679-
map.m_len = done;
1678+
map.m_len = expanded;
16801679
} else {
16811680
err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
1681+
expanded = map.m_len;
16821682
}
16831683
out_err:
16841684
if (err) {
16851685
pgoff_t last_off;
16861686

1687-
if (!map.m_len)
1687+
if (!expanded)
16881688
return err;
16891689

1690-
last_off = map.m_lblk + map.m_len - 1;
1690+
last_off = pg_start + expanded - 1;
16911691

16921692
/* update new size to the failed position */
16931693
new_size = (last_off == pg_end) ? offset + len :

0 commit comments

Comments
 (0)