Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Sep 2012 09:09:08 -0700
From:      mdf@FreeBSD.org
To:        Aleksandr Rybalko <ray@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r240067 - head/sys/kern
Message-ID:  <CAMBSHm93ct9GCc_S6D8N15bAkitU3jTWr2_5P5Z4maQ5oim8PQ@mail.gmail.com>
In-Reply-To: <201209030852.q838q6lC053405@svn.freebsd.org>
References:  <201209030852.q838q6lC053405@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Sep 3, 2012 at 1:52 AM, Aleksandr Rybalko <ray@freebsd.org> wrote:
> 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 <sys/param.h>
>  #include <sys/lock.h>
> +#include <sys/malloc.h>
>  #include <sys/mutex.h>
>  #include <sys/systm.h>
> +#include <sys/sysctl.h>

Putting on my style-nazi hat.  sysctl comes before systm alphabetically.

>  #include <sys/bus.h>
>
>  /*
> @@ -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;

These are not sorted properly; pointers come before scalars, and
within the group they should be sorted alphabetically; e.g. "eqidx"
comes before all the other ints.

> +
> +       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)

This may be copying existing code, but style(9) explicitly forbids
using '!' except on boolean expressions.  Since req->newptr is a
pointer, an explicit comparison to NULL should be made.  This error is
repeated later.

Thanks,
matthew

> +               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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAMBSHm93ct9GCc_S6D8N15bAkitU3jTWr2_5P5Z4maQ5oim8PQ>