Subject: Re: Question: how to detect if a qdisc is root or not?

From: Patrick McHardy <[email-masked]>
Date: Sun, 22 Jul 2007 18:24:16 +0200

Waskiewicz Jr, Peter P wrote:
>>I dont think I understand. Whats the problem with setting 
>>sch->parent on initialization instead on grafting as I did in 
>>my example patch?
>>Please explain the problems arrising on unload in detail.
> 
> 
> sch->parent is getting set on initialization, and for the root and
> ingress qdiscs, it's left at zero.  If I change that value, when the
> root qdisc is unloaded and pfifo_fast is put back into place, the
> qdisc_destroy() walks the tree and attempts to free memory from the
> handle pointed at by sch->parent.

First of all, qdisc destruction never propagates up, only down
the tree. Secondly neither qdisc_destroy nor pfifo nor prio
even look at sch->parent. So this is completely wrong, the only
place where sch->parent is used for walking through the tree
is qdisc_tree_decrease_qlen.

> It stops when sch->parent is NULL,

Where are you getting this? sch->parent is an *integer*.

> so
> sch->parent is actually being set as intended.  The only thing that
> confused me is that nowhere in the qdisc is TC_H_ROOT included
> explicitly, rather, the root qdisc is where sch->parent is NULL.
> 
> So I misunderstood what was actually wrong.  The qdisc code is ok as-is,
> it's just that the top-level qdisc (root and ingress) have a sch->parent
> of NULL, which is being set correctly today.
> 
> Hope that clarifies.

Not at all :)