Message ID | 20241011075253.2369053-1-chizhiling@163.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
Series | [v2] xfs_logprint: Fix super block buffer interpretation issue | expand |
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
On Fri, Oct 11, 2024 at 03:52:53PM +0800, Chi Zhiling wrote: > From: Chi Zhiling <chizhiling@kylinos.cn> > > 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 > > Suggested-by: Darrick J. Wong <djwong@kernel.org> > Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn> > --- > logprint/log_misc.c | 17 +++++------------ > 1 file changed, 5 insertions(+), 12 deletions(-) > > diff --git a/logprint/log_misc.c b/logprint/log_misc.c > index 8e86ac34..0da92744 100644 > --- a/logprint/log_misc.c > +++ b/logprint/log_misc.c > @@ -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; Nit: tab between type and variable ^ name With that fixed, Reviewed-by: Darrick J. Wong <djwong@kernel.org> --D > > 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) be64_to_cpu(dsb->sb_icount), > + (unsigned long long) be64_to_cpu(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) be64_to_cpu(dsb->sb_fdblocks), > + (unsigned long long) be64_to_cpu(dsb->sb_frextents)); > } > super_block = 0; > } else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGI_MAGIC) { > -- > 2.43.0 > >
On 2024/10/12 00:36, Darrick J. Wong wrote: > On Fri, Oct 11, 2024 at 03:52:53PM +0800, Chi Zhiling wrote: >> From: Chi Zhiling <chizhiling@kylinos.cn> >> >> 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 >> >> Suggested-by: Darrick J. Wong <djwong@kernel.org> >> Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn> >> --- >> logprint/log_misc.c | 17 +++++------------ >> 1 file changed, 5 insertions(+), 12 deletions(-) >> >> diff --git a/logprint/log_misc.c b/logprint/log_misc.c >> index 8e86ac34..0da92744 100644 >> --- a/logprint/log_misc.c >> +++ b/logprint/log_misc.c >> @@ -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; > Nit: tab between type and variable ^ name Thank you, I will fix it soon chi > > With that fixed, > Reviewed-by: Darrick J. Wong <djwong@kernel.org> > > --D > >> >> 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) be64_to_cpu(dsb->sb_icount), >> + (unsigned long long) be64_to_cpu(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) be64_to_cpu(dsb->sb_fdblocks), >> + (unsigned long long) be64_to_cpu(dsb->sb_frextents)); >> } >> super_block = 0; >> } else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGI_MAGIC) { >> -- >> 2.43.0 >> >>
diff --git a/logprint/log_misc.c b/logprint/log_misc.c index 8e86ac34..0da92744 100644 --- a/logprint/log_misc.c +++ b/logprint/log_misc.c @@ -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) be64_to_cpu(dsb->sb_icount), + (unsigned long long) be64_to_cpu(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) be64_to_cpu(dsb->sb_fdblocks), + (unsigned long long) be64_to_cpu(dsb->sb_frextents)); } super_block = 0; } else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGI_MAGIC) {