|
| 1 | +#!/usr/bin/env bash |
| 2 | +# group: rw quick |
| 3 | +# |
| 4 | +# Test of NBD+TLS+iothread |
| 5 | +# |
| 6 | +# Copyright (C) 2024 Red Hat, Inc. |
| 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 | + |
| 24 | + |
| 25 | +seq=`basename $0` |
| 26 | +echo "QA output created by $seq" |
| 27 | + |
| 28 | +status=1 # failure is the default! |
| 29 | + |
| 30 | +_cleanup() |
| 31 | +{ |
| 32 | + _cleanup_qemu |
| 33 | + _cleanup_test_img |
| 34 | + rm -f "$dst_image" |
| 35 | + tls_x509_cleanup |
| 36 | +} |
| 37 | +trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 38 | + |
| 39 | +# get standard environment, filters and checks |
| 40 | +cd .. |
| 41 | +. ./common.rc |
| 42 | +. ./common.filter |
| 43 | +. ./common.qemu |
| 44 | +. ./common.tls |
| 45 | +. ./common.nbd |
| 46 | + |
| 47 | +_supported_fmt qcow2 # Hardcoded to qcow2 command line and QMP below |
| 48 | +_supported_proto file |
| 49 | + |
| 50 | +# pick_unused_port |
| 51 | +# |
| 52 | +# Picks and returns an "unused" port, setting the global variable |
| 53 | +# $port. |
| 54 | +# |
| 55 | +# This is inherently racy, but we need it because qemu does not currently |
| 56 | +# permit NBD+TLS over a Unix domain socket |
| 57 | +pick_unused_port () |
| 58 | +{ |
| 59 | + if ! (ss --version) >/dev/null 2>&1; then |
| 60 | + _notrun "ss utility required, skipped this test" |
| 61 | + fi |
| 62 | + |
| 63 | + # Start at a random port to make it less likely that two parallel |
| 64 | + # tests will conflict. |
| 65 | + port=$(( 50000 + (RANDOM%15000) )) |
| 66 | + while ss -ltn | grep -sqE ":$port\b"; do |
| 67 | + ((port++)) |
| 68 | + if [ $port -eq 65000 ]; then port=50000; fi |
| 69 | + done |
| 70 | + echo picked unused port |
| 71 | +} |
| 72 | + |
| 73 | +tls_x509_init |
| 74 | + |
| 75 | +size=1G |
| 76 | +DST_IMG="$TEST_DIR/dst.qcow2" |
| 77 | + |
| 78 | +echo |
| 79 | +echo "== preparing TLS creds and spare port ==" |
| 80 | + |
| 81 | +pick_unused_port |
| 82 | +tls_x509_create_root_ca "ca1" |
| 83 | +tls_x509_create_server "ca1" "server1" |
| 84 | +tls_x509_create_client "ca1" "client1" |
| 85 | +tls_obj_base=tls-creds-x509,id=tls0,verify-peer=true,dir="${tls_dir}" |
| 86 | + |
| 87 | +echo |
| 88 | +echo "== preparing image ==" |
| 89 | + |
| 90 | +_make_test_img $size |
| 91 | +$QEMU_IMG create -f qcow2 "$DST_IMG" $size | _filter_img_create |
| 92 | + |
| 93 | +echo |
| 94 | +echo === Starting Src QEMU === |
| 95 | +echo |
| 96 | + |
| 97 | +_launch_qemu -machine q35 \ |
| 98 | + -object iothread,id=iothread0 \ |
| 99 | + -object "${tls_obj_base}"/client1,endpoint=client \ |
| 100 | + -device '{"driver":"pcie-root-port", "id":"root0", "multifunction":true, |
| 101 | + "bus":"pcie.0"}' \ |
| 102 | + -device '{"driver":"virtio-scsi-pci", "id":"virtio_scsi_pci0", |
| 103 | + "bus":"root0", "iothread":"iothread0"}' \ |
| 104 | + -device '{"driver":"scsi-hd", "id":"image1", "drive":"drive_image1", |
| 105 | + "bus":"virtio_scsi_pci0.0"}' \ |
| 106 | + -blockdev '{"driver":"file", "cache":{"direct":true, "no-flush":false}, |
| 107 | + "filename":"'"$TEST_IMG"'", "node-name":"drive_sys1"}' \ |
| 108 | + -blockdev '{"driver":"qcow2", "node-name":"drive_image1", |
| 109 | + "file":"drive_sys1"}' |
| 110 | +h1=$QEMU_HANDLE |
| 111 | +_send_qemu_cmd $h1 '{"execute": "qmp_capabilities"}' 'return' |
| 112 | + |
| 113 | +echo |
| 114 | +echo === Starting Dst VM2 === |
| 115 | +echo |
| 116 | + |
| 117 | +_launch_qemu -machine q35 \ |
| 118 | + -object iothread,id=iothread0 \ |
| 119 | + -object "${tls_obj_base}"/server1,endpoint=server \ |
| 120 | + -device '{"driver":"pcie-root-port", "id":"root0", "multifunction":true, |
| 121 | + "bus":"pcie.0"}' \ |
| 122 | + -device '{"driver":"virtio-scsi-pci", "id":"virtio_scsi_pci0", |
| 123 | + "bus":"root0", "iothread":"iothread0"}' \ |
| 124 | + -device '{"driver":"scsi-hd", "id":"image1", "drive":"drive_image1", |
| 125 | + "bus":"virtio_scsi_pci0.0"}' \ |
| 126 | + -blockdev '{"driver":"file", "cache":{"direct":true, "no-flush":false}, |
| 127 | + "filename":"'"$DST_IMG"'", "node-name":"drive_sys1"}' \ |
| 128 | + -blockdev '{"driver":"qcow2", "node-name":"drive_image1", |
| 129 | + "file":"drive_sys1"}' \ |
| 130 | + -incoming defer |
| 131 | +h2=$QEMU_HANDLE |
| 132 | +_send_qemu_cmd $h2 '{"execute": "qmp_capabilities"}' 'return' |
| 133 | + |
| 134 | +echo |
| 135 | +echo === Dst VM: Enable NBD server for incoming storage migration === |
| 136 | +echo |
| 137 | + |
| 138 | +_send_qemu_cmd $h2 '{"execute": "nbd-server-start", "arguments": |
| 139 | + {"addr": {"type": "inet", "data": {"host": "127.0.0.1", "port": "'$port'"}}, |
| 140 | + "tls-creds": "tls0"}}' '{"return": {}}' | sed "s/\"$port\"/PORT/g" |
| 141 | +_send_qemu_cmd $h2 '{"execute": "block-export-add", "arguments": |
| 142 | + {"node-name": "drive_image1", "type": "nbd", "writable": true, |
| 143 | + "id": "drive_image1"}}' '{"return": {}}' |
| 144 | + |
| 145 | +echo |
| 146 | +echo === Src VM: Mirror to dst NBD for outgoing storage migration === |
| 147 | +echo |
| 148 | + |
| 149 | +_send_qemu_cmd $h1 '{"execute": "blockdev-add", "arguments": |
| 150 | + {"node-name": "mirror", "driver": "nbd", |
| 151 | + "server": {"type": "inet", "host": "127.0.0.1", "port": "'$port'"}, |
| 152 | + "export": "drive_image1", "tls-creds": "tls0", |
| 153 | + "tls-hostname": "127.0.0.1"}}' '{"return": {}}' | sed "s/\"$port\"/PORT/g" |
| 154 | +_send_qemu_cmd $h1 '{"execute": "blockdev-mirror", "arguments": |
| 155 | + {"sync": "full", "device": "drive_image1", "target": "mirror", |
| 156 | + "job-id": "drive_image1_53"}}' '{"return": {}}' |
| 157 | +_timed_wait_for $h1 '"ready"' |
| 158 | + |
| 159 | +echo |
| 160 | +echo === Cleaning up === |
| 161 | +echo |
| 162 | + |
| 163 | +_send_qemu_cmd $h1 '{"execute":"quit"}' '' |
| 164 | +_send_qemu_cmd $h2 '{"execute":"quit"}' '' |
| 165 | + |
| 166 | +echo "*** done" |
| 167 | +rm -f $seq.full |
| 168 | +status=0 |
0 commit comments