Blame 0007-99base-dracut-lib.sh-added-inst_mount_hook-add_mount.patch

Harald Hoyer 6adbc8
From bb61d657c1ff11c4339a777e1fcf57173783bf7d Mon Sep 17 00:00:00 2001
Harald Hoyer 6adbc8
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 6adbc8
Date: Thu, 15 Dec 2011 14:37:34 +0100
Harald Hoyer 6adbc8
Subject: [PATCH] 99base/dracut-lib.sh: added inst_mount_hook add_mount_point
Harald Hoyer 6adbc8
Harald Hoyer 6adbc8
inst_mount_hook <mountpoint> <prio> <name> <script>
Harald Hoyer 6adbc8
Harald Hoyer 6adbc8
Install a mount hook with priority <prio>,
Harald Hoyer 6adbc8
which executes <script> as soon as <mountpoint> is mounted.
Harald Hoyer 6adbc8
Harald Hoyer 6adbc8
add_mount_point <dev> <mountpoint> <filesystem> <fsopts>
Harald Hoyer 6adbc8
Harald Hoyer 6adbc8
Mount <dev> on <mountpoint> with <filesystem> and <fsopts>
Harald Hoyer 6adbc8
and call any mount hooks, as soon, as it is mounted
Harald Hoyer 6adbc8
---
Harald Hoyer 6adbc8
 modules.d/99base/dracut-lib.sh |   91 ++++++++++++++++++++++++++++++++++++++++
Harald Hoyer 6adbc8
 1 files changed, 91 insertions(+), 0 deletions(-)
Harald Hoyer 6adbc8
Harald Hoyer 6adbc8
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
Harald Hoyer 6adbc8
index c881869..9eae4d9 100755
Harald Hoyer 6adbc8
--- a/modules.d/99base/dracut-lib.sh
Harald Hoyer 6adbc8
+++ b/modules.d/99base/dracut-lib.sh
Harald Hoyer 6adbc8
@@ -602,6 +602,92 @@ usable_root() {
Harald Hoyer 6adbc8
     return 0
Harald Hoyer 6adbc8
 }
Harald Hoyer 6adbc8
 
