xref: /openbmc/qemu/tests/qemu-iotests/058 (revision 8dff69b9)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29c468a01SWenchao Xia#
3f33d2873SWenchao Xia# Test export internal snapshot by qemu-nbd, convert it by qemu-img.
49c468a01SWenchao Xia#
59c468a01SWenchao Xia# Copyright (C) 2013 IBM, Inc.
69c468a01SWenchao Xia#
79c468a01SWenchao Xia# Based on 029.
89c468a01SWenchao Xia#
99c468a01SWenchao Xia# This program is free software; you can redistribute it and/or modify
109c468a01SWenchao Xia# it under the terms of the GNU General Public License as published by
119c468a01SWenchao Xia# the Free Software Foundation; either version 2 of the License, or
129c468a01SWenchao Xia# (at your option) any later version.
139c468a01SWenchao Xia#
149c468a01SWenchao Xia# This program is distributed in the hope that it will be useful,
159c468a01SWenchao Xia# but WITHOUT ANY WARRANTY; without even the implied warranty of
169c468a01SWenchao Xia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
179c468a01SWenchao Xia# GNU General Public License for more details.
189c468a01SWenchao Xia#
199c468a01SWenchao Xia# You should have received a copy of the GNU General Public License
209c468a01SWenchao Xia# along with this program.  If not, see <http://www.gnu.org/licenses/>.
219c468a01SWenchao Xia#
229c468a01SWenchao Xia
239c468a01SWenchao Xia# creator
249c468a01SWenchao Xiaowner=xiawenc@linux.vnet.ibm.com
259c468a01SWenchao Xia
269c468a01SWenchao Xiaseq=`basename $0`
279c468a01SWenchao Xiaecho "QA output created by $seq"
289c468a01SWenchao Xia
299c468a01SWenchao Xiastatus=1	# failure is the default!
309c468a01SWenchao Xia
319c468a01SWenchao Xia_export_nbd_snapshot()
329c468a01SWenchao Xia{
33e6d5d6fdSDaniel P. Berrangé    nbd_server_start_unix_socket "$TEST_IMG" -l $1
349c468a01SWenchao Xia}
359c468a01SWenchao Xia
369c468a01SWenchao Xia_export_nbd_snapshot1()
379c468a01SWenchao Xia{
38e6d5d6fdSDaniel P. Berrangé    nbd_server_start_unix_socket "$TEST_IMG" -l snapshot.name=$1
399c468a01SWenchao Xia}
409c468a01SWenchao Xia
419c468a01SWenchao Xia_cleanup()
429c468a01SWenchao Xia{
43e6d5d6fdSDaniel P. Berrangé    nbd_server_stop
449c468a01SWenchao Xia    _cleanup_test_img
45f91ecbd7SMax Reitz    _rm_test_img "$converted_image"
469c468a01SWenchao Xia}
479c468a01SWenchao Xiatrap "_cleanup; exit \$status" 0 1 2 3 15
489c468a01SWenchao Xia
499c468a01SWenchao Xia# get standard environment, filters and checks
509c468a01SWenchao Xia. ./common.rc
519c468a01SWenchao Xia. ./common.filter
529c468a01SWenchao Xia. ./common.pattern
53e6d5d6fdSDaniel P. Berrangé. ./common.nbd
549c468a01SWenchao Xia
559c468a01SWenchao Xia_supported_fmt qcow2
569c468a01SWenchao Xia_supported_proto file
579c8ab1aeSFam Zheng_supported_os Linux
589c468a01SWenchao Xia_require_command QEMU_NBD
593be2024aSMax Reitz# Internal snapshots are (currently) impossible with refcount_bits=1,
603be2024aSMax Reitz# and generally impossible with external data files
613be2024aSMax Reitz_unsupported_imgopts 'refcount_bits=1[^0-9]' data_file
629c468a01SWenchao Xia
63e6d5d6fdSDaniel P. Berrangénbd_snapshot_img="nbd:unix:$nbd_unix_socket"
64e6d5d6fdSDaniel P. Berrangé
65e6d5d6fdSDaniel P. Berrangéconverted_image=$TEST_IMG.converted
66e6d5d6fdSDaniel P. Berrangé
678f9e835fSKevin Wolf# Use -f raw instead of -f $IMGFMT for the NBD connection
68*8dff69b9SAarushi MehtaQEMU_IO_NBD="$QEMU_IO -f raw --cache=$CACHEMODE --aio=$AIOMODE"
698f9e835fSKevin Wolf
709c468a01SWenchao Xiaecho
719c468a01SWenchao Xiaecho "== preparing image =="
729c468a01SWenchao Xia_make_test_img 64M
739c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xa 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io
749c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xb 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io
759c468a01SWenchao Xia$QEMU_IMG snapshot -c sn1 "$TEST_IMG"
769c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xc 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io
779c468a01SWenchao Xia$QEMU_IO -c 'write -P 0xd 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io
789c468a01SWenchao Xia_check_test_img
799c468a01SWenchao Xia
809c468a01SWenchao Xiaecho
819c468a01SWenchao Xiaecho "== verifying the image file with patterns =="
829c468a01SWenchao Xia$QEMU_IO -c 'read -P 0xc 0x1000 0x1000' "$TEST_IMG" | _filter_qemu_io
839c468a01SWenchao Xia$QEMU_IO -c 'read -P 0xd 0x2000 0x1000' "$TEST_IMG" | _filter_qemu_io
849c468a01SWenchao Xia
859c468a01SWenchao Xia_export_nbd_snapshot sn1
869c468a01SWenchao Xia
879c468a01SWenchao Xiaecho
889c468a01SWenchao Xiaecho "== verifying the exported snapshot with patterns, method 1 =="
891104d83cSEric Blake$QEMU_IO_NBD -r -c 'read -P 0xa 0x1000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io
901104d83cSEric Blake$QEMU_IO_NBD -r -c 'read -P 0xb 0x2000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io
919c468a01SWenchao Xia
929c468a01SWenchao Xia_export_nbd_snapshot1 sn1
939c468a01SWenchao Xia
949c468a01SWenchao Xiaecho
959c468a01SWenchao Xiaecho "== verifying the exported snapshot with patterns, method 2 =="
961104d83cSEric Blake$QEMU_IO_NBD -r -c 'read -P 0xa 0x1000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io
971104d83cSEric Blake$QEMU_IO_NBD -r -c 'read -P 0xb 0x2000 0x1000' "$nbd_snapshot_img" | _filter_qemu_io
989c468a01SWenchao Xia
99f33d2873SWenchao Xia$QEMU_IMG convert "$TEST_IMG" -l sn1 -O qcow2 "$converted_image"
100f33d2873SWenchao Xia
101f33d2873SWenchao Xiaecho
102f33d2873SWenchao Xiaecho "== verifying the converted snapshot with patterns, method 1 =="
103f33d2873SWenchao Xia$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' "$converted_image" | _filter_qemu_io
104f33d2873SWenchao Xia$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' "$converted_image" | _filter_qemu_io
105f33d2873SWenchao Xia
106f33d2873SWenchao Xia$QEMU_IMG convert "$TEST_IMG" -l snapshot.name=sn1 -O qcow2 "$converted_image"
107f33d2873SWenchao Xia
108f33d2873SWenchao Xiaecho
109f33d2873SWenchao Xiaecho "== verifying the converted snapshot with patterns, method 2 =="
110f33d2873SWenchao Xia$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' "$converted_image" | _filter_qemu_io
111f33d2873SWenchao Xia$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' "$converted_image" | _filter_qemu_io
112f33d2873SWenchao Xia
1139c468a01SWenchao Xia# success, all done
1149c468a01SWenchao Xiaecho "*** done"
1159c468a01SWenchao Xiarm -f $seq.full
1169c468a01SWenchao Xiastatus=0
117