st.rst 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ====================
  3. The SCSI Tape Driver
  4. ====================
  5. This file contains brief information about the SCSI tape driver.
  6. The driver is currently maintained by Kai Mäkisara (email
  7. Kai.Makisara@kolumbus.fi)
  8. Last modified: Tue Feb 9 21:54:16 2016 by kai.makisara
  9. Basics
  10. ======
  11. The driver is generic, i.e., it does not contain any code tailored
  12. to any specific tape drive. The tape parameters can be specified with
  13. one of the following three methods:
  14. 1. Each user can specify the tape parameters he/she wants to use
  15. directly with ioctls. This is administratively a very simple and
  16. flexible method and applicable to single-user workstations. However,
  17. in a multiuser environment the next user finds the tape parameters in
  18. state the previous user left them.
  19. 2. The system manager (root) can define default values for some tape
  20. parameters, like block size and density using the MTSETDRVBUFFER ioctl.
  21. These parameters can be programmed to come into effect either when a
  22. new tape is loaded into the drive or if writing begins at the
  23. beginning of the tape. The second method is applicable if the tape
  24. drive performs auto-detection of the tape format well (like some
  25. QIC-drives). The result is that any tape can be read, writing can be
  26. continued using existing format, and the default format is used if
  27. the tape is rewritten from the beginning (or a new tape is written
  28. for the first time). The first method is applicable if the drive
  29. does not perform auto-detection well enough and there is a single
  30. "sensible" mode for the device. An example is a DAT drive that is
  31. used only in variable block mode (I don't know if this is sensible
  32. or not :-).
  33. The user can override the parameters defined by the system
  34. manager. The changes persist until the defaults again come into
  35. effect.
  36. 3. By default, up to four modes can be defined and selected using the minor
  37. number (bits 5 and 6). The number of modes can be changed by changing
  38. ST_NBR_MODE_BITS in st.h. Mode 0 corresponds to the defaults discussed
  39. above. Additional modes are dormant until they are defined by the
  40. system manager (root). When specification of a new mode is started,
  41. the configuration of mode 0 is used to provide a starting point for
  42. definition of the new mode.
  43. Using the modes allows the system manager to give the users choices
  44. over some of the buffering parameters not directly accessible to the
  45. users (buffered and asynchronous writes). The modes also allow choices
  46. between formats in multi-tape operations (the explicitly overridden
  47. parameters are reset when a new tape is loaded).
  48. If more than one mode is used, all modes should contain definitions
  49. for the same set of parameters.
  50. Many Unices contain internal tables that associate different modes to
  51. supported devices. The Linux SCSI tape driver does not contain such
  52. tables (and will not do that in future). Instead of that, a utility
  53. program can be made that fetches the inquiry data sent by the device,
  54. scans its database, and sets up the modes using the ioctls. Another
  55. alternative is to make a small script that uses mt to set the defaults
  56. tailored to the system.
  57. The driver supports fixed and variable block size (within buffer
  58. limits). Both the auto-rewind (minor equals device number) and
  59. non-rewind devices (minor is 128 + device number) are implemented.
  60. In variable block mode, the byte count in write() determines the size
  61. of the physical block on tape. When reading, the drive reads the next
  62. tape block and returns to the user the data if the read() byte count
  63. is at least the block size. Otherwise, error ENOMEM is returned.
  64. In fixed block mode, the data transfer between the drive and the
  65. driver is in multiples of the block size. The write() byte count must
  66. be a multiple of the block size. This is not required when reading but
  67. may be advisable for portability.
  68. Support is provided for changing the tape partition and partitioning
  69. of the tape with one or two partitions. By default support for
  70. partitioned tape is disabled for each driver and it can be enabled
  71. with the ioctl MTSETDRVBUFFER.
  72. By default the driver writes one filemark when the device is closed after
  73. writing and the last operation has been a write. Two filemarks can be
  74. optionally written. In both cases end of data is signified by
  75. returning zero bytes for two consecutive reads.
  76. Writing filemarks without the immediate bit set in the SCSI command block acts
  77. as a synchronization point, i.e., all remaining data form the drive buffers is
  78. written to tape before the command returns. This makes sure that write errors
  79. are caught at that point, but this takes time. In some applications, several
  80. consecutive files must be written fast. The MTWEOFI operation can be used to
  81. write the filemarks without flushing the drive buffer. Writing filemark at
  82. close() is always flushing the drive buffers. However, if the previous
  83. operation is MTWEOFI, close() does not write a filemark. This can be used if
  84. the program wants to close/open the tape device between files and wants to
  85. skip waiting.
  86. If rewind, offline, bsf, or seek is done and previous tape operation was
  87. write, a filemark is written before moving tape.
  88. The compile options are defined in the file linux/drivers/scsi/st_options.h.
  89. 4. If the open option O_NONBLOCK is used, open succeeds even if the
  90. drive is not ready. If O_NONBLOCK is not used, the driver waits for
  91. the drive to become ready. If this does not happen in ST_BLOCK_SECONDS
  92. seconds, open fails with the errno value EIO. With O_NONBLOCK the
  93. device can be opened for writing even if there is a write protected
  94. tape in the drive (commands trying to write something return error if
  95. attempted).
  96. Minor Numbers
  97. =============
  98. The tape driver currently supports up to 2^17 drives if 4 modes for
  99. each drive are used.
  100. The minor numbers consist of the following bit fields::
  101. dev_upper non-rew mode dev-lower
  102. 20 - 8 7 6 5 4 0
  103. The non-rewind bit is always bit 7 (the uppermost bit in the lowermost
  104. byte). The bits defining the mode are below the non-rewind bit. The
  105. remaining bits define the tape device number. This numbering is
  106. backward compatible with the numbering used when the minor number was
  107. only 8 bits wide.
  108. Sysfs Support
  109. =============
  110. The driver creates the directory /sys/class/scsi_tape and populates it with
  111. directories corresponding to the existing tape devices. There are autorewind
  112. and non-rewind entries for each mode. The names are stxy and nstxy, where x
  113. is the tape number and y a character corresponding to the mode (none, l, m,
  114. a). For example, the directories for the first tape device are (assuming four
  115. modes): st0 nst0 st0l nst0l st0m nst0m st0a nst0a.
  116. Each directory contains the entries: default_blksize default_compression
  117. default_density defined dev device driver. The file 'defined' contains 1
  118. if the mode is defined and zero if not defined. The files 'default_*' contain
  119. the defaults set by the user. The value -1 means the default is not set. The
  120. file 'dev' contains the device numbers corresponding to this device. The links
  121. 'device' and 'driver' point to the SCSI device and driver entries.
  122. Each directory also contains the entry 'options' which shows the currently
  123. enabled driver and mode options. The value in the file is a bit mask where the
  124. bit definitions are the same as those used with MTSETDRVBUFFER in setting the
  125. options.
  126. Each directory contains the entry 'position_lost_in_reset'. If this value is
  127. one, reading and writing to the device is blocked after device reset. Most
  128. devices rewind the tape after reset and the writes/read don't access the
  129. tape position the user expects.
  130. A link named 'tape' is made from the SCSI device directory to the class
  131. directory corresponding to the mode 0 auto-rewind device (e.g., st0).
  132. Sysfs and Statistics for Tape Devices
  133. =====================================
  134. The st driver maintains statistics for tape drives inside the sysfs filesystem.
  135. The following method can be used to locate the statistics that are
  136. available (assuming that sysfs is mounted at /sys):
  137. 1. Use opendir(3) on the directory /sys/class/scsi_tape
  138. 2. Use readdir(3) to read the directory contents
  139. 3. Use regcomp(3)/regexec(3) to match directory entries to the extended
  140. regular expression "^st[0-9]+$"
  141. 4. Access the statistics from the /sys/class/scsi_tape/<match>/stats
  142. directory (where <match> is a directory entry from /sys/class/scsi_tape
  143. that matched the extended regular expression)
  144. The reason for using this approach is that all the character devices
  145. pointing to the same tape drive use the same statistics. That means
  146. that st0 would have the same statistics as nst0.
  147. The directory contains the following statistics files:
  148. 1. in_flight
  149. - The number of I/Os currently outstanding to this device.
  150. 2. io_ns
  151. - The amount of time spent waiting (in nanoseconds) for all I/O
  152. to complete (including read and write). This includes tape movement
  153. commands such as seeking between file or set marks and implicit tape
  154. movement such as when rewind on close tape devices are used.
  155. 3. other_cnt
  156. - The number of I/Os issued to the tape drive other than read or
  157. write commands. The time taken to complete these commands uses the
  158. following calculation io_ms-read_ms-write_ms.
  159. 4. read_byte_cnt
  160. - The number of bytes read from the tape drive.
  161. 5. read_cnt
  162. - The number of read requests issued to the tape drive.
  163. 6. read_ns
  164. - The amount of time (in nanoseconds) spent waiting for read
  165. requests to complete.
  166. 7. write_byte_cnt
  167. - The number of bytes written to the tape drive.
  168. 8. write_cnt
  169. - The number of write requests issued to the tape drive.
  170. 9. write_ns
  171. - The amount of time (in nanoseconds) spent waiting for write
  172. requests to complete.
  173. 10. resid_cnt
  174. - The number of times during a read or write we found
  175. the residual amount to be non-zero. This should mean that a program
  176. is issuing a read larger thean the block size on tape. For write
  177. not all data made it to tape.
  178. .. Note::
  179. The in_flight value is incremented when an I/O starts the I/O
  180. itself is not added to the statistics until it completes.
  181. The total of read_cnt, write_cnt, and other_cnt may not total to the same
  182. value as iodone_cnt at the device level. The tape statistics only count
  183. I/O issued via the st module.
  184. When read the statistics may not be temporally consistent while I/O is in
  185. progress. The individual values are read and written to atomically however
  186. when reading them back via sysfs they may be in the process of being
  187. updated when starting an I/O or when it is completed.
  188. The value shown in in_flight is incremented before any statstics are
  189. updated and decremented when an I/O completes after updating statistics.
  190. The value of in_flight is 0 when there are no I/Os outstanding that are
  191. issued by the st driver. Tape statistics do not take into account any
  192. I/O performed via the sg device.
  193. BSD and Sys V Semantics
  194. =======================
  195. The user can choose between these two behaviours of the tape driver by
  196. defining the value of the symbol ST_SYSV. The semantics differ when a
  197. file being read is closed. The BSD semantics leaves the tape where it
  198. currently is whereas the SYS V semantics moves the tape past the next
  199. filemark unless the filemark has just been crossed.
  200. The default is BSD semantics.
  201. Buffering
  202. =========
  203. The driver tries to do transfers directly to/from user space. If this
  204. is not possible, a driver buffer allocated at run-time is used. If
  205. direct i/o is not possible for the whole transfer, the driver buffer
  206. is used (i.e., bounce buffers for individual pages are not
  207. used). Direct i/o can be impossible because of several reasons, e.g.:
  208. - one or more pages are at addresses not reachable by the HBA
  209. - the number of pages in the transfer exceeds the number of
  210. scatter/gather segments permitted by the HBA
  211. - one or more pages can't be locked into memory (should not happen in
  212. any reasonable situation)
  213. The size of the driver buffers is always at least one tape block. In fixed
  214. block mode, the minimum buffer size is defined (in 1024 byte units) by
  215. ST_FIXED_BUFFER_BLOCKS. With small block size this allows buffering of
  216. several blocks and using one SCSI read or write to transfer all of the
  217. blocks. Buffering of data across write calls in fixed block mode is
  218. allowed if ST_BUFFER_WRITES is non-zero and direct i/o is not used.
  219. Buffer allocation uses chunks of memory having sizes 2^n * (page
  220. size). Because of this the actual buffer size may be larger than the
  221. minimum allowable buffer size.
  222. NOTE that if direct i/o is used, the small writes are not buffered. This may
  223. cause a surprise when moving from 2.4. There small writes (e.g., tar without
  224. -b option) may have had good throughput but this is not true any more with
  225. 2.6. Direct i/o can be turned off to solve this problem but a better solution
  226. is to use bigger write() byte counts (e.g., tar -b 64).
  227. Asynchronous writing. Writing the buffer contents to the tape is
  228. started and the write call returns immediately. The status is checked
  229. at the next tape operation. Asynchronous writes are not done with
  230. direct i/o and not in fixed block mode.
  231. Buffered writes and asynchronous writes may in some rare cases cause
  232. problems in multivolume operations if there is not enough space on the
  233. tape after the early-warning mark to flush the driver buffer.
  234. Read ahead for fixed block mode (ST_READ_AHEAD). Filling the buffer is
  235. attempted even if the user does not want to get all of the data at
  236. this read command. Should be disabled for those drives that don't like
  237. a filemark to truncate a read request or that don't like backspacing.
  238. Scatter/gather buffers (buffers that consist of chunks non-contiguous
  239. in the physical memory) are used if contiguous buffers can't be
  240. allocated. To support all SCSI adapters (including those not
  241. supporting scatter/gather), buffer allocation is using the following
  242. three kinds of chunks:
  243. 1. The initial segment that is used for all SCSI adapters including
  244. those not supporting scatter/gather. The size of this buffer will be
  245. (PAGE_SIZE << ST_FIRST_ORDER) bytes if the system can give a chunk of
  246. this size (and it is not larger than the buffer size specified by
  247. ST_BUFFER_BLOCKS). If this size is not available, the driver halves
  248. the size and tries again until the size of one page. The default
  249. settings in st_options.h make the driver to try to allocate all of the
  250. buffer as one chunk.
  251. 2. The scatter/gather segments to fill the specified buffer size are
  252. allocated so that as many segments as possible are used but the number
  253. of segments does not exceed ST_FIRST_SG.
  254. 3. The remaining segments between ST_MAX_SG (or the module parameter
  255. max_sg_segs) and the number of segments used in phases 1 and 2
  256. are used to extend the buffer at run-time if this is necessary. The
  257. number of scatter/gather segments allowed for the SCSI adapter is not
  258. exceeded if it is smaller than the maximum number of scatter/gather
  259. segments specified. If the maximum number allowed for the SCSI adapter
  260. is smaller than the number of segments used in phases 1 and 2,
  261. extending the buffer will always fail.
  262. EOM Behaviour When Writing
  263. ==========================
  264. When the end of medium early warning is encountered, the current write
  265. is finished and the number of bytes is returned. The next write
  266. returns -1 and errno is set to ENOSPC. To enable writing a trailer,
  267. the next write is allowed to proceed and, if successful, the number of
  268. bytes is returned. After this, -1 and the number of bytes are
  269. alternately returned until the physical end of medium (or some other
  270. error) is encountered.
  271. Module Parameters
  272. =================
  273. The buffer size, write threshold, and the maximum number of allocated buffers
  274. are configurable when the driver is loaded as a module. The keywords are:
  275. ========================== ===========================================
  276. buffer_kbs=xxx the buffer size for fixed block mode is set
  277. to xxx kilobytes
  278. write_threshold_kbs=xxx the write threshold in kilobytes set to xxx
  279. max_sg_segs=xxx the maximum number of scatter/gather
  280. segments
  281. try_direct_io=x try direct transfer between user buffer and
  282. tape drive if this is non-zero
  283. ========================== ===========================================
  284. Note that if the buffer size is changed but the write threshold is not
  285. set, the write threshold is set to the new buffer size - 2 kB.
  286. Boot Time Configuration
  287. =======================
  288. If the driver is compiled into the kernel, the same parameters can be
  289. also set using, e.g., the LILO command line. The preferred syntax is
  290. to use the same keyword used when loading as module but prepended
  291. with 'st.'. For instance, to set the maximum number of scatter/gather
  292. segments, the parameter 'st.max_sg_segs=xx' should be used (xx is the
  293. number of scatter/gather segments).
  294. For compatibility, the old syntax from early 2.5 and 2.4 kernel
  295. versions is supported. The same keywords can be used as when loading
  296. the driver as module. If several parameters are set, the keyword-value
  297. pairs are separated with a comma (no spaces allowed). A colon can be
  298. used instead of the equal mark. The definition is prepended by the
  299. string st=. Here is an example::
  300. st=buffer_kbs:64,write_threshold_kbs:60
  301. The following syntax used by the old kernel versions is also supported::
  302. st=aa[,bb[,dd]]
  303. where:
  304. - aa is the buffer size for fixed block mode in 1024 byte units
  305. - bb is the write threshold in 1024 byte units
  306. - dd is the maximum number of scatter/gather segments
  307. IOCTLs
  308. ======
  309. The tape is positioned and the drive parameters are set with ioctls
  310. defined in mtio.h The tape control program 'mt' uses these ioctls. Try
  311. to find an mt that supports all of the Linux SCSI tape ioctls and
  312. opens the device for writing if the tape contents will be modified
  313. (look for a package mt-st* from the Linux ftp sites; the GNU mt does
  314. not open for writing for, e.g., erase).
  315. The supported ioctls are:
  316. The following use the structure mtop:
  317. MTFSF
  318. Space forward over count filemarks. Tape positioned after filemark.
  319. MTFSFM
  320. As above but tape positioned before filemark.
  321. MTBSF
  322. Space backward over count filemarks. Tape positioned before
  323. filemark.
  324. MTBSFM
  325. As above but ape positioned after filemark.
  326. MTFSR
  327. Space forward over count records.
  328. MTBSR
  329. Space backward over count records.
  330. MTFSS
  331. Space forward over count setmarks.
  332. MTBSS
  333. Space backward over count setmarks.
  334. MTWEOF
  335. Write count filemarks.
  336. MTWEOFI
  337. Write count filemarks with immediate bit set (i.e., does not
  338. wait until data is on tape)
  339. MTWSM
  340. Write count setmarks.
  341. MTREW
  342. Rewind tape.
  343. MTOFFL
  344. Set device off line (often rewind plus eject).
  345. MTNOP
  346. Do nothing except flush the buffers.
  347. MTRETEN
  348. Re-tension tape.
  349. MTEOM
  350. Space to end of recorded data.
  351. MTERASE
  352. Erase tape. If the argument is zero, the short erase command
  353. is used. The long erase command is used with all other values
  354. of the argument.
  355. MTSEEK
  356. Seek to tape block count. Uses Tandberg-compatible seek (QFA)
  357. for SCSI-1 drives and SCSI-2 seek for SCSI-2 drives. The file and
  358. block numbers in the status are not valid after a seek.
  359. MTSETBLK
  360. Set the drive block size. Setting to zero sets the drive into
  361. variable block mode (if applicable).
  362. MTSETDENSITY
  363. Sets the drive density code to arg. See drive
  364. documentation for available codes.
  365. MTLOCK and MTUNLOCK
  366. Explicitly lock/unlock the tape drive door.
  367. MTLOAD and MTUNLOAD
  368. Explicitly load and unload the tape. If the
  369. command argument x is between MT_ST_HPLOADER_OFFSET + 1 and
  370. MT_ST_HPLOADER_OFFSET + 6, the number x is used sent to the
  371. drive with the command and it selects the tape slot to use of
  372. HP C1553A changer.
  373. MTCOMPRESSION
  374. Sets compressing or uncompressing drive mode using the
  375. SCSI mode page 15. Note that some drives other methods for
  376. control of compression. Some drives (like the Exabytes) use
  377. density codes for compression control. Some drives use another
  378. mode page but this page has not been implemented in the
  379. driver. Some drives without compression capability will accept
  380. any compression mode without error.
  381. MTSETPART
  382. Moves the tape to the partition given by the argument at the
  383. next tape operation. The block at which the tape is positioned
  384. is the block where the tape was previously positioned in the
  385. new active partition unless the next tape operation is
  386. MTSEEK. In this case the tape is moved directly to the block
  387. specified by MTSEEK. MTSETPART is inactive unless
  388. MT_ST_CAN_PARTITIONS set.
  389. MTMKPART
  390. Formats the tape with one partition (argument zero) or two
  391. partitions (argument non-zero). If the argument is positive,
  392. it specifies the size of partition 1 in megabytes. For DDS
  393. drives and several early drives this is the physically first
  394. partition of the tape. If the argument is negative, its absolute
  395. value specifies the size of partition 0 in megabytes. This is
  396. the physically first partition of many later drives, like the
  397. LTO drives from LTO-5 upwards. The drive has to support partitions
  398. with size specified by the initiator. Inactive unless
  399. MT_ST_CAN_PARTITIONS set.
  400. MTSETDRVBUFFER
  401. Is used for several purposes. The command is obtained from count
  402. with mask MT_SET_OPTIONS, the low order bits are used as argument.
  403. This command is only allowed for the superuser (root). The
  404. subcommands are:
  405. * 0
  406. The drive buffer option is set to the argument. Zero means
  407. no buffering.
  408. * MT_ST_BOOLEANS
  409. Sets the buffering options. The bits are the new states
  410. (enabled/disabled) the following options (in the
  411. parenthesis is specified whether the option is global or
  412. can be specified differently for each mode):
  413. MT_ST_BUFFER_WRITES
  414. write buffering (mode)
  415. MT_ST_ASYNC_WRITES
  416. asynchronous writes (mode)
  417. MT_ST_READ_AHEAD
  418. read ahead (mode)
  419. MT_ST_TWO_FM
  420. writing of two filemarks (global)
  421. MT_ST_FAST_EOM
  422. using the SCSI spacing to EOD (global)
  423. MT_ST_AUTO_LOCK
  424. automatic locking of the drive door (global)
  425. MT_ST_DEF_WRITES
  426. the defaults are meant only for writes (mode)
  427. MT_ST_CAN_BSR
  428. backspacing over more than one records can
  429. be used for repositioning the tape (global)
  430. MT_ST_NO_BLKLIMS
  431. the driver does not ask the block limits
  432. from the drive (block size can be changed only to
  433. variable) (global)
  434. MT_ST_CAN_PARTITIONS
  435. enables support for partitioned
  436. tapes (global)
  437. MT_ST_SCSI2LOGICAL
  438. the logical block number is used in
  439. the MTSEEK and MTIOCPOS for SCSI-2 drives instead of
  440. the device dependent address. It is recommended to set
  441. this flag unless there are tapes using the device
  442. dependent (from the old times) (global)
  443. MT_ST_SYSV
  444. sets the SYSV semantics (mode)
  445. MT_ST_NOWAIT
  446. enables immediate mode (i.e., don't wait for
  447. the command to finish) for some commands (e.g., rewind)
  448. MT_ST_NOWAIT_EOF
  449. enables immediate filemark mode (i.e. when
  450. writing a filemark, don't wait for it to complete). Please
  451. see the BASICS note about MTWEOFI with respect to the
  452. possible dangers of writing immediate filemarks.
  453. MT_ST_SILI
  454. enables setting the SILI bit in SCSI commands when
  455. reading in variable block mode to enhance performance when
  456. reading blocks shorter than the byte count; set this only
  457. if you are sure that the drive supports SILI and the HBA
  458. correctly returns transfer residuals
  459. MT_ST_DEBUGGING
  460. debugging (global; debugging must be
  461. compiled into the driver)
  462. * MT_ST_SETBOOLEANS, MT_ST_CLEARBOOLEANS
  463. Sets or clears the option bits.
  464. * MT_ST_WRITE_THRESHOLD
  465. Sets the write threshold for this device to kilobytes
  466. specified by the lowest bits.
  467. * MT_ST_DEF_BLKSIZE
  468. Defines the default block size set automatically. Value
  469. 0xffffff means that the default is not used any more.
  470. * MT_ST_DEF_DENSITY, MT_ST_DEF_DRVBUFFER
  471. Used to set or clear the density (8 bits), and drive buffer
  472. state (3 bits). If the value is MT_ST_CLEAR_DEFAULT
  473. (0xfffff) the default will not be used any more. Otherwise
  474. the lowermost bits of the value contain the new value of
  475. the parameter.
  476. * MT_ST_DEF_COMPRESSION
  477. The compression default will not be used if the value of
  478. the lowermost byte is 0xff. Otherwise the lowermost bit
  479. contains the new default. If the bits 8-15 are set to a
  480. non-zero number, and this number is not 0xff, the number is
  481. used as the compression algorithm. The value
  482. MT_ST_CLEAR_DEFAULT can be used to clear the compression
  483. default.
  484. * MT_ST_SET_TIMEOUT
  485. Set the normal timeout in seconds for this device. The
  486. default is 900 seconds (15 minutes). The timeout should be
  487. long enough for the retries done by the device while
  488. reading/writing.
  489. * MT_ST_SET_LONG_TIMEOUT
  490. Set the long timeout that is used for operations that are
  491. known to take a long time. The default is 14000 seconds
  492. (3.9 hours). For erase this value is further multiplied by
  493. eight.
  494. * MT_ST_SET_CLN
  495. Set the cleaning request interpretation parameters using
  496. the lowest 24 bits of the argument. The driver can set the
  497. generic status bit GMT_CLN if a cleaning request bit pattern
  498. is found from the extended sense data. Many drives set one or
  499. more bits in the extended sense data when the drive needs
  500. cleaning. The bits are device-dependent. The driver is
  501. given the number of the sense data byte (the lowest eight
  502. bits of the argument; must be >= 18 (values 1 - 17
  503. reserved) and <= the maximum requested sense data sixe),
  504. a mask to select the relevant bits (the bits 9-16), and the
  505. bit pattern (bits 17-23). If the bit pattern is zero, one
  506. or more bits under the mask indicate cleaning request. If
  507. the pattern is non-zero, the pattern must match the masked
  508. sense data byte.
  509. (The cleaning bit is set if the additional sense code and
  510. qualifier 00h 17h are seen regardless of the setting of
  511. MT_ST_SET_CLN.)
  512. The following ioctl uses the structure mtpos:
  513. MTIOCPOS
  514. Reads the current position from the drive. Uses
  515. Tandberg-compatible QFA for SCSI-1 drives and the SCSI-2
  516. command for the SCSI-2 drives.
  517. The following ioctl uses the structure mtget to return the status:
  518. MTIOCGET
  519. Returns some status information.
  520. The file number and block number within file are returned. The
  521. block is -1 when it can't be determined (e.g., after MTBSF).
  522. The drive type is either MTISSCSI1 or MTISSCSI2.
  523. The number of recovered errors since the previous status call
  524. is stored in the lower word of the field mt_erreg.
  525. The current block size and the density code are stored in the field
  526. mt_dsreg (shifts for the subfields are MT_ST_BLKSIZE_SHIFT and
  527. MT_ST_DENSITY_SHIFT).
  528. The GMT_xxx status bits reflect the drive status. GMT_DR_OPEN
  529. is set if there is no tape in the drive. GMT_EOD means either
  530. end of recorded data or end of tape. GMT_EOT means end of tape.
  531. Miscellaneous Compile Options
  532. =============================
  533. The recovered write errors are considered fatal if ST_RECOVERED_WRITE_FATAL
  534. is defined.
  535. The maximum number of tape devices is determined by the define
  536. ST_MAX_TAPES. If more tapes are detected at driver initialization, the
  537. maximum is adjusted accordingly.
  538. Immediate return from tape positioning SCSI commands can be enabled by
  539. defining ST_NOWAIT. If this is defined, the user should take care that
  540. the next tape operation is not started before the previous one has
  541. finished. The drives and SCSI adapters should handle this condition
  542. gracefully, but some drive/adapter combinations are known to hang the
  543. SCSI bus in this case.
  544. The MTEOM command is by default implemented as spacing over 32767
  545. filemarks. With this method the file number in the status is
  546. correct. The user can request using direct spacing to EOD by setting
  547. ST_FAST_EOM 1 (or using the MT_ST_OPTIONS ioctl). In this case the file
  548. number will be invalid.
  549. When using read ahead or buffered writes the position within the file
  550. may not be correct after the file is closed (correct position may
  551. require backspacing over more than one record). The correct position
  552. within file can be obtained if ST_IN_FILE_POS is defined at compile
  553. time or the MT_ST_CAN_BSR bit is set for the drive with an ioctl.
  554. (The driver always backs over a filemark crossed by read ahead if the
  555. user does not request data that far.)
  556. Debugging Hints
  557. ===============
  558. Debugging code is now compiled in by default but debugging is turned off
  559. with the kernel module parameter debug_flag defaulting to 0. Debugging
  560. can still be switched on and off with an ioctl. To enable debug at
  561. module load time add debug_flag=1 to the module load options, the
  562. debugging output is not voluminous. Debugging can also be enabled
  563. and disabled by writing a '0' (disable) or '1' (enable) to the sysfs
  564. file /sys/bus/scsi/drivers/st/debug_flag.
  565. If the tape seems to hang, I would be very interested to hear where
  566. the driver is waiting. With the command 'ps -l' you can see the state
  567. of the process using the tape. If the state is D, the process is
  568. waiting for something. The field WCHAN tells where the driver is
  569. waiting. If you have the current System.map in the correct place (in
  570. /boot for the procps I use) or have updated /etc/psdatabase (for kmem
  571. ps), ps writes the function name in the WCHAN field. If not, you have
  572. to look up the function from System.map.
  573. Note also that the timeouts are very long compared to most other
  574. drivers. This means that the Linux driver may appear hung although the
  575. real reason is that the tape firmware has got confused.