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{ 32c78dc182SMax Reitz _cleanup_test_img 33c78dc182SMax Reitz rm -f "$TEST_DIR/{b,m,o}.$IMGFMT" 34c78dc182SMax Reitz} 35c78dc182SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 36c78dc182SMax Reitz 37c78dc182SMax Reitz# get standard environment, filters and checks 38c78dc182SMax Reitz. ./common.rc 39c78dc182SMax Reitz. ./common.filter 40c78dc182SMax Reitz. ./common.qemu 41c78dc182SMax Reitz 42c78dc182SMax Reitz# Needs backing file and backing format support 43c78dc182SMax Reitz_supported_fmt qcow2 qed 44c78dc182SMax Reitz_supported_proto file 45c78dc182SMax Reitz_supported_os Linux 46c78dc182SMax Reitz 47c78dc182SMax Reitz 48c78dc182SMax Reitztest_blockjob() 49c78dc182SMax Reitz{ 50c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 51c78dc182SMax Reitz "{'execute': 'blockdev-add', 52c78dc182SMax Reitz 'arguments': { 5378645881SKevin Wolf 'node-name': 'drv0', 54c78dc182SMax Reitz 'driver': '$IMGFMT', 55c78dc182SMax Reitz 'file': { 56c78dc182SMax Reitz 'driver': 'file', 57c78dc182SMax Reitz 'filename': '$TEST_IMG' 580153d2f5SKevin Wolf }}}" \ 59c78dc182SMax Reitz 'return' 60c78dc182SMax Reitz 61c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 62c78dc182SMax Reitz "$1" \ 63c78dc182SMax Reitz "$2" \ 64c78dc182SMax Reitz | _filter_img_create 65c78dc182SMax Reitz 66c78dc182SMax Reitz # We want this to return an error because the block job is still running 67c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 68*79b7a77eSMarkus Armbruster "{'execute': 'blockdev-del', 6978645881SKevin Wolf 'arguments': {'node-name': 'drv0'}}" \ 704ef85a9cSKevin Wolf 'error' | _filter_generated_node_ids 71c78dc182SMax Reitz 72c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 73c78dc182SMax Reitz "{'execute': 'block-job-cancel', 7478645881SKevin Wolf 'arguments': {'device': 'job0'}}" \ 75c78dc182SMax Reitz "$3" 76c78dc182SMax Reitz 77c78dc182SMax Reitz _send_qemu_cmd $QEMU_HANDLE \ 78*79b7a77eSMarkus Armbruster "{'execute': 'blockdev-del', 7978645881SKevin Wolf 'arguments': {'node-name': 'drv0'}}" \ 80c78dc182SMax Reitz 'return' 81c78dc182SMax Reitz} 82c78dc182SMax Reitz 83c78dc182SMax Reitz 84c78dc182SMax ReitzTEST_IMG="$TEST_DIR/b.$IMGFMT" _make_test_img 1M 85c78dc182SMax ReitzTEST_IMG="$TEST_DIR/m.$IMGFMT" _make_test_img -b "$TEST_DIR/b.$IMGFMT" 1M 86c78dc182SMax Reitz_make_test_img -b "$TEST_DIR/m.$IMGFMT" 1M 87c78dc182SMax Reitz 88c78dc182SMax Reitz_launch_qemu -nodefaults 89c78dc182SMax Reitz 90c78dc182SMax Reitz_send_qemu_cmd $QEMU_HANDLE \ 91c78dc182SMax Reitz "{'execute': 'qmp_capabilities'}" \ 92c78dc182SMax Reitz 'return' 93c78dc182SMax Reitz 94c78dc182SMax Reitzecho 95c78dc182SMax Reitzecho '=== Testing drive-backup ===' 96c78dc182SMax Reitzecho 97c78dc182SMax Reitz 98c78dc182SMax Reitz# drive-backup will not send BLOCK_JOB_READY by itself, and cancelling the job 99c78dc182SMax Reitz# will consequently result in BLOCK_JOB_CANCELLED being emitted. 100c78dc182SMax Reitz 101c78dc182SMax Reitztest_blockjob \ 102c78dc182SMax Reitz "{'execute': 'drive-backup', 10378645881SKevin Wolf 'arguments': {'job-id': 'job0', 10478645881SKevin Wolf 'device': 'drv0', 105c78dc182SMax Reitz 'target': '$TEST_DIR/o.$IMGFMT', 106c78dc182SMax Reitz 'format': '$IMGFMT', 107c78dc182SMax Reitz 'sync': 'none'}}" \ 108c78dc182SMax Reitz 'return' \ 109c78dc182SMax Reitz 'BLOCK_JOB_CANCELLED' 110c78dc182SMax Reitz 111c78dc182SMax Reitzecho 112c78dc182SMax Reitzecho '=== Testing drive-mirror ===' 113c78dc182SMax Reitzecho 114c78dc182SMax Reitz 115c78dc182SMax Reitz# drive-mirror will send BLOCK_JOB_READY basically immediately, and cancelling 116c78dc182SMax Reitz# the job will consequently result in BLOCK_JOB_COMPLETED being emitted. 117c78dc182SMax Reitz 118c78dc182SMax Reitztest_blockjob \ 119c78dc182SMax Reitz "{'execute': 'drive-mirror', 12078645881SKevin Wolf 'arguments': {'job-id': 'job0', 12178645881SKevin Wolf 'device': 'drv0', 122c78dc182SMax Reitz 'target': '$TEST_DIR/o.$IMGFMT', 123c78dc182SMax Reitz 'format': '$IMGFMT', 124c78dc182SMax Reitz 'sync': 'none'}}" \ 125c78dc182SMax Reitz 'BLOCK_JOB_READY' \ 126c78dc182SMax Reitz 'BLOCK_JOB_COMPLETED' 127c78dc182SMax Reitz 128c78dc182SMax Reitzecho 129c78dc182SMax Reitzecho '=== Testing active block-commit ===' 130c78dc182SMax Reitzecho 131c78dc182SMax Reitz 132c78dc182SMax Reitz# An active block-commit will send BLOCK_JOB_READY basically immediately, and 133c78dc182SMax Reitz# cancelling the job will consequently result in BLOCK_JOB_COMPLETED being 134c78dc182SMax Reitz# emitted. 135c78dc182SMax Reitz 136c78dc182SMax Reitztest_blockjob \ 137c78dc182SMax Reitz "{'execute': 'block-commit', 13878645881SKevin Wolf 'arguments': {'job-id': 'job0', 'device': 'drv0'}}" \ 139c78dc182SMax Reitz 'BLOCK_JOB_READY' \ 140c78dc182SMax Reitz 'BLOCK_JOB_COMPLETED' 141c78dc182SMax Reitz 142c78dc182SMax Reitzecho 143c78dc182SMax Reitzecho '=== Testing non-active block-commit ===' 144c78dc182SMax Reitzecho 145c78dc182SMax Reitz 146c78dc182SMax Reitz# Give block-commit something to work on, otherwise it would be done 147c78dc182SMax Reitz# immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just 148c78dc182SMax Reitz# fine without the block job still running. 149c78dc182SMax Reitz 150c78dc182SMax Reitz$QEMU_IO -c 'write 0 1M' "$TEST_DIR/m.$IMGFMT" | _filter_qemu_io 151c78dc182SMax Reitz 152c78dc182SMax Reitztest_blockjob \ 153c78dc182SMax Reitz "{'execute': 'block-commit', 15478645881SKevin Wolf 'arguments': {'job-id': 'job0', 15578645881SKevin Wolf 'device': 'drv0', 156c78dc182SMax Reitz 'top': '$TEST_DIR/m.$IMGFMT', 157c78dc182SMax Reitz 'speed': 1}}" \ 158c78dc182SMax Reitz 'return' \ 159c78dc182SMax Reitz 'BLOCK_JOB_CANCELLED' 160c78dc182SMax Reitz 161c78dc182SMax Reitzecho 162c78dc182SMax Reitzecho '=== Testing block-stream ===' 163c78dc182SMax Reitzecho 164c78dc182SMax Reitz 165c78dc182SMax Reitz# Give block-stream something to work on, otherwise it would be done 166c78dc182SMax Reitz# immediately, send a BLOCK_JOB_COMPLETED and ejecting the BDS would work just 167c78dc182SMax Reitz# fine without the block job still running. 168c78dc182SMax Reitz 169c78dc182SMax Reitz$QEMU_IO -c 'write 0 1M' "$TEST_DIR/b.$IMGFMT" | _filter_qemu_io 170c78dc182SMax Reitz 171c78dc182SMax Reitz# With some data to stream (and @speed set to 1), block-stream will not complete 172c78dc182SMax Reitz# until we send the block-job-cancel command. Therefore, no event other than 173c78dc182SMax Reitz# BLOCK_JOB_CANCELLED will be emitted. 174c78dc182SMax Reitz 175c78dc182SMax Reitztest_blockjob \ 176c78dc182SMax Reitz "{'execute': 'block-stream', 17778645881SKevin Wolf 'arguments': {'job-id': 'job0', 17878645881SKevin Wolf 'device': 'drv0', 179c78dc182SMax Reitz 'speed': 1}}" \ 180c78dc182SMax Reitz 'return' \ 181c78dc182SMax Reitz 'BLOCK_JOB_CANCELLED' 182c78dc182SMax Reitz 183c78dc182SMax Reitz_cleanup_qemu 184c78dc182SMax Reitz 185c78dc182SMax Reitz# success, all done 186c78dc182SMax Reitzecho "*** done" 187c78dc182SMax Reitzrm -f $seq.full 188c78dc182SMax Reitzstatus=0 189