Skip to content

Commit 80e126e

Browse files
daimngobrenns10
authored andcommitted
nfs_tools: fix problem of displaying string representation of tk_runstate
This fix ensures the correct string representation of the bits in tk_runstate, which vary depending on the kernel version. Signed-off-by: Dai Ngo <[email protected]>
1 parent 6a15f9e commit 80e126e

File tree

1 file changed

+69
-5
lines changed

1 file changed

+69
-5
lines changed

drgn_tools/nfs_tools.py

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,81 @@
4040
""" include/linux/sunrpc/sched.h """
4141

4242

43-
class RpcTaskState(BitNumberFlags):
43+
class RpcTaskState_1(BitNumberFlags):
44+
RPC_TASK_RUNNING = 0
45+
RPC_TASK_QUEUED = 1
46+
RPC_TASK_ACTIVE = 2
47+
48+
49+
# 729749bb8da1 SUNRPC: Don't hold the transport lock across socket copy operations
50+
class RpcTaskState_2(BitNumberFlags):
4451
RPC_TASK_RUNNING = 0
4552
RPC_TASK_QUEUED = 1
4653
RPC_TASK_ACTIVE = 2
4754
RPC_TASK_MSG_RECV = 3
4855
RPC_TASK_MSG_RECV_WAIT = 4
4956

5057

58+
# 7ebbbc6e7bd0 SUNRPC: Simplify identification of when the message send/receive is complete
59+
class RpcTaskState_3(BitNumberFlags):
60+
RPC_TASK_RUNNING = 0
61+
RPC_TASK_QUEUED = 1
62+
RPC_TASK_ACTIVE = 2
63+
RPC_TASK_NEED_XMIT = 3
64+
RPC_TASK_NEED_RECV = 4
65+
RPC_TASK_MSG_RECV = 5
66+
RPC_TASK_MSG_RECV_WAIT = 6
67+
68+
69+
# cf9946cd6144 SUNRPC: Refactor the transport request pinning
70+
class RpcTaskState_4(BitNumberFlags):
71+
RPC_TASK_RUNNING = 0
72+
RPC_TASK_QUEUED = 1
73+
RPC_TASK_ACTIVE = 2
74+
RPC_TASK_NEED_XMIT = 3
75+
RPC_TASK_NEED_RECV = 4
76+
RPC_TASK_MSG_PIN_WAIT = 5
77+
78+
79+
# ae67bd3821bb SUNRPC: Fix up task signalling
80+
class RpcTaskState_5(BitNumberFlags):
81+
RPC_TASK_RUNNING = 0
82+
RPC_TASK_QUEUED = 1
83+
RPC_TASK_ACTIVE = 2
84+
RPC_TASK_NEED_XMIT = 3
85+
RPC_TASK_NEED_RECV = 4
86+
RPC_TASK_MSG_PIN_WAIT = 5
87+
RPC_TASK_SIGNALLED = 6
88+
89+
90+
def does_func_exist(prog: drgn.Program, func: str) -> bool:
91+
try:
92+
prog.symbol(func)
93+
return True
94+
except LookupError:
95+
return False
96+
97+
98+
def decode_tk_runstate(prog: drgn.Program, task: Object) -> str:
99+
"""
100+
Given a rpc_task, return the string representation of tk_runstate
101+
102+
:param task: rpc_task object
103+
:returns: tk_runstate decoded as string.
104+
"""
105+
106+
if does_func_exist(prog, "xprt_pin_rqst") is False:
107+
return RpcTaskState_1.decode(task.tk_runstate.value_())
108+
elif does_func_exist(prog, "xprt_request_data_received") is False:
109+
return RpcTaskState_2.decode(task.tk_runstate.value_())
110+
elif has_member(task.tk_rqstp, "rq_pin") is False:
111+
return RpcTaskState_3.decode(task.tk_runstate.value_())
112+
elif does_func_exist(prog, "rpc_signal_task") is False:
113+
return RpcTaskState_4.decode(task.tk_runstate.value_())
114+
else:
115+
return RpcTaskState_5.decode(task.tk_runstate.value_())
116+
117+
51118
""" include/linux/sunrpc/xprt.h """
52119

53120

@@ -397,10 +464,7 @@ def display_rpc_tasks(
397464

398465
print(
399466
" tk_runstate: 0x%x (%s)"
400-
% (
401-
task.tk_runstate,
402-
RpcTaskState.decode(task.tk_runstate.value_()),
403-
)
467+
% (task.tk_runstate, decode_tk_runstate(prog, task))
404468
)
405469
print(
406470
" tk_priority: %d tk_timeout(ticks): %d tk_timeouts(major): %d"

0 commit comments

Comments
 (0)