f2fs: fix to check return value of f2fs_reserve_new_block()
authorChao Yu <chao@kernel.org>
Thu, 16 Nov 2023 06:25:56 +0000 (14:25 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 5 Feb 2024 20:14:25 +0000 (20:14 +0000)
[ Upstream commit 956fa1ddc132e028f3b7d4cf17e6bfc8cb36c7fd ]

Let's check return value of f2fs_reserve_new_block() in do_recover_data()
rather than letting it fails silently.

Also refactoring check condition on return value of f2fs_reserve_new_block()
as below:
- trigger f2fs_bug_on() only for ENOSPC case;
- use do-while statement to avoid redundant codes;

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/f2fs/recovery.c

index 7be60df..f0de36e 100644 (file)
@@ -712,7 +712,16 @@ retry_dn:
                 */
                if (dest == NEW_ADDR) {
                        f2fs_truncate_data_blocks_range(&dn, 1);
-                       f2fs_reserve_new_block(&dn);
+                       do {
+                               err = f2fs_reserve_new_block(&dn);
+                               if (err == -ENOSPC) {
+                                       f2fs_bug_on(sbi, 1);
+                                       break;
+                               }
+                       } while (err &&
+                               IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION));
+                       if (err)
+                               goto err;
                        continue;
                }
 
@@ -720,12 +729,14 @@ retry_dn:
                if (f2fs_is_valid_blkaddr(sbi, dest, META_POR)) {
 
                        if (src == NULL_ADDR) {
-                               err = f2fs_reserve_new_block(&dn);
-                               while (err &&
-                                      IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION))
+                               do {
                                        err = f2fs_reserve_new_block(&dn);
-                               /* We should not get -ENOSPC */
-                               f2fs_bug_on(sbi, err);
+                                       if (err == -ENOSPC) {
+                                               f2fs_bug_on(sbi, 1);
+                                               break;
+                                       }
+                               } while (err &&
+                                       IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION));
                                if (err)
                                        goto err;
                        }