#!/bin/bash
# SPDX-License-Identifier: GPL-2.0+
# Copyright 2019 Google LLC

. tests/srp/rc

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

requires() {
	# See also iproute commit 4336c5821a7b ("rdma: add 'link add/delete'
	# commands").
	_have_module siw && _have_kver 5 5 && _have_iproute2 190404
}

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-015.txt" \
		>>"$FULL"
	fio_status=$?
	wait
	log_in
	return $fio_status
}

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