Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add the ability for file systems mounted via mount_critical_...



details:   https://anonhg.NetBSD.org/src/rev/5169a70510b7
branches:  trunk
changeset: 747423:5169a70510b7
user:      apb <apb%NetBSD.org@localhost>
date:      Mon Sep 14 12:05:12 2009 +0000

description:
Add the ability for file systems mounted via mount_critical_filesystems()
in rc.subr to be marked as optional.  This means that it's not an
error if the file system is not mentioned in /etc/fstab.  It is
still an error if something else goes wrong.

Change the defaults for these two variables in /etc/defaults/rc.conf:
critical_filesystems_local="OPTIONAL:/var"
critical_filesystems_remote="OPTIONAL:/usr"

diffstat:

 etc/defaults/rc.conf     |   9 +++---
 etc/rc.subr              |  61 ++++++++++++++++++++++++++++++++++++++---------
 share/man/man5/rc.conf.5 |  18 ++++++++++++-
 3 files changed, 70 insertions(+), 18 deletions(-)

diffs (152 lines):

diff -r ff34f46a2438 -r 5169a70510b7 etc/defaults/rc.conf
--- a/etc/defaults/rc.conf      Mon Sep 14 12:02:48 2009 +0000
+++ b/etc/defaults/rc.conf      Mon Sep 14 12:05:12 2009 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: rc.conf,v 1.105 2009/09/11 18:17:04 apb Exp $
+#      $NetBSD: rc.conf,v 1.106 2009/09/14 12:05:12 apb Exp $
 #
 # /etc/defaults/rc.conf --
 #      default configuration of /etc/rc.conf
@@ -87,10 +87,11 @@
 # Note that `/var' is needed in $critical_filesystems_local (or
 # implied as part of `/') as certain services that need /var (such as
 # dhclient) may be needed to get the network operational enough to mount
-# the $critical_filesystems_remote.
+# the $critical_filesystems_remote.  Prepending "OPTIONAL:"  means it
+# will not be an error if that file system is not present in fstab(5).
 #
-critical_filesystems_local="/var"
-critical_filesystems_remote="/usr"
+critical_filesystems_local="OPTIONAL:/var"
+critical_filesystems_remote="OPTIONAL:/usr"
 
 # Swap device controls.
 #
diff -r ff34f46a2438 -r 5169a70510b7 etc/rc.subr
--- a/etc/rc.subr       Mon Sep 14 12:02:48 2009 +0000
+++ b/etc/rc.subr       Mon Sep 14 12:05:12 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: rc.subr,v 1.78 2009/09/11 18:17:04 apb Exp $
+# $NetBSD: rc.subr,v 1.79 2009/09/14 12:05:12 apb Exp $
 #
 # Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -115,25 +115,62 @@
 #      Go through the list of critical filesystems as provided in
 #      the rc.conf(5) variable $critical_filesystems_${type}, checking
 #      each one to see if it is mounted, and if it is not, mounting it.
+#      It's not an error if file systems prefixed with "OPTIONAL:"
+#      are not mentioned in /etc/fstab.
 #
 mount_critical_filesystems()
 {
        eval _fslist=\$critical_filesystems_${1}
+       _mountcrit_es=0
        for _fs in $_fslist; do
-               mount | (
-                       _ismounted=false
-                       while read what _on on _type type; do
-                               if [ $on = $_fs ]; then
-                                       _ismounted=true
+               _optional=false
+               case "$_fs" in
+               OPTIONAL:*)
+                       _optional=true
+                       _fs="${_fs#*:}"
+                       ;;
+               esac
+               _ismounted=false
+               # look for a line like "${fs} on * type *"
+               # or "* on ${fs} type *" in the output from mount.
+               case "${nl}$( mount )${nl}" in
+               *" on ${_fs} type "*)
+                       _ismounted=true
+                       ;;
+               *"${nl}${_fs} on "*)
+                       _ismounted=true
+                       ;;
+               esac
+               if $_ismounted; then
+                       print_rc_metadata \
+                       "note:File system ${_fs} was already mounted"
+               else
+                       _mount_output=$( mount $_fs 2>&1 )
+                       _mount_es=$?
+                       case "$_mount_output" in
+                       *"${nl}"*)
+                               # multiple lines can't be good,
+                               # not even if $_optional is true
+                               ;;
+                       *'unknown special file or file system'*)
+                               if $_optional; then
+                                       # ignore this error
+                                       print_rc_metadata \
+                       "note:Optional file system ${_fs} is not present"
+                                       _mount_es=0
+                                       _mount_output=""
                                fi
-                       done
-                       if $_ismounted; then
-                               :
-                       else
-                               mount $_fs >/dev/null 2>&1
+                               ;;
+                       esac
+                       if [ -n "$_mount_output" ]; then
+                               printf >&2 "%s\n" "$_mount_output"
                        fi
-               )
+                       if [ "$_mount_es" != 0 ]; then
+                               _mountcrit_es="$_mount_es"
+                       fi
+               fi
        done
+       return $_mountcrit_es
 }
 
 #
diff -r ff34f46a2438 -r 5169a70510b7 share/man/man5/rc.conf.5
--- a/share/man/man5/rc.conf.5  Mon Sep 14 12:02:48 2009 +0000
+++ b/share/man/man5/rc.conf.5  Mon Sep 14 12:05:12 2009 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: rc.conf.5,v 1.134 2009/09/11 19:47:27 wiz Exp $
+.\"    $NetBSD: rc.conf.5,v 1.135 2009/09/14 12:05:12 apb Exp $
 .\"
 .\" Copyright (c) 1996 Matthew R. Green
 .\" All rights reserved.
@@ -55,7 +55,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd September 11, 2009
+.Dd September 14, 2009
 .Dt RC.CONF 5
 .Os
 .Sh NAME
@@ -279,12 +279,26 @@
 is part of this, because it is needed by services such as
 .Xr dhclient 8
 which may be required to get the network operational.
+The default is
+.Dq "OPTIONAL:/var" ,
+where the
+.Dq OPTIONAL:
+prefix means that it's not an error if the file system is not
+present in
+.Xr fstab 5.
 .It Sy critical_filesystems_remote
 A string.
 File systems such as
 .Pa /usr
 that may require network services to be available to mount,
 that must be available early in the system boot for general services to use.
+The default is
+.Dq "OPTIONAL:/usr" ,
+where the
+.Dq OPTIONAL:
+prefix means that it's not an error if the file system is not
+present in
+.Xr fstab 5.
 .It Sy fsck_flags
 A string.
 A file system is checked with



Home | Main Index | Thread Index | Old Index