public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2 3/5] btrfs-progs: rootdir: warn about hard links
Date: Thu,  1 Aug 2024 15:42:38 +0930	[thread overview]
Message-ID: <f12f7dfb97b7cfbe5e6cfc7e929d674e1444cfec.1722492491.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1722492491.git.wqu@suse.com>

The recent rework changes how we detect hard links.

[OLD BEHAVIOR]
We trusted st_nlink and st_ino, reuse them without extra sanity
checks.

That behavior has problems handling cross mount-point or hard links out
of the rootdir cases.

[NEW BEHAVIOR]
The new refactored code will treat every inode, no matter if it's a
hardlink, as a new inode.

This means we will break the hard link detection, and every hard link
will be created as a different inode.

For the most common use case, like populating a rootfs, it's toally
fine.

[EXTRA WARNING]
But for cases where the user have extra hard links inside the rootdir,
output a warning just to inform the end user.

This will not cause any content difference, just breaking the hard links
into new inodes.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 mkfs/rootdir.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/mkfs/rootdir.c b/mkfs/rootdir.c
index 3db32982550b..05787dc3f46c 100644
--- a/mkfs/rootdir.c
+++ b/mkfs/rootdir.c
@@ -419,6 +419,21 @@ static int ftw_add_inode(const char *full_path, const struct stat *st,
 	u64 ino;
 	int ret;
 
+	/*
+	 * Hard link need extra detection code, not supported for now, but
+	 * it's not to break anything but splitting the hard links into
+	 * new inodes.
+	 * And we do not even know if the hard links are inside the rootdir.
+	 *
+	 * So here we only need to do extra warning.
+	 *
+	 * On most filesystems st_nlink of a directory is the number of
+	 * subdirs, including "." and "..", so skip directory inodes.
+	 */
+	if (unlikely(!S_ISDIR(st->st_mode) && st->st_nlink > 1))
+		warning("'%s' has extra hard links, they will be converted into new inodes.",
+			full_path);
+
 	/* The rootdir itself. */
 	if (unlikely(ftwbuf->level == 0)) {
 		u64 root_ino = btrfs_root_dirid(&root->root_item);
-- 
2.45.2


  parent reply	other threads:[~2024-08-01  6:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-01  6:12 [PATCH v2 0/5] btrfs-progs: rework how we traverse rootdir Qu Wenruo
2024-08-01  6:12 ` [PATCH v2 1/5] btrfs-progs: constify the name parameter of btrfs_add_link() Qu Wenruo
2024-08-01  6:12 ` [PATCH v2 2/5] btrfs-progs: mkfs: rework how we traverse rootdir Qu Wenruo
2024-08-01  6:12 ` Qu Wenruo [this message]
2024-08-01  6:12 ` [PATCH v2 4/5] btrfs-progs: mkfs-tests: a new test case to verify handling of hard links Qu Wenruo
2024-08-01  6:12 ` [PATCH v2 5/5] btrfs-progs: mkfs-tests: verify cross mount point behavior for rootdir Qu Wenruo

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=f12f7dfb97b7cfbe5e6cfc7e929d674e1444cfec.1722492491.git.wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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