* [f2fs-dev] [PATCH V2 1/2] f2fs: compress: relocate some judgments in f2fs_reserve_compress_blocks
@ 2024-03-06 3:47 Xiuhong Wang
2024-03-06 3:47 ` [f2fs-dev] [PATCH V2 2/2] f2fs: compress: fix reserve_cblocks counting error when out of space Xiuhong Wang
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Xiuhong Wang @ 2024-03-06 3:47 UTC (permalink / raw)
To: jaegeuk, chao, linux-f2fs-devel, linux-kernel
Cc: ke.wang, xiuhong.wang.cn, hongyu.jin.cn
The following f2fs_io test will get a "0" result instead of -EINVAL,
unisoc # ./f2fs_io compress file
unisoc # ./f2fs_io reserve_cblocks file
0
it's not reasonable, so the judgement of
atomic_read(&F2FS_I(inode)->i_compr_blocks) should be placed after
the judgement of is_inode_flag_set(inode, FI_COMPRESS_RELEASED).
Fixes: c75488fb4d82 ("f2fs: introduce F2FS_IOC_RESERVE_COMPRESS_BLOCKS")
Signed-off-by: Xiuhong Wang <xiuhong.wang@unisoc.com>
Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
---
fs/f2fs/file.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 4ca6c693b33a..74c5e48fce22 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3720,9 +3720,6 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
if (ret)
return ret;
- if (atomic_read(&F2FS_I(inode)->i_compr_blocks))
- goto out;
-
f2fs_balance_fs(sbi, true);
inode_lock(inode);
@@ -3732,6 +3729,9 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
goto unlock_inode;
}
+ if (atomic_read(&F2FS_I(inode)->i_compr_blocks))
+ goto unlock_inode;
+
f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
filemap_invalidate_lock(inode->i_mapping);
@@ -3778,7 +3778,6 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
}
unlock_inode:
inode_unlock(inode);
-out:
mnt_drop_write_file(filp);
if (ret >= 0) {
--
2.25.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 5+ messages in thread* [f2fs-dev] [PATCH V2 2/2] f2fs: compress: fix reserve_cblocks counting error when out of space 2024-03-06 3:47 [f2fs-dev] [PATCH V2 1/2] f2fs: compress: relocate some judgments in f2fs_reserve_compress_blocks Xiuhong Wang @ 2024-03-06 3:47 ` Xiuhong Wang 2024-03-06 6:01 ` Chao Yu 2024-03-06 6:01 ` [f2fs-dev] [PATCH V2 1/2] f2fs: compress: relocate some judgments in f2fs_reserve_compress_blocks Chao Yu 2024-03-13 1:30 ` patchwork-bot+f2fs 2 siblings, 1 reply; 5+ messages in thread From: Xiuhong Wang @ 2024-03-06 3:47 UTC (permalink / raw) To: jaegeuk, chao, linux-f2fs-devel, linux-kernel Cc: ke.wang, xiuhong.wang.cn, hongyu.jin.cn When a file only needs one direct_node, performing the following operations will cause the file to be unrepairable: unisoc # ./f2fs_io compress test.apk unisoc #df -h | grep dm-48 /dev/block/dm-48 112G 112G 1.2M 100% /data unisoc # ./f2fs_io release_cblocks test.apk 924 unisoc # df -h | grep dm-48 /dev/block/dm-48 112G 112G 4.8M 100% /data unisoc # dd if=/dev/random of=file4 bs=1M count=3 3145728 bytes (3.0 M) copied, 0.025 s, 120 M/s unisoc # df -h | grep dm-48 /dev/block/dm-48 112G 112G 1.8M 100% /data unisoc # ./f2fs_io reserve_cblocks test.apk F2FS_IOC_RESERVE_COMPRESS_BLOCKS failed: No space left on device adb reboot unisoc # df -h | grep dm-48 /dev/block/dm-48 112G 112G 11M 100% /data unisoc # ./f2fs_io reserve_cblocks test.apk 0 This is because the file has only one direct_node. After returning to -ENOSPC, reserved_blocks += ret will not be executed. As a result, the reserved_blocks at this time is still 0, which is not the real number of reserved blocks. Therefore, fsck cannot be set to repair the file. After this patch, the fsck flag will be set to fix this problem. unisoc # df -h | grep dm-48 /dev/block/dm-48 112G 112G 1.8M 100% /data unisoc # ./f2fs_io reserve_cblocks test.apk F2FS_IOC_RESERVE_COMPRESS_BLOCKS failed: No space left on device adb reboot then fsck will be executed unisoc # df -h | grep dm-48 /dev/block/dm-48 112G 112G 11M 100% /data unisoc # ./f2fs_io reserve_cblocks test.apk 924 Fixes: c75488fb4d82 ("f2fs: introduce F2FS_IOC_RESERVE_COMPRESS_BLOCKS") Signed-off-by: Xiuhong Wang <xiuhong.wang@unisoc.com> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com> --- fs/f2fs/file.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 74c5e48fce22..dc9c6bac678d 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3624,10 +3624,10 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) return ret; } -static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) +static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count, + unsigned int *reserved_blocks) { struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); - unsigned int reserved_blocks = 0; int cluster_size = F2FS_I(dn->inode)->i_cluster_size; block_t blkaddr; int i; @@ -3691,12 +3691,12 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) f2fs_i_compr_blocks_update(dn->inode, compr_blocks, true); - reserved_blocks += reserved; + *reserved_blocks += reserved; next: count -= cluster_size; } - return reserved_blocks; + return 0; } static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) @@ -3757,7 +3757,7 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) count = min(end_offset - dn.ofs_in_node, last_idx - page_idx); count = round_up(count, F2FS_I(inode)->i_cluster_size); - ret = reserve_compress_blocks(&dn, count); + ret = reserve_compress_blocks(&dn, count, &reserved_blocks); f2fs_put_dnode(&dn); @@ -3765,13 +3765,12 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) break; page_idx += count; - reserved_blocks += ret; } filemap_invalidate_unlock(inode->i_mapping); f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); - if (ret >= 0) { + if (!ret) { clear_inode_flag(inode, FI_COMPRESS_RELEASED); inode_set_ctime_current(inode); f2fs_mark_inode_dirty_sync(inode, true); @@ -3780,7 +3779,7 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) inode_unlock(inode); mnt_drop_write_file(filp); - if (ret >= 0) { + if (!ret) { ret = put_user(reserved_blocks, (u64 __user *)arg); } else if (reserved_blocks && atomic_read(&F2FS_I(inode)->i_compr_blocks)) { -- 2.25.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH V2 2/2] f2fs: compress: fix reserve_cblocks counting error when out of space 2024-03-06 3:47 ` [f2fs-dev] [PATCH V2 2/2] f2fs: compress: fix reserve_cblocks counting error when out of space Xiuhong Wang @ 2024-03-06 6:01 ` Chao Yu 0 siblings, 0 replies; 5+ messages in thread From: Chao Yu @ 2024-03-06 6:01 UTC (permalink / raw) To: Xiuhong Wang, jaegeuk, linux-f2fs-devel, linux-kernel Cc: ke.wang, xiuhong.wang.cn, hongyu.jin.cn On 2024/3/6 11:47, Xiuhong Wang wrote: > When a file only needs one direct_node, performing the following > operations will cause the file to be unrepairable: > > unisoc # ./f2fs_io compress test.apk > unisoc #df -h | grep dm-48 > /dev/block/dm-48 112G 112G 1.2M 100% /data > > unisoc # ./f2fs_io release_cblocks test.apk > 924 > unisoc # df -h | grep dm-48 > /dev/block/dm-48 112G 112G 4.8M 100% /data > > unisoc # dd if=/dev/random of=file4 bs=1M count=3 > 3145728 bytes (3.0 M) copied, 0.025 s, 120 M/s > unisoc # df -h | grep dm-48 > /dev/block/dm-48 112G 112G 1.8M 100% /data > > unisoc # ./f2fs_io reserve_cblocks test.apk > F2FS_IOC_RESERVE_COMPRESS_BLOCKS failed: No space left on device > > adb reboot > unisoc # df -h | grep dm-48 > /dev/block/dm-48 112G 112G 11M 100% /data > unisoc # ./f2fs_io reserve_cblocks test.apk > 0 > > This is because the file has only one direct_node. After returning > to -ENOSPC, reserved_blocks += ret will not be executed. As a result, > the reserved_blocks at this time is still 0, which is not the real > number of reserved blocks. Therefore, fsck cannot be set to repair > the file. > > After this patch, the fsck flag will be set to fix this problem. > > unisoc # df -h | grep dm-48 > /dev/block/dm-48 112G 112G 1.8M 100% /data > unisoc # ./f2fs_io reserve_cblocks test.apk > F2FS_IOC_RESERVE_COMPRESS_BLOCKS failed: No space left on device > > adb reboot then fsck will be executed > unisoc # df -h | grep dm-48 > /dev/block/dm-48 112G 112G 11M 100% /data > unisoc # ./f2fs_io reserve_cblocks test.apk > 924 > > Fixes: c75488fb4d82 ("f2fs: introduce F2FS_IOC_RESERVE_COMPRESS_BLOCKS") > Signed-off-by: Xiuhong Wang <xiuhong.wang@unisoc.com> > Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com> Reviewed-by: Chao Yu <chao@kernel.org> Thanks, _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH V2 1/2] f2fs: compress: relocate some judgments in f2fs_reserve_compress_blocks 2024-03-06 3:47 [f2fs-dev] [PATCH V2 1/2] f2fs: compress: relocate some judgments in f2fs_reserve_compress_blocks Xiuhong Wang 2024-03-06 3:47 ` [f2fs-dev] [PATCH V2 2/2] f2fs: compress: fix reserve_cblocks counting error when out of space Xiuhong Wang @ 2024-03-06 6:01 ` Chao Yu 2024-03-13 1:30 ` patchwork-bot+f2fs 2 siblings, 0 replies; 5+ messages in thread From: Chao Yu @ 2024-03-06 6:01 UTC (permalink / raw) To: Xiuhong Wang, jaegeuk, linux-f2fs-devel, linux-kernel Cc: ke.wang, xiuhong.wang.cn, hongyu.jin.cn On 2024/3/6 11:47, Xiuhong Wang wrote: > The following f2fs_io test will get a "0" result instead of -EINVAL, > unisoc # ./f2fs_io compress file > unisoc # ./f2fs_io reserve_cblocks file > 0 > it's not reasonable, so the judgement of > atomic_read(&F2FS_I(inode)->i_compr_blocks) should be placed after > the judgement of is_inode_flag_set(inode, FI_COMPRESS_RELEASED). > > Fixes: c75488fb4d82 ("f2fs: introduce F2FS_IOC_RESERVE_COMPRESS_BLOCKS") > Signed-off-by: Xiuhong Wang <xiuhong.wang@unisoc.com> > Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com> Reviewed-by: Chao Yu <chao@kernel.org> Thanks, _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [f2fs-dev] [PATCH V2 1/2] f2fs: compress: relocate some judgments in f2fs_reserve_compress_blocks 2024-03-06 3:47 [f2fs-dev] [PATCH V2 1/2] f2fs: compress: relocate some judgments in f2fs_reserve_compress_blocks Xiuhong Wang 2024-03-06 3:47 ` [f2fs-dev] [PATCH V2 2/2] f2fs: compress: fix reserve_cblocks counting error when out of space Xiuhong Wang 2024-03-06 6:01 ` [f2fs-dev] [PATCH V2 1/2] f2fs: compress: relocate some judgments in f2fs_reserve_compress_blocks Chao Yu @ 2024-03-13 1:30 ` patchwork-bot+f2fs 2 siblings, 0 replies; 5+ messages in thread From: patchwork-bot+f2fs @ 2024-03-13 1:30 UTC (permalink / raw) To: Xiuhong Wang Cc: hongyu.jin.cn, ke.wang, linux-kernel, linux-f2fs-devel, xiuhong.wang.cn, jaegeuk Hello: This series was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <jaegeuk@kernel.org>: On Wed, 6 Mar 2024 11:47:45 +0800 you wrote: > The following f2fs_io test will get a "0" result instead of -EINVAL, > unisoc # ./f2fs_io compress file > unisoc # ./f2fs_io reserve_cblocks file > 0 > it's not reasonable, so the judgement of > atomic_read(&F2FS_I(inode)->i_compr_blocks) should be placed after > the judgement of is_inode_flag_set(inode, FI_COMPRESS_RELEASED). > > [...] Here is the summary with links: - [f2fs-dev,V2,1/2] f2fs: compress: relocate some judgments in f2fs_reserve_compress_blocks https://git.kernel.org/jaegeuk/f2fs/c/b7d797d241c1 - [f2fs-dev,V2,2/2] f2fs: compress: fix reserve_cblocks counting error when out of space https://git.kernel.org/jaegeuk/f2fs/c/2f6d721e14b6 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-03-13 1:30 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-03-06 3:47 [f2fs-dev] [PATCH V2 1/2] f2fs: compress: relocate some judgments in f2fs_reserve_compress_blocks Xiuhong Wang 2024-03-06 3:47 ` [f2fs-dev] [PATCH V2 2/2] f2fs: compress: fix reserve_cblocks counting error when out of space Xiuhong Wang 2024-03-06 6:01 ` Chao Yu 2024-03-06 6:01 ` [f2fs-dev] [PATCH V2 1/2] f2fs: compress: relocate some judgments in f2fs_reserve_compress_blocks Chao Yu 2024-03-13 1:30 ` patchwork-bot+f2fs
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox