Add VERIFY16 support and tests

Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
This commit is contained in:
Ronnie Sahlberg
2012-06-04 20:16:44 +10:00
parent f6fd18ee3a
commit 6003000809
14 changed files with 725 additions and 1 deletions

View File

@@ -80,7 +80,9 @@ bin_iscsi_test_SOURCES = test-tool/iscsi-test.c \
test-tool/0234_write12_beyondeol.c \
test-tool/0240_prefetch10_simple.c \
test-tool/0250_prefetch16_simple.c \
test-tool/0260_get_lba_status_simple.c test-tool/0264_get_lba_status_beyondeol.c
test-tool/0260_get_lba_status_simple.c test-tool/0264_get_lba_status_beyondeol.c \
test-tool/0270_verify16_simple.c test-tool/0271_verify16_mismatch.c \
test-tool/0272_verify16_mismatch_no_cmp.c test-tool/0273_verify16_beyondeol.c
endif
# LD_PRELOAD library.

View File

@@ -642,6 +642,12 @@ iscsi_verify10_task(struct iscsi_context *iscsi, int lun,
int blocksize, iscsi_command_cb cb,
void *private_data);
EXTERN struct scsi_task *
iscsi_verify16_task(struct iscsi_context *iscsi, int lun,
unsigned char *data, uint32_t datalen, uint64_t lba,
int vprotect, int dpo, int bytchk,
int blocksize, iscsi_command_cb cb,
void *private_data);
EXTERN struct scsi_task *
iscsi_writesame10_task(struct iscsi_context *iscsi, int lun,
unsigned char *data, uint32_t datalen,
uint32_t lba, uint16_t num_blocks,
@@ -751,6 +757,12 @@ iscsi_verify10_sync(struct iscsi_context *iscsi, int lun,
int vprotect, int dpo, int bytchk,
int blocksize);
EXTERN struct scsi_task *
iscsi_verify16_sync(struct iscsi_context *iscsi, int lun,
unsigned char *data, uint32_t datalen, uint64_t lba,
int vprotect, int dpo, int bytchk,
int blocksize);
EXTERN struct scsi_task *
iscsi_writesame10_sync(struct iscsi_context *iscsi, int lun,
unsigned char *data, uint32_t datalen,

View File

@@ -34,6 +34,7 @@ enum scsi_opcode {
SCSI_OPCODE_UNMAP = 0x42,
SCSI_OPCODE_READ16 = 0x88,
SCSI_OPCODE_WRITE16 = 0x8A,
SCSI_OPCODE_VERIFY16 = 0x8F,
SCSI_OPCODE_PREFETCH16 = 0x90,
SCSI_OPCODE_WRITE_SAME16 = 0x93,
SCSI_OPCODE_SERVICE_ACTION_IN = 0x9E,
@@ -123,6 +124,13 @@ struct scsi_verify10_params {
int dpo;
int bytchk;
};
struct scsi_verify16_params {
uint64_t lba;
uint32_t num_blocks;
int vprotect;
int dpo;
int bytchk;
};
struct scsi_readcapacity10_params {
int lba;
int pmi;
@@ -179,6 +187,7 @@ struct scsi_task {
struct scsi_write12_params write12;
struct scsi_write16_params write16;
struct scsi_verify10_params verify10;
struct scsi_verify16_params verify16;
struct scsi_readcapacity10_params readcapacity10;
struct scsi_reportluns_params reportluns;
struct scsi_inquiry_params inquiry;
@@ -605,6 +614,7 @@ EXTERN struct scsi_task *scsi_cdb_write10(uint32_t lba, uint32_t xferlen, int fu
EXTERN struct scsi_task *scsi_cdb_write12(uint32_t lba, uint32_t xferlen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group_number);
EXTERN struct scsi_task *scsi_cdb_write16(uint64_t lba, uint32_t xferlen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group_number);
EXTERN struct scsi_task *scsi_cdb_verify10(uint32_t lba, uint32_t xferlen, int vprotect, int dpo, int bytchk, int blocksize);
EXTERN struct scsi_task *scsi_cdb_verify16(uint64_t lba, uint32_t xferlen, int vprotect, int dpo, int bytchk, int blocksize);
EXTERN struct scsi_task *scsi_cdb_synchronizecache10(int lba, int num_blocks,
int syncnv, int immed);

View File

@@ -74,6 +74,8 @@ iscsi_unmap_sync
iscsi_unmap_task
iscsi_verify10_sync
iscsi_verify10_task
iscsi_verify16_sync
iscsi_verify16_task
iscsi_which_events
iscsi_write10_sync
iscsi_write10_task
@@ -102,6 +104,7 @@ scsi_cdb_synchronizecache10
scsi_cdb_testunitready
scsi_cdb_unmap
scsi_cdb_verify10
scsi_cdb_verify16
scsi_cdb_write10
scsi_cdb_write12
scsi_cdb_write16

View File

@@ -72,6 +72,8 @@ iscsi_unmap_sync
iscsi_unmap_task
iscsi_verify10_sync
iscsi_verify10_task
iscsi_verify16_sync
iscsi_verify16_task
iscsi_which_events
iscsi_write10_sync
iscsi_write10_task
@@ -100,6 +102,7 @@ scsi_cdb_synchronizecache10
scsi_cdb_testunitready
scsi_cdb_unmap
scsi_cdb_verify10
scsi_cdb_verify16
scsi_cdb_write10
scsi_cdb_write12
scsi_cdb_write16

View File

@@ -899,6 +899,39 @@ iscsi_verify10_task(struct iscsi_context *iscsi, int lun, unsigned char *data,
return task;
}
struct scsi_task *
iscsi_verify16_task(struct iscsi_context *iscsi, int lun, unsigned char *data,
uint32_t datalen, uint64_t lba, int vprotect, int dpo, int bytchk, int blocksize,
iscsi_command_cb cb, void *private_data)
{
struct scsi_task *task;
struct iscsi_data outdata;
if (datalen % blocksize != 0) {
iscsi_set_error(iscsi, "Datalen:%d is not a multiple of the "
"blocksize:%d.", datalen, blocksize);
return NULL;
}
task = scsi_cdb_verify16(lba, datalen, vprotect, dpo, bytchk, blocksize);
if (task == NULL) {
iscsi_set_error(iscsi, "Out-of-memory: Failed to create "
"verify16 cdb.");
return NULL;
}
outdata.data = data;
outdata.size = datalen;
if (iscsi_scsi_command_async(iscsi, lun, task, cb, &outdata,
private_data) != 0) {
scsi_free_scsi_task(task);
return NULL;
}
return task;
}
struct scsi_task *
iscsi_modesense6_task(struct iscsi_context *iscsi, int lun, int dbd, int pc,
int page_code, int sub_page_code,

View File

@@ -978,6 +978,53 @@ scsi_cdb_verify10(uint32_t lba, uint32_t xferlen, int vprotect, int dpo, int byt
return task;
}
/*
* VERIFY16
*/
struct scsi_task *
scsi_cdb_verify16(uint64_t lba, uint32_t xferlen, int vprotect, int dpo, int bytchk, int blocksize)
{
struct scsi_task *task;
task = malloc(sizeof(struct scsi_task));
if (task == NULL) {
return NULL;
}
memset(task, 0, sizeof(struct scsi_task));
task->cdb[0] = SCSI_OPCODE_VERIFY16;
if (vprotect) {
task->cdb[1] |= ((vprotect << 5) & 0xe0);
}
if (dpo) {
task->cdb[1] |= 0x10;
}
if (bytchk) {
task->cdb[1] |= 0x02;
}
*(uint32_t *)&task->cdb[2] = htonl(lba >> 32);
*(uint32_t *)&task->cdb[6] = htonl(lba & 0xffffffff);
*(uint32_t *)&task->cdb[10] = htonl(xferlen/blocksize);
task->cdb_size = 16;
if (xferlen != 0) {
task->xfer_dir = SCSI_XFER_WRITE;
} else {
task->xfer_dir = SCSI_XFER_NONE;
}
task->expxferlen = xferlen;
task->params.verify16.lba = lba;
task->params.verify16.num_blocks = xferlen/blocksize;
task->params.verify16.vprotect = vprotect;
task->params.verify16.dpo = dpo;
task->params.verify16.bytchk = bytchk;
return task;
}
/*
* UNMAP

View File

@@ -523,6 +523,26 @@ iscsi_verify10_sync(struct iscsi_context *iscsi, int lun, unsigned char *data, u
return state.task;
}
struct scsi_task *
iscsi_verify16_sync(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint64_t lba,
int vprotect, int dpo, int bytchk, int blocksize)
{
struct iscsi_sync_state state;
memset(&state, 0, sizeof(state));
if (iscsi_verify16_task(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize,
scsi_sync_cb, &state) == NULL) {
iscsi_set_error(iscsi,
"Failed to send Verify16 command");
return NULL;
}
event_loop(iscsi, &state);
return state.task;
}
struct scsi_task *
iscsi_writesame10_sync(struct iscsi_context *iscsi, int lun,
unsigned char *data, uint32_t datalen,

View File

@@ -0,0 +1,131 @@
/*
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 T0270_verify16_simple(const char *initiator, const char *url, int data_loss _U_, int show_info)
{
struct iscsi_context *iscsi;
struct scsi_task *task;
struct scsi_task *vtask;
struct scsi_readcapacity16 *rc16;
int ret, i, lun;
uint32_t block_size;
uint64_t num_blocks;
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;
}
/* find the size of the LUN */
task = iscsi_readcapacity16_sync(iscsi, lun);
if (task == NULL) {
printf("Failed to send readcapacity16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("Readcapacity16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto finished;
}
rc16 = scsi_datain_unmarshall(task);
if (rc16 == NULL) {
printf("failed to unmarshall readcapacity16 data. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto finished;
}
block_size = rc16->block_length;
num_blocks = rc16->returned_lba;
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 ... ");
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 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;
}
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 finished;
}
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 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 finished;
}
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
}
printf("[OK]\n");
finished:
iscsi_logout_sync(iscsi);
iscsi_destroy_context(iscsi);
return ret;
}

View File

@@ -0,0 +1,143 @@
/*
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 "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test.h"
int T0271_verify16_mismatch(const char *initiator, const char *url, int data_loss _U_, int show_info)
{
struct iscsi_context *iscsi;
struct scsi_task *task;
struct scsi_task *vtask;
struct scsi_readcapacity16 *rc16;
int ret, i, lun;
uint32_t block_size;
uint64_t num_blocks;
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;
}
/* find the size of the LUN */
task = iscsi_readcapacity16_sync(iscsi, lun);
if (task == NULL) {
printf("Failed to send readcapacity16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("Readcapacity16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto finished;
}
rc16 = scsi_datain_unmarshall(task);
if (rc16 == NULL) {
printf("failed to unmarshall readcapacity16 data. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto finished;
}
block_size = rc16->block_length;
num_blocks = rc16->returned_lba;
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 ... ");
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 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;
}
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 finished;
}
/* flip a random byte in the data */
buf[random() % task->datain.size] ^= '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 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 finished;
}
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 finished;
}
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
}
printf("[OK]\n");
finished:
iscsi_logout_sync(iscsi);
iscsi_destroy_context(iscsi);
return ret;
}

