]>
Commit | Line | Data |
---|---|---|
d3a4bc8e TN |
1 | // Block I/O tapset |
2 | // Copyright (C) 2006 Intel Corp. | |
11df5b74 | 3 | // Copyright (C) 2006 IBM Corp. |
ef36f781 | 4 | // Copyright (C) 2014 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 TN |
12 | #include <linux/bio.h> |
13 | #include <linux/genhd.h> | |
c1d2d085 WC |
14 | #ifdef STAPCONF_BLK_TYPES |
15 | #include <linux/blk_types.h> | |
16 | #else | |
17 | #define REQ_WRITE (1 << BIO_RW) | |
18 | #endif | |
d3a4bc8e TN |
19 | %} |
20 | ||
11df5b74 TN |
21 | /* get i-node number of mapped file */ |
22 | function __bio_ino:long(bio:long) | |
da64b256 | 23 | %{ /* pure */ |
b7b482fb | 24 | struct bio *bio = (struct bio *)(long)STAP_ARG_bio; |
3963dacd | 25 | struct page *bv_page = (bio && bio->bi_vcnt) ? kread(&(bio->bi_io_vec[0].bv_page)) : NULL; |
478831cf MH |
26 | struct address_space *mapping; |
27 | struct inode *host; | |
b7b482fb | 28 | STAP_RETVALUE = -1; |
478831cf MH |
29 | if (bv_page && !PageSlab(bv_page) && !PageSwapCache(bv_page)) { |
30 | mapping = kread(&(bv_page->mapping)); | |
31 | if (mapping && ((unsigned long)mapping & PAGE_MAPPING_ANON) == 0) { | |
32 | host = kread(&(mapping->host)); | |
33 | if (host) | |
b7b482fb | 34 | STAP_RETVALUE = kread(&(host->i_ino)); |
478831cf MH |
35 | } |
36 | } | |
b8772cce | 37 | CATCH_DEREF_FAULT(); |
11df5b74 TN |
38 | %} |
39 | ||
40 | /* returns 0 for read, 1 for write */ | |
30cd73d3 | 41 | function bio_rw_num:long(rw:long) |
da64b256 | 42 | %{ /* pure */ |
b7b482fb SM |
43 | long rw = (long)STAP_ARG_rw; |
44 | STAP_RETVALUE = (rw & REQ_WRITE); | |
11df5b74 TN |
45 | %} |
46 | ||
47 | /* returns R for read, W for write */ | |
2bc468b1 | 48 | function bio_rw_str(rw:long) |
11df5b74 | 49 | { |
b8772cce | 50 | return bio_rw_num(rw) == BIO_READ ? "R" : "W" |
11df5b74 TN |
51 | } |
52 | ||
53 | /* returns start sector */ | |
54 | function __bio_start_sect:long(bio:long) | |
354c797e DS |
55 | { |
56 | bi_bdev = bio ? @cast(bio, "bio")->bi_bdev : 0 | |
57 | bd_part = bi_bdev ? @cast(bi_bdev, "block_device")->bd_part : 0 | |
58 | return bd_part ? @cast(bd_part, "hd_struct")->start_sect : -1 | |
59 | } | |
11df5b74 TN |
60 | |
61 | /* returns the block device name */ | |
62 | function __bio_devname:string(bio:long) | |
1713a05f DS |
63 | { |
64 | return bdevname(@cast(bio, "bio")->bi_bdev) | |
65 | } | |
11df5b74 | 66 | |
da64b256 FCE |
67 | global BIO_READ = 0, BIO_WRITE = 1 |
68 | ||
11df5b74 | 69 | |
4eea0069 PS |
70 | /** |
71 | * probe ioblock.request - Fires whenever making a generic block I/O request. | |
d3a4bc8e | 72 | * |
2bc468b1 | 73 | * @name - name of the probe point |
4eea0069 PS |
74 | * @devname - block device name |
75 | * @ino - i-node number of the mapped file | |
76 | * @sector - beginning sector for the entire bio | |
77 | * @flags - see below | |
11df5b74 TN |
78 | * BIO_UPTODATE 0 ok after I/O completion |
79 | * BIO_RW_BLOCK 1 RW_AHEAD set, and read/write would block | |
80 | * BIO_EOF 2 out-out-bounds error | |
81 | * BIO_SEG_VALID 3 nr_hw_seg valid | |
82 | * BIO_CLONED 4 doesn't own data | |
83 | * BIO_BOUNCED 5 bio is a bounce bio | |
84 | * BIO_USER_MAPPED 6 contains user pages | |
85 | * BIO_EOPNOTSUPP 7 not supported | |
86 | * | |
4eea0069 PS |
87 | * @rw - binary trace for read/write request |
88 | * @vcnt - bio vector count which represents number of array element (page, offset, length) which make up this I/O request | |
89 | * @idx - offset into the bio vector array | |
90 | * @phys_segments - number of segments in this bio after physical address coalescing is performed | |
91 | * @hw_segments - number of segments after physical and DMA remapping hardware coalescing is performed | |
92 | * @size - total size in bytes | |
93 | * @bdev - target block device | |
94 | * @bdev_contains - points to the device object which contains the partition (when bio structure represents a partition) | |
95 | * @p_start_sect - points to the start sector of the partition structure of the device | |
96 | * | |
97 | * Context: | |
98 | * The process makes block I/O request | |
d3a4bc8e | 99 | */ |
11df5b74 | 100 | probe ioblock.request = kernel.function ("generic_make_request") |
d3a4bc8e | 101 | { |
2bc468b1 | 102 | name = "ioblock.request" |
11df5b74 TN |
103 | devname = __bio_devname($bio) |
104 | ino = __bio_ino($bio) | |
105 | ||
6befa119 | 106 | sector = @choose_defined($bio->bi_iter->bi_sector, $bio->bi_sector) |
11df5b74 TN |
107 | flags = $bio->bi_flags |
108 | rw = $bio->bi_rw | |
109 | vcnt = $bio->bi_vcnt | |
6befa119 | 110 | idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx) |
11df5b74 | 111 | phys_segments = $bio->bi_phys_segments |
1d19665b | 112 | hw_segments = @choose_defined($bio->bi_hw_segments, 0) |
6befa119 | 113 | size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
11df5b74 TN |
114 | |
115 | bdev = $bio->bi_bdev | |
116 | bdev_contains = $bio->bi_bdev->bd_contains | |
117 | p_start_sect = __bio_start_sect($bio) | |
d3a4bc8e TN |
118 | } |
119 | ||
4eea0069 PS |
120 | /** |
121 | * probe ioblock.end - Fires whenever a block I/O transfer is complete. | |
d3a4bc8e | 122 | * |
2bc468b1 | 123 | * @name - name of the probe point |
4eea0069 PS |
124 | * @devname - block device name |
125 | * @ino - i-node number of the mapped file | |
126 | * @bytes_done - number of bytes transferred | |
127 | * @sector - beginning sector for the entire bio | |
128 | * @flags - see below | |
11df5b74 TN |
129 | * BIO_UPTODATE 0 ok after I/O completion |
130 | * BIO_RW_BLOCK 1 RW_AHEAD set, and read/write would block | |
131 | * BIO_EOF 2 out-out-bounds error | |
132 | * BIO_SEG_VALID 3 nr_hw_seg valid | |
133 | * BIO_CLONED 4 doesn't own data | |
134 | * BIO_BOUNCED 5 bio is a bounce bio | |
135 | * BIO_USER_MAPPED 6 contains user pages | |
136 | * BIO_EOPNOTSUPP 7 not supported | |
4eea0069 PS |
137 | * @error - 0 on success |
138 | * @rw - binary trace for read/write request | |
139 | * @vcnt - bio vector count which represents number of array element (page, offset, length) which makes up this I/O request | |
140 | * @idx - offset into the bio vector array | |
141 | * @phys_segments - number of segments in this bio after physical address coalescing is performed. | |
142 | * @hw_segments - number of segments after physical and DMA remapping hardware coalescing is performed | |
143 | * @size - total size in bytes | |
144 | * | |
145 | * Context: | |
146 | * The process signals the transfer is done. | |
d3a4bc8e | 147 | */ |
11df5b74 | 148 | probe ioblock.end = kernel.function("bio_endio") |
d3a4bc8e | 149 | { |
2bc468b1 | 150 | name = "ioblock.end" |
11df5b74 TN |
151 | devname = __bio_devname($bio) |
152 | ino = __bio_ino($bio) | |
d3a4bc8e | 153 | |
6befa119 DS |
154 | bytes_done = @choose_defined($bytes_done, |
155 | @choose_defined($bio->bi_iter->bi_size, | |
156 | $bio->bi_size)) | |
11df5b74 | 157 | error = $error |
d3a4bc8e | 158 | |
6befa119 | 159 | sector = @choose_defined($bio->bi_iter->bi_sector, $bio->bi_sector) |
11df5b74 TN |
160 | flags = $bio->bi_flags |
161 | rw = $bio->bi_rw | |
162 | vcnt = $bio->bi_vcnt | |
6befa119 | 163 | idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx) |
11df5b74 | 164 | phys_segments = $bio->bi_phys_segments |
1d19665b | 165 | hw_segments = @choose_defined($bio->bi_hw_segments, 0) |
6befa119 | 166 | size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
11df5b74 | 167 | } |
4eea0069 PS |
168 | |
169 | /** | |
170 | * probe ioblock_trace.bounce - Fires whenever a buffer bounce is needed for at least one page of a block IO request. | |
171 | * | |
2bc468b1 DS |
172 | * @name - name of the probe point |
173 | * @q - request queue on which this bio was queued. | |
174 | * @devname - device for which a buffer bounce was needed. | |
4eea0069 PS |
175 | * @ino - i-node number of the mapped file |
176 | * @bytes_done - number of bytes transferred | |
177 | * @sector - beginning sector for the entire bio | |
178 | * @flags - see below | |
179 | * BIO_UPTODATE 0 ok after I/O completion | |
180 | * BIO_RW_BLOCK 1 RW_AHEAD set, and read/write would block | |
181 | * BIO_EOF 2 out-out-bounds error | |
182 | * BIO_SEG_VALID 3 nr_hw_seg valid | |
183 | * BIO_CLONED 4 doesn't own data | |
184 | * BIO_BOUNCED 5 bio is a bounce bio | |
185 | * BIO_USER_MAPPED 6 contains user pages | |
186 | * BIO_EOPNOTSUPP 7 not supported | |
4eea0069 PS |
187 | * @rw - binary trace for read/write request |
188 | * @vcnt - bio vector count which represents number of array element (page, offset, length) which makes up this I/O request | |
189 | * @idx - offset into the bio vector array | |
190 | * @phys_segments - number of segments in this bio after physical address coalescing is performed. | |
191 | * @size - total size in bytes | |
2bc468b1 DS |
192 | * @bdev - target block device |
193 | * @bdev_contains - points to the device object which contains the partition (when bio structure represents a partition) | |
194 | * @p_start_sect - points to the start sector of the partition structure of the device | |
4eea0069 PS |
195 | * |
196 | * Context : | |
197 | * The process creating a block IO request. | |
198 | */ | |
199 | probe ioblock_trace.bounce = kernel.trace("block_bio_bounce") | |
200 | { | |
2bc468b1 DS |
201 | name = "ioblock_trace.bounce" |
202 | q = $q | |
4eea0069 PS |
203 | devname = __bio_devname($bio) |
204 | ino = __bio_ino($bio) | |
205 | ||
6befa119 DS |
206 | bytes_done = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
207 | sector = @choose_defined($bio->bi_iter->bi_sector, $bio->bi_sector) | |
4eea0069 PS |
208 | flags = $bio->bi_flags |
209 | rw = $bio->bi_rw | |
210 | vcnt = $bio->bi_vcnt | |
6befa119 | 211 | idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx) |
4eea0069 | 212 | phys_segments = $bio->bi_phys_segments |
6befa119 | 213 | size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
2bc468b1 DS |
214 | bdev_contains = $bio->bi_bdev->bd_contains |
215 | bdev = $bio->bi_bdev | |
216 | p_start_sect = __bio_start_sect($bio) | |
4eea0069 PS |
217 | } |
218 | ||
219 | /** | |
220 | * probe ioblock_trace.request - Fires just as a generic block I/O request is created for a bio. | |
221 | * | |
2bc468b1 DS |
222 | * @name - name of the probe point |
223 | * @q - request queue on which this bio was queued. | |
4eea0069 PS |
224 | * @devname - block device name |
225 | * @ino - i-node number of the mapped file | |
b28d67e2 | 226 | * @bytes_done - number of bytes transferred |
4eea0069 PS |
227 | * @sector - beginning sector for the entire bio |
228 | * @flags - see below | |
229 | * BIO_UPTODATE 0 ok after I/O completion | |
230 | * BIO_RW_BLOCK 1 RW_AHEAD set, and read/write would block | |
231 | * BIO_EOF 2 out-out-bounds error | |
232 | * BIO_SEG_VALID 3 nr_hw_seg valid | |
233 | * BIO_CLONED 4 doesn't own data | |
234 | * BIO_BOUNCED 5 bio is a bounce bio | |
235 | * BIO_USER_MAPPED 6 contains user pages | |
236 | * BIO_EOPNOTSUPP 7 not supported | |
237 | * | |
238 | * @rw - binary trace for read/write request | |
239 | * @vcnt - bio vector count which represents number of array element (page, offset, length) which make up this I/O request | |
240 | * @idx - offset into the bio vector array | |
241 | * @phys_segments - number of segments in this bio after physical address coalescing is performed. | |
242 | * @size - total size in bytes | |
243 | * @bdev - target block device | |
244 | * @bdev_contains - points to the device object which contains the partition (when bio structure represents a partition) | |
245 | * @p_start_sect - points to the start sector of the partition structure of the device | |
246 | * | |
247 | * Context: | |
248 | * The process makes block I/O request | |
249 | */ | |
250 | ||
251 | probe ioblock_trace.request = kernel.trace("block_bio_queue") | |
252 | { | |
2bc468b1 DS |
253 | name = "ioblock_trace.request" |
254 | q = $q | |
4eea0069 PS |
255 | devname = __bio_devname($bio) |
256 | ino = __bio_ino($bio) | |
257 | ||
6befa119 DS |
258 | bytes_done = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
259 | sector = @choose_defined($bio->bi_iter->bi_sector, $bio->bi_sector) | |
4eea0069 PS |
260 | flags = $bio->bi_flags |
261 | rw = $bio->bi_rw | |
262 | vcnt = $bio->bi_vcnt | |
6befa119 | 263 | idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx) |
4eea0069 | 264 | phys_segments = $bio->bi_phys_segments |
6befa119 | 265 | size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
4eea0069 PS |
266 | bdev_contains = $bio->bi_bdev->bd_contains |
267 | bdev = $bio->bi_bdev | |
268 | p_start_sect = __bio_start_sect($bio) | |
269 | } | |
270 | ||
271 | /** | |
272 | * probe ioblock_trace.end - Fires whenever a block I/O transfer is complete. | |
273 | * | |
2bc468b1 DS |
274 | * @name - name of the probe point |
275 | * @q - request queue on which this bio was queued. | |
4eea0069 PS |
276 | * @devname - block device name |
277 | * @ino - i-node number of the mapped file | |
278 | * @bytes_done - number of bytes transferred | |
279 | * @sector - beginning sector for the entire bio | |
280 | * @flags - see below | |
281 | * BIO_UPTODATE 0 ok after I/O completion | |
282 | * BIO_RW_BLOCK 1 RW_AHEAD set, and read/write would block | |
283 | * BIO_EOF 2 out-out-bounds error | |
284 | * BIO_SEG_VALID 3 nr_hw_seg valid | |
285 | * BIO_CLONED 4 doesn't own data | |
286 | * BIO_BOUNCED 5 bio is a bounce bio | |
287 | * BIO_USER_MAPPED 6 contains user pages | |
288 | * BIO_EOPNOTSUPP 7 not supported | |
18871ad0 | 289 | * |
4eea0069 PS |
290 | * @rw - binary trace for read/write request |
291 | * @vcnt - bio vector count which represents number of array element (page, offset, length) which makes up this I/O request | |
292 | * @idx - offset into the bio vector array | |
293 | * @phys_segments - number of segments in this bio after physical address coalescing is performed. | |
294 | * @size - total size in bytes | |
2bc468b1 DS |
295 | * @bdev - target block device |
296 | * @bdev_contains - points to the device object which contains the partition (when bio structure represents a partition) | |
297 | * @p_start_sect - points to the start sector of the partition structure of the device | |
4eea0069 PS |
298 | * |
299 | * Context: | |
300 | * The process signals the transfer is done. | |
301 | */ | |
302 | probe ioblock_trace.end = kernel.trace("block_bio_complete") | |
303 | { | |
2bc468b1 | 304 | name = "ioblock_trace.end" |
4eea0069 PS |
305 | q = $q |
306 | devname = __bio_devname($bio) | |
307 | ino = __bio_ino($bio) | |
308 | ||
6befa119 | 309 | bytes_done = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
4eea0069 | 310 | |
6befa119 | 311 | sector = @choose_defined($bio->bi_iter->bi_sector, $bio->bi_sector) |
4eea0069 PS |
312 | flags = $bio->bi_flags |
313 | rw = $bio->bi_rw | |
314 | vcnt = $bio->bi_vcnt | |
6befa119 | 315 | idx = @choose_defined($bio->bi_iter->bi_idx, $bio->bi_idx) |
4eea0069 | 316 | phys_segments = $bio->bi_phys_segments |
6befa119 | 317 | size = @choose_defined($bio->bi_iter->bi_size, $bio->bi_size) |
2bc468b1 DS |
318 | bdev_contains = $bio->bi_bdev->bd_contains |
319 | bdev = $bio->bi_bdev | |
320 | p_start_sect = __bio_start_sect($bio) | |
4eea0069 | 321 | } |