Merge with upstream
This commit is contained in:
@@ -41,6 +41,7 @@ int T0000_testunitready_simple(const char *initiator, const char *url, int data_
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret=0;
|
||||
|
||||
printf("Test TESTUNITREADY ... ");
|
||||
task = iscsi_testunitready_sync(iscsi, lun);
|
||||
|
||||
212
test-tool/0424_reserve6_target_reset.c
Normal file
212
test-tool/0424_reserve6_target_reset.c
Normal file
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
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 <string.h>
|
||||
#include <ctype.h>
|
||||
#include <poll.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
struct mgmt_task {
|
||||
uint32_t status;
|
||||
uint32_t finished;
|
||||
};
|
||||
|
||||
static void mgmt_cb(struct iscsi_context *iscsi _U_, int status _U_,
|
||||
void *command_data, void *private_data)
|
||||
{
|
||||
struct mgmt_task *mgmt_task = (struct mgmt_task *)private_data;
|
||||
|
||||
mgmt_task->status = *(uint32_t *)command_data;
|
||||
mgmt_task->finished = 1;
|
||||
}
|
||||
|
||||
int T0424_reserve6_target_reset(const char *initiator, const char *url, int data_loss, int show_info)
|
||||
{
|
||||
struct iscsi_context *iscsi, *iscsi2;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
struct mgmt_task mgmt_task = {0, 0};
|
||||
struct pollfd pfd;
|
||||
|
||||
printf("0424_reserve6_target_reset:\n");
|
||||
printf("========================\n");
|
||||
if (show_info) {
|
||||
printf("Test that a RESERVE6 is dropped by a Target-reset\n");
|
||||
printf(" If device does not support RESERVE6, just skip the test.\n");
|
||||
printf("1, Reserve the device from the first initiator.\n");
|
||||
printf("2, Verify we can access the LUN from the first initiator\n");
|
||||
printf("3, Verify we can NOT access the LUN from the second initiator\n");
|
||||
printf("4, Send a Target-reset\n");
|
||||
printf("5, Verify we can access the LUN from the second initiator\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(initiator2, url, &lun);
|
||||
if (iscsi2 == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
printf("Send RESERVE6 from the first initiator ... ");
|
||||
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_CHECK_CONDITION
|
||||
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
|
||||
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("RESERVE6 Not Supported\n");
|
||||
ret = -2;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("RESERVE6 failed with sense:%s\n",
|
||||
iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto test2;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
test2:
|
||||
printf("Verify we can access the LUN from the first initiator ... ");
|
||||
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));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto test3;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
test3:
|
||||
printf("Verify we can NOT access the LUN from the second initiator ... ");
|
||||
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");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
test4:
|
||||
printf("Send a Target Cold-Reset ... ");
|
||||
iscsi_task_mgmt_target_cold_reset_async(iscsi, mgmt_cb, &mgmt_task);
|
||||
while (mgmt_task.finished == 0) {
|
||||
pfd.fd = iscsi_get_fd(iscsi);
|
||||
pfd.events = iscsi_which_events(iscsi);
|
||||
|
||||
if (poll(&pfd, 1, -1) < 0) {
|
||||
printf("Poll failed");
|
||||
goto finished;
|
||||
}
|
||||
if (iscsi_service(iscsi, pfd.revents) < 0) {
|
||||
printf("iscsi_service failed with : %s\n", iscsi_get_error(iscsi));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mgmt_task.status != 0) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to reset the LUN\n");
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
test5:
|
||||
/* We might be getting UNIT_ATTENTION/BUS_RESET after the lun-reset above.
|
||||
If so just loop and try the TESTUNITREADY again until it clears
|
||||
*/
|
||||
printf("Verify we can access the LUN from the second initiator ... ");
|
||||
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_CHECK_CONDITION
|
||||
&& task->sense.key == SCSI_SENSE_UNIT_ATTENTION
|
||||
&& task->sense.ascq == SCSI_SENSE_ASCQ_BUS_RESET) {
|
||||
printf("Got BUS RESET. Retry accessing the LUN\n");
|
||||
goto test5;
|
||||
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("TEST UNIT READY command: failed with sense %s\n",
|
||||
iscsi_get_error(iscsi2));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto test3;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
iscsi_logout_sync(iscsi2);
|
||||
iscsi_destroy_context(iscsi2);
|
||||
return ret;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ int T1020_bufferoffset_invalid(const char *initiator, const char *url, int data_
|
||||
struct scsi_task *task;
|
||||
struct scsi_readcapacity16 *rc16;
|
||||
int ret, lun;
|
||||
unsigned char data[block_size * 256];
|
||||
unsigned char data[4096 * 256];
|
||||
struct iscsi_async_state test_state;
|
||||
|
||||
printf("1020_bufferoffset_invalid:\n");
|
||||
|
||||
150
test-tool/1030_unsolicited_data_overflow.c
Normal file
150
test-tool/1030_unsolicited_data_overflow.c
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
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 <stdlib.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
uint32_t block_size;
|
||||
|
||||
static void test_cb(struct iscsi_context *iscsi _U_, int status,
|
||||
void *command_data _U_, void *private_data)
|
||||
{
|
||||
struct scsi_task *task = command_data;
|
||||
struct iscsi_async_state *state = private_data;
|
||||
|
||||
state->finished = 1;
|
||||
state->status = status;
|
||||
|
||||
if (status) {
|
||||
task->status = status;
|
||||
}
|
||||
}
|
||||
|
||||
int T1030_unsolicited_data_overflow(const char *initiator, const char *url, int data_loss, int show_info)
|
||||
{
|
||||
struct iscsi_context *iscsi, *iscsi2;
|
||||
struct scsi_task *task;
|
||||
struct scsi_readcapacity16 *rc16;
|
||||
int ret, lun;
|
||||
unsigned char *buf = NULL;
|
||||
struct iscsi_async_state test_state;
|
||||
uint32_t old_first_burst_len;
|
||||
|
||||
printf("1030_unsolicited_data_overflow:\n");
|
||||
printf("===============================\n");
|
||||
if (show_info) {
|
||||
printf("Test sending command with way more unsolicited data than the target supports\n");
|
||||
printf("1, Send HUGE unsolicited data to the target.\n");
|
||||
printf("2, Verify the target is still alive\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* find the size of the LUN */
|
||||
task = iscsi_readcapacity16_sync(iscsi, lun);
|
||||
if (task == NULL) {
|
||||
printf("Failed to send READCAPACITY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("READCAPACITY16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
rc16 = scsi_datain_unmarshall(task);
|
||||
if (rc16 == NULL) {
|
||||
printf("failed to unmarshall READCAPACITY16 data. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
block_size = rc16->block_length;
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
iscsi->use_immediate_data = ISCSI_IMMEDIATE_DATA_YES;
|
||||
old_first_burst_len = iscsi->first_burst_length;
|
||||
/* make first burst REAL big */
|
||||
iscsi->first_burst_length *= 16;
|
||||
buf = malloc(iscsi->first_burst_length);
|
||||
|
||||
printf("Write too much unsolicited data ... ");
|
||||
/* we dont want autoreconnect since some targets will drop the session
|
||||
* on this condition.
|
||||
*/
|
||||
iscsi_set_noautoreconnect(iscsi, 1);
|
||||
|
||||
// 102400 -- 1024000
|
||||
task = iscsi_write16_task(iscsi, lun, 0, buf,
|
||||
iscsi->first_burst_length, block_size,
|
||||
0, 0, 0, 0, 0,
|
||||
test_cb, &test_state);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret++;
|
||||
goto test2;
|
||||
}
|
||||
|
||||
test_state.task = task;
|
||||
test_state.finished = 0;
|
||||
test_state.status = 0;
|
||||
wait_until_test_finished(iscsi, &test_state);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
test2:
|
||||
printf("Verify the target is still alive ... ");
|
||||
iscsi2 = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi2 == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Target is dead?\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
if (buf) {
|
||||
free(buf);
|
||||
}
|
||||
iscsi_destroy_context(iscsi);
|
||||
iscsi_destroy_context(iscsi2);
|
||||
return ret;
|
||||
}
|
||||
@@ -221,6 +221,7 @@ struct scsi_test tests[] = {
|
||||
{ "T0421_reserve6_lun_reset", T0421_reserve6_lun_reset },
|
||||
{ "T0422_reserve6_logout", T0422_reserve6_logout },
|
||||
{ "T0423_reserve6_sessionloss", T0423_reserve6_sessionloss },
|
||||
{ "T0424_reserve6_target_reset", T0424_reserve6_target_reset },
|
||||
|
||||
/* Maintenance In - Report Supported Operations */
|
||||
{ "T0430_report_all_supported_ops", T0430_report_all_supported_ops },
|
||||
@@ -236,12 +237,15 @@ struct scsi_test tests[] = {
|
||||
/* invalid bufferoffset from initiator */
|
||||
{ "T1020_bufferoffset_invalid", T1020_bufferoffset_invalid },
|
||||
|
||||
/* sending too much unsolicited data */
|
||||
{ "T1030_unsolicited_data_overflow", T1030_unsolicited_data_overflow },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
void print_usage(void)
|
||||
{
|
||||
fprintf(stderr, "Usage: iscsi-test [-?] [-?|--help] [--usage] [-t|--test=<test>]\n"
|
||||
fprintf(stderr, "Usage: iscsi-test [-?] [-?|--help] [--usage] [-t|--test=<test>] [-s|--skip=<test>]\n"
|
||||
"\t\t[-l|--list] [--info] [-i|--initiator-name=<iqn-name>]\n"
|
||||
"\t\t<iscsi-url>\n");
|
||||
}
|
||||
@@ -252,6 +256,7 @@ void print_help(void)
|
||||
fprintf(stderr, " -i, --initiator-name=iqn-name Initiatorname to use\n");
|
||||
fprintf(stderr, " -I, --initiator-name-2=iqn-name Second initiatorname to use\n");
|
||||
fprintf(stderr, " -t, --test=test-name Which test to run. Default is to run all tests.\n");
|
||||
fprintf(stderr, " -s, --skip=test-name Which test to skip. Default is to run all tests.\n");
|
||||
fprintf(stderr, " -l, --list List all tests.\n");
|
||||
fprintf(stderr, " --info, Print extra info about a test.\n");
|
||||
fprintf(stderr, " --dataloss Allow destructive tests.\n");
|
||||
@@ -375,6 +380,7 @@ int main(int argc, const char *argv[])
|
||||
int res, num_failed, num_skipped;
|
||||
struct scsi_test *test;
|
||||
char *testname = NULL;
|
||||
char *skipname = NULL;
|
||||
|
||||
struct poptOption popt_options[] = {
|
||||
{ "help", '?', POPT_ARG_NONE, &show_help, 0, "Show this help message", NULL },
|
||||
@@ -383,6 +389,7 @@ int main(int argc, const char *argv[])
|
||||
{ "initiator-name", 'i', POPT_ARG_STRING, &initiator, 0, "Initiatorname to use", "iqn-name" },
|
||||
{ "initiator-name-2", 'I', POPT_ARG_STRING, &initiator, 0, "Second initiatorname to use for tests using more two sessions", "iqn-name" },
|
||||
{ "test", 't', POPT_ARG_STRING, &testname, 0, "Which test to run", "testname" },
|
||||
{ "skip", 's', POPT_ARG_STRING, &skipname, 0, "Which test to skip", "skipname" },
|
||||
{ "info", 0, POPT_ARG_NONE, &show_info, 0, "Show information about the test", "testname" },
|
||||
{ "dataloss", 0, POPT_ARG_NONE, &data_loss, 0, "Allow destructuve tests", NULL },
|
||||
POPT_TABLEEND
|
||||
@@ -437,6 +444,21 @@ int main(int argc, const char *argv[])
|
||||
if (testname != NULL && fnmatch(testname, test->name, 0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (skipname != NULL) {
|
||||
char * pchr = skipname;
|
||||
char * pchr2 = NULL;
|
||||
int skip = 0;
|
||||
do {
|
||||
pchr2 = strchr(pchr,',');
|
||||
if (pchr2) pchr2[0]=0x00;
|
||||
if (!fnmatch(pchr, test->name, 0)) {
|
||||
skip = 1;
|
||||
}
|
||||
if (pchr2) {pchr2[0]=',';pchr=pchr2+1;}
|
||||
} while (pchr2);
|
||||
if (skip) continue;
|
||||
}
|
||||
|
||||
res = test->test(initiator, url, data_loss, show_info);
|
||||
if (res == 0) {
|
||||
|
||||
@@ -173,9 +173,12 @@ int T0420_reserve6_simple(const char *initiator, const char *url, int data_loss,
|
||||
int T0421_reserve6_lun_reset(const char *initiator, const char *url, int data_loss, int show_info);
|
||||
int T0422_reserve6_logout(const char *initiator, const char *url, int data_loss, int show_info);
|
||||
int T0423_reserve6_sessionloss(const char *initiator, const char *url, int data_loss, int show_info);
|
||||
int T0424_reserve6_target_reset(const char *initiator, const char *url, int data_loss, int show_info);
|
||||
|
||||
int T0430_report_all_supported_ops(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);
|
||||
int T1030_unsolicited_data_overflow(const char *initiator, const char *url, int data_loss, int show_info);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user