Commit f2610da0 authored by WANG Cong's avatar WANG Cong Committed by Ben Hutchings

net_sched: introduce qdisc_replace() helper

commit 86a7996c upstream.

Remove nearly duplicated code and prepare for the following patch.

Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Acked-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 4fecee0b
...@@ -608,6 +608,23 @@ static inline void qdisc_reset_queue(struct Qdisc *sch) ...@@ -608,6 +608,23 @@ static inline void qdisc_reset_queue(struct Qdisc *sch)
sch->qstats.backlog = 0; sch->qstats.backlog = 0;
} }
static inline struct Qdisc *qdisc_replace(struct Qdisc *sch, struct Qdisc *new,
struct Qdisc **pold)
{
struct Qdisc *old;
sch_tree_lock(sch);
old = *pold;
*pold = new;
if (old != NULL) {
qdisc_tree_decrease_qlen(old, old->q.qlen);
qdisc_reset(old);
}
sch_tree_unlock(sch);
return old;
}
static inline unsigned int __qdisc_queue_drop(struct Qdisc *sch, static inline unsigned int __qdisc_queue_drop(struct Qdisc *sch,
struct sk_buff_head *list) struct sk_buff_head *list)
{ {
......
...@@ -1643,13 +1643,8 @@ static int cbq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -1643,13 +1643,8 @@ static int cbq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
new->reshape_fail = cbq_reshape_fail; new->reshape_fail = cbq_reshape_fail;
#endif #endif
} }
sch_tree_lock(sch);
*old = cl->q;
cl->q = new;
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
qdisc_reset(*old);
sch_tree_unlock(sch);
*old = qdisc_replace(sch, new, &cl->q);
return 0; return 0;
} }
......
...@@ -224,11 +224,7 @@ static int drr_graft_class(struct Qdisc *sch, unsigned long arg, ...@@ -224,11 +224,7 @@ static int drr_graft_class(struct Qdisc *sch, unsigned long arg,
new = &noop_qdisc; new = &noop_qdisc;
} }
sch_tree_lock(sch); *old = qdisc_replace(sch, new, &cl->qdisc);
drr_purge_queue(cl);
*old = cl->qdisc;
cl->qdisc = new;
sch_tree_unlock(sch);
return 0; return 0;
} }
......
...@@ -67,13 +67,7 @@ static int dsmark_graft(struct Qdisc *sch, unsigned long arg, ...@@ -67,13 +67,7 @@ static int dsmark_graft(struct Qdisc *sch, unsigned long arg,
new = &noop_qdisc; new = &noop_qdisc;
} }
sch_tree_lock(sch); *old = qdisc_replace(sch, new, &p->q);
*old = p->q;
p->q = new;
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
qdisc_reset(*old);
sch_tree_unlock(sch);
return 0; return 0;
} }
......
...@@ -1212,11 +1212,7 @@ hfsc_graft_class(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -1212,11 +1212,7 @@ hfsc_graft_class(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
new = &noop_qdisc; new = &noop_qdisc;
} }
sch_tree_lock(sch); *old = qdisc_replace(sch, new, &cl->qdisc);
hfsc_purge_queue(sch, cl);
*old = cl->qdisc;
cl->qdisc = new;
sch_tree_unlock(sch);
return 0; return 0;
} }
......
...@@ -1164,14 +1164,7 @@ static int htb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -1164,14 +1164,7 @@ static int htb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
cl->common.classid)) == NULL) cl->common.classid)) == NULL)
return -ENOBUFS; return -ENOBUFS;
sch_tree_lock(sch); *old = qdisc_replace(sch, new, &cl->un.leaf.q);
*old = cl->un.leaf.q;
cl->un.leaf.q = new;
if (*old != NULL) {
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
qdisc_reset(*old);
}
sch_tree_unlock(sch);
return 0; return 0;
} }
......
...@@ -302,13 +302,7 @@ static int multiq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -302,13 +302,7 @@ static int multiq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
if (new == NULL) if (new == NULL)
new = &noop_qdisc; new = &noop_qdisc;
sch_tree_lock(sch); *old = qdisc_replace(sch, new, &q->queues[band]);
*old = q->queues[band];
q->queues[band] = new;
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
qdisc_reset(*old);
sch_tree_unlock(sch);
return 0; return 0;
} }
......
...@@ -1050,15 +1050,7 @@ static int netem_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -1050,15 +1050,7 @@ static int netem_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
{ {
struct netem_sched_data *q = qdisc_priv(sch); struct netem_sched_data *q = qdisc_priv(sch);
sch_tree_lock(sch); *old = qdisc_replace(sch, new, &q->qdisc);
*old = q->qdisc;
q->qdisc = new;
if (*old) {
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
qdisc_reset(*old);
}
sch_tree_unlock(sch);
return 0; return 0;
} }
......
...@@ -266,13 +266,7 @@ static int prio_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -266,13 +266,7 @@ static int prio_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
if (new == NULL) if (new == NULL)
new = &noop_qdisc; new = &noop_qdisc;
sch_tree_lock(sch); *old = qdisc_replace(sch, new, &q->queues[band]);
*old = q->queues[band];
q->queues[band] = new;
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
qdisc_reset(*old);
sch_tree_unlock(sch);
return 0; return 0;
} }
......
...@@ -616,11 +616,7 @@ static int qfq_graft_class(struct Qdisc *sch, unsigned long arg, ...@@ -616,11 +616,7 @@ static int qfq_graft_class(struct Qdisc *sch, unsigned long arg,
new = &noop_qdisc; new = &noop_qdisc;
} }
sch_tree_lock(sch); *old = qdisc_replace(sch, new, &cl->qdisc);
qfq_purge_queue(cl);
*old = cl->qdisc;
cl->qdisc = new;
sch_tree_unlock(sch);
return 0; return 0;
} }
......
...@@ -313,12 +313,7 @@ static int red_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -313,12 +313,7 @@ static int red_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
if (new == NULL) if (new == NULL)
new = &noop_qdisc; new = &noop_qdisc;
sch_tree_lock(sch); *old = qdisc_replace(sch, new, &q->qdisc);
*old = q->qdisc;
q->qdisc = new;
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
qdisc_reset(*old);
sch_tree_unlock(sch);
return 0; return 0;
} }
......
...@@ -612,12 +612,7 @@ static int sfb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -612,12 +612,7 @@ static int sfb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
if (new == NULL) if (new == NULL)
new = &noop_qdisc; new = &noop_qdisc;
sch_tree_lock(sch); *old = qdisc_replace(sch, new, &q->qdisc);
*old = q->qdisc;
q->qdisc = new;
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
qdisc_reset(*old);
sch_tree_unlock(sch);
return 0; return 0;
} }
......
...@@ -501,13 +501,7 @@ static int tbf_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new, ...@@ -501,13 +501,7 @@ static int tbf_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
if (new == NULL) if (new == NULL)
new = &noop_qdisc; new = &noop_qdisc;
sch_tree_lock(sch); *old = qdisc_replace(sch, new, &q->qdisc);
*old = q->qdisc;
q->qdisc = new;
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
qdisc_reset(*old);
sch_tree_unlock(sch);
return 0; return 0;
} }
......
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