new file mode 100755
@@ -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"
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> --- .../034-rootdir-extra-hard-links/test.sh | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 tests/mkfs-tests/034-rootdir-extra-hard-links/test.sh