diff --git a/configure.ac b/configure.ac index e9c5c93..1d28579 100644 --- a/configure.ac +++ b/configure.ac @@ -89,6 +89,16 @@ if test x"$libiscsi_cv_HAVE_SOCKADDR_IN6" = x"yes"; then AC_DEFINE(HAVE_SOCKADDR_IN6,1,[Whether we have IPv6 support]) fi +AC_CACHE_CHECK([for SG_IO support],libiscsi_cv_HAVE_SG_IO,[ +AC_TRY_COMPILE([ +#include +#include ], +[int sgio = SG_IO;], +libiscsi_cv_HAVE_SG_IO=yes,libiscsi_cv_HAVE_SG_IO=no)]) +if test x"$libiscsi_cv_HAVE_SG_IO" = x"yes"; then + AC_DEFINE(HAVE_SG_IO,1,[Whether we have SG_IO support]) +fi + AC_MSG_CHECKING(whether libcunit is available) ac_save_CFLAGS="$CFLAGS" ac_save_LIBS="$LIBS" diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 35813a4..988d2ab 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -159,6 +159,8 @@ EXTERN const char *scsi_sense_key_str(int key); #define SCSI_SENSE_ASCQ_LOGICAL_UNIT_NOT_SUPPORTED 0x2500 #define SCSI_SENSE_ASCQ_INVALID_FIELD_IN_PARAMETER_LIST 0x2600 #define SCSI_SENSE_ASCQ_WRITE_PROTECTED 0x2700 +#define SCSI_SENSE_ASCQ_HARDWARE_WRITE_PROTECTED 0x2701 +#define SCSI_SENSE_ASCQ_SOFTWARE_WRITE_PROTECTED 0x2702 #define SCSI_SENSE_ASCQ_BUS_RESET 0x2900 #define SCSI_SENSE_ASCQ_POWER_ON_OCCURED 0x2901 #define SCSI_SENSE_ASCQ_SCSI_BUS_RESET_OCCURED 0x2902 diff --git a/lib/libiscsi.def b/lib/libiscsi.def index 86448ab..5388dc5 100644 --- a/lib/libiscsi.def +++ b/lib/libiscsi.def @@ -155,8 +155,8 @@ iscsi_writesame10_task iscsi_writesame16_sync iscsi_writesame16_task scsi_association_to_str -scsi_cdb_inquiry scsi_cdb_compareandwrite +scsi_cdb_inquiry scsi_cdb_get_lba_status scsi_cdb_modeselect6 scsi_cdb_modeselect10 diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index d404266..f8cb71a 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -189,6 +189,12 @@ scsi_sense_ascq_str(int ascq) "INVALID_FIELD_IN_PARAMETER_LIST"}, {SCSI_SENSE_ASCQ_WRITE_PROTECTED, "WRITE_PROTECTED"}, + {SCSI_SENSE_ASCQ_WRITE_PROTECTED, + "WRITE_PROTECTED"}, + {SCSI_SENSE_ASCQ_HARDWARE_WRITE_PROTECTED, + "HARDWARE_WRITE_PROTECTED"}, + {SCSI_SENSE_ASCQ_SOFTWARE_WRITE_PROTECTED, + "SOFTWARE_WRITE_PROTECTED"}, {SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT, "MEDIUM_NOT_PRESENT"}, {SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED, diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index 5db77dd..cba050f 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -2,6 +2,7 @@ iscsi-test tool support Copyright (C) 2012 by Lee Duncan + Copyright (C) 2014 Ronnie Sahlberg 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 @@ -17,7 +18,10 @@ along with this program; if not, see . */ +#include "config.h" + #define _GNU_SOURCE +#include #include #include #include @@ -29,6 +33,13 @@ #include #include #include + +#ifdef HAVE_SG_IO +#include +#include +#include +#endif + #include "slist.h" #include "iscsi.h" #include "scsi-lowlevel.h" @@ -44,7 +55,31 @@ const char *initiatorname1 = const char *initiatorname2 = "iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-test-2"; -const char *tgt_url; +int no_medium_ascqs[3] = { + SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT, + SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN, + SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED +}; +int lba_oob_ascqs[1] = { + SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE +}; +int invalid_cdb_ascqs[1] = { + SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB +}; +int write_protect_ascqs[3] = { + SCSI_SENSE_ASCQ_WRITE_PROTECTED, + SCSI_SENSE_ASCQ_HARDWARE_WRITE_PROTECTED, + SCSI_SENSE_ASCQ_SOFTWARE_WRITE_PROTECTED +}; +int sanitize_ascqs[1] = { + SCSI_SENSE_ASCQ_SANITIZE_IN_PROGRESS +}; +int removal_ascqs[1] = { + SCSI_SENSE_ASCQ_MEDIUM_REMOVAL_PREVENTED +}; +int miscompare_ascqs[1] = { + SCSI_SENSE_ASCQ_MISCOMPARE_DURING_VERIFY +}; struct scsi_inquiry_standard *inq; struct scsi_inquiry_logical_block_provisioning *inq_lbp; @@ -65,6 +100,250 @@ int maximum_transfer_length; int (*real_iscsi_queue_pdu)(struct iscsi_context *iscsi, struct iscsi_pdu *pdu); +static const char *scsi_status_str(int status) +{ + switch(status) { + case SCSI_STATUS_GOOD: return "SUCCESS"; + case SCSI_STATUS_CHECK_CONDITION: return "CHECK_CONDITION"; + case SCSI_STATUS_CONDITION_MET: return "CONDITIONS_MET"; + case SCSI_STATUS_BUSY: return "BUSY"; + case SCSI_STATUS_RESERVATION_CONFLICT: return "RESERVATION_CONFLICT"; + case SCSI_STATUS_TASK_SET_FULL: return "TASK_SET_FULL"; + case SCSI_STATUS_ACA_ACTIVE: return "ACA_ACTIVE"; + case SCSI_STATUS_TASK_ABORTED: return "TASK_ABORTED"; + } + return "UNKNOWN"; +} + +/* + * There is no agreement among the T10 committee whether a SCSI target should + * report "invalid opcode", "invalid field in CDB" or "invalid field in + * parameter list" if the opcode consists of two bytes. Hence accept all three + * sense codes for two-byte opcodes. For more information see also Frederick + * Knight, RE: INVALID COMMAND OPERATION CODE, T10 Reflector, 16 May 2008 + * (http://t10.org/ftp/t10/t10r/2008/r0805167.htm). + */ +static int status_is_invalid_opcode(struct scsi_task *task) +{ + if (task->status == SCSI_STATUS_CHECK_CONDITION + && task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST) { + if (task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) + return 1; + switch (task->cdb[0]) { + case SCSI_OPCODE_MAINTENANCE_IN: + case SCSI_OPCODE_SERVICE_ACTION_IN: + switch (task->sense.ascq) { + case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB: + case SCSI_SENSE_ASCQ_INVALID_FIELD_IN_PARAMETER_LIST: + return 1; + } + } + } + return 0; +} + +static int check_result(const char *opcode, struct scsi_device *sdev, + struct scsi_task *task, + int status, enum scsi_sense_key key, + int *ascq, int num_ascq) +{ + int ascq_ok = 0; + + if (task == NULL) { + logging(LOG_NORMAL, "[FAILED] Failed to send %s command: " + "%s", opcode, sdev->error_str); + return -1; + } + if (status_is_invalid_opcode(task)) { + logging(LOG_NORMAL, "[SKIPPED] %s is not implemented.", + opcode); + return -2; + } + if (status == SCSI_STATUS_GOOD && task->status != SCSI_STATUS_GOOD) { + logging(LOG_NORMAL, "[FAILED] %s command failed with " + "sense. %s", opcode, sdev->error_str); + return -1; + } + if (status != SCSI_STATUS_GOOD && task->status == SCSI_STATUS_GOOD) { + logging(LOG_NORMAL, "[FAILED] %s successful but should " + "have failed with %s(0x%02x)/%s(0x%04x)", + opcode, + scsi_sense_key_str(key), key, + scsi_sense_ascq_str(ascq[0]), ascq[0]); + return -1; + } + if (status == SCSI_STATUS_RESERVATION_CONFLICT + && task->status != SCSI_STATUS_RESERVATION_CONFLICT) { + logging(LOG_NORMAL, "[FAILED] %s command should have failed " + "with RESERVATION_CONFLICT.", opcode); + return -1; + } + /* did we get any of the expected ASCQs ?*/ + if (status == SCSI_STATUS_CHECK_CONDITION) { + int i; + for (i = 0; i < num_ascq; i++) { + if (ascq[i] == task->sense.ascq) { + ascq_ok = 1; + } + } + if (num_ascq == 0) { + ascq_ok = 1; + } + } + if (status == SCSI_STATUS_CHECK_CONDITION && + (task->status != status + || task->sense.key != key + || !ascq_ok)) { + logging(LOG_NORMAL, "[FAILED] %s failed with wrong sense. " + "Should have failed with %s(0x%02x)/%s(0x%04x)" + "but failed with Sense:%s\n", + opcode, + scsi_sense_key_str(key), key, + scsi_sense_ascq_str(ascq[0]), ascq[0], + sdev->error_str); + return -1; + } + logging(LOG_VERBOSE, "[OK] %s returned %s %s(0x%02x) %s(0x%04x)", + opcode, scsi_status_str(status), + scsi_sense_key_str(task->sense.key), task->sense.key, + scsi_sense_ascq_str(task->sense.ascq), task->sense.ascq); + return 0; +} + +static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi_task *task, struct iscsi_data *d) +{ + if (sdev->iscsi_url) { + if (sdev->error_str != NULL) { + free(discard_const(sdev->error_str)); + sdev->error_str = NULL; + } + task = iscsi_scsi_command_sync(sdev->iscsi_ctx, sdev->iscsi_lun, task, d); + if (task == NULL) { + sdev->error_str = strdup(iscsi_get_error(sdev->iscsi_ctx)); + } + + return task; + } + +#ifdef HAVE_SG_IO + if (sdev->sgio_dev) { + sg_io_hdr_t io_hdr; + unsigned int sense_len=32; + unsigned char sense[sense_len]; + char buf[1024]; + + memset(sense, 0, sizeof(sense)); + memset(&io_hdr, 0, sizeof(sg_io_hdr_t)); + io_hdr.interface_id = 'S'; + + /* CDB */ + io_hdr.cmdp = task->cdb; + io_hdr.cmd_len = task->cdb_size; + + /* Where to store the sense_data, if there was an error */ + io_hdr.sbp = sense; + io_hdr.mx_sb_len = sense_len; + sense_len=0; + + /* Transfer direction, either in or out. Linux does not yet + support bidirectional SCSI transfers ? + */ + switch (task->xfer_dir) { + case SCSI_XFER_WRITE: + io_hdr.dxfer_direction = SG_DXFER_TO_DEV; + io_hdr.dxferp = d->data; + io_hdr.dxfer_len = d->size; + break; + case SCSI_XFER_READ: + io_hdr.dxfer_direction = SG_DXFER_FROM_DEV; + task->datain.size = task->expxferlen; + task->datain.data = malloc(task->datain.size); + memset(task->datain.data, 0, task->datain.size); + io_hdr.dxferp = task->datain.data; + io_hdr.dxfer_len = task->datain.size; + break; + } + + /* SCSI timeout in ms */ + io_hdr.timeout = 5000; + + if(ioctl(sdev->sgio_fd, SG_IO, &io_hdr) < 0){ + if (sdev->error_str != NULL) { + free(discard_const(sdev->error_str)); + } + sdev->error_str = strdup("SG_IO ioctl failed"); + return NULL; + } + + /* now for the error processing */ + if(io_hdr.sb_len_wr > 0){ + task->status = SCSI_STATUS_CHECK_CONDITION; + task->sense.error_type = sense[0] & 0x7f; + switch (task->sense.error_type) { + case 0x70: + case 0x71: + task->sense.key = sense[2] & 0x0f; + task->sense.ascq = scsi_get_uint16(&sense[12]); + break; + case 0x72: + case 0x73: + task->sense.key = sense[1] & 0x0f; + task->sense.ascq = scsi_get_uint16(&sense[2]); + break; + } + sense_len=io_hdr.sb_len_wr; + snprintf(buf, sizeof(buf), "SENSE KEY:%s(%d) ASCQ:%s(0x%04x)", + scsi_sense_key_str(task->sense.key), + task->sense.key, + scsi_sense_ascq_str(task->sense.ascq), + task->sense.ascq); + if (sdev->error_str != NULL) { + free(discard_const(sdev->error_str)); + } + sdev->error_str = strdup(buf); + return task; + } + + if(io_hdr.masked_status){ + task->status = SCSI_STATUS_ERROR; + task->sense.key = 0x0f; + task->sense.ascq = 0xffff; + + if (sdev->error_str != NULL) { + free(discard_const(sdev->error_str)); + } + sdev->error_str = strdup("SCSI masked error"); + return NULL; + } + if(io_hdr.host_status){ + task->status = SCSI_STATUS_ERROR; + task->sense.key = 0x0f; + task->sense.ascq = 0xffff; + + snprintf(buf, sizeof(buf), "SCSI host error. Status=0x%x", io_hdr.host_status); + if (sdev->error_str != NULL) { + free(discard_const(sdev->error_str)); + } + sdev->error_str = strdup(buf); + return task; + } + if(io_hdr.driver_status){ + task->status = SCSI_STATUS_ERROR; + task->sense.key = 0x0f; + task->sense.ascq = 0xffff; + + if (sdev->error_str != NULL) { + free(discard_const(sdev->error_str)); + } + sdev->error_str = strdup("SCSI driver error"); + return NULL; + } + return task; + } +#endif + return NULL; +} + void logging(int level, const char *format, ...) { va_list ap; @@ -189,61 +468,19 @@ 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) +orwrite(struct scsi_device *sdev, uint64_t lba, + 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); @@ -252,208 +489,23 @@ 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) { - 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; - } + task = scsi_cdb_orwrite(lba, datalen, blocksize, wrprotect, + dpo, fua, fua_nv, group); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] ORWRITE returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB."); - return 0; + d.data = data; + d.size = datalen; + task = send_scsi_command(sdev, task, &d); + + ret = check_result("ORWRITE", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } 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; -} - -int -prin_task(struct iscsi_context *iscsi, int lun, int service_action, +prin_task(struct scsi_device *sdev, int service_action, int success_expected) { const int buf_sz = 16384; @@ -464,17 +516,15 @@ prin_task(struct iscsi_context *iscsi, int lun, int service_action, logging(LOG_VERBOSE, "Send PRIN/SA=0x%02x, expect %s", service_action, success_expected ? "success" : "failure"); - task = iscsi_persistent_reserve_in_sync(iscsi, lun, + task = iscsi_persistent_reserve_in_sync(sdev->iscsi_ctx, sdev->iscsi_lun, service_action, buf_sz); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send PRIN command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); 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) { + if (status_is_invalid_opcode(task)) { scsi_free_scsi_task(task); logging(LOG_NORMAL, "[SKIPPED] PERSISTENT RESERVE IN is not implemented."); return -2; @@ -484,7 +534,7 @@ prin_task(struct iscsi_context *iscsi, int lun, int service_action, if (task->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[FAILED] PRIN/SA=0x%x failed: %s", - service_action, iscsi_get_error(iscsi)); + service_action, iscsi_get_error(sdev->iscsi_ctx)); ret = -1; } } else { @@ -503,7 +553,7 @@ prin_task(struct iscsi_context *iscsi, int lun, int service_action, } int -prin_read_keys(struct iscsi_context *iscsi, int lun, struct scsi_task **tp, +prin_read_keys(struct scsi_device *sdev, struct scsi_task **tp, struct scsi_persistent_reserve_in_read_keys **rkp) { const int buf_sz = 16384; @@ -512,24 +562,22 @@ prin_read_keys(struct iscsi_context *iscsi, int lun, struct scsi_task **tp, logging(LOG_VERBOSE, "Send PRIN/READ_KEYS"); - *tp = iscsi_persistent_reserve_in_sync(iscsi, lun, + *tp = iscsi_persistent_reserve_in_sync(sdev->iscsi_ctx, sdev->iscsi_lun, SCSI_PERSISTENT_RESERVE_READ_KEYS, buf_sz); if (*tp == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send PRIN command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); return -1; } - if ((*tp)->status == SCSI_STATUS_CHECK_CONDITION - && (*tp)->sense.key == SCSI_SENSE_ILLEGAL_REQUEST - && (*tp)->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { + if (status_is_invalid_opcode(*tp)) { logging(LOG_NORMAL, "[SKIPPED] PERSISTENT RESERVE IN is not implemented."); return -2; } if ((*tp)->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[FAILED] PRIN command: failed with sense. %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); return -1; } @@ -537,7 +585,7 @@ prin_read_keys(struct iscsi_context *iscsi, int lun, struct scsi_task **tp, if (rk == NULL) { logging(LOG_NORMAL, "[FAIL] failed to unmarshall PRIN/READ_KEYS data. %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); return -1; } if (rkp != NULL) @@ -547,7 +595,7 @@ prin_read_keys(struct iscsi_context *iscsi, int lun, struct scsi_task **tp, } int -prout_register_and_ignore(struct iscsi_context *iscsi, int lun, +prout_register_and_ignore(struct scsi_device *sdev, unsigned long long sark) { struct scsi_persistent_reserve_out_basic poc; @@ -557,8 +605,8 @@ prout_register_and_ignore(struct iscsi_context *iscsi, int lun, /* register our reservation key with the target */ logging(LOG_VERBOSE, - "Send PROUT/REGISTER_AND_IGNORE to register init=%s", - iscsi->initiator_name); + "Send PROUT/REGISTER_AND_IGNORE to register init=%s", + sdev->iscsi_ctx->initiator_name); if (!data_loss) { printf("--dataloss flag is not set in. Skipping PROUT\n"); @@ -567,18 +615,16 @@ prout_register_and_ignore(struct iscsi_context *iscsi, int lun, memset(&poc, 0, sizeof (poc)); poc.service_action_reservation_key = sark; - task = iscsi_persistent_reserve_out_sync(iscsi, lun, + task = iscsi_persistent_reserve_out_sync(sdev->iscsi_ctx, sdev->iscsi_lun, SCSI_PERSISTENT_RESERVE_REGISTER_AND_IGNORE_EXISTING_KEY, SCSI_PERSISTENT_RESERVE_SCOPE_LU, 0, &poc); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send PROUT command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); 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) { + if (status_is_invalid_opcode(task)) { logging(LOG_NORMAL, "[SKIPPED] PROUT Not Supported"); ret = -2; goto dun; @@ -586,7 +632,7 @@ prout_register_and_ignore(struct iscsi_context *iscsi, int lun, if (task->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[FAILED] PROUT command: failed with sense. %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); ret = -1; } @@ -596,7 +642,7 @@ prout_register_and_ignore(struct iscsi_context *iscsi, int lun, } int -prout_register_key(struct iscsi_context *iscsi, int lun, +prout_register_key(struct scsi_device *sdev, unsigned long long sark, unsigned long long rk) { struct scsi_persistent_reserve_out_basic poc; @@ -607,8 +653,8 @@ prout_register_key(struct iscsi_context *iscsi, int lun, /* register/unregister our reservation key with the target */ logging(LOG_VERBOSE, "Send PROUT/REGISTER to %s init=%s", - sark != 0 ? "register" : "unregister", - iscsi->initiator_name); + sark != 0 ? "register" : "unregister", + sdev->iscsi_ctx->initiator_name); if (!data_loss) { printf("--dataloss flag is not set in. Skipping PROUT\n"); @@ -618,18 +664,16 @@ prout_register_key(struct iscsi_context *iscsi, int lun, memset(&poc, 0, sizeof (poc)); poc.service_action_reservation_key = sark; poc.reservation_key = rk; - task = iscsi_persistent_reserve_out_sync(iscsi, lun, + task = iscsi_persistent_reserve_out_sync(sdev->iscsi_ctx, sdev->iscsi_lun, SCSI_PERSISTENT_RESERVE_REGISTER, SCSI_PERSISTENT_RESERVE_SCOPE_LU, 0, &poc); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send PROUT command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); 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) { + if (status_is_invalid_opcode(task)) { scsi_free_scsi_task(task); logging(LOG_NORMAL, "[SKIPPED] PERSISTENT RESERVE OUT is not implemented."); return -2; @@ -637,7 +681,7 @@ prout_register_key(struct iscsi_context *iscsi, int lun, if (task->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[FAILED] PROUT command: failed with sense: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); ret = -1; } @@ -647,7 +691,7 @@ prout_register_key(struct iscsi_context *iscsi, int lun, } int -prin_verify_key_presence(struct iscsi_context *iscsi, int lun, +prin_verify_key_presence(struct scsi_device *sdev, unsigned long long key, int present) { struct scsi_task *task; @@ -659,21 +703,19 @@ prin_verify_key_presence(struct iscsi_context *iscsi, int lun, logging(LOG_VERBOSE, - "Send PRIN/READ_KEYS to verify key %s init=%s... ", - present ? "present" : "absent", - iscsi->initiator_name); + "Send PRIN/READ_KEYS to verify key %s init=%s... ", + present ? "present" : "absent", + sdev->iscsi_ctx->initiator_name); - task = iscsi_persistent_reserve_in_sync(iscsi, lun, + task = iscsi_persistent_reserve_in_sync(sdev->iscsi_ctx, sdev->iscsi_lun, SCSI_PERSISTENT_RESERVE_READ_KEYS, buf_sz); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send PRIN command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); 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) { + if (status_is_invalid_opcode(task)) { scsi_free_scsi_task(task); logging(LOG_NORMAL, "[SKIPPED] PERSISTENT RESERVE IN is not implemented."); return -2; @@ -682,7 +724,7 @@ prin_verify_key_presence(struct iscsi_context *iscsi, int lun, if (task->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[FAILED] PRIN command: failed with sense. %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); ret = -1; goto dun; } @@ -691,7 +733,7 @@ prin_verify_key_presence(struct iscsi_context *iscsi, int lun, if (rk == NULL) { logging(LOG_NORMAL, "[FAILED] failed to unmarshall PRIN/READ_KEYS data. %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); ret = -1; goto dun; } @@ -718,7 +760,7 @@ prin_verify_key_presence(struct iscsi_context *iscsi, int lun, } int -prout_reregister_key_fails(struct iscsi_context *iscsi, int lun, +prout_reregister_key_fails(struct scsi_device *sdev, unsigned long long sark) { struct scsi_persistent_reserve_out_basic poc; @@ -727,8 +769,8 @@ prout_reregister_key_fails(struct iscsi_context *iscsi, int lun, logging(LOG_VERBOSE, - "Send PROUT/REGISTER to ensure reregister fails init=%s", - iscsi->initiator_name); + "Send PROUT/REGISTER to ensure reregister fails init=%s", + sdev->iscsi_ctx->initiator_name); if (!data_loss) { printf("--dataloss flag is not set in. Skipping PROUT\n"); @@ -737,18 +779,16 @@ prout_reregister_key_fails(struct iscsi_context *iscsi, int lun, memset(&poc, 0, sizeof (poc)); poc.service_action_reservation_key = sark; - task = iscsi_persistent_reserve_out_sync(iscsi, lun, + task = iscsi_persistent_reserve_out_sync(sdev->iscsi_ctx, sdev->iscsi_lun, SCSI_PERSISTENT_RESERVE_REGISTER, SCSI_PERSISTENT_RESERVE_SCOPE_LU, 0, &poc); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send PROUT command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); 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) { + if (status_is_invalid_opcode(task)) { scsi_free_scsi_task(task); logging(LOG_NORMAL, "[SKIPPED] PERSISTENT RESERVE OUT is not implemented."); return -2; @@ -765,7 +805,7 @@ prout_reregister_key_fails(struct iscsi_context *iscsi, int lun, } int -prout_reserve(struct iscsi_context *iscsi, int lun, +prout_reserve(struct scsi_device *sdev, unsigned long long key, enum scsi_persistent_out_type pr_type) { struct scsi_persistent_reserve_out_basic poc; @@ -775,9 +815,9 @@ prout_reserve(struct iscsi_context *iscsi, int lun, /* reserve the target using specified reservation type */ logging(LOG_VERBOSE, - "Send PROUT/RESERVE to reserve, type=%d (%s) init=%s", - pr_type, scsi_pr_type_str(pr_type), - iscsi->initiator_name); + "Send PROUT/RESERVE to reserve, type=%d (%s) init=%s", + pr_type, scsi_pr_type_str(pr_type), + sdev->iscsi_ctx->initiator_name); if (!data_loss) { printf("--dataloss flag is not set in. Skipping PROUT\n"); @@ -786,19 +826,17 @@ prout_reserve(struct iscsi_context *iscsi, int lun, memset(&poc, 0, sizeof (poc)); poc.reservation_key = key; - task = iscsi_persistent_reserve_out_sync(iscsi, lun, + task = iscsi_persistent_reserve_out_sync(sdev->iscsi_ctx, sdev->iscsi_lun, SCSI_PERSISTENT_RESERVE_RESERVE, SCSI_PERSISTENT_RESERVE_SCOPE_LU, pr_type, &poc); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send PROUT command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); 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) { + if (status_is_invalid_opcode(task)) { scsi_free_scsi_task(task); logging(LOG_NORMAL, "[SKIPPED] PERSISTENT RESERVE OUT is not implemented."); return -2; @@ -807,7 +845,7 @@ prout_reserve(struct iscsi_context *iscsi, int lun, if (task->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[FAILED] PROUT command: failed with sense. %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); ret = -1; } @@ -816,7 +854,7 @@ prout_reserve(struct iscsi_context *iscsi, int lun, } int -prout_release(struct iscsi_context *iscsi, int lun, +prout_release(struct scsi_device *sdev, unsigned long long key, enum scsi_persistent_out_type pr_type) { struct scsi_persistent_reserve_out_basic poc; @@ -825,8 +863,8 @@ prout_release(struct iscsi_context *iscsi, int lun, logging(LOG_VERBOSE, - "Send PROUT/RELEASE to release reservation, type=%d init=%s", - pr_type, iscsi->initiator_name); + "Send PROUT/RELEASE to release reservation, type=%d init=%s", + pr_type, sdev->iscsi_ctx->initiator_name); if (!data_loss) { printf("--dataloss flag is not set in. Skipping PROUT\n"); @@ -835,19 +873,17 @@ prout_release(struct iscsi_context *iscsi, int lun, memset(&poc, 0, sizeof (poc)); poc.reservation_key = key; - task = iscsi_persistent_reserve_out_sync(iscsi, lun, + task = iscsi_persistent_reserve_out_sync(sdev->iscsi_ctx, sdev->iscsi_lun, SCSI_PERSISTENT_RESERVE_RELEASE, SCSI_PERSISTENT_RESERVE_SCOPE_LU, pr_type, &poc); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send PROUT command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); 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) { + if (status_is_invalid_opcode(task)) { scsi_free_scsi_task(task); logging(LOG_NORMAL, "[SKIPPED] PERSISTENT RESERVE OUT is not implemented."); return -2; @@ -856,7 +892,7 @@ prout_release(struct iscsi_context *iscsi, int lun, if (task->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[FAILED] PROUT command: failed with sense. %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); ret = -1; } @@ -865,7 +901,7 @@ prout_release(struct iscsi_context *iscsi, int lun, } int -prin_verify_reserved_as(struct iscsi_context *iscsi, int lun, +prin_verify_reserved_as(struct scsi_device *sdev, unsigned long long key, enum scsi_persistent_out_type pr_type) { struct scsi_task *task; @@ -875,20 +911,18 @@ prin_verify_reserved_as(struct iscsi_context *iscsi, int lun, logging(LOG_VERBOSE, - "Send PRIN/READ_RESERVATION to verify type=%d init=%s... ", - pr_type, iscsi->initiator_name); + "Send PRIN/READ_RESERVATION to verify type=%d init=%s... ", + pr_type, sdev->iscsi_ctx->initiator_name); - task = iscsi_persistent_reserve_in_sync(iscsi, lun, + task = iscsi_persistent_reserve_in_sync(sdev->iscsi_ctx, sdev->iscsi_lun, SCSI_PERSISTENT_RESERVE_READ_RESERVATION, buf_sz); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send PRIN command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); 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) { + if (status_is_invalid_opcode(task)) { scsi_free_scsi_task(task); logging(LOG_NORMAL, "[SKIPPED] PERSISTENT RESERVE IN is not implemented."); return -2; @@ -897,7 +931,7 @@ prin_verify_reserved_as(struct iscsi_context *iscsi, int lun, if (task->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[FAILED] PRIN command: failed with sense: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); ret = -1; goto dun; } @@ -905,7 +939,7 @@ prin_verify_reserved_as(struct iscsi_context *iscsi, int lun, if (rr == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to unmarshall PRIN/READ_RESERVATION data. %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); ret = -1; goto dun; } @@ -939,7 +973,7 @@ prin_verify_reserved_as(struct iscsi_context *iscsi, int lun, } int -prin_verify_not_reserved(struct iscsi_context *iscsi, int lun) +prin_verify_not_reserved(struct scsi_device *sdev) { struct scsi_task *task; const int buf_sz = 16384; @@ -948,20 +982,18 @@ prin_verify_not_reserved(struct iscsi_context *iscsi, int lun) logging(LOG_VERBOSE, - "Send PRIN/READ_RESERVATION to verify not reserved init=%s", - iscsi->initiator_name); + "Send PRIN/READ_RESERVATION to verify not reserved init=%s", + sdev->iscsi_ctx->initiator_name); - task = iscsi_persistent_reserve_in_sync(iscsi, lun, + task = iscsi_persistent_reserve_in_sync(sdev->iscsi_ctx, sdev->iscsi_lun, SCSI_PERSISTENT_RESERVE_READ_RESERVATION, buf_sz); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send PRIN command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); 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) { + if (status_is_invalid_opcode(task)) { scsi_free_scsi_task(task); logging(LOG_NORMAL, "[SKIPPED] PERSISTENT RESERVE IN is not implemented."); return -2; @@ -970,7 +1002,7 @@ prin_verify_not_reserved(struct iscsi_context *iscsi, int lun) if (task->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[FAILED] PRIN command: failed with sense: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); ret = -1; goto dun; } @@ -978,7 +1010,7 @@ prin_verify_not_reserved(struct iscsi_context *iscsi, int lun) if (rr == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to unmarshall PRIN/READ_RESERVATION data: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); ret = -1; goto dun; } @@ -996,7 +1028,7 @@ prin_verify_not_reserved(struct iscsi_context *iscsi, int lun) } int -verify_read_works(struct iscsi_context *iscsi, int lun, unsigned char *buf) +verify_read_works(struct scsi_device *sdev, unsigned char *buf) { struct scsi_task *task; const uint32_t lba = 1; @@ -1010,21 +1042,21 @@ verify_read_works(struct iscsi_context *iscsi, int lun, unsigned char *buf) */ logging(LOG_VERBOSE, "Send READ10 to verify READ works init=%s", - iscsi->initiator_name); + sdev->iscsi_ctx->initiator_name); - task = iscsi_read10_sync(iscsi, lun, lba, datalen, blksize, + task = iscsi_read10_sync(sdev->iscsi_ctx, sdev->iscsi_lun, lba, datalen, blksize, 0, 0, 0, 0, 0); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send READ10 command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); return -1; } if (task->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[FAILED] READ10 command: failed with sense: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); ret = -1; goto dun; } @@ -1036,7 +1068,7 @@ verify_read_works(struct iscsi_context *iscsi, int lun, unsigned char *buf) } int -verify_write_works(struct iscsi_context *iscsi, int lun, unsigned char *buf) +verify_write_works(struct scsi_device *sdev, unsigned char *buf) { struct scsi_task *task; const uint32_t lba = 1; @@ -1050,20 +1082,20 @@ verify_write_works(struct iscsi_context *iscsi, int lun, unsigned char *buf) */ logging(LOG_VERBOSE, "Send WRITE10 to verify WRITE works init=%s", - iscsi->initiator_name); + sdev->iscsi_ctx->initiator_name); - task = iscsi_write10_sync(iscsi, lun, lba, buf, datalen, blksize, + task = iscsi_write10_sync(sdev->iscsi_ctx, sdev->iscsi_lun, lba, buf, datalen, blksize, 0, 0, 0, 0, 0); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send WRITE10 command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); return -1; } if (task->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[FAILED] WRITE10 command: failed with sense: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); ret = -1; } scsi_free_scsi_task(task); @@ -1071,7 +1103,7 @@ verify_write_works(struct iscsi_context *iscsi, int lun, unsigned char *buf) } int -verify_read_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf) +verify_read_fails(struct scsi_device *sdev, unsigned char *buf) { struct scsi_task *task; const uint32_t lba = 1; @@ -1085,15 +1117,15 @@ verify_read_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf) */ logging(LOG_VERBOSE, - "Send READ10 to verify READ does not work init=%s", - iscsi->initiator_name); + "Send READ10 to verify READ does not work init=%s", + sdev->iscsi_ctx->initiator_name); - task = iscsi_read10_sync(iscsi, lun, lba, datalen, blksize, + task = iscsi_read10_sync(sdev->iscsi_ctx, sdev->iscsi_lun, lba, datalen, blksize, 0, 0, 0, 0, 0); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send READ10 command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); return -1; } @@ -1115,7 +1147,7 @@ verify_read_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf) } int -verify_write_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf) +verify_write_fails(struct scsi_device *sdev, unsigned char *buf) { struct scsi_task *task; const uint32_t lba = 1; @@ -1129,15 +1161,15 @@ verify_write_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf) */ logging(LOG_VERBOSE, - "Send WRITE10 to verify WRITE does not work init=%s", - iscsi->initiator_name); + "Send WRITE10 to verify WRITE does not work init=%s", + sdev->iscsi_ctx->initiator_name); - task = iscsi_write10_sync(iscsi, lun, lba, buf, datalen, blksize, + task = iscsi_write10_sync(sdev->iscsi_ctx, sdev->iscsi_lun, lba, buf, datalen, blksize, 0, 0, 0, 0, 0); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send WRITE10 command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); return -1; } @@ -1158,472 +1190,146 @@ verify_write_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf) } int -synchronizecache10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num, int sync_nv, int immed) +synchronizecache10(struct scsi_device *sdev, uint32_t lba, int num, int sync_nv, int immed, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send SYNCHRONIZECACHE10 LBA:%d blocks:%d" - " sync_nv:%d immed:%d", + logging(LOG_VERBOSE, "Send SYNCHRONIZECACHE10 (Expecting %s) LBA:%d" + " blocks:%d sync_nv:%d immed:%d", + scsi_status_str(status), lba, num, sync_nv, immed); - task = iscsi_synchronizecache10_sync(iscsi, lun, lba, num, - sync_nv, immed); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send SYNCHRONIZECAHCE10 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] SYNCHRONIZECAHCE10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] SYNCHRONIZECACHE10 command: " - "failed with sense. %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } + task = scsi_cdb_synchronizecache10(lba, num_blocks, sync_nv, immed); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] SYNCHRONIZECAHCE10 returned SUCCESS."); - return 0; + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("SYNCHRONIZECACHE10", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -synchronizecache10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int num, int sync_nv, int immed) +synchronizecache16(struct scsi_device *sdev, uint64_t lba, int num, int sync_nv, int immed, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send SYNCHRONIZECACHE10 (Expecting MEDIUM_NOT_PRESENT) LBA:%d blocks:%d" - " sync_nv:%d immed:%d", + logging(LOG_VERBOSE, "Send SYNCHRONIZECACHE16 (Expecting %s) LBA:%" + PRIu64 " blocks:%d sync_nv:%d immed:%d", + scsi_status_str(status), lba, num, sync_nv, immed); - task = iscsi_synchronizecache10_sync(iscsi, lun, lba, num, - sync_nv, immed); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send SYNCHRONIZECAHCE10 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] SYNCHRONIZECAHCE10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] SYNCHRONIZECACHE10 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] SYNCHRONIZECAHCE10 Should have failed " - "with NOT_READY/MEDIUM_NOT_PRESENT* But failed " - "with %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } + task = scsi_cdb_synchronizecache16(lba, num_blocks, sync_nv, immed); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] SYNCHRONIZECAHCE10 returned MEDIUM_NOT_PRESENT."); - return 0; + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("SYNCHRONIZECACHE16", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } -int -synchronizecache16(struct iscsi_context *iscsi, int lun, uint64_t lba, int num, int sync_nv, int immed) +int sanitize(struct scsi_device *sdev, int immed, int ause, int sa, int param_len, struct iscsi_data *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send SYNCHRONIZECACHE16 LBA:%" PRIu64 " blocks:%d" - " sync_nv:%d immed:%d", - lba, num, sync_nv, immed); - - task = iscsi_synchronizecache16_sync(iscsi, lun, lba, num, - sync_nv, immed); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send SYNCHRONIZECAHCE16 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] SYNCHRONIZECAHCE16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] SYNCHRONIZECACHE16 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] SYNCHRONIZECAHCE16 returned SUCCESS."); - return 0; -} - -int -synchronizecache16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, int num, int sync_nv, int immed) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send SYNCHRONIZECACHE16 (Expecting MEDIUM_NOT_PRESENT) LBA:%" PRIu64 " blocks:%d" - " sync_nv:%d immed:%d", - lba, num, sync_nv, immed); - - task = iscsi_synchronizecache16_sync(iscsi, lun, lba, num, - sync_nv, immed); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send SYNCHRONIZECAHCE16 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] SYNCHRONIZECAHCE16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] SYNCHRONIZECACHE16 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] SYNCHRONIZECACHE16 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] SYNCHRONIZECAHCE16 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int sanitize(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send SANITIZE IMMED:%d AUSE:%d SA:%d " - "PARAM_LEN:%d", + logging(LOG_VERBOSE, "Send SANITIZE (Expecting %s) IMMED:%d AUSE:%d " + "SA:%d PARAM_LEN:%d", + scsi_status_str(status), immed, ause, sa, param_len); - task = iscsi_sanitize_sync(iscsi, lun, immed, ause, sa, param_len, + if (!data_loss) { + printf("--dataloss flag is not set in. Skipping sanitize\n"); + return -1; + } + + task = iscsi_sanitize_sync(sdev->iscsi_ctx, sdev->iscsi_lun, immed, ause, sa, param_len, data); - if (task == NULL) { - logging(LOG_NORMAL, - "[FAILED] Failed to send SANITIZE 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] SANITIZE is not " - "implemented on target"); + task = scsi_cdb_sanitize(immed, ause, sa, param_len); + + assert(task != NULL); + + task = send_scsi_command(sdev, task, data); + + ret = check_result("SANITIZE", sdev, 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] SANITIZE 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] SANITIZE returned SUCCESS."); - return 0; + return ret; } -int sanitize_invalidfieldincdb(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data) +int startstopunit(struct scsi_device *sdev, int immed, int pcm, int pc, int no_flush, int loej, int start, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send SANITIZE (Expecting INVALID_FIELD_IN_CDB) " - "IMMED:%d AUSE:%d SA:%d " - "PARAM_LEN:%d", - immed, ause, sa, param_len); - - task = iscsi_sanitize_sync(iscsi, lun, immed, ause, sa, param_len, - data); - if (task == NULL) { - logging(LOG_NORMAL, - "[FAILED] Failed to send SANITIZE 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] SANITIZE is not " - "implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] SANITIZE 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] SANITIZE 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] SANITIZE returned ILLEGAL_REQUEST/" - "INVALID_FIELD_IB_CDB."); - return 0; -} - -int sanitize_conflict(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send SANITIZE (Expecting RESERVATION_CONFLICT) " - "IMMED:%d AUSE:%d SA:%d " - "PARAM_LEN:%d", - immed, ause, sa, param_len); - - task = iscsi_sanitize_sync(iscsi, lun, immed, ause, sa, param_len, - data); - if (task == NULL) { - logging(LOG_NORMAL, - "[FAILED] Failed to send SANITIZE command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, - "[FAILED] SANITIZE successful but should have failed with RESERVATION_CONFLICT"); - scsi_free_scsi_task(task); - return -1; - } - - if (task->status != SCSI_STATUS_RESERVATION_CONFLICT) { - logging(LOG_NORMAL, "[FAILED] Expected RESERVATION CONFLICT. " - "Sense:%s", iscsi_get_error(iscsi)); - return -1; - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] SANITIZE returned RESERVATION_CONFLICT."); - return 0; -} - -int sanitize_writeprotected(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send SANITIZE (Expecting WRITE_PROTECTED) " - "IMMED:%d AUSE:%d SA:%d " - "PARAM_LEN:%d", - immed, ause, sa, param_len); - - task = iscsi_sanitize_sync(iscsi, lun, immed, ause, sa, param_len, - data); - if (task == NULL) { - logging(LOG_NORMAL, - "[FAILED] Failed to send SANITIZE command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] SANITIZE 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] SANITIZE 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] SANITIZE returned DATA_PROTECTION/WRITE_PROTECTED."); - return 0; -} - -int startstopunit(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send STARTSTOPUNIT IMMED:%d PCM:%d PC:%d NO_FLUSH:%d LOEJ:%d START:%d", immed, pcm, pc, no_flush, loej, start); - task = iscsi_startstopunit_sync(iscsi, lun, immed, pcm, pc, no_flush, - loej, start); - if (task == NULL) { - logging(LOG_NORMAL, - "[FAILED] Failed to send STARTSTOPUNIT command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, - "[FAILED] STARTSTOPUNIT 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] STARTSTOPUNIT returned SUCCESS."); - return 0; -} - -int startstopunit_preventremoval(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send STARTSTOPUNIT (Expecting MEDIUM_REMOVAL_PREVENTED) " - "IMMED:%d PCM:%d PC:%d NO_FLUSH:%d LOEJ:%d START:%d", + logging(LOG_VERBOSE, "Send STARTSTOPUNIT (Expecting %s) IMMED:%d " + "PCM:%d PC:%d NO_FLUSH:%d LOEJ:%d START:%d", + scsi_status_str(status), immed, pcm, pc, no_flush, loej, start); - task = iscsi_startstopunit_sync(iscsi, lun, immed, pcm, pc, no_flush, - loej, start); - if (task == NULL) { - logging(LOG_NORMAL, - "[FAILED] Failed to send STARTSTOPUNIT command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, - "[FAILED] STARTSTOPUNIT successful but should have failed with ILLEGAL_REQUEST/MEDIUM_REMOVAL_PREVENTED"); - 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_MEDIUM_REMOVAL_PREVENTED) { - logging(LOG_NORMAL, "[FAILED] STARTSTOPUNIT Should have failed " - "with ILLEGAL_REQUEST/MEDIUM_REMOVAL_PREVENTED But failed " - "with %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] STARTSTOPUNIT returned MEDIUM_REMOVAL_PREVENTED."); - return 0; -} + task = scsi_cdb_startstopunit(immed, pcm, pc, no_flush, loej, start); + assert(task != NULL); -int startstopunit_sanitize(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start) -{ - struct scsi_task *task; + task = send_scsi_command(sdev, task, NULL); - logging(LOG_VERBOSE, "Send STARTSTOPUNIT (Expecting SANITIZE_IN_PROGRESS) " - "IMMED:%d PCM:%d PC:%d NO_FLUSH:%d LOEJ:%d START:%d", - immed, pcm, pc, no_flush, loej, start); - - task = iscsi_startstopunit_sync(iscsi, lun, immed, pcm, pc, no_flush, - loej, start); - if (task == NULL) { - logging(LOG_NORMAL, - "[FAILED] Failed to send STARTSTOPUNIT command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, - "[FAILED] STARTSTOPUNIT successful but should have failed with NOT_READY/SANITIZE_IN_PROGRESS"); + ret = check_result("STARTSTOPUNIT", sdev, task, status, key, ascq, + num_ascq); + if (task) { 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_SANITIZE_IN_PROGRESS) { - logging(LOG_NORMAL, "[FAILED] STARTSTOPUNIT Should have failed " - "with NOT_READY/SANITIZE_IN_PROGRESS But failed " - "with %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] STARTSTOPUNIT returned SANITIZE_IN_PROGRESS."); - return 0; + return ret; } int -testunitready(struct iscsi_context *iscsi, int lun) +testunitready(struct scsi_device *sdev, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send TESTUNITREADY"); - task = iscsi_testunitready_sync(iscsi, lun); - if (task == NULL) { - logging(LOG_NORMAL, - "[FAILED] Failed to send TESTUNITREADY command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_TIMEOUT) { - logging(LOG_NORMAL, - "TESTUNITREADY timed out"); + logging(LOG_VERBOSE, "Send TESTUNITREADY (Expecting %s)", + scsi_status_str(status)); + + task = scsi_cdb_testunitready(); + assert(task != NULL); + + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("TESTUNITREADY", sdev, task, status, key, ascq, num_ascq); + if (task) { scsi_free_scsi_task(task); - return -1; } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, - "[FAILED] TESTUNITREADY 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] TESTUNITREADY returned SUCCESS."); - return 0; + return ret; } int -testunitready_clear_ua(struct iscsi_context *iscsi, int lun) +testunitready_clear_ua(struct scsi_device *sdev) { struct scsi_task *task; int ret = -1; logging(LOG_VERBOSE, - "Send TESTUNITREADY (To Clear Possible UA) init=%s", - iscsi->initiator_name); + "Send TESTUNITREADY (To Clear Possible UA) init=%s", + sdev->iscsi_ctx->initiator_name); - task = iscsi_testunitready_sync(iscsi, lun); + task = iscsi_testunitready_sync(sdev->iscsi_ctx, sdev->iscsi_lun); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send TESTUNITREADY command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); goto out; } if (task->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[INFO] TESTUNITREADY command: failed with sense. %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); goto out; } logging(LOG_VERBOSE, "[OK] TESTUNITREADY does not return unit " @@ -1635,678 +1341,191 @@ out: return ret; } -int -testunitready_nomedium(struct iscsi_context *iscsi, int lun) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send TESTUNITREADY (Expecting MEDIUM_NOT_PRESENT)"); - task = iscsi_testunitready_sync(iscsi, lun); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send TESTUNITREADY " - "command: %s", iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] TESTUNITREADY 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] TESTUNITREADY 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] TESTUNITREADY returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -testunitready_sanitize(struct iscsi_context *iscsi, int lun) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send TESTUNITREADY (Expecting SANITIZE_IN_PROGRESS)"); - task = iscsi_testunitready_sync(iscsi, lun); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send TESTUNITREADY " - "command: %s", iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] TESTUNITREADY command successful. But should have failed with NOT_READY/SANITIZE_IN_PROGRESS"); - 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_SANITIZE_IN_PROGRESS) { - logging(LOG_NORMAL, "[FAILED] TESTUNITREADY Should have failed " - "with NOT_READY/SANITIZE_IN_PROGRESS But failed " - "with %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] TESTUNITREADY returned SANITIZE_IN_PROGRESS."); - return 0; -} - -int -testunitready_conflict(struct iscsi_context *iscsi, int lun) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send TESTUNITREADY (Expecting RESERVATION_CONFLICT)"); - task = iscsi_testunitready_sync(iscsi, lun); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send TESTUNITREADY " - "command: %s", iscsi_get_error(iscsi)); - return -1; - } - if (task->status != SCSI_STATUS_RESERVATION_CONFLICT) { - logging(LOG_NORMAL, "[FAILED] Expected RESERVATION CONFLICT"); - return -1; - } - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] TESTUNITREADY returned RESERVATION_CONFLICT."); - return 0; -} - /* * Returns -1 if allocating a SCSI task failed or if a communication error * occurred and a SCSI status if a SCSI response has been received. */ -int mode_sense(struct iscsi_context *iscsi, int lun) +int modesense6(struct scsi_device *sdev, struct scsi_task **out_task, int dbd, enum scsi_modesense_page_control pc, enum scsi_modesense_page_code page_code, int sub_page_code, unsigned char alloc_len, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { - struct scsi_task *t; - enum scsi_status ret = -1; + struct scsi_task *task; + int ret; - t = iscsi_modesense6_sync(iscsi, lun, 0, SCSI_MODESENSE_PC_CURRENT, - SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 255); - if (t) { - ret = t->status; - scsi_free_scsi_task(t); + logging(LOG_VERBOSE, "Send MODESENSE6 (Expecting %s) ", + scsi_status_str(status)); + + task = scsi_cdb_modesense6(dbd, pc, page_code, sub_page_code, alloc_len); + assert(task != NULL); + + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("MODESENSE6", sdev, task, status, key, ascq, num_ascq); + if (out_task) { + *out_task = task; + } else if (task) { + scsi_free_scsi_task(task); } return ret; } -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) +int modeselect6(struct scsi_device *sdev, int pf, int sp, struct scsi_mode_page *mp, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; + struct scsi_data *data; + struct iscsi_data d; - logging(LOG_VERBOSE, "Send COMPARE_AND_WRITE LBA:%" PRIu64 - " LEN:%d WRPROTECT:%d", - lba, len, wrprotect); + logging(LOG_VERBOSE, "Send MODESELECT6 (Expecting %s) ", + scsi_status_str(status)); - 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)); + task = scsi_cdb_modeselect6(pf, sp, 255); + assert(task != NULL); + + data = scsi_modesense_dataout_marshall(task, mp, 1); + if (data == NULL) { + logging(LOG_VERBOSE, "Failed to marshall MODESELECT6 data"); scsi_free_scsi_task(task); return -1; } - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] COMPARE_AND_WRITE returned SUCCESS."); - return 0; + d.data = data->data; + d.size = data->size; + task->cdb[4] = data->size; + task->expxferlen = data->size; + + task = send_scsi_command(sdev, task, &d); + + ret = check_result("MODESELECT6", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } -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) +int compareandwrite(struct scsi_device *sdev, uint64_t lba, + 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 (expecting MISCOMPARE)", - 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 successful " - "but should have failed with MISCOMPARE."); - scsi_free_scsi_task(task); + if (!data_loss) { + printf("--dataloss flag is not set in. Skipping write\n"); 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; - } + task = scsi_cdb_compareandwrite(lba, datalen, blocksize, wrprotect, + dpo, fua, 0, group_number); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] COMPARE_AND_WRITE returned MISCOMPARE."); - return 0; + d.data = data; + d.size = datalen; + task = send_scsi_command(sdev, task, &d); + + ret = check_result("COMPAREANDWRITE", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } -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) +int get_lba_status(struct scsi_device *sdev, struct scsi_task **out_task, uint64_t lba, uint32_t len, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - 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; -} - -struct scsi_task *get_lba_status_task(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send GET_LBA_STATUS LBA:%" PRIu64 " alloc_len:%d", + logging(LOG_VERBOSE, "Send GET_LBA_STATUS (Expecting %s) LBA:%" PRIu64 + " alloc_len:%d", + scsi_status_str(status), lba, len); - task = iscsi_get_lba_status_sync(iscsi, lun, lba, len); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send GET_LBA_STATUS " - "command: %s", - iscsi_get_error(iscsi)); - return NULL; - } - 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] GET_LBA_STATUS is not " - "implemented on target"); + task = scsi_cdb_get_lba_status(lba, len); + assert(task != NULL); + + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("GET_LBA_STATUS", sdev, task, status, key, ascq, num_ascq); + if (out_task) { + *out_task = task; + } else if (task) { scsi_free_scsi_task(task); - return NULL; } - - logging(LOG_VERBOSE, "[OK] GET_LBA_STATUS returned SUCCESS."); - return task; -} - -int get_lba_status(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len, - enum scsi_provisioning_type *provisioning0) -{ - struct scsi_task *task; - struct scsi_get_lba_status *lbas = NULL; - struct scsi_lba_status_descriptor *lbasd = NULL; - - logging(LOG_VERBOSE, "Send GET_LBA_STATUS LBA:%" PRIu64 " alloc_len:%d", - lba, len); - - task = iscsi_get_lba_status_sync(iscsi, lun, lba, len); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send GET_LBA_STATUS " - "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] GET_LBA_STATUS is not " - "implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] GET_LBA_STATUS command: " - "failed with sense. %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - lbas = scsi_datain_unmarshall(task); - if (lbas == NULL) { - logging(LOG_NORMAL, "[FAILED] GET_LBA_STATUS command: " - "failed to unmarschall data."); - scsi_free_scsi_task(task); - return -1; - } - lbasd = &lbas->descriptors[0]; - if (lbasd->lba != lba) { - logging(LOG_NORMAL, "[FAILED] GET_LBA_STATUS command: " - "lba offset in first descriptor does not match request (0x%" PRIx64 " != 0x%" PRIx64 ").", - lbasd->lba, lba); - scsi_free_scsi_task(task); - return -1; - } - if (provisioning0 != NULL) { - *provisioning0 = lbasd->provisioning; - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] GET_LBA_STATUS returned SUCCESS."); - return 0; -} - -int get_lba_status_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send GET_LBA_STATUS (Expecting LBA_OUT_OF_RANGE) LBA:%" PRIu64 " alloc_len:%d", - lba, len); - - task = iscsi_get_lba_status_sync(iscsi, lun, lba, len); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send GET_LBA_STATUS " - "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] GET_LBA_STATUS is not " - "implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] GET_LBA_STATUS returned SUCCESS. 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] GET_LBA_STATUS failed with the wrong sense code. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE 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] GET_LBA_STATUS returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; -} - -int get_lba_status_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send GET_LBA_STATUS (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%" PRIu64 " alloc_len:%d", - lba, len); - - task = iscsi_get_lba_status_sync(iscsi, lun, lba, len); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send GET_LBA_STATUS " - "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] GET_LBA_STATUS is not " - "implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] GET_LBA_STATUS returned SUCCESS. Should have failed with 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] GET_LBA_STATUS failed with the wrong sense code. Should have failed with NOT_READY/MEDIUM_NOT_PRESENT 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] GET_LBA_STATUS returned MEDIUM_NOT_PRESENT."); - return 0; + return ret; } int -prefetch10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num, int immed, int group) +prefetch10(struct scsi_device *sdev, uint32_t lba, int num, int immed, int group, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send PREFETCH10 LBA:%d blocks:%d" - " immed:%d group:%d", - lba, num, immed, group); - - task = iscsi_prefetch10_sync(iscsi, lun, lba, num, immed, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send PREFETCH10 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] PREFETCH10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] PREFETCH10 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] PREFETCH10 returned SUCCESS."); - return 0; -} - -int -prefetch10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, - int num, int immed, int group) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send PREFETCH10 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%d blocks:%d immed:%d group:%d", + logging(LOG_VERBOSE, "Send PREFETCH10 (Expecting %s) LBA:%d blocks:%d" + " immed:%d group:%d", + scsi_status_str(status), lba, num, immed, group); - task = iscsi_prefetch10_sync(iscsi, lun, lba, num, immed, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send PREFETCH10 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] PREFETCH10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] PREFETCH10 returned SUCCESS. 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] PREFETCH10 failed with the wrong sense code. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE but failed with sense:%s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } + task = scsi_cdb_prefetch10(lba, num, immed, group); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] PREFETCH10 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("PREFETCH10", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -prefetch10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, - int num, int immed, int group) +prefetch16(struct scsi_device *sdev, uint64_t lba, int num, int immed, int group, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send PREFETCH10 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%d blocks:%d immed:%d group:%d", + logging(LOG_VERBOSE, "Send PREFETCH16 (Expecting %s) LBA:%" PRIu64 + " blocks:%d immed:%d group:%d", + scsi_status_str(status), lba, num, immed, group); - task = iscsi_prefetch10_sync(iscsi, lun, lba, num, immed, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send PREFETCH10 command: %s", - iscsi_get_error(iscsi)); - return -1; - 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] PREFETCH10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] PREFETCH10 returned SUCCESS. 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] PREFETCH10 failed with the wrong sense code. Should have failed with NOT_READY/MEDIUM_NOT_PRESENT but failed with sense:%s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } + task = scsi_cdb_prefetch16(lba, num, immed, group); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] PREFETCH10 returned MEDIUM_NOT_PRESENT."); - return 0; + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("PREFETCH16", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -prefetch16(struct iscsi_context *iscsi, int lun, uint64_t lba, int num, int immed, int group) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send PREFETCH16 LBA:%" PRIu64 " blocks:%d" - " immed:%d group:%d", - lba, num, immed, group); - - task = iscsi_prefetch16_sync(iscsi, lun, lba, num, immed, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send PREFETCH16 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] PREFETCH16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] PREFETCH16 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] PREFETCH16 returned SUCCESS."); - return 0; -} - -int -prefetch16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, - int num, int immed, int group) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send PREFETCH16 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%" PRIu64 " blocks:%d immed:%d group:%d", - lba, num, immed, group); - - task = iscsi_prefetch16_sync(iscsi, lun, lba, num, immed, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send PREFETCH16 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] PREFETCH16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] PREFETCH16 returned SUCCESS. 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] PREFETCH16 failed with the wrong sense code. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE 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] PREFETCH16 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; -} - -int -prefetch16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, - int num, int immed, int group) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send PREFETCH16 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%" PRIu64 " blocks:%d immed:%d group:%d", - lba, num, immed, group); - - task = iscsi_prefetch16_sync(iscsi, lun, lba, num, immed, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send PREFETCH16 command: %s", - iscsi_get_error(iscsi)); - return -1; - 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] PREFETCH16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] PREFETCH16 returned SUCCESS. 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] PREFETCH16 failed with the wrong sense code. Should have failed with NOT_READY/MEDIUM_NOT_PRESENT 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] PREFETCH16 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -preventallow(struct iscsi_context *iscsi, int lun, int prevent) +preventallow(struct scsi_device *sdev, int prevent) { struct scsi_task *task; logging(LOG_VERBOSE, "Send PREVENTALLOW prevent:%d", prevent); - task = iscsi_preventallow_sync(iscsi, lun, prevent); + task = iscsi_preventallow_sync(sdev->iscsi_ctx, sdev->iscsi_lun, prevent); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send PREVENTALLOW " - "command: %s", iscsi_get_error(iscsi)); + "command: %s", iscsi_get_error(sdev->iscsi_ctx)); 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) { + if (status_is_invalid_opcode(task)) { logging(LOG_NORMAL, "[SKIPPED] PREVENTALLOW is not implemented on target"); scsi_free_scsi_task(task); return -2; } if (task->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[FAILED] PREVENTALLOW command: " - "failed with sense. %s", iscsi_get_error(iscsi)); + "failed with sense. %s", iscsi_get_error(sdev->iscsi_ctx)); scsi_free_scsi_task(task); return -1; } @@ -2317,945 +1536,184 @@ preventallow(struct iscsi_context *iscsi, int lun, int prevent) } int -read6(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, - unsigned char *data) +read6(struct scsi_device *sdev, struct scsi_task **out_task, uint32_t lba, + uint32_t datalen, int blocksize, + unsigned char *data, + int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send READ6 LBA:%d blocks:%d", + logging(LOG_VERBOSE, "Send READ6 (Expecting %s) LBA:%d blocks:%d", + scsi_status_str(status), lba, datalen / blocksize); - task = iscsi_read6_sync(iscsi, lun, lba, datalen, blocksize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ6 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] READ6 is not implemented."); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ6 command: " - "failed with sense. %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } + task = scsi_cdb_read6(lba, datalen, blocksize); + assert(task != NULL); - if (data != NULL) { + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("READ6", sdev, task, status, key, ascq, num_ascq); + if (data && task) { memcpy(data, task->datain.data, task->datain.size); } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ6 returned SUCCESS."); - return 0; + if (out_task) { + *out_task = task; + } else if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -read6_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send READ6 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%d blocks:%d", - lba, datalen / blocksize); - - task = iscsi_read6_sync(iscsi, lun, lba, datalen, blocksize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ6 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] READ6 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ6 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] READ6 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; - } - - if (data != NULL) { - memcpy(data, task->datain.data, task->datain.size); - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ6 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; -} - -struct scsi_task* -read10_task(struct iscsi_context *iscsi, int lun, uint32_t lba, +read10(struct scsi_device *sdev, struct scsi_task **out_task, + uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, - unsigned char *data) + unsigned char *data, + int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send READ10 LBA:%d blocks:%d rdprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", - lba, datalen / blocksize, rdprotect, - dpo, fua, fua_nv, group); - - task = iscsi_read10_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ10 command: %s", - iscsi_get_error(iscsi)); - return NULL; - } - - if (data != NULL) { - memcpy(data, task->datain.data, task->datain.size); - } - - logging(LOG_VERBOSE, "[OK] READ10 returned SUCCESS."); - return task; -} - -int -read10(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int rdprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send READ10 LBA:%d blocks:%d rdprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", - lba, datalen / blocksize, rdprotect, - dpo, fua, fua_nv, group); - - task = iscsi_read10_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ10 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ10 command: " - "failed with sense. %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - if (data != NULL) { - memcpy(data, task->datain.data, task->datain.size); - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ10 returned SUCCESS."); - return 0; -} - -int -read10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int rdprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send READ10 (Expecting INVALID_FIELD_IN_CDB) " - "LBA:%d blocks:%d rdprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", + logging(LOG_VERBOSE, "Send READ10 (Expecting %s) LBA:%d" + " blocks:%d rdprotect:%d dpo:%d fua:%d fua_nv:%d group:%d", + scsi_status_str(status), lba, datalen / blocksize, rdprotect, dpo, fua, fua_nv, group); - task = iscsi_read10_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ10 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ10 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] READ10 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; - } + task = scsi_cdb_read10(lba, datalen, blocksize, rdprotect, + dpo, fua, fua_nv, group); + assert(task != NULL); - if (data != NULL) { + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("READ10", sdev, task, status, key, ascq, num_ascq); + if (data && task) { memcpy(data, task->datain.data, task->datain.size); } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ10 returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB."); - return 0; + if (out_task) { + *out_task = task; + } else if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -read10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, +read12(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, - unsigned char *data) + unsigned char *data, + int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send READ10 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%d blocks:%d rdprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", + logging(LOG_VERBOSE, "Send READ12 (Expecting %s) LBA:%d" + " blocks:%d rdprotect:%d dpo:%d fua:%d fua_nv:%d group:%d", + scsi_status_str(status), lba, datalen / blocksize, rdprotect, dpo, fua, fua_nv, group); - task = iscsi_read10_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ10 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ10 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] READ10 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; - } + task = scsi_cdb_read12(lba, datalen, blocksize, rdprotect, + dpo, fua, fua_nv, group); + assert(task != NULL); - if (data != NULL) { + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("READ12", sdev, task, status, key, ascq, num_ascq); + if (data && task) { memcpy(data, task->datain.data, task->datain.size); } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ10 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -read10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int rdprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send READ10 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%d blocks:%d rdprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", - lba, datalen / blocksize, rdprotect, - dpo, fua, fua_nv, group); - - task = iscsi_read10_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ10 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ10 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] READ10 Should have failed " - "with NOT_READY/MEDIUM_NOT_PRESENT* But failed " - "with %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - if (data != NULL) { - memcpy(data, task->datain.data, task->datain.size); - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ10 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -read12(struct iscsi_context *iscsi, int lun, uint32_t lba, +read16(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, - unsigned char *data) + unsigned char *data, + int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send READ12 LBA:%d blocks:%d rdprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", - lba, datalen / blocksize, rdprotect, - dpo, fua, fua_nv, group); - - task = iscsi_read12_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ12 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] READ12 is not implemented."); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ12 command: " - "failed with sense. %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - if (data != NULL) { - memcpy(data, task->datain.data, task->datain.size); - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ12 returned SUCCESS."); - return 0; -} - -int -read12_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int rdprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send READ12 (Expecting INVALID_FIELD_IN_CDB) " - "LBA:%d blocks:%d rdprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", + logging(LOG_VERBOSE, "Send READ16 (Expecting %s) LBA:%" PRIu64 + " blocks:%d rdprotect:%d dpo:%d fua:%d fua_nv:%d group:%d", + scsi_status_str(status), lba, datalen / blocksize, rdprotect, dpo, fua, fua_nv, group); - task = iscsi_read12_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ12 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] READ12 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ12 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] READ12 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; - } + task = scsi_cdb_read16(lba, datalen, blocksize, rdprotect, + dpo, fua, fua_nv, group); + assert(task != NULL); - if (data != NULL) { + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("READ16", sdev, task, status, key, ascq, num_ascq); + if (data && task) { memcpy(data, task->datain.data, task->datain.size); } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ12 returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB."); - return 0; + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -read12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int rdprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) +readcapacity10(struct scsi_device *sdev, struct scsi_task **out_task, uint32_t lba, int pmi, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send READ12 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%d blocks:%d rdprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", - lba, datalen / blocksize, rdprotect, - dpo, fua, fua_nv, group); - - task = iscsi_read12_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ12 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] READ12 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ12 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] READ12 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; - } - - if (data != NULL) { - memcpy(data, task->datain.data, task->datain.size); - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ12 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; -} - -int -read12_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int rdprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send READ12 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%d blocks:%d rdprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", - lba, datalen / blocksize, rdprotect, - dpo, fua, fua_nv, group); - - task = iscsi_read12_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ12 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] READ12 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ12 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] READ12 Should have failed " - "with NOT_READY/MEDIUM_NOT_PRESENT* But failed " - "with %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - if (data != NULL) { - memcpy(data, task->datain.data, task->datain.size); - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ12 returned MEDIUM_NOT_PRESENT*."); - return 0; -} - -int -read16(struct iscsi_context *iscsi, int lun, uint64_t lba, - uint32_t datalen, int blocksize, int rdprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send READ16 LBA:%" PRId64 " blocks:%d " - "rdprotect:%d dpo:%d fua:%d fua_nv:%d group:%d", - lba, datalen / blocksize, rdprotect, - dpo, fua, fua_nv, group); - - task = iscsi_read16_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ16 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); - if (sbc3_support) { - logging(LOG_NORMAL, "[FAILED] READ16 is not available but the device claims SBC-3 support."); - return -1; - } else { - logging(LOG_NORMAL, "[SKIPPED] READ16 is not implemented and SBC-3 is not claimed."); - return -2; - } - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ16 command: " - "failed with sense. %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - if (data != NULL) { - memcpy(data, task->datain.data, task->datain.size); - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ16 returned SUCCESS."); - return 0; -} - -int -read16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba, - uint32_t datalen, int blocksize, int rdprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send READ16 (Expecting INVALID_FIELD_IN_CDB) " - "LBA:%" PRId64 " blocks:%d rdprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", - lba, datalen / blocksize, rdprotect, - dpo, fua, fua_nv, group); - - task = iscsi_read16_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ16 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); - if (sbc3_support) { - logging(LOG_NORMAL, "[FAILED] READ16 is not available but the device claims SBC-3 support."); - return -1; - } else { - logging(LOG_NORMAL, "[SKIPPED] READ16 is not implemented and SBC-3 is not claimed."); - return -2; - } - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ16 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] READ16 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; - } - - if (data != NULL) { - memcpy(data, task->datain.data, task->datain.size); - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ16 returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB."); - return 0; -} - -int -read16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, - uint32_t datalen, int blocksize, int rdprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send READ16 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%" PRId64 " blocks:%d rdprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", - lba, datalen / blocksize, rdprotect, - dpo, fua, fua_nv, group); - - task = iscsi_read16_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ16 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); - if (sbc3_support) { - logging(LOG_NORMAL, "[FAILED] READ16 is not available but the device claims SBC-3 support."); - return -1; - } else { - logging(LOG_NORMAL, "[SKIPPED] READ16 is not implemented and SBC-3 is not claimed."); - return -2; - } - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ16 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] READ16 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; - } - - if (data != NULL) { - memcpy(data, task->datain.data, task->datain.size); - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ16 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; -} - -int -read16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, - uint32_t datalen, int blocksize, int rdprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send READ16 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%" PRId64 " blocks:%d rdprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", - lba, datalen / blocksize, rdprotect, - dpo, fua, fua_nv, group); - - task = iscsi_read16_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ16 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); - if (sbc3_support) { - logging(LOG_NORMAL, "[FAILED] READ16 is not available but the device claims SBC-3 support."); - return -1; - } else { - logging(LOG_NORMAL, "[SKIPPED] READ16 is not implemented and SBC-3 is not claimed."); - return -2; - } - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ16 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] READ16 Should have failed " - "with NOT_READY/MEDIUM_NOT_PRESENT* But failed " - "with %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - if (data != NULL) { - memcpy(data, task->datain.data, task->datain.size); - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ16 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -read16_sanitize(struct iscsi_context *iscsi, int lun, uint64_t lba, - uint32_t datalen, int blocksize, int rdprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send READ16 (Expecting SANITIZE_IN_PROGRESS) " - "LBA:%" PRId64 " blocks:%d rdprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", - lba, datalen / blocksize, rdprotect, - dpo, fua, fua_nv, group); - - task = iscsi_read16_sync(iscsi, lun, lba, datalen, blocksize, - rdprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READ16 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READ16 successful but should " - "have failed with NOT_READY/SANITIZE_IN_PROGRESS"); - 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_SANITIZE_IN_PROGRESS) { - logging(LOG_NORMAL, "[FAILED] READ16 Should have failed " - "with NOT_READY/SANITIZE_IN_PROGRESS But failed " - "with %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - if (data != NULL) { - memcpy(data, task->datain.data, task->datain.size); - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READ16 returned SANITIZE_IN_PROGRESS"); - return 0; -} - -int -readcapacity10(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send READCAPACITY10 LBA:%d pmi:%d", + logging(LOG_VERBOSE, "Send READCAPACITY10 (Expecting %s) LBA:%d" + " pmi:%d", + scsi_status_str(status), lba, pmi); - task = iscsi_readcapacity10_sync(iscsi, lun, lba, pmi); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READCAPACITY10 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READCAPACITY10 command: " - "failed with sense. %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } + task = scsi_cdb_readcapacity10(lba, pmi); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READCAPACITY10 returned SUCCESS."); - return 0; + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("READCAPACITY10", sdev, task, status, key, ascq, num_ascq); + if (out_task) { + *out_task = task; + } else if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -readcapacity10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi) +readcapacity16(struct scsi_device *sdev, struct scsi_task **out_task, int alloc_len, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send READCAPACITY10 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%d pmi:%d", - lba, pmi); - - task = iscsi_readcapacity10_sync(iscsi, lun, lba, pmi); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READCAPACITY10 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READCAPACITY10 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] READCAPACITY10 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] READCAPACITY10 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -readcapacity16(struct iscsi_context *iscsi, int lun, int alloc_len) -{ - struct scsi_task *task; - - - logging(LOG_VERBOSE, "Send READCAPACITY16 alloc_len:%d", alloc_len); + logging(LOG_VERBOSE, "Send READCAPACITY16 (Expecting %s)", + scsi_status_str(status)); task = scsi_cdb_serviceactionin16(SCSI_READCAPACITY16, alloc_len); - if (task == NULL) { - logging(LOG_NORMAL, "Out-of-memory: Failed to create " - "READCAPACITY16 cdb."); - return -1; - } - task = iscsi_scsi_command_sync(iscsi, lun, task, NULL); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READCAPACITY16 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); - if (inq->protect) { - logging(LOG_NORMAL, "[FAILED] READCAPACITY16 is not " - "available but INQ->PROTECT is set. " - "ReadCapacity16 is mandatory when INQ->PROTECT " - "is set."); - return -1; - } - if (sbc3_support) { - logging(LOG_NORMAL, "[FAILED] READCAPACITY16 is not available but the device claims SBC-3 support."); - return -1; - } else { - logging(LOG_NORMAL, "[SKIPPED] READCAPACITY16 is not implemented and SBC-3 is not claimed."); - return -2; - } - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READCAPACITY16 command: " - "failed with sense. %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] READCAPACITY16 returned SUCCESS."); - return 0; + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("READCAPACITY16", sdev, task, status, key, ascq, num_ascq); + if (out_task) { + *out_task = task; + } else if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -readcapacity16_nomedium(struct iscsi_context *iscsi, int lun, int alloc_len) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send READCAPACITY16 (Expecting MEDIUM_NOT_PRESENT) " - "alloc_len:%d", alloc_len); - - task = scsi_cdb_serviceactionin16(SCSI_READCAPACITY16, alloc_len); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READCAPACITY16 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - task = iscsi_scsi_command_sync(iscsi, lun, task, NULL); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send READCAPACITY16 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); - if (sbc3_support) { - logging(LOG_NORMAL, "[FAILED] READCAPACITY16 is not available but the device claims SBC-3 support."); - return -1; - } else { - logging(LOG_NORMAL, "[SKIPPED] READCAPACITY16 is not implemented and SBC-3 is not claimed."); - return -2; - } - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] READCAPACITY16 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] READCAPACITY16 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] READCAPACITY16 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -release6(struct iscsi_context *iscsi, int lun) +release6(struct scsi_device *sdev) { struct scsi_task *task; int i, res = 0; @@ -3263,11 +1721,11 @@ release6(struct iscsi_context *iscsi, int lun) logging(LOG_VERBOSE, "Send RELEASE6"); for (i = 0; i < 3 && res == 0; ++i) { - task = iscsi_release6_sync(iscsi, lun); + task = iscsi_release6_sync(sdev->iscsi_ctx, sdev->iscsi_lun); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send RELEASE6 command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); res = -1; break; } @@ -3277,7 +1735,7 @@ release6(struct iscsi_context *iscsi, int lun) && task->sense.ascq == SCSI_SENSE_ASCQ_BUS_RESET)) { logging(LOG_NORMAL, "[FAILED] RELEASE6 command: " "failed with sense. %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); res = -1; } scsi_free_scsi_task(task); @@ -3288,93 +1746,33 @@ release6(struct iscsi_context *iscsi, int lun) return res; } -int report_supported_opcodes(struct iscsi_context *iscsi, int lun, int rctd, int options, int opcode, int sa, int alloc_len, struct scsi_task **save_task) +int report_supported_opcodes(struct scsi_device *sdev, struct scsi_task **out_task, int rctd, int options, int opcode, int sa, int alloc_len, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + int ret; - logging(LOG_VERBOSE, "Send REPORT_SUPPORTED_OPCODE RCTD:%d OPTIONS:%d " - "OPCODE:0x%02x SA:%d ALLOC_LEN:%d", + logging(LOG_VERBOSE, "Send REPORT_SUPPORTED_OPCODE (Expecting %s) " + "RCTD:%d OPTIONS:%d OPCODE:0x%02x SA:%d ALLOC_LEN:%d", + scsi_status_str(status), rctd, options, opcode, sa, alloc_len); - task = iscsi_report_supported_opcodes_sync(iscsi, lun, - rctd, options, opcode, sa, alloc_len); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send " - "REPORT_SUPPORTED_OPCODES 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] REPORT_SUPPORTED_OPCODES is not " - "implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] REPORT_SUPPORTED_OPCODES " - "command: failed with sense. %s", - iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } + task = scsi_cdb_report_supported_opcodes(rctd, options, opcode, sa, + alloc_len); + assert(task != NULL); - if (save_task != NULL) { - *save_task = task; - } else { + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("REPORT_SUPPORTED_OPCODES", sdev, task, status, key, ascq, num_ascq); + if (out_task) { + *out_task = task; + } else if (task) { scsi_free_scsi_task(task); } - - logging(LOG_VERBOSE, "[OK] REPORT_SUPPORTED_OPCODES returned SUCCESS."); - return 0; -} - -int report_supported_opcodes_invalidfieldincdb(struct iscsi_context *iscsi, int lun, int rctd, int options, int opcode, int sa, int alloc_len, struct scsi_task **save_task) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send REPORT_SUPPORTED_OPCODE (expecting INVALID_FIELD_IN_CDB) RCTD:%d OPTIONS:%d " - "OPCODE:0x%02x SA:%d ALLOC_LEN:%d", - rctd, options, opcode, sa, alloc_len); - - task = iscsi_report_supported_opcodes_sync(iscsi, lun, - rctd, options, opcode, sa, alloc_len); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send " - "REPORT_SUPPORTED_OPCODES 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] REPORT_SUPPORTED_OPCODES is not " - "implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - 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] REPORT_SUPPORTED_OPCODES should have failed with ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB. Sense:%s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - if (save_task != NULL) { - *save_task = task; - } else { - scsi_free_scsi_task(task); - } - - logging(LOG_VERBOSE, "[OK] REPORT_SUPPORTED_OPCODES returned " - "INVALID_FIELD_IN_CDB."); - return 0; + return ret; } int -reserve6(struct iscsi_context *iscsi, int lun) +reserve6(struct scsi_device *sdev) { struct scsi_task *task; int i, res = 0; @@ -3382,17 +1780,15 @@ reserve6(struct iscsi_context *iscsi, int lun) logging(LOG_VERBOSE, "Send RESERVE6"); for (i = 0; i < 3 && res == 0; ++i) { - task = iscsi_reserve6_sync(iscsi, lun); + task = iscsi_reserve6_sync(sdev->iscsi_ctx, sdev->iscsi_lun); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send RESERVE6 command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); res = -1; break; } - if (task->status == SCSI_STATUS_CHECK_CONDITION - && task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST - && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { + if (status_is_invalid_opcode(task)) { logging(LOG_NORMAL, "[SKIPPED] RESERVE6 is not " "implemented on target"); res = -2; @@ -3402,7 +1798,7 @@ reserve6(struct iscsi_context *iscsi, int lun) && task->sense.ascq == SCSI_SENSE_ASCQ_BUS_RESET)) { logging(LOG_NORMAL, "[FAILED] RESERVE6 command: " "failed with sense. %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); res = -1; } scsi_free_scsi_task(task); @@ -3414,7 +1810,7 @@ reserve6(struct iscsi_context *iscsi, int lun) } int -reserve6_conflict(struct iscsi_context *iscsi, int lun) +reserve6_conflict(struct scsi_device *sdev) { struct scsi_task *task; int i, res = 0; @@ -3422,17 +1818,15 @@ reserve6_conflict(struct iscsi_context *iscsi, int lun) logging(LOG_VERBOSE, "Send RESERVE6 (Expecting RESERVATION_CONFLICT)"); for (i = 0; i < 3 && res == 0; ++i) { - task = iscsi_reserve6_sync(iscsi, lun); + task = iscsi_reserve6_sync(sdev->iscsi_ctx, sdev->iscsi_lun); if (task == NULL) { logging(LOG_NORMAL, "[FAILED] Failed to send RESERVE6 command: %s", - iscsi_get_error(iscsi)); + iscsi_get_error(sdev->iscsi_ctx)); res = -1; break; } - if (task->status == SCSI_STATUS_CHECK_CONDITION - && task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST - && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { + if (status_is_invalid_opcode(task)) { logging(LOG_NORMAL, "[SKIPPED] RESERVE6 is not" " implemented on target"); res = -2; @@ -3454,748 +1848,146 @@ reserve6_conflict(struct iscsi_context *iscsi, int lun) } int -unmap(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len) +unmap(struct scsi_device *sdev, int anchor, struct unmap_list *list, int list_len, int status, enum scsi_sense_key key, int *ascq, int num_ascq) { struct scsi_task *task; + unsigned char *data; + struct iscsi_data d; + int xferlen; + int i; + int ret; - logging(LOG_VERBOSE, "Send UNMAP list_len:%d anchor:%d", list_len, anchor); - task = iscsi_unmap_sync(iscsi, lun, anchor, 0, list, list_len); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send UNMAP command: %s", - iscsi_get_error(iscsi)); + logging(LOG_VERBOSE, "Send UNMAP (Expecting %s) list_len:%d anchor:%d", + scsi_status_str(status), + list_len, anchor); + + if (!data_loss) { + printf("--dataloss flag is not set in. Skipping unmap\n"); 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] UNMAP is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] UNMAP command: failed with sense. %s", iscsi_get_error(iscsi)); + + xferlen = 8 + list_len * 16; + + task = scsi_cdb_unmap(anchor, 0, xferlen); + assert(task != NULL); + + data = scsi_malloc(task, xferlen); + if (data == NULL) { + logging(LOG_NORMAL, "Out-of-memory: Failed to create " + "unmap parameters."); scsi_free_scsi_task(task); return -1; } - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] UNMAP returned SUCCESS."); - return 0; + scsi_set_uint16(&data[0], xferlen - 2); + scsi_set_uint16(&data[2], xferlen - 8); + for (i = 0; i < list_len; i++) { + scsi_set_uint32(&data[8 + 16 * i], list[i].lba >> 32); + scsi_set_uint32(&data[8 + 16 * i + 4], list[i].lba & 0xffffffff); + scsi_set_uint32(&data[8 + 16 * i + 8], list[i].num); + } + + d.data = data; + d.size = xferlen; + + task = send_scsi_command(sdev, task, &d); + + ret = check_result("UNMAP", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -unmap_writeprotected(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len) +verify10(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, 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 UNMAP (Expecting WRITE_PROTECTED) " - "list_len:%d anchor:%d", list_len, anchor); - - task = iscsi_unmap_sync(iscsi, lun, anchor, 0, list, list_len); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send UNMAP 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] UNMAP is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] UNMAP 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] UNMAP 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] UNMAP returned DATA_PROTECTION/WRITE_PROTECTED."); - return 0; -} - -int -unmap_nomedium(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send UNMAP (Expecting MEDIUM_NOT_PRESENT) " - "list_len:%d anchor:%d", list_len, anchor); - - task = iscsi_unmap_sync(iscsi, lun, anchor, 0, list, list_len); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send UNMAP 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] UNMAP is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] UNMAP 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] UNMAP 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] UNMAP returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -verify10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send VERIFY10 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d", lba, datalen / blocksize, vprotect, dpo, bytchk); - task = iscsi_verify10_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY10 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] VERIFY10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY10 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] VERIFY10 returned SUCCESS."); - return 0; -} - -int -verify10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send VERIFY10 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d", + logging(LOG_VERBOSE, "Send VERIFY10 (Expecting %s) LBA:%d " + "blocks:%d vprotect:%d dpo:%d bytchk:%d", + scsi_status_str(status), lba, datalen / blocksize, vprotect, dpo, bytchk); - task = iscsi_verify10_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY10 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] VERIFY10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY10 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] VERIFY10 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT* but failed with %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } + task = scsi_cdb_verify10(lba, datalen, vprotect, dpo, bytchk, blocksize); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] VERIFY10 returned MEDIUM_NOT_PRESENT."); - return 0; + d.data = data; + d.size = datalen; + task = send_scsi_command(sdev, task, &d); + + ret = check_result("VERIFY10", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -verify10_miscompare(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) +verify12(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, 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 VERIFY10 (Expecting MISCOMPARE) " - "LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d", + logging(LOG_VERBOSE, "Send VERIFY12 (Expecting %s) LBA:%d " + "blocks:%d vprotect:%d dpo:%d bytchk:%d", + scsi_status_str(status), lba, datalen / blocksize, vprotect, dpo, bytchk); - task = iscsi_verify10_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY10 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] VERIFY10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY10 successful but should have failed with MISCOMPARE"); - scsi_free_scsi_task(task); - return -1; - } - if (task->sense.key != SCSI_SENSE_MISCOMPARE) { - logging(LOG_NORMAL, "[FAILED] VERIFY10 command returned wrong sense key. MISCOMPARE MISCOMPARE 0x%x expected but got key 0x%x. Sense:%s", SCSI_SENSE_MISCOMPARE, task->sense.key, iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } + task = scsi_cdb_verify12(lba, datalen, vprotect, dpo, bytchk, blocksize); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] VERIFY10 returned MISCOMPARE."); - return 0; + d.data = data; + d.size = datalen; + task = send_scsi_command(sdev, task, &d); + + ret = check_result("VERIFY12", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -verify10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) +verify16(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, 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 VERIFY10 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d", + logging(LOG_VERBOSE, "Send VERIFY16 (Expecting %s) LBA:%" PRIu64 + " blocks:%d vprotect:%d dpo:%d bytchk:%d", + scsi_status_str(status), lba, datalen / blocksize, vprotect, dpo, bytchk); - task = iscsi_verify10_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY10 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] VERIFY10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY10 successful but should have failed with 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] VERIFY10 should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } + task = scsi_cdb_verify16(lba, datalen, vprotect, dpo, bytchk, blocksize); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] VERIFY10 returned LBA_OUT_OF_RANGE."); - return 0; + d.data = data; + d.size = datalen; + task = send_scsi_command(sdev, task, &d); + + ret = check_result("VERIFY16", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -verify10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) +write10(struct scsi_device *sdev, uint32_t lba, 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 VERIFY10 (Expecting INVALID_FIELD_IN_CDB) " - "LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d", - lba, datalen / blocksize, vprotect, dpo, bytchk); - - task = iscsi_verify10_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY10 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] VERIFY10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY10 successful but should have failed with ILLEGAL_REQUEST"); - 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] VERIFY10 should have failed with ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB. Sense:%s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] VERIFY10 returned INVALID_FIELD_IN_CDB."); - return 0; -} - -int -verify12(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send VERIFY12 LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d", lba, datalen / blocksize, vprotect, dpo, bytchk); - task = iscsi_verify12_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY12 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] VERIFY12 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY12 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] VERIFY12 returned SUCCESS."); - return 0; -} - -int -verify12_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send VERIFY12 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d", - lba, datalen / blocksize, vprotect, dpo, bytchk); - - task = iscsi_verify12_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY12 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] VERIFY12 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY12 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] VERIFY12 after eject failed with the wrong sense code. Should fail 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] VERIFY12 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -verify12_miscompare(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send VERIFY12 (expecting MISCOMPARE) " - "LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d", - lba, datalen / blocksize, vprotect, dpo, bytchk); - - task = iscsi_verify12_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY12 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] VERIFY12 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY12 successful but should have failed with MISCOMPARE"); - scsi_free_scsi_task(task); - return -1; - } - if (task->sense.key != SCSI_SENSE_MISCOMPARE) { - logging(LOG_NORMAL, "[FAILED] VERIFY12 command returned wrong sense key. MISCOMPARE MISCOMPARE 0x%x expected but got key 0x%x. Sense:%s", SCSI_SENSE_MISCOMPARE, task->sense.key, iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] VERIFY12 returned MISCOMPARE."); - return 0; -} - -int -verify12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send VERIFY12 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d", - lba, datalen / blocksize, vprotect, dpo, bytchk); - - task = iscsi_verify12_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY12 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] VERIFY12 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY12 successful but should have failed with 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] VERIFY12 should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] VERIFY12 returned LBA_OUT_OF_RANGE."); - return 0; -} - -int -verify12_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send VERIFY12 (Expecting INVALID_FIELD_IN_CDB) " - "LBA:%d blocks:%d vprotect:%d dpo:%d bytchk:%d", - lba, datalen / blocksize, vprotect, dpo, bytchk); - - task = iscsi_verify12_sync(iscsi, lun, data, datalen, lba, vprotect, dpo, bytchk, blocksize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY12 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] VERIFY12 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY12 successful but should have failed with ILLEGAL_REQUEST"); - 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] VERIFY12 should have failed with ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB. Sense:%s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] VERIFY12 returned INVALID_FIELD_IN_CDB."); - return 0; -} - -int -verify16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "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) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY16 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] VERIFY16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY16 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] VERIFY16 returned SUCCESS."); - return 0; -} - -int -verify16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send VERIFY16 (Expecting MEDIUM_NOT_PRESENT) " - "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) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY16 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] VERIFY16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY16 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] VERIFY16 after eject failed with the wrong sense code. Should fail 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] VERIFY16 returned NOT_MEDIUM_NOT_PRESENT."); - return 0; -} - -int -verify16_miscompare(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send VERIFY16 (Expecting MISCOMPARE) " - "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) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY16 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] VERIFY16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY16 successful but should have failed with MISCOMPARE"); - scsi_free_scsi_task(task); - return -1; - } - if (task->sense.key != SCSI_SENSE_MISCOMPARE) { - logging(LOG_NORMAL, "[FAILED] VERIFY16 command returned wrong sense key. MISCOMPARE MISCOMPARE 0x%x expected but got key 0x%x. Sense:%s", SCSI_SENSE_MISCOMPARE, task->sense.key, iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] VERIFY16 returned MISCOMPARE."); - return 0; -} - -int -verify16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send VERIFY16 (Expecting LBA_OUT_OF_RANGE) " - "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) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY16 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] VERIFY16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY16 successful but should have failed with 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] VERIFY16 should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] VERIFY16 returned LBA_OUT_OF_RANGE."); - return 0; -} - -int -verify16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send VERIFY16 (Expecting INVALID_FIELD_IN_CDB) " - "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) { - logging(LOG_NORMAL, "[FAILED] Failed to send VERIFY16 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] VERIFY16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] VERIFY16 successful but should have failed with 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_INVALID_FIELD_IN_CDB) { - logging(LOG_NORMAL, "[FAILED] VERIFY16 should have failed with ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB. Sense:%s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] VERIFY16 returned INVALID_FIELD_IN_CDB."); - return 0; -} - -int -write10(struct iscsi_context *iscsi, int lun, uint32_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 WRITE10 LBA:%d blocks:%d " + logging(LOG_VERBOSE, "Send WRITE10 (Expecting %s) LBA:%d 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_write10_sync(iscsi, lun, lba, - data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE10 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] WRITE10 is not implemented."); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE10 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] WRITE10 returned SUCCESS."); - return 0; -} - -int -write10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_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 WRITE10 (Expecting INVALID_FIELD_IN_CDB) " - "LBA:%d 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); @@ -4204,263 +1996,31 @@ write10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, return -1; } - task = iscsi_write10_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE10 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] WRITE10 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE10 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] WRITE10 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; - } + task = scsi_cdb_write10(lba, datalen, blocksize, wrprotect, + dpo, fua, fua_nv, group); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] WRITE10 returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB."); - return 0; + d.data = data; + d.size = datalen; + task = send_scsi_command(sdev, task, &d); + + ret = check_result("WRITE10", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -write10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) +write12(struct scsi_device *sdev, uint32_t lba, 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 WRITE10 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%d 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_write10_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE10 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] WRITE10 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE10 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] WRITE10 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] WRITE10 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; -} - -int -write10_writeprotected(struct iscsi_context *iscsi, int lun, uint32_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 WRITE10 (Expecting WRITE_PROTECTED) " - "LBA:%d 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_write10_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE10 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] WRITE10 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE10 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] WRITE10 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] WRITE10 returned DATA_PROTECTION/WRITE_PROTECTED."); - return 0; -} - -int -write10_nomedium(struct iscsi_context *iscsi, int lun, uint32_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 WRITE10 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%d 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_write10_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE10 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] WRITE10 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE10 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] WRITE10 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] WRITE10 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -write12(struct iscsi_context *iscsi, int lun, uint32_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 WRITE12 LBA:%d blocks:%d " + logging(LOG_VERBOSE, "Send WRITE12 (Expecting %s) LBA:%d 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_write12_sync(iscsi, lun, lba, - data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE12 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] WRITE12 is not implemented."); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE12 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] WRITE12 returned SUCCESS."); - return 0; -} - -int -write12_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_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 WRITE12 (Expecting INVALID_FIELD_IN_CDB) " - "LBA:%d 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); @@ -4469,53 +2029,31 @@ write12_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, return -1; } - task = iscsi_write12_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE12 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] WRITE12 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE12 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] WRITE12 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; - } + task = scsi_cdb_write12(lba, datalen, blocksize, wrprotect, + dpo, fua, fua_nv, group); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] WRITE12 returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB."); - return 0; + d.data = data; + d.size = datalen; + task = send_scsi_command(sdev, task, &d); + + ret = check_result("WRITE12", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -write12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) +write16(struct scsi_device *sdev, uint64_t lba, 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 WRITE12 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%d blocks:%d wrprotect:%d " - "dpo:%d fua:%d fua_nv:%d group:%d", + logging(LOG_VERBOSE, "Send WRITE16 (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); @@ -4524,1822 +2062,230 @@ write12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, return -1; } - task = iscsi_write12_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE12 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] WRITE12 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE12 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] WRITE12 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; - } + task = scsi_cdb_write16(lba, datalen, blocksize, wrprotect, + dpo, fua, fua_nv, group); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] WRITE12 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; + d.data = data; + d.size = datalen; + task = send_scsi_command(sdev, task, &d); + + ret = check_result("WRITE16", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -write12_writeprotected(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int fua, int fua_nv, int group, - unsigned char *data) +writesame10(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, 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 WRITE12 (Expecting WRITE_PROTECTED) " - "LBA:%d 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_write12_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE12 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] WRITE12 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE12 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] WRITE12 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] WRITE12 returned DATA_PROTECTION/WRITE_PROTECTED."); - return 0; -} - -int -write12_nomedium(struct iscsi_context *iscsi, int lun, uint32_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 WRITE12 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%d 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_write12_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE12 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] WRITE12 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE12 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] WRITE12 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] WRITE12 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -write16(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 WRITE16 LBA:%" PRId64 " 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_write16_sync(iscsi, lun, lba, - data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE16 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] WRITE16 is not implemented."); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE16 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] WRITE16 returned SUCCESS."); - return 0; -} - -int -write16_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 WRITE16 (Expecting INVALID_FIELD_IN_CDB) " - "LBA:%" PRId64 " 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_write16_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE16 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] WRITE16 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE16 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] WRITE16 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] WRITE16 returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB."); - return 0; -} - -int -write16_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 WRITE16 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%" PRId64 " 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_write16_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE16 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] WRITE16 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE16 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] WRITE16 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] WRITE16 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; -} - -int -write16_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 WRITE16 (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_write16_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE16 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE16 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_ILLEGAL_REQUEST - && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { - scsi_free_scsi_task(task); - logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented."); - return -2; - } - 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] WRITE16 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] WRITE16 returned DATA_PROTECTION/WRITE_PROTECTED."); - return 0; -} - -int -write16_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 WRITE16 (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_write16_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, fua, fua_nv, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITE16 command: %s", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITE16 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_ILLEGAL_REQUEST - && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { - scsi_free_scsi_task(task); - logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented."); - 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)) { - logging(LOG_NORMAL, "[FAILED] WRITE16 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] WRITE16 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -writesame10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data) -{ - struct scsi_task *task; - uint64_t realdatalen; - - logging(LOG_VERBOSE, "Send WRITESAME10 LBA:%d blocks:%d " - "wrprotect:%d anchor:%d unmap:%d group:%d", - lba, num, wrprotect, - anchor, unmap_flag, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writesame10_sync(iscsi, lun, lba, - data, datalen, num, - anchor, unmap_flag, wrprotect, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME10 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] WRITESAME10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_CHECK_CONDITION - && task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST - && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) { - if (inq_bl->wsnz == 1 && num == 0) { - logging(LOG_NORMAL, "[SKIPPED] Target does not support WRITESAME10 with NUMBER OF LOGICAL BLOCKS == 0"); - scsi_free_scsi_task(task); - return -3; - } - - if (datalen == 0) { - realdatalen = num_blocks; - } else { - realdatalen = datalen; - } - if (inq_bl->max_ws_len > 0 && realdatalen > inq_bl->max_ws_len) { - logging(LOG_NORMAL, "[SKIPPED] Number of WRITESAME10 logical blocks to be written exceeds MAXIMUM WRITE SAME LENGTH"); - scsi_free_scsi_task(task); - return -4; - } - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITESAME10 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] WRITESAME10 returned SUCCESS."); - return 0; -} - -int -writesame10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITESAME10 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%d blocks:%d " + logging(LOG_VERBOSE, "Send WRITESAME10 (Expecting %s) LBA:%d blocks:%d " "wrprotect:%d anchor:%d unmap:%d group:%d", - lba, num, wrprotect, - anchor, unmap_flag, group); + scsi_status_str(status), + lba, num, wrprotect, anchor, unmap_flag, group); if (!data_loss) { printf("--dataloss flag is not set in. Skipping write\n"); return -1; } - task = iscsi_writesame10_sync(iscsi, lun, lba, - data, datalen, num, - anchor, unmap_flag, wrprotect, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME10 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] WRITESAME10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITESAME10 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] WRITESAME10 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; - } + task = scsi_cdb_writesame10(wrprotect, anchor, unmap_flag, lba, group, + num, datalen); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] WRITESAME10 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; -} - -int -writesame10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITESAME10 (Expecting INVALID_FIELD_IN_CDB) " - "LBA:%d blocks:%d " - "wrprotect:%d anchor:%d unmap:%d group:%d", - lba, num, wrprotect, - anchor, unmap_flag, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writesame10_sync(iscsi, lun, lba, - data, datalen, num, - anchor, unmap_flag, wrprotect, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME10 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] WRITESAME10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITESAME10 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] WRITESAME10 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] WRITESAME10 returned ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB."); - return 0; -} - -int -writesame10_writeprotected(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITESAME10 (Expecting WRITE_PROTECTED) " - "LBA:%d blocks:%d " - "wrprotect:%d anchor:%d unmap:%d group:%d", - lba, num, wrprotect, - anchor, unmap_flag, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writesame10_sync(iscsi, lun, lba, - data, datalen, num, - anchor, unmap_flag, wrprotect, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME10 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] WRITESAME10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITESAME10 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] WRITESAME10 failed with wrong sense. " - "Should have failed with DATA_PROTECTION/" - "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] WRITESAME10 returned DATA_PROTECTION/WRITE_PROTECTED."); - return 0; -} - -int -writesame10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITESAME10 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%d blocks:%d " - "wrprotect:%d anchor:%d unmap:%d group:%d", - lba, num, wrprotect, - anchor, unmap_flag, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writesame10_sync(iscsi, lun, lba, - data, datalen, num, - anchor, unmap_flag, wrprotect, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME10 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] WRITESAME10 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITESAME10 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] WRITESAME10 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] WRITESAME10 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -writesame16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data) -{ - struct scsi_task *task; - uint64_t realdatalen; - - logging(LOG_VERBOSE, "Send WRITESAME16 LBA:%" PRIu64 " blocks:%d " - "wrprotect:%d anchor:%d unmap:%d group:%d", - lba, num, wrprotect, - anchor, unmap_flag, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writesame16_sync(iscsi, lun, lba, - data, datalen, num, - anchor, unmap_flag, wrprotect, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME16 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] WRITESAME16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_CHECK_CONDITION - && task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST - && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) { - if (inq_bl->wsnz == 1 && num == 0) { - logging(LOG_NORMAL, "[SKIPPED] Target does not support WRITESAME16 with NUMBER OF LOGICAL BLOCKS == 0"); - scsi_free_scsi_task(task); - return -3; - } - - if (datalen == 0) { - realdatalen = num_blocks; - } else { - realdatalen = datalen; - } - if (inq_bl->max_ws_len > 0 && realdatalen > inq_bl->max_ws_len) { - logging(LOG_NORMAL, "[SKIPPED] Number of WRITESAME16 logical blocks to be written exceeds MAXIMUM WRITE SAME LENGTH"); - scsi_free_scsi_task(task); - return -4; - } - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITESAME16 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] WRITESAME16 returned SUCCESS."); - return 0; -} - -int -writesame16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITESAME16 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%" PRIu64 " blocks:%d " - "wrprotect:%d anchor:%d unmap:%d group:%d", - lba, num, wrprotect, - anchor, unmap_flag, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writesame16_sync(iscsi, lun, lba, - data, datalen, num, - anchor, unmap_flag, wrprotect, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME16 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] WRITESAME16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITESAME16 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] WRITESAME16 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] WRITESAME16 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; -} - -int -writesame16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITESAME16 (Expecting INVALID_FIELD_IN_CDB) " - "LBA:%" PRIu64 " blocks:%d " - "wrprotect:%d anchor:%d unmap:%d group:%d", - lba, num, wrprotect, - anchor, unmap_flag, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writesame16_sync(iscsi, lun, lba, - data, datalen, num, - anchor, unmap_flag, wrprotect, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME16 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] WRITESAME16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITESAME16 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] WRITESAME16 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] WRITESAME16 returned ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB."); - return 0; -} - -int -writesame16_writeprotected(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITESAME16 (Expecting WRITE_PROTECTED) " - "LBA:%" PRIu64 " blocks:%d " - "wrprotect:%d anchor:%d unmap:%d group:%d", - lba, num, wrprotect, - anchor, unmap_flag, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writesame16_sync(iscsi, lun, lba, - data, datalen, num, - anchor, unmap_flag, wrprotect, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME16 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] WRITESAME16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITESAME16 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] WRITESAME16 failed with wrong sense. " - "Should have failed with DATA_PROTECTION/" - "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] WRITESAME16 returned DATA_PROTECTION/WRITE_PROTECTED."); - return 0; -} - -int -writesame16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, int group, unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITESAME16 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%" PRIu64 " blocks:%d " - "wrprotect:%d anchor:%d unmap:%d group:%d", - lba, num, wrprotect, - anchor, unmap_flag, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writesame16_sync(iscsi, lun, lba, - data, datalen, num, - anchor, unmap_flag, wrprotect, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITESAME16 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] WRITESAME16 is not implemented on target"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITESAME16 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] WRITESAME16 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] WRITESAME16 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -writeverify10(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY10 LBA:%d blocks:%d " - "wrprotect:%d dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify10_sync(iscsi, lun, lba, - data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY10 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] WRITEVERIFY10 is not implemented."); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY10 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] WRITEVERIFY10 returned SUCCESS."); - return 0; -} - -int -writeverify10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY10 (Expecting INVALID_FIELD_IN_CDB) " - "LBA:%d blocks:%d wrprotect:%d " - "dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify10_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY10 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] WRITEVERIFY10 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY10 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] WRITEVERIFY10 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] WRITEVERIFY10 returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB."); - return 0; -} - -int -writeverify10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY10 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%d blocks:%d wrprotect:%d " - "dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify10_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY10 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] WRITEVERIFY10 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY10 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] WRITEVERIFY10 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] WRITEVERIFY10 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; -} - -int -writeverify10_writeprotected(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY10 (Expecting WRITE_PROTECTED) " - "LBA:%d blocks:%d wrprotect:%d " - "dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify10_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY10 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] WRITEVERIFY10 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY10 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] WRITEVERIFY10 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] WRITEVERIFY10 returned DATA_PROTECTION/WRITE_PROTECTED."); - return 0; -} - -int -writeverify10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY10 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%d blocks:%d wrprotect:%d " - "dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify10_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY10 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] WRITEVERIFY10 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY10 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] WRITEVERIFY10 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] WRITEVERIFY10 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -writeverify12(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY12 LBA:%d blocks:%d " - "wrprotect:%d dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify12_sync(iscsi, lun, lba, - data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY12 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] WRITEVERIFY12 is not implemented."); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY12 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] WRITEVERIFY12 returned SUCCESS."); - return 0; -} - -int -writeverify12_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY12 (Expecting INVALID_FIELD_IN_CDB) " - "LBA:%d blocks:%d wrprotect:%d " - "dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify12_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY12 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] WRITEVERIFY12 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY12 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] WRITEVERIFY12 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] WRITEVERIFY12 returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB."); - return 0; -} - -int -writeverify12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY12 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%d blocks:%d wrprotect:%d " - "dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify12_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY12 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] WRITEVERIFY12 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY12 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] WRITEVERIFY12 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] WRITEVERIFY12 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; -} - -int -writeverify12_writeprotected(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY12 (Expecting WRITE_PROTECTED) " - "LBA:%d blocks:%d wrprotect:%d " - "dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify12_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY12 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] WRITEVERIFY12 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY12 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] WRITEVERIFY12 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] WRITEVERIFY12 returned DATA_PROTECTION/WRITE_PROTECTED."); - return 0; -} - -int -writeverify12_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY12 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%d blocks:%d wrprotect:%d " - "dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify12_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY12 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] WRITEVERIFY12 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY12 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] WRITEVERIFY12 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] WRITEVERIFY12 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -writeverify16(struct iscsi_context *iscsi, int lun, uint64_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY16 LBA:%" PRIu64 " blocks:%d " - "wrprotect:%d dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify16_sync(iscsi, lun, lba, - data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY16 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] WRITEVERIFY16 is not implemented."); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY16 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] WRITEVERIFY16 returned SUCCESS."); - return 0; -} - -int -writeverify16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY16 (Expecting INVALID_FIELD_IN_CDB) " - "LBA:%" PRIu64 " blocks:%d wrprotect:%d " - "dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify16_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY16 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] WRITEVERIFY16 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY16 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] WRITEVERIFY16 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] WRITEVERIFY16 returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB."); - return 0; -} - -int -writeverify16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY16 (Expecting LBA_OUT_OF_RANGE) " - "LBA:%" PRIu64 " blocks:%d wrprotect:%d " - "dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify16_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY16 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] WRITEVERIFY16 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY16 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] WRITEVERIFY16 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] WRITEVERIFY16 returned ILLEGAL_REQUEST/LBA_OUT_OF_RANGE."); - return 0; -} - -int -writeverify16_writeprotected(struct iscsi_context *iscsi, int lun, uint64_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY16 (Expecting WRITE_PROTECTED) " - "LBA:%" PRIu64 " blocks:%d wrprotect:%d " - "dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify16_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY16 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] WRITEVERIFY16 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY16 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] WRITEVERIFY16 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] WRITEVERIFY16 returned DATA_PROTECTION/WRITE_PROTECTED."); - return 0; -} - -int -writeverify16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, - uint32_t datalen, int blocksize, int wrprotect, - int dpo, int bytchk, int group, - unsigned char *data) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send WRITEVERIFY16 (Expecting MEDIUM_NOT_PRESENT) " - "LBA:%" PRIu64 " blocks:%d wrprotect:%d " - "dpo:%d bytchk:%d group:%d", - lba, datalen / blocksize, wrprotect, - dpo, bytchk, group); - - if (!data_loss) { - printf("--dataloss flag is not set in. Skipping write\n"); - return -1; - } - - task = iscsi_writeverify16_sync(iscsi, lun, lba, data, datalen, blocksize, - wrprotect, dpo, bytchk, group); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send WRITEVERIFY16 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] WRITEVERIFY16 is not implemented."); - return -2; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] WRITEVERIFY16 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] WRITEVERIFY16 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] WRITEVERIFY16 returned MEDIUM_NOT_PRESENT."); - return 0; -} - -int -inquiry(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize, struct scsi_task **save_task) -{ - struct scsi_task *task; - - logging(LOG_VERBOSE, "Send INQUIRY evpd:%d page_code:%02x alloc_len:%d", - evpd, page_code, maxsize); - task = iscsi_inquiry_sync(iscsi, lun, evpd, page_code, maxsize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send INQUIRY command: " - "%s", iscsi_get_error(iscsi)); - return -1; - } - if (task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] INQUIRY command: failed with " - "sense. %s", iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - if (save_task != NULL) { - *save_task = task; + if (data != NULL) { + task->expxferlen = datalen; } else { - scsi_free_scsi_task(task); + task->expxferlen = 0; + task->xfer_dir = SCSI_XFER_NONE; } - logging(LOG_VERBOSE, "[OK] INQUIRY returned SUCCESS."); - return 0; + d.data = data; + d.size = datalen; + task = send_scsi_command(sdev, task, &d); + + ret = check_result("WRITESAME10", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; } int -inquiry_invalidfieldincdb(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize) +writesame16(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int num, int anchor, int unmap_flag, int wrprotect, 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 INQUIRY (Expecting INVALID_FIELD_IN_CDB) evpd:%d page_code:%02x alloc_len:%d", + logging(LOG_VERBOSE, "Send WRITESAME16 (Expecting %s) LBA:%" PRIu64 + " blocks:%d wrprotect:%d anchor:%d unmap:%d group:%d", + scsi_status_str(status), + lba, num, wrprotect, anchor, unmap_flag, group); + + if (!data_loss) { + printf("--dataloss flag is not set in. Skipping write\n"); + return -1; + } + + task = scsi_cdb_writesame16(wrprotect, anchor, unmap_flag, lba, group, + num, datalen); + assert(task != NULL); + + if (data != NULL) { + task->expxferlen = datalen; + } else { + task->expxferlen = 0; + task->xfer_dir = SCSI_XFER_NONE; + } + + d.data = data; + d.size = datalen; + task = send_scsi_command(sdev, task, &d); + + ret = check_result("WRITESAME16", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; +} + +int +writeverify10(struct scsi_device *sdev, uint32_t lba, + uint32_t datalen, int blocksize, int wrprotect, + int dpo, int bytchk, 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 WRITEVERIFY10 (Expecting %s) LBA:%d " + "blocks:%d wrprotect:%d dpo:%d bytchk:%d group:%d", + scsi_status_str(status), + lba, datalen / blocksize, wrprotect, + dpo, bytchk, group); + + if (!data_loss) { + printf("--dataloss flag is not set in. Skipping write\n"); + return -1; + } + + task = scsi_cdb_writeverify10(lba, datalen, blocksize, wrprotect, + dpo, bytchk, group); + assert(task != NULL); + + d.data = data; + d.size = datalen; + task = send_scsi_command(sdev, task, &d); + + ret = check_result("WRITEVERIFY10", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; +} + +int +writeverify12(struct scsi_device *sdev, uint32_t lba, + uint32_t datalen, int blocksize, int wrprotect, + int dpo, int bytchk, 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 WRITEVERIFY12 (Expecting %s) LBA:%d " + "blocks:%d wrprotect:%d dpo:%d bytchk:%d group:%d", + scsi_status_str(status), + lba, datalen / blocksize, wrprotect, + dpo, bytchk, group); + + if (!data_loss) { + printf("--dataloss flag is not set in. Skipping write\n"); + return -1; + } + + task = scsi_cdb_writeverify12(lba, datalen, blocksize, wrprotect, + dpo, bytchk, group); + assert(task != NULL); + + d.data = data; + d.size = datalen; + task = send_scsi_command(sdev, task, &d); + + ret = check_result("WRITEVERIFY12", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; +} + +int +writeverify16(struct scsi_device *sdev, uint64_t lba, + uint32_t datalen, int blocksize, int wrprotect, + int dpo, int bytchk, 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 WRITEVERIFY16 (Expecting %s) LBA:%" PRIu64 + " blocks:%d wrprotect:%d dpo:%d bytchk:%d group:%d", + scsi_status_str(status), + lba, datalen / blocksize, wrprotect, + dpo, bytchk, group); + + if (!data_loss) { + printf("--dataloss flag is not set in. Skipping write\n"); + return -1; + } + + task = scsi_cdb_writeverify16(lba, datalen, blocksize, wrprotect, + dpo, bytchk, group); + assert(task != NULL); + + d.data = data; + d.size = datalen; + task = send_scsi_command(sdev, task, &d); + + ret = check_result("WRITEVERIFY16", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; +} + +int +inquiry(struct scsi_device *sdev, struct scsi_task **out_task, int evpd, int page_code, int maxsize, int status, enum scsi_sense_key key, int *ascq, int num_ascq) +{ + struct scsi_task *task; + int ret; + + logging(LOG_VERBOSE, "Send INQUIRY (Expecting %s) evpd:%d " + "page_code:%02x alloc_len:%d", + scsi_status_str(status), evpd, page_code, maxsize); - task = iscsi_inquiry_sync(iscsi, lun, evpd, page_code, maxsize); - if (task == NULL) { - logging(LOG_NORMAL, "[FAILED] Failed to send INQUIRY command: " - "%s", iscsi_get_error(iscsi)); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "[FAILED] INQUIRY 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] INQUIRY 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; - } + task = scsi_cdb_inquiry(evpd, page_code, maxsize); + assert(task != NULL); - scsi_free_scsi_task(task); - logging(LOG_VERBOSE, "[OK] INQUIRY returned ILLEGAL_REQUEST/INVALID_FIELD_IB_CDB."); - return 0; + task = send_scsi_command(sdev, task, NULL); + + ret = check_result("INQUIRY", sdev, task, status, key, ascq, num_ascq); + if (out_task) { + *out_task = task; + } else if (task) { + scsi_free_scsi_task(task); + } + return ret; } struct scsi_command_descriptor * @@ -6361,31 +2307,23 @@ get_command_descriptor(int opcode, int sa) return NULL; } -int set_swp(struct iscsi_context *iscsi, int lun) +int set_swp(struct scsi_device *sdev) { - int ret = 0; + int ret; struct scsi_task *sense_task = NULL; - struct scsi_task *select_task = NULL; struct scsi_mode_sense *ms; struct scsi_mode_page *mp; logging(LOG_VERBOSE, "Read CONTROL page"); - sense_task = iscsi_modesense6_sync(iscsi, lun, - 1, SCSI_MODESENSE_PC_CURRENT, - SCSI_MODEPAGE_CONTROL, - 0, 255); - if (sense_task == NULL) { - logging(LOG_NORMAL, "Failed to send MODE_SENSE6 command: %s", - iscsi_get_error(iscsi)); - ret = -1; - goto finished; - } - if (sense_task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "MODE_SENSE6 failed: %s", - iscsi_get_error(iscsi)); - ret = -1; + ret = modesense6(sdev, &sense_task, 1, SCSI_MODESENSE_PC_CURRENT, + SCSI_MODEPAGE_CONTROL, 0, 255, + EXPECT_STATUS_GOOD); + if (ret) { + logging(LOG_NORMAL, "Failed to read CONTROL mode page."); goto finished; } + logging(LOG_VERBOSE, "[SUCCESS] CONTROL page fetched."); + ms = scsi_datain_unmarshall(sense_task); if (ms == NULL) { logging(LOG_NORMAL, "failed to unmarshall mode sense datain " @@ -6400,59 +2338,44 @@ int set_swp(struct iscsi_context *iscsi, int lun) goto finished; } + /* For MODE SELECT PS is reserved and hence must be cleared */ + mp->ps = 0; + logging(LOG_VERBOSE, "Turn SWP ON"); mp->control.swp = 1; - select_task = iscsi_modeselect6_sync(iscsi, lun, - 1, 0, mp); - if (select_task == NULL) { - logging(LOG_NORMAL, "Failed to send MODE_SELECT6 command: %s", - iscsi_get_error(iscsi)); - ret = -1; - goto finished; - } - if (select_task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "MODE_SELECT6 failed: %s", - iscsi_get_error(iscsi)); - ret = -1; + ret = modeselect6(sdev, 1, 0, mp, + EXPECT_STATUS_GOOD); + if (ret) { + logging(LOG_NORMAL, "Failed to write CONTROL mode page."); goto finished; } + logging(LOG_VERBOSE, "[SUCCESS] CONTROL page written."); finished: if (sense_task != NULL) { scsi_free_scsi_task(sense_task); } - if (select_task != NULL) { - scsi_free_scsi_task(select_task); - } return ret; } -int clear_swp(struct iscsi_context *iscsi, int lun) +int clear_swp(struct scsi_device *sdev) { - int ret = 0; + int ret; struct scsi_task *sense_task = NULL; - struct scsi_task *select_task = NULL; struct scsi_mode_sense *ms; struct scsi_mode_page *mp; logging(LOG_VERBOSE, "Read CONTROL page"); - sense_task = iscsi_modesense6_sync(iscsi, lun, - 1, SCSI_MODESENSE_PC_CURRENT, - SCSI_MODEPAGE_CONTROL, - 0, 255); - if (sense_task == NULL) { - logging(LOG_NORMAL, "Failed to send MODE_SENSE6 command: %s", - iscsi_get_error(iscsi)); - ret = -1; - goto finished; - } - if (sense_task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "MODE_SENSE6 failed: %s", - iscsi_get_error(iscsi)); - ret = -1; + ret = modesense6(sdev, &sense_task, 1, SCSI_MODESENSE_PC_CURRENT, + SCSI_MODEPAGE_CONTROL, 0, 255, + EXPECT_STATUS_GOOD); + if (ret) { + logging(LOG_NORMAL, "Failed to read CONTROL mode page."); goto finished; } + logging(LOG_VERBOSE, "[SUCCESS] CONTROL page fetched."); + ms = scsi_datain_unmarshall(sense_task); if (ms == NULL) { logging(LOG_NORMAL, "failed to unmarshall mode sense datain " @@ -6467,30 +2390,23 @@ int clear_swp(struct iscsi_context *iscsi, int lun) goto finished; } + /* For MODE SELECT PS is reserved and hence must be cleared */ + mp->ps = 0; + logging(LOG_VERBOSE, "Turn SWP OFF"); mp->control.swp = 0; - select_task = iscsi_modeselect6_sync(iscsi, lun, - 1, 0, mp); - if (select_task == NULL) { - logging(LOG_NORMAL, "Failed to send MODE_SELECT6 command: %s", - iscsi_get_error(iscsi)); - ret = -1; - goto finished; - } - if (select_task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "MODE_SELECT6 failed: %s", - iscsi_get_error(iscsi)); - ret = -1; + ret = modeselect6(sdev, 1, 0, mp, + EXPECT_STATUS_GOOD); + if (ret) { + logging(LOG_NORMAL, "Failed to write CONTROL mode page."); goto finished; } + logging(LOG_VERBOSE, "[SUCCESS] CONTROL page written."); finished: if (sense_task != NULL) { scsi_free_scsi_task(sense_task); } - if (select_task != NULL) { - scsi_free_scsi_task(select_task); - } return ret; } diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 78c41fc..cf6ae7c 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -2,6 +2,7 @@ iscsi-test tool support Copyright (C) 2012 by Lee Duncan + Copyright (C) 2014 by Ronnie sahlberg 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 @@ -25,9 +26,30 @@ #include #include +#ifndef discard_const +#define discard_const(ptr) ((void *)((intptr_t)(ptr))) +#endif + extern const char *initiatorname1; extern const char *initiatorname2; -extern const char *tgt_url; + +#define EXPECT_STATUS_GOOD SCSI_STATUS_GOOD, SCSI_SENSE_NO_SENSE, NULL, 0 +#define EXPECT_NO_MEDIUM SCSI_STATUS_CHECK_CONDITION, SCSI_SENSE_NOT_READY, no_medium_ascqs, 3 +#define EXPECT_LBA_OOB SCSI_STATUS_CHECK_CONDITION, SCSI_SENSE_ILLEGAL_REQUEST, lba_oob_ascqs, 1 +#define EXPECT_INVALID_FIELD_IN_CDB SCSI_STATUS_CHECK_CONDITION, SCSI_SENSE_ILLEGAL_REQUEST, invalid_cdb_ascqs, 1 +#define EXPECT_MISCOMPARE SCSI_STATUS_CHECK_CONDITION, SCSI_SENSE_MISCOMPARE, miscompare_ascqs, 1 +#define EXPECT_WRITE_PROTECTED SCSI_STATUS_CHECK_CONDITION, SCSI_SENSE_DATA_PROTECTION, write_protect_ascqs, 3 +#define EXPECT_SANITIZE SCSI_STATUS_CHECK_CONDITION, SCSI_SENSE_NOT_READY, sanitize_ascqs, 1 +#define EXPECT_REMOVAL_PREVENTED SCSI_STATUS_CHECK_CONDITION, SCSI_SENSE_ILLEGAL_REQUEST, removal_ascqs, 1 +#define EXPECT_RESERVATION_CONFLICT SCSI_STATUS_RESERVATION_CONFLICT, 0, NULL, 0 + +int no_medium_ascqs[3]; +int lba_oob_ascqs[1]; +int invalid_cdb_ascqs[1]; +int write_protect_ascqs[3]; +int sanitize_ascqs[1]; +int removal_ascqs[1]; +int miscompare_ascqs[1]; extern int loglevel; #define LOG_SILENT 0 @@ -166,6 +188,18 @@ extern int readonly; extern int sbc3_support; extern int maximum_transfer_length; +struct scsi_device { + const char *error_str; + + struct iscsi_context *iscsi_ctx; + int iscsi_lun; + const char *iscsi_url; + + const char *sgio_dev; + int sgio_fd; +}; +extern struct scsi_device *sd; + struct iscsi_context *iscsi_context_login(const char *initiatorname, const char *url, int *lun); struct iscsi_async_state { @@ -211,153 +245,70 @@ static inline int pr_type_is_all_registrants( } } -int prin_task(struct iscsi_context *iscsi, int lun, int service_action, +int prin_task(struct scsi_device *sdev, int service_action, int success_expected); -int prin_read_keys(struct iscsi_context *iscsi, int lun, struct scsi_task **tp, +int prin_read_keys(struct scsi_device *sdev, struct scsi_task **tp, struct scsi_persistent_reserve_in_read_keys **rkp); -int prout_register_and_ignore(struct iscsi_context *iscsi, int lun, +int prout_register_and_ignore(struct scsi_device *sdev, unsigned long long key); -int prout_register_key(struct iscsi_context *iscsi, int lun, +int prout_register_key(struct scsi_device *sdev, unsigned long long sark, unsigned long long rk); -int prin_verify_key_presence(struct iscsi_context *iscsi, int lun, +int prin_verify_key_presence(struct scsi_device *sdev, unsigned long long key, int present); -int prout_reregister_key_fails(struct iscsi_context *iscsi, int lun, +int prout_reregister_key_fails(struct scsi_device *sdev, unsigned long long sark); -int prout_reserve(struct iscsi_context *iscsi, int lun, +int prout_reserve(struct scsi_device *sdev, unsigned long long key, enum scsi_persistent_out_type pr_type); -int prout_release(struct iscsi_context *iscsi, int lun, +int prout_release(struct scsi_device *sdev, unsigned long long key, enum scsi_persistent_out_type pr_type); -int prin_verify_not_reserved(struct iscsi_context *iscsi, int lun); -int prin_verify_reserved_as(struct iscsi_context *iscsi, int lun, +int prin_verify_not_reserved(struct scsi_device *sdev); +int prin_verify_reserved_as(struct scsi_device *sdev, unsigned long long key, enum scsi_persistent_out_type pr_type); -int verify_read_works(struct iscsi_context *iscsi, int lun, unsigned char *buf); -int verify_write_works(struct iscsi_context *iscsi, int lun, unsigned char *buf); -int verify_read_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf); -int verify_write_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf); -int inquiry(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize, struct scsi_task **save_task); -int inquiry_invalidfieldincdb(struct iscsi_context *iscsi, int lun, int evpd, int page_code, int maxsize); -struct scsi_task *get_lba_status_task(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len); -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); -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); -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); -int get_lba_status(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len, enum scsi_provisioning_type *provisioning0); -int get_lba_status_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len); -int get_lba_status_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t len); -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); -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); -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); -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); -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); -int prefetch10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int immed, int group); -int prefetch10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int immed, int group); -int prefetch10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int immed, int group); -int prefetch16(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int immed, int group); -int prefetch16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int immed, int group); -int prefetch16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int immed, int group); -int preventallow(struct iscsi_context *iscsi, int lun, int prevent); -int read6(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, unsigned char *data); -int read6_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, unsigned char *data); -struct scsi_task *read10_task(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int read10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int read10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int read10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int read10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int read12(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int read12_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int read12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int read12_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int read16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int read16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int read16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int read16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int read16_sanitize(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int readcapacity10(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi); -int readcapacity10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi); -int readcapacity16(struct iscsi_context *iscsi, int lun, int alloc_len); -int readcapacity16_nomedium(struct iscsi_context *iscsi, int lun, int alloc_len); -int report_supported_opcodes(struct iscsi_context *iscsi, int lun, int rctd, int options, int opcode, int sa, int alloc_len, struct scsi_task **save_task); -int report_supported_opcodes_invalidfieldincdb(struct iscsi_context *iscsi, int lun, int rctd, int options, int opcode, int sa, int alloc_len, struct scsi_task **save_task); -int release6(struct iscsi_context *iscsi, int lun); -int reserve6(struct iscsi_context *iscsi, int lun); -int reserve6_conflict(struct iscsi_context *iscsi, int lun); -int sanitize(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data); -int sanitize_conflict(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data); -int sanitize_invalidfieldincdb(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data); -int sanitize_writeprotected(struct iscsi_context *iscsi, int lun, int immed, int ause, int sa, int param_len, struct iscsi_data *data); -int startstopunit(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start); -int startstopunit_sanitize(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start); -int startstopunit_preventremoval(struct iscsi_context *iscsi, int lun, int immed, int pcm, int pc, int no_flush, int loej, int start); -int synchronizecache10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int sync_nv, int immed); -int synchronizecache10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int sync_nv, int immed); -int synchronizecache16(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int sync_nv, int immed); -int synchronizecache16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int sync_nv, int immed); -int testunitready_clear_ua(struct iscsi_context *iscsi, int lun); -int testunitready(struct iscsi_context *iscsi, int lun); -int testunitready_nomedium(struct iscsi_context *iscsi, int lun); -int testunitready_conflict(struct iscsi_context *iscsi, int lun); -int testunitready_sanitize(struct iscsi_context *iscsi, int lun); -int mode_sense(struct iscsi_context *iscsi, int lun); -int unmap(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len); -int unmap_writeprotected(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len); -int unmap_nomedium(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len); -int verify10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify10_miscompare(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify12(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify12_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify12_miscompare(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify12_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify16_miscompare(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int verify16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data); -int write10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int write10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int write10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int write10_writeprotected(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int write10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int write12(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int write12_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int write12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int write12_writeprotected(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int write12_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data); -int write16(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); -int write16_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); -int write16_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); -int write16_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); -int write16_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); -int writesame10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); -int writesame10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); -int writesame10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); -int writesame10_writeprotected(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); -int writesame10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); -int writesame16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); -int writesame16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); -int writesame16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); -int writesame16_writeprotected(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); -int writesame16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data); -int writeverify10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify10_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify10_writeprotected(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify12(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify12_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify12_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify12_writeprotected(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify12_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify16_invalidfieldincdb(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify16_writeprotected(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); -int writeverify16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data); +int verify_read_works(struct scsi_device *sdev, unsigned char *buf); +int verify_write_works(struct scsi_device *sdev, unsigned char *buf); +int verify_read_fails(struct scsi_device *sdev, unsigned char *buf); +int verify_write_fails(struct scsi_device *sdev, unsigned char *buf); -int set_swp(struct iscsi_context *iscsi, int lun); -int clear_swp(struct iscsi_context *iscsi, int lun); +int compareandwrite(struct scsi_device *sdev, uint64_t lba, unsigned char *data, uint32_t len, int blocksize, int wrprotect, int dpo, int fua, int group_number, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int get_lba_status(struct scsi_device *sdev, struct scsi_task **task, uint64_t lba, uint32_t len, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int inquiry(struct scsi_device *sdev, struct scsi_task **task, int evpd, int page_code, int maxsize, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int modesense6(struct scsi_device *sdev, struct scsi_task **task, int dbd, enum scsi_modesense_page_control pc, enum scsi_modesense_page_code page_code, int sub_page_code, unsigned char alloc_len, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int modeselect6(struct scsi_device *sdev, int pf, int sp, struct scsi_mode_page *mp, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int orwrite(struct scsi_device *sdev, uint64_t lba, 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); +int prefetch10(struct scsi_device *sdev, uint32_t lba, int num_blocks, int immed, int group, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int prefetch16(struct scsi_device *sdev, uint64_t lba, int num_blocks, int immed, int group, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int preventallow(struct scsi_device *sdev, int prevent); +int read6(struct scsi_device *sdev, struct scsi_task **task, uint32_t lba, uint32_t datalen, int blocksize, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int read10(struct scsi_device *sdev, struct scsi_task **task, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int read12(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int read16(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int blocksize, int rdprotect, int dpo, int fua, int fua_nv, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int readcapacity10(struct scsi_device *sdev, struct scsi_task **task, uint32_t lba, int pmi, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int readcapacity16(struct scsi_device *sdev, struct scsi_task **task, int alloc_len, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int report_supported_opcodes(struct scsi_device *sdev, struct scsi_task **save_task, int rctd, int options, int opcode, int sa, int alloc_len, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int release6(struct scsi_device *sdev); +int reserve6(struct scsi_device *sdev); +int reserve6_conflict(struct scsi_device *sdev); +int sanitize(struct scsi_device *sdev, int immed, int ause, int sa, int param_len, struct iscsi_data *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int startstopunit(struct scsi_device *sdev, int immed, int pcm, int pc, int no_flush, int loej, int start, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int synchronizecache10(struct scsi_device *sdev, uint32_t lba, int num_blocks, int sync_nv, int immed, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int synchronizecache16(struct scsi_device *sdev, uint64_t lba, int num_blocks, int sync_nv, int immed, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int testunitready_clear_ua(struct scsi_device *sdev); +int testunitready(struct scsi_device *sdev, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int unmap(struct scsi_device *sdev, int anchor, struct unmap_list *list, int list_len, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int verify10(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int verify12(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int verify16(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int write10(struct scsi_device *sdev, uint32_t lba, 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); +int write12(struct scsi_device *sdev, uint32_t lba, 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); +int write16(struct scsi_device *sdev, uint64_t lba, 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); +int writesame10(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int writesame16(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int num_blocks, int anchor, int unmap, int wrprotect, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int writeverify10(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int writeverify12(struct scsi_device *sdev, uint32_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int writeverify16(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, int dpo, int bytchk, int group, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); + +int set_swp(struct scsi_device *sdev); +int clear_swp(struct scsi_device *sdev); #endif /* _ISCSI_SUPPORT_H_ */ diff --git a/test-tool/iscsi-test-cu.c b/test-tool/iscsi-test-cu.c index 2659a2b..ce57f7f 100644 --- a/test-tool/iscsi-test-cu.c +++ b/test-tool/iscsi-test-cu.c @@ -17,6 +17,8 @@ along with this program; if not, see . */ +#include "config.h" + #define _GNU_SOURCE #include #include @@ -30,6 +32,12 @@ #include #include +#ifdef HAVE_SG_IO +#include +#include +#include +#endif + #include #include #include @@ -40,16 +48,12 @@ #include "iscsi-support.h" #include "iscsi-test-cu.h" - - - -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif +#include "iscsi-support.h" #define PROG "iscsi-test-cu" int loglevel = LOG_NORMAL; +struct scsi_device *sd; /* * this allows us to redefine how PDU are queued, at times, for @@ -409,7 +413,6 @@ typedef struct libiscsi_suite_info { } libiscsi_suite_info; #define NON_PGR_FUNCS suite_init, suite_cleanup, test_setup, test_teardown -#define PGR_FUNCS suite_init_pgr, suite_cleanup_pgr, test_setup, test_teardown /* SCSI protocol tests */ static libiscsi_suite_info scsi_suites[] = { @@ -426,7 +429,7 @@ static libiscsi_suite_info scsi_suites[] = { { "PrinReadKeys", NON_PGR_FUNCS, tests_prin_read_keys }, { "PrinServiceactionRange", NON_PGR_FUNCS, tests_prin_serviceaction_range }, { "ProutRegister", NON_PGR_FUNCS, tests_prout_register }, - { "ProutReserve", PGR_FUNCS, tests_prout_reserve }, + { "ProutReserve", NON_PGR_FUNCS, tests_prout_reserve }, { "Read6", NON_PGR_FUNCS, tests_read6 }, { "Read10", NON_PGR_FUNCS, tests_read10 }, { "Read12", NON_PGR_FUNCS, tests_read12 }, @@ -507,7 +510,7 @@ static libiscsi_suite_info all_suites[] = { { "PrinServiceactionRange", NON_PGR_FUNCS, tests_prin_serviceaction_range }, { "ProutRegister", NON_PGR_FUNCS, tests_prout_register }, - { "ProutReserve", PGR_FUNCS, tests_prout_reserve }, + { "ProutReserve", NON_PGR_FUNCS, tests_prout_reserve }, { "Read6", NON_PGR_FUNCS, tests_read6 }, { "Read10", NON_PGR_FUNCS, tests_read10 }, { "Read12", NON_PGR_FUNCS, tests_read12 }, @@ -539,21 +542,14 @@ static libiscsi_suite_info all_suites[] = { { NULL, NULL, NULL, NULL, NULL, NULL }, }; -static libiscsi_suite_info scsi_usb_sbc_suites[] = { +static libiscsi_suite_info linux_suites[] = { { "CompareAndWrite", NON_PGR_FUNCS, tests_compareandwrite }, { "GetLBAStatus", NON_PGR_FUNCS, tests_get_lba_status }, { "Inquiry", NON_PGR_FUNCS, tests_inquiry }, { "Mandatory", NON_PGR_FUNCS, tests_mandatory }, - { "ModeSense6", NON_PGR_FUNCS, tests_modesense6 }, { "OrWrite", NON_PGR_FUNCS, tests_orwrite }, { "Prefetch10", NON_PGR_FUNCS, tests_prefetch10 }, { "Prefetch16", NON_PGR_FUNCS, tests_prefetch16 }, - { "PrinReadKeys", NON_PGR_FUNCS, tests_prin_read_keys }, - { "PrinServiceactionRange", NON_PGR_FUNCS, - tests_prin_serviceaction_range }, - { "ProutRegister", NON_PGR_FUNCS, tests_prout_register }, - { "ProutReserve", PGR_FUNCS, tests_prout_reserve }, - { "Read6", NON_PGR_FUNCS, tests_read6 }, { "Read10", NON_PGR_FUNCS, tests_read10 }, { "Read12", NON_PGR_FUNCS, tests_read12 }, { "Read16", NON_PGR_FUNCS, tests_read16 }, @@ -562,7 +558,6 @@ static libiscsi_suite_info scsi_usb_sbc_suites[] = { { "ReadOnly", NON_PGR_FUNCS, tests_readonly }, { "ReportSupportedOpcodes", NON_PGR_FUNCS, tests_report_supported_opcodes }, - { "Reserve6", NON_PGR_FUNCS, tests_reserve6 }, { "TestUnitReady", NON_PGR_FUNCS, tests_testunitready }, { "Unmap", NON_PGR_FUNCS, tests_unmap }, { "Verify10", NON_PGR_FUNCS, tests_verify10 }, @@ -585,24 +580,19 @@ struct test_family { }; static struct test_family families[] = { - { "ALL", all_suites }, - { "SCSI", scsi_suites }, - { "iSCSI", iscsi_suites }, - { "SCSI-USB-SBC", scsi_usb_sbc_suites }, - { NULL, NULL} + { "ALL", all_suites }, + { "SCSI", scsi_suites }, + { "iSCSI", iscsi_suites }, + { "LINUX", linux_suites }, + { NULL, NULL} }; /* * globals for test setup and teardown */ -int tgt_lun; -struct iscsi_context *iscsic; struct scsi_task *task; -int tgt_lun2; -struct iscsi_context *iscsic2; unsigned char *read_write_buf; - static void print_usage(void) { @@ -683,11 +673,17 @@ test_teardown(void) int suite_init(void) { - iscsic = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun); - if (iscsic == NULL) { - fprintf(stderr, - "error: Failed to login to target for test set-up\n"); - return 1; + if (sd->iscsi_url) { + if (sd->iscsi_ctx) { + iscsi_logout_sync(sd->iscsi_ctx); + iscsi_destroy_context(sd->iscsi_ctx); + } + sd->iscsi_ctx = iscsi_context_login(initiatorname1, sd->iscsi_url, &sd->iscsi_lun); + if (sd->iscsi_ctx == NULL) { + fprintf(stderr, + "error: Failed to login to target for test set-up\n"); + return 1; + } } #ifndef HAVE_CU_SUITEINFO_PSETUPFUNC /* libcunit version 1 */ @@ -703,40 +699,16 @@ suite_cleanup(void) /* libcunit version 1 */ test_teardown(); #endif - if (iscsic) { - iscsi_logout_sync(iscsic); - iscsi_destroy_context(iscsic); - iscsic = NULL; + if (sd->iscsi_url) { + if (sd->iscsi_ctx) { + iscsi_logout_sync(sd->iscsi_ctx); + iscsi_destroy_context(sd->iscsi_ctx); + sd->iscsi_ctx = NULL; + } } return 0; } -int -suite_init_pgr(void) -{ - suite_init(); - iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun2); - if (iscsic2 == NULL) { - fprintf(stderr, - "error: Failed to login to target for test set-up\n"); - suite_cleanup(); - return 1; - } - return 0; -} - -int -suite_cleanup_pgr(void) -{ - if (iscsic2) { - iscsi_logout_sync(iscsic2); - iscsi_destroy_context(iscsic2); - iscsic2 = NULL; - } - suite_cleanup(); - return 0; -} - static void list_all_tests(void) { @@ -893,11 +865,66 @@ static void parse_and_add_tests(char *testname_re) parse_and_add_test(testname_re); } +static int connect_scsi_device(struct scsi_device *sdev, const char *initiatorname) +{ + if (sdev->iscsi_url) { + sdev->iscsi_ctx = iscsi_context_login(initiatorname, sdev->iscsi_url, &sdev->iscsi_lun); + if (sdev->iscsi_ctx == NULL) { + return -1; + } + return 0; + } +#ifdef HAVE_SG_IO + if (sdev->sgio_dev) { + int version; + + if ((sdev->sgio_fd = open(sdev->sgio_dev, O_RDWR)) == -1) { + fprintf(stderr, "Failed to open SG_IO device %s. Error:%s\n", sdev->sgio_dev, + strerror(errno)); + return -1; + } + if ((ioctl(sdev->sgio_fd, SG_GET_VERSION_NUM, &version) < 0) || (version < 30000)) { + fprintf(stderr, "%s is not a SCSI device node\n", sdev->sgio_dev); + close(sdev->sgio_fd); + return -1; + } + return 0; + } +#endif + return -1; +} + +static void free_scsi_device(struct scsi_device *sdev) +{ + if (sdev->error_str) { + free(discard_const(sdev->error_str)); + sdev->error_str = NULL; + } + if (sdev->iscsi_url) { + free(discard_const(sdev->iscsi_url)); + sdev->iscsi_url = NULL; + } + if (sdev->iscsi_ctx) { + iscsi_logout_sync(sdev->iscsi_ctx); + iscsi_destroy_context(sdev->iscsi_ctx); + sdev->iscsi_ctx = NULL; + } + + if (sdev->sgio_dev) { + free(discard_const(sdev->sgio_dev)); + sdev->sgio_dev = NULL; + } + if (sdev->sgio_fd != -1) { + close(sdev->sgio_fd); + sdev->sgio_fd = -1; + } + free(sd); +} + int main(int argc, char *argv[]) { char *testname_re = NULL; - int lun; CU_BasicRunMode mode = CU_BRM_VERBOSE; CU_ErrorAction error_action = CUEA_IGNORE; int res; @@ -933,6 +960,10 @@ main(int argc, char *argv[]) int i, c; int opt_idx = 0; + sd = malloc(sizeof(struct scsi_device)); + memset(sd, '\0', sizeof(struct scsi_device)); + sd->sgio_fd = -1; + while ((c = getopt_long(argc, argv, "?hli:I:t:sdgfAsSnuvxV", long_opts, &opt_idx)) > 0) { switch (c) { @@ -994,7 +1025,13 @@ main(int argc, char *argv[]) } if (optind < argc) { - tgt_url = strdup(argv[optind++]); + if (!strncmp(argv[optind], "iscsi://", 8)) { + sd->iscsi_url = strdup(argv[optind++]); +#ifdef HAVE_SG_IO + } else if (!strncmp(argv[optind], "/dev/sg", 7)) { + sd->sgio_dev = strdup(argv[optind++]); +#endif + } } if (optind < argc) { fprintf(stderr, "error: too many arguments\n"); @@ -1005,17 +1042,21 @@ main(int argc, char *argv[]) /* XXX why is this done? */ real_iscsi_queue_pdu = dlsym(RTLD_NEXT, "iscsi_queue_pdu"); - if (tgt_url == NULL) { - fprintf(stderr, "You must specify the URL\n"); + if (sd->iscsi_url == NULL && sd->sgio_dev== NULL ) { +#ifdef HAVE_SG_IO + fprintf(stderr, "You must specify either an iSCSI URL or a /dev/sg device\n"); +#else + fprintf(stderr, "You must specify either an iSCSI URL\n"); +#endif print_usage(); if (testname_re) free(testname_re); return 10; } - iscsic = iscsi_context_login(initiatorname1, tgt_url, &lun); - if (iscsic == NULL) { - printf("Failed to login to target\n"); + if (connect_scsi_device(sd, initiatorname1)) { + fprintf(stderr, "Failed to connect to SCSI device\n"); + free_scsi_device(sd); return -1; } @@ -1024,46 +1065,43 @@ main(int argc, char *argv[]) * All devices support readcapacity10 but only some support * readcapacity16 */ - task = iscsi_readcapacity10_sync(iscsic, lun, 0, 0); + task = NULL; + readcapacity10(sd, &task, 0, 0, EXPECT_STATUS_GOOD); if (task == NULL) { - printf("Failed to send READCAPACITY10 command: %s\n", - iscsi_get_error(iscsic)); - iscsi_destroy_context(iscsic); + printf("Failed to send READCAPACITY10 command: %s\n", sd->error_str); + free_scsi_device(sd); return -1; } if (task->status != SCSI_STATUS_GOOD) { - printf("READCAPACITY10 command: failed with sense. %s\n", - iscsi_get_error(iscsic)); + printf("READCAPACITY10 command: failed with sense. %s\n", sd->error_str); scsi_free_scsi_task(task); - iscsi_destroy_context(iscsic); + free_scsi_device(sd); return -1; } rc10 = scsi_datain_unmarshall(task); if (rc10 == NULL) { - printf("failed to unmarshall READCAPACITY10 data. %s\n", - iscsi_get_error(iscsic)); + printf("failed to unmarshall READCAPACITY10 data.\n"); scsi_free_scsi_task(task); - iscsi_destroy_context(iscsic); + free_scsi_device(sd); return -1; } block_size = rc10->block_size; num_blocks = rc10->lba + 1; scsi_free_scsi_task(task); - rc16_task = iscsi_readcapacity16_sync(iscsic, lun); + rc16_task = NULL; + readcapacity16(sd, &rc16_task, 96, EXPECT_STATUS_GOOD); if (rc16_task == NULL) { - printf("Failed to send READCAPACITY16 command: %s\n", - iscsi_get_error(iscsic)); - iscsi_destroy_context(iscsic); + printf("Failed to send READCAPACITY16 command: %s\n", sd->error_str); + free_scsi_device(sd); return -1; } if (rc16_task->status == SCSI_STATUS_GOOD) { rc16 = scsi_datain_unmarshall(rc16_task); if (rc16 == NULL) { - printf("failed to unmarshall READCAPACITY16 data. %s\n", - iscsi_get_error(iscsic)); + printf("failed to unmarshall READCAPACITY16 data. %s\n", sd->error_str); scsi_free_scsi_task(rc16_task); - iscsi_destroy_context(iscsic); + free_scsi_device(sd); return -1; } block_size = rc16->block_length; @@ -1071,9 +1109,10 @@ main(int argc, char *argv[]) lbppb = 1 << rc16->lbppbe; } - inq_task = iscsi_inquiry_sync(iscsic, lun, 0, 0, 64); + inq_task = NULL; + inquiry(sd, &inq_task, 0, 0, 64, EXPECT_STATUS_GOOD); if (inq_task == NULL || inq_task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic)); + printf("Inquiry command failed : %s\n", sd->error_str); return -1; } full_size = scsi_datain_getfullsize(inq_task); @@ -1081,10 +1120,10 @@ main(int argc, char *argv[]) scsi_free_scsi_task(inq_task); /* we need more data for the full list */ - inq_task = iscsi_inquiry_sync(iscsic, lun, 0, 0, full_size); + inq_task = NULL; + inquiry(sd, &inq_task, 0, 0, full_size, EXPECT_STATUS_GOOD); if (inq_task == NULL) { - printf("Inquiry command failed : %s\n", - iscsi_get_error(iscsic)); + printf("Inquiry command failed : %s\n", sd->error_str); return -1; } } @@ -1103,7 +1142,8 @@ main(int argc, char *argv[]) } /* try reading block limits vpd */ - inq_bl_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, 64); + inq_bl_task = NULL; + inquiry(sd, &inq_bl_task, 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, 64, EXPECT_STATUS_GOOD); if (inq_bl_task && inq_bl_task->status != SCSI_STATUS_GOOD) { scsi_free_scsi_task(inq_bl_task); inq_bl_task = NULL; @@ -1113,8 +1153,11 @@ main(int argc, char *argv[]) if (full_size > inq_bl_task->datain.size) { scsi_free_scsi_task(inq_bl_task); - if ((inq_bl_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic)); + inq_bl_task = NULL; + inquiry(sd, &inq_bl_task, 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, full_size, + EXPECT_STATUS_GOOD); + if (inq_bl_task == NULL) { + printf("Inquiry command failed : %s\n", sd->error_str); return -1; } } @@ -1127,7 +1170,9 @@ main(int argc, char *argv[]) } /* try reading block device characteristics vpd */ - inq_bdc_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_BLOCK_DEVICE_CHARACTERISTICS, 255); + inq_bdc_task = NULL; + inquiry(sd, &inq_bdc_task, 1, SCSI_INQUIRY_PAGECODE_BLOCK_DEVICE_CHARACTERISTICS, 255, + EXPECT_STATUS_GOOD); if (inq_bdc_task == NULL) { printf("Failed to read Block Device Characteristics page\n"); } @@ -1141,9 +1186,11 @@ main(int argc, char *argv[]) /* if thin provisioned we also need to read the VPD page for it */ if (rc16 && rc16->lbpme != 0){ - inq_lbp_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, 64); + inq_lbp_task = NULL; + inquiry(sd, &inq_lbp_task, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, 64, + EXPECT_STATUS_GOOD); if (inq_lbp_task == NULL || inq_lbp_task->status != SCSI_STATUS_GOOD) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic)); + printf("Inquiry command failed : %s\n", sd->error_str); return -1; } full_size = scsi_datain_getfullsize(inq_lbp_task); @@ -1151,8 +1198,11 @@ main(int argc, char *argv[]) scsi_free_scsi_task(inq_lbp_task); /* we need more data for the full list */ - if ((inq_lbp_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, full_size)) == NULL) { - printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic)); + inq_lbp_task = NULL; + inquiry(sd, &inq_lbp_task, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, + full_size, EXPECT_STATUS_GOOD); + if (inq_lbp_task == NULL) { + printf("Inquiry command failed : %s\n", sd->error_str); return -1; } } @@ -1164,32 +1214,29 @@ main(int argc, char *argv[]) } } - rsop_task = iscsi_report_supported_opcodes_sync(iscsic, lun, - 1, SCSI_REPORT_SUPPORTING_OPS_ALL, 0, 0, 65535); + rsop_task = NULL; + report_supported_opcodes(sd, &rsop_task, 1, SCSI_REPORT_SUPPORTING_OPS_ALL, 0, 0, 65535, + EXPECT_STATUS_GOOD); if (rsop_task == NULL) { - printf("Failed to send REPORT_SUPPORTED_OPCODES command: %s\n", - iscsi_get_error(iscsic)); - iscsi_destroy_context(iscsic); + printf("Failed to send REPORT_SUPPORTED_OPCODES command: %s\n", sd->error_str); + free_scsi_device(sd); return -1; } if (rsop_task->status == SCSI_STATUS_GOOD) { rsop = scsi_datain_unmarshall(rsop_task); if (rsop == NULL) { - printf("failed to unmarshall REPORT_SUPPORTED_OPCODES " - "data. %s\n", - iscsi_get_error(iscsic)); + printf("failed to unmarshall REPORT_SUPPORTED_OPCODES data.\n"); scsi_free_scsi_task(rsop_task); } } /* check if the device is write protected or not */ - task = iscsi_modesense6_sync(iscsic, lun, 0, SCSI_MODESENSE_PC_CURRENT, - SCSI_MODEPAGE_RETURN_ALL_PAGES, - 0, 255); + task = NULL; + modesense6(sd, &task, 0, SCSI_MODESENSE_PC_CURRENT, SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 255, + EXPECT_STATUS_GOOD); if (task == NULL) { - printf("Failed to send MODE_SENSE6 command: %s\n", - iscsi_get_error(iscsic)); - iscsi_destroy_context(iscsic); + printf("Failed to send MODE_SENSE6 command: %s\n", sd->error_str); + free_scsi_device(sd); return -1; } if (task->status == SCSI_STATUS_GOOD) { @@ -1205,9 +1252,6 @@ main(int argc, char *argv[]) } scsi_free_scsi_task(task); - iscsi_logout_sync(iscsic); - iscsi_destroy_context(iscsic); - if (is_usb) { printf("USB device. Clamping maximum transfer length to 120k\n"); maximum_transfer_length = 120 *1024 / block_size; @@ -1243,7 +1287,6 @@ main(int argc, char *argv[]) } CU_cleanup_registry(); - free(discard_const(tgt_url)); if (inq_task != NULL) { scsi_free_scsi_task(inq_task); @@ -1263,6 +1306,7 @@ main(int argc, char *argv[]) if (rsop_task != NULL) { scsi_free_scsi_task(rsop_task); } + free_scsi_device(sd); return 0; } diff --git a/test-tool/iscsi-test-cu.h b/test-tool/iscsi-test-cu.h index 0b02db3..cd82f74 100644 --- a/test-tool/iscsi-test-cu.h +++ b/test-tool/iscsi-test-cu.h @@ -32,11 +32,7 @@ #include "iscsi-support.h" /* globals between setup, tests, and teardown */ -extern struct iscsi_context *iscsic; -extern int tgt_lun; extern struct scsi_task *task; -extern struct iscsi_context *iscsic2; -extern int tgt_lun2; extern unsigned char *read_write_buf; #ifndef HAVE_CU_SUITEINFO_PSETUPFUNC diff --git a/test-tool/test_compareandwrite_miscompare.c b/test-tool/test_compareandwrite_miscompare.c index cf88110..83ea2f5 100644 --- a/test-tool/test_compareandwrite_miscompare.c +++ b/test-tool/test_compareandwrite_miscompare.c @@ -53,8 +53,9 @@ test_compareandwrite_miscompare(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write16(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented."); CU_PASS("WRITE16 is not implemented."); @@ -71,9 +72,10 @@ test_compareandwrite_miscompare(void) "BlockLimits.MaximumCompareAndWriteLength(%d). " "Command should fail with INVALID_FIELD_IN_CDB", i, maxbl); - ret = compareandwrite_invalidfieldincdb(iscsic, tgt_lun, 0, - buf, 2 * i * block_size, block_size, - 0, 0, 0, 0); + ret = compareandwrite(sd, 0, + buf, 2 * i * block_size, + block_size, 0, 0, 0, 0, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support " "COMPARE_AND_WRITE. Skipping test"); @@ -88,8 +90,10 @@ test_compareandwrite_miscompare(void) logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' " "at LBA:0 (if they all contain 'A')", i); - ret = compareandwrite_miscompare(iscsic, tgt_lun, 0, - buf, 2 * i * block_size, block_size, 0, 0, 0, 0); + ret = compareandwrite(sd, 0, + buf, 2 * i * block_size, block_size, + 0, 0, 0, 0, + EXPECT_MISCOMPARE); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support " "COMPARE_AND_WRITE. Skipping test"); @@ -99,8 +103,9 @@ test_compareandwrite_miscompare(void) logging(LOG_VERBOSE, "Read %d blocks at LBA:0 and verify " "they are still unchanged as 'A'", i); - ret = read16(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read16(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); for (j = 0; j < i * block_size; j++) { @@ -123,8 +128,9 @@ test_compareandwrite_miscompare(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write16(iscsic, tgt_lun, num_blocks - i, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, num_blocks - i, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Change byte 27 from the end to 'C' so that it does not match."); @@ -136,9 +142,10 @@ test_compareandwrite_miscompare(void) "BlockLimits.MaximumCompareAndWriteLength(%d). " "Command should fail with INVALID_FIELD_IN_CDB", i, maxbl); - ret = compareandwrite_invalidfieldincdb(iscsic, tgt_lun, 0, - buf, 2 * i * block_size, block_size, - 0, 0, 0, 0); + ret = compareandwrite(sd, 0, + buf, 2 * i * block_size, + block_size, 0, 0, 0, 0, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); continue; @@ -148,16 +155,18 @@ test_compareandwrite_miscompare(void) logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' " "at LBA:%" PRIu64 " (if they all contain 'A')", i, num_blocks - i); - ret = compareandwrite_miscompare(iscsic, tgt_lun, - num_blocks - i, - buf, 2 * i * block_size, block_size, 0, 0, 0, 0); + ret = compareandwrite(sd, num_blocks - i, + buf, 2 * i * block_size, block_size, + 0, 0, 0, 0, + EXPECT_MISCOMPARE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Read %d blocks at LBA:%" PRIu64 "they are still unchanged as 'A'", i, num_blocks - i); - ret = read16(iscsic, tgt_lun, num_blocks - i, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read16(sd, num_blocks - i, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); for (j = 0; j < i * block_size; j++) { diff --git a/test-tool/test_compareandwrite_simple.c b/test-tool/test_compareandwrite_simple.c index 7e8b4c7..81b1fd0 100644 --- a/test-tool/test_compareandwrite_simple.c +++ b/test-tool/test_compareandwrite_simple.c @@ -54,8 +54,9 @@ test_compareandwrite_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write16(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented."); CU_PASS("WRITE16 is not implemented."); @@ -68,9 +69,10 @@ test_compareandwrite_simple(void) "BlockLimits.MaximumCompareAndWriteLength(%d). " "Command should fail with INVALID_FIELD_IN_CDB", i, maxbl); - ret = compareandwrite_invalidfieldincdb(iscsic, tgt_lun, 0, - buf, 2 * i * block_size, block_size, - 0, 0, 0, 0); + ret = compareandwrite(sd, 0, + buf, 2 * i * block_size, + block_size, 0, 0, 0, 0, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support " "COMPARE_AND_WRITE. Skipping test"); @@ -85,9 +87,10 @@ test_compareandwrite_simple(void) logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' " "at LBA:0 (if they all contain 'A')", i); - ret = compareandwrite(iscsic, tgt_lun, 0, - buf, 2 * i * block_size, block_size, - 0, 0, 0, 0); + ret = compareandwrite(sd, 0, + buf, 2 * i * block_size, block_size, + 0, 0, 0, 0, + EXPECT_STATUS_GOOD); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support " "COMPARE_AND_WRITE. Skipping test"); @@ -97,8 +100,9 @@ test_compareandwrite_simple(void) logging(LOG_VERBOSE, "Read %d blocks at LBA:0 and verify " "they are all 'B'", i); - ret = read16(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read16(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); for (j = 0; j < i * block_size; j++) { @@ -122,8 +126,9 @@ test_compareandwrite_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write16(iscsic, tgt_lun, num_blocks - i, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, num_blocks - i, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (i > maxbl) { @@ -131,9 +136,10 @@ test_compareandwrite_simple(void) "BlockLimits.MaximumCompareAndWriteLength(%d). " "Command should fail with INVALID_FIELD_IN_CDB", i, maxbl); - ret = compareandwrite_invalidfieldincdb(iscsic, tgt_lun, 0, - buf, 2 * i * block_size, block_size, - 0, 0, 0, 0); + ret = compareandwrite(sd, 0, + buf, 2 * i * block_size, + block_size, 0, 0, 0, 0, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); continue; @@ -143,15 +149,18 @@ test_compareandwrite_simple(void) logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' " "at LBA:%" PRIu64 " (if they all contain 'A')", i, num_blocks - i); - ret = compareandwrite(iscsic, tgt_lun, num_blocks - i, - buf, 2 * i * block_size, block_size, 0, 0, 0, 0); + ret = compareandwrite(sd, num_blocks - i, + buf, 2 * i * block_size, block_size, + 0, 0, 0, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Read %d blocks at LBA:%" PRIu64 " and verify they are all 'B'", i, num_blocks - i); - ret = read16(iscsic, tgt_lun, num_blocks - i, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read16(sd, num_blocks - i, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); for (j = 0; j < i * block_size; j++) { diff --git a/test-tool/test_get_lba_status_beyond_eol.c b/test-tool/test_get_lba_status_beyond_eol.c index 202fbfa..100e899 100644 --- a/test-tool/test_get_lba_status_beyond_eol.c +++ b/test-tool/test_get_lba_status_beyond_eol.c @@ -33,7 +33,8 @@ test_get_lba_status_beyond_eol(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test GET_LBA_STATUS one block beyond the end of the LUN"); - ret = get_lba_status_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 24); + ret = get_lba_status(sd, NULL, num_blocks + 1, 24, + EXPECT_LBA_OOB); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support GET_LBA_STATUS. Skipping test"); return; @@ -42,11 +43,13 @@ test_get_lba_status_beyond_eol(void) logging(LOG_VERBOSE, "Test GET_LBA_STATUS at LBA 2^63"); - ret = get_lba_status_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000ULL, 24); + ret = get_lba_status(sd, NULL, 0x8000000000000000ULL, 24, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test GET_LBA_STATUS at LBA -1"); - ret = get_lba_status_lbaoutofrange(iscsic, tgt_lun, 0xffffffffffffffffULL, 24); + ret = get_lba_status(sd, NULL, 0xffffffffffffffffULL, 24, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_get_lba_status_simple.c b/test-tool/test_get_lba_status_simple.c index 52b0f97..03258e9 100644 --- a/test-tool/test_get_lba_status_simple.c +++ b/test-tool/test_get_lba_status_simple.c @@ -33,7 +33,8 @@ test_get_lba_status_simple(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test GET_LBA_STATUS of 1-256 blocks at the start of the LUN"); for (i = 1; i <= 256; i++) { - ret = get_lba_status(iscsic, tgt_lun, 0, 24, NULL); + ret = get_lba_status(sd, NULL,0, 24, + EXPECT_STATUS_GOOD); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support GET_LBA_STATUS. Skipping test"); return; @@ -47,7 +48,8 @@ test_get_lba_status_simple(void) logging(LOG_VERBOSE, "Test GET_LBA_STATUS of 1-256 blocks at the end of the LUN"); for (i = 1; i <= 256; i++) { - ret = get_lba_status(iscsic, tgt_lun, num_blocks - i, 24, NULL); + ret = get_lba_status(sd, NULL, num_blocks - i, 24, + EXPECT_STATUS_GOOD); if (ret != 0) { CU_FAIL("[FAILED] GET_LBA_STATUS command failed"); return; diff --git a/test-tool/test_get_lba_status_unmap_single.c b/test-tool/test_get_lba_status_unmap_single.c index a41e7d1..e174c02 100644 --- a/test-tool/test_get_lba_status_unmap_single.c +++ b/test-tool/test_get_lba_status_unmap_single.c @@ -25,7 +25,6 @@ #include "iscsi-support.h" #include "iscsi-test-cu.h" - void test_get_lba_status_unmap_single(void) { @@ -33,7 +32,9 @@ test_get_lba_status_unmap_single(void) uint64_t i; unsigned char *buf = alloca(257 * block_size); struct unmap_list list[1]; - enum scsi_provisioning_type provisioning; + struct scsi_task *t = NULL; + struct scsi_get_lba_status *lbas = NULL; + struct scsi_lba_status_descriptor *lbasd = NULL; CHECK_FOR_DATALOSS; CHECK_FOR_THIN_PROVISIONING; @@ -49,8 +50,9 @@ test_get_lba_status_unmap_single(void) logging(LOG_VERBOSE, "Write the first %i blocks with a known " "pattern and thus map the blocks", 256 + lbppb); - ret = write10(iscsic, tgt_lun, 0, (256 + lbppb) * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, 0, (256 + lbppb) * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); for (i = 0; i + lbppb <= 256; i += lbppb) { @@ -58,12 +60,14 @@ test_get_lba_status_unmap_single(void) PRIu64 " (number of logical blocks: %d)", i, lbppb); list[0].lba = i; list[0].num = lbppb; - ret = unmap(iscsic, tgt_lun, 0, list, 1); + ret = unmap(sd, 0, list, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Read the status of the block at LBA:%" PRIu64, i); - ret = get_lba_status(iscsic, tgt_lun, i, 24, NULL); + ret = get_lba_status(sd, NULL, i, 24, + EXPECT_STATUS_GOOD); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support GET_LBA_STATUS. Skipping test"); return; @@ -74,15 +78,36 @@ test_get_lba_status_unmap_single(void) } logging(LOG_VERBOSE, "Read the status of the block at LBA:%" PRIu64, i + lbppb); - ret = get_lba_status(iscsic, tgt_lun, i + lbppb, 24, &provisioning); + ret = get_lba_status(sd, &t, i + lbppb, 24, + EXPECT_STATUS_GOOD); if (ret != 0) { CU_FAIL("[FAILED] GET_LBA_STATUS command failed"); return; } - if (provisioning != SCSI_PROVISIONING_TYPE_MAPPED) { + if (t == NULL) { + CU_FAIL("[FAILED] GET_LBA_STATUS task is NULL"); + return; + } + lbas = scsi_datain_unmarshall(t); + if (lbas == NULL) { + CU_FAIL("[FAILED] GET_LBA_STATUS command: failed " + "to unmarshall data."); + scsi_free_scsi_task(t); + return; + } + lbasd = &lbas->descriptors[0]; + if (lbasd->lba != i + lbppb) { + CU_FAIL("[FAILED] GET_LBA_STATUS command: " + "lba offset in first descriptor does not " + "match request."); + scsi_free_scsi_task(t); + return; + } + if (lbasd->provisioning != SCSI_PROVISIONING_TYPE_MAPPED) { CU_FAIL("[FAILED] LBA should be mapped but isn't"); return; } + scsi_free_scsi_task(t); } logging(LOG_VERBOSE, LOG_BLANK_LINE); @@ -91,18 +116,21 @@ test_get_lba_status_unmap_single(void) for (i = lbppb; i + lbppb <= 256; i += lbppb) { logging(LOG_VERBOSE, "Write the first %i blocks with a known " "pattern and thus map the blocks", (256 + lbppb)); - ret = write10(iscsic, tgt_lun, 0, (256 + lbppb) * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, 0, (256 + lbppb) * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Unmap %" PRIu64 " blocks at LBA 0", i); list[0].lba = 0; list[0].num = i; - ret = unmap(iscsic, tgt_lun, 0, list, 1); + ret = unmap(sd, 0, list, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Read the status of the block at LBA:0"); - ret = get_lba_status(iscsic, tgt_lun, 0, 24, NULL); + ret = get_lba_status(sd, NULL, 0, 24, + EXPECT_STATUS_GOOD); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support GET_LBA_STATUS. Skipping test"); return; @@ -112,14 +140,35 @@ test_get_lba_status_unmap_single(void) return; } logging(LOG_VERBOSE, "Read the status of the block at LBA:%" PRIu64, i + 1); - ret = get_lba_status(iscsic, tgt_lun, i + 1, 24, &provisioning); + ret = get_lba_status(sd, &t, i + 1, 24, + EXPECT_STATUS_GOOD); if (ret != 0) { CU_FAIL("[FAILED] GET_LBA_STATUS command failed"); return; } - if (provisioning != SCSI_PROVISIONING_TYPE_MAPPED) { + if (t == NULL) { + CU_FAIL("[FAILED] GET_LBA_STATUS task is NULL"); + return; + } + lbas = scsi_datain_unmarshall(t); + if (lbas == NULL) { + CU_FAIL("[FAILED] GET_LBA_STATUS command: failed " + "to unmarshall data."); + scsi_free_scsi_task(t); + return; + } + lbasd = &lbas->descriptors[0]; + if (lbasd->lba != i + lbppb) { + CU_FAIL("[FAILED] GET_LBA_STATUS command: " + "lba offset in first descriptor does not " + "match request."); + scsi_free_scsi_task(t); + return; + } + if (lbasd->provisioning != SCSI_PROVISIONING_TYPE_MAPPED) { CU_FAIL("[FAILED] LBA should be mapped but isn't"); return; } + scsi_free_scsi_task(t); } } diff --git a/test-tool/test_inquiry_alloc_length.c b/test-tool/test_inquiry_alloc_length.c index 0d761cd..1634479 100644 --- a/test-tool/test_inquiry_alloc_length.c +++ b/test-tool/test_inquiry_alloc_length.c @@ -34,14 +34,14 @@ test_inquiry_alloc_length(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test of the INQUIRY allocation length"); - logging(LOG_VERBOSE, "Verify we can read standard INQUIRY page with alloc length from 5-255"); for (i = 5; i < 256 ; i++) { if (task != NULL) { scsi_free_scsi_task(task); task = NULL; } - ret = inquiry(iscsic, tgt_lun, 0, 0, i, &task); + ret = inquiry(sd, &task, 0, 0, i, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Verify we got at least 36 bytes of data when reading with alloc length 255"); @@ -83,11 +83,13 @@ test_inquiry_alloc_length(void) logging(LOG_VERBOSE, "Version is SPC-3 or later. Read INQUIRY data using 16-bit allocation length"); logging(LOG_VERBOSE, "Read INQUIRY data with allocation length 511 (low order byte is 0xff)"); - ret = inquiry(iscsic, tgt_lun, 0, 0, 511, &task); + ret = inquiry(sd, &task, 0, 0, 511, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Read INQUIRY data with allocation length 512 (low order byte is 0x00)"); - ret = inquiry(iscsic, tgt_lun, 0, 0, 512, &task2); + ret = inquiry(sd, &task2, 0, 0, 512, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "INQUIRY data should be the same when allocation length is 511 and 512 bytes"); diff --git a/test-tool/test_inquiry_block_limits.c b/test-tool/test_inquiry_block_limits.c index 3b2d108..3976088 100644 --- a/test-tool/test_inquiry_block_limits.c +++ b/test-tool/test_inquiry_block_limits.c @@ -24,10 +24,19 @@ #include "iscsi-support.h" #include "iscsi-test-cu.h" +static void check_lbp(int *supports_lbp) +{ + *supports_lbp = 0; + + CHECK_FOR_THIN_PROVISIONING; + + *supports_lbp = 1; +} + void test_inquiry_block_limits(void) { - int ret; + int supports_lbp, ret; struct scsi_inquiry_block_limits *bl; struct scsi_task *bl_task = NULL; struct scsi_inquiry_logical_block_provisioning *lbp = NULL; @@ -38,10 +47,11 @@ test_inquiry_block_limits(void) CHECK_FOR_SBC; - logging(LOG_VERBOSE, "Block device. Verify that we can read Block Limits VPD"); - ret = inquiry(iscsic, tgt_lun, - 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, - 64, &bl_task); + logging(LOG_VERBOSE, "Block device. Verify that we can read Block " + "Limits VPD"); + ret = inquiry(sd, &bl_task, + 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, 255, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (ret != 0) { logging(LOG_NORMAL, "[FAILURE] failed to send inquiry."); @@ -57,59 +67,63 @@ test_inquiry_block_limits(void) goto finished; } - logging(LOG_VERBOSE, "Verify that the PageLength matches up with the size of the DATA-IN buffer."); + logging(LOG_VERBOSE, "Verify that the PageLength matches up with the " + "size of the DATA-IN buffer."); CU_ASSERT_EQUAL(bl_task->datain.size, bl_task->datain.data[3] + 4); if (bl_task->datain.size != bl_task->datain.data[3] + 4) { logging(LOG_NORMAL, "[FAILURE] Invalid PageLength returned. " "Was %d but expected %d", bl_task->datain.data[3], bl_task->datain.size - 4); } else { - logging(LOG_VERBOSE, "[SUCCESS] PageLength matches DataIn buffer size"); + logging(LOG_VERBOSE, "[SUCCESS] PageLength matches DataIn " + "buffer size"); } logging(LOG_VERBOSE, "Verify that the PageLength matches SCSI-level."); /* if it is not SBC3 then we assume it must be SBC2 */ if (sbc3_support) { - logging(LOG_VERBOSE, "Device claims SBC-3. Verify that " "PageLength == 0x3C"); + logging(LOG_VERBOSE, "Device claims SBC-3. Verify that " "page size is >= 60"); } else { logging(LOG_VERBOSE, "Device is not SBC-3. Verify that " - "PageLength == 0x0C (but allow 0x3C too. Some SBC-2 " + "PageLength == 8 (but allow >= 60 too. Some SBC-2 " "devices support some SBC-3 features."); } - switch (bl_task->datain.data[3]) { - case 0x3c: - /* accept 0x3c (==SBC-3) for all levels */ - if (!sbc3_support) { - logging(LOG_NORMAL, "[WARNING] SBC-3 pagelength (0x3C) " - "returned but SBC-3 support was not claimed " - "in the standard inquiry page."); - } - break; - case 0x0c: - /* only accept 0x0c for levels < SBC-3 */ - if (!sbc3_support) { - break; - } - /* fallthrough */ - default: - CU_FAIL("[FAILED] Invalid pagelength returned"); - logging(LOG_NORMAL, "[FAILURE] Invalid PageLength returned."); - } + if (bl_task->datain.data[3] == 8) { + if (sbc3_support) { + logging(LOG_NORMAL, "[FAILURE] Invalid PageLength " + "returned. SBC3 claimed but page length " + "is 8."); + CU_FAIL("[FAILED] Invalid pagelength returned. " + "SBC3 claimed but page length is 8."); + } + } else if (bl_task->datain.size >= 60) { + if (!sbc3_support) { + logging(LOG_NORMAL, "[WARNING] SBC-3 pagelength " + "(>=60) returned but SBC-3 support was not " + "claimed in the standard inquiry page."); + CU_FAIL("[WARNING] SBC-3 pagelength " + "(>=60) returned but SBC-3 support was not " + "claimed in the standard inquiry page."); + } + } if (bl_task->datain.data[3] != 0x3c) { goto finished; } + check_lbp(&supports_lbp); + if (!supports_lbp) + goto finished; /* * MAXIMUM UNMAP LBA COUNT * MAXIMUM UNMAP BLOCK DESCRIPTOR COUNT */ logging(LOG_VERBOSE, "Try reading the logical block provisioning VPD"); - ret = inquiry(iscsic, tgt_lun, - 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, - 64, &lbp_task); + ret = inquiry(sd, &lbp_task, + 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, 255, + EXPECT_STATUS_GOOD); if (ret == 0) { lbp = scsi_datain_unmarshall(lbp_task); if (lbp == NULL) { diff --git a/test-tool/test_inquiry_evpd.c b/test-tool/test_inquiry_evpd.c index e791f1a..ad580d0 100644 --- a/test-tool/test_inquiry_evpd.c +++ b/test-tool/test_inquiry_evpd.c @@ -33,6 +33,7 @@ test_inquiry_evpd(void) logging(LOG_VERBOSE, "Test of the INQUIRY EVPD bit"); logging(LOG_VERBOSE, "Verify that INQUIRY with EVPD==0 and PC!=0 is an error"); - ret = inquiry_invalidfieldincdb(iscsic, tgt_lun, 0, 1, 256); + ret = inquiry(sd, NULL, 0, 1, 256, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_inquiry_mandatory_vpd_sbc.c b/test-tool/test_inquiry_mandatory_vpd_sbc.c index 00926aa..d9366cf 100644 --- a/test-tool/test_inquiry_mandatory_vpd_sbc.c +++ b/test-tool/test_inquiry_mandatory_vpd_sbc.c @@ -36,14 +36,14 @@ test_inquiry_mandatory_vpd_sbc(void) logging(LOG_VERBOSE, "SUPPORTED_VPD_PAGES is mandatory for SBC devices. Verify we can read it."); - ret = inquiry(iscsic, tgt_lun, - 1, SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES, - 255, NULL); + ret = inquiry(sd, NULL, + 1, SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES, 255, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "DEVICE_IDENTIFICATION is mandatory for SBC devices. Verify we can read it."); - ret = inquiry(iscsic, tgt_lun, - 1, SCSI_INQUIRY_PAGECODE_DEVICE_IDENTIFICATION, - 255, NULL); + ret = inquiry(sd, NULL, + 1, SCSI_INQUIRY_PAGECODE_DEVICE_IDENTIFICATION, 255, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_inquiry_standard.c b/test-tool/test_inquiry_standard.c index 76d33c7..4ea35f4 100644 --- a/test-tool/test_inquiry_standard.c +++ b/test-tool/test_inquiry_standard.c @@ -35,7 +35,8 @@ test_inquiry_standard(void) logging(LOG_VERBOSE, "Verify we can read standard INQUIRY page"); /* 260 bytes is the maximum possible size of the standard vpd */ - ret = inquiry(iscsic, tgt_lun, 0, 0, 260, &task); + ret = inquiry(sd, &task, 0, 0, 260, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we got at least 36 bytes of data"); @@ -82,13 +83,29 @@ test_inquiry_standard(void) CU_ASSERT_EQUAL(std_inq->response_data_format, 2); logging(LOG_VERBOSE, "Verify additional-length is correct"); - if (std_inq->additional_length != task->datain.size - 5) { + if (std_inq->additional_length > task->datain.size - 5) { logging(LOG_NORMAL, "[FAILED] Bad additional length " "returned. Should be %d but device returned %d.", task->datain.size - 5, std_inq->additional_length); + logging(LOG_NORMAL, "[FAILED] Additional length points " + "beyond end of data"); + CU_FAIL("Additional length points beyond end of data"); + } + if (std_inq->additional_length < task->datain.size - 5) { + logging(LOG_NORMAL, "[WARNING] Bad additional length " + "returned. Should be %d but device returned %d. ", + task->datain.size - 5, + std_inq->additional_length); + logging(LOG_VERBOSE, "Verify that all padding data is 0"); + for (i = std_inq->additional_length + 6; i < task->datain.size; i++) { + if (!task->datain.data[i]) + continue; + logging(LOG_NORMAL, "[FAILED] Padding data is not zero." + " Are we leaking data?"); + CU_FAIL("Padding data is not zero. Leaking data?"); + } } - CU_ASSERT_EQUAL(std_inq->additional_length, task->datain.size - 5); logging(LOG_VERBOSE, "Verify VENDOR_IDENTIFICATION is in ASCII"); for (i = 8; i < 16; i++) { diff --git a/test-tool/test_inquiry_supported_vpd.c b/test-tool/test_inquiry_supported_vpd.c index cc21efa..8bc00fc 100644 --- a/test-tool/test_inquiry_supported_vpd.c +++ b/test-tool/test_inquiry_supported_vpd.c @@ -34,9 +34,9 @@ test_inquiry_supported_vpd(void) logging(LOG_VERBOSE, "Test INQUIRY supported VPD pages"); logging(LOG_VERBOSE, "Verify we can read the SUPPORTED VPD page"); - ret = inquiry(iscsic, tgt_lun, - 1, SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES, - 255, &task); + ret = inquiry(sd, &task, + 1, SCSI_INQUIRY_PAGECODE_SUPPORTED_VPD_PAGES, 255, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we got at least 4 bytes of data"); @@ -56,9 +56,8 @@ test_inquiry_supported_vpd(void) logging(LOG_VERBOSE, "Verify we can read page 0x%02x", sup_inq->pages[i]); - ret = inquiry(iscsic, tgt_lun, - 1, sup_inq->pages[i], - 255, NULL); + ret = inquiry(sd, NULL, 1, sup_inq->pages[i], 255, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_iscsi_cmdsn_toohigh.c b/test-tool/test_iscsi_cmdsn_toohigh.c index 7d24a1a..eb7aa53 100644 --- a/test-tool/test_iscsi_cmdsn_toohigh.c +++ b/test-tool/test_iscsi_cmdsn_toohigh.c @@ -51,20 +51,29 @@ void test_iscsi_cmdsn_toohigh(void) logging(LOG_VERBOSE, "Test sending invalid iSCSI CMDSN"); logging(LOG_VERBOSE, "CMDSN MUST be in the range EXPCMDSN and MAXCMDSN"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + logging(LOG_VERBOSE, "RFC3720:3.2.2.1 CMDSN > MAXCMDSN must be silently ignored by the target"); logging(LOG_VERBOSE, "Send a TESTUNITREADY with CMDSN == MAXCMDSN+1. Should be ignored by the target."); - iscsic->use_immediate_data = ISCSI_IMMEDIATE_DATA_NO; - iscsic->target_max_recv_data_segment_length = block_size; + sd->iscsi_ctx->use_immediate_data = ISCSI_IMMEDIATE_DATA_NO; + sd->iscsi_ctx->target_max_recv_data_segment_length = block_size; local_iscsi_queue_pdu = my_iscsi_queue_pdu; change_cmdsn = 1; /* we don't want autoreconnect since some targets will incorrectly * drop the connection on this condition. */ - iscsi_set_noautoreconnect(iscsic, 1); - iscsi_set_timeout(iscsic, 3); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); + iscsi_set_timeout(sd->iscsi_ctx, 3); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, -1); if (ret == -1) { logging(LOG_VERBOSE, "[SUCCESS] We did not receive a reply"); @@ -73,9 +82,10 @@ void test_iscsi_cmdsn_toohigh(void) } - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Send a TESTUNITREADY with CMDSN == EXPCMDSN. should work again"); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_iscsi_cmdsn_toolow.c b/test-tool/test_iscsi_cmdsn_toolow.c index 33257ba..c9cbc40 100644 --- a/test-tool/test_iscsi_cmdsn_toolow.c +++ b/test-tool/test_iscsi_cmdsn_toolow.c @@ -51,20 +51,29 @@ void test_iscsi_cmdsn_toolow(void) logging(LOG_VERBOSE, "Test sending invalid iSCSI CMDSN"); logging(LOG_VERBOSE, "CMDSN MUST be in the range EXPCMDSN and MAXCMDSN"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + logging(LOG_VERBOSE, "RFC3720:3.2.2.1 CMDSN < EXPCMDSN must be silently ignored by the target"); logging(LOG_VERBOSE, "Send a TESTUNITREADY with CMDSN == EXPCMDSN-1. Should be ignored by the target."); - iscsic->use_immediate_data = ISCSI_IMMEDIATE_DATA_NO; - iscsic->target_max_recv_data_segment_length = block_size; + sd->iscsi_ctx->use_immediate_data = ISCSI_IMMEDIATE_DATA_NO; + sd->iscsi_ctx->target_max_recv_data_segment_length = block_size; local_iscsi_queue_pdu = my_iscsi_queue_pdu; change_cmdsn = 1; /* we don't want autoreconnect since some targets will incorrectly * drop the connection on this condition. */ - iscsi_set_noautoreconnect(iscsic, 1); - iscsi_set_timeout(iscsic, 3); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); + iscsi_set_timeout(sd->iscsi_ctx, 3); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, -1); if (ret == -1) { logging(LOG_VERBOSE, "[SUCCESS] We did not receive a reply"); @@ -74,9 +83,10 @@ void test_iscsi_cmdsn_toolow(void) - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Send a TESTUNITREADY with CMDSN == EXPCMDSN. should work again"); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_iscsi_datasn_invalid.c b/test-tool/test_iscsi_datasn_invalid.c index 029395a..61cbae7 100644 --- a/test-tool/test_iscsi_datasn_invalid.c +++ b/test-tool/test_iscsi_datasn_invalid.c @@ -35,19 +35,19 @@ static int my_iscsi_queue_pdu(struct iscsi_context *iscsi _U_, struct iscsi_pdu } switch (change_datasn) { case 1: - /* change datasn to 0 */ + /* change DataSN to 0 */ scsi_set_uint32(&pdu->outdata.data[36], 0); break; case 2: - /* change datasn to 27 */ + /* change DataSN to 27 */ scsi_set_uint32(&pdu->outdata.data[36], 27); break; case 3: - /* change datasn to -1 */ + /* change DataSN to -1 */ scsi_set_uint32(&pdu->outdata.data[36], -1); break; case 4: - /* change datasn from (0,1) to (1,0) */ + /* change DataSN from (0,1) to (1,0) */ datasn = scsi_get_uint32(&pdu->outdata.data[36]); scsi_set_uint32(&pdu->outdata.data[36], 1 - datasn); break; @@ -63,20 +63,28 @@ void test_iscsi_datasn_invalid(void) CHECK_FOR_DATALOSS; logging(LOG_VERBOSE, LOG_BLANK_LINE); - logging(LOG_VERBOSE, "Test sending invalid iSCSI DATASN"); + logging(LOG_VERBOSE, "Test sending invalid iSCSI DataSN"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } - logging(LOG_VERBOSE, "Send 2 DATAIN with DATASN==0. Should fail."); + logging(LOG_VERBOSE, "Send two Data-Out PDU's with DataSN==0. Should fail."); change_datasn = 1; - iscsic->use_immediate_data = ISCSI_IMMEDIATE_DATA_NO; - iscsic->target_max_recv_data_segment_length = block_size; + sd->iscsi_ctx->use_immediate_data = ISCSI_IMMEDIATE_DATA_NO; + sd->iscsi_ctx->target_max_recv_data_segment_length = block_size; local_iscsi_queue_pdu = my_iscsi_queue_pdu; - iscsi_set_noautoreconnect(iscsic, 1); - iscsi_set_timeout(iscsic, 3); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); + iscsi_set_timeout(sd->iscsi_ctx, 3); - ret = write10(iscsic, tgt_lun, 100, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, 100, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE10 is not implemented."); CU_PASS("WRITE10 is not implemented."); @@ -85,20 +93,21 @@ void test_iscsi_datasn_invalid(void) } CU_ASSERT_NOT_EQUAL(ret, 0); - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); - logging(LOG_VERBOSE, "Send DATAIN with DATASN==27. Should fail"); + logging(LOG_VERBOSE, "Send Data-Out PDU with DataSN==27. Should fail"); change_datasn = 2; - iscsic->use_immediate_data = ISCSI_IMMEDIATE_DATA_NO; - iscsic->target_max_recv_data_segment_length = block_size; + sd->iscsi_ctx->use_immediate_data = ISCSI_IMMEDIATE_DATA_NO; + sd->iscsi_ctx->target_max_recv_data_segment_length = block_size; local_iscsi_queue_pdu = my_iscsi_queue_pdu; - iscsi_set_noautoreconnect(iscsic, 1); - iscsi_set_timeout(iscsic, 3); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); + iscsi_set_timeout(sd->iscsi_ctx, 3); - ret = write10(iscsic, tgt_lun, 100, block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, 100, block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE10 is not implemented."); CU_PASS("WRITE10 is not implemented."); @@ -107,20 +116,21 @@ void test_iscsi_datasn_invalid(void) } CU_ASSERT_NOT_EQUAL(ret, 0); - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); - logging(LOG_VERBOSE, "Send DATAIN with DATASN==-1. Should fail"); + logging(LOG_VERBOSE, "Send Data-Out PDU with DataSN==-1. Should fail"); change_datasn = 3; - iscsic->use_immediate_data = ISCSI_IMMEDIATE_DATA_NO; - iscsic->target_max_recv_data_segment_length = block_size; + sd->iscsi_ctx->use_immediate_data = ISCSI_IMMEDIATE_DATA_NO; + sd->iscsi_ctx->target_max_recv_data_segment_length = block_size; local_iscsi_queue_pdu = my_iscsi_queue_pdu; - iscsi_set_noautoreconnect(iscsic, 1); - iscsi_set_timeout(iscsic, 3); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); + iscsi_set_timeout(sd->iscsi_ctx, 3); - ret = write10(iscsic, tgt_lun, 100, block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, 100, block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE10 is not implemented."); CU_PASS("WRITE10 is not implemented."); @@ -129,21 +139,22 @@ void test_iscsi_datasn_invalid(void) } CU_ASSERT_NOT_EQUAL(ret, 0); - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); - logging(LOG_VERBOSE, "Send DATAIN in reverse order (datasn == 1,0). Should fail"); + logging(LOG_VERBOSE, "Send Data-Out PDU's in reverse order (DataSN == 1,0). Should fail"); change_datasn = 4; - iscsic->use_immediate_data = ISCSI_IMMEDIATE_DATA_NO; - iscsic->target_max_recv_data_segment_length = block_size; + sd->iscsi_ctx->use_immediate_data = ISCSI_IMMEDIATE_DATA_NO; + sd->iscsi_ctx->target_max_recv_data_segment_length = block_size; local_iscsi_queue_pdu = my_iscsi_queue_pdu; - iscsi_set_noautoreconnect(iscsic, 1); - iscsi_set_timeout(iscsic, 3); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); + iscsi_set_timeout(sd->iscsi_ctx, 3); - ret = write10(iscsic, tgt_lun, 100, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, 100, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE10 is not implemented."); CU_PASS("WRITE10 is not implemented."); @@ -153,5 +164,5 @@ void test_iscsi_datasn_invalid(void) CU_ASSERT_NOT_EQUAL(ret, 0); local_iscsi_queue_pdu = NULL; - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); } diff --git a/test-tool/test_mandatory_sbc.c b/test-tool/test_mandatory_sbc.c index 6012955..9bc7d06 100644 --- a/test-tool/test_mandatory_sbc.c +++ b/test-tool/test_mandatory_sbc.c @@ -37,32 +37,38 @@ test_mandatory_sbc(void) CHECK_FOR_SBC; logging(LOG_VERBOSE, "Test INQUIRY."); - ret = inquiry(iscsic, tgt_lun, 0, 0, 255, NULL); + ret = inquiry(sd, NULL, 0, 0, 255, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READCAPACITY10."); - ret = readcapacity10(iscsic, tgt_lun, 0, 0); + ret = readcapacity10(sd, NULL, 0, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (sbc3_support) { logging(LOG_VERBOSE, "Test READCAPACITY16. The device claims SBC-3 support."); - ret = readcapacity16(iscsic, tgt_lun, 15); + ret = readcapacity16(sd, NULL, 15, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test READ10."); - ret = read10(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read10(sd, NULL, 0, block_size, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (sbc3_support) { logging(LOG_VERBOSE, "Test READ16. the device claims SBC-3 support."); - ret = read16(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read16(sd, 0, block_size, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test TESTUNITREADY."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_modesense6_all_pages.c b/test-tool/test_modesense6_all_pages.c index 7c96141..9cf9461 100644 --- a/test-tool/test_modesense6_all_pages.c +++ b/test-tool/test_modesense6_all_pages.c @@ -28,39 +28,28 @@ void test_modesense6_all_pages(void) { struct scsi_mode_sense *ms; + struct scsi_task *ms_task = NULL; + int ret; logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test of MODESENSE6 AllPages"); - if (task != NULL) { - scsi_free_scsi_task(task); - task = NULL; - } - logging(LOG_VERBOSE, "Send MODESENSE6 command to fetch AllPages"); - task = iscsi_modesense6_sync(iscsic, tgt_lun, 0, - SCSI_MODESENSE_PC_CURRENT, - SCSI_MODEPAGE_RETURN_ALL_PAGES, - 0, 255); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - logging(LOG_VERBOSE, "[FAILED] Failed to send MODE_SENSE6 " - "command:%s", - iscsi_get_error(iscsic)); - CU_FAIL("[FAILED] Failed to fetch the All Pages page."); - return; - } + ret = modesense6(sd, &ms_task, 0, SCSI_MODESENSE_PC_CURRENT, + SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 255, + EXPECT_STATUS_GOOD); + CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] All Pages fetched."); logging(LOG_VERBOSE, "Try to unmarshall the DATA-IN buffer."); - ms = scsi_datain_unmarshall(task); + ms = scsi_datain_unmarshall(ms_task); if (ms == NULL) { logging(LOG_VERBOSE, "[FAILED] failed to unmarshall mode sense " "datain buffer"); CU_FAIL("[FAILED] Failed to unmarshall the data-in buffer."); - scsi_free_scsi_task(task); - task = NULL; + scsi_free_scsi_task(ms_task); return; } logging(LOG_VERBOSE, "[SUCCESS] Unmarshalling successful."); @@ -75,8 +64,5 @@ test_modesense6_all_pages(void) CU_ASSERT_TRUE(ms->mode_data_length >= 3); - if (task != NULL) { - scsi_free_scsi_task(task); - task = NULL; - } + scsi_free_scsi_task(ms_task); } diff --git a/test-tool/test_modesense6_residuals.c b/test-tool/test_modesense6_residuals.c index fdb2f72..ab0dbbf 100644 --- a/test-tool/test_modesense6_residuals.c +++ b/test-tool/test_modesense6_residuals.c @@ -27,6 +27,9 @@ void test_modesense6_residuals(void) { + struct scsi_task *ms_task = NULL; + int ret; + logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test of MODESENSE6 Residuals"); @@ -36,95 +39,69 @@ test_modesense6_residuals(void) logging(LOG_VERBOSE, "Try a MODESENSE6 command with 4 bytes of " "transfer length and verify that we don't get residuals."); - if (task != NULL) { - scsi_free_scsi_task(task); - task = NULL; - } - task = iscsi_modesense6_sync(iscsic, tgt_lun, 0, - SCSI_MODESENSE_PC_CURRENT, - SCSI_MODEPAGE_RETURN_ALL_PAGES, - 0, 4); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - logging(LOG_VERBOSE, "[FAILED] Failed to send MODE_SENSE6 " - "command:%s", - iscsi_get_error(iscsic)); - CU_FAIL("[FAILED] Failed to fetch the All Pages page."); - return; - } + ret = modesense6(sd, &ms_task, 0, SCSI_MODESENSE_PC_CURRENT, + SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 4, + EXPECT_STATUS_GOOD); + CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] All Pages fetched."); logging(LOG_VERBOSE, "Verify that we got at most 4 bytes of DATA-IN"); - if (task->datain.size > 4) { + if (ms_task->datain.size > 4) { logging(LOG_NORMAL, "[FAILED] got more than 4 bytes of " "DATA-IN."); } else { logging(LOG_VERBOSE, "[SUCCESS] <= 4 bytes of DATA-IN " "received."); } - CU_ASSERT_TRUE(task->datain.size <= 4); + CU_ASSERT_TRUE(ms_task->datain.size <= 4); logging(LOG_VERBOSE, "Verify residual overflow flag not set"); - if (task->residual_status == SCSI_RESIDUAL_OVERFLOW) { + if (ms_task->residual_status == SCSI_RESIDUAL_OVERFLOW) { logging(LOG_VERBOSE, "[FAILED] Target set residual " "overflow flag"); } - CU_ASSERT_NOT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW); + CU_ASSERT_NOT_EQUAL(ms_task->residual_status, SCSI_RESIDUAL_OVERFLOW); logging(LOG_VERBOSE, "Try a MODESENSE6 command with 255 bytes of " "transfer length and verify that we get residuals if the target returns less than the requested amount of data."); - if (task != NULL) { - scsi_free_scsi_task(task); - task = NULL; - } - task = iscsi_modesense6_sync(iscsic, tgt_lun, 0, - SCSI_MODESENSE_PC_CURRENT, - SCSI_MODEPAGE_RETURN_ALL_PAGES, - 0, 255); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - logging(LOG_VERBOSE, "[FAILED] Failed to send MODE_SENSE6 " - "command:%s", - iscsi_get_error(iscsic)); - CU_FAIL("[FAILED] Failed to fetch the All Pages page."); - return; - } + scsi_free_scsi_task(ms_task); + ret = modesense6(sd, &ms_task, 0, SCSI_MODESENSE_PC_CURRENT, + SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 255, + EXPECT_STATUS_GOOD); + CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] All Pages fetched."); - - if (task->datain.size == 255) { + if (ms_task->datain.size == 255) { logging(LOG_VERBOSE, "We got all 255 bytes of data back " "from the target. Verify that underflow is not set."); - if (task->residual_status == SCSI_RESIDUAL_UNDERFLOW) { + if (ms_task->residual_status == SCSI_RESIDUAL_UNDERFLOW) { logging(LOG_VERBOSE, "[FAILED] Target set residual " "underflow flag"); } else { logging(LOG_VERBOSE, "[SUCCESS] Residual underflow " "is not set"); } - CU_ASSERT_NOT_EQUAL(task->residual_status, + CU_ASSERT_NOT_EQUAL(ms_task->residual_status, SCSI_RESIDUAL_UNDERFLOW); } else { logging(LOG_VERBOSE, "We got less than the requested 255 bytes " "from the target. Verify that underflow is set."); - if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) { + if (ms_task->residual_status != SCSI_RESIDUAL_UNDERFLOW) { logging(LOG_VERBOSE, "[FAILED] Target did not set " "residual underflow flag"); } else { logging(LOG_VERBOSE, "[SUCCESS] Residual underflow " "is set"); } - CU_ASSERT_EQUAL(task->residual_status, + CU_ASSERT_EQUAL(ms_task->residual_status, SCSI_RESIDUAL_UNDERFLOW); } - - if (task != NULL) { - scsi_free_scsi_task(task); - task = NULL; - } + scsi_free_scsi_task(ms_task); } diff --git a/test-tool/test_nomedia_sbc.c b/test-tool/test_nomedia_sbc.c index 3290341..b9dc0af 100644 --- a/test-tool/test_nomedia_sbc.c +++ b/test-tool/test_nomedia_sbc.c @@ -43,15 +43,18 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Eject the medium."); - ret = startstopunit(iscsic, tgt_lun, 1, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 1, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test TESTUNITREADY when medium is ejected."); - ret = testunitready_nomedium(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test SYNCHRONIZECACHE10 when medium is ejected."); - ret = synchronizecache10_nomedium(iscsic, tgt_lun, 0, 1, 1, 1); + ret = synchronizecache10(sd, 0, 1, 1, 1, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "SYNCHRONIZECACHE10"); @@ -60,7 +63,8 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test SYNCHRONIZECACHE16 when medium is ejected."); - ret = synchronizecache16_nomedium(iscsic, tgt_lun, 0, 1, 1, 1); + ret = synchronizecache16(sd, 0, 1, 1, 1, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "SYNCHRONIZECACHE16"); @@ -69,26 +73,31 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test READ10 when medium is ejected."); - ret = read10_nomedium(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read10(sd, NULL, 0, block_size, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ12 when medium is ejected."); - ret = read12_nomedium(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read12(sd, 0, block_size, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ16 when medium is ejected."); - ret = read16_nomedium(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read16(sd, 0, block_size, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READCAPACITY10 when medium is ejected."); - ret = readcapacity10_nomedium(iscsic, tgt_lun, 0, 0); + ret = readcapacity10(sd, NULL, 0, 0, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READCAPACITY16 when medium is ejected."); - ret = readcapacity16_nomedium(iscsic, tgt_lun, 15); + ret = readcapacity16(sd, NULL, 15, + EXPECT_NO_MEDIUM); if (ret == -2) { if (sbc3_support) { logging(LOG_NORMAL, "[FAILED] READCAPACITY16 is not available but the device claims SBC-3 support."); @@ -101,7 +110,8 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test GET_LBA_STATUS when medium is ejected."); - ret = get_lba_status_nomedium(iscsic, tgt_lun, 0, 24); + ret = get_lba_status(sd, NULL, 0, 24, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "GET_LBA_STATUS"); @@ -110,7 +120,8 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test PREFETCH10 when medium is ejected."); - ret = prefetch10_nomedium(iscsic, tgt_lun, 0, 1, 1, 0); + ret = prefetch10(sd, 0, 1, 1, 0, EXPECT_NO_MEDIUM); + if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "PREFETCH10"); @@ -119,7 +130,7 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test PREFETCH16 when medium is ejected."); - ret = prefetch16_nomedium(iscsic, tgt_lun, 0, 1, 1, 0); + ret = prefetch16(sd, 0, 1, 1, 0, EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "PREFETCH16"); @@ -128,8 +139,9 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test VERIFY10 when medium is ejected."); - ret = verify10_nomedium(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 1, buf); + ret = verify10(sd, 0, block_size, block_size, + 0, 0, 1, buf, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "VERIFY10"); @@ -138,8 +150,9 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test VERIFY12 when medium is ejected."); - ret = verify12_nomedium(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 1, buf); + ret = verify12(sd, 0, block_size, block_size, + 0, 0, 1, buf, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "VERIFY102"); @@ -148,8 +161,9 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test VERIFY16 when medium is ejected."); - ret = verify16_nomedium(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 1, buf); + ret = verify16(sd, 0, block_size, block_size, + 0, 0, 1, buf, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "VERIFY16"); @@ -163,23 +177,27 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test WRITE10 when medium is ejected."); - ret = write10_nomedium(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write10(sd, 0, block_size, block_size, + 0, 0, 0, 0, 0, buf, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE12 when medium is ejected."); - ret = write12_nomedium(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write12(sd, 0, block_size, block_size, + 0, 0, 0, 0, 0, buf, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE16 when medium is ejected."); - ret = write16_nomedium(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write16(sd, 0, block_size, block_size, + 0, 0, 0, 0, 0, buf, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITEVERIFY10 when medium is ejected."); - ret = writeverify10_nomedium(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify10(sd, 0, block_size, block_size, + 0, 0, 0, 0, buf, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "WRITEVERIFY10"); @@ -188,8 +206,9 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test WRITEVERIFY12 when medium is ejected."); - ret = writeverify12_nomedium(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify12(sd, 0, block_size, block_size, + 0, 0, 0, 0, buf, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "WRITEVERIFY12"); @@ -198,8 +217,9 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test WRITEVERIFY16 when medium is ejected."); - ret = writeverify16_nomedium(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify16(sd, 0, block_size, block_size, + 0, 0, 0, 0, buf, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "WRITEVERIFY16"); @@ -208,8 +228,9 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test ORWRITE when medium is ejected."); - ret = orwrite_nomedium(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = orwrite(sd, 0, block_size, block_size, + 0, 0, 0, 0, 0, buf, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "ORWRITE"); @@ -221,8 +242,9 @@ test_nomedia_sbc(void) logging(LOG_VERBOSE, "[SKIPPED] Test not implemented yet"); logging(LOG_VERBOSE, "Test WRITESAME10 when medium is ejected."); - ret = writesame10_nomedium(iscsic, tgt_lun, 0, block_size, - 1, 0, 0, 0, 0, buf); + ret = writesame10(sd, 0, block_size, + 1, 0, 0, 0, 0, buf, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "WRITESAME10"); @@ -231,8 +253,9 @@ test_nomedia_sbc(void) } logging(LOG_VERBOSE, "Test WRITESAME16 when medium is ejected."); - ret = writesame16_nomedium(iscsic, tgt_lun, 0, block_size, - 1, 0, 0, 0, 0, buf); + ret = writesame16(sd, 0, block_size, + 1, 0, 0, 0, 0, buf, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "WRITESAME16"); @@ -243,7 +266,8 @@ test_nomedia_sbc(void) logging(LOG_VERBOSE, "Test UNMAP when medium is ejected."); list[0].lba = 0; list[0].num = lbppb; - ret = unmap_nomedium(iscsic, tgt_lun, 0, list, 1); + ret = unmap(sd, 0, list, 1, + EXPECT_NO_MEDIUM); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] target does not support " "UNMAP"); @@ -254,6 +278,7 @@ test_nomedia_sbc(void) finished: logging(LOG_VERBOSE, "Load the medium again."); - ret = startstopunit(iscsic, tgt_lun, 1, 0, 0, 0, 1, 1); + ret = startstopunit(sd, 1, 0, 0, 0, 1, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_orwrite_0blocks.c b/test-tool/test_orwrite_0blocks.c index e3151c1..0d3b0e3 100644 --- a/test-tool/test_orwrite_0blocks.c +++ b/test-tool/test_orwrite_0blocks.c @@ -33,9 +33,9 @@ test_orwrite_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test ORWRITE 0-blocks at LBA==0"); - ret = orwrite(iscsic, tgt_lun, 0, - 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = orwrite(sd, 0, + 0, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] ORWRITE is not implemented."); CU_PASS("ORWRITE is not implemented."); @@ -44,22 +44,22 @@ test_orwrite_0blocks(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test ORWRITE 0-blocks one block past end-of-LUN"); - ret = orwrite_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, - 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = orwrite(sd, num_blocks + 1, + 0, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test ORWRITE 0-blocks at LBA==2^63"); - ret = orwrite_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000ULL, - 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = orwrite(sd, 0x8000000000000000ULL, + 0, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test ORWRITE 0-blocks at LBA==-1"); - ret = orwrite_lbaoutofrange(iscsic, tgt_lun, -1, - 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = orwrite(sd, -1, + 0, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_orwrite_beyond_eol.c b/test-tool/test_orwrite_beyond_eol.c index 6cbc907..a4745af 100644 --- a/test-tool/test_orwrite_beyond_eol.c +++ b/test-tool/test_orwrite_beyond_eol.c @@ -40,10 +40,9 @@ test_orwrite_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = orwrite_lbaoutofrange(iscsic, tgt_lun, - num_blocks + 1 - i, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = orwrite(sd, num_blocks + 1 - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] ORWRITE is not implemented."); CU_PASS("ORWRITE is not implemented."); @@ -58,10 +57,9 @@ test_orwrite_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = orwrite_lbaoutofrange(iscsic, tgt_lun, - 0x8000000000000000ULL, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = orwrite(sd, 0x8000000000000000ULL, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -71,10 +69,9 @@ test_orwrite_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = orwrite_lbaoutofrange(iscsic, tgt_lun, - -1, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = orwrite(sd, -1, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -84,10 +81,9 @@ test_orwrite_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = orwrite_lbaoutofrange(iscsic, tgt_lun, - num_blocks - 1, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = orwrite(sd, num_blocks - 1, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_orwrite_flags.c b/test-tool/test_orwrite_flags.c index 123a87b..3af9aa1 100644 --- a/test-tool/test_orwrite_flags.c +++ b/test-tool/test_orwrite_flags.c @@ -39,9 +39,9 @@ test_orwrite_flags(void) logging(LOG_VERBOSE, "Test ORWRITE flags"); logging(LOG_VERBOSE, "Test ORWRITE with DPO==1"); - ret = orwrite(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 0, 0, 0, buf); + ret = orwrite(sd, 0, + block_size, block_size, 0, 1, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support VERIFY16. Skipping test"); return; @@ -50,29 +50,29 @@ test_orwrite_flags(void) logging(LOG_VERBOSE, "Test ORWRITE with FUA==1 FUA_NV==0"); - ret = orwrite(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 0, 0, buf); + ret = orwrite(sd, 0, + block_size, block_size, 0, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test ORWRITE with FUA==1 FUA_NV==1"); - ret = orwrite(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 1, 0, buf); + ret = orwrite(sd, 0, + block_size, block_size, 0, 0, 1, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test ORWRITE with FUA==0 FUA_NV==1"); - ret = orwrite(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 0, 1, 0, buf); + ret = orwrite(sd, 0, + block_size, block_size, 0, 0, 0, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test ORWRITE with DPO==1 FUA==1 FUA_NV==1"); - ret = orwrite(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 1, 1, 0, buf); + ret = orwrite(sd, 0, + block_size, block_size, 0, 1, 1, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_orwrite_simple.c b/test-tool/test_orwrite_simple.c index 4eafb78..d1fb5c6 100644 --- a/test-tool/test_orwrite_simple.c +++ b/test-tool/test_orwrite_simple.c @@ -42,8 +42,9 @@ test_orwrite_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = orwrite(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = orwrite(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] ORWRITE is not implemented."); CU_PASS("ORWRITE is not implemented."); @@ -57,8 +58,9 @@ test_orwrite_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = orwrite(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, buf); + ret = orwrite(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_orwrite_verify.c b/test-tool/test_orwrite_verify.c index d4ad014..061f872 100644 --- a/test-tool/test_orwrite_verify.c +++ b/test-tool/test_orwrite_verify.c @@ -47,14 +47,16 @@ test_orwrite_verify(void) logging(LOG_VERBOSE, "Write %d blocks of all-zero", i); memset(buf, 0, block_size * i); - ret = write10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "OrWrite %d blocks with 0xa5", i); memset(buf, 0xa5, block_size * i); - ret = orwrite(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = orwrite(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] ORWRITE is not implemented."); CU_PASS("ORWRITE is not implemented."); @@ -63,8 +65,9 @@ test_orwrite_verify(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Read %d blocks back", i); - ret = read10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, readbuf); + ret = read10(sd, NULL, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, readbuf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the blocks are all 0xa5"); @@ -73,13 +76,15 @@ test_orwrite_verify(void) logging(LOG_VERBOSE, "OrWrite %d blocks with 0x5a", i); memset(buf, 0x5a, block_size * i); - ret = orwrite(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = orwrite(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Read %d blocks back", i); - ret = read10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, readbuf); + ret = read10(sd, NULL, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, readbuf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the blocks are all 0xff"); @@ -96,19 +101,22 @@ test_orwrite_verify(void) logging(LOG_VERBOSE, "Write %d blocks of all-zero", i); memset(buf, 0, block_size * i); - ret = write16(iscsic, tgt_lun, num_blocks - i, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, num_blocks - i, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "OrWrite %d blocks with 0xa5", i); memset(buf, 0xa5, block_size * i); - ret = orwrite(iscsic, tgt_lun, num_blocks - i, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = orwrite(sd, num_blocks - i, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Read %d blocks back", i); - ret = read16(iscsic, tgt_lun, num_blocks - i, i * block_size, - block_size, 0, 0, 0, 0, 0, readbuf); + ret = read16(sd, num_blocks - i, i * block_size, + block_size, 0, 0, 0, 0, 0, readbuf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the blocks are all 0xa5"); @@ -117,13 +125,15 @@ test_orwrite_verify(void) logging(LOG_VERBOSE, "OrWrite %d blocks with 0x5a", i); memset(buf, 0x5a, block_size * i); - ret = orwrite(iscsic, tgt_lun, num_blocks - i, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = orwrite(sd, num_blocks - i, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Read %d blocks back", i); - ret = read16(iscsic, tgt_lun, num_blocks - i, i * block_size, - block_size, 0, 0, 0, 0, 0, readbuf); + ret = read16(sd, num_blocks - i, i * block_size, + block_size, 0, 0, 0, 0, 0, readbuf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the blocks are all 0xff"); diff --git a/test-tool/test_orwrite_wrprotect.c b/test-tool/test_orwrite_wrprotect.c index 338f46e..fd1e6be 100644 --- a/test-tool/test_orwrite_wrprotect.c +++ b/test-tool/test_orwrite_wrprotect.c @@ -44,9 +44,10 @@ test_orwrite_wrprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = orwrite_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, block_size, - i, 0, 0, 0, 0, buf); + ret = orwrite(sd, 0, block_size, + block_size, i, 0, 0, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); + if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] ORWRITE is not implemented."); CU_PASS("ORWRITE is not implemented."); diff --git a/test-tool/test_prefetch10_0blocks.c b/test-tool/test_prefetch10_0blocks.c index 43c076a..51736fb 100644 --- a/test-tool/test_prefetch10_0blocks.c +++ b/test-tool/test_prefetch10_0blocks.c @@ -30,8 +30,8 @@ test_prefetch10_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test PREFETCH10 0-blocks at LBA==0"); - ret = prefetch10(iscsic, tgt_lun, 0, - 0, 0, 0); + ret = prefetch10(sd, 0, 0, 0, 0, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PREFETCH10 is not implemented."); CU_PASS("PREFETCH10 is not implemented."); @@ -45,19 +45,19 @@ test_prefetch10_0blocks(void) } logging(LOG_VERBOSE, "Test PREFETCH10 0-blocks one block past end-of-LUN"); - ret = prefetch10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, - 0, 0, 0); + ret = prefetch10(sd, num_blocks + 1, 0, 0, 0, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test PREFETCH10 0-blocks at LBA==2^31"); - ret = prefetch10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, - 0, 0, 0); + ret = prefetch10(sd, 0x80000000, 0, 0, 0, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test PREFETCH10 0-blocks at LBA==-1"); - ret = prefetch10_lbaoutofrange(iscsic, tgt_lun, -1, - 0, 0, 0); + ret = prefetch10(sd, -1, 0, 0, 0, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_prefetch10_beyond_eol.c b/test-tool/test_prefetch10_beyond_eol.c index 6c90c09..d663af9 100644 --- a/test-tool/test_prefetch10_beyond_eol.c +++ b/test-tool/test_prefetch10_beyond_eol.c @@ -37,8 +37,8 @@ test_prefetch10_beyond_eol(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test PREFETCH10 1-256 blocks one block beyond the end"); for (i = 1; i <= 256; i++) { - ret = prefetch10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i, 0, 0); + ret = prefetch10(sd, num_blocks + 1 - i, i, 0, 0, + EXPECT_LBA_OOB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PREFETCH10 is not implemented."); CU_PASS("PREFETCH10 is not implemented."); @@ -50,24 +50,24 @@ test_prefetch10_beyond_eol(void) logging(LOG_VERBOSE, "Test PREFETCH10 1-256 blocks at LBA==2^31"); for (i = 1; i <= 256; i++) { - ret = prefetch10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, - i, 0, 0); + ret = prefetch10(sd, 0x80000000, i, 0, 0, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test PREFETCH10 1-256 blocks at LBA==-1"); for (i = 1; i <= 256; i++) { - ret = prefetch10_lbaoutofrange(iscsic, tgt_lun, -1, - i, 0, 0); + ret = prefetch10(sd, -1, i, 0, 0, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test PREFETCH10 2-256 blocks all but one block beyond the end"); for (i = 2; i <= 256; i++) { - ret = prefetch10_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i, 0, 0); + ret = prefetch10(sd, num_blocks - 1, i, 0, 0, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_prefetch10_flags.c b/test-tool/test_prefetch10_flags.c index 93396f2..8846798 100644 --- a/test-tool/test_prefetch10_flags.c +++ b/test-tool/test_prefetch10_flags.c @@ -34,8 +34,8 @@ test_prefetch10_flags(void) logging(LOG_VERBOSE, "Test PREFETCH10 flags"); logging(LOG_VERBOSE, "Test PREFETCH10 with IMMED==1"); - ret = prefetch10(iscsic, tgt_lun, 0, - 1, 1, 0); + ret = prefetch10(sd, 0, 1, 1, 0, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PREFETCH10 is not implemented."); CU_PASS("PREFETCH10 is not implemented."); @@ -44,12 +44,12 @@ test_prefetch10_flags(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test PREFETCH10 with GROUP==3"); - ret = prefetch10(iscsic, tgt_lun, 0, - 1, 0, 3); + ret = prefetch10(sd, 0, 1, 0, 3, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test PREFETCH10 with IMMED=1 and GROUP==3"); - ret = prefetch10(iscsic, tgt_lun, 0, - 1, 1, 3); + ret = prefetch10(sd, 0, 1, 1, 3, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_prefetch10_simple.c b/test-tool/test_prefetch10_simple.c index 90dc6c0..89fe426 100644 --- a/test-tool/test_prefetch10_simple.c +++ b/test-tool/test_prefetch10_simple.c @@ -33,7 +33,8 @@ test_prefetch10_simple(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test PREFETCH10 of 1-256 blocks at the start of the LUN"); for (i = 1; i <= 256; i++) { - ret = prefetch10(iscsic, tgt_lun, 0, i, 0, 0); + ret = prefetch10(sd, 0, i, 0, 0, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PREFETCH10 is not implemented."); CU_PASS("PREFETCH10 is not implemented."); @@ -45,7 +46,8 @@ test_prefetch10_simple(void) logging(LOG_VERBOSE, "Test PREFETCH10 of 1-256 blocks at the end of the LUN"); for (i = 1; i <= 256; i++) { - ret = prefetch10(iscsic, tgt_lun, num_blocks - i, i, 0, 0); + ret = prefetch10(sd, num_blocks - i, i, 0, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_prefetch16_0blocks.c b/test-tool/test_prefetch16_0blocks.c index 905cd78..79ede7b 100644 --- a/test-tool/test_prefetch16_0blocks.c +++ b/test-tool/test_prefetch16_0blocks.c @@ -30,8 +30,8 @@ test_prefetch16_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test PREFETCH16 0-blocks at LBA==0"); - ret = prefetch16(iscsic, tgt_lun, 0, - 0, 0, 0); + ret = prefetch16(sd, 0, 0, 0, 0, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PREFETCH16 is not implemented."); CU_PASS("PREFETCH16 is not implemented."); @@ -40,19 +40,19 @@ test_prefetch16_0blocks(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test PREFETCH16 0-blocks one block past end-of-LUN"); - ret = prefetch16_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, - 0, 0, 0); + ret = prefetch16(sd, num_blocks + 1, 0, 0, 0, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test PREFETCH16 0-blocks at LBA==2^63"); - ret = prefetch16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000ULL, - 0, 0, 0); + ret = prefetch16(sd, 0x8000000000000000ULL, 0, 0, 0, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test PREFETCH16 0-blocks at LBA==-1"); - ret = prefetch16_lbaoutofrange(iscsic, tgt_lun, -1, - 0, 0, 0); + ret = prefetch16(sd, -1, 0, 0, 0, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_prefetch16_beyond_eol.c b/test-tool/test_prefetch16_beyond_eol.c index 43b5751..ca5df11 100644 --- a/test-tool/test_prefetch16_beyond_eol.c +++ b/test-tool/test_prefetch16_beyond_eol.c @@ -32,8 +32,8 @@ test_prefetch16_beyond_eol(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test PREFETCH16 1-256 blocks one block beyond the end"); for (i = 1; i <= 256; i++) { - ret = prefetch16_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i, 0, 0); + ret = prefetch16(sd, num_blocks + 1 - i, i, 0, 0, + EXPECT_LBA_OOB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PREFETCH16 is not implemented."); CU_PASS("PREFETCH16 is not implemented."); @@ -45,24 +45,25 @@ test_prefetch16_beyond_eol(void) logging(LOG_VERBOSE, "Test PREFETCH16 1-256 blocks at LBA==2^63"); for (i = 1; i <= 256; i++) { - ret = prefetch16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000ULL, - i, 0, 0); + ret = prefetch16(sd, 0x8000000000000000ULL, + i, 0, 0, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test PREFETCH16 1-256 blocks at LBA==-1"); for (i = 1; i <= 256; i++) { - ret = prefetch16_lbaoutofrange(iscsic, tgt_lun, -1, - i, 0, 0); + ret = prefetch16(sd, -1, i, 0, 0, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test PREFETCH16 2-256 blocks all but one block beyond the end"); for (i = 2; i <= 256; i++) { - ret = prefetch16_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i, 0, 0); + ret = prefetch16(sd, num_blocks - 1, i, 0, 0, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_prefetch16_flags.c b/test-tool/test_prefetch16_flags.c index 7240bde..384a1a7 100644 --- a/test-tool/test_prefetch16_flags.c +++ b/test-tool/test_prefetch16_flags.c @@ -34,8 +34,8 @@ test_prefetch16_flags(void) logging(LOG_VERBOSE, "Test PREFETCH16 flags"); logging(LOG_VERBOSE, "Test PREFETCH16 with IMMED==1"); - ret = prefetch16(iscsic, tgt_lun, 0, - 1, 1, 0); + ret = prefetch16(sd, 0, 1, 1, 0, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PREFETCH16 is not implemented."); CU_PASS("PREFETCH16 is not implemented."); @@ -44,12 +44,12 @@ test_prefetch16_flags(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test PREFETCH16 with GROUP==3"); - ret = prefetch16(iscsic, tgt_lun, 0, - 1, 0, 3); + ret = prefetch16(sd, 0, 1, 0, 3, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test PREFETCH16 with IMMED=1 and GROUP==3"); - ret = prefetch16(iscsic, tgt_lun, 0, - 1, 1, 3); + ret = prefetch16(sd, 0, 1, 1, 3, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_prefetch16_simple.c b/test-tool/test_prefetch16_simple.c index dab69de..587677f 100644 --- a/test-tool/test_prefetch16_simple.c +++ b/test-tool/test_prefetch16_simple.c @@ -33,7 +33,8 @@ test_prefetch16_simple(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test PREFETCH16 of 1-256 blocks at the start of the LUN"); for (i = 1; i <= 256; i++) { - ret = prefetch16(iscsic, tgt_lun, 0, i, 0, 0); + ret = prefetch16(sd, 0, i, 0, 0, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PREFETCH16 is not implemented."); CU_PASS("PREFETCH16 is not implemented."); @@ -45,7 +46,8 @@ test_prefetch16_simple(void) logging(LOG_VERBOSE, "Test PREFETCH16 of 1-256 blocks at the end of the LUN"); for (i = 1; i <= 256; i++) { - ret = prefetch16(iscsic, tgt_lun, num_blocks - i, i, 0, 0); + ret = prefetch16(sd, num_blocks - i, i, 0, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_preventallow_2_itnexuses.c b/test-tool/test_preventallow_2_itnexuses.c index 49af325..a957fe3 100644 --- a/test-tool/test_preventallow_2_itnexuses.c +++ b/test-tool/test_preventallow_2_itnexuses.c @@ -28,6 +28,7 @@ void test_preventallow_2_itnexuses(void) { int ret; + struct scsi_device sd2; CHECK_FOR_SBC; CHECK_FOR_REMOVABLE; @@ -35,43 +36,55 @@ test_preventallow_2_itnexuses(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test that PREVENT MEDIUM REMOVAL are seen on other nexuses as well"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PREVENTALLOW test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + logging(LOG_VERBOSE, "Set the PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 1); + ret = preventallow(sd, 1); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Try to eject the medium"); - ret = startstopunit_preventremoval(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_REMOVAL_PREVENTED); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Create a second connection to the target"); - iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun); - if (iscsic2 == NULL) { + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd->iscsi_url, &sd->iscsi_lun); + if (sd2.iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return; } logging(LOG_VERBOSE, "Try to eject the medium on the second connection"); - ret = startstopunit_preventremoval(iscsic2, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(&sd2, 0, 0, 0, 0, 1, 0, + EXPECT_REMOVAL_PREVENTED); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Logout the second connection from target"); - iscsi_logout_sync(iscsic2); - iscsi_destroy_context(iscsic2); + iscsi_logout_sync(sd2.iscsi_ctx); + iscsi_destroy_context(sd2.iscsi_ctx); logging(LOG_VERBOSE, "Clear PREVENT and load medium in case target failed"); logging(LOG_VERBOSE, "Test we can clear PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 0); + ret = preventallow(sd, 0); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Load the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 1); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_preventallow_cold_reset.c b/test-tool/test_preventallow_cold_reset.c index 817b841..a604b2e 100644 --- a/test-tool/test_preventallow_cold_reset.c +++ b/test-tool/test_preventallow_cold_reset.c @@ -35,46 +35,60 @@ test_preventallow_cold_reset(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test that Target Warm Reset clears PREVENT MEDIUM REMOVAL"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PREVENTALLOW test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + logging(LOG_VERBOSE, "Set the PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 1); + ret = preventallow(sd, 1); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Try to eject the medium"); - ret = startstopunit_preventremoval(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_REMOVAL_PREVENTED); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Perform cold reset on target"); - ret = iscsi_task_mgmt_target_cold_reset_sync(iscsic); + ret = iscsi_task_mgmt_target_cold_reset_sync(sd->iscsi_ctx); logging(LOG_VERBOSE, "Wait until all unit attentions clear"); - while (testunitready(iscsic, tgt_lun) != 0); + while (testunitready(sd, EXPECT_STATUS_GOOD) != 0); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Try to eject the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can not access the media."); - ret = testunitready_nomedium(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Load the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Clear PREVENT and load medium in case target failed"); logging(LOG_VERBOSE, "Test we can clear PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 0); + ret = preventallow(sd, 0); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Load the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 1); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_preventallow_eject.c b/test-tool/test_preventallow_eject.c index 26da530..0f50357 100644 --- a/test-tool/test_preventallow_eject.c +++ b/test-tool/test_preventallow_eject.c @@ -36,43 +36,49 @@ test_preventallow_eject(void) logging(LOG_VERBOSE, "Test that we can not eject medium when PREVENT is active"); logging(LOG_VERBOSE, "Set the PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 1); + ret = preventallow(sd, 1); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Try to eject the medium"); - ret = startstopunit_preventremoval(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_REMOVAL_PREVENTED); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test we can clear PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 0); + ret = preventallow(sd, 0); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Try to eject the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can not access the media."); - ret = testunitready_nomedium(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Set the PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 1); + ret = preventallow(sd, 1); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Try to load the medium"); - ret = startstopunit_preventremoval(iscsic, tgt_lun, 0, 0, 0, 0, 1, 1); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 1, + EXPECT_REMOVAL_PREVENTED); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Clear PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 0); + ret = preventallow(sd, 0); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Load the medium again"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 1); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_preventallow_itnexus_loss.c b/test-tool/test_preventallow_itnexus_loss.c index 3c108a8..38b8d0f 100644 --- a/test-tool/test_preventallow_itnexus_loss.c +++ b/test-tool/test_preventallow_itnexus_loss.c @@ -35,49 +35,63 @@ test_preventallow_itnexus_loss(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test that IT-Nexus loss clears PREVENT MEDIUM REMOVAL"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PREVENTALLOW test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + logging(LOG_VERBOSE, "Set the PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 1); + ret = preventallow(sd, 1); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Try to eject the medium"); - ret = startstopunit_preventremoval(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_REMOVAL_PREVENTED); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Disconnect from the target."); - iscsi_destroy_context(iscsic); + iscsi_destroy_context(sd->iscsi_ctx); logging(LOG_VERBOSE, "Reconnect to target"); - iscsic = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun); - if (iscsic == NULL) { + sd->iscsi_ctx = iscsi_context_login(initiatorname1, sd->iscsi_url, &sd->iscsi_lun); + if (sd->iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return; } logging(LOG_VERBOSE, "Try to eject the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can not access the media."); - ret = testunitready_nomedium(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Load the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Clear PREVENT and load medium in case target failed"); logging(LOG_VERBOSE, "Test we can clear PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 0); + ret = preventallow(sd, 0); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Load the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 1); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_preventallow_logout.c b/test-tool/test_preventallow_logout.c index e5cc02a..e78baed 100644 --- a/test-tool/test_preventallow_logout.c +++ b/test-tool/test_preventallow_logout.c @@ -35,50 +35,64 @@ test_preventallow_logout(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test that Logout loss clears PREVENT MEDIUM REMOVAL"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PREVENTALLOW test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + logging(LOG_VERBOSE, "Set the PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 1); + ret = preventallow(sd, 1); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Try to eject the medium"); - ret = startstopunit_preventremoval(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_REMOVAL_PREVENTED); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Logout from target"); - iscsi_logout_sync(iscsic); - iscsi_destroy_context(iscsic); + iscsi_logout_sync(sd->iscsi_ctx); + iscsi_destroy_context(sd->iscsi_ctx); logging(LOG_VERBOSE, "Relogin to target"); - iscsic = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun); - if (iscsic == NULL) { + sd->iscsi_ctx = iscsi_context_login(initiatorname1, sd->iscsi_url, &sd->iscsi_lun); + if (sd->iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return; } logging(LOG_VERBOSE, "Try to eject the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can not access the media."); - ret = testunitready_nomedium(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Load the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Clear PREVENT and load medium in case target failed"); logging(LOG_VERBOSE, "Test we can clear PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 0); + ret = preventallow(sd, 0); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Load the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 1); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_preventallow_lun_reset.c b/test-tool/test_preventallow_lun_reset.c index fa1aa03..f7c0502 100644 --- a/test-tool/test_preventallow_lun_reset.c +++ b/test-tool/test_preventallow_lun_reset.c @@ -35,46 +35,59 @@ test_preventallow_lun_reset(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test that Target Warm Reset clears PREVENT MEDIUM REMOVAL"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PREVENTALLOW test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + logging(LOG_VERBOSE, "Set the PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 1); + ret = preventallow(sd, 1); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Try to eject the medium"); - ret = startstopunit_preventremoval(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_REMOVAL_PREVENTED); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Perform LUN reset on target"); - ret = iscsi_task_mgmt_lun_reset_sync(iscsic, tgt_lun); + ret = iscsi_task_mgmt_lun_reset_sync(sd->iscsi_ctx, sd->iscsi_lun); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Wait until all unit attentions clear"); - while (testunitready(iscsic, tgt_lun) != 0); + while (testunitready(sd, EXPECT_STATUS_GOOD) != 0); logging(LOG_VERBOSE, "Try to eject the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can not access the media."); - ret = testunitready_nomedium(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Load the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Clear PREVENT and load medium in case target failed"); logging(LOG_VERBOSE, "Test we can clear PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 0); + ret = preventallow(sd, 0); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Load the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 1); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); - } diff --git a/test-tool/test_preventallow_simple.c b/test-tool/test_preventallow_simple.c index eb2324d..a76fbdb 100644 --- a/test-tool/test_preventallow_simple.c +++ b/test-tool/test_preventallow_simple.c @@ -36,10 +36,10 @@ test_preventallow_simple(void) logging(LOG_VERBOSE, "Test PREVENTALLOW basics"); logging(LOG_VERBOSE, "Test we can set PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 1); + ret = preventallow(sd, 1); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test we can clear PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 0); + ret = preventallow(sd, 0); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_preventallow_warm_reset.c b/test-tool/test_preventallow_warm_reset.c index 7f9edc3..42604d1 100644 --- a/test-tool/test_preventallow_warm_reset.c +++ b/test-tool/test_preventallow_warm_reset.c @@ -35,46 +35,60 @@ test_preventallow_warm_reset(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test that Target Warm Reset clears PREVENT MEDIUM REMOVAL"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PREVENTALLOW test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + logging(LOG_VERBOSE, "Set the PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 1); + ret = preventallow(sd, 1); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Try to eject the medium"); - ret = startstopunit_preventremoval(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_REMOVAL_PREVENTED); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can still access the media."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Perform warm reset on target"); - ret = iscsi_task_mgmt_target_warm_reset_sync(iscsic); + ret = iscsi_task_mgmt_target_warm_reset_sync(sd->iscsi_ctx); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Wait until all unit attentions clear"); - while (testunitready(iscsic, tgt_lun) != 0); + while (testunitready(sd, EXPECT_STATUS_GOOD) != 0); logging(LOG_VERBOSE, "Try to eject the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can not access the media."); - ret = testunitready_nomedium(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Load the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Clear PREVENT and load medium in case target failed"); logging(LOG_VERBOSE, "Test we can clear PREVENT flag"); - ret = preventallow(iscsic, tgt_lun, 0); + ret = preventallow(sd, 0); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Load the medium"); - ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 1); + ret = startstopunit(sd, 0, 0, 0, 0, 1, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_prin_read_keys_simple.c b/test-tool/test_prin_read_keys_simple.c index 01b748c..e7c006b 100644 --- a/test-tool/test_prin_read_keys_simple.c +++ b/test-tool/test_prin_read_keys_simple.c @@ -36,7 +36,7 @@ test_prin_read_keys_simple(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test Persistent Reserve IN READ_KEYS works."); - ret = prin_read_keys(iscsic, tgt_lun, &task, NULL); + ret = prin_read_keys(sd, &task, NULL); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PERSISTEN RESERVE IN is not implemented."); CU_PASS("PERSISTENT RESERVE IN is not implemented."); diff --git a/test-tool/test_prin_serviceaction_range.c b/test-tool/test_prin_serviceaction_range.c index d8f3a00..0c9912e 100644 --- a/test-tool/test_prin_serviceaction_range.c +++ b/test-tool/test_prin_serviceaction_range.c @@ -37,7 +37,7 @@ test_prin_serviceaction_range(void) logging(LOG_VERBOSE, "Test Persistent Reserve IN Serviceaction range."); /* verify PRIN/READ_KEYS works -- XXX redundant -- remove this? */ - ret = prin_read_keys(iscsic, tgt_lun, &task, NULL); + ret = prin_read_keys(sd, &task, NULL); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PERSISTEN RESERVE IN is not implemented."); CU_PASS("PERSISTENT RESERVE IN is not implemented."); @@ -47,13 +47,13 @@ test_prin_serviceaction_range(void) /* verify that PRIN/SA={0,1,2,3} works ... */ for (i = 0; i < 4; i++) { - ret = prin_task(iscsic, tgt_lun, i, 1); + ret = prin_task(sd, i, 1); CU_ASSERT_EQUAL(ret, 0); } /* verify that PRIN/SA={4..0x20} fails ... */ for (i = 4; i < 0x20; i++) { - ret = prin_task(iscsic, tgt_lun, i, 0); + ret = prin_task(sd, i, 0); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_prout_register_simple.c b/test-tool/test_prout_register_simple.c index ca13193..a95f39b 100644 --- a/test-tool/test_prout_register_simple.c +++ b/test-tool/test_prout_register_simple.c @@ -37,7 +37,7 @@ test_prout_register_simple(void) logging(LOG_VERBOSE, "Test Persistent Reserve IN REGISTER works."); /* register our reservation key with the target */ - ret = prout_register_and_ignore(iscsic, tgt_lun, key); + ret = prout_register_and_ignore(sd, key); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PERSISTEN RESERVE OUT is not implemented."); CU_PASS("PERSISTENT RESERVE OUT is not implemented."); @@ -46,18 +46,18 @@ test_prout_register_simple(void) CU_ASSERT_EQUAL(ret, 0); /* verify we can read the registration */ - ret = prin_verify_key_presence(iscsic, tgt_lun, key, 1); + ret = prin_verify_key_presence(sd, key, 1); CU_ASSERT_EQUAL(ret, 0); /* try to reregister, which should fail */ - ret = prout_reregister_key_fails(iscsic, tgt_lun, key+1); + ret = prout_reregister_key_fails(sd, key+1); CU_ASSERT_EQUAL(ret, 0); /* release from the target */ - ret = prout_register_key(iscsic, tgt_lun, 0, key); + ret = prout_register_key(sd, 0, key); CU_ASSERT_EQUAL(ret, 0); /* Verify the registration is gone */ - ret = prin_verify_key_presence(iscsic, tgt_lun, key, 0); + ret = prin_verify_key_presence(sd, key, 0); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_prout_reserve_access.c b/test-tool/test_prout_reserve_access.c index 2d4dd65..c3c5ce3 100644 --- a/test-tool/test_prout_reserve_access.c +++ b/test-tool/test_prout_reserve_access.c @@ -25,8 +25,7 @@ static void -verify_persistent_reserve_access(struct iscsi_context *iscsi1, int lun1, - struct iscsi_context *iscsi2, int lun2, +verify_persistent_reserve_access(struct scsi_device *sd1, struct scsi_device *sd2, const enum scsi_persistent_out_type pr_type, int reg_i2_can_read, int reg_i2_can_write, @@ -44,26 +43,26 @@ verify_persistent_reserve_access(struct iscsi_context *iscsi1, int lun1, scsi_pr_type_str(pr_type)); /* send TURs to clear possible check conditions */ - (void) testunitready_clear_ua(iscsi1, lun1); - (void) testunitready_clear_ua(iscsi2, lun2); + (void) testunitready_clear_ua(sd1); + (void) testunitready_clear_ua(sd2); /* register our reservation key with the target */ - ret = prout_register_and_ignore(iscsi1, lun1, key); + ret = prout_register_and_ignore(sd1, key); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PERSISTEN RESERVE OUT is not implemented."); CU_PASS("PERSISTENT RESERVE OUT is not implemented."); return; } CU_ASSERT_EQUAL(0, ret); - ret = prout_register_and_ignore(iscsi2, lun2, key2); + ret = prout_register_and_ignore(sd2, key2); CU_ASSERT_EQUAL(0, ret); /* reserve the target through initiator 1 */ - ret = prout_reserve(iscsi1, lun1, key, pr_type); + ret = prout_reserve(sd1, key, pr_type); CU_ASSERT_EQUAL(0, ret); /* verify target reservation */ - ret = prin_verify_reserved_as(iscsi1, lun1, + ret = prin_verify_reserved_as(sd1, pr_type_is_all_registrants(pr_type) ? 0 : key, pr_type); CU_ASSERT_EQUAL(0, ret); @@ -72,98 +71,212 @@ verify_persistent_reserve_access(struct iscsi_context *iscsi1, int lun1, CU_ASSERT_PTR_NOT_NULL(read_write_buf); /* make sure init1 can read */ - ret = verify_read_works(iscsi1, lun1, read_write_buf); + ret = verify_read_works(sd1, read_write_buf); CU_ASSERT_EQUAL(0, ret); /* make sure init1 can write */ - ret = verify_write_works(iscsi1, lun1, read_write_buf); + ret = verify_write_works(sd1, read_write_buf); CU_ASSERT_EQUAL(0, ret); /* verify registered init2 read access */ if (reg_i2_can_read) - ret = verify_read_works(iscsi2, lun2, read_write_buf); + ret = verify_read_works(sd2, read_write_buf); else - ret = verify_read_fails(iscsi2, lun2, read_write_buf); + ret = verify_read_fails(sd2, read_write_buf); CU_ASSERT_EQUAL(0, ret); /* verify registered init2 write access */ if (reg_i2_can_write) - ret = verify_write_works(iscsi2, lun2, read_write_buf); + ret = verify_write_works(sd2, read_write_buf); else - ret = verify_write_fails(iscsi2, lun2, read_write_buf); + ret = verify_write_fails(sd2, read_write_buf); CU_ASSERT_EQUAL(0, ret); /* unregister init2 */ - ret = prout_register_key(iscsi2, lun2, 0, key); + ret = prout_register_key(sd2, 0, key); CU_ASSERT_EQUAL(0, ret); /* verify unregistered init2 read access */ if (unreg_i2_can_read) - ret = verify_read_works(iscsi2, lun2, read_write_buf); + ret = verify_read_works(sd2, read_write_buf); else - ret = verify_read_fails(iscsi2, lun2, read_write_buf); + ret = verify_read_fails(sd2, read_write_buf); CU_ASSERT_EQUAL(0, ret); /* verify unregistered init2 write access */ if (unreg_i2_can_write) - ret = verify_write_works(iscsi2, lun2, read_write_buf); + ret = verify_write_works(sd2, read_write_buf); else - ret = verify_write_fails(iscsi2, lun2, read_write_buf); + ret = verify_write_fails(sd2, read_write_buf); CU_ASSERT_EQUAL(0, ret); /* release our reservation */ - ret = prout_release(iscsi1, lun1, key, pr_type); + ret = prout_release(sd1, key, pr_type); CU_ASSERT_EQUAL(0, ret); /* remove our key from the target */ - ret = prout_register_key(iscsi1, lun1, 0, key); + ret = prout_register_key(sd1, 0, key); CU_ASSERT_EQUAL(0, ret); } void test_prout_reserve_access_ea(void) { - verify_persistent_reserve_access(iscsic, tgt_lun, iscsic2, tgt_lun2, + struct scsi_device sd2; + + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PERSISTENT RESERVE test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { + logging(LOG_VERBOSE, "Failed to login to target"); + return; + } + verify_persistent_reserve_access(sd, &sd2, SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS, 0, 0, 0, 0); + iscsi_destroy_context(sd2.iscsi_ctx); } void test_prout_reserve_access_we(void) { - verify_persistent_reserve_access(iscsic, tgt_lun, iscsic2, tgt_lun2, + struct scsi_device sd2; + + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PERSISTENT RESERVE test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { + logging(LOG_VERBOSE, "Failed to login to target"); + return; + } + verify_persistent_reserve_access(sd, &sd2, SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE, 1, 0, 1, 0); + iscsi_destroy_context(sd2.iscsi_ctx); } void test_prout_reserve_access_earo(void) { - verify_persistent_reserve_access(iscsic, tgt_lun, iscsic2, tgt_lun2, + struct scsi_device sd2; + + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PERSISTENT RESERVE test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { + logging(LOG_VERBOSE, "Failed to login to target"); + return; + } + verify_persistent_reserve_access(sd, &sd2, SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_REGISTRANTS_ONLY, 1, 1, 0, 0); + iscsi_destroy_context(sd2.iscsi_ctx); } void test_prout_reserve_access_wero(void) { - verify_persistent_reserve_access(iscsic, tgt_lun, iscsic2, tgt_lun2, + struct scsi_device sd2; + + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PERSISTENT RESERVE test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { + logging(LOG_VERBOSE, "Failed to login to target"); + return; + } + verify_persistent_reserve_access(sd, &sd2, SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_REGISTRANTS_ONLY, 1, 1, 1, 0); + iscsi_destroy_context(sd2.iscsi_ctx); } void test_prout_reserve_access_eaar(void) { - verify_persistent_reserve_access(iscsic, tgt_lun, iscsic2, tgt_lun2, + struct scsi_device sd2; + + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PERSISTENT RESERVE test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { + logging(LOG_VERBOSE, "Failed to login to target"); + return; + } + verify_persistent_reserve_access(sd, &sd2, SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_ALL_REGISTRANTS, 1, 1, 0, 0); + iscsi_destroy_context(sd2.iscsi_ctx); } void test_prout_reserve_access_wear(void) { - verify_persistent_reserve_access(iscsic, tgt_lun, iscsic2, tgt_lun2, + struct scsi_device sd2; + + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PERSISTENT RESERVE test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { + logging(LOG_VERBOSE, "Failed to login to target"); + return; + } + verify_persistent_reserve_access(sd, &sd2, SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_ALL_REGISTRANTS, 1, 1, 1, 0); + iscsi_destroy_context(sd2.iscsi_ctx); } diff --git a/test-tool/test_prout_reserve_ownership.c b/test-tool/test_prout_reserve_ownership.c index 9404e6d..54c7638 100644 --- a/test-tool/test_prout_reserve_ownership.c +++ b/test-tool/test_prout_reserve_ownership.c @@ -25,8 +25,7 @@ static void -verify_persistent_reserve_ownership(struct iscsi_context *iscsi1, int lun1, - struct iscsi_context *iscsi2, int lun2, +verify_persistent_reserve_ownership(struct scsi_device *sd1, struct scsi_device *sd2, const enum scsi_persistent_out_type pr_type, int resvn_is_shared) { @@ -41,97 +40,211 @@ verify_persistent_reserve_ownership(struct iscsi_context *iscsi1, int lun1, scsi_pr_type_str(pr_type)); /* send TURs to clear possible check conditions */ - (void) testunitready_clear_ua(iscsi1, lun1); - (void) testunitready_clear_ua(iscsi2, lun2); + (void) testunitready_clear_ua(sd1); + (void) testunitready_clear_ua(sd2); /* register our reservation key with the target */ - ret = prout_register_and_ignore(iscsi1, lun1, key1); + ret = prout_register_and_ignore(sd1, key1); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PERSISTEN RESERVE OUT is not implemented."); CU_PASS("PERSISTENT RESERVE OUT is not implemented."); return; } CU_ASSERT_EQUAL(0, ret); - ret = prout_register_and_ignore(iscsi2, lun2, key2); + ret = prout_register_and_ignore(sd2, key2); CU_ASSERT_EQUAL(0, ret); /* reserve the target through initiator 1 */ - ret = prout_reserve(iscsi1, lun1, key1, pr_type); + ret = prout_reserve(sd1, key1, pr_type); CU_ASSERT_EQUAL(0, ret); /* verify target reservation */ - ret = prin_verify_reserved_as(iscsi1, lun1, + ret = prin_verify_reserved_as(sd1, pr_type_is_all_registrants(pr_type) ? 0 : key1, pr_type); CU_ASSERT_EQUAL(0, ret); /* unregister init1 */ - ret = prout_register_key(iscsi1, lun1, 0, key1); + ret = prout_register_key(sd1, 0, key1); CU_ASSERT_EQUAL(0, ret); /* verify if reservation is still present */ if (resvn_is_shared) { /* verify target reservation */ - ret = prin_verify_reserved_as(iscsi1, lun1, + ret = prin_verify_reserved_as(sd1, pr_type_is_all_registrants(pr_type) ? 0 : key1, pr_type); CU_ASSERT_EQUAL(0, ret); /* release our reservation */ - ret = prout_release(iscsi2, lun2, key2, pr_type); + ret = prout_release(sd2, key2, pr_type); CU_ASSERT_EQUAL(0, ret); } else { /* verify target is not reserved now */ - ret = prin_verify_not_reserved(iscsi1, lun1); + ret = prin_verify_not_reserved(sd1); CU_ASSERT_EQUAL(0, ret); /* send TUR to clear possible check condition */ - (void) testunitready_clear_ua(iscsi2, lun2); + (void) testunitready_clear_ua(sd2); } /* remove our remaining key from the target */ - ret = prout_register_key(iscsi2, lun2, 0, key2); + ret = prout_register_key(sd2, 0, key2); CU_ASSERT_EQUAL(0, ret); } void test_prout_reserve_ownership_ea(void) { - verify_persistent_reserve_ownership(iscsic, tgt_lun, iscsic2, tgt_lun2, + struct scsi_device sd2; + + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PERSISTENT RESERVE test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { + logging(LOG_VERBOSE, "Failed to login to target"); + return; + } + verify_persistent_reserve_ownership(sd, &sd2, SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS, 0); + iscsi_destroy_context(sd2.iscsi_ctx); } void test_prout_reserve_ownership_we(void) { - verify_persistent_reserve_ownership(iscsic, tgt_lun, iscsic2, tgt_lun2, + struct scsi_device sd2; + + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PERSISTENT RESERVE test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { + logging(LOG_VERBOSE, "Failed to login to target"); + return; + } + verify_persistent_reserve_ownership(sd, &sd2, SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE, 0); + iscsi_destroy_context(sd2.iscsi_ctx); } void test_prout_reserve_ownership_earo(void) { - verify_persistent_reserve_ownership(iscsic, tgt_lun, iscsic2, tgt_lun2, + struct scsi_device sd2; + + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PERSISTENT RESERVE test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { + logging(LOG_VERBOSE, "Failed to login to target"); + return; + } + verify_persistent_reserve_ownership(sd, &sd2, SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_REGISTRANTS_ONLY, 0); + iscsi_destroy_context(sd2.iscsi_ctx); } void test_prout_reserve_ownership_wero(void) { - verify_persistent_reserve_ownership(iscsic, tgt_lun, iscsic2, tgt_lun2, + struct scsi_device sd2; + + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PERSISTENT RESERVE test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { + logging(LOG_VERBOSE, "Failed to login to target"); + return; + } + verify_persistent_reserve_ownership(sd, &sd2, SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_REGISTRANTS_ONLY, 0); + iscsi_destroy_context(sd2.iscsi_ctx); } void test_prout_reserve_ownership_eaar(void) { - verify_persistent_reserve_ownership(iscsic, tgt_lun, iscsic2, tgt_lun2, + struct scsi_device sd2; + + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PERSISTENT RESERVE test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { + logging(LOG_VERBOSE, "Failed to login to target"); + return; + } + verify_persistent_reserve_ownership(sd, &sd2, SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_ALL_REGISTRANTS, 1); + iscsi_destroy_context(sd2.iscsi_ctx); } void test_prout_reserve_ownership_wear(void) { - verify_persistent_reserve_ownership(iscsic, tgt_lun, iscsic2, tgt_lun2, + struct scsi_device sd2; + + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This PERSISTENT RESERVE test is " + "only supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { + logging(LOG_VERBOSE, "Failed to login to target"); + return; + } + verify_persistent_reserve_ownership(sd, &sd2, SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_ALL_REGISTRANTS, 1); + iscsi_destroy_context(sd2.iscsi_ctx); } diff --git a/test-tool/test_prout_reserve_simple.c b/test-tool/test_prout_reserve_simple.c index c7a0c42..8ab149c 100644 --- a/test-tool/test_prout_reserve_simple.c +++ b/test-tool/test_prout_reserve_simple.c @@ -52,7 +52,7 @@ test_prout_reserve_simple(void) logging(LOG_VERBOSE, "Test Persistent Reserve IN RESERVE works."); /* register our reservation key with the target */ - ret = prout_register_and_ignore(iscsic, tgt_lun, key); + ret = prout_register_and_ignore(sd, key); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] PERSISTEN RESERVE OUT is not implemented."); CU_PASS("PERSISTENT RESERVE OUT is not implemented."); @@ -65,22 +65,22 @@ test_prout_reserve_simple(void) enum scsi_persistent_out_type pr_type = pr_types_to_test[i]; /* reserve the target */ - ret = prout_reserve(iscsic, tgt_lun, key, pr_type); + ret = prout_reserve(sd, key, pr_type); CU_ASSERT_EQUAL(ret, 0); /* verify target reservation */ - ret = prin_verify_reserved_as(iscsic, tgt_lun, + ret = prin_verify_reserved_as(sd, pr_type_is_all_registrants(pr_type) ? 0 : key, pr_type); CU_ASSERT_EQUAL(ret, 0); /* release our reservation */ - ret = prout_release(iscsic, tgt_lun, key, pr_type); + ret = prout_release(sd, key, pr_type); CU_ASSERT_EQUAL(ret, 0); } /* remove our key from the target */ - ret = prout_register_key(iscsic, tgt_lun, 0, key); + ret = prout_register_key(sd, 0, key); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_read10_0blocks.c b/test-tool/test_read10_0blocks.c index 376fbcd..dced0f4 100644 --- a/test-tool/test_read10_0blocks.c +++ b/test-tool/test_read10_0blocks.c @@ -30,8 +30,9 @@ test_read10_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test READ10 0-blocks at LBA==0"); - ret = read10(iscsic, tgt_lun, 0, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read10(sd, NULL, 0, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (num_blocks > 0x80000000) { @@ -40,19 +41,22 @@ test_read10_0blocks(void) } logging(LOG_VERBOSE, "Test READ10 0-blocks one block past end-of-LUN"); - ret = read10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0, - block_size, 0, 0, 0, 0, 0, NULL); + ret = read10(sd, NULL, num_blocks + 1, 0, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ10 0-blocks at LBA==2^31"); - ret = read10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read10(sd, NULL, 0x80000000, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ10 0-blocks at LBA==-1"); - ret = read10_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read10(sd, NULL, -1, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_read10_beyond_eol.c b/test-tool/test_read10_beyond_eol.c index 213cc83..ae9aa95 100644 --- a/test-tool/test_read10_beyond_eol.c +++ b/test-tool/test_read10_beyond_eol.c @@ -40,21 +40,20 @@ test_read10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i * block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read10(sd, NULL, num_blocks + 1 - i, + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } - logging(LOG_VERBOSE, "Test READ10 1-256 blocks at LBA==2^31"); for (i = 1; i <= 256; i++) { if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, - i * block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read10(sd, NULL, 0x80000000, + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -64,8 +63,9 @@ test_read10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size, - block_size, 0, 0, 0, 0, 0, NULL); + ret = read10(sd, NULL, -1, i * block_size, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -75,9 +75,9 @@ test_read10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i * block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read10(sd, NULL, num_blocks - 1, + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_read10_flags.c b/test-tool/test_read10_flags.c index c303db7..2814ae9 100644 --- a/test-tool/test_read10_flags.c +++ b/test-tool/test_read10_flags.c @@ -36,36 +36,36 @@ test_read10_flags(void) CHECK_FOR_SBC; logging(LOG_VERBOSE, "Test READ10 with DPO==1"); - ret = read10(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 0, 0, 0, NULL); + ret = read10(sd, NULL, 0, + block_size, block_size, 0, 1, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ10 with FUA==1 FUA_NV==0"); - ret = read10(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 0, 0, NULL); + ret = read10(sd, NULL, 0, + block_size, block_size, 0, 0, 1, 0, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ10 with FUA==1 FUA_NV==1"); - ret = read10(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 1, 0, NULL); + ret = read10(sd, NULL, 0, + block_size, block_size, 0, 0, 1, 1, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ10 with FUA==0 FUA_NV==1"); - ret = read10(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 0, 1, 0, NULL); + ret = read10(sd, NULL, 0, + block_size, block_size, 0, 0, 0, 1, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ10 with DPO==1 FUA==1 FUA_NV==1"); - ret = read10(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 1, 1, 0, NULL); + ret = read10(sd, NULL, 0, + block_size, block_size, 0, 1, 1, 1, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_read10_invalid.c b/test-tool/test_read10_invalid.c index 4de7360..40e55c2 100644 --- a/test-tool/test_read10_invalid.c +++ b/test-tool/test_read10_invalid.c @@ -39,6 +39,14 @@ test_read10_invalid(void) logging(LOG_VERBOSE, "Test invalid READ10 commands"); logging(LOG_VERBOSE, "Block size is %zu", block_size); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This READ10 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + /* Try a read10 of 1 block but xferlength == 0 */ task = malloc(sizeof(struct scsi_task)); CU_ASSERT_PTR_NOT_NULL(task); @@ -54,19 +62,19 @@ test_read10_invalid(void) * we don't want autoreconnect since some targets will drop the session * on this condition. */ - iscsi_set_noautoreconnect(iscsic, 1); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==0"); - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */ logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -89,7 +97,7 @@ test_read10_invalid(void) task = NULL; /* in case the previous test failed the session */ - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==10000"); @@ -103,13 +111,13 @@ test_read10_invalid(void) task->xfer_dir = SCSI_XFER_READ; task->expxferlen = 10000; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -147,13 +155,13 @@ test_read10_invalid(void) task->xfer_dir = SCSI_XFER_READ; task->expxferlen = 200; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -193,13 +201,13 @@ test_read10_invalid(void) task->xfer_dir = SCSI_XFER_READ; task->expxferlen = block_size; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -240,16 +248,16 @@ test_read10_invalid(void) data.size = block_size; data.data = (unsigned char *)buf; - iscsi_set_noautoreconnect(iscsic, 1); - iscsi_set_timeout(iscsic, 3); - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); + iscsi_set_timeout(sd->iscsi_ctx, 3); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); scsi_free_scsi_task(task); diff --git a/test-tool/test_read10_rdprotect.c b/test-tool/test_read10_rdprotect.c index 77f475d..b2c764f 100644 --- a/test-tool/test_read10_rdprotect.c +++ b/test-tool/test_read10_rdprotect.c @@ -42,9 +42,10 @@ test_read10_rdprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = read10_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, block_size, - i, 0, 0, 0, 0, NULL); + ret = read10(sd, NULL, 0, + block_size, block_size, + i, 0, 0, 0, 0, NULL, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); } return; diff --git a/test-tool/test_read10_residuals.c b/test-tool/test_read10_residuals.c index f177d44..f546efa 100644 --- a/test-tool/test_read10_residuals.c +++ b/test-tool/test_read10_residuals.c @@ -40,6 +40,14 @@ test_read10_residuals(void) logging(LOG_VERBOSE, "Test READ10 commands with residuals"); logging(LOG_VERBOSE, "Block size is %zu", block_size); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This READ10 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + /* Try a read10 of 1 block but xferlength == 0 */ task = malloc(sizeof(struct scsi_task)); CU_ASSERT_PTR_NOT_NULL(task); @@ -55,19 +63,19 @@ test_read10_residuals(void) * we don't want autoreconnect since some targets will drop the session * on this condition. */ - iscsi_set_noautoreconnect(iscsic, 1); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==0"); - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */ logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -90,7 +98,7 @@ test_read10_residuals(void) task = NULL; /* in case the previous test failed the session */ - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==10000"); @@ -104,13 +112,13 @@ test_read10_residuals(void) task->xfer_dir = SCSI_XFER_READ; task->expxferlen = 10000; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -152,13 +160,13 @@ test_read10_residuals(void) task->xfer_dir = SCSI_XFER_READ; task->expxferlen = 200; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -198,13 +206,13 @@ test_read10_residuals(void) task->xfer_dir = SCSI_XFER_READ; task->expxferlen = block_size; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); diff --git a/test-tool/test_read10_simple.c b/test-tool/test_read10_simple.c index 663a2e2..233bde8 100644 --- a/test-tool/test_read10_simple.c +++ b/test-tool/test_read10_simple.c @@ -37,8 +37,9 @@ test_read10_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, NULL); + ret = read10(sd, NULL, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } @@ -48,8 +49,9 @@ test_read10_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, NULL); + ret = read10(sd, NULL, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_read12_0blocks.c b/test-tool/test_read12_0blocks.c index be18734..35ff1f4 100644 --- a/test-tool/test_read12_0blocks.c +++ b/test-tool/test_read12_0blocks.c @@ -30,8 +30,9 @@ test_read12_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test READ12 0-blocks at LBA==0"); - ret = read12(iscsic, tgt_lun, 0, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read12(sd, 0, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ12 is not implemented."); CU_PASS("READ12 is not implemented."); @@ -45,19 +46,22 @@ test_read12_0blocks(void) } logging(LOG_VERBOSE, "Test READ12 0-blocks one block past end-of-LUN"); - ret = read12_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0, - block_size, 0, 0, 0, 0, 0, NULL); + ret = read12(sd, num_blocks + 1, 0, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ12 0-blocks at LBA==2^31"); - ret = read12_lbaoutofrange(iscsic, tgt_lun, 0x80000000, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read12(sd, 0x80000000, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ12 0-blocks at LBA==-1"); - ret = read12_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read12(sd, -1, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_read12_beyond_eol.c b/test-tool/test_read12_beyond_eol.c index 5de1699..4afeb14 100644 --- a/test-tool/test_read12_beyond_eol.c +++ b/test-tool/test_read12_beyond_eol.c @@ -40,9 +40,9 @@ test_read12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read12_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i * block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read12(sd, num_blocks + 1 - i, + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ12 is not implemented."); CU_PASS("READ12 is not implemented."); @@ -57,9 +57,9 @@ test_read12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read12_lbaoutofrange(iscsic, tgt_lun, 0x80000000, - i * block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read12(sd, 0x80000000, + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -69,8 +69,9 @@ test_read12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read12_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size, - block_size, 0, 0, 0, 0, 0, NULL); + ret = read12(sd, -1, i * block_size, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -80,9 +81,9 @@ test_read12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read12_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i * block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read12(sd, num_blocks - 1, + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_read12_flags.c b/test-tool/test_read12_flags.c index d643f6f..095b6b9 100644 --- a/test-tool/test_read12_flags.c +++ b/test-tool/test_read12_flags.c @@ -36,9 +36,9 @@ test_read12_flags(void) CHECK_FOR_SBC; logging(LOG_VERBOSE, "Test READ12 with DPO==1"); - ret = read12(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 0, 0, 0, NULL); + ret = read12(sd, 0, + block_size, block_size, 0, 1, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ12 is not implemented."); CU_PASS("READ12 is not implemented."); @@ -48,29 +48,29 @@ test_read12_flags(void) logging(LOG_VERBOSE, "Test READ12 with FUA==1 FUA_NV==0"); - ret = read12(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 0, 0, NULL); + ret = read12(sd, 0, + block_size, block_size, 0, 0, 1, 0, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ12 with FUA==1 FUA_NV==1"); - ret = read12(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 1, 0, NULL); + ret = read12(sd, 0, + block_size, block_size, 0, 0, 1, 1, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ12 with FUA==0 FUA_NV==1"); - ret = read12(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 0, 1, 0, NULL); + ret = read12(sd, 0, + block_size, block_size, 0, 0, 0, 1, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ12 with DPO==1 FUA==1 FUA_NV==1"); - ret = read12(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 1, 1, 0, NULL); + ret = read12(sd, 0, + block_size, block_size, 0, 1, 1, 1, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_read12_rdprotect.c b/test-tool/test_read12_rdprotect.c index 6f9709c..9efddfd 100644 --- a/test-tool/test_read12_rdprotect.c +++ b/test-tool/test_read12_rdprotect.c @@ -41,9 +41,10 @@ test_read12_rdprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = read12_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, block_size, - i, 0, 0, 0, 0, NULL); + ret = read12(sd, 0, + block_size, block_size, + i, 0, 0, 0, 0, NULL, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ12 is not implemented."); CU_PASS("READ12 is not implemented."); diff --git a/test-tool/test_read12_residuals.c b/test-tool/test_read12_residuals.c index 38ed3b4..1deddc0 100644 --- a/test-tool/test_read12_residuals.c +++ b/test-tool/test_read12_residuals.c @@ -36,6 +36,14 @@ test_read12_residuals(void) logging(LOG_VERBOSE, "Test READ12 commands with residuals"); logging(LOG_VERBOSE, "Block size is %zu", block_size); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This READ12 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + task = malloc(sizeof(struct scsi_task)); CU_ASSERT_PTR_NOT_NULL(task); @@ -50,12 +58,12 @@ test_read12_residuals(void) * we don't want autoreconnect since some targets will drop the session * on this condition. */ - iscsi_set_noautoreconnect(iscsic, 1); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==0"); - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */ @@ -69,7 +77,7 @@ test_read12_residuals(void) logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -92,7 +100,7 @@ test_read12_residuals(void) task = NULL; /* in case the previous test failed the session */ - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==10000"); @@ -106,13 +114,13 @@ test_read12_residuals(void) task->xfer_dir = SCSI_XFER_READ; task->expxferlen = 10000; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -154,13 +162,13 @@ test_read12_residuals(void) task->xfer_dir = SCSI_XFER_READ; task->expxferlen = 200; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -200,13 +208,13 @@ test_read12_residuals(void) task->xfer_dir = SCSI_XFER_READ; task->expxferlen = block_size; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); diff --git a/test-tool/test_read12_simple.c b/test-tool/test_read12_simple.c index ce886cf..8846e98 100644 --- a/test-tool/test_read12_simple.c +++ b/test-tool/test_read12_simple.c @@ -37,8 +37,9 @@ test_read12_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read12(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, NULL); + ret = read12(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ12 is not implemented."); CU_PASS("READ12 is not implemented."); @@ -53,8 +54,9 @@ test_read12_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read12(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, NULL); + ret = read12(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_read16_0blocks.c b/test-tool/test_read16_0blocks.c index 9541136..c7e0928 100644 --- a/test-tool/test_read16_0blocks.c +++ b/test-tool/test_read16_0blocks.c @@ -32,8 +32,9 @@ test_read16_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test READ16 0-blocks at LBA==0"); - ret = read16(iscsic, tgt_lun, 0, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read16(sd, 0, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ16 is not implemented on this target and it does not claim SBC-3 support."); CU_PASS("READ16 is not implemented and no SBC-3 support claimed."); @@ -42,19 +43,22 @@ test_read16_0blocks(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ16 0-blocks one block past end-of-LUN"); - ret = read16_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0, - block_size, 0, 0, 0, 0, 0, NULL); + ret = read16(sd, num_blocks + 1, 0, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ16 0-blocks at LBA==2^63"); - ret = read16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000ULL, 0, - block_size, 0, 0, 0, 0, 0, NULL); + ret = read16(sd, 0x8000000000000000ULL, 0, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ16 0-blocks at LBA==-1"); - ret = read16_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read16(sd, -1, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_read16_beyond_eol.c b/test-tool/test_read16_beyond_eol.c index b488513..badf6b3 100644 --- a/test-tool/test_read16_beyond_eol.c +++ b/test-tool/test_read16_beyond_eol.c @@ -49,9 +49,9 @@ test_read16_beyond_eol(void) break; } - ret = read16_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i * block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read16(sd, num_blocks + 1 - i, + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ16 is not implemented on this target and it does not claim SBC-3 support."); CU_PASS("READ16 is not implemented and no SBC-3 support claimed."); @@ -60,16 +60,15 @@ test_read16_beyond_eol(void) CU_ASSERT_EQUAL(ret, 0); } - logging(LOG_VERBOSE, "Test READ16 1-256 blocks at LBA==2^63"); for (i = 1; i <= 256; i++) { if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000ULL, - i * block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read16(sd, 0x8000000000000000ULL, + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -81,10 +80,10 @@ test_read16_beyond_eol(void) break; } - ret = read16_lbaoutofrange(iscsic, tgt_lun, - 1ULL << (64 - ilog2(block_size)), - i * block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read16(sd, + 1ULL << (64 - ilog2(block_size)), + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -96,10 +95,10 @@ test_read16_beyond_eol(void) break; } - ret = read16_lbaoutofrange(iscsic, tgt_lun, - 1ULL << (63 - ilog2(block_size)), - i * block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read16(sd, + 1ULL << (63 - ilog2(block_size)), + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -110,8 +109,9 @@ test_read16_beyond_eol(void) break; } - ret = read16_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size, - block_size, 0, 0, 0, 0, 0, NULL); + ret = read16(sd, -1, i * block_size, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -122,9 +122,9 @@ test_read16_beyond_eol(void) break; } - ret = read16_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i * block_size, block_size, - 0, 0, 0, 0, 0, NULL); + ret = read16(sd, num_blocks - 1, + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_read16_flags.c b/test-tool/test_read16_flags.c index 101c79b..6f355f5 100644 --- a/test-tool/test_read16_flags.c +++ b/test-tool/test_read16_flags.c @@ -36,9 +36,9 @@ test_read16_flags(void) logging(LOG_VERBOSE, "Test READ16 flags"); logging(LOG_VERBOSE, "Test READ16 with DPO==1"); - ret = read16(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 0, 0, 0, NULL); + ret = read16(sd, 0, + block_size, block_size, 0, 1, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ16 is not implemented on this target and it does not claim SBC-3 support."); CU_PASS("READ16 is not implemented and no SBC-3 support claimed."); @@ -48,29 +48,29 @@ test_read16_flags(void) logging(LOG_VERBOSE, "Test READ16 with FUA==1 FUA_NV==0"); - ret = read16(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 0, 0, NULL); + ret = read16(sd, 0, + block_size, block_size, 0, 0, 1, 0, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ16 with FUA==1 FUA_NV==1"); - ret = read16(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 1, 0, NULL); + ret = read16(sd, 0, + block_size, block_size, 0, 0, 1, 1, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ16 with FUA==0 FUA_NV==1"); - ret = read16(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 0, 1, 0, NULL); + ret = read16(sd, 0, + block_size, block_size, 0, 0, 0, 1, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test READ16 with DPO==1 FUA==1 FUA_NV==1"); - ret = read16(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 1, 1, 0, NULL); + ret = read16(sd, 0, + block_size, block_size, 0, 1, 1, 1, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_read16_rdprotect.c b/test-tool/test_read16_rdprotect.c index 0abeee6..e8ff73a 100644 --- a/test-tool/test_read16_rdprotect.c +++ b/test-tool/test_read16_rdprotect.c @@ -41,9 +41,10 @@ test_read16_rdprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = read16_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, block_size, - i, 0, 0, 0, 0, NULL); + ret = read16(sd, 0, + block_size, block_size, + i, 0, 0, 0, 0, NULL, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ16 is not im lemented on this target and it does not claim SBC-3 support."); CU_PASS("READ16 is not implemented and no SBC-3 support claimed."); diff --git a/test-tool/test_read16_residuals.c b/test-tool/test_read16_residuals.c index 538096e..125b662 100644 --- a/test-tool/test_read16_residuals.c +++ b/test-tool/test_read16_residuals.c @@ -36,6 +36,14 @@ test_read16_residuals(void) logging(LOG_VERBOSE, "Test READ16 commands with residuals"); logging(LOG_VERBOSE, "Block size is %zu", block_size); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This READ16 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + task = malloc(sizeof(struct scsi_task)); CU_ASSERT_PTR_NOT_NULL(task); @@ -50,12 +58,12 @@ test_read16_residuals(void) * we don't want autoreconnect since some targets will drop the session * on this condition. */ - iscsi_set_noautoreconnect(iscsic, 1); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==0"); - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */ @@ -69,7 +77,7 @@ test_read16_residuals(void) logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -92,7 +100,7 @@ test_read16_residuals(void) task = NULL; /* in case the previous test failed the session */ - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==10000"); @@ -106,13 +114,13 @@ test_read16_residuals(void) task->xfer_dir = SCSI_XFER_READ; task->expxferlen = 10000; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -154,13 +162,13 @@ test_read16_residuals(void) task->xfer_dir = SCSI_XFER_READ; task->expxferlen = 200; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -200,13 +208,13 @@ test_read16_residuals(void) task->xfer_dir = SCSI_XFER_READ; task->expxferlen = block_size; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); diff --git a/test-tool/test_read16_simple.c b/test-tool/test_read16_simple.c index ad92ec8..bc77d93 100644 --- a/test-tool/test_read16_simple.c +++ b/test-tool/test_read16_simple.c @@ -39,8 +39,9 @@ test_read16_simple(void) break; } - ret = read16(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, NULL); + ret = read16(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ16 is not implemented on this target and it does not claim SBC-3 support."); CU_PASS("READ16 is not implemented and no SBC-3 support claimed."); @@ -56,9 +57,9 @@ test_read16_simple(void) break; } - ret = read16(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, NULL); - + ret = read16(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_read6_beyond_eol.c b/test-tool/test_read6_beyond_eol.c index e4ac0e2..b0020ef 100644 --- a/test-tool/test_read6_beyond_eol.c +++ b/test-tool/test_read6_beyond_eol.c @@ -38,9 +38,9 @@ test_read6_beyond_eol(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test READ6 1-255 blocks one block beyond the end"); for (i = 1; i <= 255; i++) { - ret = read6_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i * block_size, block_size, - NULL); + ret = read6(sd, NULL, num_blocks + 1 - i, + i * block_size, block_size, NULL, + EXPECT_LBA_OOB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ6 is not implemented."); CU_PASS("READ6 is not implemented."); @@ -52,18 +52,18 @@ test_read6_beyond_eol(void) logging(LOG_VERBOSE, "Test READ6 1-255 blocks at LBA==0x1fffff"); for (i = 1; i <= 255; i++) { - ret = read6_lbaoutofrange(iscsic, tgt_lun, 0x1fffff, - i * block_size, block_size, - NULL); + ret = read6(sd, NULL, 0x1fffff, + i * block_size, block_size, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test READ6 2-255 blocks all but one block beyond the end"); for (i = 2; i <= 255; i++) { - ret = read6_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i * block_size, block_size, - NULL); + ret = read6(sd, NULL, num_blocks - 1, + i * block_size, block_size, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_read6_simple.c b/test-tool/test_read6_simple.c index fd25195..eb98a9f 100644 --- a/test-tool/test_read6_simple.c +++ b/test-tool/test_read6_simple.c @@ -34,8 +34,9 @@ test_read6_simple(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test READ6 of 1-255 blocks at the start of the LUN"); for (i = 1; i <= 255; i++) { - ret = read6(iscsic, tgt_lun, 0, i * block_size, - block_size, NULL); + ret = read6(sd, NULL, 0, i * block_size, + block_size, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ6 is not implemented."); CU_PASS("READ6 is not implemented."); @@ -50,8 +51,9 @@ test_read6_simple(void) CU_PASS("LUN is too big for read-at-eol tests with READ6. Skipping test.\n"); } else { for (i = 1; i <= 255; i++) { - ret = read6(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, NULL); + ret = read6(sd, NULL, num_blocks - i, + i * block_size, block_size, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } } @@ -62,11 +64,12 @@ test_read6_simple(void) logging(LOG_VERBOSE, "Test sending a READ6 with transfer length == 0 " "(meaning 256 blocks)"); /* 256 is converted to 0 when the CDB is marshalled by the helper */ - task = iscsi_read6_sync(iscsic, tgt_lun, 0, - 256 * block_size, block_size); + ret = read6(sd, &task, 0, + 256 * block_size, block_size, NULL, + EXPECT_STATUS_GOOD); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_NORMAL, "[FAILED] READ6 command: " - "failed with sense. %s", iscsi_get_error(iscsic)); + "failed with sense. %s", sd->error_str ); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); diff --git a/test-tool/test_readcapacity10_simple.c b/test-tool/test_readcapacity10_simple.c index abfcbaf..7c3ca7f 100644 --- a/test-tool/test_readcapacity10_simple.c +++ b/test-tool/test_readcapacity10_simple.c @@ -1,4 +1,3 @@ - /* Copyright (C) 2013 by Ronnie Sahlberg @@ -35,6 +34,7 @@ test_readcapacity10_simple(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test basic READCAPACITY10"); - ret = readcapacity10(iscsic, tgt_lun, 0, 0); + ret = readcapacity10(sd, NULL, 0, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_readcapacity16_alloclen.c b/test-tool/test_readcapacity16_alloclen.c index 17b275e..b620138 100644 --- a/test-tool/test_readcapacity16_alloclen.c +++ b/test-tool/test_readcapacity16_alloclen.c @@ -35,7 +35,8 @@ test_readcapacity16_alloclen(void) logging(LOG_VERBOSE, "Test that READCAPACITY16 with alloc_len 0-15 is not an error"); for (i = 0; i < 16; i++) { - ret = readcapacity16(iscsic, tgt_lun, i); + ret = readcapacity16(sd, NULL, i, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READCAPACITY16 is not implemented on this target and it does not claim SBC-3 support."); CU_PASS("READCAPACITY16 is not implemented and no SBC-3 support claimed."); diff --git a/test-tool/test_readcapacity16_simple.c b/test-tool/test_readcapacity16_simple.c index 82b4348..d14bc61 100644 --- a/test-tool/test_readcapacity16_simple.c +++ b/test-tool/test_readcapacity16_simple.c @@ -34,7 +34,8 @@ test_readcapacity16_simple(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test that READCAPACITY16 works"); - ret = readcapacity16(iscsic, tgt_lun, 16); + ret = readcapacity16(sd, NULL, 16, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READCAPACITY16 is not implemented on this target and it does not claim support."); CU_PASS("READCAPACITY16 is not implemented and no SBC-3 support claimed."); diff --git a/test-tool/test_readonly_sbc.c b/test-tool/test_readonly_sbc.c index 7de9320..acfced1 100644 --- a/test-tool/test_readonly_sbc.c +++ b/test-tool/test_readonly_sbc.c @@ -41,49 +41,54 @@ test_readonly_sbc(void) logging(LOG_VERBOSE, "Test WRITE10 fails with WRITE_PROTECTED"); - ret = write10_writeprotected(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write10(sd, 0, block_size, block_size, + 0, 0, 0, 0, 0, buf, + EXPECT_WRITE_PROTECTED); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE12 fails with WRITE_PROTECTED"); - ret = write12_writeprotected(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write12(sd, 0, block_size, block_size, + 0, 0, 0, 0, 0, buf, + EXPECT_WRITE_PROTECTED); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE16 fails with WRITE_PROTECTED"); - ret = write16_writeprotected(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write16(sd, 0, block_size, block_size, + 0, 0, 0, 0, 0, buf, + EXPECT_WRITE_PROTECTED); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE_SAME10 fails with WRITE_PROTECTED"); - ret = writesame10_writeprotected(iscsic, tgt_lun, 0, block_size, 1, - 0, 0, 0, 0, buf); + ret = writesame10(sd, 0, block_size, 1, + 0, 0, 0, 0, buf, + EXPECT_WRITE_PROTECTED); if (ret == -2) { logging(LOG_VERBOSE, "WRITE_SAME10 not supported on target. Skipped."); } CU_ASSERT_NOT_EQUAL(ret, -1); logging(LOG_VERBOSE, "Test WRITE_SAME16 fails with WRITE_PROTECTED"); - ret = writesame16_writeprotected(iscsic, tgt_lun, 0, block_size, 1, - 0, 0, 0, 0, buf); + ret = writesame16(sd, 0, block_size, 1, + 0, 0, 0, 0, buf, + EXPECT_WRITE_PROTECTED); if (ret == -2) { logging(LOG_VERBOSE, "WRITE_SAME16 not supported on target. Skipped."); } CU_ASSERT_NOT_EQUAL(ret, -1); logging(LOG_VERBOSE, "Test WRITE_SAME10 UNMAP fails with WRITE_PROTECTED"); - ret = writesame10_writeprotected(iscsic, tgt_lun, 0, - block_size, 1, - 0, 1, 0, 0, NULL); + ret = writesame10(sd, 0, + block_size, 1, 0, 1, 0, 0, NULL, + EXPECT_WRITE_PROTECTED); if (ret == -2) { logging(LOG_VERBOSE, "WRITE_SAME10 not supported on target. Skipped."); } CU_ASSERT_NOT_EQUAL(ret, -1); logging(LOG_VERBOSE, "Test WRITE_SAME16 UNMAP fails with WRITE_PROTECTED"); - ret = writesame16_writeprotected(iscsic, tgt_lun, 0, - block_size, 1, - 0, 1, 0, 0, NULL); + ret = writesame16(sd, 0, + block_size, 1, 0, 1, 0, 0, NULL, + EXPECT_WRITE_PROTECTED); if (ret == -2) { logging(LOG_VERBOSE, "WRITE_SAME16 not supported on target. Skipped."); } @@ -92,7 +97,8 @@ test_readonly_sbc(void) logging(LOG_VERBOSE, "Test UNMAP of one physical block fails with WRITE_PROTECTED"); list[0].lba = 0; list[0].num = lbppb; - ret = unmap_writeprotected(iscsic, tgt_lun, 0, list, 1); + ret = unmap(sd, 0, list, 1, + EXPECT_WRITE_PROTECTED); if (ret == -2) { logging(LOG_VERBOSE, "UNMAP not supported on target. Skipped."); } @@ -101,43 +107,44 @@ test_readonly_sbc(void) logging(LOG_VERBOSE, "Test UNMAP of one logical block fails with WRITE_PROTECTED"); list[0].lba = 0; list[0].num = 1; - ret = unmap_writeprotected(iscsic, tgt_lun, 0, list, 1); + ret = unmap(sd, 0, list, 1, + EXPECT_WRITE_PROTECTED); if (ret == -2) { logging(LOG_VERBOSE, "UNMAP not supported on target. Skipped."); } CU_ASSERT_NOT_EQUAL(ret, -1); logging(LOG_VERBOSE, "Test WRITEVERIFY10 fails with WRITE_PROTECTED"); - ret = writeverify10_writeprotected(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify10(sd, 0, + block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_WRITE_PROTECTED); if (ret == -2) { logging(LOG_VERBOSE, "WRITEVERIFY10 not supported on target. Skipped."); } CU_ASSERT_NOT_EQUAL(ret, -1); logging(LOG_VERBOSE, "Test WRITEVERIFY12 fails with WRITE_PROTECTED"); - ret = writeverify12_writeprotected(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify12(sd, 0, + block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_WRITE_PROTECTED); if (ret == -2) { logging(LOG_VERBOSE, "WRITEVERIFY12 not supported on target. Skipped."); } CU_ASSERT_NOT_EQUAL(ret, -1); logging(LOG_VERBOSE, "Test WRITEVERIFY16 fails with WRITE_PROTECTED"); - ret = writeverify16_writeprotected(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify16(sd, 0, + block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_WRITE_PROTECTED); if (ret == -2) { logging(LOG_VERBOSE, "WRITEVERIFY16 not supported on target. Skipped."); } CU_ASSERT_NOT_EQUAL(ret, -1); logging(LOG_VERBOSE, "Test ORWRITE fails with WRITE_PROTECTED"); - ret = orwrite_writeprotected(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = orwrite(sd, 0, + block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_WRITE_PROTECTED); if (ret == -2) { logging(LOG_VERBOSE, "ORWRITE not supported on target. Skipped."); } diff --git a/test-tool/test_report_supported_opcodes_one_command.c b/test-tool/test_report_supported_opcodes_one_command.c index b49f11c..d11eca9 100644 --- a/test-tool/test_report_supported_opcodes_one_command.c +++ b/test-tool/test_report_supported_opcodes_one_command.c @@ -39,17 +39,20 @@ test_report_supported_opcodes_one_command(void) logging(LOG_VERBOSE, "Fetch list of all supported opcodes"); - ret = report_supported_opcodes(iscsic, tgt_lun, - 0, SCSI_REPORT_SUPPORTING_OPS_ALL, 0, 0, - 65535, &rso_task); + ret = report_supported_opcodes(sd, &rso_task, + 0, SCSI_REPORT_SUPPORTING_OPS_ALL, + 0, 0, 65535, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ_SUPPORTED_OPCODES is not " "implemented."); CU_PASS("READ_SUPPORTED_OPCODES is not implemented."); + scsi_free_scsi_task(rso_task); return; } CU_ASSERT_EQUAL(ret, 0); if (ret != 0) { + scsi_free_scsi_task(rso_task); return; } @@ -67,22 +70,23 @@ test_report_supported_opcodes_one_command(void) if (rsoc->descriptors[i].servactv) { logging(LOG_VERBOSE, "This opcode has service actions. " "Reporting Options 001b should fail"); - ret = report_supported_opcodes_invalidfieldincdb( - iscsic, tgt_lun, + ret = report_supported_opcodes(sd, NULL, 0, SCSI_REPORT_SUPPORTING_OPCODE, rsoc->descriptors[i].opcode, rsoc->descriptors[i].sa, - 65535, NULL); + 65535, + EXPECT_INVALID_FIELD_IN_CDB); } else { logging(LOG_VERBOSE, "This opcode does not have " "service actions. Reporting Options 001b " "should work"); ret = report_supported_opcodes( - iscsic, tgt_lun, + sd, NULL, 0, SCSI_REPORT_SUPPORTING_OPCODE, rsoc->descriptors[i].opcode, rsoc->descriptors[i].sa, - 65535, NULL); + 65535, + EXPECT_STATUS_GOOD); } CU_ASSERT_EQUAL(ret, 0); @@ -90,21 +94,23 @@ test_report_supported_opcodes_one_command(void) logging(LOG_VERBOSE, "This opcode has service actions. " "Reporting Options 002b should work"); ret = report_supported_opcodes( - iscsic, tgt_lun, + sd, NULL, 0, SCSI_REPORT_SUPPORTING_SERVICEACTION, rsoc->descriptors[i].opcode, rsoc->descriptors[i].sa, - 65535, NULL); + 65535, + EXPECT_STATUS_GOOD); } else { logging(LOG_VERBOSE, "This opcode does not have " "service actions. Reporting Options 002b " "should fail"); - ret = report_supported_opcodes_invalidfieldincdb( - iscsic, tgt_lun, + ret = report_supported_opcodes( + sd, NULL, 0, SCSI_REPORT_SUPPORTING_SERVICEACTION, rsoc->descriptors[i].opcode, rsoc->descriptors[i].sa, - 65535, NULL); + 65535, + EXPECT_INVALID_FIELD_IN_CDB); } CU_ASSERT_EQUAL(ret, 0); } @@ -117,14 +123,14 @@ test_report_supported_opcodes_one_command(void) rsoc->descriptors[i].opcode, rsoc->descriptors[i].sa); ret = report_supported_opcodes( - iscsic, tgt_lun, - 0, + sd, &one_task, 0, rsoc->descriptors[i].servactv ? SCSI_REPORT_SUPPORTING_SERVICEACTION : SCSI_REPORT_SUPPORTING_OPCODE, rsoc->descriptors[i].opcode, rsoc->descriptors[i].sa, - 65535, &one_task); + 65535, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Unmarshall the DATA-IN buffer"); rsoc_one = scsi_datain_unmarshall(one_task); diff --git a/test-tool/test_report_supported_opcodes_rctd.c b/test-tool/test_report_supported_opcodes_rctd.c index ca19683..cb6f3b8 100644 --- a/test-tool/test_report_supported_opcodes_rctd.c +++ b/test-tool/test_report_supported_opcodes_rctd.c @@ -38,17 +38,21 @@ test_report_supported_opcodes_rctd(void) logging(LOG_VERBOSE, "Test READ_SUPPORTED_OPCODES report ALL opcodes " "without timeout descriptors"); - ret = report_supported_opcodes(iscsic, tgt_lun, + ret = report_supported_opcodes( + sd, &rso_task, 0, SCSI_REPORT_SUPPORTING_OPS_ALL, 0, 0, - 65535, &rso_task); + 65535, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ_SUPPORTED_OPCODES is not " "implemented."); CU_PASS("READ_SUPPORTED_OPCODES is not implemented."); + scsi_free_scsi_task(rso_task); return; } CU_ASSERT_EQUAL(ret, 0); if (ret != 0) { + scsi_free_scsi_task(rso_task); return; } @@ -73,9 +77,11 @@ test_report_supported_opcodes_rctd(void) logging(LOG_VERBOSE, "Test READ_SUPPORTED_OPCODES report ALL opcodes " "with timeout descriptors"); - ret = report_supported_opcodes(iscsic, tgt_lun, + ret = report_supported_opcodes( + sd, &rso_task, 1, SCSI_REPORT_SUPPORTING_OPS_ALL, 0, 0, - 65535, &rso_task); + 65535, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (ret != 0) { return; diff --git a/test-tool/test_report_supported_opcodes_servactv.c b/test-tool/test_report_supported_opcodes_servactv.c index b7920d0..307f373 100644 --- a/test-tool/test_report_supported_opcodes_servactv.c +++ b/test-tool/test_report_supported_opcodes_servactv.c @@ -36,17 +36,21 @@ test_report_supported_opcodes_servactv(void) logging(LOG_VERBOSE, "Test READ_SUPPORTED_OPCODES SERVACTV flag"); - ret = report_supported_opcodes(iscsic, tgt_lun, + ret = report_supported_opcodes( + sd, &rso_task, 0, SCSI_REPORT_SUPPORTING_OPS_ALL, 0, 0, - 65535, &rso_task); + 65535, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ_SUPPORTED_OPCODES is not " "implemented."); CU_PASS("READ_SUPPORTED_OPCODES is not implemented."); + scsi_free_scsi_task(rso_task); return; } CU_ASSERT_EQUAL(ret, 0); if (ret != 0) { + scsi_free_scsi_task(rso_task); return; } diff --git a/test-tool/test_report_supported_opcodes_simple.c b/test-tool/test_report_supported_opcodes_simple.c index f2435e6..b893833 100644 --- a/test-tool/test_report_supported_opcodes_simple.c +++ b/test-tool/test_report_supported_opcodes_simple.c @@ -33,9 +33,11 @@ test_report_supported_opcodes_simple(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test basic READ_SUPPORTED_OPCODES"); - ret = report_supported_opcodes(iscsic, tgt_lun, + ret = report_supported_opcodes( + sd, NULL, 0, SCSI_REPORT_SUPPORTING_OPS_ALL, 0, 0, - 1024, NULL); + 1024, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] READ_SUPPORTED_OPCODES is not " "implemented."); diff --git a/test-tool/test_reserve6_2initiators.c b/test-tool/test_reserve6_2initiators.c index 1952aa4..b95ebf0 100644 --- a/test-tool/test_reserve6_2initiators.c +++ b/test-tool/test_reserve6_2initiators.c @@ -29,14 +29,21 @@ void test_reserve6_2initiators(void) { int ret; - + struct scsi_device sd2; logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test RESERVE6/RELEASE6 across two initiators"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This RESERVE6 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } logging(LOG_NORMAL, "Take out a RESERVE6 from the first initiator"); - ret = reserve6(iscsic, tgt_lun); + ret = reserve6(sd); if (ret == -2) { logging(LOG_VERBOSE, "[SKIPPED] Target does not support RESERVE6. Skipping test"); CU_PASS("[SKIPPED] Target does not support RESERVE6. Skipping test"); @@ -46,53 +53,54 @@ test_reserve6_2initiators(void) logging(LOG_NORMAL, "Verify that the first initiator can re-RESERVE6 the same reservation"); - ret = reserve6(iscsic, tgt_lun); + ret = reserve6(sd); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Create a second connection to the target"); - iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun); - if (iscsic2 == NULL) { + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd->iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return; } logging(LOG_NORMAL, "Try to take out a RESERVE6 from the second initiator"); - ret = reserve6_conflict(iscsic2, tgt_lun); + ret = reserve6_conflict(&sd2); CU_ASSERT_EQUAL(ret, 0); logging(LOG_NORMAL, "Try to RELEASE from the second initiator. Should be a nop"); - ret = release6(iscsic2, tgt_lun); + ret = release6(&sd2); CU_ASSERT_EQUAL(ret, 0); logging(LOG_NORMAL, "Test we can still send MODE SENSE from the first initiator"); - ret = mode_sense(iscsic, tgt_lun); + ret = modesense6(sd, NULL, 0, SCSI_MODESENSE_PC_CURRENT, SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 255, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_NORMAL, "MODE SENSE should fail from the second initiator"); - ret = mode_sense(iscsic2, tgt_lun); + ret = modesense6(&sd2, NULL, 0, SCSI_MODESENSE_PC_CURRENT, SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 255, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, SCSI_STATUS_RESERVATION_CONFLICT); logging(LOG_NORMAL, "RESERVE6 from the second initiator should still fail"); - ret = reserve6_conflict(iscsic2, tgt_lun); + ret = reserve6_conflict(&sd2); CU_ASSERT_EQUAL(ret, 0); logging(LOG_NORMAL, "RELEASE6 from the first initiator"); - ret = release6(iscsic, tgt_lun); + ret = release6(sd); CU_ASSERT_EQUAL(ret, 0); logging(LOG_NORMAL, "RESERVE6 from the second initiator should work now"); - ret = reserve6(iscsic2, tgt_lun); + ret = reserve6(&sd2); CU_ASSERT_EQUAL(ret, 0); logging(LOG_NORMAL, "RELEASE6 from the second initiator"); - ret = release6(iscsic2, tgt_lun); + ret = release6(&sd2); CU_ASSERT_EQUAL(ret, 0); - iscsi_logout_sync(iscsic2); - iscsi_destroy_context(iscsic2); - iscsic2 = NULL; + iscsi_logout_sync(sd2.iscsi_ctx); + iscsi_destroy_context(sd2.iscsi_ctx); } diff --git a/test-tool/test_reserve6_itnexus_loss.c b/test-tool/test_reserve6_itnexus_loss.c index 7aebbd6..0555f18 100644 --- a/test-tool/test_reserve6_itnexus_loss.c +++ b/test-tool/test_reserve6_itnexus_loss.c @@ -29,14 +29,21 @@ void test_reserve6_itnexus_loss(void) { int ret; - + struct scsi_device sd2; logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test that RESERVE6 is released on it-nexus loss"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This RESERVE6 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } logging(LOG_NORMAL, "Take out a RESERVE6 from the first initiator"); - ret = reserve6(iscsic, tgt_lun); + ret = reserve6(sd); if (ret == -2) { logging(LOG_VERBOSE, "[SKIPPED] Target does not support RESERVE6. Skipping test"); CU_PASS("[SKIPPED] Target does not support RESERVE6. Skipping test"); @@ -46,39 +53,38 @@ test_reserve6_itnexus_loss(void) logging(LOG_VERBOSE, "Create a second connection to the target"); - iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun); - if (iscsic2 == NULL) { + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd->iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return; } logging(LOG_NORMAL, "Try to take out a RESERVE6 from the second initiator"); - ret = reserve6_conflict(iscsic2, tgt_lun); + ret = reserve6_conflict(&sd2); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Disconnect from the target."); - iscsi_destroy_context(iscsic); + iscsi_destroy_context(sd->iscsi_ctx); logging(LOG_VERBOSE, "Sleep for three seconds incase the target is slow to reset"); sleep(3); logging(LOG_VERBOSE, "Reconnect to target"); - iscsic = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun); - if (iscsic == NULL) { + sd->iscsi_ctx = iscsi_context_login(initiatorname1, sd->iscsi_url, &sd->iscsi_lun); + if (sd->iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); goto finished; } logging(LOG_NORMAL, "RESERVE6 from the second initiator should work now"); - ret = reserve6(iscsic2, tgt_lun); + ret = reserve6(&sd2); CU_ASSERT_EQUAL(ret, 0); logging(LOG_NORMAL, "RELEASE6 from the second initiator"); - ret = release6(iscsic2, tgt_lun); + ret = release6(&sd2); CU_ASSERT_EQUAL(ret, 0); finished: - iscsi_logout_sync(iscsic2); - iscsi_destroy_context(iscsic2); - iscsic2 = NULL; + iscsi_logout_sync(sd2.iscsi_ctx); + iscsi_destroy_context(sd2.iscsi_ctx); } diff --git a/test-tool/test_reserve6_logout.c b/test-tool/test_reserve6_logout.c index e0ea4ff..5feacba 100644 --- a/test-tool/test_reserve6_logout.c +++ b/test-tool/test_reserve6_logout.c @@ -29,14 +29,21 @@ void test_reserve6_logout(void) { int ret; - + struct scsi_device sd2; logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test that RESERVE6 is released on logout"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This RESERVE6 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } logging(LOG_NORMAL, "Take out a RESERVE6 from the first initiator"); - ret = reserve6(iscsic, tgt_lun); + ret = reserve6(sd); if (ret == -2) { logging(LOG_VERBOSE, "[SKIPPED] Target does not support RESERVE6. Skipping test"); CU_PASS("[SKIPPED] Target does not support RESERVE6. Skipping test"); @@ -46,36 +53,35 @@ test_reserve6_logout(void) logging(LOG_VERBOSE, "Create a second connection to the target"); - iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun); - if (iscsic2 == NULL) { + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd->iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return; } logging(LOG_NORMAL, "Try to take out a RESERVE6 from the second initiator"); - ret = reserve6_conflict(iscsic2, tgt_lun); + ret = reserve6_conflict(&sd2); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Logout from target"); - iscsi_logout_sync(iscsic); - iscsi_destroy_context(iscsic); + iscsi_logout_sync(sd->iscsi_ctx); + iscsi_destroy_context(sd->iscsi_ctx); logging(LOG_VERBOSE, "Relogin to target"); - iscsic = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun); - if (iscsic == NULL) { + sd->iscsi_ctx = iscsi_context_login(initiatorname1, sd->iscsi_url, &sd->iscsi_lun); + if (sd->iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return; } logging(LOG_NORMAL, "RESERVE6 from the second initiator should work now"); - ret = reserve6(iscsic2, tgt_lun); + ret = reserve6(&sd2); CU_ASSERT_EQUAL(ret, 0); logging(LOG_NORMAL, "RELEASE6 from the second initiator"); - ret = release6(iscsic2, tgt_lun); + ret = release6(&sd2); CU_ASSERT_EQUAL(ret, 0); - iscsi_logout_sync(iscsic2); - iscsi_destroy_context(iscsic2); - iscsic2 = NULL; + iscsi_logout_sync(sd2.iscsi_ctx); + iscsi_destroy_context(sd2.iscsi_ctx); } diff --git a/test-tool/test_reserve6_lun_reset.c b/test-tool/test_reserve6_lun_reset.c index 3b4a2ed..9175056 100644 --- a/test-tool/test_reserve6_lun_reset.c +++ b/test-tool/test_reserve6_lun_reset.c @@ -29,14 +29,21 @@ void test_reserve6_lun_reset(void) { int ret; - + struct scsi_device sd2; logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test that RESERVE6 is released on lun reset"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This RESERVE6 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } logging(LOG_VERBOSE, "Take out a RESERVE6 from the first initiator"); - ret = reserve6(iscsic, tgt_lun); + ret = reserve6(sd); if (ret == -2) { logging(LOG_VERBOSE, "[SKIPPED] Target does not support RESERVE6. Skipping test"); CU_PASS("[SKIPPED] Target does not support RESERVE6. Skipping test"); @@ -46,9 +53,9 @@ test_reserve6_lun_reset(void) logging(LOG_VERBOSE, "Send a LUN Reset"); - ret = iscsi_task_mgmt_lun_reset_sync(iscsic, tgt_lun); + ret = iscsi_task_mgmt_lun_reset_sync(sd->iscsi_ctx, sd->iscsi_lun); if (ret != 0) { - logging(LOG_NORMAL, "LUN reset failed. %s", iscsi_get_error(iscsic)); + logging(LOG_NORMAL, "LUN reset failed. %s", iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(ret, 0); @@ -57,21 +64,20 @@ test_reserve6_lun_reset(void) logging(LOG_VERBOSE, "Create a second connection to the target"); - iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun); - if (iscsic2 == NULL) { + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd->iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return; } logging(LOG_VERBOSE, "RESERVE6 from the second initiator should work now"); - ret = reserve6(iscsic2, tgt_lun); + ret = reserve6(&sd2); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "RELEASE6 from the second initiator"); - ret = release6(iscsic2, tgt_lun); + ret = release6(&sd2); CU_ASSERT_EQUAL(ret, 0); - iscsi_logout_sync(iscsic2); - iscsi_destroy_context(iscsic2); - iscsic2 = NULL; + iscsi_logout_sync(sd2.iscsi_ctx); + iscsi_destroy_context(sd2.iscsi_ctx); } diff --git a/test-tool/test_reserve6_simple.c b/test-tool/test_reserve6_simple.c index 8f5c69d..03d22f5 100644 --- a/test-tool/test_reserve6_simple.c +++ b/test-tool/test_reserve6_simple.c @@ -34,7 +34,7 @@ test_reserve6_simple(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test basic RESERVE6/RELEASE6 commands if supported"); - ret = reserve6(iscsic, tgt_lun); + ret = reserve6(sd); if (ret == -2) { logging(LOG_VERBOSE, "[SKIPPED] Target does not support RESERVE6. Skipping test"); CU_PASS("[SKIPPED] Target does not support RESERVE6. Skipping test"); @@ -42,6 +42,6 @@ test_reserve6_simple(void) } CU_ASSERT_EQUAL(ret, 0); - ret = release6(iscsic, tgt_lun); + ret = release6(sd); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_reserve6_target_cold_reset.c b/test-tool/test_reserve6_target_cold_reset.c index 15914c7..9b98168 100644 --- a/test-tool/test_reserve6_target_cold_reset.c +++ b/test-tool/test_reserve6_target_cold_reset.c @@ -29,14 +29,21 @@ void test_reserve6_target_cold_reset(void) { int ret; - + struct scsi_device sd2; logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test that RESERVE6 is released on target cold reset"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This RESERVE6 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } logging(LOG_VERBOSE, "Take out a RESERVE6 from the first initiator"); - ret = reserve6(iscsic, tgt_lun); + ret = reserve6(sd); if (ret == -2) { logging(LOG_VERBOSE, "[SKIPPED] Target does not support RESERVE6. Skipping test"); CU_PASS("[SKIPPED] Target does not support RESERVE6. Skipping test"); @@ -46,9 +53,9 @@ test_reserve6_target_cold_reset(void) logging(LOG_VERBOSE, "Send a Cold Reset to the target"); - ret = iscsi_task_mgmt_target_cold_reset_sync(iscsic); + ret = iscsi_task_mgmt_target_cold_reset_sync(sd->iscsi_ctx); if (ret != 0) { - logging(LOG_NORMAL, "Cold reset failed. %s", iscsi_get_error(iscsic)); + logging(LOG_NORMAL, "Cold reset failed. %s", iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(ret, 0); @@ -56,21 +63,20 @@ test_reserve6_target_cold_reset(void) sleep(3); logging(LOG_VERBOSE, "Create a second connection to the target"); - iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun); - if (iscsic2 == NULL) { + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd->iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return; } logging(LOG_VERBOSE, "RESERVE6 from the second initiator should work now"); - ret = reserve6(iscsic2, tgt_lun); + ret = reserve6(&sd2); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "RELEASE6 from the second initiator"); - ret = release6(iscsic2, tgt_lun); + ret = release6(&sd2); CU_ASSERT_EQUAL(ret, 0); - iscsi_logout_sync(iscsic2); - iscsi_destroy_context(iscsic2); - iscsic2 = NULL; + iscsi_logout_sync(sd2.iscsi_ctx); + iscsi_destroy_context(sd2.iscsi_ctx); } diff --git a/test-tool/test_reserve6_target_warm_reset.c b/test-tool/test_reserve6_target_warm_reset.c index db5bdd3..cf31e84 100644 --- a/test-tool/test_reserve6_target_warm_reset.c +++ b/test-tool/test_reserve6_target_warm_reset.c @@ -29,14 +29,21 @@ void test_reserve6_target_warm_reset(void) { int ret; - + struct scsi_device sd2; logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test that RESERVE6 is released on target warm reset"); + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This RESERVE6 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } logging(LOG_VERBOSE, "Take out a RESERVE6 from the first initiator"); - ret = reserve6(iscsic, tgt_lun); + ret = reserve6(sd); if (ret == -2) { logging(LOG_VERBOSE, "[SKIPPED] Target does not support RESERVE6. Skipping test"); CU_PASS("[SKIPPED] Target does not support RESERVE6. Skipping test"); @@ -46,9 +53,9 @@ test_reserve6_target_warm_reset(void) logging(LOG_VERBOSE, "Send a Warm Reset to the target"); - ret = iscsi_task_mgmt_target_warm_reset_sync(iscsic); + ret = iscsi_task_mgmt_target_warm_reset_sync(sd->iscsi_ctx); if (ret != 0) { - logging(LOG_NORMAL, "Warm reset failed. %s", iscsi_get_error(iscsic)); + logging(LOG_NORMAL, "Warm reset failed. %s", iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(ret, 0); @@ -57,22 +64,21 @@ test_reserve6_target_warm_reset(void) logging(LOG_VERBOSE, "Create a second connection to the target"); - iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun); - if (iscsic2 == NULL) { + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd->iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return; } logging(LOG_VERBOSE, "RESERVE6 from the second initiator should work now"); - ret = reserve6(iscsic2, tgt_lun); + ret = reserve6(&sd2); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "RELEASE6 from the second initiator"); - ret = release6(iscsic2, tgt_lun); + ret = release6(&sd2); CU_ASSERT_EQUAL(ret, 0); - iscsi_logout_sync(iscsic2); - iscsi_destroy_context(iscsic2); - iscsic2 = NULL; + iscsi_logout_sync(sd2.iscsi_ctx); + iscsi_destroy_context(sd2.iscsi_ctx); } diff --git a/test-tool/test_sanitize_block_erase.c b/test-tool/test_sanitize_block_erase.c index e99d5fe..f7cf647 100644 --- a/test-tool/test_sanitize_block_erase.c +++ b/test-tool/test_sanitize_block_erase.c @@ -30,11 +30,12 @@ static void check_wabereq(void) { - struct scsi_task *task_ret; + struct scsi_task *task_ret = NULL; logging(LOG_VERBOSE, "Read one block from LBA 0"); - task_ret = read10_task(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, NULL); + read10(sd, &task_ret, 0, block_size, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_PTR_NOT_NULL(task_ret); CU_ASSERT_NOT_EQUAL(task_ret->status, SCSI_STATUS_CANCELLED); @@ -103,12 +104,13 @@ static void check_unmap(void) { int i; - struct scsi_task *task_ret; + struct scsi_task *task_ret = NULL; struct scsi_get_lba_status *lbas; uint64_t lba; logging(LOG_VERBOSE, "Read LBA mapping from the target"); - task_ret = get_lba_status_task(iscsic, tgt_lun, 0, 256); + get_lba_status(sd, &task_ret, 0, 256, + EXPECT_STATUS_GOOD); if (task_ret == NULL) { logging(LOG_VERBOSE, "[FAILED] Failed to read LBA mapping " "from the target."); @@ -119,7 +121,7 @@ check_unmap(void) if (task_ret->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Failed to read LBA mapping " "from the target. Sense: %s", - iscsi_get_error(iscsic)); + sd->error_str); CU_FAIL("[FAILED] Failed to read LBA mapping " "from the target."); scsi_free_scsi_task(task_ret); @@ -195,8 +197,9 @@ init_lun_with_data(unsigned char *buf, uint64_t lba) int ret; memset(buf, 'a', 256 * block_size); - ret = write16(iscsic, tgt_lun, lba, 256 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } @@ -206,8 +209,9 @@ check_lun_is_wiped(unsigned char *buf, uint64_t lba) int ret; unsigned char *rbuf = alloca(256 * block_size); - ret = read16(iscsic, tgt_lun, lba, 256 * block_size, - block_size, 0, 0, 0, 0, 0, rbuf); + ret = read16(sd, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, rbuf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (rc16 == NULL) { @@ -321,8 +325,8 @@ test_sanitize_block_erase(void) logging(LOG_VERBOSE, "Test we can perform basic BLOCK ERASE SANITIZE"); - ret = sanitize(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Check that the first 256 LBAs are wiped."); @@ -337,8 +341,8 @@ test_sanitize_block_erase(void) logging(LOG_VERBOSE, "BLOCK_ERASE parameter list length must be 0"); logging(LOG_VERBOSE, "Test that non-zero param length is an error for " "BLOCK ERASE"); - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 8, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 8, &data, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); if (inq_bdc) { diff --git a/test-tool/test_sanitize_block_erase_reserved.c b/test-tool/test_sanitize_block_erase_reserved.c index b6ad9e3..4af0b63 100644 --- a/test-tool/test_sanitize_block_erase_reserved.c +++ b/test-tool/test_sanitize_block_erase_reserved.c @@ -63,8 +63,8 @@ void test_sanitize_block_erase_reserved(void) logging(LOG_VERBOSE, "Send SANITIZE command with the reserved " "bit in byte 1 set to 1"); change_num = 1; - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] SANITIZE BLOCK_ERASE is not " "implemented on target."); @@ -79,8 +79,8 @@ void test_sanitize_block_erase_reserved(void) "byte %d set to non-zero", i); change_num = i; - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_sanitize_crypto_erase.c b/test-tool/test_sanitize_crypto_erase.c index 754979a..008afe1 100644 --- a/test-tool/test_sanitize_crypto_erase.c +++ b/test-tool/test_sanitize_crypto_erase.c @@ -30,11 +30,12 @@ static void check_wacereq(void) { - struct scsi_task *task_ret; + struct scsi_task *task_ret = NULL; logging(LOG_VERBOSE, "Read one block from LBA 0"); - task_ret = read10_task(iscsic, tgt_lun, 0, block_size, block_size, - 0, 0, 0, 0, 0, NULL); + read10(sd, &task_ret, 0, block_size, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_PTR_NOT_NULL(task_ret); CU_ASSERT_NOT_EQUAL(task_ret->status, SCSI_STATUS_CANCELLED); @@ -105,8 +106,9 @@ init_lun_with_data(unsigned char *buf, uint64_t lba) int ret; memset(buf, 'a', 256 * block_size); - ret = write16(iscsic, tgt_lun, lba, 256 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } @@ -116,8 +118,9 @@ check_lun_is_wiped(unsigned char *buf, uint64_t lba) int ret; unsigned char *rbuf = alloca(256 * block_size); - ret = read16(iscsic, tgt_lun, lba, 256 * block_size, - block_size, 0, 0, 0, 0, 0, rbuf); + ret = read16(sd, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, rbuf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (!memcmp(buf, rbuf, 256 * block_size)) { @@ -181,8 +184,8 @@ test_sanitize_crypto_erase(void) logging(LOG_VERBOSE, "Test we can perform basic CRYPTO ERASE SANITIZE"); - ret = sanitize(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 0, NULL); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 0, NULL, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Check that the first 256 LBAs are wiped."); @@ -199,8 +202,8 @@ return; logging(LOG_VERBOSE, "CRYPTO_ERASE parameter list length must be 0"); logging(LOG_VERBOSE, "Test that non-zero param length is an error for " "CRYPTO ERASE"); - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 8, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 8, &data, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); if (inq_bdc) { diff --git a/test-tool/test_sanitize_crypto_erase_reserved.c b/test-tool/test_sanitize_crypto_erase_reserved.c index 2afb0e7..01a4e78 100644 --- a/test-tool/test_sanitize_crypto_erase_reserved.c +++ b/test-tool/test_sanitize_crypto_erase_reserved.c @@ -63,8 +63,8 @@ void test_sanitize_crypto_erase_reserved(void) logging(LOG_VERBOSE, "Send SANITIZE command with the reserved " "bit in byte 1 set to 1"); change_num = 1; - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 0, NULL); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 0, NULL, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] SANITIZE CRYPTO_ERASE is not " "implemented on target."); @@ -79,8 +79,8 @@ void test_sanitize_crypto_erase_reserved(void) "byte %d set to non-zero", i); change_num = i; - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 0, NULL); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 0, NULL, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_sanitize_exit_failure_mode.c b/test-tool/test_sanitize_exit_failure_mode.c index 3264dc5..fc937c2 100644 --- a/test-tool/test_sanitize_exit_failure_mode.c +++ b/test-tool/test_sanitize_exit_failure_mode.c @@ -60,7 +60,7 @@ test_sanitize_exit_failure_mode(void) "be 0"); logging(LOG_VERBOSE, "Test that non-zero param length is an error for " "EXIT_FAILURE_MODE"); - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_EXIT_FAILURE_MODE, 8, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_EXIT_FAILURE_MODE, 8, &data, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_sanitize_invalid_serviceaction.c b/test-tool/test_sanitize_invalid_serviceaction.c index 55361bb..1b1dc5c 100644 --- a/test-tool/test_sanitize_invalid_serviceaction.c +++ b/test-tool/test_sanitize_invalid_serviceaction.c @@ -51,8 +51,8 @@ test_sanitize_invalid_serviceaction(void) logging(LOG_VERBOSE, "Verify that ServiceAction:0x%02d is " "an error.", i); - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, i, 0, NULL); + ret = sanitize(sd, 0, 0, i, 0, NULL, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not " "implemented."); diff --git a/test-tool/test_sanitize_overwrite.c b/test-tool/test_sanitize_overwrite.c index 963dcbd..b3c53f3 100644 --- a/test-tool/test_sanitize_overwrite.c +++ b/test-tool/test_sanitize_overwrite.c @@ -33,8 +33,9 @@ init_lun_with_data(uint64_t lba) unsigned char *buf = alloca(256 * block_size); memset(buf, 'a', 256 * block_size); - ret = write16(iscsic, tgt_lun, lba, 256 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } @@ -45,8 +46,9 @@ check_lun_is_wiped(uint64_t lba, char c) unsigned char *rbuf = alloca(256 * block_size); unsigned char *zbuf = alloca(256 * block_size); - ret = read16(iscsic, tgt_lun, lba, 256 * block_size, - block_size, 0, 0, 0, 0, 0, rbuf); + ret = read16(sd, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, rbuf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); memset(zbuf, c, 256 * block_size); @@ -122,8 +124,8 @@ test_sanitize_overwrite(void) data.data[1] = 0x00; data.data[2] = block_size >> 8; data.data[3] = block_size & 0xff; - ret = sanitize(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Check that the first 256 LBAs are wiped."); @@ -138,8 +140,8 @@ test_sanitize_overwrite(void) data.data[2] = (block_size / 2) >> 8; data.data[3] = (block_size / 2 ) & 0xff; - ret = sanitize(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); @@ -149,8 +151,8 @@ test_sanitize_overwrite(void) data.data[2] = 0; data.data[3] = 4; - ret = sanitize(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "OVERWRITE parameter list length must " @@ -159,8 +161,8 @@ test_sanitize_overwrite(void) logging(LOG_VERBOSE, "Test OVERWRITE with ParamLen:%d is an " "error.", i); - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_OVERWRITE, i, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_OVERWRITE, i, &data, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not " "implemented."); @@ -178,8 +180,9 @@ test_sanitize_overwrite(void) data.size = block_size + 8; data.data = alloca(block_size + 8); /* so we can send IP > blocksize */ memset(data.data, 0, data.size); - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_OVERWRITE, block_size + 5, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_OVERWRITE, block_size + 5, &data, + EXPECT_INVALID_FIELD_IN_CDB); + if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] SANITIZE is not " "implemented."); @@ -197,8 +200,8 @@ test_sanitize_overwrite(void) data.data[1] = 0x00; data.data[2] = block_size >> 8; data.data[3] = block_size & 0xff; - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); @@ -210,8 +213,8 @@ test_sanitize_overwrite(void) data.data[1] = 0x00; data.data[2] = 0x00; data.data[3] = 0x00; - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); @@ -224,7 +227,7 @@ test_sanitize_overwrite(void) data.data[1] = 0x00; data.data[2] = (block_size + 4) >> 8; data.data[3] = (block_size + 4) & 0xff; - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_sanitize_overwrite_reserved.c b/test-tool/test_sanitize_overwrite_reserved.c index 2a17d37..eb89a1c 100644 --- a/test-tool/test_sanitize_overwrite_reserved.c +++ b/test-tool/test_sanitize_overwrite_reserved.c @@ -73,8 +73,8 @@ void test_sanitize_overwrite_reserved(void) logging(LOG_VERBOSE, "Send SANITIZE command with the reserved " "bit in byte 1 set to 1"); change_num = 1; - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] SANITIZE OVERWRITE is not " "implemented on target."); @@ -89,8 +89,9 @@ void test_sanitize_overwrite_reserved(void) "byte %d set to non-zero", i); change_num = i; - ret = sanitize_invalidfieldincdb(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, + &data, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_sanitize_readonly.c b/test-tool/test_sanitize_readonly.c index b0e7a4b..1dc9b6c 100644 --- a/test-tool/test_sanitize_readonly.c +++ b/test-tool/test_sanitize_readonly.c @@ -32,6 +32,7 @@ test_sanitize_readonly(void) int ret; struct iscsi_data data; struct scsi_command_descriptor *cd; + struct scsi_device sd2; logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test SANITIZE with READONLY devices"); @@ -39,15 +40,26 @@ test_sanitize_readonly(void) CHECK_FOR_SANITIZE; CHECK_FOR_DATALOSS; + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This SANITIZE test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + logging(LOG_VERBOSE, "Create a second connection to the target"); - iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun); - if (iscsic2 == NULL) { + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return; } logging(LOG_VERBOSE, "Set Software Write Protect on the second connection"); - ret = set_swp(iscsic2, tgt_lun); + ret = set_swp(&sd2); CU_ASSERT_EQUAL(ret, 0); if (ret != 0) { return; @@ -55,7 +67,7 @@ test_sanitize_readonly(void) logging(LOG_VERBOSE, "Use TESTUNITREADY to clear unit attention on " "first connection"); - while (testunitready_clear_ua(iscsic, tgt_lun)) { + while (testunitready_clear_ua(sd)) { sleep(1); } @@ -77,8 +89,9 @@ test_sanitize_readonly(void) data.data[1] = 0x00; data.data[2] = block_size >> 8; data.data[3] = block_size & 0xff; - ret = sanitize_writeprotected(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, + &data, + EXPECT_WRITE_PROTECTED); CU_ASSERT_EQUAL(ret, 0); } @@ -92,8 +105,8 @@ test_sanitize_readonly(void) "implemented according to REPORT_SUPPORTED_OPCODES."); } else { logging(LOG_VERBOSE, "Test SANITIZE BLOCK_ERASE"); - ret = sanitize_writeprotected(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL, + EXPECT_WRITE_PROTECTED); CU_ASSERT_EQUAL(ret, 0); } @@ -106,21 +119,20 @@ test_sanitize_readonly(void) "implemented according to REPORT_SUPPORTED_OPCODES."); } else { logging(LOG_VERBOSE, "Test SANITIZE CRYPTO_ERASE"); - ret = sanitize_writeprotected(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 0, NULL); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 0, NULL, + EXPECT_WRITE_PROTECTED); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Clear Software Write Protect on the second connection"); - ret = clear_swp(iscsic2, tgt_lun); + ret = clear_swp(&sd2); logging(LOG_VERBOSE, "Use TESTUNITREADY to clear unit attention on " "first connection"); - while (testunitready_clear_ua(iscsic, tgt_lun)) { + while (testunitready_clear_ua(sd)) { sleep(1); } - iscsi_destroy_context(iscsic2); - iscsic2 = NULL; + iscsi_destroy_context(sd2.iscsi_ctx); } diff --git a/test-tool/test_sanitize_reservations.c b/test-tool/test_sanitize_reservations.c index 05e1919..ce133e7 100644 --- a/test-tool/test_sanitize_reservations.c +++ b/test-tool/test_sanitize_reservations.c @@ -32,6 +32,7 @@ test_sanitize_reservations(void) int ret; struct iscsi_data data; struct scsi_command_descriptor *cd; + struct scsi_device sd2; logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test SANITIZE with RESERVATIONS"); @@ -39,16 +40,24 @@ test_sanitize_reservations(void) CHECK_FOR_SANITIZE; CHECK_FOR_DATALOSS; + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This SANITIZE test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + logging(LOG_VERBOSE, "Create a second connection to the target"); - iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun); - if (iscsic2 == NULL) { + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd->iscsi_url, &sd2.iscsi_lun); + if (sd2.iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return; } logging(LOG_VERBOSE, "Take out a RESERVE6 from the second " "initiator"); - ret = reserve6(iscsic2, tgt_lun); + ret = reserve6(&sd2); CU_ASSERT_EQUAL(ret, 0); @@ -70,8 +79,9 @@ test_sanitize_reservations(void) data.data[1] = 0x00; data.data[2] = block_size >> 8; data.data[3] = block_size & 0xff; - ret = sanitize_conflict(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, + &data, + EXPECT_RESERVATION_CONFLICT); CU_ASSERT_EQUAL(ret, 0); } @@ -85,8 +95,8 @@ test_sanitize_reservations(void) "implemented according to REPORT_SUPPORTED_OPCODES."); } else { logging(LOG_VERBOSE, "Test SANITIZE BLOCK_ERASE"); - ret = sanitize_conflict(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_BLOCK_ERASE, 0, NULL, + EXPECT_RESERVATION_CONFLICT); CU_ASSERT_EQUAL(ret, 0); } @@ -99,12 +109,10 @@ test_sanitize_reservations(void) "implemented according to REPORT_SUPPORTED_OPCODES."); } else { logging(LOG_VERBOSE, "Test SANITIZE CRYPTO_ERASE"); - ret = sanitize_conflict(iscsic, tgt_lun, - 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 0, NULL); + ret = sanitize(sd, 0, 0, SCSI_SANITIZE_CRYPTO_ERASE, 0, NULL, + EXPECT_RESERVATION_CONFLICT); CU_ASSERT_EQUAL(ret, 0); } - - iscsi_destroy_context(iscsic2); - iscsic2 = NULL; + iscsi_destroy_context(sd2.iscsi_ctx); } diff --git a/test-tool/test_sanitize_reset.c b/test-tool/test_sanitize_reset.c index adc48be..604d112 100644 --- a/test-tool/test_sanitize_reset.c +++ b/test-tool/test_sanitize_reset.c @@ -46,6 +46,14 @@ test_sanitize_reset(void) CHECK_FOR_SANITIZE; CHECK_FOR_DATALOSS; + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This SANITIZE test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + logging(LOG_VERBOSE, "Check that SANITIZE OVERWRITE will continue " "even after Task/Lun/Target/* reset."); cd = get_command_descriptor(SCSI_OPCODE_SANITIZE, @@ -66,7 +74,7 @@ test_sanitize_reset(void) data.data[1] = 0x00; data.data[2] = block_size >> 8; data.data[3] = block_size & 0xff; - sanitize_task = iscsi_sanitize_task(iscsic, tgt_lun, + sanitize_task = iscsi_sanitize_task(sd->iscsi_ctx, sd->iscsi_lun, 0, 0, SCSI_SANITIZE_OVERWRITE, data.size, &data, sanitize_cb, NULL); @@ -74,7 +82,7 @@ test_sanitize_reset(void) /* just send something so that we know the sanitize command is sent * to the target */ - rl_task = iscsi_reportluns_sync(iscsic, 0, 64); + rl_task = iscsi_reportluns_sync(sd->iscsi_ctx, 0, 64); if (rl_task) { scsi_free_scsi_task(rl_task); } @@ -86,78 +94,83 @@ test_sanitize_reset(void) logging(LOG_VERBOSE, "Verify that the SANITIZE has started and that " "TESTUNITREADY fails with SANITIZE_IN_PROGRESS"); - ret = testunitready_sanitize(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that STARTSTOPUNIT fails with " "SANITIZE_IN_PROGRESS"); - ret = startstopunit_sanitize(iscsic, tgt_lun, 1, 0, 1, 0, 1, 0); + ret = startstopunit(sd, 1, 0, 1, 0, 1, 0, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that READ16 fails with " "SANITIZE_IN_PROGRESS"); - ret = read16_sanitize(iscsic, tgt_lun, 0, block_size, - block_size, 0, 0, 0, 0, 0, NULL); + ret = read16(sd, 0, block_size, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that INQUIRY is still allowed while " "SANITIZE is in progress"); - ret = inquiry(iscsic, tgt_lun, 0, 0, 255, NULL); + ret = inquiry(sd, NULL, 0, 0, 255, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Send an ABORT TASK"); - ret = iscsi_task_mgmt_abort_task_sync(iscsic, sanitize_task); + ret = iscsi_task_mgmt_abort_task_sync(sd->iscsi_ctx, sanitize_task); if (ret != 0) { logging(LOG_NORMAL, "ABORT TASK failed. %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } logging(LOG_VERBOSE, "Send an ABORT TASK SET"); - ret = iscsi_task_mgmt_abort_task_set_sync(iscsic, tgt_lun); + ret = iscsi_task_mgmt_abort_task_set_sync(sd->iscsi_ctx, sd->iscsi_lun); if (ret != 0) { logging(LOG_NORMAL, "ABORT TASK SET failed. %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } logging(LOG_VERBOSE, "Send a LUN Reset"); - ret = iscsi_task_mgmt_lun_reset_sync(iscsic, tgt_lun); + ret = iscsi_task_mgmt_lun_reset_sync(sd->iscsi_ctx, sd->iscsi_lun); if (ret != 0) { - logging(LOG_NORMAL, "LUN reset failed. %s", iscsi_get_error(iscsic)); + logging(LOG_NORMAL, "LUN reset failed. %s", iscsi_get_error(sd->iscsi_ctx)); } logging(LOG_VERBOSE, "Send a Warm Reset"); - ret = iscsi_task_mgmt_target_warm_reset_sync(iscsic); + ret = iscsi_task_mgmt_target_warm_reset_sync(sd->iscsi_ctx); if (ret != 0) { - logging(LOG_NORMAL, "Warm reset failed. %s", iscsi_get_error(iscsic)); + logging(LOG_NORMAL, "Warm reset failed. %s", iscsi_get_error(sd->iscsi_ctx)); } logging(LOG_VERBOSE, "Send a Cold Reset"); - ret = iscsi_task_mgmt_target_cold_reset_sync(iscsic); + ret = iscsi_task_mgmt_target_cold_reset_sync(sd->iscsi_ctx); if (ret != 0) { - logging(LOG_NORMAL, "Cold reset failed. %s", iscsi_get_error(iscsic)); + logging(LOG_NORMAL, "Cold reset failed. %s", iscsi_get_error(sd->iscsi_ctx)); } logging(LOG_VERBOSE, "Disconnect from the target."); - iscsi_destroy_context(iscsic); + iscsi_destroy_context(sd->iscsi_ctx); logging(LOG_VERBOSE, "Sleep for one seconds incase the target is " "slow to reset"); sleep(1); logging(LOG_VERBOSE, "Reconnect to target"); - iscsic = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun); - if (iscsic == NULL) { + sd->iscsi_ctx = iscsi_context_login(initiatorname1, sd->iscsi_url, &sd->iscsi_lun); + if (sd->iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return; } logging(LOG_VERBOSE, "Verify that the SANITIZE is still going."); - ret = testunitready_sanitize(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Wait until the SANITIZE operation has finished"); - while (testunitready_clear_ua(iscsic, tgt_lun)) { + while (testunitready_clear_ua(sd)) { sleep(60); } } diff --git a/test-tool/test_startstopunit_noloej.c b/test-tool/test_startstopunit_noloej.c index 475e4ce..8005658 100644 --- a/test-tool/test_startstopunit_noloej.c +++ b/test-tool/test_startstopunit_noloej.c @@ -39,78 +39,95 @@ test_startstopunit_noloej(void) } logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==0 START==0"); - ret = startstopunit(iscsic, tgt_lun, - 0, 0, 0, 0, 0, 0); + ret = startstopunit(sd, + 0, 0, 0, 0, 0, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==0 START==1"); - ret = startstopunit(iscsic, tgt_lun, - 0, 0, 0, 0, 0, 1); + ret = startstopunit(sd, + 0, 0, 0, 0, 0, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==0 START==0"); - ret = startstopunit(iscsic, tgt_lun, - 1, 0, 0, 0, 0, 0); + ret = startstopunit(sd, + 1, 0, 0, 0, 0, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==0 START==1"); - ret = startstopunit(iscsic, tgt_lun, - 1, 0, 0, 0, 0, 1); + ret = startstopunit(sd, + 1, 0, 0, 0, 0, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==1 START==0"); - ret = startstopunit(iscsic, tgt_lun, - 0, 0, 0, 1, 0, 0); + ret = startstopunit(sd, + 0, 0, 0, 1, 0, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==0 NO_FLUSH==1 START==1"); - ret = startstopunit(iscsic, tgt_lun, - 0, 0, 0, 1, 0, 1); + ret = startstopunit(sd, + 0, 0, 0, 1, 0, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==1 START==0"); - ret = startstopunit(iscsic, tgt_lun, - 1, 0, 0, 1, 0, 0); + ret = startstopunit(sd, + 1, 0, 0, 1, 0, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test that media is not ejected when LOEJ==0 IMMED==1 NO_FLUSH==1 START==1"); - ret = startstopunit(iscsic, tgt_lun, - 1, 0, 0, 1, 0, 1); + ret = startstopunit(sd, + 1, 0, 0, 1, 0, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "In case the target did eject the medium, load it again."); - startstopunit(iscsic, tgt_lun, 1, 0, 0, 0, 1, 1); + startstopunit(sd, 1, 0, 0, 0, 1, 1, + EXPECT_STATUS_GOOD); } diff --git a/test-tool/test_startstopunit_pwrcnd.c b/test-tool/test_startstopunit_pwrcnd.c index f6a9342..48b6574 100644 --- a/test-tool/test_startstopunit_pwrcnd.c +++ b/test-tool/test_startstopunit_pwrcnd.c @@ -40,15 +40,18 @@ test_startstopunit_pwrcnd(void) logging(LOG_VERBOSE, "Test that media is not ejected when PC!=0"); for (i = 1; i < 16; i++) { - ret = startstopunit(iscsic, tgt_lun, - 1, 0, i, 0, 1, 0); + ret = startstopunit(sd, + 1, 0, i, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is not ejected."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "In case the target did eject the medium, load it again."); - startstopunit(iscsic, tgt_lun, 1, 0, 0, 0, 1, 1); + startstopunit(sd, 1, 0, 0, 0, 1, 1, + EXPECT_STATUS_GOOD); } diff --git a/test-tool/test_startstopunit_simple.c b/test-tool/test_startstopunit_simple.c index c7774fb..951fa83 100644 --- a/test-tool/test_startstopunit_simple.c +++ b/test-tool/test_startstopunit_simple.c @@ -41,8 +41,9 @@ test_startstopunit_simple(void) logging(LOG_VERBOSE, "Media is not removable. STARTSTOPUNIT should fail"); } - ret = startstopunit(iscsic, tgt_lun, - 1, 0, 0, 0, 1, 0); + ret = startstopunit(sd, + 1, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); if (!inq->rmb) { CU_ASSERT_NOT_EQUAL(ret, 0); return; @@ -51,38 +52,45 @@ test_startstopunit_simple(void) logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is ejected."); - ret = testunitready_nomedium(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test we can load the removable the media with IMMED==1"); - ret = startstopunit(iscsic, tgt_lun, - 1, 0, 0, 0, 1, 1); + ret = startstopunit(sd, + 1, 0, 0, 0, 1, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can read from the media."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test we can eject removable the media with IMMED==1"); - ret = startstopunit(iscsic, tgt_lun, - 0, 0, 0, 0, 1, 0); + ret = startstopunit(sd, + 0, 0, 0, 0, 1, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test TESTUNITREADY that medium is ejected."); - ret = testunitready_nomedium(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_NO_MEDIUM); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test we can load the removable the media with IMMED==1"); - ret = startstopunit(iscsic, tgt_lun, - 0, 0, 0, 0, 1, 1); + ret = startstopunit(sd, + 0, 0, 0, 0, 1, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify we can access the media again."); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_SANITIZE); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_testunitready_simple.c b/test-tool/test_testunitready_simple.c index d01e521..e56b49d 100644 --- a/test-tool/test_testunitready_simple.c +++ b/test-tool/test_testunitready_simple.c @@ -30,6 +30,7 @@ test_testunitready_simple(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test TESTUNITREADY"); - ret = testunitready(iscsic, tgt_lun); + ret = testunitready(sd, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_unmap_0blocks.c b/test-tool/test_unmap_0blocks.c index 63bf1dd..063b798 100644 --- a/test-tool/test_unmap_0blocks.c +++ b/test-tool/test_unmap_0blocks.c @@ -1,4 +1,3 @@ - /* Copyright (C) 2013 Ronnie Sahlberg @@ -41,7 +40,8 @@ test_unmap_0blocks(void) for (i = 0; i < 256; i++) { list[0].lba = i; list[0].num = 0; - ret = unmap(iscsic, tgt_lun, 0, list, 1); + ret = unmap(sd, 0, list, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } @@ -49,14 +49,16 @@ test_unmap_0blocks(void) for (i = 0; i < 256; i++) { list[i].lba = i; list[i].num = 0; - ret = unmap(iscsic, tgt_lun, 0, list, i); + ret = unmap(sd, 0, list, i, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test UNMAP of 0 blocks at end-of-LUN"); list[0].lba = num_blocks; list[0].num = 0; - ret = unmap(iscsic, tgt_lun, 0, list, 1); + ret = unmap(sd, 0, list, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); @@ -65,12 +67,14 @@ test_unmap_0blocks(void) list[i].lba = i/2; list[i].num = 0; } - ret = unmap(iscsic, tgt_lun, 0, list, 256); + ret = unmap(sd, 0, list, 256, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test UNMAP without any descriptors."); - ret = unmap(iscsic, tgt_lun, 0, list, 0); + ret = unmap(sd, 0, list, 0, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_unmap_simple.c b/test-tool/test_unmap_simple.c index d080ae5..6e6f0fd 100644 --- a/test-tool/test_unmap_simple.c +++ b/test-tool/test_unmap_simple.c @@ -31,8 +31,9 @@ init_lun_with_data(unsigned char *buf, uint64_t lba) int ret; memset(buf, 'a', 256 * block_size); - ret = write10(iscsic, tgt_lun, lba, 256 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, lba, 256 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } @@ -63,12 +64,14 @@ test_unmap_simple(void) logging(LOG_VERBOSE, "UNMAP blocks 0-%d", i); list[0].lba = 0; list[0].num = i; - ret = unmap(iscsic, tgt_lun, 0, list, 1); + ret = unmap(sd, 0, list, 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Read blocks 0-%d", i); - ret = read10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (rc16 && rc16->lbprz) { @@ -96,12 +99,14 @@ test_unmap_simple(void) for (i = 0; i < 256; i++) { list[i].lba = i; list[i].num = 1; - ret = unmap(iscsic, tgt_lun, 0, list, i + 1); + ret = unmap(sd, 0, list, i + 1, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Read blocks 0-%d", i); - ret = read10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (rc16 && rc16->lbprz) { diff --git a/test-tool/test_unmap_vpd.c b/test-tool/test_unmap_vpd.c index 26e15b5..ee060f7 100644 --- a/test-tool/test_unmap_vpd.c +++ b/test-tool/test_unmap_vpd.c @@ -40,8 +40,8 @@ test_unmap_vpd(void) logging(LOG_VERBOSE, "Check if UNMAP is available."); list[0].lba = 0; list[0].num = 0; - ret = unmap(iscsic, tgt_lun, 0, list, 1); - + ret = unmap(sd, 0, list, 1, + EXPECT_STATUS_GOOD); if (ret != 0) { logging(LOG_VERBOSE, "UNMAP is not available. Verify that VPD " "settings reflect this."); diff --git a/test-tool/test_verify10_0blocks.c b/test-tool/test_verify10_0blocks.c index f30cf85..4ac008f 100644 --- a/test-tool/test_verify10_0blocks.c +++ b/test-tool/test_verify10_0blocks.c @@ -30,8 +30,9 @@ test_verify10_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test VERIFY10 0-blocks at LBA==0"); - ret = verify10(iscsic, tgt_lun, 0, 0, block_size, - 0, 0, 1, NULL); + ret = verify10(sd, 0, 0, block_size, + 0, 0, 1, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY10 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY10. Skipping test"); @@ -40,19 +41,22 @@ test_verify10_0blocks(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test VERIFY10 0-blocks one block past end-of-LUN"); - ret = verify10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0, - block_size, 0, 0, 1, NULL); + ret = verify10(sd, num_blocks + 1, 0, + block_size, 0, 0, 1, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test VERIFY10 0-blocks at LBA==2^31"); - ret = verify10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, 0, - block_size, 0, 0, 1, NULL); + ret = verify10(sd, 0x80000000, 0, + block_size, 0, 0, 1, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test VERIFY10 0-blocks at LBA==-1"); - ret = verify10_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size, - 0, 0, 1, NULL); + ret = verify10(sd, -1, 0, block_size, + 0, 0, 1, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_verify10_beyond_eol.c b/test-tool/test_verify10_beyond_eol.c index db49ac9..9b80296 100644 --- a/test-tool/test_verify10_beyond_eol.c +++ b/test-tool/test_verify10_beyond_eol.c @@ -42,9 +42,9 @@ test_verify10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = verify10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i * block_size, block_size, - 0, 0, 1, buf); + ret = verify10(sd, num_blocks + 1 - i, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_LBA_OOB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY10 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY10. Skipping test"); @@ -59,9 +59,9 @@ test_verify10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = verify10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, - i * block_size, block_size, - 0, 0, 1, buf); + ret = verify10(sd, 0x80000000, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -71,8 +71,9 @@ test_verify10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = verify10_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size, - block_size, 0, 0, 1, buf); + ret = verify10(sd, -1, i * block_size, + block_size, 0, 0, 1, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -82,9 +83,9 @@ test_verify10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = verify10_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i * block_size, block_size, - 0, 0, 1, buf); + ret = verify10(sd, num_blocks - 1, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_verify10_flags.c b/test-tool/test_verify10_flags.c index 993d276..5bb109f 100644 --- a/test-tool/test_verify10_flags.c +++ b/test-tool/test_verify10_flags.c @@ -34,14 +34,16 @@ test_verify10_flags(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test VERIFY10 flags"); - ret = read10(iscsic, tgt_lun, 0, block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test VERIFY10 with DPO==1"); - ret = verify10(iscsic, tgt_lun, 0, block_size, - block_size, 0, 1, 0, buf); + ret = verify10(sd, 0, block_size, + block_size, 0, 1, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY10 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY10. Skipping test"); @@ -52,8 +54,9 @@ test_verify10_flags(void) logging(LOG_VERBOSE, "Test VERIFY10 with BYTCHK==1"); - ret = verify10(iscsic, tgt_lun, 0, block_size, - block_size, 0, 0, 1, buf); + ret = verify10(sd, 0, block_size, + block_size, 0, 0, 1, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); free(buf); } diff --git a/test-tool/test_verify10_mismatch.c b/test-tool/test_verify10_mismatch.c index f625edc..93e0c98 100644 --- a/test-tool/test_verify10_mismatch.c +++ b/test-tool/test_verify10_mismatch.c @@ -40,16 +40,18 @@ test_verify10_mismatch(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); /* flip a random byte in the data */ buf[offset] ^= 'X'; logging(LOG_VERBOSE, "Flip some bits in the data"); - ret = verify10_miscompare(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 1, buf); + ret = verify10(sd, 0, i * block_size, + block_size, 0, 0, 1, buf, + EXPECT_MISCOMPARE); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support VERIFY10. Skipping test"); return; @@ -64,16 +66,18 @@ test_verify10_mismatch(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); /* flip a random byte in the data */ buf[offset] ^= 'X'; logging(LOG_VERBOSE, "Flip some bits in the data"); - ret = verify10_miscompare(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 1, buf); + ret = verify10(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_MISCOMPARE); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_verify10_mismatch_no_cmp.c b/test-tool/test_verify10_mismatch_no_cmp.c index e1a4cd2..f8637b1 100644 --- a/test-tool/test_verify10_mismatch_no_cmp.c +++ b/test-tool/test_verify10_mismatch_no_cmp.c @@ -40,16 +40,18 @@ test_verify10_mismatch_no_cmp(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); /* flip a random byte in the data */ buf[offset] ^= 'X'; logging(LOG_VERBOSE, "Flip some bits in the data"); - ret = verify10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, buf); + ret = verify10(sd, 0, i * block_size, + block_size, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY10 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY10. Skipping test"); @@ -65,16 +67,18 @@ test_verify10_mismatch_no_cmp(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); /* flip a random byte in the data */ buf[offset] ^= 'X'; logging(LOG_VERBOSE, "Flip some bits in the data"); - ret = verify10(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, buf); + ret = verify10(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_verify10_simple.c b/test-tool/test_verify10_simple.c index 452cbd9..dca1139 100644 --- a/test-tool/test_verify10_simple.c +++ b/test-tool/test_verify10_simple.c @@ -38,12 +38,14 @@ test_verify10_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); - ret = verify10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 1, buf); + ret = verify10(sd, 0, i * block_size, + block_size, 0, 0, 1, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY10 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY10. Skipping test"); @@ -57,12 +59,14 @@ test_verify10_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); - ret = verify10(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 1, buf); + ret = verify10(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_verify10_vrprotect.c b/test-tool/test_verify10_vrprotect.c index 1e4b7a2..171e53c 100644 --- a/test-tool/test_verify10_vrprotect.c +++ b/test-tool/test_verify10_vrprotect.c @@ -32,7 +32,6 @@ test_verify10_vrprotect(void) int i, ret; unsigned char *buf = alloca(block_size); - logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test VERIFY10 with non-zero VRPROTECT"); @@ -41,12 +40,14 @@ test_verify10_vrprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = read10(iscsic, tgt_lun, 0, block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); - ret = verify10_invalidfieldincdb(iscsic, tgt_lun, 0, block_size, - block_size, i, 0, 1, buf); + ret = verify10(sd, 0, block_size, + block_size, i, 0, 1, buf, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY10 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY10. Skipping test"); diff --git a/test-tool/test_verify12_0blocks.c b/test-tool/test_verify12_0blocks.c index b004f57..ea1b3d0 100644 --- a/test-tool/test_verify12_0blocks.c +++ b/test-tool/test_verify12_0blocks.c @@ -30,8 +30,9 @@ test_verify12_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test VERIFY12 0-blocks at LBA==0"); - ret = verify12(iscsic, tgt_lun, 0, 0, block_size, - 0, 0, 1, NULL); + ret = verify12(sd, 0, 0, block_size, + 0, 0, 1, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY12 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY12. Skipping test"); @@ -40,19 +41,22 @@ test_verify12_0blocks(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test VERIFY12 0-blocks one block past end-of-LUN"); - ret = verify12_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0, - block_size, 0, 0, 1, NULL); + ret = verify12(sd, num_blocks + 1, 0, + block_size, 0, 0, 1, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test VERIFY12 0-blocks at LBA==2^31"); - ret = verify12_lbaoutofrange(iscsic, tgt_lun, 0x80000000, 0, - block_size, 0, 0, 1, NULL); + ret = verify12(sd, 0x80000000, 0, + block_size, 0, 0, 1, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test VERIFY12 0-blocks at LBA==-1"); - ret = verify12_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size, - 0, 0, 1, NULL); + ret = verify12(sd, -1, 0, block_size, + 0, 0, 1, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_verify12_beyond_eol.c b/test-tool/test_verify12_beyond_eol.c index ae6d17d..4d56cf2 100644 --- a/test-tool/test_verify12_beyond_eol.c +++ b/test-tool/test_verify12_beyond_eol.c @@ -42,9 +42,9 @@ test_verify12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = verify12_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i * block_size, block_size, - 0, 0, 1, buf); + ret = verify12(sd, num_blocks + 1 - i, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_LBA_OOB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY12 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY12. Skipping test"); @@ -59,9 +59,9 @@ test_verify12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = verify12_lbaoutofrange(iscsic, tgt_lun, 0x80000000, - i * block_size, block_size, - 0, 0, 1, buf); + ret = verify12(sd, 0x80000000, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -71,8 +71,9 @@ test_verify12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = verify12_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size, - block_size, 0, 0, 1, buf); + ret = verify12(sd, -1, i * block_size, + block_size, 0, 0, 1, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -82,9 +83,9 @@ test_verify12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = verify12_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i * block_size, block_size, - 0, 0, 1, buf); + ret = verify12(sd, num_blocks - 1, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_verify12_flags.c b/test-tool/test_verify12_flags.c index e3d2999..6c1900a 100644 --- a/test-tool/test_verify12_flags.c +++ b/test-tool/test_verify12_flags.c @@ -35,14 +35,16 @@ test_verify12_flags(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test VERIFY12 flags"); - ret = read10(iscsic, tgt_lun, 0, block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read12(sd, 0, block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test VERIFY12 with DPO==1"); - ret = verify12(iscsic, tgt_lun, 0, block_size, - block_size, 0, 1, 0, buf); + ret = verify12(sd, 0, block_size, + block_size, 0, 1, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY12 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY12. Skipping test"); @@ -52,7 +54,8 @@ test_verify12_flags(void) logging(LOG_VERBOSE, "Test VERIFY12 with BYTCHK==1"); - ret = verify12(iscsic, tgt_lun, 0, block_size, - block_size, 0, 0, 1, buf); + ret = verify12(sd, 0, block_size, + block_size, 0, 0, 1, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_verify12_mismatch.c b/test-tool/test_verify12_mismatch.c index 144e81b..03f2c50 100644 --- a/test-tool/test_verify12_mismatch.c +++ b/test-tool/test_verify12_mismatch.c @@ -40,15 +40,17 @@ test_verify12_mismatch(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read12(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); /* flip a random byte in the data */ buf[offset] ^= 'X'; logging(LOG_VERBOSE, "Flip some bits in the data"); - ret = verify12_miscompare(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 1, buf); + ret = verify12(sd, 0, i * block_size, + block_size, 0, 0, 1, buf, + EXPECT_MISCOMPARE); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY12 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY12. Skipping test"); @@ -64,16 +66,18 @@ test_verify12_mismatch(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read12(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, buf); + ret = read12(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); /* flip a random byte in the data */ buf[offset] ^= 'X'; logging(LOG_VERBOSE, "Flip some bits in the data"); - ret = verify12_miscompare(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 1, buf); + ret = verify12(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_MISCOMPARE); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_verify12_mismatch_no_cmp.c b/test-tool/test_verify12_mismatch_no_cmp.c index ef7e013..0d948ce 100644 --- a/test-tool/test_verify12_mismatch_no_cmp.c +++ b/test-tool/test_verify12_mismatch_no_cmp.c @@ -40,15 +40,17 @@ test_verify12_mismatch_no_cmp(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read12(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); /* flip a random byte in the data */ buf[offset] ^= 'X'; logging(LOG_VERBOSE, "Flip some bits in the data"); - ret = verify12(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, buf); + ret = verify12(sd, 0, i * block_size, + block_size, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY12 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY12. Skipping test"); @@ -64,16 +66,18 @@ test_verify12_mismatch_no_cmp(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read12(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, buf); + ret = read12(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); /* flip a random byte in the data */ buf[offset] ^= 'X'; logging(LOG_VERBOSE, "Flip some bits in the data"); - ret = verify12(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, buf); + ret = verify12(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_verify12_simple.c b/test-tool/test_verify12_simple.c index d2e6abd..3d43b90 100644 --- a/test-tool/test_verify12_simple.c +++ b/test-tool/test_verify12_simple.c @@ -38,12 +38,14 @@ test_verify12_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); - ret = verify12(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 1, buf); + ret = verify12(sd, 0, i * block_size, + block_size, 0, 0, 1, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY12 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY12. Skipping test"); @@ -57,12 +59,14 @@ test_verify12_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read12(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, buf); + ret = read12(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); - ret = verify12(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 1, buf); + ret = verify12(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_verify12_vrprotect.c b/test-tool/test_verify12_vrprotect.c index 3e1d77a..f17c584 100644 --- a/test-tool/test_verify12_vrprotect.c +++ b/test-tool/test_verify12_vrprotect.c @@ -41,11 +41,12 @@ test_verify12_vrprotect(void) logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = read10(iscsic, tgt_lun, 0, block_size, - block_size, 0, 0, 0, 0, 0, buf); - - ret = verify12_invalidfieldincdb(iscsic, tgt_lun, 0, block_size, - block_size, i, 0, 1, buf); + ret = read10(sd, NULL, 0, block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); + ret = verify12(sd, 0, block_size, + block_size, i, 0, 1, buf, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY12 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY12. Skipping test"); diff --git a/test-tool/test_verify16_0blocks.c b/test-tool/test_verify16_0blocks.c index ccc344c..2805ef0 100644 --- a/test-tool/test_verify16_0blocks.c +++ b/test-tool/test_verify16_0blocks.c @@ -30,8 +30,9 @@ test_verify16_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test VERIFY16 0-blocks at LBA==0"); - ret = verify16(iscsic, tgt_lun, 0, 0, block_size, - 0, 0, 1, NULL); + ret = verify16(sd, 0, 0, block_size, + 0, 0, 1, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY16 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY16. Skipping test"); @@ -40,19 +41,22 @@ test_verify16_0blocks(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test VERIFY16 0-blocks one block past end-of-LUN"); - ret = verify16_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0, - block_size, 0, 0, 1, NULL); + ret = verify16(sd, num_blocks + 1, 0, + block_size, 0, 0, 1, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test VERIFY16 0-blocks at LBA==2^63"); - ret = verify16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000ULL, 0, - block_size, 0, 0, 1, NULL); + ret = verify16(sd, 0x8000000000000000ULL, 0, + block_size, 0, 0, 1, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test VERIFY16 0-blocks at LBA==-1"); - ret = verify16_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size, - 0, 0, 1, NULL); + ret = verify16(sd, -1, 0, block_size, + 0, 0, 1, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_verify16_beyond_eol.c b/test-tool/test_verify16_beyond_eol.c index d105834..e494b97 100644 --- a/test-tool/test_verify16_beyond_eol.c +++ b/test-tool/test_verify16_beyond_eol.c @@ -39,9 +39,9 @@ test_verify16_beyond_eol(void) break; } - ret = verify16_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i * block_size, block_size, - 0, 0, 1, buf); + ret = verify16(sd, num_blocks + 1 - i, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_LBA_OOB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY16 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY16. Skipping test"); @@ -57,9 +57,9 @@ test_verify16_beyond_eol(void) break; } - ret = verify16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000ULL, - i * block_size, block_size, - 0, 0, 1, buf); + ret = verify16(sd, 0x8000000000000000ULL, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -70,8 +70,9 @@ test_verify16_beyond_eol(void) break; } - ret = verify16_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size, - block_size, 0, 0, 1, buf); + ret = verify16(sd, -1, i * block_size, + block_size, 0, 0, 1, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -82,9 +83,10 @@ test_verify16_beyond_eol(void) break; } - ret = verify16_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i * block_size, block_size, - 0, 0, 1, buf); + ret = verify16(sd, num_blocks - 1, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_LBA_OOB); + CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_verify16_flags.c b/test-tool/test_verify16_flags.c index ddac339..a91608a 100644 --- a/test-tool/test_verify16_flags.c +++ b/test-tool/test_verify16_flags.c @@ -1,4 +1,3 @@ - /* Copyright (C) 2013 Ronnie Sahlberg @@ -36,13 +35,14 @@ test_verify16_flags(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test VERIFY16 flags"); - ret = read16(iscsic, tgt_lun, 0, block_size, - block_size, 0, 0, 0, 0, 0, buf); - + ret = read16(sd, 0, block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Test VERIFY16 with DPO==1"); - ret = verify16(iscsic, tgt_lun, 0, block_size, - block_size, 0, 1, 0, buf); + ret = verify16(sd, 0, block_size, + block_size, 0, 1, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY16 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY16. Skipping test"); @@ -52,7 +52,8 @@ test_verify16_flags(void) logging(LOG_VERBOSE, "Test VERIFY16 with BYTCHK==1"); - ret = verify16(iscsic, tgt_lun, 0, block_size, - block_size, 0, 0, 1, buf); + ret = verify16(sd, 0, block_size, + block_size, 0, 0, 1, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_verify16_mismatch.c b/test-tool/test_verify16_mismatch.c index 6203ac5..61701be 100644 --- a/test-tool/test_verify16_mismatch.c +++ b/test-tool/test_verify16_mismatch.c @@ -41,15 +41,17 @@ test_verify16_mismatch(void) break; } - ret = read16(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read16(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); /* flip a random byte in the data */ buf[offset] ^= 'X'; logging(LOG_VERBOSE, "Flip some bits in the data"); - ret = verify16_miscompare(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 1, buf); + ret = verify16(sd, 0, i * block_size, + block_size, 0, 0, 1, buf, + EXPECT_MISCOMPARE); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY16 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY16. Skipping test"); @@ -66,16 +68,18 @@ test_verify16_mismatch(void) break; } - ret = read16(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, buf); + ret = read16(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); /* flip a random byte in the data */ buf[offset] ^= 'X'; logging(LOG_VERBOSE, "Flip some bits in the data"); - ret = verify16_miscompare(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 1, buf); + ret = verify16(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_MISCOMPARE); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_verify16_mismatch_no_cmp.c b/test-tool/test_verify16_mismatch_no_cmp.c index 6802883..0c4fe39 100644 --- a/test-tool/test_verify16_mismatch_no_cmp.c +++ b/test-tool/test_verify16_mismatch_no_cmp.c @@ -1,4 +1,3 @@ - /* Copyright (C) 2013 Ronnie Sahlberg @@ -42,15 +41,17 @@ test_verify16_mismatch_no_cmp(void) break; } - ret = read16(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read16(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); /* flip a random byte in the data */ buf[offset] ^= 'X'; logging(LOG_VERBOSE, "Flip some bits in the data"); - ret = verify16(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, buf); + ret = verify16(sd, 0, i * block_size, + block_size, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY16 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY16. Skipping test"); @@ -67,16 +68,18 @@ test_verify16_mismatch_no_cmp(void) break; } - ret = read16(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, buf); + ret = read16(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); /* flip a random byte in the data */ buf[offset] ^= 'X'; logging(LOG_VERBOSE, "Flip some bits in the data"); - ret = verify16(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, buf); + ret = verify16(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_verify16_simple.c b/test-tool/test_verify16_simple.c index c781db2..66c266f 100644 --- a/test-tool/test_verify16_simple.c +++ b/test-tool/test_verify16_simple.c @@ -38,11 +38,12 @@ test_verify16_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = read10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); - - ret = verify16(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 1, buf); + ret = read10(sd, NULL, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); + ret = verify16(sd, 0, i * block_size, + block_size, 0, 0, 1, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY16 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY16. Skipping test"); @@ -57,12 +58,14 @@ test_verify16_simple(void) break; } - ret = read16(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, buf); + ret = read16(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); - ret = verify16(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 1, buf); + ret = verify16(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 1, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_verify16_vrprotect.c b/test-tool/test_verify16_vrprotect.c index 6642559..cd0dc22 100644 --- a/test-tool/test_verify16_vrprotect.c +++ b/test-tool/test_verify16_vrprotect.c @@ -41,11 +41,12 @@ test_verify16_vrprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = read16(iscsic, tgt_lun, 0, block_size, - block_size, 0, 0, 0, 0, 0, buf); - - ret = verify16_invalidfieldincdb(iscsic, tgt_lun, 0, block_size, - block_size, i, 0, 1, buf); + ret = read16(sd, 0, block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); + ret = verify16(sd, 0, block_size, + block_size, i, 0, 1, buf, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] VERIFY16 is not implemented."); CU_PASS("[SKIPPED] Target does not support VERIFY16. Skipping test"); diff --git a/test-tool/test_write10_0blocks.c b/test-tool/test_write10_0blocks.c index 57f6666..6967174 100644 --- a/test-tool/test_write10_0blocks.c +++ b/test-tool/test_write10_0blocks.c @@ -32,8 +32,9 @@ test_write10_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITE10 0-blocks at LBA==0"); - ret = write10(iscsic, tgt_lun, 0, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = write10(sd, 0, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE10 is not implemented."); CU_PASS("WRITE10 is not implemented."); @@ -47,19 +48,22 @@ test_write10_0blocks(void) } logging(LOG_VERBOSE, "Test WRITE10 0-blocks one block past end-of-LUN"); - ret = write10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0, - block_size, 0, 0, 0, 0, 0, NULL); + ret = write10(sd, num_blocks + 1, 0, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE10 0-blocks at LBA==2^31"); - ret = write10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, 0, - block_size, 0, 0, 0, 0, 0, NULL); + ret = write10(sd, 0x80000000, 0, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE10 0-blocks at LBA==-1"); - ret = write10_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = write10(sd, -1, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_write10_beyond_eol.c b/test-tool/test_write10_beyond_eol.c index db4b3c3..1e1ab09 100644 --- a/test-tool/test_write10_beyond_eol.c +++ b/test-tool/test_write10_beyond_eol.c @@ -44,9 +44,9 @@ test_write10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write10(sd, num_blocks + 1 - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE10 is not implemented."); CU_PASS("WRITE10 is not implemented."); @@ -61,9 +61,9 @@ test_write10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write10(sd, 0x80000000, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -73,8 +73,9 @@ test_write10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write10_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, -1, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -84,9 +85,9 @@ test_write10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write10_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write10(sd, num_blocks - 1, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_write10_flags.c b/test-tool/test_write10_flags.c index e4306a4..f3305a8 100644 --- a/test-tool/test_write10_flags.c +++ b/test-tool/test_write10_flags.c @@ -38,9 +38,9 @@ test_write10_flags(void) logging(LOG_VERBOSE, "Test WRITE10 flags"); logging(LOG_VERBOSE, "Test WRITE10 with DPO==1"); - ret = write10(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 0, 0, 0, buf); + ret = write10(sd, 0, + block_size, block_size, 0, 1, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE10 is not implemented."); CU_PASS("WRITE10 is not implemented."); @@ -50,29 +50,29 @@ test_write10_flags(void) logging(LOG_VERBOSE, "Test WRITE10 with FUA==1 FUA_NV==0"); - ret = write10(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 0, 0, buf); + ret = write10(sd, 0, + block_size, block_size, 0, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE10 with FUA==1 FUA_NV==1"); - ret = write10(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 1, 0, buf); + ret = write10(sd, 0, + block_size, block_size, 0, 0, 1, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE10 with FUA==0 FUA_NV==1"); - ret = write10(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 0, 1, 0, buf); + ret = write10(sd, 0, + block_size, block_size, 0, 0, 0, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE10 with DPO==1 FUA==1 FUA_NV==1"); - ret = write10(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 1, 1, 0, buf); + ret = write10(sd, 0, + block_size, block_size, 0, 1, 1, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_write10_residuals.c b/test-tool/test_write10_residuals.c index 1e9d1d5..7c68d47 100644 --- a/test-tool/test_write10_residuals.c +++ b/test-tool/test_write10_residuals.c @@ -43,6 +43,14 @@ test_write10_residuals(void) CHECK_FOR_DATALOSS; CHECK_FOR_SBC; + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This WRITE10 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + /* Try a write10 of 1 block but xferlength == 0 */ task = malloc(sizeof(struct scsi_task)); CU_ASSERT_PTR_NOT_NULL(task); @@ -58,11 +66,11 @@ test_write10_residuals(void) * we don't want autoreconnect since some targets will drop the session * on this condition. */ - iscsi_set_noautoreconnect(iscsic, 1); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==0"); - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */ @@ -76,7 +84,7 @@ test_write10_residuals(void) logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -99,7 +107,7 @@ test_write10_residuals(void) task = NULL; /* in case the previous test failed the session */ - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==10000"); @@ -115,13 +123,13 @@ test_write10_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -157,7 +165,7 @@ test_write10_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); @@ -167,7 +175,7 @@ test_write10_residuals(void) && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_INFORMATION_UNIT)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); CU_ASSERT(0); } @@ -206,13 +214,13 @@ test_write10_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -241,8 +249,9 @@ test_write10_residuals(void) logging(LOG_VERBOSE, "Write two blocks of 'a'"); memset(buf, 'a', 10000); - ret = write10(iscsic, tgt_lun, 0, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, 0, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Write one block of 'b' but set iSCSI EDTL to 2 blocks."); @@ -260,13 +269,13 @@ test_write10_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -288,8 +297,9 @@ test_write10_residuals(void) task = NULL; logging(LOG_VERBOSE, "Read the two blocks"); - ret = read10(iscsic, tgt_lun, 0, 2* block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, 2* block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'"); @@ -315,8 +325,9 @@ test_write10_residuals(void) logging(LOG_VERBOSE, "Write two blocks of 'a'"); memset(buf, 'a', 10000); - ret = write10(iscsic, tgt_lun, 0, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, 0, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Write two blocks of 'b' but set iSCSI EDTL to 1 blocks."); @@ -334,13 +345,13 @@ test_write10_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -362,8 +373,9 @@ test_write10_residuals(void) task = NULL; logging(LOG_VERBOSE, "Read the two blocks"); - ret = read10(iscsic, tgt_lun, 0, 2* block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, 2* block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'"); diff --git a/test-tool/test_write10_simple.c b/test-tool/test_write10_simple.c index 6ad4726..aa50f82 100644 --- a/test-tool/test_write10_simple.c +++ b/test-tool/test_write10_simple.c @@ -42,8 +42,9 @@ test_write10_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE10 is not implemented."); CU_PASS("WRITE10 is not implemented."); @@ -57,8 +58,9 @@ test_write10_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write10(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_write10_wrprotect.c b/test-tool/test_write10_wrprotect.c index 2adb17f..84ae438 100644 --- a/test-tool/test_write10_wrprotect.c +++ b/test-tool/test_write10_wrprotect.c @@ -44,9 +44,10 @@ test_write10_wrprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = write10_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, block_size, - i, 0, 0, 0, 0, buf); + ret = write10(sd, 0, + block_size, block_size, + i, 0, 0, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE10 is not implemented."); CU_PASS("WRITE10 is not implemented."); diff --git a/test-tool/test_write12_0blocks.c b/test-tool/test_write12_0blocks.c index ea720a8..9d5cae3 100644 --- a/test-tool/test_write12_0blocks.c +++ b/test-tool/test_write12_0blocks.c @@ -37,8 +37,9 @@ test_write12_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITE12 0-blocks at LBA==0"); - ret = write12(iscsic, tgt_lun, 0, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = write12(sd, 0, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE12 is not implemented."); CU_PASS("WRITE12 is not implemented."); @@ -47,19 +48,22 @@ test_write12_0blocks(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE12 0-blocks one block past end-of-LUN"); - ret = write12_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0, - block_size, 0, 0, 0, 0, 0, NULL); + ret = write12(sd, num_blocks + 1, 0, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE12 0-blocks at LBA==2^31"); - ret = write12_lbaoutofrange(iscsic, tgt_lun, 0x80000000, 0, - block_size, 0, 0, 0, 0, 0, NULL); + ret = write12(sd, 0x80000000, 0, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE12 0-blocks at LBA==-1"); - ret = write12_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = write12(sd, -1, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_write12_beyond_eol.c b/test-tool/test_write12_beyond_eol.c index 405d948..a466356 100644 --- a/test-tool/test_write12_beyond_eol.c +++ b/test-tool/test_write12_beyond_eol.c @@ -44,9 +44,9 @@ test_write12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write12_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write12(sd, num_blocks + 1 - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE12 is not implemented."); CU_PASS("WRITE12 is not implemented."); @@ -61,9 +61,9 @@ test_write12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write12_lbaoutofrange(iscsic, tgt_lun, 0x80000000, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write12(sd, 0x80000000, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -73,8 +73,9 @@ test_write12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write12_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write12(sd, -1, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -84,9 +85,9 @@ test_write12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write12_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write12(sd, num_blocks - 1, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_write12_flags.c b/test-tool/test_write12_flags.c index 860ca38..f2f68d4 100644 --- a/test-tool/test_write12_flags.c +++ b/test-tool/test_write12_flags.c @@ -38,9 +38,9 @@ test_write12_flags(void) logging(LOG_VERBOSE, "Test WRITE12 flags"); logging(LOG_VERBOSE, "Test WRITE12 with DPO==1"); - ret = write12(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 0, 0, 0, buf); + ret = write12(sd, 0, + block_size, block_size, 0, 1, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE12 is not implemented."); CU_PASS("WRITE12 is not implemented."); @@ -50,29 +50,29 @@ test_write12_flags(void) logging(LOG_VERBOSE, "Test WRITE12 with FUA==1 FUA_NV==0"); - ret = write12(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 0, 0, buf); + ret = write12(sd, 0, + block_size, block_size, 0, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE12 with FUA==1 FUA_NV==1"); - ret = write12(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 1, 0, buf); + ret = write12(sd, 0, + block_size, block_size, 0, 0, 1, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE12 with FUA==0 FUA_NV==1"); - ret = write12(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 0, 1, 0, buf); + ret = write12(sd, 0, + block_size, block_size, 0, 0, 0, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE12 with DPO==1 FUA==1 FUA_NV==1"); - ret = write12(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 1, 1, 0, buf); + ret = write12(sd, 0, + block_size, block_size, 0, 1, 1, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_write12_residuals.c b/test-tool/test_write12_residuals.c index 4e278e6..854b840 100644 --- a/test-tool/test_write12_residuals.c +++ b/test-tool/test_write12_residuals.c @@ -43,6 +43,14 @@ test_write12_residuals(void) CHECK_FOR_DATALOSS; CHECK_FOR_SBC; + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This WRITE12 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + /* Try a write12 of 1 block but xferlength == 0 */ task = malloc(sizeof(struct scsi_task)); CU_ASSERT_PTR_NOT_NULL(task); @@ -58,11 +66,11 @@ test_write12_residuals(void) * we don't want autoreconnect since some targets will drop the session * on this condition. */ - iscsi_set_noautoreconnect(iscsic, 1); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==0"); - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */ @@ -76,7 +84,7 @@ test_write12_residuals(void) logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -99,7 +107,7 @@ test_write12_residuals(void) task = NULL; /* in case the previous test failed the session */ - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==10000"); @@ -115,13 +123,13 @@ test_write12_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -157,7 +165,7 @@ test_write12_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); @@ -168,7 +176,7 @@ test_write12_residuals(void) SCSI_SENSE_ASCQ_INVALID_FIELD_IN_INFORMATION_UNIT)) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); CU_ASSERT(0); } @@ -207,13 +215,13 @@ test_write12_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -241,8 +249,9 @@ test_write12_residuals(void) logging(LOG_VERBOSE, "Write two blocks of 'a'"); memset(buf, 'a', 10000); - ret = write12(iscsic, tgt_lun, 0, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write12(sd, 0, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Write one block of 'b' but set iSCSI EDTL to 2 blocks."); @@ -260,13 +269,13 @@ test_write12_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -288,8 +297,9 @@ test_write12_residuals(void) task = NULL; logging(LOG_VERBOSE, "Read the two blocks"); - ret = read12(iscsic, tgt_lun, 0, 2* block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read12(sd, 0, 2* block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'"); @@ -315,8 +325,9 @@ test_write12_residuals(void) logging(LOG_VERBOSE, "Write two blocks of 'a'"); memset(buf, 'a', 10000); - ret = write12(iscsic, tgt_lun, 0, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write12(sd, 0, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Write two blocks of 'b' but set iSCSI EDTL to 1 blocks."); @@ -334,13 +345,13 @@ test_write12_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -362,8 +373,9 @@ test_write12_residuals(void) task = NULL; logging(LOG_VERBOSE, "Read the two blocks"); - ret = read12(iscsic, tgt_lun, 0, 2* block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read12(sd, 0, 2* block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'"); diff --git a/test-tool/test_write12_simple.c b/test-tool/test_write12_simple.c index c5639d7..1d9860b 100644 --- a/test-tool/test_write12_simple.c +++ b/test-tool/test_write12_simple.c @@ -41,8 +41,9 @@ test_write12_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write12(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write12(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE12 is not implemented."); CU_PASS("WRITE12 is not implemented."); @@ -56,8 +57,9 @@ test_write12_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write12(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, buf); + ret = write12(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_write12_wrprotect.c b/test-tool/test_write12_wrprotect.c index daf1093..b48ea12 100644 --- a/test-tool/test_write12_wrprotect.c +++ b/test-tool/test_write12_wrprotect.c @@ -45,9 +45,10 @@ test_write12_wrprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = write12_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, block_size, - i, 0, 0, 0, 0, buf); + ret = write12(sd, 0, + block_size, block_size, + i, 0, 0, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE12 is not implemented."); CU_PASS("WRITE12 is not implemented."); diff --git a/test-tool/test_write16_0blocks.c b/test-tool/test_write16_0blocks.c index fde3006..8eb6c8f 100644 --- a/test-tool/test_write16_0blocks.c +++ b/test-tool/test_write16_0blocks.c @@ -33,8 +33,9 @@ test_write16_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITE16 0-blocks at LBA==0"); - ret = write16(iscsic, tgt_lun, 0, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = write16(sd, 0, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented."); CU_PASS("WRITE16 is not implemented."); @@ -43,19 +44,22 @@ test_write16_0blocks(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE16 0-blocks one block past end-of-LUN"); - ret = write16_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0, - block_size, 0, 0, 0, 0, 0, NULL); + ret = write16(sd, num_blocks + 1, 0, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE16 0-blocks at LBA==2^63"); - ret = write16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000ULL, 0, - block_size, 0, 0, 0, 0, 0, NULL); + ret = write16(sd, 0x8000000000000000ULL, 0, + block_size, 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE16 0-blocks at LBA==-1"); - ret = write16_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size, - 0, 0, 0, 0, 0, NULL); + ret = write16(sd, -1, 0, block_size, + 0, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_write16_beyond_eol.c b/test-tool/test_write16_beyond_eol.c index 7b16327..6da51d6 100644 --- a/test-tool/test_write16_beyond_eol.c +++ b/test-tool/test_write16_beyond_eol.c @@ -42,9 +42,9 @@ test_write16_beyond_eol(void) break; } - ret = write16_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write16(sd, num_blocks + 1 - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented."); CU_PASS("WRITE16 is not implemented."); @@ -59,9 +59,9 @@ test_write16_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000ULL, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write16(sd, 0x8000000000000000ULL, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -71,8 +71,9 @@ test_write16_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write16_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, -1, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -82,9 +83,9 @@ test_write16_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write16_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write16(sd, num_blocks - 1, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_write16_flags.c b/test-tool/test_write16_flags.c index dadaa11..3750c8a 100644 --- a/test-tool/test_write16_flags.c +++ b/test-tool/test_write16_flags.c @@ -39,9 +39,9 @@ test_write16_flags(void) logging(LOG_VERBOSE, "Test WRITE16 flags"); logging(LOG_VERBOSE, "Test WRITE16 with DPO==1"); - ret = write16(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 0, 0, 0, buf); + ret = write16(sd, 0, + block_size, block_size, 0, 1, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented."); CU_PASS("WRITE16 is not implemented."); @@ -51,29 +51,29 @@ test_write16_flags(void) logging(LOG_VERBOSE, "Test WRITE16 with FUA==1 FUA_NV==0"); - ret = write16(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 0, 0, buf); + ret = write16(sd, 0, + block_size, block_size, 0, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE16 with FUA==1 FUA_NV==1"); - ret = write16(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 1, 0, buf); + ret = write16(sd, 0, + block_size, block_size, 0, 0, 1, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE16 with FUA==0 FUA_NV==1"); - ret = write16(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 0, 1, 0, buf); + ret = write16(sd, 0, + block_size, block_size, 0, 0, 0, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITE16 with DPO==1 FUA==1 FUA_NV==1"); - ret = write16(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 1, 1, 0, buf); + ret = write16(sd, 0, + block_size, block_size, 0, 1, 1, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_write16_residuals.c b/test-tool/test_write16_residuals.c index e9ecb1c..6860994 100644 --- a/test-tool/test_write16_residuals.c +++ b/test-tool/test_write16_residuals.c @@ -43,6 +43,14 @@ test_write16_residuals(void) CHECK_FOR_DATALOSS; CHECK_FOR_SBC; + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This WRITE16 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + /* Try a write16 of 1 block but xferlength == 0 */ task = malloc(sizeof(struct scsi_task)); CU_ASSERT_PTR_NOT_NULL(task); @@ -58,11 +66,11 @@ test_write16_residuals(void) * we don't want autoreconnect since some targets will drop the session * on this condition. */ - iscsi_set_noautoreconnect(iscsic, 1); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==0"); - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */ @@ -76,7 +84,7 @@ test_write16_residuals(void) logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -99,7 +107,7 @@ test_write16_residuals(void) task = NULL; /* in case the previous test failed the session */ - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==10000"); @@ -115,13 +123,13 @@ test_write16_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -157,13 +165,13 @@ test_write16_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -202,13 +210,13 @@ test_write16_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -236,8 +244,9 @@ test_write16_residuals(void) logging(LOG_VERBOSE, "Write two blocks of 'a'"); memset(buf, 'a', 10000); - ret = write16(iscsic, tgt_lun, 0, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, 0, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Write one block of 'b' but set iSCSI EDTL to 2 blocks."); @@ -255,13 +264,13 @@ test_write16_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -283,8 +292,9 @@ test_write16_residuals(void) task = NULL; logging(LOG_VERBOSE, "Read the two blocks"); - ret = read16(iscsic, tgt_lun, 0, 2* block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read16(sd, 0, 2* block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'"); @@ -310,8 +320,9 @@ test_write16_residuals(void) logging(LOG_VERBOSE, "Write two blocks of 'a'"); memset(buf, 'a', 10000); - ret = write16(iscsic, tgt_lun, 0, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, 0, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Write two blocks of 'b' but set iSCSI EDTL to 1 blocks."); @@ -329,13 +340,13 @@ test_write16_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -357,8 +368,9 @@ test_write16_residuals(void) task = NULL; logging(LOG_VERBOSE, "Read the two blocks"); - ret = read16(iscsic, tgt_lun, 0, 2* block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read16(sd, 0, 2* block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'"); diff --git a/test-tool/test_write16_simple.c b/test-tool/test_write16_simple.c index f55e40b..10f54ea 100644 --- a/test-tool/test_write16_simple.c +++ b/test-tool/test_write16_simple.c @@ -43,8 +43,9 @@ test_write16_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write16(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented."); CU_PASS("WRITE16 is not implemented."); @@ -58,8 +59,9 @@ test_write16_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = write16(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_write16_wrprotect.c b/test-tool/test_write16_wrprotect.c index bc8e064..242dc2a 100644 --- a/test-tool/test_write16_wrprotect.c +++ b/test-tool/test_write16_wrprotect.c @@ -44,9 +44,10 @@ test_write16_wrprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = write16_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, block_size, - i, 0, 0, 0, 0, buf); + ret = write16(sd, 0, + block_size, block_size, + i, 0, 0, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented."); CU_PASS("WRITE16 is not implemented."); diff --git a/test-tool/test_writesame10_0blocks.c b/test-tool/test_writesame10_0blocks.c index 11ac599..4bcd001 100644 --- a/test-tool/test_writesame10_0blocks.c +++ b/test-tool/test_writesame10_0blocks.c @@ -40,9 +40,10 @@ test_writesame10_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITESAME10 0-blocks at LBA==0 (WSNZ=%d)", inq_bl->wsnz); - ret = writesame10(iscsic, tgt_lun, 0, - block_size, 0, - 0, 0, 0, 0, buf); + memset(buf, 0, block_size); + ret = writesame10(sd, 0, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support WRITESAME10. Skipping test"); return; @@ -59,22 +60,22 @@ test_writesame10_0blocks(void) } logging(LOG_VERBOSE, "Test WRITESAME10 0-blocks one block past end-of-LUN"); - ret = writesame10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, - block_size, 0, - 0, 0, 0, 0, buf); + ret = writesame10(sd, num_blocks + 1, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITESAME10 0-blocks at LBA==2^31"); - ret = writesame10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, - block_size, 0, - 0, 0, 0, 0, buf); + ret = writesame10(sd, 0x80000000, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITESAME10 0-blocks at LBA==-1"); - ret = writesame10_lbaoutofrange(iscsic, tgt_lun, -1, - block_size, 0, - 0, 0, 0, 0, buf); + ret = writesame10(sd, -1, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writesame10_beyond_eol.c b/test-tool/test_writesame10_beyond_eol.c index 5eb4b60..183455e 100644 --- a/test-tool/test_writesame10_beyond_eol.c +++ b/test-tool/test_writesame10_beyond_eol.c @@ -43,9 +43,9 @@ test_writesame10_beyond_eol(void) logging(LOG_VERBOSE, "Test WRITESAME10 1-256 blocks one block beyond the end"); memset(buf, 0, block_size); for (i = 1; i <= 256; i++) { - ret = writesame10_lbaoutofrange(iscsic, tgt_lun, num_blocks - i + 1, - block_size, i, - 0, 0, 0, 0, buf); + ret = writesame10(sd, num_blocks - i + 1, + block_size, i, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support WRITESAME10. Skipping test"); return; @@ -56,27 +56,27 @@ test_writesame10_beyond_eol(void) logging(LOG_VERBOSE, "Test WRITESAME10 1-256 blocks at LBA==2^31"); for (i = 1; i <= 256; i++) { - ret = writesame10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, - block_size, i, - 0, 0, 0, 0, buf); + ret = writesame10(sd, 0x80000000, + block_size, i, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test WRITESAME10 1-256 blocks at LBA==-1"); for (i = 1; i <= 256; i++) { - ret = writesame10_lbaoutofrange(iscsic, tgt_lun, -1, - block_size, i, - 0, 0, 0, 0, buf); + ret = writesame10(sd, -1, + block_size, i, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test WRITESAME10 2-256 blocks all but one block beyond the end"); for (i = 2; i <= 256; i++) { - ret = writesame10_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - block_size, i, - 0, 0, 0, 0, buf); + ret = writesame10(sd, num_blocks - 1, + block_size, i, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_writesame10_simple.c b/test-tool/test_writesame10_simple.c index 3a9c5c3..7f33baf 100644 --- a/test-tool/test_writesame10_simple.c +++ b/test-tool/test_writesame10_simple.c @@ -1,4 +1,3 @@ - /* Copyright (C) 2013 Ronnie Sahlberg @@ -41,9 +40,9 @@ test_writesame10_simple(void) memset(buf, 0, block_size); for (i = 1; i <= 256; i++) { - ret = writesame10(iscsic, tgt_lun, 0, - block_size, i, - 0, 0, 0, 0, buf); + ret = writesame10(sd, 0, + block_size, i, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support WRITESAME10. Skipping test"); return; @@ -53,9 +52,9 @@ test_writesame10_simple(void) logging(LOG_VERBOSE, "Test WRITESAME10 of 1-256 blocks at the end of the LUN"); for (i = 1; i <= 256; i++) { - ret = writesame10(iscsic, tgt_lun, num_blocks - i, - block_size, i, - 0, 0, 0, 0, buf); + ret = writesame10(sd, num_blocks - i, + block_size, i, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writesame10_unmap.c b/test-tool/test_writesame10_unmap.c index bc950d6..07d7870 100644 --- a/test-tool/test_writesame10_unmap.c +++ b/test-tool/test_writesame10_unmap.c @@ -44,16 +44,16 @@ test_writesame10_unmap(void) for (i = 1; i <= 256; i++) { logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); memset(buf, 0xff, i * block_size); - ret = write10(iscsic, tgt_lun, 0, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write10(sd, 0, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME10", i); memset(buf, 0, block_size); - ret = writesame10(iscsic, tgt_lun, 0, - block_size, i, - 0, 1, 0, 0, buf); + ret = writesame10(sd, 0, + block_size, i, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (rc16->lbprz) { @@ -62,9 +62,10 @@ test_writesame10_unmap(void) logging(LOG_VERBOSE, "Read %d blocks and verify they " "are now zero", i); - ret = read10(iscsic, tgt_lun, 0, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, + i * block_size, block_size, + 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); for (j = 0; j < block_size * i; j++) { if (buf[j] != 0) { CU_ASSERT_EQUAL(buf[j], 0); @@ -82,16 +83,16 @@ test_writesame10_unmap(void) for (i = 1; i <= 256; i++) { logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); memset(buf, 0xff, i * block_size); - ret = write10(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write10(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME10", i); memset(buf, 0, block_size); - ret = writesame10(iscsic, tgt_lun, num_blocks - i, - block_size, i, - 0, 1, 0, 0, buf); + ret = writesame10(sd, num_blocks - i, + block_size, i, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (rc16->lbprz) { @@ -100,9 +101,10 @@ test_writesame10_unmap(void) logging(LOG_VERBOSE, "Read %d blocks and verify they " "are now zero", i); - ret = read10(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, num_blocks - i, + i * block_size, block_size, + 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); for (j = 0; j < block_size * i; j++) { if (buf[j] != 0) { CU_ASSERT_EQUAL(buf[j], 0); @@ -116,9 +118,9 @@ test_writesame10_unmap(void) logging(LOG_VERBOSE, "Verify that WRITESAME10 ANCHOR==1 + UNMAP==0 is " "invalid"); - ret = writesame10_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, 1, - 1, 0, 0, 0, buf); + ret = writesame10(sd, 0, + block_size, 1, 1, 0, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); @@ -126,15 +128,15 @@ test_writesame10_unmap(void) if (inq_lbp->anc_sup) { logging(LOG_VERBOSE, "Test WRITESAME10 ANCHOR==1 + UNMAP==0"); memset(buf, 0, block_size); - ret = writesame10(iscsic, tgt_lun, 0, - block_size, 1, - 1, 1, 0, 0, buf); + ret = writesame10(sd, 0, + block_size, 1, 1, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); } else { logging(LOG_VERBOSE, "Test WRITESAME10 ANCHOR==1 + UNMAP==0 no " "ANC_SUP so expecting to fail"); - ret = writesame10_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, 1, - 1, 1, 0, 0, buf); + ret = writesame10(sd, 0, + block_size, 1, 1, 1, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); } CU_ASSERT_EQUAL(ret, 0); @@ -157,16 +159,16 @@ test_writesame10_unmap(void) logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); memset(buf, 0xff, i * block_size); - ret = write10(iscsic, tgt_lun, 0, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write10(sd, 0, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME10", i); memset(buf, 0, block_size); - ret = writesame10(iscsic, tgt_lun, 0, - block_size, i, - 0, 1, 0, 0, buf); + ret = writesame10(sd, 0, + block_size, i, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (rc16->lbprz) { @@ -175,9 +177,10 @@ test_writesame10_unmap(void) logging(LOG_VERBOSE, "Read %d blocks and verify they " "are now zero", i); - ret = read10(iscsic, tgt_lun, 0, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, + i * block_size, block_size, + 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); for (j = 0; j < block_size * i; j++) { if (buf[j] != 0) { CU_ASSERT_EQUAL(buf[j], 0); @@ -193,9 +196,9 @@ test_writesame10_unmap(void) "INVALID_FIELD_IN_CDB."); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME10", i); - ret = writesame10_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, i, - 0, 1, 0, 0, buf); + ret = writesame10(sd, 0, + block_size, i, 0, 1, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_writesame10_unmap_unaligned.c b/test-tool/test_writesame10_unmap_unaligned.c index 9085500..3a121eb 100644 --- a/test-tool/test_writesame10_unmap_unaligned.c +++ b/test-tool/test_writesame10_unmap_unaligned.c @@ -41,9 +41,9 @@ test_writesame10_unmap_unaligned(void) logging(LOG_VERBOSE, "Test that unaligned WRITESAME10 Unmap succeeds. LBPPB==%d", lbppb); for (i = 1; i < lbppb; i++) { logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME10 at LBA:%d", lbppb - i, i); - ret = writesame10(iscsic, tgt_lun, i, - block_size, lbppb - i, - 0, 1, 0, 0, buf); + ret = writesame10(sd, i, + block_size, lbppb - i, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_writesame10_unmap_until_end.c b/test-tool/test_writesame10_unmap_until_end.c index 8cbc761..6b9bfdd 100644 --- a/test-tool/test_writesame10_unmap_until_end.c +++ b/test-tool/test_writesame10_unmap_until_end.c @@ -47,15 +47,15 @@ test_writesame10_unmap_until_end(void) logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); memset(buf, 0xff, block_size * i); - ret = write10(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write10(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME10", i); - ret = writesame10(iscsic, tgt_lun, num_blocks - i, - block_size, i, - 0, 1, 0, 0, buf); + ret = writesame10(sd, num_blocks - i, + block_size, i, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (rc16->lbprz) { @@ -64,9 +64,10 @@ test_writesame10_unmap_until_end(void) logging(LOG_VERBOSE, "Read %d blocks and verify they " "are now zero", i); - ret = read10(iscsic, tgt_lun, num_blocks - i, + ret = read10(sd, NULL, num_blocks - i, i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); for (j = 0; j < i; j++) { CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0); } diff --git a/test-tool/test_writesame10_unmap_vpd.c b/test-tool/test_writesame10_unmap_vpd.c index 98a1308..736fac9 100644 --- a/test-tool/test_writesame10_unmap_vpd.c +++ b/test-tool/test_writesame10_unmap_vpd.c @@ -42,10 +42,9 @@ test_writesame10_unmap_vpd(void) logging(LOG_VERBOSE, "Check if WRITESAME10 can be used for UNMAP."); logging(LOG_VERBOSE, "Unmap 1 block using WRITESAME10"); memset(buf, 0, block_size); - ret = writesame10(iscsic, tgt_lun, 0, - block_size, 1, - 0, 1, 0, 0, buf); - + ret = writesame10(sd, 0, + block_size, 1, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret != 0) { logging(LOG_VERBOSE, "WRITESAME10 UNMAP is not available. " "Verify that VPD settings reflect this."); diff --git a/test-tool/test_writesame10_wrprotect.c b/test-tool/test_writesame10_wrprotect.c index 579457a..ad02d06 100644 --- a/test-tool/test_writesame10_wrprotect.c +++ b/test-tool/test_writesame10_wrprotect.c @@ -45,9 +45,9 @@ test_writesame10_wrprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = writesame10_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, 1, - 0, 0, i, 0, buf); + ret = writesame10(sd, 0, + block_size, 1, 0, 0, i, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITESAME10 is not implemented."); CU_PASS("WRITESAME10 is not implemented."); diff --git a/test-tool/test_writesame16_0blocks.c b/test-tool/test_writesame16_0blocks.c index 3223f6b..b9091c4 100644 --- a/test-tool/test_writesame16_0blocks.c +++ b/test-tool/test_writesame16_0blocks.c @@ -27,6 +27,7 @@ void test_writesame16_0blocks(void) { int ret; + unsigned char *buf = alloca(block_size); CHECK_FOR_DATALOSS; CHECK_FOR_SBC; @@ -34,9 +35,10 @@ test_writesame16_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITESAME16 0-blocks at LBA==0 (WSNZ=%d)", inq_bl->wsnz); - ret = writesame16(iscsic, tgt_lun, 0, - block_size, 0, - 0, 0, 0, 0, NULL); + memset(buf, 0, block_size); + ret = writesame16(sd, 0, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITESAME16 is not implemented."); CU_PASS("[SKIPPED] Target does not support WRITESAME16. Skipping test"); @@ -54,22 +56,22 @@ test_writesame16_0blocks(void) } logging(LOG_VERBOSE, "Test WRITESAME16 0-blocks one block past end-of-LUN"); - ret = writesame16_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, - block_size, inq_bl->wsnz, - 0, 0, 0, 0, NULL); + ret = writesame16(sd, num_blocks + 1, + block_size, inq_bl->wsnz, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITESAME16 0-blocks at LBA==2^63"); - ret = writesame16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000ULL, - block_size, inq_bl->wsnz, - 0, 0, 0, 0, NULL); + ret = writesame16(sd, 0x8000000000000000ULL, + block_size, inq_bl->wsnz, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITESAME16 0-blocks at LBA==-1"); - ret = writesame16_lbaoutofrange(iscsic, tgt_lun, -1, - block_size, inq_bl->wsnz, - 0, 0, 0, 0, NULL); + ret = writesame16(sd, -1, + block_size, inq_bl->wsnz, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writesame16_beyond_eol.c b/test-tool/test_writesame16_beyond_eol.c index ca5dfb7..4a68ace 100644 --- a/test-tool/test_writesame16_beyond_eol.c +++ b/test-tool/test_writesame16_beyond_eol.c @@ -38,9 +38,9 @@ test_writesame16_beyond_eol(void) logging(LOG_VERBOSE, "Test WRITESAME16 1-256 blocks one block beyond the end"); memset(buf, 0, block_size); for (i = 1; i <= 256; i++) { - ret = writesame16_lbaoutofrange(iscsic, tgt_lun, num_blocks - i + 1, - block_size, i, - 0, 0, 0, 0, buf); + ret = writesame16(sd, num_blocks - i + 1, + block_size, i, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITESAME16 is not implemented."); CU_PASS("[SKIPPED] Target does not support WRITESAME16. Skipping test"); @@ -52,27 +52,27 @@ test_writesame16_beyond_eol(void) logging(LOG_VERBOSE, "Test WRITESAME16 1-256 blocks at LBA==2^63"); for (i = 1; i <= 256; i++) { - ret = writesame16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000ULL, - block_size, i, - 0, 0, 0, 0, buf); + ret = writesame16(sd, 0x8000000000000000ULL, + block_size, i, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test WRITESAME16 1-256 blocks at LBA==-1"); for (i = 1; i <= 256; i++) { - ret = writesame16_lbaoutofrange(iscsic, tgt_lun, -1, - block_size, i, - 0, 0, 0, 0, buf); + ret = writesame16(sd, -1, + block_size, i, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test WRITESAME16 2-256 blocks all but one block beyond the end"); for (i = 2; i <= 256; i++) { - ret = writesame16_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - block_size, i, - 0, 0, 0, 0, buf); + ret = writesame16(sd, num_blocks - 1, + block_size, i, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_writesame16_simple.c b/test-tool/test_writesame16_simple.c index c9ac093..ac7eded 100644 --- a/test-tool/test_writesame16_simple.c +++ b/test-tool/test_writesame16_simple.c @@ -40,9 +40,9 @@ test_writesame16_simple(void) memset(buf, 0, block_size); for (i = 1; i <= 256; i++) { - ret = writesame16(iscsic, tgt_lun, 0, - block_size, i, - 0, 0, 0, 0, buf); + ret = writesame16(sd, 0, + block_size, i, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITESAME16 is not implemented."); CU_PASS("[SKIPPED] Target does not support WRITESAME16. Skipping test"); @@ -53,9 +53,9 @@ test_writesame16_simple(void) logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the end of the LUN"); for (i = 1; i <= 256; i++) { - ret = writesame16(iscsic, tgt_lun, num_blocks - i, - block_size, i, - 0, 0, 0, 0, buf); + ret = writesame16(sd, num_blocks - i, + block_size, i, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writesame16_unmap.c b/test-tool/test_writesame16_unmap.c index 513cb5d..04280c8 100644 --- a/test-tool/test_writesame16_unmap.c +++ b/test-tool/test_writesame16_unmap.c @@ -46,15 +46,14 @@ test_writesame16_unmap(void) for (i = 1; i <= 256; i++) { logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); memset(buf, 0xff, i * block_size); - ret = write16(iscsic, tgt_lun, 0, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); - + ret = write16(sd, 0, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i); memset(buf, 0, block_size); - ret = writesame16(iscsic, tgt_lun, 0, - block_size, i, - 0, 1, 0, 0, buf); + ret = writesame16(sd, 0, + block_size, i, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITESAME16 is not implemented."); CU_PASS("[SKIPPED] Target does not support WRITESAME16. Skipping test"); @@ -67,9 +66,10 @@ test_writesame16_unmap(void) "blocks back and verify they are all zero"); logging(LOG_VERBOSE, "Read %d blocks and verify they " "are now zero", i); - ret = read16(iscsic, tgt_lun, 0, + ret = read16(sd, 0, i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); for (j = 0; j < i; j++) { CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0); } @@ -84,16 +84,16 @@ test_writesame16_unmap(void) for (i = 1; i <= 256; i++) { logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); memset(buf, 0xff, i * block_size); - ret = write16(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write16(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i); memset(buf, 0, block_size); - ret = writesame16(iscsic, tgt_lun, num_blocks - i, - block_size, i, - 0, 1, 0, 0, buf); + ret = writesame16(sd, num_blocks - i, + block_size, i, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (rc16->lbprz) { @@ -101,9 +101,10 @@ test_writesame16_unmap(void) "blocks back and verify they are all zero"); logging(LOG_VERBOSE, "Read %d blocks and verify they " "are now zero", i); - ret = read16(iscsic, tgt_lun, num_blocks - i, + ret = read16(sd, num_blocks - i, i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); for (j = 0; j < i; j++) { CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0); } @@ -114,9 +115,9 @@ test_writesame16_unmap(void) } logging(LOG_VERBOSE, "Verify that WRITESAME16 ANCHOR==1 + UNMAP==0 is invalid"); - ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, 1, - 1, 0, 0, 0, buf); + ret = writesame16(sd, 0, + block_size, 1, 1, 0, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); @@ -124,14 +125,14 @@ test_writesame16_unmap(void) if (inq_lbp->anc_sup) { logging(LOG_VERBOSE, "Test WRITESAME16 ANCHOR==1 + UNMAP==0"); memset(buf, 0, block_size); - ret = writesame16(iscsic, tgt_lun, 0, - block_size, 1, - 1, 1, 0, 0, buf); + ret = writesame16(sd, 0, + block_size, 1, 1, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); } else { logging(LOG_VERBOSE, "Test WRITESAME16 ANCHOR==1 + UNMAP==0 no ANC_SUP so expecting to fail"); - ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, 1, - 1, 1, 0, 0, buf); + ret = writesame16(sd, 0, + block_size, 1, 1, 1, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); } CU_ASSERT_EQUAL(ret, 0); @@ -155,16 +156,16 @@ test_writesame16_unmap(void) logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); memset(buf, 0xff, i * block_size); - ret = write16(iscsic, tgt_lun, 0, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write16(sd, 0, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i); memset(buf, 0, block_size); - ret = writesame16(iscsic, tgt_lun, 0, - block_size, i, - 0, 1, 0, 0, buf); + ret = writesame16(sd, 0, + block_size, i, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (rc16->lbprz) { @@ -173,9 +174,10 @@ test_writesame16_unmap(void) logging(LOG_VERBOSE, "Read %d blocks and verify they " "are now zero", i); - ret = read16(iscsic, tgt_lun, 0, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = read16(sd, 0, + i * block_size, block_size, + 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); for (j = 0; j < i; j++) { CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0); } @@ -189,9 +191,9 @@ test_writesame16_unmap(void) "INVALID_FIELD_IN_CDB."); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i); - ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, i, - 0, 1, 0, 0, buf); + ret = writesame16(sd, 0, + block_size, i, 0, 1, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); } @@ -206,16 +208,16 @@ test_writesame16_unmap(void) logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); memset(buf, 0xff, i * block_size); - ret = write16(iscsic, tgt_lun, 0, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = write16(sd, 0, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i); memset(buf, 0, block_size); - ret = writesame16(iscsic, tgt_lun, 0, - block_size, i, - 0, 1, 0, 0, buf); + ret = writesame16(sd, 0, + block_size, i, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); if (rc16->lbprz) { @@ -224,9 +226,10 @@ test_writesame16_unmap(void) logging(LOG_VERBOSE, "Read %d blocks and verify they " "are now zero", i); - ret = read16(iscsic, tgt_lun, 0, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + ret = read16(sd, 0, + i * block_size, block_size, + 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); for (j = 0; j < i; j++) { CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0); } @@ -240,9 +243,9 @@ test_writesame16_unmap(void) "INVALID_FIELD_IN_CDB."); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i); - ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, i, - 0, 1, 0, 0, buf); + ret = writesame16(sd, 0, + block_size, i, 0, 1, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writesame16_unmap_unaligned.c b/test-tool/test_writesame16_unmap_unaligned.c index 41d8ab5..b25c499 100644 --- a/test-tool/test_writesame16_unmap_unaligned.c +++ b/test-tool/test_writesame16_unmap_unaligned.c @@ -41,8 +41,9 @@ test_writesame16_unmap_unaligned(void) for (i = 1; i < lbppb; i++) { logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16 at LBA:%d", lbppb - i, i); - ret = writesame16(iscsic, tgt_lun, i, 0, lbppb - i, - 0, 1, 0, 0, NULL); + ret = writesame16(sd, i, 0, lbppb - i, + 0, 1, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITESAME16 is not implemented."); CU_PASS("[SKIPPED] Target does not support WRITESAME16. Skipping test"); diff --git a/test-tool/test_writesame16_unmap_until_end.c b/test-tool/test_writesame16_unmap_until_end.c index 71c2347..76e0d58 100644 --- a/test-tool/test_writesame16_unmap_until_end.c +++ b/test-tool/test_writesame16_unmap_until_end.c @@ -47,14 +47,13 @@ test_writesame16_unmap_until_end(void) for (i = 1; i <= 256; i++) { logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); memset(buf, 0xff, block_size * i); - ret = write16(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, - 0, 0, 0, 0, 0, buf); - + ret = write16(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i); - ret = writesame16(iscsic, tgt_lun, num_blocks - i, - 0, i, - 0, 1, 0, 0, NULL); + ret = writesame16(sd, num_blocks - i, + 0, i, 0, 1, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITESAME16 is not implemented."); CU_PASS("[SKIPPED] Target does not support WRITESAME16. Skipping test"); @@ -68,9 +67,10 @@ test_writesame16_unmap_until_end(void) logging(LOG_VERBOSE, "Read %d blocks and verify they " "are now zero", i); - ret = read16(iscsic, tgt_lun, num_blocks - i, + ret = read16(sd, num_blocks - i, i * block_size, block_size, - 0, 0, 0, 0, 0, buf); + 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); for (j = 0; j < i; j++) { CU_ASSERT_EQUAL(memcmp(buf + j*block_size, zeroBlock, block_size), 0); } diff --git a/test-tool/test_writesame16_unmap_vpd.c b/test-tool/test_writesame16_unmap_vpd.c index 4489eea..81c8c4c 100644 --- a/test-tool/test_writesame16_unmap_vpd.c +++ b/test-tool/test_writesame16_unmap_vpd.c @@ -43,10 +43,9 @@ test_writesame16_unmap_vpd(void) logging(LOG_VERBOSE, "Unmap 1 block using WRITESAME16"); memset(buf, 0, block_size); - ret = writesame16(iscsic, tgt_lun, 0, - block_size, 1, - 0, 1, 0, 0, buf); - + ret = writesame16(sd, 0, + block_size, 1, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret != 0) { logging(LOG_VERBOSE, "WRITESAME16 UNMAP is not available. " "Verify that VPD settings reflect this."); diff --git a/test-tool/test_writesame16_wrprotect.c b/test-tool/test_writesame16_wrprotect.c index 8128ef5..001306c 100644 --- a/test-tool/test_writesame16_wrprotect.c +++ b/test-tool/test_writesame16_wrprotect.c @@ -45,9 +45,9 @@ test_writesame16_wrprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, 1, - 0, 0, i, 0, buf); + ret = writesame16(sd, 0, + block_size, 1, 0, 0, i, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITESAME16 is not implemented."); CU_PASS("[SKIPPED] Target does not support WRITESAME16. Skipping test"); diff --git a/test-tool/test_writeverify10_0blocks.c b/test-tool/test_writeverify10_0blocks.c index 920fc40..bda5bbe 100644 --- a/test-tool/test_writeverify10_0blocks.c +++ b/test-tool/test_writeverify10_0blocks.c @@ -37,8 +37,9 @@ test_writeverify10_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITEVERIFY10 0-blocks at LBA==0"); - ret = writeverify10(iscsic, tgt_lun, 0, 0, block_size, - 0, 0, 0, 0, NULL); + ret = writeverify10(sd, 0, 0, block_size, + 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY10 is not implemented."); CU_PASS("WRITEVERIFY10 is not implemented."); @@ -47,19 +48,22 @@ test_writeverify10_0blocks(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITEVERIFY10 0-blocks one block past end-of-LUN"); - ret = writeverify10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0, - block_size, 0, 0, 0, 0, NULL); + ret = writeverify10(sd, num_blocks + 1, 0, + block_size, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITEVERIFY10 0-blocks at LBA==2^31"); - ret = writeverify10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, 0, - block_size, 0, 0, 0, 0, NULL); + ret = writeverify10(sd, 0x80000000, 0, + block_size, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITEVERIFY10 0-blocks at LBA==-1"); - ret = writeverify10_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size, - 0, 0, 0, 0, NULL); + ret = writeverify10(sd, -1, 0, block_size, + 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writeverify10_beyond_eol.c b/test-tool/test_writeverify10_beyond_eol.c index b89b000..6dad866 100644 --- a/test-tool/test_writeverify10_beyond_eol.c +++ b/test-tool/test_writeverify10_beyond_eol.c @@ -44,11 +44,11 @@ test_writeverify10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeverify10_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i * block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify10(sd, num_blocks + 1 - i, + i * block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE1VERIFY10 is not implemented."); + logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY10 is not implemented."); CU_PASS("WRITEVERIFY10 is not implemented."); return; } @@ -61,9 +61,9 @@ test_writeverify10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeverify10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, - i * block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify10(sd, 0x80000000, + i * block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -73,8 +73,9 @@ test_writeverify10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeverify10_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size, - block_size, 0, 0, 0, 0, buf); + ret = writeverify10(sd, -1, i * block_size, + block_size, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -84,9 +85,9 @@ test_writeverify10_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeverify10_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i * block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify10(sd, num_blocks - 1, + i * block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_writeverify10_flags.c b/test-tool/test_writeverify10_flags.c index 48a8425..2461cbe 100644 --- a/test-tool/test_writeverify10_flags.c +++ b/test-tool/test_writeverify10_flags.c @@ -38,9 +38,9 @@ test_writeverify10_flags(void) logging(LOG_VERBOSE, "Test WRITEVERIFY10 flags"); logging(LOG_VERBOSE, "Test WRITEVERIFY10 with DPO==1"); - ret = writeverify10(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 0, 0, buf); + ret = writeverify10(sd, 0, + block_size, block_size, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY10 is not implemented."); CU_PASS("WRITEVERIFY10 is not implemented."); @@ -49,8 +49,8 @@ test_writeverify10_flags(void) CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITEVERIFY10 with BYTCHK==1"); - ret = writeverify10(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 0, buf); + ret = writeverify10(sd, 0, + block_size, block_size, 0, 0, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writeverify10_residuals.c b/test-tool/test_writeverify10_residuals.c index 881da07..287ec85 100644 --- a/test-tool/test_writeverify10_residuals.c +++ b/test-tool/test_writeverify10_residuals.c @@ -43,9 +43,18 @@ test_writeverify10_residuals(void) CHECK_FOR_DATALOSS; CHECK_FOR_SBC; + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This WRITEVERIFY10 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + /* check if writeverify10 is supported */ - ret = writeverify10(iscsic, tgt_lun, 0, 0, - block_size, 0, 0, 0, 0, NULL); + ret = writeverify10(sd, 0, 0, + block_size, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support WRITEVERIFY10. Skipping test"); return; @@ -66,11 +75,11 @@ test_writeverify10_residuals(void) * we don't want autoreconnect since some targets will drop the session * on this condition. */ - iscsi_set_noautoreconnect(iscsic, 1); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==0"); - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */ @@ -84,7 +93,7 @@ test_writeverify10_residuals(void) logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -107,7 +116,7 @@ test_writeverify10_residuals(void) task = NULL; /* in case the previous test failed the session */ - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==10000"); @@ -123,13 +132,13 @@ test_writeverify10_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -165,13 +174,13 @@ test_writeverify10_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -210,13 +219,13 @@ test_writeverify10_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -245,8 +254,9 @@ test_writeverify10_residuals(void) logging(LOG_VERBOSE, "Write two blocks of 'a'"); memset(buf, 'a', 10000); - ret = write10(iscsic, tgt_lun, 0, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, 0, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Write one block of 'b' but set iSCSI EDTL to 2 blocks."); @@ -264,13 +274,13 @@ test_writeverify10_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -292,8 +302,9 @@ test_writeverify10_residuals(void) task = NULL; logging(LOG_VERBOSE, "Read the two blocks"); - ret = read10(iscsic, tgt_lun, 0, 2* block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, 2* block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'"); @@ -319,8 +330,9 @@ test_writeverify10_residuals(void) logging(LOG_VERBOSE, "Write two blocks of 'a'"); memset(buf, 'a', 10000); - ret = write10(iscsic, tgt_lun, 0, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write10(sd, 0, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Write two blocks of 'b' but set iSCSI EDTL to 1 blocks."); @@ -338,13 +350,13 @@ test_writeverify10_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -366,8 +378,9 @@ test_writeverify10_residuals(void) task = NULL; logging(LOG_VERBOSE, "Read the two blocks"); - ret = read10(iscsic, tgt_lun, 0, 2* block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read10(sd, NULL, 0, 2* block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'"); diff --git a/test-tool/test_writeverify10_simple.c b/test-tool/test_writeverify10_simple.c index f44d93a..4e64767 100644 --- a/test-tool/test_writeverify10_simple.c +++ b/test-tool/test_writeverify10_simple.c @@ -41,8 +41,9 @@ test_writeverify10_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeverify10(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, buf); + ret = writeverify10(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY10 is not implemented."); CU_PASS("[SKIPPED] Target does not support WRITEVERIFY10. Skipping test"); @@ -56,8 +57,9 @@ test_writeverify10_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeverify10(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, buf); + ret = writeverify10(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writeverify10_wrprotect.c b/test-tool/test_writeverify10_wrprotect.c index 649f042..7364ddb 100644 --- a/test-tool/test_writeverify10_wrprotect.c +++ b/test-tool/test_writeverify10_wrprotect.c @@ -44,11 +44,12 @@ test_writeverify10_wrprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = writeverify10_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, block_size, - i, 0, 0, 0, buf); + ret = writeverify10(sd, 0, + block_size, block_size, + i, 0, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE1VERIFY10 is not implemented."); + logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY10 is not implemented."); CU_PASS("WRITEVERIFY10 is not implemented."); return; } diff --git a/test-tool/test_writeverify12_0blocks.c b/test-tool/test_writeverify12_0blocks.c index 1d8b60d..4f84f21 100644 --- a/test-tool/test_writeverify12_0blocks.c +++ b/test-tool/test_writeverify12_0blocks.c @@ -37,29 +37,33 @@ test_writeverify12_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITEVERIFY12 0-blocks at LBA==0"); - ret = writeverify12(iscsic, tgt_lun, 0, 0, block_size, - 0, 0, 0, 0, NULL); + ret = writeverify12(sd, 0, 0, block_size, + 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE1VERIFY12 is not implemented."); + logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY12 is not implemented."); CU_PASS("WRITEVERIFY12 is not implemented."); return; } CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITEVERIFY12 0-blocks one block past end-of-LUN"); - ret = writeverify12_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, 0, - block_size, 0, 0, 0, 0, NULL); + ret = writeverify12(sd, num_blocks + 1, 0, + block_size, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITEVERIFY12 0-blocks at LBA==2^31"); - ret = writeverify12_lbaoutofrange(iscsic, tgt_lun, 0x80000000, 0, - block_size, 0, 0, 0, 0, NULL); + ret = writeverify12(sd, 0x80000000, 0, + block_size, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITEVERIFY12 0-blocks at LBA==-1"); - ret = writeverify12_lbaoutofrange(iscsic, tgt_lun, -1, 0, block_size, - 0, 0, 0, 0, NULL); + ret = writeverify12(sd, -1, 0, block_size, + 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writeverify12_beyond_eol.c b/test-tool/test_writeverify12_beyond_eol.c index 29d900b..0a158c4 100644 --- a/test-tool/test_writeverify12_beyond_eol.c +++ b/test-tool/test_writeverify12_beyond_eol.c @@ -44,11 +44,11 @@ test_writeverify12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeverify12_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i, - i * block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify12(sd, num_blocks + 1 - i, + i * block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE1VERIFY12 is not implemented."); + logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY12 is not implemented."); CU_PASS("WRITEVERIFY12 is not implemented."); return; } @@ -61,9 +61,9 @@ test_writeverify12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeverify12_lbaoutofrange(iscsic, tgt_lun, 0x80000000, - i * block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify12(sd, 0x80000000, + i * block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -73,8 +73,9 @@ test_writeverify12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeverify12_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size, - block_size, 0, 0, 0, 0, buf); + ret = writeverify12(sd, -1, i * block_size, + block_size, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -84,9 +85,9 @@ test_writeverify12_beyond_eol(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeverify12_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, - i * block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify12(sd, num_blocks - 1, + i * block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_writeverify12_flags.c b/test-tool/test_writeverify12_flags.c index 719ca16..a894e29 100644 --- a/test-tool/test_writeverify12_flags.c +++ b/test-tool/test_writeverify12_flags.c @@ -38,19 +38,19 @@ test_writeverify12_flags(void) logging(LOG_VERBOSE, "Test WRITEVERIFY12 flags"); logging(LOG_VERBOSE, "Test WRITEVERIFY12 with DPO==1"); - ret = writeverify12(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 0, 0, buf); + ret = writeverify12(sd, 0, + block_size, block_size, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE1VERIFY12 is not implemented."); + logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY12 is not implemented."); CU_PASS("WRITEVERIFY12 is not implemented."); return; } CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITEVERIFY12 with BYTCHK==1"); - ret = writeverify12(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 0, buf); + ret = writeverify12(sd, 0, + block_size, block_size, 0, 0, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writeverify12_residuals.c b/test-tool/test_writeverify12_residuals.c index ac7e731..879bbf8 100644 --- a/test-tool/test_writeverify12_residuals.c +++ b/test-tool/test_writeverify12_residuals.c @@ -43,9 +43,18 @@ test_writeverify12_residuals(void) CHECK_FOR_DATALOSS; CHECK_FOR_SBC; + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This WRITEVERIFY12 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + /* check if writeverify12 is supported */ - ret = writeverify12(iscsic, tgt_lun, 0, 0, - block_size, 0, 0, 0, 0, NULL); + ret = writeverify12(sd, 0, 0, + block_size, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support WRITEVERIFY12. Skipping test"); return; @@ -66,11 +75,11 @@ test_writeverify12_residuals(void) * we don't want autoreconnect since some targets will drop the session * on this condition. */ - iscsi_set_noautoreconnect(iscsic, 1); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==0"); - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */ @@ -84,7 +93,7 @@ test_writeverify12_residuals(void) logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -107,7 +116,7 @@ test_writeverify12_residuals(void) task = NULL; /* in case the previous test failed the session */ - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==10000"); @@ -123,13 +132,13 @@ test_writeverify12_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -165,13 +174,13 @@ test_writeverify12_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -210,13 +219,13 @@ test_writeverify12_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -245,8 +254,9 @@ test_writeverify12_residuals(void) logging(LOG_VERBOSE, "Write two blocks of 'a'"); memset(buf, 'a', 10000); - ret = write12(iscsic, tgt_lun, 0, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write12(sd, 0, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Write one block of 'b' but set iSCSI EDTL to 2 blocks."); @@ -264,13 +274,13 @@ test_writeverify12_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -292,8 +302,9 @@ test_writeverify12_residuals(void) task = NULL; logging(LOG_VERBOSE, "Read the two blocks"); - ret = read12(iscsic, tgt_lun, 0, 2* block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read12(sd, 0, 2* block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'"); @@ -319,8 +330,9 @@ test_writeverify12_residuals(void) logging(LOG_VERBOSE, "Write two blocks of 'a'"); memset(buf, 'a', 10000); - ret = write12(iscsic, tgt_lun, 0, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write12(sd, 0, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Write two blocks of 'b' but set iSCSI EDTL to 1 blocks."); @@ -338,13 +350,13 @@ test_writeverify12_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -366,8 +378,9 @@ test_writeverify12_residuals(void) task = NULL; logging(LOG_VERBOSE, "Read the two blocks"); - ret = read12(iscsic, tgt_lun, 0, 2* block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read12(sd, 0, 2* block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'"); diff --git a/test-tool/test_writeverify12_simple.c b/test-tool/test_writeverify12_simple.c index 1b51bde..1fc0054 100644 --- a/test-tool/test_writeverify12_simple.c +++ b/test-tool/test_writeverify12_simple.c @@ -41,10 +41,11 @@ test_writeverify12_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeverify12(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, buf); + ret = writeverify12(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE1VERIFY12 is not implemented."); + logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY12 is not implemented."); CU_PASS("WRITEVERIFY12 is not implemented."); return; } @@ -56,8 +57,9 @@ test_writeverify12_simple(void) if (maximum_transfer_length && maximum_transfer_length < i) { break; } - ret = writeverify12(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, buf); + ret = writeverify12(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writeverify12_wrprotect.c b/test-tool/test_writeverify12_wrprotect.c index 7c44ada..fac88d4 100644 --- a/test-tool/test_writeverify12_wrprotect.c +++ b/test-tool/test_writeverify12_wrprotect.c @@ -44,11 +44,12 @@ test_writeverify12_wrprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = writeverify12_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, block_size, - i, 0, 0, 0, buf); + ret = writeverify12(sd, 0, + block_size, block_size, + i, 0, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE1VERIFY12 is not implemented."); + logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY12 is not implemented."); CU_PASS("WRITEVERIFY12 is not implemented."); return; } diff --git a/test-tool/test_writeverify16_0blocks.c b/test-tool/test_writeverify16_0blocks.c index d2b7780..ef0d29c 100644 --- a/test-tool/test_writeverify16_0blocks.c +++ b/test-tool/test_writeverify16_0blocks.c @@ -33,33 +33,33 @@ test_writeverify16_0blocks(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITEVERIFY16 0-blocks at LBA==0"); - ret = writeverify16(iscsic, tgt_lun, 0, - 0, block_size, - 0, 0, 0, 0, NULL); + ret = writeverify16(sd, 0, + 0, block_size, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE1VERIFY16 is not implemented."); + logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY16 is not implemented."); CU_PASS("WRITEVERIFY16 is not implemented."); return; } CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITEVERIFY16 0-blocks one block past end-of-LUN"); - ret = writeverify16_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1, - 0, block_size, - 0, 0, 0, 0, NULL); + ret = writeverify16(sd, num_blocks + 1, + 0, block_size, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITEVERIFY16 0-blocks at LBA==2^63"); - ret = writeverify16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000ULL, - 0, block_size, - 0, 0, 0, 0, NULL); + ret = writeverify16(sd, 0x8000000000000000ULL, + 0, block_size, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITEVERIFY16 0-blocks at LBA==-1"); - ret = writeverify16_lbaoutofrange(iscsic, tgt_lun, -1, - 0, block_size, - 0, 0, 0, 0, NULL); + ret = writeverify16(sd, -1, + 0, block_size, 0, 0, 0, 0, NULL, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writeverify16_beyond_eol.c b/test-tool/test_writeverify16_beyond_eol.c index a1db917..7af0a7f 100644 --- a/test-tool/test_writeverify16_beyond_eol.c +++ b/test-tool/test_writeverify16_beyond_eol.c @@ -41,12 +41,11 @@ test_writeverify16_beyond_eol(void) break; } - ret = writeverify16_lbaoutofrange(iscsic, tgt_lun, - num_blocks + 1 - i, - i * block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify16(sd, num_blocks + 1 - i, + i * block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE1VERIFY16 is not implemented."); + logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY16 is not implemented."); CU_PASS("WRITEVERIFY16 is not implemented."); return; } @@ -60,10 +59,9 @@ test_writeverify16_beyond_eol(void) break; } - ret = writeverify16_lbaoutofrange(iscsic, tgt_lun, - 0x8000000000000000ULL, - i * block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify16(sd, 0x8000000000000000ULL, + i * block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -74,10 +72,9 @@ test_writeverify16_beyond_eol(void) break; } - ret = writeverify16_lbaoutofrange(iscsic, tgt_lun, - -1, - i * block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify16(sd, -1, + i * block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } @@ -88,10 +85,9 @@ test_writeverify16_beyond_eol(void) break; } - ret = writeverify16_lbaoutofrange(iscsic, tgt_lun, - num_blocks - 1, - i * block_size, block_size, - 0, 0, 0, 0, buf); + ret = writeverify16(sd, num_blocks - 1, + i * block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_LBA_OOB); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_writeverify16_flags.c b/test-tool/test_writeverify16_flags.c index b94d539..911a417 100644 --- a/test-tool/test_writeverify16_flags.c +++ b/test-tool/test_writeverify16_flags.c @@ -38,19 +38,19 @@ test_writeverify16_flags(void) logging(LOG_VERBOSE, "Test WRITEVERIFY16 flags"); logging(LOG_VERBOSE, "Test WRITEVERIFY16 with DPO==1"); - ret = writeverify16(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 1, 0, 0, buf); + ret = writeverify16(sd, 0, + block_size, block_size, 0, 1, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE1VERIFY16 is not implemented."); + logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY16 is not implemented."); CU_PASS("WRITEVERIFY16 is not implemented."); return; } CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Test WRITEVERIFY16 with BYTCHK==1"); - ret = writeverify16(iscsic, tgt_lun, 0, - block_size, block_size, - 0, 0, 1, 0, buf); + ret = writeverify16(sd, 0, + block_size, block_size, 0, 0, 1, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writeverify16_residuals.c b/test-tool/test_writeverify16_residuals.c index dc19f03..72f84a8 100644 --- a/test-tool/test_writeverify16_residuals.c +++ b/test-tool/test_writeverify16_residuals.c @@ -43,15 +43,32 @@ test_writeverify16_residuals(void) CHECK_FOR_DATALOSS; CHECK_FOR_SBC; + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] This WRITEVERIFY16 test is only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + /* check if writeverify16 is supported */ - ret = writeverify16(iscsic, tgt_lun, 0, 0, - block_size, 0, 0, 0, 0, NULL); + ret = writeverify16(sd, 0, 0, + block_size, 0, 0, 0, 0, NULL, + EXPECT_STATUS_GOOD); if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE1VERIFY16 is not implemented."); + logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY16 is not implemented."); CU_PASS("[SKIPPED] Target does not support WRITEVERIFY16. Skipping test"); return; } + if (sd->iscsi_ctx == NULL) { + const char *err = "[SKIPPED] WRITEVERIFY16 tests are only " + "supported for iSCSI backends"; + logging(LOG_NORMAL, "%s", err); + CU_PASS(err); + return; + } + /* Try a writeverify16 of 1 block but xferlength == 0 */ task = malloc(sizeof(struct scsi_task)); CU_ASSERT_PTR_NOT_NULL(task); @@ -67,11 +84,11 @@ test_writeverify16_residuals(void) * we don't want autoreconnect since some targets will drop the session * on this condition. */ - iscsi_set_noautoreconnect(iscsic, 1); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 1); logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==0"); - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL); CU_ASSERT_PTR_NOT_NULL(task_ret); CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */ @@ -85,7 +102,7 @@ test_writeverify16_residuals(void) logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -108,7 +125,7 @@ test_writeverify16_residuals(void) task = NULL; /* in case the previous test failed the session */ - iscsi_set_noautoreconnect(iscsic, 0); + iscsi_set_noautoreconnect(sd->iscsi_ctx, 0); logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==10000"); @@ -124,13 +141,13 @@ test_writeverify16_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -166,13 +183,13 @@ test_writeverify16_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -211,13 +228,13 @@ test_writeverify16_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -246,8 +263,9 @@ test_writeverify16_residuals(void) logging(LOG_VERBOSE, "Write two blocks of 'a'"); memset(buf, 'a', 10000); - ret = write16(iscsic, tgt_lun, 0, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, 0, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Write one block of 'b' but set iSCSI EDTL to 2 blocks."); @@ -265,13 +283,13 @@ test_writeverify16_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -293,8 +311,9 @@ test_writeverify16_residuals(void) task = NULL; logging(LOG_VERBOSE, "Read the two blocks"); - ret = read16(iscsic, tgt_lun, 0, 2* block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read16(sd, 0, 2* block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'"); @@ -320,8 +339,9 @@ test_writeverify16_residuals(void) logging(LOG_VERBOSE, "Write two blocks of 'a'"); memset(buf, 'a', 10000); - ret = write16(iscsic, tgt_lun, 0, 2 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = write16(sd, 0, 2 * block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Write two blocks of 'b' but set iSCSI EDTL to 1 blocks."); @@ -339,13 +359,13 @@ test_writeverify16_residuals(void) data.size = task->expxferlen; data.data = &buf[0]; - task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data); + task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data); CU_ASSERT_PTR_NOT_NULL(task_ret); logging(LOG_VERBOSE, "Verify that the target returned SUCCESS"); if (task->status != SCSI_STATUS_GOOD) { logging(LOG_VERBOSE, "[FAILED] Target returned error %s", - iscsi_get_error(iscsic)); + iscsi_get_error(sd->iscsi_ctx)); } CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD); @@ -367,8 +387,9 @@ test_writeverify16_residuals(void) task = NULL; logging(LOG_VERBOSE, "Read the two blocks"); - ret = read16(iscsic, tgt_lun, 0, 2* block_size, - block_size, 0, 0, 0, 0, 0, buf); + ret = read16(sd, 0, 2* block_size, + block_size, 0, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'"); diff --git a/test-tool/test_writeverify16_simple.c b/test-tool/test_writeverify16_simple.c index 6c864a1..d36558a 100644 --- a/test-tool/test_writeverify16_simple.c +++ b/test-tool/test_writeverify16_simple.c @@ -43,10 +43,11 @@ test_writeverify16_simple(void) break; } - ret = writeverify16(iscsic, tgt_lun, 0, i * block_size, - block_size, 0, 0, 0, 0, buf); + ret = writeverify16(sd, 0, i * block_size, + block_size, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE1VERIFY16 is not implemented."); + logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY16 is not implemented."); CU_PASS("WRITEVERIFY16 is not implemented."); return; } @@ -59,8 +60,9 @@ test_writeverify16_simple(void) break; } - ret = writeverify16(iscsic, tgt_lun, num_blocks - i, - i * block_size, block_size, 0, 0, 0, 0, buf); + ret = writeverify16(sd, num_blocks - i, + i * block_size, block_size, 0, 0, 0, 0, buf, + EXPECT_STATUS_GOOD); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writeverify16_wrprotect.c b/test-tool/test_writeverify16_wrprotect.c index df46ce5..48ef14a 100644 --- a/test-tool/test_writeverify16_wrprotect.c +++ b/test-tool/test_writeverify16_wrprotect.c @@ -46,11 +46,12 @@ test_writeverify16_wrprotect(void) if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { - ret = writeverify16_invalidfieldincdb(iscsic, tgt_lun, 0, - block_size, block_size, - i, 0, 0, 0, buf); + ret = writeverify16(sd, 0, + block_size, block_size, + i, 0, 0, 0, buf, + EXPECT_INVALID_FIELD_IN_CDB); if (ret == -2) { - logging(LOG_NORMAL, "[SKIPPED] WRITE1VERIFY16 is not implemented."); + logging(LOG_NORMAL, "[SKIPPED] WRITEVERIFY16 is not implemented."); CU_PASS("WRITEVERIFY16 is not implemented."); return; } diff --git a/utils/iscsi-swp.c b/utils/iscsi-swp.c index fc34281..c282df4 100644 --- a/utils/iscsi-swp.c +++ b/utils/iscsi-swp.c @@ -206,6 +206,9 @@ int main(int argc, char *argv[]) goto finished; } + /* For MODE SELECT PS is reserved and hence must be cleared */ + mp->ps = 0; + printf("SWP:%d\n", mp->control.swp); switch (swp) {