From d901700633ffb3928c95c3e9dd7e84cab3e7c916 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sun, 21 Jul 2013 14:11:13 -0700 Subject: [PATCH] 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 --- Makefile.am | 1 + test-tool/iscsi-support.c | 31 ++++++ test-tool/iscsi-support.h | 1 + test-tool/iscsi-test-cu.c | 1 + test-tool/iscsi-test-cu.h | 1 + test-tool/test_sanitize_readonly.c | 8 +- test-tool/test_sanitize_reset.c | 145 +++++++++++++++++++++++++++++ 7 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 test-tool/test_sanitize_reset.c diff --git a/Makefile.am b/Makefile.am index b50f4db..0839be1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index a9e4d29..b768e5e 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -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) { diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 3fa92ed..09d4281 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -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); diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index 25ec827..a70f014 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -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 }; diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index 9c0f345..034e09f 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -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); diff --git a/test-tool/test_sanitize_readonly.c b/test-tool/test_sanitize_readonly.c index 562f92c..f009064 100644 --- a/test-tool/test_sanitize_readonly.c +++ b/test-tool/test_sanitize_readonly.c @@ -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; diff --git a/test-tool/test_sanitize_reset.c b/test-tool/test_sanitize_reset.c new file mode 100644 index 0000000..8bb8f86 --- /dev/null +++ b/test-tool/test_sanitize_reset.c @@ -0,0 +1,145 @@ +/* + Copyright (C) 2013 Ronnie Sahlberg + + 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 . +*/ + +#include +#include +#include +#include + +#include + +#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); + } +}