summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomohiro Kusumi <[email protected]>2019-05-30 08:26:46 +0900
committerBrian Behlendorf <[email protected]>2019-05-29 16:26:46 -0700
commit1608985a411a8fd7698a41f9150f4bb3543d7093 (patch)
treefae0e2913fd2c4628b251cb6fcfb2b851962a3d0
parentfe0c9f409a1914ad5e5ea5b7cf14a8991e6c1126 (diff)
Add link count test for root inode
Add tests for 97aa3ba44("Fix link count of root inode when snapdir is visible") as suggested in #8727. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Tomohiro Kusumi <[email protected]> Closes #8732
-rw-r--r--tests/runfiles/linux.run2
-rw-r--r--tests/zfs-tests/tests/functional/link_count/Makefile.am3
-rwxr-xr-xtests/zfs-tests/tests/functional/link_count/link_count_root_inode.ksh119
3 files changed, 122 insertions, 2 deletions
diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run
index 8219cf42b..22fc26212 100644
--- a/tests/runfiles/linux.run
+++ b/tests/runfiles/linux.run
@@ -635,7 +635,7 @@ tests = ['filesystem_count', 'filesystem_limit', 'snapshot_count',
tags = ['functional', 'limits']
[tests/functional/link_count]
-tests = ['link_count_001']
+tests = ['link_count_001', 'link_count_root_inode.ksh']
tags = ['functional', 'link_count']
[tests/functional/migration]
diff --git a/tests/zfs-tests/tests/functional/link_count/Makefile.am b/tests/zfs-tests/tests/functional/link_count/Makefile.am
index 669f3c142..bfb7154a6 100644
--- a/tests/zfs-tests/tests/functional/link_count/Makefile.am
+++ b/tests/zfs-tests/tests/functional/link_count/Makefile.am
@@ -2,4 +2,5 @@ pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/link_count
dist_pkgdata_SCRIPTS = \
cleanup.ksh \
setup.ksh \
- link_count_001.ksh
+ link_count_001.ksh \
+ link_count_root_inode.ksh
diff --git a/tests/zfs-tests/tests/functional/link_count/link_count_root_inode.ksh b/tests/zfs-tests/tests/functional/link_count/link_count_root_inode.ksh
new file mode 100755
index 000000000..d2bf30ac3
--- /dev/null
+++ b/tests/zfs-tests/tests/functional/link_count/link_count_root_inode.ksh
@@ -0,0 +1,119 @@
+#!/bin/ksh
+
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2019 by Tomohiro Kusumi. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify root inode (directory) has correct link count.
+#
+# STRATEGY:
+# 1. Create pool and fs.
+# 2. Test link count of root inode.
+# 3. Create directories and test link count of root inode.
+# 4. Delete directories and test link count of root inode.
+# 5. Create regular file and test link count of root inode.
+# 6. Delete regular file and test link count of root inode.
+#
+
+function assert_link_count
+{
+ typeset dirpath="$1"
+ typeset value="$2"
+
+ log_must test "$(ls -ld $dirpath | awk '{ print $2 }')" == "$value"
+}
+
+verify_runnable "both"
+
+log_note "Verify root inode (directory) has correct link count."
+
+# Delete a directory from link_count_001.ksh.
+if [ -d "${TESTDIR}" -a -d "${TESTDIR}/tmp" ]; then
+ log_must rm -rf ${TESTDIR}/tmp
+fi
+
+#
+# Test with hidden '.zfs' directory.
+# This also tests general directories.
+#
+log_note "Testing with snapdir set to hidden (default)"
+
+for dst in $TESTPOOL $TESTPOOL/$TESTFS
+do
+ typeset mtpt=$(get_prop mountpoint $dst)
+ log_must zfs set snapdir=hidden $dst
+ log_must test -d "$mtpt/.zfs"
+ if test -n "$(ls $mtpt)"; then
+ ls $mtpt
+ log_note "$mtpt not empty, skipping"
+ continue
+ fi
+ assert_link_count $mtpt 2
+
+ log_must mkdir $mtpt/a
+ assert_link_count $mtpt 3
+ log_must rmdir $mtpt/a
+ assert_link_count $mtpt 2
+
+ log_must mkdir -p $mtpt/a/b
+ assert_link_count $mtpt 3
+ log_must rmdir $mtpt/a/b
+ log_must rmdir $mtpt/a
+ assert_link_count $mtpt 2
+
+ log_must touch $mtpt/a
+ assert_link_count $mtpt 2
+ log_must rm $mtpt/a
+ assert_link_count $mtpt 2
+done
+
+#
+# Test with visible '.zfs' directory.
+#
+log_note "Testing with snapdir set to visible"
+
+for dst in $TESTPOOL $TESTPOOL/$TESTFS
+do
+ typeset mtpt=$(get_prop mountpoint $dst)
+ log_must zfs set snapdir=visible $dst
+ log_must test -d "$mtpt/.zfs"
+ if test -n "$(ls $mtpt)"; then
+ ls $mtpt
+ log_note "$mtpt not empty, skipping"
+ continue
+ fi
+ assert_link_count $mtpt 3
+
+ log_must mkdir $mtpt/a
+ assert_link_count $mtpt 4
+ log_must rmdir $mtpt/a
+ assert_link_count $mtpt 3
+
+ log_must mkdir -p $mtpt/a/b
+ assert_link_count $mtpt 4
+ log_must rmdir $mtpt/a/b
+ log_must rmdir $mtpt/a
+ assert_link_count $mtpt 3
+
+ log_must touch $mtpt/a
+ assert_link_count $mtpt 3
+ log_must rm $mtpt/a
+ assert_link_count $mtpt 3
+done
+
+log_pass "Verify root inode (directory) has correct link count passed"