aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_display_block.ksh
blob: 5cc4575851f7bf848924736a4ed34bec587d1e1e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/ksh

#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright (c) 2019 by Datto, Inc. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib

#
# Description:
# zdb -R pool <DVA>:b will display the block
#
# Strategy:
# 1. Create a pool, set compression to lzjb
# 2. Write some identifiable data to a file
# 3. Run zdb -ddddddbbbbbb against the file
# 4. Record the DVA of the first L1 block;
#    record the first L0 block display; and
#    record the 2nd L0 block display.
# 5. Run zdb -R with :bd displays first L0
# 6. Run zdb -R with :b80d displays 2nd L0
# 7. Run zdb -R with :db80 displays 2nd L0
# 8. Run zdb -R with :id flag displays indirect block
#     (similar to zdb -ddddddbbbbbb output)
# 9. Run zdb -R with :id flag and .0 vdev
#


function cleanup
{
	datasetexists $TESTPOOL && destroy_pool $TESTPOOL
}

log_assert "Verify zdb -R :b flag (block display) works as expected"
log_onexit cleanup
init_data=$TESTDIR/file1
write_count=256
blksize=4096

# only read 256 128 byte block pointers in L1 (:i flag)
# 256 x 128 = 32k / 0x8000
l1_read_size="8000"

verify_runnable "global"
verify_disk_count "$DISKS" 2

default_mirror_setup_noexit $DISKS
log_must zfs set recordsize=$blksize $TESTPOOL/$TESTFS
log_must zfs set compression=lzjb $TESTPOOL/$TESTFS

file_write -d R -o create -w -f $init_data -b $blksize -c $write_count
sync_pool $TESTPOOL true

# get object number of file
listing=$(ls -i $init_data)
set -A array $listing
obj=${array[0]}
log_note "file $init_data has object number $obj"

output=$(zdb -ddddddbbbbbb $TESTPOOL/$TESTFS $obj 2> /dev/null \
    |grep -m 1 "L1  DVA" |head -n1)
dva=$(sed -Ene 's/^.+DVA\[0\]=<([^>]+)>.*/\1/p' <<< "$output")
log_note "first L1 block $init_data has a DVA of $dva"
output=$(zdb -ddddddbbbbbb $TESTPOOL/$TESTFS $obj 2> /dev/null \
    |grep -m 1 "L0 DVA" |head -n1)
blk_out0=${output##*>}
blk_out0=${blk_out0##+([[:space:]])}

output=$(zdb -ddddddbbbbbb $TESTPOOL/$TESTFS $obj 2> /dev/null \
    |grep -m 1 "1000  L0 DVA" |head -n1)
blk_out1=${output##*>}
blk_out1=${blk_out1##+([[:space:]])}

output=$(export ZDB_NO_ZLE=\"true\"; zdb -R $TESTPOOL $dva:bd\
    2> /dev/null)
output=${output##*>}
output=${output##+([[:space:]])}
if [ "$output" != "$blk_out0" ]; then
	log_fail "zdb -R :bd (block 0 display/decompress) failed"
fi

output=$(export ZDB_NO_ZLE=\"true\"; zdb -R $TESTPOOL $dva:db80\
    2> /dev/null)
output=${output##*>}
output=${output##+([[:space:]])}
if [ "$output" != "$blk_out1" ]; then
	log_fail "zdb -R :db80 (block 1 display/decompress) failed"
fi

output=$(export ZDB_NO_ZLE=\"true\"; zdb -R $TESTPOOL $dva:b80d\
    2> /dev/null)
output=${output##*>}
output=${output##+([[:space:]])}
if [ "$output" != "$blk_out1" ]; then
	log_fail "zdb -R :b80d (block 1 display/decompress) failed"
fi

vdev=$(echo "$dva" |awk '{split($0,array,":")} END{print array[1]}')
offset=$(echo "$dva" |awk '{split($0,array,":")} END{print array[2]}')
output=$(export ZDB_NO_ZLE=\"true\";\
    zdb -R $TESTPOOL $vdev:$offset:$l1_read_size:id 2> /dev/null)
block_cnt=$(echo "$output" | grep 'L0' | wc -l)
if [ $block_cnt -ne $write_count ]; then
	log_fail "zdb -R :id (indirect block display) failed"
fi

# read from specific half of mirror
vdev="$vdev.0"
log_note "Reading from DVA $vdev:$offset:$l1_read_size"
output=$(export ZDB_NO_ZLE=\"true\";\
    zdb -R $TESTPOOL $vdev:$offset:$l1_read_size:id 2> /dev/null)
block_cnt=$(echo "$output" | grep 'L0' | wc -l)
if [ $block_cnt -ne $write_count ]; then
        log_fail "zdb -R 0.0:offset:length:id (indirect block display) failed"
fi

log_pass "zdb -R :b flag (block display) works as expected"