xref: /spdk/test/vhost/integrity/integrity_vm.sh (revision 962671f711e8d634c3cca152ddca5ea0c508392c)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2016 Intel Corporation
4#  All rights reserved.
5#
6set -xe
7
8wipe() {
9	wipefs --all --force "$@"
10	sync
11}
12
13cleanup() {
14	local _devs=()
15
16	((${#devs[@]} > 0)) || return 0
17
18	_devs=("${devs[@]/#//dev/}")
19
20	umount "${_devs[@]}" || :
21	wipe "${_devs[@]}" || :
22}
23
24MAKE="make -j$(($(nproc) * 2))"
25
26devs=()
27if [[ $1 == "spdk_vhost_scsi" ]]; then
28	for entry in /sys/block/sd*; do
29		if [[ $(< "$entry/device/vendor") =~ (INTEL|RAWSCSI|LIO-ORG) ]]; then
30			devs+=("${entry##*/}")
31		fi
32	done
33elif [[ $1 == "spdk_vhost_blk" ]]; then
34	devs=(/sys/block/vd*)
35fi
36
37fs=$2
38devs=("${devs[@]##*/}")
39
40trap "cleanup; exit 1" SIGINT SIGTERM EXIT
41
42for fs in $fs; do
43	for dev in "${devs[@]}"; do
44		[[ -b /dev/$dev ]]
45		wipe "/dev/$dev"
46		echo "INFO: Creating partition table on $dev disk"
47		parted "/dev/$dev" -s mklabel gpt mkpart SPDK_TEST 2048s 100%
48		sleep 1s
49		wipe "/dev/${dev}1"
50		echo "INFO: Creating filesystem on /dev/${dev}1"
51
52		if [[ $fs == ext4 ]]; then
53			"mkfs.$fs" -F "/dev/${dev}1"
54		else
55			"mkfs.$fs" -f "/dev/${dev}1"
56		fi
57
58		mkdir -p /mnt/${dev}dir
59		mount -o sync /dev/${dev}1 /mnt/${dev}dir
60
61		fio --name="integrity" --bsrange=4k-512k --iodepth=128 --numjobs=1 --direct=1 \
62			--thread=1 --group_reporting=1 --rw=randrw --rwmixread=70 \
63			--filename=/mnt/${dev}dir/test_file --verify=md5 --do_verify=1 \
64			--verify_backlog=1024 --fsync_on_close=1 --runtime=20 --time_based=1 \
65			--size=512m --verify_state_save=0
66
67		# Print out space consumed on target device
68		df -h /dev/$dev
69
70		umount /mnt/${dev}dir
71		rm -rf /mnt/${dev}dir
72		stats=($(cat /sys/block/$dev/stat))
73		echo ""
74		echo "$dev stats"
75		printf "READ  IO cnt: % 8u merges: % 8u sectors: % 8u ticks: % 8u\n" \
76			${stats[0]} ${stats[1]} ${stats[2]} ${stats[3]}
77		printf "WRITE IO cnt: % 8u merges: % 8u sectors: % 8u ticks: % 8u\n" \
78			${stats[4]} ${stats[5]} ${stats[6]} ${stats[7]}
79		printf "in flight: % 8u io ticks: % 8u time in queue: % 8u\n" \
80			${stats[8]} ${stats[9]} ${stats[10]}
81		echo ""
82	done
83done
84
85trap - SIGINT SIGTERM EXIT
86cleanup
87