]>
Commit | Line | Data |
---|---|---|
11a82d14 | 1 | #!/usr/bin/env bash |
9c468a01 | 2 | # |
f33d2873 | 3 | # Test export internal snapshot by qemu-nbd, convert it by qemu-img. |
9c468a01 WX |
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 | owner=xiawenc@linux.vnet.ibm.com | |
25 | ||
26 | seq=`basename $0` | |
27 | echo "QA output created by $seq" | |
28 | ||
9c468a01 WX |
29 | status=1 # failure is the default! |
30 | ||
9c468a01 WX |
31 | _export_nbd_snapshot() |
32 | { | |
e6d5d6fd | 33 | nbd_server_start_unix_socket "$TEST_IMG" -l $1 |
9c468a01 WX |
34 | } |
35 | ||
36 | _export_nbd_snapshot1() | |
37 | { | |
e6d5d6fd | 38 | nbd_server_start_unix_socket "$TEST_IMG" -l snapshot.name=$1 |
9c468a01 WX |
39 | } |
40 | ||
41 | _cleanup() | |
42 | { | |
e6d5d6fd | 43 | nbd_server_stop |
9c468a01 | 44 | _cleanup_test_img |
f91ecbd7 | 45 | _rm_test_img "$converted_image" |
9c468a01 WX |
46 | } |
47 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
48 | ||
49 | # get standard environment, filters and checks | |
50 | . ./common.rc | |
51 | . ./common.filter | |
52 | . ./common.pattern | |
e6d5d6fd | 53 | . ./common.nbd |
9c468a01 WX |
54 | |
55 | _supported_fmt qcow2 | |
56 | _supported_proto file | |
9c8ab1ae | 57 | _supported_os Linux |
9c468a01 | 58 | _require_command QEMU_NBD |
3be2024a HR |
59 | # Internal snapshots are (currently) impossible with refcount_bits=1, |
60 | # and generally impossible with external data files | |
61 | _unsupported_imgopts 'refcount_bits=1[^0-9]' data_file | |
9c468a01 | 62 | |
e6d5d6fd DB |
63 | nbd_snapshot_img="nbd:unix:$nbd_unix_socket" |
64 | ||
65 | converted_image=$TEST_IMG.converted | |
66 | ||
8f9e835f KW |
67 | # Use -f raw instead of -f $IMGFMT for the NBD connection |
68 | QEMU_IO_NBD="$QEMU_IO -f raw --cache=$CACHEMODE" | |
69 | ||
9c468a01 WX |
70 | echo |
71 | echo "== preparing image ==" | |
72 | _make_test_img 64M | |
73 | $QEMU_IO -c 'write -P 0xa 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io | |
74 | $QEMU_IO -c 'write -P 0xb 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io | |
75 | $QEMU_IMG snapshot -c sn1 "$TEST_IMG" | |
76 | $QEMU_IO -c 'write -P 0xc 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io | |
77 | $QEMU_IO -c 'write -P 0xd 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io | |
78 | _check_test_img | |
79 | ||
80 | echo | |
81 | echo "== verifying the image file with patterns ==" | |
82 | $QEMU_IO -c 'read -P 0xc 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io | |
83 | $QEMU_IO -c 'read -P 0xd 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io | |
84 | ||
85 | _export_nbd_snapshot sn1 | |
86 | ||
87 | echo | |
88 | echo "== verifying the exported snapshot with patterns, method 1 ==" | |
1104d83c EB |
89 | $QEMU_IO_NBD -r -c 'read -P 0xa 0x1000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io |
90 | $QEMU_IO_NBD -r -c 'read -P 0xb 0x2000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io | |
9c468a01 WX |
91 | |
92 | _export_nbd_snapshot1 sn1 | |
93 | ||
94 | echo | |
95 | echo "== verifying the exported snapshot with patterns, method 2 ==" | |
1104d83c EB |
96 | $QEMU_IO_NBD -r -c 'read -P 0xa 0x1000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io |
97 | $QEMU_IO_NBD -r -c 'read -P 0xb 0x2000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io | |
9c468a01 | 98 | |
f33d2873 WX |
99 | $QEMU_IMG convert "$TEST_IMG" -l sn1 -O qcow2 "$converted_image" |
100 | ||
101 | echo | |
102 | echo "== verifying the converted snapshot with patterns, method 1 ==" | |
103 | $QEMU_IO -c 'read -P 0xa 0x1000 0x1000' "$converted_image" | _filter_qemu_io | |
104 | $QEMU_IO -c 'read -P 0xb 0x2000 0x1000' "$converted_image" | _filter_qemu_io | |
105 | ||
106 | $QEMU_IMG convert "$TEST_IMG" -l snapshot.name=sn1 -O qcow2 "$converted_image" | |
107 | ||
108 | echo | |
109 | echo "== verifying the converted snapshot with patterns, method 2 ==" | |
110 | $QEMU_IO -c 'read -P 0xa 0x1000 0x1000' "$converted_image" | _filter_qemu_io | |
111 | $QEMU_IO -c 'read -P 0xb 0x2000 0x1000' "$converted_image" | _filter_qemu_io | |
112 | ||
9c468a01 WX |
113 | # success, all done |
114 | echo "*** done" | |
115 | rm -f $seq.full | |
116 | status=0 |