Implement READ/WRITE_12/16 and a simple test for read16
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
This commit is contained in:
@@ -47,8 +47,10 @@ iscsi_readcapacity16_task
|
||||
iscsi_synchronizecache10_task
|
||||
iscsi_read6_task
|
||||
iscsi_read10_task
|
||||
iscsi_read12_task
|
||||
iscsi_verify10_task
|
||||
iscsi_write10_task
|
||||
iscsi_write12_task
|
||||
iscsi_writesame10_task
|
||||
iscsi_writesame16_task
|
||||
iscsi_modesense6_task
|
||||
@@ -61,8 +63,10 @@ iscsi_readcapacity16_sync
|
||||
iscsi_synchronizecache10_sync
|
||||
iscsi_read6_sync
|
||||
iscsi_read10_sync
|
||||
iscsi_read12_sync
|
||||
iscsi_verify10_sync
|
||||
iscsi_write10_sync
|
||||
iscsi_write12_sync
|
||||
iscsi_writesame10_sync
|
||||
iscsi_writesame16_sync
|
||||
iscsi_scsi_task_cancel
|
||||
|
||||
@@ -681,6 +681,66 @@ iscsi_read10_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
|
||||
return task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_read12_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
|
||||
uint32_t datalen, int blocksize,
|
||||
int rdprotect, int dpo, int fua, int fua_nv, int group_number,
|
||||
iscsi_command_cb cb, void *private_data)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
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_read12(lba, datalen, blocksize, rdprotect,
|
||||
dpo, fua, fua_nv, group_number);
|
||||
if (task == NULL) {
|
||||
iscsi_set_error(iscsi, "Out-of-memory: Failed to create "
|
||||
"read12 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_read16_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
uint32_t datalen, int blocksize,
|
||||
int rdprotect, int dpo, int fua, int fua_nv, int group_number,
|
||||
iscsi_command_cb cb, void *private_data)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
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_read16(lba, datalen, blocksize, rdprotect,
|
||||
dpo, fua, fua_nv, group_number);
|
||||
if (task == NULL) {
|
||||
iscsi_set_error(iscsi, "Out-of-memory: Failed to create "
|
||||
"read16 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_write10_task(struct iscsi_context *iscsi, int lun, unsigned char *data,
|
||||
uint32_t datalen, uint32_t lba, int fua, int fuanv, int blocksize,
|
||||
@@ -714,6 +774,76 @@ iscsi_write10_task(struct iscsi_context *iscsi, int lun, unsigned char *data,
|
||||
return task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_write12_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
|
||||
unsigned char *data, uint32_t datalen, int blocksize,
|
||||
int wrprotect, int dpo, int fua, int fua_nv, int group_number,
|
||||
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_write12(lba, datalen, blocksize, wrprotect,
|
||||
dpo, fua, fua_nv, group_number);
|
||||
if (task == NULL) {
|
||||
iscsi_set_error(iscsi, "Out-of-memory: Failed to create "
|
||||
"write12 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_write16_task(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
unsigned char *data, uint32_t datalen, int blocksize,
|
||||
int wrprotect, int dpo, int fua, int fua_nv, int group_number,
|
||||
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_write16(lba, datalen, blocksize, wrprotect,
|
||||
dpo, fua, fua_nv, group_number);
|
||||
if (task == NULL) {
|
||||
iscsi_set_error(iscsi, "Out-of-memory: Failed to create "
|
||||
"write16 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,
|
||||
|
||||
@@ -675,11 +675,104 @@ scsi_cdb_read10(uint32_t lba, uint32_t xferlen, int blocksize)
|
||||
return task;
|
||||
}
|
||||
|
||||
/*
|
||||
* READ12
|
||||
*/
|
||||
struct scsi_task *
|
||||
scsi_cdb_read12(uint32_t lba, uint32_t xferlen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group_number)
|
||||
{
|
||||
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_READ12;
|
||||
|
||||
task->cdb[1] |= ((rdprotect & 0x07) << 5);
|
||||
if (dpo) {
|
||||
task->cdb[1] |= 0x10;
|
||||
}
|
||||
if (fua) {
|
||||
task->cdb[1] |= 0x08;
|
||||
}
|
||||
if (fua_nv) {
|
||||
task->cdb[1] |= 0x02;
|
||||
}
|
||||
|
||||
*(uint32_t *)&task->cdb[2] = htonl(lba);
|
||||
*(uint32_t *)&task->cdb[6] = htonl(xferlen/blocksize);
|
||||
|
||||
task->cdb[10] |= (group_number & 0x1f);
|
||||
|
||||
task->cdb_size = 12;
|
||||
if (xferlen != 0) {
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
} else {
|
||||
task->xfer_dir = SCSI_XFER_NONE;
|
||||
}
|
||||
task->expxferlen = xferlen;
|
||||
|
||||
task->params.read12.lba = lba;
|
||||
task->params.read12.num_blocks = xferlen/blocksize;
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
/*
|
||||
* READ16
|
||||
*/
|
||||
struct scsi_task *
|
||||
scsi_cdb_read16(uint64_t lba, uint32_t xferlen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group_number)
|
||||
{
|
||||
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_READ16;
|
||||
|
||||
task->cdb[1] |= ((rdprotect & 0x07) << 5);
|
||||
if (dpo) {
|
||||
task->cdb[1] |= 0x10;
|
||||
}
|
||||
if (fua) {
|
||||
task->cdb[1] |= 0x08;
|
||||
}
|
||||
if (fua_nv) {
|
||||
task->cdb[1] |= 0x02;
|
||||
}
|
||||
|
||||
*(uint32_t *)&task->cdb[2] = htonl(lba >> 32);
|
||||
*(uint32_t *)&task->cdb[6] = htonl(lba & 0xffffffff);
|
||||
*(uint32_t *)&task->cdb[10] = htonl(xferlen/blocksize);
|
||||
|
||||
task->cdb[14] |= (group_number & 0x1f);
|
||||
|
||||
task->cdb_size = 16;
|
||||
if (xferlen != 0) {
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
} else {
|
||||
task->xfer_dir = SCSI_XFER_NONE;
|
||||
}
|
||||
task->expxferlen = xferlen;
|
||||
|
||||
task->params.read16.lba = lba;
|
||||
task->params.read16.num_blocks = xferlen/blocksize;
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
/*
|
||||
* WRITE10
|
||||
*/
|
||||
struct scsi_task *
|
||||
scsi_cdb_write10(uint32_t lba, uint32_t xferlen, int fua, int fuanv, int blocksize)
|
||||
scsi_cdb_write10(uint32_t lba, uint32_t xferlen, int fua, int fua_nv, int blocksize)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
@@ -694,7 +787,7 @@ scsi_cdb_write10(uint32_t lba, uint32_t xferlen, int fua, int fuanv, int blocksi
|
||||
if (fua) {
|
||||
task->cdb[1] |= 0x08;
|
||||
}
|
||||
if (fuanv) {
|
||||
if (fua_nv) {
|
||||
task->cdb[1] |= 0x02;
|
||||
}
|
||||
|
||||
@@ -715,6 +808,98 @@ scsi_cdb_write10(uint32_t lba, uint32_t xferlen, int fua, int fuanv, int blocksi
|
||||
return task;
|
||||
}
|
||||
|
||||
/*
|
||||
* WRITE12
|
||||
*/
|
||||
struct scsi_task *
|
||||
scsi_cdb_write12(uint32_t lba, uint32_t xferlen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group_number)
|
||||
{
|
||||
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_WRITE12;
|
||||
|
||||
task->cdb[1] |= ((wrprotect & 0x07) << 5);
|
||||
if (dpo) {
|
||||
task->cdb[1] |= 0x10;
|
||||
}
|
||||
if (fua) {
|
||||
task->cdb[1] |= 0x08;
|
||||
}
|
||||
if (fua_nv) {
|
||||
task->cdb[1] |= 0x02;
|
||||
}
|
||||
|
||||
*(uint32_t *)&task->cdb[2] = htonl(lba);
|
||||
*(uint32_t *)&task->cdb[6] = htonl(xferlen/blocksize);
|
||||
|
||||
task->cdb[10] |= (group_number & 0x1f);
|
||||
|
||||
task->cdb_size = 12;
|
||||
if (xferlen != 0) {
|
||||
task->xfer_dir = SCSI_XFER_WRITE;
|
||||
} else {
|
||||
task->xfer_dir = SCSI_XFER_NONE;
|
||||
}
|
||||
task->expxferlen = xferlen;
|
||||
|
||||
task->params.write12.lba = lba;
|
||||
task->params.write12.num_blocks = xferlen/blocksize;
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
/*
|
||||
* WRITE16
|
||||
*/
|
||||
struct scsi_task *
|
||||
scsi_cdb_write16(uint64_t lba, uint32_t xferlen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group_number)
|
||||
{
|
||||
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_WRITE16;
|
||||
|
||||
task->cdb[1] |= ((wrprotect & 0x07) << 5);
|
||||
if (dpo) {
|
||||
task->cdb[1] |= 0x10;
|
||||
}
|
||||
if (fua) {
|
||||
task->cdb[1] |= 0x08;
|
||||
}
|
||||
if (fua_nv) {
|
||||
task->cdb[1] |= 0x02;
|
||||
}
|
||||
|
||||
*(uint32_t *)&task->cdb[2] = htonl(lba >> 32);
|
||||
*(uint32_t *)&task->cdb[6] = htonl(lba & 0xffffffff);
|
||||
*(uint32_t *)&task->cdb[10] = htonl(xferlen/blocksize);
|
||||
|
||||
task->cdb[14] |= (group_number & 0x1f);
|
||||
|
||||
task->cdb_size = 16;
|
||||
if (xferlen != 0) {
|
||||
task->xfer_dir = SCSI_XFER_WRITE;
|
||||
} else {
|
||||
task->xfer_dir = SCSI_XFER_NONE;
|
||||
}
|
||||
task->expxferlen = xferlen;
|
||||
|
||||
task->params.write16.lba = lba;
|
||||
task->params.write16.num_blocks = xferlen/blocksize;
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
/*
|
||||
* VERIFY10
|
||||
|
||||
90
lib/sync.c
90
lib/sync.c
@@ -271,6 +271,50 @@ iscsi_read10_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
|
||||
return state.task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_read12_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
|
||||
uint32_t datalen, int blocksize,
|
||||
int rdprotect, int dpo, int fua, int fua_nv, int group_number)
|
||||
{
|
||||
struct iscsi_sync_state state;
|
||||
|
||||
memset(&state, 0, sizeof(state));
|
||||
|
||||
if (iscsi_read12_task(iscsi, lun, lba, datalen, blocksize, rdprotect,
|
||||
dpo, fua, fua_nv, group_number,
|
||||
scsi_sync_cb, &state) == NULL) {
|
||||
iscsi_set_error(iscsi,
|
||||
"Failed to send Read12 command");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
event_loop(iscsi, &state);
|
||||
|
||||
return state.task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_read16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
uint32_t datalen, int blocksize,
|
||||
int rdprotect, int dpo, int fua, int fua_nv, int group_number)
|
||||
{
|
||||
struct iscsi_sync_state state;
|
||||
|
||||
memset(&state, 0, sizeof(state));
|
||||
|
||||
if (iscsi_read16_task(iscsi, lun, lba, datalen, blocksize, rdprotect,
|
||||
dpo, fua, fua_nv, group_number,
|
||||
scsi_sync_cb, &state) == NULL) {
|
||||
iscsi_set_error(iscsi,
|
||||
"Failed to send Read16 command");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
event_loop(iscsi, &state);
|
||||
|
||||
return state.task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_readcapacity10_sync(struct iscsi_context *iscsi, int lun, int lba,
|
||||
int pmi)
|
||||
@@ -351,6 +395,52 @@ iscsi_write10_sync(struct iscsi_context *iscsi, int lun, unsigned char *data, ui
|
||||
return state.task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_write12_sync(struct iscsi_context *iscsi, int lun, uint32_t lba,
|
||||
unsigned char *data, uint32_t datalen, int blocksize,
|
||||
int wrprotect, int dpo, int fua, int fua_nv, int group_number)
|
||||
{
|
||||
struct iscsi_sync_state state;
|
||||
|
||||
memset(&state, 0, sizeof(state));
|
||||
|
||||
if (iscsi_write12_task(iscsi, lun, lba,
|
||||
data, datalen, blocksize, wrprotect,
|
||||
dpo, fua, fua_nv, group_number,
|
||||
scsi_sync_cb, &state) == NULL) {
|
||||
iscsi_set_error(iscsi,
|
||||
"Failed to send Write12 command");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
event_loop(iscsi, &state);
|
||||
|
||||
return state.task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_write16_sync(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
unsigned char *data, uint32_t datalen, int blocksize,
|
||||
int wrprotect, int dpo, int fua, int fua_nv, int group_number)
|
||||
{
|
||||
struct iscsi_sync_state state;
|
||||
|
||||
memset(&state, 0, sizeof(state));
|
||||
|
||||
if (iscsi_write16_task(iscsi, lun, lba,
|
||||
data, datalen, blocksize, wrprotect,
|
||||
dpo, fua, fua_nv, group_number,
|
||||
scsi_sync_cb, &state) == NULL) {
|
||||
iscsi_set_error(iscsi,
|
||||
"Failed to send Write16 command");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
event_loop(iscsi, &state);
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user