#!/bin/bash
# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2016-2018 Western Digital Corporation or its affiliates

. tests/srp/rc

DESCRIPTION="File I/O on top of multipath concurrently with logout and login (mq)"
TIMED=1

test_disconnect_repeatedly() {
	local dev fio_status m

	use_blk_mq y y || return $?
	dev=$(get_bdev 0) || return $?
	m=$(mountpoint 0) || return $?
	create_filesystem "$dev" || return $?
	mount_and_check "$dev" "$m" || return $?
	# shellcheck disable=SC2064
	trap "unmount_and_check $m" RETURN
	simulate_network_failure_loop "$dev" "$TIMEOUT" &
	run_fio --verify=md5 --rw=randwrite --bs=4K --loops=$((10**6)) \
		--iodepth=64 --group_reporting --sync=1 --direct=1 \
		--ioengine=libaio --directory="$m" --runtime="${TIMEOUT}" \
		--name=data-integrity-test-mq --thread --numjobs=16 \
		--output="${RESULTS_DIR}/srp/fio-output-002.txt" \
		>>"$FULL"
	fio_status=$?
	wait
	log_in
	return $fio_status
}

test() {
	: "${TIMEOUT:=30}"
	trap 'trap "" EXIT; teardown' EXIT
	setup && test_disconnect_repeatedly && echo Passed
}
