diff mbox

[v2] xfs_db: update sector size when type is set

Message ID 20170622234535.30942-1-billodo@redhat.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Bill O'Donnell June 22, 2017, 11:45 p.m. UTC
xfs_db doesn't take sector size into account when setting type.
This can result in an errant crc. For example, with a sector size
of 4096:

xfs_db> agi 0
xfs_db> p crc
crc = 0xab85043e (correct)
xfs_db> daddr
current daddr is 16
xfs_db> daddr 42
xfs_db> daddr 16
xfs_db> type agi
Metadata CRC error detected at xfs_agi block 0x10/0x200
xfs_db> p crc
crc = 0xab85043e (bad)

When xfs_db sets the new daddr in daddr_f, it does so with one
BBSIZE sector (512). Changing the type doesn't change the size
of the current buffer in iocur_top, so the checksum is calculated
on the wrong length for the type (when the actual sector size > BBSIZE (512)).

For types with fields, reread the buffer to pick up the correct size for
the new type when it gets set. Facilitate the reread by setting the cursor
with set_cur().

Signed-off-by: Bill O'Donnell <billodo@redhat.com>
---
v2: correction to argument 3 in call to set_cur: compute and pass basic block count;
    add comment regarding conditional call to set_cur.
    

 db/io.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Carlos Maiolino June 23, 2017, 10:16 a.m. UTC | #1
Hey Bill,

> diff --git a/db/io.c b/db/io.c
> index 9918a51..792cc0a 100644
> --- a/db/io.c
> +++ b/db/io.c
> @@ -615,7 +615,13 @@ set_iocur_type(
>  	const typ_t	*t)
>  {
>  	struct xfs_buf	*bp = iocur_top->bp;
> +	int bb_count;
>  
> +	/* adjust cursor for types that contain fields */
> +	if (t->fields) {
> +		bb_count = BTOBB(byteize(fsize(t->fields, iocur_top->data, 0, 0)));

Doesn't byteize() requires:

#include "bit.h"

?

I can't build xfsprogs with this patch without including bit.h

In file included from ../include/xfs.h:68:0,
                 from ../include/libxfs.h:24,
                 from io.c:19:
io.c: In function ‘set_iocur_type’:
io.c:600:20: warning: implicit declaration of function ‘byteize’
[-Wimplicit-function-declaration]
   bb_count = BTOBB(byteize(fsize(t->fields, iocur_top->data, 0, 0)));
                    ^


Although, after including it, the patch works fine, fixes the problem with
different sector sizes.

After fixing the include above, you can add:

Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>


Cheers


> +		set_cur(t, iocur_top->bb, bb_count, DB_RING_IGN, NULL);
> +	}
>  	iocur_top->typ = t;
>  
>  	/* verify the buffer if the type has one. */
> -- 
> 2.9.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bill O'Donnell June 23, 2017, 10:26 a.m. UTC | #2
On Fri, Jun 23, 2017 at 12:16:02PM +0200, Carlos Maiolino wrote:
> Hey Bill,
> 
> > diff --git a/db/io.c b/db/io.c
> > index 9918a51..792cc0a 100644
> > --- a/db/io.c
> > +++ b/db/io.c
> > @@ -615,7 +615,13 @@ set_iocur_type(
> >  	const typ_t	*t)
> >  {
> >  	struct xfs_buf	*bp = iocur_top->bp;
> > +	int bb_count;
> >  
> > +	/* adjust cursor for types that contain fields */
> > +	if (t->fields) {
> > +		bb_count = BTOBB(byteize(fsize(t->fields, iocur_top->data, 0, 0)));
> 
> Doesn't byteize() requires:
> 
> #include "bit.h"
> 
> ?

Gah! Yes it's required. I had it on my test box, but missed it
in my v2 submit. I'll fix it.

Thanks!
Bill


> 
> I can't build xfsprogs with this patch without including bit.h
> 
> In file included from ../include/xfs.h:68:0,
>                  from ../include/libxfs.h:24,
>                  from io.c:19:
> io.c: In function ‘set_iocur_type’:
> io.c:600:20: warning: implicit declaration of function ‘byteize’
> [-Wimplicit-function-declaration]
>    bb_count = BTOBB(byteize(fsize(t->fields, iocur_top->data, 0, 0)));
>                     ^
> 
> 
> Although, after including it, the patch works fine, fixes the problem with
> different sector sizes.
> 
> After fixing the include above, you can add:
> 
> Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
> 
> 
> Cheers
> 
> 
> > +		set_cur(t, iocur_top->bb, bb_count, DB_RING_IGN, NULL);
> > +	}
> >  	iocur_top->typ = t;
> >  
> >  	/* verify the buffer if the type has one. */
> > -- 
> > 2.9.4
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> -- 
> Carlos
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/db/io.c b/db/io.c
index 9918a51..792cc0a 100644
--- a/db/io.c
+++ b/db/io.c
@@ -615,7 +615,13 @@  set_iocur_type(
 	const typ_t	*t)
 {
 	struct xfs_buf	*bp = iocur_top->bp;
+	int bb_count;
 
+	/* adjust cursor for types that contain fields */
+	if (t->fields) {
+		bb_count = BTOBB(byteize(fsize(t->fields, iocur_top->data, 0, 0)));
+		set_cur(t, iocur_top->bb, bb_count, DB_RING_IGN, NULL);
+	}
 	iocur_top->typ = t;
 
 	/* verify the buffer if the type has one. */