#!/bin/sh
#
# multipath: load modules and daemon

PREREQ=" "

prereqs() { echo "$PREREQ"; }

case $1 in
prereqs)
	prereqs
	exit 0
	;;
esac

. /scripts/functions

verbose()
{
	case "$quiet" in y*|Y*|1|t*|T*)
		return 1;;
	*)
		return 0;;
	esac
}

maybe_break pre-multipath

VERBOSITY=0
HW_HANDLERS="scsi_dh_alua scsi_dh_rdac scsi_dh_emc"
MP_MODULES="dm-multipath"

verbose && log_begin_msg "Loading multipath modules"
for module in ${MP_MODULES}; do
	if modprobe --syslog "$module"; then
		verbose && log_success_msg "loaded module ${module}."
	else
		log_failure_msg "failed to load module ${module}."
	fi
done
verbose && log_end_msg

verbose && log_begin_msg "Loading multipath hardware handlers"
for module in ${HW_HANDLERS}; do
	if modprobe --syslog "$module"; then
		verbose && log_success_msg "loaded module ${module}."
	else
		log_failure_msg "failed to load module ${module}."
	fi
done
verbose && log_end_msg

# Start multipathd
verbose && log_begin_msg "Starting multipathd"
# If the /etc/multipath/bindings file does not exist, multipathd -B will fail
# and exit. Calling multipath first in dry-run mode will ensure the file gets
# created. See LP: #2120444
# Please note that if the path to the bindings file is configured
# differently, this test should be updated.
if [ ! -f /etc/multipath/bindings ]; then
    multipath -B -d
fi

multipathd -B
verbose && log_end_msg

maybe_break post-multipath

exit 0
