TESTS: change ORWRITE to use a single helper function for all
Switch orwrite helpers to use _command_async instead of calling _orwrite_sync() to prepare for switching to non-iscsi targets. Use the new check_result API so that we only need a single helper function for ORWRITE instead of one helper for each expected result. Signed-off-by: Ronnie Sahlberg <sahlberg@localhost>
This commit is contained in:
committed by
Ronnie Sahlberg
parent
905695575f
commit
138939cb0e
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <assert.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <dlfcn.h>
|
||||
#include <sys/types.h>
|
||||
@@ -285,60 +286,18 @@ iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||
|
||||
int
|
||||
orwrite(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
uint32_t datalen, int blocksize, int wrprotect,
|
||||
int dpo, int fua, int fua_nv, int group,
|
||||
unsigned char *data)
|
||||
uint32_t datalen, int blocksize, int wrprotect,
|
||||
int dpo, int fua, int fua_nv, int group,
|
||||
unsigned char *data,
|
||||
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 ORWRITE LBA:%" PRIu64 " blocks:%d "
|
||||
"wrprotect:%d dpo:%d fua:%d fua_nv:%d group:%d",
|
||||
lba, datalen / blocksize, wrprotect,
|
||||
dpo, fua, fua_nv, group);
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set in. Skipping write\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
task = iscsi_orwrite_sync(iscsi, lun, lba,
|
||||
data, datalen, blocksize,
|
||||
wrprotect, dpo, fua, fua_nv, group);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL, "[FAILED] Failed to send ORWRITE 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) {
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_NORMAL, "[SKIPPED] ORWRITE is not implemented.");
|
||||
return -2;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL, "[FAILED] ORWRITE command: "
|
||||
"failed with sense. %s", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] ORWRITE returned SUCCESS.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
orwrite_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
uint32_t datalen, int blocksize, int wrprotect,
|
||||
int dpo, int fua, int fua_nv, int group,
|
||||
unsigned char *data)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
logging(LOG_VERBOSE, "Send ORWRITE (Expecting INVALID_FIELD_IN_CDB) "
|
||||
"LBA:%" PRIu64 " blocks:%d wrprotect:%d "
|
||||
"dpo:%d fua:%d fua_nv:%d group:%d",
|
||||
logging(LOG_VERBOSE, "Send ORWRITE (Expecting %s) LBA:%" PRIu64
|
||||
" blocks:%d wrprotect:%d dpo:%d fua:%d fua_nv:%d group:%d",
|
||||
scsi_status_str(status),
|
||||
lba, datalen / blocksize, wrprotect,
|
||||
dpo, fua, fua_nv, group);
|
||||
|
||||
@@ -347,204 +306,19 @@ orwrite_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
return -1;
|
||||
}
|
||||
|
||||
task = iscsi_orwrite_sync(iscsi, lun, lba, data, datalen, blocksize,
|
||||
wrprotect, dpo, fua, fua_nv, group);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL, "[FAILED] Failed to send ORWRITE 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) {
|
||||
task = scsi_cdb_orwrite(lba, datalen, blocksize, wrprotect,
|
||||
dpo, fua, fua_nv, group);
|
||||
assert(task != NULL);
|
||||
|
||||
d.data = data;
|
||||
d.size = datalen;
|
||||
task = iscsi_scsi_command_sync(iscsi, lun, task, &d);
|
||||
|
||||
ret = check_result("ORWRITE", iscsi, task, status, key, ascq, num_ascq);
|
||||
if (task) {
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_NORMAL, "[SKIPPED] ORWRITE is not implemented.");
|
||||
return -2;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL, "[FAILED] ORWRITE successful but should "
|
||||
"have failed with ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB");
|
||||
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] ORWRITE failed with wrong sense. "
|
||||
"Should have failed with ILLEGAL_REQUEST/"
|
||||
"INVALID_FIELD_IN_CDB. Sense:%s\n",
|
||||
iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] ORWRITE returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
orwrite_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
uint32_t datalen, int blocksize, int wrprotect,
|
||||
int dpo, int fua, int fua_nv, int group,
|
||||
unsigned char *data)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
logging(LOG_VERBOSE, "Send ORWRITE (Expecting LBA_OUT_OF_RANGE) "
|
||||
"LBA:%" PRIu64 " blocks:%d wrprotect:%d "
|
||||
"dpo:%d fua:%d fua_nv:%d group:%d",
|
||||
lba, datalen / blocksize, wrprotect,
|
||||
dpo, fua, fua_nv, group);
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set in. Skipping write\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
task = iscsi_orwrite_sync(iscsi, lun, lba, data, datalen, blocksize,
|
||||
wrprotect, dpo, fua, fua_nv, group);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL, "[FAILED] Failed to send ORWRITE 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) {
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_NORMAL, "[SKIPPED] ORWRITE is not implemented.");
|
||||
return -2;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL, "[FAILED] ORWRITE successful but should "
|
||||
"have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE");
|
||||
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) {
|
||||
logging(LOG_NORMAL, "[FAILED] ORWRITE failed with wrong sense. "
|
||||
"Should have failed with ILLEGAL_REQUEST/"
|
||||
"LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] ORWRITE returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
orwrite_writeprotected(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
uint32_t datalen, int blocksize, int wrprotect,
|
||||
int dpo, int fua, int fua_nv, int group,
|
||||
unsigned char *data)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
logging(LOG_VERBOSE, "Send ORWRITE (Expecting WRITE_PROTECTED) "
|
||||
"LBA:%" PRIu64 " blocks:%d wrprotect:%d "
|
||||
"dpo:%d fua:%d fua_nv:%d group:%d",
|
||||
lba, datalen / blocksize, wrprotect,
|
||||
dpo, fua, fua_nv, group);
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set in. Skipping write\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
task = iscsi_orwrite_sync(iscsi, lun, lba, data, datalen, blocksize,
|
||||
wrprotect, dpo, fua, fua_nv, group);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL, "[FAILED] Failed to send ORWRITE 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) {
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_NORMAL, "[SKIPPED] ORWRITE is not implemented.");
|
||||
return -2;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL, "[FAILED] ORWRITE successful but should "
|
||||
"have failed with DATA_PROTECTION/WRITE_PROTECTED");
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_CHECK_CONDITION
|
||||
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION
|
||||
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) {
|
||||
logging(LOG_NORMAL, "[FAILED] ORWRITE failed with wrong sense. "
|
||||
"Should have failed with DATA_PRTOTECTION/"
|
||||
"WRITE_PROTECTED. Sense:%s\n",
|
||||
iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] ORWRITE returned DATA_PROTECTION/WRITE_PROTECTED.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
orwrite_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
||||
uint32_t datalen, int blocksize, int wrprotect,
|
||||
int dpo, int fua, int fua_nv, int group,
|
||||
unsigned char *data)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
logging(LOG_VERBOSE, "Send ORWRITE (Expecting MEDIUM_NOT_PRESENT) "
|
||||
"LBA:%" PRIu64 " blocks:%d wrprotect:%d "
|
||||
"dpo:%d fua:%d fua_nv:%d group:%d",
|
||||
lba, datalen / blocksize, wrprotect,
|
||||
dpo, fua, fua_nv, group);
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set in. Skipping write\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
task = iscsi_orwrite_sync(iscsi, lun, lba, data, datalen, blocksize,
|
||||
wrprotect, dpo, fua, fua_nv, group);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL, "[FAILED] Failed to send ORWRITE 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) {
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_NORMAL, "[SKIPPED] ORWRITE is not implemented.");
|
||||
return -2;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL, "[FAILED] ORWRITE command successful. But should have failed with NOT_READY/MEDIUM_NOT_PRESENT*");
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
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)) {
|
||||
logging(LOG_NORMAL, "[FAILED] ORWRITE Should have failed "
|
||||
"with NOT_READY/MEDIUM_NOT_PRESENT* But failed "
|
||||
"with %s", iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_VERBOSE, "[OK] ORWRITE returned MEDIUM_NOT_PRESENT.");
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user