[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree

zrouter-src-freebsd at zrouter.org zrouter-src-freebsd at zrouter.org
Wed Feb 1 10:57:09 UTC 2012


details:   http://zrouter.org/hg/FreeBSD/head//rev/721f00303e2a
changeset: 329:721f00303e2a
user:      ray at terran.dlink.ua
date:      Wed Feb 01 12:37:46 2012 +0200
description:
Add kern.hintmode sysctl, ability to move static hints to kenv

diffstat:

 head/sys/kern/subr_hints.c |  73 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)

diffs (92 lines):

diff -r 9f71f5dba02d -r 721f00303e2a head/sys/kern/subr_hints.c
--- a/head/sys/kern/subr_hints.c	Wed Feb 01 12:36:49 2012 +0200
+++ b/head/sys/kern/subr_hints.c	Wed Feb 01 12:37:46 2012 +0200
@@ -29,8 +29,10 @@
 
 #include <sys/param.h>
 #include <sys/lock.h>
+#include <sys/malloc.h>
 #include <sys/mutex.h>
 #include <sys/systm.h>
+#include <sys/sysctl.h>
 #include <sys/bus.h>
 
 /*
@@ -41,6 +43,77 @@
 static int use_kenv;
 static char *hintp;
 
+static int
+sysctl_hintmode(SYSCTL_HANDLER_ARGS)
+{
+	int error, i, from_kenv, value, eqidx;
+	const char *cp;
+	char *line, *eq;
+
+	from_kenv = 0;
+	cp = kern_envp;
+
+	/* Write out the old value. */
+	error = SYSCTL_OUT(req, &hintmode, sizeof(int));
+	if (error || req->newptr == NULL)
+		return (error);
+
+	/* Read in and verify the new value. */
+	error = SYSCTL_IN(req, &value, sizeof(int));
+	if (error)
+		return (error);
+	if (value != 2)
+		/* Only accept swithing to hintmode 2 */
+		return (EINVAL);
+
+	/* Migrate from static to dynamic hints */
+	switch (hintmode) {
+	case 0:
+		if (dynamic_kenv)
+			/* Already here */
+			hintmode = value; /* XXX: Need we switch or not ? */
+			return (0);
+		from_kenv = 1;
+		cp = kern_envp;
+		break;
+	case 1:
+		cp = static_hints;
+		break;
+	case 2:
+		/* Nothing to do, hintmode already 2 */
+		return (0);
+	}
+
+	while (cp) {
+		i = strlen(cp);
+		if (i == 0)
+			break;
+		if (from_kenv) {
+			if (strncmp(cp, "hint.", 5) != 0)
+				/* kenv can have not only hints */
+				continue;
+		}
+		eq = strchr(cp, '=');
+		if (!eq)
+			/* Bad hint value */
+			continue;
+		eqidx = eq - cp;
+
+		line = malloc(i+1, M_TEMP, M_WAITOK);
+		strcpy(line, cp);
+		line[eqidx] = '\0';
+		setenv(line, line + eqidx + 1);
+		free(line, M_TEMP);
+		cp += i + 1;
+	}
+
+	hintmode = value;
+	return (0);
+}
+
+SYSCTL_PROC(_kern, OID_AUTO, hintmode, CTLTYPE_INT|CTLFLAG_RW,
+    &hintmode, 0, sysctl_hintmode, "I", "get/set hintmode");
+
 /*
  * Evil wildcarding resource string lookup.
  * This walks the supplied env string table and returns a match.


More information about the Zrouter-src-freebsd mailing list