1dc728923Sopenharmony_ciFrom d37a9f1818fa04fc91a497b3541ed205804720af Mon Sep 17 00:00:00 2001 2dc728923Sopenharmony_ciFrom: "lihaoxiang (F)" <lihaoxiang9@huawei.com> 3dc728923Sopenharmony_ciDate: Tue, 15 Nov 2022 16:29:55 +0800 4dc728923Sopenharmony_ciSubject: [PATCH] debugfs: fix repeated output problem with `logdump -O -n 5dc728923Sopenharmony_ci <num_trans>` 6dc728923Sopenharmony_ci 7dc728923Sopenharmony_ciPreviously, patch 6e4cc3d5eeb2dfaa055e652b5390beaa6c3d05da introduces 8dc728923Sopenharmony_cithe function of printing the specified number of logs. But there exists 9dc728923Sopenharmony_cia shortage when n is larger than the total number of logs, it dumped the 10dc728923Sopenharmony_ciduplicated records circulately. 11dc728923Sopenharmony_ci 12dc728923Sopenharmony_ciFor example, the disk sda only has three records, but using instruction logdump 13dc728923Sopenharmony_ci-On5, it would output the result as follow: 14dc728923Sopenharmony_ci---------------------------------------------------------------------- 15dc728923Sopenharmony_ciJournal starts at block 1, transaction 6 16dc728923Sopenharmony_ciFound expected sequence 6, type 1 (descriptor block) at block 1 17dc728923Sopenharmony_ciFound expected sequence 6, type 2 (commit block) at block 4 18dc728923Sopenharmony_ciNo magic number at block 5: end of journal. 19dc728923Sopenharmony_ciFound sequence 2 (not 7) at block 7: end of journal. 20dc728923Sopenharmony_ciFound expected sequence 2, type 2 (commit block) at block 7 21dc728923Sopenharmony_ciFound sequence 3 (not 8) at block 8: end of journal. 22dc728923Sopenharmony_ciFound expected sequence 3, type 1 (descriptor block) at block 8 23dc728923Sopenharmony_ciFound sequence 3 (not 8) at block 15: end of journal. 24dc728923Sopenharmony_ciFound expected sequence 3, type 2 (commit block) at block 15 25dc728923Sopenharmony_ciFound sequence 6 (not 9) at block 1: end of journal. <---------begin loop 26dc728923Sopenharmony_ciFound expected sequence 6, type 1 (descriptor block) at block 1 27dc728923Sopenharmony_ciFound sequence 6 (not 9) at block 4: end of journal. 28dc728923Sopenharmony_ciFound expected sequence 6, type 2 (commit block) at block 4 29dc728923Sopenharmony_ciFound sequence 2 (not 10) at block 7: end of journal. 30dc728923Sopenharmony_ciFound expected sequence 2, type 2 (commit block) at block 7 31dc728923Sopenharmony_cilogdump: short read (read 0, expected 1024) while reading journal 32dc728923Sopenharmony_ci 33dc728923Sopenharmony_ciIn this commit, we solve the problem above by exiting dumping if the 34dc728923Sopenharmony_ciblocknr had already encountered, displayed the total number of logs 35dc728923Sopenharmony_cithat the disk only possessed. 36dc728923Sopenharmony_ci 37dc728923Sopenharmony_ciSigned-off-by: lihaoxiang <lihaoxiang9@huawei.com> 38dc728923Sopenharmony_ciSigned-off-by: Theodore Ts'o <tytso@mit.edu> 39dc728923Sopenharmony_ci--- 40dc728923Sopenharmony_ci debugfs/logdump.c | 9 +++++++++ 41dc728923Sopenharmony_ci 1 file changed, 9 insertions(+) 42dc728923Sopenharmony_ci 43dc728923Sopenharmony_cidiff --git a/debugfs/logdump.c b/debugfs/logdump.c 44dc728923Sopenharmony_ciindex 614414e..036b50b 100644 45dc728923Sopenharmony_ci--- a/debugfs/logdump.c 46dc728923Sopenharmony_ci+++ b/debugfs/logdump.c 47dc728923Sopenharmony_ci@@ -376,6 +376,7 @@ static void dump_journal(char *cmdname, FILE *out_file, 48dc728923Sopenharmony_ci journal_header_t *header; 49dc728923Sopenharmony_ci tid_t transaction; 50dc728923Sopenharmony_ci unsigned int blocknr = 0; 51dc728923Sopenharmony_ci+ unsigned int first_transaction_blocknr; 52dc728923Sopenharmony_ci int fc_done; 53dc728923Sopenharmony_ci __u64 total_len; 54dc728923Sopenharmony_ci __u32 maxlen; 55dc728923Sopenharmony_ci@@ -470,10 +471,18 @@ static void dump_journal(char *cmdname, FILE *out_file, 56dc728923Sopenharmony_ci blocknr = 1; 57dc728923Sopenharmony_ci } 58dc728923Sopenharmony_ci 59dc728923Sopenharmony_ci+ first_transaction_blocknr = blocknr; 60dc728923Sopenharmony_ci+ 61dc728923Sopenharmony_ci while (1) { 62dc728923Sopenharmony_ci if (dump_old && (dump_counts != -1) && (cur_counts >= dump_counts)) 63dc728923Sopenharmony_ci break; 64dc728923Sopenharmony_ci 65dc728923Sopenharmony_ci+ if ((blocknr == first_transaction_blocknr) && 66dc728923Sopenharmony_ci+ (cur_counts != 0) && dump_old && (dump_counts != -1)) { 67dc728923Sopenharmony_ci+ fprintf(out_file, "Dump all %lld journal records.\n", cur_counts); 68dc728923Sopenharmony_ci+ break; 69dc728923Sopenharmony_ci+ } 70dc728923Sopenharmony_ci+ 71dc728923Sopenharmony_ci retval = read_journal_block(cmdname, source, 72dc728923Sopenharmony_ci ((ext2_loff_t) blocknr) * blocksize, 73dc728923Sopenharmony_ci buf, blocksize); 74dc728923Sopenharmony_ci-- 75dc728923Sopenharmony_ci1.8.3.1 76dc728923Sopenharmony_ci 77