Skip to content

Commit 86a7996

Browse files
congwangdavem330
authored andcommitted
net_sched: introduce qdisc_replace() helper
Remove nearly duplicated code and prepare for the following patch. Cc: Jamal Hadi Salim <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Signed-off-by: Cong Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f12d33f commit 86a7996

File tree

13 files changed

+29
-78
lines changed

13 files changed

+29
-78
lines changed

include/net/sch_generic.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,23 @@ static inline void qdisc_reset_queue(struct Qdisc *sch)
707707
sch->qstats.backlog = 0;
708708
}
709709

710+
static inline struct Qdisc *qdisc_replace(struct Qdisc *sch, struct Qdisc *new,
711+
struct Qdisc **pold)
712+
{
713+
struct Qdisc *old;
714+
715+
sch_tree_lock(sch);
716+
old = *pold;
717+
*pold = new;
718+
if (old != NULL) {
719+
qdisc_tree_decrease_qlen(old, old->q.qlen);
720+
qdisc_reset(old);
721+
}
722+
sch_tree_unlock(sch);
723+
724+
return old;
725+
}
726+
710727
static inline unsigned int __qdisc_queue_drop(struct Qdisc *sch,
711728
struct sk_buff_head *list)
712729
{

net/sched/sch_cbq.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,13 +1624,8 @@ static int cbq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
16241624
new->reshape_fail = cbq_reshape_fail;
16251625
#endif
16261626
}
1627-
sch_tree_lock(sch);
1628-
*old = cl->q;
1629-
cl->q = new;
1630-
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
1631-
qdisc_reset(*old);
1632-
sch_tree_unlock(sch);
16331627

1628+
*old = qdisc_replace(sch, new, &cl->q);
16341629
return 0;
16351630
}
16361631

net/sched/sch_drr.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,7 @@ static int drr_graft_class(struct Qdisc *sch, unsigned long arg,
226226
new = &noop_qdisc;
227227
}
228228

229-
sch_tree_lock(sch);
230-
drr_purge_queue(cl);
231-
*old = cl->qdisc;
232-
cl->qdisc = new;
233-
sch_tree_unlock(sch);
229+
*old = qdisc_replace(sch, new, &cl->qdisc);
234230
return 0;
235231
}
236232

net/sched/sch_dsmark.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,7 @@ static int dsmark_graft(struct Qdisc *sch, unsigned long arg,
7373
new = &noop_qdisc;
7474
}
7575

76-
sch_tree_lock(sch);
77-
*old = p->q;
78-
p->q = new;
79-
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
80-
qdisc_reset(*old);
81-
sch_tree_unlock(sch);
82-
76+
*old = qdisc_replace(sch, new, &p->q);
8377
return 0;
8478
}
8579

net/sched/sch_hfsc.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,11 +1215,7 @@ hfsc_graft_class(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
12151215
new = &noop_qdisc;
12161216
}
12171217

1218-
sch_tree_lock(sch);
1219-
hfsc_purge_queue(sch, cl);
1220-
*old = cl->qdisc;
1221-
cl->qdisc = new;
1222-
sch_tree_unlock(sch);
1218+
*old = qdisc_replace(sch, new, &cl->qdisc);
12231219
return 0;
12241220
}
12251221

net/sched/sch_htb.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,14 +1163,7 @@ static int htb_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
11631163
cl->common.classid)) == NULL)
11641164
return -ENOBUFS;
11651165

1166-
sch_tree_lock(sch);
1167-
*old = cl->un.leaf.q;
1168-
cl->un.leaf.q = new;
1169-
if (*old != NULL) {
1170-
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
1171-
qdisc_reset(*old);
1172-
}
1173-
sch_tree_unlock(sch);
1166+
*old = qdisc_replace(sch, new, &cl->un.leaf.q);
11741167
return 0;
11751168
}
11761169

net/sched/sch_multiq.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,7 @@ static int multiq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
303303
if (new == NULL)
304304
new = &noop_qdisc;
305305

306-
sch_tree_lock(sch);
307-
*old = q->queues[band];
308-
q->queues[band] = new;
309-
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
310-
qdisc_reset(*old);
311-
sch_tree_unlock(sch);
312-
306+
*old = qdisc_replace(sch, new, &q->queues[band]);
313307
return 0;
314308
}
315309

net/sched/sch_netem.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,15 +1037,7 @@ static int netem_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
10371037
{
10381038
struct netem_sched_data *q = qdisc_priv(sch);
10391039

1040-
sch_tree_lock(sch);
1041-
*old = q->qdisc;
1042-
q->qdisc = new;
1043-
if (*old) {
1044-
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
1045-
qdisc_reset(*old);
1046-
}
1047-
sch_tree_unlock(sch);
1048-
1040+
*old = qdisc_replace(sch, new, &q->qdisc);
10491041
return 0;
10501042
}
10511043

net/sched/sch_prio.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,7 @@ static int prio_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
268268
if (new == NULL)
269269
new = &noop_qdisc;
270270

271-
sch_tree_lock(sch);
272-
*old = q->queues[band];
273-
q->queues[band] = new;
274-
qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
275-
qdisc_reset(*old);
276-
sch_tree_unlock(sch);
277-
271+
*old = qdisc_replace(sch, new, &q->queues[band]);
278272
return 0;
279273
}
280274

net/sched/sch_qfq.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,7 @@ static int qfq_graft_class(struct Qdisc *sch, unsigned long arg,
617617
new = &noop_qdisc;
618618
}
619619

620-
sch_tree_lock(sch);
621-
qfq_purge_queue(cl);
622-
*old = cl->qdisc;
623-
cl->qdisc = new;
624-
sch_tree_unlock(sch);
620+
*old = qdisc_replace(sch, new, &cl->qdisc);
625621
return 0;
626622
}
627623

0 commit comments

Comments
 (0)