Add a test that a sanitize operation will continue across resets

Verify that abort task/abort task set/lun reset/warm reset/cold reset
and full blown session failures will not affect a sanitize that is in
progress
This commit is contained in:
Ronnie Sahlberg
2013-07-21 14:11:13 -07:00
parent 49698e0322
commit d901700633
7 changed files with 186 additions and 2 deletions

View File

@@ -279,6 +279,7 @@ bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \
test-tool/test_sanitize_overwrite_reserved.c \
test-tool/test_sanitize_readonly.c \
test-tool/test_sanitize_reservations.c \
test-tool/test_sanitize_reset.c \
test-tool/test_startstopunit_simple.c \
test-tool/test_startstopunit_pwrcnd.c \
test-tool/test_startstopunit_noloej.c \

View File

@@ -1629,6 +1629,37 @@ testunitready_nomedium(struct iscsi_context *iscsi, int lun)
return 0;
}
int
testunitready_sanitize(struct iscsi_context *iscsi, int lun)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send TESTUNITREADY (Expecting SANITIZE_IN_PROGRESS)");
task = iscsi_testunitready_sync(iscsi, lun);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send TESTUNITREADY "
"command: %s", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] TESTUNITREADY command successful. But should have failed with NOT_READY/SANITIZE_IN_PROGRESS");
scsi_free_scsi_task(task);
return -1;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_NOT_READY
|| task->sense.ascq != SCSI_SENSE_ASCQ_SANITIZE_IN_PROGRESS) {
logging(LOG_NORMAL, "[FAILED] TESTUNITREADY Should have failed "
"with NOT_READY/SANITIZE_IN_PROGRESS But failed "
"with %s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] TESTUNITREADY returned SANITIZE_IN_PROGRESS.");
return 0;
}
int
testunitready_conflict(struct iscsi_context *iscsi, int lun)
{

View File

@@ -279,6 +279,7 @@ int testunitready_clear_ua(struct iscsi_context *iscsi, int lun);
int testunitready(struct iscsi_context *iscsi, int lun);
int testunitready_nomedium(struct iscsi_context *iscsi, int lun);
int testunitready_conflict(struct iscsi_context *iscsi, int lun);
int testunitready_sanitize(struct iscsi_context *iscsi, int lun);
int unmap(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len);
int unmap_writeprotected(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len);
int unmap_nomedium(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len);

View File

@@ -237,6 +237,7 @@ static CU_TestInfo tests_sanitize[] = {
{ (char *)"OverwriteReserved", test_sanitize_overwrite_reserved },
{ (char *)"Readonly", test_sanitize_readonly },
{ (char *)"Reservations", test_sanitize_reservations },
{ (char *)"Reset", test_sanitize_reset },
CU_TEST_INFO_NULL
};

View File

@@ -163,6 +163,7 @@ void test_sanitize_overwrite(void);
void test_sanitize_overwrite_reserved(void);
void test_sanitize_readonly(void);
void test_sanitize_reservations(void);
void test_sanitize_reset(void);
void test_startstopunit_simple(void);
void test_startstopunit_pwrcnd(void);

View File

@@ -55,7 +55,9 @@ test_sanitize_readonly(void)
logging(LOG_VERBOSE, "Use TESTUNITREADY to clear unit attention on "
"first connection");
while (testunitready_clear_ua(iscsic, tgt_lun));
while (testunitready_clear_ua(iscsic, tgt_lun)) {
sleep(1);
}
logging(LOG_VERBOSE, "Check if SANITIZE OVERWRITE is supported "
"in REPORT_SUPPORTED_OPCODES");
@@ -115,7 +117,9 @@ test_sanitize_readonly(void)
logging(LOG_VERBOSE, "Use TESTUNITREADY to clear unit attention on "
"first connection");
while (testunitready_clear_ua(iscsic, tgt_lun));
while (testunitready_clear_ua(iscsic, tgt_lun)) {
sleep(1);
}
iscsi_destroy_context(iscsic2);
iscsic2 = NULL;

View File

@@ -0,0 +1,145 @@
/*
Copyright (C) 2013 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 <string.h>
#include <alloca.h>
#include <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test-cu.h"
static void sanitize_cb(struct iscsi_context *iscsi _U_, int status _U_,
void *command_data _U_, void *private_data _U_)
{
}
void
test_sanitize_reset(void)
{
int ret;
struct scsi_command_descriptor *cd;
struct scsi_task *sanitize_task;
struct scsi_task *rl_task;
struct iscsi_data data;
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test SANITIZE with Task/Lun/Target/Session reset");
CHECK_FOR_SANITIZE;
CHECK_FOR_DATALOSS;
logging(LOG_VERBOSE, "Check that SANITIZE OVERWRITE will continue "
"even after Task/Lun/Target/* reset.");
cd = get_command_descriptor(SCSI_OPCODE_SANITIZE,
SCSI_SANITIZE_OVERWRITE);
if (cd == NULL) {
logging(LOG_NORMAL, "[SKIPPED] SANITIZE OVERWRITE is not "
"implemented according to REPORT_SUPPORTED_OPCODES.");
CU_PASS("SANITIZE is not implemented.");
return;
}
logging(LOG_VERBOSE, "Send an asyncronous SANITIZE to the target.");
data.size = block_size + 4;
data.data = alloca(data.size);
memset(&data.data[4], 0, block_size);
data.data[0] = 0x01;
data.data[1] = 0x00;
data.data[2] = block_size >> 8;
data.data[3] = block_size & 0xff;
sanitize_task = iscsi_sanitize_task(iscsic, tgt_lun,
0, 0, SCSI_SANITIZE_OVERWRITE,
data.size, &data,
sanitize_cb, NULL);
CU_ASSERT_NOT_EQUAL(sanitize_task, NULL);
/* just send something so that we know the sanitize command is sent
* to the target
*/
rl_task = iscsi_reportluns_sync(iscsic, 0, 64);
if (rl_task) {
scsi_free_scsi_task(rl_task);
}
logging(LOG_VERBOSE, "Sleep for three seconds incase the target is "
"slow to start the SANITIZE");
sleep(3);
logging(LOG_VERBOSE, "Verify that the SANITIZE has started.");
ret = testunitready_sanitize(iscsic, tgt_lun);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Send an ABORT TASK");
ret = iscsi_task_mgmt_abort_task_sync(iscsic, sanitize_task);
if (ret != 0) {
logging(LOG_NORMAL, "ABORT TASK failed. %s",
iscsi_get_error(iscsic));
}
logging(LOG_VERBOSE, "Send an ABORT TASK SET");
ret = iscsi_task_mgmt_abort_task_set_sync(iscsic, tgt_lun);
if (ret != 0) {
logging(LOG_NORMAL, "ABORT TASK SET failed. %s",
iscsi_get_error(iscsic));
}
logging(LOG_VERBOSE, "Send a LUN Reset");
ret = iscsi_task_mgmt_lun_reset_sync(iscsic, tgt_lun);
if (ret != 0) {
logging(LOG_NORMAL, "LUN reset failed. %s", iscsi_get_error(iscsic));
}
logging(LOG_VERBOSE, "Send a Warm Reset");
ret = iscsi_task_mgmt_target_warm_reset_sync(iscsic);
if (ret != 0) {
logging(LOG_NORMAL, "Warm reset failed. %s", iscsi_get_error(iscsic));
}
logging(LOG_VERBOSE, "Send a Cold Reset");
ret = iscsi_task_mgmt_target_cold_reset_sync(iscsic);
if (ret != 0) {
logging(LOG_NORMAL, "Cold reset failed. %s", iscsi_get_error(iscsic));
}
logging(LOG_VERBOSE, "Disconnect from the target.");
iscsi_destroy_context(iscsic);
logging(LOG_VERBOSE, "Sleep for one seconds incase the target is "
"slow to reset");
sleep(1);
logging(LOG_VERBOSE, "Reconnect to target");
iscsic = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun);
if (iscsic == NULL) {
logging(LOG_VERBOSE, "Failed to login to target");
return;
}
logging(LOG_VERBOSE, "Verify that the SANITIZE is still going.");
ret = testunitready_sanitize(iscsic, tgt_lun);
CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Wait until the SANITIZE operation has finished");
while (testunitready_clear_ua(iscsic, tgt_lun)) {
sleep(60);
}
}