]> sourceware.org Git - systemtap.git/blame - tapset/linux/ioblock.stp
Deal with kernels pre-6.12 kernel that relocated unaligned.h
[systemtap.git] / tapset / linux / ioblock.stp
CommitLineData
d3a4bc8e
TN
1// Block I/O tapset
2// Copyright (C) 2006 Intel Corp.
11df5b74 3// Copyright (C) 2006 IBM Corp.
e1a43110 4// Copyright (C) 2014-2017 Red Hat Inc.
d3a4bc8e
TN
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%{
11df5b74 12#include <linux/bio.h>
da9d1c42 13#ifdef STAPCONF_GENHD_H
11df5b74 14#include <linux/genhd.h>
78313b5e
WC
15#else
16#include <linux/blkdev.h>
17#endif
c1d2d085
WC
18#ifdef STAPCONF_BLK_TYPES
19#include <linux/blk_types.h>
e1a43110
DS
20#endif
21%}
22
3de36221
DS
23private 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
e1a43110
DS
49/* Returns the REQ_OP_* bits for a bio structure. */
50function bio_op:long(bio:long)
51%{ /* pure */ /* unprivileged */
f630ccfb 52#if defined(STAPCONF_BIO_BI_OPF)
f6b623f6 53 struct bio *bio = (struct bio *)(uintptr_t)STAP_ARG_bio;
e1a43110
DS
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 }
c1d2d085 62#else
f6b623f6 63 struct bio *bio = (struct bio *)(uintptr_t)STAP_ARG_bio;
e1a43110
DS
64
65 STAP_RETVALUE = 0;
66 if (bio) {
67 STAP_RETVALUE = kread(&(bio->bi_rw));
68 }
c1d2d085 69#endif
e1a43110 70 CATCH_DEREF_FAULT();
d3a4bc8e
TN
71%}
72
11df5b74 73/* get i-node number of mapped file */
6b131ba7 74@__private30 function __bio_ino:long(bio:long)
da64b256 75%{ /* pure */
f6b623f6 76 struct bio *bio = (struct bio *)(uintptr_t)STAP_ARG_bio;
6520870c
DS
77 struct page *bv_page = ((bio && kread(&(bio->bi_vcnt)))
78 ? kread(&(bio->bi_io_vec[0].bv_page)) : NULL);
79
b7b482fb 80 STAP_RETVALUE = -1;
6520870c
DS
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 }
478831cf 94 }
b8772cce 95 CATCH_DEREF_FAULT();
11df5b74
TN
96%}
97
98/* returns 0 for read, 1 for write */
30cd73d3 99function bio_rw_num:long(rw:long)
6520870c 100{
e1a43110 101 return (rw & BIO_WRITE)
6520870c 102}
11df5b74
TN
103
104/* returns R for read, W for write */
2bc468b1 105function bio_rw_str(rw:long)
11df5b74 106{
b8772cce 107 return bio_rw_num(rw) == BIO_READ ? "R" : "W"
11df5b74
TN
108}
109
110/* returns start sector */
6b131ba7 111@__private30 function __bio_start_sect:long(bio:long)
354c797e 112{
f7e525cb 113 try {
a948c291
WC
114 if (@defined(@cast(bio, "bio", "kernel")->bi_dev)) {
115 return @cast(bio, "bio", "kernel")->bi_bdev->bd_part->start_sect
3de36221 116 }
a948c291
WC
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)
3de36221 120 }
f7e525cb
JS
121 } catch {
122 return -1
123 }
354c797e 124}
11df5b74
TN
125
126/* returns the block device name */
6b131ba7 127@__private30 function __bio_devname:string(bio:long)
1713a05f 128{
a948c291
WC
129 if (@defined(@cast(bio, "bio", "kernel")->bi_bdev)) {
130 return bdevname(@cast(bio, "bio", "kernel")->bi_bdev)
3de36221
DS
131 }
132 else {
a948c291
WC
133 return disk_name(@cast(bio, "bio", "kernel")->bi_disk,
134 @cast(bio, "bio", "kernel")->bi_partno)
3de36221 135 }
1713a05f 136}
11df5b74 137
da64b256
FCE
138global BIO_READ = 0, BIO_WRITE = 1
139
11df5b74 140
4eea0069 141/**
7441e8ec
FL
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
e1a43110 157 * @opf : operations and flags
7441e8ec
FL
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
4eea0069
PS
166 *
167 * Context:
168 * The process makes block I/O request
d3a4bc8e 169 */
0a4bcbc1
WC
170probe ioblock.request = kernel.function ("submit_bio_noacct")!,
171 kernel.function ("generic_make_request")
d3a4bc8e 172{
2bc468b1 173 name = "ioblock.request"
11df5b74
TN
174 devname = __bio_devname($bio)
175 ino = __bio_ino($bio)
176
6befa119 177 sector = @choose_defined($bio->bi_iter->bi_sector, $bio->bi_sector)
11df5b74 178 flags = $bio->bi_flags
e1a43110
DS
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 }
11df5b74 187 vcnt = $bio->bi_vcnt
6befa119 188 idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx)
f1612b12
WC
189 /* use bi_vcnt as a proxy as it is close enough */
190 phys_segments = @choose_defined($bio->bi_phys_segments, $bio->bi_vcnt)
1d19665b 191 hw_segments = @choose_defined($bio->bi_hw_segments, 0)
6befa119 192 size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size)
11df5b74 193
3de36221
DS
194 bdev = @choose_defined($bio->bi_bdev, 0)
195 bdev_contains = @choose_defined($bio->bi_bdev->bd_contains, 0)
11df5b74 196 p_start_sect = __bio_start_sect($bio)
d3a4bc8e
TN
197}
198
4eea0069
PS
199/**
200 * probe ioblock.end - Fires whenever a block I/O transfer is complete.
7441e8ec
FL
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
11df5b74
TN
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
7441e8ec
FL
215 * @error : 0 on success
216 * @rw : binary trace for read/write request
e1a43110 217 * @opf : operations and flags
7441e8ec
FL
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
4eea0069
PS
223 *
224 * Context:
225 * The process signals the transfer is done.
d3a4bc8e 226 */
11df5b74 227probe ioblock.end = kernel.function("bio_endio")
d3a4bc8e 228{
2bc468b1 229 name = "ioblock.end"
11df5b74
TN
230 devname = __bio_devname($bio)
231 ino = __bio_ino($bio)
d3a4bc8e 232
6befa119
DS
233 bytes_done = @choose_defined($bytes_done,
234 @choose_defined($bio->bi_iter->bi_size,
235 $bio->bi_size))
b9210972
DS
236 error = @choose_defined($error, @choose_defined($bio->bi_error,
237 $bio->bi_status))
d3a4bc8e 238
6befa119 239 sector = @choose_defined($bio->bi_iter->bi_sector, $bio->bi_sector)
11df5b74 240 flags = $bio->bi_flags
e1a43110
DS
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 }
11df5b74 249 vcnt = $bio->bi_vcnt
6befa119 250 idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx)
f1612b12
WC
251 /* use bi_vcnt as a proxy as it is close enough */
252 phys_segments = @choose_defined($bio->bi_phys_segments, $bio->bi_vcnt)
1d19665b 253 hw_segments = @choose_defined($bio->bi_hw_segments, 0)
6befa119 254 size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size)
11df5b74 255}
4eea0069
PS
256
257/**
258 * probe ioblock_trace.bounce - Fires whenever a buffer bounce is needed for at least one page of a block IO request.
7441e8ec
FL
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
e1a43110 275 * @opf : operations and flags
7441e8ec
FL
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
4eea0069
PS
283 *
284 * Context :
285 * The process creating a block IO request.
286 */
287probe ioblock_trace.bounce = kernel.trace("block_bio_bounce")
288{
2bc468b1 289 name = "ioblock_trace.bounce"
f1612b12 290 q = @choose_defined($q, $bio->bi_bdev->bd_queue)
4eea0069
PS
291 devname = __bio_devname($bio)
292 ino = __bio_ino($bio)
293
6befa119
DS
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)
4eea0069 296 flags = $bio->bi_flags
e1a43110
DS
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 }
4eea0069 305 vcnt = $bio->bi_vcnt
6befa119 306 idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx)
f1612b12
WC
307 /* use bi_vcnt as a proxy as it is close enough */
308 phys_segments = @choose_defined($bio->bi_phys_segments, $bio->bi_vcnt)
6befa119 309 size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size)
3de36221
DS
310 bdev_contains = @choose_defined($bio->bi_bdev->bd_contains, 0)
311 bdev = @choose_defined($bio->bi_bdev, 0)
2bc468b1 312 p_start_sect = __bio_start_sect($bio)
4eea0069
PS
313}
314
315/**
316 * probe ioblock_trace.request - Fires just as a generic block I/O request is created for a bio.
7441e8ec
FL
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
e1a43110 333 * @opf : operations and flags
7441e8ec
FL
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
4eea0069
PS
341 *
342 * Context:
343 * The process makes block I/O request
344 */
4eea0069
PS
345probe ioblock_trace.request = kernel.trace("block_bio_queue")
346{
2bc468b1 347 name = "ioblock_trace.request"
f1612b12 348 q = @choose_defined($q, $bio->bi_bdev->bd_queue)
4eea0069
PS
349 devname = __bio_devname($bio)
350 ino = __bio_ino($bio)
351
6befa119
DS
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)
4eea0069 354 flags = $bio->bi_flags
e1a43110
DS
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 }
4eea0069 363 vcnt = $bio->bi_vcnt
6befa119 364 idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx)
f1612b12
WC
365 /* use bi_vcnt as a proxy as it is close enough */
366 phys_segments = @choose_defined($bio->bi_phys_segments, $bio->bi_vcnt)
6befa119 367 size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size)
3de36221
DS
368 bdev_contains = @choose_defined($bio->bi_bdev->bd_contains, 0)
369 bdev = @choose_defined($bio->bi_bdev, 0)
4eea0069
PS
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.
7441e8ec
FL
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
4eea0069
PS
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
7441e8ec 390 * @rw : binary trace for read/write request
e1a43110 391 * @opf : operations and flags
7441e8ec
FL
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
4eea0069
PS
399 *
400 * Context:
401 * The process signals the transfer is done.
402 */
403probe ioblock_trace.end = kernel.trace("block_bio_complete")
404{
2bc468b1 405 name = "ioblock_trace.end"
f1612b12 406 q = @choose_defined($q, $bio->bi_bdev->bd_queue)
4eea0069
PS
407 devname = __bio_devname($bio)
408 ino = __bio_ino($bio)
409
6befa119 410 bytes_done = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size)
4eea0069 411
6befa119 412 sector = @choose_defined($bio->bi_iter->bi_sector, $bio->bi_sector)
4eea0069 413 flags = $bio->bi_flags
e1a43110
DS
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 }
4eea0069 422 vcnt = $bio->bi_vcnt
6befa119 423 idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx)
f1612b12
WC
424 /* use bi_vcnt as a proxy as it is close enough */
425 phys_segments = @choose_defined($bio->bi_phys_segments, $bio->bi_vcnt)
6befa119 426 size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size)
3de36221
DS
427 bdev_contains = @choose_defined($bio->bi_bdev->bd_contains, 0)
428 bdev = @choose_defined($bio->bi_bdev, 0)
2bc468b1 429 p_start_sect = __bio_start_sect($bio)
4eea0069 430}
This page took 0.287252 seconds and 6 git commands to generate.