On Thu, 3 Feb 2011, Monthadar Al Jaberi wrote:

On Wed, Feb 2, 2011 at 8:06 PM, Julian Elischer <jul...@freebsd.org> wrote:
On 2/2/11 10:05 AM, Monthadar Al Jaberi wrote:

I just tried something that seems to work, but please dont hit me ^^;;;

in wtap_ioctl I assigned curthread->td_vnet myself to point to a VNET
(saved it when the module first loaded) (I have not created any jails
yet)... and it works... I didnt put any CURVNET macros...

td->td_vnet is exactly what the CURVNET_SET macro sets.
You should use the Macros because we may change the place where we store it.

The vnet for the current thread is picked up from several places depending
on the context,
and it is cleared again when it is not needed.  the V_xxx usages in the code
end up being
in effect expanded to curthread->td_vnet.xxx, where each 'xxx' is sort of
like an element in a structure
but not quite.

Now, theoretically we could just leave it set all the time but then it would
be nearly impossible
to find places where we should have changed it, but forgot and just got the
existing one.

if you want to find the correct place to go, then look at the vnet of the
calling process
which should be in the process cred. or just use vnet0.

Can I check it from user space?

I don't understand why you saw a CRED_TO_VNET of 0
I was under the impression that every process/thread in the system would be
on vnet0
in a vimage kernel.

This is how my printf looks like:
struct thread *td = curthread;
struct vnet *v = TD_TO_VNET(td);
struct ucred *cred = CRED_TO_VNET(td->ucred);
struct vnet *td_vnet = td->td_vnet;

here's your problem:

strcut vnet *vnet = cred->cr_prison->pr_vnet;

printf("td=%p, td->td_vnet=%p, td->td_ucred=%p, TD_TO_VNET=%p,
CRED_TO_VNET=%p\n", td, td_vnet, td->td_ucred, v, cred);

I made a fast search in /usr/src for "td_vnet" and found it was
assigned only in
int fork1(td, flags, pages, procp):
#ifdef VIMAGE
        td2->td_vnet = NULL;
        td2->td_vnet_lpush = NULL;

Nice try.  Want another search?  Hint: there is this in vnet.h:

#define curvnet curthread->td_vnet

And then you'll, again, find the CURVNET_SET_* macros.

Maybe something wrong with how I declare my wtap_ioctl:

static struct cdevsw wtap_cdevsw = {
        .d_version =    D_VERSION,
        .d_flags =      0,
        .d_ioctl =      wtap_ioctl,
        .d_name =       "wtapctl",
make_dev(&wtap_cdevsw,0,UID_ROOT,GID_WHEEL,0600,(const char *)"wtapctl");

your stored vnet idea is ok as well, but may go strange if you load the
driver from a vnet jail
and then remove the jail.

Ok, will document it in the code for now

my assumption is that if ath drivers dont use VNET I shouldnt :P

What is wrong with this hack?


P.S. I have printed "porting to vnet" text to have it always at hand,
but its a bit hard for me... doing my best.

On Wed, Feb 2, 2011 at 6:30 PM, Julian Elischer<jul...@freebsd.org>

On 2/2/11 9:12 AM, Bjoern A. Zeeb wrote:

On Wed, 2 Feb 2011, Monthadar Al Jaberi wrote:


Thanx makes more sense, but I have noticed something weired if you can
shade some light on.

I added printfs one when the module is first loaded (static int
event_handler(module_t module, int event, void *arg)):

Try to load it from laoder on boot; I think that should work as we are
setting the curvent for the kernel startup.

The problem you are seeing is a bug in the current implementation that
you cannot add any physical network interface after the kernel started.
This applies to cardbus/usb/... as well as any kind of ethernet
interface, so a kldload igb should yield it as well.

The fix for that is easy and hard at the same time:
A) either touch all drivers
B) or touch all cloned interfaces and change 3 common lines.
  or try to make cloners aware of vimages.

Solution B) is sitting in perforce with the entire stuff that it depends
on and was started with CH=179022,179255 but not limited to that if you
want to have a peek.

What you certainly can do locally to your driver for now is to make a
change like this:

+#ifdef VIMAGE
+       CURVNET_SET(vnet0);
       ifp = if_alloc(IFT_ETHER);
+#ifdef VIMAGE

you don't really need  the #ifdef except for readability as CURVNET_XXX
enot defined for !vnet

It's the type A) kind of change from above that will break eventually
in the future.


Bjoern A. Zeeb                                 You have to have visions!
        <ks> Going to jail sucks -- <bz> All my daemons like it!
freebsd-virtualization@freebsd.org mailing list
To unsubscribe, send any mail to 

Reply via email to