[CRIU] [PATCH v2] net/sysctl: remove excess type conversions for sysctl_entry.type

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Fri May 20 06:35:58 PDT 2016


use native SYSCTL_TYPE__CTL_32 and SYSCTL_TYPE__CTL_STR

v2: add BUILD_BUG_ONS to check SysctlType constants are equal to
__CTL_STR and CTL_32, change __CTL_STR to CTL_STR in SysctlType enum.

Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 criu/crtools.c      |  3 +++
 criu/net.c          | 29 +++++++++++++++--------------
 images/sysctl.proto |  4 ++--
 3 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/criu/crtools.c b/criu/crtools.c
index 7a0f977..04f17e4 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -46,6 +46,7 @@
 #include "proc_parse.h"
 #include "syscall-types.h"
 #include "setproctitle.h"
+#include "sysctl.h"
 
 struct cr_options opts;
 
@@ -324,6 +325,8 @@ int main(int argc, char *argv[], char *envp[])
 	};
 
 	BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE);
+	BUILD_BUG_ON(CTL_32 != SYSCTL_TYPE__CTL_32);
+	BUILD_BUG_ON(__CTL_STR != SYSCTL_TYPE__CTL_STR);
 
 	if (fault_injection_init())
 		return 1;
diff --git a/criu/net.c b/criu/net.c
index 59c1161..d3b659a 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -66,11 +66,12 @@ static bool sysctl_entries_equal(SysctlEntry *a, SysctlEntry *b)
 	if (a->type != b->type)
 		return false;
 
-	switch (CTL_TYPE(a->type)) {
-		case CTL_32:
+	switch (a->type) {
+		case SYSCTL_TYPE__CTL_32:
 			return a->has_iarg && b->has_iarg && a->iarg == b->iarg;
-		case __CTL_STR:
+		case SYSCTL_TYPE__CTL_STR:
 			return a->sarg && b->sarg && !strcmp(a->sarg, b->sarg);
+		default:;
 	}
 
 	return false;
@@ -191,8 +192,8 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto
 
 		snprintf(path[i], MAX_CONF_OPT_PATH, CONF_OPT_PATH, proto, tgt, devconfs[i]);
 		req[ri].name = path[i];
-		switch (CTL_TYPE(conf[i]->type)) {
-			case CTL_32:
+		switch (conf[i]->type) {
+			case SYSCTL_TYPE__CTL_32:
 				req[ri].type = CTL_32;
 
 				/* skip non-existing sysctl */
@@ -201,7 +202,7 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto
 
 				req[ri].arg = &conf[i]->iarg;
 				break;
-			case __CTL_STR:
+			case SYSCTL_TYPE__CTL_STR:
 				req[ri].type = CTL_STR(MAX_STR_CONF_LEN);
 				flags |= op == CTL_READ && !strcmp(devconfs[i], "stable_secret")
 					? CTL_FLAGS_READ_EIO_SKIP : 0;
@@ -230,10 +231,10 @@ static int net_conf_op(char *tgt, SysctlEntry **conf, int n, int op, char *proto
 		/* (un)mark (non-)existing sysctls in image */
 		for (i = 0; i < ri; i++)
 			if (req[i].flags & CTL_FLAGS_HAS) {
-				if (CTL_TYPE(rconf[i]->type) == CTL_32)
+				if (rconf[i]->type == SYSCTL_TYPE__CTL_32)
 					rconf[i]->has_iarg = true;
 			} else {
-				if (CTL_TYPE(rconf[i]->type) == __CTL_STR)
+				if (rconf[i]->type == SYSCTL_TYPE__CTL_STR)
 					rconf[i]->sarg = NULL;
 			}
 	}
@@ -380,9 +381,9 @@ static int dump_one_netdev(int type, struct ifinfomsg *ifi,
 		sysctl_entry__init(&confs6[i]);
 		netdev.conf6[i] = &confs6[i];
 		if (strcmp(devconfs6[i], "stable_secret")) {
-			netdev.conf6[i]->type = CTL_32;
+			netdev.conf6[i]->type = SYSCTL_TYPE__CTL_32;
 		} else {
-			netdev.conf6[i]->type = __CTL_STR;
+			netdev.conf6[i]->type = SYSCTL_TYPE__CTL_STR;
 			netdev.conf6[i]->sarg = stable_secret;
 		}
 	}
@@ -1179,11 +1180,11 @@ static int dump_netns_conf(struct cr_imgset *fds)
 		netns.def_conf6[i] = &def_confs6[i];
 		netns.all_conf6[i] = &all_confs6[i];
 		if (strcmp(devconfs6[i], "stable_secret")) {
-			netns.def_conf6[i]->type = CTL_32;
-			netns.all_conf6[i]->type = CTL_32;
+			netns.def_conf6[i]->type = SYSCTL_TYPE__CTL_32;
+			netns.all_conf6[i]->type = SYSCTL_TYPE__CTL_32;
 		} else {
-			netns.def_conf6[i]->type = __CTL_STR;
-			netns.all_conf6[i]->type = __CTL_STR;
+			netns.def_conf6[i]->type = SYSCTL_TYPE__CTL_STR;
+			netns.all_conf6[i]->type = SYSCTL_TYPE__CTL_STR;
 			netns.def_conf6[i]->sarg = def_stable_secret;
 			netns.all_conf6[i]->sarg = all_stable_secret;
 		}
diff --git a/images/sysctl.proto b/images/sysctl.proto
index c64789a..3b78c8f 100644
--- a/images/sysctl.proto
+++ b/images/sysctl.proto
@@ -1,6 +1,6 @@
 enum SysctlType {
-	__CTL_STR	= 5;
-	CTL_32		= 6;
+	CTL_STR	= 5;
+	CTL_32	= 6;
 }
 
 message sysctl_entry {
-- 
2.5.5



More information about the CRIU mailing list