Subject: Re: dynamic sysctl
To: None <>
From: David Young <>
List: tech-kern
Date: 11/15/2003 03:20:45
On Fri, Nov 14, 2003 at 09:27:47PM -0600, David Young wrote:
> On Fri, Nov 14, 2003 at 02:40:52PM -0500, Andrew Brown wrote:
> > >> and then you have all the mappings for name<->number under net.  for
> > >> the children of those nodes, you simply iterate.
> > >
> > >What happens if the name<->number mappings change in between the 
> > >mapping call and the walking?  It's dynamic, so you're going to have to 
> > >expect this.
> > 
> > good question.
> > 
> > the answer is that each node has a version number (an int -- i am
> > studiously ignoring the case where the version number wraps around).
> > 
> > when a node is created the global version counter is incremented and
> > the new version number is assigned to the new node and its parent,
> > straight up to the root of the tree.
> > 
> > likewise, when a node is destroyed, the global version number is
> > incremented, and the new version number is assigned to the parent of
> > the node that is being destroyed all the way back up the tree.
> > 
> > sysctlnametomib() just checks that all the versions are the same at
> > the top of the tree each time it's called, and for those that have
> > changed, it purges that data from its cache.

I do not even understand my own question. Let me try that again.

I am not sure I understand how sysctlnametomib works. Tell me if this is
right: my program calls sysctlnametomib("/a/b/c"). sysctlnametomib uses
sysctl to record the version number stored at the top of the tree. It
resolves "/a/b" to 13.27 using two sysctl calls. In the mean time, the
kernel deletes the path "/a/b/d", which increases the version number
at 13.27, at 13, and at the root.  Now, sysctlnametomib resolves "c"
at 13.27 to 4.  It compares the version number at the root with the
version number it recorded. Finding that the versions are different,
it sets errno to EAGAIN (say) and returns -1. My program has to try
again to resolve /a/b/c to a number.

Assuming that is the way it works, I will worry that my program will
sometimes have to try again forever to resolve "/a/b/c" to a numeric path.


David Young             OJC Technologies      Urbana, IL * (217) 278-3933