Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0f87f20d authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim
Browse files

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: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 3e27aebf
Loading
Loading
Loading
Loading
+20 −3
Original line number Original line Diff line number Diff line
@@ -291,14 +291,31 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page)
			fi->i_flags & F2FS_COMPR_FL &&
			fi->i_flags & F2FS_COMPR_FL &&
			F2FS_FITS_IN_INODE(ri, fi->i_extra_isize,
			F2FS_FITS_IN_INODE(ri, fi->i_extra_isize,
						i_log_cluster_size)) {
						i_log_cluster_size)) {
		if (ri->i_compress_algorithm >= COMPRESS_MAX)
		if (ri->i_compress_algorithm >= COMPRESS_MAX) {
			f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported "
				"compress algorithm: %u, run fsck to fix",
				  __func__, inode->i_ino,
				  ri->i_compress_algorithm);
			return false;
			return false;
		if (le64_to_cpu(ri->i_compr_blocks) > inode->i_blocks)
		}
		if (le64_to_cpu(ri->i_compr_blocks) >
				SECTOR_TO_BLOCK(inode->i_blocks)) {
			f2fs_warn(sbi, "%s: inode (ino=%lx) has inconsistent "
				"i_compr_blocks:%llu, i_blocks:%lu, run fsck to fix",
				  __func__, inode->i_ino,
				  le64_to_cpu(ri->i_compr_blocks),
				  SECTOR_TO_BLOCK(inode->i_blocks));
			return false;
			return false;
		}
		if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE ||
		if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE ||
			ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE)
			ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) {
			f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported "
				"log cluster size: %u, run fsck to fix",
				  __func__, inode->i_ino,
				  ri->i_log_cluster_size);
			return false;
			return false;
		}
		}
	}


	return true;
	return true;
}
}