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