Add MaintenanceIn: Report Supported Opcodes (all) and testcase.
This commit is contained in:
@@ -52,6 +52,8 @@ iscsi_reserve6_sync
|
||||
iscsi_reserve6_task
|
||||
iscsi_release6_sync
|
||||
iscsi_release6_task
|
||||
iscsi_report_supported_opcodes_sync
|
||||
iscsi_report_supported_opcodes_task
|
||||
iscsi_reconnect
|
||||
iscsi_set_noautoreconnect
|
||||
iscsi_reportluns_sync
|
||||
@@ -130,6 +132,7 @@ scsi_cdb_readcapacity16
|
||||
scsi_cdb_readtoc
|
||||
scsi_cdb_reserve6
|
||||
scsi_cdb_release6
|
||||
scsi_cdb_report_supported_opcodes
|
||||
scsi_cdb_serviceactionin16
|
||||
scsi_cdb_startstopunit
|
||||
scsi_cdb_synchronizecache10
|
||||
|
||||
@@ -50,6 +50,8 @@ iscsi_reserve6_sync
|
||||
iscsi_reserve6_task
|
||||
iscsi_release6_sync
|
||||
iscsi_release6_task
|
||||
iscsi_report_supported_opcodes_sync
|
||||
iscsi_report_supported_opcodes_task
|
||||
iscsi_reconnect
|
||||
iscsi_set_noautoreconnect
|
||||
iscsi_reportluns_sync
|
||||
@@ -128,6 +130,7 @@ scsi_cdb_readcapacity16
|
||||
scsi_cdb_readtoc
|
||||
scsi_cdb_reserve6
|
||||
scsi_cdb_release6
|
||||
scsi_cdb_report_supported_opcodes
|
||||
scsi_cdb_serviceactionin16
|
||||
scsi_cdb_startstopunit
|
||||
scsi_cdb_synchronizecache10
|
||||
|
||||
@@ -1541,6 +1541,28 @@ iscsi_release6_task(struct iscsi_context *iscsi, int lun,
|
||||
return task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_report_supported_opcodes_task(struct iscsi_context *iscsi,
|
||||
int lun, int return_timeouts, int maxsize,
|
||||
iscsi_command_cb cb, void *private_data)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
task = scsi_cdb_report_supported_opcodes(return_timeouts, maxsize);
|
||||
if (task == NULL) {
|
||||
iscsi_set_error(iscsi, "Out-of-memory: Failed to create "
|
||||
"Maintenance In/Read Supported Op Codes cdb.");
|
||||
return NULL;
|
||||
}
|
||||
if (iscsi_scsi_command_async(iscsi, lun, task, cb, NULL,
|
||||
private_data) != 0) {
|
||||
scsi_free_scsi_task(task);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_scsi_get_task_from_pdu(struct iscsi_pdu *pdu)
|
||||
{
|
||||
|
||||
@@ -563,6 +563,120 @@ scsi_serviceactionin_datain_unmarshall(struct scsi_task *task)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* parse the data in blob and calcualte the size of a full report luns
|
||||
* datain structure
|
||||
*/
|
||||
static int
|
||||
scsi_maintenancein_datain_getfullsize(struct scsi_task *task)
|
||||
{
|
||||
|
||||
switch (task->params.maintenancein.sa) {
|
||||
case SCSI_REPORT_SUPPORTED_OP_CODES:
|
||||
return ntohl(*(uint32_t *)&(task->datain.data[0])) + 4;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* maintenance_in unmarshall
|
||||
*/
|
||||
static void *
|
||||
scsi_maintenancein_datain_unmarshall(struct scsi_task *task)
|
||||
{
|
||||
struct scsi_report_supported_op_codes *rsoc;
|
||||
struct scsi_command_descriptor *desc, *datain;
|
||||
uint32_t len, i;
|
||||
int return_timeouts, desc_size;
|
||||
|
||||
switch (task->params.maintenancein.sa) {
|
||||
case SCSI_REPORT_SUPPORTED_OP_CODES:
|
||||
if (task->datain.size < 4) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
len = ntohl(*(uint32_t *)&(task->datain.data[0]));
|
||||
rsoc = scsi_malloc(task, sizeof(struct scsi_report_supported_op_codes) + len);
|
||||
if (rsoc == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
/* Does the descriptor include command timeout info? */
|
||||
return_timeouts = task->params.maintenancein.params.reportsupported.return_timeouts;
|
||||
|
||||
/* Size of descriptor depends on whether timeout included. */
|
||||
desc_size = sizeof (struct scsi_command_descriptor);
|
||||
if (return_timeouts) {
|
||||
desc_size += sizeof (struct scsi_op_timeout_descriptor);
|
||||
}
|
||||
rsoc->num_descriptors = len / desc_size;
|
||||
|
||||
desc = &rsoc->descriptors[0];
|
||||
datain = (struct scsi_command_descriptor *)&task->datain.data[4];
|
||||
|
||||
for (i=0; i < rsoc->num_descriptors; i++) {
|
||||
desc->op_code = datain->op_code;
|
||||
desc->service_action = ntohs(datain->service_action);
|
||||
desc->cdb_length = ntohs(datain->cdb_length);
|
||||
if (return_timeouts) {
|
||||
desc->to[0].descriptor_length = ntohs(datain->to[0].descriptor_length);
|
||||
desc->to[0].command_specific = datain->to[0].command_specific;
|
||||
desc->to[0].nominal_processing_timeout
|
||||
= ntohl(datain->to[0].nominal_processing_timeout);
|
||||
desc->to[0].recommended_timeout
|
||||
= ntohl(datain->to[0].recommended_timeout);
|
||||
}
|
||||
desc = (struct scsi_command_descriptor *)((char *)desc + desc_size);
|
||||
datain = (struct scsi_command_descriptor *)((char *)datain + desc_size);
|
||||
}
|
||||
|
||||
return rsoc;
|
||||
};
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* MAINTENANCE In / Read Supported Op Codes
|
||||
*/
|
||||
struct scsi_task *
|
||||
scsi_cdb_report_supported_opcodes(int return_timeouts, uint32_t alloc_len)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_MAINTENANCE_IN;
|
||||
task->cdb[1] = SCSI_REPORT_SUPPORTED_OP_CODES;
|
||||
task->cdb[2] = SCSI_REPORT_SUPPORTING_OPS_ALL;
|
||||
|
||||
if (return_timeouts) {
|
||||
task->cdb[2] |= 0x80;
|
||||
}
|
||||
|
||||
*(uint32_t *)&task->cdb[6] = htonl(alloc_len);
|
||||
|
||||
task->cdb_size = 12;
|
||||
if (alloc_len != 0) {
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
} else {
|
||||
task->xfer_dir = SCSI_XFER_NONE;
|
||||
}
|
||||
task->expxferlen = alloc_len;
|
||||
|
||||
task->params.maintenancein.sa = SCSI_REPORT_SUPPORTED_OP_CODES;
|
||||
task->params.maintenancein.params.reportsupported.return_timeouts = return_timeouts;
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
/*
|
||||
* parse the data in blob and calcualte the size of a full
|
||||
* readcapacity10 datain structure
|
||||
@@ -2172,6 +2286,8 @@ scsi_datain_getfullsize(struct scsi_task *task)
|
||||
return scsi_readtoc_datain_getfullsize(task);
|
||||
case SCSI_OPCODE_REPORTLUNS:
|
||||
return scsi_reportluns_datain_getfullsize(task);
|
||||
case SCSI_OPCODE_MAINTENANCE_IN:
|
||||
return scsi_maintenancein_datain_getfullsize(task);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -2196,6 +2312,8 @@ scsi_datain_unmarshall(struct scsi_task *task)
|
||||
return scsi_reportluns_datain_unmarshall(task);
|
||||
case SCSI_OPCODE_SERVICE_ACTION_IN:
|
||||
return scsi_serviceactionin_datain_unmarshall(task);
|
||||
case SCSI_OPCODE_MAINTENANCE_IN:
|
||||
return scsi_maintenancein_datain_unmarshall(task);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
18
lib/sync.c
18
lib/sync.c
@@ -874,6 +874,24 @@ iscsi_release6_sync(struct iscsi_context *iscsi, int lun)
|
||||
return state.task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_report_supported_opcodes_sync(struct iscsi_context *iscsi, int lun, int return_timeouts, int maxsize)
|
||||
{
|
||||
struct iscsi_sync_state state;
|
||||
|
||||
memset(&state, 0, sizeof(state));
|
||||
|
||||
if (iscsi_report_supported_opcodes_task(iscsi, lun, return_timeouts, maxsize, scsi_sync_cb, &state) == NULL) {
|
||||
iscsi_set_error(iscsi, "Failed to send MaintenanceIn:"
|
||||
"Report Supported Opcodes command");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
event_loop(iscsi, &state);
|
||||
|
||||
return state.task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_scsi_command_sync(struct iscsi_context *iscsi, int lun,
|
||||
struct scsi_task *task, struct iscsi_data *data)
|
||||
|
||||
Reference in New Issue
Block a user