#!/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 (sq-on-mq)"
TIMED=1

requires() {
	_have_legacy_dm
}

test_disconnect_repeatedly() {
	local dev fio_status m

	use_blk_mq n 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" \
		--name=data-integrity-test-02-sq-on-mq --thread \
		--numjobs=16 --runtime="${TIMEOUT}" \
		--output="${RESULTS_DIR}/srp/fio-output-004.txt" >>"$FULL"
	fio_status=$?
	wait
	log_in
	return $fio_status
}

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