From 047b650151d6a2055e793ac5d36cf40330795de4 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Tue, 25 Dec 2012 08:31:30 -0800 Subject: [PATCH] TEST: Add helpers for PREFETCH10 and convert all tests to use them --- test-tool/0240_prefetch10_simple.c | 87 ++++------------- test-tool/0241_prefetch10_flags.c | 50 ++-------- test-tool/0242_prefetch10_beyondeol.c | 132 ++++---------------------- test-tool/0243_prefetch10_0blocks.c | 111 ++++------------------ test-tool/0370_nomedia.c | 23 +---- test-tool/iscsi-test.c | 103 +++++++++++++++++++- test-tool/iscsi-test.h | 3 + 7 files changed, 165 insertions(+), 344 deletions(-) diff --git a/test-tool/0240_prefetch10_simple.c b/test-tool/0240_prefetch10_simple.c index 6f3f499..cd23ff2 100644 --- a/test-tool/0240_prefetch10_simple.c +++ b/test-tool/0240_prefetch10_simple.c @@ -32,10 +32,8 @@ int T0240_prefetch10_simple(const char *initiator, const char *url, int data_los printf("===================\n"); if (show_info) { printf("Test basic PREFETCH10 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("\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"); return 0; } @@ -70,78 +68,25 @@ int T0240_prefetch10_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_prefetch10_sync(iscsi, lun, 0, i, 0, 0); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send prefetch10 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 = prefetch10(iscsi, lun, 0, i, 0, 0); + if (ret != 0) { goto finished; } - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("Prefetch10 command: failed with sense. %s\n", iscsi_get_error(iscsi)); - ret = -1; - scsi_free_scsi_task(task); - goto test2; + } + + + /* Prefetch the last 0 - 256 blocks at the end of the LUN */ + printf("Prefetching last 0-256 blocks.\n"); + for (i = 0; i <= 256; i++) { + ret = prefetch10(iscsi, lun, num_blocks - i, i, 0, 0); + if (ret != 0) { + goto finished; } - scsi_free_scsi_task(task); } - printf("[OK]\n"); -test2: - - /* Prefetch the last 0 - 255 blocks at the end of the LUN */ - printf("Prefetching last 1-255 blocks ... "); - for (i = 1; i < 256; i++) { - task = iscsi_prefetch10_sync(iscsi, lun, num_blocks - i, i, 0, 0); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send prefetch10 command: %s\n", iscsi_get_error(iscsi)); - ret = -1; - goto test3; - } - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("Prefetch10 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: - task = iscsi_prefetch10_sync(iscsi, lun, num_blocks - 256, 0, 0, 0); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send prefetch10 command: %s\n", iscsi_get_error(iscsi)); - ret = -1; - goto test4; - } - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("Prefetch10 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/0241_prefetch10_flags.c b/test-tool/0241_prefetch10_flags.c index 0b86092..c4c2a23 100644 --- a/test-tool/0241_prefetch10_flags.c +++ b/test-tool/0241_prefetch10_flags.c @@ -69,56 +69,22 @@ int T0241_prefetch10_flags(const char *initiator, const char *url, int data_loss ret = 0; /* prefetch with IMMED==1 */ - printf("Prefetch with IMMED==1 ... "); - task = iscsi_prefetch10_sync(iscsi, lun, 0, 1, 1, 0); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send prefetch10 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 PREFETCH10 with IMMED==1.\n"); + ret = prefetch10(iscsi, lun, 0, 1, 1, 0); + if (ret != 0) { goto finished; } - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("Prefetch10 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 PREFETCH10 with GROUPNEMBER 0-31.\n"); for (i = 0; i < 32; i++) { - task = iscsi_prefetch10_sync(iscsi, lun, 0, 1, 0, i); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send prefetch10 command: %s\n", iscsi_get_error(iscsi)); - ret = -1; - goto test3; + ret = prefetch10(iscsi, lun, 0, 1, 0, i); + if (ret != 0) { + goto finished; } - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("Prefetch10 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/0242_prefetch10_beyondeol.c b/test-tool/0242_prefetch10_beyondeol.c index ffccdc7..c6edea9 100644 --- a/test-tool/0242_prefetch10_beyondeol.c +++ b/test-tool/0242_prefetch10_beyondeol.c @@ -73,7 +73,7 @@ int T0242_prefetch10_beyondeol(const char *initiator, const char *url, int data_ ret = 0; - if (num_blocks >= 0x80000000) { + if (num_blocks > 0x80000000) { printf("[SKIPPED]\n"); printf("LUN is too big for read-beyond-eol tests with PREFETCH10. Skipping test.\n"); ret = -2; @@ -81,143 +81,45 @@ int T0242_prefetch10_beyondeol(const char *initiator, const char *url, int data_ } /* 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_prefetch10_sync(iscsi, lun, num_blocks + 2 - i, i, 0, 0); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send PREFETCH10 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 = prefetch10_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("PREFETCH10 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^31 */ - printf("Prefetch 1-256 blocks at LBA 2^31 ... "); - if (num_blocks > 0x80000000) { - printf("LUN is too big, skipping test\n"); - goto test3; - } + printf("Prefetch 1-256 blocks at LBA 2^31.\n"); for (i = 1; i <= 256; i++) { - task = iscsi_prefetch10_sync(iscsi, lun, 0x80000000, i, 0, 0); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send PREFETCH10 command: %s\n", iscsi_get_error(iscsi)); - ret = -1; - goto test3; + ret = prefetch10_lbaoutofrange(iscsi, lun, 0x80000000, i, 0, 0); + if (ret != 0) { + goto finished; } - if (task->status == SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("PREFETCH10 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("PREFETCH10 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 ... "); - if (num_blocks > 0x80000000) { - printf("LUN is too big, skipping test\n"); - goto test4; - } + printf("Prefetch 1-256 blocks at LBA -1.\n"); for (i = 1; i <= 256; i++) { - task = iscsi_prefetch10_sync(iscsi, lun, -1, i, 0, 0); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send PREFETCH10 command: %s\n", iscsi_get_error(iscsi)); - ret = -1; - goto test4; + ret = prefetch10_lbaoutofrange(iscsi, lun, -1, i, 0, 0); + if (ret != 0) { + goto finished; } - if (task->status == SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("PREFETCH10 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("PREFETCH10 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_prefetch10_sync(iscsi, lun, num_blocks, i, 0, 0); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send PREFETCH10 command: %s\n", iscsi_get_error(iscsi)); - ret = -1; - goto test5; + ret = prefetch10_lbaoutofrange(iscsi, lun, num_blocks, i, 0, 0); + if (ret != 0) { + goto finished; } - if (task->status == SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("PREFETCH10 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("PREFETCH10 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/0243_prefetch10_0blocks.c b/test-tool/0243_prefetch10_0blocks.c index cf88a74..cfaf1c4 100644 --- a/test-tool/0243_prefetch10_0blocks.c +++ b/test-tool/0243_prefetch10_0blocks.c @@ -74,116 +74,41 @@ int T0243_prefetch10_0blocks(const char *initiator, const char *url, int data_lo /* prefetch 0blocks at the start of the LUN */ - printf("PREFETCH10 0blocks at LBA==0 ... "); - task = iscsi_prefetch10_sync(iscsi, lun, 0, 0, 0, 0); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send PREFETCH10 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("PREFETCH10 0blocks at LBA==0.\n"); + ret = prefetch10(iscsi, lun, 0, 0, 0, 0); + if (ret != 0) { goto finished; } - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("PREFETCH10 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("PREFETCH10 0blocks at one block beyond ... "); + printf("PREFETCH10 0blocks at one block beyond .\n"); if (num_blocks > 0x80000000) { printf("[SKIPPED]\n"); printf("LUN is too big, skipping test\n"); - goto test3; + goto finished; } - task = iscsi_prefetch10_sync(iscsi, lun, num_blocks + 1, 0, 0, 0); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send PREFETCH10 command: %s\n", iscsi_get_error(iscsi)); - ret = -1; - goto test3; + ret = prefetch10_lbaoutofrange(iscsi, lun, num_blocks + 1, 0, 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("PREFETCH10 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 0blocks at LBA:2^31 */ - printf("PREFETCH10 0blocks at LBA:2^31 ... "); - if (num_blocks > 0x80000000) { - printf("[SKIPPED]\n"); - printf("LUN is too big, skipping test\n"); - goto test4; + printf("PREFETCH10 0blocks at LBA:2^31.\n"); + ret = prefetch10_lbaoutofrange(iscsi, lun, 0x80000000, 0, 0, 0); + if (ret != 0) { + goto finished; } - task = iscsi_prefetch10_sync(iscsi, lun, 0x80000000, 0, 0, 0); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send PREFETCH10 command: %s\n", iscsi_get_error(iscsi)); - ret = -1; - 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("PREFETCH10 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 0blocks at LBA:-1 */ - printf("PREFETCH10 0blocks at LBA:-1 ... "); - if (num_blocks > 0x80000000) { - printf("[SKIPPED]\n"); - printf("LUN is too big, skipping test\n"); - goto test5; + printf("PREFETCH10 0blocks at LBA:-1.\n"); + ret = prefetch10_lbaoutofrange(iscsi, lun, 0xffffffff, 0, 0, 0); + if (ret != 0) { + goto finished; } - task = iscsi_prefetch10_sync(iscsi, lun, 0xffffffff, 0, 0, 0); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send PREFETCH10 command: %s\n", iscsi_get_error(iscsi)); - ret = -1; - 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("PREFETCH10 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 b401949..e49cf77 100644 --- a/test-tool/0370_nomedia.c +++ b/test-tool/0370_nomedia.c @@ -349,27 +349,8 @@ int T0370_nomedia(const char *initiator, const char *url, int data_loss, int sho printf("[OK]\n"); - printf("Test PREFETCH10 ... "); - task = iscsi_prefetch10_sync(iscsi, lun, 0, 1, 1, 0); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send PREFETCH10 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("PREFETCH10 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 PREFETCH10.\n"); + prefetch10_nomedium(iscsi, lun, 0, 1, 1, 0); printf("Test PREFETCH16 ... "); diff --git a/test-tool/iscsi-test.c b/test-tool/iscsi-test.c index 6ee9c63..a28a79d 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -749,7 +749,7 @@ int testunitready_nomedium(struct iscsi_context *iscsi, int lun) { struct scsi_task *task; - printf("Send TESTUNITREADY expecting it to fail with CHECK_CONDITION/NOT_READY/MEDIUM_NOT_PRESENT ... "); + printf("Send TESTUNITREADY (expecting NOT_READY/MEDIUM_NOT_PRESENT) ... "); task = iscsi_testunitready_sync(iscsi, lun); if (task == NULL) { printf("[FAILED]\n"); @@ -776,7 +776,7 @@ int testunitready_conflict(struct iscsi_context *iscsi, int lun) { struct scsi_task *task; - printf("Send TESTUNITREADY expecting it to fail with RESERVATION_CONFLICT ... "); + printf("Send TESTUNITREADY (expecting RESERVATION_CONFLICT) ... "); task = iscsi_testunitready_sync(iscsi, lun); if (task == NULL) { printf("[FAILED]\n"); @@ -794,6 +794,105 @@ int testunitready_conflict(struct iscsi_context *iscsi, int lun) return 0; } +int prefetch10(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int immed, int group) +{ + struct scsi_task *task; + + printf("Send PREFETCH10 LBA:%d Count:%d IMEMD:%d GROUP:%d ... ", lba, num_blocks, immed, group); + 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)); + 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("PREFETCH10 is not implemented on target\n"); + scsi_free_scsi_task(task); + return -2; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("PREFETCH10 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 prefetch10_lbaoutofrange(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int immed, int group) +{ + struct scsi_task *task; + + printf("Send PREFETCH10 LBA:%d Count:%d IMEMD:%d GROUP:%d (expecting ILLEGAL_REQUEST/LBA_OUT_OF_RANGE) ... ", lba, num_blocks, immed, group); + 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)); + 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("PREFETCH10 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("PREFETCH10 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 prefetch10_nomedium(struct iscsi_context *iscsi, int lun, uint32_t lba, int num_blocks, int immed, int group) +{ + struct scsi_task *task; + + printf("Send PREFETCH10 LBA:%d Count:%d IMEMD:%d GROUP:%d (expecting NOT_READY/MEDIUM_NOT_PRESENT) ... ", lba, num_blocks, immed, group); + 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)); + 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("PREFETCH10 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("PREFETCH10 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[]) { poptContext pc; diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index 786adb6..2ee2ee4 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -255,5 +255,8 @@ int verify_reserved_as(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 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); #endif /* _ISCSI_TEST_H_ */