Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Mar 2015 18:26:50 +0800
From:      Tiwei Bie <btw@mail.ustc.edu.cn>
To:        Mateusz Guzik <mjguzik@gmail.com>
Cc:        Konstantin Belousov <kostikbel@gmail.com>, freebsd-hackers@freebsd.org
Subject:   Re: [PATCH] Finish the task 'Validate coredump format string'
Message-ID:  <20150322102650.GA14629@freebsd>
In-Reply-To: <20150322101401.GH14650@dft-labs.eu>
References:  <1426946345-67889-1-git-send-email-btw@mail.ustc.edu.cn> <20150321200500.GC14650@dft-labs.eu> <20150322091853.GA89976@freebsd> <20150322101401.GH14650@dft-labs.eu>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Mar 22, 2015 at 11:14:01AM +0100, Mateusz Guzik wrote:
> On Sun, Mar 22, 2015 at 05:19:40PM +0800, Tiwei Bie wrote:
> [..]
> 
> I was somehow convinced that tunables are dealt with other code.
> 
> If such sysctl handler is also called for tunables, the kernel should
> pass a flag or some other indicator so that the function knows it is
> dealing with a tunable and that would avoid locking and thus solve the
> problem.
> 

If a sysctl is registered as a tunable (CTLFLAG_TUN), when calling
sysctl_register_oid(), sysctl_load_tunable_by_oid_locked() will be
called to fetch the kenv setting (i.e. tunable setting defined in
loader.conf) to update the sysctl setting:

void
sysctl_register_oid(struct sysctl_oid *oidp)
{
        ......
        if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE &&
#ifdef VIMAGE
            (oidp->oid_kind & CTLFLAG_VNET) == 0 &&
#endif
            (oidp->oid_kind & CTLFLAG_TUN) != 0 &&
            (oidp->oid_kind & CTLFLAG_NOFETCH) == 0) {
                sysctl_load_tunable_by_oid_locked(oidp);
        }
}

sysctl_load_tunable_by_oid_locked() will fetch the kenv setting, and
call the sysctl handler, e.g. sysctl_kern_corefile() to update the
sysctl setting:

static void
sysctl_load_tunable_by_oid_locked(struct sysctl_oid *oidp)
{
        ......
        case CTLTYPE_STRING:
                penv = kern_getenv(path + rem);
                if (penv == NULL)
                        return;
                req.newlen = strlen(penv);
                req.newptr = penv;
                break;
        default:
                return;
        }
        error = sysctl_root_handler_locked(oidp, oidp->oid_arg1,
            oidp->oid_arg2, &req);
        if (error != 0)
                printf("Setting sysctl %s failed: %d\n", path, error);
        ......
}

The tunable setting is just a "name"=value format in kenv. And the kenv
codes have no idea of the meaning of the "name". It can also be modified
later when system is up by `kenv' command. And the corresponding sysctl
setting won't be affected any more.

> I'm wondering if we should go a little bit further and get rid of
> static char corefilename[MAXPATHLEN]
> 
> and have a static char *corefilename instead.
> 
> A dedicated sysinit func could fetch and validate the tunable, if any.
> If no tunable was provided it would alloc memory for the default.
> 
> -- 
> Mateusz Guzik <mjguzik gmail.com>

Best regards,
Tiwei Bie




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