From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2 4/5] btrfs-progs: mkfs-tests: a new test case to verify handling of hard links
Date: Thu, 1 Aug 2024 15:42:39 +0930 [thread overview]
Message-ID: <cfa3a9d4f18f11641a87f617feb073e54f03d79e.1722492491.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1722492491.git.wqu@suse.com>
The test case will create the following directory layout:
.
|- rootdir/
| |- inside_link
|- outside_link
Both inside_link and outside_link are hard links of each other.
And use rootdir/ as the rootdir for mkfs.
This is to ensure the nlink of inside_link is correctly set to 1.
Inspired by the recent rework which fixes the handling of hard links.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
| 24 +++++++++++++++++++
1 file changed, 24 insertions(+)
create mode 100755 tests/mkfs-tests/034-rootdir-extra-hard-links/test.sh
--git a/tests/mkfs-tests/034-rootdir-extra-hard-links/test.sh b/tests/mkfs-tests/034-rootdir-extra-hard-links/test.sh
new file mode 100755
index 000000000000..e5c00cb861e9
--- /dev/null
+++ b/tests/mkfs-tests/034-rootdir-extra-hard-links/test.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+#
+# Test if "mkfs.btrfs --rootdir" would handle hard links where one
+# is inside the rootdir, the other out of the rootdir.
+
+source "$TEST_TOP/common" || exit
+
+prepare_test_dev
+
+tmpdir=$(_mktemp_dir mkfs-rootdir-hardlinks)
+
+mkdir "$tmpdir/rootdir"
+touch "$tmpdir/rootdir/inside_link"
+ln "$tmpdir/rootdir/inside_link" "$tmpdir/outside_link"
+
+run_check "$TOP/mkfs.btrfs" --rootdir "$tmpdir/rootdir" -f "$TEST_DEV"
+
+# For older mkfs.btrfs --rootdir we will create inside_link with 2 links,
+# but since the other one is out of the rootdir, there should only be one
+# 1 link, leading to btrfs check fail.
+#
+# The new behavior will split all hard links into different inodes, thus
+# have correct nlink for each new inode.
+run_check "$TOP/btrfs" check "$TEST_DEV"
--
2.45.2
next prev 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 ` [PATCH v2 3/5] btrfs-progs: rootdir: warn about hard links Qu Wenruo
2024-08-01 6:12 ` Qu Wenruo [this message]
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=cfa3a9d4f18f11641a87f617feb073e54f03d79e.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