5 # This file and its contents are supplied under the terms of the
6 # Common Development and Distribution License ("CDDL"), version 1.0.
7 # You may only use this file in accordance with the terms of version
10 # A full copy of the text of the CDDL should have accompanied this
11 # source. A copy of the CDDL is also available via the Internet at
12 # http://www.illumos.org/license/CDDL.
16 # Copyright (c) 2020 Lawrence Livermore National Security, LLC.
18 . $STF_SUITE/include/libtest.shlib
22 # Object range parameters passed to zdb -dd work correctly.
26 # 2. Create some files
27 # 3. Run zdb -dd with assorted object range arguments and verify output
31 datasetexists $TESTPOOL && destroy_pool $TESTPOOL
35 # Print objects in @dataset with identifiers greater than or equal to
36 # @begin and less than or equal to @end, without using object range
39 function get_object_list_range
44 get_object_list $dataset |
46 obj=$(echo $line | awk '{print $1}')
47 if [[ $obj -ge $begin && $obj -le $end ]] ; then
49 elif [[ $obj -gt $end ]] ; then
56 # Print just the list of objects from 'zdb -dd' with leading whitespace
57 # trimmed, discarding other zdb output, sorted by object identifier.
58 # Caller must pass in the dataset argument at minimum.
60 function get_object_list
62 zdb -P -dd $@ 2>/dev/null |
63 egrep "^ +-?([0-9]+ +){7}" |
64 sed 's/^[[:space:]]*//' |
68 log_assert "Verify zdb -dd object range arguments work correctly."
70 verify_runnable "both"
71 verify_disk_count "$DISKS" 2
72 default_mirror_setup_noexit $DISKS
74 for x in $(seq 0 7); do
81 # Get list of all objects, but filter out user/group objects which don't
82 # appear when using object or object range arguments
83 all_objects=$(get_object_list $TESTPOOL/$TESTFS | grep -v 'used$')
85 # Range 0:-1 gets all objects
87 actual=$(get_object_list $TESTPOOL/$TESTFS 0:-1)
88 log_must test "\n$actual\n" == "\n$expected\n"
90 # Range 0:-1:A gets all objects
92 actual=$(get_object_list $TESTPOOL/$TESTFS 0:-1:A)
93 log_must test "\n$actual\n" == "\n$expected\n"
95 # Range 0:-1:f must output all file objects
96 expected=$(grep "ZFS plain file" <<< $all_objects)
97 actual=$(get_object_list $TESTPOOL/$TESTFS 0:-1:f)
98 log_must test "\n$actual\n" == "\n$expected\n"
100 # Range 0:-1:d must output all directory objects
101 expected=$(grep "ZFS directory" <<< $all_objects)
102 actual=$(get_object_list $TESTPOOL/$TESTFS 0:-1:d)
103 log_must test "\n$actual\n" == "\n$expected\n"
105 # Range 0:-1:df must output all directory and file objects
106 expected=$(grep -e "ZFS directory" -e "ZFS plain file" <<< $all_objects)
107 actual=$(get_object_list $TESTPOOL/$TESTFS 0:-1:df)
108 log_must test "\n$actual\n" == "\n$expected\n"
110 # Range 0:-1:A-f-d must output all non-files and non-directories
111 expected=$(grep -v -e "ZFS plain file" -e "ZFS directory" <<< $all_objects)
112 actual=$(get_object_list $TESTPOOL/$TESTFS 0:-1:A-f-d)
113 log_must test "\n$actual\n" == "\n$expected\n"
115 # Specifying multiple ranges works
116 set -A obj_ids $(ls -i $TESTDIR | awk '{print $1}' | sort -n)
121 expected=$(get_object_list_range $TESTPOOL/$TESTFS $start1 $end1;
122 get_object_list_range $TESTPOOL/$TESTFS $start2 $end2)
123 actual=$(get_object_list $TESTPOOL/$TESTFS $start1:$end1 $start2:$end2)
124 log_must test "\n$actual\n" == "\n$expected\n"
126 # Combining ranges with individual object IDs works
127 expected=$(get_object_list_range $TESTPOOL/$TESTFS $start1 $end1;
128 get_object_list $TESTPOOL/$TESTFS $start2 $end2)
129 actual=$(get_object_list $TESTPOOL/$TESTFS $start1:$end1 $start2 $end2)
130 log_must test "\n$actual\n" == "\n$expected\n"
132 # Hex conversion must work for ranges and individual object identifiers
133 # (this test uses expected result from previous test).
134 start1_hex=$(printf "0x%x" $start1)
135 end1_hex=$(printf "0x%x" $end1)
136 start2_hex=$(printf "0x%x" $start2)
137 end2_hex=$(printf "0x%x" $end2)
138 actual=$(get_object_list $TESTPOOL/$TESTFS $start1_hex:$end1_hex \
139 $start2_hex $end2_hex)
140 log_must test "\n$actual\n" == "\n$expected\n"
142 # Specifying individual object IDs works
143 objects="$start1 $end1 $start2 $end2"
145 actual=$(get_object_list $TESTPOOL/$TESTFS $objects | awk '{print $1}' | xargs)
146 log_must test "$actual" == "$expected"
148 # Get all objects in the meta-objset to test m (spacemap) and z (zap) flags
149 all_mos_objects=$(get_object_list $TESTPOOL 0:-1)
151 # Range 0:-1:m must output all space map objects
152 expected=$(grep "SPA space map" <<< $all_mos_objects)
153 actual=$(get_object_list $TESTPOOL 0:-1:m)
154 log_must test "\n$actual\n" == "\n$expected\n"
156 # Range 0:-1:z must output all zap objects
157 expected=$(grep "zap" <<< $all_mos_objects)
158 actual=$(get_object_list $TESTPOOL 0:-1:z)
159 log_must test "\n$actual\n" == "\n$expected\n"
161 # Range 0:-1:A-m-z must output all non-space maps and non-zaps
162 expected=$(grep -v -e "zap" -e "SPA space map" <<< $all_mos_objects)
163 actual=$(get_object_list $TESTPOOL 0:-1:A-m-z)
164 log_must test "\n$actual\n" == "\n$expected\n"
166 # Range 0:-1:mz must output all space maps and zaps
167 expected=$(grep -e "SPA space map" -e "zap" <<< $all_mos_objects)
168 actual=$(get_object_list $TESTPOOL 0:-1:mz)
169 log_must test "\n$actual\n" == "\n$expected\n"
171 log_pass "zdb -dd object range arguments work correctly"