111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2426d52d8SDaniel P. Berrange# 3*f4649069SEric Blake# Test encrypted read/write using plain bdrv_pread/bdrv_pwrite 4426d52d8SDaniel P. Berrange# 5426d52d8SDaniel P. Berrange# Copyright (C) 2017 Red Hat, Inc. 6426d52d8SDaniel P. Berrange# 7426d52d8SDaniel P. Berrange# This program is free software; you can redistribute it and/or modify 8426d52d8SDaniel P. Berrange# it under the terms of the GNU General Public License as published by 9426d52d8SDaniel P. Berrange# the Free Software Foundation; either version 2 of the License, or 10426d52d8SDaniel P. Berrange# (at your option) any later version. 11426d52d8SDaniel P. Berrange# 12426d52d8SDaniel P. Berrange# This program is distributed in the hope that it will be useful, 13426d52d8SDaniel P. Berrange# but WITHOUT ANY WARRANTY; without even the implied warranty of 14426d52d8SDaniel P. Berrange# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15426d52d8SDaniel P. Berrange# GNU General Public License for more details. 16426d52d8SDaniel P. Berrange# 17426d52d8SDaniel P. Berrange# You should have received a copy of the GNU General Public License 18426d52d8SDaniel P. Berrange# along with this program. If not, see <http://www.gnu.org/licenses/>. 19426d52d8SDaniel P. Berrange# 20426d52d8SDaniel P. Berrange 21426d52d8SDaniel P. Berrange# creator 22426d52d8SDaniel P. Berrangeowner=berrange@redhat.com 23426d52d8SDaniel P. Berrange 24426d52d8SDaniel P. Berrangeseq=`basename $0` 25426d52d8SDaniel P. Berrangeecho "QA output created by $seq" 26426d52d8SDaniel P. Berrange 27426d52d8SDaniel P. Berrangestatus=1 # failure is the default! 28426d52d8SDaniel P. Berrange 29426d52d8SDaniel P. Berrange_cleanup() 30426d52d8SDaniel P. Berrange{ 31426d52d8SDaniel P. Berrange _cleanup_test_img 32426d52d8SDaniel P. Berrange} 33426d52d8SDaniel P. Berrangetrap "_cleanup; exit \$status" 0 1 2 3 15 34426d52d8SDaniel P. Berrange 35426d52d8SDaniel P. Berrange# get standard environment, filters and checks 36426d52d8SDaniel P. Berrange. ./common.rc 37426d52d8SDaniel P. Berrange. ./common.filter 38426d52d8SDaniel P. Berrange 39426d52d8SDaniel P. Berrange_supported_fmt qcow2 40426d52d8SDaniel P. Berrange_supported_proto generic 41426d52d8SDaniel P. Berrange_supported_os Linux 42426d52d8SDaniel P. Berrange 43426d52d8SDaniel P. Berrange 44426d52d8SDaniel P. Berrangesize=16M 45426d52d8SDaniel P. Berrange 46426d52d8SDaniel P. BerrangeSECRET="secret,id=sec0,data=astrochicken" 47426d52d8SDaniel P. BerrangeSECRETALT="secret,id=sec0,data=platypus" 48426d52d8SDaniel P. Berrange 49426d52d8SDaniel P. Berrange_make_test_img --object $SECRET -o "encrypt.format=luks,encrypt.key-secret=sec0,encrypt.iter-time=10" $size 50426d52d8SDaniel P. Berrange 515a840549SMax ReitzIMGSPEC="driver=$IMGFMT,encrypt.key-secret=sec0,file.filename=$TEST_IMG" 52426d52d8SDaniel P. Berrange 53426d52d8SDaniel P. BerrangeQEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT 54426d52d8SDaniel P. Berrange 55426d52d8SDaniel P. Berrangeecho 56426d52d8SDaniel P. Berrangeecho "== reading whole image ==" 57426d52d8SDaniel P. Berrange$QEMU_IO --object $SECRET -c "read -P 0 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 58426d52d8SDaniel P. Berrange 59426d52d8SDaniel P. Berrangeecho 60426d52d8SDaniel P. Berrangeecho "== rewriting whole image ==" 61426d52d8SDaniel P. Berrange$QEMU_IO --object $SECRET -c "write -P 0xa 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 62426d52d8SDaniel P. Berrange 63426d52d8SDaniel P. Berrangeecho 64426d52d8SDaniel P. Berrangeecho "== verify pattern ==" 65426d52d8SDaniel P. Berrange$QEMU_IO --object $SECRET -c "read -P 0xa 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 66426d52d8SDaniel P. Berrange 67426d52d8SDaniel P. Berrangeecho 68426d52d8SDaniel P. Berrangeecho "== verify open failure with wrong password ==" 69426d52d8SDaniel P. Berrange$QEMU_IO --object $SECRETALT -c "read -P 0xa 0 $size" --image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir 70426d52d8SDaniel P. Berrange 715a840549SMax Reitz_cleanup_test_img 725a840549SMax Reitz 735a840549SMax Reitzecho 745a840549SMax Reitzecho "== verify that has_zero_init returns false when preallocating ==" 755a840549SMax Reitz 765a840549SMax Reitz# Empty source file 775a840549SMax Reitzif [ -n "$TEST_IMG_FILE" ]; then 785a840549SMax Reitz TEST_IMG_FILE="${TEST_IMG_FILE}.orig" _make_test_img $size 795a840549SMax Reitzelse 805a840549SMax Reitz TEST_IMG="${TEST_IMG}.orig" _make_test_img $size 815a840549SMax Reitzfi 825a840549SMax Reitz 835a840549SMax Reitz$QEMU_IMG convert -O "$IMGFMT" --object $SECRET \ 845a840549SMax Reitz -o "encrypt.format=luks,encrypt.key-secret=sec0,encrypt.iter-time=10,preallocation=metadata" \ 855a840549SMax Reitz "${TEST_IMG}.orig" "$TEST_IMG" 865a840549SMax Reitz 875a840549SMax Reitz$QEMU_IMG compare --object $SECRET --image-opts "${IMGSPEC}.orig" "$IMGSPEC" 885a840549SMax Reitz 89426d52d8SDaniel P. Berrange 90426d52d8SDaniel P. Berrange# success, all done 91426d52d8SDaniel P. Berrangeecho "*** done" 92426d52d8SDaniel P. Berrangerm -f $seq.full 93426d52d8SDaniel P. Berrangestatus=0 94