Skip to contentSkip to conversation

xfs_db: update sector size when type is set

PATCH Superseded Bill O'Donnell 4 participants 14 messages Jun 22, 2017 – Jun 26, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_db: update sector size when type is set

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().

---
 db/io.c | 6 ++++++
 1 file changed, 6 insertions(+)
db/io.c +6 -0
index 9918a51..7e6d330 100644
@@ -616,6 +616,12 @@ set_iocur_type(
 {
 	struct xfs_buf	*bp = iocur_top->bp;
 
+	if (t->fields)
+		set_cur(t,
+			iocur_top->bb,
+			fsize(t->fields, iocur_top->data,
+			      0, 0) / mp->m_sb.sb_blocksize,
+			DB_RING_IGN, NULL);
 	iocur_top->typ = t;
 
 	/* verify the buffer if the type has one. */
Signature · 1 line
2.9.4
#1 lore raw
Quoted 35 lines · Bill O'Donnell

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().

---
 db/io.c | 6 ++++++
 1 file changed, 6 insertions(+)
db/io.c +0 -0
index 9918a51..7e6d330 100644

db/io.c set_iocur_type( · line 623

Quoted 8 lines
db/io.c +5 -0
@@ -616,6 +616,12 @@ set_iocur_type(
 {
 	struct xfs_buf	*bp = iocur_top->bp;
 
+	if (t->fields)
+		set_cur(t,
+			iocur_top->bb,
+			fsize(t->fields, iocur_top->data,
+			      0, 0) / mp->m_sb.sb_blocksize,

I thought the third parameter to set_cur (which is fed as the third parameter to libxfs_readbuf) was expressed in units of basic blocks (i.e. 512 bytes)? fsize returns the size of the field in bytes (I think?), so dividing by sb_blocksize renders units of fs blocks, not basic blocks.

<shrug> the naming isn't helpful at all:

void
set_cur(

	const typ_t	*t,
	int64_t		d,
	int		c,
...
	iocur_top->len = BBTOB(c);

<codeconfused>

--D

Quoted 11 lines
db/io.c +1 -0
+			DB_RING_IGN, NULL);
 	iocur_top->typ = t;
 
 	/* verify the buffer if the type has one. */
Signature · 6 lines
2.9.4

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 31 lines · Darrick J. Wong
Quoted 30 lines · Bill O'Donnell

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().

---
 db/io.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 8 lines

db/io.c set_iocur_type( · line 618

Quoted 8 lines
db/io.c +0 -0
index 9918a51..7e6d330 100644
@@ -616,6 +616,12 @@ set_iocur_type(
 {
 	struct xfs_buf	*bp = iocur_top->bp;
 

a comment about why only this "if" case is there would be good.

Quoted 10 lines

db/io.c set_iocur_type( · line 623

Quoted 5 lines
db/io.c +5 -0
+	if (t->fields)
+		set_cur(t,
+			iocur_top->bb,
+			fsize(t->fields, iocur_top->data,
+			      0, 0) / mp->m_sb.sb_blocksize,

I thought the third parameter to set_cur (which is fed as the third parameter to libxfs_readbuf) was expressed in units of basic blocks (i.e. 512 bytes)? fsize returns the size of the field in bytes (I think?),

nope, bits :)

Quoted 2 lines

so dividing by sb_blocksize renders units of fs blocks, not basic blocks.

As Darrick just pointed out to me, you treated bits as bytes and daddr as fsblock so for 4k blocks, 8/8 came out right ;)

I think what you want for the size is something like:

BTOBB(byteize(fsize(t->fields, iocur_top->data, 0, 0)));

It might be a little nicer to stash that in a temp var so you don't have all that gunk in the call to set_cur.

Quoted 11 lines

<shrug> the naming isn't helpful at all:

void
set_cur(

	const typ_t	*t,
	int64_t		d,
	int		c,
...
	iocur_top->len = BBTOB(c);

<codeconfused>

yup isn't xfs_db fun?

Quoted 19 lines

--D

Quoted 11 lines
db/io.c +1 -0
+			DB_RING_IGN, NULL);
 	iocur_top->typ = t;
 
 	/* verify the buffer if the type has one. */
Signature · 6 lines
2.9.4

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 34 lines · Eric Sandeen
Quoted 31 lines · Darrick J. Wong
Quoted 30 lines · Bill O'Donnell

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().

---
 db/io.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 10 lines
Quoted 8 lines

db/io.c set_iocur_type( · line 618

Quoted 8 lines
db/io.c +0 -0
index 9918a51..7e6d330 100644
@@ -616,6 +616,12 @@ set_iocur_type(
 {
 	struct xfs_buf	*bp = iocur_top->bp;
 

a comment about why only this "if" case is there would be good.

agreed.

Quoted 12 lines
Quoted 11 lines

db/io.c set_iocur_type( · line 623

Quoted 6 lines
db/io.c +5 -0
+	if (t->fields)
+		set_cur(t,
+			iocur_top->bb,
+			fsize(t->fields, iocur_top->data,
+			      0, 0) / mp->m_sb.sb_blocksize,

I thought the third parameter to set_cur (which is fed as the third parameter to libxfs_readbuf) was expressed in units of basic blocks (i.e. 512 bytes)? fsize returns the size of the field in bytes (I think?),

Quoted 7 lines

nope, bits :)

Quoted 2 lines

so dividing by sb_blocksize renders units of fs blocks, not basic blocks.

As Darrick just pointed out to me, you treated bits as bytes and daddr as fsblock so for 4k blocks, 8/8 came out right ;)

Yeah. Doh! I tested with sector sizes 512 and 4096 and it all just worked, since mp->m_sb.sb_blocksize returned 1 and 8, respectively.

Quoted 7 lines

I think what you want for the size is something like:

BTOBB(byteize(fsize(t->fields, iocur_top->data, 0, 0)));

It might be a little nicer to stash that in a temp var so you don't have all that gunk in the call to set_cur.

Yep.

Quoted 37 lines
Quoted 11 lines

<shrug> the naming isn't helpful at all:

void
set_cur(

	const typ_t	*t,
	int64_t		d,
	int		c,
...
	iocur_top->len = BBTOB(c);

<codeconfused>

yup isn't xfs_db fun?

Quoted 10 lines

--D

Quoted 7 lines
db/io.c +1 -0
+			DB_RING_IGN, NULL);
 	iocur_top->typ = t;
 
 	/* verify the buffer if the type has one. */
Signature · 1 line
2.9.4
Quoted 9 lines
Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 62 lines · Bill O'Donnell
Quoted 34 lines · Eric Sandeen
Quoted 31 lines · Darrick J. Wong
Quoted 30 lines · Bill O'Donnell

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().

---
 db/io.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 10 lines
Quoted 8 lines

db/io.c set_iocur_type( · line 618

Quoted 8 lines
db/io.c +0 -0
index 9918a51..7e6d330 100644
@@ -616,6 +616,12 @@ set_iocur_type(
 {
 	struct xfs_buf	*bp = iocur_top->bp;
 

a comment about why only this "if" case is there would be good.

agreed.

Quoted 14 lines
Quoted 11 lines

db/io.c set_iocur_type( · line 623

Quoted 6 lines
db/io.c +5 -0
+	if (t->fields)
+		set_cur(t,
+			iocur_top->bb,
+			fsize(t->fields, iocur_top->data,
+			      0, 0) / mp->m_sb.sb_blocksize,

I thought the third parameter to set_cur (which is fed as the third parameter to libxfs_readbuf) was expressed in units of basic blocks (i.e. 512 bytes)? fsize returns the size of the field in bytes (I think?),

nope, bits :)

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

so dividing by sb_blocksize renders units of fs blocks, not basic blocks.

As Darrick just pointed out to me, you treated bits as bytes and daddr as fsblock so for 4k blocks, 8/8 came out right ;)

Yeah. Doh! I tested with sector sizes 512 and 4096 and it all just worked, since mp->m_sb.sb_blocksize returned 1 and 8, respectively.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Correction: _dividing by mp->m_sb.sb_blocksize_ gave 1 and 8, respectively.

Quoted 53 lines
Quoted 8 lines

I think what you want for the size is something like:

BTOBB(byteize(fsize(t->fields, iocur_top->data, 0, 0)));

It might be a little nicer to stash that in a temp var so you don't have all that gunk in the call to set_cur.

Yep.

Quoted 33 lines
Quoted 11 lines

<shrug> the naming isn't helpful at all:

void
set_cur(

	const typ_t	*t,
	int64_t		d,
	int		c,
...
	iocur_top->len = BBTOB(c);

<codeconfused>

yup isn't xfs_db fun?

Quoted 10 lines

--D

Quoted 7 lines
db/io.c +1 -0
+			DB_RING_IGN, NULL);
 	iocur_top->typ = t;
 
 	/* verify the buffer if the type has one. */
Signature · 1 line
2.9.4
Quoted 9 lines
Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
In reply to Darrick J. Wong
Quoted 39 lines · Darrick J. Wong
Quoted 38 lines · Bill O'Donnell

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().

---
 db/io.c | 6 ++++++
 1 file changed, 6 insertions(+)
db/io.c +0 -0
index 9918a51..7e6d330 100644
@@ -616,6 +616,12 @@ set_iocur_type(
 {
 	struct xfs_buf	*bp = iocur_top->bp;
 
Quoted 12 lines

db/io.c set_iocur_type( · line 623

Quoted 5 lines
db/io.c +5 -0
+	if (t->fields)
+		set_cur(t,
+			iocur_top->bb,
+			fsize(t->fields, iocur_top->data,
+			      0, 0) / mp->m_sb.sb_blocksize,

I thought the third parameter to set_cur (which is fed as the third parameter to libxfs_readbuf) was expressed in units of basic blocks (i.e. 512 bytes)? fsize returns the size of the field in bytes (I think?), so dividing by sb_blocksize renders units of fs blocks, not basic blocks.

fsize returns the field size in bits. Dividing by sb_blocksize gives basic blocks.

Quoted 1 line

<shrug> the naming isn't helpful at all:

I also found the naming through the call stack to be terrible and damned confusing (c, d ? really??), but left that battle for another day, another patch. ;)

Thanks-
Bill

Quoted 24 lines

void
set_cur(

	const typ_t	*t,
	int64_t		d,
	int		c,
...
	iocur_top->len = BBTOB(c);

<codeconfused>

--D

Quoted 11 lines
db/io.c +1 -0
+			DB_RING_IGN, NULL);
 	iocur_top->typ = t;
 
 	/* verify the buffer if the type has one. */
Signature · 6 lines
2.9.4

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw
Quoted 53 lines · Bill O'Donnell
Quoted 39 lines · Darrick J. Wong
Quoted 38 lines · Bill O'Donnell

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().

---
 db/io.c | 6 ++++++
 1 file changed, 6 insertions(+)
db/io.c +0 -0
index 9918a51..7e6d330 100644
@@ -616,6 +616,12 @@ set_iocur_type(
 {
 	struct xfs_buf	*bp = iocur_top->bp;
 
Quoted 12 lines

db/io.c set_iocur_type( · line 623

Quoted 5 lines
db/io.c +5 -0
+	if (t->fields)
+		set_cur(t,
+			iocur_top->bb,
+			fsize(t->fields, iocur_top->data,
+			      0, 0) / mp->m_sb.sb_blocksize,

I thought the third parameter to set_cur (which is fed as the third parameter to libxfs_readbuf) was expressed in units of basic blocks (i.e. 512 bytes)? fsize returns the size of the field in bytes (I think?), so dividing by sb_blocksize renders units of fs blocks, not basic blocks.

Quoted 1 line

fsize returns the field size in bits. Dividing by sb_blocksize gives basic blocks.

Yes, the subtlety that fsize() returns bits and sb_blocksize is usually 4096 / 512 == 8 means that the conversion works for the default case, but that leaves us open to bugs. Consider if sb_blocksize == 65536.

There are so many different unit types in XFS that it is crucial for auditing to make analyzing unit conversions as easy as possible. That means that we must show all intermediate steps in converting from one unit system to another, and we must not short circuit those hops. This helps the reviewers find bugs.

For example, consider Eric's suggested replacement for the third parameter:

BTOBB(byteize(fsize(t->fields, iocur_top->data, 0, 0)));

We know that the units of the third parameter are in basic blocks from flailing around in the set_cur code due to unhelpful parameter names. BTOBB converts bytes to basic blocks, so we theorize that the input must be in units of bytes. We can then unpack the next level:

byteize(fsize(...))

Starting from the premise that this expression is in units of bytes, we apply the knowledge that byteize converts bit counts to byte counts, so we now also theorize that the input must be in units of bits. Unpack the next level:

fsize(...)

To finish checking the expression value, we simply have to confirm that fsize() returns units of bits. Therefore, the expression is correct. The unit analysis is straightforward and does not require knowledge of subtleties.

--D

Quoted 38 lines
Quoted 2 lines

<shrug> the naming isn't helpful at all:

I also found the naming through the call stack to be terrible and damned confusing (c, d ? really??), but left that battle for another day, another patch. ;)

Thanks-
Bill

Quoted 16 lines

void
set_cur(

	const typ_t	*t,
	int64_t		d,
	int		c,
...
	iocur_top->len = BBTOB(c);

<codeconfused>

--D

Quoted 3 lines
db/io.c +1 -0
+			DB_RING_IGN, NULL);
 	iocur_top->typ = t;
 
Quoted 8 lines
Quoted 8 lines
db/io.c +0 -0
 	/* verify the buffer if the type has one. */
Signature · 6 lines
2.9.4

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw
Quoted 82 lines · Darrick J. Wong
Quoted 53 lines · Bill O'Donnell
Quoted 39 lines · Darrick J. Wong
Quoted 38 lines · Bill O'Donnell

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().

---
 db/io.c | 6 ++++++
 1 file changed, 6 insertions(+)
db/io.c +0 -0
index 9918a51..7e6d330 100644
@@ -616,6 +616,12 @@ set_iocur_type(
 {
 	struct xfs_buf	*bp = iocur_top->bp;
 
Quoted 12 lines

db/io.c set_iocur_type( · line 623

Quoted 5 lines
db/io.c +5 -0
+	if (t->fields)
+		set_cur(t,
+			iocur_top->bb,
+			fsize(t->fields, iocur_top->data,
+			      0, 0) / mp->m_sb.sb_blocksize,

I thought the third parameter to set_cur (which is fed as the third parameter to libxfs_readbuf) was expressed in units of basic blocks (i.e. 512 bytes)? fsize returns the size of the field in bytes (I think?), so dividing by sb_blocksize renders units of fs blocks, not basic blocks.

Quoted 1 line

fsize returns the field size in bits. Dividing by sb_blocksize gives basic blocks.

Yes, the subtlety that fsize() returns bits and sb_blocksize is usually 4096 / 512 == 8 means that the conversion works for the default case, but that leaves us open to bugs. Consider if sb_blocksize == 65536.

There are so many different unit types in XFS that it is crucial for auditing to make analyzing unit conversions as easy as possible. That means that we must show all intermediate steps in converting from one unit system to another, and we must not short circuit those hops. This helps the reviewers find bugs.

For example, consider Eric's suggested replacement for the third parameter:

BTOBB(byteize(fsize(t->fields, iocur_top->data, 0, 0)));

We know that the units of the third parameter are in basic blocks from flailing around in the set_cur code due to unhelpful parameter names. BTOBB converts bytes to basic blocks, so we theorize that the input must be in units of bytes. We can then unpack the next level:

byteize(fsize(...))

Starting from the premise that this expression is in units of bytes, we apply the knowledge that byteize converts bit counts to byte counts, so we now also theorize that the input must be in units of bits. Unpack the next level:

Quoted 6 lines

fsize(...)

To finish checking the expression value, we simply have to confirm that fsize() returns units of bits. Therefore, the expression is correct. The unit analysis is straightforward and does not require knowledge of subtleties.

Excellent analysis, thanks!
Eric suggested I come up with a (robust) test case, and as you point out, the need is fairly obvious.

Thanks-
Bill

Quoted 41 lines

--D

Quoted 38 lines
Quoted 2 lines

<shrug> the naming isn't helpful at all:

I also found the naming through the call stack to be terrible and damned confusing (c, d ? really??), but left that battle for another day, another patch. ;)

Thanks-
Bill

Quoted 16 lines

void
set_cur(

	const typ_t	*t,
	int64_t		d,
	int		c,
...
	iocur_top->len = BBTOB(c);

<codeconfused>

--D

Quoted 3 lines
db/io.c +1 -0
+			DB_RING_IGN, NULL);
 	iocur_top->typ = t;
 
Quoted 8 lines
Quoted 8 lines
db/io.c +0 -0
 	/* verify the buffer if the type has one. */
Signature · 6 lines
2.9.4

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

PATCH v2 1/1 xfs_db: update sector size when type is set

In reply to Bill O'Donnell

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().

---
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(+)
db/io.c +6 -0
index 9918a51..792cc0a 100644
@@ -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. */
Signature · 1 line
2.9.4
Reviewed-by on v2 1/1
#9 lore raw

Hey Bill,

db/io.c set_iocur_type( · line 622

Quoted 13 lines
db/io.c +4 -0
index 9918a51..792cc0a 100644
@@ -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:

Cheers

Quoted 12 lines
db/io.c +2 -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. */
Signature · 6 lines
2.9.4

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Carlos
#10 lore raw
Quoted 18 lines · Carlos Maiolino

Hey Bill,

db/io.c set_iocur_type( · line 622

Quoted 13 lines
db/io.c +4 -0
index 9918a51..792cc0a 100644
@@ -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:

Quoted 3 lines

#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

Quoted 39 lines

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:

Cheers

Quoted 12 lines
db/io.c +2 -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. */
Signature · 6 lines
2.9.4

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Carlos
#11 lore raw

PATCH v3 1/1 xfs_db: update sector size when type is set

In reply to Bill O'Donnell

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().

---

v2: correction to argument 3 in call to set_cur: compute and pass basic block count;
add comment regarding conditional call to set_cur.
v3: include bit.h for byteize function

 db/io.c | 7 +++++++
 1 file changed, 7 insertions(+)
db/io.c +7 -0
index 9918a51..b97b710 100644
@@ -28,6 +28,7 @@
 #include "init.h"
 #include "malloc.h"
 #include "crc.h"
+#include "bit.h"
 
 static int	pop_f(int argc, char **argv);
 static void     pop_help(void);
@@ -615,7 +616,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. */
Signature · 1 line
2.9.4
Reviewed-by on v3 1/1
#12 lore raw
Quoted 40 lines · Bill O'Donnell

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().

---

v2: correction to argument 3 in call to set_cur: compute and pass basic block count;
add comment regarding conditional call to set_cur.
v3: include bit.h for byteize function

 db/io.c | 7 +++++++
 1 file changed, 7 insertions(+)
db/io.c +0 -0
index 9918a51..b97b710 100644

db/io.c line 32

Quoted 5 lines
db/io.c +1 -0
@@ -28,6 +28,7 @@
 #include "init.h"
 #include "malloc.h"
 #include "crc.h"
+#include "bit.h"
 

Thanks!!

Quoted 23 lines
db/io.c +6 -0
 static int	pop_f(int argc, char **argv);
 static void     pop_help(void);
@@ -615,7 +616,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. */
Signature · 6 lines
2.9.4

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Carlos
Reviewed-by on v3 1/1
#13 lore raw
In reply to Bill O'Donnell
Quoted 21 lines · Bill O'Donnell

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).

Quoted 5 lines

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().

--D

Quoted 42 lines

---

v2: correction to argument 3 in call to set_cur: compute and pass basic block count;
add comment regarding conditional call to set_cur.
v3: include bit.h for byteize function

 db/io.c | 7 +++++++
 1 file changed, 7 insertions(+)
db/io.c +7 -0
index 9918a51..b97b710 100644
@@ -28,6 +28,7 @@
 #include "init.h"
 #include "malloc.h"
 #include "crc.h"
+#include "bit.h"
 
 static int	pop_f(int argc, char **argv);
 static void     pop_help(void);
@@ -615,7 +616,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. */
Signature · 6 lines
2.9.4

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html