Skip to contentSkip to conversation

xfs_repair: Fix root inode's parent when it's bogus for sf directory

PATCH In review Marco Benatto 3 participants 5 messages Jun 14, 2018 – Jun 15, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_repair: Fix root inode's parent when it's bogus for sf directory

Currently when root inode is in short-form and its parent ino has an invalid value, process_sf_dir2() ends up not fixing it, because if verify_inum() fails we never get to the next case which would fix the root inode's parent pointer.

This behavior triggers the following assert on process_dir2():

   ASSERT((ino != mp->m_sb.sb_rootino && ino != *parent) ||
        (ino == mp->m_sb.sb_rootino &&
        (ino == *parent || need_root_dotdot == 1)));

This patch fixes this behavior by making sure we always properly handle rootino parent pointer in process_sf_dir2()

---
 repair/dir2.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
repair/dir2.c +3 -1
index e162d2b..225f926 100644
@@ -495,8 +495,10 @@ _("corrected entry offsets in directory %" PRIu64 "\n"),
 
 	/*
 	 * if parent entry is bogus, null it out.  we'll fix it later .
+	 * If the validation fails for the root inode we fix it in
+	 * the next else case.
 	 */
-	if (verify_inum(mp, *parent))  {
+	if (verify_inum(mp, *parent) && ino != mp->m_sb.sb_rootino)  {
 
 		do_warn(
 _("bogus .. inode number (%" PRIu64 ") in directory inode %" PRIu64 ", "),
Signature · 1 line
2.9.5
#1 lore raw
Quoted 7 lines · Marco Benatto

Currently when root inode is in short-form and its parent ino has an invalid value, process_sf_dir2() ends up not fixing it, because if verify_inum() fails we never get to the next case which would fix the root inode's parent pointer.

This behavior triggers the following assert on process_dir2():

Quoted 8 lines
   ASSERT((ino != mp->m_sb.sb_rootino && ino != *parent) ||
        (ino == mp->m_sb.sb_rootino &&
        (ino == *parent || need_root_dotdot == 1)));

This patch fixes this behavior by making sure we always properly handle rootino parent pointer in process_sf_dir2()

This looks correct to me, thanks.

FWIW the problem can be demonstrated by setting the root inode's parent to 0 on a freshly made fs:

# mkfs.xfs -f -dfile,name=fsfile,size=1g
# xfs_db -x -c "sb 0" -c "addr rootino" -c "write u3.sfdir3.hdr.parent.i4 0" fsfile
# xfs_repair fsfile
Quoted 21 lines
---
 repair/dir2.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
repair/dir2.c +3 -1
index e162d2b..225f926 100644
@@ -495,8 +495,10 @@ _("corrected entry offsets in directory %" PRIu64 "\n"),
 
 	/*
 	 * if parent entry is bogus, null it out.  we'll fix it later .
+	 * If the validation fails for the root inode we fix it in
+	 * the next else case.
 	 */
-	if (verify_inum(mp, *parent))  {
+	if (verify_inum(mp, *parent) && ino != mp->m_sb.sb_rootino)  {
 
 		do_warn(
 _("bogus .. inode number (%" PRIu64 ") in directory inode %" PRIu64 ", "),
#2 lore raw
Quoted 17 lines · Eric Sandeen
Quoted 7 lines · Marco Benatto

Currently when root inode is in short-form and its parent ino has an invalid value, process_sf_dir2() ends up not fixing it, because if verify_inum() fails we never get to the next case which would fix the root inode's parent pointer.

This behavior triggers the following assert on process_dir2():

Quoted 8 lines
   ASSERT((ino != mp->m_sb.sb_rootino && ino != *parent) ||
        (ino == mp->m_sb.sb_rootino &&
        (ino == *parent || need_root_dotdot == 1)));

This patch fixes this behavior by making sure we always properly handle rootino parent pointer in process_sf_dir2()

Quoted 8 lines

This looks correct to me, thanks.

FWIW the problem can be demonstrated by setting the root inode's parent to 0 on a freshly made fs:

# mkfs.xfs -f -dfile,name=fsfile,size=1g
# xfs_db -x -c "sb 0" -c "addr rootino" -c "write u3.sfdir3.hdr.parent.i4 0" fsfile
# xfs_repair fsfile

xfstest please (also to check that xfs_scrub detects it)?

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#3 lore raw
Quoted 20 lines · Dave Chinner
Quoted 19 lines · Eric Sandeen
Quoted 7 lines · Marco Benatto

Currently when root inode is in short-form and its parent ino has an invalid value, process_sf_dir2() ends up not fixing it, because if verify_inum() fails we never get to the next case which would fix the root inode's parent pointer.

This behavior triggers the following assert on process_dir2():

Quoted 8 lines
   ASSERT((ino != mp->m_sb.sb_rootino && ino != *parent) ||
        (ino == mp->m_sb.sb_rootino &&
        (ino == *parent || need_root_dotdot == 1)));

This patch fixes this behavior by making sure we always properly handle rootino parent pointer in process_sf_dir2()

This looks correct to me, thanks.

Quoted 8 lines
Quoted 6 lines

FWIW the problem can be demonstrated by setting the root inode's parent to 0 on a freshly made fs:

# mkfs.xfs -f -dfile,name=fsfile,size=1g
# xfs_db -x -c "sb 0" -c "addr rootino" -c "write u3.sfdir3.hdr.parent.i4 0" fsfile
# xfs_repair fsfile

xfstest please (also to check that xfs_scrub detects it)?

Sure, working on this. I'll send you once it's done.

Quoted 7 lines

Cheers,

Dave.
--
Dave Chinner
[email protected]

Cheers,

Signature · 1 line
Marco Benatto
#4 lore raw

FYI,

just sent out "[PATCH] xfstests: Teste root inode parent pointer repairing"

Quoted 46 lines · Marco Benatto
Quoted 20 lines · Dave Chinner
Quoted 19 lines · Eric Sandeen
Quoted 7 lines · Marco Benatto

Currently when root inode is in short-form and its parent ino has an invalid value, process_sf_dir2() ends up not fixing it, because if verify_inum() fails we never get to the next case which would fix the root inode's parent pointer.

This behavior triggers the following assert on process_dir2():

Quoted 8 lines
   ASSERT((ino != mp->m_sb.sb_rootino && ino != *parent) ||
        (ino == mp->m_sb.sb_rootino &&
        (ino == *parent || need_root_dotdot == 1)));

This patch fixes this behavior by making sure we always properly handle rootino parent pointer in process_sf_dir2()

This looks correct to me, thanks.

Quoted 8 lines
Quoted 6 lines

FWIW the problem can be demonstrated by setting the root inode's parent to 0 on a freshly made fs:

# mkfs.xfs -f -dfile,name=fsfile,size=1g
# xfs_db -x -c "sb 0" -c "addr rootino" -c "write u3.sfdir3.hdr.parent.i4 0" fsfile
# xfs_repair fsfile

xfstest please (also to check that xfs_scrub detects it)?

Sure, working on this. I'll send you once it's done.

Quoted 7 lines

Cheers,

Dave.
--
Dave Chinner
[email protected]

Cheers,

--
Marco Benatto

Signature · 5 lines
Marco Benatto
Senior Software Maintenance Engineer | Red Hat Brasil
T: +55 11 35246161 | M: +55 41 9 88504051
Av. Brigadeiro Faria Lima 3900, 8° Andar. São Paulo, Brasil. RED HAT |
TRIED. TESTED. TRUSTED. Saiba porque em redhat.com