1#!/bin/ksh
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2020 by Datto, Inc. All rights reserved.
16#
17
18. $STF_SUITE/include/libtest.shlib
19
20#
21# Description:
22# zdb -d pool/<objset id> will display the dataset
23#
24# Strategy:
25# 1. Create a pool
26# 2. Write some data to a file
27# 3. Get the inode number (object number) of the file
28# 4. Run zdb -d to get the objset ID of the dataset
29# 5. Run zdb -dddddd pool/objsetID objectID (decimal)
30# 6. Confirm names
31# 7. Run zdb -dddddd pool/objsetID objectID (hex)
32# 8. Confirm names
33# 9. Obtain objsetID from /proc/spl/kstat/zfs/testpool/obset-0x<ID>
34#    (linux only)
35# 10. Run zdb -dddddd pool/objsetID (hex)
36# 11. Match name from zdb against proc entry
37#
38
39function cleanup
40{
41	datasetexists $TESTPOOL && destroy_pool $TESTPOOL
42}
43
44log_assert "Verify zdb -d <pool>/<objset ID> generates the correct names."
45log_onexit cleanup
46init_data=$TESTDIR/file1
47write_count=8
48blksize=131072
49verify_runnable "global"
50verify_disk_count "$DISKS" 2
51
52default_mirror_setup_noexit $DISKS
53file_write -o create -w -f $init_data -b $blksize -c $write_count
54
55# get object number of file
56listing=$(ls -i $init_data)
57set -A array $listing
58obj=${array[0]}
59log_note "file $init_data has object number $obj"
60
61output=$(zdb -d $TESTPOOL/$TESTFS)
62objset_id=$(echo $output | awk '{split($0,array,",")} END{print array[2]}' |
63    awk '{split($0,array," ")} END{print array[2]}')
64objset_hex=$(printf "0x%X" $objset_id)
65log_note "objset $TESTPOOL/$TESTFS has objset ID $objset_id ($objset_hex)"
66
67for id in "$objset_id" "$objset_hex"
68do
69	log_note "zdb -dddddd $TESTPOOL/$id $obj"
70	output=$(zdb -dddddd $TESTPOOL/$id $obj)
71	reason="($TESTPOOL/$TESTFS not in zdb output)"
72	echo $output |grep "$TESTPOOL/$TESTFS" > /dev/null
73	(( $? != 0 )) && log_fail \
74	    "zdb -dddddd $TESTPOOL/$id $obj failed $reason"
75	reason="(file1 not in zdb output)"
76	echo $output |grep "file1" > /dev/null
77	(( $? != 0 )) && log_fail \
78	    "zdb -dddddd $TESTPOOL/$id $obj failed $reason"
79	obj=$(printf "0x%X" $obj)
80done
81
82if is_linux; then
83	output=$(ls -1 /proc/spl/kstat/zfs/$TESTPOOL |grep objset- |tail -1)
84	objset_hex=${output#*-}
85	name_from_proc=$(cat /proc/spl/kstat/zfs/$TESTPOOL/$output |
86	    grep dataset_name | awk '{split($0,array," ")} END{print array[3]}')
87	log_note "checking zdb output for $name_from_proc"
88	reason="(name $name_from_proc from proc not in zdb output)"
89	log_note "zdb -dddddd $TESTPOOL/$objset_hex"
90	output=$(zdb -dddddd $TESTPOOL/$objset_hex)
91	echo $output |grep "$name_from_proc" > /dev/null
92	(( $? != 0 )) && log_fail \
93	    "zdb -dddddd $TESTPOOL/$objset_hex failed $reason"
94fi
95
96log_pass "zdb -d <pool>/<objset ID> generates the correct names."
97