Skip to contentSkip to conversation

Revert tc batchsize feature

RFC In review Stephen Hemminger 2 participants 6 messages Aug 1, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Revert tc batchsize feature

The batchsize feature of tc might save a few cycles but it is a maintaince nightmare, it has uninitialized variables and poor error handling.

This patch set reverts back to the original state. Please don't resubmit original code. Go back to the drawing board and do something generic. For example, the routing daemons have figured out that by using multiple threads and turning off the netlink ACK they can update millions of routes quickly.

Stephen Hemminger (4):
Revert "tc: Remove pointless assignments in batch()" Revert "tc: flush after each command in batch mode" Revert "tc: fix batch force option"
Revert "tc: Add batchsize feature for filter and actions"

 tc/m_action.c  |  65 ++++++----------
 tc/tc.c        | 201 ++++---------------------------------------------
 tc/tc_common.h |   7 +-
 tc/tc_filter.c | 129 ++++++++++++-------------------
 4 files changed, 87 insertions(+), 315 deletions(-)
#1 lore raw

RFC 1/4 Revert "tc: Remove pointless assignments in batch()"

This reverts commit 6358bbc381c6e38465838370bcbbdeb77ec3565a.

---
 tc/tc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tc/tc.c +3 -1
index 64e342dd85bf..1f23971ae4b9 100644
@@ -326,11 +326,11 @@ static int batch(const char *name)
 	struct batch_buf *head = NULL, *tail = NULL, *buf_pool = NULL;
 	char *largv[100], *largv_next[100];
 	char *line, *line_next = NULL;
+	bool bs_enabled_next = false;
 	bool bs_enabled = false;
 	bool lastline = false;
 	int largc, largc_next;
 	bool bs_enabled_saved;
-	bool bs_enabled_next;
 	int batchsize = 0;
 	size_t len = 0;
 	int ret = 0;
@@ -359,6 +359,7 @@ static int batch(const char *name)
 		goto Exit;
 	largc = makeargs(line, largv, 100);
 	bs_enabled = batchsize_enabled(largc, largv);
