Whamcloud - gitweb
LU-17705 ptlrpc: replace synchronize_rcu() with rcu_barrier()
[fs/lustre-release.git] / contrib / debug_tools / epython_scripts / cfs_hnodes.py
1 #!/usr/bin/env python
2
3 """
4 Utility to display a Lustre cfs_hash table
5 Copyright (c) 2019 Cray Inc. All Rights Reserved.
6 """
7
8 from pykdump.API import *
9 #from struct import *
10 import argparse
11 import os
12
13 import lustrelib as ll
14 from crashlib.input import toint
15
16 description_short = "Displays the specified Lustre hash table "
17
18 DEPTH = 3
19 RULER = "........................................"
20
21 hash_objects = {
22     'ldlm_res_hop_object': ['struct ldlm_resource', 'lr_hash'],
23     'jobid_object':        ['struct jobid_to_pid_map', 'jp_hash'],
24     'lu_obj_hop_object':   ['struct lu_object_header', 'loh_hash'],
25     'uuid_export_object':  ['struct obd_export', 'export_uuid_hash'],
26     'nid_export_object':   ['struct obd_export', 'exp_nid_hash'],
27     'nidstats_object':     ['struct nid_stat', 'nid_hash'],
28     'gen_export_object':   ['struct obd_export', 'exp_gen_hash'],
29     'oqi_object':          ['struct osc_quota_info', 'oqi_hash'],
30     'conn_object':         ['struct ptlrpc_connection', 'c_hash']}
31
32 def get_hash_object(hs, hnode):
33     s = addr2sym(hs.hs_ops.hs_object)
34     if s not in hash_objects:
35         return ''
36     obj = hash_objects[s]
37     obj_addr = Addr(hnode) -  member_offset(obj[0], obj[1])
38     return "%s %x" % (obj[0], obj_addr)
39
40 def dump_hnodes(hs, hlist, hnode, depth=0, ruler=RULER):
41     while(hnode != hlist & hnode):
42         s = get_hash_object(hs, hnode)
43         print("%*.*shlist_node 0x%x  %s" % (depth, depth, ruler, Addr(hnode), s))
44         hnode = hnode.next
45
46 def dump_hlist(hs, hlist, depth=0, ruler=RULER):
47     if hlist.first:
48         hnode = hlist.first
49         print("%*.*shlist_head 0x%x" % (depth, depth, ruler, Addr(hlist)))
50         dump_hnodes(hs, hlist, hnode, depth+DEPTH, ruler)
51
52 def dump_hash_bucket(hs, bd_bkt, depth=0, ruler=RULER):
53     print("%*.*scfs_hash_bucket 0x%x" % (depth, depth, ruler, Addr(bd_bkt)))
54     for bd_offset in range(ll.CFS_HASH_BKT_NHLIST(hs)):
55         hlist = ll.cfs_hash_hhead(hs, bd_bkt, bd_offset)
56         if hlist:
57             dump_hlist(hs, hlist, depth+DEPTH, ruler)
58
59 def dump_hash_table(hs):
60     print("cfs_hash@0x%x" % Addr(hs))
61
62     for bd_bkt in ll.cfs_hash_get_buckets(hs):
63         dump_hash_bucket(hs, bd_bkt, DEPTH, RULER)
64
65 if __name__ == "__main__":
66     description = "Displays the specified Lustre hash table "
67     parser = argparse.ArgumentParser(description=description)
68     parser.add_argument("htable", default=False, type=toint,
69         help="address of a cfs_hash struct")
70     args = parser.parse_args()
71
72     hs = readSU('struct cfs_hash', args.htable)
73     dump_hash_table(hs)