----- Original Message -----
----- Original Message -----
> Hello,
>
> I'd like to ask whether it's possible to traverse the chains of a
> hashtable which is defined via the hashtable.h infrastructure? If
> there is no support for this currently I guess crash has to be taught
> to understand how to do the maths to extract the container structures
> from embedded hlist_nodes, similar to how it does it for list_head
> type of structs? And unless this is done doing the arithmetic manually
> is the only way?
>
> Regards,
> Nikolay
You can easily traverse the chain of hlist_node structures linked from
an hlist_head using the "list" command, but if you want to display the data
structure that contains each hlist_node, it's typically a two-step process
where you:
(1) capture the list of hlist_node addresses in an output file, and then
(2) feed that list back to "struct -l offset", where the offset to the
hlist_node is supplied.
If you're lucky and the hlist_node happens to be the first member of the
containing structure, you could use the "list -s" option directly.
An interesting option to "list [-s struct[.member[,member]] ..." might
be the addition of a "-l offset", which would only be accepted/utilized
if "list -s ..." is being used, i.e.:
list [-s struct[.member[,member] [-l offset]]
Dave
Actually, for a hashtable headed up by a hlist_head, I think you should be able
to use the "list -H" option.
For example, each of the kernel's pid_hash[] chains is headed by an hlist_head
structure, which links a chain of "upid" structures:
crash> whatis pid_hash
struct hlist_head *pid_hash;
crash> upid
struct upid {
int nr;
struct pid_namespace *ns;
struct hlist_node pid_chain;
}
SIZE: 32
crash>
Here, one of the pid_hash[] chains has 3 members:
crash> p pid_hash[1630]
$5 = {
first = 0xffff88007786e7c0
}
crash> list 0xffff88007786e7c0
ffff88007786e7c0
ffff88022ff29240
ffff88022da515c0
crash>
Using the address of the hlist_head:
crash> p &pid_hash[1630]
$4 = (struct hlist_head *) 0xffff88043ffb5a70
crash>
I can dump the upid structures by passing that address to -H, along
with -s and -o:
crash> list -H 0xffff88043ffb5a70 -s upid -o upid.pid_chain
ffff88007786e7b0
struct upid {
nr = 58308,
ns = 0xffffffff819411a0 <init_pid_ns>,
pid_chain = {
next = 0xffff88022ff29240,
pprev = 0xffff88043ffb5a70
}
}
ffff88022ff29230
struct upid {
nr = 57787,
ns = 0xffffffff819411a0 <init_pid_ns>,
pid_chain = {
next = 0xffff88022da515c0,
pprev = 0xffff88007786e7c0
}
}
ffff88022da515b0
struct upid {
nr = 964,
ns = 0xffffffff819411a0 <init_pid_ns>,
pid_chain = {
next = 0x0,
pprev = 0xffff88022ff29240
}
}
crash>
Dave