LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] f2fs-tools: change fiemap print out format
@ 2021-08-08 21:52 Daeho Jeong
  2021-08-19 18:41 ` Daeho Jeong
  2021-08-20 10:15 ` [f2fs-dev] " Chao Yu
  0 siblings, 2 replies; 4+ messages in thread
From: Daeho Jeong @ 2021-08-08 21:52 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel, kernel-team; +Cc: Daeho Jeong

From: Daeho Jeong <daehojeong@google.com>

Given fiemap way to print out extents in the kernel, we can correctly
print the layout of each file in a unit of extent, not block. So, I
changed fiemap print out way like below.

Fiemap: offset = 0 len = 60
	logical addr.    physical addr.   length           flags
0	0000000000000000 00000020032df000 0000000000004000 00001008
1	0000000000004000 00000020032e0000 0000000000004000 00001008
2	0000000000008000 00000020032e1000 0000000000004000 00001008
3	000000000000c000 00000020032e2000 0000000000004000 00001008

Signed-off-by: Daeho Jeong <daehojeong@google.com>
---
 tools/f2fs_io/f2fs_io.c | 53 ++++++++++++++++++++++++++---------------
 1 file changed, 34 insertions(+), 19 deletions(-)

diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 42dbd60..0d2948e 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -731,11 +731,11 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)
 #if defined(HAVE_LINUX_FIEMAP_H) && defined(HAVE_LINUX_FS_H)
 static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
 {
-	unsigned count, i;
-	int fd;
-	__u64 phy_addr;
-	struct fiemap *fm = xmalloc(sizeof(struct fiemap) +
-			sizeof(struct fiemap_extent));
+	unsigned int i;
+	int fd, extents_mem_size;
+	u64 start, length;
+	u32 mapped_extents;
+	struct fiemap *fm = xmalloc(sizeof(struct fiemap));
 
 	if (argc != 4) {
 		fputs("Excess arguments\n\n", stderr);
@@ -743,26 +743,41 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
 		exit(1);
 	}
 
-	fm->fm_start = atoi(argv[1]) * F2FS_BLKSIZE;
-	fm->fm_length = F2FS_BLKSIZE;
-	fm->fm_extent_count = 1;
-	count = atoi(argv[2]);
+	memset(fm, 0, sizeof(struct fiemap));
+	start = atoi(argv[1]) * F2FS_BLKSIZE;
+	length = atoi(argv[2]) * F2FS_BLKSIZE;
+	fm->fm_start = start;
+	fm->fm_length = length;
 
 	fd = xopen(argv[3], O_RDONLY | O_LARGEFILE, 0);
 
-	printf("Fiemap: offset = %08"PRIx64" len = %d\n",
-				(u64)fm->fm_start / F2FS_BLKSIZE, count);
-	for (i = 0; i < count; i++) {
-		if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
-			die_errno("FIEMAP failed");
+	printf("Fiemap: offset = %"PRIu64" len = %"PRIu64"\n",
+				start / F2FS_BLKSIZE, length / F2FS_BLKSIZE);
+	if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
+		die_errno("FIEMAP failed");
+
+	mapped_extents = fm->fm_mapped_extents;
+	extents_mem_size = sizeof(struct fiemap_extent) * mapped_extents;
+	free(fm);
+	fm = xmalloc(sizeof(struct fiemap) + extents_mem_size);
 
-		phy_addr = fm->fm_extents[0].fe_physical / F2FS_BLKSIZE;
-		printf("%llu: %llu\n", fm->fm_start / F2FS_BLKSIZE, phy_addr);
+	memset(fm, 0, sizeof(struct fiemap));
+	memset(fm->fm_extents, 0, extents_mem_size);
+	fm->fm_start = start;
+	fm->fm_length = length;
+	fm->fm_extent_count = mapped_extents;
 
-		if (fm->fm_extents[0].fe_flags & FIEMAP_EXTENT_LAST)
-			break;
+	if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
+		die_errno("FIEMAP failed");
 
-		fm->fm_start += F2FS_BLKSIZE;
+	printf("\t%-17s%-17s%-17s%s\n", "logical addr.", "physical addr.", "length", "flags");
+	for (i = 0; i < fm->fm_mapped_extents; i++) {
+		printf("%d\t%.16llx %.16llx %.16llx %.8x\n", i,
+		    fm->fm_extents[i].fe_logical, fm->fm_extents[i].fe_physical,
+		    fm->fm_extents[i].fe_length, fm->fm_extents[i].fe_flags);
+
+		if (fm->fm_extents[i].fe_flags & FIEMAP_EXTENT_LAST)
+			break;
 	}
 	printf("\n");
 	free(fm);
-- 
2.32.0.605.g8dce9f2422-goog


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

* Re: [PATCH] f2fs-tools: change fiemap print out format
  2021-08-08 21:52 [PATCH] f2fs-tools: change fiemap print out format Daeho Jeong
@ 2021-08-19 18:41 ` Daeho Jeong
  2021-08-20 10:15 ` [f2fs-dev] " Chao Yu
  1 sibling, 0 replies; 4+ messages in thread
From: Daeho Jeong @ 2021-08-19 18:41 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel, kernel-team; +Cc: Daeho Jeong

Ping this?

On Sun, Aug 8, 2021 at 2:52 PM Daeho Jeong <daeho43@gmail.com> wrote:
>
> From: Daeho Jeong <daehojeong@google.com>
>
> Given fiemap way to print out extents in the kernel, we can correctly
> print the layout of each file in a unit of extent, not block. So, I
> changed fiemap print out way like below.
>
> Fiemap: offset = 0 len = 60
>         logical addr.    physical addr.   length           flags
> 0       0000000000000000 00000020032df000 0000000000004000 00001008
> 1       0000000000004000 00000020032e0000 0000000000004000 00001008
> 2       0000000000008000 00000020032e1000 0000000000004000 00001008
> 3       000000000000c000 00000020032e2000 0000000000004000 00001008
>
> Signed-off-by: Daeho Jeong <daehojeong@google.com>
> ---
>  tools/f2fs_io/f2fs_io.c | 53 ++++++++++++++++++++++++++---------------
>  1 file changed, 34 insertions(+), 19 deletions(-)
>
> diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
> index 42dbd60..0d2948e 100644
> --- a/tools/f2fs_io/f2fs_io.c
> +++ b/tools/f2fs_io/f2fs_io.c
> @@ -731,11 +731,11 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)
>  #if defined(HAVE_LINUX_FIEMAP_H) && defined(HAVE_LINUX_FS_H)
>  static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
>  {
> -       unsigned count, i;
> -       int fd;
> -       __u64 phy_addr;
> -       struct fiemap *fm = xmalloc(sizeof(struct fiemap) +
> -                       sizeof(struct fiemap_extent));
> +       unsigned int i;
> +       int fd, extents_mem_size;
> +       u64 start, length;
> +       u32 mapped_extents;
> +       struct fiemap *fm = xmalloc(sizeof(struct fiemap));
>
>         if (argc != 4) {
>                 fputs("Excess arguments\n\n", stderr);
> @@ -743,26 +743,41 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
>                 exit(1);
>         }
>
> -       fm->fm_start = atoi(argv[1]) * F2FS_BLKSIZE;
> -       fm->fm_length = F2FS_BLKSIZE;
> -       fm->fm_extent_count = 1;
> -       count = atoi(argv[2]);
> +       memset(fm, 0, sizeof(struct fiemap));
> +       start = atoi(argv[1]) * F2FS_BLKSIZE;
> +       length = atoi(argv[2]) * F2FS_BLKSIZE;
> +       fm->fm_start = start;
> +       fm->fm_length = length;
>
>         fd = xopen(argv[3], O_RDONLY | O_LARGEFILE, 0);
>
> -       printf("Fiemap: offset = %08"PRIx64" len = %d\n",
> -                               (u64)fm->fm_start / F2FS_BLKSIZE, count);
> -       for (i = 0; i < count; i++) {
> -               if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
> -                       die_errno("FIEMAP failed");
> +       printf("Fiemap: offset = %"PRIu64" len = %"PRIu64"\n",
> +                               start / F2FS_BLKSIZE, length / F2FS_BLKSIZE);
> +       if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
> +               die_errno("FIEMAP failed");
> +
> +       mapped_extents = fm->fm_mapped_extents;
> +       extents_mem_size = sizeof(struct fiemap_extent) * mapped_extents;
> +       free(fm);
> +       fm = xmalloc(sizeof(struct fiemap) + extents_mem_size);
>
> -               phy_addr = fm->fm_extents[0].fe_physical / F2FS_BLKSIZE;
> -               printf("%llu: %llu\n", fm->fm_start / F2FS_BLKSIZE, phy_addr);
> +       memset(fm, 0, sizeof(struct fiemap));
> +       memset(fm->fm_extents, 0, extents_mem_size);
> +       fm->fm_start = start;
> +       fm->fm_length = length;
> +       fm->fm_extent_count = mapped_extents;
>
> -               if (fm->fm_extents[0].fe_flags & FIEMAP_EXTENT_LAST)
> -                       break;
> +       if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
> +               die_errno("FIEMAP failed");
>
> -               fm->fm_start += F2FS_BLKSIZE;
> +       printf("\t%-17s%-17s%-17s%s\n", "logical addr.", "physical addr.", "length", "flags");
> +       for (i = 0; i < fm->fm_mapped_extents; i++) {
> +               printf("%d\t%.16llx %.16llx %.16llx %.8x\n", i,
> +                   fm->fm_extents[i].fe_logical, fm->fm_extents[i].fe_physical,
> +                   fm->fm_extents[i].fe_length, fm->fm_extents[i].fe_flags);
> +
> +               if (fm->fm_extents[i].fe_flags & FIEMAP_EXTENT_LAST)
> +                       break;
>         }
>         printf("\n");
>         free(fm);
> --
> 2.32.0.605.g8dce9f2422-goog
>

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

* Re: [f2fs-dev] [PATCH] f2fs-tools: change fiemap print out format
  2021-08-08 21:52 [PATCH] f2fs-tools: change fiemap print out format Daeho Jeong
  2021-08-19 18:41 ` Daeho Jeong
@ 2021-08-20 10:15 ` Chao Yu
  2021-08-20 15:20   ` Daeho Jeong
  1 sibling, 1 reply; 4+ messages in thread
From: Chao Yu @ 2021-08-20 10:15 UTC (permalink / raw)
  To: Daeho Jeong, linux-kernel, linux-f2fs-devel, kernel-team; +Cc: Daeho Jeong

On 2021/8/9 5:52, Daeho Jeong wrote:
> From: Daeho Jeong <daehojeong@google.com>
> 
> Given fiemap way to print out extents in the kernel, we can correctly
> print the layout of each file in a unit of extent, not block. So, I
> changed fiemap print out way like below.
> 
> Fiemap: offset = 0 len = 60
> 	logical addr.    physical addr.   length           flags
> 0	0000000000000000 00000020032df000 0000000000004000 00001008
> 1	0000000000004000 00000020032e0000 0000000000004000 00001008
> 2	0000000000008000 00000020032e1000 0000000000004000 00001008
> 3	000000000000c000 00000020032e2000 0000000000004000 00001008
> 
> Signed-off-by: Daeho Jeong <daehojeong@google.com>
> ---
>   tools/f2fs_io/f2fs_io.c | 53 ++++++++++++++++++++++++++---------------
>   1 file changed, 34 insertions(+), 19 deletions(-)
> 
> diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
> index 42dbd60..0d2948e 100644
> --- a/tools/f2fs_io/f2fs_io.c
> +++ b/tools/f2fs_io/f2fs_io.c
> @@ -731,11 +731,11 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)
>   #if defined(HAVE_LINUX_FIEMAP_H) && defined(HAVE_LINUX_FS_H)
>   static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
>   {
> -	unsigned count, i;
> -	int fd;
> -	__u64 phy_addr;
> -	struct fiemap *fm = xmalloc(sizeof(struct fiemap) +
> -			sizeof(struct fiemap_extent));
> +	unsigned int i;
> +	int fd, extents_mem_size;
> +	u64 start, length;
> +	u32 mapped_extents;
> +	struct fiemap *fm = xmalloc(sizeof(struct fiemap));
>   
>   	if (argc != 4) {
>   		fputs("Excess arguments\n\n", stderr);
> @@ -743,26 +743,41 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
>   		exit(1);
>   	}
>   
> -	fm->fm_start = atoi(argv[1]) * F2FS_BLKSIZE;
> -	fm->fm_length = F2FS_BLKSIZE;
> -	fm->fm_extent_count = 1;
> -	count = atoi(argv[2]);
> +	memset(fm, 0, sizeof(struct fiemap));
> +	start = atoi(argv[1]) * F2FS_BLKSIZE;
> +	length = atoi(argv[2]) * F2FS_BLKSIZE;
> +	fm->fm_start = start;
> +	fm->fm_length = length;
>   
>   	fd = xopen(argv[3], O_RDONLY | O_LARGEFILE, 0);
>   
> -	printf("Fiemap: offset = %08"PRIx64" len = %d\n",
> -				(u64)fm->fm_start / F2FS_BLKSIZE, count);
> -	for (i = 0; i < count; i++) {
> -		if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
> -			die_errno("FIEMAP failed");
> +	printf("Fiemap: offset = %"PRIu64" len = %"PRIu64"\n",
> +				start / F2FS_BLKSIZE, length / F2FS_BLKSIZE);
> +	if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
> +		die_errno("FIEMAP failed");
> +
> +	mapped_extents = fm->fm_mapped_extents;
> +	extents_mem_size = sizeof(struct fiemap_extent) * mapped_extents;
> +	free(fm);
> +	fm = xmalloc(sizeof(struct fiemap) + extents_mem_size);
>   
> -		phy_addr = fm->fm_extents[0].fe_physical / F2FS_BLKSIZE;
> -		printf("%llu: %llu\n", fm->fm_start / F2FS_BLKSIZE, phy_addr);
> +	memset(fm, 0, sizeof(struct fiemap));
> +	memset(fm->fm_extents, 0, extents_mem_size);

Is that equals to memset(fm, 0, sizeof(struct fiemap) + extents_mem_size);?

> +	fm->fm_start = start;
> +	fm->fm_length = length;
> +	fm->fm_extent_count = mapped_extents;
>   
> -		if (fm->fm_extents[0].fe_flags & FIEMAP_EXTENT_LAST)
> -			break;
> +	if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
> +		die_errno("FIEMAP failed");
>   
> -		fm->fm_start += F2FS_BLKSIZE;
> +	printf("\t%-17s%-17s%-17s%s\n", "logical addr.", "physical addr.", "length", "flags");
> +	for (i = 0; i < fm->fm_mapped_extents; i++) {
> +		printf("%d\t%.16llx %.16llx %.16llx %.8x\n", i,
> +		    fm->fm_extents[i].fe_logical, fm->fm_extents[i].fe_physical,
> +		    fm->fm_extents[i].fe_length, fm->fm_extents[i].fe_flags);
> +
> +		if (fm->fm_extents[i].fe_flags & FIEMAP_EXTENT_LAST)
> +			break;
>   	}
>   	printf("\n");
>   	free(fm);
> 

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

* Re: [f2fs-dev] [PATCH] f2fs-tools: change fiemap print out format
  2021-08-20 10:15 ` [f2fs-dev] " Chao Yu
@ 2021-08-20 15:20   ` Daeho Jeong
  0 siblings, 0 replies; 4+ messages in thread
From: Daeho Jeong @ 2021-08-20 15:20 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-kernel, linux-f2fs-devel, kernel-team, Daeho Jeong

On Fri, Aug 20, 2021 at 3:15 AM Chao Yu <chao@kernel.org> wrote:
>
> On 2021/8/9 5:52, Daeho Jeong wrote:
> > From: Daeho Jeong <daehojeong@google.com>
> >
> > Given fiemap way to print out extents in the kernel, we can correctly
> > print the layout of each file in a unit of extent, not block. So, I
> > changed fiemap print out way like below.
> >
> > Fiemap: offset = 0 len = 60
> >       logical addr.    physical addr.   length           flags
> > 0     0000000000000000 00000020032df000 0000000000004000 00001008
> > 1     0000000000004000 00000020032e0000 0000000000004000 00001008
> > 2     0000000000008000 00000020032e1000 0000000000004000 00001008
> > 3     000000000000c000 00000020032e2000 0000000000004000 00001008
> >
> > Signed-off-by: Daeho Jeong <daehojeong@google.com>
> > ---
> >   tools/f2fs_io/f2fs_io.c | 53 ++++++++++++++++++++++++++---------------
> >   1 file changed, 34 insertions(+), 19 deletions(-)
> >
> > diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
> > index 42dbd60..0d2948e 100644
> > --- a/tools/f2fs_io/f2fs_io.c
> > +++ b/tools/f2fs_io/f2fs_io.c
> > @@ -731,11 +731,11 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)
> >   #if defined(HAVE_LINUX_FIEMAP_H) && defined(HAVE_LINUX_FS_H)
> >   static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
> >   {
> > -     unsigned count, i;
> > -     int fd;
> > -     __u64 phy_addr;
> > -     struct fiemap *fm = xmalloc(sizeof(struct fiemap) +
> > -                     sizeof(struct fiemap_extent));
> > +     unsigned int i;
> > +     int fd, extents_mem_size;
> > +     u64 start, length;
> > +     u32 mapped_extents;
> > +     struct fiemap *fm = xmalloc(sizeof(struct fiemap));
> >
> >       if (argc != 4) {
> >               fputs("Excess arguments\n\n", stderr);
> > @@ -743,26 +743,41 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
> >               exit(1);
> >       }
> >
> > -     fm->fm_start = atoi(argv[1]) * F2FS_BLKSIZE;
> > -     fm->fm_length = F2FS_BLKSIZE;
> > -     fm->fm_extent_count = 1;
> > -     count = atoi(argv[2]);
> > +     memset(fm, 0, sizeof(struct fiemap));
> > +     start = atoi(argv[1]) * F2FS_BLKSIZE;
> > +     length = atoi(argv[2]) * F2FS_BLKSIZE;
> > +     fm->fm_start = start;
> > +     fm->fm_length = length;
> >
> >       fd = xopen(argv[3], O_RDONLY | O_LARGEFILE, 0);
> >
> > -     printf("Fiemap: offset = %08"PRIx64" len = %d\n",
> > -                             (u64)fm->fm_start / F2FS_BLKSIZE, count);
> > -     for (i = 0; i < count; i++) {
> > -             if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
> > -                     die_errno("FIEMAP failed");
> > +     printf("Fiemap: offset = %"PRIu64" len = %"PRIu64"\n",
> > +                             start / F2FS_BLKSIZE, length / F2FS_BLKSIZE);
> > +     if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
> > +             die_errno("FIEMAP failed");
> > +
> > +     mapped_extents = fm->fm_mapped_extents;
> > +     extents_mem_size = sizeof(struct fiemap_extent) * mapped_extents;
> > +     free(fm);
> > +     fm = xmalloc(sizeof(struct fiemap) + extents_mem_size);
> >
> > -             phy_addr = fm->fm_extents[0].fe_physical / F2FS_BLKSIZE;
> > -             printf("%llu: %llu\n", fm->fm_start / F2FS_BLKSIZE, phy_addr);
> > +     memset(fm, 0, sizeof(struct fiemap));
> > +     memset(fm->fm_extents, 0, extents_mem_size);
>
> Is that equals to memset(fm, 0, sizeof(struct fiemap) + extents_mem_size);?
>

Oh, you're right~

> > +     fm->fm_start = start;
> > +     fm->fm_length = length;
> > +     fm->fm_extent_count = mapped_extents;
> >
> > -             if (fm->fm_extents[0].fe_flags & FIEMAP_EXTENT_LAST)
> > -                     break;
> > +     if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
> > +             die_errno("FIEMAP failed");
> >
> > -             fm->fm_start += F2FS_BLKSIZE;
> > +     printf("\t%-17s%-17s%-17s%s\n", "logical addr.", "physical addr.", "length", "flags");
> > +     for (i = 0; i < fm->fm_mapped_extents; i++) {
> > +             printf("%d\t%.16llx %.16llx %.16llx %.8x\n", i,
> > +                 fm->fm_extents[i].fe_logical, fm->fm_extents[i].fe_physical,
> > +                 fm->fm_extents[i].fe_length, fm->fm_extents[i].fe_flags);
> > +
> > +             if (fm->fm_extents[i].fe_flags & FIEMAP_EXTENT_LAST)
> > +                     break;
> >       }
> >       printf("\n");
> >       free(fm);
> >

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

end of thread, other threads:[~2021-08-20 15:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-08 21:52 [PATCH] f2fs-tools: change fiemap print out format Daeho Jeong
2021-08-19 18:41 ` Daeho Jeong
2021-08-20 10:15 ` [f2fs-dev] " Chao Yu
2021-08-20 15:20   ` 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).