0001 .. SPDX-License-Identifier: GPL-2.0
0002
0003 ====================
0004 The SCSI Tape Driver
0005 ====================
0006
0007 This file contains brief information about the SCSI tape driver.
0008 The driver is currently maintained by Kai Mäkisara (email
0009 Kai.Makisara@kolumbus.fi)
0010
0011 Last modified: Tue Feb 9 21:54:16 2016 by kai.makisara
0012
0013
0014 Basics
0015 ======
0016
0017 The driver is generic, i.e., it does not contain any code tailored
0018 to any specific tape drive. The tape parameters can be specified with
0019 one of the following three methods:
0020
0021 1. Each user can specify the tape parameters he/she wants to use
0022 directly with ioctls. This is administratively a very simple and
0023 flexible method and applicable to single-user workstations. However,
0024 in a multiuser environment the next user finds the tape parameters in
0025 state the previous user left them.
0026
0027 2. The system manager (root) can define default values for some tape
0028 parameters, like block size and density using the MTSETDRVBUFFER ioctl.
0029 These parameters can be programmed to come into effect either when a
0030 new tape is loaded into the drive or if writing begins at the
0031 beginning of the tape. The second method is applicable if the tape
0032 drive performs auto-detection of the tape format well (like some
0033 QIC-drives). The result is that any tape can be read, writing can be
0034 continued using existing format, and the default format is used if
0035 the tape is rewritten from the beginning (or a new tape is written
0036 for the first time). The first method is applicable if the drive
0037 does not perform auto-detection well enough and there is a single
0038 "sensible" mode for the device. An example is a DAT drive that is
0039 used only in variable block mode (I don't know if this is sensible
0040 or not :-).
0041
0042 The user can override the parameters defined by the system
0043 manager. The changes persist until the defaults again come into
0044 effect.
0045
0046 3. By default, up to four modes can be defined and selected using the minor
0047 number (bits 5 and 6). The number of modes can be changed by changing
0048 ST_NBR_MODE_BITS in st.h. Mode 0 corresponds to the defaults discussed
0049 above. Additional modes are dormant until they are defined by the
0050 system manager (root). When specification of a new mode is started,
0051 the configuration of mode 0 is used to provide a starting point for
0052 definition of the new mode.
0053
0054 Using the modes allows the system manager to give the users choices
0055 over some of the buffering parameters not directly accessible to the
0056 users (buffered and asynchronous writes). The modes also allow choices
0057 between formats in multi-tape operations (the explicitly overridden
0058 parameters are reset when a new tape is loaded).
0059
0060 If more than one mode is used, all modes should contain definitions
0061 for the same set of parameters.
0062
0063 Many Unices contain internal tables that associate different modes to
0064 supported devices. The Linux SCSI tape driver does not contain such
0065 tables (and will not do that in future). Instead of that, a utility
0066 program can be made that fetches the inquiry data sent by the device,
0067 scans its database, and sets up the modes using the ioctls. Another
0068 alternative is to make a small script that uses mt to set the defaults
0069 tailored to the system.
0070
0071 The driver supports fixed and variable block size (within buffer
0072 limits). Both the auto-rewind (minor equals device number) and
0073 non-rewind devices (minor is 128 + device number) are implemented.
0074
0075 In variable block mode, the byte count in write() determines the size
0076 of the physical block on tape. When reading, the drive reads the next
0077 tape block and returns to the user the data if the read() byte count
0078 is at least the block size. Otherwise, error ENOMEM is returned.
0079
0080 In fixed block mode, the data transfer between the drive and the
0081 driver is in multiples of the block size. The write() byte count must
0082 be a multiple of the block size. This is not required when reading but
0083 may be advisable for portability.
0084
0085 Support is provided for changing the tape partition and partitioning
0086 of the tape with one or two partitions. By default support for
0087 partitioned tape is disabled for each driver and it can be enabled
0088 with the ioctl MTSETDRVBUFFER.
0089
0090 By default the driver writes one filemark when the device is closed after
0091 writing and the last operation has been a write. Two filemarks can be
0092 optionally written. In both cases end of data is signified by
0093 returning zero bytes for two consecutive reads.
0094
0095 Writing filemarks without the immediate bit set in the SCSI command block acts
0096 as a synchronization point, i.e., all remaining data form the drive buffers is
0097 written to tape before the command returns. This makes sure that write errors
0098 are caught at that point, but this takes time. In some applications, several
0099 consecutive files must be written fast. The MTWEOFI operation can be used to
0100 write the filemarks without flushing the drive buffer. Writing filemark at
0101 close() is always flushing the drive buffers. However, if the previous
0102 operation is MTWEOFI, close() does not write a filemark. This can be used if
0103 the program wants to close/open the tape device between files and wants to
0104 skip waiting.
0105
0106 If rewind, offline, bsf, or seek is done and previous tape operation was
0107 write, a filemark is written before moving tape.
0108
0109 The compile options are defined in the file linux/drivers/scsi/st_options.h.
0110
0111 4. If the open option O_NONBLOCK is used, open succeeds even if the
0112 drive is not ready. If O_NONBLOCK is not used, the driver waits for
0113 the drive to become ready. If this does not happen in ST_BLOCK_SECONDS
0114 seconds, open fails with the errno value EIO. With O_NONBLOCK the
0115 device can be opened for writing even if there is a write protected
0116 tape in the drive (commands trying to write something return error if
0117 attempted).
0118
0119
0120 Minor Numbers
0121 =============
0122
0123 The tape driver currently supports up to 2^17 drives if 4 modes for
0124 each drive are used.
0125
0126 The minor numbers consist of the following bit fields::
0127
0128 dev_upper non-rew mode dev-lower
0129 20 - 8 7 6 5 4 0
0130
0131 The non-rewind bit is always bit 7 (the uppermost bit in the lowermost
0132 byte). The bits defining the mode are below the non-rewind bit. The
0133 remaining bits define the tape device number. This numbering is
0134 backward compatible with the numbering used when the minor number was
0135 only 8 bits wide.
0136
0137
0138 Sysfs Support
0139 =============
0140
0141 The driver creates the directory /sys/class/scsi_tape and populates it with
0142 directories corresponding to the existing tape devices. There are autorewind
0143 and non-rewind entries for each mode. The names are stxy and nstxy, where x
0144 is the tape number and y a character corresponding to the mode (none, l, m,
0145 a). For example, the directories for the first tape device are (assuming four
0146 modes): st0 nst0 st0l nst0l st0m nst0m st0a nst0a.
0147
0148 Each directory contains the entries: default_blksize default_compression
0149 default_density defined dev device driver. The file 'defined' contains 1
0150 if the mode is defined and zero if not defined. The files 'default_*' contain
0151 the defaults set by the user. The value -1 means the default is not set. The
0152 file 'dev' contains the device numbers corresponding to this device. The links
0153 'device' and 'driver' point to the SCSI device and driver entries.
0154
0155 Each directory also contains the entry 'options' which shows the currently
0156 enabled driver and mode options. The value in the file is a bit mask where the
0157 bit definitions are the same as those used with MTSETDRVBUFFER in setting the
0158 options.
0159
0160 A link named 'tape' is made from the SCSI device directory to the class
0161 directory corresponding to the mode 0 auto-rewind device (e.g., st0).
0162
0163
0164 Sysfs and Statistics for Tape Devices
0165 =====================================
0166
0167 The st driver maintains statistics for tape drives inside the sysfs filesystem.
0168 The following method can be used to locate the statistics that are
0169 available (assuming that sysfs is mounted at /sys):
0170
0171 1. Use opendir(3) on the directory /sys/class/scsi_tape
0172 2. Use readdir(3) to read the directory contents
0173 3. Use regcomp(3)/regexec(3) to match directory entries to the extended
0174 regular expression "^st[0-9]+$"
0175 4. Access the statistics from the /sys/class/scsi_tape/<match>/stats
0176 directory (where <match> is a directory entry from /sys/class/scsi_tape
0177 that matched the extended regular expression)
0178
0179 The reason for using this approach is that all the character devices
0180 pointing to the same tape drive use the same statistics. That means
0181 that st0 would have the same statistics as nst0.
0182
0183 The directory contains the following statistics files:
0184
0185 1. in_flight
0186 - The number of I/Os currently outstanding to this device.
0187 2. io_ns
0188 - The amount of time spent waiting (in nanoseconds) for all I/O
0189 to complete (including read and write). This includes tape movement
0190 commands such as seeking between file or set marks and implicit tape
0191 movement such as when rewind on close tape devices are used.
0192 3. other_cnt
0193 - The number of I/Os issued to the tape drive other than read or
0194 write commands. The time taken to complete these commands uses the
0195 following calculation io_ms-read_ms-write_ms.
0196 4. read_byte_cnt
0197 - The number of bytes read from the tape drive.
0198 5. read_cnt
0199 - The number of read requests issued to the tape drive.
0200 6. read_ns
0201 - The amount of time (in nanoseconds) spent waiting for read
0202 requests to complete.
0203 7. write_byte_cnt
0204 - The number of bytes written to the tape drive.
0205 8. write_cnt
0206 - The number of write requests issued to the tape drive.
0207 9. write_ns
0208 - The amount of time (in nanoseconds) spent waiting for write
0209 requests to complete.
0210 10. resid_cnt
0211 - The number of times during a read or write we found
0212 the residual amount to be non-zero. This should mean that a program
0213 is issuing a read larger thean the block size on tape. For write
0214 not all data made it to tape.
0215
0216 .. Note::
0217
0218 The in_flight value is incremented when an I/O starts the I/O
0219 itself is not added to the statistics until it completes.
0220
0221 The total of read_cnt, write_cnt, and other_cnt may not total to the same
0222 value as iodone_cnt at the device level. The tape statistics only count
0223 I/O issued via the st module.
0224
0225 When read the statistics may not be temporally consistent while I/O is in
0226 progress. The individual values are read and written to atomically however
0227 when reading them back via sysfs they may be in the process of being
0228 updated when starting an I/O or when it is completed.
0229
0230 The value shown in in_flight is incremented before any statstics are
0231 updated and decremented when an I/O completes after updating statistics.
0232 The value of in_flight is 0 when there are no I/Os outstanding that are
0233 issued by the st driver. Tape statistics do not take into account any
0234 I/O performed via the sg device.
0235
0236 BSD and Sys V Semantics
0237 =======================
0238
0239 The user can choose between these two behaviours of the tape driver by
0240 defining the value of the symbol ST_SYSV. The semantics differ when a
0241 file being read is closed. The BSD semantics leaves the tape where it
0242 currently is whereas the SYS V semantics moves the tape past the next
0243 filemark unless the filemark has just been crossed.
0244
0245 The default is BSD semantics.
0246
0247
0248 Buffering
0249 =========
0250
0251 The driver tries to do transfers directly to/from user space. If this
0252 is not possible, a driver buffer allocated at run-time is used. If
0253 direct i/o is not possible for the whole transfer, the driver buffer
0254 is used (i.e., bounce buffers for individual pages are not
0255 used). Direct i/o can be impossible because of several reasons, e.g.:
0256
0257 - one or more pages are at addresses not reachable by the HBA
0258 - the number of pages in the transfer exceeds the number of
0259 scatter/gather segments permitted by the HBA
0260 - one or more pages can't be locked into memory (should not happen in
0261 any reasonable situation)
0262
0263 The size of the driver buffers is always at least one tape block. In fixed
0264 block mode, the minimum buffer size is defined (in 1024 byte units) by
0265 ST_FIXED_BUFFER_BLOCKS. With small block size this allows buffering of
0266 several blocks and using one SCSI read or write to transfer all of the
0267 blocks. Buffering of data across write calls in fixed block mode is
0268 allowed if ST_BUFFER_WRITES is non-zero and direct i/o is not used.
0269 Buffer allocation uses chunks of memory having sizes 2^n * (page
0270 size). Because of this the actual buffer size may be larger than the
0271 minimum allowable buffer size.
0272
0273 NOTE that if direct i/o is used, the small writes are not buffered. This may
0274 cause a surprise when moving from 2.4. There small writes (e.g., tar without
0275 -b option) may have had good throughput but this is not true any more with
0276 2.6. Direct i/o can be turned off to solve this problem but a better solution
0277 is to use bigger write() byte counts (e.g., tar -b 64).
0278
0279 Asynchronous writing. Writing the buffer contents to the tape is
0280 started and the write call returns immediately. The status is checked
0281 at the next tape operation. Asynchronous writes are not done with
0282 direct i/o and not in fixed block mode.
0283
0284 Buffered writes and asynchronous writes may in some rare cases cause
0285 problems in multivolume operations if there is not enough space on the
0286 tape after the early-warning mark to flush the driver buffer.
0287
0288 Read ahead for fixed block mode (ST_READ_AHEAD). Filling the buffer is
0289 attempted even if the user does not want to get all of the data at
0290 this read command. Should be disabled for those drives that don't like
0291 a filemark to truncate a read request or that don't like backspacing.
0292
0293 Scatter/gather buffers (buffers that consist of chunks non-contiguous
0294 in the physical memory) are used if contiguous buffers can't be
0295 allocated. To support all SCSI adapters (including those not
0296 supporting scatter/gather), buffer allocation is using the following
0297 three kinds of chunks:
0298
0299 1. The initial segment that is used for all SCSI adapters including
0300 those not supporting scatter/gather. The size of this buffer will be
0301 (PAGE_SIZE << ST_FIRST_ORDER) bytes if the system can give a chunk of
0302 this size (and it is not larger than the buffer size specified by
0303 ST_BUFFER_BLOCKS). If this size is not available, the driver halves
0304 the size and tries again until the size of one page. The default
0305 settings in st_options.h make the driver to try to allocate all of the
0306 buffer as one chunk.
0307 2. The scatter/gather segments to fill the specified buffer size are
0308 allocated so that as many segments as possible are used but the number
0309 of segments does not exceed ST_FIRST_SG.
0310 3. The remaining segments between ST_MAX_SG (or the module parameter
0311 max_sg_segs) and the number of segments used in phases 1 and 2
0312 are used to extend the buffer at run-time if this is necessary. The
0313 number of scatter/gather segments allowed for the SCSI adapter is not
0314 exceeded if it is smaller than the maximum number of scatter/gather
0315 segments specified. If the maximum number allowed for the SCSI adapter
0316 is smaller than the number of segments used in phases 1 and 2,
0317 extending the buffer will always fail.
0318
0319
0320 EOM Behaviour When Writing
0321 ==========================
0322
0323 When the end of medium early warning is encountered, the current write
0324 is finished and the number of bytes is returned. The next write
0325 returns -1 and errno is set to ENOSPC. To enable writing a trailer,
0326 the next write is allowed to proceed and, if successful, the number of
0327 bytes is returned. After this, -1 and the number of bytes are
0328 alternately returned until the physical end of medium (or some other
0329 error) is encountered.
0330
0331 Module Parameters
0332 =================
0333
0334 The buffer size, write threshold, and the maximum number of allocated buffers
0335 are configurable when the driver is loaded as a module. The keywords are:
0336
0337 ========================== ===========================================
0338 buffer_kbs=xxx the buffer size for fixed block mode is set
0339 to xxx kilobytes
0340 write_threshold_kbs=xxx the write threshold in kilobytes set to xxx
0341 max_sg_segs=xxx the maximum number of scatter/gather
0342 segments
0343 try_direct_io=x try direct transfer between user buffer and
0344 tape drive if this is non-zero
0345 ========================== ===========================================
0346
0347 Note that if the buffer size is changed but the write threshold is not
0348 set, the write threshold is set to the new buffer size - 2 kB.
0349
0350
0351 Boot Time Configuration
0352 =======================
0353
0354 If the driver is compiled into the kernel, the same parameters can be
0355 also set using, e.g., the LILO command line. The preferred syntax is
0356 to use the same keyword used when loading as module but prepended
0357 with 'st.'. For instance, to set the maximum number of scatter/gather
0358 segments, the parameter 'st.max_sg_segs=xx' should be used (xx is the
0359 number of scatter/gather segments).
0360
0361 For compatibility, the old syntax from early 2.5 and 2.4 kernel
0362 versions is supported. The same keywords can be used as when loading
0363 the driver as module. If several parameters are set, the keyword-value
0364 pairs are separated with a comma (no spaces allowed). A colon can be
0365 used instead of the equal mark. The definition is prepended by the
0366 string st=. Here is an example::
0367
0368 st=buffer_kbs:64,write_threshold_kbs:60
0369
0370 The following syntax used by the old kernel versions is also supported::
0371
0372 st=aa[,bb[,dd]]
0373
0374 where:
0375
0376 - aa is the buffer size for fixed block mode in 1024 byte units
0377 - bb is the write threshold in 1024 byte units
0378 - dd is the maximum number of scatter/gather segments
0379
0380
0381 IOCTLs
0382 ======
0383
0384 The tape is positioned and the drive parameters are set with ioctls
0385 defined in mtio.h The tape control program 'mt' uses these ioctls. Try
0386 to find an mt that supports all of the Linux SCSI tape ioctls and
0387 opens the device for writing if the tape contents will be modified
0388 (look for a package mt-st* from the Linux ftp sites; the GNU mt does
0389 not open for writing for, e.g., erase).
0390
0391 The supported ioctls are:
0392
0393 The following use the structure mtop:
0394
0395 MTFSF
0396 Space forward over count filemarks. Tape positioned after filemark.
0397 MTFSFM
0398 As above but tape positioned before filemark.
0399 MTBSF
0400 Space backward over count filemarks. Tape positioned before
0401 filemark.
0402 MTBSFM
0403 As above but ape positioned after filemark.
0404 MTFSR
0405 Space forward over count records.
0406 MTBSR
0407 Space backward over count records.
0408 MTFSS
0409 Space forward over count setmarks.
0410 MTBSS
0411 Space backward over count setmarks.
0412 MTWEOF
0413 Write count filemarks.
0414 MTWEOFI
0415 Write count filemarks with immediate bit set (i.e., does not
0416 wait until data is on tape)
0417 MTWSM
0418 Write count setmarks.
0419 MTREW
0420 Rewind tape.
0421 MTOFFL
0422 Set device off line (often rewind plus eject).
0423 MTNOP
0424 Do nothing except flush the buffers.
0425 MTRETEN
0426 Re-tension tape.
0427 MTEOM
0428 Space to end of recorded data.
0429 MTERASE
0430 Erase tape. If the argument is zero, the short erase command
0431 is used. The long erase command is used with all other values
0432 of the argument.
0433 MTSEEK
0434 Seek to tape block count. Uses Tandberg-compatible seek (QFA)
0435 for SCSI-1 drives and SCSI-2 seek for SCSI-2 drives. The file and
0436 block numbers in the status are not valid after a seek.
0437 MTSETBLK
0438 Set the drive block size. Setting to zero sets the drive into
0439 variable block mode (if applicable).
0440 MTSETDENSITY
0441 Sets the drive density code to arg. See drive
0442 documentation for available codes.
0443 MTLOCK and MTUNLOCK
0444 Explicitly lock/unlock the tape drive door.
0445 MTLOAD and MTUNLOAD
0446 Explicitly load and unload the tape. If the
0447 command argument x is between MT_ST_HPLOADER_OFFSET + 1 and
0448 MT_ST_HPLOADER_OFFSET + 6, the number x is used sent to the
0449 drive with the command and it selects the tape slot to use of
0450 HP C1553A changer.
0451 MTCOMPRESSION
0452 Sets compressing or uncompressing drive mode using the
0453 SCSI mode page 15. Note that some drives other methods for
0454 control of compression. Some drives (like the Exabytes) use
0455 density codes for compression control. Some drives use another
0456 mode page but this page has not been implemented in the
0457 driver. Some drives without compression capability will accept
0458 any compression mode without error.
0459 MTSETPART
0460 Moves the tape to the partition given by the argument at the
0461 next tape operation. The block at which the tape is positioned
0462 is the block where the tape was previously positioned in the
0463 new active partition unless the next tape operation is
0464 MTSEEK. In this case the tape is moved directly to the block
0465 specified by MTSEEK. MTSETPART is inactive unless
0466 MT_ST_CAN_PARTITIONS set.
0467 MTMKPART
0468 Formats the tape with one partition (argument zero) or two
0469 partitions (argument non-zero). If the argument is positive,
0470 it specifies the size of partition 1 in megabytes. For DDS
0471 drives and several early drives this is the physically first
0472 partition of the tape. If the argument is negative, its absolute
0473 value specifies the size of partition 0 in megabytes. This is
0474 the physically first partition of many later drives, like the
0475 LTO drives from LTO-5 upwards. The drive has to support partitions
0476 with size specified by the initiator. Inactive unless
0477 MT_ST_CAN_PARTITIONS set.
0478 MTSETDRVBUFFER
0479 Is used for several purposes. The command is obtained from count
0480 with mask MT_SET_OPTIONS, the low order bits are used as argument.
0481 This command is only allowed for the superuser (root). The
0482 subcommands are:
0483
0484 * 0
0485 The drive buffer option is set to the argument. Zero means
0486 no buffering.
0487 * MT_ST_BOOLEANS
0488 Sets the buffering options. The bits are the new states
0489 (enabled/disabled) the following options (in the
0490 parenthesis is specified whether the option is global or
0491 can be specified differently for each mode):
0492
0493 MT_ST_BUFFER_WRITES
0494 write buffering (mode)
0495 MT_ST_ASYNC_WRITES
0496 asynchronous writes (mode)
0497 MT_ST_READ_AHEAD
0498 read ahead (mode)
0499 MT_ST_TWO_FM
0500 writing of two filemarks (global)
0501 MT_ST_FAST_EOM
0502 using the SCSI spacing to EOD (global)
0503 MT_ST_AUTO_LOCK
0504 automatic locking of the drive door (global)
0505 MT_ST_DEF_WRITES
0506 the defaults are meant only for writes (mode)
0507 MT_ST_CAN_BSR
0508 backspacing over more than one records can
0509 be used for repositioning the tape (global)
0510 MT_ST_NO_BLKLIMS
0511 the driver does not ask the block limits
0512 from the drive (block size can be changed only to
0513 variable) (global)
0514 MT_ST_CAN_PARTITIONS
0515 enables support for partitioned
0516 tapes (global)
0517 MT_ST_SCSI2LOGICAL
0518 the logical block number is used in
0519 the MTSEEK and MTIOCPOS for SCSI-2 drives instead of
0520 the device dependent address. It is recommended to set
0521 this flag unless there are tapes using the device
0522 dependent (from the old times) (global)
0523 MT_ST_SYSV
0524 sets the SYSV semantics (mode)
0525 MT_ST_NOWAIT
0526 enables immediate mode (i.e., don't wait for
0527 the command to finish) for some commands (e.g., rewind)
0528 MT_ST_NOWAIT_EOF
0529 enables immediate filemark mode (i.e. when
0530 writing a filemark, don't wait for it to complete). Please
0531 see the BASICS note about MTWEOFI with respect to the
0532 possible dangers of writing immediate filemarks.
0533 MT_ST_SILI
0534 enables setting the SILI bit in SCSI commands when
0535 reading in variable block mode to enhance performance when
0536 reading blocks shorter than the byte count; set this only
0537 if you are sure that the drive supports SILI and the HBA
0538 correctly returns transfer residuals
0539 MT_ST_DEBUGGING
0540 debugging (global; debugging must be
0541 compiled into the driver)
0542
0543 * MT_ST_SETBOOLEANS, MT_ST_CLEARBOOLEANS
0544 Sets or clears the option bits.
0545 * MT_ST_WRITE_THRESHOLD
0546 Sets the write threshold for this device to kilobytes
0547 specified by the lowest bits.
0548 * MT_ST_DEF_BLKSIZE
0549 Defines the default block size set automatically. Value
0550 0xffffff means that the default is not used any more.
0551 * MT_ST_DEF_DENSITY, MT_ST_DEF_DRVBUFFER
0552 Used to set or clear the density (8 bits), and drive buffer
0553 state (3 bits). If the value is MT_ST_CLEAR_DEFAULT
0554 (0xfffff) the default will not be used any more. Otherwise
0555 the lowermost bits of the value contain the new value of
0556 the parameter.
0557 * MT_ST_DEF_COMPRESSION
0558 The compression default will not be used if the value of
0559 the lowermost byte is 0xff. Otherwise the lowermost bit
0560 contains the new default. If the bits 8-15 are set to a
0561 non-zero number, and this number is not 0xff, the number is
0562 used as the compression algorithm. The value
0563 MT_ST_CLEAR_DEFAULT can be used to clear the compression
0564 default.
0565 * MT_ST_SET_TIMEOUT
0566 Set the normal timeout in seconds for this device. The
0567 default is 900 seconds (15 minutes). The timeout should be
0568 long enough for the retries done by the device while
0569 reading/writing.
0570 * MT_ST_SET_LONG_TIMEOUT
0571 Set the long timeout that is used for operations that are
0572 known to take a long time. The default is 14000 seconds
0573 (3.9 hours). For erase this value is further multiplied by
0574 eight.
0575 * MT_ST_SET_CLN
0576 Set the cleaning request interpretation parameters using
0577 the lowest 24 bits of the argument. The driver can set the
0578 generic status bit GMT_CLN if a cleaning request bit pattern
0579 is found from the extended sense data. Many drives set one or
0580 more bits in the extended sense data when the drive needs
0581 cleaning. The bits are device-dependent. The driver is
0582 given the number of the sense data byte (the lowest eight
0583 bits of the argument; must be >= 18 (values 1 - 17
0584 reserved) and <= the maximum requested sense data sixe),
0585 a mask to select the relevant bits (the bits 9-16), and the
0586 bit pattern (bits 17-23). If the bit pattern is zero, one
0587 or more bits under the mask indicate cleaning request. If
0588 the pattern is non-zero, the pattern must match the masked
0589 sense data byte.
0590
0591 (The cleaning bit is set if the additional sense code and
0592 qualifier 00h 17h are seen regardless of the setting of
0593 MT_ST_SET_CLN.)
0594
0595 The following ioctl uses the structure mtpos:
0596
0597 MTIOCPOS
0598 Reads the current position from the drive. Uses
0599 Tandberg-compatible QFA for SCSI-1 drives and the SCSI-2
0600 command for the SCSI-2 drives.
0601
0602 The following ioctl uses the structure mtget to return the status:
0603
0604 MTIOCGET
0605 Returns some status information.
0606 The file number and block number within file are returned. The
0607 block is -1 when it can't be determined (e.g., after MTBSF).
0608 The drive type is either MTISSCSI1 or MTISSCSI2.
0609 The number of recovered errors since the previous status call
0610 is stored in the lower word of the field mt_erreg.
0611 The current block size and the density code are stored in the field
0612 mt_dsreg (shifts for the subfields are MT_ST_BLKSIZE_SHIFT and
0613 MT_ST_DENSITY_SHIFT).
0614 The GMT_xxx status bits reflect the drive status. GMT_DR_OPEN
0615 is set if there is no tape in the drive. GMT_EOD means either
0616 end of recorded data or end of tape. GMT_EOT means end of tape.
0617
0618
0619 Miscellaneous Compile Options
0620 =============================
0621
0622 The recovered write errors are considered fatal if ST_RECOVERED_WRITE_FATAL
0623 is defined.
0624
0625 The maximum number of tape devices is determined by the define
0626 ST_MAX_TAPES. If more tapes are detected at driver initialization, the
0627 maximum is adjusted accordingly.
0628
0629 Immediate return from tape positioning SCSI commands can be enabled by
0630 defining ST_NOWAIT. If this is defined, the user should take care that
0631 the next tape operation is not started before the previous one has
0632 finished. The drives and SCSI adapters should handle this condition
0633 gracefully, but some drive/adapter combinations are known to hang the
0634 SCSI bus in this case.
0635
0636 The MTEOM command is by default implemented as spacing over 32767
0637 filemarks. With this method the file number in the status is
0638 correct. The user can request using direct spacing to EOD by setting
0639 ST_FAST_EOM 1 (or using the MT_ST_OPTIONS ioctl). In this case the file
0640 number will be invalid.
0641
0642 When using read ahead or buffered writes the position within the file
0643 may not be correct after the file is closed (correct position may
0644 require backspacing over more than one record). The correct position
0645 within file can be obtained if ST_IN_FILE_POS is defined at compile
0646 time or the MT_ST_CAN_BSR bit is set for the drive with an ioctl.
0647 (The driver always backs over a filemark crossed by read ahead if the
0648 user does not request data that far.)
0649
0650
0651 Debugging Hints
0652 ===============
0653
0654 Debugging code is now compiled in by default but debugging is turned off
0655 with the kernel module parameter debug_flag defaulting to 0. Debugging
0656 can still be switched on and off with an ioctl. To enable debug at
0657 module load time add debug_flag=1 to the module load options, the
0658 debugging output is not voluminous. Debugging can also be enabled
0659 and disabled by writing a '0' (disable) or '1' (enable) to the sysfs
0660 file /sys/bus/scsi/drivers/st/debug_flag.
0661
0662 If the tape seems to hang, I would be very interested to hear where
0663 the driver is waiting. With the command 'ps -l' you can see the state
0664 of the process using the tape. If the state is D, the process is
0665 waiting for something. The field WCHAN tells where the driver is
0666 waiting. If you have the current System.map in the correct place (in
0667 /boot for the procps I use) or have updated /etc/psdatabase (for kmem
0668 ps), ps writes the function name in the WCHAN field. If not, you have
0669 to look up the function from System.map.
0670
0671 Note also that the timeouts are very long compared to most other
0672 drivers. This means that the Linux driver may appear hung although the
0673 real reason is that the tape firmware has got confused.