From owner-svn-src-all@freebsd.org Thu Oct 13 06:19:55 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D9845C0FE49; Thu, 13 Oct 2016 06:19:55 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9A2E0FE2; Thu, 13 Oct 2016 06:19:55 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u9D6JsvV088688; Thu, 13 Oct 2016 06:19:54 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u9D6JsMd088686; Thu, 13 Oct 2016 06:19:54 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201610130619.u9D6JsMd088686@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Thu, 13 Oct 2016 06:19:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r307182 - head/etc/rc.d X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Oct 2016 06:19:55 -0000 Author: avg Date: Thu Oct 13 06:19:54 2016 New Revision: 307182 URL: https://svnweb.freebsd.org/changeset/base/307182 Log: rc.d/zfsbe: a new script designed for boot environment support Currently zfsbe ensures that subordinate filesystems are mounted at the right mount points. The script assumes that the subordinate filesystems of a boot environment have their canmount property set to noauto, so that they are not automatically mounted on boot. Whereas the root filesystem is mounted by the kernel, there was nothing to mount its subordinates. rc.d/zfsbe fills that gap. Discussed with: allanjude, will MFC after: 3 weeks Differential Revision: https://reviews.freebsd.org/D7797 Added: head/etc/rc.d/zfsbe (contents, props changed) Modified: head/etc/rc.d/zfs Modified: head/etc/rc.d/zfs ============================================================================== --- head/etc/rc.d/zfs Thu Oct 13 06:17:33 2016 (r307181) +++ head/etc/rc.d/zfs Thu Oct 13 06:19:54 2016 (r307182) @@ -4,7 +4,7 @@ # # PROVIDE: zfs -# REQUIRE: mountcritlocal +# REQUIRE: zfsbe # BEFORE: FILESYSTEMS var . /etc/rc.subr Added: head/etc/rc.d/zfsbe ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/etc/rc.d/zfsbe Thu Oct 13 06:19:54 2016 (r307182) @@ -0,0 +1,71 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +# PROVIDE: zfsbe +# REQUIRE: mountcritlocal + +# Handle boot environment subordinate filesystems +# that may have canmount property set to noauto. +# For these filesystems mountpoint relative to / +# must be the same as their dataset name relative +# to BE root dataset. + +. /etc/rc.subr + +name="zfsbe" +rcvar="zfs_enable" +start_cmd="be_start" +stop_cmd="be_stop" +required_modules="zfs" + +mount_subordinate() +{ + local _be + + _be=$1 + zfs list -rH -o mountpoint,name,canmount,mounted -s mountpoint -t filesystem $_be | \ + while read _mp _name _canmount _mounted ; do + # skip filesystems that must not be mounted + [ "$_canmount" = "off" ] && continue + # skip filesystems that are already mounted + [ "$_mounted" = "yes" ] && continue + case "$_mp" in + "none" | "legacy" | "/" | "/$_be") + # do nothing for filesystems with unset or legacy mountpoint + # or those that would be mounted over / + ;; + "/$_be/"*) + # filesystems with mountpoint relative to BE + mount -t zfs $_name ${_mp#/$_be} + ;; + *) + # filesystems with mountpoint elsewhere + zfs mount $_name + ;; + esac + done +} + +be_start() +{ + if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then + : + else + mount -p | while read _dev _mp _type _rest; do + [ $_mp = "/" ] || continue + if [ $_type = "zfs" ] ; then + mount_subordinate $_dev + fi + break + done + fi +} + +be_stop() +{ +} + +load_rc_config $name +run_rc_command "$1"