]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zdb/zdb_display_block.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zdb / zdb_display_block.ksh
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) 2019 by Datto, Inc. All rights reserved.
16 #
17
18 . $STF_SUITE/include/libtest.shlib
19
20 #
21 # Description:
22 # zdb -R pool <DVA>:b will display the block
23 #
24 # Strategy:
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
37 #
38
39
40 function cleanup
41 {
42         datasetexists $TESTPOOL && destroy_pool $TESTPOOL
43 }
44
45 log_assert "Verify zdb -R :b flag (block display) works as expected"
46 log_onexit cleanup
47 init_data=$TESTDIR/file1
48 write_count=256
49 blksize=4096
50
51 # only read 256 128 byte block pointers in L1 (:i flag)
52 # 256 x 128 = 32k / 0x8000
53 l1_read_size="8000"
54
55 verify_runnable "global"
56 verify_disk_count "$DISKS" 2
57
58 default_mirror_setup_noexit $DISKS
59 log_must zfs set recordsize=$blksize $TESTPOOL/$TESTFS
60 log_must zfs set compression=lzjb $TESTPOOL/$TESTFS
61
62 file_write -d R -o create -w -f $init_data -b $blksize -c $write_count
63 sync_pool $TESTPOOL true
64
65 # get object number of file
66 listing=$(ls -i $init_data)
67 set -A array $listing
68 obj=${array[0]}
69 log_note "file $init_data has object number $obj"
70
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:]])}
79
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:]])}
84
85 output=$(export ZDB_NO_ZLE=\"true\"; zdb -R $TESTPOOL $dva:bd\
86     2> /dev/null)
87 output=${output##*>}
88 output=${output##+([[:space:]])}
89 if [ "$output" != "$blk_out0" ]; then
90         log_fail "zdb -R :bd (block 0 display/decompress) failed"
91 fi
92
93 output=$(export ZDB_NO_ZLE=\"true\"; zdb -R $TESTPOOL $dva:db80\
94     2> /dev/null)
95 output=${output##*>}
96 output=${output##+([[:space:]])}
97 if [ "$output" != "$blk_out1" ]; then
98         log_fail "zdb -R :db80 (block 1 display/decompress) failed"
99 fi
100
101 output=$(export ZDB_NO_ZLE=\"true\"; zdb -R $TESTPOOL $dva:b80d\
102     2> /dev/null)
103 output=${output##*>}
104 output=${output##+([[:space:]])}
105 if [ "$output" != "$blk_out1" ]; then
106         log_fail "zdb -R :b80d (block 1 display/decompress) failed"
107 fi
108
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"
116 fi
117
118 # read from specific half of mirror
119 vdev="$vdev.0"
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"
126 fi
127
128 log_pass "zdb -R :b flag (block display) works as expected"