-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrdma-functions.sh
1487 lines (1399 loc) · 46.3 KB
/
rdma-functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
source ~/fsdp_setup/machines/wwns
source ~/fsdp_setup/machines/nfs-mounts
###########################################################################
#
# Network Specifications
#
# The following variables define the network setup of the cluser
# on the fabics, etc.
###########################################################################
# If set, this will set the domain-name option in the DHCP
# and interface configurations
domain_name="ofa.iol.unh.edu"
# If set, this will set the DNS servers optins in the DHCP and
# interface configurations
domain_name_servers=("10.12.2.254")
# IPv4 prefix for fabric neworks (i.e. 172.31.x.0/24)
network_prefix="172.31"
# Networks (IPMI, lights-out, etc.) used in the lab
lab_networks="10.12.0.0/16"
# Defines of all our network fabrics so we don't have to define these
# in multiple places. Format is, label.subnet, where subnet is defined
# as x in the network prefix above. As many or as few as 1 network can be
# defined as needed. Note, all fabric IPv4 networks are assumed to be /24 size.
# Infiniband Fabric 1
ib0_2k_nets=(ib0 ib0.2)
ib0_4k_nets=(ib0.4 ib0.6)
ib0_nets=(${ib0_2k_nets[*]} ${ib0_4k_nets[*]})
# InfiniBand Fabric 2
#ib1_2k_nets=(ib1 ib1.3 ib1.5 ib1.7)
#ib1_4k_nets=(ib1.9 ib1.11 ib1.13)
#ib1_nets=(${ib1_2k_nets[*]} ${ib1_4k_nets[*]})
# OmniPath Fabric 1
opa0_nets=(opa0 opa0.22 opa0.24)
# OmniPath Fabric 2
#opa1_nets=(opa1 opa1.23 opa1.25)
# ROCE Fabric 1
roce_nets=(roce roce.43 roce.45)
# iWARP Fabric 1
iw_nets=(iw iw.51 iw.52)
all_nets=(${ib0_nets[*]} ${ib1_nets[*]} ${opa0_nets[*]} ${opa1_nets[*]} ${roce_nets[*]} ${iw_nets[*]})
__restart_config_options() {
local file="$1"
local tag="$2"
sed -e '/^# Begin '"$tag"'$/,/^# End '"$tag"'$/d' -i "$file"
echo "# Begin $tag" >> "$file"
}
__write_config_option() {
local file="$1"
local option="$2"
echo "$option" >> "$file"
}
__end_config_options() {
local file="$1"
local tag="$2"
echo "# End $tag" >> "$file"
}
# Set_Config_Options - Adds custom configuration to the specified file
# while making sure not to add the same information twice
# Args:
# @file - Config file to edit
# @tag - Unique string to identify start/end of config options in file
# @options - String to put between the tags in the file
Set_Config_Options() {
local file="$1"
local tag="$2"
local options="$3"
[ -z "$file" -o -z "$tag" -o -z "$options" ] && return
[ ! -f "$file" ] && return
__restart_config_options "$file" "$tag"
__write_config_option "$file" "$options"
__end_config_options "$file" "$tag"
}
Disable_Target() {
[ -f /lib/systemd/system/$1.target ] && systemctl disable $1.target
}
Enable_Target() {
[ -f /lib/systemd/system/$1.target ] && systemctl enable $1.target
}
Start_Service() {
[ -f /etc/rc.d/init.d/$1 ] && service $1 start
[ -f /lib/systemd/system/$1.service ] && systemctl start $1.service
}
Stop_Service() {
[ -f /etc/rc.d/init.d/$1 ] && service $1 stop
[ -f /lib/systemd/system/$1.service ] && systemctl stop $1.service
}
Disable_Service() {
[ -f /etc/rc.d/init.d/$1 ] && chkconfig --level 2345 $1 off
[ -f /lib/systemd/system/$1.service ] && systemctl disable $1.service
}
Enable_Service() {
[ -f /etc/rc.d/init.d/$1 ] && chkconfig --level 2345 $1 on
[ -f /lib/systemd/system/$1.service ] && systemctl enable $1.service
}
Restart_Service() {
[ -f /etc/rd.d/init.d/$1 ] && service $1 restart
[ -f /lib/systemd/system/$1.service ] && systemctl restart $1.service
}
Clear_Default_Interfaces() {
pushd /etc/sysconfig/network-scripts >/dev/null
for file in ifcfg-*; do
if [ "$file" != "ifcfg-lo" ]; then
rm -f $file
fi
done
popd >/dev/null
}
Clear_Rdma_Interfaces() {
pushd /etc/sysconfig/network-scripts >/dev/null
rm -f ifcfg-cxgb* ifcfg-ib* ifcfg-qib* ifcfg-mlx* ifcfg-mthca* ifcfg-usnic* ifcfg-ocrdma*
popd >/dev/null
}
Nmcli_Con_Reload() {
[ -x /usr/bin/nmcli ] && nmcli con reload
}
Create_Fixed_Addresses() {
IP_addrs0=()
IP_addrs1=()
IP_addrs2=()
IP_addrs3=()
IP_addrs4=()
for fabrics in $*; do
fabric=`echo $fabrics | cut -f 1 -d '_'`
instance=`echo $fabrics | cut -f 2 -s -d '_'`
[ -z "$instance" ] && instance=0
for subnet in ${all_nets[*]}; do
net_part=`echo $subnet | cut -f 1 -d '.'`
vlan_part=`echo $subnet | cut -f 2 -s -d '.'`
[ -n "$vlan_part" ] && vlan_part=".$vlan_part"
__if_x_in_y $fabric $net_part || continue
if [ "$instance" -gt 0 ]; then
case $instance in
1) IP_addrs1=(${IP_addrs1[*]} `grep -w ${net_part}_${instance}${vlan_part}-${RDMA_HOST} /etc/hosts | awk '{print $1}'`);;
2) IP_addrs2=(${IP_addrs2[*]} `grep -w ${net_part}_${instance}${vlan_part}-${RDMA_HOST} /etc/hosts | awk '{print $1}'`);;
3) IP_addrs3=(${IP_addrs3[*]} `grep -w ${net_part}_${instance}${vlan_part}-${RDMA_HOST} /etc/hosts | awk '{print $1}'`);;
4) IP_addrs4=(${IP_addrs4[*]} `grep -w ${net_part}_${instance}${vlan_part}-${RDMA_HOST} /etc/hosts | awk '{print $1}'`);;
esac
else
IP_addrs0=(${IP_addrs0[*]} `grep -w "${subnet}-${RDMA_HOST}$" /etc/hosts | awk '{print $1}'`)
fi
done
done
echo "IP_addrs0= ${IP_addrs0[*]}"
echo "IP_addrs1= ${IP_addrs1[*]}"
echo "IP_addrs2= ${IP_addrs2[*]}"
echo "IP_addrs3= ${IP_addrs3[*]}"
echo "IP_addrs4= ${IP_addrs4[*]}"
}
Create_Interface() {
declare bootproto="" ipaddr="" network="" broadcast="" stp=""
declare mtu="" vlan="" pkey="" connected_mode="" hwaddr="" defroute="no"
declare mac="" netmask="255.255.255.0" priority="" master=""
if [[ $# -lt 3 ]]; then
echo "Usage: $FUNCNAME <physdev> <type> <onboot> ..."
echo " [[static IPADDR] | [dhcp [defroute]]]"
echo " [bridge BRIDGE] [master MASTER] [stp yes|no] [priority PRIORITY]"
echo " [hwaddr HWADDR] [vlan vlan_id] [mac HWADDR] [mtu MTU]"
echo " [pkey pkey_id] [connected_mode yes|no]"
echo
echo " @physdev - the name that you want the physical device to have"
echo " (system names like eth0/ib0 are discouraged as they may clash"
echo " with what the kernel picks for other devices, and there is a"
echo " standard to name devices em# for the network interfaces"
echo " embedded on the motherboard, and p#p# for devices on the PCI"
echo " bus). Udev will rename devices to the physdev name if you"
echo " specify the hwaddr and it matches the native hwaddr of the"
echo " device. However, Udev does not handle IPoIB devices for you"
echo " automatically like it does Ethernet devices, so we create an"
echo " entry in /etc/udev/rules.d/70-persistent-ipoib.rules for the"
echo " IPoIB devices if they have a HWADDR entry given."
echo " In the case of vlans, the physdev is the real dev the vlan"
echo " is being added onto, and the vlan device will end up being"
echo " named physdev.vlan_id. For IPoIB P_Key devices, the pkey_id"
echo " can be given in decimal or in hex, but it will always be"
echo " converted to hex before the device is created and the name"
echo " will use the hex version of the number. If you want to pass"
echo " the vlan_id in hex, you must use the 0x prefix."
echo " @type - Interface type: Ethernet, Vlan, InfiniBand, Bridge, Team, Bond"
echo " @onboot - Yes|No, should we start this interface automatically"
echo " @static - Statically defined network interface, netmask for all"
echo " fabrics in test cluster is always 255.255.255.0, so we only"
echo " need the IPADDR of this interface, we can calculate the rest"
echo " @dhcp - Use dhcp on interface, not supported on all types and all"
echo " releases, we will attempt to fall back to static when we"
echo " know it isn't available. The optional defroute item tells"
echo " us to treat this interface as the default route interface"
echo " !@static and !@dhcp - When neither a static address or dhcp is given"
echo " we will set BOOTPROTO=none and disable IPV4 and IPV6 on the"
echo " interface"
echo " @stp - Only relevant on Bridge master devices, should we enable the"
echo " Spanning Tree Protocol, yes or no"
echo " @priority - Only relevant for Bridge masters or slaves, sets the"
echo " priority of this device in the spanning tree messages"
echo " @bridge - This is given on a bridge slave device to enslave it to"
echo " the named bridge"
echo " @master - Passed in on slave devices, this links the slave to the"
echo " named master (regardless of type of master, works on bridges,"
echo " teams, and bonds alike). Use of the bridge setting is"
echo " deprecated and the new master option is the preferred usage"
echo " @hwaddr - Physical address of device (MAC address for Ethernet,"
echo " fake MAC address for IPoIB interfaces, HWADDR of slaves to"
echo " bridge and team devices)"
echo " @vlan - Create a vlan interface using vlan_id as the number and"
echo " physdev as the parent device"
echo " @mac - Use the listed HWADDR for the device. Mainly applicable to"
echo " the various subdevices (like vlan interfaces) and masters"
echo " (such as bridge, team, and bond devices). This allows you"
echo " to give those devices a unique address. This is separate"
echo " from hwaddr which is used to tie a configuration to a specific"
echo " piece of hardware."
echo " @pkey - Create an IPoIB P_Key based device (like a vlan)."
echo " @mtu - MTU of device. For vlans, this means nothing as MTU is set"
echo " on parent device."
echo " @connected_mode - Whether or not to use connected mode on IPoIB"
echo " interfaces. Defaults to no."
return 1
fi
physdev=$1
iftype=$2
onboot=$3
shift 3
while [[ $# != 0 ]]; do
case $1 in
dhcp)
bootproto=$1
shift;;
static)
bootproto=$1
ipaddr=$2
shift 2;;
mtu)
mtu=$2
shift 2;;
vlan)
vlan=$2
shift 2;;
pkey)
pkey=$2
shift 2;;
connected_mode)
connected_mode=$2
shift 2;;
hwaddr)
hwaddr=$2
shift 2;;
defroute)
defroute=yes
shift;;
mac)
mac=$2
shift 2;;
bridge|master)
master=$2
shift 2;;
stp)
stp=$2
shift 2;;
priority)
priority=$2
shift 2;;
*)
echo "Unknown option ($1) passed to CreateInterface"
shift;;
esac
done
[ "$iftype" = infiniband ] && iftype=InfiniBand
# rhel5 doesn't support InfiniBand P_Key vlans properly, so skip them
[ "$OS" = rhel -a "$RELEASE" -lt 6 -a "$iftype" = InfiniBand -a -n "$pkey" ] && return 0
devname="${physdev}"
if [ -n "${vlan}" ]; then
devname="${physdev}.${vlan}"
fi
if [ -n "${pkey}" ]; then
hex_pkey=$(printf "0x%d" $pkey)
devname="${physdev}.$(printf "%04x" $(( 0x8000 | ${hex_pkey} )) )"
# devname="${physdev}.${pkey}"
fi
output=/etc/sysconfig/network-scripts/ifcfg-$devname
# Check if we are set to use dhcp and are installing a
# release that doesn't support dhcp on IB. We can use
# dhcp on rhel6 or later, and on Fedora 17(?) or 18 or later,
# but not on Fedora 16 or earlier
if [ "$OS" = "rhel" -a "$RELEASE" -lt 6 -a "$bootproto" = "dhcp" -a "$defroute" = "no" ]; then
fabric=`echo "$devname" | cut -f 2- -d '_' | sed -e 's/800//'`
ipaddr=`grep ${fabric}-${RDMA_HOST} /etc/hosts | awk '{print $1}'`
[ -n "$ipaddr" ] && bootproto=static
fi
if [ "$iftype" = InfiniBand -a "$bootproto" = dhcp ]; then
if [ $OS = fedora -a $RELEASE -lt 17 ] || [ $OS = rhel -a $RELEASE -lt 6 ]; then
fabric=`echo "$devname" | cut -f 2- -d '_' | sed -e 's/800//'`
ipaddr=`grep ${fabric}-${RDMA_HOST} /etc/hosts | awk '{print $1}'`
[ -n "$ipaddr" ] && bootproto=static
fi
fi
if [ "$bootproto" = static ]; then
network=`echo $ipaddr | cut -f -3 -d '.'`.0
broadcast=`echo $ipaddr | cut -f -3 -d '.'`.255
fi
echo "DEVICE=${devname}" > $output
if [ -n "${vlan}" ]; then
echo "VLAN=yes" >> $output
echo "VLAN_ID=${vlan}" >> $output
# echo "REORDER_HDR=0" >> $output
[ "${vlan}" -eq 43 ] && echo "VLAN_EGRESS_PRIORITY_MAP=0:3,1:3,2:3,3:3,4:3,5:3,6:3,7:3" >> $output
[ "${vlan}" -eq 45 ] && echo "VLAN_EGRESS_PRIORITY_MAP=0:5,1:5,2:5,3:5,4:5,5:5,6:5,7:5" >> $output
fi
if [ -n "${pkey}" ]; then
echo "PHYSDEV=${physdev}" >> $output
echo "PKEY=yes" >> $output
echo "PKEY_ID=${hex_pkey}" >> $output
fi
[ -n "${mac}" ] && echo "MACADDR=${mac}" >> $output
echo "TYPE=${iftype}" >> $output
case $iftype in
Bond)
echo "BONDING_OPTS=\"downdelay=0 miimon=100 mode=802.3ad updelay=0\"" >> $output
echo "BONDING_MASTER=yes" >> $output
echo "AUTOCONNECT_SLAVES=yes" >> $output
;;
Team)
echo "DEVICETYPE=Team" >> $output
echo "AUTOCONNECT_SLAVES=yes" >> $output
echo 'TEAM_CONFIG="{\"runner\": {\"name\": \"lacp\", \"active\": true, \"fast_rate\": true, \"tx_balancer\": {\"name\": \"basic\"}, \"tx_hash\": [\"eth\", \"ipv4\", \"ipv6\"]}, \"link_watch\": {\"name\": \"ethtool\"}}"' >> $output
;;
Bridge)
[ -n "${priority}" ] && echo "BRIDGING_OPTS=priority=${priority}" >> $output
[ -n "${stp}" ] && echo "STP=${stp}" >> $output
;;
Ethernet)
case "${master}" in
*bond*)
echo "MASTER=${master}" >> $output
echo "SLAVE=yes" >> $output
;;
*bridge*|br[0123456789]_*)
echo "BRIDGE=${master}" >> $output
;;
*team*)
echo "TEAM_MASTER=${master}" >> $output
echo "DEVICETYPE=TeamPort" >> $output
;;
esac
;;
esac
[ ${iftype} = "InfiniBand" ] && [ "$OS" = "rhel" -a "$RELEASE" -lt 7 ] && echo "NM_CONTROLLED=No" >> $output
[ ${iftype} = "InfiniBand" ] && [ "$OS" = "fedora" -a "$RELEASE" -lt 20 ] && echo "NM_CONTROLLED=No" >> $output
echo "ONBOOT=${onboot}" >> $output
[ -n "${hwaddr}" ] && echo "HWADDR=${hwaddr}" >> $output
if [ -n "${ipaddr}" ]; then
echo "BOOTPROTO=${bootproto}" >> $output
echo "IPADDR=${ipaddr}" >> $output
echo "NETMASK=${netmask}" >> $output
echo "NETWORK=${network}" >> $output
echo "BROADCAST=${broadcast}" >> $output
echo "IPV4_FAILURE_FATAL=yes" >> $output
echo "PEERDNS=no" >> $output
echo "IPV6INIT=yes" >> $output
echo "IPV6_AUTOCONF=yes" >> $output
echo "IPV6_DEFROUTE=no" >> $output
echo "IPV6_PEERDNS=no" >> $output
echo "IPV6_PEERROUTES=yes" >> $output
echo "IPV6_FAILURE_FATAL=no" >> $output
elif [ -n "${bootproto}" ]; then
echo "BOOTPROTO=${bootproto}" >> $output
echo "DEFROUTE=${defroute}" >> $output
if [ "${defroute}" = "yes" ]; then
echo "PEERDNS=yes" >> $output
echo "SEARCH=\"lab.bos.redhat.com bos.redhat.com devel.redhat.com redhat.com\"" >> $output
else
echo "PEERDNS=no" >> $output
fi
echo "PEERROUTES=yes" >> $output
echo "IPV4_FAILURE_FATAL=yes" >> $output
echo "IPV6INIT=yes" >> $output
echo "IPV6_AUTOCONF=yes" >> $output
echo "IPV6_DEFROUTE=no" >> $output
echo "IPV6_PEERDNS=no" >> $output
echo "IPV6_PEERROUTES=yes" >> $output
echo "IPV6_FAILURE_FATAL=no" >> $output
else
echo "BOOTPROTO=none" >> $output
echo "DEFROUTE=no" >> $output
echo "PEERDNS=no" >> $output
echo "PEERROUTES=no" >> $output
echo "IPV4_FAILURE_FATAL=no" >> $output
echo "IPV4INIT=no" >> $output
echo "IPV6INIT=no" >> $output
fi
[ -n "${mtu}" ] && echo "MTU=${mtu}" >> $output
[ -n "${connected_mode}" ] && echo "CONNECTED_MODE=${connected_mode}" >> $output
echo "NAME=${devname}" >> $output
if [ "${iftype}" = "InfiniBand" ]; then
output=/etc/udev/rules.d/70-persistent-ipoib.rules
match_addr=$(echo $hwaddr | tail -c 24)
else
output=/etc/udev/rules.d/70-persistent-net.rules
match_addr=$(echo $hwaddr)
fi
if [ ! -f $output ]; then
touch $output
fi
[ $OS = rhel -a $RELEASE -gt 5 -a -n "${hwaddr}" -a -z "$pkey" ] && ( sed -e "/$match_addr/d" -i $output; echo "ACTION==\"add\", SUBSYSTEM==\"net\", DRIVERS==\"?*\", ATTR{type}==\"32\", ATTR{address}==\"?*${match_addr}\", NAME=\"$physdev\"" >> $output )
[ $OS = fedora -a $RELEASE -gt 16 -a -n "${hwaddr}" -a -z "$pkey" ] && ( sed -e "/$match_addr/d" -i $output; echo "ACTION==\"add\", SUBSYSTEM==\"net\", DRIVERS==\"?*\", ATTR{type}==\"32\", ATTR{address}==\"?*${match_addr}\", NAME=\"$physdev\"" >> $output )
}
Create_Multicast_Route() {
if [ "$OS" = rhel -a "$RELEASE" -lt 6 ]; then
# Don't yet know how to accomplish this when we don't have
# NetworkManager as our network agent
echo "Can't create a multicast route, NetworkManager isn't used"
echo "in this release as our default network control agent."
return
fi
# Create a NetworkManager dispatcher event to create the route
cat > /etc/NetworkManager/dispatcher.d/99-multicast.conf <<EOF
#!/bin/sh
interface=\$1
status=\$2
[ "\$interface" = $1 ] || exit 0
case \$status in
up)
ip route add 224.0.0.0/4 dev \$interface
;;
esac
EOF
chmod +x /etc/NetworkManager/dispatcher.d/99-multicast.conf
}
# $1 - Parent interface name
Create_Target_Restart_Dispatcher() {
if [ "$OS" = rhel -a "$RELEASE" -lt 6 ]; then
# Don't yet know how to accomplish this when we don't have
# NetworkManager as our network agent
echo "Can't create a NetworkManager dispatcher as NM isn't used"
echo "in this release as our default network control agent."
return
fi
cat > /etc/NetworkManager/dispatcher.d/99-restart-target.conf <<EOF
#!/bin/sh
interface=\$1
status=\$2
case \$status in
up)
systemctl restart target
;;
esac
EOF
chmod +x /etc/NetworkManager/dispatcher.d/99-restart-target.conf
}
# $1 - Parent interface name
# $2 - Vlan interface name
# $3 - Priority
Create_Pfc_Egress_Dispatcher() {
if [ "$OS" = rhel -a "$RELEASE" -lt 6 ]; then
# Don't yet know how to accomplish this when we don't have
# NetworkManager as our network agent
echo "Can't create a NetworkManager dispatcher as NM isn't used"
echo "in this release as our default network control agent."
return
fi
prios="$3 $3 $3 $3 $3 $3 $3 $3 $3 $3 $3 $3 $3 $3 $3 $3"
user_prios="$3,$3,$3,$3,$3,$3,$3,$3,$3,$3,$3,$3,$3,$3,$3,$3"
case $1 in
ocrdma_roce)
num_tc="num_tc 8"
queues="queues 1@0 1@1 1@2 1@3 1@4 1@5 1@6 1@7"
;;
mlx4_roce)
num_tc="num_tc 8"
queues="queues 32@0 32@32 32@64 32@96 32@128 32@160 32@192 32@224"
;;
mlx5_roce)
num_tc="num_tc 8"
queues=""
;;
esac
# Create a NetworkManager dispatcher
cat > /etc/NetworkManager/dispatcher.d/98-${2}-egress.conf <<EOF
#!/bin/sh
interface=\$1
status=\$2
[ "\$interface" = $2 ] || exit 0
case \$status in
up)
tc qdisc add dev $1 root mqprio $num_tc map $prios $queues
# tc_wrap.py -i $1 -u $user_prios
;;
esac
EOF
chmod +x /etc/NetworkManager/dispatcher.d/98-${2}-egress.conf
}
__get_net_from_subnet() {
# Requires: name of fabric
# Returns: network address of fabric
case $1 in
ib0)
net=0
;;
ib1)
net=1
;;
opa0)
net=20
;;
opa1)
net=21
;;
roce)
net=40
;;
iw)
net=50
;;
*)
net=`echo $1 | cut -f 2 -d '.'`
;;
esac
}
__if_x_in_y() {
[ -z "$1" ] && return 1
[ -z "$2" ] && return 1
for tmp in $2; do
[ "${tmp}" = "$1" ] && return
done
return 1
}
__create_rdma_interfaces_usage() {
echo "Usage: $FUNCNAME <dev> <fabric> <guid/mac> <dhcp/host byte of IP address>"
echo " [<slavedev> <hwaddr>]..."
echo
echo " @dev - the name that you want the physical device to have"
echo " (system names like eth0/ib0 are discouraged as they may clash"
echo " with what the kernel picks for other devices, and there is a"
echo " standard to name devices em# for the network interfaces"
echo " embedded on the motherboard, and p#p# for devices on the PCI"
echo " bus). Standard in the Westford cluster is to use the driver"
echo " name as the dev name (mlx4, qib, cxgb4, etc.). However, it"
echo " can also be a bond or a team or a bridge device name. If it"
echo " is any of those three composite devices, then there must be"
echo " at least one slavedev/hwaddr pair added to the command, but"
echo " there may be more than one pair."
echo " In order to trigger bond, bridge, or team processing, the dev"
echo " name must be formatted properly:"
echo " Bond: includes the full word bond anywhere in the name"
echo " Bridge: is br and a single digit number, or includes the"
echo " full word bridge anywhere in the dev name"
echo " Team: includes the full word team anywhere in the name"
echo " @fabric - One of our supported RDMA fabric types: ib0, ib1, roce,"
echo " iwarp, opa0"
echo " @guid/mac - A valid MAC address for Ethernet devices or Ethernet"
echo " metadevices like bridge or bond. On Ethernet devices, this"
echo " will end up passed as HWADDR, on metadevices it will be the"
echo " metadevice's MACADDR entry. For IB and OPA devices, a valid"
echo " IPoIB guid which is used by the udev renaming to tie the"
echo " requested name to the device and also by configuration file"
echo " to tie our configuration to our specific hardware."
echo " @dhcp/host byte of IP address - Either dhcp or the final byte of our"
echo " static IP address to be used on the RDMA interface"
echo " @slavedev @hwaddr - These must be specified in pairs. The slavedev"
echo " will become the name of the Ethernet device we are adding"
echo " to the metadevice and the hwaddr will be used on the slave"
echo " Ethernet device as the HWADDR entry in the file to tie the"
echo " configuration to the specific Ethernet device."
}
Create_Rdma_Interfaces() {
if [ $# -lt 4 ]; then
__create_rdma_interfaces_usage
return 1
fi
local CM=""
local TYPE=InfiniBand
local HWADDR=hwaddr
local SUBNET=`echo $2 | cut -f 1 -d '_'`
__get_net_from_subnet $SUBNET
start_net=$net
case "$SUBNET" in
ib0)
# In the FSDP we only have 2k nets and only mlx5 devices
# so there won't be any connected mode machines
#[ "$1" != "mlx5" ] && CM="connected_mode yes"
nets=(${ib0_2k_nets[*]} ${ib0_4k_nets[*]})
__get_net_from_subnet ${ib0_4k_nets[0]}
_4k_start=$net
;;
ib1)
nets=(${ib1_2k_nets[*]} ${ib1_4k_nets[*]})
__get_net_from_subnet ${ib1_4k_nets[0]}
_4k_start=$net
;;
opa0)
nets=(${opa0_nets[*]})
MTU="mtu 10236"
;;
opa1)
nets=(${opa1_nets[*]})
MTU="mtu 10236"
;;
roce)
TYPE=Ethernet
nets=(${roce_nets[*]})
MTU="mtu ${SYSTEM_MTU:-9000}"
;;
iw)
TYPE=Ethernet
nets=(${iw_nets[*]})
MTU="mtu ${SYSTEM_MTU:-9000}"
;;
*)
echo "Unknown fabric type passed to Create_Rdma_Interfaces"
;;
esac
case "$1" in
*bond*)
TYPE=Bond
parent="$1_$2"
HWADDR=mac
;;
*team*)
TYPE=Team
parent="$1_$2"
HWADDR=mac
;;
*bridge*|br[0123456789])
TYPE=Bridge
parent="$1_$2"
HWADDR=mac
;;
esac
if [ $HWADDR = "mac" -a $# -lt 6 ]; then
__create_rdma_interfaces_usage
return 1
fi
for subnet in ${nets[*]}; do
__get_net_from_subnet $subnet
if [ "$4" = "dhcp" ]; then
BP=dhcp
else
BP="static ${network_prefix}.$net.$4"
fi
if [ "$TYPE" = "InfiniBand" ]; then
if [ -z "$CM" -a -z "$MTU" ]; then
[ $net -lt $_4k_start ] && MTU="mtu 2044" || MTU="mtu 4092"
#MTU="mtu 2044"
elif [ -z "$MTU" ]; then
MTU="mtu 65520"
fi
fi
if [ $net = $start_net ]; then
Create_Interface $1_$2 $TYPE yes $HWADDR $3 $BP $CM $MTU
else
case $TYPE in
InfiniBand)
Create_Interface $1_$2 $TYPE yes $HWADDR $3 $BP $CM $MTU pkey $net
;;
Ethernet|Bond|Team)
Create_Interface $1_$2 Vlan yes $BP vlan $net
[ "$2" != "iw" ] && Create_Pfc_Egress_Dispatcher $1_$2 $1_$2.$net $(($net - $start_net))
;;
esac
fi
done
# shift out our parent config and check for slave pairs
shift 4
while [ $# -ge 2 ]; do
Create_Interface $1 Ethernet yes hwaddr $2 master $parent
shift 2
done
}
# Append the aliases to /etc/hosts..
Update_Etc_Hosts() {
FILE="/etc/hosts"
cat > $FILE <<EOF
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
EOF
local __awk_src='
BEGIN {
offset["node"]=0
offset["builder"]=252
net["ib0", 0]="ib0"
net["ib0", 2]="ib0.2"
net["ib0", 4]="ib0.4"
net["ib0", 6]="ib0.6"
net["opa0", 20]="opa0"
net["opa0", 22]="opa0.22"
net["opa0", 24]="opa0.24"
net["roce", 40]="roce"
net["roce", 43]="roce.43"
net["roce", 45]="roce.45"
net["iw", 50]="iw"
net["iw", 51]="iw.51"
net["iw", 52]="iw.52"
}
{
split($1, host_fields, "-")
group = host_fields[1]
host_ip = offset[group] + (host_fields[2] * 5)
for (i=2; i<=NF; i++) {
split($i, net_part, "_")
for (j=0; j<=254; j++) {
if ((net_part[1], j) in net) {
net_ip = j
net_name = net[net_part[1], j]
if (net_part[2] == "")
printf("'"${network_prefix}"'.%d.%d\t\t%s-%s\n",
net_ip, host_ip, net_name, $1)
else {
split(net_name, net_fields, ".")
if (net_fields[2] != "")
net_name = net_fields[1]"_"net_part[2]"."net_fields[2]
else
net_name = net_fields[1]"_"net_part[2]
printf("'"${network_prefix}"'.%d.%d\t\t%s-%s\n",
net_ip, host_ip + net_part[2],
net_name, $1)
}
}
}
}
}
'
awk "$__awk_src" machines/host-fabrics >> $FILE
return 0
}
# ppc64 uses efi, in a way, but it's of efi, not UEFI, and it uses it via
# grub2 and not via the UEFI tools
Fix_Boot_Loader() {
if [ -x /usr/sbin/efibootmgr ]; then
# not much to do here for UEFI...our bashrc file takes care of this
# for us, so just save our EFI state in case we want to look at it
# later
efibootmgr > /root/EFI_SETUP_POST_INSTALL.TXT
elif [ -x /usr/sbin/grub2-mkconfig ]; then
deffile=/etc/default/grub
cfgfile=/boot/grub2/grub.cfg
cp $deffile $deffile.orig
GCL=`grep CMDLINE $deffile | sed -e 's/GRUB_CMDLINE_LINUX=//;s/"//g'`
if [ -n "$HOST_GRUB_OPTIONS" ]; then
GCL=`echo $GCL | sed -e "s/$HOST_GRUB_OPTIONS//g"`
fi
GCL=`echo $GCL | sed -e 's/console=tty0 //g;s/rd_NO_PLYMOUTH //g'`
sed -e '/GRUB_TIMEOUT.*$/ d;/GRUB_CMDLINE_LINUX.*$/ d' -i $deffile
echo "GRUB_TIMEOUT=10" >> $deffile
echo "GRUB_CMDLINE_LINUX=\"$HOST_GRUB_OPTIONS console=tty0 rd_NO_PLYMOUTH $GCL\"" >> $deffile
grub2-mkconfig -o $cfgfile
if [ $ARCH_FAMILY = x86 ]; then
grub2-install --recheck --force /dev/sda
fi
elif [ -f /boot/grub/grub.conf ]; then
# When using the original grub on a Dell machine with console
# redirection enabled, you need to remove the terminal line
# from the grub.conf or it messes up grub.
if [ "`dmidecode -s system-manufacturer | cut -c 1-4`" = "Dell" ]; then
sed -e '/^terminal.*$/ d' -i /boot/grub/grub.conf
fi
fi
}
Setup_FSDP_Mounts() {
Set_Config_Options /etc/fstab "internal FSDP mounts" ""
}
Setup_Nfs_Client_Mounts() {
local opt_tag="RDMA nfs client mounts"
__restart_config_options /etc/fstab "$opt_tag"
for server in $NFSServers; do
[ "$server" = "$RDMA_HOST" ] && continue
for fabric in ${NFSFabrics[$server]}; do
__if_x_in_y "$fabric" "${HOST_FABRICS[*]}" || continue
for ver in ${NFSProtos[$server]}; do
for mpt in ${NFSMPoints[$server]}; do
mkdir -p /srv/$server/$fabric/$ver-$mpt-${NFSIntDevs[$server-$fabric]}
__write_config_option /etc/fstab "${fabric}-$server:/srv/NFSoRDMA/$ver-$mpt /srv/$server/$fabric/$ver-$mpt-${NFSIntDevs[$server-$fabric]} ${NFSMOpts[$ver]}"
done
done
done
done
__end_config_options /etc/fstab "$opt_tag"
}
Stop_Nfs_Server() {
Stop_Service nfs-server
Stop_Service nfs
Stop_Service nfs-rdma
Stop_Service nfs-idmap
Stop_Service nfs-lock
Stop_Service nfs-mountd
}
Disable_Nfs_Server() {
Disable_Service nfs
Disable_Service nfs-rdma
Disable_Service nfs-idmap
Disable_Service nfs-lock
Disable_Service nfs-mountd
Disable_Service nfs-server
}
Enable_Nfs_Server() {
Enable_Service nfs-idmap
Enable_Service nfs-lock
Enable_Service nfs-mountd
Enable_Service nfs-server
Enable_Service nfs
Enable_Service nfs-rdma
}
Setup_Nfs_Server() {
# Depending on the OS release, the NFSoRDMA server might be configured by
# /etc/sysconfig/nfs or by /etc/rdma/rdma.conf, so set the port in both
sed -e 's/#RDMA_PORT=.*/RDMA_PORT=20049/;s/.*RPCNFSDARGS=.*$/RPCNFSDARGS="--rdma=20049"/' -i /etc/sysconfig/nfs
sed -e 's/NFSoRDMA_LOAD=.*/NFSoRDMA_LOAD=yes/;s/NFSoRDMA_PORT=.*/NFSoRDMA_PORT=20049/' -i /etc/rdma/rdma.conf
Enable_Nfs_Server
}
# Export names are expected to be in v#-name format by the client mount code
# above.
Setup_Nfs_Exports() {
for export in $*; do
mkdir -p /srv/NFSoRDMA/$export
mount /srv/NFSoRDMA/$export
sed -e '/'"${export}"'/ d' -i /etc/exports
echo "/srv/NFSoRDMA/$export ${network_prefix}.0.0/16(rw,async,insecure,no_root_squash,mp) rdma-*(rw,async,insecure,no_root_squash,mp)" >> /etc/exports
done
}
__setup_iser_client_path() {
local server="$1"
local fabric="$2"
local backstore="$3"
local path_num=$4
local server_part=`echo $server | cut -f 2- -d '-' -`
local target=${iqn}:$server
local portal=$fabric-$server_part
local wwn="${iqn}:$RDMA_HOST"
# We have auto mapped luns turned off, so we also map our specific lun
# to our ACL
ssh $server "targetcli ls /iscsi/$target/tpg1/acls" | grep $wwn >/dev/null 2>&1
[ $? -eq 1 ] && ssh $server "targetcli /iscsi/$target/tpg1/acls create $wwn; targetcli saveconfig"
lun_stat=`ssh $server "targetcli ls /iscsi/$target/tpg1/acls/$wwn"`
lun=`echo $lun_stat | wc -l`
let lun--
echo $lun_stat | grep iser-$backstore >/dev/null 2>&1
[ $? -eq 1 ] && ssh $server "targetcli /iscsi/$target/tpg1/acls/$wwn create $lun /backstores/block/iser-$backstore; targetcli saveconfig"
# Log us out
iscsiadm -m node -I iser -p $portal -u
# Redo discovery
iscsiadm -m discovery -I iser -t sendtargets -p $portal
# Log us back in
iscsiadm -m node -p $portal -I iser -l
if [ $path_num -eq 0 ]; then
mkdir -p /srv/$server/iser-$backstore
fi
}
__create_iser_client_usage() {
echo -e "
Usage:
Create_Iser_Client_Devices <server> <backstore> [fabrics ...]
\tserver - Required, we will ssh to this server to add ourselves to the
\t ACLs and map our LUN
\tbackstore - name of backstore device to use on server. The name must
\t start with iser- in the actual /backstores/block directory on the
\t server, but the iser- portion of the name must not be included in the
\t name passed here as it will be pre-pended later.
\tfabric - One or more fabrics you wish to enable access to the LUN via.
\t The fabrics will be checked to make sure that both the server and
\t this host have connections to the fabrics. If no fabrics are
\t specified, then the union of all fabrics for the server and this
\t host will be used. If there is more than one fabric configured,
\t multipath will be enabled by default."
}
# Call this to set up possible iSER device definitions.
Create_Iser_Client_Devices() {
if [ $# -lt 2 ]; then
__create_iser_client_usage
return
fi
local server="$1"
local backstore="$2"
shift 2
local paths=""
local num_paths=0
echo "InitiatorName=${iqn}:$RDMA_HOST" > /etc/iscsi/initiatorname.iscsi
__if_x_in_y "$server" "${ISER_SERVERS[*]}" || return
[ -n "$1" ] && paths="$*" || paths="${ISER_FABRICS[$server]}"
for fabric in $paths; do
__if_x_in_y "$fabric" "${HOST_FABRICS[*]}" || continue
__if_x_in_y "$fabric" "${ISER_FABRICS[$server]}" || continue
__setup_iser_client_path "$server" "$fabric" "$backstore" $num_paths
let num_paths++
done
if [ $num_paths -gt 1 ]; then
if [ ! -f /etc/multipath.conf ]; then
cp /usr/share/doc/device-mapper-multipath*/multipath.conf /etc
fi
Enable_Service multipathd
Start_Service multipathd
fi
}
# ssh to srp target to add an ACL for this client
# targetcli uses srp names of the format:
# "ib.<32 hex chars>"
# for both target wwn and client wwn.
__setup_srp_client_path() {
local server="$1"
local fabric="$2"
local backstore=$3
local path_num=$4
local dgid=${SRP_DGID[$server-$fabric]}
local var_file=/etc/rdma/srp_client_variables
local tmp_conf=/etc/rdma/srp_client_tmp_conf
local conf_file=/etc/srp_daemon.conf
echo -e "a pkey=ffff,dgid=$dgid\nd\n" > $tmp_conf
pushd /dev/infiniband >/dev/null
for umad in umad*; do
srp_daemon -n -c -o -f $tmp_conf -d ./$umad | sed -e 'y/,/\n/' > $var_file
[ -s $var_file ] && break
done
local ibdev=`cat /sys/class/infiniband_mad/$umad/ibdev`
local ibport=`cat /sys/class/infiniband_mad/$umad/port`
rm $tmp_conf
popd >/dev/null
[ ! -s $var_file ] && return
port_guid=`ibstat $ibdev $ibport | grep "Port GUID" | cut -f 2 -d 'x'`
init_ext=`grep initiator_ext $var_file | cut -f 2 -d '='`
sgid="${init_ext}${port_guid}"
# We have auto mapped luns turned off, so we also map our specific lun
# to our ACL
ssh $server "targetcli ls /srpt/ib.$dgid/acls" | grep $sgid >/dev/null 2>&1
[ $? -eq 1 ] && ssh $server "targetcli /srpt/ib.$dgid/acls create ib.$sgid; targetcli saveconfig"
lun_stat=`ssh $server "targetcli ls /srpt/ib.$dgid/acls/ib.$sgid"`
lun=`echo $lun_stat | wc -l`
let lun--
echo $lun_stat | grep srp-$backstore >/dev/null 2>&1
[ $? -eq 1 ] && ssh $server "targetcli /srpt/ib.$dgid/acls/ib.$sgid create $lun /backstores/block/srp-$backstore; targetcli saveconfig"
sed -e "/.*dgid=$dgid.*/ d" -i $conf_file
echo "a pkey=ffff,dgid=$dgid,queue_size=512,max_cmd_per_lun=16" >> $conf_file
rm $var_file
if [ $path_num -eq 0 ]; then
mkdir -p /srv/$server/srp-$backstore
fi
}
__create_srp_client_usage() {
echo -e "
Usage:
Create_Srp_Client_Devices <server> <backstore> [fabrics ...]
\tserver - Required, we will ssh to this server to add ourselves to the