diff --git a/Makefile.am b/Makefile.am index 427c862..db64c4c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -178,6 +178,7 @@ bin_iscsi_test_cu_LDFLAGS = -ldl -lcunit bin_iscsi_test_cu_SOURCES = test-tool/iscsi-test-cu.c \ test-tool/iscsi-support.c \ test-tool/test_get_lba_status_simple.c \ + test-tool/test_get_lba_status_beyond_eol.c \ test-tool/test_prefetch10_simple.c \ test-tool/test_prefetch10_beyond_eol.c \ test-tool/test_prefetch10_0blocks.c \ diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index 7639ed3..32f7e27 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -927,6 +927,46 @@ int get_lba_status(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t return 0; } +int get_lba_status_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len) +{ + struct scsi_task *task; + + logging(LOG_VERBOSE, "Send GET_LBA_STATUS (expecting LBA_OUT_OF_RANGE) LBA:%" PRIu64 " blocks:%d", + lba, len); + + task = iscsi_get_lba_status_sync(iscsi, lun, lba, len); + if (task == NULL) { + logging(LOG_NORMAL, "[FAILED] Failed to send GET_LBA_STATUS " + "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] GET_LBA_STATUS is not " + "implemented on target"); + scsi_free_scsi_task(task); + return -2; + } + if (task->status == SCSI_STATUS_GOOD) { + logging(LOG_NORMAL, "[FAILED] GET_LBA_STATUS returned SUCCESS. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); + scsi_free_scsi_task(task); + return -1; + } + if (task->status != SCSI_STATUS_CHECK_CONDITION + || task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST + || task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) { + logging(LOG_NORMAL, "[FAILED] GET_LBA_STATUS failed with the wrong sense code. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE but failed with sense:%s", iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + + scsi_free_scsi_task(task); + logging(LOG_VERBOSE, "[OK] GET_LBA_STATUS returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); + return 0; +} + int prefetch10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num, int immed, int group) { diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 46bd4f7..3bf5e51 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -189,6 +189,7 @@ int verify_read_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf); int verify_write_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf); int inquiry(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize); int get_lba_status(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len); +int get_lba_status_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len); int prefetch10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int immed, int group); int prefetch10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int immed, int group); int prefetch10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int immed, int group); diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index 098a424..fd0407c 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -62,6 +62,7 @@ int (*real_iscsi_queue_pdu)(struct iscsi_context *iscsi, struct iscsi_pdu *pdu); *****************************************************************/ static CU_TestInfo tests_get_lba_status[] = { { (char *)"testGetLBAStatusSimple", test_get_lba_status_simple }, + { (char *)"testGetLBAStatusBeyondEol", test_get_lba_status_beyond_eol }, CU_TEST_INFO_NULL }; diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index 6b4a6ca..8ee4f1b 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -41,6 +41,7 @@ int test_setup_pgr(void); int test_teardown_pgr(void); void test_get_lba_status_simple(void); +void test_get_lba_status_beyond_eol(void); void test_prefetch10_simple(void); void test_prefetch10_beyond_eol(void); diff --git a/test-tool/test_get_lba_status_beyond_eol.c b/test-tool/test_get_lba_status_beyond_eol.c new file mode 100644 index 0000000..75d17ed --- /dev/null +++ b/test-tool/test_get_lba_status_beyond_eol.c @@ -0,0 +1,52 @@ +/* + 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 "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-support.h" +#include "iscsi-test-cu.h" + + +void +test_get_lba_status_beyond_eol(void) +{ + int ret; + + logging(LOG_VERBOSE, LOG_BLANK_LINE); + logging(LOG_VERBOSE, "Test GET_LBA_STATUS one block beyond the end of the LUN"); + + ret = get_lba_status_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 24); + if (ret == -2) { + CU_PASS("[SKIPPED] Target does not support GET_LBA_STATUS. Skipping test"); + return; + } + CU_ASSERT_EQUAL(ret, 0); + + logging(LOG_VERBOSE, "Test GET_LBA_STATUS at LBA 2^63"); + + ret = get_lba_status_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000, 24); + CU_ASSERT_EQUAL(ret, 0); + + logging(LOG_VERBOSE, "Test GET_LBA_STATUS at LBA -1"); + + ret = get_lba_status_lbaoutofrange(iscsic, tgt_lun, 0xffffffffffffffff, 24); + CU_ASSERT_EQUAL(ret, 0); +}