Skip to contentSkip to conversation

xfs_repair: Bump link count if longform_dir2_rebuild yields shortform dir

PATCH In review user.mail 5 participants 7 messages Apr 15, 2025 – Apr 16, 2025

lore
Share & tools
lore

user.mail

author
#0 lore raw

PATCH 1/1 xfs_repair: Bump link count if longform_dir2_rebuild yields shortform dir

From: Eric Sandeen <[email protected]>

If longform_dir2_rebuild() has so few entries in *hashtab that it results in a short form directory, bump the link count manually as shortform directories have no explicit "." entry.

Without this, repair will end with i.e.:

resetting inode 131 nlinks from 2 to 1

in this case, because it thinks this directory inode only has 1 link discovered, and then a 2nd repair will fix it:

resetting inode 131 nlinks from 1 to 2

because shortform_dir2_entry_check() explicitly adds the extra ref when the (newly-created)shortform directory is checked:

/*
* no '.' entry in shortform dirs, just bump up ref count by 1
* '..' was already (or will be) accounted for and checked when
* the directory is reached or will be taken care of when the
* directory is moved to orphanage.
*/
add_inode_ref(current_irec, current_ino_offset);

Avoid this by adding the extra ref if we convert from longform to shortform.

---
 repair/phase6.c | 7 +++++++
 1 file changed, 7 insertions(+)
repair/phase6.c +7 -0
index dbc090a5..8804278a 100644
@@ -1392,6 +1392,13 @@ _("name create failed in ino %" PRIu64 " (%d)\n"), ino, error);
 _("name create failed (%d) during rebuild\n"), error);
 	}
 
+	/*
+	 * If we added too few entries to retain longform, add the extra
+	 * ref for . as this is now a shortform directory.
+	 */
+	if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL)
+		add_inode_ref(irec, ino_offset);
+
 	return;
 
 out_bmap_cancel:
Signature · 1 line
2.49.0
#1 lore raw
Quoted 26 lines · user.mail

From: Eric Sandeen <[email protected]>

If longform_dir2_rebuild() has so few entries in *hashtab that it results in a short form directory, bump the link count manually as shortform directories have no explicit "." entry.

Without this, repair will end with i.e.:

resetting inode 131 nlinks from 2 to 1

in this case, because it thinks this directory inode only has 1 link discovered, and then a 2nd repair will fix it:

resetting inode 131 nlinks from 1 to 2

because shortform_dir2_entry_check() explicitly adds the extra ref when the (newly-created)shortform directory is checked:

/*
* no '.' entry in shortform dirs, just bump up ref count by 1
* '..' was already (or will be) accounted for and checked when
* the directory is reached or will be taken care of when the
* directory is moved to orphanage.
*/
add_inode_ref(current_irec, current_ino_offset);

Quoted 5 lines

Avoid this by adding the extra ref if we convert from longform to shortform.

Ugh, sorry about the user.mail business, not sure how that happened.

New VM, who dis? :(

FWIW this fix is related to the fix Bill has been working on, but it is independent. Bill's hoping to address the problem where we fail to build up any directory entries for a long-form rebuild, and when that is fixed, in most cases the entries will be there and the dir will remain long form.

Still, it is possible that the entry scan turns up so few entries that the directory becomes short form when rebuilt, so I think this patch still makes sense.

Thanks,
-Eric

Quoted 22 lines
---
 repair/phase6.c | 7 +++++++
 1 file changed, 7 insertions(+)
repair/phase6.c +7 -0
index dbc090a5..8804278a 100644
@@ -1392,6 +1392,13 @@ _("name create failed in ino %" PRIu64 " (%d)\n"), ino, error);
 _("name create failed (%d) during rebuild\n"), error);
 	}
 
+	/*
+	 * If we added too few entries to retain longform, add the extra
+	 * ref for . as this is now a shortform directory.
+	 */
+	if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL)
+		add_inode_ref(irec, ino_offset);
+
 	return;
 
 out_bmap_cancel:
Reviewed-by on v1 1/1
#2 lore raw
In reply to user.mail
Quoted 26 lines · user.mail

From: Eric Sandeen <[email protected]>

If longform_dir2_rebuild() has so few entries in *hashtab that it results in a short form directory, bump the link count manually as shortform directories have no explicit "." entry.

Without this, repair will end with i.e.:

resetting inode 131 nlinks from 2 to 1

in this case, because it thinks this directory inode only has 1 link discovered, and then a 2nd repair will fix it:

