linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] f2fs: change fiemap way in printing compression chunk
@ 2021-07-26  4:18 Daeho Jeong
  2021-07-27 10:19 ` [f2fs-dev] " Chao Yu
  0 siblings, 1 reply; 7+ messages in thread
From: Daeho Jeong @ 2021-07-26  4:18 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel, kernel-team; +Cc: Daeho Jeong, Eric Biggers

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.

Let's assume 16KB compression cluster.

<before>
   Logical          Physical         Length           Flags
0:  0000000000000000 00000002c091f000 0000000000004000 1008
1:  0000000000004000 00000002c0920000 0000000000004000 1008
  ...
9:  0000000000034000 0000000f8c623000 0000000000004000 1008
10: 0000000000038000 000000101a6eb000 0000000000004000 1008

<after>
0:  0000000000000000 00000002c091f000 0000000000004000 1008
1:  0000000000004000 00000002c0920000 0000000000004000 1008
  ...
9:  0000000000034000 0000000f8c623000 0000000000001000 1008
10: 0000000000035000 000000101a6ea000 0000000000003000 1008
11: 0000000000038000 000000101a6eb000 0000000000002000 1008
12: 000000000003a000 00000002c3544000 0000000000002000 1008

Flags
0x1000 => FIEMAP_EXTENT_MERGED
0x0008 => FIEMAP_EXTENT_ENCODED

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Tested-by: Eric Biggers <ebiggers@google.com>

---
v4: initialized count_in_cluster
v3: fix the missing last extent flag issue
v2: changed the print format
---
 fs/f2fs/data.c | 75 ++++++++++++++++++++++++++++----------------------
 1 file changed, 42 insertions(+), 33 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 3a01a1b50104..1a716c3b5457 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1843,8 +1843,9 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 	u64 logical = 0, phys = 0, size = 0;
 	u32 flags = 0;
 	int ret = 0;
-	bool compr_cluster = false;
+	bool compr_cluster = false, compr_appended;
 	unsigned int cluster_size = F2FS_I(inode)->i_cluster_size;
+	unsigned int count_in_cluster = 0;
 	loff_t maxbytes;
 
 	if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) {
@@ -1892,15 +1893,17 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 	map.m_next_pgofs = &next_pgofs;
 	map.m_seg_type = NO_CHECK_TYPE;
 
-	if (compr_cluster)
-		map.m_len = cluster_size - 1;
+	if (compr_cluster) {
+		map.m_lblk += 1;
+		map.m_len = cluster_size - count_in_cluster;
+	}
 
 	ret = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_FIEMAP);
 	if (ret)
 		goto out;
 
 	/* HOLE */
-	if (!(map.m_flags & F2FS_MAP_FLAGS)) {
+	if (!compr_cluster && !(map.m_flags & F2FS_MAP_FLAGS)) {
 		start_blk = next_pgofs;
 
 		if (blks_to_bytes(inode, start_blk) < blks_to_bytes(inode,
@@ -1910,6 +1913,14 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 		flags |= FIEMAP_EXTENT_LAST;
 	}
 
+	compr_appended = false;
+	/* In a case of compressed cluster, append this to the last extent */
+	if (compr_cluster && ((map.m_flags & F2FS_MAP_UNWRITTEN) ||
+			!(map.m_flags & F2FS_MAP_FLAGS))) {
+		compr_appended = true;
+		goto skip_fill;
+	}
+
 	if (size) {
 		flags |= FIEMAP_EXTENT_MERGED;
 		if (IS_ENCRYPTED(inode))
@@ -1926,38 +1937,36 @@ 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;
-	}
-
+skip_fill:
 	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);
-	size = blks_to_bytes(inode, map.m_len);
-	flags = 0;
-	if (map.m_flags & F2FS_MAP_UNWRITTEN)
-		flags = FIEMAP_EXTENT_UNWRITTEN;
+		count_in_cluster = 1;
+	} else if (compr_appended) {
+		unsigned int appended_blks = cluster_size -
+						count_in_cluster + 1;
+		size += blks_to_bytes(inode, appended_blks);
+		start_blk += appended_blks;
+		compr_cluster = false;
+	} else {
+		logical = blks_to_bytes(inode, start_blk);
+		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 (compr_cluster) {
+			flags = FIEMAP_EXTENT_ENCODED;
+			count_in_cluster += map.m_len;
+			if (count_in_cluster == cluster_size) {
+				compr_cluster = false;
+				size += blks_to_bytes(inode, 1);
+			}
+		} else if (map.m_flags & F2FS_MAP_UNWRITTEN) {
+			flags = FIEMAP_EXTENT_UNWRITTEN;
+		}
 
-	start_blk += bytes_to_blks(inode, size);
+		start_blk += bytes_to_blks(inode, size);
+	}
 
 prep_next:
 	cond_resched();
-- 
2.32.0.432.gabb21c7263-goog


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

* Re: [f2fs-dev] [PATCH v4] f2fs: change fiemap way in printing compression chunk
  2021-07-26  4:18 [PATCH v4] f2fs: change fiemap way in printing compression chunk Daeho Jeong
@ 2021-07-27 10:19 ` Chao Yu
  2021-07-27 16:41   ` Daeho Jeong
  2021-07-27 17:17   ` Jaegeuk Kim
  0 siblings, 2 replies; 7+ messages in thread
