Skip to content

Commit

Permalink
Merge 1e14eb6 into 227cd11
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkSymsCtx committed Jan 7, 2020
2 parents 227cd11 + 1e14eb6 commit 6d23b12
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions mk/sm.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ tests/run_python_unittests.sh
/opt/xensource/libexec/make-dummy-sr
/opt/xensource/libexec/usb_change
/opt/xensource/libexec/kickpipe
/opt/xensource/libexec/set-iscsi-initiator
/opt/xensource/sm/DummySR
/opt/xensource/sm/DummySR.py
/opt/xensource/sm/DummySR.pyc
Expand Down
66 changes: 66 additions & 0 deletions scripts/set-iscsi-initiator
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/sh
#
# Copyright (C) Citrix Systems Inc.
#
# 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.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

SCRIPT=$(basename $0)
TMPDIR=$(mktemp --tmpdir -d $SCRIPT.XXXXXXXXX)
cleanup() {
if [ -n "$TMPDIR" ]; then
rm -rf "$TMPDIR"
fi
}
ecleanup() {
cleanup
exit 1
}
trap cleanup EXIT
trap ecleanup INT
trap ecleanup TERM

INITIATORFILE=/etc/iscsi/initiatorname.iscsi
TMPFILE=$TMPDIR/initiatorname.iscsi

(
flock -s 200

iscsiadm -m session > /dev/null 2>&1
if [ $? -eq 0 ]
then
logger -p local2.err "set-iscsi-initiator active sessions so not updating"
exit 1
fi

echo "InitiatorName=$1" > $TMPFILE
echo "InitiatorAlias=$2" >> $TMPFILE

diff $INITIATORFILE $TMPFILE > /dev/null 2>&1
if [ $? -eq 0 ]
then
# unchanged so remove the tmp file
rm $TMPFILE
exit 0
fi

mv $TMPFILE $INITIATORFILE

systemctl is-active -q iscsid
if [ $? -eq 0 ]
then
# iscsid is running so restart
systemctl restart iscsid
fi

) 200>/var/lock/sm/iscsiadm/running

0 comments on commit 6d23b12

Please sign in to comment.