generic: new test to check nlink returned by fstat()
Subsystems (2)
ChenXiaoSong
reviewerv4 cover generic: new test to check nlink returned by fstat()
From: ChenXiaoSong <[email protected]>
Resend it to [email protected].
Christoph's review:
- https://lore.kernel.org/linux-cifs/[email protected]/
Zorro's reviews:
- https://lore.kernel.org/linux-cifs/anBwHPuds0VQjHuu@zlang-mailbox/
- https://lore.kernel.org/linux-cifs/anBvmrwo6SvhVFuu@zlang-mailbox/
v4 on smb mailing list: https://lore.kernel.org/linux-cifs/[email protected]/
ChenXiaoSong (2):
generic/002: add test to hardlink group
generic: new test to check nlink returned by fstat()
tests/generic/002 | 2 +- tests/generic/798 | 59 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/798.out | 2 ++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100755 tests/generic/798 create mode 100644 tests/generic/798.out
Signature · 1 line
2.43.0
ChenXiaoSong
reviewerPATCH RESEND v4 1/2 generic/002: add test to hardlink group
From: ChenXiaoSong <[email protected]>
The test creates and removes hard links, so add it to the hardlink group.
--- tests/generic/002 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/generic/002 +1 -1
@@ -7,7 +7,7 @@ # simple inode link count test for a regular file # . ./common/preamble -_begin_fstest metadata udf auto quick +_begin_fstest metadata udf auto quick hardlink # Import common functions. . ./common/filter
Signature · 1 line
2.43.0
ChenXiaoSong
reviewerPATCH RESEND v4 2/2 generic: new test to check nlink returned by fstat()
In reply to ChenXiaoSongFrom: ChenXiaoSong <[email protected]>
Add a test to verify that fstat(2) returns the expected st_nlink value as hardlinks are created and removed.
Regression test for kernel commit:9dd1964ac59d ("smb/client: fix incorrect nlink returned by fstat()")
--- tests/generic/798 | 59 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/798.out | 2 ++ 2 files changed, 61 insertions(+) create mode 100755 tests/generic/798 create mode 100644 tests/generic/798.out
tests/generic/798 new file +59 -0
@@ -0,0 +1,59 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2026 KylinSoft Co., Ltd. All rights reserved. +# Author(s): ChenXiaoSong <[email protected]> +# +# FS QA Test 798 +# +# Check that fstat(2) returns the correct hard link count for a regular file. +# +# from +# tests/generic/002 +# Copyright (c) 2000-2001 Silicon Graphics, Inc. All Rights Reserved. +# +. ./common/preamble +_begin_fstest metadata auto quick hardlink + +_cleanup() +{ + cd / + rm -rf "$tmp".* "$testdir" +} + +_require_test +_require_hardlinks + +_fixed_by_fs_commit cifs 9dd1964ac59d \ + "smb/client: fix incorrect nlink returned by fstat()" + +_get_nlink() +{ + # This calls `fstat()`, see `stat_f()` in xfsprogs-dev.git io/stat.c: + # https://git.kernel.org/pub/scm/fs/xfs/xfsprogs-dev.git/tree/io/stat.c + $XFS_IO_PROG -c 'stat -r' "$1" | + sed -n 's/^stat\.nlink = //p' +} + +testdir=$TEST_DIR/$seq +rm -rf "$testdir" +mkdir "$testdir" + +touch "$testdir/tmp.1" +for ((l = 2; l <= 20; l++)); do + ln "$testdir/tmp.1" "$testdir/tmp.$l" + nlink=$(_get_nlink "$testdir/tmp.1") + if [ "$nlink" != "$l" ]; then + _fail "Expected nlink $l after creating link $testdir/tmp.$l, got ${nlink:-nothing}" + fi +done + +for ((l = 20; l >= 1; l--)); do + nlink=$(_get_nlink "$testdir/tmp.1") + if [ "$nlink" != "$l" ]; then + _fail "Expected nlink $l before removing link $testdir/tmp.$l, got ${nlink:-nothing}" + fi + rm -f "$testdir/tmp.$l" +done + +echo "Silence is golden" +_exit 0
tests/generic/798.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 798 +Silence is golden
Signature · 1 line
2.43.0