Add support for PERSISTENT_RESERVE_IN and add a simple test for READ_KEYS
This commit is contained in:
@@ -150,7 +150,8 @@ bin_iscsi_test_SOURCES = test-tool/iscsi-test.c \
|
||||
test-tool/1031_unsolicited_data_out.c \
|
||||
test-tool/1040_saturate_maxcmdsn.c \
|
||||
test-tool/1041_unsolicited_immediate_data.c \
|
||||
test-tool/1042_unsolicited_nonimmediate_data.c
|
||||
test-tool/1042_unsolicited_nonimmediate_data.c \
|
||||
test-tool/1100_persistent_reserve_in_read_keys_simple.c
|
||||
|
||||
endif
|
||||
|
||||
|
||||
@@ -773,6 +773,11 @@ struct unmap_list {
|
||||
uint32_t num;
|
||||
};
|
||||
|
||||
EXTERN struct scsi_task *
|
||||
iscsi_persistent_reserve_in_task(struct iscsi_context *iscsi, int lun,
|
||||
int sa, uint16_t xferlen,
|
||||
iscsi_command_cb cb, void *private_data);
|
||||
|
||||
EXTERN struct scsi_task *
|
||||
iscsi_unmap_task(struct iscsi_context *iscsi, int lun, int anchor, int group,
|
||||
struct unmap_list *list, int list_len,
|
||||
@@ -946,6 +951,9 @@ iscsi_writesame16_sync(struct iscsi_context *iscsi, int lun,
|
||||
int wrprotect, int group);
|
||||
|
||||
EXTERN struct scsi_task *
|
||||
iscsi_persistent_reserve_in_sync(struct iscsi_context *iscsi, int lun,
|
||||
int sa, uint16_t xferlen);
|
||||
EXTERN struct scsi_task *
|
||||
iscsi_unmap_sync(struct iscsi_context *iscsi, int lun, int anchor, int group,
|
||||
struct unmap_list *list, int list_len);
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ enum scsi_opcode {
|
||||
SCSI_OPCODE_WRITE_SAME10 = 0x41,
|
||||
SCSI_OPCODE_UNMAP = 0x42,
|
||||
SCSI_OPCODE_READTOC = 0x43,
|
||||
SCSI_OPCODE_PERSISTENT_RESERVE_IN = 0x5E,
|
||||
SCSI_OPCODE_READ16 = 0x88,
|
||||
SCSI_OPCODE_COMPARE_AND_WRITE = 0x89,
|
||||
SCSI_OPCODE_WRITE16 = 0x8A,
|
||||
@@ -66,6 +67,13 @@ enum scsi_opcode {
|
||||
SCSI_OPCODE_VERIFY12 = 0xAF
|
||||
};
|
||||
|
||||
enum scsi_persistent_in_sa {
|
||||
SCSI_PERSISTENT_RESERVE_READ_KEYS = 0,
|
||||
SCSI_PERSISTENT_RESERVE_READ_RESERVATION = 1,
|
||||
SCSI_PERSISTENT_RESERVE_REPORT_CAPABILITIES = 2,
|
||||
SCSI_PERSISTENT_RESERVE_READ_FULL_STATUS = 3
|
||||
};
|
||||
|
||||
enum scsi_service_action_in {
|
||||
SCSI_READCAPACITY16 = 0x10,
|
||||
SCSI_GET_LBA_STATUS = 0x12
|
||||
@@ -718,6 +726,7 @@ EXTERN struct scsi_task *scsi_cdb_serviceactionin16(enum scsi_service_action_in
|
||||
EXTERN struct scsi_task *scsi_cdb_readcapacity16(void);
|
||||
EXTERN struct scsi_task *scsi_cdb_get_lba_status(uint64_t starting_lba, uint32_t alloc_len);
|
||||
EXTERN struct scsi_task *scsi_cdb_unmap(int anchor, int group, uint16_t xferlen);
|
||||
EXTERN struct scsi_task *scsi_cdb_persistent_reserve_in(enum scsi_persistent_in_sa sa, uint16_t xferlen);
|
||||
EXTERN struct scsi_task *scsi_cdb_writesame10(int wrprotect, int anchor, int unmap, int pbdata, int lbdata, uint32_t lba, int group, uint16_t num_blocks);
|
||||
EXTERN struct scsi_task *scsi_cdb_writesame16(int wrprotect, int anchor, int unmap, int pbdata, int lbdata, uint64_t lba, int group, uint32_t num_blocks);
|
||||
EXTERN struct scsi_task *scsi_cdb_prefetch10(uint32_t lba, int num_blocks, int immed, int group);
|
||||
|
||||
@@ -1254,6 +1254,28 @@ iscsi_synchronizecache16_task(struct iscsi_context *iscsi, int lun, uint64_t lba
|
||||
return task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_persistent_reserve_in_task(struct iscsi_context *iscsi, int lun,
|
||||
int sa, uint16_t xferlen,
|
||||
iscsi_command_cb cb, void *private_data)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
task = scsi_cdb_persistent_reserve_in(sa, xferlen);
|
||||
if (task == NULL) {
|
||||
iscsi_set_error(iscsi, "Out-of-memory: Failed to create "
|
||||
"persistent-reserver-in 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,
|
||||
|
||||
@@ -28,6 +28,8 @@ iscsi_modesense6_task
|
||||
iscsi_nop_out_async
|
||||
iscsi_parse_full_url
|
||||
iscsi_parse_portal_url
|
||||
iscsi_persistent_reserve_in_task
|
||||
iscsi_persistent_reserve_in_sync
|
||||
iscsi_prefetch10_sync
|
||||
iscsi_prefetch10_task
|
||||
iscsi_prefetch16_sync
|
||||
@@ -133,6 +135,7 @@ scsi_association_to_str
|
||||
scsi_cdb_inquiry
|
||||
scsi_cdb_get_lba_status
|
||||
scsi_cdb_modesense6
|
||||
scsi_cdb_persistent_reserve_in
|
||||
scsi_cdb_prefetch10
|
||||
scsi_cdb_prefetch16
|
||||
scsi_cdb_preventallow
|
||||
|
||||
@@ -26,6 +26,8 @@ iscsi_modesense6_task
|
||||
iscsi_nop_out_async
|
||||
iscsi_parse_full_url
|
||||
iscsi_parse_portal_url
|
||||
iscsi_persistent_reserve_in_task
|
||||
iscsi_persistent_reserve_in_sync
|
||||
iscsi_prefetch10_sync
|
||||
iscsi_prefetch10_task
|
||||
iscsi_prefetch16_sync
|
||||
@@ -131,6 +133,7 @@ scsi_association_to_str
|
||||
scsi_cdb_inquiry
|
||||
scsi_cdb_get_lba_status
|
||||
scsi_cdb_modesense6
|
||||
scsi_cdb_persistent_reserve_in
|
||||
scsi_cdb_prefetch10
|
||||
scsi_cdb_prefetch16
|
||||
scsi_cdb_preventallow
|
||||
|
||||
@@ -1611,6 +1611,37 @@ scsi_cdb_unmap(int anchor, int group, uint16_t xferlen)
|
||||
return task;
|
||||
}
|
||||
|
||||
/*
|
||||
* PERSISTENT_RESEERVE_IN
|
||||
*/
|
||||
struct scsi_task *
|
||||
scsi_cdb_persistent_reserve_in(enum scsi_persistent_in_sa sa, uint16_t xferlen)
|
||||
{
|
||||
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_PERSISTENT_RESERVE_IN;
|
||||
|
||||
task->cdb[1] |= sa & 0x1f;
|
||||
|
||||
scsi_set_uint16(&task->cdb[7], xferlen);
|
||||
|
||||
task->cdb_size = 10;
|
||||
if (xferlen != 0) {
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
} else {
|
||||
task->xfer_dir = SCSI_XFER_NONE;
|
||||
}
|
||||
task->expxferlen = xferlen;
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
/*
|
||||
* WRITE_SAME10
|
||||
*/
|
||||
|
||||
20
lib/sync.c
20
lib/sync.c
@@ -798,6 +798,26 @@ iscsi_writesame16_sync(struct iscsi_context *iscsi, int lun,
|
||||
return state.task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_persistent_reserve_in_sync(struct iscsi_context *iscsi, int lun,
|
||||
int sa, uint16_t xferlen)
|
||||
{
|
||||
struct iscsi_sync_state state;
|
||||
|
||||
memset(&state, 0, sizeof(state));
|
||||
|
||||
if (iscsi_persistent_reserve_in_task(iscsi, lun, sa, xferlen,
|
||||
scsi_sync_cb, &state) == NULL) {
|
||||
iscsi_set_error(iscsi,
|
||||
"Failed to send PERSISTENT_RESERVE_IN 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)
|
||||
|
||||
111
test-tool/1100_persistent_reserve_in_read_keys_simple.c
Normal file
111
test-tool/1100_persistent_reserve_in_read_keys_simple.c
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
Copyright (C) 2012 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T1100_persistent_reserve_in_read_keys_simple(const char *initiator, const char *url, int data_loss _U_, int show_info)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun, al;
|
||||
|
||||
printf("1100_persistent_reserve_in_read_keys_simple:\n");
|
||||
printf("============================================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic PERSISTENT_RESERVE_IN/READ_KEYS functionality.\n");
|
||||
printf("1, Verify that READ_KEYS works.\n"),
|
||||
printf("2, Verify that DATA-IN is at least 8 bytes.\n");
|
||||
printf("3, Verify that ADDITIONAL_LENGTH matches DATA-IN size.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* Verify that PERSISTENT_RESERVE_IN/READ_KEYS works */
|
||||
printf("Send PERSISTENT_RESERVE_IN/READ_KEYS ... ");
|
||||
task = iscsi_persistent_reserve_in_sync(iscsi, lun,
|
||||
SCSI_PERSISTENT_RESERVE_READ_KEYS,
|
||||
16384);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PERSISTENT_RESERVE_IN command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_CHECK_CONDITION
|
||||
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
|
||||
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("PERSISTENT_RESERVE_IN Not Supported\n");
|
||||
ret = -2;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PERSISTENT_RESERVE_IN command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Verify that DATA-IN was at least 8 bytes */
|
||||
printf("Verify that DATA-IN is at least 8 bytes ... ");
|
||||
if (task->datain.size < 8) {
|
||||
printf("[FAILED]\n");
|
||||
printf("DATA-IN returned less than 8 bytes\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Verify that ADDITIONAL_LENGTH matches DATA-IN size */
|
||||
printf("Verify that ADDITIONAL_LENGTH matches DATA-IN size ... ");
|
||||
al = ntohl(*(uint32_t *)&task->datain.data[4]);
|
||||
if (al != task->datain.size - 8) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ADDITIONAL_LENGTH was %d bytes but %d was expected.\n",
|
||||
al, task->datain.size - 8);
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -253,6 +253,9 @@ struct scsi_test tests[] = {
|
||||
{ "T1041_unsolicited_immediate_data", T1041_unsolicited_immediate_data },
|
||||
{ "T1042_unsolicited_nonimmediate_data",T1042_unsolicited_nonimmediate_data },
|
||||
|
||||
/* PERSISTENT_RESERVE_IN */
|
||||
{ "T1100_persistent_reserve_in_read_keys_simple", T1100_persistent_reserve_in_read_keys_simple },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
@@ -185,3 +185,4 @@ int T1031_unsolicited_data_out(const char *initiator, const char *url, int data_
|
||||
int T1040_saturate_maxcmdsn(const char *initiator, const char *url, int data_loss, int show_info);
|
||||
int T1041_unsolicited_immediate_data(const char *initiator, const char *url, int data_loss, int show_info);
|
||||
int T1042_unsolicited_nonimmediate_data(const char *initiator, const char *url, int data_loss, int show_info);
|
||||
int T1100_persistent_reserve_in_read_keys_simple(const char *initiator, const char *url, int data_loss, int show_info);
|
||||
|
||||
Reference in New Issue
Block a user