]> Git Repo - qemu.git/blob - tests/qemu-iotests/058
Merge remote-tracking branch 'mreitz/tags/pull-block-for-kevin-2015-11-11' into queue...
[qemu.git] / tests / qemu-iotests / 058
1 #!/bin/bash
2 #
3 # Test export internal snapshot by qemu-nbd, convert it by qemu-img.
4 #
5 # Copyright (C) 2013 IBM, Inc.
6 #
7 # Based on 029.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22
23 # creator
24 [email protected]
25
26 seq=`basename $0`
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32
33 nbd_unix_socket=$TEST_DIR/test_qemu_nbd_socket
34 nbd_snapshot_img="nbd:unix:$nbd_unix_socket"
35 rm -f "${TEST_DIR}/qemu-nbd.pid"
36
37 _cleanup_nbd()
38 {
39     local NBD_SNAPSHOT_PID
40     if [ -f "${TEST_DIR}/qemu-nbd.pid" ]; then
41         read NBD_SNAPSHOT_PID < "${TEST_DIR}/qemu-nbd.pid"
42         rm -f "${TEST_DIR}/qemu-nbd.pid"
43         if [ -n "$NBD_SNAPSHOT_PID" ]; then
44             kill "$NBD_SNAPSHOT_PID"
45         fi
46     fi
47     rm -f "$nbd_unix_socket"
48 }
49
50 _wait_for_nbd()
51 {
52     for ((i = 0; i < 300; i++))
53     do
54         if [ -r "$nbd_unix_socket" ]; then
55             return
56         fi
57         sleep 0.1
58     done
59     echo "Failed in check of unix socket created by qemu-nbd"
60     exit 1
61 }
62
63 converted_image=$TEST_IMG.converted
64
65 _export_nbd_snapshot()
66 {
67     _cleanup_nbd
68     $QEMU_NBD -v -t -k "$nbd_unix_socket" "$TEST_IMG" -l $1 &
69     _wait_for_nbd
70 }
71
72 _export_nbd_snapshot1()
73 {
74     _cleanup_nbd
75     $QEMU_NBD -v -t -k "$nbd_unix_socket" "$TEST_IMG" -l snapshot.name=$1 &
76     _wait_for_nbd
77 }
78
79 _cleanup()
80 {
81     _cleanup_nbd
82     _cleanup_test_img
83     rm -f "$converted_image"
84 }
85 trap "_cleanup; exit \$status" 0 1 2 3 15
86
87 # get standard environment, filters and checks
88 . ./common.rc
89 . ./common.filter
90 . ./common.pattern
91
92 _supported_fmt qcow2
93 _supported_proto file
94 _supported_os Linux
95 _require_command QEMU_NBD
96 # Internal snapshots are (currently) impossible with refcount_bits=1
97 _unsupported_imgopts 'refcount_bits=1[^0-9]'
98
99 # Use -f raw instead of -f $IMGFMT for the NBD connection
100 QEMU_IO_NBD="$QEMU_IO -f raw --cache=$CACHEMODE"
101
102 echo
103 echo "== preparing image =="
104 _make_test_img 64M
105 $QEMU_IO -c 'write -P 0xa 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io
106 $QEMU_IO -c 'write -P 0xb 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io
107 $QEMU_IMG snapshot -c sn1 "$TEST_IMG"
108 $QEMU_IO -c 'write -P 0xc 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io
109 $QEMU_IO -c 'write -P 0xd 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io
110 _check_test_img
111
112 echo
113 echo "== verifying the image file with patterns =="
114 $QEMU_IO -c 'read -P 0xc 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io
115 $QEMU_IO -c 'read -P 0xd 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io
116
117 _export_nbd_snapshot sn1
118
119 echo
120 echo "== verifying the exported snapshot with patterns, method 1 =="
121 $QEMU_IO_NBD -c 'read -P 0xa 0x1000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io
122 $QEMU_IO_NBD -c 'read -P 0xb 0x2000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io
123
124 _export_nbd_snapshot1 sn1
125
126 echo
127 echo "== verifying the exported snapshot with patterns, method 2 =="
128 $QEMU_IO_NBD -c 'read -P 0xa 0x1000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io
129 $QEMU_IO_NBD -c 'read -P 0xb 0x2000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io
130
131 $QEMU_IMG convert "$TEST_IMG" -l sn1 -O qcow2 "$converted_image"
132
133 echo
134 echo "== verifying the converted snapshot with patterns, method 1 =="
135 $QEMU_IO -c 'read -P 0xa 0x1000 0x1000' "$converted_image" | _filter_qemu_io
136 $QEMU_IO -c 'read -P 0xb 0x2000 0x1000' "$converted_image" | _filter_qemu_io
137
138 $QEMU_IMG convert "$TEST_IMG" -l snapshot.name=sn1 -O qcow2 "$converted_image"
139
140 echo
141 echo "== verifying the converted snapshot with patterns, method 2 =="
142 $QEMU_IO -c 'read -P 0xa 0x1000 0x1000' "$converted_image" | _filter_qemu_io
143 $QEMU_IO -c 'read -P 0xb 0x2000 0x1000' "$converted_image" | _filter_qemu_io
144
145 # success, all done
146 echo "*** done"
147 rm -f $seq.full
148 status=0
This page took 0.032231 seconds and 4 git commands to generate.