Hi folks,

I just found out about these sg_utils which may be helpful for folks
running amanda on Linux systems, especially for debugging tapedrive and
changer problems...

http://gear.torque.net/sg/#Utilities: sg_utils and sg3_utils
-- 
"Jonathan F. Dill" ([EMAIL PROTECTED])
CARB Systems and Network Administrator
Home Page:  http://www.umbi.umd.edu/~dill
Title: The Linux SCSI Generic (sg) Driver

The Linux SCSI Generic (sg) Driver

Introduction
Background
Features
SG device driver downloads
Utilities: sg_utils and sg3_utils
Sg related pages
External references
SG in Redhat 6.2, 7.0 and Mandrake 7.1
 

Introduction

The Linux sg driver is a upper level SCSI subsystem device driver that is used primarily to handle devices _not_ covered by the other upper level drivers: sd (disks), st (tapes) and sr (CDROMs). The sg driver is used by scanners, cd writers and applications that read cd audio digitally. Sg can also be used for less usual tasks performed on disks, tapes and cdroms. Sg is a character device which, in some contexts, gives it some advantages over sd and sr which are block devices. The interface of sg is at the level of SCSI command requests and their associated responses.

Background

The original driver was written by Lawrence Foard in 1992 and remained unchanged for several years. In August 1998 Heiko Eissfeldt and Joerg Schilling started working on enhancements to this driver. Soon after, the author became involved and these efforts culminated in a new sg driver being placed in Linux kernel 2.2.6 which was released on 16th April 1999. It contains the first major upgrade to the SCSI generic packet device driver ("sg") since 1992. This new driver has a super-set of the original interface and the semantics of the implementation are very similar. Hence it offers a high degree of backward compatibility with the original driver.

The major reason for introducing a new sg driver into the 2.2 series of kernels was the problem that the original device driver was having trouble finding memory. This driver improves the situation by using scatter gather, memory above the 16 Mbytes level and memory from the scsi dma pool as appropriate. Other drivers were affected by these memory problems (especially those associated with ISA hardware). In kernel 2.2.10 H.J. Lu introduced a new kernel memory allocator that alleviated many of these memory problems.

On 4th January 2001 the Linux 2.4.0 kernel was introduced and it contained a "version 3" sg driver that is described below.

Features

The following enhancements have been added: scatter gather, command queuing, per file descriptor sequencing (was per device) and asynchronous notification. Scatter gather allows large buffers (previously limited to 128 KB on i386) to be used. Scatter gather is also a lot more "kernel friendly". The original driver used a single large buffer which made it impossible to run 2 or more sg-based applications at the same time. With the new driver a buffer is reserved for each file descriptor guaranteeing that at least that buffer size will be available for each request on the file descriptor. A user may request a larger buffer size on any particular request but runs the (usually remote) risk of an out of memory (ENOMEM) error.

A "version 3" sg driver is now available. It adds a new interface that allows more control over SCSI commands and returns more information about their performance. This driver is present in Linux kernel 2.4.0 . A separate version with reduced capabilities is available for the 2.2 series kernels. Features include: larger sense buffer, residual DMA count, 16 byte commands, direct IO support, command duration timing and a "proc_fs" interface. Naturally it is backward compatible with applications based on the sg interface in the lk 2.2 series and earlier.

SG device driver downloads

The following table summarizes the different versions of the sg device driver that are available. If you wish to use one of these tarballs then untar it in /usr/src/linux (or wherever the top of your kernel tree is). As a precaution you may wish to copy the files include/scsi/sg.h and drivers/scsi/sg.c to other names. This will facilitate reversing the patch if required. For information about the differences between versions see the history section at the top of the include/scsi/sg.h file.
 
Linux version Sg driver 
version+tarball
Patch Notes
 < 2.2.6 sg22orig.tgz   found in RH6.0, original documentation
       
2.2.6 + 2.2.7 sg2131.tgz pat_sg2134_225.gz  
2.2.8 + 2.2.9 sg2132.tgz    
2.2.10 - 2.2.13 sg2134.tgz patch  
2.2.14 + 2.2.15 sg2136.tgz patch  on sg version 2.1.34 (for documentation see bullet list)
2.2.16 sg2138.tgz patch  on sg in lk 2.2.14+15 fixes scatter gather bugs on aha1542
2.2.17 - 2.2.19 sg2139.tgz patch  on sg in lk 2.2.16 sg2138 broke sym53c416, now fixed
       
optional 2.2 series sg version  3.0.17   sg version 3 backported to lk 2.2
optional 2.4 series sg version  1.5.01   sg version 1 (original) ported to lk 2.4
2.4.0 sg3117_lk240   documentation and notes
2.4.1 - 2.4.3 sg3117_lk241   unplugs queues
test 2.4.* sg3118   testing dio, detaching, see sg v3 notes
Table 1. sg device drivers

