#! /bin/sh

# This test should only be run when the scsi module is loaded (or scsi
# functionality is built into the kernel).

# We test for scsi functionality by grepping in /proc/kallsyms for
# 'scsi_dispatch_cmd', which is what 'scsi.iodispatching' maps to.
# If that mapping changes this grep command will also need changing.
if ! grep scsi_dispatch_cmd /proc/kallsyms >/dev/null 2>&1 ; then
	echo "scsi funtionality not present - not running test";
	exit 0;
fi


stap $@ -p4 - << EOF
probe scsi.ioentry
{
	printf("%20s, disk_major=%d, disk_minor=%d, device_state=%s, req_addr=%p\n",
		probefunc(), disk_major, disk_minor, device_state_str, req_addr)
}

probe scsi.iodispatching
{
	printf("%20s, host_no=%d, channel=%d, lun=%d, dev_id=%d, device_state=%s, data_direction=%s, request_buffer=%p, request_bufflen=%d, req_addr=%p\n",
		probefunc(), host_no, channel, lun, dev_id, device_state_str,
		data_direction_str, request_buffer, request_bufflen, req_addr)
}

probe scsi.iodone
{
	printf("%20s, host_no=%d, channel=%d, lun=%d, dev_id=%d, device_state=%s, data_direction=%s, scsi_timer_pending=%d, req_addr=%p\n",
		probefunc(), host_no, channel, lun, dev_id, device_state_str,
		data_direction_str, scsi_timer_pending, req_addr)
}

probe scsi.iocompleted
{
	printf("%20s, host_no=%d, channel=%d, lun=%d, dev_id=%d, device_state=%s, data_direction=%s, goodbytes=%d, req_addr=%p\n",
		probefunc(), host_no, channel, lun, dev_id, device_state_str,
		data_direction_str, goodbytes, req_addr)
}

probe scsi.ioexecute
{
	printf("%20s, host_no=%d, channel=%d, lun=%d, dev_id=%d, device_state=%s, data_direction=%s, request_buffer=%p, request_bufflen=%d retries=%d, timeout=%d\n",
		probefunc(), host_no, channel, lun, dev_id, device_state_str,
		data_direction_str, request_buffer, request_bufflen, retries, timeout)
}

probe scsi.set_state
{
	printf("%20s, host_no=%d, channel=%d, lun=%d, dev_id=%d, old_state=%s, state=%s\n",
		probefunc(), host_no, channel, lun, dev_id, old_state_str, state_str)
}
EOF
