test-tool: Split send_scsi_command()
This patch does not change any functionality. Signed-off-by: Bart Van Assche <bvanassche@acm.org>
This commit is contained in:
@@ -267,65 +267,10 @@ static size_t iov_tot_len(struct scsi_iovec *iov, int niov)
|
||||
len += iov[i].iov_len;
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi_task *task, struct iscsi_data *d)
|
||||
static struct scsi_task *
|
||||
sg_send_scsi_cmd(struct scsi_device *sdev, struct scsi_task *task)
|
||||
{
|
||||
static time_t last_time = 0;
|
||||
|
||||
/* We got an actual buffer from the application. Convert it to
|
||||
* a data-out iovector.
|
||||
* We need to attach the iovector to the task before calling
|
||||
* iscsi_scsi_command_sync() as iSER needs all iovectors to be setup
|
||||
* before we queue the task.
|
||||
*/
|
||||
if (d != NULL && d->data != NULL) {
|
||||
struct scsi_iovec *iov;
|
||||
|
||||
iov = scsi_malloc(task, sizeof(struct scsi_iovec));
|
||||
iov->iov_base = d->data;
|
||||
iov->iov_len = d->size;
|
||||
switch (task->xfer_dir) {
|
||||
case SCSI_XFER_WRITE:
|
||||
scsi_task_set_iov_out(task, iov, 1);
|
||||
break;
|
||||
case SCSI_XFER_READ:
|
||||
scsi_task_set_iov_in(task, iov, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (sdev->iscsi_url) {
|
||||
time_t current_time = time(NULL);
|
||||
|
||||
free(sdev->error_str);
|
||||
sdev->error_str = NULL;
|
||||
task = iscsi_scsi_command_sync(sdev->iscsi_ctx, sdev->iscsi_lun, task, NULL);
|
||||
if (task == NULL) {
|
||||
sdev->error_str = strdup(iscsi_get_error(sdev->iscsi_ctx));
|
||||
}
|
||||
|
||||
if (current_time > last_time + 1) {
|
||||
int i;
|
||||
|
||||
/* Device [0] is where we are doing all the I/O
|
||||
* so it will always work the socket and respond
|
||||
* to NOPs from the target.
|
||||
* But we need to trigger a service event every
|
||||
* now and then on all the other devices to ensure that
|
||||
* we detect and respond to any NOPs.
|
||||
*/
|
||||
for (i = 1; i < mp_num_sds; i++) {
|
||||
iscsi_service(mp_sds[i]->iscsi_ctx, POLLIN|POLLOUT);
|
||||
}
|
||||
last_time = current_time;
|
||||
}
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
#ifdef HAVE_SG_IO
|
||||
if (sdev->sgio_dev) {
|
||||
sg_io_hdr_t io_hdr;
|
||||
unsigned char sense[32];
|
||||
const unsigned int sense_len = sizeof(sense);
|
||||
@@ -401,7 +346,6 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi
|
||||
sdev->error_str = strdup(buf);
|
||||
return task;
|
||||
}
|
||||
|
||||
if (io_hdr.status == SCSI_STATUS_RESERVATION_CONFLICT) {
|
||||
task->status = SCSI_STATUS_RESERVATION_CONFLICT;
|
||||
free(sdev->error_str);
|
||||
@@ -440,6 +384,67 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi
|
||||
return task;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi_task *task, struct iscsi_data *d)
|
||||
{
|
||||
static time_t last_time = 0;
|
||||
|
||||
/* We got an actual buffer from the application. Convert it to
|
||||
* a data-out iovector.
|
||||
* We need to attach the iovector to the task before calling
|
||||
* iscsi_scsi_command_sync() as iSER needs all iovectors to be setup
|
||||
* before we queue the task.
|
||||
*/
|
||||
if (d != NULL && d->data != NULL) {
|
||||
struct scsi_iovec *iov;
|
||||
|
||||
iov = scsi_malloc(task, sizeof(struct scsi_iovec));
|
||||
iov->iov_base = d->data;
|
||||
iov->iov_len = d->size;
|
||||
switch (task->xfer_dir) {
|
||||
case SCSI_XFER_WRITE:
|
||||
scsi_task_set_iov_out(task, iov, 1);
|
||||
break;
|
||||
case SCSI_XFER_READ:
|
||||
scsi_task_set_iov_in(task, iov, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (sdev->iscsi_url) {
|
||||
time_t current_time = time(NULL);
|
||||
|
||||
free(sdev->error_str);
|
||||
sdev->error_str = NULL;
|
||||
task = iscsi_scsi_command_sync(sdev->iscsi_ctx, sdev->iscsi_lun, task, NULL);
|
||||
if (task == NULL) {
|
||||
sdev->error_str = strdup(iscsi_get_error(sdev->iscsi_ctx));
|
||||
}
|
||||
|
||||
if (current_time > last_time + 1) {
|
||||
int i;
|
||||
|
||||
/* Device [0] is where we are doing all the I/O
|
||||
* so it will always work the socket and respond
|
||||
* to NOPs from the target.
|
||||
* But we need to trigger a service event every
|
||||
* now and then on all the other devices to ensure that
|
||||
* we detect and respond to any NOPs.
|
||||
*/
|
||||
for (i = 1; i < mp_num_sds; i++) {
|
||||
iscsi_service(mp_sds[i]->iscsi_ctx, POLLIN|POLLOUT);
|
||||
}
|
||||
last_time = current_time;
|
||||
}
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
#ifdef HAVE_SG_IO
|
||||
if (sdev->sgio_dev)
|
||||
return sg_send_scsi_cmd(sdev, task);
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user