From owner-freebsd-jail@FreeBSD.ORG Mon Nov 30 21:35:18 2009 Return-Path: Delivered-To: freebsd-jail@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 09269106566B; Mon, 30 Nov 2009 21:35:18 +0000 (UTC) (envelope-from merijn@inconsistent.nl) Received: from mail.inconsistent.nl (mail.inconsistent.nl [IPv6:2001:888:1744::3]) by mx1.freebsd.org (Postfix) with ESMTP id 60E2C8FC0C; Mon, 30 Nov 2009 21:35:17 +0000 (UTC) Received: from localhost (unknown [IPv6:2001:888:1744:2:226:8ff:fe05:84f4]) (Authenticated sender: merijn@inconsistent.nl) by mail.inconsistent.nl (Postfix) with ESMTPSA id DD3C63164; Mon, 30 Nov 2009 22:35:16 +0100 (CET) Content-Type: multipart/mixed; boundary=----------7MpzyhJtchi0YuZMFlCK5J To: freebsd-jail@freebsd.org, "Simon L. Nielsen" References: <20091129174407.Q37440@maildrop.int.zabbadoz.net> Date: Mon, 30 Nov 2009 22:35:15 +0100 MIME-Version: 1.0 From: "Merijn Verstraaten" Message-ID: In-Reply-To: <20091129174407.Q37440@maildrop.int.zabbadoz.net> User-Agent: Opera Mail/10.01 (MacIntel) Cc: Subject: Re: [patch] Improved jail fstab functionality inside rc.d (needs testers and review) X-BeenThere: freebsd-jail@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion about FreeBSD jail\(8\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Nov 2009 21:35:18 -0000 ------------7MpzyhJtchi0YuZMFlCK5J Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On Sun, 29 Nov 2009 18:45:18 +0100, Bjoern A. Zeeb 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__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/folder ROOT/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 ------------7MpzyhJtchi0YuZMFlCK5J Content-Disposition: attachment; filename=jail.diff Content-Type: text/plain; name=jail.diff Content-Transfer-Encoding: 7bit --- /etc/rc.d/jail 2009-11-29 14:57:51.903840488 +0100 +++ jail 2009-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 - jail_mount_fstab + for _fstab_file in ${_fstab}; do + if [ ! -f "${_fstab_file}" ]; then + err 3 "$name: ${_fstab_file} does not exist" + fi + jail_mount_fstab ${_fstab_file} + done fi if checkyesno _devfs; then # If devfs is already mounted here, skip it. ------------7MpzyhJtchi0YuZMFlCK5J--