TESTS: convert readcapacity to new api
Signed-off-by: Ronnie Sahlberg <sahlberg@localhost>
This commit is contained in:
committed by
Ronnie Sahlberg
parent
46eaa7dcc3
commit
fd21a8f2c4
@@ -1764,171 +1764,47 @@ read16(struct iscsi_context *iscsi, int lun, uint64_t lba,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
readcapacity10(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi)
|
readcapacity10(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi, int status, enum scsi_sense_key key, int *ascq, int num_ascq)
|
||||||
{
|
{
|
||||||
struct scsi_task *task;
|
struct scsi_task *task;
|
||||||
|
int ret;
|
||||||
|
|
||||||
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);
|
lba, pmi);
|
||||||
|
|
||||||
task = iscsi_readcapacity10_sync(iscsi, lun, lba, pmi);
|
task = scsi_cdb_readcapacity10(lba, pmi);
|
||||||
if (task == NULL) {
|
assert(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
scsi_free_scsi_task(task);
|
task = iscsi_scsi_command_sync(iscsi, lun, task, NULL);
|
||||||
logging(LOG_VERBOSE, "[OK] READCAPACITY10 returned SUCCESS.");
|
|
||||||
return 0;
|
ret = check_result("READCAPACITY10", iscsi, task, status, key, ascq, num_ascq);
|
||||||
|
if (task) {
|
||||||
|
scsi_free_scsi_task(task);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
readcapacity10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi)
|
readcapacity16(struct iscsi_context *iscsi, int lun, int alloc_len, int status, enum scsi_sense_key key, int *ascq, int num_ascq)
|
||||||
{
|
{
|
||||||
struct scsi_task *task;
|
struct scsi_task *task;
|
||||||
|
int ret;
|
||||||
|
|
||||||
logging(LOG_VERBOSE, "Send READCAPACITY10 (Expecting MEDIUM_NOT_PRESENT) "
|
logging(LOG_VERBOSE, "Send READCAPACITY16 (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 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);
|
|
||||||
|
|
||||||
task = scsi_cdb_serviceactionin16(SCSI_READCAPACITY16, alloc_len);
|
task = scsi_cdb_serviceactionin16(SCSI_READCAPACITY16, alloc_len);
|
||||||
if (task == NULL) {
|
assert(task != NULL);
|
||||||
logging(LOG_NORMAL, "Out-of-memory: Failed to create "
|
|
||||||
"READCAPACITY16 cdb.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
task = iscsi_scsi_command_sync(iscsi, lun, task, NULL);
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
scsi_free_scsi_task(task);
|
ret = check_result("READCAPACITY16", iscsi, task, status, key, ascq, num_ascq);
|
||||||
logging(LOG_VERBOSE, "[OK] READCAPACITY16 returned SUCCESS.");
|
if (task) {
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
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) {
|
return ret;
|
||||||
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
|
int
|
||||||
|
|||||||
@@ -267,10 +267,8 @@ struct scsi_task *read10_task(struct iscsi_context *iscsi, int lun, uint32_t lba
|
|||||||
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 status, enum scsi_sense_key key, int *ascq, int num_ascq);
|
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 status, enum scsi_sense_key key, int *ascq, int num_ascq);
|
||||||
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 status, enum scsi_sense_key key, int *ascq, int num_ascq);
|
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 status, enum scsi_sense_key key, int *ascq, int num_ascq);
|
||||||
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 status, enum scsi_sense_key key, int *ascq, int num_ascq);
|
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 status, enum scsi_sense_key key, int *ascq, int num_ascq);
|
||||||
int readcapacity10(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi);
|
int readcapacity10(struct iscsi_context *iscsi, int lun, uint32_t lba, int pmi, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
|
||||||
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 status, enum scsi_sense_key key, int *ascq, int num_ascq);
|
||||||
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(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 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 release6(struct iscsi_context *iscsi, int lun);
|
||||||
|
|||||||
@@ -41,12 +41,14 @@ test_mandatory_sbc(void)
|
|||||||
CU_ASSERT_EQUAL(ret, 0);
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
|
||||||
logging(LOG_VERBOSE, "Test READCAPACITY10.");
|
logging(LOG_VERBOSE, "Test READCAPACITY10.");
|
||||||
ret = readcapacity10(iscsic, tgt_lun, 0, 0);
|
ret = readcapacity10(iscsic, tgt_lun, 0, 0,
|
||||||
|
EXPECT_STATUS_GOOD);
|
||||||
CU_ASSERT_EQUAL(ret, 0);
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
|
||||||
if (sbc3_support) {
|
if (sbc3_support) {
|
||||||
logging(LOG_VERBOSE, "Test READCAPACITY16. The device claims SBC-3 support.");
|
logging(LOG_VERBOSE, "Test READCAPACITY16. The device claims SBC-3 support.");
|
||||||
ret = readcapacity16(iscsic, tgt_lun, 15);
|
ret = readcapacity16(iscsic, tgt_lun, 15,
|
||||||
|
EXPECT_STATUS_GOOD);
|
||||||
CU_ASSERT_EQUAL(ret, 0);
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,11 +91,13 @@ test_nomedia_sbc(void)
|
|||||||
CU_ASSERT_EQUAL(ret, 0);
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
|
||||||
logging(LOG_VERBOSE, "Test READCAPACITY10 when medium is ejected.");
|
logging(LOG_VERBOSE, "Test READCAPACITY10 when medium is ejected.");
|
||||||
ret = readcapacity10_nomedium(iscsic, tgt_lun, 0, 0);
|
ret = readcapacity10(iscsic, tgt_lun, 0, 0,
|
||||||
|
EXPECT_NO_MEDIUM);
|
||||||
CU_ASSERT_EQUAL(ret, 0);
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
|
|
||||||
logging(LOG_VERBOSE, "Test READCAPACITY16 when medium is ejected.");
|
logging(LOG_VERBOSE, "Test READCAPACITY16 when medium is ejected.");
|
||||||
ret = readcapacity16_nomedium(iscsic, tgt_lun, 15);
|
ret = readcapacity16(iscsic, tgt_lun, 15,
|
||||||
|
EXPECT_NO_MEDIUM);
|
||||||
if (ret == -2) {
|
if (ret == -2) {
|
||||||
if (sbc3_support) {
|
if (sbc3_support) {
|
||||||
logging(LOG_NORMAL, "[FAILED] READCAPACITY16 is not available but the device claims SBC-3 support.");
|
logging(LOG_NORMAL, "[FAILED] READCAPACITY16 is not available but the device claims SBC-3 support.");
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2013 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
|
Copyright (C) 2013 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
|
||||||
|
|
||||||
@@ -35,6 +34,7 @@ test_readcapacity10_simple(void)
|
|||||||
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||||
logging(LOG_VERBOSE, "Test basic READCAPACITY10");
|
logging(LOG_VERBOSE, "Test basic READCAPACITY10");
|
||||||
|
|
||||||
ret = readcapacity10(iscsic, tgt_lun, 0, 0);
|
ret = readcapacity10(iscsic, tgt_lun, 0, 0,
|
||||||
|
EXPECT_STATUS_GOOD);
|
||||||
CU_ASSERT_EQUAL(ret, 0);
|
CU_ASSERT_EQUAL(ret, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ test_readcapacity16_alloclen(void)
|
|||||||
logging(LOG_VERBOSE, "Test that READCAPACITY16 with alloc_len 0-15 is not an error");
|
logging(LOG_VERBOSE, "Test that READCAPACITY16 with alloc_len 0-15 is not an error");
|
||||||
|
|
||||||
for (i = 0; i < 16; i++) {
|
for (i = 0; i < 16; i++) {
|
||||||
ret = readcapacity16(iscsic, tgt_lun, i);
|
ret = readcapacity16(iscsic, tgt_lun, i,
|
||||||
|
EXPECT_STATUS_GOOD);
|
||||||
if (ret == -2) {
|
if (ret == -2) {
|
||||||
logging(LOG_NORMAL, "[SKIPPED] READCAPACITY16 is not implemented on this target and it does not claim SBC-3 support.");
|
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.");
|
CU_PASS("READCAPACITY16 is not implemented and no SBC-3 support claimed.");
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ test_readcapacity16_simple(void)
|
|||||||
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
logging(LOG_VERBOSE, LOG_BLANK_LINE);
|
||||||
logging(LOG_VERBOSE, "Test that READCAPACITY16 works");
|
logging(LOG_VERBOSE, "Test that READCAPACITY16 works");
|
||||||
|
|
||||||
ret = readcapacity16(iscsic, tgt_lun, 16);
|
ret = readcapacity16(iscsic, tgt_lun, 16,
|
||||||
|
EXPECT_STATUS_GOOD);
|
||||||
if (ret == -2) {
|
if (ret == -2) {
|
||||||
logging(LOG_NORMAL, "[SKIPPED] READCAPACITY16 is not implemented on this target and it does not claim support.");
|
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.");
|
CU_PASS("READCAPACITY16 is not implemented and no SBC-3 support claimed.");
|
||||||
|
|||||||
Reference in New Issue
Block a user