76daa3
From 5fbd54010b1e735b762e315c6817fb46e45611b2 Mon Sep 17 00:00:00 2001
76daa3
From: Kevin Wolf <kwolf@redhat.com>
76daa3
Date: Mon, 12 Jun 2017 13:33:35 +0200
76daa3
Subject: [PATCH 09/13] qemu-iotests: Test exiting qemu with running job
76daa3
76daa3
RH-Author: Kevin Wolf <kwolf@redhat.com>
76daa3
Message-id: <1497274415-4884-4-git-send-email-kwolf@redhat.com>
76daa3
Patchwork-id: 75589
76daa3
O-Subject: [RHEL-7.4 qemu-kvm-rhev PATCH 3/3] qemu-iotests: Test exiting qemu with running job
76daa3
Bugzilla: 1453169
76daa3
RH-Acked-by: Max Reitz <mreitz@redhat.com>
76daa3
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
76daa3
RH-Acked-by: John Snow <jsnow@redhat.com>
76daa3
76daa3
When qemu is exited, all running jobs should be cancelled successfully.
76daa3
This adds a test for this for all types of block jobs that currently
76daa3
exist in qemu.
76daa3
76daa3
Upstream status: Applied to git://repo.or.cz/qemu/kevin.git block
76daa3
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
76daa3
Reviewed-by: Eric Blake <eblake@redhat.com>
76daa3
76daa3
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
76daa3
76daa3
Conflicts:
76daa3
	tests/qemu-iotests/group
76daa3
---
76daa3
 tests/qemu-iotests/185     | 206 +++++++++++++++++++++++++++++++++++++++++++++
76daa3
 tests/qemu-iotests/185.out |  59 +++++++++++++
76daa3
 tests/qemu-iotests/group   |   1 +
76daa3
 3 files changed, 266 insertions(+)
76daa3
 create mode 100755 tests/qemu-iotests/185
76daa3
 create mode 100644 tests/qemu-iotests/185.out
