xfs_logprint: Fix super block buffer interpretation issue
PATCH 1/1 xfs_logprint: Fix super block buffer interpretation issue
From: chizhiling <[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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
logprint/log_misc.c +4 -4
@@ -288,13 +288,13 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)/* * memmove because *ptr may not be 8-byte aligned */ -memmove (&a, *ptr,sizeof (__be64)); -memmove (&b, *ptr+8 ,sizeof (__be64)); +memmove (&a, *ptr + offsetof(struct xfs_dsb , sb_icount),sizeof (__be64)); +memmove (&b, *ptr + offsetof(struct xfs_dsb , sb_ifree),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)); +memmove (&a, *ptr + offsetof(struct xfs_dsb , sb_fdblocks),sizeof (__be64)); +memmove (&b, *ptr + offsetof(struct xfs_dsb , sb_frextents),sizeof (__be64));printf (_ ("fdblks: %llu frext: %llu\n" ), (unsigned long long )be64_to_cpu (a), (unsigned long long )be64_to_cpu (b));
Signature · 1 line
2.43.0
Quoted 24 lines · Chi Zhiling
From: chizhiling <[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: 0Signed-off-by chizhiling <[email protected]>--- logprint/log_misc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)logprint/log_misc.c +0
-0
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 292
Quoted 5 lines
logprint/log_misc.c +0
-2@@ -288,13 +288,13 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)/* * memmove because *ptr may not be 8-byte aligned */ -memmove (&a, *ptr,sizeof (__be64)); -memmove (&b, *ptr+8 ,sizeof (__be64));
How did this ever work?? This even looks wrong in "Release_1.0.0".
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 292
Quoted 2 lines
logprint/log_misc.c +2
-0+memmove (&a, *ptr + offsetof(struct xfs_dsb , sb_icount),sizeof (__be64)); +memmove (&b, *ptr + offsetof(struct xfs_dsb , sb_ifree),sizeof (__be64));
Why not do:
struct xfs_dsb *dsb = *ptr; memcpy(&a, &dsb->sb_icount, sizeof(a));
or better yet, skip the indirection and do
printf(_("icount: %llu ifree: %llu "),
(unsigned long long)be64_to_cpu(dsb->sb_icount),
(unsigned long long)be64_to_cpu(dsb->sb_ifree));Hm?
--D
Quoted 13 lines
logprint/log_misc.c +2
-2printf (_ ("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)); +memmove (&a, *ptr + offsetof(struct xfs_dsb , sb_fdblocks),sizeof (__be64)); +memmove (&b, *ptr + offsetof(struct xfs_dsb , sb_frextents),sizeof (__be64));printf (_ ("fdblks: %llu frext: %llu\n" ), (unsigned long long )be64_to_cpu (a), (unsigned long long )be64_to_cpu (b));Signature · 1 line
2.43.0
Quoted 20 lines · Darrick J. Wong
Quoted 19 lines · Chi Zhiling
From: chizhiling <[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: 0Signed-off-by chizhiling <[email protected]>--- logprint/log_misc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 12 lines
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 292
Quoted 10 lines
logprint/log_misc.c +0
-2@@ -288,13 +288,13 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)/* * memmove because *ptr may not be 8-byte aligned */ -memmove (&a, *ptr,sizeof (__be64)); -memmove (&b, *ptr+8 ,sizeof (__be64));How did this ever work?? This even looks wrong in "Release_1.0.0".
Yes, I was surprised when I find this issue
Quoted 8 lines
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 292
Quoted 2 lines
logprint/log_misc.c +2
-0+memmove (&a, *ptr + offsetof(struct xfs_dsb , sb_icount),sizeof (__be64)); +memmove (&b, *ptr + offsetof(struct xfs_dsb , sb_ifree),sizeof (__be64));Why not do:
struct xfs_dsb *dsb = *ptr; memcpy(&a, &dsb->sb_icount, sizeof(a));
Quoted 7 lines
or better yet, skip the indirection and do
printf(_("icount: %llu ifree: %llu "), (unsigned long long)be64_to_cpu(dsb->sb_icount), (unsigned long long)be64_to_cpu(dsb->sb_ifree));Hm?
Yes, of course we can do it this way, I just want the fix patch to look smaller :)
I think both ok.
chi
Quoted 16 lines
--D
Quoted 13 lines
logprint/log_misc.c +2
-2printf (_ ("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)); +memmove (&a, *ptr + offsetof(struct xfs_dsb , sb_fdblocks),sizeof (__be64)); +memmove (&b, *ptr + offsetof(struct xfs_dsb , sb_frextents),sizeof (__be64));printf (_ ("fdblks: %llu frext: %llu\n" ), (unsigned long long )be64_to_cpu (a), (unsigned long long )be64_to_cpu (b));Signature · 1 line
2.43.0
Quoted 22 lines · Chi Zhiling
Quoted 20 lines · Darrick J. Wong
Quoted 19 lines · Chi Zhiling
From: chizhiling <[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: 0Signed-off-by chizhiling <[email protected]>--- logprint/log_misc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 7 lines
Quoted 7 lines
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 289
Quoted 7 lines
logprint/log_misc.c +0
-0@@ -288,13 +288,13 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)/* * memmove because *ptr may not be 8-byte aligned
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is important. I'll come back to it.
Quoted 6 lines
Quoted 5 lines
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 292
Quoted 3 lines
logprint/log_misc.c +0
-2*/ -memmove (&a, *ptr,sizeof (__be64)); -memmove (&b, *ptr+8 ,sizeof (__be64));How did this ever work?? This even looks wrong in "Release_1.0.0".
Yes, I was surprised when I find this issue
I"ve never cared about these values when doing diagnosis because lazy-count means they aren't guaranteed to be correct except at unmount. At which point, the correct values are generally found in the superblock. IOWs, the values are largely meaningless whether they are correct or not, so nobody has really cared enough about this to bother fixing it...
Quoted 10 lines
Quoted 10 lines
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 292
Quoted 2 lines
logprint/log_misc.c +2
-0+memmove (&a, *ptr + offsetof(struct xfs_dsb , sb_icount),sizeof (__be64)); +memmove (&b, *ptr + offsetof(struct xfs_dsb , sb_ifree),sizeof (__be64));Why not do:
struct xfs_dsb *dsb = *ptr; memcpy(&a, &dsb->sb_icount, sizeof(a));or better yet, skip the indirection and do
Quoted 8 lines
Quoted 5 lines
printf(_("icount: %llu ifree: %llu "), (unsigned long long)be64_to_cpu(dsb->sb_icount), (unsigned long long)be64_to_cpu(dsb->sb_ifree));Hm?
Yes, of course we can do it this way, I just want the fix patch to look smaller :)
This won't work on platforms where we can't do 4-byte aligned 64 bit accesses (various risc archs), hence the comment above about using memmove.
It should work if we use get_unaligned_be64() rather than be64_to_cpu() - I would suggest that all such structure decoding in logprint would need to do the same thing...
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 47 lines · Chi Zhiling
Quoted 38 lines · Dave Chinner
Quoted 21 lines · Chi Zhiling
Quoted 20 lines · Darrick J. Wong
Quoted 19 lines · Chi Zhiling
From: chizhiling<[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: 0Signed-off-by chizhiling<[email protected]>--- logprint/log_misc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)Quoted 7 lines
Quoted 7 lines
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 289
Quoted 7 lines
logprint/log_misc.c +0
-0@@ -288,13 +288,13 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)/* * memmove because *ptr may not be 8-byte aligned ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^This is important. I'll come back to it.
Quoted 5 lines
Quoted 5 lines
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 292
Quoted 3 lines
logprint/log_misc.c +0
-2*/ -memmove (&a, *ptr,sizeof (__be64)); -memmove (&b, *ptr+8 ,sizeof (__be64));How did this ever work?? This even looks wrong in "Release_1.0.0".
Quoted 7 lines
Quoted 1 line
Yes, I was surprised when I find this issue
I"ve never cared about these values when doing diagnosis because lazy-count means they aren't guaranteed to be correct except at unmount. At which point, the correct values are generally found in the superblock. IOWs, the values are largely meaningless whether they are correct or not, so nobody has really cared enough about this to bother fixing it...
Quoted 2 lines
Because I got a log which shows that the fdblocks was (-8), it caused the filesystem to fail mounting again. 'SB summary counter sanity check failed'
What kernel? Because AFAIK, that was fixed in commit 58f880711f2b ("xfs: make sure sb_fdblocks is non-negative") in 6.10...
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 47 lines · Dave Chinner
Quoted 46 lines · Chi Zhiling
Quoted 45 lines · Dave Chinner
Quoted 21 lines · Chi Zhiling
Quoted 20 lines · Darrick J. Wong
Quoted 19 lines · Chi Zhiling
From: chizhiling<[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: 0Signed-off-by chizhiling<[email protected]>--- logprint/log_misc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)Quoted 7 lines
Quoted 7 lines
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 289
Quoted 7 lines
logprint/log_misc.c +0
-0@@ -288,13 +288,13 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)/* * memmove because *ptr may not be 8-byte aligned ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^This is important. I'll come back to it.
Quoted 6 lines
Quoted 5 lines
logprint/log_misc.c xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops) · line 292
Quoted 3 lines
logprint/log_misc.c +0
-2*/ -memmove (&a, *ptr,sizeof (__be64)); -memmove (&b, *ptr+8 ,sizeof (__be64));How did this ever work?? This even looks wrong in "Release_1.0.0".
Yes, I was surprised when I find this issue
I"ve never cared about these values when doing diagnosis because lazy-count means they aren't guaranteed to be correct except at unmount. At which point, the correct values are generally found in the superblock. IOWs, the values are largely meaningless whether they are correct or not, so nobody has really cared enough about this to bother fixing it...
Quoted 4 lines
Quoted 2 lines
Because I got a log which shows that the fdblocks was (-8), it caused the filesystem to fail mounting again. 'SB summary counter sanity check failed'
What kernel? Because AFAIK, that was fixed in commit
58f880711f2b("xfs: make suresb_fdblocksis non-negative") in 6.10...
It's a 4.19 kernel. As you said, the fdblocks is meaningless, I think that patch (commit 58f880711f2b) is enough to fix the issue.
Thank you for your reminding.
chi