]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/95iscsi/module-setup.sh
Factor out all the "type -V" commands
[thirdparty/dracut.git] / modules.d / 95iscsi / module-setup.sh
1 #!/bin/bash
2 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
3 # ex: ts=8 sw=4 sts=4 et filetype=sh
4
5 # called by dracut
6 check() {
7 local _rootdev
8 # If our prerequisites are not met, fail anyways.
9 require_binaries iscsistart hostname iscsi-iname || return 1
10
11 # If hostonly was requested, fail the check if we are not actually
12 # booting from root.
13
14 is_iscsi() {
15 local _dev=$1
16
17 [[ -L "/sys/dev/block/$_dev" ]] || return
18 cd "$(readlink -f "/sys/dev/block/$_dev")"
19 until [[ -d sys || -d iscsi_session ]]; do
20 cd ..
21 done
22 [[ -d iscsi_session ]]
23 }
24
25 [[ $hostonly ]] || [[ $mount_needs ]] && {
26 pushd . >/dev/null
27 for_each_host_dev_and_slaves is_iscsi || return 255
28 popd >/dev/null
29 }
30 return 0
31 }
32
33 # called by dracut
34 depends() {
35 echo network rootfs-block
36 }
37
38 # called by dracut
39 installkernel() {
40 local _arch=$(uname -m)
41
42 instmods bnx2i qla4xxx cxgb3i cxgb4i be2iscsi
43 hostonly="" instmods iscsi_tcp iscsi_ibft crc32c iscsi_boot_sysfs
44 iscsi_module_filter() {
45 local _funcs='iscsi_register_transport'
46 # subfunctions inherit following FDs
47 local _merge=8 _side2=9
48 function bmf1() {
49 local _f
50 while read _f; do
51 case "$_f" in
52 *.ko) [[ $(< $_f) =~ $_funcs ]] && echo "$_f" ;;
53 *.ko.gz) [[ $(gzip -dc <$_f) =~ $_funcs ]] && echo "$_f" ;;
54 *.ko.xz) [[ $(xz -dc <$_f) =~ $_funcs ]] && echo "$_f" ;;
55 esac
56 done
57 return 0
58 }
59
60 function rotor() {
61 local _f1 _f2
62 while read _f1; do
63 echo "$_f1"
64 if read _f2; then
65 echo "$_f2" 1>&${_side2}
66 fi
67 done | bmf1 1>&${_merge}
68 return 0
69 }
70 # Use two parallel streams to filter alternating modules.
71 set +x
72 eval "( ( rotor ) ${_side2}>&1 | bmf1 ) ${_merge}>&1"
73 [[ $debug ]] && set -x
74 return 0
75 }
76
77 { find_kernel_modules_by_path drivers/scsi; if [ "$_arch" = "s390" -o "$_arch" = "s390x" ]; then find_kernel_modules_by_path drivers/s390/scsi; fi;} \
78 | iscsi_module_filter | instmods
79 }
80
81 # called by dracut
82 install() {
83 inst_multiple umount iscsistart hostname iscsi-iname
84 inst_multiple -o iscsiuio
85 inst_hook cmdline 90 "$moddir/parse-iscsiroot.sh"
86 inst_hook cleanup 90 "$moddir/cleanup-iscsi.sh"
87 inst "$moddir/iscsiroot.sh" "/sbin/iscsiroot"
88 if ! dracut_module_included "systemd"; then
89 inst "$moddir/mount-lun.sh" "/bin/mount-lun.sh"
90 fi
91 dracut_need_initqueue
92 }