public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/8] erofs: simplify z_erofs_read_fragment()
@ 2023-08-17  8:28 Gao Xiang
  2023-08-17  8:28 ` [PATCH 2/8] erofs: avoid obsolete {collector,collection} terms Gao Xiang
                   ` (8 more replies)
  0 siblings, 9 replies; 26+ messages in thread
From: Gao Xiang @ 2023-08-17  8:28 UTC (permalink / raw)
  To: linux-erofs; +Cc: LKML, Gao Xiang

A trivial cleanup to make the fragment handling logic more clear.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/zdata.c | 39 +++++++++++++--------------------------
 1 file changed, 13 insertions(+), 26 deletions(-)

diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index 53820271e538..dc104add0a99 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -932,34 +932,27 @@ static bool z_erofs_collector_end(struct z_erofs_decompress_frontend *fe)
 	return true;
 }
 
-static int z_erofs_read_fragment(struct inode *inode, erofs_off_t pos,
-				 struct page *page, unsigned int pageofs,
-				 unsigned int len)
+static int z_erofs_read_fragment(struct super_block *sb, struct page *page,
+			unsigned int cur, unsigned int end, erofs_off_t pos)
 {
-	struct super_block *sb = inode->i_sb;
-	struct inode *packed_inode = EROFS_I_SB(inode)->packed_inode;
+	struct inode *packed_inode = EROFS_SB(sb)->packed_inode;
 	struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
-	u8 *src, *dst;
-	unsigned int i, cnt;
+	unsigned int cnt;
+	u8 *src;
 
 	if (!packed_inode)
 		return -EFSCORRUPTED;
 
 	buf.inode = packed_inode;
-	pos += EROFS_I(inode)->z_fragmentoff;
-	for (i = 0; i < len; i += cnt) {
-		cnt = min_t(unsigned int, len - i,
+	for (; cur < end; cur += cnt, pos += cnt) {
+		cnt = min_t(unsigned int, end - cur,
 			    sb->s_blocksize - erofs_blkoff(sb, pos));
 		src = erofs_bread(&buf, erofs_blknr(sb, pos), EROFS_KMAP);
 		if (IS_ERR(src)) {
 			erofs_put_metabuf(&buf);
 			return PTR_ERR(src);
 		}
-
-		dst = kmap_local_page(page);
-		memcpy(dst + pageofs + i, src + erofs_blkoff(sb, pos), cnt);
-		kunmap_local(dst);
-		pos += cnt;
+		memcpy_to_page(page, cur, src + erofs_blkoff(sb, pos), cnt);
 	}
 	erofs_put_metabuf(&buf);
 	return 0;
@@ -972,7 +965,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
 	struct erofs_map_blocks *const map = &fe->map;
 	const loff_t offset = page_offset(page);
 	bool tight = true, exclusive;
-	unsigned int cur, end, spiltted;
+	unsigned int cur, end, len, spiltted;
 	int err = 0;
 
 	/* register locked file pages as online pages in pack */
@@ -1041,17 +1034,11 @@ static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe,
 		goto next_part;
 	}
 	if (map->m_flags & EROFS_MAP_FRAGMENT) {
-		unsigned int pageofs, skip, len;
+		erofs_off_t fpos = offset + cur - map->m_la;
 
-		if (offset > map->m_la) {
-			pageofs = 0;
-			skip = offset - map->m_la;
-		} else {
-			pageofs = map->m_la & ~PAGE_MASK;
-			skip = 0;
-		}
-		len = min_t(unsigned int, map->m_llen - skip, end - cur);
-		err = z_erofs_read_fragment(inode, skip, page, pageofs, len);
+		len = min_t(unsigned int, map->m_llen - fpos, end - cur);
+		err = z_erofs_read_fragment(inode->i_sb, page, cur, cur + len,
+				EROFS_I(inode)->z_fragmentoff + fpos);
 		if (err)
 			goto out;
 		++spiltted;
-- 
2.24.4


^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2023-08-23 15:24 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-17  8:28 [PATCH 1/8] erofs: simplify z_erofs_read_fragment() Gao Xiang
2023-08-17  8:28 ` [PATCH 2/8] erofs: avoid obsolete {collector,collection} terms Gao Xiang
2023-08-18  2:25   ` Yue Hu
2023-08-23 14:58   ` Chao Yu
2023-08-17  8:28 ` [PATCH 3/8] erofs: move preparation logic into z_erofs_pcluster_begin() Gao Xiang
2023-08-18  2:42   ` Yue Hu
2023-08-23 15:05   ` Chao Yu
2023-08-23 15:22     ` Gao Xiang
2023-08-17  8:28 ` [PATCH 4/8] erofs: tidy up z_erofs_do_read_page() Gao Xiang
2023-08-18  3:12   ` Yue Hu
2023-08-23 15:09   ` Chao Yu
2023-08-17  8:28 ` [PATCH 5/8] erofs: drop z_erofs_page_mark_eio() Gao Xiang
2023-08-18  3:20   ` Yue Hu
2023-08-23 15:19   ` Chao Yu
2023-08-17  8:28 ` [PATCH 6/8] erofs: get rid of fe->backmost for cache decompression Gao Xiang
2023-08-18  5:51   ` Yue Hu
2023-08-18  7:48     ` Gao Xiang
2023-08-18  8:02       ` Yue Hu
2023-08-23 15:19   ` Chao Yu
2023-08-17  8:28 ` [PATCH 7/8] erofs: adapt folios for z_erofs_readahead() Gao Xiang
2023-08-23 15:22   ` Chao Yu
2023-08-17  8:28 ` [PATCH 8/8] erofs: adapt folios for z_erofs_read_folio() Gao Xiang
2023-08-17  8:39   ` [PATCH v2 " Gao Xiang
2023-08-23 15:23   ` [PATCH " Chao Yu
2023-08-18  2:18 ` [PATCH 1/8] erofs: simplify z_erofs_read_fragment() Yue Hu
2023-08-23 14:56 ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox