Skip to content

Commit d6da563

Browse files
author
Don Brady
committed
DLPX-73229 iSCSI initiator name should be unique on each engine
1 parent b52e8f3 commit d6da563

File tree

4 files changed

+128
-1
lines changed

4 files changed

+128
-1
lines changed

debian/postinst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash -eux
22
#
3-
# Copyright 2018, 2019 Delphix
3+
# Copyright 2018, 2021 Delphix
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -51,6 +51,7 @@ configure)
5151
systemctl enable delphix.target
5252
systemctl enable delphix-platform.service
5353
systemctl enable systemd-networkd.service
54+
systemctl enable iscsi-name-init.service
5455

5556
if ! id -u postgres >/dev/null; then
5657
# When installing postgres, a postgres user is created unless it
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2021 by Delphix. All rights reserved.
4+
#
5+
6+
#
7+
# This script generates a unique initiator name based on the system-uuid
8+
#
9+
10+
PATH=/bin:/usr/bin/
11+
12+
NAME_FILE="/etc/iscsi/initiatorname.iscsi"
13+
AUTHORITY="2008-07.com.delphix"
14+
15+
if [[ -f $NAME_FILE ]]; then
16+
system_uuid=$(get-system-uuid)
17+
18+
if [[ ${#system_uuid} -ne 36 ]]; then
19+
echo "Error: unexpected UUID -- $system_uuid" >&2
20+
exit 1
21+
fi
22+
23+
name_entry="InitiatorName=iqn.$AUTHORITY:$system_uuid"
24+
25+
#
26+
# Generate IQN for this Delphix Engine (if not already present)
27+
#
28+
if ! grep -Gq "^$name_entry" $NAME_FILE; then
29+
{
30+
echo "## DO NOT EDIT OR REMOVE THIS FILE!"
31+
echo "## If you remove this file, the iSCSI daemon will not start."
32+
echo "## If you change the InitiatorName, existing access control lists"
33+
echo "## may reject this initiator. The InitiatorName must be unique"
34+
echo "## for each iSCSI initiator. Do NOT duplicate iSCSI InitiatorNames."
35+
printf '%s\n' "$name_entry"
36+
} >$NAME_FILE
37+
chmod 640 $NAME_FILE
38+
echo "Generating unique iSCSI name using UUID $system_uuid"
39+
fi
40+
fi
41+
42+
exit 0
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# Copyright 2021 Delphix
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
[Unit]
18+
Description=One time IQN configuration for iscsid.service
19+
Before=open-iscsi.service
20+
21+
[Service]
22+
Type=oneshot
23+
RemainAfterExit=no
24+
ExecStart=/lib/open-iscsi/unique-name-check.sh
25+
26+
[Install]
27+
WantedBy=open-iscsi.service

files/common/usr/bin/get-system-uuid

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2021 Delphix
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
PATH=/bin:/usr/bin/:/usr/sbin
19+
20+
set -o pipefail
21+
22+
function die() {
23+
echo "$(basename "$0"): $*" >&2
24+
exit 1
25+
}
26+
27+
[[ "$EUID" -ne 0 ]] && die "must be run as root"
28+
29+
if [[ $# -ne 0 ]]; then
30+
echo "Error: unexpected arguments"
31+
echo "Usage: $(basename "$0")"
32+
echo
33+
echo "Display the persistent system uuid for the appliance."
34+
exit 2
35+
fi
36+
37+
#
38+
# Extract the 'system-uuid' property.
39+
#
40+
# This property is used for an engine-uuid as well as to derive
41+
# a unique iSCSI initiator IQN.
42+
#
43+
# NOTE:
44+
# IBMcloud changes the system-uuid whenever the engine is
45+
# power-cycled but preserves the chassis-asset-tag-uuid. For that
46+
# cloud provider we use that property to obtain a UUID.
47+
#
48+
if [[ "$(dmidecode -s chassis-asset-tag)" == "ibmcloud" ]]; then
49+
DMI_KEYWORD="baseboard-asset-tag"
50+
else
51+
DMI_KEYWORD="system-uuid"
52+
fi
53+
54+
system_uuid=$(dmidecode -s $DMI_KEYWORD | awk '{print tolower($0)}')
55+
56+
echo -n "$system_uuid"
57+
exit 0

0 commit comments

Comments
 (0)