Commit 256d61b8 authored by Patrick McHardy's avatar Patrick McHardy Committed by David S. Miller

[NET_SCHED]: Fix endless loops (part 4): HTB

Convert HTB to use qdisc_tree_decrease_len() and add a callback
for deactivating a class when its child queue becomes empty.
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f973b913
...@@ -1230,11 +1230,7 @@ static int htb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -1230,11 +1230,7 @@ static int htb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
return -ENOBUFS; return -ENOBUFS;
sch_tree_lock(sch); sch_tree_lock(sch);
if ((*old = xchg(&cl->un.leaf.q, new)) != NULL) { if ((*old = xchg(&cl->un.leaf.q, new)) != NULL) {
if (cl->prio_activity) qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
htb_deactivate(qdisc_priv(sch), cl);
/* TODO: is it correct ? Why CBQ doesn't do it ? */
sch->q.qlen -= (*old)->q.qlen;
qdisc_reset(*old); qdisc_reset(*old);
} }
sch_tree_unlock(sch); sch_tree_unlock(sch);
...@@ -1249,6 +1245,14 @@ static struct Qdisc *htb_leaf(struct Qdisc *sch, unsigned long arg) ...@@ -1249,6 +1245,14 @@ static struct Qdisc *htb_leaf(struct Qdisc *sch, unsigned long arg)
return (cl && !cl->level) ? cl->un.leaf.q : NULL; return (cl && !cl->level) ? cl->un.leaf.q : NULL;
} }
static void htb_qlen_notify(struct Qdisc *sch, unsigned long arg)
{
struct htb_class *cl = (struct htb_class *)arg;
if (cl->un.leaf.q->q.qlen == 0)
htb_deactivate(qdisc_priv(sch), cl);
}
static unsigned long htb_get(struct Qdisc *sch, u32 classid) static unsigned long htb_get(struct Qdisc *sch, u32 classid)
{ {
struct htb_class *cl = htb_find(classid, sch); struct htb_class *cl = htb_find(classid, sch);
...@@ -1323,6 +1327,7 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg) ...@@ -1323,6 +1327,7 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg)
{ {
struct htb_sched *q = qdisc_priv(sch); struct htb_sched *q = qdisc_priv(sch);
struct htb_class *cl = (struct htb_class *)arg; struct htb_class *cl = (struct htb_class *)arg;
unsigned int qlen;
// TODO: why don't allow to delete subtree ? references ? does // TODO: why don't allow to delete subtree ? references ? does
// tc subsys quarantee us that in htb_destroy it holds no class // tc subsys quarantee us that in htb_destroy it holds no class
...@@ -1336,8 +1341,9 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg) ...@@ -1336,8 +1341,9 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg)
hlist_del_init(&cl->hlist); hlist_del_init(&cl->hlist);
if (!cl->level) { if (!cl->level) {
sch->q.qlen -= cl->un.leaf.q->q.qlen; qlen = cl->un.leaf.q->q.qlen;
qdisc_reset(cl->un.leaf.q); qdisc_reset(cl->un.leaf.q);
qdisc_tree_decrease_qlen(cl->un.leaf.q, qlen);
} }
if (cl->prio_activity) if (cl->prio_activity)
...@@ -1419,8 +1425,11 @@ static int htb_change_class(struct Qdisc *sch, u32 classid, ...@@ -1419,8 +1425,11 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
new_q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops, classid); new_q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops, classid);
sch_tree_lock(sch); sch_tree_lock(sch);
if (parent && !parent->level) { if (parent && !parent->level) {
unsigned int qlen = parent->un.leaf.q->q.qlen;
/* turn parent into inner node */ /* turn parent into inner node */
sch->q.qlen -= parent->un.leaf.q->q.qlen; qdisc_reset(parent->un.leaf.q);
qdisc_tree_decrease_qlen(parent->un.leaf.q, qlen);
qdisc_destroy(parent->un.leaf.q); qdisc_destroy(parent->un.leaf.q);
if (parent->prio_activity) if (parent->prio_activity)
htb_deactivate(q, parent); htb_deactivate(q, parent);
...@@ -1568,6 +1577,7 @@ static void htb_walk(struct Qdisc *sch, struct qdisc_walker *arg) ...@@ -1568,6 +1577,7 @@ static void htb_walk(struct Qdisc *sch, struct qdisc_walker *arg)
static struct Qdisc_class_ops htb_class_ops = { static struct Qdisc_class_ops htb_class_ops = {
.graft = htb_graft, .graft = htb_graft,
.leaf = htb_leaf, .leaf = htb_leaf,
.qlen_notify = htb_qlen_notify,
.get = htb_get, .get = htb_get,
.put = htb_put, .put = htb_put,
.change = htb_change_class, .change = htb_change_class,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment