Commit 4afe6b8d authored by Al Viro's avatar Al Viro Committed by Gao Xiang

erofs: don't round offset down for erofs_read_metabuf()

There's only one place where struct z_erofs_maprecorder ->kaddr is
used not in the same function that has assigned it -
the value read in unpack_compacted_index() gets calculated in
z_erofs_load_compact_lcluster().  With minor massage we can switch
to storing it with offset in block already added.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Link: https://lore.kernel.org/r/20240425195944.GE1031757@ZenIVSigned-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
parent 076d965e
...@@ -34,13 +34,13 @@ static int z_erofs_load_full_lcluster(struct z_erofs_maprecorder *m, ...@@ -34,13 +34,13 @@ static int z_erofs_load_full_lcluster(struct z_erofs_maprecorder *m,
unsigned int advise; unsigned int advise;
m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb, m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb,
erofs_pos(inode->i_sb, erofs_blknr(inode->i_sb, pos)), EROFS_KMAP); pos, EROFS_KMAP);
if (IS_ERR(m->kaddr)) if (IS_ERR(m->kaddr))
return PTR_ERR(m->kaddr); return PTR_ERR(m->kaddr);
m->nextpackoff = pos + sizeof(struct z_erofs_lcluster_index); m->nextpackoff = pos + sizeof(struct z_erofs_lcluster_index);
m->lcn = lcn; m->lcn = lcn;
di = m->kaddr + erofs_blkoff(inode->i_sb, pos); di = m->kaddr;
advise = le16_to_cpu(di->di_advise); advise = le16_to_cpu(di->di_advise);
m->type = advise & Z_EROFS_LI_LCLUSTER_TYPE_MASK; m->type = advise & Z_EROFS_LI_LCLUSTER_TYPE_MASK;
...@@ -109,7 +109,7 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m, ...@@ -109,7 +109,7 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
{ {
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;
unsigned int vcnt, base, lo, lobits, encodebits, nblk, eofs; unsigned int vcnt, lo, lobits, encodebits, nblk, bytes;
int i; int i;
u8 *in, type; u8 *in, type;
bool big_pcluster; bool big_pcluster;
...@@ -127,11 +127,11 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m, ...@@ -127,11 +127,11 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
big_pcluster = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1; big_pcluster = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1;
lobits = max(lclusterbits, ilog2(Z_EROFS_LI_D0_CBLKCNT) + 1U); lobits = max(lclusterbits, ilog2(Z_EROFS_LI_D0_CBLKCNT) + 1U);
encodebits = ((vcnt << amortizedshift) - sizeof(__le32)) * 8 / vcnt; encodebits = ((vcnt << amortizedshift) - sizeof(__le32)) * 8 / vcnt;
eofs = erofs_blkoff(m->inode->i_sb, pos); bytes = pos & ((vcnt << amortizedshift) - 1);
base = round_down(eofs, vcnt << amortizedshift);
in = m->kaddr + base;
i = (eofs - base) >> amortizedshift; in = m->kaddr - bytes;
i = bytes >> amortizedshift;
lo = decode_compactedbits(lobits, in, encodebits * i, &type); lo = decode_compactedbits(lobits, in, encodebits * i, &type);
m->type = type; m->type = type;
...@@ -256,7 +256,7 @@ static int z_erofs_load_compact_lcluster(struct z_erofs_maprecorder *m, ...@@ -256,7 +256,7 @@ static int z_erofs_load_compact_lcluster(struct z_erofs_maprecorder *m,
out: out:
pos += lcn * (1 << amortizedshift); pos += lcn * (1 << amortizedshift);
m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb, m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb,
erofs_pos(inode->i_sb, erofs_blknr(inode->i_sb, pos)), EROFS_KMAP); pos, EROFS_KMAP);
if (IS_ERR(m->kaddr)) if (IS_ERR(m->kaddr))
return PTR_ERR(m->kaddr); return PTR_ERR(m->kaddr);
return unpack_compacted_index(m, amortizedshift, pos, lookahead); return unpack_compacted_index(m, amortizedshift, pos, lookahead);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment