From 2afb5accc4ae80590786acba8a0b06f923906ee0 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 25 Dec 2012 08:57:05 -0800 Subject: [PATCH] TESTS: Create helpers for PREFETCH16 and switch all tests over to them --- test-tool/0240_prefetch10_simple.c | 1 + test-tool/0250_prefetch16_simple.c | 78 +++------------- test-tool/0251_prefetch16_flags.c | 50 ++-------- test-tool/0252_prefetch16_beyondeol.c | 122 ++++-------------------- test-tool/0253_prefetch16_0blocks.c | 129 +++++--------------------- test-tool/0370_nomedia.c | 23 +---- test-tool/iscsi-test.c | 105 ++++++++++++++++++++- test-tool/iscsi-test.h | 3 + 8 files changed, 165 insertions(+), 346 deletions(-) diff --git a/test-tool/0240_prefetch10_simple.c b/test-tool/0240_prefetch10_simple.c index cd23ff2..163594a 100644 --- a/test-tool/0240_prefetch10_simple.c +++ b/test-tool/0240_prefetch10_simple.c @@ -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; } diff --git a/test-tool/0250_prefetch16_simple.c b/test-tool/0250_prefetch16_simple.c index 26e15b8..cc9dd98 100644 --- a/test-tool/0250_prefetch16_simple.c +++ b/test-tool/0250_prefetch16_simple.c @@ -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); diff --git a/test-tool/0251_prefetch16_flags.c b/test-tool/0251_prefetch16_flags.c index f0df610..5d62dae 100644 --- a/test-tool/0251_prefetch16_flags.c +++ b/test-tool/0251_prefetch16_flags.c @@ -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); diff --git a/test-tool/0252_prefetch16_beyondeol.c b/test-tool/0252_prefetch16_beyondeol.c index 27767d1..a3fc6a4 100644 --- a/test-tool/0252_prefetch16_beyondeol.c +++ b/test-tool/0252_prefetch16_beyondeol.c @@ -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); diff --git a/test-tool/0253_prefetch16_0blocks.c b/test-tool/0253_prefetch16_0blocks.c index 4206390..5a62467 100644 --- a/test-tool/0253_prefetch16_0blocks.c +++ b/test-tool/0253_prefetch16_0blocks.c @@ -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 ... "); - 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 .\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); diff --git a/test-tool/0370_nomedia.c b/test-tool/0370_nomedia.c index e49cf77..17429b7 100644 --- a/test-tool/0370_nomedia.c +++ b/test-tool/0370_nomedia.c @@ -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 ... "); diff --git a/test-tool/iscsi-test.c b/test-tool/iscsi-test.c index a28a79d..b091530 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -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[]) { diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index 2ee2ee4..e9816f5 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -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_ */