test/vhost: test for the vhost-blk readonly feature.

Change-Id: I5dde0555bd7d0e03dea3779dfd59c13ece92696a
Signed-off-by: Pawel Niedzwiecki <pawelx.niedzwiecki@intel.com>
Reviewed-on: https://review.gerrithub.io/382835
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Pawel Niedzwiecki 2017-10-17 20:59:36 +02:00 committed by Jim Harris
parent e4c4fec260
commit 30dbca865b
8 changed files with 340 additions and 0 deletions

View File

@ -139,6 +139,10 @@ if [ $SPDK_TEST_VHOST -eq 1 ]; then
timing_enter integrity
run_test ./test/vhost/spdk_vhost.sh --integrity
timing_exit integrity
timing_enter readonly
run_test ./test/vhost/spdk_vhost.sh --readonly
timing_exit readonly
fi
timing_enter integrity_lvol_scsi

View File

@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -e
BASE_DIR=$(readlink -f $(dirname $0))
disk_name="vda"
test_folder_name="readonly_test"
test_file_name="some_test_file"
function error()
{
echo "==========="
echo -e "ERROR: $@"
echo "==========="
trap - ERR
set +e
umount "$test_folder_name"
rm -rf "$BASE_DIR/$test_folder_name"
exit 1
}
trap 'error "In delete_partition_vm.sh, line:" "${LINENO}"' ERR
if [[ ! -d "/sys/block/$disk_name" ]]; then
error "No vhost-blk disk found!"
fi
if (( $(lsblk -r -n -o RO -d "/dev/$disk_name") == 1 )); then
error "Vhost-blk disk is set as readonly!"
fi
mkdir -p $test_folder_name
echo "INFO: Mounting disk"
mount /dev/$disk_name"1" $test_folder_name
echo "INFO: Removing folder and unmounting $test_folder_name"
umount "$test_folder_name"
rm -rf "$BASE_DIR/$test_folder_name"
echo "INFO: Deleting partition"
echo -e "d\n1\nw" | fdisk /dev/$disk_name

View File

@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -e
BASE_DIR=$(readlink -f $(dirname $0))
disk_name="vda"
test_folder_name="readonly_test"
test_file_name="some_test_file"
function error()
{
echo "==========="
echo -e "ERROR: $@"
echo "==========="
trap - ERR
set +e
umount "$test_folder_name"
rm -rf "$BASE_DIR/$test_folder_name"
exit 1
}
trap 'error "In disabled_readonly_vm.sh, line:" "${LINENO}"' ERR
if [[ ! -d "/sys/block/$disk_name" ]]; then
error "No vhost-blk disk found!"
fi
if (( $(lsblk -r -n -o RO -d "/dev/$disk_name") == 1 )); then
error "Vhost-blk disk is set as readonly!"
fi
parted -s /dev/$disk_name mklabel gpt
parted -s /dev/$disk_name mkpart primary 2048s 100%
partprobe
sleep 0.1
echo "INFO: Creating file system"
mkfs.ext4 -F /dev/$disk_name"1"
echo "INFO: Mounting disk"
mkdir -p $test_folder_name
mount /dev/$disk_name"1" $test_folder_name
echo "INFO: Creating a test file $test_file_name"
truncate -s "200M" $test_folder_name/$test_file_name
umount "$test_folder_name"
rm -rf "$BASE_DIR/$test_folder_name"

View File

