-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstmf_view
executable file
·1224 lines (1028 loc) · 29.4 KB
/
stmf_view
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 -e
#Copyright (c) 2012 Adam Jodock
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
#files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
#modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
#Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
#WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
#COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
#ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Program Name: stmf_view
# Program Description: This program is designed to give an entire overview
# of the storage framework
# Author: Adam Jodock
# Contact: echo "ajodock,hotmail.com" | sed -e 's/,/@/' -e 's/hot/g/'
# SCSI target mode framework (stmf)
#
# Portal
# \
# TPG Logged in Initiators
# \ /
# Target Allowed Initiators
# \ /
# Target Group Host Group
# \ /
# View
# /
# LU
# /
# zvol,device,file
#
# The goal of this program is to display all of the information in this tree changing
# the root that the data is sorted on.
# This allows the user to better view what data is available to what clients. For
# instance you might want to know every LU that is available to a particular target,
# or which LUs are visible by a particular host group.
# Increasing the verbosity can create quite a lot of output, especially if you have a
# lot of LUs or targets. It is a good idea to save the output to a file and then use
# less/more/a text editor to view the output.
#Check to make sure that the user only specified one function
function check_action()
{
if [ -n "$action" ]
then
echo "Error: Only specify one action"
exit
fi
}
#This function requires two inputs. The first is a description of the section that the output is coming from
#and the second is minimum number for the output to be displayed
function debug()
{
if [ "$debug" -ge "$2" ]
then
echo "$results" | sed "s/^/$1: /" 1>&2
fi
}
#Generate a graphviz dot file. Save the output to a file and render it like this
#./stmf_view --dot > graph.dot;dot -O -Tsvg graph.dot
#The pdf and svg formats take up much less room, render faster, and the pdf format will easily allow you to copy/paste
function generate_dot()
{
results=""
zfs_devices=""
targetgroups=""
hostgroups=""
portalgroups=""
edges=""
lus=""
views="$(get_views)"
lun_num="$(echo "$views" | wc -l)"
#Generate LU Nodes
for LU in $(get_lus)
do
if [ -z "$lus" ]
then
lus="LUs [shape=record,label=\""
else
lus="$lus|"
fi
device="$(echo "$VIEW" | awk -F, '{print $6}')"
if [ -z "$device" ]
then
if [ "$debug" -ge "1" ]
then
lus="$lus{<$LU>LU: $LU|{$(get_lu_info | sed '{:q;N;s/\n/\\\\n/g;t q}')}"
else
lus="$lus{<$LU>LU: $LU"
fi
else
if [ "$debug" -ge "1" ]
then
lus="$lus{<$LU>Device: $device|{$(get_zfs_info | sed '{:q;N;s/\n/\\\\n/g;t q}')}|LU: $LU|{$(get_lu_info | sed '{:q;N;s/\n/\\\\n/g;t q}')}"
else
lus="$lus{<$LU>Device: $device|LU: $LU"
fi
fi
lu_views=''
#For each LU node create view subnodes
for VIEW in $(echo "$views" | grep $LU)
do
VE="$(echo "$VIEW" | awk -F, '{print $2}')"
LUN="$(echo "$VIEW" | awk -F, '{print $3}')"
TG="$(echo "$VIEW" | awk -F, '{print $4}')"
HG="$(echo "$VIEW" | awk -F, '{print $5}')"
if [ -z "$lu_views" ]
then
lu_views="|{"
else
lu_views="$lu_views|"
fi
lu_views="$lu_views{VE: $VE|{<$LU,$VE,TG>TG: $TG|<$LU,$VE,HG>HG: $HG|LUN: $LUN}}"
done
if [ -n "$lu_views" ]
then
lu_views="$lu_views}"
fi
lus="$lus$lu_views}"
done
#Generate host group nodes
for HG in $(get_hgs)
do
color="$(get_color)"
if [ -z "$hostgroups" ]
then
hostgroups="hostgroups [shape=record,label=\"{"
else
hostgroups="$hostgroups|{"
fi
hg_members=''
hostgroups="$hostgroups<$HG>HG: $HG"
#Generate initiator sub nodes
for INITIATOR in $(get_hg_members)
do
if [ -z "$hg_members" ]
then
hg_members="|{"
else
hg_members="$hg_members|"
fi
hg_members="$hg_members<$INITIATOR>$INITIATOR"
done
if [ -z "$hg_members" ]
then
hostgroups="$hostgroups$hg_members}"
else
hostgroups="$hostgroups$hg_members}}"
fi
#Generate connections between each view and the host group
for VIEW in $(echo "$views" | awk -v HG="$HG" -F, '{if ($5 == HG) print $0}')
do
LU="$(echo "$VIEW" | awk -F, '{print $1}')"
VE="$(echo "$VIEW" | awk -F, '{print $2}')"
edges="$edges\nLUs:\"$LU,$VE,HG\" -> hostgroups:\"$HG\" [color=$color]"
done
done
#Generate target groups
for TG in $(get_tgs)
do
color="$(get_color)"
if [ -z "$targetgroups" ]
then
targetgroups="targetgroups [shape=record,label=\"{"
else
targetgroups="$targetgroups|{"
fi
tg_members=''
targetgroups="$targetgroups<$TG>TG: $TG"
#Generate target sub nodes
for TARGET in $(get_tg_members)
do
if [ -z "$tg_members" ]
then
tg_members="|{"
else
tg_members="$tg_members|"
fi
if [ "$TG" = 'All' ]
then
if [ "$debug" -ge "1" ]
then
tg_members="$tg_members{Target: $TARGET|<$(echo "$TARGET-all" |sed 's/:/?/g')>$(get_target_info |sed '{:q;N;s/\n/\\\\n/g;t q}')}"
else
tg_members="$tg_members<$(echo "$TARGET-all" |sed 's/:/?/g')>Target: $TARGET"
fi
for TPG in $(get_target_tpgs)
do
edges="$edges\ntargetgroups:\"$(echo "$TARGET-all" | sed 's/:/?/g')\" -> tpgs:\"$TPG\""
done
else
if [ "$debug" -ge "1" ]
then
tg_members="$tg_members{Target: $TARGET|<$(echo "$TARGET" |sed 's/:/?/g')>$(get_target_info |sed '{:q;N;s/\n/\\\\n/g;t q}')}"
else
tg_members="$tg_members<$(echo "$TARGET" |sed 's/:/?/g')>Target: $TARGET"
fi
for TPG in $(get_target_tpgs)
do
edges="$edges\ntargetgroups:\"$(echo "$TARGET" | sed 's/:/?/g')\" -> tpgs:\"$TPG\""
done
fi
done
if [ -z "$tg_members" ]
then
targetgroups="$targetgroups$tg_members}"
else
targetgroups="$targetgroups$tg_members}}"
fi
#Connect views to target groups
for VIEW in $(echo "$views" | awk -v TG="$TG" -F, '{if ($4 == TG) print $0}')
do
LU="$(echo "$VIEW" | awk -F, '{print $1}')"
VE="$(echo "$VIEW" | awk -F, '{print $2}')"
edges="$edges\nLUs:\"$LU,$VE,TG\" -> targetgroups:\"$TG\" [color=$color]"
done
done
#Generate target poral group nodes
for TPG in $(get_tpgs)
do
if [ -z "$portalgroups" ]
then
portalgroups="tpgs [shape=record,label=\""
else
portalgroups="$portalgroups|"
fi
portalgroups="$portalgroups{<$TPG>TPG: $TPG"
portals=''
for PORTAL in $(get_tpg_portals)
do
if [ -z "$portals" ]
then
portals="|{"
else
portals="$portals|"
fi
portals="$portals<$PORTAL>Portal: $PORTAL"
done
if [ -z "$portals" ]
then
portalgroups="$portalgroups$portals}"
else
portalgroups="$portalgroups$portals}}"
fi
done
if [ -n "$portalgroups" ]
then
portalgroups="$portalgroups\"]"
fi
if [ -n "$targetgroups" ]
then
targetgroups="$targetgroups\"]"
fi
if [ -n "$hostgroups" ]
then
hostgroups="$hostgroups\"]"
fi
if [ -n "$zfs_devices" ]
then
zfs_devices="$zfs_devices\"]"
fi
if [ -n "$lus" ]
then
lus="$lus\"]"
fi
results="digraph stmf {\n\trankdir=LR\nranksep=$((lun_num/15+1))\nnodesep=$((lun_num/20+1))\nsplines=ortho\n\n$results\n$zfs_devices\n\n$lus\n\n$targetgroups\n\n$hostgroups\n\n$portalgroups\n\n$edges"
echo -e "$results\n}"
}
#Returns the next color from color_list
function get_color()
{
if [ -z "$color" ]
then
color="antiquewhite4"
fi
found='0'
results=''
#Grab the next color in the list from the current one
for COLOR in $color_list
do
if [ "$found" = '1' ]
then
results="$COLOR"
break
fi
if [ "$color" = "$COLOR" ]
then
found='1'
fi
done
if [ -z "$results" ]
then
results="antiquewhite4"
fi
print_results
}
#This function returns a list of all of the host groups
function get_hgs()
{
XPATH="/service_bundle/service/property_group[@name='host_groups']/propval[not (contains(@name, 'member_list'))]/@value"
results="All\n$(xpath)"
debug "get_hgs" 4
print_results
}
#This function returns a list of initiators that are a member of $HG
function get_hg_members()
{
if [ -z "$HG" ]
then
echo "Error in get_hg_members: HG=$HG"
exit
fi
if [ "$HG" != 'All' ]
then
XPATH="/service_bundle/service/property_group[@name='host_groups']/propval[not (contains(@name, 'member_list')) and @value='$HG']/@name"
xml_group="$(xpath)"
#I don't know who created the XML spec for stmf but they really didn't structure the groups logically...
#A normal person would make the members a sub node instead of the group, but instead they are their own node
#and the path is different for a single entry versus multiple.
#Because of this we need two queries and a separate case for a single host vs multiple wwns/IQNs.
XPATH="/service_bundle/service/property_group[@name='host_groups']/propval[@name='$xml_group-member_list']/@value"
results="$(xpath)"
if [ -z "$results" ]
then
XPATH="/service_bundle/service/property_group[@name='host_groups']/property[@name='$xml_group-member_list']/ustring_list/value_node/@value"
results="$(xpath)"
fi
else
XPATH="/service_bundle/service/property_group[@name='host_groups']/property[contains(@name,'member_list')]/ustring_list/value_node/@value"
results="$(xpath)"
XPATH="/service_bundle/service/property_group[@name='host_groups']/propval[contains(@name,'member_list')]/@value"
results="$results\n$(xpath)"
fi
debug "get_hg_members" 3
print_results
}
#Returns a list of views (in the same format as list_views) that are associated to $HG
function get_hg_views()
{
if [ -z "$HG" ]
then
echo "Error in get_hg_views: $HG"
exit
fi
results="$(echo "$(get_views)" | awk -v HG="$HG" -F, '{if ($5 == "HG");print $0}')"
debug "get_hg_views" 5
print_results
}
#This function returns a list of all LUs
function get_lus()
{
XPATH="/service_bundle/service/property_group[starts-with(@name,'lu-')]/@name"
results="$(xpath | sed 's/^lu-//')"
debug "get_lus" 3
print_results
}
#This function returns information related to $LU
function get_lu_info()
{
if [ -z "$LU" ]
then
echo "Error in get_lu_info: LU=$LU"
exit
fi
results="$(stmfadm list-lu -v $LU 2> /dev/null | grep -v 'LU Name:' | sed 's/^\ *//')"
debug "get_lu_info" 4
print_results
}
#This function returns all available targets
function get_targets()
{
results="$(stmfadm list-target | awk '{print $2}')"
debug "get_targets" 3
print_results
}
#This function returns several lines of info related to $TARGET
function get_target_info()
{
if [ -z "$TARGET" ]
then
echo "Error in get_target_info: TARGET=$TARGET"
exit
fi
if [ -n "$(get_targets | grep "$TARGET")" ]
then
results="$(stmfadm list-target -v $TARGET | egrep -v 'Target|Alias|Initiator|Logged in' | sed 's/^ *//')"
iscsi_regex="^iqn."
fc_regex="^wwn."
if [[ "$TARGET" =~ $iscsi_regex ]]
then
results="$results\n$(itadm list-target -v $TARGET | egrep -v "^iqn.|tpg-tags:|TARGET NAME" | sed 's/^[\t ]*//')"
elif [[ "$TARGET" =~ $fc_regex ]]
then
wwn="$(echo "$TARGET" | sed 's/wwn\.//')"
results="$results\n$(fcinfo hba-port $wwn | grep -v 'HBA Port WWN' | sed 's/^\t//')"
fi
debug "get_target_info" 3
print_results
fi
}
#This function returns all of the initators related to $TARGET
function get_target_initiators()
{
if [ -z "$TARGET" ]
then
echo "Error in get_target_initiators: TARGET=$TARGET"
exit
fi
if [ "$TARGET" != "All" ]
then
results="$(stmfadm list-target -v $TARGET | awk '/Initiator/ {print $2}')"
debug "get_target_initiators" 3
print_results
fi
}
#This function returns information about $INITIATOR
function get_target_initiator_info()
{
if [ -z "$INITIATOR" -o -z "$TARGET" ]
then
echo "Error in get_target_initiator_info: TARGET=$TARGET INITIATOR=$INITIATOR"
exit
fi
info="$(stmfadm list-target -v $TARGET | egrep 'Initiator:|Alias:|Logged in')"
debug "get_target_initiator_info" 3
#INITIATOR_FIX="$(echo "$INITIATOR" | sed 's/\./\\./g')"
regex="Initiator: $INITIATOR"
unset found
echo "$info" | while read line
do
if [[ "$line" =~ "$regex" ]]
then
found='1'
elif [ "$found" = '1' ]
then
echo "$line" | sed 's/\ *//'
found='2'
elif [ "$found" = '2' ]
then
echo "$line" | sed 's/\ *//'
unset found
fi
done
}
#This function returns a list of TPGs related to $TARGET
function get_target_tpgs()
{
if [ -z "$TARGET" ]
then
echo "Error in get_target_tpgs: TARGET=$TARGET"
exit
fi
iscsi_regex="^iqn."
if [[ "$TARGET" =~ $iscsi_regex ]]
then
results="$(itadm list-target -v $TARGET | awk '/tpg-tags/ {$1="";print $0}' | sed -e 's/^[\t ]*//' -e 's/ = [0-9]*//g' -e 's/,/\n/g')"
fi
debug "get_target_tpgs" 3
print_results
}
#This function returns a list of all target groups
function get_tgs()
{
XPATH="/service_bundle/service/property_group[@name='target_groups']/propval[not (contains(@name, 'member_list'))]/@value"
results="All\n$(xpath)"
debug "get_tgs" 4
print_results
}
#This function returns a list of all the targets that are a member of a target group
function get_tg_members()
{
if [ -z "$TG" ]
then
echo "Error in get_tg_members: TG=$TG"
exit
fi
if [ "$TG" != 'All' ]
then
XPATH="/service_bundle/service/property_group[@name='target_groups']/propval[not (contains(@name, 'member_list')) and @value='$TG']/@name"
xml_group="$(xpath)"
#I don't know who created the XML spec for stmf but they really didn't structure the groups logically...
#A normal person would make the members a sub node instead of the group, but instead they are their own node
#and the path is different for a single entry versus multiple.
#Because of this we need two queries and a separate case for a single host vs multiple wwns/IQNs.
XPATH="/service_bundle/service/property_group[@name='target_groups']/propval[@name='$xml_group-member_list']/@value"
results="$(xpath)"
if [ -z "$results" ]
then
XPATH="/service_bundle/service/property_group[@name='target_groups']/property[@name='$xml_group-member_list']/ustring_list/value_node/@value"
results="$(xpath)"
fi
else
XPATH="/service_bundle/service/property_group[@name='target_groups']/property[contains(@name,'member_list')]/ustring_list/value_node/@value"
results="$(xpath)"
XPATH="/service_bundle/service/property_group[@name='target_groups']/propval[contains(@name,'member_list')]/@value"
results="$results\n$(xpath)"
fi
debug "get_tg_members" 3
print_results
}
#This function returns a list of TGs that the $TARGET is a member of
function get_tg_membership()
{
if [ -z "$TARGET" ]
then
echo "Error in get_tg_membership: TARGET=$TARGET"
exit
fi
XPATH="/service_bundle/service/property_group[@name='target_groups']/propval[@value='$TARGET']/@name"
target_group="$(xpath)"
#stmf only allows a target to be a part of one group, so this will be only one or the other type of group.
#It really seems like stmf should be capable of having a target in more than one group and a host in more than
#one host group, but for some reason it cant. It already does this with the "All" groups, and you can logically
#do this yourself by creating one hg per host and one tg per group and then creating multiple views.
#This of course adds to the management of the system, so it would be much better if stmf was just fixed to do what it
#is apparently already capable of.
if [ -z "$target_group" ]
then
XPATH="/service_bundle/service/property_group[@name='target_groups']/*[./ustring_list/value_node/@value='$TARGET']/@name"
target_group="$(xpath | sed 's/-member_list$//')"
fi
if [ -n "$target_group" ]
then
XPATH="/service_bundle/service/property_group[@name='target_groups']/propval[@name='$target_group']/@value"
results="All\n$(xpath)"
else
results="All"
fi
debug "get_tg_membersip" 3
print_results
}
#Returns a list of views (in the same format as list_views) that are associated to $TG
function get_tg_views()
{
if [ -z "$TG" ]
then
echo "Error in get_tg_views: $TG"
exit
fi
results="$(echo "$(get_views)" | awk -v TG="$TG" -F, '{if ($4 == "TG");print $0}')"
debug "get_tg_views" 5
print_results
}
#Return all TPGs
function get_tpgs()
{
results="$(itadm list-tpg | grep -v "TARGET PORTAL GROUP" | awk '{print $1}')"
debug "get_tpgs" 4
print_results
}
#This function returns a list of the portals related to $TPG
function get_tpg_portals()
{
if [ -z "$TPG" ]
then
echo "Error in get_tpg_portals: TPG=$TPG"
exit
fi
if [ "$TPG" != 'default' ]
then
results="$(itadm list-tpg -v $TPG | awk '/portals:/ {print $2}' | sed 's/,/\n/')"
debug "get_tpg_portals" 3
print_results
fi
}
#This function returns the LU,VE,TG,HG of every view that has $HG as its host group
function get_views()
{
unset results
for LU in $(get_lus)
do
device="$(get_zfs_device)"
for VE in $(get_view_ves)
do
XPATH="/service_bundle/service/property_group[@name='view_entry-$VE-$LU']/propval[@name='target_group']/@value"
target_group="$(xpath)"
if [ -z "$target_group" ]
then
target_group="All"
fi
XPATH="/service_bundle/service/property_group[@name='view_entry-$VE-$LU']/propval[@name='host_group']/@value"
host_group="$(xpath)"
if [ -z "$host_group" ]
then
host_group="All"
fi
XPATH="/service_bundle/service/property_group[@name='view_entry-$VE-$LU']/propval[@name='lu_nbr']/@value"
lun="$(printf '%d' 0x$(xpath | sed 's/000000000000$//'))"
if [ -z "$results" ]
then
results="$LU,$VE,$lun,$target_group,$host_group,$device"
else
results="$results\n$LU,$VE,$lun,$target_group,$host_group,$device"
fi
done
done
debug "get_views" 3
print_results
}
#This function returns a list of view entries that $LU is a member of
function get_view_ves()
{
if [ -z "$LU" ]
then
echo "Error in get_view_ves: LU=$LU"
exit
fi
XPATH="/service_bundle/service/property_group[starts-with(@name,'view_entry') and contains(@name,'$LU')]/@name"
results="$(xpath | awk -F- '{print $2}')"
debug "get_view_ves" 3
print_results
}
#This function returns the zfs volume name of $LU
function get_zfs_device()
{
if [ -z "$LU" ]
then
echo "Error in get_lu_info: LU=$LU"
exit
fi
device_path="$(stmfadm list-lu -v $LU | awk '/Data File/ {$1=$2=$3="";print $0}' | sed 's/^ *//')"
if [ -z "$device_path" ]
then
results=''
else
regex="^/dev/zvol/(rdsk|dsk)"
if [[ "$device_path" =~ $regex ]]
then
results="$(echo "$device_path" | sed 's#^/dev/zvol/.dsk/##')"
fi
fi
debug "get_zfs_device" 3
print_results
}
#This function returns info about the ZFS device $device
function get_zfs_info()
{
if [ -z "$device" ]
then
echo "Error in get_tg_members: device=$device"
exit
fi
options="used,referenced,compressratio,compression,refreservation,logbias,volblocksize,volsize,dedup,sync"
origin="$(zfs get origin $device | awk '!/VALUE/ {print $3}')"
results="$(zfs get $options $device | grep "$device" | sed "s#^$device *##")"
debug "get_zfs_info" 3
print_results
if [ "$origin" != '-' ]
then
results="$(echo "Origin: $origin")"
device="$origin"
#These print_results have to be split up because they are sorted.
#Maybe should have another function without a sort
debug "get_zfs_info_origin" 3
verbose 2 print_results
#Yay recursion!
results="$(get_zfs_info | sed 's/^/ /')"
debug "get_zfs_info_origin" 3
verbose 2 print_results
fi
}
#List the entire tree with host group as the root
function list-hg()
{
if [ -z "$objects" ]
then
hg_list="$(get_hgs)"
else
hg_list="$objects"
fi
views="$(get_views)"
for HG in $hg_list
do
echo "Host Group: $HG"
target_groups="$(echo "$views" | awk -F, '{print $4}' | sort -u)"
get_hg_members | sed 's/^/ Initiator: /'
for TG in $target_groups
do
echo " Target Group: $TG"
for TARGET in $(get_tg_members)
do
echo " Target: $TARGET"
verbose 1 get_target_info | sed 's/^/ /'
for INITIATOR in $(get_target_initiators)
do
echo " Initiator: $INITIATOR"
verbose 1 get_target_initiator_info | sed 's/^/ /'
done
for TPG in $(get_target_tpgs)
do
echo " Target Portal Group: $TPG"
for PORTAL in $(get_tpg_portals)
do
echo " Portal: $PORTAL"
done
done
done
for VIEW in $(echo "$views" | awk -v TG="$TG" -F, '{if ($4 == TG || $4 == "All") print $0}' | awk -v HG="$HG" -F, '{if ($5 == HG || $5 == "All") print $0}')
do
LU="$(echo "$VIEW" | awk -F, '{print $1}')"
VE="$(echo "$VIEW" | awk -F, '{print $2}')"
LUN="$(echo "$VIEW" | awk -F, '{print $3}')"
device="$(echo "$VIEW" | awk -F, '{print $6}')"
echo " LU: $LU"
echo " View VE : $VE"
echo " LUN : $LUN"
verbose 1 get_lu_info | sed 's/^/ /'
if [ -n "$device" ]
then
echo " ZFS Volume: $device"
verbose 1 get_zfs_info | sed 's/^/ /'
fi
done
done
done
}
#List the entire tree with target as the root
function list-target()
{
if [ -z "$objects" ]
then
target_list="$(get_targets)"
else
target_list="$objects"
fi
views="$(get_views)"
for TARGET in $target_list
do
echo "Target: $TARGET"
verbose 1 get_target_info | sed 's/^/ /'
for INITIATOR in $(get_target_initiators)
do
echo " Initiator: $INITIATOR"
verbose 1 get_target_initiator_info | sed 's/^/ /'
done
for TPG in $(get_target_tpgs)
do
echo " Target Portal Group: $TPG"
for PORTAL in $(get_tpg_portals)
do
echo " Portal: $PORTAL"
done
done
for TG in $(get_tg_membership)
do
echo " Target Group: $TG"
hg_list="$(echo "$views" | awk -v TG="$TG" -F, '{if ($4 == TG || $4 == "All") print $5}' | sort -u)"
for HG in $hg_list
do
echo " Host Group: $HG"
if [ "$HG" != 'All' ]
then
get_hg_members | sed 's/^/ Initiator: /'
fi
tg_views="$(echo "$views" | awk -v TG="$TG" -F, '{if ($4 == TG || $4 == "All") print $0}' | awk -v HG="$HG" -F, '{if ($5 == HG || $5 == "All") print $0}' | sort -u)"
for VIEW in $tg_views
do
LU="$(echo "$VIEW" | awk -F, '{print $1}')"
VE="$(echo "$VIEW" | awk -F, '{print $2}')"
LUN="$(echo "$VIEW" | awk -F, '{print $3}')"
device="$(echo "$VIEW" | awk -F, '{print $6}')"
echo " LU: $LU"
echo " View Entry : $VE"
echo " LUN : $LUN"
verbose 1 get_lu_info | sed 's/^/ /'
echo " ZFS Volume: $device"
verbose 1 get_zfs_info | sed 's/^/ /'
done
done
done
done
}
#List the entire tree with TG as root
function list-tg()
{
if [ -z "$objects" ]
then
tg_list="$(get_tgs)"
else
tg_list="$objects"
fi
views="$(get_views)"
for TG in $tg_list
do
echo "Target Group: $TG"
for TARGET in $(get_tg_members)
do
echo " Target: $TARGET"
for INITIATOR in $(get_target_initiators)
do
echo " Initiator: $INITIATOR"
verbose 1 get_target_initiator_info | sed 's/^/ /'
done
for TPG in $(get_target_tpgs)
do
echo " Target Portal Group: $TPG"
for PORTAL in $(get_tpg_portals)
do
echo " Portal: $PORTAL"
done
done
verbose 1 get_target_info | sed 's/^/ /'
done
for VIEW in $(echo "$views" | awk -v TG="$TG" -F, '{if ($4 == TG || $4 == "All") print $0}')
do
LU="$(echo "$VIEW" | awk -F, '{print $1}')"
VE="$(echo "$VIEW" | awk -F, '{print $2}')"
LUN="$(echo "$VIEW" | awk -F, '{print $3}')"
HG="$(echo "$VIEW" | awk -F, '{print $5}')"
device="$(echo "$VIEW" | awk -F, '{print $6}')"
echo " LU: $LU"
echo " View Entry: $VE"
echo " Host Group: $HG"
echo " LUN : $LUN"
for INITIATOR in $(get_hg_members)
do
echo " Initiator: $INITIATOR"
done
verbose 1 get_lu_info | sed 's/^/ /'
echo " ZFS Device: $device"
verbose 1 get_zfs_info | sed 's/^/ /'
done
done
}
#List entire tree with view as the root
function list-view()
{
if [ -z "$objects" ]
then
lu_list="$(get_lus)"
else
lu_list="$objects"
fi