Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Oct 2023 15:03:17 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: cfcb53e1a132 - stable/14 - makefs/zfs: Add a regression test which checks the 'used*' properties
Message-ID:  <202310251503.39PF3HZ5039072@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=cfcb53e1a132932bf3d22e87e47e38e64b118c4a

commit cfcb53e1a132932bf3d22e87e47e38e64b118c4a
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-10-23 15:11:26 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2023-10-25 14:27:27 +0000

    makefs/zfs: Add a regression test which checks the 'used*' properties
    
    PR:             274613
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
---
 usr.sbin/makefs/tests/makefs_zfs_tests.sh | 73 ++++++++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/makefs/tests/makefs_zfs_tests.sh b/usr.sbin/makefs/tests/makefs_zfs_tests.sh
index 9173600dc555..1811b1bc8a8c 100644
--- a/usr.sbin/makefs/tests/makefs_zfs_tests.sh
+++ b/usr.sbin/makefs/tests/makefs_zfs_tests.sh
@@ -1,7 +1,7 @@
 #-
 # SPDX-License-Identifier: BSD-2-Clause
 #
-# Copyright (c) 2022 The FreeBSD Foundation
+# Copyright (c) 2022-2023 The FreeBSD Foundation
 #
 # This software was developed by Mark Johnston under sponsorship from
 # the FreeBSD Foundation.
@@ -57,7 +57,7 @@ import_image()
 	atf_check -e empty -o save:$TEST_MD_DEVICE_FILE -s exit:0 \
 	    mdconfig -a -f $TEST_IMAGE
 	atf_check -o ignore -e empty -s exit:0 \
-            zdb -e -p /dev/$(cat $TEST_MD_DEVICE_FILE) -mmm -ddddd $ZFS_POOL_NAME
+	    zdb -e -p /dev/$(cat $TEST_MD_DEVICE_FILE) -mmm -ddddd $ZFS_POOL_NAME
 	atf_check zpool import -R $TEST_MOUNT_DIR $ZFS_POOL_NAME
 	echo "$ZFS_POOL_NAME" > $TEST_ZFS_POOL_NAME
 }
@@ -726,6 +726,74 @@ root_props_cleanup()
 	common_cleanup
 }
 
+#
+# Verify that usedds and usedchild props are set properly.
+#
+atf_test_case used_space_props cleanup
+used_space_props_body()
+{
+	local used usedds usedchild
+	local rootmb childmb totalmb fudge
+	local status
+
+	create_test_dirs
+	cd $TEST_INPUTS_DIR
+	mkdir dir
+
+	rootmb=17
+	childmb=39
+	totalmb=$(($rootmb + $childmb))
+	fudge=$((2 * 1024 * 1024))
+
+	atf_check -e ignore dd if=/dev/random of=foo bs=1M count=$rootmb
+	atf_check -e ignore dd if=/dev/random of=dir/bar bs=1M count=$childmb
+
+	cd -
+
+	atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
+	    -o fs=${ZFS_POOL_NAME}/dir \
+	    $TEST_IMAGE $TEST_INPUTS_DIR
+
+	import_image
+
+	# Make sure that each dataset's space usage is no more than 2MB larger
+	# than their files.  This number is magic and might need to change
+	# someday.
+	usedds=$(zfs list -o usedds -Hp ${ZFS_POOL_NAME})
+	atf_check test $usedds -gt $(($rootmb * 1024 * 1024)) -a \
+	    $usedds -le $(($rootmb * 1024 * 1024 + $fudge))
+	usedds=$(zfs list -o usedds -Hp ${ZFS_POOL_NAME}/dir)
+	atf_check test $usedds -gt $(($childmb * 1024 * 1024)) -a \
+	    $usedds -le $(($childmb * 1024 * 1024 + $fudge))
+
+	# Make sure that the usedchild property value makes sense: the parent's
+	# value corresponds to the size of the child, and the child has no
+	# children.
+	usedchild=$(zfs list -o usedchild -Hp ${ZFS_POOL_NAME})
+	atf_check test $usedchild -gt $(($childmb * 1024 * 1024)) -a \
+	    $usedchild -le $(($childmb * 1024 * 1024 + $fudge))
+	atf_check -o inline:'0\n' \
+	    zfs list -Hp -o usedchild ${ZFS_POOL_NAME}/dir
+
+	# Make sure that the used property value makes sense: the parent's
+	# value is the sum of the two sizes, and the child's value is the
+	# same as its usedds value, which has already been checked.
+	used=$(zfs list -o used -Hp ${ZFS_POOL_NAME})
+	atf_check test $used -gt $(($totalmb * 1024 * 1024)) -a \
+	    $used -le $(($totalmb * 1024 * 1024 + 2 * $fudge))
+	used=$(zfs list -o used -Hp ${ZFS_POOL_NAME}/dir)
+	atf_check -o inline:$used'\n' \
+	    zfs list -Hp -o usedds ${ZFS_POOL_NAME}/dir
+
+	# Both datasets do not have snapshots.
+	atf_check -o inline:'0\n' zfs list -Hp -o usedsnap ${ZFS_POOL_NAME}
+	atf_check -o inline:'0\n' zfs list -Hp -o usedsnap ${ZFS_POOL_NAME}/dir
+}
+used_space_props_cleanup()
+{
+	common_cleanup
+}
+
 atf_init_test_cases()
 {
 	atf_add_test_case autoexpand
@@ -748,6 +816,7 @@ atf_init_test_cases()
 	atf_add_test_case snapshot
 	atf_add_test_case soft_links
 	atf_add_test_case root_props
+	atf_add_test_case used_space_props
 
 	# XXXMJ tests:
 	# - test with different ashifts (at least, 9 and 12), different image sizes



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202310251503.39PF3HZ5039072>