]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/95iscsi/module-setup.sh
95iscsi: More empty cmdline fixes
[thirdparty/dracut.git] / modules.d / 95iscsi / module-setup.sh
1 #!/bin/bash
2
3 # called by dracut
4 check() {
5 local _rootdev
6 # If our prerequisites are not met, fail anyways.
7 require_binaries iscsistart hostname iscsi-iname || return 1
8
9 # If hostonly was requested, fail the check if we are not actually
10 # booting from root.
11
12 is_iscsi() {
13 local _dev=$1
14
15 [[ -L "/sys/dev/block/$_dev" ]] || return
16 cd "$(readlink -f "/sys/dev/block/$_dev")"
17 until [[ -d sys || -d iscsi_session ]]; do
18 cd ..
19 done
20 [[ -d iscsi_session ]]
21 }
22
23 [[ $hostonly ]] || [[ $mount_needs ]] && {
24 pushd . >/dev/null
25 for_each_host_dev_and_slaves is_iscsi || return 255
26 popd >/dev/null
27 }
28 return 0
29 }
30
31 get_ibft_mod() {
32 local ibft_mac=$1
33 # Return the iSCSI offload module for a given MAC address
34 iscsiadm -m iface | while read iface_name iface_desc ; do
35 IFS=$','
36 set -- $iface_desc
37 if [ "$ibft_mac" = "$2" ] ; then
38 echo $1
39 return 0
40 fi
41 unset IFS
42 done
43 }
44
45 install_ibft() {
46 # When iBFT / iscsi_boot is detected:
47 # - Use 'ip=ibft' to set up iBFT network interface
48 # Note: bnx2i is using a different MAC address of iSCSI offloading
49 # so the 'ip=ibft' parameter must not be set
50 # - specify firmware booting cmdline parameter
51
52 for d in /sys/firmware/* ; do
53 if [ -d ${d}/ethernet0 ] ; then
54 read ibft_mac < ${d}/ethernet0/mac
55 ibft_mod=$(get_ibft_mod $ibft_mac)
56 fi
57 if [ -z "$ibft_mod" ] && [ -d ${d}/ethernet1 ] ; then
58 read ibft_mac < ${d}/ethernet1/mac
59 ibft_mod=$(get_ibft_mod $ibft_mac)
60 fi
61 if [ -d ${d}/initiator ] ; then
62 if [ ${d##*/} = "ibft" ] && [ "$ibft_mod" != "bnx2i" ] ; then
63 echo -n "ip=ibft "
64 fi
65 echo -n "rd.iscsi.firmware=1"
66 fi
67 done
68 }
69
70 # called by dracut
71 depends() {
72 echo network rootfs-block
73 }
74
75 # called by dracut
76 installkernel() {
77 local _arch=$(uname -m)
78
79 instmods bnx2i qla4xxx cxgb3i cxgb4i be2iscsi
80 hostonly="" instmods iscsi_tcp iscsi_ibft crc32c iscsi_boot_sysfs
81 iscsi_module_filter() {
82 local _funcs='iscsi_register_transport'
83 # subfunctions inherit following FDs
84 local _merge=8 _side2=9
85 function bmf1() {
86 local _f
87 while read _f; do
88 case "$_f" in
89 *.ko) [[ $(< $_f) =~ $_funcs ]] && echo "$_f" ;;
90 *.ko.gz) [[ $(gzip -dc <$_f) =~ $_funcs ]] && echo "$_f" ;;
91 *.ko.xz) [[ $(xz -dc <$_f) =~ $_funcs ]] && echo "$_f" ;;
92 esac
93 done
94 return 0
95 }
96
97 function rotor() {
98 local _f1 _f2
99 while read _f1; do
100 echo "$_f1"
101 if read _f2; then
102 echo "$_f2" 1>&${_side2}
103 fi
104 done | bmf1 1>&${_merge}
105 return 0
106 }
107 # Use two parallel streams to filter alternating modules.
108 set +x
109 eval "( ( rotor ) ${_side2}>&1 | bmf1 ) ${_merge}>&1"
110 [[ $debug ]] && set -x
111 return 0
112 }
113
114 { find_kernel_modules_by_path drivers/scsi; if [ "$_arch" = "s390" -o "$_arch" = "s390x" ]; then find_kernel_modules_by_path drivers/s390/scsi; fi;} \
115 | iscsi_module_filter | instmods
116 }
117
118 # called by dracut
119 cmdline() {
120 install_ibft
121 }
122
123 # called by dracut
124 install() {
125 inst_multiple umount iscsistart hostname iscsi-iname
126 inst_multiple -o iscsiuio
127 inst_libdir_file 'libgcc_s.so*'
128
129 # Detect iBFT and perform mandatory steps
130 if [[ $hostonly_cmdline == "yes" ]] ; then
131 local _ibftconf=$(install_ibft)
132 [[ $_ibftconf ]] && printf "%s\n" "$_ibftconf" >> "${initdir}/etc/cmdline.d/95iscsi.conf"
133 fi
134
135 inst_hook cmdline 90 "$moddir/parse-iscsiroot.sh"
136 inst_hook cleanup 90 "$moddir/cleanup-iscsi.sh"
137 inst "$moddir/iscsiroot.sh" "/sbin/iscsiroot"
138 if ! dracut_module_included "systemd"; then
139 inst "$moddir/mount-lun.sh" "/bin/mount-lun.sh"
140 fi
141 dracut_need_initqueue
142 }