xref: /openbmc/qemu/tests/qemu-iotests/133 (revision 57284d2ada481fe557c9a2f00228eca2a83e1d60)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
20a8111e0SKevin Wolf#
30a8111e0SKevin Wolf# Test for reopen
40a8111e0SKevin Wolf#
50a8111e0SKevin Wolf# Copyright (C) 2015 Red Hat, Inc.
60a8111e0SKevin Wolf#
70a8111e0SKevin Wolf# This program is free software; you can redistribute it and/or modify
80a8111e0SKevin Wolf# it under the terms of the GNU General Public License as published by
90a8111e0SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
100a8111e0SKevin Wolf# (at your option) any later version.
110a8111e0SKevin Wolf#
120a8111e0SKevin Wolf# This program is distributed in the hope that it will be useful,
130a8111e0SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
140a8111e0SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
150a8111e0SKevin Wolf# GNU General Public License for more details.
160a8111e0SKevin Wolf#
170a8111e0SKevin Wolf# You should have received a copy of the GNU General Public License
180a8111e0SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
190a8111e0SKevin Wolf#
200a8111e0SKevin Wolf
210a8111e0SKevin Wolf# creator
220a8111e0SKevin Wolfowner=kwolf@redhat.com
230a8111e0SKevin Wolf
240a8111e0SKevin Wolfseq=`basename $0`
250a8111e0SKevin Wolfecho "QA output created by $seq"
260a8111e0SKevin Wolf
270a8111e0SKevin Wolfstatus=1	# failure is the default!
280a8111e0SKevin Wolf
290a8111e0SKevin Wolf_cleanup()
300a8111e0SKevin Wolf{
310a8111e0SKevin Wolf    _cleanup_test_img
320a8111e0SKevin Wolf}
330a8111e0SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
340a8111e0SKevin Wolf
350a8111e0SKevin Wolf# get standard environment, filters and checks
360a8111e0SKevin Wolf. ./common.rc
370a8111e0SKevin Wolf. ./common.filter
380a8111e0SKevin Wolf
390a8111e0SKevin Wolf_supported_fmt qcow2
40*57284d2aSMax Reitz_supported_proto file fuse
410a8111e0SKevin Wolf
420a8111e0SKevin WolfTEST_IMG="$TEST_IMG.base" _make_test_img 64M
43b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT
440a8111e0SKevin Wolf
450a8111e0SKevin Wolfecho
460a8111e0SKevin Wolfecho "=== Check that node-name can't be changed ==="
470a8111e0SKevin Wolfecho
480a8111e0SKevin Wolf
490a8111e0SKevin Wolf$QEMU_IO -c 'reopen -o node-name=foo' $TEST_IMG
500a8111e0SKevin Wolf$QEMU_IO -c 'reopen -o file.node-name=foo' $TEST_IMG
510a8111e0SKevin Wolf$QEMU_IO -c 'reopen -o backing.node-name=foo' $TEST_IMG
520a8111e0SKevin Wolf
530a8111e0SKevin Wolfecho
540a8111e0SKevin Wolfecho "=== Check that unchanged node-name is okay ==="
550a8111e0SKevin Wolfecho
560a8111e0SKevin Wolf
570a8111e0SKevin Wolf# Explicitly repeated
580a8111e0SKevin Wolf$QEMU_IO -c "open -o node-name=foo $TEST_IMG" -c 'reopen -o node-name=foo'
590a8111e0SKevin Wolf$QEMU_IO -c "open -o file.node-name=foo $TEST_IMG" -c 'reopen -o file.node-name=foo'
600a8111e0SKevin Wolf$QEMU_IO -c "open -o backing.node-name=foo $TEST_IMG" -c 'reopen -o backing.node-name=foo'
610a8111e0SKevin Wolf
620a8111e0SKevin Wolf# Implicitly retained
630a8111e0SKevin Wolf$QEMU_IO -c "open -o node-name=foo $TEST_IMG" -c 'reopen'
640a8111e0SKevin Wolf$QEMU_IO -c "open -o file.node-name=foo $TEST_IMG" -c 'reopen'
650a8111e0SKevin Wolf$QEMU_IO -c "open -o backing.node-name=foo $TEST_IMG" -c 'reopen'
660a8111e0SKevin Wolf
670a8111e0SKevin Wolfecho
680a8111e0SKevin Wolfecho "=== Check that driver can't be changed ==="
690a8111e0SKevin Wolfecho
700a8111e0SKevin Wolf
710a8111e0SKevin Wolf$QEMU_IO -c 'reopen -o driver=raw' $TEST_IMG
720a8111e0SKevin Wolf$QEMU_IO -c 'reopen -o file.driver=qcow2' $TEST_IMG
730a8111e0SKevin Wolf$QEMU_IO -c 'reopen -o backing.driver=file' $TEST_IMG
740a8111e0SKevin Wolf
750a8111e0SKevin Wolfecho
760a8111e0SKevin Wolfecho "=== Check that unchanged driver is okay ==="
770a8111e0SKevin Wolfecho
780a8111e0SKevin Wolf
790a8111e0SKevin Wolf# Explicitly repeated (implicit case is covered in node-name test)
800a8111e0SKevin Wolf$QEMU_IO -c 'reopen -o driver=qcow2' $TEST_IMG
810a8111e0SKevin Wolf$QEMU_IO -c 'reopen -o file.driver=file' $TEST_IMG
820a8111e0SKevin Wolf$QEMU_IO -c 'reopen -o backing.driver=qcow2' $TEST_IMG
830a8111e0SKevin Wolf
84791cbcccSMax Reitzecho
85791cbcccSMax Reitzecho "=== Check that reopening works with non-string options ==="
86791cbcccSMax Reitzecho
87791cbcccSMax Reitz
88791cbcccSMax Reitz# Using the json: pseudo-protocol we can create non-string options
89791cbcccSMax Reitz# (Invoke 'info' just so we get some output afterwards)
90791cbcccSMax ReitzIMGOPTSSYNTAX=false $QEMU_IO -f null-co -c 'reopen' -c 'info' \
91791cbcccSMax Reitz    "json:{'driver': 'null-co', 'size': 65536}"
92791cbcccSMax Reitz
93dc900c35SAlberto Garciaecho
94dc900c35SAlberto Garciaecho "=== Check that mixing -c/-r/-w and their corresponding options is forbidden ==="
95dc900c35SAlberto Garciaecho
96dc900c35SAlberto Garcia
97dc900c35SAlberto Garcia$QEMU_IO -c 'reopen -r -o read-only=on' $TEST_IMG
98dc900c35SAlberto Garcia$QEMU_IO -c 'reopen -w -o read-only=on' $TEST_IMG
99dc900c35SAlberto Garcia$QEMU_IO -c 'reopen -c none -o cache.direct=on' $TEST_IMG
100dc900c35SAlberto Garcia$QEMU_IO -c 'reopen -c writeback -o cache.direct=on' $TEST_IMG
101dc900c35SAlberto Garcia$QEMU_IO -c 'reopen -c directsync -o cache.no-flush=on' $TEST_IMG
1028eb4b07bSAlberto Garcia
1038eb4b07bSAlberto Garciaecho
1048eb4b07bSAlberto Garciaecho "=== Check that invalid options are handled correctly ==="
1058eb4b07bSAlberto Garciaecho
1068eb4b07bSAlberto Garcia
1078eb4b07bSAlberto Garcia$QEMU_IO -c 'reopen -o read-only=foo' $TEST_IMG
1088eb4b07bSAlberto Garcia$QEMU_IO -c 'reopen -o cache.no-flush=bar' $TEST_IMG
1098eb4b07bSAlberto Garcia$QEMU_IO -c 'reopen -o cache.direct=baz' $TEST_IMG
1108eb4b07bSAlberto Garcia$QEMU_IO -c 'reopen -o auto-read-only=qux' $TEST_IMG
1110a8111e0SKevin Wolf# success, all done
1120a8111e0SKevin Wolfecho "*** done"
1130a8111e0SKevin Wolfrm -f $seq.full
1140a8111e0SKevin Wolfstatus=0
115