xfs_logprint: Fix super block buffer interpretation issue
PATCH v4 1/1 xfs_logprint: Fix super block buffer interpretation issue
From: Chi Zhiling <[email protected]>
When using xfs_logprint to interpret the buffer of the super block, the icount will always be 6360863066640355328 (0x5846534200001000). This is because the offset of icount is incorrect, causing xfs_logprint to misinterpret the MAGIC number as icount.
This patch fixes the offset value of the SB counters in xfs_logprint.
Before this patch:
icount: 6360863066640355328 ifree: 5242880 fdblks: 0 frext: 0
After this patch:
icount: 10240 ifree: 4906 fdblks: 37 frext: 0
--- logprint/log_misc.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-)
logprint/log_misc.c +5 -12
@@ -282,22 +282,15 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)if (be32_to_cpu (head->oh_len) <4 *8 ) {printf (_ ("Out of space\n" )); }else { -__be64 a, b; +struct xfs_dsb *dsb = (struct xfs_dsb *) *ptr;printf ("\n" ); -/* -* memmove because *ptr may not be 8-byte aligned -*/ -memmove (&a, *ptr,sizeof (__be64)); -memmove (&b, *ptr+8 ,sizeof (__be64));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)); + (unsigned long long )get_unaligned_be64 (dsb->sb_icount), + (unsigned long long )get_unaligned_be64 (dsb->sb_ifree));printf (_ ("fdblks: %llu frext: %llu\n" ), - (unsigned long long )be64_to_cpu (a), - (unsigned long long )be64_to_cpu (b)); + (unsigned long long )get_unaligned_be64 (dsb->sb_fdblocks), + (unsigned long long )get_unaligned_be64 (dsb->sb_frextents)); } super_block =0 ; }else if (be32_to_cpu (*(__be32 *)(*ptr)) ==XFS_AGI_MAGIC ) {
Signature · 1 line
2.43.0
Quoted 14 lines · Chi Zhiling
From: Chi Zhiling <[email protected]>
When using
xfs_logprintto interpret the buffer of the super block, the icount will always be 6360863066640355328 (0x5846534200001000). This is because the offset of icount is incorrect, causingxfs_logprintto misinterpret the MAGIC number as icount.
This patch fixes the offset value of the SB counters inxfs_logprint.Before this patch:
icount: 6360863066640355328 ifree: 5242880 fdblks: 0 frext: 0After this patch:
icount: 10240 ifree: 4906 fdblks: 37 frext: 0
Quoted 7 lines
Suggested-by Darrick J. Wong <[email protected]>Suggested-by Dave Chinner <[email protected]>Signed-off-by Chi Zhiling <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>--- logprint/log_misc.c | 17 +++++------------
Hmm, I don't think this ever got merged...
but shouldn't log_print_all.c also get fixed? I think it has the same pointer arithmetic problem that could be replaced by get_unaligned_be64 calls just like you did below.
--D
Quoted 39 lines
1 file changed, 5 insertions(+), 12 deletions(-)logprint/log_misc.c +5
-12@@ -282,22 +282,15 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)if (be32_to_cpu (head->oh_len) <4 *8 ) {printf (_ ("Out of space\n" )); }else { -__be64 a, b; +struct xfs_dsb *dsb = (struct xfs_dsb *) *ptr;printf ("\n" ); -/* -* memmove because *ptr may not be 8-byte aligned -*/ -memmove (&a, *ptr,sizeof (__be64)); -memmove (&b, *ptr+8 ,sizeof (__be64));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)); + (unsigned long long )get_unaligned_be64 (dsb->sb_icount), + (unsigned long long )get_unaligned_be64 (dsb->sb_ifree));printf (_ ("fdblks: %llu frext: %llu\n" ), - (unsigned long long )be64_to_cpu (a), - (unsigned long long )be64_to_cpu (b)); + (unsigned long long )get_unaligned_be64 (dsb->sb_fdblocks), + (unsigned long long )get_unaligned_be64 (dsb->sb_frextents)); } super_block =0 ; }else if (be32_to_cpu (*(__be32 *)(*ptr)) ==XFS_AGI_MAGIC ) {Signature · 1 line
2.43.0
Quoted 23 lines · Darrick J. Wong
Quoted 14 lines · Chi Zhiling
From: Chi Zhiling <[email protected]>
When using
xfs_logprintto interpret the buffer of the super block, the icount will always be 6360863066640355328 (0x5846534200001000). This is because the offset of icount is incorrect, causingxfs_logprintto misinterpret the MAGIC number as icount.
This patch fixes the offset value of the SB counters inxfs_logprint.Before this patch:
icount: 6360863066640355328 ifree: 5242880 fdblks: 0 frext: 0After this patch:
icount: 10240 ifree: 4906 fdblks: 37 frext: 0Quoted 7 lines
Suggested-by Darrick J. Wong <[email protected]>Suggested-by Dave Chinner <[email protected]>Signed-off-by Chi Zhiling <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>--- logprint/log_misc.c | 17 +++++------------
Quoted 5 lines
Hmm, I don't think this ever got merged...
but shouldn't
log_print_all.calso get fixed? I think it has the same pointer arithmetic problem that could be replaced byget_unaligned_be64calls just like you did below.
Indeed, the same issue also exists in log_print_all.c. I will fix it in the next push.
Thanks,
Chi Zhiling
Quoted 42 lines
--D
Quoted 39 lines
1 file changed, 5 insertions(+), 12 deletions(-)logprint/log_misc.c +5
-12@@ -282,22 +282,15 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)if (be32_to_cpu (head->oh_len) <4 *8 ) {printf (_ ("Out of space\n" )); }else { -__be64 a, b; +struct xfs_dsb *dsb = (struct xfs_dsb *) *ptr;printf ("\n" ); -/* -* memmove because *ptr may not be 8-byte aligned -*/ -memmove (&a, *ptr,sizeof (__be64)); -memmove (&b, *ptr+8 ,sizeof (__be64));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)); + (unsigned long long )get_unaligned_be64 (dsb->sb_icount), + (unsigned long long )get_unaligned_be64 (dsb->sb_ifree));printf (_ ("fdblks: %llu frext: %llu\n" ), - (unsigned long long )be64_to_cpu (a), - (unsigned long long )be64_to_cpu (b)); + (unsigned long long )get_unaligned_be64 (dsb->sb_fdblocks), + (unsigned long long )get_unaligned_be64 (dsb->sb_frextents)); } super_block =0 ; }else if (be32_to_cpu (*(__be32 *)(*ptr)) ==XFS_AGI_MAGIC ) {Signature · 1 line
2.43.0