+	bs_enabled_saved = bs_enabled;
 	do {
 		if (getcmdline(&line_next, &len, stdin) == -1)
 			lastline = true;
@@ -394,6 +395,7 @@ static int batch(const char *name)
 		len = 0;
 		bs_enabled_saved = bs_enabled;
 		bs_enabled = bs_enabled_next;
+		bs_enabled_next = false;
 
 		if (largc == 0) {
 			largc = largc_next;
Signature · 1 line
2.20.1
#2 lore raw

RFC 2/4 Revert "tc: flush after each command in batch mode"

In reply to Stephen Hemminger

This reverts commit d66fdfda71e4a30c1ca0ddb7b1a048bef30fe79e.

---
 tc/tc.c | 1 -
 1 file changed, 1 deletion(-)
tc/tc.c +0 -1
index 1f23971ae4b9..c115155b2234 100644
@@ -405,7 +405,6 @@ static int batch(const char *name)
 
 		err = do_cmd(largc, largv, tail == NULL ? NULL : tail->buf,
 			     tail == NULL ? 0 : sizeof(tail->buf));
-		fflush(stdout);
 		if (err != 0) {
 			fprintf(stderr, "Command failed %s:%d\n", name,
 				cmdlineno - 1);
Signature · 1 line
2.20.1
#3 lore raw

RFC 3/4 Revert "tc: fix batch force option"

In reply to Stephen Hemminger

This reverts commit b133392468d1f404077a8f3554d1f63d48bb45e8.

---
 tc/tc.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
tc/tc.c +8 -11
index c115155b2234..b7b6bd288897 100644
@@ -334,7 +334,6 @@ static int batch(const char *name)
 	int batchsize = 0;
 	size_t len = 0;
 	int ret = 0;
-	int err;
 	bool send;
 
 	batch_mode = 1;
@@ -403,9 +402,9 @@ static int batch(const char *name)
 			continue;	/* blank line */
 		}
 
-		err = do_cmd(largc, largv, tail == NULL ? NULL : tail->buf,
+		ret = do_cmd(largc, largv, tail == NULL ? NULL : tail->buf,
 			     tail == NULL ? 0 : sizeof(tail->buf));
-		if (err != 0) {
+		if (ret != 0) {
 			fprintf(stderr, "Command failed %s:%d\n", name,
 				cmdlineno - 1);
 			ret = 1;
@@ -427,17 +426,15 @@ static int batch(const char *name)
 				iov->iov_len = n->nlmsg_len;
 			}
 
-			err = rtnl_talk_iov(&rth, iovs, batchsize, NULL);
-			put_batch_bufs(&buf_pool, &head, &tail);
-			free(iovs);
-			if (err < 0) {
+			ret = rtnl_talk_iov(&rth, iovs, batchsize, NULL);
+			if (ret < 0) {
 				fprintf(stderr, "Command failed %s:%d\n", name,
-					cmdlineno - (batchsize + err) - 1);
-				ret = 1;
-				if (!force)
-					break;
+					cmdlineno - (batchsize + ret) - 1);
+				return 2;
 			}
+			put_batch_bufs(&buf_pool, &head, &tail);
 			batchsize = 0;
+			free(iovs);
 		}
 	} while (!lastline);
 
Signature · 1 line
2.20.1
#4 lore raw

RFC 4/4 Revert "tc: Add batchsize feature for filter and actions"

In reply to Stephen Hemminger

This reverts commit 485d0c6001c4aa134b99c86913d6a7089b7b2ab0.

---
 tc/m_action.c  |  65 ++++++----------
 tc/tc.c        | 199 ++++---------------------------------------------
 tc/tc_common.h |   7 +-
 tc/tc_filter.c | 129 ++++++++++++--------------------
 4 files changed, 87 insertions(+), 313 deletions(-)
tc/m_action.c +22 -43
index ab6bc0ad28ff..bdc62720879c 100644
@@ -556,61 +556,40 @@ bad_val:
 	return ret;
 }
 
-struct tc_action_req {
-	struct nlmsghdr		n;
-	struct tcamsg		t;
-	char			buf[MAX_MSG];
-};
-
 static int tc_action_modify(int cmd, unsigned int flags,
-			    int *argc_p, char ***argv_p,
-			    void *buf, size_t buflen)
+			    int *argc_p, char ***argv_p)
 {
-	struct tc_action_req *req, action_req;
-	char **argv = *argv_p;
-	struct rtattr *tail;
 	int argc = *argc_p;
-	struct iovec iov;
+	char **argv = *argv_p;
 	int ret = 0;
-
-	if (buf) {
-		req = buf;
-		if (buflen < sizeof (struct tc_action_req)) {
-			fprintf(stderr, "buffer is too small: %zu\n", buflen);
-			return -1;
-		}
-	} else {
-		memset(&action_req, 0, sizeof (struct tc_action_req));
-		req = &action_req;
-	}
-
-	req->n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg));
-	req->n.nlmsg_flags = NLM_F_REQUEST | flags;
-	req->n.nlmsg_type = cmd;
-	req->t.tca_family = AF_UNSPEC;
-	tail = NLMSG_TAIL(&req->n);
+	struct {
+		struct nlmsghdr         n;
+		struct tcamsg           t;
+		char                    buf[MAX_MSG];
+	} req = {
+		.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg)),
+		.n.nlmsg_flags = NLM_F_REQUEST | flags,
+		.n.nlmsg_type = cmd,
+		.t.tca_family = AF_UNSPEC,
+	};
+	struct rtattr *tail = NLMSG_TAIL(&req.n);
 
 	argc -= 1;
 	argv += 1;