@ -0,0 +1,75 @@
#!/usr/bin/env bash
BASE_DIR=$(readlink -f $(dirname $0))
disk_name="vda"
test_folder_name="readonly_test"
test_file_name="some_test_file"
function error()
{
echo "==========="
echo -e "ERROR: $@"
echo "==========="
umount "$test_folder_name"
rm -rf "$BASE_DIR/$test_folder_name"
exit 1
}
if [[ ! -d "/sys/block/$disk_name" ]]; then
error "No vhost-blk disk found!"
fi
if (( $(lsblk -r -n -o RO -d "/dev/$disk_name") == 0 )); then
error "Vhost-blk disk is not set as readonly!"
fi
echo "INFO: Found vhost-blk disk with readonly flag"
if [[ ! -b "/dev/$disk_name"1"" ]]; then
error "Partition not found!"
fi
mkdir $BASE_DIR/$test_folder_name
if [[ $? != 0 ]]; then
error "Failed to create test folder $test_folder_name"
fi
echo "INFO: Mounting partition"
mount /dev/$disk_name"1" $BASE_DIR/$test_folder_name
if [[ $? != 0 ]]; then
error "Failed to mount partition $disk_name""1"
fi
echo "INFO: Trying to create file on readonly disk"
truncate -s "200M" $test_folder_name/$test_file_name"_on_readonly"
if [[ $? == 0 ]]; then
error "Created a file on a readonly disk!"
fi
if [[ -f $test_folder_name/$test_file_name ]]; then
echo "INFO: Trying to delete previously created file"
rm $test_folder_name/$test_file_name
if [[ $? == 0 ]]; then
error "Deleted a file from a readonly disk!"
fi
else
error "Previously created file not found!"
fi
echo "INFO: Copying file from readonly disk"
cp $test_folder_name/$test_file_name $BASE_DIR
if ! rm $BASE_DIR/$test_file_name; then
error "Copied file from a readonly disk was not found!"
fi
umount "$test_folder_name"
rm -rf "$BASE_DIR/$test_folder_name"
echo "INFO: Trying to create file system on a readonly disk"
if mkfs.ext4 -F /dev/$disk_name"1"; then
error "Created file system on a readonly disk!"
fi
echo "INFO: Trying to delete partition from readonly disk"
if echo -e "d\n1\nw" | fdisk /dev/$disk_name; then
error "Deleted partition from readonly disk!"
fi

135
test/vhost/readonly/readonly.sh Executable file
View File

@ -0,0 +1,135 @@
#!/usr/bin/env bash
set -e
BASE_DIR=$(readlink -f $(dirname $0))
[[ -z "$TEST_DIR" ]] && TEST_DIR="$(cd $BASE_DIR/../../../../ && pwd)"
[[ -z "$COMMON_DIR" ]] && COMMON_DIR="$(cd $BASE_DIR/../common && pwd)"
rpc_py="$BASE_DIR/../../../scripts/rpc.py "
vm_img=""
disk="Nvme0n1_size_1G"
x=""
function usage()
{
[[ ! -z $2 ]] && ( echo "$2"; echo ""; )
echo "Shortcut script for automated readonly test fo vhost-block"
echo "For test details check test_plan.md"
echo
echo "Usage: $(basename $1) [OPTIONS]"
echo
echo "-h, --help Print help and exit"
echo " --vm_image= Path to VM image"
echo " --disk= Disk name and size. Disk can have additional size parameter,"
echo " e.g. --disk=Nvme0n1_size_35G; unit can be M or G; default - 20G."
echo " If disk=malloc, then creates malloc disk. For malloc disks, size is always 512M,"
echo " e.g. --disk=malloc. (Default: Nvme0n1_size_1G)"
echo "-x set -x for script debug"
}
while getopts 'xh-:' optchar; do
case "$optchar" in
-)
case "$OPTARG" in
help) usage $0 && exit 0;;
vm_image=*) vm_img="${OPTARG#*=}" ;;
disk=*) disk="${OPTARG#*=}" ;;
*) usage $0 "Invalid argument '$OPTARG'" && exit 1
esac
;;
h) usage $0 && exit 0 ;;
x) set -x
x="-x" ;;
*) usage $0 "Invalid argument '$OPTARG'" && exit 1
esac
done
if [[ $EUID -ne 0 ]]; then
echo "INFO: Go away user come back as root"
exit 1
fi
. $COMMON_DIR/common.sh
trap 'error_exit "${FUNCNAME}" "${LINENO}"' ERR
function print_tc_name()
{
echo ""
echo "==============================================================="
echo "Now running: $1"
echo "==============================================================="
}
function blk_ro_tc1()
{
print_tc_name ${FUNCNAME[0]}
local vm_no="0"
local disk_name=$disk
local vhost_blk_name=""
local vm_dir="$TEST_DIR/vms/$vm_no"
if [[ $disk =~ .*malloc.* ]]; then
disk_name=$($rpc_py construct_malloc_bdev 512 4096)
if [ $? != 0 ]; then
error "Failed to create malloc bdev"
fi
disk=$disk_name"_size_512M"
else
disk_name=${disk%%_*}
if ! $rpc_py get_bdevs | jq -r '.[] .name' | grep -qi $disk_name$; then
error "$disk_name bdev not found!"
fi
fi
#Create controller and create file on disk for later test
echo "INFO: Creating vhost_blk controller"
vhost_blk_name="naa.$disk_name.$vm_no"
$rpc_py construct_vhost_blk_controller $vhost_blk_name $disk_name
setup_cmd="$COMMON_DIR/vm_setup.sh $x --work-dir=$TEST_DIR --test-type=spdk_vhost_blk"
setup_cmd+=" -f $vm_no"
setup_cmd+=" --os=$vm_img"
setup_cmd+=" --disk=$disk"
$setup_cmd
$COMMON_DIR/vm_run.sh $x --work-dir=$TEST_DIR $vm_no
vm_wait_for_boot 600 $vm_no
echo "INFO: Prepearing partition and file on guest VM"
vm_ssh $vm_no "bash -s" < $BASE_DIR/disabled_readonly_vm.sh
sleep 1
vm_shutdown_all
#Create readonly controller and test readonly featchure
echo "INFO: Removing controller and creating new one with readonly flag"
$rpc_py remove_vhost_controller $vhost_blk_name
$rpc_py construct_vhost_blk_controller -r $vhost_blk_name $disk_name
$COMMON_DIR/vm_run.sh $x --work-dir=$TEST_DIR $vm_no
vm_wait_for_boot 600 $vm_no
echo "INFO: Testing readonly feature on guest VM"
vm_ssh $vm_no "bash -s" < $BASE_DIR/enabled_readonly_vm.sh
sleep 1
vm_shutdown_all
#Delete file from disk and delete partition
echo "INFO: Removing controller and creating new one"
$rpc_py remove_vhost_controller $vhost_blk_name
$rpc_py construct_vhost_blk_controller $vhost_blk_name $disk_name
$COMMON_DIR/vm_run.sh $x --work-dir=$TEST_DIR $vm_no
vm_wait_for_boot 600 $vm_no
echo "INFO: removing partition and file from test disk on guest VM"
vm_ssh $vm_no "bash -s" < $BASE_DIR/delete_partition_vm.sh
sleep 1
vm_shutdown_all
}
spdk_vhost_run $BASE_DIR
if [[ -z $x ]]; then
set +x
fi
blk_ro_tc1
spdk_vhost_kill

