Add support for VERIFY12 and tests
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
This commit is contained in:
@@ -82,7 +82,9 @@ bin_iscsi_test_SOURCES = test-tool/iscsi-test.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/0270_verify16_simple.c test-tool/0271_verify16_mismatch.c \
|
||||
test-tool/0272_verify16_mismatch_no_cmp.c test-tool/0273_verify16_beyondeol.c
|
||||
test-tool/0272_verify16_mismatch_no_cmp.c test-tool/0273_verify16_beyondeol.c \
|
||||
test-tool/0280_verify12_simple.c test-tool/0281_verify12_mismatch.c \
|
||||
test-tool/0282_verify12_mismatch_no_cmp.c
|
||||
endif
|
||||
|
||||
# LD_PRELOAD library.
|
||||
|
||||
@@ -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_verify12_task(struct iscsi_context *iscsi, int lun,
|
||||
unsigned char *data, uint32_t datalen, uint32_t lba,
|
||||
int vprotect, int dpo, int bytchk,
|
||||
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,
|
||||
@@ -757,6 +763,12 @@ iscsi_verify10_sync(struct iscsi_context *iscsi, int lun,
|
||||
int vprotect, int dpo, int bytchk,
|
||||
int blocksize);
|
||||
|
||||
EXTERN struct scsi_task *
|
||||
iscsi_verify12_sync(struct iscsi_context *iscsi, int lun,
|
||||
unsigned char *data, uint32_t datalen, uint32_t lba,
|
||||
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,
|
||||
|
||||
@@ -40,7 +40,8 @@ enum scsi_opcode {
|
||||
SCSI_OPCODE_SERVICE_ACTION_IN = 0x9E,
|
||||
SCSI_OPCODE_REPORTLUNS = 0xA0,
|
||||
SCSI_OPCODE_READ12 = 0xA8,
|
||||
SCSI_OPCODE_WRITE12 = 0xAA
|
||||
SCSI_OPCODE_WRITE12 = 0xAA,
|
||||
SCSI_OPCODE_VERIFY12 = 0xAF
|
||||
};
|
||||
|
||||
enum scsi_service_action_in {
|
||||
@@ -124,6 +125,13 @@ struct scsi_verify10_params {
|
||||
int dpo;
|
||||
int bytchk;
|
||||
};
|
||||
struct scsi_verify12_params {
|
||||
uint32_t lba;
|
||||
uint32_t num_blocks;
|
||||
int vprotect;
|
||||
int dpo;
|
||||
int bytchk;
|
||||
};
|
||||
struct scsi_verify16_params {
|
||||
uint64_t lba;
|
||||
uint32_t num_blocks;
|
||||
@@ -187,6 +195,7 @@ struct scsi_task {
|
||||
struct scsi_write12_params write12;
|
||||
struct scsi_write16_params write16;
|
||||
struct scsi_verify10_params verify10;
|
||||
struct scsi_verify12_params verify12;
|
||||
struct scsi_verify16_params verify16;
|
||||
struct scsi_readcapacity10_params readcapacity10;
|
||||
struct scsi_reportluns_params reportluns;
|
||||
@@ -614,6 +623,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_verify12(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,
|
||||
|
||||
@@ -74,6 +74,8 @@ iscsi_unmap_sync
|
||||
iscsi_unmap_task
|
||||
iscsi_verify10_sync
|
||||
iscsi_verify10_task
|
||||
iscsi_verify12_sync
|
||||
iscsi_verify12_task
|
||||
iscsi_verify16_sync
|
||||
iscsi_verify16_task
|
||||
iscsi_which_events
|
||||
@@ -104,6 +106,7 @@ scsi_cdb_synchronizecache10
|
||||
scsi_cdb_testunitready
|
||||
scsi_cdb_unmap
|
||||
scsi_cdb_verify10
|
||||
scsi_cdb_verify12
|
||||
scsi_cdb_verify16
|
||||
scsi_cdb_write10
|
||||
scsi_cdb_write12
|
||||
|
||||
@@ -72,6 +72,8 @@ iscsi_unmap_sync
|
||||
iscsi_unmap_task
|
||||
iscsi_verify10_sync
|
||||
iscsi_verify10_task
|
||||
iscsi_verify12_sync
|
||||
iscsi_verify12_task
|
||||
iscsi_verify16_sync
|
||||
iscsi_verify16_task
|
||||
iscsi_which_events
|
||||
@@ -102,6 +104,7 @@ scsi_cdb_synchronizecache10
|
||||
scsi_cdb_testunitready
|
||||
scsi_cdb_unmap
|
||||
scsi_cdb_verify10
|
||||
scsi_cdb_verify12
|
||||
scsi_cdb_verify16
|
||||
scsi_cdb_write10
|
||||
scsi_cdb_write12
|
||||
|
||||
@@ -899,6 +899,39 @@ iscsi_verify10_task(struct iscsi_context *iscsi, int lun, unsigned char *data,
|
||||
return task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_verify12_task(struct iscsi_context *iscsi, int lun, unsigned char *data,
|
||||
uint32_t datalen, uint32_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_verify12(lba, datalen, vprotect, dpo, bytchk, blocksize);
|
||||
if (task == NULL) {
|
||||
iscsi_set_error(iscsi, "Out-of-memory: Failed to create "
|
||||
"verify12 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_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,
|
||||
|
||||
@@ -978,6 +978,52 @@ scsi_cdb_verify10(uint32_t lba, uint32_t xferlen, int vprotect, int dpo, int byt
|
||||
return task;
|
||||
}
|
||||
|
||||
/*
|
||||
* VERIFY12
|
||||
*/
|
||||
struct scsi_task *
|
||||
scsi_cdb_verify12(uint32_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_VERIFY12;
|
||||
|
||||
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);
|
||||
*(uint32_t *)&task->cdb[6] = htonl(xferlen/blocksize);
|
||||
|
||||
task->cdb_size = 12;
|
||||
if (xferlen != 0) {
|
||||
task->xfer_dir = SCSI_XFER_WRITE;
|
||||
} else {
|
||||
task->xfer_dir = SCSI_XFER_NONE;
|
||||
}
|
||||
task->expxferlen = xferlen;
|
||||
|
||||
task->params.verify12.lba = lba;
|
||||
task->params.verify12.num_blocks = xferlen/blocksize;
|
||||
task->params.verify12.vprotect = vprotect;
|
||||
task->params.verify12.dpo = dpo;
|
||||
task->params.verify12.bytchk = bytchk;
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
/*
|
||||
* VERIFY16
|
||||
*/
|
||||
@@ -1025,7 +1071,6 @@ scsi_cdb_verify16(uint64_t lba, uint32_t xferlen, int vprotect, int dpo, int byt
|
||||
return task;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* UNMAP
|
||||
*/
|
||||
|
||||
20
lib/sync.c
20
lib/sync.c
@@ -523,6 +523,26 @@ iscsi_verify10_sync(struct iscsi_context *iscsi, int lun, unsigned char *data, u
|
||||
return state.task;
|
||||
}
|
||||
|
||||
struct scsi_task *
|
||||
iscsi_verify12_sync(struct iscsi_context *iscsi, int lun, unsigned char *data, uint32_t datalen, uint32_t lba,
|
||||
int vprotect, int dpo, int bytchk, int blocksize)
|
||||
{
|
||||
struct iscsi_sync_state state;
|
||||
|
||||
memset(&state, 0, sizeof(state));
|
||||
|
||||
if (iscsi_verify12_task(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize,
|
||||
scsi_sync_cb, &state) == NULL) {
|
||||
iscsi_set_error(iscsi,
|
||||
"Failed to send Verify12 command");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
event_loop(iscsi, &state);
|
||||
|
||||
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)
|
||||
|
||||
131
test-tool/0280_verify12_simple.c
Normal file
131
test-tool/0280_verify12_simple.c
Normal 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 T0280_verify12_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("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;
|
||||
}
|
||||
|
||||
/* 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_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;
|
||||
}
|
||||
|
||||
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_verify12_sync(iscsi, lun, buf, i * block_size, 0, 0, 1, 1, block_size);
|
||||
if (vtask == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send verify12 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("Verify12 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;
|
||||
}
|
||||
143
test-tool/0281_verify12_mismatch.c
Normal file
143
test-tool/0281_verify12_mismatch.c
Normal 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 T0281_verify12_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("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;
|
||||
}
|
||||
|
||||
/* 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_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;
|
||||
}
|
||||
|
||||
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_verify12_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("Verify12 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("Verify12 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;
|
||||
}
|
||||
137
test-tool/0282_verify12_mismatch_no_cmp.c
Normal file
137
test-tool/0282_verify12_mismatch_no_cmp.c
Normal 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 T0282_verify12_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("0282_verify12_mismatch_no_cmp:\n");
|
||||
printf("==============================\n");
|
||||
if (show_info) {
|
||||
printf("Test VERIFY12 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_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;
|
||||
}
|
||||
|
||||
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_verify12_sync(iscsi, lun, buf, i * block_size, 0, 0, 1, 0, block_size);
|
||||
if (vtask == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send verify12 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("Verify12 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;
|
||||
}
|
||||
@@ -119,6 +119,11 @@ struct scsi_test tests[] = {
|
||||
{ "T0272_verify16_mismatch_no_cmp", T0272_verify16_mismatch_no_cmp },
|
||||
{ "T0273_verify16_beyondeol", T0273_verify16_beyondeol },
|
||||
|
||||
/* verify12*/
|
||||
{ "T0280_verify12_simple", T0280_verify12_simple },
|
||||
{ "T0281_verify12_mismatch", T0281_verify12_mismatch },
|
||||
{ "T0282_verify12_mismatch_no_cmp", T0282_verify12_mismatch_no_cmp },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
@@ -82,3 +82,7 @@ int T0270_verify16_simple(const char *initiator, const char *url, int data_loss,
|
||||
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);
|
||||
|
||||
int T0280_verify12_simple(const char *initiator, const char *url, int data_loss, int show_info);
|
||||
int T0281_verify12_mismatch(const char *initiator, const char *url, int data_loss, int show_info);
|
||||
int T0282_verify12_mismatch_no_cmp(const char *initiator, const char *url, int data_loss, int show_info);
|
||||
|
||||
Reference in New Issue
Block a user