xref: /openbmc/qemu/tests/qemu-iotests/289 (revision 57284d2ada481fe557c9a2f00228eca2a83e1d60)
1c264e5d2SMax Reitz#!/usr/bin/env bash
2c264e5d2SMax Reitz#
3c264e5d2SMax Reitz# qcow2 v3-exclusive error path testing
4c264e5d2SMax Reitz# (026 tests paths common to v2 and v3)
5c264e5d2SMax Reitz#
6c264e5d2SMax Reitz# Copyright (C) 2020 Red Hat, Inc.
7c264e5d2SMax Reitz#
8c264e5d2SMax Reitz# This program is free software; you can redistribute it and/or modify
9c264e5d2SMax Reitz# it under the terms of the GNU General Public License as published by
10c264e5d2SMax Reitz# the Free Software Foundation; either version 2 of the License, or
11c264e5d2SMax Reitz# (at your option) any later version.
12c264e5d2SMax Reitz#
13c264e5d2SMax Reitz# This program is distributed in the hope that it will be useful,
14c264e5d2SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
15c264e5d2SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16c264e5d2SMax Reitz# GNU General Public License for more details.
17c264e5d2SMax Reitz#
18c264e5d2SMax Reitz# You should have received a copy of the GNU General Public License
19c264e5d2SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20c264e5d2SMax Reitz#
21c264e5d2SMax Reitz
22c264e5d2SMax Reitzseq=$(basename $0)
23c264e5d2SMax Reitzecho "QA output created by $seq"
24c264e5d2SMax Reitz
25c264e5d2SMax Reitzstatus=1	# failure is the default!
26c264e5d2SMax Reitz
27c264e5d2SMax Reitz_cleanup()
28c264e5d2SMax Reitz{
29c264e5d2SMax Reitz    _cleanup_test_img
30c264e5d2SMax Reitz    rm "$TEST_DIR/blkdebug.conf"
31c264e5d2SMax Reitz    rm -f "$TEST_IMG.data_file"
32c264e5d2SMax Reitz}
33c264e5d2SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
34c264e5d2SMax Reitz
35c264e5d2SMax Reitz# get standard environment, filters and checks
36c264e5d2SMax Reitz. ./common.rc
37c264e5d2SMax Reitz. ./common.filter
38c264e5d2SMax Reitz. ./common.pattern
39c264e5d2SMax Reitz
40c264e5d2SMax Reitz_supported_fmt qcow2
41*57284d2aSMax Reitz_supported_proto file fuse
42c264e5d2SMax Reitz# This is a v3-exclusive test;
43c264e5d2SMax Reitz# As for data_file, error paths often very much depend on whether
44c264e5d2SMax Reitz# there is an external data file or not; so we create one exactly when
45c264e5d2SMax Reitz# we want to test it
46c264e5d2SMax Reitz_unsupported_imgopts 'compat=0.10' data_file
47c264e5d2SMax Reitz
48c264e5d2SMax Reitzecho
49c264e5d2SMax Reitzecho === Avoid freeing external data clusters on failure ===
50c264e5d2SMax Reitzecho
51c264e5d2SMax Reitz
52c264e5d2SMax Reitzcat > "$TEST_DIR/blkdebug.conf" <<EOF
53c264e5d2SMax Reitz[inject-error]
54c264e5d2SMax Reitzevent = "write_aio"
55c264e5d2SMax Reitzerrno = "5"
56c264e5d2SMax Reitzonce = "on"
57c264e5d2SMax ReitzEOF
58c264e5d2SMax Reitz
59c264e5d2SMax Reitz# Test what happens when there is an error when writing to an external
60c264e5d2SMax Reitz# data file instead of when writing to a preallocated zero cluster
61c264e5d2SMax Reitz_make_test_img -o "data_file=$TEST_IMG.data_file" 64k
62c264e5d2SMax Reitz
63c264e5d2SMax Reitz# Put blkdebug above the data-file, and a raw node on top of that so
64c264e5d2SMax Reitz# that blkdebug will see a write_aio event and emit an error.  This
65c264e5d2SMax Reitz# will then trigger the alloc abort code, which we want to test here.
66c264e5d2SMax Reitz$QEMU_IO -c "write 0 64k" \
67c264e5d2SMax Reitz    "json:{
68c264e5d2SMax Reitz         'driver': 'qcow2',
69c264e5d2SMax Reitz         'file': { 'driver': 'file', 'filename': '$TEST_IMG' },
70c264e5d2SMax Reitz         'data-file': {
71c264e5d2SMax Reitz             'driver': 'raw',
72c264e5d2SMax Reitz             'file': {
73c264e5d2SMax Reitz                 'driver': 'blkdebug',
74c264e5d2SMax Reitz                 'config': '$TEST_DIR/blkdebug.conf',
75c264e5d2SMax Reitz                 'image': {
76c264e5d2SMax Reitz                     'driver': 'file',
77c264e5d2SMax Reitz                     'filename': '$TEST_IMG.data_file'
78c264e5d2SMax Reitz                 }
79c264e5d2SMax Reitz             }
80c264e5d2SMax Reitz         }
81c264e5d2SMax Reitz     }" \
82c264e5d2SMax Reitz    | _filter_qemu_io
83c264e5d2SMax Reitz
84c264e5d2SMax Reitz_check_test_img
85c264e5d2SMax Reitz
86c264e5d2SMax Reitz# success, all done
87c264e5d2SMax Reitzecho "*** done"
88c264e5d2SMax Reitzrm -f $seq.full
89c264e5d2SMax Reitzstatus=0
90