tests: remove deprecated test tool iscsi-test
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
This commit is contained in:
23
README
23
README
@@ -117,29 +117,6 @@ These results can be converted to JUnit format using this script:
|
||||
http://git.cyrusimap.org/cyrus-imapd/plain/cunit/cunit-to-junit.pl
|
||||
|
||||
|
||||
ISCSI-TEST
|
||||
==========
|
||||
iscsi-test is deprecated and is being replaced by iscsi-test-cu.
|
||||
No new tests will be developed for iscsi-test.
|
||||
|
||||
The test-tool subdirectory contains an iSCSI/SCSI test tool.
|
||||
This is a tool that is aimed at providing a comprehensive iSCSI and SCSI
|
||||
emulation test suite.
|
||||
|
||||
Run ./bin/iscsi-test --help and
|
||||
Run ./bin/iscsi-test --list
|
||||
for instructions
|
||||
|
||||
Example:
|
||||
$ ./bin/iscsi-test --initiator-name=iqn.ronnie.test --test=T0105_read10_invalid iscsi://127.0.0.1/iqn.ronnie.test/1
|
||||
=========
|
||||
Running test T0105_read10_invalid
|
||||
Read10 1 block but with iscsi ExpectedDataTransferLength==0 ... [FAILED]
|
||||
Read10 of 1 block with iscsi ExpectedDataTransferLength==0 should fail.
|
||||
TEST T0105_read10_invalid [FAILED]
|
||||
|
||||
|
||||
|
||||
LD_PRELOAD FUN
|
||||
==============
|
||||
There is a small LD_PRELOAD hack in the src directory that intercepts a handful
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0000_testunitready_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
int ret, lun;
|
||||
|
||||
printf("0000_testunitready_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic TESTUNITREADY functionality.\n");
|
||||
printf("1, Verify TESTUNITREADY works.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret=0;
|
||||
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
|
||||
/*
|
||||
Copyright (C) 2010 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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0100_read10_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0100_read10_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic READ10 functionality.\n");
|
||||
printf("1, Verify we can read the first 1-256 blocks of the LUN.\n");
|
||||
printf("2, Verify we can read the last 1-256 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Reading first 1-256 blocks ... ");
|
||||
for (i=1; i<=256; i++) {
|
||||
task = iscsi_read10_sync(iscsi, lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read the last 1 - 256 blocks at the end of the LUN */
|
||||
printf("Reading last 1-256 blocks ... ");
|
||||
for (i=1; i<=256; i++) {
|
||||
task = iscsi_read10_sync(iscsi, lun, num_blocks +1 - i, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,185 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2010 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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0101_read10_beyond_eol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0101_read10_beyond_eol:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that READ10 fails when reading beyond end-of-lun.\n");
|
||||
printf("This test is skipped for LUNs with more than 2^31 blocks\n");
|
||||
printf("1, Read 1-256 blocks one block beyond end-of-lun.\n");
|
||||
printf("2, Read 1-256 blocks at LBA 2^31\n");
|
||||
printf("3, Read 1-256 blocks at LBA -1\n");
|
||||
printf("4, Read 2-256 blocks all but one beyond end-of-lun.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
if (num_blocks >= 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big for read-beyond-eol tests with READ10. Skipping test.\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* read 1-256 blocks, one block beyond the end-of-lun */
|
||||
printf("Reading last 1-256 blocks one block beyond eol ... ");
|
||||
for (i=1; i<=256; i++) {
|
||||
task = iscsi_read10_sync(iscsi, lun, num_blocks + 2 - i, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 beyond end-of-lun did not fail with sense.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Reading 1 - 256 blocks at LBA 2^31 */
|
||||
printf("Reaing 1-256 blocks at LBA 2^31 ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_read10_sync(iscsi, lun, 0x80000000, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command should fail when reading from LBA 2^31\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 1 - 256 blocks at LBA -1 */
|
||||
printf("Read 1-256 blocks at LBA -1 ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_read10_sync(iscsi, lun, -1, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command should fail when reading at LBA -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 2-256 blocks, all but one block beyond the eol */
|
||||
printf("Reading 1-255 blocks beyond eol starting at last block ... ");
|
||||
for (i=2; i<=256; i++) {
|
||||
task = iscsi_read10_sync(iscsi, lun, num_blocks, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 beyond end-of-lun did not return sense.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0102_read10_0blocks(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, lun;
|
||||
|
||||
printf("0102_read10_0blocks:\n");
|
||||
printf("====================\n");
|
||||
if (show_info) {
|
||||
printf("Test that READ10 works correctly when transfer length is 0 blocks.\n");
|
||||
printf("1, Read at LBA:0 should work.\n");
|
||||
printf("2, Read at one block beyond end-of-lun should fail. (only on LUNs with less than 2^31 blocks)\n");
|
||||
printf("3, Read at LBA:2^31 should fail (only on LUNs with less than 2^31 blocks).\n");
|
||||
printf("4, Read at LBA:-1 should fail (only on LUNs with less than 2^31 blocks).\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
printf("READ10 0blocks at LBA:0 ... ");
|
||||
task = iscsi_read10_sync(iscsi, lun, 0, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("READ10 0blocks at one block beyond <end-of-LUN> ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_read10_sync(iscsi, lun, num_blocks + 2, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: Should fail when reading 0blocks beyond end\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("READ10 0blocks at LBA 2^31 ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_read10_sync(iscsi, lun, 0x80000000, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: Should fail when reading 0blocks at 2^31\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("READ10 0blocks at LBA -1 ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_read10_sync(iscsi, lun, -1, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: Should fail when reading 0blocks at -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2010 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 <string.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0103_read10_rdprotect(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0103_read10_rdprotect:\n");
|
||||
printf("======================\n");
|
||||
if (show_info) {
|
||||
printf("Test how READ10 handles the rdprotect bits\n");
|
||||
printf("1, Any non-zero valued for rdprotect should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) {
|
||||
logging(LOG_VERBOSE, "[SKIPPED] Not SBC device."
|
||||
" Skipping test");
|
||||
return -2;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* Try out Different non-zero values for RDPROTECT. They should all fail */
|
||||
printf("Read10 with non-zero RDPROTECT ... ");
|
||||
for (i = 1; i < 8; i++) {
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ10;
|
||||
task->cdb[1] = (i<<5)&0xe0;
|
||||
task->cdb[8] = 1;
|
||||
task->cdb_size = 10;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = block_size;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 with rdprotect should fail with ILLEGAL REQUEST/INVALID_FIELD_IN_CDB\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,245 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2010 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 <string.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0104_read10_flags(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
|
||||
printf("0104_read10_flags:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test how READ10 handles DPO, FUA and FUA_NV flags.\n");
|
||||
printf("1, DPO:1 should work\n");
|
||||
printf("2, FUA:1 and FUA_NV:0 should work\n");
|
||||
printf("3, FUA:1 and FUA_NV:1 should work\n");
|
||||
printf("4, FUA:0 and FUA_NV:1 should work\n");
|
||||
printf("5, DPO:1 , FUA:1 and FUA_NV:1 should work\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) {
|
||||
logging(LOG_VERBOSE, "[SKIPPED] Not SBC device."
|
||||
" Skipping test");
|
||||
return -2;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* Try out DPO : 1 */
|
||||
printf("Read10 with DPO==1 ... ");
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ10;
|
||||
task->cdb[1] = 0x10;
|
||||
task->cdb[8] = 1;
|
||||
task->cdb_size = 10;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = block_size;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 with DPO==1 Failed. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
|
||||
/* Try out FUA : 1 FUA_NV : 0 */
|
||||
printf("Read10 with FUA==1 FUA_NV==0 ... ");
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ10;
|
||||
task->cdb[1] = 0x08;
|
||||
task->cdb[8] = 1;
|
||||
task->cdb_size = 10;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = block_size;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 with FUA==1 FUA_NV==0 Failed. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Try out FUA : 1 FUA_NV : 1 */
|
||||
printf("Read10 with FUA==1 FUA_NV==1 ... ");
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ10;
|
||||
task->cdb[1] = 0x0a;
|
||||
task->cdb[8] = 1;
|
||||
task->cdb_size = 10;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = block_size;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 with FUA==1 FUA_NV==1 Failed. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Try out FUA : 0 FUA_NV : 1 */
|
||||
printf("Read10 with FUA==0 FUA_NV==1 ... ");
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ10;
|
||||
task->cdb[1] = 0x02;
|
||||
task->cdb[8] = 1;
|
||||
task->cdb_size = 10;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = block_size;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 with FUA==0 FUA_NV==1 Failed. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Try out DPO : 1 FUA : 1 FUA_NV : 1 */
|
||||
printf("Read10 with DPO==1 FUA==1 FUA_NV==1 ... ");
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ10;
|
||||
task->cdb[1] = 0x18;
|
||||
task->cdb[8] = 1;
|
||||
task->cdb_size = 10;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = block_size;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 with DPO==1 FUA==1 FUA_NV==0Failed. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,283 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2010 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 <string.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0105_read10_invalid(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
struct iscsi_data data;
|
||||
char buf[4096];
|
||||
int ret, lun;
|
||||
|
||||
printf("0105_read10_invalid:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test various protocol violations.\n");
|
||||
printf("1, Read 1 block but set xferlength to 0. Should result in residual overflow of 'block_size' bytes.\n");
|
||||
printf("2, Read 1 block but set xferlength to 2*'block_size'. Should result in residual underflow of 'block_size' bytes.\n");
|
||||
printf("3, Read 1 block but set xferlength to 200. Should result in residual overflow of 'block_size'-200 bytes.\n");
|
||||
printf("4, Read 2 blocks but set xferlength to 'block_size'. Should result in residual overflow of 'block_size' bytes.\n");
|
||||
printf("5, Read 1 block but send one block as data-out write on the iSCSI level. Should result in both residual overflow and underflow of 'block_size' bytes.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* Try a read of 1 block but xferlength == 0 */
|
||||
printf("Read10 1 block but with iscsi ExpectedDataTransferLength==0 ... ");
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ10;
|
||||
task->cdb[8] = 1;
|
||||
task->cdb_size = 10;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = 0;
|
||||
|
||||
/* we don't want autoreconnect since some targets will drop the session
|
||||
* on this condition.
|
||||
*/
|
||||
iscsi_set_noautoreconnect(iscsi, 1);
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_CANCELLED) {
|
||||
scsi_free_scsi_task(task);
|
||||
printf("Target dropped the session [OK]\n");
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 of 1 block with iscsi ExpectedDataTransferLength==0 should not fail.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->residual_status != SCSI_RESIDUAL_OVERFLOW ||
|
||||
task->residual != block_size) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 returned incorrect residual overflow.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* in case the previous test failed the session */
|
||||
iscsi_set_noautoreconnect(iscsi, 0);
|
||||
|
||||
/* Try a read of 1 block but xferlength == 1024 */
|
||||
printf("Read10 1 block but with iscsi ExpectedDataTransferLength==1024 ... ");
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ10;
|
||||
task->cdb[8] = 1;
|
||||
task->cdb_size = 10;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = 1024;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 of 1 block with iscsi ExpectedDataTransferLength==1024 should not fail.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW ||
|
||||
task->residual != block_size) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 returned incorrect residual underflow.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Try a read of 1 block but xferlength == 200 */
|
||||
printf("Read10 1 block but with iscsi ExpectedDataTransferLength==200 ... ");
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ10;
|
||||
task->cdb[8] = 1;
|
||||
task->cdb_size = 10;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = 200;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 of 1 block with iscsi ExpectedDataTransferLength==200 should not fail.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->residual_status != SCSI_RESIDUAL_OVERFLOW ||
|
||||
task->residual != block_size - 200) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 returned incorrect residual overflow.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Try a read of 2 blocks but xferlength == 'block_size' */
|
||||
printf("Read10 2 blocks but with iscsi ExpectedDataTransferLength==%zu ... ", block_size);
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ10;
|
||||
task->cdb[8] = 2;
|
||||
task->cdb_size = 10;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = block_size;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 of 2 blocks with iscsi ExpectedDataTransferLength==%zu should succeed.\n", block_size);
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->residual_status != SCSI_RESIDUAL_OVERFLOW ||
|
||||
task->residual != block_size) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 returned incorrect residual overflow.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Try a read of 1 block but make it a data-out write on the iscsi layer */
|
||||
printf("Read10 of 1 block but sent as data-out write in iscsi layer ... ");
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ10;
|
||||
task->cdb[8] = 1;
|
||||
task->cdb_size = 10;
|
||||
task->xfer_dir = SCSI_XFER_WRITE;
|
||||
task->expxferlen = sizeof(buf);
|
||||
|
||||
data.size = sizeof(buf);
|
||||
data.data = (unsigned char *)&buf[0];
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, &data) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read10 of 1 block but iscsi data-out write should fail.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2010 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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0110_readcapacity10_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
struct scsi_readcapacity10 *rc10;
|
||||
int ret, lun;
|
||||
|
||||
ret = 0;
|
||||
|
||||
printf("0110_readcapacity10_simple:\n");
|
||||
printf("===========================\n");
|
||||
if (show_info) {
|
||||
printf("Test that basic READCAPACITY10 works\n");
|
||||
printf("1, Readcapacity10 should work.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Test that Readcapacity10 is supported ... ");
|
||||
task = iscsi_readcapacity10_sync(iscsi, lun, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send readcapacity10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Readcapacity command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
rc10 = scsi_datain_unmarshall(task);
|
||||
if (rc10 == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("failed to unmarshall readcapacity10 data. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2010 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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0120_read6_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0120_read6_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic READ6 functionality.\n");
|
||||
printf("1, Verify we can read the first 1-256 blocks of the LUN using READ6.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Reading first 1-256 blocks ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_read6_sync(iscsi, lun, 0, i * block_size, block_size);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read6 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2010 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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0121_read6_beyond_eol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0121_read6_beyond_eol:\n");
|
||||
printf("======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that READ6 fails if reading beyond end-of-lun.\n");
|
||||
printf("This test is skipped for LUNs with more than 2^20 blocks\n");
|
||||
printf("1, Read 1-256 blocks one block beyond end-of-lun.\n");
|
||||
printf("2, Read 2-256 blocks all but one beyond end-of-lun.\n");
|
||||
printf("3, Read 0(==256) blocks 128 blocks beyond end-of-lun.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
if (num_blocks > 0x1fffff) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big for read-beyond-eol tests with READ6. Skipping test.\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* read 1-256 blocks, one block beyond the end-of-lun */
|
||||
printf("Reading last 1-256 blocks one block beyond eol ... ");
|
||||
for (i=1; i<=256; i++) {
|
||||
task = iscsi_read6_sync(iscsi, lun, num_blocks + 2 - i, i * block_size, block_size);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ6 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ6 beyond end-of-lun did not fail with sense.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ6 beyond end-of-lun did not return sense key ILLEGAL_REQUEST. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ6 beyond end-of-lun did not return sense ascq LBA OUT OF RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 2-256 blocks, all but one block beyond the eol */
|
||||
printf("Reading 1-255 blocks beyond eol starting at last block ... ");
|
||||
for (i=2; i<=256; i++) {
|
||||
task = iscsi_read6_sync(iscsi, lun, num_blocks, i * block_size, block_size);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ6 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ6 beyond end-of-lun did not return sense.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ6 beyond end-of-lun did not return sense key ILLEGAL_REQUEST. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ6 beyond end-of-lun did not return sense ascq LBA OUT OF RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 0 (==256) blocks 128 blocks from eol */
|
||||
printf("Reading 0(==256) blocks beyond eol starting at 128 blocks before eol ... ");
|
||||
task = iscsi_read6_sync(iscsi, lun, num_blocks-128, i * block_size, block_size);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ6 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ6 beyond end-of-lun did not return sense.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ6 beyond end-of-lun did not return sense key ILLEGAL_REQUEST. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ6 beyond end-of-lun did not return sense ascq LBA OUT OF RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,283 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2010 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 <string.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0122_read6_invalid(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
struct iscsi_data data;
|
||||
char buf[4096];
|
||||
int ret, lun;
|
||||
|
||||
printf("0122_read6_invalid:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test various protocol violations.\n");
|
||||
printf("1, Read 1 block but set xferlength to 0. Should result in residual overflow of 'block_size' bytes.\n");
|
||||
printf("2, Read 1 block but set xferlength to 2*'block_size'. Should result in residual underflow of 'block_size' bytes.\n");
|
||||
printf("3, Read 1 block but set xferlength to 200. Should result in residual overflow of 'block_size' - 200 bytes.\n");
|
||||
printf("4, Read 2 blocks but set xferlength to 'block_size'. Should result in residual overflow of 'block_size' bytes.\n");
|
||||
printf("5, Read 1 block but send one block as data-out write on the iSCSI level. Should result in both residual overflow and underflow of 'block_size' bytes.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* Try a read of 1 block but xferlength == 0 */
|
||||
printf("Read6 1 block but with iscsi ExpectedDataTransferLength==0 ... ");
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ6;
|
||||
task->cdb[4] = 1;
|
||||
task->cdb_size = 6;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = 0;
|
||||
|
||||
/* we don't want autoreconnect since some targets will drop the session
|
||||
* on this condition.
|
||||
*/
|
||||
iscsi_set_noautoreconnect(iscsi, 1);
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read6 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_CANCELLED) {
|
||||
scsi_free_scsi_task(task);
|
||||
printf("Target dropped the session [OK]\n");
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 of 1 block with iscsi ExpectedDataTransferLength==0 should not fail.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->residual_status != SCSI_RESIDUAL_OVERFLOW ||
|
||||
task->residual != block_size) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 returned incorrect residual overflow.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* in case the previous test failed the session */
|
||||
iscsi_set_noautoreconnect(iscsi, 0);
|
||||
|
||||
/* Try a read of 1 block but xferlength == 1024 */
|
||||
printf("Read6 1 block but with iscsi ExpectedDataTransferLength==1024 ... ");
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ6;
|
||||
task->cdb[4] = 1;
|
||||
task->cdb_size = 6;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = 1024;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read6 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 of 1 block with iscsi ExpectedDataTransferLength==1024 should not fail.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW ||
|
||||
task->residual != block_size) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 returned incorrect residual underflow.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Try a read of 1 block but xferlength == 200 */
|
||||
printf("Read6 1 block but with iscsi ExpectedDataTransferLength==200 ... ");
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ6;
|
||||
task->cdb[4] = 1;
|
||||
task->cdb_size = 6;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = 200;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read6 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 of 1 block with iscsi ExpectedDataTransferLength==200 should not fail.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->residual_status != SCSI_RESIDUAL_OVERFLOW ||
|
||||
task->residual != block_size - 200) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 returned incorrect residual overflow.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Try a read of 2 blocks but xferlength == block_size */
|
||||
printf("Read6 2 blocks but with iscsi ExpectedDataTransferLength==%zu ... ", block_size);
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ6;
|
||||
task->cdb[4] = 2;
|
||||
task->cdb_size = 6;
|
||||
task->xfer_dir = SCSI_XFER_READ;
|
||||
task->expxferlen = block_size;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read6 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 of 2 blocks with iscsi ExpectedDataTransferLength==%zu should succeed.\n", block_size);
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->residual_status != SCSI_RESIDUAL_OVERFLOW ||
|
||||
task->residual != block_size) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 returned incorrect residual overflow.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Try a read of 1 block but make it a data-out write on the iscsi layer */
|
||||
printf("Read6 of 1 block but sent as data-out write in iscsi layer ... ");
|
||||
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = SCSI_OPCODE_READ6;
|
||||
task->cdb[4] = 1;
|
||||
task->cdb_size = 6;
|
||||
task->xfer_dir = SCSI_XFER_WRITE;
|
||||
task->expxferlen = sizeof(buf);
|
||||
|
||||
data.size = sizeof(buf);
|
||||
data.data = (unsigned char *)&buf[0];
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, &data) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read6 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read6 of 1 block but iscsi data-out write should fail.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2010 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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0130_verify10_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
printf("0130_verify10_simple:\n");
|
||||
printf("=====================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic VERIFY10 functionality.\n");
|
||||
printf("1, Read and verify the first 1-256 blocks of the LUN using READ10/VERIFY10.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
buf = malloc(256 * block_size);
|
||||
if (buf == NULL) {
|
||||
printf("Failed to allocate buffer.\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Read first 256 blocks.\n");
|
||||
task = iscsi_read10_sync(iscsi, lun, 0, 256 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(buf, task->datain.data, task->datain.size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* verify the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Verify first 1-256 blocks.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = verify10(iscsi, lun, 0, i * block_size, block_size, 0, 1, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
free(buf);
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2010 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 <string.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0131_verify10_mismatch(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
|
||||
printf("0131_verify10_mismatch:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic VERIFY10 functionality.\n");
|
||||
printf("1, Verify the first 1-256 blocks with a deliberate error detects the mismatch.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
buf = malloc(256 * block_size);
|
||||
if (buf == NULL) {
|
||||
printf("Failed to allocate buffer.\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Read first 256 blocks.\n");
|
||||
task = iscsi_read10_sync(iscsi, lun, 0, 256 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(buf, task->datain.data, task->datain.size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read and verify the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Verify first 1-256 blocks with a miscompare.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
int offset = random() % (i * block_size);
|
||||
|
||||
/* flip a random byte in the data */
|
||||
buf[offset] ^= 'X';
|
||||
|
||||
ret = verify10_miscompare(iscsi, lun, 0, i * block_size, block_size, 0, 1, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* flip the byte back */
|
||||
buf[offset] ^= 'X';
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
free(buf);
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2010 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 <string.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0132_verify10_mismatch_no_cmp(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
printf("0132_verify10_mismatch_no_cmp:\n");
|
||||
printf("==============================\n");
|
||||
if (show_info) {
|
||||
printf("Test VERIFY10 BYTCHK:0 only checks medium and should never fail unless the medium is bad.\n");
|
||||
printf("1, Read the first 256 blocks and verify the medium is good.\n");
|
||||
printf("2, Verify the first 1-256 blocks retruns SUCCESS if BYTCHK is 0\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
buf = malloc(256 * block_size);
|
||||
if (buf == NULL) {
|
||||
printf("Failed to allocate buffer.\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Read first 256 blocks.\n");
|
||||
task = iscsi_read10_sync(iscsi, lun, 0, 256 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(buf, task->datain.data, task->datain.size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read and verify the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Verify first 1-256 blocks with a miscompare but BYTCHK==0.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
int offset = random() % (i * block_size);
|
||||
|
||||
/* flip a random byte in the data */
|
||||
buf[offset] ^= 'X';
|
||||
|
||||
ret = verify10(iscsi, lun, 0, i * block_size, block_size, 0, 1, 0, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* flip the byte back */
|
||||
buf[offset] ^= 'X';
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
free(buf);
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0133_verify10_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
int ret, i, lun;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
printf("0133_verify10_beyond_eol:\n");
|
||||
printf("========================\n");
|
||||
if (show_info) {
|
||||
printf("Test that VERIFY10 fails if reading beyond end-of-lun.\n");
|
||||
printf("This test is skipped for LUNs with more than 2^31 blocks\n");
|
||||
printf("1, Verify 2-256 blocks one block beyond end-of-lun.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
if (num_blocks >= 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big for read-beyond-eol tests with VERIFY10. Skipping test.\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
buf = malloc(256 * block_size);
|
||||
|
||||
/* verify 2 - 256 blocks beyond the end of the device */
|
||||
printf("Verifying 2-256 blocks beyond end-of-device.\n");
|
||||
for (i = 2; i <= 256; i++) {
|
||||
ret = verify10_lbaoutofrange(iscsi, lun, num_blocks, i * block_size, block_size, 0, 1, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
free(buf);
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0160_readcapacity16_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_readcapacity16 *rc;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
|
||||
printf("0160_readcapacity16_simple:\n");
|
||||
printf("===========================\n");
|
||||
if (show_info) {
|
||||
printf("Test that basic READCAPACITY16 works\n");
|
||||
printf("1, READCAPACITY16 should work.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Test that READCAPACITY16 is supported ... ");
|
||||
task = iscsi_readcapacity16_sync(iscsi, lun);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READCAPACITY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READCAPACITY16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
rc = scsi_datain_unmarshall(task);
|
||||
if (rc == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("failed to unmarshall READCAPACITY16 data. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2010 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 <string.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0161_readcapacity16_alloclen(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
|
||||
printf("0161_readcapacity16_alloclen:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test allocation-length for READCAPACITY16\n");
|
||||
printf("1, READCAPACITY16 with alloclen==0 is not an error\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
printf("READCAPACITY16 with AllocationLength==0 ... ");
|
||||
task = malloc(sizeof(struct scsi_task));
|
||||
if (task == NULL) {
|
||||
printf("Failed to allocate task structure\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
memset(task, 0, sizeof(struct scsi_task));
|
||||
task->cdb[0] = 0x9e;
|
||||
task->cdb[1] = 0x10;
|
||||
task->cdb_size = 16;
|
||||
task->xfer_dir = SCSI_XFER_NONE;
|
||||
task->expxferlen = 0;
|
||||
|
||||
if (iscsi_scsi_command_sync(iscsi, lun, task, NULL) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READCAPACITY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READCAPACITY16 with AllocationLength==0 should not fail. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0170_unmap_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0170_unmap_simple:\n");
|
||||
printf("==================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic UNMAP functionality.\n");
|
||||
printf("1, Test UNMAP the first 1-256 blocks of the LUN.\n");
|
||||
printf("2, Test UNMAP the last 1-256 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rc16 == NULL || rc16->lbpme == 0){
|
||||
printf("Logical unit is fully provisioned. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("data_loss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* unmap the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Unmapping first 1-256 blocks ... ");
|
||||
for (i=1; i<=256; i++) {
|
||||
struct unmap_list list[1];
|
||||
|
||||
list[0].lba = 0;
|
||||
list[0].num = i;
|
||||
task = iscsi_unmap_sync(iscsi, lun, 0, 0, &list[0], 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send UNMAP command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("UNMAP command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* unmap the last 1 - 256 blocks at the end of the LUN */
|
||||
printf("Unmapping last 1-256 blocks ... ");
|
||||
for (i=1; i<=256; i++) {
|
||||
struct unmap_list list[1];
|
||||
|
||||
list[0].lba = num_blocks + 1 - i;
|
||||
list[0].num = i;
|
||||
task = iscsi_unmap_sync(iscsi, lun, 0, 0, &list[0], 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send UNMAP command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("UNMAP command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0171_unmap_zero(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0171_unmap_zero:\n");
|
||||
printf("================\n");
|
||||
if (show_info) {
|
||||
printf("Test UNMAP of 0 blocks.\n");
|
||||
printf("1, Try to UNMAP 0 blocks at LBA 0 to LBA 255\n");
|
||||
printf("2, Try to UNMAP 0 blocks at 0 to 255 blocks from end-of-lun\n");
|
||||
printf("3, Try to UNMAP 0 blocks at 1 to 256 blocks beyond end-of-lun\n");
|
||||
printf("4, Send UNMAP without any block descriptors\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rc16 == NULL || rc16->lbpme == 0){
|
||||
printf("Logical unit is fully provisioned. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("data_loss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* unmap no blocks at LBA 0 - 255 */
|
||||
printf("Unmapping of no block at lbas 0-255 blocks ... ");
|
||||
for (i=0; i<=255; i++) {
|
||||
struct unmap_list list[1];
|
||||
|
||||
list[0].lba = i;
|
||||
list[0].num = 0;
|
||||
task = iscsi_unmap_sync(iscsi, lun, 0, 0, &list[0], 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send UNMAP command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("UNMAP command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* unmap no blocks at the last 1 - 256 blocks at the end of the LUN */
|
||||
printf("Unmapping last 1-256 blocks ... ");
|
||||
for (i=0; i<=255; i++) {
|
||||
struct unmap_list list[1];
|
||||
|
||||
list[0].lba = num_blocks - i;
|
||||
list[0].num = 0;
|
||||
task = iscsi_unmap_sync(iscsi, lun, 0, 0, &list[0], 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send UNMAP command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("UNMAP command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
/* unmap no blocks 0-255 blocks beyond the end of the LUN */
|
||||
printf("Unmapping no blocks but 0-255 blocks beyong end of LUN... ");
|
||||
for (i=0; i<=255; i++) {
|
||||
struct unmap_list list[1];
|
||||
|
||||
list[0].lba = num_blocks + 1 + i;
|
||||
list[0].num = 0;
|
||||
task = iscsi_unmap_sync(iscsi, lun, 0, 0, &list[0], 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send UNMAP command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STATUS==GOOD. UNMAP command should fail with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("UNMAP fail but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
/* unmap with no block descriptors at all */
|
||||
printf("Unmap without any block descriptors ... ");
|
||||
task = iscsi_unmap_sync(iscsi, lun, 0, 0, NULL, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send UNMAP command: %s\n", iscsi_get_error(iscsi)); ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("UNMAP command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,279 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0180_writesame10_unmap(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int full_size;
|
||||
struct scsi_inquiry_logical_block_provisioning *lbp;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0180_writesame10_unmap:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic WRITESAME10-UNMAP functionality.\n");
|
||||
printf("1, If LBPME==1 we should have VPD page 0xB2\n");
|
||||
printf("2, UNMAP the first 1-256 blocks at the start of the LUN\n");
|
||||
printf("3, UNMAP the last 1-256 blocks at the end of the LUN\n");
|
||||
printf("4, Verify that UNMAP == 0 and ANCHOR == 1 is invalid\n");
|
||||
printf("5, UNMAP == 1 and ANCHOR == 1\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
if (rc16 == NULL || rc16->lbpme == 0){
|
||||
printf("Logical unit is fully provisioned.\n");
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN does not use thin provisioning. LBPME==0.\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* Check that if we have logical block provisioning we also have the VPD page for it */
|
||||
printf("Logical Block Provisioning is available. Check that VPD page 0xB2 exists ... ");
|
||||
|
||||
/* See how big this inquiry data is */
|
||||
task = iscsi_inquiry_sync(iscsi, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, 64);
|
||||
if (task == NULL || task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
full_size = scsi_datain_getfullsize(task);
|
||||
if (full_size > task->datain.size) {
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
/* we need more data for the full list */
|
||||
if ((task = iscsi_inquiry_sync(iscsi, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, full_size)) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
lbp = scsi_datain_unmarshall(task);
|
||||
if (lbp == NULL) {
|
||||
printf("failed to unmarshall inquiry datain blob\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
if (lbp->lbpws10 == 0) {
|
||||
printf("Device does not support WRITE_SAME10 for UNMAP. All WRITE_SAME10 commands to unmap should fail.\n");
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* unmap the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Unmapping first 1-256 blocks ... ");
|
||||
if (lbp->lbpws10 == 0) {
|
||||
printf("(Should all fail since LBPWS10 is 0) ");
|
||||
}
|
||||
for (i=1; i<=256; i++) {
|
||||
/* only try unmapping whole physical blocks, of if unmap using ws10 is not supported
|
||||
we test for all and they should all fail */
|
||||
if (lbp->lbpws10 == 1 && i % lbppb) {
|
||||
continue;
|
||||
}
|
||||
task = iscsi_writesame10_sync(iscsi, lun, 0,
|
||||
NULL, 0,
|
||||
i,
|
||||
0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (lbp->lbpws10) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
} else {
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command should fail since LBPWS10 is 0 but failed with wrong sense code %s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* unmap the last 1 - 256 blocks at the end of the LUN */
|
||||
printf("Unmapping last 1-256 blocks ... ");
|
||||
if (lbp->lbpws10 == 0) {
|
||||
printf("(Should all fail since LBPWS10 is 0) ");
|
||||
}
|
||||
for (i=1; i<=256; i++) {
|
||||
/* only try unmapping whole physical blocks, of if unmap using ws10 is not supported
|
||||
we test for all and they should all fail */
|
||||
if (lbp->lbpws10 == 1 && i % lbppb) {
|
||||
continue;
|
||||
}
|
||||
|
||||
task = iscsi_writesame10_sync(iscsi, lun, num_blocks + 1 - i,
|
||||
NULL, 0,
|
||||
i,
|
||||
0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (lbp->lbpws10) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
} else {
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command should fail since LBPWS10 is 0 but failed with wrong sense code %s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Test that UNMAP=0 and ANCHOR==1 fails with check condition */
|
||||
printf("Try UNMAP==0 and ANCHOR==1 ... ");
|
||||
task = iscsi_writesame10_sync(iscsi, lun, 0,
|
||||
NULL, 0,
|
||||
64,
|
||||
1, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 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_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 with UNMAP=0 ANCHOR=1 failed with wrong sense code %d %s(%d) %s(0x%04x) should be CHECK_CONDITION/ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB\n",
|
||||
task->status,
|
||||
scsi_sense_key_str(task->sense.key), task->sense.key,
|
||||
scsi_sense_ascq_str(task->sense.ascq), task->sense.ascq);
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Test UNMAP=1 and ANCHOR==1 */
|
||||
printf("Try UNMAP==1 and ANCHOR==1 ... ");
|
||||
if (lbp->anc_sup == 0) {
|
||||
printf("(ANC_SUP==0 so check condition expected) ");
|
||||
}
|
||||
task = iscsi_writesame10_sync(iscsi, lun, 0,
|
||||
NULL, 0,
|
||||
64,
|
||||
1, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (lbp->anc_sup == 0) {
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 with UNMAP=1 ANCHOR=1 failed with wrong sense code %d %s(%d) %s(0x%04x) should be CHECK_CONDITION/ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB\n",
|
||||
task->status,
|
||||
scsi_sense_key_str(task->sense.key), task->sense.key,
|
||||
scsi_sense_ascq_str(task->sense.ascq), task->sense.ascq);
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
} else {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0181_writesame10_unmap_unaligned(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0181_writesame10_unmap_unaligned:\n");
|
||||
printf("=================================\n");
|
||||
if (show_info) {
|
||||
printf("Test unaligned WRITESAME10-UNMAP functionality.\n");
|
||||
printf("1, UNMAP the first 1-lbppb blocks at the start of the LUN\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rc16 == NULL || rc16->lbpme == 0){
|
||||
printf("Logical unit is fully provisioned. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
if (lbppb < 2) {
|
||||
printf("LBPPB==%d Can not unmap fractional physical block\n", lbppb);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* unmap the first 1 - lbppb blocks at the start of the LUN */
|
||||
printf("Unmapping first 1 - (LBPPB-1) blocks ... ");
|
||||
for (i=1; i < lbppb; i++) {
|
||||
task = iscsi_writesame10_sync(iscsi, lun, 0,
|
||||
NULL, 0,
|
||||
i,
|
||||
0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command to unmap a fractional physical block should fail\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0182_writesame10_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char buf[4096];
|
||||
|
||||
printf("0182_writesame10_beyondeol:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITESAME10 fails if writing beyond end-of-lun.\n");
|
||||
printf("This test is skipped for LUNs with more than 2^31 blocks\n");
|
||||
printf("1, Write 1-256 blocks one block beyond end-of-lun.\n");
|
||||
printf("2, Write 1-256 blocks at LBA 2^31\n");
|
||||
printf("3, Write 1-256 blocks at LBA -1\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
if (num_blocks >= 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big for read-beyond-eol tests with WRITESAME10. Skipping test.\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* write 1 - 256 blocks beyond the end of the device */
|
||||
printf("Writing 1-256 blocks beyond end-of-device ... ");
|
||||
for (i = 2; i <= 257; i++) {
|
||||
task = iscsi_writesame10_sync(iscsi, lun, num_blocks,
|
||||
buf, block_size,
|
||||
i,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command should fail when writing beyond end of device\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* writing 1 - 256 blocks at LBA 2^31 */
|
||||
printf("Writing 1-256 blocks at LBA 2^31 ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writesame10_sync(iscsi, lun, 0x80000000,
|
||||
buf, block_size,
|
||||
i,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command should fail when writing at LBA 2^31\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* write 1 - 256 blocks at LBA -1 */
|
||||
printf("Writing 1-256 blocks at LBA -1 ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writesame10_sync(iscsi, lun, -1,
|
||||
buf, block_size,
|
||||
i,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command should fail when reading at LBA -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0183_writesame10_wrprotect(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char buf[4096];
|
||||
|
||||
printf("0183_writesame10_wrptotect:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITESAME10 wrprotect\n");
|
||||
printf("1, Write using WRPROTECT as non-zero\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* Writesame10 with wrprotect */
|
||||
printf("WRITESAME10 with WRPROTECT ... ");
|
||||
for (i = 1; i <= 7; i++) {
|
||||
task = iscsi_writesame10_sync(iscsi, lun, 0,
|
||||
buf, block_size,
|
||||
1,
|
||||
0, 0, i, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command should fail when WRPROTECT is set\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,208 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0184_writesame10_0blocks(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
unsigned char buf[4096];
|
||||
|
||||
printf("0184_writesame10_0blocks:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITESAME10 works correctly when transfer length is 0 blocks.\n");
|
||||
printf("1, Writesame at LBA:0 should work.\n");
|
||||
printf("2, Writesame at one block beyond end-of-lun should fail. (only on LUNs with less than 2^31 blocks)\n");
|
||||
printf("3, Writesame at LBA:2^31 should fail (only on LUNs with less than 2^31 blocks).\n");
|
||||
printf("4, Writesame at LBA:-1 should fail (only on LUNs with less than 2^31 blocks).\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
printf("Writesame10 0blocks at LBA:0 ... ");
|
||||
task = iscsi_writesame10_sync(iscsi, lun, 0,
|
||||
buf, block_size,
|
||||
0,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (inq_bl == NULL) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("Target does not support block limits VPD\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if ((!inq_bl->wsnz && task->status != SCSI_STATUS_GOOD) ||
|
||||
(inq_bl->wsnz && task->status != SCSI_STATUS_CHECK_CONDITION)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command: failed with sense and WSNZ = %d. "
|
||||
"%s\n", inq_bl->wsnz, iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Writesame10 0blocks at one block beyond <end-of-LUN> ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_writesame10_sync(iscsi, lun, num_blocks + 2,
|
||||
buf, block_size,
|
||||
0,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command: Should fail when writing 0blocks beyond end\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Writesame10 0blocks at LBA 2^31 ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_writesame10_sync(iscsi, lun, 0x80000000,
|
||||
buf, block_size,
|
||||
0,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command: Should fail when writing 0blocks at 2^31\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Writesame10 0blocks at LBA -1 ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_writesame10_sync(iscsi, lun, -1,
|
||||
buf, block_size,
|
||||
0,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command: Should fail when writing 0blocks at -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,271 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0190_writesame16_unmap(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int full_size;
|
||||
struct scsi_inquiry_logical_block_provisioning *lbp;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0190_writesame16_unmap:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic WRITESAME16-UNMAP functionality.\n");
|
||||
printf("1, If LBPME==1 we should have VPD page 0xB2\n");
|
||||
printf("2, UNMAP the first 1-256 blocks at the start of the LUN\n");
|
||||
printf("3, UNMAP the last 1-256 blocks at the end of the LUN\n");
|
||||
printf("4, Verify that UNMAP == 0 and ANCHOR == 1 is invalid\n");
|
||||
printf("5, UNMAP == 1 and ANCHOR == 1\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
if (rc16 == NULL || rc16->lbpme == 0){
|
||||
printf("LBPME not set. Skip test for CPD page 0xB2 (logical block provisioning)\n");
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* Check that id we have logical block provisioning we also have the VPD page for it */
|
||||
printf("Logical Block Provisioning is available. Check that VPD page 0xB2 exists ... ");
|
||||
|
||||
/* See how big this inquiry data is */
|
||||
task = iscsi_inquiry_sync(iscsi, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, 64);
|
||||
if (task == NULL || task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
full_size = scsi_datain_getfullsize(task);
|
||||
if (full_size > task->datain.size) {
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
/* we need more data for the full list */
|
||||
if ((task = iscsi_inquiry_sync(iscsi, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, full_size)) == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Inquiry command failed : %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
lbp = scsi_datain_unmarshall(task);
|
||||
if (lbp == NULL) {
|
||||
printf("failed to unmarshall inquiry datain blob\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
if (lbp->lbpws == 0) {
|
||||
printf("Device does not support WRITE_SAME16 for UNMAP. All WRITE_SAME16 commands to unmap should fail.\n");
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* unmap the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Unmapping first 1-256 blocks ... ");
|
||||
if (lbp->lbpws == 0) {
|
||||
printf("(Should all fail since LBPWS is 0) ");
|
||||
}
|
||||
for (i=1; i<=256; i++) {
|
||||
/* only try unmapping whole physical blocks, of if unmap using ws16 is not supported
|
||||
we test for all and they should all fail */
|
||||
if (lbp->lbpws == 1 && i % lbppb) {
|
||||
continue;
|
||||
}
|
||||
task = iscsi_writesame16_sync(iscsi, lun, 0,
|
||||
NULL, 0,
|
||||
i,
|
||||
0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (lbp->lbpws) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
} else {
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command should fail since LBPWS is 0 but failed with wrong sense code %s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* unmap the last 1 - 256 blocks at the end of the LUN */
|
||||
printf("Unmapping last 1-256 blocks ... ");
|
||||
if (lbp->lbpws == 0) {
|
||||
printf("(Should all fail since LBPWS is 0) ");
|
||||
}
|
||||
for (i=1; i<=256; i++) {
|
||||
/* only try unmapping whole physical blocks, of if unmap using ws16 is not supported
|
||||
we test for all and they should all fail */
|
||||
if (lbp->lbpws == 1 && i % lbppb) {
|
||||
continue;
|
||||
}
|
||||
|
||||
task = iscsi_writesame16_sync(iscsi, lun, num_blocks + 1 - i,
|
||||
NULL, 0,
|
||||
i,
|
||||
0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (lbp->lbpws) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
} else {
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command should fail since LBPWS is 0 but failed with wrong sense code %s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Test that UNMAP=0 and ANCHOR==1 fails with check condition */
|
||||
printf("Try UNMAP==0 and ANCHOR==1 ... ");
|
||||
task = iscsi_writesame16_sync(iscsi, lun, 0,
|
||||
NULL, 0,
|
||||
64,
|
||||
1, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 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_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 with UNMAP=0 ANCHOR=1 failed with wrong sense code %s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Test UNMAP=1 and ANCHOR==1 */
|
||||
printf("Try UNMAP==1 and ANCHOR==1 ... ");
|
||||
if (lbp->anc_sup == 0) {
|
||||
printf("(ANC_SUP==0 so check condition expected) ");
|
||||
}
|
||||
task = iscsi_writesame16_sync(iscsi, lun, 0,
|
||||
NULL, 0,
|
||||
64,
|
||||
1, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (lbp->anc_sup == 0) {
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 with UNMAP=1 ANCHOR=1 failed with wrong sense code %s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
} else {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0191_writesame16_unmap_unaligned(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0191_writesame16_unmap_unaligned:\n");
|
||||
printf("=================================\n");
|
||||
if (show_info) {
|
||||
printf("Test unaligned WRITESAME16-UNMAP functionality.\n");
|
||||
printf("1, UNMAP the first 1-lbppb blocks at the start of the LUN\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rc16 == NULL || rc16->lbpme == 0){
|
||||
printf("Logical unit is fully provisioned. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (lbppb < 2) {
|
||||
printf("LBPPB==%d Can not unmap fractional physical block\n", lbppb);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* unmap the first 1 - lbppb blocks at the start of the LUN */
|
||||
printf("Unmapping first 1 - (LBPPB-1) blocks ... ");
|
||||
for (i=1; i < lbppb; i++) {
|
||||
task = iscsi_writesame16_sync(iscsi, lun, 0,
|
||||
NULL, 0,
|
||||
i,
|
||||
0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command to unmap a fractional physical block should fail\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0192_writesame16_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char buf[4096];
|
||||
|
||||
printf("0192_writesame16_beyondeol:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITESAME16 fails if writing beyond end-of-lun.\n");
|
||||
printf("1, Write 1-256 blocks one block beyond end-of-lun.\n");
|
||||
printf("2, Write 1-256 blocks at LBA 2^63\n");
|
||||
printf("3, Write 1-256 blocks at LBA -1\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* write 1 - 256 blocks beyond the end of the device */
|
||||
printf("Writing 1-256 blocks beyond end-of-device ... ");
|
||||
for (i = 2; i <= 257; i++) {
|
||||
task = iscsi_writesame16_sync(iscsi, lun, num_blocks,
|
||||
buf, block_size,
|
||||
i,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command should fail when writing beyond end of device\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* writing 1 - 256 blocks at LBA 2^63 */
|
||||
printf("Writing 1-256 blocks at LBA 2^63 ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writesame16_sync(iscsi, lun, 0x8000000000000000ULL,
|
||||
buf, block_size,
|
||||
i,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command should fail when writing at LBA 2^63\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* write 1 - 256 blocks at LBA -1 */
|
||||
printf("Writing 1-256 blocks at LBA -1 ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writesame16_sync(iscsi, lun, -1,
|
||||
buf, block_size,
|
||||
i,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command should fail when reading at LBA -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0193_writesame16_wrprotect(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char buf[4096];
|
||||
|
||||
printf("0193_writesame16_wrptotect:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITESAME16 wrprotect\n");
|
||||
printf("1, Write using WRPROTECT as non-zero\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* Writesame16 with wrprotect */
|
||||
printf("WRITESAME16 with WRPROTECT ... ");
|
||||
for (i = 1; i <= 7; i++) {
|
||||
task = iscsi_writesame16_sync(iscsi, lun, 0,
|
||||
buf, block_size,
|
||||
1,
|
||||
0, 0, i, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command should fail when WRPROTECT is set\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,185 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0194_writesame16_0blocks(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
unsigned char buf[4096];
|
||||
|
||||
printf("0194_writesame16_0blocks:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITESAME16 works correctly when transfer length is 0 blocks.\n");
|
||||
printf("1, Writesame at LBA:0 should work.\n");
|
||||
printf("2, Writesame at one block beyond end-of-lun should fail.\n");
|
||||
printf("3, Writesame at LBA 2^63 should fail.\n");
|
||||
printf("4, Writesame at LBA -1 should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
printf("Writesame16 0blocks at LBA:0 ... ");
|
||||
task = iscsi_writesame16_sync(iscsi, lun, 0,
|
||||
buf, block_size,
|
||||
0,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Writesame16 0blocks at one block beyond <end-of-LUN> ... ");
|
||||
task = iscsi_writesame16_sync(iscsi, lun, num_blocks + 2,
|
||||
buf, block_size,
|
||||
0,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command: Should fail when writing 0blocks beyond end\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Writesame16 0blocks at LBA 2^63 ... ");
|
||||
task = iscsi_writesame16_sync(iscsi, lun, 0x8000000000000000,
|
||||
buf, block_size,
|
||||
0,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command: Should fail when writing 0blocks at 2^63\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Writesame16 0blocks at LBA -1 ... ");
|
||||
task = iscsi_writesame16_sync(iscsi, lun, -1,
|
||||
buf, block_size,
|
||||
0,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command: Should fail when writing 0blocks at -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0200_read16_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0200_read16_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic READ16 functionality.\n");
|
||||
printf("1, Verify we can read the first 1-256 blocks of the LUN.\n");
|
||||
printf("2, Verify we can read the last 1-256 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Reading first 1-256 blocks ... ");
|
||||
for (i=1; i<=256; i++) {
|
||||
task = iscsi_read16_sync(iscsi, lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read the last 1 - 256 blocks at the end of the LUN */
|
||||
printf("Reading last 1-256 blocks ... ");
|
||||
for (i=1; i<=256; i++) {
|
||||
task = iscsi_read16_sync(iscsi, lun, num_blocks +1 - i, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0201_read16_rdprotect(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, i, lun;
|
||||
|
||||
printf("0201_read16_rdprotect:\n");
|
||||
printf("======================\n");
|
||||
if (show_info) {
|
||||
printf("Test how READ16 handles the rdprotect bits\n");
|
||||
printf("1, Any non-zero valued for rdprotect should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
printf("Read16 with RDPROTECT ");
|
||||
for (i = 1; i <= 7; i++) {
|
||||
task = iscsi_read16_sync(iscsi, lun, 0, block_size, block_size, i, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read16 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_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read16 with RDPROTECT!=0 should have failed with CHECK_CONDITION/ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0202_read16_flags(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, lun;
|
||||
|
||||
printf("0202_read16_flags:\n");
|
||||
printf("==================\n");
|
||||
if (show_info) {
|
||||
printf("Test how READ16 handles the flag bits\n");
|
||||
printf("1, Reading with DPO should work\n");
|
||||
printf("2, Reading with FUA should work\n");
|
||||
printf("3, Reading with FUA_NV should work\n");
|
||||
printf("4, Reading with FUA+FUA_NV should work\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) {
|
||||
logging(LOG_VERBOSE, "[SKIPPED] Not SBC device."
|
||||
" Skipping test");
|
||||
return -2;
|
||||
}
|
||||
|
||||
printf("Read16 with DPO ");
|
||||
task = iscsi_read16_sync(iscsi, lun, 0, block_size, block_size, 0, 1, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Read16 with FUA ");
|
||||
task = iscsi_read16_sync(iscsi, lun, 0, block_size, block_size, 0, 0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Read16 with FUA_NV ");
|
||||
task = iscsi_read16_sync(iscsi, lun, 0, block_size, block_size, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Read16 with FUA+FUA_NV ");
|
||||
task = iscsi_read16_sync(iscsi, lun, 0, block_size, block_size, 0, 0, 1, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0203_read16_0blocks(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, lun;
|
||||
|
||||
printf("0203_read16_0blocks:\n");
|
||||
printf("====================\n");
|
||||
if (show_info) {
|
||||
printf("Test that READ16 works correctly when transfer length is 0 blocks.\n");
|
||||
printf("1, Read at 0 should work.\n");
|
||||
printf("2, Read at one block beyond end-of-lun should fail.\n");
|
||||
printf("3, Read at LBA:2^63 should fail.\n");
|
||||
printf("4, Read at LBA:-1 should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
printf("READ16 0blocks at LBA:0 ... ");
|
||||
task = iscsi_read16_sync(iscsi, lun, 0, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("READ16 0blocks at LBA:<beyond end-of-disk> ... ");
|
||||
task = iscsi_read16_sync(iscsi, lun, num_blocks + 2, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 command: Should fail when reading 0blocks beyond end\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("READ16 0blocks at LBA 2^63 ... ");
|
||||
task = iscsi_read16_sync(iscsi, lun, 0x8000000000000000, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 command: Should fail when reading 0blocks at 2^63\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("READ16 0blocks at LBA -1 ... ");
|
||||
task = iscsi_read16_sync(iscsi, lun, -1, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 command: Should fail when reading 0blocks at -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0204_read16_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0204_read16_beyond_eol:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that READ16 fails if reading beyond end-of-lun.\n");
|
||||
printf("1, Read 1-256 blocks one block beyond end-of-lun.\n");
|
||||
printf("2, Read 1-256 blocks at LBA 2^63\n");
|
||||
printf("3, Read 1-256 blocks at LBA -1\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read 1 - 256 blocks beyond the end of the device */
|
||||
printf("Reading 1-256 blocks beyond end-of-device ... ");
|
||||
for (i = 2; i <= 257; i++) {
|
||||
task = iscsi_read16_sync(iscsi, lun, num_blocks, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read16 command should fail when reading beyond end of device\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
/* read 1 - 256 blocks at LBA 2^63 */
|
||||
printf("Reading 1-256 blocks at LBA 2^63 ... ");
|
||||
for (i = 2; i <= 257; i++) {
|
||||
task = iscsi_read16_sync(iscsi, lun, 0x8000000000000000ULL, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read16 command should fail when reading at LBA 2^63\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
/* read 1 - 256 blocks at LBA -1 */
|
||||
printf("Reading 1-256 blocks at LBA -1 ... ");
|
||||
for (i = 2; i <= 257; i++) {
|
||||
task = iscsi_read16_sync(iscsi, lun, -1, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read16 command should fail when reading at LBA -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0210_read12_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0210_read12_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic READ12 functionality.\n");
|
||||
printf("1, Verify we can read the first 1-256 blocks of the LUN.\n");
|
||||
printf("2, Verify we can read the last 1-256 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Reading first 1-256 blocks ... ");
|
||||
for (i=1; i<=256; i++) {
|
||||
task = iscsi_read12_sync(iscsi, lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read the last 1 - 256 blocks at the end of the LUN */
|
||||
printf("Reading last 1-256 blocks ... ");
|
||||
for (i=1; i<=256; i++) {
|
||||
task = iscsi_read12_sync(iscsi, lun, num_blocks +1 - i, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0211_read12_rdprotect(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, i, lun;
|
||||
|
||||
printf("0211_read12_rdprotect:\n");
|
||||
printf("======================\n");
|
||||
if (show_info) {
|
||||
printf("Test how READ12 handles the rdprotect bits\n");
|
||||
printf("1, Any non-zero valued for rdprotect should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
printf("Read12 with RDPROTECT ");
|
||||
for (i = 1; i <= 7; i++) {
|
||||
task = iscsi_read12_sync(iscsi, lun, 0, block_size, block_size, i, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read12 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_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read12 with RDPROTECT!=0 should have failed with CHECK_CONDITION/ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0212_read12_flags(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, lun;
|
||||
|
||||
printf("0212_read12_flags:\n");
|
||||
printf("==================\n");
|
||||
if (show_info) {
|
||||
printf("Test how READ12 handles the flag bits\n");
|
||||
printf("1, Reading with DPO should work\n");
|
||||
printf("2, Reading with FUA should work\n");
|
||||
printf("3, Reading with FUA_NV should work\n");
|
||||
printf("4, Reading with FUA+FUA_NV should work\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) {
|
||||
logging(LOG_VERBOSE, "[SKIPPED] Not SBC device."
|
||||
" Skipping test");
|
||||
return -2;
|
||||
}
|
||||
|
||||
printf("Read12 with DPO ");
|
||||
task = iscsi_read12_sync(iscsi, lun, 0, block_size, block_size, 0, 1, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Read12 with FUA ");
|
||||
task = iscsi_read12_sync(iscsi, lun, 0, block_size, block_size, 0, 0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Read12 with FUA_NV ");
|
||||
task = iscsi_read12_sync(iscsi, lun, 0, block_size, block_size, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Read12 with FUA+FUA_NV ");
|
||||
task = iscsi_read12_sync(iscsi, lun, 0, block_size, block_size, 0, 0, 1, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0213_read12_0blocks(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, lun;
|
||||
|
||||
printf("0213_read12_0blocks:\n");
|
||||
printf("====================\n");
|
||||
if (show_info) {
|
||||
printf("Test that READ12 works correctly when transfer length is 0 blocks.\n");
|
||||
printf("1, Read at LBA:0 should work.\n");
|
||||
printf("2, Read at one block beyond end-of-lun should fail. (only on LUNs with less than 2^31 blocks)\n");
|
||||
printf("3, Read at LBA:2^31 should fail (only on LUNs with less than 2^31 blocks).\n");
|
||||
printf("4, Read at LBA:-1 should fail (only on LUNs with less than 2^31 blocks).\n");
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
printf("READ12 0blocks at LBA:0 ... ");
|
||||
task = iscsi_read12_sync(iscsi, lun, 0, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("READ12 0blocks at one block beyond <end-of-LUN> ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_read12_sync(iscsi, lun, num_blocks + 2, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 command: Should fail when reading 0blocks beyond end\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("READ12 0blocks at LBA 2^31 ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_read12_sync(iscsi, lun, 0x80000000, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 command: Should fail when reading 0blocks at 2^31\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("READ12 0blocks at LBA -1 ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_read12_sync(iscsi, lun, -1, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 command: Should fail when reading 0blocks at -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0214_read12_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0214_read12_beyond_eol:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that READ12 fails if reading beyond end-of-lun.\n");
|
||||
printf("This test is skipped for LUNs with more than 2^31 blocks\n");
|
||||
printf("1, Read 1-256 blocks one block beyond end-of-lun.\n");
|
||||
printf("2, Read 1-256 blocks at LBA 2^31\n");
|
||||
printf("2, Read 1-256 blocks at LBA -1\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
if (num_blocks >= 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big for read-beyond-eol tests with READ12. Skipping test.\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* read 1 - 256 blocks beyond the end of the device */
|
||||
printf("Reading 1-256 blocks beyond end-of-device ... ");
|
||||
for (i = 2; i <= 257; i++) {
|
||||
task = iscsi_read12_sync(iscsi, lun, num_blocks, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 command should fail when reading beyond end of device\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 1 - 256 blocks at LBA 2^31 */
|
||||
printf("Reading 1-256 blocks at LBA 2^31 ... ");
|
||||
if (num_blocks >= 0xffffffff) {
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
for (i = 2; i <= 257; i++) {
|
||||
task = iscsi_read12_sync(iscsi, lun, 0x80000000U, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 command should fail when reading from LBA 2^31\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 1 - 256 blocks at LBA -1 */
|
||||
printf("Reading 1-256 blocks at LBA -1 ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
for (i = 2; i <= 257; i++) {
|
||||
task = iscsi_read12_sync(iscsi, lun, -1, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 command should fail when reading from LBA -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0220_write16_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 256];
|
||||
|
||||
printf("0220_write16_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic WRITE16 functionality.\n");
|
||||
printf("1, Verify we can write the first 1-256 blocks of the LUN.\n");
|
||||
printf("2, Verify we can write the last 1-256 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* write the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Writing first 1-256 blocks ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_write16_sync(iscsi, lun, 0, data, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* write the last 1 - 256 blocks at the end of the LUN */
|
||||
printf("Writing last 1-256 blocks ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_write16_sync(iscsi, lun, num_blocks +1 - i, data, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0221_write16_wrprotect(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, i, lun;
|
||||
unsigned char data[4096];
|
||||
|
||||
printf("0221_write16_wrprotect:\n");
|
||||
printf("======================\n");
|
||||
if (show_info) {
|
||||
printf("Test how WRITE16 handles the wrprotect bits\n");
|
||||
printf("1, Any non-zero valued for wrprotect should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Write16 with WRPROTECT ");
|
||||
for (i = 1; i <= 7; i++) {
|
||||
task = iscsi_write16_sync(iscsi, lun, 0, data, block_size, block_size, i, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write16 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_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write16 with WRPROTECT!=0 should have failed with CHECK_CONDITION/ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0222_write16_flags(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, lun;
|
||||
unsigned char data[4096 * 256];
|
||||
|
||||
printf("0222_write16_flags:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test how WRITE16 handles the flags\n");
|
||||
printf("1, Write with DPU should work.\n");
|
||||
printf("2, Write with FUA should work.\n");
|
||||
printf("3, Write with FUA_NV should work.\n");
|
||||
printf("4, Write with FUA+FUA_NV should work.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) {
|
||||
logging(LOG_VERBOSE, "[SKIPPED] Not SBC device."
|
||||
" Skipping test");
|
||||
return -2;
|
||||
}
|
||||
|
||||
printf("Write16 with DPO ");
|
||||
task = iscsi_write16_sync(iscsi, lun, 0, data, block_size, block_size, 0, 1, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
printf("Write16 with FUA ");
|
||||
task = iscsi_write16_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Write16 with FUA_NV ");
|
||||
task = iscsi_write16_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Write16 with FUA+FUA_NV ");
|
||||
task = iscsi_write16_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 1, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0223_write16_0blocks(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, lun;
|
||||
|
||||
printf("0223_write16_0blocks:\n");
|
||||
printf("====================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITE16 works correctly when transfer length is 0 blocks.\n");
|
||||
printf("1, Write at LBA:0 should work.\n");
|
||||
printf("2, Write at one block beyond end-of-lun should fail.\n");
|
||||
printf("3, Write at LBA:2^63 should fail.\n");
|
||||
printf("4, Write at LBA:-1 should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
printf("WRITE16 0blocks at LBA:0 ... ");
|
||||
task = iscsi_write16_sync(iscsi, lun, 0, NULL, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("WRITE16 0blocks at one block beyond <end-of-LUN> ... ");
|
||||
task = iscsi_write16_sync(iscsi, lun, num_blocks + 1, NULL, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE16 command: Should fail when writing 0blocks beyond end\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("WRITE16 0blocks at LBA 2^63 ... ");
|
||||
task = iscsi_write16_sync(iscsi, lun, 0x8000000000000000, NULL, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE16 command: Should fail when writing 0blocks at 2^31\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("WRITE16 0blocks at LBA -1 ... ");
|
||||
task = iscsi_write16_sync(iscsi, lun, -1, NULL, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE16 command: Should fail when writing 0blocks at -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0224_write16_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 258];
|
||||
|
||||
printf("0224_write16_beyond_eol:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITE16 fails if writing beyond end-of-lun.\n");
|
||||
printf("1, Writing 1-256 blocks beyond end-of-lun should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read 1 - 256 blocks beyond the end of the device */
|
||||
printf("Writing 1-256 blocks beyond end-of-device ... ");
|
||||
for (i = 2; i <= 257; i++) {
|
||||
task = iscsi_write16_sync(iscsi, lun, num_blocks, data, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write16 command should fail when writing beyond end of device\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0230_write12_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 256];
|
||||
|
||||
printf("0230_write12_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic WRITE12 functionality.\n");
|
||||
printf("1, Verify we can write the first 1-256 blocks of the LUN.\n");
|
||||
printf("2, Verify we can write the last 1-256 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* write the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Writing first 1-256 blocks ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_write12_sync(iscsi, lun, 0, data, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* write the last 1 - 256 blocks at the end of the LUN */
|
||||
printf("Writing last 1-256 blocks ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_write12_sync(iscsi, lun, num_blocks +1 - i, data, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0231_write12_wrprotect(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, i, lun;
|
||||
unsigned char data[4096];
|
||||
|
||||
printf("0231_write12_wrprotect:\n");
|
||||
printf("======================\n");
|
||||
if (show_info) {
|
||||
printf("Test how WRITE12 handles the wrprotect bits\n");
|
||||
printf("1, Any non-zero valued for wrprotect should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Write12 with RDPROTECT ");
|
||||
for (i = 1; i <= 7; i++) {
|
||||
task = iscsi_write12_sync(iscsi, lun, 0, data, block_size, block_size, i, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write12 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_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write12 with RDPROTECT!=0 should have failed with CHECK_CONDITION/ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0232_write12_flags(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, lun;
|
||||
unsigned char data[4096];
|
||||
|
||||
printf("0232_write12_flags:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test how WRITE12 handles the flags\n");
|
||||
printf("1, Write with DPU should work.\n");
|
||||
printf("2, Write with FUA should work.\n");
|
||||
printf("3, Write with FUA_NV should work.\n");
|
||||
printf("4, Write with FUA+FUA_NV should work.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) {
|
||||
logging(LOG_VERBOSE, "[SKIPPED] Not SBC device."
|
||||
" Skipping test");
|
||||
return -2;
|
||||
}
|
||||
|
||||
printf("Write12 with DPO ");
|
||||
task = iscsi_write12_sync(iscsi, lun, 0, data, block_size, block_size, 0, 1, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
printf("Write12 with FUA ");
|
||||
task = iscsi_write12_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Write12 with FUA_NV ");
|
||||
task = iscsi_write12_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Write12 with FUA+FUA_NV ");
|
||||
task = iscsi_write12_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 1, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0233_write12_0blocks(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, lun;
|
||||
|
||||
printf("0233_write12_0blocks:\n");
|
||||
printf("====================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITE12 works correctly when transfer length is 0 blocks.\n");
|
||||
printf("1, Write at LBA:0 should work.\n");
|
||||
printf("2, Write at one block beyond end-of-lun should fail. (only on LUNs with less than 2^31 blocks)\n");
|
||||
printf("3, Write at LBA:2^31 should fail (only on LUNs with less than 2^31 blocks).\n");
|
||||
printf("4, Write at LBA:-1 should fail (only on LUNs with less than 2^31 blocks).\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
printf("WRITE12 0blocks at LBA:0 ... ");
|
||||
task = iscsi_write12_sync(iscsi, lun, 0, NULL, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("WRITE12 0blocks at one block beyond <end-of-LUN> ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_write12_sync(iscsi, lun, num_blocks + 2, NULL, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE12 command: Should fail when writing 0blocks beyond end\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE12 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("WRITE12 0blocks at LBA 2^31 ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_write12_sync(iscsi, lun, 0x80000000, NULL, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE12 command: Should fail when writing 0blocks at 2^31\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE12 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("WRITE12 0blocks at LBA -1 ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_write12_sync(iscsi, lun, -1, NULL, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE12 command: Should fail when writing 0blocks at -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE12 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0234_write12_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 258];
|
||||
|
||||
printf("0234_write12_beyond_eol:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITE12 fails if writing beyond end-of-lun.\n");
|
||||
printf("This test is skipped for LUNs with more than 2^31 blocks\n");
|
||||
printf("1, Writing 1-256 blocks beyond end-of-lun should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
if (num_blocks >= 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big for read-beyond-eol tests with WRITE12. Skipping test.\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* read 1 - 256 blocks beyond the end of the device */
|
||||
printf("Writing 1-256 blocks beyond end-of-device ... ");
|
||||
for (i = 2; i <= 257; i++) {
|
||||
task = iscsi_write12_sync(iscsi, lun, num_blocks, data, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write12 command should fail when writing beyond end of device\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0240_prefetch10_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0240_prefetch10_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic PREFETCH10 functionality.\n");
|
||||
printf("1, Verify we can prefetch the first 0-256 blocks of the LUN.\n");
|
||||
printf("2, Verify we can prefetch the last 0-256 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* prefetch the first 0 - 256 blocks at the start of the LUN */
|
||||
printf("Prefetching first 0-256 blocks.\n");
|
||||
for (i = 0; i <= 256; i++) {
|
||||
ret = prefetch10(iscsi, lun, 0, i, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Prefetch the last 0 - 256 blocks at the end of the LUN */
|
||||
printf("Prefetching last 0-256 blocks.\n");
|
||||
for (i = 0; i <= 256; i++) {
|
||||
ret = prefetch10(iscsi, lun, num_blocks - i, i, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0241_prefetch10_flags(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0241_prefetch10_flags:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test PREFETCH10 flags.\n");
|
||||
printf("1, Test the IMMED flag.\n");
|
||||
printf("2, Test different GROUPNUMBERS.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* prefetch with IMMED==1 */
|
||||
printf("Check PREFETCH10 with IMMED==1.\n");
|
||||
ret = prefetch10(iscsi, lun, 0, 1, 1, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* Prefetch with GROUPNUMBER==0..31 */
|
||||
printf("Check PREFETCH10 with GROUPNEMBER 0-31.\n");
|
||||
for (i = 0; i < 32; i++) {
|
||||
ret = prefetch10(iscsi, lun, 0, 1, 0, i);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0242_prefetch10_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0242_prefetch10_beyondeol:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test PREFETCH10 for blocks beyond the EOL.\n");
|
||||
printf("This test is skipped for LUNs with more than 2^31 blocks\n");
|
||||
printf("1, Prefetch 1-256 blocks one block beyond end-of-lun.\n");
|
||||
printf("2, Prefetch 1-256 blocks at LBA 2^31 (only on LUNs < 1TB)\n");
|
||||
printf("3, Prefetch 1-256 blocks at LBA -1 (only on LUN < 2TB)\n");
|
||||
printf("4, Prefetch 2-256 blocks all but one beyond end-of-lun.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big for read-beyond-eol tests with PREFETCH10. Skipping test.\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* prefetch 1-256 blocks, one block beyond the end-of-lun */
|
||||
printf("Prefetch last 1-256 blocks one block beyond eol.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = prefetch10_lbaoutofrange(iscsi, lun, num_blocks + 2 - i, i, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Prefetch 1 - 256 blocks at LBA 2^31 */
|
||||
printf("Prefetch 1-256 blocks at LBA 2^31.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = prefetch10_lbaoutofrange(iscsi, lun, 0x80000000, i, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* prefetch 1 - 256 blocks at LBA -1 */
|
||||
printf("Prefetch 1-256 blocks at LBA -1.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = prefetch10_lbaoutofrange(iscsi, lun, -1, i, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* prefetch 2-256 blocks, all but one block beyond the eol */
|
||||
printf("Prefetch 1-255 blocks beyond eol starting at last block.\n");
|
||||
for (i=2; i<=256; i++) {
|
||||
ret = prefetch10_lbaoutofrange(iscsi, lun, num_blocks, i, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0243_prefetch10_0blocks(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
int ret, lun;
|
||||
|
||||
printf("0243_prefetch10_0blocks:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test that PREFETCH10 works correctly when transfer length is 0 blocks.\n");
|
||||
printf("Transfer Length == 0 means to PREFETCH until the end of the LUN.\n");
|
||||
printf("1, Prefetch at LBA:0 should work.\n");
|
||||
printf("2, Prefetch at one block beyond end-of-lun should fail. (only on LUNs with less than 2^31 blocks)\n");
|
||||
printf("3, Prefetch at LBA:2^31 should fail (only on LUNs with less than 2^31 blocks).\n");
|
||||
printf("4, Prefetch at LBA:-1 should fail (only on LUNs with less than 2^31 blocks).\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* prefetch 0blocks at the start of the LUN */
|
||||
printf("PREFETCH10 0blocks at LBA==0.\n");
|
||||
ret = prefetch10(iscsi, lun, 0, 0, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* Prefetch 0 blocks beyond end of the LUN */
|
||||
printf("PREFETCH10 0blocks at one block beyond <end-of-LUN>.\n");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
ret = prefetch10_lbaoutofrange(iscsi, lun, num_blocks + 2, 0, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* Prefetch 0blocks at LBA:2^31 */
|
||||
printf("PREFETCH10 0blocks at LBA:2^31.\n");
|
||||
ret = prefetch10_lbaoutofrange(iscsi, lun, 0x80000000, 0, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* Prefetch 0blocks at LBA:-1 */
|
||||
printf("PREFETCH10 0blocks at LBA:-1.\n");
|
||||
ret = prefetch10_lbaoutofrange(iscsi, lun, 0xffffffff, 0, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0250_prefetch16_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0250_prefetch16_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic PREFETCH16 functionality.\n");
|
||||
printf("1, Verify we can prefetch the first 0-256 blocks of the LUN.\n");
|
||||
printf("2, Verify we can prefetch the last 0-256 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* prefetch the first 0 - 256 blocks at the start of the LUN */
|
||||
printf("Prefetching first 0-256 blocks.\n");
|
||||
for (i = 0; i <= 256; i++) {
|
||||
ret = prefetch16(iscsi, lun, 0, i, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Prefetch the last 0 - 255 blocks at the end of the LUN */
|
||||
printf("Prefetching last 0-255 blocks.\n");
|
||||
for (i = 1; i < 256; i++) {
|
||||
ret = prefetch16(iscsi, lun, num_blocks - i, i, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0251_prefetch16_flags(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0251_prefetch16_flags:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test PREFETCH16 flags.\n");
|
||||
printf("1, Test the IMMED flag.\n");
|
||||
printf("2, Test different GROUPNUMBERS.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* prefetch with IMMED==1 */
|
||||
printf("Check PREFETCH16 with IMMED==1.\n");
|
||||
ret = prefetch16(iscsi, lun, 0, 1, 1, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* Prefetch with GROUPNUMBER==0..31 */
|
||||
printf("Check PREFETCH16 with GROUPNEMBER 0-31.\n");
|
||||
for (i = 0; i < 32; i++) {
|
||||
ret = prefetch16(iscsi, lun, 0, 1, 0, i);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0252_prefetch16_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0252_prefetch16_beyondeol:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test PREFETCH16 for blocks beyond the EOL.\n");
|
||||
printf("1, Prefetch 1-256 blocks one block beyond end-of-lun.\n");
|
||||
printf("2, Prefetch 1-256 blocks at LBA 2^63 should fail.\n");
|
||||
printf("3, Prefetch 1-256 blocks at LBA -1 should fail.\n");
|
||||
printf("4, Prefetch 1-256 blocks all but one block beyond eol\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* prefetch 1-256 blocks, one block beyond the end-of-lun */
|
||||
printf("Prefetch last 1-256 blocks one block beyond eol.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = prefetch16_lbaoutofrange(iscsi, lun, num_blocks + 2 - i, i, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Prefetch 1 - 256 blocks at LBA 2^63 */
|
||||
printf("Prefetch 1-256 blocks at LBA 2^63.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = prefetch16_lbaoutofrange(iscsi, lun, 0x8000000000000000, i, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* prefetch 1 - 256 blocks at LBA -1 */
|
||||
printf("Prefetch 1-256 blocks at LBA -1.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = prefetch16_lbaoutofrange(iscsi, lun, -1, i, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* prefetch 2-256 blocks, all but one block beyond the eol */
|
||||
printf("Prefetch 1-255 blocks beyond eol starting at last block.\n");
|
||||
for (i=2; i<=256; i++) {
|
||||
ret = prefetch16_lbaoutofrange(iscsi, lun, num_blocks, i, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0253_prefetch16_0blocks(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
int ret, lun;
|
||||
|
||||
printf("0253_prefetch16_0blocks:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test that PREFETCH16 works correctly when transfer length is 0 blocks.\n");
|
||||
printf("1, Prefetch at LBA:0 should work.\n");
|
||||
printf("2, Prefetch at one block beyond end-of-lun should fail.\n");
|
||||
printf("3, Prefetch at LBA:2^63 should fail.\n");
|
||||
printf("4, Prefetch at LBA:-1 should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* prefetch 0blocks at the start of the LUN */
|
||||
printf("PREFETCH16 0blocks at LBA==0.\n");
|
||||
ret = prefetch16(iscsi, lun, 0, 0, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* Prefetch 0 blocks beyond end of the LUN */
|
||||
printf("PREFETCH16 0blocks at one block beyond <end-of-LUN>.\n");
|
||||
ret = prefetch16_lbaoutofrange(iscsi, lun, num_blocks + 2, 0, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* Prefetch 0blocks at LBA:2^63 */
|
||||
printf("PREFETCH16 0blocks at LBA:2^63.\n");
|
||||
ret = prefetch16_lbaoutofrange(iscsi, lun, 0x8000000000000000, 0, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* Prefetch 0blocks at LBA:-1 */
|
||||
printf("PREFETCH16 0blocks at LBA:-1.\n");
|
||||
ret = prefetch16_lbaoutofrange(iscsi, lun, 0xffffffffffffffff, 0, 0, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0260_get_lba_status_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
|
||||
printf("0260_get_lba_status_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic GET_LBA_STATUS functionality.\n");
|
||||
printf("1, Verify we can read a descriptor at the start of the lun.\n");
|
||||
printf("2, Verify we can read a descriptor at the end of the lun.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rc16 == NULL || rc16->lbpme == 0){
|
||||
printf("Logical unit is fully provisioned. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* try reading one descriptor at offset 0 */
|
||||
printf("Read one descriptor at LBA 0 ... ");
|
||||
task = iscsi_get_lba_status_sync(iscsi, lun, 0, 8 + 16);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send GET_LBA_STATUS command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("GET_LBA_STATUS command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* try reading one descriptor at end-of-device */
|
||||
printf("Read one descriptor at end-of-device ... ");
|
||||
task = iscsi_get_lba_status_sync(iscsi, lun, num_blocks, 8 + 16);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send GET_LBA_STATUS command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("GET_LBA_STATUS command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0264_get_lba_status_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
|
||||
printf("0264_get_lba_status_beyondeol:\n");
|
||||
printf("==============================\n");
|
||||
if (show_info) {
|
||||
printf("Test GET_LBA_STATUS functionality for beyond end-of-lun requests\n");
|
||||
printf("1, Reading a descriptor beyond the end of the lun should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (rc16 == NULL || rc16->lbpme == 0){
|
||||
printf("Logical unit is fully provisioned. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* try reading one descriptor beyond end-of-device */
|
||||
printf("Read one descriptor beyond end-of-device ... ");
|
||||
task = iscsi_get_lba_status_sync(iscsi, lun, num_blocks + 1, 8 + 16);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send GET_LBA_STATUS command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("GET_LBA_STATUS beyond eol should fail with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("GET_LBA_STATUS failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0270_verify16_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
printf("0270_verify16_simple:\n");
|
||||
printf("=====================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic VERIFY16 functionality.\n");
|
||||
printf("1, Read and verify the first 1-256 blocks of the LUN using READ16/VERIFY16.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
buf = malloc(256 * block_size);
|
||||
if (buf == NULL) {
|
||||
printf("Failed to allocate buffer.\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Read first 256 blocks.\n");
|
||||
task = iscsi_read10_sync(iscsi, lun, 0, 256 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(buf, task->datain.data, task->datain.size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* verify the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Verify first 1-256 blocks.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = verify16(iscsi, lun, 0, i * block_size, block_size, 0, 1, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
free(buf);
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
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 <string.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0271_verify16_mismatch(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
printf("0271_verify16_mismatch:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic VERIFY16 functionality.\n");
|
||||
printf("1, Verify the first 1-256 blocks with a deliberate error detects the mismatch.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
buf = malloc(256 * block_size);
|
||||
if (buf == NULL) {
|
||||
printf("Failed to allocate buffer.\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Read first 256 blocks.\n");
|
||||
task = iscsi_read10_sync(iscsi, lun, 0, 256 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(buf, task->datain.data, task->datain.size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read and verify the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Verify first 1-256 blocks with a miscompare.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
int offset = random() % (i * block_size);
|
||||
|
||||
/* flip a random byte in the data */
|
||||
buf[offset] ^= 'X';
|
||||
|
||||
ret = verify16_miscompare(iscsi, lun, 0, i * block_size, block_size, 0, 1, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* flip the byte back */
|
||||
buf[offset] ^= 'X';
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
free(buf);
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
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 <string.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0272_verify16_mismatch_no_cmp(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
printf("0272_verify16_mismatch_no_cmp:\n");
|
||||
printf("==============================\n");
|
||||
if (show_info) {
|
||||
printf("Test VERIFY16 BYTCHK:0 only checks medium and should never fail unless the medium is bad.\n");
|
||||
printf("1, Read the first 256 blocks and verify the medium is good.\n");
|
||||
printf("2, Verify the first 1-256 blocks retruns SUCCESS if BYTCHK is 0\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf = malloc(256 * block_size);
|
||||
if (buf == NULL) {
|
||||
printf("Failed to allocate buffer.\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Read first 256 blocks.\n");
|
||||
task = iscsi_read10_sync(iscsi, lun, 0, 256 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(buf, task->datain.data, task->datain.size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read and verify the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Verify first 1-256 blocks with a miscompare but BYTCHK==0.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
int offset = random() % (i * block_size);
|
||||
|
||||
/* flip a random byte in the data */
|
||||
buf[offset] ^= 'X';
|
||||
|
||||
ret = verify16(iscsi, lun, 0, i * block_size, block_size, 0, 1, 0, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* flip the byte back */
|
||||
buf[offset] ^= 'X';
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
free(buf);
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0273_verify16_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
int ret, i, lun;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
printf("0273_verify16_beyond_eol:\n");
|
||||
printf("========================\n");
|
||||
if (show_info) {
|
||||
printf("Test that VERIFY16 fails if reading beyond end-of-lun.\n");
|
||||
printf("1, Verify 2-256 blocks one block beyond end-of-lun.\n");
|
||||
printf("2, Verify 1-256 blocks at LBA 2^63\n");
|
||||
printf("3, Verify 1-256 blocks at LBA -1\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
buf = malloc(256 * block_size);
|
||||
|
||||
/* verify 2 - 256 blocks beyond the end of the device */
|
||||
printf("Verifying 2-256 blocks beyond end-of-device.\n");
|
||||
for (i = 2; i <= 256; i++) {
|
||||
ret = verify16_lbaoutofrange(iscsi, lun, num_blocks, i * block_size, block_size, 0, 1, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
/* verify 1 - 256 blocks at LBA 2^63 */
|
||||
printf("Verifying 1-256 blocks at LBA 2^63.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = verify16_lbaoutofrange(iscsi, lun, 0x8000000000000000, i * block_size, block_size, 0, 1, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
/* verify 1 - 256 blocks at LBA -1 */
|
||||
printf("Verifying 1-256 blocks at LBA -1.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = verify16_lbaoutofrange(iscsi, lun, 0xffffffffffffffff, i * block_size, block_size, 0, 1, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
finished:
|
||||
free(buf);
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0280_verify12_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
printf("0280_verify12_simple:\n");
|
||||
printf("=====================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic VERIFY12 functionality.\n");
|
||||
printf("1, Read and verify the first 1-256 blocks of the LUN using READ12/VERIFY12.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
buf = malloc(256 * block_size);
|
||||
if (buf == NULL) {
|
||||
printf("Failed to allocate buffer.\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Read first 256 blocks.\n");
|
||||
task = iscsi_read10_sync(iscsi, lun, 0, 256 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(buf, task->datain.data, task->datain.size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* verify the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Verify first 1-256 blocks.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
ret = verify12(iscsi, lun, 0, i * block_size, block_size, 0, 1, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
free(buf);
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
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 <string.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0281_verify12_mismatch(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
printf("0281_verify12_mismatch:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic VERIFY12 functionality.\n");
|
||||
printf("1, Verify the first 1-256 blocks with a deliberate error detects the mismatch.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
buf = malloc(256 * block_size);
|
||||
if (buf == NULL) {
|
||||
printf("Failed to allocate buffer.\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Read first 256 blocks.\n");
|
||||
task = iscsi_read10_sync(iscsi, lun, 0, 256 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(buf, task->datain.data, task->datain.size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read and verify the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Verify first 1-256 blocks with a miscompare.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
int offset = random() % (i * block_size);
|
||||
|
||||
/* flip a random byte in the data */
|
||||
buf[offset] ^= 'X';
|
||||
|
||||
ret = verify12_miscompare(iscsi, lun, 0, i * block_size, block_size, 0, 1, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* flip the byte back */
|
||||
buf[offset] ^= 'X';
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
free(buf);
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
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 <string.h>
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0282_verify12_mismatch_no_cmp(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
printf("0282_verify12_mismatch_no_cmp:\n");
|
||||
printf("==============================\n");
|
||||
if (show_info) {
|
||||
printf("Test VERIFY12 BYTCHK:0 only checks medium and should never fail unless the medium is bad.\n");
|
||||
printf("1, Read the first 256 blocks and verify the medium is good.\n");
|
||||
printf("2, Verify the first 1-256 blocks retruns SUCCESS if BYTCHK is 0\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
buf = malloc(256 * block_size);
|
||||
if (buf == NULL) {
|
||||
printf("Failed to allocate buffer.\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Read first 256 blocks.\n");
|
||||
task = iscsi_read10_sync(iscsi, lun, 0, 256 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(buf, task->datain.data, task->datain.size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read and verify the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Verify first 1-256 blocks with a miscompare but BYTCHK==0.\n");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
int offset = random() % (i * block_size);
|
||||
|
||||
/* flip a random byte in the data */
|
||||
buf[offset] ^= 'X';
|
||||
|
||||
ret = verify12(iscsi, lun, 0, i * block_size, block_size, 0, 1, 0, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* flip the byte back */
|
||||
buf[offset] ^= 'X';
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
free(buf);
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0283_verify12_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
int ret, i, lun;
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
printf("0283_verify12_beyond_eol:\n");
|
||||
printf("========================\n");
|
||||
if (show_info) {
|
||||
printf("Test that VERIFY12 fails if reading beyond end-of-lun.\n");
|
||||
printf("This test is skipped for LUNs with more than 2^31 blocks\n");
|
||||
printf("1, Verify 2-256 blocks one block beyond end-of-lun.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
if (num_blocks >= 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big for read-beyond-eol tests with VERIFY12. Skipping test.\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
buf = malloc(256 * block_size);
|
||||
|
||||
/* verify 2 - 256 blocks beyond the end of the device */
|
||||
printf("Verifying 2-256 blocks beyond end-of-device.\n");
|
||||
for (i = 2; i <= 256; i++) {
|
||||
ret = verify12_lbaoutofrange(iscsi, lun, num_blocks, i * block_size, block_size, 0, 1, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
free(buf);
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0290_write10_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 256];
|
||||
|
||||
printf("0290_write10_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic WRITE10 functionality.\n");
|
||||
printf("1, Verify we can write the first 1-256 blocks of the LUN.\n");
|
||||
printf("2, Verify we can write the last 1-256 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* write the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Writing first 1-256 blocks ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_write10_sync(iscsi, lun, 0, data, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* write the last 1 - 256 blocks at the end of the LUN */
|
||||
printf("Writing last 1-256 blocks ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_write10_sync(iscsi, lun, num_blocks +1 - i, data, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0291_write10_wrprotect(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, i, lun;
|
||||
unsigned char data[4096];
|
||||
|
||||
printf("0291_write10_wrprotect:\n");
|
||||
printf("======================\n");
|
||||
if (show_info) {
|
||||
printf("Test how WRITE10 handles the wrprotect bits\n");
|
||||
printf("1, Any non-zero valued for wrprotect should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Write10 with WRPROTECT ");
|
||||
for (i = 1; i <= 7; i++) {
|
||||
task = iscsi_write10_sync(iscsi, lun, 0, data, block_size, block_size, i, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write10 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_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write10 with WRPROTECT!=0 should have failed with CHECK_CONDITION/ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0292_write10_flags(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, lun;
|
||||
unsigned char data[4096];
|
||||
|
||||
printf("0292_write10_flags:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test how WRITE10 handles the flags\n");
|
||||
printf("1, Write with DPU should work.\n");
|
||||
printf("2, Write with FUA should work.\n");
|
||||
printf("3, Write with FUA_NV should work.\n");
|
||||
printf("4, Write with FUA+FUA_NV should work.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) {
|
||||
logging(LOG_VERBOSE, "[SKIPPED] Not SBC device."
|
||||
" Skipping test");
|
||||
return -2;
|
||||
}
|
||||
|
||||
printf("Write10 with DPO ");
|
||||
task = iscsi_write10_sync(iscsi, lun, 0, data, block_size, block_size, 0, 1, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
printf("Write10 with FUA ");
|
||||
task = iscsi_write10_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Write10 with FUA_NV ");
|
||||
task = iscsi_write10_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Write10 with FUA+FUA_NV ");
|
||||
task = iscsi_write10_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 1, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send write10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Write10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0293_write10_0blocks(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, lun;
|
||||
|
||||
printf("0293_write10_0blocks:\n");
|
||||
printf("====================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITE10 works correctly when transfer length is 0 blocks.\n");
|
||||
printf("1, Write at LBA:0 should work.\n");
|
||||
printf("2, Write at one block beyond end-of-lun should fail. (only on LUNs with less than 2^31 blocks)\n");
|
||||
printf("3, Write at LBA:2^31 should fail (only on LUNs with less than 2^31 blocks).\n");
|
||||
printf("4, Write at LBA:-1 should fail (only on LUNs with less than 2^31 blocks).\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
printf("WRITE10 0blocks at LBA:0 ... ");
|
||||
task = iscsi_write10_sync(iscsi, lun, 0, NULL, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("WRITE10 0blocks at one block beyond <end-of-LUN> ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_write10_sync(iscsi, lun, num_blocks + 2, NULL, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE10 command: Should fail when writing 0blocks beyond end\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("WRITE10 0blocks at LBA:2^31 ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_write10_sync(iscsi, lun, 0x80000000, NULL, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE10 command: Should fail when writing 0blocks at 2^31\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("WRITE10 0blocks at LBA:-1 ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_write10_sync(iscsi, lun, -1, NULL, 0, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE10 command: Should fail when writing 0blocks at -1\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0294_write10_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 258];
|
||||
|
||||
printf("0294_write10_beyond_eol:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITE10 fails if writing beyond end-of-lun.\n");
|
||||
printf("This test is skipped for LUNs with more than 2^31 blocks\n");
|
||||
printf("1, Writing 1-256 blocks beyond end-of-lun should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
if (num_blocks >= 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big for read-beyond-eol tests with WRITE10. Skipping test.\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* write 1 - 256 blocks beyond the end of the device */
|
||||
printf("Writing 1-256 blocks beyond end-of-device ... ");
|
||||
for (i = 2; i <= 257; i++) {
|
||||
task = iscsi_write10_sync(iscsi, lun, num_blocks, data, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE10 command should fail when writing beyond end of device\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,508 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0300_readonly(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
struct scsi_mode_sense *ms;
|
||||
int ret, lun;
|
||||
unsigned char data[4096];
|
||||
struct unmap_list list[1];
|
||||
int full_size;
|
||||
|
||||
ret = -1;
|
||||
|
||||
printf("0300_readonly:\n");
|
||||
printf("==============\n");
|
||||
if (show_info) {
|
||||
printf("Test that all commands that modify the medium fail for readonly devices\n");
|
||||
printf("1, WRITE10 at LUN 0 should fail.\n");
|
||||
printf("2, WRITE12 at LUN 0 should fail.\n");
|
||||
printf("3, WRITE16 at LUN 0 should fail.\n");
|
||||
printf("4, WRITESAME10 at LUN 0 should fail.\n");
|
||||
printf("5, WRITESAME16 at LUN 0 should fail.\n");
|
||||
printf("6, WRITESAME10 with UNMAP at LUN 0 should fail (skipped if not thin-provisioned).\n");
|
||||
printf("7, WRITESAME16 with UNMAP at LUN 0 should fail (skipped if not thin-provisioned).\n");
|
||||
printf("8, UNMAP at LUN 0 should fail (skipped if not thin-provisioned).\n");
|
||||
printf("9, WRITEVERIFY10 at LUN 0 should fail.\n");
|
||||
printf("10, WRITEVERIFY12 at LUN 0 should fail.\n");
|
||||
printf("11, WRITEVERIFY16 at LUN 0 should fail.\n");
|
||||
printf("12, COMPAREANDWRITE at LUN 0 should fail.\n");
|
||||
printf("13, ORWRITE at LUN 0 should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (inq->device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) {
|
||||
logging(LOG_VERBOSE, "[SKIPPED] Not SBC device."
|
||||
" Skipping test");
|
||||
return -2;
|
||||
}
|
||||
if (!data_loss) {
|
||||
logging(LOG_VERBOSE, "[SKIPPED] --dataloss flag not set."
|
||||
" Skipping test");
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* verify the device is readonly */
|
||||
task = iscsi_modesense6_sync(iscsi, lun, 0, SCSI_MODESENSE_PC_CURRENT,
|
||||
SCSI_MODEPAGE_RETURN_ALL_PAGES, 0,
|
||||
4);
|
||||
if (task == NULL) {
|
||||
printf("Failed to send modesense6 command: %s\n", iscsi_get_error(iscsi));
|
||||
goto finished;
|
||||
}
|
||||
full_size = scsi_datain_getfullsize(task);
|
||||
if (full_size > task->datain.size) {
|
||||
scsi_free_scsi_task(task);
|
||||
task = iscsi_modesense6_sync(iscsi, lun, 0, SCSI_MODESENSE_PC_CURRENT,
|
||||
SCSI_MODEPAGE_RETURN_ALL_PAGES, 0,
|
||||
full_size);
|
||||
if (task == NULL) {
|
||||
printf("Failed to send modesense6 command: %s\n", iscsi_get_error(iscsi));
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
ms = scsi_datain_unmarshall(task);
|
||||
if (ms == NULL) {
|
||||
printf("failed to unmarshall mode sense datain blob\n");
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (!(ms->device_specific_parameter & 0x80)) {
|
||||
printf("Device is not read-only. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* Write one block at lba 0 */
|
||||
printf("WRITE10 to LUN 0 ... ");
|
||||
task = iscsi_write10_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE10 command should fail when writing to readonly devices\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE10 failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Write one block at lba 0 */
|
||||
printf("WRITE12 to LUN 0 ... ");
|
||||
task = iscsi_write12_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE12 command should fail when writing to readonly devices\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE12 failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Write one block at lba 0 */
|
||||
printf("WRITE16 to LUN 0 ... ");
|
||||
task = iscsi_write16_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE16 command should fail when writing to readonly devices\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE16 failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Write one block at lba 0 */
|
||||
printf("WRITESAME10 to LUN 0 ... ");
|
||||
task = iscsi_writesame10_sync(iscsi, lun, 0,
|
||||
data, block_size,
|
||||
1,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command should fail when writing to readonly devices\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Write one block at lba 0 */
|
||||
printf("WRITESAME16 to LUN 0 ... ");
|
||||
task = iscsi_writesame16_sync(iscsi, lun, 0,
|
||||
data, block_size,
|
||||
1,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command should fail when writing to readonly devices\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* UNMAP one block at lba 0 */
|
||||
printf("WRITESAME10 to UNMAP LUN 0 ... ");
|
||||
if (rc16 == NULL || rc16->lbpme == 0){
|
||||
printf("LUN is not thin-provisioned. [SKIPPED]\n");
|
||||
goto finished;
|
||||
}
|
||||
task = iscsi_writesame10_sync(iscsi, lun, 0,
|
||||
data, block_size,
|
||||
1,
|
||||
0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 command should fail when writing to readonly devices\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* UNMAP one block at lba 0 */
|
||||
printf("WRITESAME16 to UNMAP LUN 0 ... ");
|
||||
task = iscsi_writesame16_sync(iscsi, lun, 0,
|
||||
data, block_size,
|
||||
1,
|
||||
0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 command should fail when writing to readonly devices\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* UNMAP one block at lba 0 */
|
||||
printf("UNMAP LUN 0 ... ");
|
||||
list[0].lba = 0;
|
||||
list[0].num = 1;
|
||||
task = iscsi_unmap_sync(iscsi, lun, 0, 0, &list[0], 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send UNMAP command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("UNMAP command should fail when writing to readonly devices\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("UNMAP failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Write one block at lba 0 */
|
||||
printf("WRITEVERIFY10 to LUN 0 ... ");
|
||||
task = iscsi_writeverify10_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 command should fail when writing to readonly devices\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Write one block at lba 0 */
|
||||
printf("WRITEVERIFY12 to LUN 0 ... ");
|
||||
task = iscsi_writeverify12_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 command should fail when writing to readonly devices\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Write one block at lba 0 */
|
||||
printf("WRITEVERIFY16 to LUN 0 ... ");
|
||||
task = iscsi_writeverify16_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 command should fail when writing to readonly devices\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Write one block at lba 0 */
|
||||
printf("COMPAREWRITE to LUN 0 ... ");
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send COMPAREANDWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE command should fail when writing to readonly devices\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* Write one block at lba 0 */
|
||||
printf("ORWRITE to LUN 0 ... ");
|
||||
task = iscsi_orwrite_sync(iscsi, lun, 0, data, block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send ORWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE command should fail when writing to readonly devices\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE failed with the wrong sense code. Should fail with DATA_PROTECTION/WRITE_PROTECTED\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0310_writeverify10_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 256];
|
||||
|
||||
printf("0310_writeverify10_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic WRITEVERIFY10 functionality.\n");
|
||||
printf("1, Verify we can write the first 1-256 blocks of the LUN.\n");
|
||||
printf("2, Verify we can write the last 1-256 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* write the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Writing first 1-256 blocks ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify10_sync(iscsi, lun, 0, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* write the last 1 - 256 blocks at the end of the LUN */
|
||||
printf("Writing last 1-256 blocks ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify10_sync(iscsi, lun, num_blocks +1 - i, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0311_writeverify10_wrprotect(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, i, lun;
|
||||
unsigned char data[4096];
|
||||
|
||||
printf("0311_writeverify10_wrprotect:\n");
|
||||
printf("======================\n");
|
||||
if (show_info) {
|
||||
printf("Test how WRITEVERIFY10 handles the wrprotect bits\n");
|
||||
printf("1, Any non-zero valued for wrprotect should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Test WRITEVERIFY10 with WRPROTECT != 0 ... ");
|
||||
for (i = 1; i <= 7; i++) {
|
||||
task = iscsi_writeverify10_sync(iscsi, lun, 0, data, block_size, block_size, i, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY10 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_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 with WRPROTECT!=0 should have failed with CHECK_CONDITION/ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0314_writeverify10_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 258];
|
||||
|
||||
printf("0314_writeverify10_beyond_eol:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITEVERIFY10 fails if writing beyond end-of-lun.\n");
|
||||
printf("This test is skipped for LUNs with more than 2^31 blocks\n");
|
||||
printf("1, Writing 1-256 blocks with one block beyond end-of-lun should fail.\n");
|
||||
printf("2, Writing 1-256 blocks at LBA 2^31 should fail.\n");
|
||||
printf("3, Writing 1-256 blocks at LBA -1 should fail.\n");
|
||||
printf("4, Writing 1-256 blocks all but one block beyond eol\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
if (num_blocks >= 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big for read-beyond-eol tests with WRITEVERIFY10. Skipping test.\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* write+verify 1 - 256 blocks beyond the end of the device */
|
||||
printf("Writing 1-256 blocks with one block beyond end-of-device ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify10_sync(iscsi, lun, num_blocks + 2 - i, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY10 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 1 - 256 blocks at lba 2^31 */
|
||||
printf("Writing 1-256 blocks at LBA 2^31 ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify10_sync(iscsi, lun, 0x80000000, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 1 - 256 blocks at lba -1 */
|
||||
printf("Writing 1-256 blocks at LBA -1 ... ");
|
||||
if (num_blocks >= 0xffffffff) {
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify10_sync(iscsi, lun, 0xffffffff, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 2-256 blocks, all but one block beyond the eol */
|
||||
printf("Writing 1-255 blocks beyond eol starting at last block ... ");
|
||||
for (i=2; i<=256; i++) {
|
||||
task = iscsi_writeverify10_sync(iscsi, lun, num_blocks, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0320_writeverify12_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 256];
|
||||
|
||||
printf("0320_writeverify12_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic WRITEVERIFY12 functionality.\n");
|
||||
printf("1, Verify we can write the first 1-256 blocks of the LUN.\n");
|
||||
printf("2, Verify we can write the last 1-256 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* write the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Writing first 1-256 blocks ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify12_sync(iscsi, lun, 0, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* write the last 1 - 256 blocks at the end of the LUN */
|
||||
printf("Writing last 1-256 blocks ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify12_sync(iscsi, lun, num_blocks +1 - i, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0321_writeverify12_wrprotect(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, i, lun;
|
||||
unsigned char data[4096];
|
||||
|
||||
printf("0321_writeverify12_wrprotect:\n");
|
||||
printf("======================\n");
|
||||
if (show_info) {
|
||||
printf("Test how WRITEVERIFY12 handles the wrprotect bits\n");
|
||||
printf("1, Any non-zero valued for wrprotect should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Test WRITEVERIFY12 with WRPROTECT != 0 ... ");
|
||||
for (i = 1; i <= 7; i++) {
|
||||
task = iscsi_writeverify12_sync(iscsi, lun, 0, data, block_size, block_size, i, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY12 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_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 with WRPROTECT!=0 should have failed with CHECK_CONDITION/ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0324_writeverify12_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 258];
|
||||
|
||||
printf("0324_writeverify12_beyond_eol:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITEVERIFY12 fails if writing beyond end-of-lun.\n");
|
||||
printf("This test is skipped for LUNs with more than 2^31 blocks\n");
|
||||
printf("1, Writing 1-256 blocks with one block beyond end-of-lun should fail.\n");
|
||||
printf("2, Writing 1-256 blocks at LBA 2^31 should fail.\n");
|
||||
printf("3, Writing 1-256 blocks at LBA -1 should fail.\n");
|
||||
printf("4, Writing 1-256 blocks all but one block beyond eol\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
if (num_blocks >= 0x80000000) {
|
||||
printf("[SKIPPED]\n");
|
||||
printf("LUN is too big for read-beyond-eol tests with WRITEVERIFY12. Skipping test.\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* read 1 - 256 blocks beyond the end of the device */
|
||||
printf("Writing 1-256 blocks with one block beyond end-of-device ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify12_sync(iscsi, lun, num_blocks + 2 - i, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY12 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 1 - 256 blocks at lba 2^31 */
|
||||
printf("Writing 1-256 blocks at LBA 2^31 ... ");
|
||||
if (num_blocks > 0x80000000) {
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify12_sync(iscsi, lun, 0x80000000, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 1 - 256 blocks at lba -1 */
|
||||
printf("Writing 1-256 blocks at LBA -1 ... ");
|
||||
if (num_blocks >= 0xffffffff) {
|
||||
printf("LUN is too big, skipping test\n");
|
||||
goto finished;
|
||||
}
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify12_sync(iscsi, lun, 0xffffffff, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 2-256 blocks, all but one block beyond the eol */
|
||||
printf("Writing 1-255 blocks beyond eol starting at last block ... ");
|
||||
for (i=2; i<=256; i++) {
|
||||
task = iscsi_writeverify12_sync(iscsi, lun, num_blocks, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0330_writeverify16_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 256];
|
||||
|
||||
printf("0330_writeverify16_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic WRITEVERIFY16 functionality.\n");
|
||||
printf("1, Verify we can write the first 1-256 blocks of the LUN.\n");
|
||||
printf("2, Verify we can write the last 1-256 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* write the first 1 - 256 blocks at the start of the LUN */
|
||||
printf("Writing first 1-256 blocks ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify16_sync(iscsi, lun, 0, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* write the last 1 - 256 blocks at the end of the LUN */
|
||||
printf("Writing last 1-256 blocks ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify16_sync(iscsi, lun, num_blocks +1 - i, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0331_writeverify16_wrprotect(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, i, lun;
|
||||
unsigned char data[4096];
|
||||
|
||||
printf("0331_writeverify16_wrprotect:\n");
|
||||
printf("======================\n");
|
||||
if (show_info) {
|
||||
printf("Test how WRITEVERIFY16 handles the wrprotect bits\n");
|
||||
printf("1, Any non-zero valued for wrprotect should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Test WRITEVERIFY16 with WRPROTECT != 0 ... ");
|
||||
for (i = 1; i <= 7; i++) {
|
||||
task = iscsi_writeverify16_sync(iscsi, lun, 0, data, block_size, block_size, i, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY16 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_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 with WRPROTECT!=0 should have failed with CHECK_CONDITION/ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0334_writeverify16_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 258];
|
||||
|
||||
printf("0334_writeverify16_beyond_eol:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that WRITEVERIFY16 fails if writing beyond end-of-lun.\n");
|
||||
printf("1, Writing 1-256 blocks with one block beyond end-of-lun should fail.\n");
|
||||
printf("2, Writing 1-256 blocks at LBA 2^63 should fail.\n");
|
||||
printf("3, Writing 1-256 blocks at LBA -1 should fail.\n");
|
||||
printf("4, Writing 1-256 blocks all but one block beyond eol\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read 1 - 256 blocks beyond the end of the device */
|
||||
printf("Writing 1-256 blocks with one block beyond end-of-device ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify16_sync(iscsi, lun, num_blocks + 2 - i, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY16 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 1 - 256 blocks at lba 2^63 */
|
||||
printf("Writing 1-256 blocks at LBA 2^63 ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify16_sync(iscsi, lun, 0x8000000000000000, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 1 - 256 blocks at lba -1 */
|
||||
printf("Writing 1-256 blocks at LBA -1 ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_writeverify16_sync(iscsi, lun, 0xffffffffffffffff, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 2-256 blocks, all but one block beyond the eol */
|
||||
printf("Writing 1-255 blocks beyond eol starting at last block ... ");
|
||||
for (i=2; i<=256; i++) {
|
||||
task = iscsi_writeverify16_sync(iscsi, lun, num_blocks, data, i * block_size, block_size, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
static void bitwise_invert(unsigned char data[], int len) {
|
||||
int j;
|
||||
|
||||
for (j = 0; j < len; j++) {
|
||||
data[j] = ~data[j];
|
||||
}
|
||||
}
|
||||
|
||||
int T0340_compareandwrite_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 256];
|
||||
|
||||
printf("0340_compareandwrite_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic COMPAREANDWRITE functionality.\n");
|
||||
printf("1, Verify we can write the first 1-255 blocks of the LUN.\n");
|
||||
printf("2, Verify we can write the last 1-255 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* write the first 1 - 255 blocks at the start of the LUN */
|
||||
printf("Compare and write first 1-255 blocks ... ");
|
||||
for (i = 1; i < 256; i++) {
|
||||
task = iscsi_read16_sync(iscsi, lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (task->datain.data == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to access DATA-IN buffer %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(data, task->datain.data, i * block_size);
|
||||
memcpy(data + (i * block_size), task->datain.data, i * block_size);
|
||||
bitwise_invert(data + (i * block_size), i * block_size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, 0, data, i * 2 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send COMPAREANDWRITE 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* write the last 1 - 255 blocks at the end of the LUN */
|
||||
printf("Compare and write last 1-255 blocks ... ");
|
||||
for (i = 1; i < 256; i++) {
|
||||
task = iscsi_read16_sync(iscsi, lun, num_blocks + 1 - i, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (task->datain.data == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to access DATA-IN buffer %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(data, task->datain.data, i * block_size);
|
||||
memcpy(data + (i * block_size), task->datain.data, i * block_size);
|
||||
bitwise_invert(data + (i * block_size), i * block_size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, num_blocks + 1 - i, data, i * 2 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send COMPAREANDWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0341_compareandwrite_mismatch(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 256];
|
||||
|
||||
printf("0341_compareandwrite_mismatch:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test COMPAREANDWRITE can detect a data mismatch.\n");
|
||||
printf("1, Verify we detect a mismatch in the first 1-255 blocks of the LUN.\n");
|
||||
printf("2, Verify we detect a mismatch in the last 1-255 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* write the first 1 - 255 blocks at the start of the LUN */
|
||||
printf("Compare and write first 1-255 blocks (data is not matching) ... ");
|
||||
for (i = 1; i < 256; i++) {
|
||||
task = iscsi_read16_sync(iscsi, lun, 0, i * 2 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (task->datain.data == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to access DATA-IN buffer %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(data, task->datain.data, i * block_size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
/* flip some bits */
|
||||
data[ (i - 1) * block_size] ^= 0xa5;
|
||||
/* set the write part of the data-out buffer to 1s */
|
||||
memset(data + (i * block_size), 0xff, (i * block_size));
|
||||
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, 0, data, i * 2 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send COMPAREANDWRITE 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE successful. It should have failed with MISCOMPARE/MISCOMPARE_DURING_VERIFY\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_MISCOMPARE
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_MISCOMPARE_DURING_VERIFY) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE Failed with the wrong sense : %s(0x%02x)/%s(0x%04x). It should have failed with MISCOMPARE/MISCOMPARE_DURING_VERIFY\n", scsi_sense_key_str(task->sense.key), task->sense.key, scsi_sense_ascq_str(task->sense.ascq), task->sense.ascq);
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* write the last 1 - 255 blocks at the end of the LUN */
|
||||
printf("Compare and write last 1-255 blocks (data is not matching) ... ");
|
||||
for (i = 1; i < 256; i++) {
|
||||
task = iscsi_read16_sync(iscsi, lun, num_blocks + 1 - i, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (task->datain.data == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to access DATA-IN buffer %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(data, task->datain.data, i * block_size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
/* flip some bits */
|
||||
data[ (i - 1) * block_size] ^= 0xa5;
|
||||
/* set the write part of the data-out buffer to 1s */
|
||||
memset(data + (i * block_size), 0xff, (i * block_size));
|
||||
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, num_blocks + 1 - i, data, i * 2 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send COMPAREANDWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE successful. It should have failed with MISCOMPARE/MISCOMPARE_DURING_VERIFY\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_MISCOMPARE
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_MISCOMPARE_DURING_VERIFY) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE Failed with the wrong sense : %s(0x%02x)/%s(0x%04x). It should have failed with MISCOMPARE/MISCOMPARE_DURING_VERIFY\n", scsi_sense_key_str(task->sense.key), task->sense.key, scsi_sense_ascq_str(task->sense.ascq), task->sense.ascq);
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,194 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0343_compareandwrite_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 258];
|
||||
|
||||
printf("0343_compareandwrite_beyond_eol:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that COMPAREANDWRITE fails if writing beyond end-of-lun.\n");
|
||||
printf("1, Writing 1-255 blocks with one block beyond end-of-lun should fail.\n");
|
||||
printf("2, Writing 1-255 blocks at LBA 2^63 should fail.\n");
|
||||
printf("3, Writing 1-255 blocks at LBA -1 should fail.\n");
|
||||
printf("4, Writing 1-255 blocks all but one block beyond eol\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read 1 - 255 blocks beyond the end of the device */
|
||||
printf("Writing 1-255 blocks with one block beyond end-of-device ... ");
|
||||
for (i = 1; i <= 255; i++) {
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, num_blocks + 2 - i, data, i * 2 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send COMPAREANDWRITE 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 1 - 255 blocks at lba 2^63 */
|
||||
printf("Writing 1-255 blocks at LBA 2^63 ... ");
|
||||
for (i = 1; i < 256; i++) {
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, 0x8000000000000000, data, i * 2 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send COMPAREANDWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 1 - 255 blocks at lba -1 */
|
||||
printf("Writing 1-255 blocks at LBA -1 ... ");
|
||||
for (i = 1; i < 256; i++) {
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, 0xffffffffffffffff, data, i * 2 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send COMPAREANDWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 2-255 blocks, all but one block beyond the eol */
|
||||
printf("Writing 1-255 blocks beyond eol starting at last block ... ");
|
||||
for (i = 2; i < 256; i++) {
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, num_blocks, data, i * 2 * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send COMPAREANDWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREANDWRITE failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,233 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0350_orwrite_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned int j;
|
||||
unsigned char r1data[4096 * 256];
|
||||
unsigned char r2data[4096 * 256];
|
||||
unsigned char ordata[4096 * 256];
|
||||
|
||||
printf("0350_orwrite_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic ORWRITE functionality.\n");
|
||||
printf("1, Verify we can write the first 1-255 blocks of the LUN.\n");
|
||||
printf("2, Verify we can write the last 1-255 blocks of the LUN.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
/* write the first 1 - 255 blocks at the start of the LUN */
|
||||
printf("Orwrite first 1-255 blocks ... ");
|
||||
for (i = 1; i < 256; i++) {
|
||||
task = iscsi_read16_sync(iscsi, lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (task->datain.data == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to access DATA-IN buffer %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(r1data, task->datain.data, i * block_size);
|
||||
memset(ordata, 0x5a, i * block_size);
|
||||
for (j = 0; j < i * block_size; j++) {
|
||||
r2data[j] = r1data[j] | ordata[j];
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
task = iscsi_orwrite_sync(iscsi, lun, 0, ordata, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send ORWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
task = iscsi_read16_sync(iscsi, lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (task->datain.data == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to access DATA-IN buffer %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (memcmp(r2data, task->datain.data, i * block_size)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Blocks were not updated as expected.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* write the last 1 - 255 blocks at the end of the LUN */
|
||||
printf("Orwrite last 1-255 blocks ... ");
|
||||
for (i = 1; i < 256; i++) {
|
||||
task = iscsi_read16_sync(iscsi, lun, num_blocks + 1 - i, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (task->datain.data == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to access DATA-IN buffer %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
memcpy(r1data, task->datain.data, i * block_size);
|
||||
memcpy(r1data, task->datain.data, i * block_size);
|
||||
memset(ordata, 0xa5, i * block_size);
|
||||
for (j = 0; j < i * block_size; j++) {
|
||||
r2data[j] = r1data[j] | ordata[j];
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
task = iscsi_orwrite_sync(iscsi, lun, num_blocks + 1 - i, ordata, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send ORWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
task = iscsi_read16_sync(iscsi, lun, num_blocks + 1 - i, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (task->datain.data == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to access DATA-IN buffer %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (memcmp(r2data, task->datain.data, i * block_size)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Blocks were not updated as expected.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0351_orwrite_wrprotect(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret = 0, i, lun;
|
||||
unsigned char data[4096];
|
||||
|
||||
printf("0351_orwrite_wrprotect:\n");
|
||||
printf("======================\n");
|
||||
if (show_info) {
|
||||
printf("Test how ORWRITE handles the wrprotect bits\n");
|
||||
printf("1, Any non-zero valued for wrprotect should fail.\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Test ORWRITE with WRPROTECT != 0 ... ");
|
||||
for (i = 1; i <= 7; i++) {
|
||||
task = iscsi_orwrite_sync(iscsi, lun, 0, data, block_size, block_size, i, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send ORWRITE 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_FIELD_IN_CDB) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE with WRPROTECT!=0 should have failed with CHECK_CONDITION/ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,194 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0354_orwrite_beyondeol(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
unsigned char data[4096 * 258];
|
||||
|
||||
printf("0354_orwrite_beyondeol:\n");
|
||||
printf("=======================\n");
|
||||
if (show_info) {
|
||||
printf("Test that ORWRITE fails if writing beyond end-of-lun.\n");
|
||||
printf("1, Writing 1-256 blocks with one block beyond end-of-lun should fail.\n");
|
||||
printf("2, Writing 1-256 blocks at LBA 2^63 should fail.\n");
|
||||
printf("3, Writing 1-256 blocks at LBA -1 should fail.\n");
|
||||
printf("4, Writing 1-256 blocks all but one block beyond eol\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
/* read 1 - 256 blocks beyond the end of the device */
|
||||
printf("Writing 1-256 blocks with one block beyond end-of-device ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_orwrite_sync(iscsi, lun, num_blocks + 2 - i, data, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send ORWRITE 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("Opcode is not implemented on target\n");
|
||||
scsi_free_scsi_task(task);
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 1 - 256 blocks at lba 2^63 */
|
||||
printf("Writing 1-256 blocks at LBA 2^63 ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_orwrite_sync(iscsi, lun, 0x8000000000000000, data, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send ORWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 1 - 256 blocks at lba -1 */
|
||||
printf("Writing 1-256 blocks at LBA -1 ... ");
|
||||
for (i = 1; i <= 256; i++) {
|
||||
task = iscsi_orwrite_sync(iscsi, lun, 0xffffffffffffffff, data, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send ORWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
/* read 2-256 blocks, all but one block beyond the eol */
|
||||
printf("Writing 1-255 blocks beyond eol starting at last block ... ");
|
||||
for (i=2; i<=256; i++) {
|
||||
task = iscsi_orwrite_sync(iscsi, lun, num_blocks, data, i * block_size, block_size, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send ORWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE beyond end-of-lun did not return sense. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0360_startstopunit_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
|
||||
printf("0360_startstopunit_simple:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic STARTSTOPUNIT functionality.\n");
|
||||
printf("1, Verify we can eject removable the media with IMMED==1\n");
|
||||
printf("2, Verify we can load the media back again with IMMED==1\n");
|
||||
printf("3, Verify we can eject removable the media with IMMED==0\n");
|
||||
printf("4, Verify we can load the media back again with IMMED==0\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
if (inq->rmb) {
|
||||
printf("Media is removable. STARTSTOPUNIT should work\n");
|
||||
} else {
|
||||
printf("Media is not removable. STARTSTOPUNIT should fail\n");
|
||||
}
|
||||
|
||||
|
||||
printf("STARTSTOPUNIT try to eject the media with IMMED==1 ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
if (inq->rmb) {
|
||||
printf("Medium is removable. Check with TESTUNITREADY that was removed.\n");
|
||||
ret = testunitready_nomedium(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
} else {
|
||||
printf("Medium is not removable. Check with TESTUNITREADY that medium is still present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
printf("STARTSTOPUNIT try to mount the media again with IMMED==1 ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Check with TESTUNITREADY that the medium is present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
printf("STARTSTOPUNIT try to eject the media with IMMED==0 ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 0, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
if (inq->rmb) {
|
||||
printf("Medium is removable. Check with TESTUNITREADY that was removed.\n");
|
||||
ret = testunitready_nomedium(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
} else {
|
||||
printf("Medium is not removable. Check with TESTUNITREADY that medium is still present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
printf("STARTSTOPUNIT try to mount the media again with IMMED==0 ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 0, 0, 0, 0, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Check with TESTUNITREADY that the medium is present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0361_startstopunit_pwrcnd(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, i, lun;
|
||||
|
||||
printf("0361_startstopunit_pwrcnd:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test STARTSTOPUNIT POWERCONDITION functionality.\n");
|
||||
printf("1, If PC != 0 we can not eject the media\n");
|
||||
printf("2, Try to remount the media\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
if (inq->rmb) {
|
||||
printf("Media is removable. STARTSTOPUNIT should work\n");
|
||||
} else {
|
||||
printf("Media is not removable. STARTSTOPUNIT should fail\n");
|
||||
}
|
||||
for (i = 1; i < 16; i++) {
|
||||
printf("Try to eject media with PC == %d ... ", i);
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, i, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Check with TESTUNITREADY that the medium is still present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
printf("Try to mount the media again ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Check with TESTUNITREADY that the medium is still present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,298 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0362_startstopunit_noloej(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
|
||||
printf("0362_startstopunit_noloej:\n");
|
||||
printf("===================\n");
|
||||
if (show_info) {
|
||||
printf("Test STARTSTOPUNIT and LOEJ==0 will never eject/load media.\n");
|
||||
printf("1, LOEJ==0 IMMED==0 NO_FLUSH==0 START==0 will not eject the media\n");
|
||||
printf("2, LOEJ==0 IMMED==0 NO_FLUSH==0 START==1 will not eject the media\n");
|
||||
printf("3, LOEJ==0 IMMED==1 NO_FLUSH==0 START==0 will not eject the media\n");
|
||||
printf("4, LOEJ==0 IMMED==1 NO_FLUSH==0 START==1 will not eject the media\n");
|
||||
printf("5, LOEJ==0 IMMED==0 NO_FLUSH==1 START==0 will not eject the media\n");
|
||||
printf("6, LOEJ==0 IMMED==0 NO_FLUSH==1 START==1 will not eject the media\n");
|
||||
printf("7, LOEJ==0 IMMED==1 NO_FLUSH==1 START==0 will not eject the media\n");
|
||||
printf("8, LOEJ==0 IMMED==1 NO_FLUSH==1 START==1 will not eject the media\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
if (!inq->rmb) {
|
||||
printf("Media is not removable. SKIPPING tests\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
|
||||
printf("STARTSTOP LOEJ==0 IMMED==0 NO_FLUSH==0 START==0 does not eject media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 0, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Check with TESTUNITREADY that the medium is still present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* in case the previous command did eject the media */
|
||||
iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
|
||||
printf("STARTSTOP LOEJ==0 IMMED==0 NO_FLUSH==0 START==1 does not eject media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 0, 0, 0, 0, 0, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Check with TESTUNITREADY that the medium is still present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* in case the previous command did eject the media */
|
||||
iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
|
||||
printf("STARTSTOP LOEJ==0 IMMED==1 NO_FLUSH==0 START==0 does not eject media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Check with TESTUNITREADY that the medium is still present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* in case the previous command did eject the media */
|
||||
iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
|
||||
printf("STARTSTOP LOEJ==0 IMMED==1 NO_FLUSH==0 START==1 does not eject media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 0, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Check with TESTUNITREADY that the medium is still present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* in case the previous command did eject the media */
|
||||
iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
|
||||
printf("STARTSTOP LOEJ==0 IMMED==0 NO_FLUSH==1 START==0 does not eject media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 0, 0, 0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Check with TESTUNITREADY that the medium is still present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* in case the previous command did eject the media */
|
||||
iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
|
||||
printf("STARTSTOP LOEJ==0 IMMED==0 NO_FLUSH==1 START==1 does not eject media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 0, 0, 0, 1, 0, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Check with TESTUNITREADY that the medium is still present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* in case the previous command did eject the media */
|
||||
iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
|
||||
printf("STARTSTOP LOEJ==0 IMMED==1 NO_FLUSH==1 START==0 does not eject media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 1, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Check with TESTUNITREADY that the medium is still present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* in case the previous command did eject the media */
|
||||
iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
|
||||
printf("STARTSTOP LOEJ==0 IMMED==1 NO_FLUSH==1 START==1 does not eject media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 1, 0, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Check with TESTUNITREADY that the medium is still present.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/* in case the previous command did eject the media */
|
||||
iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,641 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0370_nomedia(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
unsigned char buf[4096];
|
||||
|
||||
printf("0370_nomedia:\n");
|
||||
printf("============\n");
|
||||
if (show_info) {
|
||||
printf("Test that media access commands fail correctly if media is ejected\n");
|
||||
printf("1, Verify we can eject the media\n");
|
||||
printf("2, Verify TESTUNITREADY\n");
|
||||
printf("3, Verify SYNCHRONIZECACHE10\n");
|
||||
printf("4, Verify SYNCHRONIZECACHE16\n");
|
||||
printf("5, Verify READ10\n");
|
||||
printf("6, Verify READ12\n");
|
||||
printf("7, Verify READ16\n");
|
||||
printf("8, Verify READCAPACITY10\n");
|
||||
printf("9, Verify READCAPACITY16\n");
|
||||
printf("10, Verify GETLBASTATUS\n");
|
||||
printf("11, Verify PREFETCH10\n");
|
||||
printf("12, Verify PREFETCH16\n");
|
||||
printf("13, Verify VERIFY10\n");
|
||||
printf("14, Verify VERIFY12\n");
|
||||
printf("15, Verify VERIFY16\n");
|
||||
printf("Write commands (only if --dataloss is specified)\n");
|
||||
printf("16, Verify WRITE10\n");
|
||||
printf("17, Verify WRITE12\n");
|
||||
printf("18, Verify WRITE16\n");
|
||||
printf("19, Verify WRITEVERIFY10\n");
|
||||
printf("20, Verify WRITEVERIFY12\n");
|
||||
printf("21, Verify WRITEVERIFY16\n");
|
||||
printf("22, Verify ORWRITE\n");
|
||||
printf("23, Verify COMPAREWRITE\n");
|
||||
printf("24, Verify WRITESAME10\n");
|
||||
printf("25, Verify WRITESAME16\n");
|
||||
printf("26, Verify UNMAP\n");
|
||||
|
||||
printf("Verify we can load the media back again\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!inq->rmb) {
|
||||
printf("Media is not removable. Skipping test.\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
printf("Try to eject the media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* TESTS THAT READ FROM THE MEDIUM
|
||||
*/
|
||||
printf("Test TESTUNITREADY.\n");
|
||||
ret = testunitready_nomedium(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
printf("Test SYNCHRONIZECACHE10 ... ");
|
||||
task = iscsi_synchronizecache10_sync(iscsi, lun, 0, 1, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send SYNCHRONIZECACHE10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("SYNCHRONIZECACHE10 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test SYNCHRONIZECACHE16 ... ");
|
||||
task = iscsi_synchronizecache16_sync(iscsi, lun, 0, 1, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send SYNCHRONIZECACHE16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("SYNCHRONIZECACHE16 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test READ10 ... ");
|
||||
task = iscsi_read10_sync(iscsi, lun, 0, block_size, block_size, 0, 0, 1, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test READ12 ... ");
|
||||
task = iscsi_read12_sync(iscsi, lun, 0, block_size, block_size, 0, 0, 1, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ12 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test READ16 ... ");
|
||||
task = iscsi_read16_sync(iscsi, lun, 0, block_size, block_size, 0, 0, 1, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ16 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test READCAPACITY10 ... ");
|
||||
task = iscsi_readcapacity10_sync(iscsi, lun, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READCAPACITY10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READCAPACITY10 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test READCAPACITY16 ... ");
|
||||
task = iscsi_readcapacity16_sync(iscsi, lun);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READCAPACITY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READCAPACITY16 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test GETLBASTATUS ... ");
|
||||
task = iscsi_get_lba_status_sync(iscsi, lun, 0, 64);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send GETLBASTATUS command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("GETLBASTATUS after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test PREFETCH10.\n");
|
||||
ret = prefetch10_nomedium(iscsi, lun, 0, 1, 1, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
printf("Test PREFETCH16.\n");
|
||||
ret = prefetch16_nomedium(iscsi, lun, 0, 1, 1, 0);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
printf("Test VERIFY10.\n");
|
||||
ret = verify10_nomedium(iscsi, lun, 0, block_size, block_size, 0, 0, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
printf("Test VERIFY12.\n");
|
||||
ret = verify12_nomedium(iscsi, lun, 0, block_size, block_size, 0, 0, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Test VERIFY16.\n");
|
||||
ret = verify16_nomedium(iscsi, lun, 0, block_size, block_size, 0, 0, 1, buf);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping all WRITE tests\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* TESTS THAT WRITE TO THE MEDIUM
|
||||
*/
|
||||
|
||||
printf("Test WRITE10 ... ");
|
||||
task = iscsi_write10_sync(iscsi, lun, 0, buf, block_size, block_size, 0, 0, 1, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE10 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test WRITE12 ... ");
|
||||
task = iscsi_write12_sync(iscsi, lun, 0, buf, block_size, block_size, 0, 0, 1, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE12 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test WRITE16 ... ");
|
||||
task = iscsi_write16_sync(iscsi, lun, 0, buf, block_size, block_size, 0, 0, 1, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE16 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test WRITEVERIFY10 ... ");
|
||||
task = iscsi_writeverify10_sync(iscsi, lun, 0, buf, block_size, block_size, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY10 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test WRITEVERIFY12 ... ");
|
||||
task = iscsi_writeverify12_sync(iscsi, lun, 0, buf, block_size, block_size, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY12 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY12 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test WRITEVERIFY16 ... ");
|
||||
task = iscsi_writeverify16_sync(iscsi, lun, 0, buf, block_size, block_size, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITEVERIFY16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITEVERIFY16 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test ORWRITE ... ");
|
||||
task = iscsi_orwrite_sync(iscsi, lun, 0, buf, block_size, block_size, 0, 0, 1, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send ORWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("ORWRITE after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test COMPAREWRITE ... ");
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, 0, buf, block_size, block_size, 0, 0, 1, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send COMPAREWRITE command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("COMPAREWRITE after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test WRITESAME10 ... ");
|
||||
task = iscsi_writesame10_sync(iscsi, lun, 0,
|
||||
buf, block_size,
|
||||
1,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME10 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME10 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test WRITESAME16 ... ");
|
||||
task = iscsi_writesame16_sync(iscsi, lun, 0,
|
||||
buf, block_size,
|
||||
1,
|
||||
0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITESAME16 command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITESAME16 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Test UNMAP ... ");
|
||||
task = iscsi_unmap_sync(iscsi, lun, 0, 0, NULL, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send UNMAP command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_NOT_READY
|
||||
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
|
||||
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
|
||||
printf("[FAILED]\n");
|
||||
printf("UNMAP after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
|
||||
printf("Try to mount the media again ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command: failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
printf("Check with TESTUNITREADY that the medium is present again.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
finished:
|
||||
printf("Make sure the media is mounted again before the next test ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0380_preventallow_simple(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
|
||||
printf("0380_preventallow_simple:\n");
|
||||
printf("=========================\n");
|
||||
if (show_info) {
|
||||
printf("Test basic PREVENTALLOW functionality.\n");
|
||||
printf("1, Verify we can set PREVENTALLOW (if the medium is removable)\n");
|
||||
printf("2, Verify we can clear it again\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
if (inq->rmb) {
|
||||
printf("Media is removable. PREVENTALLOW should work\n");
|
||||
} else {
|
||||
printf("Media is not removable. PREVENTALLOW should fail\n");
|
||||
}
|
||||
printf("Try to set PREVENTALLOW ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Clear the PREVENTALLOW again ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0381_preventallow_eject(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
|
||||
printf("0381_preventallow_eject:\n");
|
||||
printf("========================\n");
|
||||
if (show_info) {
|
||||
printf("Test we can not eject media when PREVENTALLOW is active.\n");
|
||||
printf("1, Verify we can set PREVENTALLOW (if the medium is removable)\n");
|
||||
printf("2, Verify we can no longer eject the media\n");
|
||||
printf("3, Load the media again in case it was ejected\n");
|
||||
printf("4, Clear PREVENTALLOW again\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (!inq->rmb) {
|
||||
printf("Media is not removable. Skipping tests\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
printf("Try to set PREVENTALLOW ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Try to eject the media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT 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_MEDIUM_REMOVAL_PREVENTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command should have failed with ILLEGAL_REQUEST/MEDIUM_REMOVAL_PREVENTED with : failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("Eject failed. [OK]\n");
|
||||
|
||||
|
||||
printf("Load the media again in case it was ejected ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SBC doesnt really say anything about whether we can LOAD media when the prevent
|
||||
* flag is set
|
||||
*/
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Clear the PREVENTALLOW again ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0382_preventallow_itnexus_loss(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
|
||||
printf("0382_preventallow_itnexus_loss:\n");
|
||||
printf("===============================\n");
|
||||
if (show_info) {
|
||||
printf("Test that an I_T_Nexus loss clears PREVENTALLOW.\n");
|
||||
printf("1, Verify we can set PREVENTALLOW (if the medium is removable)\n");
|
||||
printf("2, Verify we can no longer eject the media\n");
|
||||
printf("3, Tear down the I_T_Nexus and re-login on a new nexus\n");
|
||||
printf("4, Verify we can eject the media\n");
|
||||
printf("5, Load the media again in case it was ejected\n");
|
||||
printf("6, Clear PREVENTALLOW again\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
if (!inq->rmb) {
|
||||
printf("Media is not removable. Skipping tests\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
printf("Try to set PREVENTALLOW ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Try to eject the media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT 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_MEDIUM_REMOVAL_PREVENTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command should have failed with ILLEGAL_REQUEST/MEDIUM_REMOVAL_PREVENTED with : failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("Eject failed. [OK]\n");
|
||||
|
||||
|
||||
printf("Tear down the IT_Nexus and create a new one ... ");
|
||||
iscsi_destroy_context(iscsi);
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
//test4:
|
||||
|
||||
printf("Try to eject the media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command should have worked but it failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Load the media again in case it was ejected ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SBC doesnt really say anything about whether we can LOAD media when the prevent
|
||||
* flag is set
|
||||
*/
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Clear the PREVENTALLOW again ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
/*
|
||||
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 <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 T0383_preventallow_target_warm_reset(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
struct mgmt_task mgmt_task = {0, 0};
|
||||
struct pollfd pfd;
|
||||
|
||||
printf("0383_preventallow_target_warm_reset:\n");
|
||||
printf("====================================\n");
|
||||
if (show_info) {
|
||||
printf("Test that a target reset clears PREVENTALLOW.\n");
|
||||
printf("1, Verify we can set PREVENTALLOW (if the medium is removable)\n");
|
||||
printf("2, Verify we can no longer eject the media\n");
|
||||
printf("3, Send a Warm Reset to the target\n");
|
||||
printf("4, Verify we can eject the media\n");
|
||||
printf("5, Load the media again in case it was ejected\n");
|
||||
printf("6, Clear PREVENTALLOW again\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (!inq->rmb) {
|
||||
printf("Media is not removable. Skipping tests\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
printf("Try to set PREVENTALLOW ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Try to eject the media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT 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_MEDIUM_REMOVAL_PREVENTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command should have failed with ILLEGAL_REQUEST/MEDIUM_REMOVAL_PREVENTED with : failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("Eject failed. [OK]\n");
|
||||
|
||||
|
||||
printf("Send a Warm Reset to the target ... ");
|
||||
iscsi_task_mgmt_target_warm_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 target\n");
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
again:
|
||||
printf("Use TESTUNITREADY and clear any unit attentions.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto again;
|
||||
}
|
||||
|
||||
printf("Try to eject the media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command should have worked but it failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Load the media again in case it was ejected ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SBC doesnt really say anything about whether we can LOAD media when the prevent
|
||||
* flag is set
|
||||
*/
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Clear the PREVENTALLOW again ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
/*
|
||||
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 <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 T0384_preventallow_target_cold_reset(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
struct mgmt_task mgmt_task = {0, 0};
|
||||
struct pollfd pfd;
|
||||
|
||||
printf("0384_preventallow_target_cold_reset:\n");
|
||||
printf("====================================\n");
|
||||
if (show_info) {
|
||||
printf("Test that a target reset clears PREVENTALLOW.\n");
|
||||
printf("1, Verify we can set PREVENTALLOW (if the medium is removable)\n");
|
||||
printf("2, Verify we can no longer eject the media\n");
|
||||
printf("3, Send a Cold Reset to the target\n");
|
||||
printf("4, Verify we can eject the media\n");
|
||||
printf("5, Load the media again in case it was ejected\n");
|
||||
printf("6, Clear PREVENTALLOW again\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (!inq->rmb) {
|
||||
printf("Media is not removable. Skipping tests\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
printf("Try to set PREVENTALLOW ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Try to eject the media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT 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_MEDIUM_REMOVAL_PREVENTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command should have failed with ILLEGAL_REQUEST/MEDIUM_REMOVAL_PREVENTED with : failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("Eject failed. [OK]\n");
|
||||
|
||||
|
||||
printf("Send a Cold Reset to the target ... ");
|
||||
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 target\n");
|
||||
goto finished;
|
||||
}
|
||||
printf("[OK]\n");
|
||||
|
||||
again:
|
||||
printf("Use TESTUNITREADY and clear any unit attentions.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto again;
|
||||
}
|
||||
|
||||
|
||||
printf("Try to eject the media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command should have worked but it failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Load the media again in case it was ejected ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SBC doesnt really say anything about whether we can LOAD media when the prevent
|
||||
* flag is set
|
||||
*/
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Clear the PREVENTALLOW again ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
/*
|
||||
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 <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 T0385_preventallow_lun_reset(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
struct mgmt_task mgmt_task = {0, 0};
|
||||
struct pollfd pfd;
|
||||
|
||||
printf("0385_preventallow_lun_reset:\n");
|
||||
printf("============================\n");
|
||||
if (show_info) {
|
||||
printf("Test that a target reset clears PREVENTALLOW.\n");
|
||||
printf("1, Verify we can set PREVENTALLOW (if the medium is removable)\n");
|
||||
printf("2, Verify we can no longer eject the media\n");
|
||||
printf("3, Send a LUN Reset to the target\n");
|
||||
printf("4, Verify we can eject the media\n");
|
||||
printf("5, Load the media again in case it was ejected\n");
|
||||
printf("6, Clear PREVENTALLOW again\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (!inq->rmb) {
|
||||
printf("Media is not removable. Skipping tests\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
printf("Try to set PREVENTALLOW ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Try to eject the media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT 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_MEDIUM_REMOVAL_PREVENTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command should have failed with ILLEGAL_REQUEST/MEDIUM_REMOVAL_PREVENTED with : failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("Eject failed. [OK]\n");
|
||||
|
||||
|
||||
printf("Send a LUN Reset to the target ... ");
|
||||
iscsi_task_mgmt_lun_reset_async(iscsi, lun, 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");
|
||||
|
||||
again:
|
||||
printf("Use TESTUNITREADY and clear any unit attentions.\n");
|
||||
ret = testunitready(iscsi, lun);
|
||||
if (ret != 0) {
|
||||
goto again;
|
||||
}
|
||||
|
||||
|
||||
printf("Try to eject the media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command should have worked but it failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Load the media again in case it was ejected ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SBC doesnt really say anything about whether we can LOAD media when the prevent
|
||||
* flag is set
|
||||
*/
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Clear the PREVENTALLOW again ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
return ret;
|
||||
}
|
||||
@@ -1,214 +0,0 @@
|
||||
/*
|
||||
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 "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-test.h"
|
||||
|
||||
int T0386_preventallow_2_itl_nexuses(const char *initiator, const char *url)
|
||||
{
|
||||
struct iscsi_context *iscsi;
|
||||
struct iscsi_context *iscsi2 = NULL;
|
||||
struct scsi_task *task;
|
||||
int ret, lun;
|
||||
|
||||
printf("0386_preventallow_2_itl_nexuses:\n");
|
||||
printf("============================\n");
|
||||
if (show_info) {
|
||||
printf("Test that each IT nexus has its own PREVENT setting\n");
|
||||
printf("1, Verify we can set PREVENTALLOW on two IT_Nexusen (if the medium is removable)\n");
|
||||
printf("2, Verify we can no longer eject the media\n");
|
||||
printf("3, Remove the PREVENT on this IT_Nexus\n");
|
||||
printf("4, Verify we can still not eject the media\n");
|
||||
printf("5, Load the media again in case it was ejected\n");
|
||||
printf("6, Clear PREVENTALLOW again\n");
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (!inq->rmb) {
|
||||
printf("Media is not removable. Skipping tests\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
printf("Try to set PREVENTALLOW on 2 different IT_Nexusen ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
iscsi2 = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
task = iscsi_preventallow_sync(iscsi2, lun, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi2));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Try to eject the media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT 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_MEDIUM_REMOVAL_PREVENTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command should have failed with ILLEGAL_REQUEST/MEDIUM_REMOVAL_PREVENTED with : failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("Eject failed. [OK]\n");
|
||||
|
||||
|
||||
printf("Remove the PREVENT on this IT_Nexus ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Try to eject the media ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT 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_MEDIUM_REMOVAL_PREVENTED) {
|
||||
printf("[FAILED]\n");
|
||||
printf("STARTSTOPUNIT command should have failed with ILLEGAL_REQUEST/MEDIUM_REMOVAL_PREVENTED with : failed with sense. %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("Eject failed. [OK]\n");
|
||||
|
||||
|
||||
printf("Load the media again in case it was ejected ... ");
|
||||
task = iscsi_startstopunit_sync(iscsi, lun, 1, 0, 0, 0, 1, 1);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send STARTSTOPUNIT command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SBC doesnt really say anything about whether we can LOAD media when the prevent
|
||||
* flag is set
|
||||
*/
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
printf("Clear the PREVENTALLOW again ... ");
|
||||
task = iscsi_preventallow_sync(iscsi, lun, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
/* SPC doesnt really say anything about what should happen if using PREVENTALLOW
|
||||
* on a device that does not support medium removals.
|
||||
*/
|
||||
if (inq->rmb) {
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("PREVENTALLOW command: failed with sense %s\n", iscsi_get_error(iscsi));
|
||||
ret = -1;
|
||||
scsi_free_scsi_task(task);
|
||||
goto finished;
|
||||
}
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
task = iscsi_preventallow_sync(iscsi2, lun, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send PREVENTALLOW command: %s\n", iscsi_get_error(iscsi2));
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
printf("[OK]\n");
|
||||
|
||||
|
||||
finished:
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
if (iscsi2 != NULL) {
|
||||
iscsi_destroy_context(iscsi2);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user