Add 'zero-copy' in libiscsi for reads.
It is not real zero-copy since the data is still copied in the kernel, but it avoids copying the data inside libiscsi as well as in the callback. For SCSI tasks that will return data from the target, the application can now specify application buffers for libiscsi to read the data directly into. This is done by calling scsi_task_add_data_in_buffer(task, ... These buffers need not be linear, you can specify different areas to read into by calling this function several times. See examples/iscsiclient.c for an example.
This commit is contained in:
@@ -248,6 +248,9 @@ int iscsi_send_target_nop_out(struct iscsi_context *iscsi, uint32_t ttt);
|
||||
void iscsi_set_error(struct iscsi_context *iscsi, const char *error_string,
|
||||
...);
|
||||
|
||||
unsigned char *iscsi_get_user_in_buffer(struct iscsi_context *iscsi, struct iscsi_in_pdu *in, uint32_t pos, ssize_t *count);
|
||||
unsigned char *scsi_task_get_data_in_buffer(struct scsi_task *task, uint32_t pos, ssize_t *count);
|
||||
|
||||
unsigned long crc32c(char *buf, int len);
|
||||
|
||||
#endif /* __iscsi_private_h__ */
|
||||
|
||||
@@ -626,4 +626,29 @@ struct scsi_task *
|
||||
iscsi_synchronizecache10_sync(struct iscsi_context *iscsi, int lun, int lba,
|
||||
int num_blocks, int syncnv, int immed);
|
||||
|
||||
|
||||
/*
|
||||
* This function is used when the application wants to specify its own buffers to read the data
|
||||
* from the DATA-IN PDUs into.
|
||||
* The main use is for SCSI read operations to have them write directly into the application buffers to
|
||||
* avoid the two copies that would occur otherwise.
|
||||
* First copy from the individual DATA-IN blobs to linearize the buffer and the second in the callback
|
||||
* to copy the data from the linearized buffer into the application buffer.
|
||||
*
|
||||
* This also supports reading into a vector of buffers by calling this function multiple times.
|
||||
* The individual buffers will be filled in the same order as they were created.
|
||||
*
|
||||
* Example:
|
||||
* task = iscsi_read10_task( ( 2 512byte blocks into two buffers)
|
||||
* scsi_task_add_data_buffer(task, first_buffer, 512
|
||||
* scsi_task_add_data_buffer(task, second_buffer, 512
|
||||
*
|
||||
*
|
||||
* If you use this function you can not use task->datain in the callback.
|
||||
* task->datain.size will be 0 and
|
||||
* task->datain.data will be NULL
|
||||
*/
|
||||
int scsi_task_add_data_in_buffer(struct scsi_task *task, int len, unsigned char *buf);
|
||||
|
||||
|
||||
#endif /* __iscsi_h__ */
|
||||
|
||||
@@ -148,6 +148,8 @@ struct scsi_task {
|
||||
uint32_t itt;
|
||||
uint32_t cmdsn;
|
||||
uint32_t lun;
|
||||
|
||||
struct scsi_data_buffer *in_buffers;
|
||||
};
|
||||
|
||||
void scsi_free_scsi_task(struct scsi_task *task);
|
||||
|
||||
Reference in New Issue
Block a user