1c78dc182SMax Reitz#!/bin/bash 2c78dc182SMax Reitz# 3c78dc182SMax Reitz# Test case for ejecting BDSs with block jobs still running on them 4c78dc182SMax Reitz# 5c78dc182SMax Reitz# Copyright (C) 2016 Red Hat, Inc. 6c78dc182SMax Reitz# 7c78dc182SMax Reitz# This program is free software; you can redistribute it and/or modify 8c78dc182SMax Reitz# it under the terms of the GNU General Public License as published by 9c78dc182SMax Reitz# the Free Software Foundation; either version 2 of the License, or 10c78dc182SMax Reitz# (at your option) any later version. 11c78dc182SMax Reitz# 12c78dc182SMax Reitz# This program is distributed in the hope that it will be useful, 13c78dc182SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 14c78dc182SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15c78dc182SMax Reitz# GNU General Public License for more details. 16c78dc182SMax Reitz# 17c78dc182SMax Reitz# You should have received a copy of the GNU General Public License 18c78dc182SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 19c78dc182SMax Reitz# 20c78dc182SMax Reitz 21c78dc182SMax Reitz# creator 22c78dc182SMax Reitzowner=mreitz@redhat.com 23c78dc182SMax Reitz 24c78dc182SMax Reitzseq="$(basename $0)" 25c78dc182SMax Reitzecho "QA output created by $seq" 26c78dc182SMax Reitz 27c78dc182SMax Reitzhere="$PWD" 28c78dc182SMax Reitzstatus=1 # failure is the default! 29c78dc182SMax Reitz 30c78dc182SMax Reitz_cleanup() 31c78dc182SMax Reitz{ 32*ecfa1854SJeff Cody _cleanup_qemu 33c78dc182SMax Reitz _cleanup_test_img 34c78dc182SMax Reitz rm -f "$TEST_DIR/{b,m,o}.$IMGFMT" 35c78dc182SMax Reitz} 36c78dc182SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 37c78dc182SMax Reitz 38c78dc182SMax Reitz# get standard environment, filters and checks 39c78dc182SMax Reitz. ./common.rc 40c78dc182SMax Reitz. ./common.filter 41c78dc182SMax Reitz. ./common.qemu 42c78dc182SMax Reitz 43c78dc182SMax Reitz# Needs backing file and backing format support 44c78dc182SMax Reitz_supported_fmt qcow2 qed 45c78dc182SMax Reitz_supported_proto file 46c78dc182SMax Reitz_supported_os Linux 47c78dc182SMax Reitz 48c78dc182SMax Reitz 49c78dc182SMax Reitztest_blockjob() 50c78dc182SMax Reitz{ 51c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 52c78dc182SMax Reitz "{'execute': 'blockdev-add', 53c78dc182SMax Reitz 'arguments': { 5478645881SKevin Wolf 'node-name': 'drv0', 55c78dc182SMax Reitz 'driver': '$IMGFMT', 56c78dc182SMax Reitz 'file': { 57c78dc182SMax Reitz 'driver': 'file', 58c78dc182SMax Reitz 'filename': '$TEST_IMG' 590153d2f5SKevin Wolf }}}" \ 60c78dc182SMax Reitz 'return' 61c78dc182SMax Reitz 62c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 63c78dc182SMax Reitz "$1" \ 64c78dc182SMax Reitz "$2" \ 65c78dc182SMax Reitz | _filter_img_create 66c78dc182SMax Reitz 67c78dc182SMax Reitz # We want this to return an error because the block job is still running 68c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 6979b7a77eSMarkus Armbruster "{'execute': 'blockdev-del', 7078645881SKevin Wolf 'arguments': {'node-name': 'drv0'}}" \ 714ef85a9cSKevin Wolf 'error' | _filter_generated_node_ids 72c78dc182SMax Reitz 73c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 74c78dc182SMax Reitz "{'execute': 'block-job-cancel', 7578645881SKevin Wolf 'arguments': {'device': 'job0'}}" \ 76c78dc182SMax Reitz "$3" 77c78dc182SMax Reitz 78c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 7979b7a77eSMarkus Armbruster "{'execute': 'blockdev-del', 8078645881SKevin Wolf 'arguments': {'node-name': 'drv0'}}" \ 81c78dc182SMax Reitz 'return' 82c78dc182SMax Reitz} 83c78dc182SMax Reitz 84c78dc182SMax Reitz 85c78dc182SMax ReitzTEST_IMG="$TEST_DIR/b.$IMGFMT" _make_test_img 1M 86c78dc182SMax ReitzTEST_IMG="$TEST_DIR/m.$IMGFMT" _make_test_img -b "$TEST_DIR/b.$IMGFMT" 1M 87c78dc182SMax Reitz_make_test_img -b "$TEST_DIR/m.$IMGFMT" 1M 88c78dc182SMax Reitz 89c78dc182SMax Reitz_launch_qemu -nodefaults 90c78dc182SMax Reitz 91c78dc182SMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 92c78dc182SMax Reitz "{'execute': 'qmp_capabilities'}" \ 93c78dc182SMax Reitz 'return' 94c78dc182SMax Reitz 95c78dc182SMax Reitzecho 96c78dc182SMax Reitzecho '=== Testing drive-backup ===' 97c78dc182SMax Reitzecho 98c78dc182SMax Reitz 99c78dc182SMax Reitz# drive-backup will not send BLOCK_JOB_READY by itself, and cancelling the job 100c78dc182SMax Reitz# will consequently result in BLOCK_JOB_CANCELLED being emitted. 101c78dc182SMax Reitz 102c78dc182SMax Reitztest_blockjob \ 103c78dc182SMax Reitz "{'execute': 'drive-backup', 10478645881SKevin Wolf 'arguments': {'job-id': 'job0', 10578645881SKevin Wolf 'device': 'drv0', 106c78dc182SMax Reitz 'target': '$TEST_DIR/o.$IMGFMT', 107c78dc182SMax Reitz 'format': '$IMGFMT', 108c78dc182SMax Reitz 'sync': 'none'}}" \ 109c78dc182SMax Reitz 'return' \ 110c78dc182SMax Reitz 'BLOCK_JOB_CANCELLED' 111c78dc182SMax Reitz 112c78dc182SMax Reitzecho 113c78dc182SMax Reitzecho '=== Testing drive-mirror ===' 114c78dc182SMax Reitzecho 115c78dc182SMax Reitz 116c78dc182SMax Reitz# drive-mirror will send BLOCK_JOB_READY basically immediately, and cancelling 117c78dc182SMax Reitz# the job will consequently result in BLOCK_JOB_COMPLETED being emitted. 118c78dc182SMax Reitz 119c78dc182SMax Reitztest_blockjob \ 120c78dc182SMax Reitz "{'execute': 'drive-mirror', 12178645881SKevin Wolf 'arguments': {'job-id': 'job0', 12278645881SKevin Wolf 'device': 'drv0', 123c78dc182SMax Reitz 'target': '$TEST_DIR/o.$IMGFMT', 124c78dc182SMax Reitz 'format': '$IMGFMT', 125c78dc182SMax Reitz 'sync': 'none'}}" \ 126c78dc182SMax Reitz 'BLOCK_JOB_READY' \ 127c78dc182SMax Reitz 'BLOCK_JOB_COMPLETED' 128c78dc182SMax Reitz 129c78dc182SMax Reitzecho 130c78dc182SMax Reitzecho '=== Testing active block-commit ===' 131c78dc182SMax Reitzecho 132c78dc182SMax Reitz 133c78dc182SMax Reitz# An active block-commit will send BLOCK_JOB_READY basically immediately, and 134c78dc182SMax Reitz# cancelling the job will consequently result in BLOCK_JOB_COMPLETED being 135c78dc182SMax Reitz# emitted. 136c78dc182SMax Reitz 137c78dc182SMax Reitztest_blockjob \ 138c78dc182SMax Reitz "{'execute': 'block-commit', 13978645881SKevin Wolf 'arguments': {'job-id': 'job0', 'device': 'drv0'}}" \ 140c78dc182SMax Reitz 'BLOCK_JOB_READY' \ 141c78dc182SMax Reitz 'BLOCK_JOB_COMPLETED' 142c78dc182SMax Reitz 143c78dc182SMax Reitzecho 144c78dc182SMax Reitzecho '=== Testing non-active block-commit ===' 145c78dc182SMax Reitzecho 146c78dc182SMax Reitz 147c78dc182SMax Reitz# Give block-commit something to work on, otherwise it would be done 148c78dc182SMax Reitz# immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just 149c78dc182SMax Reitz# fine without the block job still running. 150c78dc182SMax Reitz 151c78dc182SMax Reitz$QEMU_IO -c 'write 0 1M' "$TEST_DIR/m.$IMGFMT" | _filter_qemu_io 152c78dc182SMax Reitz 153c78dc182SMax Reitztest_blockjob \ 154c78dc182SMax Reitz "{'execute': 'block-commit', 15578645881SKevin Wolf 'arguments': {'job-id': 'job0', 15678645881SKevin Wolf 'device': 'drv0', 157c78dc182SMax Reitz 'top': '$TEST_DIR/m.$IMGFMT', 158c78dc182SMax Reitz 'speed': 1}}" \ 159c78dc182SMax Reitz 'return' \ 160c78dc182SMax Reitz 'BLOCK_JOB_CANCELLED' 161c78dc182SMax Reitz 162c78dc182SMax Reitzecho 163c78dc182SMax Reitzecho '=== Testing block-stream ===' 164c78dc182SMax Reitzecho 165c78dc182SMax Reitz 166c78dc182SMax Reitz# Give block-stream something to work on, otherwise it would be done 167c78dc182SMax Reitz# immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just 168c78dc182SMax Reitz# fine without the block job still running. 169c78dc182SMax Reitz 170c78dc182SMax Reitz$QEMU_IO -c 'write 0 1M' "$TEST_DIR/b.$IMGFMT" | _filter_qemu_io 171c78dc182SMax Reitz 172c78dc182SMax Reitz# With some data to stream (and @speed set to 1), block-stream will not complete 173c78dc182SMax Reitz# until we send the block-job-cancel command. Therefore, no event other than 174c78dc182SMax Reitz# BLOCK_JOB_CANCELLED will be emitted. 175c78dc182SMax Reitz 176c78dc182SMax Reitztest_blockjob \ 177c78dc182SMax Reitz "{'execute': 'block-stream', 17878645881SKevin Wolf 'arguments': {'job-id': 'job0', 17978645881SKevin Wolf 'device': 'drv0', 180c78dc182SMax Reitz 'speed': 1}}" \ 181c78dc182SMax Reitz 'return' \ 182c78dc182SMax Reitz 'BLOCK_JOB_CANCELLED' 183c78dc182SMax Reitz 184c78dc182SMax Reitz_cleanup_qemu 185c78dc182SMax Reitz 186c78dc182SMax Reitz# success, all done 187c78dc182SMax Reitzecho "*** done" 188c78dc182SMax Reitzrm -f $seq.full 189c78dc182SMax Reitzstatus=0 190