Skip to contentSkip to conversation

xfs_db: use correct inode to set inode type

PATCH Superseded Zorro Lang 4 participants 7 messages Aug 13, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zorro Lang

author
#0 lore raw

PATCH 1/1 xfs_db: use correct inode to set inode type

A test fails as:

  # xfs_db -c "inode 133" -c "addr" -c "p core.size" -c "type inode" -c "addr" -c "p core.size" /dev/sdb1
  current
          byte offset 68096, length 512
          buffer block 128 (fsbno 16), 32 bbs
          inode 133, dir inode -1, type inode
  core.size = 123142
  current
          byte offset 65536, length 512
          buffer block 128 (fsbno 16), 32 bbs
          inode 128, dir inode 128, type inode
  core.size = 42

The "type inode" get wrong inode addr due to it trys to get the beginning of an inode chunk, refer to "533d1d229 xfs_db: properly set inode type".

We don't need to get the beginning of a chunk in set_iocur_type, due to set_cur_inode(ino) will help to do all of that and make a proper verification. We just need to give it a correct inode.

---
 db/io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
db/io.c +2 -1
index 6628d061..61940a07 100644
@@ -591,6 +591,7 @@ set_iocur_type(
 	/* Inodes are special; verifier checks all inodes in the chunk */
 	if (type->typnm == TYP_INODE) {
 		xfs_daddr_t	b = iocur_top->bb;
+		int		bo = iocur_top->boff;
 		xfs_ino_t	ino;
 
 		/*
@@ -598,7 +599,7 @@ set_iocur_type(
  		 * which contains the current disk location; daddr may change.
  		 */
 		ino = XFS_AGINO_TO_INO(mp, xfs_daddr_to_agno(mp, b),
-			((b << BBSHIFT) >> mp->m_sb.sb_inodelog) %
+			(((b << BBSHIFT) + bo) >> mp->m_sb.sb_inodelog) %
 			XFS_AGB_TO_AGINO(mp, mp->m_sb.sb_agblocks));
 		set_cur_inode(ino);
 		return;
Signature · 1 line
2.20.1
#1 lore raw

Hi,

Quoted 13 lines · Zorro Lang

A test fails as:

  # xfs_db -c "inode 133" -c "addr" -c "p core.size" -c "type inode" -c "addr" -c "p core.size" /dev/sdb1
  current
          byte offset 68096, length 512
          buffer block 128 (fsbno 16), 32 bbs
          inode 133, dir inode -1, type inode
  core.size = 123142
  current
          byte offset 65536, length 512
          buffer block 128 (fsbno 16), 32 bbs
          inode 128, dir inode 128, type inode
  core.size = 42
Quoted 3 lines

The "type inode" get wrong inode addr due to it trys to get the beginning of an inode chunk, refer to "533d1d229 xfs_db: properly set inode type".

From the kernel side, the prefered way is
commit id ("subject")

Quoted 24 lines

We don't need to get the beginning of a chunk in set_iocur_type, due to set_cur_inode(ino) will help to do all of that and make a proper verification. We just need to give it a correct inode.

---
 db/io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
db/io.c +1 -0
index 6628d061..61940a07 100644
@@ -591,6 +591,7 @@ set_iocur_type(
 	/* Inodes are special; verifier checks all inodes in the chunk */
 	if (type->typnm == TYP_INODE) {
 		xfs_daddr_t	b = iocur_top->bb;
+		int		bo = iocur_top->boff;
 		xfs_ino_t	ino;
 
 		/*

db/io.c set_iocur_type( · line 605

Quoted 8 lines
db/io.c +1 -1
@@ -598,7 +599,7 @@ set_iocur_type(
  		 * which contains the current disk location; daddr may change.
  		 */
 		ino = XFS_AGINO_TO_INO(mp, xfs_daddr_to_agno(mp, b),
-			((b << BBSHIFT) >> mp->m_sb.sb_inodelog) %
+			(((b << BBSHIFT) + bo) >> mp->m_sb.sb_inodelog) %
 			XFS_AGB_TO_AGINO(mp, mp->m_sb.sb_agblocks));
 		set_cur_inode(ino);
 		return;

Not familar with such code, but after looking into a bit, (my premature thought is that) I'm wondering if we need to reverify original buffer in

if (type->fields) {
	...
	set_cur()
}

iocur_top->typ = type;

/* verify the buffer if the type has one. */
...

since set_cur() already verified the buffer in set_cur->libxfs_buf_read->...->libxfs_readbuf_verify?

Not related to this patchset but I'm a bit curious about it now...

Thanks,
Gao Xiang

Quoted 3 lines
Signature · 1 line
2.20.1
author
#2 lore raw
Quoted 16 lines · Gao Xiang

Hi,

Quoted 13 lines · Zorro Lang

A test fails as:

  # xfs_db -c "inode 133" -c "addr" -c "p core.size" -c "type inode" -c "addr" -c "p core.size" /dev/sdb1
  current
          byte offset 68096, length 512
          buffer block 128 (fsbno 16), 32 bbs
          inode 133, dir inode -1, type inode
  core.size = 123142
  current
          byte offset 65536, length 512
          buffer block 128 (fsbno 16), 32 bbs
          inode 128, dir inode 128, type inode
  core.size = 42
Quoted 6 lines
Quoted 3 lines

The "type inode" get wrong inode addr due to it trys to get the beginning of an inode chunk, refer to "533d1d229 xfs_db: properly set inode type".

From the kernel side, the prefered way is
commit id ("subject")

Hi Xiang,

Thanks for your review. I'll change my commit log.

Quoted 44 lines
Quoted 25 lines

We don't need to get the beginning of a chunk in set_iocur_type, due to set_cur_inode(ino) will help to do all of that and make a proper verification. We just need to give it a correct inode.

---
 db/io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
db/io.c +1 -0
index 6628d061..61940a07 100644
@@ -591,6 +591,7 @@ set_iocur_type(
 	/* Inodes are special; verifier checks all inodes in the chunk */
 	if (type->typnm == TYP_INODE) {
 		xfs_daddr_t	b = iocur_top->bb;
+		int		bo = iocur_top->boff;
 		xfs_ino_t	ino;
 
 		/*

db/io.c set_iocur_type( · line 605

Quoted 8 lines
db/io.c +1 -1
@@ -598,7 +599,7 @@ set_iocur_type(
  		 * which contains the current disk location; daddr may change.
  		 */
 		ino = XFS_AGINO_TO_INO(mp, xfs_daddr_to_agno(mp, b),
-			((b << BBSHIFT) >> mp->m_sb.sb_inodelog) %
+			(((b << BBSHIFT) + bo) >> mp->m_sb.sb_inodelog) %
 			XFS_AGB_TO_AGINO(mp, mp->m_sb.sb_agblocks));
 		set_cur_inode(ino);
 		return;

Not familar with such code, but after looking into a bit, (my premature thought is that) I'm wondering if we need to reverify original buffer in

if (type->fields) {
	...
	set_cur()
}

iocur_top->typ = type;

Quoted 7 lines

/* verify the buffer if the type has one. */
...

since set_cur() already verified the buffer in set_cur->libxfs_buf_read->...->libxfs_readbuf_verify?

Not related to this patchset but I'm a bit curious about it now...

I'm not the one who learn about xfsprogs best:) But by looking into set_cur_inode() -> set_cur(), I think the set_cur() does the xfs_buf verification, so I don't think we need to do that again at the end of set_iocur_type().

Thanks,
Zorro

Quoted 8 lines

Thanks,
Gao Xiang

Quoted 3 lines
Signature · 1 line
2.20.1
#3 lore raw

On Thu, Aug 13, 2020 at 11:29:05PM +0800, Zorro Lang wrote:

...

Quoted 23 lines
Quoted 23 lines

db/io.c set_iocur_type( · line 605

Quoted 6 lines
db/io.c +1 -1
 		ino = XFS_AGINO_TO_INO(mp, xfs_daddr_to_agno(mp, b),
-			((b << BBSHIFT) >> mp->m_sb.sb_inodelog) %
+			(((b << BBSHIFT) + bo) >> mp->m_sb.sb_inodelog) %
 			XFS_AGB_TO_AGINO(mp, mp->m_sb.sb_agblocks));
 		set_cur_inode(ino);
 		return;

Not familar with such code, but after looking into a bit, (my premature thought is that) I'm wondering if we need to reverify original buffer in

if (type->fields) {
	...
	set_cur()
}

iocur_top->typ = type;

/* verify the buffer if the type has one. */
...

since set_cur() already verified the buffer in set_cur->libxfs_buf_read->...->libxfs_readbuf_verify?

Quoted 6 lines
Quoted 1 line

Not related to this patchset but I'm a bit curious about it now...

I'm not the one who learn about xfsprogs best:) But by looking into set_cur_inode() -> set_cur(), I think the set_cur() does the xfs_buf verification, so I don't think we need to do that again at the end of set_iocur_type().

Nope, I wasn't saying we need to add anything after set_cur_inode(). but commit 55f224baf83d ("xfs_db: update buffer size when new type is set")

In detail, I think it might be

if (type->fields) {
	...
	set_cur()
	return;		<- here
}

iocur_top->typ = type;

/* verify the buffer if the type has one. */
...

Thanks,
Gao Xiang

Quoted 13 lines

Thanks,
Zorro

Quoted 8 lines

Thanks,
Gao Xiang

Quoted 3 lines
Signature · 1 line
2.20.1
#4 lore raw
In reply to Gao Xiang
Quoted 3 lines · Gao Xiang

Hi,

On Thu, Aug 13, 2020 at 02:03:24PM +0800, Zorro Lang wrote:

...

Quoted 32 lines
Quoted 13 lines
db/io.c +1 -0
index 6628d061..61940a07 100644
@@ -591,6 +591,7 @@ set_iocur_type(
 	/* Inodes are special; verifier checks all inodes in the chunk */
 	if (type->typnm == TYP_INODE) {
 		xfs_daddr_t	b = iocur_top->bb;
+		int		bo = iocur_top->boff;
 		xfs_ino_t	ino;
 
 		/*

db/io.c set_iocur_type( · line 605

Quoted 8 lines
db/io.c +1 -1
@@ -598,7 +599,7 @@ set_iocur_type(
  		 * which contains the current disk location; daddr may change.
  		 */
 		ino = XFS_AGINO_TO_INO(mp, xfs_daddr_to_agno(mp, b),
-			((b << BBSHIFT) >> mp->m_sb.sb_inodelog) %
+			(((b << BBSHIFT) + bo) >> mp->m_sb.sb_inodelog) %
 			XFS_AGB_TO_AGINO(mp, mp->m_sb.sb_agblocks));
 		set_cur_inode(ino);
 		return;

Not familar with such code, but after looking into a bit, (my premature thought is that) I'm wondering if we need to reverify original buffer in

if (type->fields) {
	...
	set_cur()
}

iocur_top->typ = type;

Quoted 7 lines

/* verify the buffer if the type has one. */
...

since set_cur() already verified the buffer in set_cur->libxfs_buf_read->...->libxfs_readbuf_verify?

Not related to this patchset but I'm a bit curious about it now...

I'm wondering about all this, too.

set_cur_inode() actually calls set_cur, which /does/ get into the verifier.

It definitely seems like a mess; the early return from the

	if (type->typnm == TYP_INODE) {

block is a little weird, and the explicit verify_read() later in the function seems like it might be unnecessary?

Agreed that it's unrelated to this bug, though.

-Eric

#5 lore raw
In reply to Zorro Lang
Quoted 13 lines · Zorro Lang

A test fails as:

  # xfs_db -c "inode 133" -c "addr" -c "p core.size" -c "type inode" -c "addr" -c "p core.size" /dev/sdb1
  current
          byte offset 68096, length 512
          buffer block 128 (fsbno 16), 32 bbs
          inode 133, dir inode -1, type inode
  core.size = 123142
  current
          byte offset 65536, length 512
          buffer block 128 (fsbno 16), 32 bbs
          inode 128, dir inode 128, type inode
  core.size = 42
Quoted 3 lines

The "type inode" get wrong inode addr due to it trys to get the beginning of an inode chunk, refer to "533d1d229 xfs_db: properly set inode type".

It took me a minute to figure out what this was referring to (though it was obvious from the code change). Might I suggest something like:

The "type inode" command accidentally moves the io cursor because it forgets to include the io cursor's buffer offset when it computes the inode number from the io cursor's location.

Fixes 533d1d229a88 ("xfs_db: properly set inode type")
Quoted 23 lines

We don't need to get the beginning of a chunk in set_iocur_type, due to set_cur_inode(ino) will help to do all of that and make a proper verification. We just need to give it a correct inode.

---
 db/io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
db/io.c +1 -0
index 6628d061..61940a07 100644
@@ -591,6 +591,7 @@ set_iocur_type(
 	/* Inodes are special; verifier checks all inodes in the chunk */
 	if (type->typnm == TYP_INODE) {
 		xfs_daddr_t	b = iocur_top->bb;
+		int		bo = iocur_top->boff;
 		xfs_ino_t	ino;
 
 		/*

db/io.c set_iocur_type( · line 603

Quoted 6 lines
db/io.c +1 -1
@@ -598,7 +599,7 @@ set_iocur_type(
  		 * which contains the current disk location; daddr may change.
  		 */
 		ino = XFS_AGINO_TO_INO(mp, xfs_daddr_to_agno(mp, b),
-			((b << BBSHIFT) >> mp->m_sb.sb_inodelog) %
+			(((b << BBSHIFT) + bo) >> mp->m_sb.sb_inodelog) %
 			XFS_AGB_TO_AGINO(mp, mp->m_sb.sb_agblocks));

/me feels like this whole thing ought to be revised into something involving XFS_OFFBNO_TO_AGINO to make the unit conversions easier to read, e.g.:

	xfs_daddr_t	b = iocur_top->bb;
	xfs_agbno_t	agbno;
	xfs_agino_t	agino;

	agbno = xfs_daddr_to_agbno(mp, b);
	agino = XFS_OFFBNO_TO_AGINO(mp, agbno,
			iocur_top->boff / mp->m_sb.sb_inodesize);
	ino = XFS_AGINO_TO_INO(mp, xfs_daddr_to_agno(mp, b), agino);

--D

Quoted 5 lines
db/io.c +0 -0
 		set_cur_inode(ino);
 		return;
Signature · 1 line
2.20.1
author
#6 lore raw
Quoted 14 lines · Darrick J. Wong
Quoted 13 lines · Zorro Lang

A test fails as:

  # xfs_db -c "inode 133" -c "addr" -c "p core.size" -c "type inode" -c "addr" -c "p core.size" /dev/sdb1
  current
          byte offset 68096, length 512
          buffer block 128 (fsbno 16), 32 bbs
          inode 133, dir inode -1, type inode
  core.size = 123142
  current
          byte offset 65536, length 512
          buffer block 128 (fsbno 16), 32 bbs
          inode 128, dir inode 128, type inode
  core.size = 42
Quoted 5 lines
Quoted 3 lines

The "type inode" get wrong inode addr due to it trys to get the beginning of an inode chunk, refer to "533d1d229 xfs_db: properly set inode type".

It took me a minute to figure out what this was referring to (though it

Sorry about that :-p

Quoted 7 lines

was obvious from the code change). Might I suggest something like:

The "type inode" command accidentally moves the io cursor because it forgets to include the io cursor's buffer offset when it computes the inode number from the io cursor's location.

Fixes 533d1d229a88 ("xfs_db: properly set inode type")

Sure, thanks for this detailed suggestion.

Quoted 35 lines
Quoted 24 lines

We don't need to get the beginning of a chunk in set_iocur_type, due to set_cur_inode(ino) will help to do all of that and make a proper verification. We just need to give it a correct inode.

---
 db/io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
db/io.c +1 -0
index 6628d061..61940a07 100644
@@ -591,6 +591,7 @@ set_iocur_type(
 	/* Inodes are special; verifier checks all inodes in the chunk */
 	if (type->typnm == TYP_INODE) {
 		xfs_daddr_t	b = iocur_top->bb;
+		int		bo = iocur_top->boff;
 		xfs_ino_t	ino;
 
 		/*

db/io.c set_iocur_type( · line 603

Quoted 6 lines
db/io.c +1 -1
@@ -598,7 +599,7 @@ set_iocur_type(
  		 * which contains the current disk location; daddr may change.
  		 */
 		ino = XFS_AGINO_TO_INO(mp, xfs_daddr_to_agno(mp, b),
-			((b << BBSHIFT) >> mp->m_sb.sb_inodelog) %
+			(((b << BBSHIFT) + bo) >> mp->m_sb.sb_inodelog) %
 			XFS_AGB_TO_AGINO(mp, mp->m_sb.sb_agblocks));

/me feels like this whole thing ought to be revised into something involving XFS_OFFBNO_TO_AGINO to make the unit conversions easier to read, e.g.:

Quoted 8 lines
	xfs_daddr_t	b = iocur_top->bb;
	xfs_agbno_t	agbno;
	xfs_agino_t	agino;

	agbno = xfs_daddr_to_agbno(mp, b);
	agino = XFS_OFFBNO_TO_AGINO(mp, agbno,
			iocur_top->boff / mp->m_sb.sb_inodesize);
	ino = XFS_AGINO_TO_INO(mp, xfs_daddr_to_agno(mp, b), agino);

Sure, that looks clearer.

Thanks,
Zorro

Quoted 9 lines

--D

Quoted 5 lines
db/io.c +0 -0
 		set_cur_inode(ino);
 		return;
Signature · 1 line
2.20.1