xfsprogs: xfs_logprint misc log decoding issues
cover xfsprogs: xfs_logprint misc log decoding issues
I've been seeing confusing superblock transactions in logprint, this is an attempt to resolve them and make debugging misc buffer updates easier.
Before
$ xfs_logprint -o xfs.image ---------------------------------------------------------------------------- Oper (2): tid: c32589f8 len: 24 clientid: TRANS flags: none BUF: #regs: 2 start blkno: 0 (0x0) len: 1 bmap size: 1 flags: 0x9000 Oper (3): tid: c32589f8 len: 384 clientid: TRANS flags: none SUPER BLOCK Buffer: icount: 6360863066640355328 ifree: 262144 fdblks: 0 frext: 0 ----------------------------------------------------------------------------
After
$ xfs_logprint -o xfs.image ---------------------------------------------------------------------------- Oper (2): tid: c32589f8 len: 24 clientid: TRANS flags: none BUF: #regs: 2 start blkno: 0 (0x0) len: 1 bmap size: 1 flags: 0x9000 Oper (3): tid: c32589f8 len: 384 clientid: TRANS flags: none SUPER BLOCK Buffer: icount: 64 ifree: 61 fdblks: 259564 frext: 0 0 42534658 100000 0 400 0 0 0 0 8 84a2ced5 974f8da4 8fd4b0b3 9a870a19 0 4000200 0 80000000 10 0 81000000 0 82000000 1000000 100 4000000 0 18 a0000 2a4b4 10000001 0 0 0 408090c 19000010 20 0 40000000 0 3d000000 0 ecf50300 0 0 28 ffffffff ffffffff ffffffff ffffffff 0 2000000 0 0 30 0 1000000 8a020000 8a020000 0 0 0 0 38 0 0 0 0 0 0 0 0 40 0 0 0 0 0 0 0 0 48 0 0 0 0 0 0 0 0 50 0 0 0 0 0 0 0 0 58 0 0 0 0 0 0 0 0
----------------------------------------------------------------------------
Donald Douwsma (2):
xfs_logprint: print misc buffers when using -o
xfs_logprint: decode superblock updates correctly
logprint/log_misc.c | 41 ++++++++++++---------------------------- logprint/log_print_all.c | 25 +++++++++++------------- 2 files changed, 23 insertions(+), 43 deletions(-)
Signature · 1 line
2.27.0
PATCH 1/2 xfs_logprint: print misc buffers when using -o
Logprint only dumps raw buffers for unhandled misc buffer types, but this information is generally useful when debugging logprint issues so allow it to print whenever -o is used.
Switch to using the common xlog_print_data function to dump the buffer.
--- logprint/log_misc.c | 19 +++---------------- logprint/log_print_all.c | 2 +- 2 files changed, 4 insertions(+), 17 deletions(-)
logprint/log_misc.c +3 -16
@@ -392,23 +392,10 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) } }else {printf (_ ("BUF DATA\n" )); -if (print_data) { -uint *dp = (uint *)*ptr; -int nums =be32_to_cpu (head->oh_len) >>2 ; -int byte =0 ; - -while (byte < nums) { -if ((byte %8 ) ==0 ) -printf ("%2x " , byte); -printf ("%8x " , *dp); - dp++; - byte++; -if ((byte %8 ) ==0 ) -printf ("\n" ); - } -printf ("\n" ); - } } + +xlog_recover_print_data (*ptr,be32_to_cpu (head->oh_len)); + *ptr +=be32_to_cpu (head->oh_len); }if (head && head->oh_flags &XLOG_CONTINUE_TRANS )
logprint/log_print_all.c +1 -1
@@ -176,8 +176,8 @@ xlog_recover_print_buffer( }else {printf (_ (" BUF DATA\n" ));if (!print_buffer)continue ; -xlog_recover_print_data (p, len); } +xlog_recover_print_data (p, len); } }
Signature · 1 line
2.27.0
Re: [PATCH 1/2] xfs_logprint: print misc buffers when using -o
Quoted 26 lines · Donald Douwsma
Logprint only dumps raw buffers for unhandled misc buffer types, but this information is generally useful when debugging logprint issues so allow it to print whenever -o is used.
Switch to using the common
xlog_print_datafunction to dump the buffer.Signed-off-by Donald Douwsma <[email protected]>--- logprint/log_misc.c | 19 +++---------------- logprint/log_print_all.c | 2 +- 2 files changed, 4 insertions(+), 17 deletions(-)logprint/log_misc.c +0
-6@@ -392,23 +392,10 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) } }else {printf (_ ("BUF DATA\n" )); -if (print_data) { -uint *dp = (uint *)*ptr; -int nums =be32_to_cpu (head->oh_len) >>2 ; -int byte =0 ; - -while (byte < nums) {
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 410
Quoted 10 lines
logprint/log_misc.c +0
-10-if ((byte %8 ) ==0 ) -printf ("%2x " , byte); -printf ("%8x " , *dp); - dp++; - byte++; -if ((byte %8 ) ==0 ) -printf ("\n" ); - } -printf ("\n" ); - }
Nitpicking: One patch to collapse this into a xlog_recover_print_data call as a no-functional-changes cleanup, then a second patch to make the buffer dumps happen any time -D or -o are specified.
TBH the sb/agheader decoders probably need some serious updating to handle newer fields. It's also unfortunate that xfs_db doesn't know how to decode log buffers; adding such a thing would be a neat way to enable targetted fuzzing of log recovery.
--D
Quoted 24 lines
logprint/log_misc.c +3
-0} + +xlog_recover_print_data (*ptr,be32_to_cpu (head->oh_len)); + *ptr +=be32_to_cpu (head->oh_len); }if (head && head->oh_flags &XLOG_CONTINUE_TRANS )logprint/log_print_all.c +1
-1@@ -176,8 +176,8 @@ xlog_recover_print_buffer( }else {printf (_ (" BUF DATA\n" ));if (!print_buffer)continue ; -xlog_recover_print_data (p, len); } +xlog_recover_print_data (p, len); } }Signature · 1 line
2.27.0
Re: [PATCH 1/2] xfs_logprint: print misc buffers when using -o
Quoted 33 lines · Darrick J. Wong
Quoted 32 lines · Donald Douwsma
Logprint only dumps raw buffers for unhandled misc buffer types, but this information is generally useful when debugging logprint issues so allow it to print whenever -o is used.
Switch to using the common
xlog_print_datafunction to dump the buffer.Signed-off-by Donald Douwsma <[email protected]>--- logprint/log_misc.c | 19 +++---------------- logprint/log_print_all.c | 2 +- 2 files changed, 4 insertions(+), 17 deletions(-)logprint/log_misc.c +0
-12@@ -392,23 +392,10 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) } }else {printf (_ ("BUF DATA\n" )); -if (print_data) { -uint *dp = (uint *)*ptr; -int nums =be32_to_cpu (head->oh_len) >>2 ; -int byte =0 ; - -while (byte < nums) { -if ((byte %8 ) ==0 ) -printf ("%2x " , byte); -printf ("%8x " , *dp); - dp++; - byte++; -if ((byte %8 ) ==0 )
Quoted 9 lines
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 410
Quoted 4 lines
logprint/log_misc.c +0
-4-printf ("\n" ); - } -printf ("\n" ); - }Nitpicking: One patch to collapse this into a
xlog_recover_print_datacall as a no-functional-changes cleanup, then a second patch to make the buffer dumps happen any time -D or -o are specified.
ok
Quoted 5 lines
TBH the sb/agheader decoders probably need some serious updating to handle newer fields. It's also unfortunate that
xfs_dbdoesn't know how to decode log buffers; adding such a thing would be a neat way to enable targetted fuzzing of log recovery.
The free space accounting probably isn't the most useful thing to be dumping because of the way they're re-calculated from the AG headers during recovery, but I'd been looking into a sb free space issue and this was confusing me.
It could dump all the fields like xfs_db does, but that would be very verbose.
By decode log buffers do you mean more of the raw log buffer?
Quoted 27 lines
--D
Quoted 24 lines
logprint/log_misc.c +3
-0} + +xlog_recover_print_data (*ptr,be32_to_cpu (head->oh_len)); + *ptr +=be32_to_cpu (head->oh_len); }if (head && head->oh_flags &XLOG_CONTINUE_TRANS )logprint/log_print_all.c +1
-1@@ -176,8 +176,8 @@ xlog_recover_print_buffer( }else {printf (_ (" BUF DATA\n" ));if (!print_buffer)continue ; -xlog_recover_print_data (p, len); } +xlog_recover_print_data (p, len); } }Signature · 1 line
2.27.0
PATCH 2/2 xfs_logprint: decode superblock updates correctly
In reply to Donald DouwsmaBack when the way superblocks are logged changed, logprint wasnt updated updated. Currently logprint displays incorrect accounting information.
SUPER BLOCK Buffer:
icount: 6360863066640355328 ifree: 262144 fdblks: 0 frext: 0
$ printf "0x%x\n" 6360863066640355328 0x5846534200001000
Part of this decodes as 'XFSB', the xfs superblock magic number and not the free space accounting.
Fix this by looking at the entire superblock buffer and using the format structure as is done for the other allocation group headers.
--- logprint/log_misc.c | 22 +++++++++------------- logprint/log_print_all.c | 23 ++++++++++------------- 2 files changed, 19 insertions(+), 26 deletions(-)
logprint/log_misc.c +9 -13
@@ -243,25 +243,21 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)xlog_print_op_header (head, *i, ptr);if (super_block) {printf (_ ("SUPER BLOCK Buffer: " )); -if (be32_to_cpu (head->oh_len) <4 *8 ) { +if (be32_to_cpu (head->oh_len) <sizeof (struct xfs_sb )) {printf (_ ("Out of space\n" )); }else { -__be64 a, b; +struct xfs_sb *sb, sb_s;printf ("\n" ); -/* -* memmove because *ptr may not be 8-byte aligned -*/ -memmove (&a, *ptr,sizeof (__be64)); -memmove (&b, *ptr+8 ,sizeof (__be64)); +/* memmove because *ptr may not be 8-byte aligned */ + sb = &sb_s; +memmove (sb, *ptr,sizeof (struct xfs_sb ));printf (_ ("icount: %llu ifree: %llu " ), - (unsigned long long )be64_to_cpu (a), - (unsigned long long )be64_to_cpu (b)); -memmove (&a, *ptr+16 ,sizeof (__be64)); -memmove (&b, *ptr+24 ,sizeof (__be64)); +be64_to_cpu (sb->sb_icount), +be64_to_cpu (sb->sb_ifree) );printf (_ ("fdblks: %llu frext: %llu\n" ), - (unsigned long long )be64_to_cpu (a), - (unsigned long long )be64_to_cpu (b)); +be64_to_cpu (sb->sb_fdblocks), +be64_to_cpu (sb->sb_frextents)); } super_block =0 ; }else if (be32_to_cpu (*(__be32 *)(*ptr)) ==XFS_AGI_MAGIC ) {
logprint/log_print_all.c +10 -13
@@ -91,22 +91,19 @@ xlog_recover_print_buffer( len = item->ri_buf[i].i_len; i++;if (blkno ==0 ) {/* super block */ -printf (_ (" SUPER Block Buffer:\n" )); +struct xfs_sb *sb = (struct xfs_sb *)p; +printf (_ (" Super Block Buffer: (XFSB)\n" ));if (!print_buffer)continue ; -printf (_ (" icount:%llu ifree:%llu " ), - (unsigned long long ) -be64_to_cpu (*(__be64 *)(p)), - (unsigned long long ) -be64_to_cpu (*(__be64 *)(p+8 ))); -printf (_ ("fdblks:%llu frext:%llu\n" ), - (unsigned long long ) -be64_to_cpu (*(__be64 *)(p+16 )), - (unsigned long long ) -be64_to_cpu (*(__be64 *)(p+24 ))); +printf (_ (" icount:%llu ifree:%llu " ), +be64_to_cpu (sb->sb_icount), +be64_to_cpu (sb->sb_ifree)); +printf (_ ("fdblks:%llu frext:%llu\n" ), +be64_to_cpu (sb->sb_fdblocks), +be64_to_cpu (sb->sb_frextents));printf (_ (" sunit:%u swidth:%u\n" ), -be32_to_cpu (*(__be32 *)(p+56 )), -be32_to_cpu (*(__be32 *)(p+60 ))); +be32_to_cpu (sb->sb_unit), +be32_to_cpu (sb->sb_width)); }else if (be32_to_cpu (*(__be32 *)p) ==XFS_AGI_MAGIC ) {int bucket, buckets; agi = (xfs_agi_t *)p;
Signature · 1 line
2.27.0
Re: [PATCH 2/2] xfs_logprint: decode superblock updates correctly
Quoted 2 lines · Donald Douwsma
Back when the way superblocks are logged changed, logprint wasnt updated updated. Currently logprint displays incorrect accounting
Double 'updated'.
Quoted 41 lines
information.
SUPER BLOCK Buffer:
icount: 6360863066640355328 ifree: 262144 fdblks: 0 frext: 0$ printf "0x%x\n" 6360863066640355328 0x5846534200001000Part of this decodes as 'XFSB', the xfs superblock magic number and not the free space accounting.
Fix this by looking at the entire superblock buffer and using the format structure as is done for the other allocation group headers.
Signed-off-by Donald Douwsma <[email protected]>--- logprint/log_misc.c | 22 +++++++++------------- logprint/log_print_all.c | 23 ++++++++++------------- 2 files changed, 19 insertions(+), 26 deletions(-)logprint/log_misc.c +2
-7@@ -243,25 +243,21 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)xlog_print_op_header (head, *i, ptr);if (super_block) {printf (_ ("SUPER BLOCK Buffer: " )); -if (be32_to_cpu (head->oh_len) <4 *8 ) { +if (be32_to_cpu (head->oh_len) <sizeof (struct xfs_sb )) {printf (_ ("Out of space\n" )); }else { -__be64 a, b; +struct xfs_sb *sb, sb_s;printf ("\n" ); -/* -* memmove because *ptr may not be 8-byte aligned -*/ -memmove (&a, *ptr,sizeof (__be64)); -memmove (&b, *ptr+8 ,sizeof (__be64));
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 257
Quoted 10 lines
logprint/log_misc.c +5
-4+/* memmove because *ptr may not be 8-byte aligned */ + sb = &sb_s; +memmove (sb, *ptr,sizeof (struct xfs_sb ));printf (_ ("icount: %llu ifree: %llu " ), - (unsigned long long )be64_to_cpu (a), - (unsigned long long )be64_to_cpu (b)); -memmove (&a, *ptr+16 ,sizeof (__be64)); -memmove (&b, *ptr+24 ,sizeof (__be64)); +be64_to_cpu (sb->sb_icount), +be64_to_cpu (sb->sb_ifree) );
Extra space at the end ..................................^
Quoted 32 lines
logprint/log_misc.c +2
-2printf (_ ("fdblks: %llu frext: %llu\n" ), - (unsigned long long )be64_to_cpu (a), - (unsigned long long )be64_to_cpu (b)); +be64_to_cpu (sb->sb_fdblocks), +be64_to_cpu (sb->sb_frextents)); } super_block =0 ; }else if (be32_to_cpu (*(__be32 *)(*ptr)) ==XFS_AGI_MAGIC ) {logprint/log_print_all.c +3
-11@@ -91,22 +91,19 @@ xlog_recover_print_buffer( len = item->ri_buf[i].i_len; i++;if (blkno ==0 ) {/* super block */ -printf (_ (" SUPER Block Buffer:\n" )); +struct xfs_sb *sb = (struct xfs_sb *)p; +printf (_ (" Super Block Buffer: (XFSB)\n" ));if (!print_buffer)continue ; -printf (_ (" icount:%llu ifree:%llu " ), - (unsigned long long ) -be64_to_cpu (*(__be64 *)(p)), - (unsigned long long ) -be64_to_cpu (*(__be64 *)(p+8 ))); -printf (_ ("fdblks:%llu frext:%llu\n" ), - (unsigned long long ) -be64_to_cpu (*(__be64 *)(p+16 )), - (unsigned long long ) -be64_to_cpu (*(__be64 *)(p+24 ))); + printf(_(" icount:%llu ifree:%llu "),
logprint/log_print_all.c xlog_recover_print_buffer( · line 106
Quoted 10 lines
logprint/log_print_all.c +7
-2+be64_to_cpu (sb->sb_icount), + be64_to_cpu(sb->sb_ifree)); +printf (_ ("fdblks:%llu frext:%llu\n" ), +be64_to_cpu (sb->sb_fdblocks), +be64_to_cpu (sb->sb_frextents));printf (_ (" sunit:%u swidth:%u\n" ), -be32_to_cpu (*(__be32 *)(p+56 )), -be32_to_cpu (*(__be32 *)(p+60 ))); +be32_to_cpu (sb->sb_unit), +be32_to_cpu (sb->sb_width));
/me wonders if these nearly identical decoder routines ought to be refactored into a common helper?
Also, what happens if logprint encounters a log from before whenever we changed superblock encoding in the log? When was that, anyway?
--D
Quoted 6 lines
logprint/log_print_all.c +0
-0}else if (be32_to_cpu (*(__be32 *)p) ==XFS_AGI_MAGIC ) {int bucket, buckets; agi = (xfs_agi_t *)p;Signature · 1 line
2.27.0
Re: [PATCH 2/2] xfs_logprint: decode superblock updates correctly
Quoted 5 lines · Darrick J. Wong
Quoted 2 lines · Donald Douwsma
Back when the way superblocks are logged changed, logprint wasnt updated updated. Currently logprint displays incorrect accounting
Double 'updated'.
Oops
Quoted 46 lines
Quoted 46 lines
information.
SUPER BLOCK Buffer:
icount: 6360863066640355328 ifree: 262144 fdblks: 0 frext: 0$ printf "0x%x\n" 6360863066640355328 0x5846534200001000Part of this decodes as 'XFSB', the xfs superblock magic number and not the free space accounting.
Fix this by looking at the entire superblock buffer and using the format structure as is done for the other allocation group headers.
Signed-off-by Donald Douwsma <[email protected]>--- logprint/log_misc.c | 22 +++++++++------------- logprint/log_print_all.c | 23 ++++++++++------------- 2 files changed, 19 insertions(+), 26 deletions(-)logprint/log_misc.c +5
-7@@ -243,25 +243,21 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)xlog_print_op_header (head, *i, ptr);if (super_block) {printf (_ ("SUPER BLOCK Buffer: " )); -if (be32_to_cpu (head->oh_len) <4 *8 ) { +if (be32_to_cpu (head->oh_len) <sizeof (struct xfs_sb )) {printf (_ ("Out of space\n" )); }else { -__be64 a, b; +struct xfs_sb *sb, sb_s;printf ("\n" ); -/* -* memmove because *ptr may not be 8-byte aligned -*/ -memmove (&a, *ptr,sizeof (__be64)); -memmove (&b, *ptr+8 ,sizeof (__be64)); +/* memmove because *ptr may not be 8-byte aligned */ + sb = &sb_s; +memmove (sb, *ptr,sizeof (struct xfs_sb )); printf(_("icount: %llu ifree: %llu "),
Quoted 8 lines
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 257
Quoted 6 lines
logprint/log_misc.c +2
-4- (unsigned long long )be64_to_cpu (a), - (unsigned long long) be64_to_cpu(b)); -memmove (&a, *ptr+16 ,sizeof (__be64)); -memmove (&b, *ptr+24 ,sizeof (__be64)); +be64_to_cpu (sb->sb_icount), + be64_to_cpu(sb->sb_ifree) );Extra space at the end ..................................^
ack
Quoted 38 lines
Quoted 38 lines
logprint/log_misc.c +2
-2printf (_ ("fdblks: %llu frext: %llu\n" ), - (unsigned long long )be64_to_cpu (a), - (unsigned long long )be64_to_cpu (b)); +be64_to_cpu (sb->sb_fdblocks), +be64_to_cpu (sb->sb_frextents)); } super_block =0 ; }else if (be32_to_cpu (*(__be32 *)(*ptr)) ==XFS_AGI_MAGIC ) {logprint/log_print_all.c +8
-11@@ -91,22 +91,19 @@ xlog_recover_print_buffer( len = item->ri_buf[i].i_len; i++;if (blkno ==0 ) {/* super block */ -printf (_ (" SUPER Block Buffer:\n" )); +struct xfs_sb *sb = (struct xfs_sb *)p; +printf (_ (" Super Block Buffer: (XFSB)\n" ));if (!print_buffer)continue ; -printf (_ (" icount:%llu ifree:%llu " ), - (unsigned long long ) -be64_to_cpu (*(__be64 *)(p)), - (unsigned long long ) -be64_to_cpu (*(__be64 *)(p+8 ))); -printf (_ ("fdblks:%llu frext:%llu\n" ), - (unsigned long long ) -be64_to_cpu (*(__be64 *)(p+16 )), - (unsigned long long ) -be64_to_cpu (*(__be64 *)(p+24 ))); +printf (_ (" icount:%llu ifree:%llu " ), +be64_to_cpu (sb->sb_icount), +be64_to_cpu (sb->sb_ifree)); +printf (_ ("fdblks:%llu frext:%llu\n" ), +be64_to_cpu (sb->sb_fdblocks), +be64_to_cpu (sb->sb_frextents));
Quoted 8 lines
logprint/log_print_all.c xlog_recover_print_buffer( · line 106
Quoted 5 lines
logprint/log_print_all.c +2
-2printf (_ (" sunit:%u swidth:%u\n" ), -be32_to_cpu (*(__be32 *)(p+56 )), -be32_to_cpu (*(__be32 *)(p+60 ))); +be32_to_cpu (sb->sb_unit), +be32_to_cpu (sb->sb_width));/me wonders if these nearly identical decoder routines ought to be refactored into a common helper?
log_print_all.c seems to be coupled to the log recovery code in libxfs when -t is used, but xfs_log_misc.c does its own thing to decode the records outside of recovery. Its a bit messy.
Quoted 3 lines
Also, what happens if logprint encounters a log from before whenever we changed superblock encoding in the log? When was that, anyway?
... um bad things, it will dump information from further along in the log, possibly beyond the end of the buffer and crash.
I _think_ it was when lazy superblock updates went in, tracking that down would be a better way to work out how to handle this, I'll do some research.
Quoted 10 lines
--D
Quoted 6 lines
logprint/log_print_all.c +0
-0}else if (be32_to_cpu (*(__be32 *)p) ==XFS_AGI_MAGIC ) {int bucket, buckets; agi = (xfs_agi_t *)p;Signature · 1 line
2.27.0