Blame 0011-dracut-functions.sh-make-use-of-findmnt.patch

Harald Hoyer ab11ed
From 9d36d4fb1d0774d9ef0597abb79390e88771bf1e Mon Sep 17 00:00:00 2001
Harald Hoyer ab11ed
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer ab11ed
Date: Tue, 9 Apr 2013 10:47:39 +0200
Harald Hoyer ab11ed
Subject: [PATCH] dracut-functions.sh: make use of findmnt
Harald Hoyer ab11ed
Harald Hoyer ab11ed
---
Harald Hoyer ab11ed
 dracut-functions.sh | 163 +++++++++++++++++++++-------------------------------
Harald Hoyer ab11ed
 1 file changed, 64 insertions(+), 99 deletions(-)
Harald Hoyer ab11ed
Harald Hoyer ab11ed
diff --git a/dracut-functions.sh b/dracut-functions.sh
Harald Hoyer ab11ed
index eba7412..96d3c6e 100755
Harald Hoyer ab11ed
--- a/dracut-functions.sh
Harald Hoyer ab11ed
+++ b/dracut-functions.sh
Harald Hoyer ab11ed
@@ -319,131 +319,96 @@ get_maj_min() {
Harald Hoyer ab11ed
 # $ find_block_device /usr
Harald Hoyer ab11ed
 # 8:4
Harald Hoyer ab11ed
 find_block_device() {
Harald Hoyer ab11ed
-    local _x _mpt _majmin _dev _fs _maj _min _find_mpt
Harald Hoyer ab11ed
+    local _majmin _dev _majmin _find_mpt
Harald Hoyer ab11ed
     _find_mpt="$1"
Harald Hoyer ab11ed
     if [[ $use_fstab != yes ]]; then
Harald Hoyer ab11ed
-        while read _x; do
Harald Hoyer ab11ed
-            set -- $_x
Harald Hoyer ab11ed
-            _majmin="$3"
Harald Hoyer ab11ed
-            _mpt="$5"
Harald Hoyer ab11ed
-            [[ $8 = "-" ]] && shift
Harald Hoyer ab11ed
-            _fs="$8"
Harald Hoyer ab11ed
-            _dev="$9"
Harald Hoyer ab11ed
-            [[ $_mpt = $_find_mpt ]] || continue
Harald Hoyer ab11ed
-            [[ $_fs = nfs ]] && { echo $_dev; return 0;}
Harald Hoyer ab11ed
-            [[ $_fs = nfs3 ]] && { echo $_dev; return 0;}
Harald Hoyer ab11ed
-            [[ $_fs = nfs4 ]] && { echo $_dev; return 0;}
Harald Hoyer ab11ed
-            [[ $_fs = btrfs ]] && {
Harald Hoyer ab11ed
-                get_maj_min $_dev
Harald Hoyer ab11ed
-                return 0;
Harald Hoyer ab11ed
-            }
Harald Hoyer ab11ed
-            if [[ ${_majmin#0:} = $_majmin ]]; then
Harald Hoyer ab11ed
-                echo $_majmin
Harald Hoyer ab11ed
-                return 0 # we have a winner!
Harald Hoyer ab11ed
+        [[ -d $_find_mpt/. ]]
Harald Hoyer ab11ed
+        while read _majmin _dev; do
Harald Hoyer ab11ed
+            if [[ -b $_dev ]]; then
Harald Hoyer ab11ed
+                if ! [[ $_majmin ]] || [[ $_majmin == 0:* ]]; then
Harald Hoyer ab11ed
+                    read _majmin < <(get_maj_min $_dev)
Harald Hoyer ab11ed
+                fi
Harald Hoyer ab11ed
+                if [[ $_majmin ]]; then
Harald Hoyer ab11ed
+                    echo $_majmin
Harald Hoyer ab11ed
+                else
Harald Hoyer ab11ed
+                    echo $_dev
Harald Hoyer ab11ed
+                fi
Harald Hoyer ab11ed
+                return 0
Harald Hoyer ab11ed
+            fi
Harald Hoyer ab11ed
+            if [[ $_dev = *:* ]]; then
Harald Hoyer ab11ed
+                echo $_dev
Harald Hoyer ab11ed
+                return 0
Harald Hoyer ab11ed
             fi
Harald Hoyer ab11ed
-        done < /proc/self/mountinfo
Harald Hoyer ab11ed
+        done < <(findmnt -e -v -n -o 'MAJ:MIN,SOURCE' "$_find_mpt")
Harald Hoyer ab11ed
     fi
Harald Hoyer ab11ed
     # fall back to /etc/fstab
Harald Hoyer ab11ed
-    while read _dev _mpt _fs _x; do
Harald Hoyer ab11ed
-        [ "${_dev%%#*}" != "$_dev" ] && continue
Harald Hoyer ab11ed
-
Harald Hoyer ab11ed
-        if [[ $_mpt = $_find_mpt ]]; then
Harald Hoyer ab11ed
-            [[ $_fs = nfs ]] && { echo $_dev; return 0;}
Harald Hoyer ab11ed
-            [[ $_fs = nfs3 ]] && { echo $_dev; return 0;}
Harald Hoyer ab11ed
-            [[ $_fs = nfs4 ]] && { echo $_dev; return 0;}
Harald Hoyer ab11ed
-            [[ $_dev != ${_dev#UUID=} ]] && _dev=/dev/disk/by-uuid/${_dev#UUID=}
Harald Hoyer ab11ed
-            [[ $_dev != ${_dev#LABEL=} ]] && _dev=/dev/disk/by-label/${_dev#LABEL=}
Harald Hoyer ab11ed
-            [[ -b $_dev ]] || return 1 # oops, not a block device.
Harald Hoyer ab11ed
-            get_maj_min "$_dev" && return 0
Harald Hoyer ab11ed
+
Harald Hoyer ab11ed
+    while read _majmin _dev; do
Harald Hoyer ab11ed
+        if ! [[ $_dev ]]; then
Harald Hoyer ab11ed
+            _dev="$_majmin"
Harald Hoyer ab11ed
+            unset _majmin
Harald Hoyer ab11ed
+        fi
Harald Hoyer ab11ed
+        if [[ -b $_dev ]]; then
Harald Hoyer ab11ed
+            [[ $_majmin ]] || read _majmin < <(get_maj_min $_dev)
Harald Hoyer ab11ed
+            if [[ $_majmin ]]; then
Harald Hoyer ab11ed
+                echo $_majmin
Harald Hoyer ab11ed
+            else
Harald Hoyer ab11ed
+                echo $_dev
Harald Hoyer ab11ed
+            fi
Harald Hoyer ab11ed
+            return 0
Harald Hoyer ab11ed
+        fi
Harald Hoyer ab11ed
+        if [[ $_dev = *:* ]]; then
Harald Hoyer ab11ed
+            echo $_dev
Harald Hoyer ab11ed
+            return 0
Harald Hoyer ab11ed
         fi
Harald Hoyer ab11ed
-    done < /etc/fstab
Harald Hoyer ab11ed
+    done < <(findmnt -e --fstab -v -n -o 'MAJ:MIN,SOURCE' "$_find_mpt")
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
     return 1
Harald Hoyer ab11ed
 }
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
-# find_dev_fstype <device>
Harald Hoyer ab11ed
-# Echo the filesystem type for a given device.
Harald Hoyer ab11ed
+# find_mp_fstype <mountpoint>
Harald Hoyer ab11ed
+# Echo the filesystem type for a given mountpoint.
Harald Hoyer ab11ed
 # /proc/self/mountinfo is taken as the primary source of information
Harald Hoyer ab11ed
 # and /etc/fstab is used as a fallback.
Harald Hoyer ab11ed
 # No newline is appended!
Harald Hoyer ab11ed
 # Example:
Harald Hoyer ab11ed
-# $ find_dev_fstype /dev/sda2;echo
Harald Hoyer ab11ed
+# $ find_mp_fstype /;echo
Harald Hoyer ab11ed
 # ext4
Harald Hoyer ab11ed
-find_dev_fstype() {
Harald Hoyer ab11ed
-    local _x _mpt _majmin _dev _fs _maj _min _find_dev
Harald Hoyer ab11ed
-    _find_dev="$1"
Harald Hoyer ab11ed
-    strstr "$_find_dev" "/dev" || _find_dev="/dev/block/$_find_dev"
Harald Hoyer ab11ed
-    while read _x; do
Harald Hoyer ab11ed
-        set -- $_x
Harald Hoyer ab11ed
-        _majmin="$3"
Harald Hoyer ab11ed
-        _mpt="$5"
Harald Hoyer ab11ed
-        [[ $8 = "-" ]] && shift
Harald Hoyer ab11ed
-        _fs="$8"
Harald Hoyer ab11ed
-        _dev="$9"
Harald Hoyer ab11ed
-        strstr "$_dev" "/dev" || continue
Harald Hoyer ab11ed
-        [[ $_dev -ef $_find_dev ]] || continue
Harald Hoyer ab11ed
-        [[ $_fs = "autofs" ]] && continue
Harald Hoyer ab11ed
-        echo -n $_fs;
Harald Hoyer ab11ed
-        return 0;
Harald Hoyer ab11ed
-    done < /proc/self/mountinfo
Harald Hoyer ab11ed
+find_mp_fstype() {
Harald Hoyer ab11ed
+    local _fs
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
-    # fall back to /etc/fstab
Harald Hoyer ab11ed
-    while read _dev _mpt _fs _x; do
Harald Hoyer ab11ed
-        [ "${_dev%%#*}" != "$_dev" ] && continue
Harald Hoyer ab11ed
-        case "$_dev" in
Harald Hoyer ab11ed
-            LABEL=*)
Harald Hoyer ab11ed
-                _dev="$(echo $_dev | sed 's,/,\\x2f,g')"
Harald Hoyer ab11ed
-                _dev="/dev/disk/by-label/${_dev#LABEL=}"
Harald Hoyer ab11ed
-                ;;
Harald Hoyer ab11ed
-            UUID=*)
Harald Hoyer ab11ed
-                _dev="/dev/disk/by-uuid/${_dev#UUID=}"
Harald Hoyer ab11ed
-                ;;
Harald Hoyer ab11ed
-            PARTUUID=*)
Harald Hoyer ab11ed
-                _dev="/dev/disk/by-partuuid/${_dev#PARTUUID=}"
Harald Hoyer ab11ed
-                ;;
Harald Hoyer ab11ed
-        esac
Harald Hoyer ab11ed
+    if [[ $use_fstab != yes ]]; then
Harald Hoyer ab11ed
+        while read _fs; do
Harald Hoyer ab11ed
+            [[ $_fs ]] || continue
Harald Hoyer ab11ed
+            [[ $_fs = "autofs" ]] && continue
Harald Hoyer ab11ed
+            echo -n $_fs
Harald Hoyer ab11ed
+            return 0
Harald Hoyer ab11ed
+        done < <(findmnt -e -v -n -o 'FSTYPE' "$1")
Harald Hoyer ab11ed
+    fi
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
-        [[ $_dev -ef $_find_dev ]] || continue
Harald Hoyer ab11ed
-        echo -n $_fs;
Harald Hoyer ab11ed
-        return 0;
Harald Hoyer ab11ed
-    done < /etc/fstab
Harald Hoyer ab11ed
+    while read _fs; do
Harald Hoyer ab11ed
+        [[ $_fs ]] || continue
Harald Hoyer ab11ed
+        [[ $_fs = "autofs" ]] && continue
Harald Hoyer ab11ed
+        echo -n $_fs
Harald Hoyer ab11ed
+        return 0
Harald Hoyer ab11ed
+    done < <(findmnt --fstab -e -v -n -o 'FSTYPE' "$1")
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
     return 1
Harald Hoyer ab11ed
 }
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
-# find_mp_fstype <mountpoint>
Harald Hoyer ab11ed
-# Echo the filesystem type for a given mountpoint.
Harald Hoyer ab11ed
+# find_dev_fstype <device>
Harald Hoyer ab11ed
+# Echo the filesystem type for a given device.
Harald Hoyer ab11ed
 # /proc/self/mountinfo is taken as the primary source of information
Harald Hoyer ab11ed
 # and /etc/fstab is used as a fallback.
Harald Hoyer ab11ed
 # No newline is appended!
Harald Hoyer ab11ed
 # Example:
Harald Hoyer ab11ed
-# $ find_mp_fstype /;echo
Harald Hoyer ab11ed
+# $ find_dev_fstype /dev/sda2;echo
Harald Hoyer ab11ed
 # ext4
Harald Hoyer ab11ed
-find_mp_fstype() {
Harald Hoyer ab11ed
-    local _x _mpt _majmin _dev _fs _maj _min _find_mpt
Harald Hoyer ab11ed
-    _find_mpt="$1"
Harald Hoyer ab11ed
-    while read _x; do
Harald Hoyer ab11ed
-        set -- $_x
Harald Hoyer ab11ed
-        _majmin="$3"
Harald Hoyer ab11ed
-        _mpt="$5"
Harald Hoyer ab11ed
-        [[ $8 = "-" ]] && shift
Harald Hoyer ab11ed
-        _fs="$8"
Harald Hoyer ab11ed
-        _dev="$9"
Harald Hoyer ab11ed
-        [[ $_mpt = $_find_mpt ]] || continue
Harald Hoyer ab11ed
-        [[ $_fs = "autofs" ]] && continue
Harald Hoyer ab11ed
-        echo -n $_fs;
Harald Hoyer ab11ed
-        return 0;
Harald Hoyer ab11ed
-    done < /proc/self/mountinfo
Harald Hoyer ab11ed
-
Harald Hoyer ab11ed
-    # fall back to /etc/fstab
Harald Hoyer ab11ed
-    while read _dev _mpt _fs _x; do
Harald Hoyer ab11ed
-        [ "${_dev%%#*}" != "$_dev" ] && continue
Harald Hoyer ab11ed
-        [[ $_mpt = $_find_mpt ]] || continue
Harald Hoyer ab11ed
-        echo -n $_fs;
Harald Hoyer ab11ed
-        return 0;
Harald Hoyer ab11ed
-    done < /etc/fstab
Harald Hoyer ab11ed
-
Harald Hoyer ab11ed
-    return 1
Harald Hoyer ab11ed
+find_dev_fstype() {
Harald Hoyer ab11ed
+    local _x _mpt _majmin _dev _fs _maj _min _find_dev
Harald Hoyer ab11ed
+    _find_dev="$1"
Harald Hoyer ab11ed
+    [[ "$_find_dev" = /dev* ]] || _find_dev="/dev/block/$_find_dev"
Harald Hoyer ab11ed
+    find_mp_fstype "$_find_dev"
Harald Hoyer ab11ed
 }
Harald Hoyer ab11ed
 
Harald Hoyer ab11ed
 # finds the major:minor of the block device backing the root filesystem.