]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/90multipath/module-setup.sh
f825c00cd6c9e8ec8a5c1f636b67a7308f82ad46
[thirdparty/dracut.git] / modules.d / 90multipath / module-setup.sh
1 #!/bin/bash
2
3 is_mpath() {
4 local _dev=$1
5 [ -e /sys/dev/block/$_dev/dm/uuid ] || return 1
6 [[ $(cat /sys/dev/block/$_dev/dm/uuid) =~ mpath- ]] && return 0
7 return 1
8 }
9
10 majmin_to_mpath_dev() {
11 local _dev
12 for i in /dev/mapper/*; do
13 [[ $i == /dev/mapper/control ]] && continue
14 _dev=$(get_maj_min $i)
15 if [ "$_dev" = "$1" ]; then
16 echo $i
17 return
18 fi
19 done
20 }
21
22 # called by dracut
23 check() {
24 local _rootdev
25
26 [[ $hostonly ]] || [[ $mount_needs ]] && {
27 for_each_host_dev_and_slaves is_mpath || return 255
28 }
29
30 # if there's no multipath binary, no go.
31 require_binaries multipath || return 1
32
33 return 0
34 }
35
36 # called by dracut
37 depends() {
38 echo rootfs-block
39 echo dm
40 return 0
41 }
42
43 # called by dracut
44 cmdline() {
45 for m in scsi_dh_alua scsi_dh_emc scsi_dh_rdac dm_multipath; do
46 if grep -m 1 -q "$m" /proc/modules ; then
47 printf 'rd.driver.pre=%s ' "$m"
48 fi
49 done
50 }
51
52 # called by dracut
53 installkernel() {
54 local _ret
55 local _arch=$(uname -m)
56 local _funcs='scsi_register_device_handler|dm_dirty_log_type_register|dm_register_path_selector|dm_register_target'
57 local _s390
58
59 if [ "$_arch" = "s390" -o "$_arch" = "s390x" ]; then
60 _s390drivers="=drivers/s390/scsi"
61 fi
62
63 hostonly='' dracut_instmods -o -s "$_funcs" "=drivers/scsi" "=drivers/md" ${_s390drivers:+"$_s390drivers"}
64 }
65
66 # called by dracut
67 install() {
68 local _f _allow
69
70 add_hostonly_mpath_conf() {
71 is_mpath $1 && {
72 local _dev
73
74 _dev=$(majmin_to_mpath_dev $1)
75 [ -z "$_dev" ] && return
76 strstr "$_allow" "$_dev" && return
77 _allow="$_allow --allow $_dev"
78 }
79 }
80
81 inst_multiple -o \
82 dmsetup \
83 kpartx \
84 mpath_wait \
85 multipath \
86 multipathd \
87 mpathpersist \
88 xdrgetuid \
89 xdrgetprio \
90 /etc/xdrdevices.conf \
91 /etc/multipath.conf \
92 /etc/multipath/* \
93 /etc/multipath/conf.d/*
94
95 [[ $hostonly ]] && [[ $hostonly_mode = "strict" ]] && {
96 for_each_host_dev_and_slaves_all add_hostonly_mpath_conf
97 [ -n "$_allow" ] && mpathconf $_allow --outfile ${initdir}/etc/multipath.conf
98 }
99
100 inst $(command -v partx) /sbin/partx
101
102 inst_libdir_file "libmultipath*" "multipath/*"
103 inst_libdir_file 'libgcc_s.so*'
104
105 if [[ $hostonly_cmdline ]] ; then
106 local _conf=$(cmdline)
107 [[ $_conf ]] && echo "$_conf" >> "${initdir}/etc/cmdline.d/90multipath.conf"
108 fi
109
110 if dracut_module_included "systemd"; then
111 inst_simple "${moddir}/multipathd.service" "${systemdsystemunitdir}/multipathd.service"
112 mkdir -p "${initdir}${systemdsystemunitdir}/sysinit.target.wants"
113 ln -rfs "${initdir}${systemdsystemunitdir}/multipathd.service" "${initdir}${systemdsystemunitdir}/sysinit.target.wants/multipathd.service"
114 else
115 inst_hook pre-trigger 02 "$moddir/multipathd.sh"
116 inst_hook cleanup 02 "$moddir/multipathd-stop.sh"
117 fi
118
119 inst_hook cleanup 80 "$moddir/multipathd-needshutdown.sh"
120 inst_hook shutdown 20 "$moddir/multipath-shutdown.sh"
121
122 inst_rules 40-multipath.rules 56-multipath.rules \
123 62-multipath.rules 65-multipath.rules \
124 66-kpartx.rules 67-kpartx-compat.rules \
125 11-dm-mpath.rules
126 }
127