1 SCST USER SPACE DEVICE HANDLER MODULE.
3 USER SPACE INTERFACE DESCRIPTION.
10 SCST user space device handler module scst_user is a device handler for
11 SCST, which provides a way to implement in the user space complete, full
12 feature virtual SCSI devices in the SCST environment.
14 This document assumes that the reader is familiar with the SCST
15 architecture and the states through which SCSI commands go during
16 processing in SCST. Module scst_user basically only provides hooks to
17 them. Their description could be found on the SCST web page on
23 Module scst_user provides /dev/scst_user character device with the
24 following system calls available:
26 - open() - allows to open the device and get a file handle, which
27 will be used in all subsequent actions until close() is called
29 - close() - closes file handle returned by open()
31 - poll() - allows to wait until some pending command from SCST to
34 - ioctl() - main call, which allows commands interchange with the SCST
37 Device /dev/scst_user could be opened in blocking or non-blocking mode
38 using O_NONBLOCK flag. In the blocking mode ioctl()
39 SCST_USER_REPLY_GET_CMD function blocks until there is a new subcommand
40 to process. In the non-blocking mode if there are no pending subcommands
41 SCST_USER_REPLY_GET_CMD function returns immediately with EAGAIN error
42 code, and the user space device handler can use poll() call to get
43 notification about new subcommands arrival. The blocking mode is the
46 The module scst_user API is defined in scst_user.h file.
49 III. IOCTL() functions.
51 There are following IOCTL functions available. All of them has one
52 argument. They all, except SCST_USER_REGISTER_DEVICE return 0 for
53 success or -1 in case of error, and errno is set appropriately.
56 1. SCST_USER_REGISTER_DEVICE
58 SCST_USER_REGISTER_DEVICE - registers new virtual user space device. The
61 struct scst_user_dev_desc
66 uint8_t has_own_order_mgmt;
67 struct scst_user_opt opt;
69 char name[SCST_MAX_NAME];
70 char sgv_name[SCST_MAX_NAME];
75 - version - is a protocol version, shall be DEV_USER_VERSION
77 - type - SCSI type of the device
79 - sgv_shared - true, if SGV cache for this device should be shared with
80 other devices. False, if the SGV cache should be dedicated.
82 - has_own_order_mgmt - set it in non-zero, if device implements own
83 ORDERED commands management, i.e. guarantees commands execution order
84 requirements, specified by SAM.
86 - opt - device options, see SCST_USER_SET_OPTIONS/SCST_USER_GET_OPTIONS below
88 - block_size - block size, shall be divisible by 512 for block devices
90 - name - name of the device
92 - sgv_name - name of SGV cache for this device
94 SCST_USER_REGISTER_DEVICE returns registered device's handler or -1
95 in case of error, and errno is set appropriately.
97 In order to unregister the device, either call SCST_USER_UNREGISTER_DEVICE
98 function, or close on its file descriptor.
101 2. SCST_USER_UNREGISTER_DEVICE
103 SCST_USER_UNREGISTER_DEVICE - unregisters the corresponding virtual user
104 space device. It doesn't have any parameters.
106 During execution of SCST_USER_UNREGISTER_DEVICE at least one another
107 thread must process all coming subcommands, otherwise after timeout it
108 will fail with EBUSY error.
110 SCST_USER_UNREGISTER_DEVICE returns 0 on success or -1 in case of error,
111 and errno is set appropriately.
114 3. SCST_USER_SET_OPTIONS/SCST_USER_GET_OPTIONS
116 SCST_USER_SET_OPTIONS/SCST_USER_GET_OPTIONS allows to set or get
117 correspondingly various options that control various aspects of SCSI
125 uint8_t on_free_cmd_type;
126 uint8_t memory_reuse_type;
127 uint8_t partial_transfers_type;
128 uint32_t partial_len;
136 uint8_t has_own_order_mgmt;
141 - parse_type - defines how the user space handler wants to process
142 PARSE subcommand. Possible values are:
144 * SCST_USER_PARSE_STANDARD - tells SCST use standard internal parser
145 for this SCSI device type.
147 * SCST_USER_PARSE_CALL - tells SCST generate SCST_USER_PARSE for all
150 * SCST_USER_PARSE_EXCEPTION - tells SCST generate SCST_USER_PARSE
151 for unknown SCSI commands or SCSI commands that produce errors in
154 - on_free_cmd_type - defines how the user space handler wants to
155 process ON_FREE_CMD subcommand. Possible values are:
157 * SCST_USER_ON_FREE_CMD_CALL - tells SCST generate
158 SCST_USER_ON_FREE_CMD for all SCSI commands
160 * SCST_USER_ON_FREE_CMD_IGNORE - tells SCST do nothing on this event.
162 - memory_reuse_type - defines how memory allocated by the user space
163 handler for a SCSI commands data buffers is then reused by the SCST
164 core as data buffer for subsequent commands. Possible values are:
166 * SCST_USER_MEM_NO_REUSE - no memory reuse is possible, for each
167 commands the user space handler will each time allocate a dedicated
170 * SCST_USER_MEM_REUSE_READ - memory reuse by only READ-type commands
171 (i.e. which involve data transfer from target to initiator) is
172 allowed. For all WRITE-type commands (i.e. which involves data
173 transfer from initiator to target) the user space handler will
174 each time allocate a dedicated data buffer
176 * SCST_USER_MEM_REUSE_WRITE - memory reuse by only WRITE-type
177 commands is allowed. For all WRITE-type commands the user space
178 handler will each time allocate a dedicated data buffer
180 * SCST_USER_MEM_REUSE_ALL - unlimited memory reuse is possible.
182 - partial_transfers_type - defines if the user space handler supports
183 partial data transfers, when a SCSI command, which required big data
184 transfer, is broken on several subcommands with smaller data
185 transfers. This allows to improve performance by simultaneous data
186 transfers from/to remote initiator and to/from the underlying storage
187 device as well as lower allocation memory requirements for each
188 (sub)command. All subcommands will have the same unique value in
189 "parent_cmd_h" field and SCST_USER_SUBCOMMAND flag in "partial" field
190 of struct scst_user_scsi_cmd_exec. The final subcommand will also
191 have in that field SCST_USER_SUBCOMMAND_FINAL flag. All the
192 subcommands will have the original unmodified CDB. Possible values
195 * SCST_USER_PARTIAL_TRANSFERS_NOT_SUPPORTED - the partial data
196 transfers are not supported
198 * SCST_USER_PARTIAL_TRANSFERS_SUPPORTED_ORDERED - the partial data
199 transfers are supported, but all the subcommands must come in order
200 of data chunks. Could be used, e.g., for tape devices.
202 * SCST_USER_PARTIAL_TRANSFERS_SUPPORTED - the partial data transfers
203 are supported without limitations.
205 - tst, queue_alg, tas, swp, d_sense - set values for TST, QUEUE ALGORITHM MODIFIER,
206 TAS, SWP and D_SENSE fields from control mode page correspondingly,
209 - has_own_order_mgmt - true, if the user space handler has full
210 commands execution order management, i.e. guarantees commands execution
211 order as required by SAM. False otherwise.
213 Flags parse_type and on_free_cmd_type are designed to improve
214 performance by eliminating context switches to the user space handler,
215 when processing of the corresponding events isn't needed.
217 Flag memory_reuse_type is designed to improve performance by eliminating
218 memory allocation, preparation and then freeing each time for each
219 commands, if the same memory will be allocated again and again. See
220 SCST_USER_ALLOC_MEM description below for more info.
222 SCST_USER_SET_OPTIONS should not be used from the same and the only
223 thread, which also handles incoming commands, otherwise there could be a
224 "deadlock", when SCST_USER_SET_OPTIONS waits for active commands finish,
225 but nobody handles them. This "deadlock" will be resolved only when
226 initiator, which sent those commands, aborts them after timeout.
229 4. SCST_USER_REPLY_AND_GET_CMD
231 SCST_USER_REPLY_AND_GET_CMD allows at one call reply on the current
232 subcommand from SCST and get the next one. If 0 is returned by ioctl(),
233 SCST_USER_REPLY_AND_GET_CMD returns a SCST subcommand in the argument,
234 which is defined as the following:
236 struct scst_user_get_cmd
242 struct scst_user_sess sess;
243 struct scst_user_scsi_cmd_parse parse_cmd;
244 struct scst_user_scsi_cmd_alloc_mem alloc_cmd;
245 struct scst_user_scsi_cmd_exec exec_cmd;
246 struct scst_user_scsi_on_free_cmd on_free_cmd;
247 struct scst_user_on_cached_mem_free on_cached_mem_free;
248 struct scst_user_tm tm_cmd;
254 - cmd_h - command handle used to identify the command in the reply.
256 - subcode - subcommand code, see 4.1 below
258 - preply - pointer to the reply data or, if 0, there is no reply. See
259 SCST_USER_REPLY_CMD for description of struct scst_user_reply_cmd
262 Other union members contain command's specific payload.
264 For all received subcommands the user space device handler shall call
265 SCST_USER_REPLY_AND_GET_CMD or SCST_USER_REPLY_CMD function to tell SCST
266 that the subcommand's processing is finished, although some subcommands
267 don't return a value.
270 4.1. Possible subcommands:
273 4.1.1. SCST_USER_ATTACH_SESS
275 SCST_USER_ATTACH_SESS notifies the user space handler that a new
276 initiator's session is about to be attached to the device. Payload
277 contains struct scst_user_sess, which is defined as the following:
279 struct scst_user_sess
283 uint16_t threads_num;
285 char initiator_name[SCST_MAX_NAME];
286 char target_name[SCST_MAX_NAME];
291 - sess_h - session's handle, may not be 0
293 - lun - assigned LUN for this device in this session
295 - threads_num - specifies amount of additional threads, requested by
296 the corresponding target driver
298 - rd_only - if true, this device is read only in this session
300 - initiator_name - name of the remote initiator, which initiated this
303 - target_name - name of the target, to which this session belongs
305 When SCST_USER_ATTACH_SESS is returned, it is guaranteed that there are
306 no other commands are being executed or pending.
308 After SCST_USER_ATTACH_SESS function completed, the user space device
309 handler shall reply using "result" field of the corresponding reply
313 4.1.2. SCST_USER_DETACH_SESS
315 SCST_USER_DETACH_SESS notifies the user space handler that the
316 corresponding initiator is about to be detached from the particular
317 device. Payload contains struct scst_user_sess, where only handle field
320 When SCST_USER_DETACH_SESS is returned, it is guaranteed that there are
321 no other commands are being executed or pending.
323 This command doesn't reply any return value, although
324 SCST_USER_REPLY_AND_GET_CMD or SCST_USER_REPLY_CMD function must be
328 4.1.3. SCST_USER_PARSE
330 SCST_USER_PARSE returns SCSI command on PARSE state of the SCST
331 processing. The PARSE state is intended to check validity of the
332 command, determine data transfer type and the necessary data buffer
333 size. This subcommand is returned only if SCST_USER_SET_OPTIONS
334 parse_type isn't set to SCST_USER_PARSE_STANDARD. In this case the
335 standard SCST internal parser for this SCSI device type will do all the
338 Payload contains struct scst_user_scsi_cmd_parse, which is defined as
341 struct scst_user_scsi_cmd_parse
345 uint8_t cdb[SCST_MAX_CDB_SIZE];
347 uint16_t ext_cdb_len;
354 uint8_t data_direction;
356 uint8_t expected_values_set;
357 uint8_t expected_data_direction;
358 int32_t expected_transfer_len;
365 - sess_h - corresponding session handler
369 - cdb_len - SCSI CDB length
371 - ext_cdb_len - size of extended CDB, see SCST_USER_GET_EXTENDED_CDB
374 - timeout - CDB execution timeout
376 - bufflen - command's buffer length
378 - in_bufflen - for bidirectional commands command's IN, i.e. from
379 initiator to target, buffer length
381 - queue_type - SCSI task attribute (queue type)
383 - data_direction - command's data flow direction, one of SCST_DATA_*
386 - expected_values_set - true if expected_data_direction and
387 expected_transfer_len contain valid values
389 - expected_data_direction - remote initiator supplied command's data
392 - expected_transfer_len - remote initiator supplied transfer length
394 - sn - command's SN, which might be used for task management
396 In the PARSE state of SCSI commands processing the user space device
397 handler shall check and provide SCST values for command data buffer
398 length, data flow direction and timeout, which it shall reply using the
399 corresponding reply command.
401 In case of any error the error reporting should be deferred until
402 SCST_USER_EXEC subcommand, where the appropriate SAM status and sense
406 4.4.4. SCST_USER_ALLOC_MEM
408 SCST_USER_ALLOC_MEM returns SCSI command on memory allocation state of
409 the SCST processing. On this state the user space device handler shall
410 allocate the command's data buffer with bufflen length and then return
411 it to SCST using the corresponding reply command. Then SCST internally
412 will convert it in SG vector in order to use it itself and by target
415 If the memory reuse type is disabled (i.e. set to SCST_USER_MEM_NO_REUSE)
416 there are no special requirements for buffer memory or its alignment, it
417 could be just what malloc() returned. If the memory reuse type is enabled,
418 the buffer shall be page size aligned, for example using memalign()
421 Payload contains struct scst_user_scsi_cmd_alloc_mem, which is defined
424 struct scst_user_scsi_cmd_alloc_mem
428 uint8_t cdb[SCST_MAX_CDB_SIZE];
430 uint16_t ext_cdb_len;
435 uint8_t data_direction;
442 - sess_h - corresponding session handler
446 - cdb_len - SCSI CDB length
448 - ext_cdb_len - size of extended CDB, see SCST_USER_GET_EXTENDED_CDB
451 - alloc_len - command's buffer length
453 - queue_type - SCSI task attribute (queue type )
455 - data_direction - command's data flow direction, one of SCST_DATA_*
458 - sn - command's SN, which might be used for task management
460 Memory allocation, preparation and freeing are ones of the most
461 complicated and expensive operations during SCSI commands processing.
462 Module scst_user provides a way to almost completely eliminate those
463 operations by reusing once allocated memory for subsequent SCSI
464 commands. It is controlled by memory_reuse_type option, which could be
465 set by SCST_USER_SET_OPTIONS function. If any type memory reusage is
466 enabled, then SCST will use its internal SGV cache in order to cache
467 allocated and fully built SG vectors for subsequent commands of this
468 type, so for them SCST_USER_ALLOC_MEM subfunction will not be called and
469 in SCST_USER_EXEC pbuf pointer will point to that reused buffer.
471 SGV cache is a backend cache made on top of Linux kernel SLAB cache. It
472 caches SG vectors with power of 2 data sizes: 4K, 8K, ..., 4M. So, if
473 there is a 5K SCSI command coming, then the user space handler will be
474 asked for 8K allocation, from which only 5K will be used for this
475 particular SCSI command. Then that SG vector will be cached and
476 subsequently reused for all SCSI commands between 4K and 8K. For a 1M
477 SCSI command the user space handler will be asked for another buffer
478 (while the previous 5K one will be kept), which will not be then reused
479 for 5K SCSI commands, since 1M and 5K vectors belong to different cache
480 data sizes, it will be reused only for commands between 512K and 1M.
481 Then, after some time of inactivity or when the system is under memory
482 pressure, the cache entries will be freed and the user space handler
483 will be notified using SCST_USER_ON_CACHED_MEM_FREE.
485 Since SGV cache caches SG vectors with power of 2 data sizes, alloc_len
486 field could be up to 2 times more, than actually required by the SCSI
489 The memory reuse could be used in both SCSI tagged and untagged queuing
490 environments. In the SCSI tagged queuing environment the SGV cache will
491 take care that several commands don't use the same buffer simultaneously
492 by asking the user space handler to allocate a new data buffer, when all
493 cached ones are busy.
495 Some important notes:
497 1. If the user space handler needs to call fork(), it must call
498 madvise() with MADV_DONTFORK flag for all allocated data buffers,
499 otherwise parent or child process could loose the connection with them,
500 which could lead to data corruption. See http://lwn.net/Articles/171941/
503 2. The interface assumes that all allocated memory by the user space
504 handler is DMA'able by the target hardware. This is almost always true
505 for most modern systems, except if the target hardware isn't capable of
506 using 64-bit address space and the system has >4GB of memory or the
507 memory addresses are in address space, which is unavailable with 32-bit
510 In case of any error the error reporting should be deferred until
511 SCST_USER_EXEC subcommand, where the appropriate SAM status and sense
515 4.4.5. SCST_USER_EXEC
517 SCST_USER_EXEC returns SCSI command on execution state of the SCST
518 processing. The user space handler should execute the SCSI command and
519 reply using the corresponding reply command.
521 In some cases for performance reasons for READ-type SCSI commands
522 SCST_USER_ALLOC_MEM subcommand isn't returned before SCST_USER_EXEC.
523 Thus, if pbuf pointer is 0 and the SCSI command needs data transfer,
524 the user space handler should be prepared to allocate the data buffer
525 with size alloc_len, which could be up to 2 times more, than actually
526 required by the SCSI command. But field bufflen will contain the correct
527 value. All the memory reusage rules, described for SCST_USER_ALLOC_MEM,
528 apply to SCST_USER_EXEC as well.
530 Payload contains struct scst_user_scsi_cmd_exec, which is defined as the
533 struct scst_user_scsi_cmd_exec
537 uint8_t cdb[SCST_MAX_CDB_SIZE];
539 uint16_t ext_cdb_len;
546 uint8_t data_direction;
550 aligned_u64 p_in_buf;
555 uint32_t parent_cmd_h;
556 int32_t parent_cmd_data_len;
557 uint32_t partial_offset;
562 - sess_h - corresponding session handler
566 - cdb_len - SCSI CDB length
568 - ext_cdb_len - size of extended CDB, see SCST_USER_GET_EXTENDED_CDB
571 - data_len - command's data length. Could be different from bufflen for
572 commands like VERIFY, which transfer different amount of data, than
573 process, or even none of them
575 - bufflen - command's buffer length
577 - alloc_len - command's buffer length, which should be allocated, if pbuf
578 is 0 and the command requires data transfer
580 - pbuf - pointer to command's data buffer or 0 for SCSI commands
581 without data transfer.
583 - queue_type - SCSI task attribute (queue type)
585 - data_direction - command's data flow direction, one of SCST_DATA_*
588 - partial - specifies, if the command is a partial subcommand, could
589 have the following OR'ed flags:
591 * SCST_USER_SUBCOMMAND - set if the command is a partial subcommand
593 * SCST_USER_SUBCOMMAND_FINAL - set if the subcommand is a final one
595 - timeout - CDB execution timeout
597 - p_in_buf - for bidirectional commands pointer on command's IN, i.e. from
598 initiator to target, data buffer or 0 for SCSI commands without data
601 - in_bufflen - for bidirectional commands command's IN, i.e. from
602 initiator to target, buffer length
604 - sn - command's SN, which might be used for task management
606 - parent_cmd_h - has the same unique value for all partial data
607 transfers subcommands of one original (parent) command
609 - parent_cmd_data_len - for partial data transfers subcommand has the
610 size of the overall data transfer of the original (parent) command
612 - partial_offset - has offset of the subcommand in the original
615 It is guaranteed that only commands of the same queue_type per session
616 can be returned simultaneously.
618 In case of any error it should be reported via appropriate SAM status
619 and sense. If it happens for a subcommand of a partial data transfers
620 command, all other subcommands of this command, which already passed the
621 the user space handler or will be passed in the future, will be aborted
622 by scst_user, the user space handler should ignore them.
625 4.4.6. SCST_USER_ON_FREE_CMD
627 SCST_USER_ON_FREE_CMD returns SCSI command when the command is about to
628 be freed. At this stage, the user space device handler could do any
629 necessary cleanups, for instance, free allocated for data buffer memory.
631 NOTE! If the memory reusage is enabled, then the data buffer must not be
632 freed, it will be reused by subsequent SCSI commands. The buffer must be
633 freed only on SCST_USER_ON_CACHED_MEM_FREE event.
635 Payload contains struct scst_user_scsi_on_free_cmd, which is defined
638 struct scst_user_scsi_on_free_cmd
641 int32_t resp_data_len;
642 uint8_t buffer_cached;
645 uint8_t delivery_status;
650 - pbuf - pointer to command's data buffer or 0 for SCSI commands
651 without data transfer.
653 - resp_data_len - length of the response data
655 - buffer_cached - true, if memory reusage is enabled for this command
657 - aborted - true, if command was aborted
659 - status - SAM status of the commands execution
661 - delivery_status - status of cmd's status/data delivery to remote
664 * SCST_CMD_DELIVERY_SUCCESS - delivery succeeded
666 * SCST_CMD_DELIVERY_FAILED - delivery failed
668 The user space handler should reply using the corresponding reply
669 command. No error code is needed.
672 4.4.7. SCST_USER_ON_CACHED_MEM_FREE
674 SCST_USER_ON_CACHED_MEM_FREE subcommand is returned, when SGV cache
675 decided that this buffer isn't needed anymore. This happens after some
676 time of inactivity or when the system is under memory pressure.
678 Payload contains struct scst_user_on_cached_mem_free, which is defined
681 struct scst_user_scsi_cmd_alloc_mem
688 - pbuf - pointer to buffer, which should be freed
691 4.4.8. SCST_USER_TASK_MGMT
693 SCST_USER_TASK_MGMT subcommand returns a task management functions.
694 Payload contains struct scst_user_tm, which is defined as the following:
700 uint32_t cmd_h_to_abort;
707 - sess_h - corresponding session handler
709 - fn - task management function, see below
711 - cmd_h_to_abort - handle of command to abort. Valid only if fn is
714 - cmd_sn - if cmd_sn_set is set, contains maximum commands SN, which
715 this task management function affects. See iSCSI RFC 3720 10.5.1 for
718 - cmd_sn_set - specifies if cmd_sn is valid
720 After TM function is completed, the user space device handler shall
721 reply using "result" field of the corresponding reply command. It isn't
722 necessary to wait for aborted command(s) finished, the result of TM
723 function shall be returned immediately. SCST core will take care that
724 the reply to the TM function isn't sent before all affection SCSI
727 Possible values of "fn" field:
729 - SCST_ABORT_TASK - cmd_h_to_abort shall be aborted
731 - SCST_ABORT_TASK_SET - task set on the device shall be aborted
733 - SCST_CLEAR_ACA - ACA status shall be cleared
735 - SCST_CLEAR_TASK_SET - task set on the device shall be cleared
737 - SCST_LUN_RESET, SCST_TARGET_RESET - reset of the device shall be done
739 - SCST_NEXUS_LOSS_SESS - notifies about nexus loss event for the session
741 - SCST_ABORT_ALL_TASKS_SESS - all tasks in the session shall be aborted
743 - SCST_NEXUS_LOSS - notifies about global nexus loss event
745 - SCST_ABORT_ALL_TASKS - all tasks shall be aborted
747 Possible return values are:
749 - SCST_MGMT_STATUS_SUCCESS - success
751 - SCST_MGMT_STATUS_TASK_NOT_EXIST - task does not exist
753 - SCST_MGMT_STATUS_LUN_NOT_EXIST - LUN does not exist
755 - SCST_MGMT_STATUS_FN_NOT_SUPPORTED - task management function not
758 - SCST_MGMT_STATUS_REJECTED - task management function was rejected
760 - SCST_MGMT_STATUS_FAILED - task management function failed
763 5. SCST_USER_REPLY_CMD
765 SCST_USER_REPLY_CMD IOCTL function allows the user space handler to
766 return the result of a command's execution. Its argument is defined as:
768 struct scst_user_reply_cmd
774 struct scst_user_scsi_cmd_reply_parse parse_reply;
775 struct scst_user_scsi_cmd_reply_alloc_mem alloc_reply;
776 struct scst_user_scsi_cmd_reply_exec exec_reply;
782 - cmd_h - command handle used to identify the command in the reply.
784 - subcode - subcommand code, see 4.1
786 Union contains the subcommand's specific payload:
788 - result - subcommand's result code
791 struct scst_user_scsi_cmd_reply_parse
794 uint8_t data_direction;
795 uint8_t write_medium;
802 - queue_type - SCSI task attribute (queue type )
804 - data_direction - command's data flow direction, one of SCST_DATA_* constants
806 - write_medium - true, if command writes data to medium, so should be
807 forbidden for read-only devices, false otherwise
809 - data_len - command's data length
811 - bufflen - command's buffer length
814 struct scst_user_scsi_cmd_reply_alloc_mem
821 - pbuf - pointer to command's data buffer
824 struct scst_user_scsi_cmd_reply_exec
826 int32_t resp_data_len;
833 aligned_u64 psense_buffer;
838 - resp_data_len - length of the response data
840 - pbuf - pointer to command's data buffer. Used only when in the
841 original SCST_USER_EXEC subcommand pbuf field is 0
843 - reply_type - could be one of the following constants:
845 * SCST_EXEC_REPLY_BACKGROUND - tells SCST send to the remote
846 initiator GOOD status, but the command not yet completed by the
847 user space handler, it is being executed in the background. When
848 it will be completed, the user space handler will call
849 SCST_USER_REPLY_CMD again with reply_type
850 SCST_EXEC_REPLY_COMPLETED.
852 * SCST_EXEC_REPLY_COMPLETED - the user space handler completed the command
854 - status - SAM status of the commands execution
856 - sense_len - length of sense data in psense_buffer, if any
858 - psense_buffer - pointed to sense buffer
861 6. SCST_USER_FLUSH_CACHE
863 SCST_USER_FLUSH_CACHE - flushes SGV cache for the corresponding virtual
864 user space device and queues for all cached memory buffers corresponding
865 SCST_USER_ON_CACHED_MEM_FREE subcommands.
867 During execution of SCST_USER_FLUSH_CACHE at least one another thread
868 must process all coming subcommands, otherwise after timeout it will
869 fail with EBUSY error.
871 SCST_USER_FLUSH_CACHE doesn't have any parameters.
873 SCST_USER_FLUSH_CACHE returns 0 on success or -1 in case of error,
874 and errno is set appropriately.
877 7. SCST_USER_DEVICE_CAPACITY_CHANGED
879 SCST_USER_DEVICE_CAPACITY_CHANGED - queues CAPACITY DATA HAS CHANGED
880 Unit Attention or corresponding Asynchronous Event to the corresponding
881 virtual device. It will notify remote initiators, connected to the
882 device, and allow them to automatically refresh new device size. You
883 should use SCST_USER_DEVICE_CAPACITY_CHANGED after resize of the device.
885 SCST_USER_DEVICE_CAPACITY_CHANGED doesn't have any parameters.
887 SCST_USER_DEVICE_CAPACITY_CHANGED returns 0 on success or -1 in case of
888 error, and errno is set appropriately.
891 8. SCST_USER_GET_EXTENDED_CDB
893 SCST_USER_GET_EXTENDED_CDB - requests extended CDB, if CDB size is more
894 than SCST_MAX_CDB_SIZE bytes. In this case SCST_USER_GET_EXTENDED_CDB
895 returns additional CDB data beyond SCST_MAX_CDB_SIZE bytes.
897 SCST_USER_GET_EXTENDED_CDB has the following arguments:
899 struct scst_user_get_ext_cdb {
901 aligned_u64 ext_cdb_buffer;
906 - cmd_h - command handle used to identify the command in the reply.
908 - ext_cdb_buffer - pointer to buffer, where extended CDB will be copied.
910 SCST_USER_GET_EXTENDED_CDB returns 0 on success or -1 in case of error,
911 and errno is set appropriately.
914 IV. Commands processing flow example.
916 As the example consider a simple synchronous VTL, which serves one
917 virtual SCSI tape device and can process only one command at time from
920 At the beginning the VTL opens using open() call /dev/scst_user in the
921 default blocking mode.
923 Then it using SCST_USER_REGISTER_DEVICE ioctl() function registers the
924 tape device. Since only one command at time is supported, the allocated
925 command's data memory could be reused for both READ-type (i.e. which
926 involve data transfer from target to initiator) and WRITE-type (i.e.
927 which involve data transfer from initiator to target) commands. So the
928 device is configured with parse_type SCST_USER_PARSE_STANDARD,
929 on_free_cmd_type SCST_USER_ON_FREE_CMD_IGNORE, memory_reuse_type
930 SCST_USER_MEM_REUSE_ALL and partial_transfers_type
931 SCST_USER_PARTIAL_TRANSFERS_NOT_SUPPORTED.
933 Then it prepares struct scst_user_get_cmd with reply set to 0, calls
934 SCST_USER_REPLY_AND_GET_CMD ioctl() and waits until some initiator
935 connects to its tape device. On that event the VTL receives
936 SCST_USER_ATTACH_SESS subcommand. Since the VTL doesn't use any
937 initiator specific data, it can do nothing on that subcommand, so it
938 prepares scst_user_reply_cmd structure, where:
940 - cmd_h set to returned by SCST_USER_REPLY_AND_GET_CMD ioctl() cmd_h
942 - subcode set to SCST_USER_ATTACH_SESS
946 Then it prepares struct scst_user_get_cmd with reply set to the prepared
947 scst_user_reply_cmd structure, calls SCST_USER_REPLY_AND_GET_CMD ioctl()
948 and waits for some SCSI command arrives from the initiator.
950 If the received SCSI command is READ-type one, SCST does the necessary
951 preparations, then the VTL receives SCST_USER_EXEC subcommand, where
952 bufflen and data_len are set correctly, but memory for buffer isn't
953 allocated, so pbuf field is 0. The VTL then allocates the data buffer
954 with size alloc_len, e.g. using malloc(). Then the VTL reads the data
955 from disk in it, e.g. using O_DIRECT read() function, then prepares
956 scst_user_reply_cmd structure, where:
958 - cmd_h set to returned by SCST_USER_REPLY_AND_GET_CMD ioctl() cmd_h
960 - subcode set to SCST_USER_EXEC
962 - exec_reply.resp_data_len set to length of the read data
964 - exec_reply.pbuf set to the data buffer, where the data were read
966 - exec_reply.reply_type set to SCST_EXEC_REPLY_COMPLETED
968 - exec_reply.status set to the SAM defined status of the
971 - exec_reply.sense_len set and exec_reply.psense_buffer filled with
972 sense data, if necessary
974 Then it prepares struct scst_user_get_cmd with reply set to the prepared
975 scst_user_reply_cmd structure, calls SCST_USER_REPLY_AND_GET_CMD ioctl()
976 and waits for the next SCSI command arrives from the initiator. That's
977 all for this SCSI command. For the next one the used data buffer will be
980 For WRITE-type SCSI commands the processing is the same, but
981 SCST_USER_ALLOC_MEM will be returned before SCST_USER_EXEC, since the
982 data transfer from the initiator precedes the commands execution.
984 In case, if the first command requires 4K data buffer, but the second
985 one - 1M, for it the VTL also will be asked to allocate the buffer.
986 Then, if no more 4K commands come for some time, for it
987 SCST_USER_ON_CACHED_MEM_FREE subcommand will be returned to the VTL in
988 order to ask it to free that buffer.
990 Vladislav Bolkhovitin