View File

@@ -0,0 +1,137 @@
/*
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 "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-test.h"
int T0272_verify16_mismatch_no_cmp(const char *initiator, const char *url, int data_loss _U_, int show_info)
{
struct iscsi_context *iscsi;
struct scsi_task *task;
struct scsi_task *vtask;
struct scsi_readcapacity16 *rc16;
int ret, i, lun;
uint32_t block_size;
uint64_t num_blocks;
printf("0272_verify16_mismatch_no_cmp:\n");
printf("==============================\n");
if (show_info) {
printf("Test VERIFY16 BYTCHK:0 should not detect mismatches.\n");
printf("1, Verify the first 1-256 blocks does nto detect a mismatch 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;
}
/* find the size of the LUN */
task = iscsi_readcapacity16_sync(iscsi, lun);
if (task == NULL) {
printf("Failed to send readcapacity16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("Readcapacity16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto finished;
}
rc16 = scsi_datain_unmarshall(task);
if (rc16 == NULL) {
printf("failed to unmarshall readcapacity16 data. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto finished;
}
block_size = rc16->block_length;
num_blocks = rc16->returned_lba;
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 ... ");
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 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;
}
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 finished;
}
/* flip a random byte in the data */
buf[random() % task->datain.size] ^= 'X';
/* bytechk == 0 ==> target should NOT compate the data so should
not detect the mismatch.
*/
vtask = iscsi_verify16_sync(iscsi, lun, buf, i * block_size, 0, 0, 1, 0, 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 finished;
}
if (vtask->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("Verify16 returned sense but BYTCHK==1 means it should not check/compare the data.\n");
ret = -1;
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
goto finished;
}
scsi_free_scsi_task(task);
scsi_free_scsi_task(vtask);
}
printf("[OK]\n");
finished:
iscsi_logout_sync(iscsi);
iscsi_destroy_context(iscsi);
return ret;
}

