有没有sg3_stringutilss的学习书资料

当前位置: >
sg3_utils 1.32发布 实用程序包
sg3_utils是一套使用SCSI命令集访问设备的实用程序包。当一些工作运行在一个略高的等级时,大多数实用程序发出一个命令并显示响应。支持获取查询数据和VPD,模式和日志页,SCSI传输,如SAS和FCP。该软件包是为Linux,FreeBSD, Solaris, Tru64, 和Windows操作平台而设计,早期版本是Linux2.2系列内核称为sg_utils。
sg3_utils 1.32版本增加sg_sanitize程序,合并了SCSI(t10.org)的变化。
下载地址:
sg3_utils 1.32发布 实用程序包的相关阅读:
本站文章《》除注明转载外,均为本站原创或编译
转载请注明:本文由()提供欢迎免费转载,转载时请保留该信息,谢谢合作!
------分隔线----------------------------
sg3_utils 1.32发布 实用程序包的网友评论当前访客身份:游客 [
当前位置:
sg3_utils 是一个Linux的开发包,用来直接使用 SCSI 命令集访问设备。
sg3_utils最新更新资讯,共1条&&()
授权协议:
操作系统:
收录时间: 日
sg3_utils 的类似软件:C/C++,共151个
Synergy允许你轻松地在你办公桌上多台计算机之间共享你的鼠标和键盘。你只要将鼠标(指针)从一台计算机的屏幕边缘移出到另 一个屏幕就行了。甚至可以共享你的剪贴板。你所需要的仅仅是一个网络连接。Synergy是跨...
最新新闻:
1、介绍 EasyFlash是一款开源的轻量级嵌入式Flash存储器库,主要为MCU(Micro Control Unit)提供便捷、通用的上层应用接口,使得开发者更加高效实现基于的Flash存储器常见应用开发。该库目前提供 三大实用功能 :...
最新新闻:
libimobiledevice 是一个跨平台的软件库,支持 iPhone(R), iPod Touch(R), iPad(R) and Apple TV(R) 等设备的通讯协议。不依赖任何已有的私有库,不需要越狱。应用软件可以通过这个开发包轻松访问设备的文件系统、获取...
最新新闻:
NTFS-3G是一个开源项目,目的是为Linux提供NTFS的驱动程序。能够安全快速的对Windows XP, Windows Server 2003, Windows 2000 and Windows Vista的文件系统进行读写。...
最新新闻:
Connectify是一款非常实用的免费软件,它可以把安装了Windows7的笔记本电脑模 拟成一台无线路由器、无线接入点(无线AP,Access Point)。使用方法:只需要把软件安装在你的Win7本本上,你朋友、同学的笔记本就可以...
OpenCL全称Open Computing Language,是第一个面向异构系统通用目的并行编程的开放式、免费标准,也是一个统一的编程环境,便于软件开发人员为高性能计算服务器、桌面计算系统、手持设备编写高效轻便的代码,而且...
最新新闻:
libusb 是一个用C语言开发的跨平台的USB设备访问接口库。
最新新闻:
Virtual ImagePrinter 是一个虚拟的打印机驱动程序,基于微软统一打印驱动接口。ImagePrinter 可以打印任何在 Windows 系统中可以打印的文档,并生成对应的图形文件,格式包括 BMP、PNG、JPG、TIFF和PDF,你完全可...
lm_sensors的软件可以帮助我们来监控主板,CPU的工作电压,风扇转速、温度等数据。这些数据我们通常在主板的 BIOS也可以看到。当我们可以在机器运行的时候通过lm_sensors随时来监测着CPU的温度变化,可以预防呵保...
最新新闻:
MadWifi 全称是Multiband Atheros Driver for Wifi,使用Atheros系列芯片的802.11a/b/g无线网卡在linux下驱动程序。 市面上有很多基于Atheros芯片的无线网卡,例如DLink的DWL-G650。 特别注意,在中国大陆市场上出...
使用 sg3_utils 中的任何问题
共有 225 个类似软件
Synergy允许你轻松地在你办公桌上多台计算机之间共享你的鼠标和键盘。你只要将鼠标...
eLua 可以让你使用 Lua 编程语言快速开发嵌入式应用,并支持大多数的微处理器架构。...
1、介绍 EasyFlash是一款开源的轻量级嵌入式Flash存储器库,主要为MCU(Micro Contr...
libimobiledevice 是一个跨平台的软件库,支持 iPhone(R), iPod Touch(R), iPad(R) an...
NTFS-3G是一个开源项目,目的是为Linux提供NTFS的驱动程序。能够安全快速的对Windo...
Connectify是一款非常实用的免费软件,它可以把安装了Windows7的笔记本电脑模 拟成一...
OpenCL全称Open Computing Language,是第一个面向异构系统通用目的并行编程的开放...
libusb 是一个用C语言开发的跨平台的USB设备访问接口库。
Virtual ImagePrinter 是一个虚拟的打印机驱动程序,基于微软统一打印驱动接口。I...
lm_sensors的软件可以帮助我们来监控主板,CPU的工作电压,风扇转速、温度等数据。...
共有 2 人关注 sg3_utils6385人阅读
在工作中,由于要对写的代码进行测试,主要需要判断数据包返回值的正确性。测试命令如:SES,SPC,SSP,SMP中涉及到的命令。觉得上面的网址挺好的,现在就来看看,整理整理,以备后用。下面主要针对sg上面的三个命令集进行说明。
1:Utilities: sg3_utils and sg_utils
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.
SCSI Block Commands (SBC) cover direct access devices such as disks.
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
[legacy, use ]
MODE SENSE/SELECT, READ DEFECT
symbolic decoding (optional changing) of mode pages. Can also output (disk) defect lists. Port of olderscsiinfo utility.
READ, WRITE
sg_dd variant that uses memory mapped IO (only on Linux sg devices)
READ, WRITE
sg_dd variant that uses POSIX threads
READ, WRITE
Unix dd command variant, uses SG_IO ioctl to send SCSI commands to copy data. See the page. Newer 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
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
REPORT/SET IDENTIFYING INFORMATION
default is to report (fetch) the device identifier. With the '--set' option a new identifier is sent to the device.
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.
fetch log sense pages, decode standard and some vendor pages
REPORT LUNS
fetch luns reported by a device (lun 0 or &well known lu&)
shows mapping between sg devices and primary device node (if any). In lk 2.6 see .
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.
MODE SENSE
fetch mode pages (output mainly in hex, to decode output use )
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)
&user specified&
send user supplied cdb
READ BUFFER
read from SCSI device cache. Typically for testing the SCSI transport (for throughput or errors)
MODE SENSE/SELECT
display or modify RDAC redundant controller mode page
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 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.
Issue a driver, (SCSI) bus or device (target or lun?) reset.
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.
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).
READ BUFFER
fetch information from a SAF-TE processor
sg_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
[.c.linux]
maps each sg device name to the corresponding numeric &host, channel, target, lun& tuple. In lk 2.6 series the & -g& command is similar.
[.c.win32]
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.
SEND/RECEIVE DIAGNOSTIC
Fetches status diagnostic pages from, and sends some control pages to, a SCSI Enclosure Services (SES) device. See the page.
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.
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).
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.
TEST UNIT READY
Issue one or more Test Unit Ready commands. Can be used to time SCSI command overhead.
logical block provisioning support (&Trim& in the ATA world)
reads indicated blocks on a SCSI disks, stops on the first error found. Does not yield any data. Useful for media scans.
Decodes standard and some vendor Vital Product Data (VPD) pages.
sg_write_buffer
WRITE BUFFER
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. See for another method of setting mode page parameters.
上面表格中的的命令,是对SPC中定义的命令的实现。
可以在sg上面下载源码包,自己编译安装。'./ 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
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命令,以后有机会我会统统的执行一遍。
版权声明:本文为博主原创文章,未经博主允许不得转载。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:235370次
积分:3471
积分:3471
排名:第4388名
原创:101篇
转载:20篇
评论:84条
(1)(2)(2)(1)(1)(2)(4)(3)(4)(2)(3)(5)(3)(7)(12)(5)(1)(13)(3)(3)(3)(3)(7)(1)(1)(5)(4)(3)(9)(15)502 Bad Gateway
502 Bad Gateway
The proxy server received an invalid response from an upstream server. Sorry for the inconvenience.
Please report this message and include the following information to us.
Thank you very much!
http://www.helplib.net/s/linux.die/65_2818/man-8-sg3-utils.shtml
lit-server1
Powered by Tengine/1.3.0汇聚2000万达人的兴趣社区下载即送20张免费照片冲印
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
On Red Hat Enterprise Linux 4 (AS/ES)&is on /proc/scsi/qla2xxx/1 (1,2,3,..N)Sample:# egrep [node|port] /proc/scsi/qlx2xxx/0scsi-qla0-adapter-node=b1c19f2;scsi-qla0-adapter-port=b1c19f2;emulex lpfc820/5[root@localhost tmp]# ls&sg3_utils-1.25-5.el5.x86_64.rpm & & & &sg3_utils-libs-1.25-5.el5.x86_64.rpm &[root@localhost tmp]# rpm -ivh sg3_utils-1.25-5.el5.x86_64.rpm&warning: sg3_utils-1.25-5.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID error: Failed dependencies: libsgutils.so.1()(64bit) is needed by sg3_utils-1.25-5.el5.x86_64 sg3_utils-libs = 1.25-5.el5 is needed by sg3_utils-1.25-5.el5.x86_64[root@localhost tmp]# rpm -ivh sg3_utils-libs-1.25-5.el5.x86_64.rpm&warning: sg3_utils-libs-1.25-5.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID Preparing... & & & & & & & &########################################### [100%]& &1:sg3_utils-libs & & & & ########################################### [100%][root@localhost tmp]# rpm -ivh sg3_utils-1.25-5.el5.x86_64.rpm&warning: sg3_utils-1.25-5.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID Preparing... & & & & & & & &########################################### [100%]& &1:sg3_utils & & & & & & &########################################### [100%][root@localhost tmp]# rescan-scsi-bus.sh&Host adapter 0 (mptspi) found.Scanning SCSI subsystem for new devicesScanning host 0 for &SCSI target IDs &0 1 2 3 4 5 6 7, all LUNsScanning for device 0 0 0 0 ...OLD: Host: scsi0 Channel: 00 Id: 00 Lun: 00& & & Vendor: VMware & Model: Virtual disk & & Rev: 1.0&& & & Type: & Direct-Access & & & & & & & & & &ANSI SCSI revision: 020 new device(s) found. & & & & & & &&0 device(s) removed. & & & & & & & &&[root@localhost tmp]# which rescan-scsi-bus.sh&/usr/bin/rescan-scsi-bus.sh[root@localhost tmp]# more /usr/bin/rescan-scsi-bus.sh&#!/bin/bash# Skript to rescan SCSI bus, using the&# scsi add-single-device mechanism# (c)
Kurt Garloff &kurt@garloff.de&, GNU GPL v2 or later# (c)
Hannes Reinecke, GNU GPL v2 or later# $Id: rescan-scsi-bus.sh-1.35,v 1.1
15:06:25 dhorak Exp $setcolor (){& red="\e[0;31m"& green="\e[0;32m"& yellow="\e[0;33m"& bold="\e[0;1m"& norm="\e[0;0m"}unsetcolor ()&{& red=""; green=""& yellow=""; norm=""}# Return hosts. sysfs must be mountedfindhosts_26 (){& hosts=& for hostdir in /sys/class/scsi_host/host*; do& & hostno=${hostdir#/sys/class/scsi_host/host}& & if [ -f $hostdir/isp_name ] ; then hostname="qla2xxx"& & elif [ -f $hostdir/lpfc_drvr_version ] ; then hostname="lpfc"& & else& & & & hostname=`cat $hostdir/proc_name`& & fi& & hosts="$hosts $hostno"& & echo "Host adapter $hostno ($hostname) found."& done && if [ -z "$hosts" ] ; then& & echo "No SCSI host adapters found in sysfs"& & exit 1;& fi& hosts=`echo $hosts | sed 's/ /\n/g' | sort -n`}# Return hosts. /proc/scsi/HOSTADAPTER/? must existfindhosts (){& hosts=& for driverdir in /proc/scsi/*; do& & driver=${driverdir#/proc/scsi/}& & if test $driver = scsi -o $driver = sg -o $driver = dummy -o $driver = device_ fi& & for hostdir in $driverdir/*; do& & & name=${hostdir#/proc/scsi/*/}& & & if test $name = add_map -o $name = map -o $name = mod_ fi& & & num=$name& & & driverinfo=$driver& & & if test -r $hostdir/ then num=$(printf '%d\n' `sed -n 's/SCSI host number://p' $hostdir/status`) driverinfo="$driver:$name"& & & fi& & & hosts="$hosts $num"& & & echo "Host adapter $num ($driverinfo) found."& & done& done}printtype (){& & local type=$1& & case "$type" in 0) echo "Direct-Access & &" ;; 1) echo "Sequential-Access" ;; 2) echo "Printer & & & & &" ;; 3) echo "Processor & & & &" ;; 4) echo "WORM & & & & & & " ;; 5) echo "CD-ROM & & & & & " ;; 6) echo "Scanner & & & & &" ;; 7) echo "Optical Device & " ;; 8) echo "Medium Changer & " ;; 9) echo "Communications & " ;; 10) echo "Unknown & & & & &" ;; 11) echo "Unknown & & & & &" ;; 12) echo "RAID & & & & & & " ;; 13) echo "Enclosure & & & &" ;; 14) echo "Direct-Access-RBC" ;; *) echo "Unknown & & & & &" ;;& & esac}print02i(){& & if [ "$1" = "*" ] ; then&& & & & echo "00"& & else& & & & printf "%02i" "$1"& & fi}# Get /proc/scsi/scsi info for device $host:$channel:$id:$lun# Optional parameter: Number of lines after first (default = 2),&# result in SCSISTR, return code 1 means empty.procscsiscsi (){ && if test -z "$1"; then LN=2; else LN=$1; fi& CHANNEL=`print02i "$channel"`& ID=`print02i "$id"`& LUN=`print02i "$lun"`& if [ -d /sys/class/scsi_device ]; then& & & SCSIPATH="/sys/class/scsi_device/${host}:${channel}:${id}:${lun}"& & & if [ -d &"$SCSIPATH" ] ; then
&SCSISTR="Host: scsi${host} Channel: $CHANNEL Id: $ID Lun: $LUN"
&if [ "$LN" -gt 0 ] ; then
& & &IVEND=$(cat ${SCSIPATH}/device/vendor)
& & &IPROD=$(cat ${SCSIPATH}/device/model)
& & &IPREV=$(cat ${SCSIPATH}/device/rev)
& & &SCSIDEV=$(printf ' &Vendor: %-08s Model: %-16s Rev: %-4s' "$IVEND" "$IPROD" "$IPREV")
& & &SCSISTR="$SCSISTR$SCSIDEV"
&if [ "$LN" -gt 1 ] ; then
& & &ILVL=$(cat ${SCSIPATH}/device/scsi_level)
& & &type=$(cat ${SCSIPATH}/device/type)
& & &ITYPE=$(printtype $type)
& & &SCSITMP=$(printf ' &Type: & %-16s & & & & & & & &ANSI SCSI revision: %02d' "$ITYPE" "$((ILVL - 1))")
& & &SCSISTR="$SCSISTR$SCSITMP"
& & && & & else
&return 1& & & fi& else& & & grepstr="scsi$host Channel: $CHANNEL Id: $ID Lun: $LUN"& & & SCSISTR=`cat /proc/scsi/scsi | grep -A$LN -e"$grepstr"`& fi& if test -z "$SCSISTR"; then return 1; else return 0; fi}# Find sg device with 2.6 sysfs supportsgdevice26 (){& if test -e /sys/class/scsi_device/$host\:$channel\:$id\:$lun/device/ then & & SGDEV=`readlink /sys/class/scsi_device/$host\:$channel\:$id\:$lun/device/generic`& & SGDEV=`basename $SGDEV`& else& & for SGDEV in /sys/class/scsi_generic/sg*; do& & & DEV=`readlink $SGDEV/device`& & & if test "${DEV##*/}" = "$host:$channel:$id:$lun"; then SGDEV=`basename $SGDEV`; return& & & fi& & done& & SGDEV=""& fi &}# Find sg device with 2.4 report-devs extensionssgdevice24 (){& if procscsiscsi 3; then& & SGDEV=`echo "$SCSISTR" | grep 'Attached drivers:' | sed 's/^ *Attached drivers: \(sg[0-9]*\).*/\1/'`& fi}# Find sg device that belongs to SCSI device $host $channel $id $lunsgdevice (){& SGDEV=& if test -d /sys/class/scsi_ then& & sgdevice26& else && & DRV=`grep 'Attached drivers:' /proc/scsi/scsi 2&/dev/null`& & repdevstat=$((1-$?))& & if [ $repdevstat = 0 ]; then& & & echo "scsi report-devs 1" &/proc/scsi/scsi& & & DRV=`grep 'Attached drivers:' /proc/scsi/scsi 2&/dev/null`& & & if [ $? = 1 ]; fi& & fi& & if ! `echo $DRV | grep 'drivers: sg' &/dev/null`; then& & & modprobe sg& & fi& & sgdevice24& & if [ $repdevstat = 0 ]; then& & & echo "scsi report-devs 0" &/proc/scsi/scsi& & fi& fi} & & &&# Test if SCSI device is still responding to commandstestonline (){& : testonline& RC=0& if test ! -x /usr/bin/sg_ then return 0; fi& sgdevice& if test -z "$SGDEV"; then return 0; fi& for t in 1 2 3 4 5; do& & sg_turs /dev/$SGDEV &/dev/null 2&&1& & RC=$?& & [ $RC -ne 6 ] && break& & sleep $t& done& # echo -e "\e[A\e[A\e[A${yellow}Test existence of $SGDEV = $RC ${norm} \n\n\n"& if test $RC = 1; then return $RC; fi& # OK, device online, compare INQUIRY string& INQ=`sg_inq $sg_len_arg /dev/$SGDEV 2&/dev/null`& IVEND=`echo "$INQ" | grep 'Vendor identification:' | sed 's/^[^:]*: \(.*\)$/\1/'`& IPROD=`echo "$INQ" | grep 'Product identification:' | sed 's/^[^:]*: \(.*\)$/\1/'`& IPREV=`echo "$INQ" | grep 'Product revision level:' | sed 's/^[^:]*: \(.*\)$/\1/'`& STR=`printf " &Vendor: %-08s Model: %-16s Rev: %-4s" "$IVEND" "$IPROD" "$IPREV"`& IPTYPE=`echo "$INQ" | sed -n 's/.* Device_type=\([0-9]*\) .*/\1/p'`& IPQUAL=`echo "$INQ" | sed -n 's/ *PQual=\([0-9]*\) &Device.*/\1/p'`& if [ "$IPQUAL" != 0 ] ; then& & echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nLU not available (PQual $IPQUAL)${norm}\n\n\n"& & return 2& fi& TYPE=$(printtype $IPTYPE)& procscsiscsi& TMPSTR=`echo "$SCSISTR" | grep 'Vendor:'`& if [ "$TMPSTR" != "$STR" ]; then& & echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nfrom:${SCSISTR#* } \nto: $STR ${norm}\n\n\n"& & return 1& fi& TMPSTR=`echo "$SCSISTR" | sed -n 's/.*Type: *\(.*\) *ANSI.*/\1/p'`& if [ $TMPSTR != $TYPE ] ; then& & echo -e "\e[A\e[A\e[A\e[A${red}$SGDEV changed: ${bold}\nfrom:${TMPSTR} \nto: $TYPE ${norm}\n\n\n"& & return 1& fi& return $RC}# Test if SCSI device $host $channen $id $lun exists# Outputs description from /proc/scsi/scsi, returns SCSISTR&testexist (){& : testexist& SCSISTR=& if procscsiscsi && test -z "$1"; then& & echo "$SCSISTR" | head -n1& & echo "$SCSISTR" | tail -n2 | pr -o4 -l1& fi}# Returns the list of existing channels per hostchanlist (){& local hcil& local cil& local chan& local tmpchan& for dev in /sys/class/scsi_device/${host}:* ; do& & [ -d $dev ] ||& & hcil=${dev##*/}& & cil=${hcil#*:}& & chan=${cil%%:*}& & for tmpchan in $ do& & & if test "$chan" -eq $ then chan=& & & fi& & done& & if test -n "$chan" ; then& & & channelsearch="$channelsearch $chan"& & fi& done}# Returns the list of existing targets per hostidlist (){& local hcil& local cil& local il& local target& local tmpid& for dev in /sys/class/scsi_device/${host}:${channel}:* ; do& & [ -d $dev ] ||& & hcil=${dev##*/}& & cil=${hcil#*:}& & il=${cil#*:}& & target=${il%%:*}& & for tmpid in $ do& & & if test "$target" -eq $ then target= break& & & fi& & done& & if test -n "$target" ; then& & & idsearch="$idsearch $target"& & fi& done}# Returns the list of existing LUNsgetluns (){& sgdevice& if test -z "$SGDEV"; fi& if test ! -x /usr/bin/sg_ then echo 0; fi& LLUN=`sg_luns -d /dev/$SGDEV 2&/dev/null`& if test $? != 0; then echo 0; fi& echo "$LLUN" | sed -n 's/.*lun=\(.*\)/\1/p'}# Perform scan on a single lundolunscan(){& SCSISTR=& devnr="$host $channel $id $lun"& echo "Scanning for device $devnr ..."& printf "${yellow}OLD: $norm"& testexist& : f $remove s $SCSISTR& if test "$remove" -a "$SCSISTR"; then& & # Device exists: Test whether it's still online& & # (testonline returns 1 if it's gone or has changed)& & testonline& & RC=$?& & if test $RC != 0 -o ! -z "$forceremove"; then& & & echo -en "\r\e[A\e[A\e[A${red}REM: "& & & echo "$SCSISTR" | head -n1& & & echo -e "${norm}\e[B\e[B"& & & if test -e /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/ then& & & & echo 1 & /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device/delete if test $RC -eq 1 -o $lun -eq 0 ; then& & & & & # Try readding, should fail if device is gone& & & & & echo "$channel $id $lun" & /sys/class/scsi_host/host${host}/scan fi& & & else& & & & echo "scsi remove-single-device $devnr" & /proc/scsi/scsi if test $RC -eq 1 -o $lun -eq 0 ; then& & & & & # Try readding, should fail if device is gone& & & & & echo "scsi add-single-device $devnr" & /proc/scsi/scsi fi& & & fi& & fi& & if test $RC = 0 -o "$forcerescan" ; then& & & if test -e /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/ then& & & & echo 1 & /sys/class/scsi_device/${host}:${channel}:${id}:${lun}/device/rescan& & & fi& & fi& & printf "\r\x1b[A\x1b[A\x1b[A${yellow}OLD: $norm"& & testexist& & if test -z "$SCSISTR"; then& & & printf "\r${red}DEL: $norm\r\n\n"& & & let rmvd+=1;& & & return 1& & fi& fi& if test -z "$SCSISTR"; then& & # Device does not exist, try to add& & printf "\r${green}NEW: $norm"& & if test -e /sys/class/scsi_host/host${host}/ then& & & echo "$channel $id $lun" & /sys/class/scsi_host/host${host}/scan 2& /dev/null& & else& & & echo "scsi add-single-device $devnr" & /proc/scsi/scsi& & fi& & testexist& & if test -z "$SCSISTR"; then& & & # Device not present& & & printf "\r\x1b[A";& & & # Optimization: if lun==0, stop here (only if in non-remove mode)& & & if test $lun = 0 -a -z "$remove" -a $optscan = 1; then&& & & && & & fi& & else&& & & let found+=1;&& & fi& fi}# Perform report lun scandoreportlun(){& lun=& SCSISTR=& for dev in /sys/class/scsi_device/${host}:${channel}:${id}:*; do& & & & if [ -d "$dev" ]; then& & & & & & & & lun=${dev##*:}& & & & & & & & break& & & & else& & & & & & & & continue& & & & fi& done& #If not a single LUN is present then assign lun=0& if [ -z $lun ]; then& & lun=0& & devnr="$host $channel $id $lun"& & echo "Scanning for device $devnr ..."& & printf "${yellow}OLD: $norm"& & testexist -1& & if test -z "$SCSISTR"; then& & & # Device does not exist, try to add& & & printf "\r${green}NEW: $norm"& & & if test -e /sys/class/scsi_host/host${host}/ then& & & & echo "$channel $id $lun" & /sys/class/scsi_host/host${host}/scan 2& /dev/null& & & else& & & & echo "scsi add-single-device $devnr" & /proc/scsi/scsi& & & fi& & & testexist& & & if test -z "$SCSISTR"; then& & & & # Device not present& & & & printf "\r\x1b[A";& & & & lunsearch=& & & & return& & & fi& & fi& & #testonline& fi& flag=0& lun_search=" `getluns`"& # Set flag=1 if all the LUNs are removed& if [ "${#lun_search}" = "1" ]; then& & flag=1& fi& lunremove=& # Check existing luns& for dev in /sys/class/scsi_device/${host}:${channel}:${id}:*; do& & [ -d "$dev" ] || continue& & lun=${dev##*:}& & if [ "$flag" = "1" ]; then& & & lunremove="$lunremove $lun"& & fi& & newsearch=& & oldsearch="$lun_search"& & for tmplun in $lun_ do& & & if test $tmplun -eq $ then dolunscan& & & else newsearch="$newsearch $tmplun"& & & fi& & done& & if [ "${#oldsearch}" = "${#newsearch}" ] ; then # Stale lun lunremove="$lunremove $lun"& & fi& & lun_search="$newsearch"& done& # Add new ones and check stale ones& for lun in $lun_search $ do& & dolunscan& done}&&# Perform search (scan $host)dosearch (){& if test -z "$channelsearch" ; then& & chanlist& fi& for channel in $ do& & if test -z "$idsearch" ; then& & & idlist& & fi& & for id in $ do& & & if test -z "$lunsearch" ; then doreportlun& & & else for lun in $ do& & & & & dolunscan& & & & done& & & fi& & done& done}&expandlist (){& & list=$1& & result=""& & first=${list%%,*}& & rest=${list#*,}& & while test ! -z "$first"; do& beg=${first%%-*}; if test "$beg" = "$first"; then
& &result="$result $beg";& &
& &end=${first#*-}
& &result="$result `seq $beg $end`" fi test "$rest" = "$first" && rest="" first=${rest%%,*} rest=${rest#*,}& & done& & echo $result}# mainif test @$1 = @--help -o @$1 = @-h -o @$1 = @-?; then& & echo "Usage: rescan-scsi-bus.sh [options] [host [host ...]]"& & echo "Options:"& & echo " -l & & &activates scanning for LUNs 0-7 & &[default: 0]"& & echo " -L NUM &activates scanning for LUNs 0--NUM [default: 0]"& & echo " -w & & &scan for target device IDs 0 .. 15 [default: 0-7]"& & echo " -c & & &enables scanning of channels 0 1 & [default: 0]"& & echo " -r & & &enables removing of devices & & & &[default: disabled]"& & echo " -i & & &issue a FibreChannel LIP reset & & [default: disabled]"& & echo "--remove: & & & &same as -r"& & echo "--issue-lip: & & same as -i"& & echo "--forcerescan: & Rescan existing devices"& & echo "--forceremove: & Remove and readd every device (DANGEROUS)"& & echo "--nooptscan: & & don't stop looking for LUNs is 0 is not found"& & echo "--color: & & & & use coloured prefixes OLD/NEW/DEL"& & echo "--hosts=LIST: & &Scan only host(s) in LIST"& & echo "--channels=LIST: Scan only channel(s) in LIST"& & echo "--ids=LIST: & & &Scan only target ID(s) in LIST"& & echo "--luns=LIST: & & Scan only lun(s) in LIST" && & echo " Host numbers may thus be specified either directly on cmd line (deprecated) or"& & echo " or with the --hosts=LIST parameter (recommended)."& & echo "LIST: A[-B][,C[-D]]... is a comma separated list of single values and ranges"& & echo " (No spaces allowed.)"& & exit 0fiif test ! -d /sys/class/scsi_host/ -a ! -d /proc/scsi/; then& echo "Error: SCSI subsystem not active"& exit 1fi # Make sure sg is theremodprobe sg &/dev/null 2&&1if test -x /usr/bin/sg_ then& & sg_version=$(sg_inq -V 2&&1 | cut -d " " -f 3)& & sg_version=${sg_version##0.}& & #echo "\"$sg_version\""& & if [ -z "$sg_version" -o "$sg_version" -lt 70 ] ; then& & & & sg_len_arg="-36"& & else& & & & sg_len_arg="--len=36"& & fifi & &# defaultsunsetcolorlunsearch=""idsearch=`seq 0 7`channelsearch=""remove=forceremove=optscan=1if test -d /sys/class/scsi_ then&& findhosts_26else && findhostsfi &# Scan optionsopt="$1"while test ! -z "$opt" -a -z "${opt##-*}"; do& opt=${opt#-}& case "$opt" in& & l) lunsearch=`seq 0 7` ;;& & L) lunsearch=`seq 0 $2`;;& & w) idsearch=`seq 0 15` ;;& & c) channelsearch="0 1" ;;& & r) remove=1 ;;& & i) lipreset=1 ;;& & -remove) & & &remove=1 ;;& & -forcerescan) remove=1; forcerescan=1 ;;& & -forceremove) remove=1; forceremove=1 ;;& & -hosts=*) & & arg=${opt#-hosts=}; & hosts=`expandlist $arg` ;;& & -channels=*) &arg=${opt#-channels=};channelsearch=`expandlist $arg` ;;&& & -ids=*) & arg=${opt#-ids=}; & & & & idsearch=`expandlist $arg` ;;&& & -luns=*) &arg=${opt#-luns=}; & & & &lunsearch=`expandlist $arg` ;;&& & -color);& & -nooptscan) optscan=0 ;;& & -issue-lip) lipreset=1 ;;& & *) echo "Unknown option -$opt !" ;;& esac& shift& opt="$1"done & &# Hosts given ?if test "@$1" != "@"; then&& hosts=$*;&fiif [ -d /sys/class/scsi_host -a ! -w /sys/class/scsi_host ]; then& echo "You need to run scsi-rescan-bus.sh as root"& exit 2fi &echo "Scanning SCSI subsystem for new devices"test -z "$remove" || echo " and remove devices that have disappeared"declare -i found=0declare -i rmvd=0for host in $ do& echo -n "Scanning host $host "& if test -e /sys/class/fc_host/host$host -o -e /sys/class/iscsi_host/host$ then& & if test -e /sys/class/fc_host/host$host -a -n "$lipreset" ; then& & & echo 1 & /sys/class/fc_host/host$host/issue_lip 2& /dev/& & fi& & # always do a scan on FC or iSCSI& & echo "- - -" & /sys/class/scsi_host/host$host/scan 2& /dev/& & [ -z $forcerescan ] && channelsearch=""& & idsearch=""& fi& [ -n "$channelsearch" ] && echo -n "channels $channelsearch "& echo -n "for "& if [ -n "$idsearch" ] ; then& & & echo -n " SCSI target IDs " $idsearch& else& & & echo -n " all SCSI target IDs"& fi& if [ -n "$lunsearch" ] ; then& & & echo ", LUNs " $lunsearch& else& & & echo ", all LUNs"& fi&&doneecho "$found new device(s) found. & & & & & & & "echo "$rmvd device(s) removed. & & & & & & & & "[root@localhost tmp]#&
阅读(580)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'rescan-scsi-bus.sh
sg3_utils',
blogAbstract:'# lspci | grep -i fibre04:00.0 Fibre Channel: QLogic Corp. ISP2432-based 4Gb Fibre Channel to PCI Express HBA (rev 03)04:00.1 Fibre Channel: QLogic Corp. ISP2432-based 4Gb Fibre Channel to PCI Express HBA (rev 03)05:00.0 Fibre Channel: QLogic Corp. ISP2432-based 4Gb Fibre Channel to PCI Express HBA (rev 03)',
blogTag:'rescan,scsi,linux',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:6,
publishTime:6,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}

我要回帖

更多关于 beanutils 的文章

 

随机推荐