From: Chao Yu @ 2021-07-27 10:19 UTC (permalink / raw)
  To: Daeho Jeong, linux-kernel, linux-f2fs-devel, kernel-team
  Cc: Daeho Jeong, Eric Biggers

On 2021/7/26 12:18, Daeho Jeong wrote:
> 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.
> 
> Let's assume 16KB compression cluster.
> 
> <before>
>     Logical          Physical         Length           Flags
> 0:  0000000000000000 00000002c091f000 0000000000004000 1008
> 1:  0000000000004000 00000002c0920000 0000000000004000 1008
>    ...
> 9:  0000000000034000 0000000f8c623000 0000000000004000 1008
> 10: 0000000000038000 000000101a6eb000 0000000000004000 1008
> 
> <after>
> 0:  0000000000000000 00000002c091f000 0000000000004000 1008
> 1:  0000000000004000 00000002c0920000 0000000000004000 1008
>    ...
> 9:  0000000000034000 0000000f8c623000 0000000000001000 1008
> 10: 0000000000035000 000000101a6ea000 0000000000003000 1008
> 11: 0000000000038000 000000101a6eb000 0000000000002000 1008
> 12: 000000000003a000 00000002c3544000 0000000000002000 1008
> 
> Flags
> 0x1000 => FIEMAP_EXTENT_MERGED
> 0x0008 => FIEMAP_EXTENT_ENCODED
> 
> Signed-off-by: Daeho Jeong <daehojeong@google.com>
> Tested-by: Eric Biggers <ebiggers@google.com>
> 
> ---
> v4: initialized count_in_cluster
> v3: fix the missing last extent flag issue
> v2: changed the print format
> ---
>   fs/f2fs/data.c | 75 ++++++++++++++++++++++++++++----------------------
>   1 file changed, 42 insertions(+), 33 deletions(-)
> 
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 3a01a1b50104..1a716c3b5457 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -1843,8 +1843,9 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
>   	u64 logical = 0, phys = 0, size = 0;
>   	u32 flags = 0;
>   	int ret = 0;
> -	bool compr_cluster = false;
> +	bool compr_cluster = false, compr_appended;
>   	unsigned int cluster_size = F2FS_I(inode)->i_cluster_size;
> +	unsigned int count_in_cluster = 0;
>   	loff_t maxbytes;
>   
>   	if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) {
> @@ -1892,15 +1893,17 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
>   	map.m_next_pgofs = &next_pgofs;
>   	map.m_seg_type = NO_CHECK_TYPE;
>   
> -	if (compr_cluster)
> -		map.m_len = cluster_size - 1;
> +	if (compr_cluster) {
> +		map.m_lblk += 1;
> +		map.m_len = cluster_size - count_in_cluster;
> +	}
>   
>   	ret = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_FIEMAP);
>   	if (ret)
>   		goto out;
>   
>   	/* HOLE */
> -	if (!(map.m_flags & F2FS_MAP_FLAGS)) {
> +	if (!compr_cluster && !(map.m_flags & F2FS_MAP_FLAGS)) {
>   		start_blk = next_pgofs;
>   
>   		if (blks_to_bytes(inode, start_blk) < blks_to_bytes(inode,
> @@ -1910,6 +1913,14 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
>   		flags |= FIEMAP_EXTENT_LAST;
>   	}
>   
> +	compr_appended = false;
> +	/* In a case of compressed cluster, append this to the last extent */
> +	if (compr_cluster && ((map.m_flags & F2FS_MAP_UNWRITTEN) ||
> +			!(map.m_flags & F2FS_MAP_FLAGS))) {
> +		compr_appended = true;
> +		goto skip_fill;
> +	}
> +
>   	if (size) {
>   		flags |= FIEMAP_EXTENT_MERGED;
>   		if (IS_ENCRYPTED(inode))
> @@ -1926,38 +1937,36 @@ 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;
> -	}
> -
> +skip_fill:
>   	if (map.m_pblk == COMPRESS_ADDR) {

Looks good, but one more thing I concern is how about detecting and
returning -EFSCORRUPTED for below corrupted metadata cases:
- [COMPRESS_ADDR, blkaddr, COMPRESS_ADDR, NEW_ADDR]
- [blkaddr, COMPRESS_ADDR, NULL_ADDR, NULL_ADDR]

Thanks,

>   		compr_cluster = true;
> -		start_blk++;
> -		goto prep_next;
> -	}
> -
> -	logical = blks_to_bytes(inode, start_blk);
> -	phys = blks_to_bytes(inode, map.m_pblk);
> -	size = blks_to_bytes(inode, map.m_len);
> -	flags = 0;
> -	if (map.m_flags & F2FS_MAP_UNWRITTEN)
> -		flags = FIEMAP_EXTENT_UNWRITTEN;
> +		count_in_cluster = 1;
> +	} else if (compr_appended) {
> +		unsigned int appended_blks = cluster_size -
> +						count_in_cluster + 1;
> +		size += blks_to_bytes(inode, appended_blks);
> +		start_blk += appended_blks;
> +		compr_cluster = false;
> +	} else {
> +		logical = blks_to_bytes(inode, start_blk);
> +		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 (compr_cluster) {
> +			flags = FIEMAP_EXTENT_ENCODED;
> +			count_in_cluster += map.m_len;
> +			if (count_in_cluster == cluster_size) {
> +				compr_cluster = false;
> +				size += blks_to_bytes(inode, 1);
> +			}
> +		} else if (map.m_flags & F2FS_MAP_UNWRITTEN) {
> +			flags = FIEMAP_EXTENT_UNWRITTEN;
> +		}
>   
> -	start_blk += bytes_to_blks(inode, size);
> +		start_blk += bytes_to_blks(inode, size);
> +	}
>   
>   prep_next:
>   	cond_resched();
> 

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

* Re: [f2fs-dev] [PATCH v4] f2fs: change fiemap way in printing compression chunk
  2021-07-27 10:19 ` [f2fs-dev] " Chao Yu
@ 2021-07-27 16:41   ` Daeho Jeong
  2021-07-29  0:37     ` Chao Yu
  2021-07-27 17:17   ` Jaegeuk Kim
  1 sibling, 1 reply; 7+ messages in thread
From: Daeho Jeong @ 2021-07-27 16:41 UTC (permalink / raw)
  To: Chao Yu
  Cc: linux-kernel, linux-f2fs-devel, kernel-team, Daeho Jeong, Eric Biggers

How about adding this?

skip_fill:

        if (map.m_pblk == COMPRESS_ADDR) {

                if (start_blk & (cluster_size - 1)) {

                        ret = -EFSCORRUPTED;

                        goto out;

                }

                compr_cluster = true;

                count_in_cluster = 1;

        } else if (compr_appended) {

On Tue, Jul 27, 2021 at 3:19 AM Chao Yu <chao@kernel.org> wrote:
>
> On 2021/7/26 12:18, Daeho Jeong wrote:
> > 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.
> >
> > Let's assume 16KB compression cluster.
> >
> > <before>
> >     Logical          Physical         Length           Flags
> > 0:  0000000000000000 00000002c091f000 0000000000004000 1008
> > 1:  0000000000004000 00000002c0920000 0000000000004000 1008
> >    ...
> > 9:  0000000000034000 0000000f8c623000 0000000000004000 1008
> > 10: 0000000000038000 000000101a6eb000 0000000000004000 1008
> >
> > <after>
> > 0:  0000000000000000 00000002c091f000 0000000000004000 1008
> > 1:  0000000000004000 00000002c0920000 0000000000004000 1008
> >    ...
> > 9:  0000000000034000 0000000f8c623000 0000000000001000 1008
> > 10: 0000000000035000 000000101a6ea000 0000000000003000 1008
> > 11: 0000000000038000 000000101a6eb000 0000000000002000 1008
> > 12: 000000000003a000 00000002c3544000 0000000000002000 1008
> >
> > Flags
> > 0x1000 => FIEMAP_EXTENT_MERGED
> > 0x0008 => FIEMAP_EXTENT_ENCODED
> >
> > Signed-off-by: Daeho Jeong <daehojeong@google.com>
> > Tested-by: Eric Biggers <ebiggers@google.com>
> >
> > ---
> > v4: initialized count_in_cluster
> > v3: fix the missing last extent flag issue
> > v2: changed the print format
> > ---
> >   fs/f2fs/data.c | 75 ++++++++++++++++++++++++++++----------------------
> >   1 file changed, 42 insertions(+), 33 deletions(-)
> >
> > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> > index 3a01a1b50104..1a716c3b5457 100644
> > --- a/fs/f2fs/data.c
> > +++ b/fs/f2fs/data.c
> > @@ -1843,8 +1843,9 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
> >       u64 logical = 0, phys = 0, size = 0;
> >       u32 flags = 0;
> >       int ret = 0;
> > -     bool compr_cluster = false;
> > +     bool compr_cluster = false, compr_appended;
> >       unsigned int cluster_size = F2FS_I(inode)->i_cluster_size;
> > +     unsigned int count_in_cluster = 0;
> >       loff_t maxbytes;
> >
> >       if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) {
> > @@ -1892,15 +1893,17 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
> >       map.m_next_pgofs = &next_pgofs;
> >       map.m_seg_type = NO_CHECK_TYPE;
> >
> > -     if (compr_cluster)
> > -             map.m_len = cluster_size - 1;
> > +     if (compr_cluster) {
> > +             map.m_lblk += 1;
> > +             map.m_len = cluster_size - count_in_cluster;
> > +     }
> >
> >       ret = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_FIEMAP);
> >       if (ret)
> >               goto out;
> >
> >       /* HOLE */
> > -     if (!(map.m_flags & F2FS_MAP_FLAGS)) {
> > +     if (!compr_cluster && !(map.m_flags & F2FS_MAP_FLAGS)) {
> >               start_blk = next_pgofs;
> >
> >               if (blks_to_bytes(inode, start_blk) < blks_to_bytes(inode,
> > @@ -1910,6 +1913,14 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
> >               flags |= FIEMAP_EXTENT_LAST;
> >       }
> >
> > +     compr_appended = false;
> > +     /* In a case of compressed cluster, append this to the last extent */
> > +     if (compr_cluster && ((map.m_flags & F2FS_MAP_UNWRITTEN) ||
> > +                     !(map.m_flags & F2FS_MAP_FLAGS))) {
> > +             compr_appended = true;
> > +             goto skip_fill;
> > +     }
> > +
> >       if (size) {
> >               flags |= FIEMAP_EXTENT_MERGED;
> >               if (IS_ENCRYPTED(inode))
> > @@ -1926,38 +1937,36 @@ 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;
> > -     }
> > -
> > +skip_fill:
> >       if (map.m_pblk == COMPRESS_ADDR) {
>
> Looks good, but one more thing I concern is how about detecting and
> returning -EFSCORRUPTED for below corrupted metadata cases:
> - [COMPRESS_ADDR, blkaddr, COMPRESS_ADDR, NEW_ADDR]
> - [blkaddr, COMPRESS_ADDR, NULL_ADDR, NULL_ADDR]
>
> Thanks,
>
> >               compr_cluster = true;
> > -             start_blk++;
> > -             goto prep_next;
> > -     }
> > -
> > -     logical = blks_to_bytes(inode, start_blk);
> > -     phys = blks_to_bytes(inode, map.m_pblk);
> > -     size = blks_to_bytes(inode, map.m_len);
> > -     flags = 0;
> > -     if (map.m_flags & F2FS_MAP_UNWRITTEN)
> > -             flags = FIEMAP_EXTENT_UNWRITTEN;
> > +             count_in_cluster = 1;
> > +     } else if (compr_appended) {
> > +             unsigned int appended_blks = cluster_size -
> > +                                             count_in_cluster + 1;
> > +             size += blks_to_bytes(inode, appended_blks);
> > +             start_blk += appended_blks;
> > +             compr_cluster = false;
> > +     } else {
> > +             logical = blks_to_bytes(inode, start_blk);
> > +             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 (compr_cluster) {
> > +                     flags = FIEMAP_EXTENT_ENCODED;
> > +                     count_in_cluster += map.m_len;
> > +                     if (count_in_cluster == cluster_size) {
> > +                             compr_cluster = false;
> > +                             size += blks_to_bytes(inode, 1);
> > +                     }
> > +             } else if (map.m_flags & F2FS_MAP_UNWRITTEN) {
> > +                     flags = FIEMAP_EXTENT_UNWRITTEN;
> > +             }
> >
> > -     start_blk += bytes_to_blks(inode, size);
> > +             start_blk += bytes_to_blks(inode, size);
> > +     }
> >
> >   prep_next:
> >       cond_resched();
> >

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

* Re: [f2fs-dev] [PATCH v4] f2fs: change fiemap way in printing compression chunk
  2021-07-27 10:19 ` [f2fs-dev] " Chao Yu
  2021-07-27 16:41   ` Daeho Jeong
@ 2021-07-27 17:17   ` Jaegeuk Kim
  2021-07-29  0:40     ` Chao Yu
  1 sibling, 1 reply; 7+ messages in thread
From: Jaegeuk Kim @ 2021-07-27 17:17 UTC (permalink / raw)
  To: Chao Yu
  Cc: Daeho Jeong, linux-kernel, linux-f2fs-devel, kernel-team,
	Daeho Jeong, Eric Biggers

On 07/27, Chao Yu wrote:
> On 2021/7/26 12:18, Daeho Jeong wrote:
> > 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.
> > 
> > Let's assume 16KB compression cluster.
> > 
> > <before>
> >     Logical          Physical         Length           Flags
> > 0:  0000000000000000 00000002c091f000 0000000000004000 1008
> > 1:  0000000000004000 00000002c0920000 0000000000004000 1008
> >    ...
> > 9:  0000000000034000 0000000f8c623000 0000000000004000 1008
> > 10: 0000000000038000 000000101a6eb000 0000000000004000 1008
> > 
> > <after>
> > 0:  0000000000000000 00000002c091f000 0000000000004000 1008
> > 1:  0000000000004000 00000002c0920000 0000000000004000 1008
> >    ...
> > 9:  0000000000034000 0000000f8c623000 0000000000001000 1008
> > 10: 0000000000035000 000000101a6ea000 0000000000003000 1008
> > 11: 0000000000038000 000000101a6eb000 0000000000002000 1008
> > 12: 000000000003a000 00000002c3544000 0000000000002000 1008
> > 
> > Flags
> > 0x1000 => FIEMAP_EXTENT_MERGED
> > 0x0008 => FIEMAP_EXTENT_ENCODED
> > 
> > Signed-off-by: Daeho Jeong <daehojeong@google.com>
> > Tested-by: Eric Biggers <ebiggers@google.com>
> > 
> > ---
> > v4: initialized count_in_cluster
> > v3: fix the missing last extent flag issue
> > v2: changed the print format
> > ---
> >   fs/f2fs/data.c | 75 ++++++++++++++++++++++++++++----------------------
> >   1 file changed, 42 insertions(+), 33 deletions(-)
> > 
> > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> > index 3a01a1b50104..1a716c3b5457 100644
> > --- a/fs/f2fs/data.c
> > +++ b/fs/f2fs/data.c
> > @@ -1843,8 +1843,9 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
> >   	u64 logical = 0, phys = 0, size = 0;
> >   	u32 flags = 0;
> >   	int ret = 0;
> > -	bool compr_cluster = false;
> > +	bool compr_cluster = false, compr_appended;
> >   	unsigned int cluster_size = F2FS_I(inode)->i_cluster_size;
> > +	unsigned int count_in_cluster = 0;
> >   	loff_t maxbytes;
> >   	if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) {
> > @@ -1892,15 +1893,17 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
> >   	map.m_next_pgofs = &next_pgofs;
> >   	map.m_seg_type = NO_CHECK_TYPE;
> > -	if (compr_cluster)
> > -		map.m_len = cluster_size - 1;
> > +	if (compr_cluster) {
> > +		map.m_lblk += 1;
> > +		map.m_len = cluster_size - count_in_cluster;
> > +	}
> >   	ret = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_FIEMAP);
> >   	if (ret)
> >   		goto out;
> >   	/* HOLE */
> > -	if (!(map.m_flags & F2FS_MAP_FLAGS)) {
> > +	if (!compr_cluster && !(map.m_flags & F2FS_MAP_FLAGS)) {
> >   		start_blk = next_pgofs;
> >   		if (blks_to_bytes(inode, start_blk) < blks_to_bytes(inode,
> > @@ -1910,6 +1913,14 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
> >   		flags |= FIEMAP_EXTENT_LAST;
> >   	}
> > +	compr_appended = false;
> > +	/* In a case of compressed cluster, append this to the last extent */
> > +	if (compr_cluster && ((map.m_flags & F2FS_MAP_UNWRITTEN) ||
> > +			!(map.m_flags & F2FS_MAP_FLAGS))) {
> > +		compr_appended = true;
> > +		goto skip_fill;
> > +	}
> > +
> >   	if (size) {
> >   		flags |= FIEMAP_EXTENT_MERGED;
> >   		if (IS_ENCRYPTED(inode))
> > @@ -1926,38 +1937,36 @@ 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;
> > -	}
> > -
> > +skip_fill:
> >   	if (map.m_pblk == COMPRESS_ADDR) {
> 
> Looks good, but one more thing I concern is how about detecting and
> returning -EFSCORRUPTED for below corrupted metadata cases:
> - [COMPRESS_ADDR, blkaddr, COMPRESS_ADDR, NEW_ADDR]
> - [blkaddr, COMPRESS_ADDR, NULL_ADDR, NULL_ADDR]

Do we really need to catch this in fiemap? What about giving the current
layout with warning message and setting NEED_FSCK?

> 
> Thanks,
> 
> >   		compr_cluster = true;
> > -		start_blk++;
> > -		goto prep_next;
> > -	}
> > -
> > -	logical = blks_to_bytes(inode, start_blk);
> > -	phys = blks_to_bytes(inode, map.m_pblk);
> > -	size = blks_to_bytes(inode, map.m_len);
> > -	flags = 0;
> > -	if (map.m_flags & F2FS_MAP_UNWRITTEN)
> > -		flags = FIEMAP_EXTENT_UNWRITTEN;
> > +		count_in_cluster = 1;
> > +	} else if (compr_appended) {
> > +		unsigned int appended_blks = cluster_size -
> > +						count_in_cluster + 1;
> > +		size += blks_to_bytes(inode, appended_blks);
> > +		start_blk += appended_blks;
> > +		compr_cluster = false;
> > +	} else {
> > +		logical = blks_to_bytes(inode, start_blk);
> > +		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 (compr_cluster) {
> > +			flags = FIEMAP_EXTENT_ENCODED;
> > +			count_in_cluster += map.m_len;
> > +			if (count_in_cluster == cluster_size) {
> > +				compr_cluster = false;
> > +				size += blks_to_bytes(inode, 1);
> > +			}
> > +		} else if (map.m_flags & F2FS_MAP_UNWRITTEN) {
> > +			flags = FIEMAP_EXTENT_UNWRITTEN;
> > +		}
> > -	start_blk += bytes_to_blks(inode, size);
> > +		start_blk += bytes_to_blks(inode, size);
> > +	}
> >   prep_next:
> >   	cond_resched();
> > 

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

* Re: [f2fs-dev] [PATCH v4] f2fs: change fiemap way in printing compression chunk
  2021-07-27 16:41   ` Daeho Jeong
@ 2021-07-29  0:37     ` Chao Yu
  0 siblings, 0 replies; 7+ messages in thread
From: Chao Yu @ 2021-07-29  0:37 UTC (permalink / raw)
  To: Daeho Jeong
  Cc: linux-kernel, linux-f2fs-devel, kernel-team, Daeho Jeong, Eric Biggers

On 2021/7/28 0:41, Daeho Jeong wrote:
> How about adding this?
> 
> skip_fill:
> 
>          if (map.m_pblk == COMPRESS_ADDR) {
> 
>                  if (start_blk & (cluster_size - 1)) {
> 
>                          ret = -EFSCORRUPTED;
> 
>                          goto out;
> 
>                  }
> 
>                  compr_cluster = true;
> 
>                  count_in_cluster = 1;
> 
>          } else if (compr_appended) {

It seems we can add a separate patch to cover all cases that cluster metadata is
going to be accessed rather than just fixing fiemap() case here?

>>> Signed-off-by: Daeho Jeong <daehojeong@google.com>
>>> Tested-by: Eric Biggers <ebiggers@google.com>

Anyway, this patch looks good to me.

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

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

* Re: [f2fs-dev] [PATCH v4] f2fs: change fiemap way in printing compression chunk
  2021-07-27 17:17   ` Jaegeuk Kim
@ 2021-07-29  0:40     ` Chao Yu
  2021-07-29 22:51       ` Jaegeuk Kim
  0 siblings, 1 reply; 7+ messages in thread
From: Chao Yu @ 2021-07-29  0:40 UTC (permalink / raw)
  To: Jaegeuk Kim
  Cc: Daeho Jeong, linux-kernel, linux-f2fs-devel, kernel-team,
	Daeho Jeong, Eric Biggers

On 2021/7/28 1:17, Jaegeuk Kim wrote:
> Do we really need to catch this in fiemap? What about giving the current

Yes, I think so.

> layout with warning message and setting NEED_FSCK?

Sure,

How about doing sanity check on cluster metadata whenever it is going to
be accessed, like we did for single blkaddr with f2fs_is_valid_blkaddr()?

Thanks,

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

* Re: [f2fs-dev] [PATCH v4] f2fs: change fiemap way in printing compression chunk
  2021-07-29  0:40     ` Chao Yu
@ 2021-07-29 22:51       ` Jaegeuk Kim
  0 siblings, 0 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2021-07-29 22:51 UTC (permalink / raw)
  To: Chao Yu
  Cc: Daeho Jeong, linux-kernel, linux-f2fs-devel, kernel-team,
	Daeho Jeong, Eric Biggers

On 07/29, Chao Yu wrote:
> On 2021/7/28 1:17, Jaegeuk Kim wrote:
> > Do we really need to catch this in fiemap? What about giving the current
> 
> Yes, I think so.
> 
> > layout with warning message and setting NEED_FSCK?
> 
> Sure,
> 
> How about doing sanity check on cluster metadata whenever it is going to
> be accessed, like we did for single blkaddr with f2fs_is_valid_blkaddr()?

I think that'd be viable.

> 
> Thanks,

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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-26  4:18 [PATCH v4] f2fs: change fiemap way in printing compression chunk Daeho Jeong
2021-07-27 10:19 ` [f2fs-dev] " Chao Yu
2021-07-27 16:41   ` Daeho Jeong
2021-07-29  0:37     ` Chao Yu
2021-07-27 17:17   ` Jaegeuk Kim
2021-07-29  0:40     ` Chao Yu
2021-07-29 22:51       ` Jaegeuk Kim

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).