1*a1532a22SEric Blake#!/bin/bash 2*a1532a22SEric Blake# 3*a1532a22SEric Blake# Test reading dirty bitmap over NBD 4*a1532a22SEric Blake# 5*a1532a22SEric Blake# Copyright (C) 2018 Red Hat, Inc. 6*a1532a22SEric Blake# 7*a1532a22SEric Blake# This program is free software; you can redistribute it and/or modify 8*a1532a22SEric Blake# it under the terms of the GNU General Public License as published by 9*a1532a22SEric Blake# the Free Software Foundation; either version 2 of the License, or 10*a1532a22SEric Blake# (at your option) any later version. 11*a1532a22SEric Blake# 12*a1532a22SEric Blake# This program is distributed in the hope that it will be useful, 13*a1532a22SEric Blake# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*a1532a22SEric Blake# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*a1532a22SEric Blake# GNU General Public License for more details. 16*a1532a22SEric Blake# 17*a1532a22SEric Blake# You should have received a copy of the GNU General Public License 18*a1532a22SEric Blake# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*a1532a22SEric Blake# 20*a1532a22SEric Blake 21*a1532a22SEric Blakeseq="$(basename $0)" 22*a1532a22SEric Blakeecho "QA output created by $seq" 23*a1532a22SEric Blake 24*a1532a22SEric Blakehere="$PWD" 25*a1532a22SEric Blakestatus=1 # failure is the default! 26*a1532a22SEric Blake 27*a1532a22SEric Blake_cleanup() 28*a1532a22SEric Blake{ 29*a1532a22SEric Blake _cleanup_test_img 30*a1532a22SEric Blake _cleanup_qemu 31*a1532a22SEric Blake rm -f "$TEST_DIR/nbd" 32*a1532a22SEric Blake} 33*a1532a22SEric Blaketrap "_cleanup; exit \$status" 0 1 2 3 15 34*a1532a22SEric Blake 35*a1532a22SEric Blake# get standard environment, filters and checks 36*a1532a22SEric Blake. ./common.rc 37*a1532a22SEric Blake. ./common.filter 38*a1532a22SEric Blake. ./common.qemu 39*a1532a22SEric Blake 40*a1532a22SEric Blake_supported_fmt qcow2 41*a1532a22SEric Blake_supported_proto file # uses NBD as well 42*a1532a22SEric Blake_supported_os Linux 43*a1532a22SEric Blake 44*a1532a22SEric Blakefunction do_run_qemu() 45*a1532a22SEric Blake{ 46*a1532a22SEric Blake echo Testing: "$@" 47*a1532a22SEric Blake $QEMU -nographic -qmp stdio -serial none "$@" 48*a1532a22SEric Blake echo 49*a1532a22SEric Blake} 50*a1532a22SEric Blake 51*a1532a22SEric Blakefunction run_qemu() 52*a1532a22SEric Blake{ 53*a1532a22SEric Blake do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ 54*a1532a22SEric Blake | _filter_qemu | _filter_imgfmt \ 55*a1532a22SEric Blake | _filter_actual_image_size 56*a1532a22SEric Blake} 57*a1532a22SEric Blake 58*a1532a22SEric Blakeecho 59*a1532a22SEric Blakeecho "=== Create partially sparse image, then add dirty bitmap ===" 60*a1532a22SEric Blakeecho 61*a1532a22SEric Blake 62*a1532a22SEric Blake_make_test_img 4M 63*a1532a22SEric Blake$QEMU_IO -c 'w -P 0x11 1M 2M' "$TEST_IMG" | _filter_qemu_io 64*a1532a22SEric Blakerun_qemu <<EOF 65*a1532a22SEric Blake{ "execute": "qmp_capabilities" } 66*a1532a22SEric Blake{ "execute": "blockdev-add", 67*a1532a22SEric Blake "arguments": { 68*a1532a22SEric Blake "driver": "$IMGFMT", 69*a1532a22SEric Blake "node-name": "n", 70*a1532a22SEric Blake "file": { 71*a1532a22SEric Blake "driver": "file", 72*a1532a22SEric Blake "filename": "$TEST_IMG" 73*a1532a22SEric Blake } 74*a1532a22SEric Blake } 75*a1532a22SEric Blake} 76*a1532a22SEric Blake{ "execute": "block-dirty-bitmap-add", 77*a1532a22SEric Blake "arguments": { 78*a1532a22SEric Blake "node": "n", 79*a1532a22SEric Blake "name": "b", 80*a1532a22SEric Blake "persistent": true 81*a1532a22SEric Blake } 82*a1532a22SEric Blake} 83*a1532a22SEric Blake{ "execute": "quit" } 84*a1532a22SEric BlakeEOF 85*a1532a22SEric Blake 86*a1532a22SEric Blakeecho 87*a1532a22SEric Blakeecho "=== Write part of the file under active bitmap ===" 88*a1532a22SEric Blakeecho 89*a1532a22SEric Blake 90*a1532a22SEric Blake$QEMU_IO -c 'w -P 0x22 2M 2M' "$TEST_IMG" | _filter_qemu_io 91*a1532a22SEric Blake 92*a1532a22SEric Blakeecho 93*a1532a22SEric Blakeecho "=== End dirty bitmap, and start serving image over NBD ===" 94*a1532a22SEric Blakeecho 95*a1532a22SEric Blake 96*a1532a22SEric Blake_launch_qemu 2> >(_filter_nbd) 97*a1532a22SEric Blake 98*a1532a22SEric Blakesilent= 99*a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"qmp_capabilities"}' "return" 100*a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"blockdev-add", 101*a1532a22SEric Blake "arguments":{"driver":"qcow2", "node-name":"n", 102*a1532a22SEric Blake "file":{"driver":"file", "filename":"'"$TEST_IMG"'"}}}' "return" 103*a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"x-block-dirty-bitmap-disable", 104*a1532a22SEric Blake "arguments":{"node":"n", "name":"b"}}' "return" 105*a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start", 106*a1532a22SEric Blake "arguments":{"addr":{"type":"unix", 107*a1532a22SEric Blake "data":{"path":"'"$TEST_DIR/nbd"'"}}}}' "return" 108*a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add", 109*a1532a22SEric Blake "arguments":{"device":"n"}}' "return" 110*a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"x-nbd-server-add-bitmap", 111*a1532a22SEric Blake "arguments":{"name":"n", "bitmap":"b"}}' "return" 112*a1532a22SEric Blake 113*a1532a22SEric Blakeecho 114*a1532a22SEric Blakeecho "=== Contrast normal status with dirty-bitmap status ===" 115*a1532a22SEric Blakeecho 116*a1532a22SEric Blake 117*a1532a22SEric BlakeQEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT 118*a1532a22SEric BlakeIMG="driver=nbd,export=n,server.type=unix,server.path=$TEST_DIR/nbd" 119*a1532a22SEric Blake$QEMU_IO -r -c 'r -P 0 0 1m' -c 'r -P 0x11 1m 1m' \ 120*a1532a22SEric Blake -c 'r -P 0x22 2m 2m' --image-opts "$IMG" | _filter_qemu_io 121*a1532a22SEric Blake$QEMU_IMG map --output=json --image-opts \ 122*a1532a22SEric Blake "$IMG" | _filter_qemu_img_map 123*a1532a22SEric Blake$QEMU_IMG map --output=json --image-opts \ 124*a1532a22SEric Blake "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map 125*a1532a22SEric Blake 126*a1532a22SEric Blakeecho 127*a1532a22SEric Blakeecho "=== End NBD server ===" 128*a1532a22SEric Blakeecho 129*a1532a22SEric Blake 130*a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove", 131*a1532a22SEric Blake "arguments":{"name":"n"}}' "return" 132*a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return" 133*a1532a22SEric Blake_send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return" 134*a1532a22SEric Blake 135*a1532a22SEric Blake# success, all done 136*a1532a22SEric Blakeecho '*** done' 137*a1532a22SEric Blakerm -f $seq.full 138*a1532a22SEric Blakestatus=0 139