TESTS: convert compareandwrite to new api
Signed-off-by: Ronnie Sahlberg <sahlberg@localhost>
This commit is contained in:
committed by
Ronnie Sahlberg
parent
44d88e3bc6
commit
46eaa7dcc3
@@ -1334,147 +1334,38 @@ int mode_sense(struct iscsi_context *iscsi, int lun)
|
||||
}
|
||||
|
||||
int compareandwrite(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
unsigned char *data, uint32_t len, int blocksize,
|
||||
int wrprotect, int dpo,
|
||||
int fua, int group_number)
|
||||
unsigned char *data, uint32_t datalen, int blocksize,
|
||||
int wrprotect, int dpo,
|
||||
int fua, int group_number,
|
||||
int status, enum scsi_sense_key key, int *ascq, int num_ascq)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
struct iscsi_data d;
|
||||
int ret;
|
||||
|
||||
logging(LOG_VERBOSE, "Send COMPARE_AND_WRITE LBA:%" PRIu64
|
||||
" LEN:%d WRPROTECT:%d",
|
||||
lba, len, wrprotect);
|
||||
logging(LOG_VERBOSE, "Send COMPAREANDWRITE (Expecting %s) LBA:%"
|
||||
PRIu64 " LEN:%d WRPROTECT:%d",
|
||||
scsi_status_str(status),
|
||||
lba, datalen, wrprotect);
|
||||
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, lba,
|
||||
data, len, blocksize,
|
||||
wrprotect, dpo, fua, 0, group_number);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL, "[FAILED] Failed to send COMPARE_AND_WRITE "
|
||||
"command: %s",
|
||||
iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_CHECK_CONDITION
|
||||
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
|
||||
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
|
||||
logging(LOG_NORMAL, "[SKIPPED] COMPARE_AND_WRITE is not "
|
||||
"implemented on target");
|
||||
scsi_free_scsi_task(task);
|
||||
return -2;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL, "[FAILED] COMPARE_AND_WRITE command: "
|
||||
"failed with sense. %s", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set in. Skipping write\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] COMPARE_AND_WRITE returned SUCCESS.");
|
||||
return 0;
|
||||
}
|
||||
task = scsi_cdb_compareandwrite(lba, datalen, blocksize, wrprotect,
|
||||
dpo, fua, 0, group_number);
|
||||
assert(task != NULL);
|
||||
|
||||
int compareandwrite_miscompare(struct iscsi_context *iscsi, int lun,
|
||||
uint64_t lba, unsigned char *data,
|
||||
uint32_t len, int blocksize,
|
||||
int wrprotect, int dpo,
|
||||
int fua, int group_number)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
d.data = data;
|
||||
d.size = datalen;
|
||||
task = iscsi_scsi_command_sync(iscsi, lun, task, &d);
|
||||
|
||||
logging(LOG_VERBOSE, "Send COMPARE_AND_WRITE LBA:%" PRIu64
|
||||
" LEN:%d WRPROTECT:%d (expecting MISCOMPARE)",
|
||||
lba, len, wrprotect);
|
||||
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, lba,
|
||||
data, len, blocksize,
|
||||
wrprotect, dpo, fua, 0, group_number);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL, "[FAILED] Failed to send COMPARE_AND_WRITE "
|
||||
"command: %s",
|
||||
iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_CHECK_CONDITION
|
||||
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
|
||||
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
|
||||
logging(LOG_NORMAL, "[SKIPPED] COMPARE_AND_WRITE is not "
|
||||
"implemented on target");
|
||||
ret = check_result("COMPAREANDWRITE", iscsi, task, status, key, ascq, num_ascq);
|
||||
if (task) {
|
||||
scsi_free_scsi_task(task);
|
||||
return -2;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL, "[FAILED] COMPARE_AND_WRITE successful "
|
||||
"but should have failed with MISCOMPARE.");
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_MISCOMPARE
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_MISCOMPARE_DURING_VERIFY) {
|
||||
logging(LOG_NORMAL, "[FAILED] COMPARE_AND_WRITE failed with "
|
||||
"the wrong sense code. Should have failed with "
|
||||
"MISCOMPARE/MISCOMPARE_DURING_VERIFY but failed with "
|
||||
"sense:%s", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] COMPARE_AND_WRITE returned MISCOMPARE.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int compareandwrite_invalidfieldincdb(struct iscsi_context *iscsi, int lun,
|
||||
uint64_t lba, unsigned char *data,
|
||||
uint32_t len, int blocksize,
|
||||
int wrprotect, int dpo,
|
||||
int fua, int group_number)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
logging(LOG_VERBOSE, "Send COMPARE_AND_WRITE LBA:%" PRIu64
|
||||
" LEN:%d WRPROTECT:%d (expecting INVALID_FIELD_IN_CDB)",
|
||||
lba, len, wrprotect);
|
||||
|
||||
task = iscsi_compareandwrite_sync(iscsi, lun, lba,
|
||||
data, len, blocksize,
|
||||
wrprotect, dpo, fua, 0, group_number);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL, "[FAILED] Failed to send COMPARE_AND_WRITE "
|
||||
"command: %s",
|
||||
iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_CHECK_CONDITION
|
||||
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
|
||||
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
|
||||
logging(LOG_NORMAL, "[SKIPPED] COMPARE_AND_WRITE is not "
|
||||
"implemented on target");
|
||||
scsi_free_scsi_task(task);
|
||||
return -2;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL, "[FAILED] COMPARE_AND_WRITE successful "
|
||||
"but should have failed with MISCOMPARE.");
|
||||
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_INVALID_FIELD_IN_CDB) {
|
||||
logging(LOG_NORMAL, "[FAILED] COMPARE_AND_WRITE failed with "
|
||||
"the wrong sense code. Should have failed with "
|
||||
"INVALID_FIELD_IN_CDB but failed with "
|
||||
"sense:%s", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] COMPARE_AND_WRITE returned INVALID_FIELD_IN_CDB.");
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct scsi_task *get_lba_status_task(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len)
|
||||
|
||||
Reference in New Issue
Block a user