View File

@ -0,0 +1,30 @@
# vhost-block readonly feature test plan
## Objective
Vhost block controllers can be created with readonly feature which prevents any write operations on this device.
The purpose of this test is to verify proper operation of this feature.
## Test cases description
To test readonly feature, this test will create normal vhost-blk controller with NVMe device and on a VM it will
create and mount a partition to which it will copy a file. Next it will poweroff a VM, remove vhost controller and
create new readonly vhost-blk controller with the same device.
## Test cases
### blk_ro_tc1
1. Start vhost
2. Create vhost-blk controller with NVMe device and readonly feature disabled using RPC
3. Run VM with attached vhost-blk controller
4. Check visibility of readonly flag using lsblk, fdisk
5. Create new partition
6. Create new file on new partition
7. Shutdown VM, remove vhost controller
8. Create vhost-blk with previously used NVMe device and readonly feature now enabled using RPC
9. Run VM with attached vhost-blk controller
10. Check visibility of readonly flag using lsblk, fdisk
11. Try to delete previous file
12. Try to create new file
13. Try to remove partition
14. Repeat steps 2 to 4
15. Remove file from disk, delete partition
16. Shutdown VM, exit vhost

View File

@ -0,0 +1,2 @@
[Ioat]
Disable Yes

View File

@ -17,6 +17,7 @@ case $1 in
echo " -ils|--integrity-lvol-scsi for running an integrity test with vhost scsi and lvol backends"
echo " -ilb|--integrity-lvol-blk for running an integrity test with vhost blk and lvol backends"
echo " -hp|--hotplug for running hotplug tests"
echo " -ro|--readonly for running readonly test for vhost blk"
echo " -h |--help prints this message"
echo ""
echo "Environment:"
@ -114,6 +115,10 @@ case $1 in
--test-type=spdk_vhost_scsi \
--fio-jobs=$WORKDIR/hotplug/fio_jobs/default_integrity.job -x
;;
-ro|--readonly)
echo 'Running readonly tests suite...'
./readonly/readonly.sh --vm_image=$VM_IMAGE --disk=Nvme0n1_size_1G
;;
*)
echo "unknown test type: $1"
exit 1