Skip to content

Commit

Permalink
fix(kernel-modules): detect block device's hardware driver
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Pingfan Liu authored and johannbg committed Aug 13, 2021

Verified

This commit was signed with the committer’s verified signature.
1 parent b292ce7 commit c86f4d2
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions dracut-functions.sh
Original file line number Diff line number Diff line change
@@ -617,6 +617,27 @@ for_each_host_dev_and_slaves() {
return 1
}
# /sys/dev/block/major:minor is symbol link to real hardware device
# go downstream $(realpath /sys/dev/block/major:minor) to detect driver
get_blockdev_drv_through_sys() {
local _block_mods=""
local _path
_path=$(realpath "$1")
while true; do
if [[ -L "$_path"/driver/module ]]; then
_mod=$(realpath "$_path"/driver/module)
_mod=$(basename "$_mod")
_block_mods="$_block_mods $_mod"
fi
_path=$(dirname "$_path")
if [[ $_path == '/sys/devices' ]] || [[ $_path == '/' ]]; then
break
fi
done
echo "$_block_mods"
}
# ugly workaround for the lvm design
# There is no volume group device,
# so, there are no slave devices for volume groups.
6 changes: 6 additions & 0 deletions modules.d/90kernel-modules/module-setup.sh
Original file line number Diff line number Diff line change
@@ -16,9 +16,15 @@ installkernel() {
}

record_block_dev_drv() {

for _mod in $(get_dev_module /dev/block/"$1"); do
_hostonly_drvs["$_mod"]="$_mod"
done

for _mod in $(get_blockdev_drv_through_sys "/sys/dev/block/$1"); do
_hostonly_drvs["$_mod"]="$_mod"
done

((${#_hostonly_drvs[@]} > 0)) && return 0
return 1
}

0 comments on commit c86f4d2

Please sign in to comment.