For the Linux kernel 2.2 series, the current  production version of the sg driver is 2.1.39 . All sg drivers for the 2.2 series of kernels (including the original) are interchangeable (but see final section on this page about Redhat 6.2 and Mandrake 7.1). So, for example, sg22orig.tgz can be put in lk 2.2.17 while, on the other hand, sg2139.tgz can be put in lk 2.2.0 .

For the Linux kernel 2.4 series, the current production version of sg is 3.1.17 .

Older versions can be obtained from this directory. A sub directory called "original" contains the original driver (i.e. prior to linux kernel 2.2.6) and its HOWTO document.

Utilities: sg_utils and sg3_utils

These are a set of utilities and test programs that use sg and associated interfaces. This utility description page contains more details. There are 2 separate groupings of these utilities as explained below.

The first is called sg_utils and it uses the sg version 2 interface found from lk 2.2.6 and onward. Over half of those utilities will also work on the original sg device driver (at least back to the lk 2.0 series). If required, "make common" will produce the subset that will work on the whole lk 2.x series. Since the sg "version 3" device driver still maintains the original interface, the sg_utils package will continue to work in lk 2.4 .

The other is called sg3_utils and it assumes (and checks at runtime) that it is using the sg "version 3" device driver (as found in lk 2.4.0). Apart from a few extra features (e.g. ability to select direct IO), the functionality offered is essentially the same as the programs in sg_utils.

The latest versions, packaged in tarballs, source and binary rpms are given in the following table. They contain README and CHANGELOG files and some man pages.
 

tarballs source rpms i386 binary rpms
sg_utils sg_utils-0.93.tgz sg_utils-0.93-3.src.rpm sg_utils-0.93-3.i386.rpm
sg3_utils sg3_utils-0.93.tgz sg3_utils-0.93-3.src.rpm sg3_utils-0.93-3.i386.rpm
Table 2. sg_utils packages

The above rpms have been rebuilt in RPM v3 (with RH 6.2) to make them easier to load.

Sg related pages

Following are some links to related pages on this site:
  • Abridged and longer documentation  (describes sg version 2.1.39)
  • A FAQ including current project status, bug fixes and other useful patches
  • Some notes about the "version 3" sg driver and its documentation
  • Timings for direct and indirect IO (as used by sg)
  • Some fast copy options for disks (including raw devices)
  • raw memory to disk patch (e.g. video frame buffer to disk)
  • devfs and SCSI in lk 2.3.46 and the lk 2.4 series
  • snapshot document of the Linux SCSI subsystem as it enters lk 2.4 . This document has become the LDP's SCSI-2.4-HOWTO
  • release notes on the scsihosts kernel boot and module load option
  • experimental scsimon driver for hotplugging

External references

Here are some useful links to related information held at other sites:
  • www.t10.org  is a very important site for SCSI related information. It contains SCSI 2 and 3 draft standards
  • www.andante.org/scsi.html  is Eric Youngdale's site. Eric is primarily responsible for the Linux SCSI architecture and its mid-level implementation.
  • www.kernel.dk  is Jens Axboe's site for Linux cdrom matters including the SCSI "sr" driver.
  • Kurt Garloff has several pages  with Linux SCSI themes (including the scsidev, scsiinfo and rescan-scsi-bus programs).
  • The Scsi Command Utility (scu) is quite comprehensive and is ported to several OSes including Linux. Its home page can be found here.
  • Doug Ledford maintains the much used Adaptec aic7xxx driver. Follow the link from this site. A new aic7xxx driver from Adaptec is available on this site.
  • The newsgroup [EMAIL PROTECTED] is the appropriate place to discuss Linux SCSI related issues.
  • The Linux source file: /usr/src/linux/MAINTAINERS contains up to date information about who maintains what and where information can be found. Links to SCSI adapter information are also in that file.

Sg in Redhat 6.2, 7.0 and Mandrake 7.1

It has come to my attention that these distributions have slightly modified sg drivers in the lk 2.2 series. The change arises due to a "sigio" patch that has been applied. [The sigio patch backports some new lk 2.4 functionality for POSIX real time signals into the lk 2.2 series.] This patch effects sg because it changes the number of arguments to the kill_fasync() call. This call is found at line 834 in sg version 2.1.39 and looks like this in the standard kernels:
       kill_fasync(sfp->async_qp, SIGPOLL);
If compiling this line gives an error (usually "too few arguments to kill_fasync") then it can safely be changed to this:
       kill_fasync(sfp->async_qp, SIGPOLL, POLL_IN);

This problem only impacts sg 2.1.x versions retrieved from this page (and sg version 3.0.17).
 
 

Douglas Gilbert can be emailed at this address (also at [EMAIL PROTECTED]).
Last updated: 15th April 2001, 15:00

Reply via email to