diff options
Diffstat (limited to 'src/spdk/test/vhost/readonly')
-rwxr-xr-x | src/spdk/test/vhost/readonly/delete_partition_vm.sh | 42 | ||||
-rwxr-xr-x | src/spdk/test/vhost/readonly/disabled_readonly_vm.sh | 47 | ||||
-rwxr-xr-x | src/spdk/test/vhost/readonly/enabled_readonly_vm.sh | 72 | ||||
-rwxr-xr-x | src/spdk/test/vhost/readonly/readonly.sh | 136 |
4 files changed, 297 insertions, 0 deletions
diff --git a/src/spdk/test/vhost/readonly/delete_partition_vm.sh b/src/spdk/test/vhost/readonly/delete_partition_vm.sh new file mode 100755 index 000000000..efba257f0 --- /dev/null +++ b/src/spdk/test/vhost/readonly/delete_partition_vm.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -xe + +testdir=$(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 "${testdir:?}/${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 "${testdir:?}/${test_folder_name:?}" + +echo "INFO: Deleting partition" +echo -e "d\n1\nw" | fdisk /dev/$disk_name diff --git a/src/spdk/test/vhost/readonly/disabled_readonly_vm.sh b/src/spdk/test/vhost/readonly/disabled_readonly_vm.sh new file mode 100755 index 000000000..2aec5b80a --- /dev/null +++ b/src/spdk/test/vhost/readonly/disabled_readonly_vm.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +set -xe + +testdir=$(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 "${testdir:?}/${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 "${testdir:?}/${test_folder_name:?}" diff --git a/src/spdk/test/vhost/readonly/enabled_readonly_vm.sh b/src/spdk/test/vhost/readonly/enabled_readonly_vm.sh new file mode 100755 index 000000000..939af6f08 --- /dev/null +++ b/src/spdk/test/vhost/readonly/enabled_readonly_vm.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +set -x + +testdir=$(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 "${testdir:?}/${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 + +if ! mkdir $testdir/$test_folder_name; then + error "Failed to create test folder $test_folder_name" +fi + +echo "INFO: Mounting partition" +if ! mount /dev/$disk_name"1" $testdir/$test_folder_name; then + error "Failed to mount partition $disk_name""1" +fi + +echo "INFO: Trying to create file on readonly disk" +if truncate -s "200M" $test_folder_name/$test_file_name"_on_readonly"; 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" + if rm $test_folder_name/$test_file_name; 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 $testdir +if ! rm $testdir/$test_file_name; then + error "Copied file from a readonly disk was not found!" +fi + +umount "$test_folder_name" +rm -rf "${testdir:?}/${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 diff --git a/src/spdk/test/vhost/readonly/readonly.sh b/src/spdk/test/vhost/readonly/readonly.sh new file mode 100755 index 000000000..ad66f72e0 --- /dev/null +++ b/src/spdk/test/vhost/readonly/readonly.sh @@ -0,0 +1,136 @@ +#!/usr/bin/env bash + +testdir=$(readlink -f $(dirname $0)) +rootdir=$(readlink -f $testdir/../../..) +source $rootdir/test/common/autotest_common.sh +source $rootdir/test/vhost/common.sh + +rpc_py="$testdir/../../../scripts/rpc.py -s $(get_vhost_dir 0)/rpc.sock" + +vm_img="" +disk="Nvme0n1" +x="" + +function usage() { + [[ -n $2 ]] && ( + echo "$2" + echo "" + ) + echo "Shortcut script for automated readonly test for 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." + echo " If disk=malloc, then creates malloc disk. For malloc disks, size is always 512M," + echo " e.g. --disk=malloc. (Default: Nvme0n1)" + 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 + +vhosttestinit + +trap 'error_exit "${FUNCNAME}" "${LINENO}"' ERR + +if [[ $EUID -ne 0 ]]; then + fail "Go away user come back as root" +fi + +function print_tc_name() { + notice "" + notice "===============================================================" + notice "Now running: $1" + notice "===============================================================" +} + +function blk_ro_tc1() { + print_tc_name ${FUNCNAME[0]} + local vm_no="0" + local disk_name=$disk + local vhost_blk_name="" + local vm_dir="$VHOST_DIR/vms/$vm_no" + + if [[ $disk =~ .*malloc.* ]]; then + if ! disk_name=$($rpc_py bdev_malloc_create 512 4096); then + fail "Failed to create malloc bdev" + fi + + disk=$disk_name + else + disk_name=${disk%%_*} + if ! $rpc_py bdev_get_bdevs | jq -r '.[] .name' | grep -qi $disk_name$; then + fail "$disk_name bdev not found!" + fi + fi + + #Create controller and create file on disk for later test + notice "Creating vhost_blk controller" + vhost_blk_name="naa.$disk_name.$vm_no" + $rpc_py vhost_create_blk_controller $vhost_blk_name $disk_name + vm_setup --disk-type=spdk_vhost_blk --force=$vm_no --os=$vm_img --disks=$disk --read-only=true + + vm_run $vm_no + vm_wait_for_boot 300 $vm_no + notice "Preparing partition and file on guest VM" + vm_exec $vm_no "bash -s" < $testdir/disabled_readonly_vm.sh + sleep 1 + + vm_shutdown_all + #Create readonly controller and test readonly feature + notice "Removing controller and creating new one with readonly flag" + $rpc_py vhost_delete_controller $vhost_blk_name + $rpc_py vhost_create_blk_controller -r $vhost_blk_name $disk_name + + vm_run $vm_no + vm_wait_for_boot 300 $vm_no + notice "Testing readonly feature on guest VM" + vm_exec $vm_no "bash -s" < $testdir/enabled_readonly_vm.sh + sleep 3 + + vm_shutdown_all + #Delete file from disk and delete partition + echo "INFO: Removing controller and creating new one" + $rpc_py vhost_delete_controller $vhost_blk_name + $rpc_py vhost_create_blk_controller $vhost_blk_name $disk_name + + vm_run $vm_no + vm_wait_for_boot 300 $vm_no + notice "Removing partition and file from test disk on guest VM" + vm_exec $vm_no "bash -s" < $testdir/delete_partition_vm.sh + sleep 1 + + vm_shutdown_all +} + +vhost_run 0 +if [[ -z $x ]]; then + set +x +fi + +blk_ro_tc1 + +$rpc_py bdev_nvme_detach_controller Nvme0 + +vhost_kill 0 + +vhosttestfini |