#!/bin/bash
# Copyright (C) 2006-2007 XenSource Ltd.
# Copyright (C) 2008-2009 Citrix Ltd.
#
# This program is free software; you can redistribute it and/or modify 
# it under the terms of the GNU Lesser General Public License as published 
# by the Free Software Foundation; version 2.1 only.
#
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
# GNU Lesser General Public License for more details.

DEFAULT_TIMEOUT=30
MPATH_TIMEOUT=10

# Check for QLogic Ports
if [ -e "/sys/class/fc_remote_ports" ]; then
    for i in `ls /sys/class/fc_remote_ports`; do
	if [ $1 == "enable" ]; then
	    echo ${MPATH_TIMEOUT} > /sys/class/fc_remote_ports/${i}/dev_loss_tmo
	else
	    echo ${DEFAULT_TIMEOUT} > /sys/class/fc_remote_ports/${i}/dev_loss_tmo
	fi
	echo "Adjusted Qlogic port ${i} dev_loss_tmo"
    done
fi

# Now check for Emulex
for i in `ls /sys/class/scsi_host`; do
    if [ -e "/sys/class/scsi_host/${i}/lpfc_fcp_class" ]; then
	if [ $1 == "enable" ]; then
	    echo ${MPATH_TIMEOUT} > /sys/class/scsi_host/${i}/lpfc_nodev_tmo
	else
	    echo ${DEFAULT_TIMEOUT} > /sys/class/scsi_host/${i}/lpfc_nodev_tmo
	fi
	echo "Adjusted Emulex port ${i} lpfc_nodev_tmo"
    fi
done

