[go: up one dir, main page]

File: lszfcp

package info (click to toggle)
s390-tools 2.3.0-2~deb10u1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 6,188 kB
  • sloc: ansic: 87,755; sh: 8,398; cpp: 8,384; perl: 3,783; makefile: 1,476; asm: 654
file content (348 lines) | stat: -rwxr-xr-x 8,144 bytes parent folder | download
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
#!/bin/bash
#
# lszfcp - Tool to display information about zfcp devices (adapters/ports/units)
#
# Copyright IBM Corp. 2006, 2017
#
# s390-tools is free software; you can redistribute it and/or modify
# it under the terms of the MIT license. See LICENSE for details.
#

SCRIPTNAME='lszfcp'
SYSFS=`cat /proc/mounts | grep -m1 sysfs | awk '{ print $2 }'`
FC_CLASS=false

# Command line parameters
VERBOSITY=0
SHOW_HOSTS=0
SHOW_PORTS=0
SHOW_DEVICES=0
SHOW_ATTRIBUTES=false
unset PAR_BUSID PAR_WWPN PAR_LUN


##############################################################################

check_sysfs()
{
	if [ -z $SYSFS -o ! -d $SYSFS -o ! -r $SYSFS ]; then
        	echo "Error: sysfs not available."
                exit 1
	fi
}

check_zfcp_support()
{
	if [ ! -e $SYSFS/bus/ccw/drivers/zfcp ]; then
		echo "Error: No zfcp support available."
		echo "Load the zfcp module or compile"
		echo "the kernel with zfcp support."
		exit 1
	fi
}

check_fcp_devs()
{
	if $FC_CLASS; then
		ignore=`ls $SYSFS/class/fc_host/host* 2>&1`
	else
		ignore=`ls $SYSFS/devices/css0/[0-9]*/[0-9]*/host[0-9]* 2>&1`
	fi

	if [ $? -ne 0 ]; then
		echo "Error: No fcp devices found."
		exit 1
	fi
}

check_fc_class()
{
	if [ -d "$SYSFS/class/fc_host" ]; then 
		FC_CLASS=true
	fi
}

print_version()
{
	cat <<EOF
$SCRIPTNAME: version %S390_TOOLS_VERSION%
Copyright IBM Corp. 2006, 2017
EOF
}

print_help()
{
	cat <<EOF
Usage: $SCRIPTNAME [OPTIONS]

Provide information contained in sysfs about zfcp adapters, ports and
units that are online.

Mandatory arguments to long options are mandatory for short options too.

OPTIONS:
    -H, --hosts		show host information (default)
    -P, --ports		show remote port information
    -D, --devices	show SCSI device information
    -b, --busid=BUSID	select specific busid
    -p, --wwpn=WWPN	select specific port name
    -l, --lun=LUN	select specific LUN
    -a, --attributes	show all attributes
    -V, --verbose	show sysfs paths of associated class
			and bus devices
    -s, --sysfs=PATH	use path as sysfs (for dbginfo archives)
    -h, --help		print this help
    -v, --version	print version information

EXAMPLE: 
    List for all zfcp adapters, ports and units the names of their 
    associated SCSI hosts, FC remote ports and SCSI devices.

    #> lszfcp -P -H -D
    0.0.3d0c host0
    0.0.3d0c/0x500507630300c562 rport-0:0-0
    0.0.3d0c/0x500507630300c562/0x4010403300000000 0:0:0:0

The default is to list bus_ids of all zfcp adapters and corresponding
SCSI host names (equals "lszfcp -H").
EOF
}


show_attributes()
{
	if [ -z $1 -o ! -d $1 -o ! -r $1 ]; then
		return 1
	fi

	for FILE in `ls $1`; do
		read 2>/dev/null CONTENT < $1/$FILE

		# Read fails for directories and
		# files with permissions 0200.
		if [ $? -ne 0 ]; then
			continue
		fi

		printf "    %-19s = \"%s\"\n" "$FILE" "$CONTENT"
	done
}


