The Linux SCSI Generic (sg) Driver(使用说明)
来源:互联网 发布:如何查看淘宝店铺等级 编辑:程序博客网 时间:2024/05/22 09:03
在工作中,由于要对写的代码进行测试,主要需要判断数据包返回值的正确性。测试命令如:SES,SPC,SSP,SMP中涉及到的命令。觉得上面的网址挺好的,现在就来看看,整理整理,以备后用。下面主要针对sg上面的三个命令集进行说明。
1:Utilities: sg3_utils and sg_utils
The sg3_utils package contains utilities that send SCSI commands to devices.
SCSI command sets are divided into a common setandseveral device class specific sets.
The common set of commands is referred to as theSCSI Primary Commands (SPC) with SPC-3 being the most recent standard. The mandatory SCSI INQUIRY command is defined in SPC-3.
The SCSI Block Commands (SBC) cover direct access devices such as disks.
The MultiMedia Commands (MMC) cover CD, DVD and BD drives and the media within them.
In the Linux kernel (lk) 2.4 series most of these utilities must be used with a SCSI generic (sg) driver device name (e.g./dev/sg0). In the lk 2.6 series almost all of these utilities can be used withthe primary device names as well (e.g./dev/sda, /dev/scd0, /dev/st0 and/dev/hdd (if it is an ATAPI device)). From lk 2.6.28 bsg devices can also be used (e.g./dev/bsg/3:0:0:0 ).
Utility name
Main SCSI commands
invoked
Notes
sginfo
[legacy, use sdparm]
MODE SENSE/SELECT, READ DEFECT
symbolic decoding (optional changing) of mode pages. Can also output (disk) defect lists. Port of olderscsiinfo utility.
sgm_dd
READ, WRITE
sg_dd variant that uses memory mapped IO (only on Linux sg devices)
sgp_dd
READ, WRITE
sg_dd variant that uses POSIX threads
sg_dd
READ, WRITE
Unix dd command variant, uses SG_IO ioctl to send SCSI commands to copy data. See thesg_dd page. Newerddpt utility adds features and is ported to "f,s,w"
sg_decode_sense
decodes sense data given as a string of hexadecimal bytes or in binary
sg_emc_trespass
MODE SELECT
utility specialized for EMC Clariion series
sg_format
FORMAT
format or resize a SCSI disk
sg_get_config
GET CONFIGURATION
fetch features and profiles of a cd/dvd drive and/or its current media
sg_get_lba_status
GET LBA STATUS
logical block provisioning support
sg_ident
REPORT/SET IDENTIFYING INFORMATION
default is to report (fetch) the device identifier. With the '--set' option a new identifier is sent to the device.
sg_inq
INQUIRY
fetch standard response, VPD pages or version descriptors. Also can perform IDENTIFY (PACKET) DEVICE ATA command. VPD page decoding also performed by sg_vpd and sdparm.
sg_logs
LOG SENSE
fetch log sense pages, decode standard and some vendor pages
sg_luns
REPORT LUNS
fetch luns reported by a device (lun 0 or "well known lu")
sg_map
INQUIRY
shows mapping between sg devices and primary device node (if any). In lk 2.6 seelsscsi .
sg_map26
maps between single Linux sg device and primary device node (and vice versa). Also does mapping in to, and out of, sysfs. For the Linux 2.6 series.
sg_modes
MODE SENSE
fetch mode pages (output mainly in hex, to decode output use sdparm)
sg_opcodes
REPORT SUPPORTED OPERATION CODES
fetch supported SCSI commands or supported task management functions
sg_persist
PERSISTENT RESERVE IN/OUT
control persistent reservations and report reservation status
sg_prevent
PREVENT ALLOW MEDIUM REMOVAL
control media removal, mainly for those SCSI devices which have removable media (e.g. CD/DVD and tape drives)
sg_raw
<user specified>
send user supplied cdb
sg_rbuf
READ BUFFER
read from SCSI device cache. Typically for testing the SCSI transport (for throughput or errors)
sg_rdac
MODE SENSE/SELECT
display or modify RDAC redundant controller mode page
sg_read
READ
read continually from same offset. Syntax similar to sg_dd (without write side). Can test SCSI device cache and transport performance.
sg_readcap
READ CAPACITY
fetch the number of blocks and the individual block size for disks and CD/DVD media
sg_read_buffer
READ BUFFER
read descriptors or data
sg_read_long
READ LONG
read data from given LBA which includes the block and ECC data.
sg_reassign
REASSIGN BLOCKS
reassign a LBA from one sector on a disk (typically damaged) to a new (spare) sector. User data copied if it is recoverable.
sg_referrals
REPORT REFERRALS
report data segment accessibility from target port groups
sg_requests
REQUEST SENSE
fetch sense data from the given device. Modern uses include getting a progress indication (e.g. during a format) or finding the power condition state.
sg_reset
-
Issue a driver, (SCSI) bus or device (target or lun?) reset.
sg_rmsn
READ MEDIA SERIAL NUMBER
Relatively new command added to SPC-3. Format of response is vendor specific so this utility outputs it in hex (default) or binary.
sg_rtpg
REPORT TARGET PORT GROUPS
Specialized for multi-ported SCSI devices where one port (or a group of them) is preferred for IO over another (or others).
sg_safte
READ BUFFER
fetch information from a SAF-TE processor
sg_sanitize
SANITIZE
Send SCSI SANITIZE command
sg_sat_identify
ATA PASS-THROUGH
Send ATA IDENTIFY DEVICE or IDENTIFY PACKET DEVICE commands via the SAT ATA PASS-THROUGH (16 or 12) SCSI command.
sg_sat_phy_event
ATA PASS-THROUGH
Sends an ATA READ LOG EXT command via a SAT to fetch log page 11h which contains SATA phy event counters.
sg_sat_set_features
ATA PASS_THROUGH
Sends ATA SET FEATURES command via SAT
sg_scan
[.c.linux]
[INQUIRY]
maps each sg device name to the corresponding numeric <host, channel, target, lun> tuple. In lk 2.6 series the "lsscsi -g" command is similar.
sg_scan
[.c.win32]
[INQUIRY]
shows one device per line, with the device's various names and INQUIRY response string on that line.
sg_senddiag
SEND DIAGNOSTIC
Issues either a default self test or a short/extended foreground/background self test. With no arguments it uses RECEIVE DIAGNOSTIC RESULTS to list all supported diagnostic pages.
sg_ses
SEND/RECEIVE DIAGNOSTIC
Fetches status diagnostic pages from, and sends some control pages to, a SCSI Enclosure Services (SES) device. See thesg_ses page.
sg_start
START STOP UNIT
Controls the power condition state of a SCSI device. Primary use is to spin up and down SCSI disks. Can also load and eject removable media.
sg_stpg
SET TARGET PORT GROUPS
Specialized for multi-ported SCSI devices where one port (or a group of them) is preferred for IO over another (or others).
sg_sync
SYNCHRONIZE CACHE
Causes disk caches to be flushed to media
sg_test_rwbuf
READ/WRITE BUFFER
Random pattern written to SCSI device buffer then read back and checked. Used in testing for data corruption.
sg_turs
TEST UNIT READY
Issue one or more Test Unit Ready commands. Can be used to time SCSI command overhead.
sg_unmap
UNMAP
logical block provisioning support ("Trim" in the ATA world)
sg_verify
VERIFY
reads indicated blocks on a SCSI disks, stops on the first error found. Does not yield any data. Useful for media scans.
sg_vpd
INQUIRY
Decodes standard and some vendor Vital Product Data (VPD) pages.
sg_write_buffer
WRITE BUFFER
write data; can be used to download firmware
sg_write_long
WRITE LONG
writes to a LBA, data which includes the block and ECC data. Suitable data typically fetched by prior sg_read_long utility.
sg_write_same
WRITE SAME
writes a single block to one or more (consecutive) LBAs. Also supports some logical block provisioning options.
sg_wr_mode
MODE SELECT
writes mode pages supplied in ASCII hex (e.g. from "sg_modes -r") to the SCSI device. Seesdparm for another method of setting mode page parameters.
上面表格中的的命令,是对SPC中定义的命令的实现。
可以在sg上面下载源码包,自己编译安装。'./configure ; make ; make install' 就可以将编译好的sg命令安装到/usr/local/bin/目录中。
[root@centos /usr/local/bin]$ls
sg_dd sginfo sg_modes sg_rdac sg_referrals sg_sat_identify sg_stpg sg_write_buffer
sg_decode_sense sg_inq sg_opcodes sg_read sg_requests sg_sat_phy_event sg_sync sg_write_long
sg_emc_trespass sg_logs sgp_dd sg_read_block_limits sg_reset sg_sat_set_features sg_test_rwbuf sg_write_same sg_format sg_luns sg_persist sg_read_buffer sg_rmsn sg_scan sg_turs sg_wr_mode sg_get_config sg_map sg_prevent sg_readcap sg_rtpg sg_senddiag sg_unmap
sg_get_lba_status sg_map26 sg_raw sg_read_long sg_safte sg_ses sg_verify
sg_ident sgm_dd sg_rbuf sg_reassign sg_sanitize sg_start sg_vpd
下面举几个例子(命令式在虚拟机上面执行的)
[root@centos /usr/local/bin]$sg_inq /dev/sda //时间inquiry命令查询target的信息
standard INQUIRY: //标准inquiry的输出数据
PQual=0 Device_type=0 RMB=0 version=0x02 [SCSI-2]
[AERC=0] [TrmTsk=0] NormACA=0 HiSUP=0 Resp_data_format=2
SCCS=0 ACC=0 TPGS=0 3PC=0 Protect=0 BQue=0
EncServ=0 MultiP=0 [MChngr=0] [ACKREQQ=0] Addr16=0
[RelAdr=0] WBus16=1 Sync=1 Linked=0 [TranDis=0] CmdQue=1
length=36 (0x24) Peripheral device type: disk
Vendor identification: VMware,
Product identification: VMware Virtual S
Product revision level: 1.0
[root@centos /usr/local/bin]$sg_scan
/dev/sg0: scsi0 channel=0 id=0 lun=0
/dev/sg1: scsi0 channel=0 id=1 lun=0
/dev/sg2: scsi0 channel=0 id=2 lun=0
2:smp_utils
The smp_utils package contains utilities for the Serial Attached SCSI (SAS) Serial Management Protocol (SMP). Most utilities correspond to a single SMP function, sending out a request, checking for errors and if all is well processing the response. The response is either decoded, printed out in ASCII hexadecimal or sent as binary to stdout.
At the lower levels SAS is a point to point interconnect (like SATA).SAS has devices called expanders which have a similar role to switches in the Fibre Channel protocol and the Ethernet.The primary role of SMP is to monitor and control SAS expanders. Most SAS Host Bus Adapters (HBAs) contain a SMP initiator through which SMP requests are sent and responses received. SAS expanders contain SMP targets that respond to SMP requests. SAS disks do not normally contains SMP targets and SATA disks do not contain SMP targets.SAS has two other protocols: SSP for transporting SCSI command sets to SAS devices(e.g. SAS disks and tape drives) , and STP for tunnelling the ATA command set to a SAS expander.
SMP is a request response protocol with each request and response limited currently to 1028 bytes in length (including a 4 byte CRC at the end of each request and response).
Each expander phy has a routing attribute. There are three routing attributes: direct, subtractive and table. Direct routing is the simplest and is all that is required if a single expander interconnects SAS end devices (e.g. SAS initiators (HBAs) and SAS targets (including SAS disks, tapes and SES devices)).Such an interconnect is termed in SAS as a "Service Delivery Subsystem" (SDS) while other transports might term this as a "fabric".
The utilities in the smp_utils packagesend requests to what the standard terms as a SMP target. A SMP target is not a SCSI device so SCSI commands like INQUIRY cannot be sent to a SMP target. Hence utilities such as those in the sg3_utils package cannot be used on a SMP target.
A SAS expander will contain one SMP target with the SAS address of the expander.Some SAS host bus adapters (HBAs) have a (hidden) SMP target. Typically SAS end devices such as disk drives (both SAS and SATA) and tape drives do not contain a SMP target.
编译完之后,linux上面的smp如下:
[root@centos /usr/local/bin]$smp
smp_conf_general smp_discover_list smp_rep_broadcast smp_rep_phy_sata smp_zoned_broadcast
smp_conf_phy_event smpdump smp_rep_exp_route_tbl smp_rep_route_info smp_zone_lock
smp_conf_route_info smp_ena_dis_zoning smp_rep_general smp_rep_self_conf_stat smp_zone_unlock
smp_conf_zone_man_pass smp_phy_control smp_rep_manufacturer smp_rep_zone_man_pass
smp_conf_zone_perm_tbl smp_phy_test smp_rep_phy_err_log smp_rep_zone_perm_tbl
smp_conf_zone_phy_info smpquery smp_rep_phy_event smp_write_gpio
smp_discover smp_read_gpio smp_rep_phy_event_list smp_zone_activate
对上面的命令的解释可以参考SPL中的9.4 Management application layer
smp_utils很重要,但是我现在的条件,不能实际的测试smp_utils中的命令,如果以后有机会肯定会把smp_utils中的命令执行一遍,看看结果,思考思考expander在整个系统的功能。
3:Scsi_ses
SCSI Enclosure Services (SES) permit themanagement and sensethe state ofpower supplies, cooling devices, displays, indicators, individual drives, and other non-SCSI elements installed in an enclosure. The scsi_ses adapter driver simulates a SES device. The default action is to appear as a disk (actually an 8 MB ramdisk) with associated Enclosure Services. This is similar to a fibre channel disk with a SCA-2 connector which includes an Enclosure Services Interface (ESI). Alternatively this driver can simulate a simple SES device.
Supported SES Diagnostic pages
A SES (and SES-2 draft) application client communicates with a SES device via diagnostic pages.Status diagnostic pages are fetched from a SES device with the RECEIVE DIAGNOSTIC RESULTS SCSI command.Control diagnostic pages are sent to a SES device with the SCSI SEND DIAGNOSTIC SCSI command.
The supported status diagnostic pages are: //状态 page code
- List supported diagnostic pages [0x0]
- Configuration [0x1]
- Enclosure status [0x2]
- Help text [0x3]
- String In [0x4]
- Threshold In [0x5]
- Element descriptor [0x7]
- Enclosure busy [0x9]
The supported control diagnostic pages are: //控制page code
- Enclosure control [0x2]
- String Out [0x4]
- Threshold Out [0x5]
上面说的很清楚通过send diagnostic和receive diagnostic来控制或获取enclosure中的elements的信息。
上面涉及到的sg命令,以后有机会我会统统的执行一遍。
- The Linux SCSI Generic (sg) Driver(使用说明)
- The Linux SCSI Generic (sg) Driver(使用说明)
- linux scsi generic howto学习笔记
- linux scsi generic howto学习笔记
- Linux USB subsystem --- register generic usb driver
- Linux USB subsystem --- register generic usb driver
- Anatomy of the Linux SCSI subsystem
- Linux cpuidle framework(3)_ARM64 generic CPU idle driver
- Writing a SCSI Device Driver
- AIX SCSI Driver 编程实质
- 用户态发送SCSI命令例程 ( sg )
- The definition of SCSI
- Linux功耗管理(20)_Linux cpuidle framework(3)_ARM64 generic CPU idle driver
- The GNU/Linux "usbnet" Driver Framework
- The Linux keyboard driver(By Andries Brouwer )
- The Linux USB Video Class (UVC) driver
- Relocation the generic ELF
- Linux SCSI 子系统剖析
- 当主线程队列,如果处理一个消息超过5秒,android 就会抛出一个 ANP(无响应)的消息
- 网页展示 word PDF 方案 仿百度文库类
- SQL Server 2008编程入门经典笔记(第二章:SQL Server管理工具)
- Jar包的正确运行方法
- 我的conky配置
- The Linux SCSI Generic (sg) Driver(使用说明)
- 自己的Allegro16.3的学习笔记,算是回报社会吧。
- C# WinForm 应用程序的 SQL Server 连接配置界面 动态库
- 键盘的快捷键
- UDP打洞技术
- C++ std::pair
- 数据结构与程序设计课后题2.2
- OFBIZ研究心得之五
- HDU4217-线段树