linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: change fiemap way in printing compression chunk
@ 2021-07-21  7:20 Daeho Jeong
  2021-07-21 21:35 ` [f2fs-dev] " Eric Biggers
  2021-07-22  6:24 ` Christoph Hellwig
  0 siblings, 2 replies; 11+ messages in thread
From: Daeho Jeong @ 2021-07-21  7:20 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel, kernel-team; +Cc: Daeho Jeong

From: Daeho Jeong <daehojeong@google.com>

When we print out a discontinuous compression chunk, it shows like a
continuous chunk now. To show it more correctly, I've changed the way of
printing fiemap info like below. Plus, eliminated NEW_ADDR(-1) in fiemap
info, since it is not in fiemap user api manual.

0: 0000000000000000 0000000000000000 0000000000001000 1008 (M/E)
1: 0000000000001000 0000000f15c0f000 0000000000001000 1008 (M/E)
2: 0000000000002000 0000000000000000 0000000000002000 1808 (M/U/E)
3: 0000000000004000 0000000000000000 0000000000001000 1008 (M/E)
4: 0000000000005000 0000000f15c10000 0000000000001000 1008 (M/E)
5: 0000000000006000 0000000000000000 0000000000002000 1808 (M/U/E)
6: 0000000000008000 0000000000000000 0000000000001000 1008 (M/E)
M => FIEMAP_EXTENT_MERGED
E => FIEMAP_EXTENT_ENCODED
U => FIEMAP_EXTENT_UNWRITTEN

Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
 fs/f2fs/data.c | 42 ++++++++++++++++--------------------------
 1 file changed, 16 insertions(+), 26 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 3a01a1b50104..6e1be876d96b 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1845,6 +1845,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 	int ret = 0;
 	bool compr_cluster = false;
 	unsigned int cluster_size = F2FS_I(inode)->i_cluster_size;
+	unsigned int count_in_cluster;
 	loff_t maxbytes;
 
 	if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) {
@@ -1893,7 +1894,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 	map.m_seg_type = NO_CHECK_TYPE;
 
 	if (compr_cluster)
-		map.m_len = cluster_size - 1;
+		map.m_len = cluster_size - count_in_cluster;
 
 	ret = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_FIEMAP);
 	if (ret)
@@ -1926,37 +1927,26 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 	if (start_blk > last_blk)
 		goto out;
 
-	if (compr_cluster) {
-		compr_cluster = false;
-
-
-		logical = blks_to_bytes(inode, start_blk - 1);
-		phys = blks_to_bytes(inode, map.m_pblk);
-		size = blks_to_bytes(inode, cluster_size);
-
-		flags |= FIEMAP_EXTENT_ENCODED;
-
-		start_blk += cluster_size - 1;
-
-		if (start_blk > last_blk)
-			goto out;
-
-		goto prep_next;
-	}
-
-	if (map.m_pblk == COMPRESS_ADDR) {
-		compr_cluster = true;
-		start_blk++;
-		goto prep_next;
-	}
-
 	logical = blks_to_bytes(inode, start_blk);
-	phys = blks_to_bytes(inode, map.m_pblk);
+	phys = __is_valid_data_blkaddr(map.m_pblk) ?
+		blks_to_bytes(inode, map.m_pblk) : 0;
 	size = blks_to_bytes(inode, map.m_len);
 	flags = 0;
 	if (map.m_flags & F2FS_MAP_UNWRITTEN)
 		flags = FIEMAP_EXTENT_UNWRITTEN;
 
+	if (map.m_pblk == COMPRESS_ADDR) {
+		flags |= FIEMAP_EXTENT_ENCODED;
+		compr_cluster = true;
+		count_in_cluster = 1;
+	} else if (compr_cluster) {
+		flags |= FIEMAP_EXTENT_ENCODED;
+		if (map.m_len > 0)
+			count_in_cluster += map.m_len;
+		if (count_in_cluster == cluster_size)
+			compr_cluster = false;
+	}
+
 	start_blk += bytes_to_blks(inode, size);
 
 prep_next:
-- 
2.32.0.402.g57bb445576-goog


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

end of thread, other threads:[~2021-07-22  6:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-21  7:20 [PATCH] f2fs: change fiemap way in printing compression chunk Daeho Jeong
2021-07-21 21:35 ` [f2fs-dev] " Eric Biggers
2021-07-21 22:30   ` Daeho Jeong
2021-07-22  0:15     ` Eric Biggers
2021-07-22  1:04       ` Daeho Jeong
2021-07-22  1:15         ` Eric Biggers
2021-07-22  1:40           ` Daeho Jeong
2021-07-22  1:56             ` Eric Biggers
2021-07-22  3:59               ` Daeho Jeong
2021-07-22  6:24 ` Christoph Hellwig
2021-07-22  6:39   ` Daeho Jeong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).