Weird problem with devstat interface
John Baldwin
jhb at FreeBSD.org
Wed Jun 29 13:40:07 GMT 2005
On Tuesday 28 June 2005 07:30 pm, Fred Gilham wrote:
> Poul-Henning Kamp <phk at phk.freebsd.dk> wrote:
> > In message <200506281749.j5SHnPlr017616 at quarter.csl.sri.com>, Fred
> >
> > Gilham writes:
> > >I have been able to get the program to stop doing this by changing
> > >the calls to
> > >
> > >devstat_checkversion()
> > >devstat_getnumdevs()
> > >devstat_getdevs()
> > >
> > >so they don't use the kvm interface but the sysctl interface
> > >(i.e. passing NULL instead of a file descriptor to /dev/kvm).
> >
> > You shouldn't be using the kvm interface in the first place.
>
> That seems reasonable, but the documentation doesn't give any indication
> that this is the case. From the devstat(3) man page:
>
> DESCRIPTION
> The devstat library is a library of helper functions for dealing with
> the kernel devstat(9) interface, which is accessible to users via sysctl(3)
> and kvm(3). All functions that take a kvm_t * as first argument can be
> passed NULL instead of a kvm handle as this argument, which causes the data
> to be read via sysctl(3). Otherwise, it is read via kvm(3) using the
> supplied handle. devstat_checkversion() should be called with each kvm
> handle that is going to be used (or with NULL if sysctl(3) is going to be
> used).
>
> >From this I got the impression that the sysctl interface was a kind of
>
> secondary alternative to the kvm interface.
>
> The /usr/sbin/iostat program also uses the kvm version (see
> /usr/src/usr.sbin/iostat/iostat.c). That's what whoever maintained the
> xsysinfo program used as an example.
>
> Also, if the kvm interface is broken it should probably be disabled or
> something. Actually I doubt that it's broken, but certainly the
> xsysinfo code doesn't interact well with it.
The idea is that you use the kvm interface when working with a kernel core
dump (so you can run iostat, etc. against core dumps), but you should use the
sysctl interface when talking to the currently running kernel. I haven't
looked at iostat to see if it does that correctly. If it doesn't, then that
should probably be fixed. You probably don't ever want to run xsysinfo on a
core dump, so it should probably always use the sysctl interface.
--
John Baldwin <jhb at FreeBSD.org> <>< http://www.FreeBSD.org/~jhb/
"Power Users Use the Power to Serve" = http://www.FreeBSD.org
More information about the freebsd-current
mailing list