]> granicus.if.org Git - zfs/commitdiff
zfs receive and rollback can skew filesystem_count
authorloli10K <loli10K@users.noreply.github.com>
Tue, 8 Jan 2019 18:17:46 +0000 (19:17 +0100)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 8 Jan 2019 18:17:46 +0000 (10:17 -0800)
This commit fixes a small issue which causes both zfs receive and
rollback operations to incorrectly increase the "filesystem_count"
property value.

This change also adds a new test group "limits" to the ZFS Test Suite
to exercise both filesystem_count/limit and snapshot_count/limit
functionality.

Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
Closes #8232

configure.ac
module/zfs/dsl_destroy.c
tests/runfiles/linux.run
tests/zfs-tests/tests/functional/Makefile.am
tests/zfs-tests/tests/functional/limits/Makefile.am [new file with mode: 0644]
tests/zfs-tests/tests/functional/limits/cleanup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/limits/filesystem_count.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/limits/filesystem_limit.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/limits/setup.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/limits/snapshot_count.ksh [new file with mode: 0755]
tests/zfs-tests/tests/functional/limits/snapshot_limit.ksh [new file with mode: 0755]

index be3e556c183f478a41bf892f01912a57d094eb11..cf0e1bf5863f602b547c378442210797b37ce4d6 100644 (file)
@@ -290,6 +290,7 @@ AC_CONFIG_FILES([
        tests/zfs-tests/tests/functional/largest_pool/Makefile
        tests/zfs-tests/tests/functional/link_count/Makefile
        tests/zfs-tests/tests/functional/libzfs/Makefile
+       tests/zfs-tests/tests/functional/limits/Makefile
        tests/zfs-tests/tests/functional/migration/Makefile
        tests/zfs-tests/tests/functional/mmap/Makefile
        tests/zfs-tests/tests/functional/mmp/Makefile
index 97d7befbd0bf1acb0e8696346436ae68631e8ea3..465b3dfac8908c42d1bc1ac8fb3bc4f33c4fbac1 100644 (file)
@@ -792,14 +792,8 @@ dsl_dir_destroy_sync(uint64_t ddobj, dmu_tx_t *tx)
 
        ASSERT0(dsl_dir_phys(dd)->dd_head_dataset_obj);
 
-       /*
-        * Decrement the filesystem count for all parent filesystems.
-        *
-        * When we receive an incremental stream into a filesystem that already
-        * exists, a temporary clone is created.  We never count this temporary
-        * clone, whose name begins with a '%'.
-        */
-       if (dd->dd_myname[0] != '%' && dd->dd_parent != NULL)
+       /* Decrement the filesystem count for all parent filesystems. */
+       if (dd->dd_parent != NULL)
                dsl_fs_ss_count_adjust(dd->dd_parent, -1,
                    DD_FIELD_FILESYSTEM_COUNT, tx);
 
index 38f040126a82757ed242292f75208e085ab8e33d..0b41d087b2dbaf69cb22634f6607acb916209540 100644 (file)
@@ -616,6 +616,11 @@ pre =
 post =
 tags = ['functional', 'largest_pool']
 
+[tests/functional/limits]
+tests = ['filesystem_count', 'filesystem_limit', 'snapshot_count',
+    'snapshot_limit']
+tags = ['functional', 'limits']
+
 [tests/functional/link_count]
 tests = ['link_count_001']
 tags = ['functional', 'link_count']
index 961a340272a9c41ecc5a80239b5a2e7c1f8521ab..90f5e1821318c6fda21e85aef3e5259aa18abe7a 100644 (file)
@@ -32,6 +32,7 @@ SUBDIRS = \
        large_files \
        largest_pool \
        libzfs \
+       limits \
        pyzfs \
        link_count \
        migration \
diff --git a/tests/zfs-tests/tests/functional/limits/Makefile.am b/tests/zfs-tests/tests/functional/limits/Makefile.am
new file mode 100644 (file)
index 0000000..7245592
--- /dev/null
@@ -0,0 +1,9 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/limits
+dist_pkgdata_SCRIPTS = \
+       setup.ksh \
+       cleanup.ksh \
+       filesystem_count.ksh \
+       filesystem_limit.ksh \
+       snapshot_count.ksh \
+       snapshot_limit.ksh
+
diff --git a/tests/zfs-tests/tests/functional/limits/cleanup.ksh b/tests/zfs-tests/tests/functional/limits/cleanup.ksh
new file mode 100755 (executable)
index 0000000..e78deac
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/ksh -p
+#
+# 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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/limits/filesystem_count.ksh b/tests/zfs-tests/tests/functional/limits/filesystem_count.ksh
new file mode 100755 (executable)
index 0000000..e9f839c
--- /dev/null
@@ -0,0 +1,123 @@
+#!/bin/ksh -p
+#
+# 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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# ZFS 'filesystem_count' property is handled correctly by various actions
+#
+# STRATEGY:
+# 1. Verify 'zfs create' and 'zfs clone' increment 'filesystem_count' value
+# 2. Verify 'zfs destroy' decrements the value
+# 3. Verify 'zfs rename' updates counts across different hierarchies
+# 4. Verify 'zfs promote' preserves counts within different hierarchies
+# 5. Verify 'zfs receive' correct behaviour
+# 6. Verify 'zfs rollback' does not update 'filesystem_count' value
+# 7. Verify 'zfs diff' does not update 'filesystem_count' value
+#
+
+verify_runnable "both"
+
+function setup
+{
+       log_must zfs create "$DATASET_TEST"
+       log_must zfs create "$DATASET_UTIL"
+       # Set filesystem_limit just to activate the filesystem_count property
+       log_must zfs set filesystem_limit=100 "$DATASET_TEST"
+}
+
+function cleanup
+{
+       destroy_dataset "$DATASET_TEST" "-Rf"
+       destroy_dataset "$DATASET_UTIL" "-Rf"
+       rm -f $ZSTREAM
+}
+
+log_assert "Verify 'filesystem_count' is handled correctly by various actions"
+log_onexit cleanup
+
+DATASET_TEST="$TESTPOOL/$TESTFS/filesystem_count_test"
+DATASET_UTIL="$TESTPOOL/$TESTFS/filesystem_count_util"
+ZSTREAM="$TEST_BASE_DIR/filesystem_count.$$"
+
+# 1. Verify 'zfs create' and 'zfs clone' increment 'filesystem_count' value
+setup
+log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "0"
+log_must zfs create "$DATASET_TEST/create_clone"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
+log_must zfs snapshot "$DATASET_TEST/create_clone@snap"
+log_must zfs clone "$DATASET_TEST/create_clone@snap" "$DATASET_TEST/clone"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "2"
+cleanup
+
+# 2. Verify 'zfs destroy' decrements the value
+setup
+log_must zfs create "$DATASET_TEST/destroy"
+log_must zfs destroy "$DATASET_TEST/destroy"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "0"
+cleanup
+
+# 3. Verify 'zfs rename' updates counts across different hierarchies
+setup
+log_must zfs create "$DATASET_TEST/rename"
+log_must zfs rename "$DATASET_TEST/rename" "$DATASET_UTIL/renamed"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "0"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_UTIL")" == "1"
+cleanup
+
+# 4. Verify 'zfs promote' preserves counts within different hierarchies
+setup
+log_must zfs create "$DATASET_UTIL/promote"
+log_must zfs snapshot "$DATASET_UTIL/promote@snap"
+log_must zfs clone "$DATASET_UTIL/promote@snap" "$DATASET_TEST/promoted"
+log_must zfs promote "$DATASET_TEST/promoted"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_UTIL")" == "1"
+cleanup
+
+# 5. Verify 'zfs receive' correct behaviour
+setup
+log_must zfs create "$DATASET_UTIL/send"
+log_must zfs snapshot "$DATASET_UTIL/send@snap1"
+log_must zfs snapshot "$DATASET_UTIL/send@snap2"
+log_must eval "zfs send $DATASET_UTIL/send@snap1 > $ZSTREAM"
+log_must eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
+log_must eval "zfs send -i @snap1 $DATASET_UTIL/send@snap2 > $ZSTREAM"
+log_must eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
+cleanup
+
+# 6. Verify 'zfs rollback' does not update 'filesystem_count' value
+setup
+log_must zfs create "$DATASET_TEST/rollback"
+log_must zfs snapshot "$DATASET_TEST/rollback@snap"
+log_must zfs rollback "$DATASET_TEST/rollback@snap"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
+cleanup
+
+# 7. Verify 'zfs diff' does not update 'filesystem_count' value
+setup
+log_must zfs create "$DATASET_TEST/diff"
+log_must zfs snapshot "$DATASET_TEST/diff@snap1"
+log_must zfs snapshot "$DATASET_TEST/diff@snap2"
+log_must zfs diff "$DATASET_TEST/diff@snap1" "$DATASET_TEST/diff@snap2"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
+log_must zfs diff "$DATASET_TEST/diff@snap2"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "1"
+
+log_pass "'filesystem_count' property is handled correctly"
diff --git a/tests/zfs-tests/tests/functional/limits/filesystem_limit.ksh b/tests/zfs-tests/tests/functional/limits/filesystem_limit.ksh
new file mode 100755 (executable)
index 0000000..a659792
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/ksh -p
+#
+# 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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# ZFS 'filesystem_limit' is enforced when executing various actions
+#
+# STRATEGY:
+# 1. Verify 'zfs create' and 'zfs clone' cannot exceed the filesystem_limit
+# 2. Verify 'zfs rename' cannot move filesystems exceeding the limit
+# 3. Verify 'zfs receive' cannot exceed the limit
+#
+
+verify_runnable "both"
+
+function setup
+{
+       log_must zfs create "$DATASET_TEST"
+       log_must zfs create "$DATASET_UTIL"
+}
+
+function cleanup
+{
+       destroy_dataset "$DATASET_TEST" "-Rf"
+       destroy_dataset "$DATASET_UTIL" "-Rf"
+       rm -f $ZSTREAM
+}
+
+log_assert "Verify 'filesystem_limit' is enforced executing various actions"
+log_onexit cleanup
+
+DATASET_TEST="$TESTPOOL/$TESTFS/filesystem_limit_test"
+DATASET_UTIL="$TESTPOOL/$TESTFS/filesystem_limit_util"
+ZSTREAM="$TEST_BASE_DIR/filesystem_limit.$$"
+
+# 1. Verify 'zfs create' and 'zfs clone' cannot exceed the filesystem_limit
+setup
+log_must zfs set filesystem_limit=1 "$DATASET_TEST"
+log_must zfs create "$DATASET_TEST/create"
+log_mustnot zfs create "$DATASET_TEST/create_exceed"
+log_mustnot datasetexists "$DATASET_TEST/create_exceed"
+log_must zfs set filesystem_limit=2 "$DATASET_TEST"
+log_must zfs snapshot "$DATASET_TEST/create@snap"
+log_must zfs clone "$DATASET_TEST/create@snap" "$DATASET_TEST/clone"
+log_mustnot zfs clone "$DATASET_TEST/create@snap" "$DATASET_TEST/clone_exceed"
+log_mustnot datasetexists "$DATASET_TEST/clone_exceed"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "2"
+cleanup
+
+# 2. Verify 'zfs rename' cannot move filesystems exceeding the limit
+setup
+log_must zfs set filesystem_limit=0 "$DATASET_UTIL"
+log_must zfs create "$DATASET_TEST/rename"
+log_mustnot zfs rename "$DATASET_TEST/rename" "$DATASET_UTIL/renamed"
+log_mustnot datasetexists "$DATASET_UTIL/renamed"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_UTIL")" == "0"
+cleanup
+
+# 3. Verify 'zfs receive' cannot exceed the limit
+setup
+log_must zfs set filesystem_limit=0 "$DATASET_TEST"
+log_must zfs create "$DATASET_UTIL/send"
+log_must zfs snapshot "$DATASET_UTIL/send@snap1"
+log_must eval "zfs send $DATASET_UTIL/send@snap1 > $ZSTREAM"
+log_mustnot eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
+log_mustnot datasetexists "$DATASET_TEST/received"
+log_must test "$(get_prop 'filesystem_count' "$DATASET_TEST")" == "0"
+
+log_pass "'filesystem_limit' property is enforced"
diff --git a/tests/zfs-tests/tests/functional/limits/setup.ksh b/tests/zfs-tests/tests/functional/limits/setup.ksh
new file mode 100755 (executable)
index 0000000..af6edbe
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/ksh -p
+#
+# 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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+
+default_volume_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/limits/snapshot_count.ksh b/tests/zfs-tests/tests/functional/limits/snapshot_count.ksh
new file mode 100755 (executable)
index 0000000..ac4a47d
--- /dev/null
@@ -0,0 +1,100 @@
+#!/bin/ksh -p
+#
+# 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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# ZFS 'snapshot_count' property is handled correctly by various actions
+#
+# STRATEGY:
+# 1. Verify 'zfs snapshot' increments 'snapshot_count' value
+# 2. Verify 'zfs destroy' decrements the value
+# 3. Verify 'zfs rename' updates counts across different hierarchies
+# 4. Verify 'zfs promote' updates counts across different hierarchies
+# 5. Verify 'zfs receive' correct behaviour
+#
+
+verify_runnable "both"
+
+function setup
+{
+       log_must zfs create "$DATASET_TEST"
+       log_must zfs create "$DATASET_UTIL"
+       # Set snapshot_limit just to activate the snapshot_count property
+       log_must zfs set snapshot_limit=100 "$DATASET_TEST"
+}
+
+function cleanup
+{
+       destroy_dataset "$DATASET_TEST" "-Rf"
+       destroy_dataset "$DATASET_UTIL" "-Rf"
+       rm -f $ZSTREAM
+}
+
+log_assert "Verify 'snapshot_count' is handled correctly by various actions"
+log_onexit cleanup
+
+DATASET_TEST="$TESTPOOL/$TESTFS/snapshot_count_test"
+DATASET_UTIL="$TESTPOOL/$TESTFS/snapshot_count_util"
+ZSTREAM="$TEST_BASE_DIR/snapshot_count.$$"
+
+# 1. Verify 'zfs snapshot' increments 'snapshot_count' value
+setup
+log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "0"
+log_must zfs snapshot "$DATASET_TEST@snap"
+log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "1"
+cleanup
+
+# 2. Verify 'zfs destroy' decrements the value
+setup
+log_must zfs snapshot "$DATASET_TEST@snap"
+log_must zfs destroy "$DATASET_TEST@snap"
+log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "0"
+cleanup
+
+# 3. Verify 'zfs rename' updates counts across different hierarchies
+setup
+log_must zfs create "$DATASET_TEST/renamed"
+log_must zfs snapshot "$DATASET_TEST/renamed@snap"
+log_must zfs rename "$DATASET_TEST/renamed" "$DATASET_UTIL/renamed"
+log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "0"
+log_must test "$(get_prop 'snapshot_count' "$DATASET_UTIL")" == "1"
+cleanup
+
+# 4. Verify 'zfs promote' updates counts across different hierarchies
+setup
+log_must zfs create "$DATASET_UTIL/promote"
+log_must zfs snapshot "$DATASET_UTIL/promote@snap"
+log_must zfs clone "$DATASET_UTIL/promote@snap" "$DATASET_TEST/promoted"
+log_must zfs promote "$DATASET_TEST/promoted"
+log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "1"
+log_must test "$(get_prop 'snapshot_count' "$DATASET_UTIL")" == "0"
+cleanup
+
+# 5. Verify 'zfs receive' correct behaviour
+setup
+log_must zfs create "$DATASET_UTIL/send"
+log_must zfs snapshot "$DATASET_UTIL/send@snap1"
+log_must zfs snapshot "$DATASET_UTIL/send@snap2"
+log_must eval "zfs send $DATASET_UTIL/send@snap1 > $ZSTREAM"
+log_must eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
+log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "1"
+log_must eval "zfs send -i @snap1 $DATASET_UTIL/send@snap2 > $ZSTREAM"
+log_must eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
+log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "2"
+
+log_pass "'snapshot_count' property is handled correctly"
diff --git a/tests/zfs-tests/tests/functional/limits/snapshot_limit.ksh b/tests/zfs-tests/tests/functional/limits/snapshot_limit.ksh
new file mode 100755 (executable)
index 0000000..fa4b6e8
--- /dev/null
@@ -0,0 +1,99 @@
+#!/bin/ksh -p
+#
+# 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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# ZFS 'snapshot_limit' is enforced when executing various actions
+#
+# STRATEGY:
+# 1. Verify 'zfs snapshot' cannot exceed the snapshot_limit
+# 2. Verify 'zfs rename' cannot move snapshots exceeding the limit
+# 3. Verify 'zfs promote' cannot exceed the limit
+# 4. Verify 'zfs receive' cannot exceed the limit
+#
+
+verify_runnable "both"
+
+function setup
+{
+       log_must zfs create "$DATASET_TEST"
+       log_must zfs create "$DATASET_UTIL"
+}
+
+function cleanup
+{
+       destroy_dataset "$DATASET_TEST" "-Rf"
+       destroy_dataset "$DATASET_UTIL" "-Rf"
+       rm -f $ZSTREAM
+}
+
+log_assert "Verify 'snapshot_limit' is enforced when executing various actions"
+log_onexit cleanup
+
+DATASET_TEST="$TESTPOOL/$TESTFS/snapshot_limit_test"
+DATASET_UTIL="$TESTPOOL/$TESTFS/snapshot_limit_util"
+ZSTREAM="$TEST_BASE_DIR/snapshot_limit.$$"
+
+# 1. Verify 'zfs snapshot' cannot exceed the snapshot_limit
+setup
+log_must zfs set snapshot_limit=1 "$DATASET_TEST"
+log_must zfs snapshot "$DATASET_TEST@snap"
+log_mustnot zfs snapshot "$DATASET_TEST@snap_exceed"
+log_mustnot datasetexists "$DATASET_TEST@snap_exceed"
+log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "1"
+cleanup
+
+# 2. Verify 'zfs rename' cannot move snapshots exceeding the limit
+setup
+log_must zfs set snapshot_limit=0 "$DATASET_UTIL"
+log_must zfs create "$DATASET_TEST/rename"
+log_must zfs snapshot "$DATASET_TEST/rename@snap"
+log_mustnot zfs rename "$DATASET_TEST/rename" "$DATASET_UTIL/renamed"
+log_mustnot datasetexists "$DATASET_UTIL/renamed"
+log_must test "$(get_prop 'snapshot_count' "$DATASET_UTIL")" == "0"
+cleanup
+
+# 3. Verify 'zfs promote' cannot exceed the limit
+setup
+log_must zfs set snapshot_limit=0 "$DATASET_UTIL"
+log_must zfs create "$DATASET_TEST/promote"
+log_must zfs snapshot "$DATASET_TEST/promote@snap"
+log_must zfs clone "$DATASET_TEST/promote@snap" "$DATASET_UTIL/promoted"
+log_mustnot zfs promote "$DATASET_UTIL/promoted"
+log_mustnot datasetexists "$DATASET_UTIL/promoted@snap"
+log_must test "$(get_prop 'snapshot_count' "$DATASET_UTIL")" == "0"
+cleanup
+
+# 4. Verify 'zfs receive' cannot exceed the limit
+setup
+log_must zfs set snapshot_limit=0 "$DATASET_TEST"
+log_must zfs create "$DATASET_UTIL/send"
+log_must zfs snapshot "$DATASET_UTIL/send@snap1"
+log_must eval "zfs send $DATASET_UTIL/send@snap1 > $ZSTREAM"
+log_mustnot eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
+log_mustnot datasetexists "$DATASET_TEST/received"
+log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "0"
+log_must zfs set snapshot_limit=1 "$DATASET_TEST"
+log_must eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
+log_must zfs snapshot "$DATASET_UTIL/send@snap2"
+log_must eval "zfs send -i @snap1 $DATASET_UTIL/send@snap2 > $ZSTREAM"
+log_mustnot eval "zfs receive $DATASET_TEST/received < $ZSTREAM"
+log_mustnot datasetexists "$DATASET_TEST/received@snap2"
+log_must test "$(get_prop 'snapshot_count' "$DATASET_TEST")" == "1"
+
+log_pass "'snapshot_limit' property is enforced"