TESTS: Create helpers for VERIFY16 and switch all tests over to use them

This commit is contained in:
Ronnie Sahlberg
2012-12-26 09:25:45 -08:00
parent eb2a586cc4
commit 3c960c1d42
7 changed files with 261 additions and 269 deletions

View File

@@ -16,6 +16,7 @@
*/
#include <stdio.h>
#include <string.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test.h"
@@ -24,10 +25,10 @@ int T0270_verify16_simple(const char *initiator, const char *url, int data_loss
{
struct iscsi_context *iscsi;
struct scsi_task *task;
struct scsi_task *vtask;
struct scsi_readcapacity16 *rc16;
int ret, i, lun;
uint32_t block_size;
unsigned char *buf = NULL;
printf("0270_verify16_simple:\n");
printf("=====================\n");
@@ -68,73 +69,47 @@ int T0270_verify16_simple(const char *initiator, const char *url, int data_loss
scsi_free_scsi_task(task);
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("Read+verify first 1-256 blocks ... ");
/* 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++) {
unsigned char *buf;
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 test2;
}
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 test2;
}
buf = task->datain.data;
if (buf == 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 test2;
}
vtask = iscsi_verify16_sync(iscsi, lun, buf, i * block_size, 0, 0, 1, 1, block_size);
if (vtask == NULL) {
printf("[FAILED]\n");
printf("Failed to send verify16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test2;
}
if (vtask->status == SCSI_STATUS_CHECK_CONDITION
&& vtask->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& vtask->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("Opcode is not implemented on target\n");
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
ret = -2;
ret = verify16(iscsi, lun, buf, i * block_size, 0, 0, 1, 1, block_size);
if (ret != 0) {
goto finished;
}
if (vtask->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("Verify16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
goto test2;
}
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
}
printf("[OK]\n");
test2:
finished:
free(buf);
iscsi_logout_sync(iscsi);
iscsi_destroy_context(iscsi);
return ret;

View File

@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test.h"
@@ -25,10 +26,10 @@ int T0271_verify16_mismatch(const char *initiator, const char *url, int data_los
{
struct iscsi_context *iscsi;
struct scsi_task *task;
struct scsi_task *vtask;
struct scsi_readcapacity16 *rc16;
int ret, i, lun;
uint32_t block_size;
unsigned char *buf = NULL;
printf("0271_verify16_mismatch:\n");
printf("=======================\n");
@@ -69,84 +70,54 @@ int T0271_verify16_mismatch(const char *initiator, const char *url, int data_los
scsi_free_scsi_task(task);
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("Read+verify first 1-256 blocks ... ");
printf("Verify first 1-256 blocks with a miscompare.\n");
for (i = 1; i <= 256; i++) {
unsigned char *buf;
int offset = random() % (i * block_size);
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 test2;
}
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 test2;
}
buf = task->datain.data;
if (buf == 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 test2;
}
/* flip a random byte in the data */
buf[random() % task->datain.size] ^= 'X';
buf[offset] ^= 'X';
vtask = iscsi_verify16_sync(iscsi, lun, buf, i * block_size, 0, 0, 1, 1, block_size);
if (vtask == NULL) {
printf("[FAILED]\n");
printf("Failed to send verify10 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test2;
}
if (vtask->status == SCSI_STATUS_CHECK_CONDITION
&& vtask->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& vtask->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("Opcode is not implemented on target\n");
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
ret = -2;
ret = verify16_miscompare(iscsi, lun, buf, i * block_size, 0, 0, 1, 1, block_size);
if (ret != 0) {
goto finished;
}
if (vtask->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("Verify16 command returned sense ok but the data is not matching.\n");
ret = -1;
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
goto test2;
}
if (vtask->sense.key != SCSI_SENSE_MISCOMPARE) {
printf("[FAILED]\n");
printf("Verify16 command returned wrong sense key. MISCOMPARE 0x%x expected but got key 0x%x\n", SCSI_SENSE_MISCOMPARE, vtask->sense.key);
ret = -1;
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
goto test2;
}
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
/* flip the byte back */
buf[offset] ^= 'X';
}
printf("[OK]\n");
test2:
finished:
free(buf);
iscsi_logout_sync(iscsi);
iscsi_destroy_context(iscsi);
return ret;

View File

@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test.h"
@@ -28,6 +29,7 @@ int T0272_verify16_mismatch_no_cmp(const char *initiator, const char *url, int d
struct scsi_readcapacity10 *rc10;
int ret, i, lun;
uint32_t block_size;
unsigned char *buf = NULL;
printf("0272_verify16_mismatch_no_cmp:\n");
printf("==============================\n");
@@ -69,65 +71,54 @@ int T0272_verify16_mismatch_no_cmp(const char *initiator, const char *url, int d
scsi_free_scsi_task(task);
ret = 0;
buf = malloc(256 * block_size);
if (buf == NULL) {
printf("Failed to allocate buffer.\n");
ret = -1;
goto finished;
}
/* read and verify the first 1 - 256 blocks at the start of the LUN */
printf("Read 256 blocks and verify they are good ... ");
task = iscsi_read16_sync(iscsi, lun, 0, 256 * block_size, block_size, 0, 0, 0, 0, 0);
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 READ16 command: %s\n", iscsi_get_error(iscsi));
printf("Failed to send READ10 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test2;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("READ16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
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);
printf("[OK]\n");
ret = 0;
test2:
printf("Verify first 1-256 ... ");
/* 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++) {
task = iscsi_verify16_sync(iscsi, lun, NULL, i * block_size, 0, 0, 1, 0, block_size);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test3;
}
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;
int offset = random() % (i * block_size);
/* flip a random byte in the data */
buf[offset] ^= 'X';
ret = verify16(iscsi, lun, buf, i * block_size, 0, 0, 1, 0, block_size);
if (ret != 0) {
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY16 returned sense but BYTCHK==1 means it should not check/compare the data. Sense:%s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test2;
}
scsi_free_scsi_task(task);
/* flip the byte back */
buf[offset] ^= 'X';
}
printf("[OK]\n");
test3:
finished:
free(buf);
iscsi_logout_sync(iscsi);
iscsi_destroy_context(iscsi);
return ret;

View File

@@ -16,6 +16,7 @@
*/
#include <stdio.h>
#include <string.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test.h"
@@ -28,7 +29,7 @@ int T0273_verify16_beyondeol(const char *initiator, const char *url, int data_lo
int ret, i, lun;
uint32_t block_size;
uint64_t num_blocks;
unsigned char buf[4096 * 256];
unsigned char *buf = NULL;
printf("0273_verify16_beyond_eol:\n");
printf("========================\n");
@@ -71,112 +72,36 @@ int T0273_verify16_beyondeol(const char *initiator, const char *url, int data_lo
num_blocks = rc16->returned_lba;
scsi_free_scsi_task(task);
ret = 0;
buf = malloc(256 * block_size);
/* verify 2 - 256 blocks beyond the end of the device */
printf("Verifying 2-256 blocks beyond end-of-device ... ");
printf("Verifying 2-256 blocks beyond end-of-device.\n");
for (i = 2; i <= 256; i++) {
task = iscsi_verify16_sync(iscsi, lun, buf, i * block_size, num_blocks, 0, 1, 1, block_size);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
ret = verify16_lbaoutofrange(iscsi, lun, buf, i * block_size, num_blocks, 0, 1, 1, block_size);
if (ret != 0) {
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("VERIFY16 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("VERIFY16 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");
/* verify 1 - 256 blocks at LBA 2^63 */
printf("Verify 1-256 blocks at LBA 2^63 ... ");
for (i = 2; i <= 257; i++) {
task = iscsi_verify16_sync(iscsi, lun, buf, i * block_size, 0x8000000000000000ULL, 0, 1, 1, block_size);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
printf("Verifying 1-256 blocks at LBA 2^63.\n");
for (i = 1; i <= 256; i++) {
ret = verify16_lbaoutofrange(iscsi, lun, buf, i * block_size, 0x8000000000000000, 0, 1, 1, block_size);
if (ret != 0) {
goto finished;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY16 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("VERIFY16 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");
/* verify 1 - 256 blocks at LBA -1 */
printf("Verifying 1-256 blocks at LBA -1 ... ");
for (i = 2; i <= 257; i++) {
task = iscsi_verify16_sync(iscsi, lun, buf, i * block_size, -1LL, 0, 1, 1, block_size);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test2;
printf("Verifying 1-256 blocks at LBA -1.\n");
for (i = 1; i <= 256; i++) {
ret = verify16_lbaoutofrange(iscsi, lun, buf, i * block_size, 0xffffffffffffffff, 0, 1, 1, block_size);
if (ret != 0) {
goto finished;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY16 command should fail when reading at LBA -1\n");
ret = -1;
scsi_free_scsi_task(task);
goto test2;
}
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("VERIFY16 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 test2;
}
scsi_free_scsi_task(task);
}
printf("[OK]\n");
test2:
finished:
free(buf);
iscsi_logout_sync(iscsi);
iscsi_destroy_context(iscsi);
return ret;

View File

@@ -376,28 +376,12 @@ int T0370_nomedia(const char *initiator, const char *url, int data_loss, int sho
goto finished;
}
printf("Test VERIFY16 ... ");
task = iscsi_verify16_sync(iscsi, lun, buf, block_size, 0, 0, 0, 1, block_size);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
printf("Test VERIFY16.\n");
ret = verify16_nomedium(iscsi, lun, buf, block_size, 0, 0, 0, 1, block_size);
if (ret != 0) {
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("VERIFY16 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");
if (!data_loss) {

View File

@@ -1256,6 +1256,148 @@ int verify12_lbaoutofrange(struct iscsi_context *iscsi, int lun, unsigned char *
return 0;
}
int verify16(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize)
{
struct scsi_task *task;
printf("Send VERIFY16 LBA:%" PRIu64 " blocks:%d vprotect:%d dpo:%d bytchk:%d ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify16_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("VERIFY16 is not implemented on target\n");
scsi_free_scsi_task(task);
return -2;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
return 0;
}
int verify16_nomedium(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize)
{
struct scsi_task *task;
printf("Send VERIFY16 LBA:%" PRIu64 " blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting NOT_READY/MEDIUM_NOT_PRESENT) ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify16_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("VERIFY16 is not implemented on target\n");
scsi_free_scsi_task(task);
return -2;
}
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("VERIFY16 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
return 0;
}
int verify16_miscompare(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize)
{
struct scsi_task *task;
printf("Send VERIFY16 LBA:%" PRIu64 " blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting MISCOMPARE) ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify16_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("VERIFY16 is not implemented on target\n");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY16 command successful but should have failed with MISCOMPARE\n");
scsi_free_scsi_task(task);
return -1;
}
if (task->sense.key != SCSI_SENSE_MISCOMPARE) {
printf("[FAILED]\n");
printf("VERIFY16 command returned wrong sense key. MISCOMPARE MISCOMPARE 0x%x expected but got key 0x%x. Sense:%s\n", SCSI_SENSE_MISCOMPARE, task->sense.key, iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
return 0;
}
int verify16_lbaoutofrange(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize)
{
struct scsi_task *task;
printf("Send VERIFY16 LBA:%" PRIu64 " blocks:%d vprotect:%d dpo:%d bytchk:%d (expecting LBA_OUT_OF_RANGE) ... ", lba, datalen / blocksize, vprotect, dpo, bytchk);
task = iscsi_verify16_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send VERIFY16 command: %s\n", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("VERIFY16 is not implemented on target\n");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("VERIFY16 command successful but should have failed with LBA_OUT_OF_RANGE\n");
scsi_free_scsi_task(task);
return -1;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
printf("[FAILED]\n");
printf("VERIFY16 should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
return 0;
}
int main(int argc, const char *argv[])
{
poptContext pc;

View File

@@ -262,5 +262,9 @@ int verify12(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t
int verify12_nomedium(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify12_miscompare(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify12_lbaoutofrange(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify16(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify16_nomedium(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify16_miscompare(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize);
int verify16_lbaoutofrange(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize);
#endif /* _ISCSI_TEST_H_ */