Skip to content

Commit 8f9530a

Browse files
committed
erofs: refine z_erofs_get_extent_compressedlen()
- Set `compressedblks = 1` directly for non-bigpcluster cases. This simplifies the logic a bit since lcluster sizes larger than one block are unsupported and the details remain unclear. - For Z_EROFS_LCLUSTER_TYPE_PLAIN pclusters, avoid assuming `compressedblks = 1` by default. Instead, check if Z_EROFS_ADVISE_BIG_PCLUSTER_2 is set. It basically has no impact to existing valid images, but it's useful to find the gap to prepare for large PLAIN pclusters. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gao Xiang <[email protected]>
1 parent 6e2c234 commit 8f9530a

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

fs/erofs/zmap.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -294,27 +294,23 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,
294294
static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
295295
unsigned int initial_lcn)
296296
{
297-
struct super_block *sb = m->inode->i_sb;
298-
struct erofs_inode *const vi = EROFS_I(m->inode);
299-
struct erofs_map_blocks *const map = m->map;
300-
const unsigned int lclusterbits = vi->z_logical_clusterbits;
301-
unsigned long lcn;
297+
struct inode *inode = m->inode;
298+
struct super_block *sb = inode->i_sb;
299+
struct erofs_inode *vi = EROFS_I(inode);
300+
bool bigpcl1 = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1;
301+
bool bigpcl2 = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2;
302+
unsigned long lcn = m->lcn + 1;
302303
int err;
303304

304-
DBG_BUGON(m->type != Z_EROFS_LCLUSTER_TYPE_PLAIN &&
305-
m->type != Z_EROFS_LCLUSTER_TYPE_HEAD1 &&
306-
m->type != Z_EROFS_LCLUSTER_TYPE_HEAD2);
305+
DBG_BUGON(m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD);
307306
DBG_BUGON(m->type != m->headtype);
308307

309-
if (m->headtype == Z_EROFS_LCLUSTER_TYPE_PLAIN ||
310-
((m->headtype == Z_EROFS_LCLUSTER_TYPE_HEAD1) &&
311-
!(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1)) ||
312-
((m->headtype == Z_EROFS_LCLUSTER_TYPE_HEAD2) &&
313-
!(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2))) {
314-
map->m_plen = 1ULL << lclusterbits;
315-
return 0;
316-
}
317-
lcn = m->lcn + 1;
308+
if ((m->headtype == Z_EROFS_LCLUSTER_TYPE_HEAD1 && !bigpcl1) ||
309+
((m->headtype == Z_EROFS_LCLUSTER_TYPE_PLAIN ||
310+
m->headtype == Z_EROFS_LCLUSTER_TYPE_HEAD2) && !bigpcl2) ||
311+
(lcn << vi->z_logical_clusterbits) >= inode->i_size)
312+
m->compressedblks = 1;
313+
318314
if (m->compressedblks)
319315
goto out;
320316

@@ -339,9 +335,9 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
339335
case Z_EROFS_LCLUSTER_TYPE_HEAD2:
340336
/*
341337
* if the 1st NONHEAD lcluster is actually PLAIN or HEAD type
342-
* rather than CBLKCNT, it's a 1 lcluster-sized pcluster.
338+
* rather than CBLKCNT, it's a 1 block-sized pcluster.
343339
*/
344-
m->compressedblks = 1 << (lclusterbits - sb->s_blocksize_bits);
340+
m->compressedblks = 1;
345341
break;
346342
case Z_EROFS_LCLUSTER_TYPE_NONHEAD:
347343
if (m->delta[0] != 1)
@@ -356,7 +352,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
356352
return -EFSCORRUPTED;
357353
}
358354
out:
359-
map->m_plen = erofs_pos(sb, m->compressedblks);
355+
m->map->m_plen = erofs_pos(sb, m->compressedblks);
360356
return 0;
361357
err_bonus_cblkcnt:
362358
erofs_err(sb, "bogus CBLKCNT @ lcn %lu of nid %llu", lcn, vi->nid);

0 commit comments

Comments
 (0)