aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/subr_hints.c
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2018-06-21 14:04:02 +0000
committerKyle Evans <kevans@FreeBSD.org>2018-06-21 14:04:02 +0000
commit770488d2026afd1b21c921be2c2100c12229ce0a (patch)
treed2c548cba3da545cfc7059d108a6a6d1460d76ad /sys/kern/subr_hints.c
parentc43e3c865939237d8c2e7230f17419e006936039 (diff)
downloadsrc-770488d2026afd1b21c921be2c2100c12229ce0a.tar.gz
src-770488d2026afd1b21c921be2c2100c12229ce0a.zip
subr_hints: simplify a little bit
Some complexity exists in these bits that isn't needed. The sysctl handler, upon change to '2', runs through the current set of hints and sets them in the kenv. However, this isn't at all necessary if we're pulling hints from the kenv, static or dynamic, as the former will get added to the latter in init_dynamic_kenv (see: kern_environment.c). We can reduce this configuration to just adding static_hints to the kenv if we were previously using them. The changes in res_find are minimal and based on the observation that once use_kenv gets set to '1' it will never be reset to '0', and it gets set to '1' as soon as we hit fallback mode. Later work will refactor res_find a little bit and eliminate this now-local, because it's become clear that there's some funkiness revolving around use_kenv=1 and it being used to imply that we're certainly looking at the dynamic_kenv. Reviewed by: ray MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D15940
Notes
Notes: svn path=/head/; revision=335479
Diffstat (limited to 'sys/kern/subr_hints.c')
-rw-r--r--sys/kern/subr_hints.c62
1 files changed, 24 insertions, 38 deletions
diff --git a/sys/kern/subr_hints.c b/sys/kern/subr_hints.c
index eeb74cfd6d8f..b6f1ecff813d 100644
--- a/sys/kern/subr_hints.c
+++ b/sys/kern/subr_hints.c
@@ -37,12 +37,15 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/bus.h>
+#define HINTMODE_KENV 0
+#define HINTMODE_STATIC 1
+#define HINTMODE_FALLBACK 2
+
/*
* Access functions for device resources.
*/
static int checkmethod = 1;
-static int use_kenv;
static char *hintp;
/*
@@ -56,10 +59,8 @@ sysctl_hintmode(SYSCTL_HANDLER_ARGS)
{
const char *cp;
char *line, *eq;
- int eqidx, error, from_kenv, i, value;
+ int eqidx, error, i, value;
- from_kenv = 0;
- cp = kern_envp;
value = hintmode;
/* Fetch candidate for new hintmode value */
@@ -67,47 +68,33 @@ sysctl_hintmode(SYSCTL_HANDLER_ARGS)
if (error || req->newptr == NULL)
return (error);
- if (value != 2)
+ if (value != HINTMODE_FALLBACK)
/* Only accept swithing to hintmode 2 */
return (EINVAL);
- /* Migrate from static to dynamic hints */
- switch (hintmode) {
- case 0:
- if (dynamic_kenv) {
- /*
- * Already here. But assign hintmode to 2, to not
- * check it in the future.
- */
- hintmode = 2;
- return (0);
- }
- from_kenv = 1;
- cp = kern_envp;
- break;
- case 1:
- cp = static_hints;
- break;
- case 2:
- /* Nothing to do, hintmode already 2 */
+ /*
+ * The rest of the sysctl handler is just making sure that our
+ * environment is consistent with the world we've already seen.
+ * If we came from kenv at all, then we have nothing to do: static
+ * kenv will get merged into dynamic kenv as soon as kmem becomes
+ * available, dynamic kenv is the environment we'd be setting these
+ * things in anyways. Therefore, we have nothing left to do unless
+ * we came from a static hints configuration.
+ */
+ if (hintmode != HINTMODE_STATIC) {
+ hintmode = value;
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;
- }
+ cp = static_hints;
+ while (cp && *cp != '\0') {
eq = strchr(cp, '=');
if (eq == NULL)
/* Bad hint value */
continue;
eqidx = eq - cp;
+ i = strlen(cp);
line = malloc(i+1, M_TEMP, M_WAITOK);
strcpy(line, cp);
line[eqidx] = '\0';
@@ -117,7 +104,6 @@ sysctl_hintmode(SYSCTL_HANDLER_ARGS)
}
hintmode = value;
- use_kenv = 1;
return (0);
}
@@ -137,7 +123,7 @@ res_find(int *line, int *startln,
{
int n = 0, hit, i = 0;
char r_name[32];
- int r_unit;
+ int r_unit, use_kenv = (hintmode == HINTMODE_FALLBACK);
char r_resname[32];
char r_value[128];
const char *s, *cp;
@@ -147,13 +133,13 @@ res_find(int *line, int *startln,
hintp = NULL;
switch (hintmode) {
- case 0: /* loader hints in environment only */
+ case HINTMODE_KENV: /* loader hints in environment only */
break;
- case 1: /* static hints only */
+ case HINTMODE_STATIC: /* static hints only */
hintp = static_hints;
checkmethod = 0;
break;
- case 2: /* fallback mode */
+ case HINTMODE_FALLBACK: /* fallback mode */
if (dynamic_kenv) {
mtx_lock(&kenv_lock);
cp = kenvp[0];