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
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.
15 # Copyright (c) 2019 by Datto, Inc. All rights reserved.
18 . $STF_SUITE/include/libtest.shlib
22 # zdb -R pool <DVA>:b will display the block
25 # 1. Create a pool, set compression to lzjb
26 # 2. Write some identifiable data to a file
27 # 3. Run zdb -ddddddbbbbbb against the file
28 # 4. Record the DVA of the first L1 block;
29 # record the first L0 block display; and
30 # record the 2nd L0 block display.
31 # 5. Run zdb -R with :bd displays first L0
32 # 6. Run zdb -R with :b80d displays 2nd L0
33 # 7. Run zdb -R with :db80 displays 2nd L0
34 # 8. Run zdb -R with :id flag displays indirect block
35 # (similar to zdb -ddddddbbbbbb output)
36 # 9. Run zdb -R with :id flag and .0 vdev
42 datasetexists $TESTPOOL && destroy_pool $TESTPOOL
45 log_assert "Verify zdb -R :b flag (block display) works as expected"
47 init_data=$TESTDIR/file1
51 # only read 256 128 byte block pointers in L1 (:i flag)
52 # 256 x 128 = 32k / 0x8000
55 verify_runnable "global"
56 verify_disk_count "$DISKS" 2
58 default_mirror_setup_noexit $DISKS
59 log_must zfs set recordsize=$blksize $TESTPOOL/$TESTFS
60 log_must zfs set compression=lzjb $TESTPOOL/$TESTFS
62 file_write -d R -o create -w -f $init_data -b $blksize -c $write_count
63 sync_pool $TESTPOOL true
65 # get object number of file
66 listing=$(ls -i $init_data)
69 log_note "file $init_data has object number $obj"
71 output=$(zdb -ddddddbbbbbb $TESTPOOL/$TESTFS $obj 2> /dev/null \
72 |grep -m 1 "L1 DVA" |head -n1)
73 dva=$(sed -Ene 's/^.+DVA\[0\]=<([^>]+)>.*/\1/p' <<< "$output")
74 log_note "first L1 block $init_data has a DVA of $dva"
75 output=$(zdb -ddddddbbbbbb $TESTPOOL/$TESTFS $obj 2> /dev/null \
76 |grep -m 1 "L0 DVA" |head -n1)
77 blk_out0=${output##*>}
78 blk_out0=${blk_out0##+([[:space:]])}
80 output=$(zdb -ddddddbbbbbb $TESTPOOL/$TESTFS $obj 2> /dev/null \
81 |grep -m 1 "1000 L0 DVA" |head -n1)
82 blk_out1=${output##*>}
83 blk_out1=${blk_out1##+([[:space:]])}
85 output=$(export ZDB_NO_ZLE=\"true\"; zdb -R $TESTPOOL $dva:bd\
88 output=${output##+([[:space:]])}
89 if [ "$output" != "$blk_out0" ]; then
90 log_fail "zdb -R :bd (block 0 display/decompress) failed"
93 output=$(export ZDB_NO_ZLE=\"true\"; zdb -R $TESTPOOL $dva:db80\
96 output=${output##+([[:space:]])}
97 if [ "$output" != "$blk_out1" ]; then
98 log_fail "zdb -R :db80 (block 1 display/decompress) failed"
101 output=$(export ZDB_NO_ZLE=\"true\"; zdb -R $TESTPOOL $dva:b80d\
104 output=${output##+([[:space:]])}
105 if [ "$output" != "$blk_out1" ]; then
106 log_fail "zdb -R :b80d (block 1 display/decompress) failed"
109 vdev=$(echo "$dva" |awk '{split($0,array,":")} END{print array[1]}')
110 offset=$(echo "$dva" |awk '{split($0,array,":")} END{print array[2]}')
111 output=$(export ZDB_NO_ZLE=\"true\";\
112 zdb -R $TESTPOOL $vdev:$offset:$l1_read_size:id 2> /dev/null)
113 block_cnt=$(echo "$output" | grep 'L0' | wc -l)
114 if [ $block_cnt -ne $write_count ]; then
115 log_fail "zdb -R :id (indirect block display) failed"
118 # read from specific half of mirror
120 log_note "Reading from DVA $vdev:$offset:$l1_read_size"
121 output=$(export ZDB_NO_ZLE=\"true\";\
122 zdb -R $TESTPOOL $vdev:$offset:$l1_read_size:id 2> /dev/null)
123 block_cnt=$(echo "$output" | grep 'L0' | wc -l)
124 if [ $block_cnt -ne $write_count ]; then
125 log_fail "zdb -R 0.0:offset:length:id (indirect block display) failed"
128 log_pass "zdb -R :b flag (block display) works as expected"