111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick 3c78dc182SMax Reitz# 4c78dc182SMax Reitz# Test case for ejecting BDSs with block jobs still running on them 5c78dc182SMax Reitz# 6c78dc182SMax Reitz# Copyright (C) 2016 Red Hat, Inc. 7c78dc182SMax Reitz# 8c78dc182SMax Reitz# This program is free software; you can redistribute it and/or modify 9c78dc182SMax Reitz# it under the terms of the GNU General Public License as published by 10c78dc182SMax Reitz# the Free Software Foundation; either version 2 of the License, or 11c78dc182SMax Reitz# (at your option) any later version. 12c78dc182SMax Reitz# 13c78dc182SMax Reitz# This program is distributed in the hope that it will be useful, 14c78dc182SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 15c78dc182SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c78dc182SMax Reitz# GNU General Public License for more details. 17c78dc182SMax Reitz# 18c78dc182SMax Reitz# You should have received a copy of the GNU General Public License 19c78dc182SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 20c78dc182SMax Reitz# 21c78dc182SMax Reitz 22c78dc182SMax Reitz# creator 23c78dc182SMax Reitzowner=mreitz@redhat.com 24c78dc182SMax Reitz 25c78dc182SMax Reitzseq="$(basename $0)" 26c78dc182SMax Reitzecho "QA output created by $seq" 27c78dc182SMax Reitz 28c78dc182SMax Reitzstatus=1 # failure is the default! 29c78dc182SMax Reitz 30c78dc182SMax Reitz_cleanup() 31c78dc182SMax Reitz{ 32ecfa1854SJeff Cody _cleanup_qemu 33c78dc182SMax Reitz _cleanup_test_img 34f91ecbd7SMax Reitz for img in "$TEST_DIR"/{b,m,o}.$IMGFMT; do 35f91ecbd7SMax Reitz _rm_test_img "$img" 36f91ecbd7SMax Reitz done 37c78dc182SMax Reitz} 38c78dc182SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 39c78dc182SMax Reitz 40c78dc182SMax Reitz# get standard environment, filters and checks 41c78dc182SMax Reitz. ./common.rc 42c78dc182SMax Reitz. ./common.filter 43c78dc182SMax Reitz. ./common.qemu 44c78dc182SMax Reitz 45c78dc182SMax Reitz# Needs backing file and backing format support 46c78dc182SMax Reitz_supported_fmt qcow2 qed 47c78dc182SMax Reitz_supported_proto file 48c78dc182SMax Reitz_supported_os Linux 49c78dc182SMax Reitz 50c78dc182SMax Reitz 51c78dc182SMax Reitztest_blockjob() 52c78dc182SMax Reitz{ 53c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 54c78dc182SMax Reitz "{'execute': 'blockdev-add', 55c78dc182SMax Reitz 'arguments': { 5678645881SKevin Wolf 'node-name': 'drv0', 57c78dc182SMax Reitz 'driver': '$IMGFMT', 58c78dc182SMax Reitz 'file': { 59c78dc182SMax Reitz 'driver': 'file', 60c78dc182SMax Reitz 'filename': '$TEST_IMG' 610153d2f5SKevin Wolf }}}" \ 62c78dc182SMax Reitz 'return' 63c78dc182SMax Reitz 649c46f4a0SMax Reitz # If "$2" is an event, we may or may not see it before the 659c46f4a0SMax Reitz # {"return": {}}. Therefore, filter the {"return": {}} out both 669c46f4a0SMax Reitz # here and in the next command. (Naturally, if we do not see it 679c46f4a0SMax Reitz # here, we will see it before the next command can be executed, 689c46f4a0SMax Reitz # so it will appear in the next _send_qemu_cmd's output.) 69c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 70c78dc182SMax Reitz "$1" \ 71c78dc182SMax Reitz "$2" \ 724b196cd1SMax Reitz | _filter_img_create | _filter_qmp_empty_return 73c78dc182SMax Reitz 74c78dc182SMax Reitz # We want this to return an error because the block job is still running 75c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 7679b7a77eSMarkus Armbruster "{'execute': 'blockdev-del', 7778645881SKevin Wolf 'arguments': {'node-name': 'drv0'}}" \ 789c46f4a0SMax Reitz 'error' | _filter_generated_node_ids | _filter_qmp_empty_return 79c78dc182SMax Reitz 80c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 81c78dc182SMax Reitz "{'execute': 'block-job-cancel', 8278645881SKevin Wolf 'arguments': {'device': 'job0'}}" \ 83c78dc182SMax Reitz "$3" 84c78dc182SMax Reitz 85c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 8679b7a77eSMarkus Armbruster "{'execute': 'blockdev-del', 8778645881SKevin Wolf 'arguments': {'node-name': 'drv0'}}" \ 88c78dc182SMax Reitz 'return' 89c78dc182SMax Reitz} 90c78dc182SMax Reitz 91c78dc182SMax Reitz 92c78dc182SMax ReitzTEST_IMG="$TEST_DIR/b.$IMGFMT" _make_test_img 1M 93b66ff2c2SEric BlakeTEST_IMG="$TEST_DIR/m.$IMGFMT" _make_test_img -b "$TEST_DIR/b.$IMGFMT" -F $IMGFMT 1M 94b66ff2c2SEric Blake_make_test_img -b "$TEST_DIR/m.$IMGFMT" 1M -F $IMGFMT 95c78dc182SMax Reitz 96c78dc182SMax Reitz_launch_qemu -nodefaults 97c78dc182SMax Reitz 98c78dc182SMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 99c78dc182SMax Reitz "{'execute': 'qmp_capabilities'}" \ 100c78dc182SMax Reitz 'return' 101c78dc182SMax Reitz 102c78dc182SMax Reitzecho 103c78dc182SMax Reitzecho '=== Testing drive-backup ===' 104c78dc182SMax Reitzecho 105c78dc182SMax Reitz 106c78dc182SMax Reitz# drive-backup will not send BLOCK_JOB_READY by itself, and cancelling the job 107c78dc182SMax Reitz# will consequently result in BLOCK_JOB_CANCELLED being emitted. 108c78dc182SMax Reitz 109c78dc182SMax Reitztest_blockjob \ 110c78dc182SMax Reitz "{'execute': 'drive-backup', 11178645881SKevin Wolf 'arguments': {'job-id': 'job0', 11278645881SKevin Wolf 'device': 'drv0', 113c78dc182SMax Reitz 'target': '$TEST_DIR/o.$IMGFMT', 114c78dc182SMax Reitz 'format': '$IMGFMT', 115c78dc182SMax Reitz 'sync': 'none'}}" \ 116c78dc182SMax Reitz 'return' \ 1171dac83f1SKevin Wolf '"status": "null"' 118c78dc182SMax Reitz 119c78dc182SMax Reitzecho 120c78dc182SMax Reitzecho '=== Testing drive-mirror ===' 121c78dc182SMax Reitzecho 122c78dc182SMax Reitz 123c78dc182SMax Reitz# drive-mirror will send BLOCK_JOB_READY basically immediately, and cancelling 124c78dc182SMax Reitz# the job will consequently result in BLOCK_JOB_COMPLETED being emitted. 125c78dc182SMax Reitz 126c78dc182SMax Reitztest_blockjob \ 127c78dc182SMax Reitz "{'execute': 'drive-mirror', 12878645881SKevin Wolf 'arguments': {'job-id': 'job0', 12978645881SKevin Wolf 'device': 'drv0', 130c78dc182SMax Reitz 'target': '$TEST_DIR/o.$IMGFMT', 131c78dc182SMax Reitz 'format': '$IMGFMT', 132c78dc182SMax Reitz 'sync': 'none'}}" \ 133c78dc182SMax Reitz 'BLOCK_JOB_READY' \ 1341dac83f1SKevin Wolf '"status": "null"' 135c78dc182SMax Reitz 136c78dc182SMax Reitzecho 137c78dc182SMax Reitzecho '=== Testing active block-commit ===' 138c78dc182SMax Reitzecho 139c78dc182SMax Reitz 140c78dc182SMax Reitz# An active block-commit will send BLOCK_JOB_READY basically immediately, and 141c78dc182SMax Reitz# cancelling the job will consequently result in BLOCK_JOB_COMPLETED being 142c78dc182SMax Reitz# emitted. 143c78dc182SMax Reitz 144c78dc182SMax Reitztest_blockjob \ 145c78dc182SMax Reitz "{'execute': 'block-commit', 14678645881SKevin Wolf 'arguments': {'job-id': 'job0', 'device': 'drv0'}}" \ 147c78dc182SMax Reitz 'BLOCK_JOB_READY' \ 1481dac83f1SKevin Wolf '"status": "null"' 149c78dc182SMax Reitz 150c78dc182SMax Reitzecho 151c78dc182SMax Reitzecho '=== Testing non-active block-commit ===' 152c78dc182SMax Reitzecho 153c78dc182SMax Reitz 154c78dc182SMax Reitz# Give block-commit something to work on, otherwise it would be done 155c78dc182SMax Reitz# immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just 156c78dc182SMax Reitz# fine without the block job still running. 157c78dc182SMax Reitz 158c78dc182SMax Reitz$QEMU_IO -c 'write 0 1M' "$TEST_DIR/m.$IMGFMT" | _filter_qemu_io 159c78dc182SMax Reitz 160c78dc182SMax Reitztest_blockjob \ 161c78dc182SMax Reitz "{'execute': 'block-commit', 16278645881SKevin Wolf 'arguments': {'job-id': 'job0', 16378645881SKevin Wolf 'device': 'drv0', 164c78dc182SMax Reitz 'top': '$TEST_DIR/m.$IMGFMT', 165c78dc182SMax Reitz 'speed': 1}}" \ 166c78dc182SMax Reitz 'return' \ 1671dac83f1SKevin Wolf '"status": "null"' 168c78dc182SMax Reitz 169c78dc182SMax Reitzecho 170c78dc182SMax Reitzecho '=== Testing block-stream ===' 171c78dc182SMax Reitzecho 172c78dc182SMax Reitz 173c78dc182SMax Reitz# Give block-stream something to work on, otherwise it would be done 174c78dc182SMax Reitz# immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just 175c78dc182SMax Reitz# fine without the block job still running. 176c78dc182SMax Reitz 177c78dc182SMax Reitz$QEMU_IO -c 'write 0 1M' "$TEST_DIR/b.$IMGFMT" | _filter_qemu_io 178c78dc182SMax Reitz 179c78dc182SMax Reitz# With some data to stream (and @speed set to 1), block-stream will not complete 1801dac83f1SKevin Wolf# until we send the block-job-cancel command. 181c78dc182SMax Reitz 182c78dc182SMax Reitztest_blockjob \ 183c78dc182SMax Reitz "{'execute': 'block-stream', 18478645881SKevin Wolf 'arguments': {'job-id': 'job0', 18578645881SKevin Wolf 'device': 'drv0', 186c78dc182SMax Reitz 'speed': 1}}" \ 187c78dc182SMax Reitz 'return' \ 1881dac83f1SKevin Wolf '"status": "null"' 189c78dc182SMax Reitz 190c78dc182SMax Reitz_cleanup_qemu 191c78dc182SMax Reitz 192c78dc182SMax Reitz# success, all done 193c78dc182SMax Reitzecho "*** done" 194c78dc182SMax Reitzrm -f $seq.full 195c78dc182SMax Reitzstatus=0 196