Simpler Vimage sysctls

James Gritton jamie at gritton.org
Fri Jul 11 16:18:27 UTC 2008


While working on combining jail_set and Vimage, I found that the sysctl 
virtualization hacks were more complicated than they needed to be.

The extra "subs" and "mod" arguments in SYSCTL_HANDLER_V_ARGS don't need 
to be explicitly passed because they're members of the sysctl_v_oid 
structure passed in the oidp argument.  By using oidp->oid_v_subs 
instead of subs (and same for mod), SYSCTL_HANDLER_V_ARGS becomes the 
same as SYSCTL_HANDLER_ARGS, and no longer need to be defined.

With the handlers now taking the same arguments, the sysctl_oid and 
sysctl_v_oid structures become identical and sysctl_v_oid can go away.

Unrelated to this is the various SYSCTL_V_XXX macros that refer to 
either SYSCTL_V_OID or SYSCTL_OID depending on the VIMAGE define.  Since 
SYSCTL_V_OID already reduces to SYSCTL_OID if VIMAGE is undefined, those 
further switches are unnecessary.

I'm including a diff that trims all this away, while keeping the same 
functionality.

- Jamie
-------------- next part --------------
diff -r -u ov/src/sys/kern/kern_sysctl.c src/sys/kern/kern_sysctl.c
--- ov/src/sys/kern/kern_sysctl.c	Wed Jul  9 14:14:02 2008
+++ src/sys/kern/kern_sysctl.c	Fri Jul 11 00:53:50 2008
@@ -849,7 +849,7 @@
 
 #ifdef VIMAGE
 int
