Add initial support for SANITIZE and a simple test to generate this opcode.
This commit is contained in:
@@ -56,6 +56,7 @@ uint64_t num_blocks;
|
||||
int lbppb;
|
||||
enum scsi_inquiry_peripheral_device_type device_type;
|
||||
int data_loss;
|
||||
int allow_sanitize;
|
||||
int readonly;
|
||||
int sbc3_support;
|
||||
int maximum_transfer_length;
|
||||
@@ -1313,6 +1314,42 @@ synchronizecache16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sanitize(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
logging(LOG_VERBOSE, "Send SANITIZE IMMED:%d AUSE:%d SA:%d "
|
||||
"PARAM_LEN:%d",
|
||||
immed, ause, sa, param_len);
|
||||
|
||||
task = iscsi_sanitize_sync(iscsi, lun, immed, ause, sa, param_len,
|
||||
data);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL,
|
||||
"[FAILED] Failed to send SANITIZE command: %s",
|
||||
iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_CHECK_CONDITION
|
||||
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
|
||||
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
|
||||
logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not "
|
||||
"implemented on target");
|
||||
scsi_free_scsi_task(task);
|
||||
return -2;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL,
|
||||
"[FAILED] SANITIZE command: failed with sense. %s",
|
||||
iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] SANITIZE returned SUCCESS.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int startstopunit(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
@@ -53,6 +53,17 @@ do { \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#define CHECK_FOR_SANITIZE \
|
||||
do { \
|
||||
if (!allow_sanitize) { \
|
||||
logging(LOG_VERBOSE, "[SKIPPED] --allow_sanitize flag " \
|
||||
"is not set. Skipping test."); \
|
||||
CU_PASS("[SKIPPED] --allow_sanitize flag is not set." \
|
||||
" Skipping test"); \
|
||||
return; \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#define CHECK_FOR_READONLY \
|
||||
do { \
|
||||
if (!readonly) { \
|
||||
@@ -137,6 +148,7 @@ extern size_t block_size;
|
||||
extern uint64_t num_blocks;
|
||||
extern int lbppb;
|
||||
extern int data_loss;
|
||||
extern int allow_sanitize;
|
||||
extern int readonly;
|
||||
extern int sbc3_support;
|
||||
extern int maximum_transfer_length;
|
||||
@@ -248,6 +260,7 @@ int report_supported_opcodes_invalidfieldincdb(struct iscsi_context *iscsi, int
|
||||
int release6(struct iscsi_context *iscsi, int lun);
|
||||
int reserve6(struct iscsi_context *iscsi, int lun);
|
||||
int reserve6_conflict(struct iscsi_context *iscsi, int lun);
|
||||
int sanitize(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data);
|
||||
int startstopunit(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start);
|
||||
int startstopunit_preventremoval(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start);
|
||||
int synchronizecache10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int sync_nv, int immed);
|
||||
|
||||
@@ -221,6 +221,11 @@ static CU_TestInfo tests_readonly[] = {
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
|
||||
static CU_TestInfo tests_sanitize[] = {
|
||||
{ (char *)"Sanitize", test_sanitize_simple },
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
|
||||
static CU_TestInfo tests_report_supported_opcodes[] = {
|
||||
{ (char *)"ReportSupportedOpcodesSimple", test_report_supported_opcodes_simple },
|
||||
{ (char *)"ReportSupportedOpcodesOneCommand", test_report_supported_opcodes_one_command },
|
||||
@@ -415,6 +420,8 @@ static CU_SuiteInfo scsi_suites[] = {
|
||||
tests_report_supported_opcodes },
|
||||
{ (char *)"Reserve6", test_setup, test_teardown,
|
||||
tests_reserve6 },
|
||||
{ (char *)"Sanitize", test_setup, test_teardown,
|
||||
tests_sanitize },
|
||||
{ (char *)"StartStopUnit", test_setup, test_teardown,
|
||||
tests_startstopunit },
|
||||
{ (char *)"UnitReady", test_setup, test_teardown,
|
||||
@@ -519,6 +526,8 @@ static CU_SuiteInfo all_suites[] = {
|
||||
tests_report_supported_opcodes },
|
||||
{ (char *)"Reserve6", test_setup, test_teardown,
|
||||
tests_reserve6 },
|
||||
{ (char *)"Sanitize", test_setup, test_teardown,
|
||||
tests_sanitize },
|
||||
{ (char *)"StartStopUnit", test_setup, test_teardown,
|
||||
tests_startstopunit },
|
||||
{ (char *)"TestUnitReady", test_setup, test_teardown,
|
||||
@@ -668,6 +677,8 @@ print_usage(void)
|
||||
" -l|--list List all tests and exit\n");
|
||||
fprintf(stderr,
|
||||
" -d|--dataloss Allow destructive tests\n");
|
||||
fprintf(stderr,
|
||||
" -S|--allow-sanitize Allow sanitize-opcode tests\n");
|
||||
fprintf(stderr,
|
||||
" -g|--ignore Error Action: Ignore test errors [DEFAULT]\n");
|
||||
fprintf(stderr,
|
||||
@@ -890,6 +901,7 @@ main(int argc, char *argv[])
|
||||
{ "initiator-name-2", required_argument, 0, 'I' },
|
||||
{ "test", required_argument, 0, 't' },
|
||||
{ "dataloss", no_argument, 0, 'd' },
|
||||
{ "allow-sanitize", no_argument, 0, 'S' },
|
||||
{ "ignore", no_argument, 0, 'g' },
|
||||
{ "fail", no_argument, 0, 'f' },
|
||||
{ "abort", no_argument, 0, 'A' },
|
||||
@@ -903,7 +915,7 @@ main(int argc, char *argv[])
|
||||
int i, c;
|
||||
int opt_idx = 0;
|
||||
|
||||
while ((c = getopt_long(argc, argv, "?hli:I:t:sdgfAsnuvV", long_opts,
|
||||
while ((c = getopt_long(argc, argv, "?hli:I:t:sdgfAsSnuvV", long_opts,
|
||||
&opt_idx)) > 0) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
@@ -937,6 +949,9 @@ main(int argc, char *argv[])
|
||||
case 's':
|
||||
mode = CU_BRM_SILENT;
|
||||
break;
|
||||
case 'S':
|
||||
allow_sanitize = 1;
|
||||
break;
|
||||
case 'n':
|
||||
mode = CU_BRM_NORMAL;
|
||||
break;
|
||||
|
||||
@@ -151,6 +151,8 @@ void test_reserve6_target_cold_reset(void);
|
||||
void test_reserve6_target_warm_reset(void);
|
||||
void test_reserve6_lun_reset(void);
|
||||
|
||||
void test_sanitize_simple(void);
|
||||
|
||||
void test_startstopunit_simple(void);
|
||||
void test_startstopunit_pwrcnd(void);
|
||||
void test_startstopunit_noloej(void);
|
||||
|
||||
48
test-tool/test_sanitize_simple.c
Normal file
48
test-tool/test_sanitize_simple.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
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 <CUnit/CUnit.h>
|
||||
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test-cu.h"
|
||||
|
||||
void
|
||||
test_sanitize_simple(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||
logging(LOG_VERBOSE, "Test basic SANITIZE");
|
||||
|
||||
CHECK_FOR_SANITIZE;
|
||||
|
||||
logging(LOG_VERBOSE, "Test we can perform basic BLOCK ERASE SANITIZE");
|
||||
|
||||
ret = sanitize(iscsic, tgt_lun,
|
||||
0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL);
|
||||
if (ret == -2) {
|
||||
logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not implemented.");
|
||||
CU_PASS("SANITIZE is not implemented.");
|
||||
return;
|
||||
}
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
Reference in New Issue
Block a user