erofs: clean up zmap.c
Several trivial cleanups which aren't quite necessary to split: - Rename lcluster load functions as well as justify full indexes since they are typically used for global deduplication for compressed data; - Avoid unnecessary lines, comments for simplicity. No logic changes. Reviewed-by: Guo Xuenan <guoxuenan@huaweicloud.com> Reviewed-by: Yue Hu <huyue2@coolpad.com> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20230615064421.103178-1-hsiangkao@linux.alibaba.com
This commit is contained in:
parent
1990595547
commit
8241fdd3cd
|
@ -22,8 +22,8 @@ struct z_erofs_maprecorder {
|
||||||
bool partialref;
|
bool partialref;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m,
|
static int z_erofs_load_full_lcluster(struct z_erofs_maprecorder *m,
|
||||||
unsigned long lcn)
|
unsigned long lcn)
|
||||||
{
|
{
|
||||||
struct inode *const inode = m->inode;
|
struct inode *const inode = m->inode;
|
||||||
struct erofs_inode *const vi = EROFS_I(inode);
|
struct erofs_inode *const vi = EROFS_I(inode);
|
||||||
|
@ -226,8 +226,8 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m,
|
static int z_erofs_load_compact_lcluster(struct z_erofs_maprecorder *m,
|
||||||
unsigned long lcn, bool lookahead)
|
unsigned long lcn, bool lookahead)
|
||||||
{
|
{
|
||||||
struct inode *const inode = m->inode;
|
struct inode *const inode = m->inode;
|
||||||
struct erofs_inode *const vi = EROFS_I(inode);
|
struct erofs_inode *const vi = EROFS_I(inode);
|
||||||
|
@ -277,23 +277,23 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m,
|
||||||
return unpack_compacted_index(m, amortizedshift, pos, lookahead);
|
return unpack_compacted_index(m, amortizedshift, pos, lookahead);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int z_erofs_load_cluster_from_disk(struct z_erofs_maprecorder *m,
|
static int z_erofs_load_lcluster_from_disk(struct z_erofs_maprecorder *m,
|
||||||
unsigned int lcn, bool lookahead)
|
unsigned int lcn, bool lookahead)
|
||||||
{
|
{
|
||||||
const unsigned int datamode = EROFS_I(m->inode)->datalayout;
|
switch (EROFS_I(m->inode)->datalayout) {
|
||||||
|
case EROFS_INODE_COMPRESSED_FULL:
|
||||||
if (datamode == EROFS_INODE_COMPRESSED_FULL)
|
return z_erofs_load_full_lcluster(m, lcn);
|
||||||
return legacy_load_cluster_from_disk(m, lcn);
|
case EROFS_INODE_COMPRESSED_COMPACT:
|
||||||
|
return z_erofs_load_compact_lcluster(m, lcn, lookahead);
|
||||||
if (datamode == EROFS_INODE_COMPRESSED_COMPACT)
|
default:
|
||||||
return compacted_load_cluster_from_disk(m, lcn, lookahead);
|
return -EINVAL;
|
||||||
|
}
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,
|
static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,
|
||||||
unsigned int lookback_distance)
|
unsigned int lookback_distance)
|
||||||
{
|
{
|
||||||
|
struct super_block *sb = m->inode->i_sb;
|
||||||
struct erofs_inode *const vi = EROFS_I(m->inode);
|
struct erofs_inode *const vi = EROFS_I(m->inode);
|
||||||
const unsigned int lclusterbits = vi->z_logical_clusterbits;
|
const unsigned int lclusterbits = vi->z_logical_clusterbits;
|
||||||
|
|
||||||
|
@ -301,21 +301,15 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,
|
||||||
unsigned long lcn = m->lcn - lookback_distance;
|
unsigned long lcn = m->lcn - lookback_distance;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
/* load extent head logical cluster if needed */
|
err = z_erofs_load_lcluster_from_disk(m, lcn, false);
|
||||||
err = z_erofs_load_cluster_from_disk(m, lcn, false);
|
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
switch (m->type) {
|
switch (m->type) {
|
||||||
case Z_EROFS_LCLUSTER_TYPE_NONHEAD:
|
case Z_EROFS_LCLUSTER_TYPE_NONHEAD:
|
||||||
if (!m->delta[0]) {
|
|
||||||
erofs_err(m->inode->i_sb,
|
|
||||||
"invalid lookback distance 0 @ nid %llu",
|
|
||||||
vi->nid);
|
|
||||||
DBG_BUGON(1);
|
|
||||||
return -EFSCORRUPTED;
|
|
||||||
}
|
|
||||||
lookback_distance = m->delta[0];
|
lookback_distance = m->delta[0];
|
||||||
|
if (!lookback_distance)
|
||||||
|
goto err_bogus;
|
||||||
continue;
|
continue;
|
||||||
case Z_EROFS_LCLUSTER_TYPE_PLAIN:
|
case Z_EROFS_LCLUSTER_TYPE_PLAIN:
|
||||||
case Z_EROFS_LCLUSTER_TYPE_HEAD1:
|
case Z_EROFS_LCLUSTER_TYPE_HEAD1:
|
||||||
|
@ -324,16 +318,15 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,
|
||||||
m->map->m_la = (lcn << lclusterbits) | m->clusterofs;
|
m->map->m_la = (lcn << lclusterbits) | m->clusterofs;
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
erofs_err(m->inode->i_sb,
|
erofs_err(sb, "unknown type %u @ lcn %lu of nid %llu",
|
||||||
"unknown type %u @ lcn %lu of nid %llu",
|
|
||||||
m->type, lcn, vi->nid);
|
m->type, lcn, vi->nid);
|
||||||
DBG_BUGON(1);
|
DBG_BUGON(1);
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
err_bogus:
|
||||||
erofs_err(m->inode->i_sb, "bogus lookback distance @ nid %llu",
|
erofs_err(sb, "bogus lookback distance %u @ lcn %lu of nid %llu",
|
||||||
vi->nid);
|
lookback_distance, m->lcn, vi->nid);
|
||||||
DBG_BUGON(1);
|
DBG_BUGON(1);
|
||||||
return -EFSCORRUPTED;
|
return -EFSCORRUPTED;
|
||||||
}
|
}
|
||||||
|
@ -365,7 +358,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
|
||||||
if (m->compressedblks)
|
if (m->compressedblks)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
err = z_erofs_load_cluster_from_disk(m, lcn, false);
|
err = z_erofs_load_lcluster_from_disk(m, lcn, false);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -397,9 +390,8 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
|
||||||
break;
|
break;
|
||||||
fallthrough;
|
fallthrough;
|
||||||
default:
|
default:
|
||||||
erofs_err(m->inode->i_sb,
|
erofs_err(sb, "cannot found CBLKCNT @ lcn %lu of nid %llu", lcn,
|
||||||
"cannot found CBLKCNT @ lcn %lu of nid %llu",
|
vi->nid);
|
||||||
lcn, vi->nid);
|
|
||||||
DBG_BUGON(1);
|
DBG_BUGON(1);
|
||||||
return -EFSCORRUPTED;
|
return -EFSCORRUPTED;
|
||||||
}
|
}
|
||||||
|
@ -407,9 +399,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
|
||||||
map->m_plen = erofs_pos(sb, m->compressedblks);
|
map->m_plen = erofs_pos(sb, m->compressedblks);
|
||||||
return 0;
|
return 0;
|
||||||
err_bonus_cblkcnt:
|
err_bonus_cblkcnt:
|
||||||
erofs_err(m->inode->i_sb,
|
erofs_err(sb, "bogus CBLKCNT @ lcn %lu of nid %llu", lcn, vi->nid);
|
||||||
"bogus CBLKCNT @ lcn %lu of nid %llu",
|
|
||||||
lcn, vi->nid);
|
|
||||||
DBG_BUGON(1);
|
DBG_BUGON(1);
|
||||||
return -EFSCORRUPTED;
|
return -EFSCORRUPTED;
|
||||||
}
|
}
|
||||||
|
@ -430,7 +420,7 @@ static int z_erofs_get_extent_decompressedlen(struct z_erofs_maprecorder *m)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = z_erofs_load_cluster_from_disk(m, lcn, true);
|
err = z_erofs_load_lcluster_from_disk(m, lcn, true);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -477,7 +467,7 @@ static int z_erofs_do_map_blocks(struct inode *inode,
|
||||||
initial_lcn = ofs >> lclusterbits;
|
initial_lcn = ofs >> lclusterbits;
|
||||||
endoff = ofs & ((1 << lclusterbits) - 1);
|
endoff = ofs & ((1 << lclusterbits) - 1);
|
||||||
|
|
||||||
err = z_erofs_load_cluster_from_disk(&m, initial_lcn, false);
|
err = z_erofs_load_lcluster_from_disk(&m, initial_lcn, false);
|
||||||
if (err)
|
if (err)
|
||||||
goto unmap_out;
|
goto unmap_out;
|
||||||
|
|
||||||
|
@ -535,8 +525,7 @@ static int z_erofs_do_map_blocks(struct inode *inode,
|
||||||
if (flags & EROFS_GET_BLOCKS_FINDTAIL) {
|
if (flags & EROFS_GET_BLOCKS_FINDTAIL) {
|
||||||
vi->z_tailextent_headlcn = m.lcn;
|
vi->z_tailextent_headlcn = m.lcn;
|
||||||
/* for non-compact indexes, fragmentoff is 64 bits */
|
/* for non-compact indexes, fragmentoff is 64 bits */
|
||||||
if (fragment &&
|
if (fragment && vi->datalayout == EROFS_INODE_COMPRESSED_FULL)
|
||||||
vi->datalayout == EROFS_INODE_COMPRESSED_FULL)
|
|
||||||
vi->z_fragmentoff |= (u64)m.pblk << 32;
|
vi->z_fragmentoff |= (u64)m.pblk << 32;
|
||||||
}
|
}
|
||||||
if (ztailpacking && m.lcn == vi->z_tailextent_headlcn) {
|
if (ztailpacking && m.lcn == vi->z_tailextent_headlcn) {
|
||||||
|
|
Loading…
Reference in New Issue