1 Generic SCSI target mid-level for Linux (SCST)
2 ==============================================
4 Version 0.9.5, XX XXX 2006
5 --------------------------
7 SCST is designed to provide unified, consistent interface between SCSI
8 target drivers and Linux kernel and simplify target drivers development
9 as much as possible. Detail description of SCST's features and internals
10 could be found in "Generic SCSI Target Middle Level for Linux" document
11 SCST's Internet page http://scst.sourceforge.net.
13 SCST looks to be quite stable (for beta) and useful. It supports disks
14 (SCSI type 0), tapes (type 1), processor (type 3), CDROM's (type 5), MO
15 disks (type 7), medium changers (type 8) and RAID controller (type 0xC)
16 as well as FILEIO and "performance" device handlers. In addition, it
17 supports advanced per-initiator access and devices visibility
18 management, so different initiators could see different set of devices
19 with different access permissions. See below for details.
21 This is quite stable (but still beta) version.
23 Tested mostly on "vanilla" 2.6.17.8 kernel from kernel.org.
28 At first, make sure that the link "/lib/modules/`you_kernel_version`/build"
29 points to the source code for your currently running kernel.
31 Then, since in the mainstream kernels scsi_do_req()/scsi_execute_async()
32 work in LIFO order, instead of expected and required FIFO, SCST needs a
33 new functions scsi_do_req_fifo()/scsi_execute_async_fifo() to be added
34 in the kernel. Patch 26_scst-2.6.X.patch from "kernel" directory does
35 that. If it doesn't apply to your kernel, apply it manually, it only
36 adds one of those functions and nothing more. You may not patch the
37 kernel if STRICT_SERIALIZING or FILEIO_ONLY are defined during the
38 compilation (see their description below).
40 To compile SCST type 'make'. It will build SCST itself and its device
41 handlers. To install them type 'make install'. The driver modules will
42 be installed in '/lib/modules/`you_kernel_version`/extra'. In addition,
43 scsi_tgt.h, scst_debug.h and scst_debug.c will be copied to
44 '/usr/local/include/scst'. The first file contains all SCST's public
45 data definition, which are used by target drivers. The other ones
46 support debug messages logging.
48 Then you can load any module by typing 'modprobe drive_name'. The names are:
50 - scsi_tgt - SCST itself
51 - scst_disk - device handler for disks (type 0)
52 - scst_tape - device handler for tapes (type 1)
53 - scst_processor - device handler for processors (type 3)
54 - scst_cdrom - device handler for CDROMs (type 5)
55 - scst_modisk - device handler for MO disks (type 7)
56 - scst_changer - device handler for medium changers (type 8)
57 - scst_raid - device handler for storage array controller (e.g. raid) (type C)
58 - scst_fileio - device handler for FILE IO (disk or ISO CD image).
60 Then, to see your devices remotely, you need to add them to at least
61 "Default" security group (see below how). By default, no local devices
62 are seen remotely. There must be LUN 0 in each security group, i.e. LUs
63 numeration must not start from, e.g., 1.
65 IMPORTANT: Without loading appropriate device handler, corresponding devices
66 ========= will be invisible for remote initiators, which could lead to holes
67 in the LUN addressing, so automatic device scanning by remote SCSI
68 mid-level could not notice the devices. Therefore you will have
69 to add them manually via
70 'echo "scsi add-single-device A 0 0 B" >/proc/scsi/scsi',
71 where A - is the host number, B - LUN.
73 IMPORTANT: In the current version simultaneous access to local SCSI devices
74 ========= via standard high-level SCSI drivers (sd, st, sg, etc.) and
75 SCST's target drivers is unsupported. Especially it is
76 important for execution via sg and st commands that change
77 the state of devices and their parameters, because that could
78 lead to data corruption. If any such command is done, at
79 least related device handler(s) must be restarted. For block
80 devices READ/WRITE commands using direct disk handler look to
83 To uninstall, type 'make uninstall'.
85 If you install QLA2x00 target driver's source code in this directory,
86 then you can build, install or uninstall it by typing 'make qla', 'make
87 qla_install' or 'make qla_uninstall' correspondingly. For more details
88 about QLA2x00 target drivers see their README files.
93 Device specific drivers (device handlers) are plugins for SCST, which
94 help SCST to analyze incoming requests and determine parameters,
95 specific to various types of devices. If an appropriate device handler
96 for a SCSI device type isn't loaded, SCST doesn't know how to handle
97 devices of this type, so they will be invisible for remote initiators
98 (more precisely, "LUN not supported" sense code will be returned).
100 In addition to device handlers for real devices, there are FILEIO and
103 FILEIO device handler works over files on file systems and makes from
104 them virtual remotely available SCSI disks or CDROM's. In addition, it
105 allows to work directly over a block device, e.g. local IDE or SCSI disk
106 or ever disk partition, where there is no file systems overhead. Using
107 block devices comparing to sending SCSI commands directly to SCSI
108 mid-level via scsi_do_req()/scsi_execute_async() has advantage that data
109 are transfered via system cache, so it is possible to fully benefit from
110 caching and read ahead performed by Linux's VM subsystem. The only
111 disadvantage here that there is superfluous data copying between the
112 cache and SCST's buffers. This issue is going to be addressed in the
113 next release. Virtual CDROM's are useful for remote installation. See
114 below for details how to setup and use FILEIO device handler.
116 "Performance" device handlers for disks, MO disks and tapes in their
117 exec() method skip (pretend to execute) all READ and WRITE operations
118 and thus provide a way for direct link performance measurements without
119 overhead of actual data transferring from/to underlying SCSI device.
121 NOTE: Since "perf" device handlers on READ operations don't touch the
122 ==== commands' data buffer, it is returned to remote initiators as it
123 was allocated, without even being zeroed. Thus, "perf" device
124 handlers impose some security risk, so use them with caution.
129 There are the following compilation options, that could be commented
132 - FILEIO_ONLY - if defined, the pass-through device handlers
133 (scst_disk, scst_tape) will not work, but SCST will not require the
134 kernel patching. Defined by default to ease new people try SCST on
137 - DEBUG - turns on some debugging code, including some logging. Makes
138 the driver considerably bigger and slower, producing large amount of
141 - TRACING - turns on ability to log events. Makes the driver considerably
142 bigger and lead to some performance loss.
144 - EXTRACHECKS - adds extra validity checks in the various places.
146 - DEBUG_TM - turns on task management functions debugging, when on
147 LUN 0 in the "Default" group some of the commands will be delayed for
148 about 60 sec., so making the remote initiator send TM functions, eg
149 ABORT TASK and TARGET RESET. Also set TM_DBG_GO_OFFLINE symbol in the
150 Makefile to 1 if you want that the device eventually become
151 completely unresponsive, or to 0 otherwise to circle around ABORTs
152 and RESETs code. Needs DEBUG turned on.
154 - STRICT_SERIALIZING - makes SCST send all commands to underlying SCSI
155 device synchronously, one after one. This makes task management more
156 reliable, with cost of some performance penalty. This is mostly
157 actual for stateful SCSI devices like tapes, where the result of
158 command's execution depends from device's settings set by previous
159 commands. Disk and RAID devices are stateless in the most cases. The
160 current SCSI core in Linux doesn't allow to abort all commands
161 reliably if they sent asynchronously to a stateful device. Turned off
162 by default, turn it on if you use stateful device(s) and need as much
163 error recovery reliability as possible. As a side effect, no kernel
164 patching is necessary.
166 - SCST_HIGHMEM - if defined on HIGHMEM systems with 2.6 kernels, it
167 allows SCST to use HIGHMEM. This is very experimental feature and it
168 is unclear, if it brings something valuable, except some performance
169 hit, so in the current version it is disabled. Note, that
170 SCST_HIGHMEM isn't required for HIGHMEM systems and SCST will work
171 fine on them with SCST_HIGHMEM off. Untested.
173 - SCST_STRICT_SECURITY - if defined, makes SCST clean allocated data
174 buffers. Undefining it (default) considerably improves performance
175 and eases CPU load, but could create a security hole (information
176 leakage), so enable it, if you have strict security requirements.
181 Module scsi_tgt supports the following parameters:
183 - scst_threads - allows to set count of SCST's threads. By default it
186 - scst_max_cmd_mem - sets maximum amount of memory in Mb allowed to be
187 consumed by the SCST commands for data buffers at any given time. By
188 default it is approximately TotalMem/4.
190 SCST "/proc" commands
191 ---------------------
193 For communications with user space programs SCST provides proc-based
194 interface in "/proc/scsi_tgt" directory. It contains the following
197 - "help" file, which provides online help for SCST commands
199 - "scsi_tgt" file, which on read provides information of serving by SCST
200 devices and their dev handlers. On write it supports the following
203 * "assign H:C:I:L HANDLER_NAME" assigns dev handler "HANDLER_NAME"
204 on device with host:channel:id:lun
206 - "sessions" file, which lists currently connected initiators (open sessions)
208 - "sgv" file provides some statistic about with which block sizes
209 commands from remote initiators come and how effective sgv_pool in
210 serving those allocations from the cache, i.e. without memory
211 allocations requests to the kernel. "Size" - is the commands data
212 size upper rounded to power of 2, "Hit" - how many there are
213 allocations from the cache, "Total" - total number of allocations.
215 - "threads" file, which allows to read and set number of SCST's threads
217 - "version" file, which shows version of SCST
219 - "trace_level" file, which allows to read and set trace (logging) level
220 for SCST. See "help" file for list of trace levels.
222 Each dev handler has own subdirectory. Most dev handler have only two
223 files in this subdirectory: "trace_level" and "type". The first one is
224 similar to main SCST "trace_level" file, the latter one shows SCSI type
225 number of this handler as well as some text description.
227 For example, "echo "assign 1:0:1:0 dev_disk" >/proc/scsi_tgt/scsi_tgt"
228 will assign device handler "dev_disk" to real device sitting on host 1,
229 channel 0, ID 1, LUN 0.
231 Access and devices visibility management
232 ----------------------------------------
234 Access and devices visibility management allows for an initiator or
235 group of initiators to have different limited set of LUs/LUNs (security
236 group) each with appropriate access permissions. Initiator is
237 represented as a SCST session. Session is binded to security group on
238 its registration time by character "name" parameter of the registration
239 function, which provided by target driver, based on its internal
240 authentication. For example, for FC "name" could be WWN or just loop
241 ID. For iSCSI this could be iSCSI login credentials or iSCSI initiator
242 name. Each security group has set of names assigned to it by system
243 administrator. Session is binded to security group with provided name.
244 If no such groups found, the session binded to "Default" group.
246 In /proc/scsi_tgt each group represented as "groups/GROUP_NAME/"
247 subdirectory. In it there are files "devices" and "users". File
248 "devices" lists all devices and their LUNs in the group, file "users"
249 lists all names that should be binded to this group.
251 To configure access and devices visibility management SCST provides the
252 following files and directories under /proc/scsi_tgt:
254 - "add_group GROUP" to /proc/scsi_tgt/scsi_tgt adds group "GROUP"
256 - "del_group GROUP" to /proc/scsi_tgt/scsi_tgt deletes group "GROUP"
258 - "add H:C:I:L lun [RO]" to /proc/scsi_tgt/groups/GROUP/devices adds
259 device with host:channel:id:lun as LUN "lun" in group "GROUP". Optionally,
260 the device could be marked as read only.
262 - "del H:C:I:L" to /proc/scsi_tgt/groups/GROUP/devices deletes device with
263 host:channel:id:lun from group "GROUP"
265 - "add V_NAME lun [RO]" to /proc/scsi_tgt/groups/GROUP/devices adds device with
266 virtual name "V_NAME" as LUN "lun" in group "GROUP". Optionally, the device
267 could be marked as read only.
269 - "del V_NAME" to /proc/scsi_tgt/groups/GROUP/devices deletes device with
270 virtual name "V_NAME" from group "GROUP"
272 - "clear" to /proc/scsi_tgt/groups/GROUP/devices clears the list of devices
275 - "add NAME" to /proc/scsi_tgt/groups/GROUP/names adds name "NAME" to group
278 - "del NAME" to /proc/scsi_tgt/groups/GROUP/names deletes name "NAME" from group
281 - "clear" to /proc/scsi_tgt/groups/GROUP/names clears the list of names
286 - "echo "add 1:0:1:0 0" >/proc/scsi_tgt/groups/Default/devices" will
287 add real device sitting on host 1, channel 0, ID 1, LUN 0 to "Default"
290 - "echo "add disk1 1" >/proc/scsi_tgt/groups/Default/devices" will
291 add virtual FILEIO device with name "disk1" to "Default" group
294 FILEIO device handler
295 ---------------------
297 After loading FILEIO device handler creates in "/proc/scsi_tgt/"
298 subdirectories "disk_fileio" and "cdrom_fileio". They have similar layout:
300 - "trace_level" and "type" files as described for other dev handlers
302 - "help" file, which provides online help for FILEIO commands
304 - "disk_fileio"/"cdrom_fileio" files, which on read provides
305 information of currently open device files. On write it supports the
308 * "open NAME [PATH] [BLOCK_SIZE] [FLAGS]" - opens file "PATH" as
309 device "NAME" with block size "BLOCK_SIZE" bytes with flags
310 "FLAGS". "PATH" could be empty only for FILEIO CDROM. "BLOCK_SIZE"
311 and "FLAGS" are valid only for disk FILEIO. The block size must be
312 power of 2 and >= 512 bytes Default is 512. Possible flags:
314 - WRITE_THROUGH - write back caching disabled
316 - READ_ONLY - read only
318 - O_DIRECT - both read and write caching disabled (doesn't work
321 - NULLIO - in this mode no real IO will be done, but success will be
322 returned. Intended to be used for performance measurements at the same
323 way as "*_perf" handlers.
325 - NV_CACHE - enables "non-volatile cache" mode. In this mode it is
326 assumed that the target has GOOD uninterruptable power supply
327 and software/hardware bug free, i.e. all data from the target's
328 cache are guaranteed sooner or later to go to the media, hence
329 all data synchronization with media operations, like
330 SYNCHRONIZE_CACHE, are ignored (BTW, so violating SCSI standard)
331 in order to bring a bit more performance. Use with extreme
332 caution, since in this mode after a crash of the target
333 journaled file systems don't guarantee the consistency after
334 journal recovery, therefore manual fsck MUST be ran. The main
335 intent for it is to determine the performance impact caused by
336 the cache synchronization. Note, that since usually the journal
337 barrier protection (see "IMPORTANT" below) turned off, enabling
338 NV_CACHE could change nothing, since no data synchronization
339 with media operations will go from the initiator.
341 * "close NAME" - closes device "NAME".
343 * "change NAME [PATH]" - changes a virtual CD in the FILEIO CDROM.
345 For example, "echo "open disk1 /vdisks/disk1" >/proc/scsi_tgt/disk_fileio/disk_fileio"
346 will open file /vdisks/disk1 as virtual FILEIO disk with name "disk1".
348 IMPORTANT: By default for performance reasons FILEIO devices use write back
349 ========= caching policy. This is generally safe from the consistence of
350 journaled file systems, laying over them, point of view, but
351 your unsaved cached data will be lost in case of
352 power/hardware/software faulure, so you must supply your
353 target server with some kind of UPS or disable write back
354 caching using WRITE_THROUGH flag. You also should note, that
355 the file systems journaling over write back caching enabled
356 devices works reliably *ONLY* if it uses some kind of data
357 protection barriers (i.e. after writing journaling data some
358 kind of synchronization with media operations will be used),
359 otherwise, because of possible reordering in the cache, even
360 after successful journal rollback you very much risk to loose
361 your data on the FS. On Linux initiators for EXT3 and
362 ReiserFS file systems the barrier protection could be turned
363 on using "barrier=1" and "barrier=flush" mount options
364 correspondingly. Note, that usually it turned off by default
365 and the status of barriers usage isn't reported anywhere in
366 the system logs as well as there is no way to know it on the
367 mounted file system (at least no known one). Also note
368 that on some real-life workloads write through caching might
369 perform better, than write back one with the barrier protection
372 IMPORTANT: Many disk and partition table mananagement utilities don't support
373 ========= block sizes >512 bytes, therefore make sure that your favorite one
374 supports it. Also, if you export disk file or device with
375 some block size, different from one, with which it was
376 already divided on partitions, you could get various weird
377 things like utilities hang up or other unexpected behaviour.
378 Hence, to be sure, zero the exported file or device before the
379 first access to it from the remote initiator with another
385 Before doing any performance measurements note that:
387 I. Maximum performance is possible only with real SCSI devices or
388 performance handlers. If you have enough CPU power, FILEIO handler could
389 provide the same results, when aggregate throughput is close to
390 aggregate throuput locally on the target on the same disks.
392 II. In order to get the maximum performance you should:
396 - Disable in Makefile STRICT_SERIALIZING, EXTRACHECKS, TRACING, DEBUG,
397 SCST_STRICT_SECURITY, SCST_HIGHMEM
399 2. For Qlogic target driver:
401 - Disable in Makefile EXTRACHECKS, TRACING, DEBUG_TGT, DEBUG_WORK_IN_THREAD
403 3. For device handlers, including FILEIO:
405 - Disable in Makefile TRACING, DEBUG
407 IMPORTANT: Some of those options enabled by default, i.e. SCST is optimized
408 ========= currently rather for development, not for performance.
412 - Don't enable debug/hacking features, i.e. use them as they are by
415 - The default kernel read-ahead and queuing settings are optimized
416 for locally attached disks, therefore they are not optimal if they
417 attached remotly (our case), which sometimes could lead to unexpectedly
418 low throughput. You should increase read-ahead size
419 (/sys/block/device/queue/read_ahead_kb) to at least 256Kb or even
420 more on all initiators and the target. Also experiment with other
421 parameters in /sys/block/device directory, they also affect the
422 performance. If you find the best values, please share them with us.
426 - Make sure that your target hardware (e.g. target FC card) and underlaying
427 SCSI hardware (e.g. SCSI card to which your disks connected) stay on
428 different PCI buses. They will have to work in parallel, so it
429 will be better if they don't race for the bus. The problem is not
430 only in the bandwidth, which they have to share, but also in the
431 interaction between the cards during that competition. We have told
432 that in some cases it could lead to 5-10 times less performance, than
435 IMPORTANT: If you use on initiator some versions of Windows (at least W2K)
436 ========= you can't get good write performance for FILEIO devices with
437 default 512 bytes block sizes. You could get about 10% of the
438 expected one. This is because of "unusual" write access
439 pattern, with which Windows'es write data and which is
440 (simplifying) incompatible with how Linux page cache works,
441 so for each write the corresponding block must be read first.
442 With 4096 bytes block sizes for FILEIO devices the write
443 performance will be as expected. Actually, any system on
444 initiator, not only Windows, will benefit from block size
445 max(PAGE_SIZE, BLOCK_SIZE_ON_UNDERLYING_FS), where PAGE_SIZE
446 is the page size, BLOCK_SIZE_ON_UNDERLYING_FS is block size on
447 the underlying FS, on which the device file located, or 0, if
448 a device node is used. Both values are on the target.
450 Just for reference: we had with 0.9.2 and "old" Qlogic driver on 2.4.2x
451 kernel, where we did carefull performance study, aggregate throuhput
452 about 390 Mb/sec from 2 qla2300 cards sitting on different 64-bit PCI
453 buses and working simultaneously for two different initiators with
454 several simultaneously working load programs on each. From one card -
455 about 190 Mb/sec. We used tape_perf handler, so there was no influence
456 from underlying SCSI hardware, i.e. we measured only SCST/FC overhead.
457 The target computer configuration was not very modern for the moment:
458 something like 2x1GHz Intel P3 Xeon CPUs. You can estimate the
459 memory/PCI speed from that. CPU load was ~5%, there were ~30K IRQ/sec
460 and no additional SCST related context switches.
467 * Mark Buechler <mark.buechler@gmail.com> for a lot of useful
468 suggestions, bug reports and help in debugging.
470 * Ming Zhang <mingz@ele.uri.edu> for fixes and comments.
472 * Nathaniel Clark <nate@misrule.us> for fixes and comments.
474 * Calvin Morrow <calvin.morrow@comcast.net> for testing and usful
477 Vladislav Bolkhovitin <vst@vlnb.net>, http://scst.sourceforge.net