-	if (parse_action(&argc, &argv, TCA_ACT_TAB, &req->n)) {
+	if (parse_action(&argc, &argv, TCA_ACT_TAB, &req.n)) {
 		fprintf(stderr, "Illegal \"action\"\n");
 		return -1;
 	}
-	tail->rta_len = (void *) NLMSG_TAIL(&req->n) - (void *) tail;
+	tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail;
 
-	*argc_p = argc;
-	*argv_p = argv;
-
-	if (buf)
-		return 0;
-
-	iov.iov_base = &req->n;
-	iov.iov_len = req->n.nlmsg_len;
-	if (rtnl_talk_iov(&rth, &iov, 1, NULL) < 0) {
+	if (rtnl_talk(&rth, &req.n, NULL) < 0) {
 		fprintf(stderr, "We have an error talking to the kernel\n");
 		ret = -1;
 	}
 
+	*argc_p = argc;
+	*argv_p = argv;
+
 	return ret;
 }
 
@@ -711,7 +690,7 @@ bad_val:
 	return ret;
 }
 
-int do_action(int argc, char **argv, void *buf, size_t buflen)
+int do_action(int argc, char **argv)
 {
 
 	int ret = 0;
@@ -721,12 +700,12 @@ int do_action(int argc, char **argv, void *buf, size_t buflen)
 		if (matches(*argv, "add") == 0) {
 			ret =  tc_action_modify(RTM_NEWACTION,
 						NLM_F_EXCL | NLM_F_CREATE,
-						&argc, &argv, buf, buflen);
+						&argc, &argv);
 		} else if (matches(*argv, "change") == 0 ||
 			  matches(*argv, "replace") == 0) {
 			ret = tc_action_modify(RTM_NEWACTION,
 					       NLM_F_CREATE | NLM_F_REPLACE,
-					       &argc, &argv, buf, buflen);
+					       &argc, &argv);
 		} else if (matches(*argv, "delete") == 0) {
 			argc -= 1;
 			argv += 1;
tc/tc.c +15 -184

245 lines not on this page · raw message

tc/tc_common.h +3 -4
index d8a6dfdeabd4..802fb7f01fe4 100644
@@ -1,15 +1,14 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 
 #define TCA_BUF_MAX	(64*1024)
-#define MSG_IOV_MAX	128
 
 extern struct rtnl_handle rth;
 
 int do_qdisc(int argc, char **argv);
 int do_class(int argc, char **argv);
-int do_filter(int argc, char **argv, void *buf, size_t buflen);
-int do_chain(int argc, char **argv, void *buf, size_t buflen);
-int do_action(int argc, char **argv, void *buf, size_t buflen);
+int do_filter(int argc, char **argv);
+int do_chain(int argc, char **argv);
+int do_action(int argc, char **argv);
 int do_tcmonitor(int argc, char **argv);
 int do_exec(int argc, char **argv);
 
tc/tc_filter.c +47 -82

223 lines not on this page · raw message

Signature · 1 line
2.20.1
#5 lore raw
In reply to Stephen Hemminger

Does this fix my longstanding issue with piping commands into it? :P

( https://github.com/tohojo/flent/issues/146 )

Quoted 24 lines · Stephen Hemminger

The batchsize feature of tc might save a few cycles but it is a maintaince nightmare, it has uninitialized variables and poor error handling.

This patch set reverts back to the original state. Please don't resubmit original code. Go back to the drawing board and do something generic. For example, the routing daemons have figured out that by using multiple threads and turning off the netlink ACK they can update millions of routes quickly.

Stephen Hemminger (4):
Revert "tc: Remove pointless assignments in batch()" Revert "tc: flush after each command in batch mode" Revert "tc: fix batch force option"
Revert "tc: Add batchsize feature for filter and actions"

 tc/m_action.c  |  65 ++++++----------
 tc/tc.c        | 201 ++++---------------------------------------------
 tc/tc_common.h |   7 +-
 tc/tc_filter.c | 129 ++++++++++++-------------------
 4 files changed, 87 insertions(+), 315 deletions(-)
Signature · 4 lines
Dave Täht
CTO, TekLibre, LLC
http://www.teklibre.com
Tel: 1-831-205-9740