summaryrefslogtreecommitdiffstats
path: root/src/spdk/test/vhost/readonly
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/spdk/test/vhost/readonly
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/spdk/test/vhost/readonly')
-rwxr-xr-xsrc/spdk/test/vhost/readonly/delete_partition_vm.sh42
-rwxr-xr-xsrc/spdk/test/vhost/readonly/disabled_readonly_vm.sh47
-rwxr-xr-xsrc/spdk/test/vhost/readonly/enabled_readonly_vm.sh76
-rwxr-xr-xsrc/spdk/test/vhost/readonly/readonly.sh132
-rw-r--r--src/spdk/test/vhost/readonly/test_plan.md30
5 files changed, 327 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 00000000..18230896
--- /dev/null
+++ b/src/spdk/test/vhost/readonly/delete_partition_vm.sh
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+
+set -xe
+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
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 00000000..bd202433
--- /dev/null
+++ b/src/spdk/test/vhost/readonly/disabled_readonly_vm.sh
@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+
+set -xe
+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"
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 00000000..79cf1ae5
--- /dev/null
+++ b/src/spdk/test/vhost/readonly/enabled_readonly_vm.sh
@@ -0,0 +1,76 @@
+#!/usr/bin/env bash
+
+set -x
+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
diff --git a/src/spdk/test/vhost/readonly/readonly.sh b/src/spdk/test/vhost/readonly/readonly.sh
new file mode 100755
index 00000000..d0b7968f
--- /dev/null
+++ b/src/spdk/test/vhost/readonly/readonly.sh
@@ -0,0 +1,132 @@
+#!/usr/bin/env bash
+
+set -e
+READONLY_BASE_DIR=$(readlink -f $(dirname $0))
+[[ -z "$TEST_DIR" ]] && TEST_DIR="$(cd $READONLY_BASE_DIR/../../../../ && pwd)"
+[[ -z "$COMMON_DIR" ]] && COMMON_DIR="$(cd $READONLY_BASE_DIR/../common && pwd)"
+source $COMMON_DIR/common.sh
+
+rpc_py="$READONLY_BASE_DIR/../../../scripts/rpc.py -s $(get_vhost_dir)/rpc.sock"
+
+vm_img=""
+disk="Nvme0n1"
+x=""
+
+function usage()
+{
+ [[ ! -z $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
+
+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="$TEST_DIR/vms/$vm_no"
+
+ if [[ $disk =~ .*malloc.* ]]; then
+ disk_name=$($rpc_py construct_malloc_bdev 512 4096)
+ if [ $? != 0 ]; then
+ fail "Failed to create malloc bdev"
+ fi
+
+ disk=$disk_name
+ else
+ disk_name=${disk%%_*}
+ if ! $rpc_py 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 construct_vhost_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 600 $vm_no
+ notice "Preparing partition and file on guest VM"
+ vm_ssh $vm_no "bash -s" < $READONLY_BASE_DIR/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 remove_vhost_controller $vhost_blk_name
+ $rpc_py construct_vhost_blk_controller -r $vhost_blk_name $disk_name
+
+ vm_run $vm_no
+ vm_wait_for_boot 600 $vm_no
+ notice "Testing readonly feature on guest VM"
+ vm_ssh $vm_no "bash -s" < $READONLY_BASE_DIR/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 remove_vhost_controller $vhost_blk_name
+ $rpc_py construct_vhost_blk_controller $vhost_blk_name $disk_name
+
+ vm_run $vm_no
+ vm_wait_for_boot 600 $vm_no
+ notice "Removing partition and file from test disk on guest VM"
+ vm_ssh $vm_no "bash -s" < $READONLY_BASE_DIR/delete_partition_vm.sh
+ sleep 1
+
+ vm_shutdown_all
+}
+
+spdk_vhost_run
+if [[ -z $x ]]; then
+ set +x
+fi
+
+blk_ro_tc1
+
+$rpc_py delete_nvme_controller Nvme0
+
+spdk_vhost_kill
diff --git a/src/spdk/test/vhost/readonly/test_plan.md b/src/spdk/test/vhost/readonly/test_plan.md
new file mode 100644
index 00000000..957000e8
--- /dev/null
+++ b/src/spdk/test/vhost/readonly/test_plan.md
@@ -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