Harald Hoyer 6adbc8
+inst_hook() {
Harald Hoyer 6adbc8
+    local _hookname _unique _name _job _exe
Harald Hoyer 6adbc8
+    while [ $# -gt 0 ]; do
Harald Hoyer 6adbc8
+        case "$1" in
Harald Hoyer 6adbc8
+            --hook)
Harald Hoyer 6adbc8
+                _hookname="/$2";shift;;
Harald Hoyer 6adbc8
+            --unique)
Harald Hoyer 6adbc8
+                _unique="yes";;
Harald Hoyer 6adbc8
+            --name)
Harald Hoyer 6adbc8
+                _name="$2";shift;;
Harald Hoyer 6adbc8
+            *)
Harald Hoyer 6adbc8
+                break;;
Harald Hoyer 6adbc8
+        esac
Harald Hoyer 6adbc8
+        shift
Harald Hoyer 6adbc8
+    done
Harald Hoyer 6adbc8
+
Harald Hoyer 6adbc8
+    if [ -z "$_unique" ]; then
Harald Hoyer 6adbc8
+        _job="${_name}$$"
Harald Hoyer 6adbc8
+    else
Harald Hoyer 6adbc8
+        _job="${_name:-$1}"
Harald Hoyer 6adbc8
+        _job=${_job##*/}
Harald Hoyer 6adbc8
+    fi
Harald Hoyer 6adbc8
+
Harald Hoyer 6adbc8
+    _exe=$1
Harald Hoyer 6adbc8
+    shift
Harald Hoyer 6adbc8
+
Harald Hoyer 6adbc8
+    [ -x "$_exe" ] || _exe=$(command -v $_exe)
Harald Hoyer 6adbc8
+
Harald Hoyer 6adbc8
+    if [ -n "$onetime" ]; then
Harald Hoyer 6adbc8
+        {
Harald Hoyer 6adbc8
+            echo '[ -e "$_job" ] && rm "$_job"'
Harald Hoyer 6adbc8
+            echo "$_exe $@"
Harald Hoyer 6adbc8
+        } > "/tmp/$$-${_job}.sh"
Harald Hoyer 6adbc8
+    else
Harald Hoyer 6adbc8
+        echo "$_exe $@" > "/tmp/$$-${_job}.sh"
Harald Hoyer 6adbc8
+    fi
Harald Hoyer 6adbc8
+
Harald Hoyer 6adbc8
+    mv -f "/tmp/$$-${_job}.sh" "$hookdir/${_hookname}/${_job}.sh"
Harald Hoyer 6adbc8
+}
Harald Hoyer 6adbc8
+
Harald Hoyer 6adbc8
+# inst_mount_hook <mountpoint> <prio> <name> <script>
Harald Hoyer 6adbc8
+#
Harald Hoyer 6adbc8
+# Install a mount hook with priority <prio>,
Harald Hoyer 6adbc8
+# which executes <script> as soon as <mountpoint> is mounted.
Harald Hoyer 6adbc8
+inst_mount_hook() {
Harald Hoyer 6adbc8
+    local _prio="$2" _jobname="$3" _script="$4"
Harald Hoyer 6adbc8
+    local _hookname="mount-$(str_replace "$1" '/' '\\x2f')"
Harald Hoyer 6adbc8
+    [ -d "$hookdir/${_hookname}" ] || mkdir -p "$hookdir/${_hookname}"
Harald Hoyer 6adbc8
+    inst_hook --hook "$_hookname" --unique --name "${_prio}-${_jobname}" "$_script"
Harald Hoyer 6adbc8
+}
Harald Hoyer 6adbc8
+
Harald Hoyer 6adbc8
+# add_mount_point <dev> <mountpoint> <filesystem> <fsopts>
Harald Hoyer 6adbc8
+#
Harald Hoyer 6adbc8
+# Mount <dev> on <mountpoint> with <filesystem> and <fsopts>
Harald Hoyer 6adbc8
+# and call any mount hooks, as soon, as it is mounted
Harald Hoyer 6adbc8
+add_mount_point() {
Harald Hoyer 6adbc8
+    local _dev="$1" _mp="$2" _fs="$3" _fsopts="$4"
Harald Hoyer 6adbc8
+    local _hookname="mount-$(str_replace "$2" '/' '\\x2f')"
Harald Hoyer 6adbc8
+    local _devname="dev-$(str_replace "$1" '/' '\\x2f')"
Harald Hoyer 6adbc8
+    echo "$_dev $_mp $_fs $_fsopts 0 0" >> /etc/fstab
Harald Hoyer 6adbc8
+
Harald Hoyer 6adbc8
+    exec 7>/etc/udev/rules.d/99-mount-${_devname}.rules
Harald Hoyer 6adbc8
+    echo 'SUBSYSTEM!="block", GOTO="mount_end"' >&7
Harald Hoyer 6adbc8
+    echo 'ACTION!="add|change", GOTO="mount_end"' >&7
Harald Hoyer 6adbc8
+    if [ -n "$_dev" ]; then
Harald Hoyer 6adbc8
+        udevmatch "$_dev" >&7 || {
Harald Hoyer 6adbc8
+            warn "add_mount_point dev=$_dev incorrect!"
Harald Hoyer 6adbc8
+            continue
Harald Hoyer 6adbc8
+        }
Harald Hoyer 6adbc8
+        printf ', ' >&7
Harald Hoyer 6adbc8
+    fi
Harald Hoyer 6adbc8
+
Harald Hoyer 6adbc8
+    {
Harald Hoyer 6adbc8
+        printf -- 'RUN+="%s --unique --onetime ' $(command -v initqueue)
Harald Hoyer 6adbc8
+        printf -- '--name mount-%%k '
Harald Hoyer 6adbc8
+        printf -- '%s %s"\n' "$(command -v mount_hook)" "${_mp}"
Harald Hoyer 6adbc8
+    } >&7
Harald Hoyer 6adbc8
+    echo 'LABEL="mount_end"' >&7
Harald Hoyer 6adbc8
+    exec 7>&-
Harald Hoyer 6adbc8
+}
Harald Hoyer 6adbc8
+
Harald Hoyer 6adbc8
+# wait_for_mount <mountpoint>
Harald Hoyer 6adbc8
+#
Harald Hoyer 6adbc8
+# Installs a initqueue-finished script,
Harald Hoyer 6adbc8
+# which will cause the main loop only to exit,
Harald Hoyer 6adbc8
+# if <mountpoint> is mounted.
Harald Hoyer 6adbc8
 wait_for_mount()
Harald Hoyer 6adbc8
 {
Harald Hoyer 6adbc8
     local _name
Harald Hoyer 6adbc8
@@ -614,6 +700,11 @@ wait_for_mount()
Harald Hoyer 6adbc8
     } >> "$hookdir/emergency/90-${_name}.sh"
Harald Hoyer 6adbc8
 }
Harald Hoyer 6adbc8
 
Harald Hoyer 6adbc8
+# wait_for_dev <dev>
Harald Hoyer 6adbc8
+#
Harald Hoyer 6adbc8
+# Installs a initqueue-finished script,
Harald Hoyer 6adbc8
+# which will cause the main loop only to exit,
Harald Hoyer 6adbc8
+# if the device <dev> is recognized by the system.
Harald Hoyer 6adbc8
 wait_for_dev()
Harald Hoyer 6adbc8
 {
Harald Hoyer 6adbc8
     local _name