Add subcommand that dumps file extents
Subsystems (2)
v4 cover Add subcommand that dumps file extents
This patch series add an subcommand in inspect-internal. It dumps file extents of the file that user provided. For avoiding duplicated code, the patch that export functions is in this series.
Sidong Yang (2):
btrfs-progs: export util functions about file extent items
btrfs-progs: cmds: Add subcommand that dumps file extents
---
v2:
- Prints type and compression
- Use the terms from file_extents_item like disk_bytenr not like "physical"
v3:
- export util functions for removing duplication
- change the way to loop with search ioctl
v4:
- export COMPRESS_STR_LEN for using function safely
---
Makefile | 2 +- cmds/commands.h | 2 +- cmds/inspect-dump-file-extents.c | 134 +++++++++++++++++++++++++++++++ cmds/inspect.c | 1 + kernel-shared/print-tree.c | 18 ++--- kernel-shared/print-tree.h | 5 ++ 6 files changed, 151 insertions(+), 11 deletions(-) create mode 100644 cmds/inspect-dump-file-extents.c
Signature · 1 line
2.25.1
PATCH v4 1/2 btrfs-progs: export util functions about file extent items
This patch export two functions that convert enum about file extents to string. It can be used in other code like inspect-internal command. And this patch also make compress_type_to_str() function more safe by using strncpy() than strcpy().
--- kernel-shared/print-tree.c | 18 +++++++++--------- kernel-shared/print-tree.h | 5 +++++ 2 files changed, 14 insertions(+), 9 deletions(-)
kernel-shared/print-tree.c +9 -9
@@ -338,27 +338,27 @@ static void print_uuids(struct extent_buffer *eb)printf ("fs uuid %s\nchunk uuid %s\n" , fs_uuid, chunk_uuid); } -static void compress_type_to_str (u8 compress_type,char *ret) +void btrfs_compress_type_to_str (u8 compress_type,char *ret) {switch (compress_type) {case BTRFS_COMPRESS_NONE : -strcpy (ret,"none" ); +strncpy (ret,"none" ,BTRFS_COMPRESS_STR_LEN );break ;case BTRFS_COMPRESS_ZLIB : -strcpy (ret,"zlib" ); +strncpy (ret,"zlib" ,BTRFS_COMPRESS_STR_LEN );break ;case BTRFS_COMPRESS_LZO : -strcpy (ret,"lzo" ); +strncpy (ret,"lzo" ,BTRFS_COMPRESS_STR_LEN );break ;case BTRFS_COMPRESS_ZSTD : -strcpy (ret,"zstd" ); +strncpy (ret,"zstd" ,BTRFS_COMPRESS_STR_LEN );break ;default : -sprintf (ret,"UNKNOWN.%d" , compress_type); +snprintf (ret,BTRFS_COMPRESS_STR_LEN ,"UNKNOWN.%d" , compress_type); } } -static const char *file_extent_type_to_str (u8 type) +const char *btrfs_file_extent_type_to_str (u8 type) {switch (type) {case BTRFS_FILE_EXTENT_INLINE :return "inline" ;
@@ -376,12 +376,12 @@ static void print_file_extent_item(struct extent_buffer *eb,unsigned char extent_type =btrfs_file_extent_type (eb, fi);char compress_str[16 ]; -compress_type_to_str (btrfs_file_extent_compression (eb, fi), +btrfs_compress_type_to_str (btrfs_file_extent_compression (eb, fi), compress_str);printf ("\t\tgeneration %llu type %hhu (%s)\n" ,btrfs_file_extent_generation (eb, fi), - extent_type,file_extent_type_to_str (extent_type)); + extent_type,btrfs_file_extent_type_to_str (extent_type));if (extent_type ==BTRFS_FILE_EXTENT_INLINE ) { printf("\t\tinline extent data size %u ram_bytes %llu compression %hhu (%s)\n",
kernel-shared/print-tree.h +5 -0
@@ -33,6 +33,8 @@ enum { BTRFS_PRINT_TREE_DEFAULT = BTRFS_PRINT_TREE_BFS, }; +#define BTRFS_COMPRESS_STR_LEN 12 +void btrfs_print_tree (struct extent_buffer *eb,unsigned int mode);void btrfs_print_leaf (struct extent_buffer *eb,unsigned int mode);
@@ -43,4 +45,7 @@ void print_objectid(FILE *stream, u64 objectid, u8 type);void print_key_type (FILE *stream,u64 objectid,u8 type);void btrfs_print_superblock (struct btrfs_super_block *sb,int full); +void btrfs_compress_type_to_str (u8 compress_type,char *ret); +const char *btrfs_file_extent_type_to_str (u8 type); +#endif
Signature · 1 line
2.25.1
PATCH v4 2/2 btrfs-progs: cmds: Add subcommand that dumps file extents
In reply to Sidong YangThis patch adds an subcommand in inspect-internal. It dumps file extents of the file that user provided. It helps to show the internal information about file extents comprise the file.
--- Makefile | 2 +- cmds/commands.h | 2 +- cmds/inspect-dump-file-extents.c | 134 +++++++++++++++++++++++++++++++ cmds/inspect.c | 1 + 4 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 cmds/inspect-dump-file-extents.c
Makefile +1 -1
@@ -156,7 +156,7 @@ cmds_objects = cmds/subvolume.o cmds/filesystem.o cmds/device.o cmds/scrub.o \ cmds/restore.o cmds/rescue.o cmds/rescue-chunk-recover.o \ cmds/rescue-super-recover.o \ cmds/property.o cmds/filesystem-usage.o cmds/inspect-dump-tree.o \ - cmds/inspect-dump-super.o cmds/inspect-tree-stats.o cmds/filesystem-du.o \ + cmds/inspect-dump-super.o cmds/inspect-tree-stats.o cmds/inspect-dump-file-extents.o cmds/filesystem-du.o \ mkfs/common.o check/mode-common.o check/mode-lowmem.o libbtrfs_objects = common/send-stream.o common/send-utils.o kernel-lib/rbtree.o btrfs-list.o \ kernel-lib/radix-tree.o common/extent-cache.o kernel-shared/extent_io.o \
cmds/commands.h +1 -1
@@ -154,5 +154,5 @@ DECLARE_COMMAND(select_super);DECLARE_COMMAND (dump_super);DECLARE_COMMAND (debug_tree);DECLARE_COMMAND (rescue); - +DECLARE_COMMAND (inspect_dump_file_extents);#endif
cmds/inspect-dump-file-extents.c new file +134 -0
134 lines not on this page · raw message
cmds/inspect.c +1 -0
@@ -696,6 +696,7 @@ static const struct cmd_group inspect_cmd_group = { &cmd_struct_inspect_dump_tree, &cmd_struct_inspect_dump_super, &cmd_struct_inspect_tree_stats, + &cmd_struct_inspect_dump_file_extents, NULL } };
Signature · 1 line
2.25.1
Re: [PATCH v4 2/2] btrfs-progs: cmds: Add subcommand that dumps file extents
Quoted 3 lines · Sidong Yang
This patch adds an subcommand in inspect-internal. It dumps file extents of the file that user provided. It helps to show the internal information about file extents comprise the file.
Do you have an example of the output? That's the most interesting part. Thanks.
Re: [PATCH v4 2/2] btrfs-progs: cmds: Add subcommand that dumps file extents
Quoted 7 lines · David Sterba
Quoted 3 lines · Sidong Yang
This patch adds an subcommand in inspect-internal. It dumps file extents of the file that user provided. It helps to show the internal information about file extents comprise the file.
Do you have an example of the output? That's the most interesting part. Thanks.
Thanks for reply.
This is an example of the output below.
# ./btrfs inspect-internal dump-file-extent /mnt/test1 type = regular, start = 2097152, len = 3227648, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 5324800, len = 16728064, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 22052864, len = 8486912, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 30572544, len = 36540416, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 67112960, len = 5299630080, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none
Thanks,
Sidong
Re: [PATCH v4 2/2] btrfs-progs: cmds: Add subcommand that dumps file extents
Quoted 12 lines · Sidong Yang
Quoted 7 lines · David Sterba
Quoted 3 lines · Sidong Yang
This patch adds an subcommand in inspect-internal. It dumps file extents of the file that user provided. It helps to show the internal information about file extents comprise the file.
Do you have an example of the output? That's the most interesting part. Thanks.
Thanks for reply.
This is an example of the output below.
Quoted 6 lines
# ./btrfs inspect-internal dump-file-extent /mnt/test1 type = regular, start = 2097152, len = 3227648, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 5324800, len = 16728064, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 22052864, len = 8486912, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 30572544, len = 36540416, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 67112960, len = 5299630080, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none
This resembles a debugging output, something like we have for tracepoints but I think this should be more human readable, with possiblity of parsing by scripts/tools.
So to not just duplicate what filefrag or xfs_io -c fiemap do, we can optionally enhance the information with the specifics of btrfs, like on which devices the extents are, which compression is there etc. But the basic output should be more or less like filefrag.
Re: [PATCH v4 2/2] btrfs-progs: cmds: Add subcommand that dumps file extents
Quoted 20 lines · David Sterba
Quoted 12 lines · Sidong Yang
Quoted 7 lines · David Sterba
Quoted 3 lines · Sidong Yang
This patch adds an subcommand in inspect-internal. It dumps file extents of the file that user provided. It helps to show the internal information about file extents comprise the file.
Do you have an example of the output? That's the most interesting part. Thanks.
Thanks for reply.
This is an example of the output below.Quoted 6 lines
# ./btrfs inspect-internal dump-file-extent /mnt/test1 type = regular, start = 2097152, len = 3227648, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 5324800, len = 16728064, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 22052864, len = 8486912, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 30572544, len = 36540416, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 67112960, len = 5299630080, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none
Quoted 3 lines
This resembles a debugging output, something like we have for tracepoints but I think this should be more human readable, with possiblity of parsing by
scripts/tools.
Yes, I agree. I think It would be text or json.
Quoted 5 lines
So to not just duplicate what filefrag or
xfs_io-c fiemap do, we can optionally enhance the information with the specifics of btrfs, like on which devices the extents are, which compression is there etc. But the basic output should be more or less like filefrag.
Yeah, this is the limit for this patch. for more than filefrag or xfs_io, it should provide more specifics. compression type is already included. But it would be better that it describe which device has the extents. it goes to v2.
Re: [PATCH v4 2/2] btrfs-progs: cmds: Add subcommand that dumps file extents
In reply to Sidong YangQuoted 12 lines · Sidong Yang
Quoted 7 lines · David Sterba
Quoted 3 lines · Sidong Yang
This patch adds an subcommand in inspect-internal. It dumps file extents of the file that user provided. It helps to show the internal information about file extents comprise the file.
Do you have an example of the output? That's the most interesting part. Thanks.
Thanks for reply.
This is an example of the output below.
Quoted 6 lines
# ./btrfs inspect-internal dump-file-extent /mnt/test1 type = regular, start = 2097152, len = 3227648, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 5324800, len = 16728064, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 22052864, len = 8486912, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 30572544, len = 36540416, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 67112960, len = 5299630080, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none
Could you give an example which includes both real (non-hole) extents and real extents (better to include regular, compressed, preallocated and inline).
Currently the output only contains holes, and for holes, a lot of members makes no sense, like disk_bytenr/disk_num_bytes/offset (even it can be non-zero) and compression.
Thanks,
Qu
Quoted 4 lines
Thanks,
Sidong
Re: [PATCH v4 2/2] btrfs-progs: cmds: Add subcommand that dumps file extents
Quoted 28 lines · Qu Wenruo
Quoted 13 lines · Sidong Yang
Quoted 8 lines · David Sterba
Quoted 4 lines · Sidong Yang
This patch adds an subcommand in inspect-internal. It dumps file extents of
the file that user provided. It helps to show the internal information about file extents comprise the file.Do you have an example of the output? That's the most interesting part. Thanks.
Thanks for reply.
This is an example of the output below.Quoted 11 lines
# ./btrfs inspect-internal dump-file-extent /mnt/test1 type = regular, start = 2097152, len = 3227648, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 5324800, len = 16728064, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 22052864, len = 8486912, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 30572544, len = 36540416, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 67112960, len = 5299630080, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none
Quoted 3 lines
Could you give an example which includes both real (non-hole) extents and real extents (better to include regular, compressed, preallocated and inline).
Tons of typos... I mean to include both holes (like the existing example) and non-holes extents...
Quoted 12 lines
Currently the output only contains holes, and for holes, a lot of members makes no sense, like disk_bytenr/disk_num_bytes/offset (even it can be non-zero) and compression.
Thanks,
QuQuoted 4 lines
Thanks,
Sidong
Re: [PATCH v4 2/2] btrfs-progs: cmds: Add subcommand that dumps file extents
Quoted 31 lines · Qu Wenruo
Quoted 28 lines · Qu Wenruo
Quoted 24 lines · Sidong Yang
Quoted 8 lines · David Sterba
Quoted 4 lines · Sidong Yang
This patch adds an subcommand in inspect-internal. It dumps file extents of
the file that user provided. It helps to show the internal information about file extents comprise the file.Do you have an example of the output? That's the most interesting part. Thanks.
Thanks for reply.
This is an example of the output below.# ./btrfs inspect-internal dump-file-extent /mnt/test1 type = regular, start = 2097152, len = 3227648, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 5324800, len = 16728064, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 22052864, len = 8486912, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 30572544, len = 36540416, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 67112960, len = 5299630080, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none
Quoted 6 lines
Quoted 3 lines
Could you give an example which includes both real (non-hole) extents and real extents (better to include regular, compressed, preallocated and inline).
Tons of typos... I mean to include both holes (like the existing example) and non-holes extents...
Sorry, I had no idea about holes. But I found some test code in xfstests. It helpes me to make hole in file.
xfs_io -c "fpunch 96K 32K" /mnt/a/foobarxfs_io -c "fpunch 64K 128K" /mnt/a/foobar
and the example is below.
# ./btrfs inspect dump-file-extent /mnt/a/foobar type = regular, start = 0, len = 98304, disk_bytenr = 21651456, disk_num_bytes = 4096, offset = 0, compression = zstd type = regular, start = 98304, len = 32768, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none
I'm afaid that I understand your request correctly. Is it what you want?
Quoted 13 lines
Quoted 13 lines
Currently the output only contains holes, and for holes, a lot of members makes no sense, like disk_bytenr/disk_num_bytes/offset (even it can be non-zero) and compression.
Thanks,
QuQuoted 4 lines
Thanks,
Sidong
Re: [PATCH v4 2/2] btrfs-progs: cmds: Add subcommand that dumps file extents
Quoted 47 lines · Sidong Yang
Quoted 31 lines · Qu Wenruo
Quoted 28 lines · Qu Wenruo
Quoted 24 lines · Sidong Yang
Quoted 8 lines · David Sterba
Quoted 4 lines · Sidong Yang
This patch adds an subcommand in inspect-internal. It dumps file extents of
the file that user provided. It helps to show the internal information about file extents comprise the file.Do you have an example of the output? That's the most interesting part. Thanks.
Thanks for reply.
This is an example of the output below.# ./btrfs inspect-internal dump-file-extent /mnt/test1 type = regular, start = 2097152, len = 3227648, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 5324800, len = 16728064, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 22052864, len = 8486912, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 30572544, len = 36540416, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 67112960, len = 5299630080, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = noneQuoted 6 lines
Quoted 3 lines
Could you give an example which includes both real (non-hole) extents and real extents (better to include regular, compressed, preallocated and inline).
Tons of typos... I mean to include both holes (like the existing example) and non-holes extents...
Sorry, I had no idea about holes. But I found some test code in xfstests. It helpes me to make hole in file.
xfs_io-c "fpunch 96K 32K"/mnt/a/foobarxfs_io-c "fpunch 64K 128K"/mnt/a/foobarand the example is below.
Quoted 7 lines
# ./btrfs inspect dump-file-extent /mnt/a/foobar type = regular, start = 0, len = 98304, disk_bytenr = 21651456, disk_num_bytes = 4096, offset = 0, compression = zstd type = regular, start = 98304, len = 32768, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = noneI'm afaid that I understand your request correctly. Is it what you want?
This example is much better.
But still, for holes, things like disk_bytenr/disk_num_bytes/offset/compression makes no sense and can be skipped.
Furthermore, for hole/prealloc they need extra type other than "regular"
Thanks,
Qu
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Currently the output only contains holes, and for holes, a lot of members makes no sense, like disk_bytenr/disk_num_bytes/offset (even it can be non-zero) and compression.
Thanks,
QuQuoted 4 lines
Thanks,
Sidong
Re: [PATCH v4 2/2] btrfs-progs: cmds: Add subcommand that dumps file extents
Quoted 56 lines · Qu Wenruo
Quoted 53 lines · Sidong Yang
Quoted 31 lines · Qu Wenruo
Quoted 28 lines · Qu Wenruo
Quoted 24 lines · Sidong Yang
Quoted 8 lines · David Sterba
Quoted 4 lines · Sidong Yang
This patch adds an subcommand in inspect-internal. It dumps file extents of
the file that user provided. It helps to show the internal information about file extents comprise the file.Do you have an example of the output? That's the most interesting part. Thanks.
Thanks for reply.
This is an example of the output below.# ./btrfs inspect-internal dump-file-extent /mnt/test1 type = regular, start = 2097152, len = 3227648, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 5324800, len = 16728064, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 22052864, len = 8486912, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 30572544, len = 36540416, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none type = regular, start = 67112960, len = 5299630080, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = noneQuoted 6 lines
Quoted 3 lines
Could you give an example which includes both real (non-hole) extents and real extents (better to include regular, compressed, preallocated and inline).
Tons of typos... I mean to include both holes (like the existing example) and non-holes extents...
Sorry, I had no idea about holes. But I found some test code in xfstests. It helpes me to make hole in file.
xfs_io-c "fpunch 96K 32K"/mnt/a/foobarxfs_io-c "fpunch 64K 128K"/mnt/a/foobarand the example is below.
# ./btrfs inspect dump-file-extent /mnt/a/foobar type = regular, start = 0, len = 98304, disk_bytenr = 21651456, disk_num_bytes = 4096, offset = 0, compression = zstd type = regular, start = 98304, len = 32768, disk_bytenr = 0, disk_num_bytes = 0, offset = 0, compression = none
Quoted 7 lines
Quoted 1 line
I'm afaid that I understand your request correctly. Is it what you want?
This example is much better.
But still, for holes, things like disk_bytenr/disk_num_bytes/offset/compression makes no sense and can be skipped.
Okay. If disk_bytenr is zero, other information after this would be skipped in next version.
Quoted 2 lines
Furthermore, for hole/prealloc they need extra type other than "regular"
For now, It already has prealloc type. but no hole type. All the types are inline/prealloc/regular/hole? If so, disk_bytenr should be checked before print it's type.
Thanks,
Sidong
Quoted 16 lines
Thanks,
QuQuoted 13 lines
Quoted 13 lines
Quoted 13 lines
Currently the output only contains holes, and for holes, a lot of members makes no sense, like disk_bytenr/disk_num_bytes/offset (even it can be non-zero) and compression.
Thanks,
QuQuoted 4 lines
Thanks,
Sidong