|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: |
3 | 3 |
|
4 | | -from typing import Iterable |
| 4 | +from typing import Callable, Iterable |
5 | 5 |
|
6 | 6 | import gdb |
7 | 7 | from gdb.types import get_basic_type |
|
21 | 21 | READ = 0 |
22 | 22 | WRITE = 1 |
23 | 23 |
|
| 24 | +# Values will be filled in via callback. These are declared here to honor |
| 25 | +# imports for lint. |
| 26 | +REQ_FUA: int |
| 27 | +REQ_PREFLUSH: int |
| 28 | +REQ_STARTED: int |
| 29 | +REQ_SYNC: int |
| 30 | + |
24 | 31 | def dev_to_gendisk(dev: gdb.Value) -> gdb.Value: |
25 | 32 | """ |
26 | 33 | Converts a ``struct device`` that is embedded in a ``struct gendisk`` |
@@ -295,12 +302,21 @@ def rq_is_sync(request: gdb.Value) -> bool: |
295 | 302 | :obj:`bool`: True for synchronous requests, False otherwise. |
296 | 303 | """ |
297 | 304 | return (request['cmd_flags'] & 1 == 0 or |
298 | | - request['cmd_flags'] & (REQ_SYNC | REQ_FUA | REQ_PREFLUSH) != 0) # type: ignore |
| 305 | + request['cmd_flags'] & (REQ_SYNC | REQ_FUA | REQ_PREFLUSH) != 0) |
| 306 | + |
| 307 | + |
| 308 | +_rq_in_flight: Callable[[gdb.Value], bool] |
| 309 | + |
| 310 | +def _rq_in_flight_rq_state(request: gdb.Value) -> bool: |
| 311 | + return (request['rq_state'] != |
| 312 | + types.enum_mq_rq_state_type['MQ_RQ_IDLE']) |
| 313 | + |
| 314 | +def _rq_in_flight_atomic_flags(request: gdb.Value) -> bool: |
| 315 | + return (request['atomic_flags'] & |
| 316 | + (1 << int(types.enum_rq_atomic_flags_type['REQ_ATOM_STARTED'].enumval)) != 0) |
299 | 317 |
|
300 | | -# This is a stub to make static checker happy. It gets overridden once 'struct |
301 | | -# request' is resolved. |
302 | | -def _rq_in_flight(request: gdb.Value) -> bool: |
303 | | - raise RuntimeError("struct request type not resolved yet!") |
| 318 | +def _rq_in_flight_cmd_flags(request: gdb.Value) -> bool: |
| 319 | + return request['cmd_flags'] & REQ_STARTED != 0 |
304 | 320 |
|
305 | 321 | def rq_in_flight(request: gdb.Value) -> bool: |
306 | 322 | """ |
@@ -359,18 +375,13 @@ def _export_req_flags(req_flag_bits: gdb.Type) -> None: |
359 | 375 | # Check struct request and define functions based on its current form in this |
360 | 376 | # kernel |
361 | 377 | def _check_struct_request(request_s: gdb.Type) -> None: |
362 | | - global _rq_in_flight |
363 | 378 | if struct_has_member(request_s, 'rq_state'): |
364 | | - def _rq_in_flight(request: gdb.Value) -> bool: |
365 | | - return (request['rq_state'] != |
366 | | - types.enum_mq_rq_state_type['MQ_RQ_IDLE']) |
| 379 | + impl = _rq_in_flight_rq_state |
367 | 380 | elif struct_has_member(request_s, 'atomic_flags'): |
368 | | - def _rq_in_flight(request: gdb.Value) -> bool: |
369 | | - return (request['atomic_flags'] & |
370 | | - (1 << int(types.enum_rq_atomic_flags_type['REQ_ATOM_STARTED'].enumval)) != 0) |
| 381 | + impl = _rq_in_flight_atomic_flags |
371 | 382 | else: |
372 | | - def _rq_in_flight(request: gdb.Value) -> bool: |
373 | | - return request['cmd_flags'] & REQ_STARTED != 0 # type: ignore |
| 383 | + impl = _rq_in_flight_cmd_flags |
| 384 | + globals()['_rq_in_flight'] = impl |
374 | 385 |
|
375 | 386 | symbol_cbs = SymbolCallbacks([('disk_type', _check_types), |
376 | 387 | ('part_type', _check_types)]) |
|
0 commit comments