From owner-svn-src-head@FreeBSD.ORG Mon Sep 3 08:52:06 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9417E106564A; Mon, 3 Sep 2012 08:52:06 +0000 (UTC) (envelope-from ray@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 656258FC1B; Mon, 3 Sep 2012 08:52:06 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q838q6Z5053407; Mon, 3 Sep 2012 08:52:06 GMT (envelope-from ray@svn.freebsd.org) Received: (from ray@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q838q6lC053405; Mon, 3 Sep 2012 08:52:06 GMT (envelope-from ray@svn.freebsd.org) Message-Id: <201209030852.q838q6lC053405@svn.freebsd.org> From: Aleksandr Rybalko Date: Mon, 3 Sep 2012 08:52:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r240067 - head/sys/kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Sep 2012 08:52:06 -0000 Author: ray Date: Mon Sep 3 08:52:05 2012 New Revision: 240067 URL: http://svn.freebsd.org/changeset/base/240067 Log: Add kern.hintmode sysctl variable to show current state of hints: 0 - loader hints in environment only; 1 - static hints only 2 - fallback mode (Dynamic KENV with fallback to kernel environment) Add kern.hintmode write handler, accept only value 2. That will switch static KENV to dynamic. So it will be possible to change device hints. Approved by: adrian (mentor) Modified: head/sys/kern/subr_hints.c Modified: head/sys/kern/subr_hints.c ============================================================================== --- head/sys/kern/subr_hints.c Mon Sep 3 07:18:24 2012 (r240066) +++ head/sys/kern/subr_hints.c Mon Sep 3 08:52:05 2012 (r240067) @@ -29,8 +29,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include +#include #include /* @@ -42,6 +44,81 @@ static int use_kenv; static char *hintp; /* + * Define kern.hintmode sysctl, which only accept value 2, that cause to + * switch from Static KENV mode to Dynamic KENV. So systems that have hints + * compiled into kernel will be able to see/modify KENV (and hints too). + */ + +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; + value = hintmode; + + /* Fetch candidate for new hintmode value */ + error = sysctl_handle_int(oidp, &value, 0, req); + if (error || !req->newptr) + 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; + use_kenv = 1; + return (0); +} + +SYSCTL_PROC(_kern, OID_AUTO, hintmode, CTLTYPE_INT|CTLFLAG_RW, + &hintmode, 0, sysctl_hintmode, "I", "Get/set current hintmode"); + +/* * Evil wildcarding resource string lookup. * This walks the supplied env string table and returns a match. * The start point can be remembered for incremental searches.