| 1 |
// Block I/O tapset |
| 2 |
// Copyright (C) 2006 Intel Corp. |
| 3 |
// Copyright (C) 2006 IBM Corp. |
| 4 |
// Copyright (C) 2014-2017 Red Hat Inc. |
| 5 |
// |
| 6 |
// This file is part of systemtap, and is free software. You can |
| 7 |
// redistribute it and/or modify it under the terms of the GNU General |
| 8 |
// Public License (GPL); either version 2, or (at your option) any |
| 9 |
// later version. |
| 10 |
|
| 11 |
%{ |
| 12 |
#include <linux/bio.h> |
| 13 |
#ifdef STAPCONF_GENHD_H |
| 14 |
#include <linux/genhd.h> |
| 15 |
#else |
| 16 |
#include <linux/blkdev.h> |
| 17 |
#endif |
| 18 |
#ifdef STAPCONF_BLK_TYPES |
| 19 |
#include <linux/blk_types.h> |
| 20 |
#endif |
| 21 |
%} |
| 22 |
|
| 23 |
private function disk_get_part_start_sect:long(disk:long, partno:long) |
| 24 |
%{ /* pure */ /* unprivileged */ |
| 25 |
#if defined(STAPCONF_DISK_GET_PART) |
| 26 |
struct gendisk *disk = (struct gendisk *)(uintptr_t)STAP_ARG_disk; |
| 27 |
int partno = (int)STAP_ARG_partno; |
| 28 |
struct hd_struct *part; |
| 29 |
|
| 30 |
STAP_RETVALUE = 0; |
| 31 |
if (disk) { |
| 32 |
/* Before calling disk_get_part() on 'disk', we need to make |
| 33 |
* sure the memory is readable. */ |
| 34 |
(void)kread(&(disk->part_tbl)); |
| 35 |
part = disk_get_part(disk, partno); |
| 36 |
|
| 37 |
if (part) { |
| 38 |
/* Let's be doubly paranoid and make sure this memory is |
| 39 |
* safe for reading. */ |
| 40 |
(void)kread(&(part->start_sect)); |
| 41 |
STAP_RETVALUE = part->start_sect; |
| 42 |
disk_put_part(part); |
| 43 |
} |
| 44 |
} |
| 45 |
CATCH_DEREF_FAULT(); |
| 46 |
#endif |
| 47 |
%} |
| 48 |
|
| 49 |
/* Returns the REQ_OP_* bits for a bio structure. */ |
| 50 |
function bio_op:long(bio:long) |
| 51 |
%{ /* pure */ /* unprivileged */ |
| 52 |
#if defined(STAPCONF_BIO_BI_OPF) |
| 53 |
struct bio *bio = (struct bio *)(uintptr_t)STAP_ARG_bio; |
| 54 |
|
| 55 |
STAP_RETVALUE = 0; |
| 56 |
if (bio) { |
| 57 |
/* Before calling bio_op() on bio, we need to make sure the |
| 58 |
* memory is readable. */ |
| 59 |
(void)kread(&(bio->bi_opf)); |
| 60 |
STAP_RETVALUE = bio_op(bio); |
| 61 |
} |
| 62 |
#else |
| 63 |
struct bio *bio = (struct bio *)(uintptr_t)STAP_ARG_bio; |
| 64 |
|
| 65 |
STAP_RETVALUE = 0; |
| 66 |
if (bio) { |
| 67 |
STAP_RETVALUE = kread(&(bio->bi_rw)); |
| 68 |
} |
| 69 |
#endif |
| 70 |
CATCH_DEREF_FAULT(); |
| 71 |
%} |
| 72 |
|
| 73 |
/* get i-node number of mapped file */ |
| 74 |
@__private30 function __bio_ino:long(bio:long) |
| 75 |
%{ /* pure */ |
| 76 |
struct bio *bio = (struct bio *)(uintptr_t)STAP_ARG_bio; |
| 77 |
struct page *bv_page = ((bio && kread(&(bio->bi_vcnt))) |
| 78 |
? kread(&(bio->bi_io_vec[0].bv_page)) : NULL); |
| 79 |
|
| 80 |
STAP_RETVALUE = -1; |
| 81 |
if (bv_page) { |
| 82 |
/* Before calling PageSlab() and PageSwapCache() on bv_page, we |
| 83 |
* need to make sure the bv_page struct is valid. */ |
| 84 |
(void)kderef_buffer(NULL, bv_page, sizeof(struct page)); |
| 85 |
|
| 86 |
if (!PageSlab(bv_page) && !PageSwapCache(bv_page)) { |
| 87 |
struct address_space *mapping = kread(&(bv_page->mapping)); |
| 88 |
if (mapping && ((unsigned long)mapping & PAGE_MAPPING_ANON) == 0) { |
| 89 |
struct inode *host = kread(&(mapping->host)); |
| 90 |
if (host) |
| 91 |
STAP_RETVALUE = kread(&(host->i_ino)); |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
CATCH_DEREF_FAULT(); |
| 96 |
%} |
| 97 |
|
| 98 |
/* returns 0 for read, 1 for write */ |
| 99 |
function bio_rw_num:long(rw:long) |
| 100 |
{ |
| 101 |
return (rw & BIO_WRITE) |
| 102 |
} |
| 103 |
|
| 104 |
/* returns R for read, W for write */ |
| 105 |
function bio_rw_str(rw:long) |
| 106 |
{ |
| 107 |
return bio_rw_num(rw) == BIO_READ ? "R" : "W" |
| 108 |
} |
| 109 |
|
| 110 |
/* returns start sector */ |
| 111 |
@__private30 function __bio_start_sect:long(bio:long) |
| 112 |
{ |
| 113 |
try { |
| 114 |
if (@defined(@cast(bio, "bio", "kernel")->bi_dev)) { |
| 115 |
return @cast(bio, "bio", "kernel")->bi_bdev->bd_part->start_sect |
| 116 |
} |
| 117 |
else if (@defined(@cast(bio, "bio", "kernel")->bi_disk)) { |
| 118 |
return disk_get_part_start_sect(@cast(bio, "bio", "kernel")->bi_disk, |
| 119 |
@cast(bio, "bio", "kernel")->bi_partno) |
| 120 |
} |
| 121 |
} catch { |
| 122 |
return -1 |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
/* returns the block device name */ |
| 127 |
@__private30 function __bio_devname:string(bio:long) |
| 128 |
{ |
| 129 |
if (@defined(@cast(bio, "bio", "kernel")->bi_bdev)) { |
| 130 |
return bdevname(@cast(bio, "bio", "kernel")->bi_bdev) |
| 131 |
} |
| 132 |
else { |
| 133 |
return disk_name(@cast(bio, "bio", "kernel")->bi_disk, |
| 134 |
@cast(bio, "bio", "kernel")->bi_partno) |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
global BIO_READ = 0, BIO_WRITE = 1 |
| 139 |
|
| 140 |
|
| 141 |
/** |
| 142 |
* probe ioblock.request - Fires whenever making a generic block I/O request. |
| 143 |
* @name : name of the probe point |
| 144 |
* @devname : block device name |
| 145 |
* @ino : i-node number of the mapped file |
| 146 |
* @sector : beginning sector for the entire bio |
| 147 |
* @flags : see below |
| 148 |
* BIO_UPTODATE 0 ok after I/O completion |
| 149 |
* BIO_RW_BLOCK 1 RW_AHEAD set, and read/write would block |
| 150 |
* BIO_EOF 2 out-out-bounds error |
| 151 |
* BIO_SEG_VALID 3 nr_hw_seg valid |
| 152 |
* BIO_CLONED 4 doesn't own data |
| 153 |
* BIO_BOUNCED 5 bio is a bounce bio |
| 154 |
* BIO_USER_MAPPED 6 contains user pages |
| 155 |
* BIO_EOPNOTSUPP 7 not supported |
| 156 |
* @rw : binary trace for read/write request |
| 157 |
* @opf : operations and flags |
| 158 |
* @vcnt : bio vector count which represents number of array element (page, offset, length) which make up this I/O request |
| 159 |
* @idx : offset into the bio vector array |
| 160 |
* @phys_segments : number of segments in this bio after physical address coalescing is performed |
| 161 |
* @hw_segments : number of segments after physical and DMA remapping hardware coalescing is performed |
| 162 |
* @size : total size in bytes |
| 163 |
* @bdev : target block device |
| 164 |
* @bdev_contains : points to the device object which contains the partition (when bio structure represents a partition) |
| 165 |
* @p_start_sect : points to the start sector of the partition structure of the device |
| 166 |
* |
| 167 |
* Context: |
| 168 |
* The process makes block I/O request |
| 169 |
*/ |
| 170 |
probe ioblock.request = kernel.function ("submit_bio_noacct")!, |
| 171 |
kernel.function ("generic_make_request") |
| 172 |
{ |
| 173 |
name = "ioblock.request" |
| 174 |
devname = __bio_devname($bio) |
| 175 |
ino = __bio_ino($bio) |
| 176 |
|
| 177 |
sector = @choose_defined($bio->bi_iter->bi_sector, $bio->bi_sector) |
| 178 |
flags = $bio->bi_flags |
| 179 |
if (@defined($bio->bi_opf)) { |
| 180 |
rw = bio_op($bio) |
| 181 |
opf = $bio->bi_opf |
| 182 |
} |
| 183 |
else { |
| 184 |
rw = $bio->bi_rw |
| 185 |
opf = $bio->bi_rw |
| 186 |
} |
| 187 |
vcnt = $bio->bi_vcnt |
| 188 |
idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx) |
| 189 |
/* use bi_vcnt as a proxy as it is close enough */ |
| 190 |
phys_segments = @choose_defined($bio->bi_phys_segments, $bio->bi_vcnt) |
| 191 |
hw_segments = @choose_defined($bio->bi_hw_segments, 0) |
| 192 |
size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
| 193 |
|
| 194 |
bdev = @choose_defined($bio->bi_bdev, 0) |
| 195 |
bdev_contains = @choose_defined($bio->bi_bdev->bd_contains, 0) |
| 196 |
p_start_sect = __bio_start_sect($bio) |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
* probe ioblock.end - Fires whenever a block I/O transfer is complete. |
| 201 |
* @name : name of the probe point |
| 202 |
* @devname : block device name |
| 203 |
* @ino : i-node number of the mapped file |
| 204 |
* @bytes_done : number of bytes transferred |
| 205 |
* @sector : beginning sector for the entire bio |
| 206 |
* @flags : see below |
| 207 |
* BIO_UPTODATE 0 ok after I/O completion |
| 208 |
* BIO_RW_BLOCK 1 RW_AHEAD set, and read/write would block |
| 209 |
* BIO_EOF 2 out-out-bounds error |
| 210 |
* BIO_SEG_VALID 3 nr_hw_seg valid |
| 211 |
* BIO_CLONED 4 doesn't own data |
| 212 |
* BIO_BOUNCED 5 bio is a bounce bio |
| 213 |
* BIO_USER_MAPPED 6 contains user pages |
| 214 |
* BIO_EOPNOTSUPP 7 not supported |
| 215 |
* @error : 0 on success |
| 216 |
* @rw : binary trace for read/write request |
| 217 |
* @opf : operations and flags |
| 218 |
* @vcnt : bio vector count which represents number of array element (page, offset, length) which makes up this I/O request |
| 219 |
* @idx : offset into the bio vector array |
| 220 |
* @phys_segments : number of segments in this bio after physical address coalescing is performed. |
| 221 |
* @hw_segments : number of segments after physical and DMA remapping hardware coalescing is performed |
| 222 |
* @size : total size in bytes |
| 223 |
* |
| 224 |
* Context: |
| 225 |
* The process signals the transfer is done. |
| 226 |
*/ |
| 227 |
probe ioblock.end = kernel.function("bio_endio") |
| 228 |
{ |
| 229 |
name = "ioblock.end" |
| 230 |
devname = __bio_devname($bio) |
| 231 |
ino = __bio_ino($bio) |
| 232 |
|
| 233 |
bytes_done = @choose_defined($bytes_done, |
| 234 |
@choose_defined($bio->bi_iter->bi_size, |
| 235 |
$bio->bi_size)) |
| 236 |
error = @choose_defined($error, @choose_defined($bio->bi_error, |
| 237 |
$bio->bi_status)) |
| 238 |
|
| 239 |
sector = @choose_defined($bio->bi_iter->bi_sector, $bio->bi_sector) |
| 240 |
flags = $bio->bi_flags |
| 241 |
if (@defined($bio->bi_opf)) { |
| 242 |
rw = bio_op($bio) |
| 243 |
opf = $bio->bi_opf |
| 244 |
} |
| 245 |
else { |
| 246 |
rw = $bio->bi_rw |
| 247 |
opf = $bio->bi_rw |
| 248 |
} |
| 249 |
vcnt = $bio->bi_vcnt |
| 250 |
idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx) |
| 251 |
/* use bi_vcnt as a proxy as it is close enough */ |
| 252 |
phys_segments = @choose_defined($bio->bi_phys_segments, $bio->bi_vcnt) |
| 253 |
hw_segments = @choose_defined($bio->bi_hw_segments, 0) |
| 254 |
size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
| 255 |
} |
| 256 |
|
| 257 |
/** |
| 258 |
* probe ioblock_trace.bounce - Fires whenever a buffer bounce is needed for at least one page of a block IO request. |
| 259 |
* @name : name of the probe point |
| 260 |
* @q : request queue on which this bio was queued. |
| 261 |
* @devname : device for which a buffer bounce was needed. |
| 262 |
* @ino : i-node number of the mapped file |
| 263 |
* @bytes_done : number of bytes transferred |
| 264 |
* @sector : beginning sector for the entire bio |
| 265 |
* @flags : see below |
| 266 |
* BIO_UPTODATE 0 ok after I/O completion |
| 267 |
* BIO_RW_BLOCK 1 RW_AHEAD set, and read/write would block |
| 268 |
* BIO_EOF 2 out-out-bounds error |
| 269 |
* BIO_SEG_VALID 3 nr_hw_seg valid |
| 270 |
* BIO_CLONED 4 doesn't own data |
| 271 |
* BIO_BOUNCED 5 bio is a bounce bio |
| 272 |
* BIO_USER_MAPPED 6 contains user pages |
| 273 |
* BIO_EOPNOTSUPP 7 not supported |
| 274 |
* @rw : binary trace for read/write request |
| 275 |
* @opf : operations and flags |
| 276 |
* @vcnt : bio vector count which represents number of array element (page, offset, length) which makes up this I/O request |
| 277 |
* @idx : offset into the bio vector array |
| 278 |
* @phys_segments - number of segments in this bio after physical address coalescing is performed. |
| 279 |
* @size : total size in bytes |
| 280 |
* @bdev : target block device |
| 281 |
* @bdev_contains : points to the device object which contains the partition (when bio structure represents a partition) |
| 282 |
* @p_start_sect : points to the start sector of the partition structure of the device |
| 283 |
* |
| 284 |
* Context : |
| 285 |
* The process creating a block IO request. |
| 286 |
*/ |
| 287 |
probe ioblock_trace.bounce = kernel.trace("block_bio_bounce") |
| 288 |
{ |
| 289 |
name = "ioblock_trace.bounce" |
| 290 |
q = @choose_defined($q, $bio->bi_bdev->bd_queue) |
| 291 |
devname = __bio_devname($bio) |
| 292 |
ino = __bio_ino($bio) |
| 293 |
|
| 294 |
bytes_done = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
| 295 |
sector = @choose_defined($bio->bi_iter->bi_sector, $bio->bi_sector) |
| 296 |
flags = $bio->bi_flags |
| 297 |
if (@defined($bio->bi_opf)) { |
| 298 |
rw = bio_op($bio) |
| 299 |
opf = $bio->bi_opf |
| 300 |
} |
| 301 |
else { |
| 302 |
rw = $bio->bi_rw |
| 303 |
opf = $bio->bi_rw |
| 304 |
} |
| 305 |
vcnt = $bio->bi_vcnt |
| 306 |
idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx) |
| 307 |
/* use bi_vcnt as a proxy as it is close enough */ |
| 308 |
phys_segments = @choose_defined($bio->bi_phys_segments, $bio->bi_vcnt) |
| 309 |
size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
| 310 |
bdev_contains = @choose_defined($bio->bi_bdev->bd_contains, 0) |
| 311 |
bdev = @choose_defined($bio->bi_bdev, 0) |
| 312 |
p_start_sect = __bio_start_sect($bio) |
| 313 |
} |
| 314 |
|
| 315 |
/** |
| 316 |
* probe ioblock_trace.request - Fires just as a generic block I/O request is created for a bio. |
| 317 |
* @name : name of the probe point |
| 318 |
* @q : request queue on which this bio was queued. |
| 319 |
* @devname : block device name |
| 320 |
* @ino : i-node number of the mapped file |
| 321 |
* @bytes_done : number of bytes transferred |
| 322 |
* @sector : beginning sector for the entire bio |
| 323 |
* @flags : see below |
| 324 |
* BIO_UPTODATE 0 ok after I/O completion |
| 325 |
* BIO_RW_BLOCK 1 RW_AHEAD set, and read/write would block |
| 326 |
* BIO_EOF 2 out-out-bounds error |
| 327 |
* BIO_SEG_VALID 3 nr_hw_seg valid |
| 328 |
* BIO_CLONED 4 doesn't own data |
| 329 |
* BIO_BOUNCED 5 bio is a bounce bio |
| 330 |
* BIO_USER_MAPPED 6 contains user pages |
| 331 |
* BIO_EOPNOTSUPP 7 not supported |
| 332 |
* @rw : binary trace for read/write request |
| 333 |
* @opf : operations and flags |
| 334 |
* @vcnt : bio vector count which represents number of array element (page, offset, length) which make up this I/O request |
| 335 |
* @idx : offset into the bio vector array |
| 336 |
* @phys_segments - number of segments in this bio after physical address coalescing is performed. |
| 337 |
* @size : total size in bytes |
| 338 |
* @bdev : target block device |
| 339 |
* @bdev_contains : points to the device object which contains the partition (when bio structure represents a partition) |
| 340 |
* @p_start_sect : points to the start sector of the partition structure of the device |
| 341 |
* |
| 342 |
* Context: |
| 343 |
* The process makes block I/O request |
| 344 |
*/ |
| 345 |
probe ioblock_trace.request = kernel.trace("block_bio_queue") |
| 346 |
{ |
| 347 |
name = "ioblock_trace.request" |
| 348 |
q = @choose_defined($q, $bio->bi_bdev->bd_queue) |
| 349 |
devname = __bio_devname($bio) |
| 350 |
ino = __bio_ino($bio) |
| 351 |
|
| 352 |
bytes_done = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
| 353 |
sector = @choose_defined($bio->bi_iter->bi_sector, $bio->bi_sector) |
| 354 |
flags = $bio->bi_flags |
| 355 |
if (@defined($bio->bi_opf)) { |
| 356 |
rw = bio_op($bio) |
| 357 |
opf = $bio->bi_opf |
| 358 |
} |
| 359 |
else { |
| 360 |
rw = $bio->bi_rw |
| 361 |
opf = $bio->bi_rw |
| 362 |
} |
| 363 |
vcnt = $bio->bi_vcnt |
| 364 |
idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx) |
| 365 |
/* use bi_vcnt as a proxy as it is close enough */ |
| 366 |
phys_segments = @choose_defined($bio->bi_phys_segments, $bio->bi_vcnt) |
| 367 |
size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
| 368 |
bdev_contains = @choose_defined($bio->bi_bdev->bd_contains, 0) |
| 369 |
bdev = @choose_defined($bio->bi_bdev, 0) |
| 370 |
p_start_sect = __bio_start_sect($bio) |
| 371 |
} |
| 372 |
|
| 373 |
/** |
| 374 |
* probe ioblock_trace.end - Fires whenever a block I/O transfer is complete. |
| 375 |
* @name : name of the probe point |
| 376 |
* @q : request queue on which this bio was queued. |
| 377 |
* @devname : block device name |
| 378 |
* @ino : i-node number of the mapped file |
| 379 |
* @bytes_done : number of bytes transferred |
| 380 |
* @sector : beginning sector for the entire bio |
| 381 |
* @flags : see below |
| 382 |
* BIO_UPTODATE 0 ok after I/O completion |
| 383 |
* BIO_RW_BLOCK 1 RW_AHEAD set, and read/write would block |
| 384 |
* BIO_EOF 2 out-out-bounds error |
| 385 |
* BIO_SEG_VALID 3 nr_hw_seg valid |
| 386 |
* BIO_CLONED 4 doesn't own data |
| 387 |
* BIO_BOUNCED 5 bio is a bounce bio |
| 388 |
* BIO_USER_MAPPED 6 contains user pages |
| 389 |
* BIO_EOPNOTSUPP 7 not supported |
| 390 |
* @rw : binary trace for read/write request |
| 391 |
* @opf : operations and flags |
| 392 |
* @vcnt : bio vector count which represents number of array element (page, offset, length) which makes up this I/O request |
| 393 |
* @idx : offset into the bio vector array |
| 394 |
* @phys_segments - number of segments in this bio after physical address coalescing is performed. |
| 395 |
* @size : total size in bytes |
| 396 |
* @bdev : target block device |
| 397 |
* @bdev_contains : points to the device object which contains the partition (when bio structure represents a partition) |
| 398 |
* @p_start_sect : points to the start sector of the partition structure of the device |
| 399 |
* |
| 400 |
* Context: |
| 401 |
* The process signals the transfer is done. |
| 402 |
*/ |
| 403 |
probe ioblock_trace.end = kernel.trace("block_bio_complete") |
| 404 |
{ |
| 405 |
name = "ioblock_trace.end" |
| 406 |
q = @choose_defined($q, $bio->bi_bdev->bd_queue) |
| 407 |
devname = __bio_devname($bio) |
| 408 |
ino = __bio_ino($bio) |
| 409 |
|
| 410 |
bytes_done = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
| 411 |
|
| 412 |
sector = @choose_defined($bio->bi_iter->bi_sector, $bio->bi_sector) |
| 413 |
flags = $bio->bi_flags |
| 414 |
if (@defined($bio->bi_opf)) { |
| 415 |
rw = bio_op($bio) |
| 416 |
opf = $bio->bi_opf |
| 417 |
} |
| 418 |
else { |
| 419 |
rw = $bio->bi_rw |
| 420 |
opf = $bio->bi_rw |
| 421 |
} |
| 422 |
vcnt = $bio->bi_vcnt |
| 423 |
idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx) |
| 424 |
/* use bi_vcnt as a proxy as it is close enough */ |
| 425 |
phys_segments = @choose_defined($bio->bi_phys_segments, $bio->bi_vcnt) |
| 426 |
size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
| 427 |
bdev_contains = @choose_defined($bio->bi_bdev->bd_contains, 0) |
| 428 |
bdev = @choose_defined($bio->bi_bdev, 0) |
| 429 |
p_start_sect = __bio_start_sect($bio) |
| 430 |
} |