Skip to content

Commit c86f4d2

Browse files
Pingfan Liujohannbg
authored andcommitted
fix(kernel-modules): detect block device's hardware driver
On hostonly mode, the platform driver is not copied blindless. There should be a way to detect the real hardware driver, which probes a block device. /sys/dev/block/major:minor is a symbol link, which points to the real device, recording the hardware stack. And those info can help to identify the associated drivers for the hardware stack. Signed-off-by: Pingfan Liu <piliu@redhat.com> --- v2 -> v3: address shellcheck in dracut-functions.sh v1 -> v2: remove local variable _extra_mod shorten subject
1 parent b292ce7 commit c86f4d2

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

dracut-functions.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,27 @@ for_each_host_dev_and_slaves() {
617617
return 1
618618
}
619619
620+
# /sys/dev/block/major:minor is symbol link to real hardware device
621+
# go downstream $(realpath /sys/dev/block/major:minor) to detect driver
622+
get_blockdev_drv_through_sys() {
623+
local _block_mods=""
624+
local _path
625+
626+
_path=$(realpath "$1")
627+
while true; do
628+
if [[ -L "$_path"/driver/module ]]; then
629+
_mod=$(realpath "$_path"/driver/module)
630+
_mod=$(basename "$_mod")
631+
_block_mods="$_block_mods $_mod"
632+
fi
633+
_path=$(dirname "$_path")
634+
if [[ $_path == '/sys/devices' ]] || [[ $_path == '/' ]]; then
635+
break
636+
fi
637+
done
638+
echo "$_block_mods"
639+
}
640+
620641
# ugly workaround for the lvm design
621642
# There is no volume group device,
622643
# so, there are no slave devices for volume groups.

modules.d/90kernel-modules/module-setup.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ installkernel() {
1616
}
1717

1818
record_block_dev_drv() {
19+
1920
for _mod in $(get_dev_module /dev/block/"$1"); do
2021
_hostonly_drvs["$_mod"]="$_mod"
2122
done
23+
24+
for _mod in $(get_blockdev_drv_through_sys "/sys/dev/block/$1"); do
25+
_hostonly_drvs["$_mod"]="$_mod"
26+
done
27+
2228
((${#_hostonly_drvs[@]} > 0)) && return 0
2329
return 1
2430
}

0 commit comments

Comments
 (0)