resetting inode 131 nlinks from 1 to 2

because shortform_dir2_entry_check() explicitly adds the extra ref when the (newly-created)shortform directory is checked:

/*
* no '.' entry in shortform dirs, just bump up ref count by 1
* '..' was already (or will be) accounted for and checked when
* the directory is reached or will be taken care of when the
* directory is moved to orphanage.
*/
add_inode_ref(current_irec, current_ino_offset);

Quoted 6 lines

Avoid this by adding the extra ref if we convert from longform to shortform.

---

I was about to send a v3 of my patch to handle this (fix link counts update...) based on djwong's review. This looks cleaner. Thanks!

Quoted 24 lines
 repair/phase6.c | 7 +++++++
 1 file changed, 7 insertions(+)
repair/phase6.c +7 -0
index dbc090a5..8804278a 100644
@@ -1392,6 +1392,13 @@ _("name create failed in ino %" PRIu64 " (%d)\n"), ino, error);
 _("name create failed (%d) during rebuild\n"), error);
 	}
 
+	/*
+	 * If we added too few entries to retain longform, add the extra
+	 * ref for . as this is now a shortform directory.
+	 */
+	if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL)
+		add_inode_ref(irec, ino_offset);
+
 	return;
 
 out_bmap_cancel:
Signature · 1 line
2.49.0
#3 lore raw
Quoted 30 lines · Bill O'Donnell
Quoted 29 lines · user.mail

From: Eric Sandeen <[email protected]>

If longform_dir2_rebuild() has so few entries in *hashtab that it results in a short form directory, bump the link count manually as shortform directories have no explicit "." entry.

Without this, repair will end with i.e.:

resetting inode 131 nlinks from 2 to 1

in this case, because it thinks this directory inode only has 1 link discovered, and then a 2nd repair will fix it:

resetting inode 131 nlinks from 1 to 2

because shortform_dir2_entry_check() explicitly adds the extra ref when the (newly-created)shortform directory is checked:

/*
* no '.' entry in shortform dirs, just bump up ref count by 1
* '..' was already (or will be) accounted for and checked when
* the directory is reached or will be taken care of when the
* directory is moved to orphanage.
*/
add_inode_ref(current_irec, current_ino_offset);

Avoid this by adding the extra ref if we convert from longform to shortform.

Quoted 6 lines
Quoted 3 lines

---

I was about to send a v3 of my patch to handle this (fix link counts update...) based on djwong's review. This looks cleaner. Thanks!

This is related to, but independent of, your patch (see my self-reply). Please continue to fix your case, so that all entries do not end up in lost+found when the header is bad.

Thanks,
-Eric

Quoted 29 lines
Quoted 24 lines
 repair/phase6.c | 7 +++++++
 1 file changed, 7 insertions(+)
repair/phase6.c +7 -0
index dbc090a5..8804278a 100644
@@ -1392,6 +1392,13 @@ _("name create failed in ino %" PRIu64 " (%d)\n"), ino, error);
 _("name create failed (%d) during rebuild\n"), error);
 	}
 
+	/*
+	 * If we added too few entries to retain longform, add the extra
+	 * ref for . as this is now a shortform directory.
+	 */
+	if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL)
+		add_inode_ref(irec, ino_offset);
+
 	return;
 
 out_bmap_cancel:
Signature · 1 line
2.49.0
Reviewed-by
#4 lore raw
Quoted 35 lines · Eric Sandeen
Quoted 34 lines · Bill O'Donnell
Quoted 32 lines · user.mail

From: Eric Sandeen <[email protected]>

If longform_dir2_rebuild() has so few entries in *hashtab that it results in a short form directory, bump the link count manually as shortform directories have no explicit "." entry.

Without this, repair will end with i.e.:

resetting inode 131 nlinks from 2 to 1

in this case, because it thinks this directory inode only has 1 link discovered, and then a 2nd repair will fix it:

resetting inode 131 nlinks from 1 to 2

because shortform_dir2_entry_check() explicitly adds the extra ref when the (newly-created)shortform directory is checked:

/*
* no '.' entry in shortform dirs, just bump up ref count by 1
* '..' was already (or will be) accounted for and checked when
* the directory is reached or will be taken care of when the
* directory is moved to orphanage.
*/
add_inode_ref(current_irec, current_ino_offset);

Avoid this by adding the extra ref if we convert from longform to shortform.

---

Quoted 6 lines
Quoted 2 lines

I was about to send a v3 of my patch to handle this (fix link counts update...) based on djwong's review. This looks cleaner. Thanks!

This is related to, but independent of, your patch (see my self-reply). Please continue to fix your case, so that all entries do not end up in lost+found when the header is bad.

Ah, right. Looks good still ;)

Quoted 34 lines

Thanks,
-Eric

Quoted 29 lines
Quoted 24 lines
 repair/phase6.c | 7 +++++++
 1 file changed, 7 insertions(+)
repair/phase6.c +7 -0
index dbc090a5..8804278a 100644
@@ -1392,6 +1392,13 @@ _("name create failed in ino %" PRIu64 " (%d)\n"), ino, error);
 _("name create failed (%d) during rebuild\n"), error);
 	}
 
+	/*
+	 * If we added too few entries to retain longform, add the extra
+	 * ref for . as this is now a shortform directory.
+	 */
+	if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL)
+		add_inode_ref(irec, ino_offset);
+
 	return;
 
 out_bmap_cancel:
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#5 lore raw
In reply to user.mail
Quoted 26 lines · user.mail

From: Eric Sandeen <[email protected]>

If longform_dir2_rebuild() has so few entries in *hashtab that it results in a short form directory, bump the link count manually as shortform directories have no explicit "." entry.

Without this, repair will end with i.e.:

resetting inode 131 nlinks from 2 to 1

in this case, because it thinks this directory inode only has 1 link discovered, and then a 2nd repair will fix it:

resetting inode 131 nlinks from 1 to 2

because shortform_dir2_entry_check() explicitly adds the extra ref when the (newly-created)shortform directory is checked:

/*
* no '.' entry in shortform dirs, just bump up ref count by 1
* '..' was already (or will be) accounted for and checked when
* the directory is reached or will be taken care of when the
* directory is moved to orphanage.
*/
add_inode_ref(current_irec, current_ino_offset);

Quoted 5 lines

Avoid this by adding the extra ref if we convert from longform to shortform.

Whoever this is ^^^^^^^^^, the change makes sense to me. ;)

--D

Quoted 26 lines
---
 repair/phase6.c | 7 +++++++
 1 file changed, 7 insertions(+)
repair/phase6.c +7 -0
index dbc090a5..8804278a 100644
@@ -1392,6 +1392,13 @@ _("name create failed in ino %" PRIu64 " (%d)\n"), ino, error);
 _("name create failed (%d) during rebuild\n"), error);
 	}
 
+	/*
+	 * If we added too few entries to retain longform, add the extra
+	 * ref for . as this is now a shortform directory.
+	 */
+	if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL)
+		add_inode_ref(irec, ino_offset);
+
 	return;
 
 out_bmap_cancel:
Signature · 1 line
2.49.0
#6 lore raw
In reply to user.mail
Quoted 26 lines · user.mail

From: Eric Sandeen <[email protected]>

If longform_dir2_rebuild() has so few entries in *hashtab that it results in a short form directory, bump the link count manually as shortform directories have no explicit "." entry.

Without this, repair will end with i.e.:

resetting inode 131 nlinks from 2 to 1

in this case, because it thinks this directory inode only has 1 link discovered, and then a 2nd repair will fix it:

resetting inode 131 nlinks from 1 to 2

because shortform_dir2_entry_check() explicitly adds the extra ref when the (newly-created)shortform directory is checked:

/*
* no '.' entry in shortform dirs, just bump up ref count by 1
* '..' was already (or will be) accounted for and checked when
* the directory is reached or will be taken care of when the
* directory is moved to orphanage.
*/
add_inode_ref(current_irec, current_ino_offset);

Quoted 5 lines

Avoid this by adding the extra ref if we convert from longform to shortform.

I will drop this SoB when applying

Quoted 26 lines
---
 repair/phase6.c | 7 +++++++
 1 file changed, 7 insertions(+)
repair/phase6.c +7 -0
index dbc090a5..8804278a 100644
@@ -1392,6 +1392,13 @@ _("name create failed in ino %" PRIu64 " (%d)\n"), ino, error);
 _("name create failed (%d) during rebuild\n"), error);
 	}
 
+	/*
+	 * If we added too few entries to retain longform, add the extra
+	 * ref for . as this is now a shortform directory.
+	 */
+	if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL)
+		add_inode_ref(irec, ino_offset);
+
 	return;
 
 out_bmap_cancel:
Signature · 1 line
2.49.0
Signature · 1 line
- Andrey