Source-Changes-HG archive

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

[src/trunk]: src/etc/rc.d Make this better ... Allow config file for raidN ...



details:   https://anonhg.NetBSD.org/src/rev/c04ecaa790c4
branches:  trunk
changeset: 368596:c04ecaa790c4
user:      kre <kre%NetBSD.org@localhost>
date:      Thu Jul 21 07:49:36 2022 +0000

description:
Make this better ...   Allow config file for raidN to be found
in /etc/conf/raid/raidN (as well as in /etc/raidN.conf) (less
clutter in /etc).

Allow config files to exist for raids that are autoconfigured (just
skip anything autoconfigured) - this allows a (simplistic) recovery
mechanism if autoconf fails, and makes it simpler to enable/disable
autoconf at will, while keeping the raid working.

While here, add sh quoting where it is needed, and remove it from
where it is pointless.

diffstat:

 etc/rc.d/raidframe |  42 ++++++++++++++++++++++++++++++++----------
 1 files changed, 32 insertions(+), 10 deletions(-)

diffs (64 lines):

diff -r ae82f6cc6811 -r c04ecaa790c4 etc/rc.d/raidframe
--- a/etc/rc.d/raidframe        Thu Jul 21 01:52:28 2022 +0000
+++ b/etc/rc.d/raidframe        Thu Jul 21 07:49:36 2022 +0000
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: raidframe,v 1.11 2021/08/03 05:15:20 mlelstv Exp $
+# $NetBSD: raidframe,v 1.12 2022/07/21 07:49:36 kre Exp $
 #
 
 # PROVIDE: raidframe
@@ -9,21 +9,43 @@
 
 $_rc_subr_loaded . /etc/rc.subr
 
-name="raidframe"
+name=raidframe
 rcvar=$name
-start_cmd="raidframe_start"
-stop_cmd=":"
+start_cmd=raidframe_start
+stop_cmd=:
 
 raidframe_start()
 {
        # Configure non-auto-configured raid devices.
-       # Ensure order by globbing raid[0-9].conf before raid[1-9][0-9].conf.
-       #
-       for cfg in /etc/raid[0-9].conf /etc/raid[1-9][0-9].conf ; do
-               [ ! -f $cfg ] && continue
+       # Ensure order by globbing raid[0-9] before raid[1-9][0-9].
+       # Assume no mixing of /etc/conf/raid/* and /etc/raid*.conf styles
+
+       devices=$(sysctl -n hw.disknames)
+       for cfg in                                      \
+               /etc/conf/raid/raid[0-9]                \
+               /etc/conf/raid/raid[1-9][0-9]           \
+               /etc/conf/raid/raid[1-9][0-9][0-9]      \
+               /etc/raid[0-9].conf                     \
+               /etc/raid[1-9][0-9].conf                \
+       ; do
+               [ -f "$cfg" ] && [ -s "$cfg" ] || continue
+
                dev=${cfg##*/}
-               dev=${dev%%.conf}
-               raidctl -c $cfg $dev
+               dev=${dev%.conf}
+
+               # This test should never fail with the possible
+               # config file patterns included, but for safety
+               case "${dev}" in
+               raid[0-9]|raid[1-9][0-9]|raid[1-9][0-9][0-9])   ;;
+               *)      : "$dev not raidNN"; continue;;
+               esac
+
+               case " ${devices} " in
+               *" ${dev} "*)   : "$dev configured already"; continue;;
+               esac
+
+               raidctl -c "$cfg" "$dev" &&
+                       devices="${devices} ${dev}"
        done
 }
 



Home | Main Index | Thread Index | Old Index