111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick 3f7ac119cSDaniel P. Berrange# 4f4649069SEric Blake# Test encrypted read/write using plain bdrv_pread/bdrv_pwrite 5f7ac119cSDaniel P. Berrange# 6f7ac119cSDaniel P. Berrange# Copyright (C) 2015 Red Hat, Inc. 7f7ac119cSDaniel P. Berrange# 8f7ac119cSDaniel P. Berrange# This program is free software; you can redistribute it and/or modify 9f7ac119cSDaniel P. Berrange# it under the terms of the GNU General Public License as published by 10f7ac119cSDaniel P. Berrange# the Free Software Foundation; either version 2 of the License, or 11f7ac119cSDaniel P. Berrange# (at your option) any later version. 12f7ac119cSDaniel P. Berrange# 13f7ac119cSDaniel P. Berrange# This program is distributed in the hope that it will be useful, 14f7ac119cSDaniel P. Berrange# but WITHOUT ANY WARRANTY; without even the implied warranty of 15f7ac119cSDaniel P. Berrange# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16f7ac119cSDaniel P. Berrange# GNU General Public License for more details. 17f7ac119cSDaniel P. Berrange# 18f7ac119cSDaniel P. Berrange# You should have received a copy of the GNU General Public License 19f7ac119cSDaniel P. Berrange# along with this program. If not, see <http://www.gnu.org/licenses/>. 20f7ac119cSDaniel P. Berrange# 21f7ac119cSDaniel P. Berrange 22f7ac119cSDaniel P. Berrange# creator 23f7ac119cSDaniel P. Berrangeowner=berrange@redhat.com 24f7ac119cSDaniel P. Berrange 25f7ac119cSDaniel P. Berrangeseq=`basename $0` 26f7ac119cSDaniel P. Berrangeecho "QA output created by $seq" 27f7ac119cSDaniel P. Berrange 28f7ac119cSDaniel P. Berrangestatus=1 # failure is the default! 29f7ac119cSDaniel P. Berrange 30f7ac119cSDaniel P. Berrange_cleanup() 31f7ac119cSDaniel P. Berrange{ 32f7ac119cSDaniel P. Berrange _cleanup_test_img 33f7ac119cSDaniel P. Berrange} 34f7ac119cSDaniel P. Berrangetrap "_cleanup; exit \$status" 0 1 2 3 15 35f7ac119cSDaniel P. Berrange 36f7ac119cSDaniel P. Berrange# get standard environment, filters and checks 37f7ac119cSDaniel P. Berrange. ./common.rc 38f7ac119cSDaniel P. Berrange. ./common.filter 39f7ac119cSDaniel P. Berrange 4023f831c3SDaniel P. Berrange_supported_fmt qcow qcow2 41*9e395444SThomas Huth_supported_proto file 42f7ac119cSDaniel P. Berrange 43f7ac119cSDaniel P. Berrange 44f7ac119cSDaniel P. Berrangesize=128M 45b25b387fSDaniel P. Berrange 46b25b387fSDaniel P. BerrangeSECRET="secret,id=sec0,data=astrochicken" 47b25b387fSDaniel P. BerrangeSECRETALT="secret,id=sec0,data=platypus" 48b25b387fSDaniel P. Berrange 49b25b387fSDaniel P. Berrange_make_test_img --object $SECRET -o "encryption=on,encrypt.key-secret=sec0" $size 50b25b387fSDaniel P. Berrange 51b25b387fSDaniel P. BerrangeIMGSPEC="driver=$IMGFMT,file.filename=$TEST_IMG,encrypt.key-secret=sec0" 52b25b387fSDaniel P. Berrange 53b25b387fSDaniel P. BerrangeQEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT 54f7ac119cSDaniel P. Berrange 55f7ac119cSDaniel P. Berrangeecho 56f7ac119cSDaniel P. Berrangeecho "== reading whole image ==" 57b25b387fSDaniel P. Berrange$QEMU_IO --object $SECRET -c "read 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 58f7ac119cSDaniel P. Berrange 59f7ac119cSDaniel P. Berrangeecho 606ec889ebSAnton Nefedovecho "== rewriting cluster part ==" 616ec889ebSAnton Nefedov$QEMU_IO --object $SECRET -c "write -P 0xb 512 512" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 626ec889ebSAnton Nefedov 636ec889ebSAnton Nefedovecho 646ec889ebSAnton Nefedovecho "== verify pattern ==" 656ec889ebSAnton Nefedov$QEMU_IO --object $SECRET -c "read -P 0 0 512" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 666ec889ebSAnton Nefedov$QEMU_IO --object $SECRET -c "read -P 0xb 512 512" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 676ec889ebSAnton Nefedov 686ec889ebSAnton Nefedovecho 69f7ac119cSDaniel P. Berrangeecho "== rewriting whole image ==" 70b25b387fSDaniel P. Berrange$QEMU_IO --object $SECRET -c "write -P 0xa 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 71f7ac119cSDaniel P. Berrange 72f7ac119cSDaniel P. Berrangeecho 73f7ac119cSDaniel P. Berrangeecho "== verify pattern ==" 74b25b387fSDaniel P. Berrange$QEMU_IO --object $SECRET -c "read -P 0xa 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 75f7ac119cSDaniel P. Berrange 76f7ac119cSDaniel P. Berrangeecho 77f7ac119cSDaniel P. Berrangeecho "== verify pattern failure with wrong password ==" 78b25b387fSDaniel P. Berrange$QEMU_IO --object $SECRETALT -c "read -P 0xa 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 79f7ac119cSDaniel P. Berrange 80f7ac119cSDaniel P. Berrange 81f7ac119cSDaniel P. Berrange# success, all done 82f7ac119cSDaniel P. Berrangeecho "*** done" 83f7ac119cSDaniel P. Berrangerm -f $seq.full 84f7ac119cSDaniel P. Berrangestatus=0 85