From nobody Sun Feb 8 05:20:56 2026 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 071AE15AF6 for ; Thu, 23 Jan 2025 09:01:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737622888; cv=none; b=rSw++wEpm19Tk1evSfs7/NHPm0G6m4qxBsL/B7VpsjyZPgOamv3X+eG6w0Rxsl/zQsb9E1rQ8Ysm2iLjkbo32SE1Yl+MmqObPwUoPCt4CjC80EtcBQDQeN56XgE0YQpUMfQ0eQF46fSqjstzhv29CEmfZX0CcugKRNtDV7Fk178= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737622888; c=relaxed/simple; bh=Ep+jHNKc+37LELK4ne984i/mrKF8IHN+u3ZQxb2poz0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=sqfL5lpejP3h5m7Fagk6tZMkhUs9mhpG6X1gFu/ax0E8SMGBRIENgextb7P3NBy9vXFUV6YMi5/G48sxZW8oeGf+VsSAo0RJWzxZiB+KpCrlUMXUIH7zxNH8ts07UmAmLBdlNzC6q+GT0wVrZbB+rES4znOx9COZBqK6tMsExtg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=jlRQxDQA; arc=none smtp.client-ip=115.124.30.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="jlRQxDQA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1737622875; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=PpA2IB08pHCZzk9POa/pWBkRxPW6FVtTAzux8QczCPc=; b=jlRQxDQAamNrA70/mhJKezqwFnrkZMZzb9TVmnBsosSMpD+LLiu2UJwAPBTnXNuvcrt4NFkv1e3aA2EAwiEUn6I3g10McwlRwozDUqWL0lD8bh6sMZWrO7B4/ZB3ytqi7z1BCk8utyjF9bT+lLzV9MFXji+O6xywk3rlMg9E3gM= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0WOBAKEy_1737622870 cluster:ay36) by smtp.aliyun-inc.com; Thu, 23 Jan 2025 17:01:15 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , Gao Xiang Subject: [PATCH] erofs: refine z_erofs_get_extent_compressedlen() Date: Thu, 23 Jan 2025 17:01:09 +0800 Message-ID: <20250123090109.973463-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" - Set `compressedblks =3D 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 =3D 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. Signed-off-by: Gao Xiang --- fs/erofs/zmap.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index b9e35089c9b8..689437e99a5a 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -294,27 +294,23 @@ static int z_erofs_extent_lookback(struct z_erofs_map= recorder *m, static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m, unsigned int initial_lcn) { - struct super_block *sb =3D m->inode->i_sb; - struct erofs_inode *const vi =3D EROFS_I(m->inode); - struct erofs_map_blocks *const map =3D m->map; - const unsigned int lclusterbits =3D vi->z_logical_clusterbits; - unsigned long lcn; + struct inode *inode =3D m->inode; + struct super_block *sb =3D inode->i_sb; + struct erofs_inode *vi =3D EROFS_I(inode); + bool bigpcl1 =3D vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1; + bool bigpcl2 =3D vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2; + unsigned long lcn =3D m->lcn + 1; int err; =20 - DBG_BUGON(m->type !=3D Z_EROFS_LCLUSTER_TYPE_PLAIN && - m->type !=3D Z_EROFS_LCLUSTER_TYPE_HEAD1 && - m->type !=3D Z_EROFS_LCLUSTER_TYPE_HEAD2); + DBG_BUGON(m->type =3D=3D Z_EROFS_LCLUSTER_TYPE_NONHEAD); DBG_BUGON(m->type !=3D m->headtype); =20 - if (m->headtype =3D=3D Z_EROFS_LCLUSTER_TYPE_PLAIN || - ((m->headtype =3D=3D Z_EROFS_LCLUSTER_TYPE_HEAD1) && - !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1)) || - ((m->headtype =3D=3D Z_EROFS_LCLUSTER_TYPE_HEAD2) && - !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2))) { - map->m_plen =3D 1ULL << lclusterbits; - return 0; - } - lcn =3D m->lcn + 1; + if ((m->headtype =3D=3D Z_EROFS_LCLUSTER_TYPE_HEAD1 && !bigpcl1) || + ((m->headtype =3D=3D Z_EROFS_LCLUSTER_TYPE_PLAIN || + m->headtype =3D=3D Z_EROFS_LCLUSTER_TYPE_HEAD2) && !bigpcl2) || + (lcn << vi->z_logical_clusterbits) >=3D inode->i_size) + m->compressedblks =3D 1; + if (m->compressedblks) goto out; =20 @@ -339,9 +335,9 @@ static int z_erofs_get_extent_compressedlen(struct z_er= ofs_maprecorder *m, case Z_EROFS_LCLUSTER_TYPE_HEAD2: /* * if the 1st NONHEAD lcluster is actually PLAIN or HEAD type - * rather than CBLKCNT, it's a 1 lcluster-sized pcluster. + * rather than CBLKCNT, it's a 1 block-sized pcluster. */ - m->compressedblks =3D 1 << (lclusterbits - sb->s_blocksize_bits); + m->compressedblks =3D 1; break; case Z_EROFS_LCLUSTER_TYPE_NONHEAD: if (m->delta[0] !=3D 1) @@ -356,7 +352,7 @@ static int z_erofs_get_extent_compressedlen(struct z_er= ofs_maprecorder *m, return -EFSCORRUPTED; } out: - map->m_plen =3D erofs_pos(sb, m->compressedblks); + m->map->m_plen =3D erofs_pos(sb, m->compressedblks); return 0; err_bonus_cblkcnt: erofs_err(sb, "bogus CBLKCNT @ lcn %lu of nid %llu", lcn, vi->nid); --=20 2.43.5