Merge pull request #20 from jongrimm/master

RESERVE6/RELEASE6 Commands + testcase.
This commit is contained in:
Ronnie Sahlberg
2012-09-27 18:39:22 -07:00
11 changed files with 443 additions and 1 deletions

View File

@@ -134,6 +134,7 @@ bin_iscsi_test_SOURCES = test-tool/iscsi-test.c \
test-tool/0403_inquiry_supported_vpd.c \
test-tool/0404_inquiry_all_reported_vpd.c \
test-tool/0410_readtoc_basic.c \
test-tool/0420_reserve6_simple.c \
\
test-tool/1000_cmdsn_invalid.c \
test-tool/1010_datasn_invalid.c \

View File

@@ -732,6 +732,15 @@ iscsi_readtoc_task(struct iscsi_context *iscsi, int lun, int msf, int format,
int track_session, int maxsize,
iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_reserve6_task(struct iscsi_context *iscsi, int lun,
iscsi_command_cb cb, void *private_data);
EXTERN struct scsi_task *
iscsi_release6_task(struct iscsi_context *iscsi, int lun,
iscsi_command_cb cb, void *private_data);
/*
* Sync commands for SCSI
*/
@@ -889,6 +898,13 @@ EXTERN struct scsi_task *
iscsi_readtoc_sync(struct iscsi_context *iscsi, int lun, int msf,
int format, int track_session, int maxsize);
EXTERN struct scsi_task *
iscsi_reserve6_sync(struct iscsi_context *iscsi, int lun);
EXTERN struct scsi_task *
iscsi_release6_sync(struct iscsi_context *iscsi, int lun);
/*
* This function is used when the application wants to specify its own buffers to read the data
* from the DATA-IN PDUs into.

View File

@@ -27,6 +27,8 @@ enum scsi_opcode {
SCSI_OPCODE_TESTUNITREADY = 0x00,
SCSI_OPCODE_READ6 = 0x08,
SCSI_OPCODE_INQUIRY = 0x12,
SCSI_OPCODE_RESERVE6 = 0x16,
SCSI_OPCODE_RELEASE6 = 0x17,
SCSI_OPCODE_MODESENSE6 = 0x1a,
SCSI_OPCODE_STARTSTOPUNIT = 0x1b,
SCSI_OPCODE_PREVENTALLOW = 0x1e,
@@ -39,7 +41,7 @@ enum scsi_opcode {
SCSI_OPCODE_SYNCHRONIZECACHE10 = 0x35,
SCSI_OPCODE_WRITE_SAME10 = 0x41,
SCSI_OPCODE_UNMAP = 0x42,
SCSI_OPCODE_READTOC = 0x43,
SCSI_OPCODE_READTOC = 0x43,
SCSI_OPCODE_READ16 = 0x88,
SCSI_OPCODE_COMPARE_AND_WRITE = 0x89,
SCSI_OPCODE_WRITE16 = 0x8A,
@@ -362,6 +364,15 @@ struct scsi_reportluns_list {
EXTERN struct scsi_task *scsi_reportluns_cdb(int report_type, int alloc_len);
/*
* RESERVE6
*/
EXTERN struct scsi_task *scsi_cdb_reserve6(void);
/*
* RELEASE6
*/
EXTERN struct scsi_task *scsi_cdb_release6(void);
/*
* READCAPACITY10
*/

View File

@@ -48,6 +48,10 @@ iscsi_readcapacity16_sync
iscsi_readcapacity16_task
iscsi_readtoc_sync
iscsi_readtoc_task
iscsi_reserve6_sync
iscsi_reserve6_task
iscsi_release6_sync
iscsi_release6_task
iscsi_reconnect
iscsi_set_noautoreconnect
iscsi_reportluns_sync
@@ -124,6 +128,8 @@ scsi_cdb_read6
scsi_cdb_readcapacity10
scsi_cdb_readcapacity16
scsi_cdb_readtoc
scsi_cdb_reserve6
scsi_cdb_release6
scsi_cdb_serviceactionin16
scsi_cdb_startstopunit
scsi_cdb_synchronizecache10

View File

@@ -46,6 +46,10 @@ iscsi_readcapacity16_sync
iscsi_readcapacity16_task
iscsi_readtoc_sync
iscsi_readtoc_task
iscsi_reserve6_sync
iscsi_reserve6_task
iscsi_release6_sync
iscsi_release6_task
iscsi_reconnect
iscsi_set_noautoreconnect
iscsi_reportluns_sync
@@ -122,6 +126,8 @@ scsi_cdb_read6
scsi_cdb_readcapacity10
scsi_cdb_readcapacity16
scsi_cdb_readtoc
scsi_cdb_reserve6
scsi_cdb_release6
scsi_cdb_serviceactionin16
scsi_cdb_startstopunit
scsi_cdb_synchronizecache10

View File

@@ -1499,6 +1499,48 @@ iscsi_readtoc_task(struct iscsi_context *iscsi, int lun, int msf,
return task;
}
struct scsi_task *
iscsi_reserve6_task(struct iscsi_context *iscsi, int lun,
iscsi_command_cb cb, void *private_data)
{
struct scsi_task *task;
task = scsi_cdb_reserve6();
if (task == NULL) {
iscsi_set_error(iscsi, "Out-of-memory: Failed to create "
"reserve6 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_release6_task(struct iscsi_context *iscsi, int lun,
iscsi_command_cb cb, void *private_data)
{
struct scsi_task *task;
task = scsi_cdb_release6();
if (task == NULL) {
iscsi_set_error(iscsi, "Out-of-memory: Failed to create "
"release6 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)
{

View File

@@ -458,6 +458,49 @@ scsi_readtoc_datain_unmarshall(struct scsi_task *task)
return list;
}
/*
* RESERVE6
*/
struct scsi_task *
scsi_cdb_reserve6(void)
{
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_RESERVE6;
task->cdb_size = 6;
task->xfer_dir = SCSI_XFER_NONE;
return task;
}
/*
* RELEASE10
*/
struct scsi_task *
scsi_cdb_release6(void)
{
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_RELEASE6;
task->cdb_size = 6;
task->xfer_dir = SCSI_XFER_NONE;
return task;
}
/*
* service_action_in unmarshall

View File

@@ -840,6 +840,40 @@ iscsi_readtoc_sync(struct iscsi_context *iscsi, int lun, int msf, int format,
return state.task;
}
struct scsi_task *
iscsi_reserve6_sync(struct iscsi_context *iscsi, int lun)
{
struct iscsi_sync_state state;
memset(&state, 0, sizeof(state));
if (iscsi_reserve6_task(iscsi, lun, scsi_sync_cb, &state) == NULL) {
iscsi_set_error(iscsi, "Failed to send RESERVE6 command");
return NULL;
}
event_loop(iscsi, &state);
return state.task;
}
struct scsi_task *
iscsi_release6_sync(struct iscsi_context *iscsi, int lun)
{
struct iscsi_sync_state state;
memset(&state, 0, sizeof(state));
if (iscsi_release6_task(iscsi, lun, scsi_sync_cb, &state) == NULL) {
iscsi_set_error(iscsi, "Failed to send RELEASE6 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)

View File

@@ -0,0 +1,278 @@
/*
Copyright (C) 2012 by Jon Grimm <jon.grimm@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 <string.h>
#include <ctype.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test.h"
int T0420_reserve6_simple(const char *initiator, const char *url, int data_loss, int show_info)
{
struct iscsi_context *iscsi, *iscsi2;
struct scsi_task *task;
int ret, lun;
printf("0420_reserve6_simple:\n");
printf("===================\n");
if (show_info) {
printf("Test RESERVE6/RELEASE6 commands if supported.\n");
printf(" If device does not support, just verify appropriate error returned\n");
printf("1. Test simple RESERVE6 followed by RELEASE6\n");
printf("2. Test Initator 1 can reserve if already reserved by Intiator 1.\n");
printf("3. Test Initiator 2 can't reserve if already reserved by Initiator 1.\n");
printf("4. Test Initiator 1 can testunitready if reserved by Initiator 1.\n");
printf("5. Test Initiator 2 can't testunitready if reserved by Initiator 1.\n");
printf("6. Test Initiator 2 can get reservation once Intiator 1 releases reservation.\n");
printf("\n");
return 0;
}
iscsi = iscsi_context_login(initiator, url, &lun);
if (iscsi == NULL) {
printf("Failed to login to target\n");
return -1;
}
iscsi2 = iscsi_context_login(initiator, url, &lun);
if (iscsi2 == NULL) {
printf("Failed to login to target\n");
return -1;
}
ret = 0;
printf("Send RESERVE6...\n");
task = iscsi_reserve6_sync(iscsi, lun);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send RESERVE6 command : %s\n",
iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[OK]\n");
printf("RESERVE6 Not Supported\n");
ret = 0;
} else {
printf("[FAILED]\n");
printf("RESERVE6 failed but ascq was wrong. Should "
"have failed with ILLEGAL_REQUEST/"
"INVALID OPERATOR. Sense:%s\n",
iscsi_get_error(iscsi));
ret = -1;
}
scsi_free_scsi_task(task);
goto finished;
}
printf("[OK]\n");
printf("Send RELEASE6...\n");
task = iscsi_release6_sync(iscsi, lun);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send RELEASE6 command : %s\n",
iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("RELEASE6 command failed : %s\n",
iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
ret = -1;
goto finished;
}
printf("[OK]\n");
test2:
printf("Test that reservation works.\n");
printf("Send RESERVE6 from Initiator 1...\n");
task = iscsi_reserve6_sync(iscsi, lun);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send RESERVE6 command : %s\n",
iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("RESERVE6 command failed : %s\n",
iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
ret = -1;
goto finished;
}
printf("[OK]\n");
printf("Send RESERVE6 from Initiator 1...\n");
task = iscsi_reserve6_sync(iscsi, lun);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send RESERVE6 command : %s\n",
iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("RESERVE6 command failed : %s\n",
iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
ret = -1;
goto finished;
}
printf("[OK]\n");
test3:
printf("Send RESERVE6 from Initiator 2...Expect conflict.\n");
task = iscsi_reserve6_sync(iscsi2, lun);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send RESERVE6 command : %s\n",
iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
/* We expect this command to fail for the test to pass. */
if (task->status != SCSI_STATUS_RESERVATION_CONFLICT) {
printf("[FAILED]\n");
printf("Expected RESERVATION CONFLICT\n");
scsi_free_scsi_task(task);
ret = -1;
goto finished;
}
printf("[OK]\n");
test4:
printf("Send TESTUNITREADY from Initiator 1...\n");
task = iscsi_testunitready_sync(iscsi, lun);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send TEST UNIT READY command: %s\n",
iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("TEST UNIT READY command: failed with sense %s\n",
iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
ret = -1;
goto finished;
}
printf("[OK]\n");
test5:
printf("Send TESTUNITREADY from Initiator 2...Expect conflict.\n");
task = iscsi_testunitready_sync(iscsi2, lun);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send TEST UNIT READY command: %s\n",
iscsi_get_error(iscsi2));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_RESERVATION_CONFLICT) {
printf("[FAILED]\n");
printf("Expected RESERVATION CONFLICT\n");
scsi_free_scsi_task(task);
ret = -1;
goto finished;
}
printf("[OK]\n");
test6:
printf("Test that release actually works\n");
printf("Send RELEASE6 from Initiator 1...\n");
task = iscsi_release6_sync(iscsi, lun);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send RELEASE6 command : %s\n",
iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("RELEASE6 command failed : %s\n",
iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
ret = -1;
goto finished;
}
printf("[OK]\n");
printf("Send RESERVE6 Initiator 2...\n");
task = iscsi_reserve6_sync(iscsi2, lun);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send RESERVE6 command : %s\n",
iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("RESERVE6 command failed : %s\n",
iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
ret = -1;
goto finished;
}
printf("[OK]\n");
printf("Send RELEASE6 Initiator 2...\n");
task = iscsi_reserve6_sync(iscsi2, lun);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send RELEASE6 command : %s\n",
iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("RELEASE6 command failed : %s\n",
iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
ret = -1;
goto finished;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
finished:
iscsi_logout_sync(iscsi);
iscsi_destroy_context(iscsi);
return ret;
}

View File

@@ -214,6 +214,9 @@ struct scsi_test tests[] = {
/* read TOC/PMA/ATIP */
{ "T0410_readtoc_basic", T0410_readtoc_basic },
/* reserve6/release6 */
{ "T0420_reserve6_simple", T0420_reserve6_simple },
/* iSCSI protocol tests */
/* invalid cmdsn from initiator */

View File

@@ -166,6 +166,8 @@ int T0404_inquiry_all_reported_vpd(const char *initiator, const char *url, int d
int T0410_readtoc_basic(const char *initiator, const char *url, int data_loss, int show_info);
int T0420_reserve6_simple(const char *initiator, const char *url, int data_loss, int show_info);
int T1000_cmdsn_invalid(const char *initiator, const char *url, int data_loss, int show_info);
int T1010_datasn_invalid(const char *initiator, const char *url, int data_loss, int show_info);
int T1020_bufferoffset_invalid(const char *initiator, const char *url, int data_loss, int show_info);