| 1 |
// scsi tapset |
| 2 |
// Copyright (C) 2005, 2006, 2009 IBM Corp. |
| 3 |
// Copyright (C) 2014 Red Hat |
| 4 |
// |
| 5 |
// This file is part of systemtap, and is free software. You can |
| 6 |
// redistribute it and/or modify it under the terms of the GNU General |
| 7 |
// Public License (GPL); either version 2, or (at your option) any |
| 8 |
// later version. |
| 9 |
// <tapsetdescription> |
| 10 |
// This family of probe points is used to probe SCSI activities. |
| 11 |
// </tapsetdescription> |
| 12 |
%{ |
| 13 |
#include <linux/types.h> |
| 14 |
#include <scsi/scsi_cmnd.h> |
| 15 |
#include <scsi/scsi_device.h> |
| 16 |
#include <scsi/scsi_host.h> |
| 17 |
#include "linux/timer_compatibility.h" |
| 18 |
#include <linux/blkdev.h> |
| 19 |
%} |
| 20 |
|
| 21 |
function describe_data_direction:string(state:long) |
| 22 |
%{ /* pure */ |
| 23 |
switch ((long)STAP_ARG_state) { |
| 24 |
case DMA_BIDIRECTIONAL: strlcpy(STAP_RETVALUE, "BIDIRECTIONAL", MAXSTRINGLEN); break; |
| 25 |
case DMA_TO_DEVICE: strlcpy(STAP_RETVALUE, "TO_DEVICE", MAXSTRINGLEN); break; |
| 26 |
case DMA_FROM_DEVICE: strlcpy(STAP_RETVALUE, "FROM_DEVICE", MAXSTRINGLEN); break; |
| 27 |
case DMA_NONE: strlcpy(STAP_RETVALUE, "NONE", MAXSTRINGLEN); break; |
| 28 |
default: strlcpy(STAP_RETVALUE, "[INVALID]", MAXSTRINGLEN); |
| 29 |
} |
| 30 |
%} |
| 31 |
|
| 32 |
function describe_device_state:string(state:long) |
| 33 |
%{ /* pure */ |
| 34 |
switch ((long)STAP_ARG_state) { |
| 35 |
case SDEV_CREATED: strlcpy(STAP_RETVALUE, "CREATED", MAXSTRINGLEN); break; |
| 36 |
case SDEV_RUNNING: strlcpy(STAP_RETVALUE, "RUNNING", MAXSTRINGLEN); break; |
| 37 |
case SDEV_CANCEL: strlcpy(STAP_RETVALUE, "CANCEL", MAXSTRINGLEN); break; |
| 38 |
case SDEV_DEL: strlcpy(STAP_RETVALUE, "DEL", MAXSTRINGLEN); break; |
| 39 |
case SDEV_QUIESCE: strlcpy(STAP_RETVALUE, "QUIESCE", MAXSTRINGLEN); break; |
| 40 |
case SDEV_OFFLINE: strlcpy(STAP_RETVALUE, "OFFLINE", MAXSTRINGLEN); break; |
| 41 |
#ifdef SDEV_BLOCK |
| 42 |
case SDEV_BLOCK: strlcpy(STAP_RETVALUE, "BLOCK", MAXSTRINGLEN); break; |
| 43 |
#endif |
| 44 |
#ifdef SDEV_CREATED_BLOCK |
| 45 |
case SDEV_CREATED_BLOCK: strlcpy(STAP_RETVALUE, "CREATED_BLOCK", MAXSTRINGLEN); break; |
| 46 |
#endif |
| 47 |
default: strlcpy(STAP_RETVALUE, "[INVALID]", MAXSTRINGLEN); |
| 48 |
} |
| 49 |
%} |
| 50 |
|
| 51 |
@__private30 function scsi_cmd_to_rq:long(cmd:long) |
| 52 |
%{ |
| 53 |
struct scsi_cmnd *scmd = (struct scsi_cmnd *) STAP_ARG_cmd; |
| 54 |
STAP_RETVALUE = (int64_t) scsi_cmd_to_rq(scmd); |
| 55 |
%} |
| 56 |
|
| 57 |
function get_scsi_request:long(scsi_cmd:long) |
| 58 |
{ |
| 59 |
if (@defined(@cast(scsi_cmd, "struct_cmnd", "kernel:scsi_mod")->request)) { |
| 60 |
return @cast(scsi_cmd, "struct_cmnd *", "kernel:scsi_mod")->request |
| 61 |
}else { |
| 62 |
return scsi_cmd_to_rq(scsi_cmd) |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* probe scsi.ioentry - Prepares a SCSI mid-layer request |
| 68 |
* @disk_major: The major number of the disk (-1 if no information) |
| 69 |
* @disk_minor: The minor number of the disk (-1 if no information) |
| 70 |
* @device_state: The current state of the device |
| 71 |
* @device_state_str: The current state of the device, as a string |
| 72 |
* @req_addr: The current struct request pointer, as a number |
| 73 |
*/ |
| 74 |
probe scsi.ioentry.scsilib = |
| 75 |
module("scsi_mod").function("scsi_prep_fn")!, kernel.function("scsi_prep_fn")? { } |
| 76 |
probe scsi.ioentry.sd = |
| 77 |
module("sd_mod").function("sd_prep_fn")!, kernel.function("sd_prep_fn")? { } |
| 78 |
probe scsi.ioentry.sr = |
| 79 |
module("sr_mod").function("sr_prep_fn")!, kernel.function("sr_prep_fn")? { } |
| 80 |
|
| 81 |
probe scsi.ioentry = scsi.ioentry.* ? |
| 82 |
{ |
| 83 |
req_addr = @choose_defined($req, $rq); |
| 84 |
if(@cast(req_addr,"request")->rq_disk == 0) { |
| 85 |
disk_major = -1 |
| 86 |
disk_minor = -1 |
| 87 |
} else { |
| 88 |
disk_major = @cast(req_addr,"request")->rq_disk->major |
| 89 |
disk_minor = @cast(req_addr,"request")->rq_disk->first_minor |
| 90 |
} |
| 91 |
device_state = get_devstate_from_req($q) |
| 92 |
device_state_str = describe_device_state(device_state) |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* probe scsi.iodispatching - SCSI mid-layer dispatched low-level SCSI command |
| 97 |
* @host_no: The host number |
| 98 |
* @channel: The channel number |
| 99 |
* @lun: The lun number |
| 100 |
* @dev_id: The scsi device id |
| 101 |
* @device_state: The current state of the device |
| 102 |
* @device_state_str: The current state of the device, as a string |
| 103 |
* @data_direction: The data_direction specifies whether this command is from/to the device |
| 104 |
* 0 (DMA_BIDIRECTIONAL), 1 (DMA_TO_DEVICE), |
| 105 |
* 2 (DMA_FROM_DEVICE), 3 (DMA_NONE) |
| 106 |
* @data_direction_str: Data direction, as a string |
| 107 |
* @request_buffer: The request buffer address |
| 108 |
* @request_bufflen: The request buffer length |
| 109 |
* @req_addr: The current struct request pointer, as a number |
| 110 |
*/ |
| 111 |
probe scsi.iodispatching |
| 112 |
= module("scsi_mod").function("scsi_dispatch_cmd")!, |
| 113 |
kernel.function("scsi_dispatch_cmd")? |
| 114 |
{ |
| 115 |
host_no = $cmd->device->host->host_no |
| 116 |
channel = $cmd->device->channel |
| 117 |
lun = $cmd->device->lun |
| 118 |
dev_id = $cmd->device->id |
| 119 |
device_state = $cmd->device->sdev_state |
| 120 |
device_state_str = describe_device_state(device_state) |
| 121 |
data_direction = $cmd->sc_data_direction |
| 122 |
data_direction_str = describe_data_direction(data_direction) |
| 123 |
request_buffer = @choose_defined($cmd->sdb->table->sgl, |
| 124 |
$cmd->request_buffer) |
| 125 |
request_bufflen = @choose_defined($cmd->sdb->length, |
| 126 |
$cmd->request_bufflen) |
| 127 |
req_addr = get_scsi_request($cmd) |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* probe scsi.iodone - SCSI command completed by low level driver and enqueued into the done queue. |
| 132 |
* @host_no: The host number |
| 133 |
* @channel: The channel number |
| 134 |
* @lun: The lun number |
| 135 |
* @dev_id: The scsi device id |
| 136 |
* @device_state: The current state of the device |
| 137 |
* @device_state_str: The current state of the device, as a string |
| 138 |
* @data_direction: The data_direction specifies whether this command is |
| 139 |
* from/to the device. |
| 140 |
* @data_direction_str: Data direction, as a string |
| 141 |
* @req_addr: The current struct request pointer, as a number |
| 142 |
* @scsi_timer_pending: 1 if a timer is pending on this request |
| 143 |
*/ |
| 144 |
probe scsi.iodone |
| 145 |
= kernel.trace("scsi_dispatch_cmd_done")!, |
| 146 |
module("scsi_mod").function("scsi_done")!, |
| 147 |
kernel.function("scsi_done")? |
| 148 |
|
| 149 |
{ |
| 150 |
# Why is the @cast() needed here? When the probe alias uses |
| 151 |
# the "scsi_dispatch_cmd_done" tracepoint, the type info isn't |
| 152 |
# in scope. |
| 153 |
host_no = @cast($cmd->device, "scsi_device", "kernel:scsi_mod")->host->host_no |
| 154 |
channel = @cast($cmd->device, "scsi_device", "kernel:scsi_mod")->channel |
| 155 |
lun = @cast($cmd->device, "scsi_device", "kernel:scsi_mod")->lun |
| 156 |
dev_id = @cast($cmd->device, "scsi_device", "kernel:scsi_mod")->id |
| 157 |
device_state = @cast($cmd->device, "scsi_device", "kernel:scsi_mod")->sdev_state |
| 158 |
device_state_str = describe_device_state(device_state) |
| 159 |
data_direction = $cmd->sc_data_direction |
| 160 |
data_direction_str = describe_data_direction(data_direction) |
| 161 |
req_addr = get_scsi_request($cmd) |
| 162 |
scsi_timer_pending = scsi_timer_pending($cmd); |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* probe scsi.iocompleted - SCSI mid-layer running the completion processing for block device I/O requests |
| 167 |
* @host_no: The host number |
| 168 |
* @channel: The channel number |
| 169 |
* @lun: The lun number |
| 170 |
* @dev_id: The scsi device id |
| 171 |
* @device_state: The current state of the device |
| 172 |
* @device_state_str: The current state of the device, as a string |
| 173 |
* @data_direction: The data_direction specifies whether this command is from/to |
| 174 |
* the device |
| 175 |
* @data_direction_str: Data direction, as a string |
| 176 |
* @goodbytes: The bytes completed |
| 177 |
* @req_addr: The current struct request pointer, as a number |
| 178 |
*/ |
| 179 |
// mid-layer processes the completed IO |
| 180 |
probe scsi.iocompleted |
| 181 |
= module("scsi_mod").function("scsi_io_completion")!, |
| 182 |
kernel.function("scsi_io_completion")? |
| 183 |
{ |
| 184 |
host_no = $cmd->device->host->host_no |
| 185 |
channel = $cmd->device->channel |
| 186 |
lun = $cmd->device->lun |
| 187 |
dev_id = $cmd->device->id |
| 188 |
device_state = $cmd->device->sdev_state |
| 189 |
device_state_str = describe_device_state(device_state) |
| 190 |
data_direction = $cmd->sc_data_direction |
| 191 |
data_direction_str = describe_data_direction(data_direction) |
| 192 |
req_addr = get_scsi_request($cmd) |
| 193 |
goodbytes = $good_bytes |
| 194 |
} |
| 195 |
|
| 196 |
function timer_pending:long(timer:long) |
| 197 |
{ |
| 198 |
return (@choose_defined(@cast(timer, "timer_list", "kernel")->entry->next, |
| 199 |
@cast(timer, "timer_list", "kernel")->base) != 0) |
| 200 |
} |
| 201 |
|
| 202 |
@__private30 function cmd_request_timer_pending:long(cmd:long) |
| 203 |
{ |
| 204 |
request = get_scsi_request(&@cast(cmd, "scsi_cmnd", "kernel")) |
| 205 |
return timer_pending(&@cast(request, "request", "kernel")->q->timeout) |
| 206 |
} |
| 207 |
|
| 208 |
function scsi_timer_pending:long(cmd:long) |
| 209 |
{ |
| 210 |
%( kernel_v >= "2.6.28" %? |
| 211 |
return cmd_request_timer_pending(cmd) |
| 212 |
%: |
| 213 |
return timer_pending(&@cast(cmd, "scsi_cmnd", "kernel:scsi_mod")->eh_timeout) |
| 214 |
%) |
| 215 |
} |
| 216 |
|
| 217 |
function get_devstate_from_req:long(var:long) |
| 218 |
{ |
| 219 |
sdev = @cast(var, "request_queue", "kernel:scsi_mod")->queuedata |
| 220 |
return @cast(sdev, "scsi_device", "kernel:scsi_mod")->sdev_state |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* probe scsi.ioexecute - Create mid-layer SCSI request and wait for the result |
| 225 |
* @host_no: The host number |
| 226 |
* @channel: The channel number |
| 227 |
* @lun: The lun number |
| 228 |
* @dev_id: The scsi device id |
| 229 |
* @device_state: The current state of the device |
| 230 |
* @device_state_str: The current state of the device, as a string |
| 231 |
* @data_direction: The data_direction specifies whether this command is |
| 232 |
* from/to the device. |
| 233 |
* @data_direction_str: Data direction, as a string |
| 234 |
* @request_buffer: The data buffer address |
| 235 |
* @request_bufflen: The data buffer buffer length |
| 236 |
* @timeout: Request timeout in seconds |
| 237 |
* @retries: Number of times to retry request |
| 238 |
*/ |
| 239 |
probe scsi.ioexecute |
| 240 |
= module("scsi_mod").function("scsi_execute")!, |
| 241 |
kernel.function("scsi_execute")? |
| 242 |
{ |
| 243 |
host_no = $sdev->host->host_no |
| 244 |
channel = $sdev->channel |
| 245 |
lun = $sdev->lun |
| 246 |
dev_id = $sdev->id |
| 247 |
device_state = $sdev->sdev_state |
| 248 |
device_state_str = describe_device_state(device_state) |
| 249 |
data_direction = $data_direction |
| 250 |
data_direction_str = describe_data_direction(data_direction) |
| 251 |
request_buffer = $buffer |
| 252 |
request_bufflen = $bufflen |
| 253 |
timeout = $timeout |
| 254 |
retries = $retries |
| 255 |
} |
| 256 |
|
| 257 |
/** |
| 258 |
* probe scsi.set_state - Order SCSI device state change |
| 259 |
* @host_no: The host number |
| 260 |
* @channel: The channel number |
| 261 |
* @lun: The lun number |
| 262 |
* @dev_id: The scsi device id |
| 263 |
* @old_state: The current state of the device |
| 264 |
* @old_state_str: The current state of the device, as a string |
| 265 |
* @state: The new state of the device |
| 266 |
* @state_str: The new state of the device, as a string |
| 267 |
*/ |
| 268 |
probe scsi.set_state |
| 269 |
= module("scsi_mod").function("scsi_device_set_state")!, |
| 270 |
kernel.function("scsi_device_set_state")? |
| 271 |
{ |
| 272 |
state = $state |
| 273 |
state_str = describe_device_state(state) |
| 274 |
|
| 275 |
host_no = $sdev->host->host_no |
| 276 |
channel = $sdev->channel |
| 277 |
lun = $sdev->lun |
| 278 |
dev_id = $sdev->id |
| 279 |
old_state = $sdev->sdev_state |
| 280 |
old_state_str = describe_device_state(old_state) |
| 281 |
} |