Initial support for PERSISTENT_RESERVER_OUT and add a simple test to show the api

This commit is contained in:
Ronnie Sahlberg
2012-12-17 21:25:46 -08:00
parent d324a94051
commit 2a74fc00bc
11 changed files with 296 additions and 3 deletions

View File

@@ -1276,6 +1276,28 @@ iscsi_persistent_reserve_in_task(struct iscsi_context *iscsi, int lun,
return task;
}
struct scsi_task *
iscsi_persistent_reserve_out_task(struct iscsi_context *iscsi, int lun,
int sa, int scope, int type, void *param,
iscsi_command_cb cb, void *private_data)
{
struct scsi_task *task;
task = scsi_cdb_persistent_reserve_out(sa, scope, type, param);
if (task == NULL) {
iscsi_set_error(iscsi, "Out-of-memory: Failed to create "
"persistent-reserver-out 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_prefetch10_task(struct iscsi_context *iscsi, int lun, uint32_t lba,
int num_blocks, int immed, int group,

View File

@@ -30,6 +30,8 @@ iscsi_parse_full_url
iscsi_parse_portal_url
iscsi_persistent_reserve_in_task
iscsi_persistent_reserve_in_sync
iscsi_persistent_reserve_out_task
iscsi_persistent_reserve_out_sync
iscsi_prefetch10_sync
iscsi_prefetch10_task
iscsi_prefetch16_sync
@@ -136,6 +138,7 @@ scsi_cdb_inquiry
scsi_cdb_get_lba_status
scsi_cdb_modesense6
scsi_cdb_persistent_reserve_in
scsi_cdb_persistent_reserve_out
scsi_cdb_prefetch10
scsi_cdb_prefetch16
scsi_cdb_preventallow

View File

@@ -28,6 +28,8 @@ iscsi_parse_full_url
iscsi_parse_portal_url
iscsi_persistent_reserve_in_task
iscsi_persistent_reserve_in_sync
iscsi_persistent_reserve_out_task
iscsi_persistent_reserve_out_sync
iscsi_prefetch10_sync
iscsi_prefetch10_task
iscsi_prefetch16_sync
@@ -134,6 +136,7 @@ scsi_cdb_inquiry
scsi_cdb_get_lba_status
scsi_cdb_modesense6
scsi_cdb_persistent_reserve_in
scsi_cdb_persistent_reserve_out
scsi_cdb_prefetch10
scsi_cdb_prefetch16
scsi_cdb_preventallow

View File

@@ -38,6 +38,8 @@
#include "slist.h"
#include "scsi-lowlevel.h"
void scsi_task_set_iov_out(struct scsi_task *task, struct scsi_iovec *iov, int niov);
struct scsi_allocated_memory {
struct scsi_allocated_memory *next;
char buf[0];
@@ -186,6 +188,19 @@ scsi_get_uint16(const unsigned char *c)
return ntohs(*(uint16_t *)c);
}
inline void
scsi_set_uint64(unsigned char *c, uint64_t v)
{
uint32_t val;
val = (v >> 32) & 0xffffffff;
*(uint32_t *)c = htonl(val);
c += 4;
val = v & 0xffffffff;
*(uint32_t *)c = htonl(val);
}
inline void
scsi_set_uint32(unsigned char *c, uint32_t val)
{
@@ -1702,6 +1717,91 @@ scsi_cdb_persistent_reserve_in(enum scsi_persistent_in_sa sa, uint16_t xferlen)
return task;
}
/*
* PERSISTENT_RESERVE_OUT
*/
struct scsi_task *
scsi_cdb_persistent_reserve_out(enum scsi_persistent_out_sa sa, enum scsi_persistent_out_scope scope, enum scsi_persistent_out_type type, void *param)
{
struct scsi_task *task;
struct scsi_persistent_reserve_out_basic *basic;
struct scsi_iovec *iov;
unsigned char *buf;
int xferlen;
task = malloc(sizeof(struct scsi_task));
if (task == NULL) {
return NULL;
}
iov = scsi_malloc(task, sizeof(struct scsi_iovec));
if (iov == NULL) {
free(task);
return NULL;
}
switch(sa) {
case SCSI_PERSISTENT_RESERVE_REGISTER:
case SCSI_PERSISTENT_RESERVE_RESERVE:
case SCSI_PERSISTENT_RESERVE_RELEASE:
case SCSI_PERSISTENT_RESERVE_CLEAR:
case SCSI_PERSISTENT_RESERVE_PREEMPT:
case SCSI_PERSISTENT_RESERVE_PREEMPT_AND_ABORT:
case SCSI_PERSISTENT_RESERVE_REGISTER_AND_IGNORE_EXISTING_KEY:
basic = param;
xferlen = 24;
buf = scsi_malloc(task, xferlen);
if (buf == NULL) {
free(task);
free(iov);
return NULL;
}
memset(buf, 0, xferlen);
scsi_set_uint64(&buf[0], basic->reservation_key);
scsi_set_uint64(&buf[8], basic->service_action_reservation_key);
if (basic->spec_i_pt) {
buf[20] |= 0x08;
}
if (basic->all_tg_pt) {
buf[20] |= 0x04;
}
if (basic->aptpl) {
buf[20] |= 0x01;
}
break;
case SCSI_PERSISTENT_RESERVE_REGISTER_AND_MOVE:
/* XXX FIXME */
free(task);
free(iov);
return NULL;
default:
free(task);
free(iov);
return NULL;
}
memset(task, 0, sizeof(struct scsi_task));
task->cdb[0] = SCSI_OPCODE_PERSISTENT_RESERVE_OUT;
task->cdb[1] |= sa & 0x1f;
task->cdb[2] = ((scope << 4) & 0xf0) | (type & 0x0f);
scsi_set_uint32(&task->cdb[5], xferlen);
task->cdb_size = 10;
task->xfer_dir = SCSI_XFER_WRITE;
task->expxferlen = xferlen;
iov->iov_base = buf;
iov->iov_len = xferlen;
scsi_task_set_iov_out(task, iov, 1);
return task;
}
/*
* WRITE_SAME10
*/

View File

@@ -818,6 +818,27 @@ iscsi_persistent_reserve_in_sync(struct iscsi_context *iscsi, int lun,
return state.task;
}
struct scsi_task *
iscsi_persistent_reserve_out_sync(struct iscsi_context *iscsi, int lun,
int sa, int scope, int type, void *param)
{
struct iscsi_sync_state state;
memset(&state, 0, sizeof(state));
if (iscsi_persistent_reserve_out_task(iscsi, lun,
sa, scope, type, param,
scsi_sync_cb, &state) == NULL) {
iscsi_set_error(iscsi,
"Failed to send PERSISTENT_RESERVE_OUT command");
return NULL;
}
event_loop(iscsi, &state);
return state.task;
}
struct scsi_task *
iscsi_unmap_sync(struct iscsi_context *iscsi, int lun, int anchor, int group,
struct unmap_list *list, int list_len)