Skip to content

Commit ff8cb63

Browse files
committed
storage: fix lint warnings
pylint is complaining about missing names, when the names are autogenerated. Add the names with just a type but not value to silence the checker. Signed-off-by: Jeff Mahoney <jeffm@suse.com>
1 parent cf0374d commit ff8cb63

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

‎crash/subsystem/storage/__init__.py‎

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
33

4-
from typing import Iterable
4+
from typing import Callable, Iterable
55

66
import gdb
77
from gdb.types import get_basic_type
@@ -21,6 +21,13 @@
2121
READ = 0
2222
WRITE = 1
2323

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+
2431
def dev_to_gendisk(dev: gdb.Value) -> gdb.Value:
2532
"""
2633
Converts a ``struct device`` that is embedded in a ``struct gendisk``
@@ -295,12 +302,21 @@ def rq_is_sync(request: gdb.Value) -> bool:
295302
:obj:`bool`: True for synchronous requests, False otherwise.
296303
"""
297304
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)
299317

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
304320

305321
def rq_in_flight(request: gdb.Value) -> bool:
306322
"""
@@ -359,18 +375,13 @@ def _export_req_flags(req_flag_bits: gdb.Type) -> None:
359375
# Check struct request and define functions based on its current form in this
360376
# kernel
361377
def _check_struct_request(request_s: gdb.Type) -> None:
362-
global _rq_in_flight
363378
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
367380
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
371382
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
374385

375386
symbol_cbs = SymbolCallbacks([('disk_type', _check_types),
376387
('part_type', _check_types)])

0 commit comments

Comments
 (0)