Commit 3f5b606d authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'refactor-duplicate-codes-in-the-qdisc-class-walk-function'

Zhengchao Shao says:

====================
refactor duplicate codes in the qdisc class walk function

The walk implementation of most qdisc class modules is basically the
same. That is, the values of count and skip are checked first. If count
is greater than or equal to skip, the registered fn function is
executed. Otherwise, increase the value of count. So the code can be
refactored.

The walk function is invoked during dump. Therefore, test cases related
 to the tdc filter need to be added.
====================

Link: https://lore.kernel.org/r/20220921024040.385296-1-shaozhengchao@huawei.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents a2c2a4dd d3f83254
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -222,4 +222,17 @@ static inline struct tc_skb_cb *tc_skb_cb(const struct sk_buff *skb)
	return cb;
}

static inline bool tc_qdisc_stats_dump(struct Qdisc *sch,
				       unsigned long cl,
				       struct qdisc_walker *arg)
{
	if (arg->count >= arg->skip && arg->fn(sch, cl, arg) < 0) {
		arg->stop = 1;
		return false;
	}

	arg->count++;
	return true;
}

#endif
+1 −5
Original line number Diff line number Diff line
@@ -354,13 +354,9 @@ static void atm_tc_walk(struct Qdisc *sch, struct qdisc_walker *walker)
	if (walker->stop)
		return;
	list_for_each_entry(flow, &p->flows, list) {
		if (walker->count >= walker->skip &&
		    walker->fn(sch, (unsigned long)flow, walker) < 0) {
			walker->stop = 1;
		if (!tc_qdisc_stats_dump(sch, (unsigned long)flow, walker))
			break;
	}
		walker->count++;
	}
}

static struct tcf_block *atm_tc_tcf_block(struct Qdisc *sch, unsigned long cl,
+3 −6
Original line number Diff line number Diff line
@@ -3061,17 +3061,14 @@ static void cake_walk(struct Qdisc *sch, struct qdisc_walker *arg)
		struct cake_tin_data *b = &q->tins[q->tin_order[i]];

		for (j = 0; j < CAKE_QUEUES; j++) {
			if (list_empty(&b->flows[j].flowchain) ||
			    arg->count < arg->skip) {
			if (list_empty(&b->flows[j].flowchain)) {
				arg->count++;
				continue;
			}
			if (arg->fn(sch, i * CAKE_QUEUES + j + 1, arg) < 0) {
				arg->stop = 1;
			if (!tc_qdisc_stats_dump(sch, i * CAKE_QUEUES + j + 1,
						 arg))
				break;
		}
			arg->count++;
		}
	}
}

+1 −8
Original line number Diff line number Diff line
@@ -1676,16 +1676,9 @@ static void cbq_walk(struct Qdisc *sch, struct qdisc_walker *arg)

	for (h = 0; h < q->clhash.hashsize; h++) {
		hlist_for_each_entry(cl, &q->clhash.hash[h], common.hnode) {
			if (arg->count < arg->skip) {
				arg->count++;
				continue;
			}
			if (arg->fn(sch, (unsigned long)cl, arg) < 0) {
				arg->stop = 1;
			if (!tc_qdisc_stats_dump(sch, (unsigned long)cl, arg))
				return;
		}
			arg->count++;
		}
	}
}

+1 −7
Original line number Diff line number Diff line
@@ -520,13 +520,7 @@ static unsigned long cbs_find(struct Qdisc *sch, u32 classid)
static void cbs_walk(struct Qdisc *sch, struct qdisc_walker *walker)
{
	if (!walker->stop) {
		if (walker->count >= walker->skip) {
			if (walker->fn(sch, 1, walker) < 0) {
				walker->stop = 1;
				return;
			}
		}
		walker->count++;
		tc_qdisc_stats_dump(sch, 1, walker);
	}
}

Loading