From: Su Yue <l@damenly.su>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/2] btrfs-progs: check/original: detect directory inode with nlinks >= 2
Date: Mon, 19 Jul 2021 08:39:11 +0800 [thread overview]
Message-ID: <lf63w2z5.fsf@damenly.su> (raw)
In-Reply-To: <20210718125449.311815-1-wqu@suse.com>
On Sun 18 Jul 2021 at 20:54, Qu Wenruo <wqu@suse.com> wrote:
> Linux VFS doesn't allow directory to have hard links, thus for
> btrfs
> on-disk directory inode items, their nlinks should never go
> beyond 1.
>
> Lowmem mode already has the check and will report it without
> problem.
> Only original mode needs this update.
>
> Reported-by: Pepperpoint <pepperpoint@mb.ardentcoding.com>
> Link:
> https://lore.kernel.org/linux-btrfs/162648632340.7.1932907459648384384.10178178@mb.ardentcoding.com/
> Signed-off-by: Qu Wenruo <wqu@suse.com>
>
Reviewed-by: Su Yue <l@damenly.su>
--
Su
> ---
> check/main.c | 7 +++++++
> check/mode-original.h | 1 +
> 2 files changed, 8 insertions(+)
>
> diff --git a/check/main.c b/check/main.c
> index ee6cf793251c..df2303939ffe 100644
> --- a/check/main.c
> +++ b/check/main.c
> @@ -623,6 +623,9 @@ static void print_inode_error(struct
> btrfs_root *root, struct inode_record *rec)
> rec->imode & ~07777);
> if (errors & I_ERR_INVALID_GEN)
> fprintf(stderr, ", invalid inode generation or transid");
> + if (errors & I_ERR_INVALID_NLINK)
> + fprintf(stderr, ", directory has invalid nlink %d",
> + rec->nlink);
> fprintf(stderr, "\n");
>
> /* Print the holes if needed */
> @@ -909,6 +912,10 @@ static int process_inode_item(struct
> extent_buffer *eb,
> if (S_ISLNK(rec->imode) &&
> flags & (BTRFS_INODE_IMMUTABLE | BTRFS_INODE_APPEND))
> rec->errors |= I_ERR_ODD_INODE_FLAGS;
> +
> + /* Directory should never have hard link */
> + if (S_ISDIR(rec->imode) && rec->nlink >= 2)
> + rec->errors |= I_ERR_INVALID_NLINK;
> /*
> * We don't have accurate root info to determine the correct
> * inode generation uplimit, use super_generation + 1 anyway
> diff --git a/check/mode-original.h b/check/mode-original.h
> index b075a95c9757..eed16d92d0db 100644
> --- a/check/mode-original.h
> +++ b/check/mode-original.h
> @@ -186,6 +186,7 @@ struct unaligned_extent_rec_t {
> #define I_ERR_MISMATCH_DIR_HASH (1 << 18)
> #define I_ERR_INVALID_IMODE (1 << 19)
> #define I_ERR_INVALID_GEN (1 << 20)
> +#define I_ERR_INVALID_NLINK (1 << 21)
>
> struct inode_record {
> struct list_head backrefs;
next prev parent reply other threads:[~2021-07-19 0:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-18 12:54 [PATCH 1/2] btrfs-progs: check/original: detect directory inode with nlinks >= 2 Qu Wenruo
2021-07-18 12:54 ` [PATCH 2/2] btrfs-progs: fsck-test: add test case where one dir has two links Qu Wenruo
2021-07-19 9:57 ` Anand Jain
2021-07-19 10:25 ` Qu Wenruo
2021-07-19 0:39 ` Su Yue [this message]
2021-07-30 13:54 ` [PATCH 1/2] btrfs-progs: check/original: detect directory inode with nlinks >= 2 David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=lf63w2z5.fsf@damenly.su \
--to=l@damenly.su \
--cc=linux-btrfs@vger.kernel.org \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).