TESTS: Create helpers for PREFETCH16 and switch all tests over to them

This commit is contained in:
Ronnie Sahlberg
2012-12-25 08:57:05 -08:00
parent 047b650151
commit 2afb5accc4
8 changed files with 165 additions and 346 deletions

View File

@@ -34,6 +34,7 @@ int T0240_prefetch10_simple(const char *initiator, const char *url, int data_los
printf("Test basic PREFETCH10 functionality.\n");
printf("1, Verify we can prefetch the first 0-256 blocks of the LUN.\n");
printf("2, Verify we can prefetch the last 0-256 blocks of the LUN.\n");
printf("\n");
return 0;
}

View File

@@ -32,9 +32,8 @@ int T0250_prefetch16_simple(const char *initiator, const char *url, int data_los
printf("===================\n");
if (show_info) {
printf("Test basic PREFETCH16 functionality.\n");
printf("1, Verify we can prefetch the first 1-256 blocks of the LUN.\n");
printf("2, Verify we can prefetch the last 1-256 blocks of the LUN.\n");
printf("3, Verify we can prefetch the last 256 blocks of the LUN by setting LEN==0.\n");
printf("1, Verify we can prefetch the first 0-256 blocks of the LUN.\n");
printf("2, Verify we can prefetch the last 0-256 blocks of the LUN.\n");
printf("\n");
return 0;
}
@@ -70,80 +69,25 @@ int T0250_prefetch16_simple(const char *initiator, const char *url, int data_los
ret = 0;
/* prefetch the first 1 - 256 blocks at the start of the LUN */
printf("Prefetching first 1-256 blocks ... ");
for (i = 1; i <= 256; i++) {
task = iscsi_prefetch16_sync(iscsi, lun, 0, i, 0, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send prefetch16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test2;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("Opcode is not implemented on target\n");
scsi_free_scsi_task(task);
ret = -2;
/* prefetch the first 0 - 256 blocks at the start of the LUN */
printf("Prefetching first 0-256 blocks.\n");
for (i = 0; i <= 256; i++) {
ret = prefetch16(iscsi, lun, 0, i, 0, 0);
if (ret != 0) {
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("Prefetch16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test2;
}
scsi_free_scsi_task(task);
}
printf("[OK]\n");
test2:
/* Prefetch the last 0 - 255 blocks at the end of the LUN */
printf("Prefetching last 0-255 blocks ... ");
printf("Prefetching last 0-255 blocks.\n");
for (i = 1; i < 256; i++) {
task = iscsi_prefetch16_sync(iscsi, lun, num_blocks - i, i, 0, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send prefetch16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test3;
ret = prefetch16(iscsi, lun, num_blocks - i, i, 0, 0);
if (ret != 0) {
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("Prefetch16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test3;
}
scsi_free_scsi_task(task);
}
printf("[OK]\n");
test3:
printf("Prefetching last 0-255 blocks ... ");
task = iscsi_prefetch16_sync(iscsi, lun, num_blocks - 256, 0, 0, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send prefetch16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test4;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("Prefetch16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test4;
}
scsi_free_scsi_task(task);
printf("[OK]\n");
test4:
finished:
iscsi_logout_sync(iscsi);

View File

@@ -69,56 +69,22 @@ int T0251_prefetch16_flags(const char *initiator, const char *url, int data_loss
ret = 0;
/* prefetch with IMMED==1 */
printf("Prefetch with IMMED==1 ... ");
task = iscsi_prefetch16_sync(iscsi, lun, 0, 1, 1, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send prefetch16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test2;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("Opcode is not implemented on target\n");
scsi_free_scsi_task(task);
ret = -2;
printf("Check PREFETCH16 with IMMED==1.\n");
ret = prefetch16(iscsi, lun, 0, 1, 1, 0);
if (ret != 0) {
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("Prefetch16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test2;
}
scsi_free_scsi_task(task);
printf("[OK]\n");
test2:
/* Prefetch with GROUPNUMBER==0..31 */
printf("Prefetching with GROUPNEMBER==0..31 ... ");
printf("Check PREFETCH16 with GROUPNEMBER 0-31.\n");
for (i = 0; i < 32; i++) {
task = iscsi_prefetch16_sync(iscsi, lun, 0, 1, 0, i);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send prefetch16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test3;
ret = prefetch16(iscsi, lun, 0, 1, 0, i);
if (ret != 0) {
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("Prefetch16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test3;
}
scsi_free_scsi_task(task);
}
printf("[OK]\n");
test3:
finished:
iscsi_logout_sync(iscsi);

View File

@@ -72,136 +72,46 @@ int T0252_prefetch16_beyondeol(const char *initiator, const char *url, int data_
ret = 0;
/* prefetch 1-256 blocks, one block beyond the end-of-lun */
printf("Prefetch last 1-256 blocks one block beyond eol ... ");
printf("Prefetch last 1-256 blocks one block beyond eol.\n");
for (i = 1; i <= 256; i++) {
task = iscsi_prefetch16_sync(iscsi, lun, num_blocks + 2 - i, i, 0, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send prefetch16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test2;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("Opcode is not implemented on target\n");
scsi_free_scsi_task(task);
ret = -2;
ret = prefetch16_lbaoutofrange(iscsi, lun, num_blocks + 2 - i, i, 0, 0);
if (ret != 0) {
goto finished;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
printf("[FAILED]\n");
printf("PREFETCH16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test2;
}
scsi_free_scsi_task(task);
}
printf("[OK]\n");
test2:
/* Prefetch 1 - 256 blocks at LBA 2^63 */
printf("Prefetch 1-256 blocks at LBA 2^63 ... ");
printf("Prefetch 1-256 blocks at LBA 2^63.\n");
for (i = 1; i <= 256; i++) {
task = iscsi_prefetch16_sync(iscsi, lun, 0x8000000000000000, i, 0, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send PREFETCH16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test3;
ret = prefetch16_lbaoutofrange(iscsi, lun, 0x8000000000000000, i, 0, 0);
if (ret != 0) {
goto finished;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("PREFETCH16 command should fail for LBA 2^31\n");
ret = -1;
scsi_free_scsi_task(task);
goto test3;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
printf("[FAILED]\n");
printf("PREFETCH16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test3;
}
scsi_free_scsi_task(task);
}
printf("[OK]\n");
test3:
/* prefetch 1 - 256 blocks at LBA -1 */
printf("Prefetch 1-256 blocks at LBA -1.\n");
for (i = 1; i <= 256; i++) {
task = iscsi_prefetch16_sync(iscsi, lun, -1, i, 0, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send PREFETCH16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test4;
ret = prefetch16_lbaoutofrange(iscsi, lun, -1, i, 0, 0);
if (ret != 0) {
goto finished;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("PREFETCH16 command should fail for LBA -1\n");
ret = -1;
scsi_free_scsi_task(task);
goto test4;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
printf("[FAILED]\n");
printf("PREFETCH16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test4;
}
scsi_free_scsi_task(task);
}
printf("[OK]\n");
test4:
/* prefetch 2-256 blocks, all but one block beyond the eol */
printf("Prefetch 1-255 blocks beyond eol starting at last block ... ");
printf("Prefetch 1-255 blocks beyond eol starting at last block.\n");
for (i=2; i<=256; i++) {
task = iscsi_prefetch16_sync(iscsi, lun, num_blocks, i, 0, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send PREFETCH16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test5;
ret = prefetch16_lbaoutofrange(iscsi, lun, num_blocks, i, 0, 0);
if (ret != 0) {
goto finished;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("PREFETCH16 beyond end-of-lun did not return sense.\n");
ret = -1;
scsi_free_scsi_task(task);
goto test5;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
printf("[FAILED]\n");
printf("PREFETCH16 failed but ascq was wrong. Should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test5;
}
scsi_free_scsi_task(task);
}
printf("[OK]\n");
test5:
finished:
iscsi_logout_sync(iscsi);
iscsi_destroy_context(iscsi);

View File

@@ -71,123 +71,38 @@ int T0253_prefetch16_0blocks(const char *initiator, const char *url, int data_lo
ret = 0;
/* prefetch 0 blocks at the start of the LUN */
printf("PREFETCH16 0blocks at LBA==0 ... ");
task = iscsi_prefetch16_sync(iscsi, lun, 0, 0, 0, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send PREFETCH16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test2;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
printf("[SKIPPED]\n");
printf("Opcode is not implemented on target\n");
scsi_free_scsi_task(task);
ret = -2;
/* prefetch 0blocks at the start of the LUN */
printf("PREFETCH16 0blocks at LBA==0.\n");
ret = prefetch16(iscsi, lun, 0, 0, 0, 0);
if (ret != 0) {
goto finished;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("PREFETCH16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test2;
}
scsi_free_scsi_task(task);
printf("[OK]\n");
test2:
/* Prefetch 0 blocks beyond end of the LUN */
printf("PREFETCH16 0blocks at one block beyond <end-of-LUN> ... ");
task = iscsi_prefetch16_sync(iscsi, lun, num_blocks + 1, 0, 0, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send PREFETCH16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test3;
printf("PREFETCH16 0blocks at one block beyond <end-of-LUN>.\n");
ret = prefetch16_lbaoutofrange(iscsi, lun, num_blocks + 1, 0, 0, 0);
if (ret != 0) {
goto finished;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("PREFETCH16 command: Should fail when reading 0blocks beyond end\n");
ret = -1;
scsi_free_scsi_task(task);
goto test3;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
printf("[FAILED]\n");
printf("PREFETCH16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test3;
}
scsi_free_scsi_task(task);
printf("[OK]\n");
test3:
/* Prefetch 0 blocks at 2^63 */
printf("PREFETCH16 0blocks at LBA:2^63 ... ");
task = iscsi_prefetch16_sync(iscsi, lun, 0x8000000000000000ULL, 0, 0, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send PREFETCH16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test4;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("PREFETCH16 command: Should fail when prefetching at LBA 2^63\n");
ret = -1;
scsi_free_scsi_task(task);
goto test4;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
printf("[FAILED]\n");
printf("PREFETCH16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test4;
}
scsi_free_scsi_task(task);
printf("[OK]\n");
test4:
/* Prefetch 0 blocks at -1 */
printf("PREFETCH16 0blocks at LBA:-1 ... ");
task = iscsi_prefetch16_sync(iscsi, lun, 0xffffffffffffffffULL, 0, 0, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send PREFETCH16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto test5;
/* Prefetch 0blocks at LBA:2^63 */
printf("PREFETCH16 0blocks at LBA:2^63.\n");
ret = prefetch16_lbaoutofrange(iscsi, lun, 0x8000000000000000, 0, 0, 0);
if (ret != 0) {
goto finished;
}
/* Prefetch 0blocks at LBA:-1 */
printf("PREFETCH16 0blocks at LBA:-1.\n");
ret = prefetch16_lbaoutofrange(iscsi, lun, 0xffffffffffffffff, 0, 0, 0);
if (ret != 0) {
goto finished;
}
if (task->status == SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("PREFETCH16 command: Should fail when prefetching at LBA -1\n");
ret = -1;
scsi_free_scsi_task(task);
goto test5;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST
|| task->sense.ascq != SCSI_SENSE_ASCQ_LBA_OUT_OF_RANGE) {
printf("[FAILED]\n");
printf("PREFETCH16 failed but with the wrong sense code. It should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
ret = -1;
scsi_free_scsi_task(task);
goto test5;
}
scsi_free_scsi_task(task);
printf("[OK]\n");
test5:
finished:
iscsi_logout_sync(iscsi);

View File

@@ -353,27 +353,8 @@ int T0370_nomedia(const char *initiator, const char *url, int data_loss, int sho
prefetch10_nomedium(iscsi, lun, 0, 1, 1, 0);
printf("Test PREFETCH16 ... ");
task = iscsi_prefetch16_sync(iscsi, lun, 0, 1, 1, 0);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send PREFETCH16 command: %s\n", iscsi_get_error(iscsi));
ret = -1;
goto finished;
}
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)) {
printf("[FAILED]\n");
printf("PREFETCH16 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
ret = -1;
scsi_free_scsi_task(task);
goto finished;
}
scsi_free_scsi_task(task);
printf("[OK]\n");
printf("Test PREFETCH16.\n");
prefetch16_nomedium(iscsi, lun, 0, 1, 1, 0);
printf("Test VERIFY10 ... ");

View File

@@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <poll.h>
#include <popt.h>
@@ -802,7 +803,7 @@ int prefetch10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_block
task = iscsi_prefetch10_sync(iscsi, lun, lba, num_blocks, immed, group);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send prefetch10 command: %s\n", iscsi_get_error(iscsi));
printf("Failed to send PREFETCH10 command: %s\n", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
@@ -832,7 +833,7 @@ int prefetch10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba,
task = iscsi_prefetch10_sync(iscsi, lun, lba, num_blocks, immed, group);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send prefetch10 command: %s\n", iscsi_get_error(iscsi));
printf("Failed to send PREFETCH10 command: %s\n", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
@@ -865,7 +866,7 @@ int prefetch10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int
task = iscsi_prefetch10_sync(iscsi, lun, lba, num_blocks, immed, group);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send prefetch10 command: %s\n", iscsi_get_error(iscsi));
printf("Failed to send PREFETCH10 command: %s\n", iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
@@ -892,6 +893,104 @@ int prefetch10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int
return 0;
}
int prefetch16(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int immed, int group)
{
struct scsi_task *task;
printf("Send PREFETCH16 LBA:%" PRIu64 " Count:%d IMEMD:%d GROUP:%d ... ", lba, num_blocks, immed, group);
task = iscsi_prefetch16_sync(iscsi, lun, lba, num_blocks, immed, group);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send PREFETCH16 command: %s\n", 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) {
printf("[SKIPPED]\n");
printf("PREFETCH16 is not implemented on target\n");
scsi_free_scsi_task(task);
return -2;
}
if (task->status != SCSI_STATUS_GOOD) {
printf("[FAILED]\n");
printf("PREFETCH16 command: failed with sense. %s\n", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
scsi_free_scsi_task(task);
printf("[OK]\n");
return 0;
}
int prefetch16_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int immed, int group)
{
struct scsi_task *task;
printf("Send PREFETCH16 LBA:%" PRIu64 " Count:%d IMEMD:%d GROUP:%d (expecting ILLEGAL_REQUEST/LBA_OUT_OF_RANGE) ... ", lba, num_blocks, immed, group);
task = iscsi_prefetch16_sync(iscsi, lun, lba, num_blocks, immed, group);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send PREFETCH16 command: %s\n", 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) {
printf("[SKIPPED]\n");
printf("PREFETCH16 is not implemented on target\n");
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_LBA_OUT_OF_RANGE) {
printf("[FAILED]\n");
printf("PREFETCH16 should have failed with ILLEGAL_REQUEST/LBA_OUT_OF_RANGE. Sense:%s\n", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
return 0;
}
int prefetch16_nomedium(struct iscsi_context *iscsi, int lun, uint64_t lba, int num_blocks, int immed, int group)
{
struct scsi_task *task;
printf("Send PREFETCH16 LBA:%" PRIu64 " Count:%d IMEMD:%d GROUP:%d (expecting NOT_READY/MEDIUM_NOT_PRESENT) ... ", lba, num_blocks, immed, group);
task = iscsi_prefetch16_sync(iscsi, lun, lba, num_blocks, immed, group);
if (task == NULL) {
printf("[FAILED]\n");
printf("Failed to send PREFETCH16 command: %s\n", 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) {
printf("[SKIPPED]\n");
printf("PREFETCH16 is not implemented on target\n");
scsi_free_scsi_task(task);
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)) {
printf("[FAILED]\n");
printf("PREFETCH16 after eject failed with the wrong sense code. Should fail with NOT_READY/MEDIUM_NOT_PRESENT*\n");
scsi_free_scsi_task(task);
return -1;
}
printf("[OK]\n");
scsi_free_scsi_task(task);
return 0;
}
int main(int argc, const char *argv[])
{

View File

@@ -258,5 +258,8 @@ int testunitready_conflict(struct iscsi_context *iscsi, int lun);
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);
#endif /* _ISCSI_TEST_H_ */