76daa3
76daa3
diff --git a/tests/qemu-iotests/185 b/tests/qemu-iotests/185
76daa3
new file mode 100755
76daa3
index 0000000..0eda371
76daa3
--- /dev/null
76daa3
+++ b/tests/qemu-iotests/185
76daa3
@@ -0,0 +1,206 @@
76daa3
+#!/bin/bash
76daa3
+#
76daa3
+# Test exiting qemu while jobs are still running
76daa3
+#
76daa3
+# Copyright (C) 2017 Red Hat, Inc.
76daa3
+#
76daa3
+# This program is free software; you can redistribute it and/or modify
76daa3
+# it under the terms of the GNU General Public License as published by
76daa3
+# the Free Software Foundation; either version 2 of the License, or
76daa3
+# (at your option) any later version.
76daa3
+#
76daa3
+# This program is distributed in the hope that it will be useful,
76daa3
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
76daa3
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
76daa3
+# GNU General Public License for more details.
76daa3
+#
76daa3
+# You should have received a copy of the GNU General Public License
76daa3
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
76daa3
+#
76daa3
+
76daa3
+# creator
76daa3
+owner=kwolf@redhat.com
76daa3
+
76daa3
+seq=`basename $0`
76daa3
+echo "QA output created by $seq"
76daa3
+
76daa3
+here=`pwd`
76daa3
+status=1 # failure is the default!
76daa3
+
76daa3
+MIG_SOCKET="${TEST_DIR}/migrate"
76daa3
+
76daa3
+_cleanup()
76daa3
+{
76daa3
+    rm -f "${TEST_IMG}.mid"
76daa3
+    rm -f "${TEST_IMG}.copy"
76daa3
+    _cleanup_test_img
76daa3
+    _cleanup_qemu
76daa3
+}
76daa3
+trap "_cleanup; exit \$status" 0 1 2 3 15
76daa3
+
76daa3
+# get standard environment, filters and checks
76daa3
+. ./common.rc
76daa3
+. ./common.filter
76daa3
+. ./common.qemu
76daa3
+
76daa3
+_supported_fmt qcow2
76daa3
+_supported_proto file
76daa3
+_supported_os Linux
76daa3
+
76daa3
+size=64M
76daa3
+TEST_IMG="${TEST_IMG}.base" _make_test_img $size
76daa3
+
76daa3
+echo
76daa3
+echo === Starting VM ===
76daa3
+echo
76daa3
+
76daa3
+qemu_comm_method="qmp"
76daa3
+
76daa3
+_launch_qemu \
76daa3
+    -drive file="${TEST_IMG}.base",cache=$CACHEMODE,driver=$IMGFMT,id=disk
76daa3
+h=$QEMU_HANDLE
76daa3
+_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
76daa3
+
76daa3
+echo
76daa3
+echo === Creating backing chain ===
76daa3
+echo
76daa3
+
76daa3
+_send_qemu_cmd $h \
76daa3
+    "{ 'execute': 'blockdev-snapshot-sync',
76daa3
+       'arguments': { 'device': 'disk',
76daa3
+                      'snapshot-file': '$TEST_IMG.mid',
76daa3
+                      'format': '$IMGFMT',
76daa3
+                      'mode': 'absolute-paths' } }" \
76daa3
+    "return"
76daa3
+
76daa3
+_send_qemu_cmd $h \
76daa3
+    "{ 'execute': 'human-monitor-command',
76daa3
+       'arguments': { 'command-line':
76daa3
+                      'qemu-io disk \"write 0 4M\"' } }" \
76daa3
+    "return"
76daa3
+
76daa3
+_send_qemu_cmd $h \
76daa3
+    "{ 'execute': 'blockdev-snapshot-sync',
76daa3
+       'arguments': { 'device': 'disk',
76daa3
+                      'snapshot-file': '$TEST_IMG',
76daa3
+                      'format': '$IMGFMT',
76daa3
+                      'mode': 'absolute-paths' } }" \
76daa3
+    "return"
76daa3
+
76daa3
+echo
76daa3
+echo === Start commit job and exit qemu ===
76daa3
+echo
76daa3
+
76daa3
+# Note that the reference output intentionally includes the 'offset' field in
76daa3
+# BLOCK_JOB_CANCELLED events for all of the following block jobs. They are
76daa3
+# predictable and any change in the offsets would hint at a bug in the job
76daa3
+# throttling code.
76daa3
+#
76daa3
+# In order to achieve these predictable offsets, all of the following tests
76daa3
+# use speed=65536. Each job will perform exactly one iteration before it has
76daa3
+# to sleep at least for a second, which is plenty of time for the 'quit' QMP
76daa3
+# command to be received (after receiving the command, the rest runs
76daa3
+# synchronously, so jobs can arbitrarily continue or complete).
76daa3
+#
76daa3
+# The buffer size for commit and streaming is 512k (waiting for 8 seconds after
76daa3
+# the first request), for active commit and mirror it's large enough to cover
76daa3
+# the full 4M, and for backup it's the qcow2 cluster size, which we know is
76daa3
+# 64k. As all of these are at least as large as the speed, we are sure that the
76daa3
+# offset doesn't advance after the first iteration before qemu exits.
76daa3
+
76daa3
+_send_qemu_cmd $h \
76daa3
+    "{ 'execute': 'block-commit',
76daa3
+       'arguments': { 'device': 'disk',
76daa3
+                      'base':'$TEST_IMG.base',
76daa3
+                      'top': '$TEST_IMG.mid',
76daa3
+                      'speed': 65536 } }" \
76daa3
+    "return"
76daa3
+
76daa3
+_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
76daa3
+wait=1 _cleanup_qemu
76daa3
+
76daa3
+echo
76daa3
+echo === Start active commit job and exit qemu ===
76daa3
+echo
76daa3
+
76daa3
+_launch_qemu \
76daa3
+    -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
76daa3
+h=$QEMU_HANDLE
76daa3
+_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
76daa3
+
76daa3
+_send_qemu_cmd $h \
76daa3
+    "{ 'execute': 'block-commit',
76daa3
+       'arguments': { 'device': 'disk',
76daa3
+                      'base':'$TEST_IMG.base',
76daa3
+                      'speed': 65536 } }" \
76daa3
+    "return"
76daa3
+
76daa3
+_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
76daa3
+wait=1 _cleanup_qemu
76daa3
+
76daa3
+echo
76daa3
+echo === Start mirror job and exit qemu ===
76daa3
+echo
76daa3
+
76daa3
+_launch_qemu \
76daa3
+    -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
76daa3
+h=$QEMU_HANDLE
76daa3
+_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
76daa3
+
76daa3
+_send_qemu_cmd $h \
76daa3
+    "{ 'execute': 'drive-mirror',
76daa3
+       'arguments': { 'device': 'disk',
76daa3
+                      'target': '$TEST_IMG.copy',
76daa3
+                      'format': '$IMGFMT',
76daa3
+                      'sync': 'full',
76daa3
+                      'speed': 65536 } }" \
76daa3
+    "return"
76daa3
+
76daa3
+_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
76daa3
+wait=1 _cleanup_qemu
76daa3
+
76daa3
+echo
76daa3
+echo === Start backup job and exit qemu ===
76daa3
+echo
76daa3
+
76daa3
+_launch_qemu \
76daa3
+    -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
76daa3
+h=$QEMU_HANDLE
76daa3
+_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
76daa3
+
76daa3
+_send_qemu_cmd $h \
76daa3
+    "{ 'execute': 'drive-backup',
76daa3
+       'arguments': { 'device': 'disk',
76daa3
+                      'target': '$TEST_IMG.copy',
76daa3
+                      'format': '$IMGFMT',
76daa3
+                      'sync': 'full',
76daa3
+                      'speed': 65536 } }" \
76daa3
+    "return"
76daa3
+
76daa3
+_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
76daa3
+wait=1 _cleanup_qemu
76daa3
+
76daa3
+echo
76daa3
+echo === Start streaming job and exit qemu ===
76daa3
+echo
76daa3
+
76daa3
+_launch_qemu \
76daa3
+    -drive file="${TEST_IMG}",cache=$CACHEMODE,driver=$IMGFMT,id=disk
76daa3
+h=$QEMU_HANDLE
76daa3
+_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
76daa3
+
76daa3
+_send_qemu_cmd $h \
76daa3
+    "{ 'execute': 'block-stream',
76daa3
+       'arguments': { 'device': 'disk',
76daa3
+                      'speed': 65536 } }" \
76daa3
+    "return"
76daa3
+
76daa3
+_send_qemu_cmd $h "{ 'execute': 'quit' }" "return"
76daa3
+wait=1 _cleanup_qemu
76daa3
+
76daa3
+_check_test_img
76daa3
+
76daa3
+# success, all done
76daa3
+echo "*** done"
76daa3
+rm -f $seq.full
76daa3
+status=0
76daa3
diff --git a/tests/qemu-iotests/185.out b/tests/qemu-iotests/185.out
76daa3
new file mode 100644
76daa3
index 0000000..45bc7cb
76daa3
--- /dev/null
76daa3
+++ b/tests/qemu-iotests/185.out
76daa3
@@ -0,0 +1,59 @@
76daa3
+QA output created by 185
76daa3
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864
76daa3
+
76daa3
+=== Starting VM ===
76daa3
+
76daa3
+{"return": {}}
76daa3
+
76daa3
+=== Creating backing chain ===
76daa3
+
76daa3
+Formatting 'TEST_DIR/t.qcow2.mid', fmt=qcow2 size=67108864 backing_file=TEST_DIR/t.qcow2.base backing_fmt=qcow2 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
76daa3
+{"return": {}}
76daa3
+wrote 4194304/4194304 bytes at offset 0
76daa3
+4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
76daa3
+{"return": ""}
76daa3
+Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 backing_file=TEST_DIR/t.qcow2.mid backing_fmt=qcow2 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
76daa3
+{"return": {}}
76daa3
+
76daa3
+=== Start commit job and exit qemu ===
76daa3
+
76daa3
+{"return": {}}
76daa3
+{"return": {}}
76daa3
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
76daa3
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 67108864, "offset": 524288, "speed": 65536, "type": "commit"}}
76daa3
+
76daa3
+=== Start active commit job and exit qemu ===
76daa3
+
76daa3
+{"return": {}}
76daa3
+{"return": {}}
76daa3
+{"return": {}}
76daa3
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
76daa3
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "commit"}}
76daa3
+
76daa3
+=== Start mirror job and exit qemu ===
76daa3
+
76daa3
+{"return": {}}
76daa3
+Formatting 'TEST_DIR/t.qcow2.copy', fmt=qcow2 size=67108864 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
76daa3
+{"return": {}}
76daa3
+{"return": {}}
76daa3
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
76daa3
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "mirror"}}
76daa3
+
76daa3
+=== Start backup job and exit qemu ===
76daa3
+
76daa3
+{"return": {}}
76daa3
+Formatting 'TEST_DIR/t.qcow2.copy', fmt=qcow2 size=67108864 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
76daa3
+{"return": {}}
76daa3
+{"return": {}}
76daa3
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
76daa3
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 67108864, "offset": 65536, "speed": 65536, "type": "backup"}}
76daa3
+
76daa3
+=== Start streaming job and exit qemu ===
76daa3
+
76daa3
+{"return": {}}
76daa3
+{"return": {}}
76daa3
+{"return": {}}
76daa3
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
76daa3
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_CANCELLED", "data": {"device": "disk", "len": 67108864, "offset": 524288, "speed": 65536, "type": "stream"}}
76daa3
+No errors were found on the image.
76daa3
+*** done
76daa3
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
76daa3
index 5618034..1c04a18 100644
76daa3
--- a/tests/qemu-iotests/group
76daa3
+++ b/tests/qemu-iotests/group
76daa3
@@ -169,3 +169,4 @@
76daa3
 174 auto
76daa3
 175 auto quick
76daa3
 176 rw auto backing
76daa3
+185 rw auto
76daa3
-- 
76daa3
1.8.3.1
76daa3