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 40function cleanup 41{ 42 datasetexists $TESTPOOL && destroy_pool $TESTPOOL 43} 44 45log_assert "Verify zdb -R :b flag (block display) works as expected" 46log_onexit cleanup 47init_data=$TESTDIR/file1 48write_count=256 49blksize=4096 50 51# only read 256 128 byte block pointers in L1 (:i flag) 52# 256 x 128 = 32k / 0x8000 53l1_read_size="8000" 54 55verify_runnable "global" 56verify_disk_count "$DISKS" 2 57 58default_mirror_setup_noexit $DISKS 59log_must zfs set recordsize=$blksize $TESTPOOL/$TESTFS 60log_must zfs set compression=lzjb $TESTPOOL/$TESTFS 61 62file_write -d R -o create -w -f $init_data -b $blksize -c $write_count 63sync_pool $TESTPOOL true 64 65# get object number of file 66listing=$(ls -i $init_data) 67set -A array $listing 68obj=${array[0]} 69log_note "file $init_data has object number $obj" 70 71output=$(zdb -ddddddbbbbbb $TESTPOOL/$TESTFS $obj 2> /dev/null \ 72 |grep -m 1 "L1 DVA" ) 73dva=$(sed -Ene 's/^.+DVA\[0\]=<([^>]+)>.*/\1/p' <<< "$output") 74log_note "first L1 block $init_data has a DVA of $dva" 75output=$(zdb -ddddddbbbbbb $TESTPOOL/$TESTFS $obj 2> /dev/null \ 76 |grep -m 1 "L0 DVA" ) 77blk_out0=${output##*>} 78blk_out0=${blk_out0##+([[:space:]])} 79 80output=$(zdb -ddddddbbbbbb $TESTPOOL/$TESTFS $obj 2> /dev/null \ 81 |grep -m 1 "1000 L0 DVA" ) 82blk_out1=${output##*>} 83blk_out1=${blk_out1##+([[:space:]])} 84 85output=$(export ZDB_NO_ZLE=\"true\"; zdb -R $TESTPOOL $dva:bd\ 86 2> /dev/null) 87output=${output##*>} 88output=${output##+([[:space:]])} 89if [ "$output" != "$blk_out0" ]; then 90 log_fail "zdb -R :bd (block 0 display/decompress) failed" 91fi 92 93output=$(export ZDB_NO_ZLE=\"true\"; zdb -R $TESTPOOL $dva:db80\ 94 2> /dev/null) 95output=${output##*>} 96output=${output##+([[:space:]])} 97if [ "$output" != "$blk_out1" ]; then 98 log_fail "zdb -R :db80 (block 1 display/decompress) failed" 99fi 100 101output=$(export ZDB_NO_ZLE=\"true\"; zdb -R $TESTPOOL $dva:b80d\ 102 2> /dev/null) 103output=${output##*>} 104output=${output##+([[:space:]])} 105if [ "$output" != "$blk_out1" ]; then 106 log_fail "zdb -R :b80d (block 1 display/decompress) failed" 107fi 108 109vdev=$(echo "$dva" | cut -d: -f1) 110offset=$(echo "$dva" | cut -d: -f2) 111output=$(export ZDB_NO_ZLE=\"true\";\ 112 zdb -R $TESTPOOL $vdev:$offset:$l1_read_size:id 2> /dev/null) 113block_cnt=$(echo "$output" | grep -c 'L0') 114if [ $block_cnt -ne $write_count ]; then 115 log_fail "zdb -R :id (indirect block display) failed" 116fi 117 118# read from specific half of mirror 119vdev="$vdev.0" 120log_note "Reading from DVA $vdev:$offset:$l1_read_size" 121output=$(export ZDB_NO_ZLE=\"true\";\ 122 zdb -R $TESTPOOL $vdev:$offset:$l1_read_size:id 2> /dev/null) 123block_cnt=$(echo "$output" | grep -c 'L0') 124if [ $block_cnt -ne $write_count ]; then 125 log_fail "zdb -R 0.0:offset:length:id (indirect block display) failed" 126fi 127 128log_pass "zdb -R :b flag (block display) works as expected" 129