Re: [patch] Improved jail fstab functionality inside rc.d (needs testers and review)

2009-11-30 Thread Merijn Verstraaten
On Sun, 29 Nov 2009 18:45:18 +0100, Bjoern A. Zeeb  
bzeeb-li...@lists.zabbadoz.net wrote:
My apologies if these are the wrong lists for this sort of thing but it  
was unclear to me where else to go with additions like this.


You may try freebsd-jail@
Make sure to get a review from simon@ for this.


Ok, so one more try to the proper list this time.

I just finished hacking /etc/rc.d/jail to fix my two pet peeves, currently  
the rc framework only accepts a single fstab file per jail and (worse!)  
there is no way to specify the mountpoints in these fstab files relative  
to the jails root. This makes sharing of mounts (for example all my jails  
nullfs mounting the same ports tree) very cumbersome.


This patch should allow you to specify multiple fstab files in the  
jail_fstab and jail_name_fstab variables and mount these in order. In  
addition the patch mangles the fstab files in such a way that any  
mountpoint in the fstab files starting with the text ROOT will have  
ROOT replaced with the jails rootdir. For example the following  
situation:

rc.conf:
jail_test_rootdir=/usr/jails/test
jail_test_fstab=/usr/jails/fstab /usr/jails/fstab.test

/usr/jails/fstab:
/usr/ports  ROOT/usr/ports  nullfs  ro  0   0

/usr/jails/fstab.test
/path/to/some/folderROOT/folder nullfs  rw  0   0

This should result in /path/to/some/folder being mounted into  
/usr/jails/test/folder and /usr/ports into /usr/jails/test/usr/ports.  
Normal mountpoints (i.e. not prefixed with ROOT) should still be mounted  
as normal.


Todo:
The code probably needs cleaning up, it tried to confirm to the style of  
the surrounding code, but I didn't know how to handle stuff which resulted  
in either lines longer then 80 chars or very ugly line wrapping. Someone  
more at home in the rc.d framework should probably clean the patch up a  
little to conform to the style. In addition the ROOT prefix is now  
hardcoded, perhaps this should be a configurable option (jail_prefix) or  
something instead.


If people have the time to review and/or test this patch I'd be grateful  
any comments/critiques are welcome. Please CC me when replying to this  
e-mail as I'm not currently subscribed to jail@ .


Kind regards,
Merijn Verstraaten
--- /etc/rc.d/jail  2009-11-29 14:57:51.903840488 +0100
+++ jail2009-11-29 16:28:50.471354236 +0100
@@ -302,14 +302,17 @@
fi
fi
if checkyesno _mount; then
-   [ -f ${_fstab} ] || warn ${_fstab} does not exist
-   tail -r ${_fstab} | while read _device _mountpt _rest; do
-   case :${_device} in
-   :#* | :)
-   continue
-   ;;
-   esac
-   secure_umount ${_mountpt}
+   for _fstab_file in ${_fstab}; do
+   [ -f ${_fstab_file} ] || warn ${_fstab_file} does 
not exist
+   sed s#ROOT#${_rootdir}# ${_fstab_file} |
+   tail -r | while read _device _mountpt _rest; do
+   case :${_device} in
+   :#* | :)
+   continue
+   ;;
+   esac
+   secure_umount ${_mountpt}
+   done
done
fi
 }
@@ -327,7 +330,8 @@
 #
 jail_mount_fstab()
 {
-   local _device _mountpt _rest
+   local _fstab_file _device _mountpt _rest
+   _fstab_file=$*
 
while read _device _mountpt _rest; do
case :${_device} in
@@ -335,12 +339,17 @@
continue
;;
esac
-   if is_symlinked_mountpoint ${_mountpt}; then
-   warn ${_mountpt} has symlink as parent - not mounting 
from ${_fstab}
+   if [ ${_mountpt%%/*} = ROOT ]; then
+   if is_symlinked_mountpoint 
${_rootdir}/${_mountpt#*/}; then
+   warn ${_rootdir}/${_mountpt#*/} has symlink as 
parent - not mounting from ${_fstab_file}
+   return
+   fi
+   elif is_symlinked_mountpoint ${_mountpt}; then
+   warn ${_mountpt} has symlink as parent - not mounting 
from ${_fstab_file}
return
fi
-   done ${_fstab}
-   mount -a -F ${_fstab}
+   done ${_fstab_file}
+   sed s#ROOT#${_rootdir}# ${_fstab_file} | mount -a -F /dev/stdin
 }
 
 # jail_show_addresses jail
@@ -575,10 +584,12 @@
fi
if checkyesno _mount; then
info Mounting fstab for jail ${_jail} (${_fstab})
-   if [ ! -f ${_fstab} ]; then
-   err 3 $name: ${_fstab} does not exist
-   fi
- 

Re: [patch] Improved jail fstab functionality inside rc.d (needs testers and review)

2009-11-29 Thread Bjoern A. Zeeb

On Sun, 29 Nov 2009, Merijn Verstraaten wrote:

My apologies if these are the wrong lists for this sort of thing but it was 
unclear to me where else to go with additions like this.


You may try freebsd-jail@

Make sure to get a review from simon@ for this.

/bz

--
Bjoern A. Zeeb It will not break if you know what you are doing.
___
freebsd-jail@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-jail
To unsubscribe, send any mail to freebsd-jail-unsubscr...@freebsd.org