28ab1c
From bc6b4ffd4e7babd34e207c2aa8bed7f0fd8bafcf Mon Sep 17 00:00:00 2001
28ab1c
From: Lukas Nykryn <lnykryn@redhat.com>
28ab1c
Date: Mon, 2 Aug 2021 12:42:09 +0200
28ab1c
Subject: [PATCH] dracut-functions: backport block_is_* functions
28ab1c
28ab1c
Based on 480aa9695f8c2e2b30c8f41ae8483140020d23db
28ab1c
RHEL-only
28ab1c
28ab1c
Related: #1959336
28ab1c
---
28ab1c
 dracut-functions.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++
28ab1c
 1 file changed, 44 insertions(+)
28ab1c
28ab1c
diff --git a/dracut-functions.sh b/dracut-functions.sh
28ab1c
index d75696fd..14e60a9c 100755
28ab1c
--- a/dracut-functions.sh
28ab1c
+++ b/dracut-functions.sh
28ab1c
@@ -718,3 +718,47 @@ btrfs_devs() {
28ab1c
         printf -- "%s\n" "$_dev"
28ab1c
         done
28ab1c
 }
28ab1c
+
28ab1c
+# block_is_nbd <maj:min>
28ab1c
+# Check whether $1 is an nbd device
28ab1c
+block_is_nbd() {
28ab1c
+    [[ -b /dev/block/$1 && $1 == 43:* ]]
28ab1c
+}
28ab1c
+
28ab1c
+# block_is_iscsi <maj:min>
28ab1c
+# Check whether $1 is an nbd device
28ab1c
+block_is_iscsi() {
28ab1c
+    local _dir
28ab1c
+    local _dev=$1
28ab1c
+    [[ -L "/sys/dev/block/$_dev" ]] || return
28ab1c
+    _dir="$(readlink -f "/sys/dev/block/$_dev")" || return
28ab1c
+    until [[ -d "$_dir/sys" || -d "$_dir/iscsi_session" ]]; do
28ab1c
+        _dir="$_dir/.."
28ab1c
+    done
28ab1c
+    [[ -d "$_dir/iscsi_session" ]]
28ab1c
+}
28ab1c
+
28ab1c
+# block_is_fcoe <maj:min>
28ab1c
+# Check whether $1 is an FCoE device
28ab1c
+# Will not work for HBAs that hide the ethernet aspect
28ab1c
+# completely and present a pure FC device
28ab1c
+block_is_fcoe() {
28ab1c
+    local _dir
28ab1c
+    local _dev=$1
28ab1c
+    [[ -L "/sys/dev/block/$_dev" ]] || return
28ab1c
+    _dir="$(readlink -f "/sys/dev/block/$_dev")"
28ab1c
+    until [[ -d "$_dir/sys" ]]; do
28ab1c
+        _dir="$_dir/.."
28ab1c
+        if [[ -d "$_dir/subsystem" ]]; then
28ab1c
+            subsystem=$(basename $(readlink $_dir/subsystem))
28ab1c
+            [[ $subsystem == "fcoe" ]] && return 0
28ab1c
+        fi
28ab1c
+    done
28ab1c
+    return 1
28ab1c
+}
28ab1c
+
28ab1c
+# block_is_netdevice <maj:min>
28ab1c
+# Check whether $1 is a net device
28ab1c
+block_is_netdevice() {
28ab1c
+    block_is_nbd "$1" || block_is_iscsi "$1" || block_is_fcoe "$1"
28ab1c
+}
28ab1c
\ No newline at end of file
28ab1c