mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
ef4dc7a45b
https://www.ibm.com/developerworks/linux/linux390/s390-tools-1.8.0.html
before the first upstream commit b627b8d8e1 ("Initial s390-tools-2.0.0
import") introduced SCSI tape/changer output for lstape. It used the SCSI
device serial number as lookup key to find a match in IBM lin_tape device
driver proc-fs output for a given SCSI device name. Since multiple paths
to the same tape/changer have the same serial number, multiple matches can
occur and distort the output:
% lstape
...
SCSI tape devices (found 12):
...
Generic Device Target Vendor Model Type State
sg0 IBMtape0 3 0:0:0:0 IBM ULT3580-TD6 tapedrv
running
sg1 IBMchanger0 1 2 3 0:0:0:1 IBM
3573-TL changer running
...
There are unexpected additional Device suffix numbers for each additional
path of the same tape/changer (independent of actual path failover
enablement in lin_tape). The multiple matches above cause excess arguments
to printf. Explaining the resulting output, the bash man page says:
"The format is reused as necessary to consume all of the arguments."
This also causes a wrong number of found devices.
Current lin_tape (v3.0.31) uses the printf format string
"%-8d%-12s%-25s%-16s%-16s%-10s" for fixed column proc-fs output.
This causes the following example input to lstape:
==> /proc/scsi/IBMchanger <==
lin_tape version: 3.0.31
lin_tape major number: 251
Attached Changer Devices:
Number model SN HBA SCSI FO Path
0 3573-TL 00L4U78W6497_LL0 Virtio SCSI HBA 0:0:0:1 Primary
1 3573-TL 00L4U78W6497_LL0 Virtio SCSI HBA 0:0:1:1 Alternate
2 3573-TL 00L4U78W6497_LL0 Virtio SCSI HBA 1:0:1:1 Alternate
3 3573-TL 00L4U78W6497_LL0 Virtio SCSI HBA 1:0:0:1 Alternate
==> /proc/scsi/IBMtape <==
lin_tape version: 3.0.31
lin_tape major number: 251
Attached Tape Devices:
Number model SN HBA SCSI FO Path
0 ULT3580-TD6 10WT037733 Virtio SCSI HBA 0:0:0:0 Primary
1 ULT3580-TD6 10WT037701 Virtio SCSI HBA 0:0:1:0 Primary
2 ULT3580-TD6 10WT037701 Virtio SCSI HBA 1:0:1:0 Alternate
3 ULT3580-TD6 10WT037733 Virtio SCSI HBA 1:0:0:0 Alternate
If that was reliable and stable, we could use fixed column parsing:
IBM_IDX=$(
awk 'BEGIN {
FIELDWIDTHS="8 12 25 16 16 10"
}
gensub(" ","","g",$5) == "'$SCSI_ID'"{
print gensub(" ","","g",$1)
}' /proc/scsi/$DEV_NAME
)
However, we can hardly guarantee a field value always fits into the left-
adjusted columns (printf won't cap to field width!). Also, the fixed column
format changed between lin_tape v3.0.20 and v3.0.18 from
"%-8d%-12s%-18s%-16s%-16s%-10s" with less width for the 'SN' field.
The column format also changed between v2.2.0 and v1.37.0 from
"%-8d%-12s%-18s%-32s%-10s" where the 'SCSI' field did not even exist.
Likely that was the reason for the original Serial lookup in lstape.
As can be seen in the example, at least the HBA device driver string can
contain whitespace and breaks the field numbers with tokenized parsing.
We want to match column 5 (SCSI) but above we would match against the
string 'SCSI' as part of "Virtio SCSI HBA" instead of e.g. '0:0:0:0'.
The following works currently knowing that the last two columns do not
contain white space. But it can also fail if the value of field
'HBA' does not fit into the left-adjusted columns so there is no white
space between columns 'HBA' and 'SCSI' making them collapse:
awk '$(NF-1) == "'$SCSI_ID'" { print $1 }' /proc/scsi/$DEV_NAME
Grep for the SCSI device name as word (to skip names with same substring,
such as 0:0:1:1 also matching 0:0:1:10) and cut the first field 'Number'.
If there is no SCSI column at all (and no SCSI LLDD or other column with a
name accidentally matching an existing SCSI device name), we get no match
and better bail out with the initialized "N/A" for the lstape column
"Device". If the SCSI column exists, the SCSI device names are unique and
we always get at most one match.
Signed-off-by: Steffen Maier <maier@linux.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Reviewed-by: Jens Remus <jremus@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
92 lines
2.7 KiB
Plaintext
92 lines
2.7 KiB
Plaintext
.\" Copyright 2017, 2018 IBM Corp.
|
|
.\" s390-tools is free software; you can redistribute it and/or modify
|
|
.\" it under the terms of the MIT license. See LICENSE for details.
|
|
.\"
|
|
.TH LSTAPE 8 "Jun 2018" "s390-tools"
|
|
|
|
.SH NAME
|
|
lstape \- list tape devices.
|
|
|
|
.SH SYNOPSIS
|
|
.TP 16
|
|
.B lstape
|
|
.RB [ -h | --help]
|
|
.RB [ --scsi-only | --ccw-only ]
|
|
.RB [ -v | --version ]
|
|
.RB [ -V | --verbose ]
|
|
.br
|
|
.RB [ --online | --offline ]
|
|
.RB [ -s ]
|
|
.br
|
|
.RB [ -t
|
|
.IR <device-type> [, <device-type> ] "" ...]
|
|
|
|
.SH DESCRIPTION
|
|
The lstape command lists all available tape devices on the current host. For
|
|
channel attached tape devices this output is the same as the contents of
|
|
/proc/tapedevices (which is obsolete) but also includes offline devices. By
|
|
default all tape devices are displayed.
|
|
|
|
Since SCSI tape devices are accessed differently to channel attached tape
|
|
devices they are only visible if they are known to the SCSI layer. There
|
|
are at least two possible drivers that can claim a SCSI tape device and the
|
|
lstape command tries to find out which one this is. For the generic tape
|
|
and changer driver the device names start with "st" or "sch", while for the
|
|
IBM tape driver this would be "IBMtape" or "IBMchanger". If "N/A" is shown,
|
|
the correct driver could not be obtained.
|
|
|
|
The serial number of a SCSI tape can be displayed with the --verbose option. If
|
|
there is no sg_inq command available "NO/INQ" is shown as the tape's serial.
|
|
|
|
.SH OPTIONS
|
|
.TP 8
|
|
\fB-h\fR or \fB--help\fR
|
|
Print help text.
|
|
|
|
.TP 8
|
|
\fB-v\fR or \fB--version\fR
|
|
Print the version of the s390-tools package and the command.
|
|
|
|
.TP
|
|
\fB-V\fB or \fB--verbose\fR
|
|
Adds additional information that does not fit into a single line of output.
|
|
This is currently only used for SCSI devices.
|
|
|
|
.TP
|
|
.BR --scsi-only | --ccw-only
|
|
Limit output to either SCSI or channel attached tape devices. The output without
|
|
SCSI devices is the same as it was with previous versions of this command.
|
|
|
|
.TP
|
|
.BR -s | --shortid
|
|
Using this option will list only tape devices that are in channel subsystem 0,
|
|
with subchannel set 0. All other devices will be suppressed and the leading
|
|
"0.0." for bus IDs of the remaining devices will be removed.
|
|
Since this is specific to CCW devices this option has no effect on the output
|
|
of SCSI tape devices.
|
|
|
|
.TP
|
|
.BR --online | --offline
|
|
Limit output to either online or offline devices. This filter has no effect
|
|
on the output of SCSI devices.
|
|
|
|
.TP
|
|
.BR -t | --type " \fI<device-type>\fR"
|
|
Limit output to given device types (currently only applies to channel attached
|
|
tape devices).
|
|
|
|
.TP
|
|
\fB<device-type>\fR =
|
|
Device type of devices that should be displayed (e.g. 3490).
|
|
|
|
.SH EXAMPLES
|
|
\fBlstape\fR
|
|
.RS
|
|
List all tape devices that are available
|
|
.RE
|
|
|
|
\fBlstape --ccw-only -t 3490 --online\fR
|
|
.RS
|
|
Show all 3490 CCW devices that are online.
|
|
.RE
|