Skip to content

Commit 2aaea53

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: compress: do sanity check on cluster when CONFIG_F2FS_CHECK_FS is on
This patch covers sanity check logic on cluster w/ CONFIG_F2FS_CHECK_FS, otherwise, there will be performance regression while querying cluster mapping info. Callers of f2fs_is_compressed_cluster() only care about whether cluster is compressed or not, rather than # of valid blocks in compressed cluster, so, let's adjust f2fs_is_compressed_cluster()'s logic according to caller's requirement. Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent b0327c8 commit 2aaea53

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

fs/f2fs/compress.c

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -893,14 +893,15 @@ static bool cluster_has_invalid_data(struct compress_ctx *cc)
893893

894894
bool f2fs_sanity_check_cluster(struct dnode_of_data *dn)
895895
{
896+
#ifdef CONFIG_F2FS_CHECK_FS
896897
struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
897898
unsigned int cluster_size = F2FS_I(dn->inode)->i_cluster_size;
898-
bool compressed = dn->data_blkaddr == COMPRESS_ADDR;
899899
int cluster_end = 0;
900+
unsigned int count;
900901
int i;
901902
char *reason = "";
902903

903-
if (!compressed)
904+
if (dn->data_blkaddr != COMPRESS_ADDR)
904905
return false;
905906

906907
/* [..., COMPR_ADDR, ...] */
@@ -909,7 +910,7 @@ bool f2fs_sanity_check_cluster(struct dnode_of_data *dn)
909910
goto out;
910911
}
911912

912-
for (i = 1; i < cluster_size; i++) {
913+
for (i = 1, count = 1; i < cluster_size; i++, count++) {
913914
block_t blkaddr = data_blkaddr(dn->inode, dn->node_page,
914915
dn->ofs_in_node + i);
915916

@@ -929,19 +930,42 @@ bool f2fs_sanity_check_cluster(struct dnode_of_data *dn)
929930
goto out;
930931
}
931932
}
933+
934+
f2fs_bug_on(F2FS_I_SB(dn->inode), count != cluster_size &&
935+
!is_inode_flag_set(dn->inode, FI_COMPRESS_RELEASED));
936+
932937
return false;
933938
out:
934939
f2fs_warn(sbi, "access invalid cluster, ino:%lu, nid:%u, ofs_in_node:%u, reason:%s",
935940
dn->inode->i_ino, dn->nid, dn->ofs_in_node, reason);
936941
set_sbi_flag(sbi, SBI_NEED_FSCK);
937942
return true;
943+
#else
944+
return false;
945+
#endif
946+
}
947+
948+
static int __f2fs_get_cluster_blocks(struct inode *inode,
949+
struct dnode_of_data *dn)
950+
{
951+
unsigned int cluster_size = F2FS_I(inode)->i_cluster_size;
952+
int count, i;
953+
954+
for (i = 1, count = 1; i < cluster_size; i++) {
955+
block_t blkaddr = data_blkaddr(dn->inode, dn->node_page,
956+
dn->ofs_in_node + i);
957+
958+
if (__is_valid_data_blkaddr(blkaddr))
959+
count++;
960+
}
961+
962+
return count;
938963
}
939964

940965
static int __f2fs_cluster_blocks(struct inode *inode,
941-
unsigned int cluster_idx, bool compr)
966+
unsigned int cluster_idx, bool compr_blks)
942967
{
943968
struct dnode_of_data dn;
944-
unsigned int cluster_size = F2FS_I(inode)->i_cluster_size;
945969
unsigned int start_idx = cluster_idx <<
946970
F2FS_I(inode)->i_log_cluster_size;
947971
int ret;
@@ -956,31 +980,14 @@ static int __f2fs_cluster_blocks(struct inode *inode,
956980

957981
if (f2fs_sanity_check_cluster(&dn)) {
958982
ret = -EFSCORRUPTED;
959-
f2fs_handle_error(F2FS_I_SB(inode), ERROR_CORRUPTED_CLUSTER);
960983
goto fail;
961984
}
962985

963986
if (dn.data_blkaddr == COMPRESS_ADDR) {
964-
int i;
965-
966-
ret = 1;
967-
for (i = 1; i < cluster_size; i++) {
968-
block_t blkaddr;
969-
970-
blkaddr = data_blkaddr(dn.inode,
971-
dn.node_page, dn.ofs_in_node + i);
972-
if (compr) {
973-
if (__is_valid_data_blkaddr(blkaddr))
974-
ret++;
975-
} else {
976-
if (blkaddr != NULL_ADDR)
977-
ret++;
978-
}
979-
}
980-
981-
f2fs_bug_on(F2FS_I_SB(inode),
982-
!compr && ret != cluster_size &&
983-
!is_inode_flag_set(inode, FI_COMPRESS_RELEASED));
987+
if (compr_blks)
988+
ret = __f2fs_get_cluster_blocks(inode, &dn);
989+
else
990+
ret = 1;
984991
}
985992
fail:
986993
f2fs_put_dnode(&dn);
@@ -993,7 +1000,7 @@ static int f2fs_compressed_blocks(struct compress_ctx *cc)
9931000
return __f2fs_cluster_blocks(cc->inode, cc->cluster_idx, true);
9941001
}
9951002

996-
/* return # of valid blocks in compressed cluster */
1003+
/* return whether cluster is compressed one or not */
9971004
int f2fs_is_compressed_cluster(struct inode *inode, pgoff_t index)
9981005
{
9991006
return __f2fs_cluster_blocks(inode,

fs/f2fs/data.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,9 +1690,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
16901690
map->m_flags |= F2FS_MAP_NEW;
16911691
} else if (is_hole) {
16921692
if (f2fs_compressed_file(inode) &&
1693-
f2fs_sanity_check_cluster(&dn) &&
1694-
(flag != F2FS_GET_BLOCK_FIEMAP ||
1695-
IS_ENABLED(CONFIG_F2FS_CHECK_FS))) {
1693+
f2fs_sanity_check_cluster(&dn)) {
16961694
err = -EFSCORRUPTED;
16971695
f2fs_handle_error(sbi,
16981696
ERROR_CORRUPTED_CLUSTER);

0 commit comments

Comments
 (0)