-sysctl_handle_v_int(SYSCTL_HANDLER_V_ARGS)
+sysctl_handle_v_int(SYSCTL_HANDLER_ARGS)
 {
 	int tmpout, error = 0;
 
@@ -1009,7 +1009,7 @@
 
 #ifdef VIMAGE
 int
-sysctl_handle_v_string(SYSCTL_HANDLER_V_ARGS)
+sysctl_handle_v_string(SYSCTL_HANDLER_ARGS)
 {
 	int error=0;
 	char *tmparg;
@@ -1088,7 +1088,7 @@
 
 #ifdef VIMAGE
 int
-sysctl_handle_v_opaque(SYSCTL_HANDLER_V_ARGS)
+sysctl_handle_v_opaque(SYSCTL_HANDLER_ARGS)
 {
 	int error, tries;
 	u_int generation;
@@ -1421,17 +1421,7 @@
 	if (error != 0)
 		return (error);
 #endif
-#ifndef VIMAGE
 	error = oid->oid_handler(oid, arg1, arg2, req);
-#else
-	if (oid->oid_v_subs) {
-		struct sysctl_v_oid *v_oid = (struct sysctl_v_oid *) oid;
-		error = v_oid->oid_handler(oid, arg1, arg2,
-					   req, oid->oid_v_subs,
-					   oid->oid_v_mod);
-	} else 
-		error = oid->oid_handler(oid, arg1, arg2, req);
-#endif
 
 	return (error);
 }
diff -r -u ov/src/sys/netinet/in_pcb.c src/sys/netinet/in_pcb.c
--- ov/src/sys/netinet/in_pcb.c	Wed Jul  9 14:14:48 2008
+++ src/sys/netinet/in_pcb.c	Fri Jul 11 00:27:08 2008
@@ -121,11 +121,7 @@
 	else if ((var) > (max)) { (var) = (max); }
 
 static int
-#ifndef VIMAGE
 sysctl_net_ipport_check(SYSCTL_HANDLER_ARGS)
-#else
-sysctl_net_ipport_check(SYSCTL_HANDLER_V_ARGS)
-#endif
 {
 #ifdef VIMAGE
 	INIT_VNET_INET(curvnet);
diff -r -u ov/src/sys/netinet/ip_fw2.c src/sys/netinet/ip_fw2.c
--- ov/src/sys/netinet/ip_fw2.c	Wed Jul  9 14:14:49 2008
+++ src/sys/netinet/ip_fw2.c	Fri Jul 11 00:27:29 2008
@@ -157,11 +157,7 @@
 static int autoinc_step;
 #endif
 
-#ifdef VIMAGE
-extern int ipfw_chg_hook(SYSCTL_HANDLER_V_ARGS);
-#else
 extern int ipfw_chg_hook(SYSCTL_HANDLER_ARGS);
-#endif
 
 #ifdef SYSCTL_NODE
 SYSCTL_NODE(_net_inet_ip, OID_AUTO, fw, CTLFLAG_RW, 0, "Firewall");
diff -r -u ov/src/sys/netinet/ip_fw_pfil.c src/sys/netinet/ip_fw_pfil.c
--- ov/src/sys/netinet/ip_fw_pfil.c	Wed Jul  9 14:14:49 2008
+++ src/sys/netinet/ip_fw_pfil.c	Fri Jul 11 00:27:54 2008
@@ -75,11 +75,7 @@
 # endif
 #endif
 
-#ifdef VIMAGE
-int ipfw_chg_hook(SYSCTL_HANDLER_V_ARGS);
-#else
 int ipfw_chg_hook(SYSCTL_HANDLER_ARGS);
-#endif
 
 /* Dummynet hooks. */
 ip_dn_ruledel_t	*ip_dn_ruledel_ptr = NULL;
@@ -493,11 +489,7 @@
 #endif /* INET6 */
 
 int
-#ifdef VIMAGE
-ipfw_chg_hook(SYSCTL_HANDLER_V_ARGS)
-#else
 ipfw_chg_hook(SYSCTL_HANDLER_ARGS)
-#endif
 {
 #ifdef VIMAGE
 	INIT_VNET_IPFW(curvnet);
diff -r -u ov/src/sys/netinet6/in6_proto.c src/sys/netinet6/in6_proto.c
--- ov/src/sys/netinet6/in6_proto.c	Wed Jul  9 14:14:55 2008
+++ src/sys/netinet6/in6_proto.c	Fri Jul 11 00:28:18 2008
@@ -450,11 +450,7 @@
 
 /* net.inet6.ip6 */
 static int
-#ifdef VIMAGE
-sysctl_ip6_temppltime(SYSCTL_HANDLER_V_ARGS)
-#else
 sysctl_ip6_temppltime(SYSCTL_HANDLER_ARGS)
-#endif
 {
 	INIT_VNET_INET6(curvnet);
 #ifdef VIMAGE
@@ -477,11 +473,7 @@
 }
 
 static int
-#ifdef VIMAGE
-sysctl_ip6_tempvltime(SYSCTL_HANDLER_V_ARGS)
-#else
 sysctl_ip6_tempvltime(SYSCTL_HANDLER_ARGS)
-#endif
 {
 	INIT_VNET_INET6(curvnet);
 #ifdef VIMAGE
diff -r -u ov/src/sys/sys/sysctl.h src/sys/sys/sysctl.h
--- ov/src/sys/sys/sysctl.h	Wed Jul  9 14:15:24 2008
+++ src/sys/sys/sysctl.h	Fri Jul 11 00:53:23 2008
@@ -115,9 +115,6 @@
 #define SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1, int arg2, \
 	struct sysctl_req *req
 
-#define SYSCTL_HANDLER_V_ARGS struct sysctl_oid *oidp, void *arg1, int arg2, \
-	struct sysctl_req *req, int subs, int mod
-
 /* definitions for sysctl_req 'lock' member */
 #define REQ_UNLOCKED	0	/* not locked and not wired */
 #define REQ_LOCKED	1	/* locked and not wired */
@@ -169,22 +166,6 @@
 	short		oid_v_mod;
 };
 
-struct sysctl_v_oid {
-	struct sysctl_oid_list *oid_parent;
-	SLIST_ENTRY(sysctl_oid) oid_link;
-	int		oid_number;
-	u_int		oid_kind;
-	void		*oid_arg1;
-	int		oid_arg2;
-	const char	*oid_name;
-	int 		(*oid_handler)(SYSCTL_HANDLER_V_ARGS);
-	const char	*oid_fmt;
-	int		oid_refcnt;
-	const char	*oid_descr;
-	short		oid_v_subs;
-	short		oid_v_mod;
-};
-
 #define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l)
 #define SYSCTL_OUT(r, p, l) (r->oldfunc)(r, p, l)
 
@@ -196,9 +177,9 @@
 int sysctl_handle_string(SYSCTL_HANDLER_ARGS);
 int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
 
-int sysctl_handle_v_int(SYSCTL_HANDLER_V_ARGS);
-int sysctl_handle_v_string(SYSCTL_HANDLER_V_ARGS);
-int sysctl_handle_v_opaque(SYSCTL_HANDLER_V_ARGS);
+int sysctl_handle_v_int(SYSCTL_HANDLER_ARGS);
+int sysctl_handle_v_string(SYSCTL_HANDLER_ARGS);
+int sysctl_handle_v_opaque(SYSCTL_HANDLER_ARGS);
 
 /*
  * These functions are used to add/remove an oid from the mib.
@@ -247,7 +228,7 @@
 #ifdef VIMAGE
 #define SYSCTL_V_OID(subs, mod, parent, nbr, name, kind, a1, a2,	 \
 		     handler, fmt, descr)				 \
-	static struct sysctl_v_oid sysctl__##parent##_##name = {	 \
+	static struct sysctl_oid sysctl__##parent##_##name = {	 \
 		&sysctl_##parent##_children, { 0 }, nbr, kind,		 \
 		(void *) offsetof(struct mod, _##a1), a2, #name,	 \
 		handler, fmt, 0,  __DESCR(descr), subs, V_MOD_##mod };	 \
@@ -277,15 +258,9 @@
 	SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access), \
 		arg, len, sysctl_handle_string, "A", descr)
 
-#ifdef VIMAGE
 #define SYSCTL_V_STRING(subs, mod, parent, nbr, name, access, sym, len, descr) \
 	SYSCTL_V_OID(subs, mod, parent, nbr, name, CTLTYPE_STRING|(access), \
 		sym, len, sysctl_handle_v_string, "A", descr)
-#else
-#define SYSCTL_V_STRING(subs, mod, parent, nbr, name, access, sym, len, descr) \
-	SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access), \
-		&sym, len, sysctl_handle_string, "A", descr)
-#endif
 
 #define SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr)  \
 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access),	    \
@@ -296,15 +271,9 @@
 	SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|(access), \
 		ptr, val, sysctl_handle_int, "I", descr)
 
-#ifdef VIMAGE
 #define SYSCTL_V_INT(subs, mod, parent, nbr, name, access, sym, val, descr) \
 	SYSCTL_V_OID(subs, mod, parent, nbr, name, CTLTYPE_INT|(access), \
 		sym, val, sysctl_handle_v_int, "I", descr)
-#else
-#define SYSCTL_V_INT(subs, mod, parent, nbr, name, access, sym, val, descr) \
-	SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|(access), \
-		&sym, val, sysctl_handle_int, "I", descr)
-#endif
 
 #define SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr)	    \
 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_INT|(access),	    \
@@ -368,19 +337,11 @@
 		ptr, sizeof(struct type), sysctl_handle_opaque, \
 		"S," #type, descr)
 
-#ifdef VIMAGE
 #define SYSCTL_V_STRUCT(subs, mod, parent, nbr, name, access, sym, \
 		type, descr) \
 	SYSCTL_V_OID(subs, mod, parent, nbr, name, CTLTYPE_OPAQUE|(access), \
 		sym, sizeof(struct type), sysctl_handle_v_opaque, \
 		"S," #type, descr)
-#else
-#define SYSCTL_V_STRUCT(subs, mod, parent, nbr, name, access, sym, \
-		type, descr) \
-	SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), \
-		&sym, sizeof(struct type), sysctl_handle_opaque, \
-		"S," #type, descr)
-#endif
 
 #define SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \
 	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access),	    \
@@ -391,17 +352,10 @@
 	SYSCTL_OID(parent, nbr, name, (access), \
 		ptr, arg, handler, fmt, descr)
 
-#ifdef VIMAGE
 #define SYSCTL_V_PROC(subs, mod, parent, nbr, name, access, sym, arg, \
 		handler, fmt, descr) \
 	SYSCTL_V_OID(subs, mod, parent, nbr, name, (access), \
 		sym, arg, handler, fmt, descr)
-#else
-#define SYSCTL_V_PROC(subs, mod, parent, nbr, name, access, sym, arg, \
-		handler, fmt, descr) \
-	SYSCTL_OID(parent, nbr, name, (access), \
-		&sym, arg, handler, fmt, descr)
-#endif
 
 #define SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
 	sysctl_add_oid(ctx, parent, nbr, name, (access),			    \
@@ -420,9 +374,10 @@
 #ifdef VIMAGE
 #define SYSCTL_RESOLVE_V_ARG1() do {					\
 	char *cp;							\
-	switch (subs) {							\
+	switch (oidp->oid_v_subs) {					\
 	case V_NET:							\
-		cp = (char *) TD_TO_VNET(curthread)->mod_data[mod];	\
+		cp = (char *)						\
+		    TD_TO_VNET(curthread)->mod_data[oidp->oid_v_mod];	\
 		break;							\
 	case V_PROCG:							\
 		cp = (char *) TD_TO_VPROCG(curthread);			\
@@ -431,7 +386,7 @@
 		cp = (char *) TD_TO_VCPU(curthread);			\
 		break;							\
 	default:							\
-		panic("unsupported module id %d", subs);		\
+		panic("unsupported module id %d", oidp->oid_v_subs);	\
 	}								\
 	arg1 = cp + (size_t) arg1;					\
 } while (0)


More information about the freebsd-virtualization mailing list