| 1 | #!/usr/bin/env bash |
| 2 | # group: rw auto quick |
| 3 | # |
| 4 | # Test reopening a backing image after block-stream and block-commit |
| 5 | # |
| 6 | # Copyright (C) 2018 Igalia, S.L. |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | # This program is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | # |
| 21 | |
| 22 | # creator |
| 23 | owner=berto@igalia.com |
| 24 | |
| 25 | seq=`basename $0` |
| 26 | echo "QA output created by $seq" |
| 27 | |
| 28 | here=`pwd` |
| 29 | status=1 # failure is the default! |
| 30 | |
| 31 | _cleanup() |
| 32 | { |
| 33 | _cleanup_test_img |
| 34 | _rm_test_img "$TEST_IMG.base" |
| 35 | _rm_test_img "$TEST_IMG.int" |
| 36 | } |
| 37 | trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 38 | |
| 39 | # get standard environment, filters and checks |
| 40 | . ./common.rc |
| 41 | . ./common.filter |
| 42 | . ./common.qemu |
| 43 | |
| 44 | # Any format implementing BlockDriver.bdrv_change_backing_file |
| 45 | _supported_fmt qcow2 qed |
| 46 | _supported_proto file fuse |
| 47 | _supported_os Linux |
| 48 | _require_hmp |
| 49 | |
| 50 | IMG_SIZE=1M |
| 51 | |
| 52 | # Create the images |
| 53 | TEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE |
| 54 | TEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" -F $IMGFMT |
| 55 | _make_test_img -b "$TEST_IMG.int" -F $IMGFMT -F $IMGFMT |
| 56 | |
| 57 | # First test: reopen $TEST.IMG changing the detect-zeroes option on |
| 58 | # its backing file ($TEST_IMG.int). |
| 59 | echo |
| 60 | echo "*** Change an option on the backing file" |
| 61 | echo |
| 62 | _launch_qemu -drive if=none,file="${TEST_IMG}" |
| 63 | _send_qemu_cmd $QEMU_HANDLE \ |
| 64 | "{ 'execute': 'qmp_capabilities' }" \ |
| 65 | 'return' |
| 66 | |
| 67 | _send_qemu_cmd $QEMU_HANDLE \ |
| 68 | "{ 'execute': 'human-monitor-command', |
| 69 | 'arguments': { 'command-line': |
| 70 | 'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \ |
| 71 | "return" |
| 72 | |
| 73 | _cleanup_qemu |
| 74 | |
| 75 | # Second test: stream $TEST_IMG.base into $TEST_IMG.int and then |
| 76 | # reopen $TEST.IMG changing the detect-zeroes option on its new |
| 77 | # backing file ($TEST_IMG.base). |
| 78 | echo |
| 79 | echo "*** Stream and then change an option on the backing file" |
| 80 | echo |
| 81 | _launch_qemu -drive if=none,file="${TEST_IMG}" |
| 82 | _send_qemu_cmd $QEMU_HANDLE \ |
| 83 | "{ 'execute': 'qmp_capabilities' }" \ |
| 84 | 'return' |
| 85 | |
| 86 | _send_qemu_cmd $QEMU_HANDLE \ |
| 87 | "{ 'execute': 'block-stream', \ |
| 88 | 'arguments': { 'device': 'none0', |
| 89 | 'base': '${TEST_IMG}.base' } }" \ |
| 90 | 'return' |
| 91 | |
| 92 | # Wait for block-stream to finish |
| 93 | sleep 0.5 |
| 94 | |
| 95 | _send_qemu_cmd $QEMU_HANDLE \ |
| 96 | "{ 'execute': 'human-monitor-command', |
| 97 | 'arguments': { 'command-line': |
| 98 | 'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \ |
| 99 | "return" |
| 100 | |
| 101 | _cleanup_qemu |
| 102 | |
| 103 | # Third test: commit $TEST_IMG.int into $TEST_IMG.base and then reopen |
| 104 | # $TEST.IMG changing the detect-zeroes option on its new backing file |
| 105 | # ($TEST_IMG.base). |
| 106 | echo |
| 107 | echo "*** Commit and then change an option on the backing file" |
| 108 | echo |
| 109 | # Create the images again |
| 110 | TEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE |
| 111 | TEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" -F $IMGFMT |
| 112 | _make_test_img -b "$TEST_IMG.int" -F $IMGFMT |
| 113 | |
| 114 | _launch_qemu -drive if=none,file="${TEST_IMG}" |
| 115 | _send_qemu_cmd $QEMU_HANDLE \ |
| 116 | "{ 'execute': 'qmp_capabilities' }" \ |
| 117 | 'return' |
| 118 | |
| 119 | _send_qemu_cmd $QEMU_HANDLE \ |
| 120 | "{ 'execute': 'block-commit', \ |
| 121 | 'arguments': { 'device': 'none0', |
| 122 | 'top': '${TEST_IMG}.int' } }" \ |
| 123 | 'return' |
| 124 | |
| 125 | # Wait for block-commit to finish |
| 126 | sleep 0.5 |
| 127 | |
| 128 | _send_qemu_cmd $QEMU_HANDLE \ |
| 129 | "{ 'execute': 'human-monitor-command', |
| 130 | 'arguments': { 'command-line': |
| 131 | 'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \ |
| 132 | "return" |
| 133 | |
| 134 | _cleanup_qemu |
| 135 | |
| 136 | # success, all done |
| 137 | echo "*** done" |
| 138 | rm -f $seq.full |
| 139 | status=0 |