SG_SES(8) | SG3_UTILS | SG_SES(8) |
sg_ses - access a SCSI Enclosure Services (SES) device
sg_ses [--descriptor=DES] [--dev-slot-num=SN] [--eiioe=A_F] [--filter] [--get=STR] [--hex] [--index=IIA | --index=TIA,II] [--inner-hex] [--join] [--maxlen=LEN] [--page=PG] [--quiet] [--raw] [--readonly] [--sas-addr=SA] [--status] [--verbose] [--warn] DEVICE
sg_ses [--byte1=B1] [--clear=STR] [--control] [--data=H,H...] [--data=@FN] [--descriptor=DES] [--dev-slot-num=SN] [--index=IIA | --index=TIA,II] [--mask] [--maxlen=LEN] [--nickname=SEN] [--nickid=SEID] [--page=PG] [--readonly] [--sas-addr=SA] [--set=STR] [--verbose] DEVICE
sg_ses --data=@FN --status [--raw --raw] [<all options from first form>]
sg_ses [--enumerate] [--index=IIA] [--list] [--help] [--version]
Fetches management information from a SCSI Enclosure Service (SES) device. This utility can also modify the state of a SES device. The DEVICE should be a SES device which may be a dedicated enclosure services processor in which case an INQUIRY response's Peripheral Device Type is 13 [0xd]. Alternatively it may be attached to another type of SCSI device (e.g. a disk) in which case the EncServ bit is set in its INQUIRY response.
If the DEVICE argument is given with no options then the names of all diagnostic pages (dpages) supported are listed. Most, but not necessarily all, of the named dpages are defined in the SES standards and drafts. The most recent reference for this utility is the draft SCSI Enclosure Services 4 document T10/BSR INCITS 555 Revision 1 at http://www.t10.org . Existing standards for SES, SES-2 and SES-3 are ANSI INCITS 305-1998 and ANSI INCITS 448-2008 and ANSI INCITS 518-2017 respectively.
The first form shown in the synopsis is for fetching and decoding dpages or fields from the SES DEVICE. A SCSI RECEIVE DIAGNOSTIC RESULTS command is sent to the DEVICE to obtain each dpage response. Rather than decoding a fetched dpage, it may be output in hex or binary with the --hex or --raw --raw options.
The second form in the synopsis is for modifying dpages or fields held in the SES DEVICE. A SCSI SEND DIAGNOSTIC command containing a "control" dpage is sent to the DEVICE to cause changes. Changing the state of an enclosure (e.g. requesting the "ident" (locate) LED to flash on a disk carrier in an array) is typically done using a read-modify-write cycle. See the section on CHANGING STATE below.
The third form in the synopsis shows the options for decoding the contents of a file that holds a hexadecimal or binary representation of a SES dpage response. Typically an earlier invocation of the first form of this utility with the '-HHHH' option would have generated that file. Since no SCSI commands are sent, the DEVICE argument if given will be ignored.
The last form in the synopsis shows the options for providing command line help (i.e. usage information), listing out dpage and field information tables held by the utility (--enumerate), or printing the version string of this utility.
There is a web page discussing this utility at http://sg.danny.cz/sg/sg_ses.html . Support for downloading microcode to a SES device has been placed in a separate utility called sg_ses_microcode.
In the following sections "dpage" refers to a diagnostic page, either fetched with a SCSI RECEIVE DIAGNOSTIC RESULTS command, sent to the DEVICE with a SCSI SEND DIAGNOSTIC command, or fetched from data supplied by the --data= option.
Arguments to long options are mandatory for short options as well. The options are arranged in alphabetical order based on the long option name.
An enclosure can have information about its disk and tape drives plus other supporting components like power supplies spread across several dpages. Addressing a specific element (overall or individual) within a dpage is complicated. This section describes low level indexing (i.e. choosing a single element (or a group of related elements) from a large number of elements). If available, the medium level indexing described in the following section (DESCRIPTOR NAME, DEVICE SLOT NUMBER AND SAS ADDRESS) might be simpler to use.
The Configuration dpage is key to low level indexing: it contains a list of "type headers", each of which contains an Element type (e.g. Array Device Slot), a Subenclosure identifier (0 for the primary enclosure) and a "Number of possible elements". Corresponding to each type header, the Enclosure Status dpage has one "overall" element plus "Number of possible elements" individual elements all of which have the given Element type. For some Element types the "Number of possible elements" will be 0 so the Enclosure Status dpage has only one "overall" element corresponding to that type header. The Element Descriptor dpage and the Threshold (In and Out) dpages follow the same pattern as the Enclosure Status dpage.
The numeric index corresponding to the overall element is "-1". If the Configuration dpage indicates a particular element type has "n" elements and n is greater than 0 then its indexes range from 0 to n-1 .
The Additional Element Status dpage is a bit more complicated. It has entries for "Number of possible elements" of certain Element types. It does not have entries corresponding to the "overall" elements. To make the correspondence a little clearer each descriptor in this dpage optionally contains an "Element Index Present" (EIP) indicator. If EIP is set then each element's "Element Index" field refers to the position of the corresponding element in the Enclosure Status dpage.
Addressing a single overall element or a single individual element is done with two indexes: TI and II. Both are origin 0. TI=0 corresponds to the first type header entry which must be a Device Slot or Array Device Slot Element type (according to the SES-2 standard). To address the corresponding overall instance, II is set to -1, otherwise II can be set to the individual instance index. As an alternative to the type header index (TI), an Element type abbreviation (A) optionally followed by a number (e.g. "ps" refers to the first Power Supply Element type; "ps1" refers to the second) can be given.
One of two command lines variants can be used to specify indexes: --index=TIA,II where TIA is either an type header index (TI) or an Element type abbreviation (A) (e.g. "ps" or "ps1"). II is either an individual index or "-1" to specify the overall element. The second variant is --index=IIA where IIA is either an individual index (II) or an Element type abbreviation (A). When IIA is an individual index then the option is equivalent to --index=0,II. When IIA is an Element type abbreviation then the option is equivalent to --index=A,-1.
Wherever an individual index is applicable, it can be replaced by an individual index range. It has the form: <first_ii>-<last_ii>. For example: '3-5' will select individual indexes 3, 4 and 5 .
To cope with vendor specific Element types (which should be in the range 128 to 255) the Element type can be given as a number with a leading underscore. For example these are equivalent: --index=arr and --index=_23 since the Array Device Slot Element type value is 23. Also --index=ps1 and --index=_2_1 are equivalent.
Another example: if the first type header in the Configuration dpage has has Array Device Slot Element type then --index=0,-1 is equivalent to --index=arr. Also --index=arr,3 is equivalent to --index=3.
The --index= options can be used to reduce the amount of output (e.g. only showing the element associated with the second 12 volt power supply). They may also be used together with with the --clear=STR, --get=STR and --set=STR options which are described in the STR section below.
The three options: --descriptor=DES, --dev-slot-num=SN and --sas-addr=SA allow medium level indexing, as an alternative to the low level --index= options. Only one of the three options can be used in an invocation. Each of the three options implicitly set the --join option since they need either the Element Descriptor dpage or the Additional Element Status dpage as well as the dpages needed by the --index= option.
These medium level indexing options need support from the SES device and that support is optional. For example the --descriptor=DES needs the Element Descriptor dpage provided by the SES device however that is optional. Also the provided descriptor names need to be useful, and having descriptor names which are all "0" is not very useful. Also some elements (e.g. overall elements) may not have descriptor names.
These medium level indexing options can be used to reduce the amount of output (e.g. only showing the elements related to device slot number 3). They may also be used together with with the --clear=STR, --get=STR and --set=STR options which are described in the following section. Note that even if a field can be set (e.g. "do not remove" (dnr)) and that field can be read back with --get=STR confirming that change, the disk array may still ignore it (e.g. because it does not have the mechanism to lock the disk drawer).
The STR operands of the --clear=STR,
--get=STR and --set=STR options all have the same structure.
There are two forms:
<acronym>[=<value>]
<start_byte>:<start_bit>[:<num_bits>][=<value>]
The <acronym> is one of a list of common fields (e.g. "ident" and "fault") that the utility converts internally into the second form. The <start_byte> is usually in the range 0 to 3, the <start_bit> must be in the range 0 to 7 and the <num_bits> must be in the range 1 to 64 (default 1). The number of bits are read in the left to right sense of the element tables shown in the various SES draft documents. For example the 8 bits of byte 2 would be represented as 2:7:8 with the most significant bit being 2:7 and the least significant bit being 2:0 .
The <value> is optional but is ignored if provided to --get=STR. For --set=STR the default <value> is 1 while for --clear=STR the default value is 0 . <value> is assumed to be decimal, hexadecimal values can be given in the normal fashion.
The supported list of <acronym>s can be viewed by using the --enumerate option twice (or "-ee").
The --clear=STR, --get=STR and --set=STR options can be used up to 8 times in the same invocation. Any <acronym>s used in the STR operands must refer to the same dpage.
When multiple of these options are used (maximum: 8), they are applied in the order in which they appear on the command line. So if options contradict each other, the last one appearing on the command line will be enforced. When there are multiple --clear=STR and --set=STR options, then the dpage they refer to is only written after the last one.
This section describes the two scenarios that can occur when the --data= option is given. These scenarios are the same irrespective of whether the argument to the --data= option is a string of hex bytes on the command line, stdin (indicated by --data=-) or names a file (e.g. --data=@thresh_in_dpage.hex).
The first scenario is flagged by the --control option. It uses the supplied data to build a 'control' dpage that will be sent to the DEVICE using the SCSI SCSI SEND DIAGNOSTIC command. The supplied dpage data should not include its first 4 bytes. Those 4 bytes are added by this utility using the --page=PG option with PG placed at byte offset 0). If needed, the --byte1=B1 option sets byte offset 1, else 0 is placed in that position. The number of bytes decoded from the data provided (i.e. its length) goes into byte offsets 2 and 3.
The second scenario is flagged by the --status option. It decodes the supplied data assuming that it represents the response to one or more SCSI RECEIVE DIAGNOSTIC RESULTS commands. Those responses have typically been captured from some earlier invocation(s) of this utility. Those earlier invocations could use the '-HHH' or '-HHHH' option and file redirection to capture that response (or responses) in hexadecimal. The supplied dpage response data is decoded according to the other command line options. For example the --join option could be given and that would require the data from multiple dpages typically: Configuration, Enclosure status, Element descriptor and Additional element status dpages. If in doubt use --page=all in the capture phase; having more dpages than needed is not a problem.
By default the user supplied data is assumed to be ASCII hexadecimal in lines that don't exceed 512 characters. Anything on a line from and including a hash mark ('#') to the end of line is ignored. An end of line can be a LF or CR,LF and blank lines are ignored. Each separated pair (or single) hexadecimal digits represent a byte (and neither a leading '0x' nor a trailing 'h' should be given). Separators are either space, tab, comma or end of line.
Alternatively binary can be used and this is flagged by the '-rr' option. The --data=H,H... form cannot use binary values for the 'H's, only ASCII hexadecimal. The other two forms (--data=- and --data=@FN) may contain binary data. Note that when the '-rr' option is used with --data=@FN that it only changes the interpretation of the input data, it does not change the decoding and output representation.
This utility has various techniques for changing the state of a SES device. As noted above this is typically a read-modify-write type operation. Most modifiable dpages have a "status" (or "in") page that can be read, and a corresponding "control" (or "out") dpage that can be written back to change the state of the enclosure.
The lower level technique provided by this utility involves outputting a "status" dpage in hex with --raw. Then a text editor can be used to edit the hex (note: to change an Enclosure Control descriptor the SELECT bit needs to be set). Next the control dpage data can fed back with the --data=H,H... option together with the --control option; the --byte1=B1 option may need to be given as well.
Changes to the Enclosure Control dpage (and the Threshold Out dpage) can be done at a higher level. This involves choosing a dpage (the default in this case is the Enclosure Control dpage). Next choose an individual or overall element index (or name it with its Element Descriptor string). Then give the element's name (e.g. "ident" for RQST IDENT) or its position within that element (e.g. in an Array Device Slot Control element RQST IDENT is byte 2, bit 1 and 1 bit long ("2:1:1")). Finally a value can be given, if not the value for --set=STR defaults to 1 and for --clear=STR defaults to 0.
The format of the Subenclosure Nickname control dpage is different from its corresponding status dpage. The status dpage reports all Subenclosure Nicknames (and Subenclosure identifier 0 is the main enclosure) while the control dpage allows only one of them to be changed. Therefore using the --data option technique to change a Subenclosure nickname is difficult (but still possible).
To simplify changing a Subenclosure nickname the --nickname=SEN and --nickid=SEID options have been added. If the SEN string contains spaces or other punctuation, it should be quoted: surrounded by single or double quotes (or the offending characters escaped). If the --nickid=SEID is not given then a Subenclosure identifier of 0 is assumed. As a guard the --control option must also be given. If the --page=PG option is not given then --page=snic is assumed.
When --nickname=SEN is given then the Subenclosure Nickname Status dpage is read to obtain the Generation Code field. That Generation Code together with no more than 32 bytes from the Nickname (SEN) and the Subenclosure Identifier (SEID) are written to the Subenclosure Nickname Control dpage.
There is an example of changing a nickname in the EXAMPLES section below.
Support has been added to sg_ses (actually, its underlying library) for NVMe (also known as NVM Express) Enclosures. It can be considered experimental in sg3_utils package version 1.43 and sg_ses version 2.34 .
This support is based on a decision by NVME-MI (Management Interface) developers to support the SES-3 standard. This was facilitated by adding NVME-MI SES Send and SES Receive commands that tunnel dpage contents as used by SES.
This utility can be used to fetch arbitrary (i.e. non SES) dpages (using the SCSI READ DIAGNOSTIC command). To this end the --page=PG and --hex options would be appropriate. Non-SES dpages can be sent to a device with the sg_senddiag utility.
The most troublesome part of the join operation is associating Additional Element Status descriptors correctly. At least one SES device vendor has misinterpreted the SES-2 standard, specifically with its "element index" field interpretation. The code in this utility interprets the "element index" field as per the SES-2 standard and if that yields an inappropriate Element type, adjusts its indexing to follow that vendor's misinterpretation. The SES-3 drafts have introduced the EIIOE (Element Index Includes Overall Elements) bit which later became a 2 bit field to resolve this ambiguity. See the --eiioe=A_F option.
In draft SES-3 revision 5 the "Door Lock" element name was changed to the "Door" (and an OPEN field was added to the status element). As a consequence the former 'dl' element type abbreviation has been changed to 'do'.
There is a related command set called SAF-TE (SCSI attached fault-tolerant enclosure) for enclosure (including RAID) status and control. SCSI devices that support SAF-TE report "Processor" peripheral device type (0x3) in their INQUIRY response. See the sg_safte utility in this package or the safte-monitor utility on the Internet.
The internal join array is statically allocated and its size is controlled by the MX_JOIN_ROWS define. Its current value is 520.
Examples can also be found at http://sg.danny.cz/sg/sg_ses.html
The following examples use Linux device names. For suitable device names in other supported Operating Systems see the sg3_utils(8) man page.
To view the supported dpages:
sg_ses /dev/bsg/6:0:2:0
To view the Configuration Diagnostic dpage:
sg_ses --page=cf /dev/bsg/6:0:2:0
To view the Enclosure Status dpage:
sg_ses --page=es /dev/bsg/6:0:2:0
To get the (attached) SAS address of that device (which is held in the Additional Element Sense dpage (dpage 10)) printed on hex:
sg_ses -p aes -D ArrayDevice07 -G at_sas_addr -H /dev/sg3
To collate the information in the Enclosure Status, Element Descriptor and Additional Element Status dpages the --join option can be used:
sg_ses --join /dev/sg3
This will produce a lot of output. To filter out lines that don't contain much information add the --filter option:
sg_ses --join --filter /dev/sg3
Fields in the various elements of the Enclosure Control and Threshold dpages can be changed with the --clear=STR and --set=STR options. [All modifiable dpages can be changed with the --raw and --data=H,H... options.] The following example looks at making the "ident" LED (also called "locate") flash on "ArrayDevice07" which is a disk (or more precisely the carrier drawer the disk is in):
sg_ses --index=7 --set=2:1:1 /dev/sg3
If the Element Descriptor diagnostic dpage shows that "ArrayDevice07" is the descriptor name associated with element index 7 then this invocation is equivalent to the previous one:
sg_ses --descriptor=ArrayDevice07 --set=2:1:1 /dev/sg3
Further the byte 2, bit 1 (for 1 bit) field in the Array Device Slot Control element is RQST IDENT for asking a disk carrier to flash a LED so it can be located. In this case "ident" (or "locate") is accepted as an acronym for that field:
sg_ses --descriptor=ArrayDevice07 --set=ident /dev/sg3
To stop that LED flashing:
sg_ses --dev-slot-num=7 --clear=ident /dev/sg3
The above assumes the descriptor name 'ArrayDevice07' corresponds to device slot number 7.
Now for an example of a more general but lower level technique for changing a modifiable diagnostic dpage. The String (In and Out) diagnostics dpage is relatively simple (compared with the Enclosure Status/Control dpage). However the use of this lower level technique is awkward involving three steps: read, modify then write. First check the current String (In) dpage contents:
sg_ses --page=str /dev/bsg/6:0:2:0
Now the "read" step. The following command will send the contents of the String dpage (from byte 4 onwards) to stdout. The output will be in ASCII hex with pairs of hex digits representing a byte, 16 pairs per line, space separated. The redirection puts stdout in a file called "t":
sg_ses --page=str --raw /dev/bsg/6:0:2:0 > t
Then with the aid of the SES-3 document (in revision 3: section 6.1.6) use your favourite editor to change t. The changes can be sent to the device with:
sg_ses --page=str --control --data=- /dev/bsg/6:0:2:0 < t
If the above is successful, the String dpage should have been changed. To check try:
sg_ses --page=str /dev/bsg/6:0:2:0
To change the nickname on the main enclosure:
sg_ses --nickname='1st enclosure' --control /dev/bsg/6:0:2:0
To capture the whole state of an enclosure (from a SES perspective) for later analysis, this can be done:
sg_ses --page=all -HHHH /dev/sg5 > enc_sg5_all.hex
Note that if there are errors or warnings they will be sent to stderr so they will appear on the command line (since only stdout is redirected). A text editor could be used to inspect enc_sg5_all.hex . If all looks in order at some later time, potentially on a different machine where enc_sg5_all.hex has been copied, a "join" could be done. Note that join reflects the state of the enclosure when the capture was done.
sg_ses --data=@enc_sg5_all.hex --status --join
The exit status of sg_ses is 0 when it is successful. Otherwise see the sg3_utils(8) man page.
Written by Douglas Gilbert.
Report bugs to <dgilbert at interlog dot com>.
Copyright © 2004-2018 Douglas Gilbert
This software is distributed under a FreeBSD license. There is NO warranty;
not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
sg_inq, sg_safte, sg_senddiag, sg_ses_microcode, sg3_utils (sg3_utils); safte-monitor (Internet)
August 2018 | sg3_utils-1.43 |