nullfs and sockets

This is a re-post from my MySpace blog.

UPDATE: This was fixed far better than I did it at the time in the stable/9 branch as of 2012-04-24

What happens on FreeBSD 6.x series machines using nullfs and sockets? At least in my current setup it fails.

The scenario is that I am running mysql on the host and apache in a chroot environment. (I don’t have the extra IP’s, and don’t want to deal with NAT to make jails work.) I have the apache chroot nullfs mounted (ro, except for the data apache needs to write and the user directories for php/perl scripts to work). In either rw/ro mode the nullfs does not translate the mysql socket correctly unless it is mounted on the nullfs mount and even then it is sporadic.

After a couple hours of googling, and rummaging through the freebsd-* archives, I ended up with the kern/51583 PR. This PR is from 2003 and fixed the socket/chr/blk devices in the sys/fs/nullfs/null_subr.c in such a manner that allowed sockets to work. Taking the approach that was taken I applied the following to the code in null_subr.c at line 235 (at least for the sources dated at 2006.09.14):

if (lowervp->v_type == VSOCK) vp->v_un = lowervp->v_un;

This allowed the sockets to work but I do not if this is a good idea to institute when using jails as opposed to my problem up above as it might work fine within a jail’d environment but not a chroot’d environment, I haven’t tested with it in either direction. I also have no other knowledge of the nullfs or vnode code. The main difference between the patch submitted in kern/51583 and mine is that mine only affects vnodes with a v_type of VSOCK, where it affected all or did an addalias to VCHR, and VBLK.