VERIFY10: Add support for VERIFY10. Also add a simple test for verify10

This commit is contained in:
Ronnie Sahlberg
2012-01-26 15:47:14 +11:00
parent b9bae6f4a7
commit cff996a96d
11 changed files with 256 additions and 4 deletions

View File

@@ -46,6 +46,7 @@ iscsi_readcapacity10_task
iscsi_synchronizecache10_task
iscsi_read6_task
iscsi_read10_task
iscsi_verify10_task
iscsi_write10_task
iscsi_modesense6_task
iscsi_scsi_command_sync
@@ -56,6 +57,7 @@ iscsi_readcapacity10_sync
iscsi_synchronizecache10_sync
iscsi_read6_sync
iscsi_read10_sync
iscsi_verify10_sync
iscsi_write10_sync
iscsi_task_cancel
poll
@@ -81,6 +83,7 @@ scsi_datain_getfullsize
scsi_datain_unmarshall
scsi_cdb_read6
scsi_cdb_read10
scsi_cdb_verify10
scsi_cdb_write10
scsi_cdb_synchronizecache10

View File

@@ -677,7 +677,40 @@ iscsi_write10_task(struct iscsi_context *iscsi, int lun, unsigned char *data,
task = scsi_cdb_write10(lba, datalen, fua, fuanv, blocksize);
if (task == NULL) {
iscsi_set_error(iscsi, "Out-of-memory: Failed to create "
"read10 cdb.");
"write10 cdb.");
return NULL;
}
outdata.data = data;
outdata.size = datalen;
if (iscsi_scsi_command_async(iscsi, lun, task, cb, &outdata,
private_data) != 0) {
scsi_free_scsi_task(task);
return NULL;
}
return task;
}
struct scsi_task *
iscsi_verify10_task(struct iscsi_context *iscsi, int lun, unsigned char *data,
uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize,
iscsi_command_cb cb, void *private_data)
{
struct scsi_task *task;
struct iscsi_data outdata;
if (datalen % blocksize != 0) {
iscsi_set_error(iscsi, "Datalen:%d is not a multiple of the "
"blocksize:%d.", datalen, blocksize);
return NULL;
}
task = scsi_cdb_verify10(lba, datalen, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
iscsi_set_error(iscsi, "Out-of-memory: Failed to create "
"verify10 cdb.");
return NULL;
}

View File

@@ -632,6 +632,52 @@ scsi_cdb_write10(uint32_t lba, uint32_t xferlen, int fua, int fuanv, int blocksi
}
/*
* VERIFY10
*/
struct scsi_task *
scsi_cdb_verify10(uint32_t lba, uint32_t xferlen, int vprotect, int dpo, int bytchk, int blocksize)
{
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_VERIFY10;
if (vprotect) {
task->cdb[1] |= ((vprotect << 5) & 0xe0);
}
if (dpo) {
task->cdb[1] |= 0x10;
}
if (bytchk) {
task->cdb[1] |= 0x02;
}
*(uint32_t *)&task->cdb[2] = htonl(lba);
*(uint16_t *)&task->cdb[7] = htons(xferlen/blocksize);
task->cdb_size = 10;
if (xferlen != 0) {
task->xfer_dir = SCSI_XFER_WRITE;
} else {
task->xfer_dir = SCSI_XFER_NONE;
}
task->expxferlen = xferlen;
task->params.verify10.lba = lba;
task->params.verify10.num_blocks = xferlen/blocksize;
task->params.verify10.vprotect = vprotect;
task->params.verify10.dpo = dpo;
task->params.verify10.bytchk = bytchk;
return task;
}
/*
* MODESENSE6

View File

@@ -322,6 +322,26 @@ iscsi_write10_sync(struct iscsi_context *iscsi, int lun, unsigned char *data, ui
return state.task;
}
struct scsi_task *
iscsi_verify10_sync(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba,
int vprotect, int dpo, int bytchk, int blocksize)
{
struct iscsi_sync_state state;
memset(&state, 0, sizeof(state));
if (iscsi_verify10_task(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize,
scsi_sync_cb, &state) == NULL) {
iscsi_set_error(iscsi,
"Failed to send Verify10 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)