show_hosts()
{
	HOST_LIST=`ls -dX $SYSFS/devices/css0/[0-9]*/[0-9]*/host[0-9]*`

	for HOST_PATH in $HOST_LIST; do
		SCSI_HOST=`basename $HOST_PATH`
		ADAPTER_PATH=`dirname $HOST_PATH`
		ADAPTER=`basename $ADAPTER_PATH`
		
		[ $ADAPTER != ${PAR_BUSID:-$ADAPTER} ] && continue

		if [ $VERBOSITY -eq 0 ]; then
			echo $ADAPTER $SCSI_HOST
		else
			echo $ADAPTER_PATH
			$FC_CLASS && echo "$SYSFS/class/fc_host/$SCSI_HOST"
			echo "$SYSFS/class/scsi_host/$SCSI_HOST"
		fi

		if $SHOW_ATTRIBUTES; then
			echo 'Bus = "ccw"'
			show_attributes $ADAPTER_PATH

			if $FC_CLASS; then
				echo 'Class = "fc_host"'
				show_attributes \
					"$SYSFS/class/fc_host/$SCSI_HOST"
			fi

			echo 'Class = "scsi_host"'
			show_attributes "$SYSFS/class/scsi_host/$SCSI_HOST"
			echo
		fi
	done
}


show_ports()
{
	# Without fc_remote_class there is far less information to display.
	if ! $FC_CLASS; then
		PORT_LIST=`ls -d $SYSFS/devices/css0/*/*/0x*`

		for PORT_PATH in $PORT_LIST; do
			WWPN=`basename $PORT_PATH`
			ADAPTER=`basename \`dirname $PORT_PATH\``
			
			[ $WWPN != ${PAR_WWPN:-$WWPN} ] && continue
			[ $ADAPTER != ${PAR_BUSID:-$ADAPTER} ] && continue

			if [ $VERBOSITY -eq 0 ]; then
				echo "$ADAPTER/$WWPN"
			else
				echo $PORT_PATH
			fi
		done
		return
	fi


	if [ -e $SYSFS/class/fc_remote_ports/ ]; then
		PORT_LIST=`ls -d $SYSFS/class/fc_remote_ports/* 2>/dev/null`
	fi;

	for FC_PORT_PATH in $PORT_LIST; do
		PORT=`basename $FC_PORT_PATH`
		read PORT_STATE < $FC_PORT_PATH/port_state
		if [ "$PORT_STATE" == "Online" ];
		then
			read WWPN < $FC_PORT_PATH/port_name
		else
			continue
		fi

		[ $WWPN != ${PAR_WWPN:-$WWPN} ] && continue

		ADAPTER_PORT_PATH=`ls -d \
			$SYSFS/devices/css0/*/*/$WWPN/../host[0-9]*/$PORT |\
			awk -F "/../host" '{ print $1 }'`
		ADAPTER=`basename \`dirname $ADAPTER_PORT_PATH\``

		[ $ADAPTER != ${PAR_BUSID:-$ADAPTER} ] && continue

		if [ $VERBOSITY -eq 0 ]; then
			echo "$ADAPTER/$WWPN $PORT"
		else
			echo $ADAPTER_PORT_PATH
			echo $FC_PORT_PATH
		fi

		if $SHOW_ATTRIBUTES; then
			echo 'Class = "fc_remote_ports"'
			show_attributes "$FC_PORT_PATH"
			echo
		fi
	done
}


