get block device driver if in a virtual subsystem

(cherry picked from commit 2c3017817e2cfc2f246b98dc8c45338c0a57737a)
This commit is contained in:
wangyuhang 2023-11-16 15:10:08 +08:00 committed by openeuler-sync-bot
parent 89896dde7c
commit 37f17d0e29
2 changed files with 70 additions and 1 deletions

View File

@ -0,0 +1,65 @@
From dc3b976f3393d7a3fb75b349418fc8ee2c9142bd Mon Sep 17 00:00:00 2001
From: Antonio Alvarez Feijoo <antonio.feijoo@suse.com>
Date: Wed, 10 Nov 2021 10:19:14 +0100
Subject: [PATCH] fix(dracut-functions.sh): get block device driver if in a
virtual subsystem
dracut does not install the kernel module of the block device that contains
the root filesystem if the following preconditions are met:
- Running in host-only mode.
- Symlinks of all block devices needed to boot the system pointing to virtual
subsystems.
The get_dev_module function uses "udevadm info -a" to get the corresponding
kernel modules of a /sys/class/*/* or /dev/* device. This function is called
in modules.d/90kernel-modules/module-setup.sh to detect if dracut must install
block device drivers in host-only mode. The symlinks in /sys/dev/block/
usually point to "real" devices in /sys/devices/pci*. But, we have come across
some NVMe systems where the kernel creates the symlinks in /sys/dev/block/
pointing to "virtual" devices instead. In this case, udevadm never finds any
"driver" attributes following up the chain of parent devices.
Reference:https://github.com/dracutdevs/dracut/commit/dc3b976f3393d7a3fb75b349418fc8ee2c9142bd
Conflict:NA
---
dracut-functions.sh | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/dracut-functions.sh b/dracut-functions.sh
index 32177994..63b6c892 100755
--- a/dracut-functions.sh
+++ b/dracut-functions.sh
@@ -945,5 +945,29 @@ block_is_netdevice() {
# get the corresponding kernel modules of a /sys/class/*/* or/dev/* device
get_dev_module() {
- udevadm info -a "$1" | sed -n 's/\s*DRIVERS=="\(\S\+\)"/\1/p'
+ local dev_attr_walk
+ local dev_drivers
+ dev_attr_walk=$(udevadm info -a "$1")
+ dev_drivers=$(echo "$dev_attr_walk" | sed -n 's/\s*DRIVERS=="\(\S\+\)"/\1/p')
+ # if no kernel modules found and device is in a virtual subsystem, follow symlinks
+ if [[ -z $dev_drivers && $(udevadm info -q path "$1") == "/devices/virtual"* ]]; then
+ local dev_vkernel
+ local dev_vsubsystem
+ local dev_vpath
+ dev_vkernel=$(echo "$dev_attr_walk" | sed -n 's/\s*KERNELS=="\(\S\+\)"/\1/p' | tail -1)
+ dev_vsubsystem=$(echo "$dev_attr_walk" | sed -n 's/\s*SUBSYSTEMS=="\(\S\+\)"/\1/p' | tail -1)
+ dev_vpath="/sys/devices/virtual/$dev_vsubsystem/$dev_vkernel"
+ if [[ -n $dev_vkernel && -n $dev_vsubsystem && -d $dev_vpath ]]; then
+ local dev_links
+ local dev_link
+ dev_links=$(find "$dev_vpath" -maxdepth 1 -type l ! -name "subsystem" -exec readlink {} \;)
+ for dev_link in $dev_links; do
+ [[ -n $dev_drivers && ${dev_drivers: -1} != $'\n' ]] && dev_drivers+=$'\n'
+ dev_drivers+=$(udevadm info -a "$dev_vpath/$dev_link" \
+ | sed -n 's/\s*DRIVERS=="\(\S\+\)"/\1/p' \
+ | grep -v -e pcieport)
+ done
+ fi
+ fi
+ echo "$dev_drivers"
}
--
2.33.0

View File

@ -9,7 +9,7 @@
Name: dracut
Version: 055
Release: 7
Release: 8
Summary: Initramfs generator using udev
@ -40,6 +40,7 @@ Patch13: backport-feat-lvm-only-run-lvchange-for-LV-that-is-seen-on-de.patch
Patch14: backport-fix-lvm-restore-setting-LVM_MD_PV_ACTIVATED.patch
Patch15: backport-Bring-back-51-dracut-rescue-postinst.sh.patch
Patch16: backport-fix-dracut-shutdown-add-cleanup-handler-on-failure.patch
Patch17: backport-fix-dracut-functions.sh-get-block-device-driver-if-i.patch
Patch9000: remove-iscsi-related-code-since-it-is-no-longer-main.patch
@ -516,6 +517,9 @@ install -m 0755 51-dracut-rescue-postinst.sh $RPM_BUILD_ROOT%{_sysconfdir}/kerne
%endif
%changelog
* Thu Nov 16 2023 wangyuhang <wangyuhang27@huawei.com> - 055-8
- get block device driver if in a virtual subsystem
* Wed Mar 22 2023 wangyuhang <wangyuhang27@huawei.com> - 055-7
- fix(dracut-shutdown): add cleanup handler on failure