Skip to content

Commit d940aa0

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix to check i_compr_blocks correctly
inode.i_blocks counts based on 512byte sector, we need to convert to 4kb sized block count before comparing to i_compr_blocks. In addition, add to print message when sanity check on inode compression configs failed. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent df77fbd commit d940aa0

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

‎fs/f2fs/inode.c‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,30 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page)
291291
fi->i_flags & F2FS_COMPR_FL &&
292292
F2FS_FITS_IN_INODE(ri, fi->i_extra_isize,
293293
i_log_cluster_size)) {
294-
if (ri->i_compress_algorithm >= COMPRESS_MAX)
294+
if (ri->i_compress_algorithm >= COMPRESS_MAX) {
295+
f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported "
296+
"compress algorithm: %u, run fsck to fix",
297+
__func__, inode->i_ino,
298+
ri->i_compress_algorithm);
295299
return false;
296-
if (le64_to_cpu(ri->i_compr_blocks) > inode->i_blocks)
300+
}
301+
if (le64_to_cpu(ri->i_compr_blocks) >
302+
SECTOR_TO_BLOCK(inode->i_blocks)) {
303+
f2fs_warn(sbi, "%s: inode (ino=%lx) has inconsistent "
304+
"i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix",
305+
__func__, inode->i_ino,
306+
le64_to_cpu(ri->i_compr_blocks),
307+
SECTOR_TO_BLOCK(inode->i_blocks));
297308
return false;
309+
}
298310
if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE ||
299-
ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE)
311+
ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) {
312+
f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported "
313+
"log cluster size: %u, run fsck to fix",
314+
__func__, inode->i_ino,
315+
ri->i_log_cluster_size);
300316
return false;
317+
}
301318
}
302319

303320
return true;

0 commit comments

Comments
 (0)