show_devices()
{
	# Differentiate old and new sysfs layout
	if $FC_CLASS; then
		SCSI_DEVICE_LIST=`ls -d \
			$SYSFS/bus/ccw/drivers/zfcp/*/host*/rport*/target*/*/ \
		       	2>/dev/null |grep -P '\d+:\d+:\d+:\d+'`
	else
		SCSI_DEVICE_LIST=`ls -d $SYSFS/devices/css0/*/*/host[0-9]*/*/`
	fi

	if [ -z "$SCSI_DEVICE_LIST" ]; then
		echo "Error: No fcp devices found."
	fi

	for SCSI_DEVICE_PATH in $SCSI_DEVICE_LIST; do
		read ADAPTER < $SCSI_DEVICE_PATH/hba_id
		read WWPN < $SCSI_DEVICE_PATH/wwpn
		read LUN < $SCSI_DEVICE_PATH/fcp_lun
		
		[ $LUN != ${PAR_LUN:-$LUN} ] && continue
		[ $WWPN != ${PAR_WWPN:-$WWPN} ] && continue
		[ $ADAPTER != ${PAR_BUSID:-$ADAPTER} ] && continue

		if [ $VERBOSITY -eq 0 ]; then
			echo "$ADAPTER/$WWPN/$LUN `basename $SCSI_DEVICE_PATH`"
		else
			echo "`ls -d $SYSFS/devices/css0/*/$ADAPTER`/$WWPN/$LUN"
			echo ${SCSI_DEVICE_PATH%*/} # without trailing slash

			# On live systems, there are links to the block and
			# generic devices. In a dbginfo archive, these links
			# are not present.  Therefore, fall back to reading 
			# the runtime.out log file.
			if [ `ls $SCSI_DEVICE_PATH | grep -c block:` -eq 1 ] 
			then
				BLOCK_DEV=`ls $SCSI_DEVICE_PATH | grep block:`
				GEN_DEV=`ls $SCSI_DEVICE_PATH |\
			       		grep scsi_generic:`
				echo -n "$SYSFS/block/${BLOCK_DEV#*:} "
				echo "$SYSFS/class/scsi_generic/${GEN_DEV#*:}"

			# FIXME Find a way to assign the generic devices.
			elif [ -r $SYSFS/../runtime.out ]; then 
				SCSI_DEV=`basename $SCSI_DEVICE_PATH`
				echo "$SYSFS/block/"`grep -r "\[$SCSI_DEV\]"\
			       		$SYSFS/../runtime.out |\
					awk -F "/dev/" '{print $2}'`
			fi
		fi

		if $SHOW_ATTRIBUTES; then
			echo 'Class = "scsi_device"'
			show_attributes "$SCSI_DEVICE_PATH"
			echo
		fi
	done
}


##############################################################################

ARGS=`getopt --options ahvHPDVb:p:l:s: --longoptions \
attributes,help,version,hosts,ports,devices,verbose,busid:,wwpn:,lun:,sysfs: \
-n "$SCRIPTNAME" -- "$@"`

if [ $? -ne 0 ]; then
	echo
	print_help
	exit
fi

eval set -- "$ARGS"

for ARG; do
	case "$ARG" in
		-a|--attributes) SHOW_ATTRIBUTES=true; 	shift 1;;
		-b|--busid) 	 PAR_BUSID=$2;		shift 2;;
		-h|--help) 	 print_help;		exit 0;;
		-l|--lun) 	 PAR_LUN=$2;		shift 2;;
		-p|--wwpn) 	 PAR_WWPN=$2;		shift 2;;
		-v|--version) 	 print_version;		exit 0;;
		-H|--hosts) 	 SHOW_HOSTS=1;		shift 1;;
		-D|--devices) 	 SHOW_DEVICES=1;	shift 1;;
		-P|--ports) 	 SHOW_PORTS=1;		shift 1;;
		-V|--verbose) 	 VERBOSITY=1;		shift 1;;
		-s|--sysfs)	 SYSFS=$2;		shift 2;;
		--) shift; break;;
	esac
done

check_sysfs
check_zfcp_support
check_fc_class
check_fcp_devs

default=1
if [ $SHOW_HOSTS -eq 1 ]; then
	default=0; show_hosts
elif [ $SHOW_PORTS -eq 0 -a $SHOW_DEVICES -eq 0 -a -n "$PAR_BUSID" ]; then
	default=0; show_hosts
fi

if [ $SHOW_PORTS -eq 1 ]; then
	default=0; show_ports
elif [ $SHOW_HOSTS -eq 0 -a $SHOW_DEVICES -eq 0 -a -n "$PAR_WWPN" ]; then
	default=0; show_ports
fi

if [ $SHOW_DEVICES -eq 1 ]; then
	default=0; show_devices
elif [ $SHOW_HOSTS -eq 0 -a $SHOW_PORTS -eq 0 -a -n "$PAR_LUN" ]; then
	default=0; show_devices
fi

if [ $default == 1 ]; then
	show_hosts
fi