This test will focus on the low level procedure of qcow2 snapshot
operations, now it covers only the create operation. Overlap error
paths are not checked since no good way to trigger those errors.
Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
tests/qemu-iotests/063 | 229
tests/qemu-iotests/063.out | 37 +++
tests/qemu-iotests/group |1 +
3 files changed, 267 insertions(+), 0 deletions(-)
create mode 100755 tests/qemu-iotests/063
create mode 100644 tests/qemu-iotests/063.out
diff --git a/tests/qemu-iotests/063 b/tests/qemu-iotests/063
new file mode 100755
index 000..f3f6e16
--- /dev/null
+++ b/tests/qemu-iotests/063
@@ -0,0 +1,229 @@
+#!/bin/bash
+#
+# qcow2 internal snapshot test
+#
+# Copyright (C) 2013 IBM, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see http://www.gnu.org/licenses/.
+#
+owner=xiaw...@linux.vnet.ibm.com
+
+seq=`basename $0`
+echo QA output created by $seq
+
+here=`pwd`
+tmp=/tmp/$$
+status=1 # failure is the default!
+
+_cleanup()
+{
+_cleanup_test_img
+rm $TEST_DIR/blkdebug.conf
+}
+trap _cleanup; exit \$status 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+. ./common.pattern
+
+# only test qcow2
+_supported_fmt qcow2
+_supported_proto generic
+_supported_os Linux
+
+IMGOPTS=compat=1.1
+
+CLUSTER_SIZE=65536
+
+SIZE=1G
+
+BLKDBG_TEST_IMG=blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG
+
+errno=5
+
+once=on
+
+imm=off
+
+
+# Start test, note that the injected errors are related to qcow2's snapshot
+# logic closely, see qcow2-snapshot.c for more details.
+
+# path 1: fail in L1 table allocation for snapshot
+echo
+echo Path 1: fail in allocation of L1 table
+
+_make_test_img $SIZE
+
+cat $TEST_DIR/blkdebug.conf EOF
+[inject-error]
+event = cluster_alloc
+errno = $errno
+immediately = $imm
+once = $once
+EOF
+
+$QEMU_IMG snapshot -c snap1 $BLKDBG_TEST_IMG
+$QEMU_IMG snapshot -l $TEST_IMG
+_check_test_img 21
+
+
+# path 2: fail in update new L1 table
+echo
+echo Path 2: fail in overlap check before update L1 table for snapshot
+
+_make_test_img $SIZE
+
+cat $TEST_DIR/blkdebug.conf EOF
+[inject-error]
+event = snapshot_l1_update
+errno = $errno
+immediately = $imm
+once = $once
+EOF
+
+$QEMU_IMG snapshot -c snap1 $BLKDBG_TEST_IMG
+$QEMU_IMG snapshot -l $TEST_IMG
+_check_test_img 21
+
+# path 3: fail in update refcount block before write snapshot list
+echo
+echo Path 3: fail in update refcount block before write snapshot list
+
+_make_test_img $SIZE
+
+cat $TEST_DIR/blkdebug.conf EOF
+[inject-error]
+event = refblock_alloc
+errno = $errno
+immediately = $imm
+once = $once
+EOF
+
+$QEMU_IMG snapshot -c snap1 $BLKDBG_TEST_IMG
+$QEMU_IMG snapshot -l $TEST_IMG
+_check_test_img 21
+
+# path 4: fail in snapshot list allocation, it is possible
+# qcow2_alloc_clusters() not fail immediately since cache hit, but in any
+# case, no error should be found in image check.
+echo
+echo Path 4: fail in snapshot list allocation
+
+_make_test_img $SIZE
+
+cat $TEST_DIR/blkdebug.conf EOF
+[set-state]
+state = 1
+event = cluster_alloc
+new_state = 2
+
+[inject-error]
+state = 2
+event = cluster_alloc
+errno = $errno
+immediately = $imm
+once = $once
+EOF
+
+$QEMU_IMG snapshot -c snap1 $BLKDBG_TEST_IMG
+$QEMU_IMG snapshot -l $TEST_IMG
+_check_test_img 21
+
+# path 5: fail in flush after snapshot list allocation, flush is related with
+# cache status, if no cache available then the flush may not trigger a error
+# in bdrv_flush(), but no error should be found in image check.
+echo
+echo Path 5: fail in flush after snapshot list allocation
+
+_make_test_img $SIZE
+
+cat $TEST_DIR/blkdebug.conf EOF
+[set-state]
+state = 1
+event = cluster_alloc
+new_state = 2
+
+[set-state]
+state = 2
+event = cluster_alloc
+new_state = 3
+
+[inject-error]
+state = 3
+event = flush_to_os
+errno = $errno
+immediately = $imm
+once = $once
+
+[set-state]
+state = 3
+event = flush_to_os
+new_state = 4
+EOF
+
+$QEMU_IMG snapshot -c snap1 $BLKDBG_TEST_IMG
+$QEMU_IMG snapshot -l $TEST_IMG
+_check_test_img 21
+
+# path 6: fail in snapshot list update
+echo
+echo Path 6: fail in snapshot list update
+
+_make_test_img $SIZE
+
+cat $TEST_DIR/blkdebug.conf EOF
+[inject-error]
+event = snapshot_list_update
+errno = $errno
+immediately = $imm
+once = $once
+EOF
+
+$QEMU_IMG snapshot -c snap1 $BLKDBG_TEST_IMG
+$QEMU_IMG snapshot -l