dump.f2fs: add -I nid to dump inode by scan full disk
PATCH v2 1/1 dump.f2fs: add -I nid to dump inode by scan full disk
Usage:
dump.f2fs -I [inode nid] /dev/sda
This feature can be useful for some bugs caused by system crash. We not only need dump current valid node page, but alse the history data in disk, which can give some clues for status change of the inode.
--- fsck/dump.c | 29 +++++++++++++++++++++++++++++ fsck/fsck.h | 1 + fsck/main.c | 14 +++++++++++++- man/dump.f2fs.8 | 7 +++++++ 4 files changed, 50 insertions(+), 1 deletion(-)
fsck/dump.c +29 -0
@@ -539,6 +539,35 @@ static bool is_sit_bitmap_set(struct f2fs_sb_info *sbi, u32 blk_addr) (const char *)se->cur_valid_map) != 0; } +void dump_node_scan_disk (struct f2fs_sb_info *sbi,nid_t nid) +{ +struct f2fs_node *node_blk; +pgoff_t blkaddr; +int ret; +pgoff_t start_blkaddr =SM_I (sbi)->main_blkaddr; +pgoff_t end_blkaddr = start_blkaddr + + (SM_I (sbi)->main_segments << sbi->log_blocks_per_seg); + + node_blk =calloc (BLOCK_SZ ,1 ); +ASSERT (node_blk); +MSG (0 ,"Info: scan all nid: %u from block_addr [%lu: %lu]\n" , + nid, start_blkaddr, end_blkaddr); + +for (blkaddr = start_blkaddr; blkaddr < end_blkaddr; blkaddr++) { + ret =dev_read_block (node_blk, blkaddr); +ASSERT (ret >=0 ); +if (le32_to_cpu (node_blk->footer.ino) != nid || +le32_to_cpu (node_blk->footer.nid) != nid) +continue ; +MSG (0 ,"Info: nid: %u, blkaddr: %lu\n" , nid, blkaddr); +MSG (0 ,"node_blk.footer.flag [0x%x]\n" ,le32_to_cpu (node_blk->footer.flag)); +MSG (0 ,"node_blk.footer.cp_ver [%x]\n" , (u32)(cpver_of_node (node_blk))); +print_inode_info (sbi, node_blk,0 ); + } + +free (node_blk); +} +int dump_node (struct f2fs_sb_info *sbi,nid_t nid,int force) {struct node_info ni;
fsck/fsck.h +1 -0
@@ -262,6 +262,7 @@ struct dump_option {int start_ssa;int end_ssa;int32_t blk_addr; +nid_t scan_nid; };extern void nat_dump (struct f2fs_sb_info *,nid_t ,nid_t );
fsck/main.c +13 -1
@@ -93,6 +93,7 @@ void dump_usage()MSG (0 ,"[options]:\n" );MSG (0 ," -d debug level [default:0]\n" );MSG (0 ," -i inode no (hex)\n" ); +MSG (0 ," -I inode no (hex) scan full disk\n" );MSG (0 ," -n [NAT dump nid from #1~#2 (decimal), for all 0~-1]\n" );MSG (0 ," -M show a block map\n" );MSG (0 ," -s [SIT dump segno from #1~#2 (decimal), for all 0~-1]\n" );
@@ -382,7 +383,7 @@ void f2fs_parse_options(int argc, char *argv[]) } }else if (!strcmp ("dump.f2fs" , prog)) {#ifdef WITH_DUMP -const char *option_string ="d:i:n:Ms:Sa:b:V" ; +const char *option_string ="d:i:I:n:Ms:Sa:b:V" ;static struct dump_option dump_opt = { .nid =0 ,/* default root ino */ .start_nat = -1,
@@ -392,6 +393,7 @@ void f2fs_parse_options(int argc, char *argv[]) .start_ssa = -1, .end_ssa = -1, .blk_addr = -1, + .scan_nid = 0, }; c.func =DUMP ;
@@ -424,6 +426,14 @@ void f2fs_parse_options(int argc, char *argv[]) ret =sscanf (optarg,"%x" , &dump_opt.nid);break ; +case 'I' : +if (strncmp (optarg,"0x" ,2 )) + ret =sscanf (optarg,"%d" , + &dump_opt.scan_nid); +else + ret =sscanf (optarg,"%x" , + &dump_opt.scan_nid); +break ;case 'n' : ret = sscanf(optarg, "%d~%d", &dump_opt.start_nat,
@@ -916,6 +926,8 @@ static void do_dump(struct f2fs_sb_info *sbi)dump_info_from_blkaddr (sbi, opt->blk_addr);if (opt->nid)dump_node (sbi, opt->nid,0 ); +if (opt->scan_nid) +dump_node_scan_disk (sbi, opt->scan_nid);print_cp_state (flag);
man/dump.f2fs.8 +7 -0
@@ -10,6 +10,10 @@ dump.f2fs \- retrieve directory and file entries from an F2FS-formated image .I inode number ] [ +.B \-I +.I inode number +] +[ .B \-n .I NAT range ]
@@ -52,6 +56,9 @@ is 0 on success and -1 on failure. .BI \-i " inode number" Specify an inode number to dump out. .TP +.BI \-I " inode number" +Specify an inode number and scan full disk to dump out, include history inode block +.TP .BI \-n " NAT range" Specify a range presented by nids to dump NAT entries. .TP
Signature · 8 lines
2.31.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 28 lines · On 2022/4/18 10:43, Yufen Yu via Linux-f2fs-devel wrote:
Usage:
dump.f2fs -I [inode nid]/dev/sdaThis feature can be useful for some bugs caused by system crash. We not only need dump current valid node page, but alse the history data in disk, which can give some clues for status change of the inode.
Signed-off-by Yufen Yu <[email protected]>--- fsck/dump.c | 29 +++++++++++++++++++++++++++++ fsck/fsck.h | 1 + fsck/main.c | 14 +++++++++++++- man/dump.f2fs.8 | 7 +++++++ 4 files changed, 50 insertions(+), 1 deletion(-)fsck/dump.c +5
-0@@ -539,6 +539,35 @@ static bool is_sit_bitmap_set(struct f2fs_sb_info *sbi, u32 blk_addr) (const char *)se->cur_valid_map) != 0; } +void dump_node_scan_disk (struct f2fs_sb_info *sbi,nid_t nid) +{ +struct f2fs_node *node_blk; +pgoff_t blkaddr; +int ret;
fsck/dump.c static bool is_sit_bitmap_set(struct f2fs_sb_info *sbi, u32 blk_addr) · line 556
Quoted 10 lines
fsck/dump.c +10
-0+pgoff_t start_blkaddr =SM_I (sbi)->main_blkaddr; +pgoff_t end_blkaddr = start_blkaddr + + (SM_I (sbi)->main_segments << sbi->log_blocks_per_seg); + + node_blk =calloc (BLOCK_SZ ,1 ); +ASSERT (node_blk); +MSG (0 ,"Info: scan all nid: %u from block_addr [%lu: %lu]\n" , + nid, start_blkaddr, end_blkaddr); + +for (blkaddr = start_blkaddr; blkaddr < end_blkaddr; blkaddr++) {
Shouldn't we skip data segment? otherwise it's possible to encounter data collision in traversed data block.
Thanks,
Quoted 98 lines
fsck/dump.c +14
-0+ ret =dev_read_block (node_blk, blkaddr); +ASSERT (ret >=0 ); +if (le32_to_cpu (node_blk->footer.ino) != nid || +le32_to_cpu (node_blk->footer.nid) != nid) +continue ; +MSG (0 ,"Info: nid: %u, blkaddr: %lu\n" , nid, blkaddr); +MSG (0 ,"node_blk.footer.flag [0x%x]\n" ,le32_to_cpu (node_blk->footer.flag)); +MSG (0 ,"node_blk.footer.cp_ver [%x]\n" , (u32)(cpver_of_node (node_blk))); +print_inode_info (sbi, node_blk,0 ); + } + +free (node_blk); +} +int dump_node (struct f2fs_sb_info *sbi,nid_t nid,int force) {struct node_info ni;fsck/fsck.h +1
-0@@ -262,6 +262,7 @@ struct dump_option {int start_ssa;int end_ssa;int32_t blk_addr; +nid_t scan_nid; };extern void nat_dump (struct f2fs_sb_info *,nid_t ,nid_t );fsck/main.c +13
-1@@ -93,6 +93,7 @@ void dump_usage()MSG (0 ,"[options]:\n" );MSG (0 ," -d debug level [default:0]\n" );MSG (0 ," -i inode no (hex)\n" ); +MSG (0 ," -I inode no (hex) scan full disk\n" );MSG (0 ," -n [NAT dump nid from #1~#2 (decimal), for all 0~-1]\n" );MSG (0 ," -M show a block map\n" );MSG (0 ," -s [SIT dump segno from #1~#2 (decimal), for all 0~-1]\n" );@@ -382,7 +383,7 @@ void f2fs_parse_options(int argc, char *argv[]) } }else if (!strcmp ("dump.f2fs" , prog)) {#ifdef WITH_DUMP -const char *option_string ="d:i:n:Ms:Sa:b:V" ; +const char *option_string ="d:i:I:n:Ms:Sa:b:V" ;static struct dump_option dump_opt = { .nid =0 ,/* default root ino */ .start_nat = -1,@@ -392,6 +393,7 @@ void f2fs_parse_options(int argc, char *argv[]) .start_ssa = -1, .end_ssa = -1, .blk_addr = -1, + .scan_nid = 0, }; c.func =DUMP ;@@ -424,6 +426,14 @@ void f2fs_parse_options(int argc, char *argv[]) ret =sscanf (optarg,"%x" , &dump_opt.nid);break ; +case 'I' : +if (strncmp (optarg,"0x" ,2 )) + ret =sscanf (optarg,"%d" , + &dump_opt.scan_nid); +else + ret =sscanf (optarg,"%x" , + &dump_opt.scan_nid); +break ;case 'n' : ret = sscanf(optarg, "%d~%d", &dump_opt.start_nat,@@ -916,6 +926,8 @@ static void do_dump(struct f2fs_sb_info *sbi)dump_info_from_blkaddr (sbi, opt->blk_addr);if (opt->nid)dump_node (sbi, opt->nid,0 ); +if (opt->scan_nid) +dump_node_scan_disk (sbi, opt->scan_nid);print_cp_state (flag);man/dump.f2fs.8 +4
-0@@ -10,6 +10,10 @@ dump.f2fs \- retrieve directory and file entries from an F2FS-formated image .I inode number ] [ +.B \-I +.I inode number +] +[ .B \-n .I NAT range ]
man/dump.f2fs.8 is 0 on success and -1 on failure. · line 64
Quoted 9 lines
man/dump.f2fs.8 +3
-0@@ -52,6 +56,9 @@ is 0 on success and -1 on failure. .BI \-i " inode number" Specify an inode number to dump out. .TP +.BI \-I " inode number" +Specify an inode number and scan full disk to dump out, include history inode block +.TP .BI \-n " NAT range" Specify a range presented by nids to dump NAT entries. .TP
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 33 lines · Chao Yu
Quoted 32 lines · On 2022/4/18 10:43, Yufen Yu via Linux-f2fs-devel wrote:
Usage:
dump.f2fs -I [inode nid]/dev/sdaThis feature can be useful for some bugs caused by system crash. We not only need dump current valid node page, but alse the history data in disk, which can give some clues for status change of the inode.
Signed-off-by Yufen Yu <[email protected]>---
fsck/dump.c | 29 +++++++++++++++++++++++++++++ fsck/fsck.h | 1 + fsck/main.c | 14 +++++++++++++- man/dump.f2fs.8 | 7 +++++++ 4 files changed, 50 insertions(+), 1 deletion(-)fsck/dump.c +10
-0@@ -539,6 +539,35 @@ static bool is_sit_bitmap_set(struct f2fs_sb_info *sbi, u32 blk_addr) (const char *)se->cur_valid_map) != 0; } +void dump_node_scan_disk (struct f2fs_sb_info *sbi,nid_t nid) +{ + struct f2fs_node *node_blk; + pgoff_t blkaddr; + int ret; + pgoff_t start_blkaddr = SM_I(sbi)->main_blkaddr; + pgoff_t end_blkaddr = start_blkaddr + + (SM_I(sbi)->main_segments << sbi->log_blocks_per_seg); + + node_blk = calloc(BLOCK_SZ, 1);
Quoted 9 lines
fsck/dump.c static bool is_sit_bitmap_set(struct f2fs_sb_info *sbi, u32 blk_addr) · line 556
Quoted 5 lines
fsck/dump.c +5
-0+ ASSERT(node_blk); + MSG(0, "Info: scan all nid: %u from block_addr [%lu: %lu]\n", + nid, start_blkaddr, end_blkaddr); + + for (blkaddr = start_blkaddr; blkaddr < end_blkaddr; blkaddr++) {Shouldn't we skip data segment? otherwise it's possible to encounter data collision in traversed data block.
Yeah, skipping data segment can be more strict. But, I am not sure segment type is correct for some invalid segments. To make things more easy, I just traverse all main blocks and identify the target inode by checking footer.ino and footer.nid.
Thanks,
Quoted 98 lines
Thanks,
Quoted 96 lines
fsck/dump.c +14
-0+ ret = dev_read_block(node_blk, blkaddr); + ASSERT(ret >= 0); + if (le32_to_cpu(node_blk->footer.ino) != nid || + le32_to_cpu(node_blk->footer.nid) != nid) + continue; + MSG(0, "Info: nid: %u, blkaddr: %lu\n", nid, blkaddr); + MSG(0, "node_blk.footer.flag [0x%x]\n", le32_to_cpu(node_blk->footer.flag)); + MSG(0, "node_blk.footer.cp_ver [%x]\n", (u32)(cpver_of_node(node_blk))); + print_inode_info(sbi, node_blk, 0); + } + + free(node_blk); +} + int dump_node(struct f2fs_sb_info *sbi, nid_t nid, int force) { struct node_info ni;fsck/fsck.h +1
-0@@ -262,6 +262,7 @@ struct dump_option { int start_ssa; int end_ssa; int32_t blk_addr; + nid_t scan_nid; }; extern void nat_dump(struct f2fs_sb_info *, nid_t, nid_t);fsck/main.c +2
-1@@ -93,6 +93,7 @@ void dump_usage() MSG(0, "[options]:\n"); MSG(0, " -d debug level [default:0]\n"); MSG(0, " -i inode no (hex)\n"); + MSG(0, " -I inode no (hex) scan full disk\n"); MSG(0, " -n [NAT dump nid from #1~#2 (decimal), for all 0~-1]\n"); MSG(0, " -M show a block map\n"); MSG(0, " -s [SIT dump segno from #1~#2 (decimal), for all 0~-1]\n");@@ -382,7 +383,7 @@ void f2fs_parse_options(int argc, char *argv[]) } } else if (!strcmp("dump.f2fs", prog)) { #ifdef WITH_DUMP - const char *option_string = "d:i:n:Ms:Sa:b:V"; + const char *option_string = "d:i:I:n:Ms:Sa:b:V"; static struct dump_option dump_opt = {.nid = 0, /* default root ino */
.start_nat = -1,fsck/main.c +9
-0@@ -392,6 +393,7 @@ void f2fs_parse_options(int argc, char *argv[]) .start_ssa = -1, .end_ssa = -1, .blk_addr = -1, + .scan_nid = 0, }; c.func = DUMP;@@ -424,6 +426,14 @@ void f2fs_parse_options(int argc, char *argv[]) ret = sscanf(optarg, "%x", &dump_opt.nid); break; + case 'I': + if (strncmp(optarg, "0x", 2)) + ret = sscanf(optarg, "%d", + &dump_opt.scan_nid); + else + ret = sscanf(optarg, "%x", + &dump_opt.scan_nid); + break;case 'n':
ret = sscanf(optarg, "%d~%d", &dump_opt.start_nat,fsck/main.c +2
-0@@ -916,6 +926,8 @@ static void do_dump(struct f2fs_sb_info *sbi) dump_info_from_blkaddr(sbi, opt->blk_addr); if (opt->nid) dump_node(sbi, opt->nid, 0); + if (opt->scan_nid) + dump_node_scan_disk(sbi, opt->scan_nid); print_cp_state(flag);man/dump.f2fs.8 +0
-0@@ -10,6 +10,10 @@ dump.f2fs \- retrieve directory and file entries from an F2FS-formated image.I inode number
]
[
+.B \-I
+.I inode number
+]
+[
.B \-n
.I NAT range
]man/dump.f2fs.8 +0
-0@@ -52,6 +56,9 @@ is 0 on success and -1 on failure..BI \-i " inode number"
Specify an inode number to dump out.
Quoted 8 lines
Quoted 7 lines
.TP
+.BI \-I " inode number"
+Specify an inode number and scan full disk to dump out, include history inode block +.TP
.BI \-n " NAT range"
Specify a range presented by nids to dump NAT entries.
.TP.
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 46 lines · On 2022/4/20 15:27, Yufen Yu via Linux-f2fs-devel wrote:
Quoted 33 lines · Chao Yu
Quoted 32 lines · On 2022/4/18 10:43, Yufen Yu via Linux-f2fs-devel wrote:
Usage:
dump.f2fs -I [inode nid]/dev/sdaThis feature can be useful for some bugs caused by system crash. We not only need dump current valid node page, but alse the history data in disk, which can give some clues for status change of the inode.
Signed-off-by Yufen Yu <[email protected]>---
fsck/dump.c | 29 +++++++++++++++++++++++++++++ fsck/fsck.h | 1 + fsck/main.c | 14 +++++++++++++- man/dump.f2fs.8 | 7 +++++++ 4 files changed, 50 insertions(+), 1 deletion(-)fsck/dump.c +10
-0@@ -539,6 +539,35 @@ static bool is_sit_bitmap_set(struct f2fs_sb_info *sbi, u32 blk_addr) (const char *)se->cur_valid_map) != 0; } +void dump_node_scan_disk (struct f2fs_sb_info *sbi,nid_t nid) +{ + struct f2fs_node *node_blk; + pgoff_t blkaddr; + int ret; + pgoff_t start_blkaddr = SM_I(sbi)->main_blkaddr; + pgoff_t end_blkaddr = start_blkaddr + + (SM_I(sbi)->main_segments << sbi->log_blocks_per_seg); + + node_blk = calloc(BLOCK_SZ, 1);Quoted 9 lines
fsck/dump.c static bool is_sit_bitmap_set(struct f2fs_sb_info *sbi, u32 blk_addr) · line 556
Quoted 5 lines
fsck/dump.c +5
-0+ ASSERT(node_blk); + MSG(0, "Info: scan all nid: %u from block_addr [%lu: %lu]\n", + nid, start_blkaddr, end_blkaddr); + + for (blkaddr = start_blkaddr; blkaddr < end_blkaddr; blkaddr++) {Shouldn't we skip data segment? otherwise it's possible to encounter data collision in traversed data block.
Quoted 3 lines
Yeah, skipping data segment can be more strict. But, I am not sure segment type is correct for some invalid segments. To make things more easy, I just traverse all main blocks and identify the target inode by checking footer.ino and footer.nid.
Even if segment is invalid, block type in segment should be consistent with the segtype recorded in SIT, right?
Thanks,
Quoted 112 lines
Thanks,
Quoted 98 lines
Thanks,
Quoted 96 lines
fsck/dump.c +14
-0+ ret = dev_read_block(node_blk, blkaddr); + ASSERT(ret >= 0); + if (le32_to_cpu(node_blk->footer.ino) != nid || + le32_to_cpu(node_blk->footer.nid) != nid) + continue; + MSG(0, "Info: nid: %u, blkaddr: %lu\n", nid, blkaddr); + MSG(0, "node_blk.footer.flag [0x%x]\n", le32_to_cpu(node_blk->footer.flag)); + MSG(0, "node_blk.footer.cp_ver [%x]\n", (u32)(cpver_of_node(node_blk))); + print_inode_info(sbi, node_blk, 0); + } + + free(node_blk); +} + int dump_node(struct f2fs_sb_info *sbi, nid_t nid, int force) { struct node_info ni;fsck/fsck.h +1
-0@@ -262,6 +262,7 @@ struct dump_option { int start_ssa; int end_ssa; int32_t blk_addr; + nid_t scan_nid; }; extern void nat_dump(struct f2fs_sb_info *, nid_t, nid_t);fsck/main.c +2
-1@@ -93,6 +93,7 @@ void dump_usage() MSG(0, "[options]:\n"); MSG(0, " -d debug level [default:0]\n"); MSG(0, " -i inode no (hex)\n"); + MSG(0, " -I inode no (hex) scan full disk\n"); MSG(0, " -n [NAT dump nid from #1~#2 (decimal), for all 0~-1]\n"); MSG(0, " -M show a block map\n"); MSG(0, " -s [SIT dump segno from #1~#2 (decimal), for all 0~-1]\n");@@ -382,7 +383,7 @@ void f2fs_parse_options(int argc, char *argv[]) } } else if (!strcmp("dump.f2fs", prog)) { #ifdef WITH_DUMP - const char *option_string = "d:i:n:Ms:Sa:b:V"; + const char *option_string = "d:i:I:n:Ms:Sa:b:V"; static struct dump_option dump_opt = {.nid = 0, /* default root ino */
.start_nat = -1,fsck/main.c +9
-0@@ -392,6 +393,7 @@ void f2fs_parse_options(int argc, char *argv[]) .start_ssa = -1, .end_ssa = -1, .blk_addr = -1, + .scan_nid = 0, }; c.func = DUMP;@@ -424,6 +426,14 @@ void f2fs_parse_options(int argc, char *argv[]) ret = sscanf(optarg, "%x", &dump_opt.nid); break; + case 'I': + if (strncmp(optarg, "0x", 2)) + ret = sscanf(optarg, "%d", + &dump_opt.scan_nid); + else + ret = sscanf(optarg, "%x", + &dump_opt.scan_nid); + break;case 'n':
ret = sscanf(optarg, "%d~%d", &dump_opt.start_nat,fsck/main.c +2
-0@@ -916,6 +926,8 @@ static void do_dump(struct f2fs_sb_info *sbi) dump_info_from_blkaddr(sbi, opt->blk_addr); if (opt->nid) dump_node(sbi, opt->nid, 0); + if (opt->scan_nid) + dump_node_scan_disk(sbi, opt->scan_nid); print_cp_state(flag);man/dump.f2fs.8 +0
-0@@ -10,6 +10,10 @@ dump.f2fs \- retrieve directory and file entries from an F2FS-formated image.I inode number
]
[
+.B \-I
+.I inode number
+]
+[
.B \-n
.I NAT range
]man/dump.f2fs.8 +0
-0@@ -52,6 +56,9 @@ is 0 on success and -1 on failure..BI \-i " inode number"
Specify an inode number to dump out.Quoted 8 lines
Quoted 7 lines
.TP
+.BI \-I " inode number"
+Specify an inode number and scan full disk to dump out, include history inode block +.TP
.BI \-n " NAT range"
Specify a range presented by nids to dump NAT entries.
.TP.
Quoted 4 lines
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel