Re: [PATCH] xfs_repair: Bump link count if longform_dir2_rebuild yields shortform dir

Eric Sandeen
2025-04-15T18:20:52Z

On 4/15/25 1:09 PM, user.mail wrote:
> From: Eric Sandeen <sandeen@redhat.com>
>
> 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.
>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> Signed-off-by: user.mail <sandeen@redhat.com>

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