View File

@@ -0,0 +1,172 @@
/*
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 T0273_verify16_beyondeol(const char *initiator, const char *url, int data_loss _U_, int show_info)
{
struct iscsi_context *iscsi;
struct scsi_task *task;
struct scsi_readcapacity16 *rc16;
int ret, i, lun;
uint32_t block_size;
uint64_t num_blocks;
unsigned char buf[512*256];
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;
}
/* find the size of the LUN */
task = iscsi_readcapacity16_sync(iscsi, lun);
if (task == NULL) {
printf("Failed to send READCAPACITY16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("READCAPACITY16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto finished;
}
rc16 = scsi_datain_unmarshall(task);
if (rc16 == NULL) {
printf("failed to unmarshall READCAPACITY10 data. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto finished;
}
block_size = rc16->block_length;
num_blocks = rc16->returned_lba;
scsi_free_scsi_task(task);
ret = 0;
/* verify 2 - 256 blocks beyond the end of the device */
printf("Verifying 2-256 blocks beyond end-of-device ... ");
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;
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.\n");
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;
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.\n");
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 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 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.\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;
}

View File

@@ -113,6 +113,12 @@ struct scsi_test tests[] = {
{ "T0260_get_lba_status_simple", T0260_get_lba_status_simple },
{ "T0264_get_lba_status_beyondeol", T0264_get_lba_status_beyondeol },
/* verify16*/
{ "T0270_verify16_simple", T0270_verify16_simple },
{ "T0271_verify16_mismatch", T0271_verify16_mismatch },
{ "T0272_verify16_mismatch_no_cmp", T0272_verify16_mismatch_no_cmp },
{ "T0273_verify16_beyondeol", T0273_verify16_beyondeol },
{ NULL, NULL }
};

View File

@@ -77,3 +77,8 @@ int T0250_prefetch16_simple(const char *initiator, const char *url, int data_los
int T0260_get_lba_status_simple(const char *initiator, const char *url, int data_loss, int show_info);
int T0264_get_lba_status_beyondeol(const char *initiator, const char *url, int data_loss, int show_info);
int T0270_verify16_simple(const char *initiator, const char *url, int data_loss, int show_info);
int T0271_verify16_mismatch(const char *initiator, const char *url, int data_loss, int show_info);
int T0272_verify16_mismatch_no_cmp(const char *initiator, const char *url, int data_loss, int show_info);
int T0273_verify16_beyondeol(const char *initiator, const char *url, int data_loss, int show_info);