/*
 * DF-4398 trigger workload: hammer a tws(4) unit with reads while (out of band)
 * forcing error completions (e.g. unit attention after a controller-initiated
 * reset, or a unit programmed to return CHECK CONDITION via the passthrough
 * ioctl). Every error completion runs tws_scsi_err_complete(), which touches
 * req->ccb_ptr->ccb_h.timeout_ch AFTER xpt_done(ccb) — the race window this
 * finding documents.
 *
 * Requires /dev/daX backed by a 3ware 9700-class controller (tws driver).
 */
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	const char *dev = argc > 1 ? argv[1] : "/dev/da0";
	char buf[512];
	int fd = open(dev, O_RDONLY);
	if (fd < 0) { perror("open"); return 1; }
	for (;;) {
		if (pread(fd, buf, sizeof(buf), (off_t)rand() << 12) < 0)
			perror("read");	/* error completions are the point */
	}
	return 0;
}
