int T0211_read12_rdprotect(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; int ret = 0, i, lun; printf("0211_read12_rdprotect:\n"); printf("======================\n"); if (show_info) { printf("Test how READ12 handles the rdprotect bits\n"); printf("1, Any non-zero valued for rdprotect should fail.\n"); printf("\n"); return 0; } iscsi = iscsi_context_login(initiator, url, &lun); if (iscsi == NULL) { printf("Failed to login to target\n"); return -1; } printf("Read12 with RDPROTECT "); for (i = 1; i <= 7; i++) { task = iscsi_read12_sync(iscsi, lun, 0, block_size, block_size, i, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status != SCSI_STATUS_CHECK_CONDITION || task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST || task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_FIELD_IN_CDB) { printf("[FAILED]\n"); printf("Read12 with RDPROTECT!=0 should have failed with CHECK_CONDITION/ILLEGAL_REQUEST/INVALID_FIELD_IN_CDB\n"); ret = -1; scsi_free_scsi_task(task); goto finished; } scsi_free_scsi_task(task); } printf("[OK]\n"); finished: iscsi_logout_sync(iscsi); iscsi_destroy_context(iscsi); return ret; }
int T0212_read12_flags(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; int ret = 0, lun; printf("0212_read12_flags:\n"); printf("==================\n"); if (show_info) { printf("Test how READ12 handles the flag bits\n"); printf("1, Reading with DPO should work\n"); printf("2, Reading with FUA should work\n"); printf("3, Reading with FUA_NV should work\n"); printf("4, Reading with FUA+FUA_NV should work\n"); printf("\n"); return 0; } iscsi = iscsi_context_login(initiator, url, &lun); if (iscsi == NULL) { printf("Failed to login to target\n"); return -1; } /* This test is only valid for SBC devices */ if (device_type != SCSI_INQUIRY_PERIPHERAL_DEVICE_TYPE_DIRECT_ACCESS) { printf("LUN is not SBC device. Skipping test\n"); return -2; } printf("Read12 with DPO "); task = iscsi_read12_sync(iscsi, lun, 0, block_size, block_size, 0, 1, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto finished; } printf("[OK]\n"); printf("Read12 with FUA "); task = iscsi_read12_sync(iscsi, lun, 0, block_size, block_size, 0, 0, 1, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto finished; } printf("[OK]\n"); printf("Read12 with FUA_NV "); task = iscsi_read12_sync(iscsi, lun, 0, block_size, block_size, 0, 0, 0, 1, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto finished; } printf("[OK]\n"); printf("Read12 with FUA+FUA_NV "); task = iscsi_read12_sync(iscsi, lun, 0, block_size, block_size, 0, 0, 1, 1, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto finished; } printf("[OK]\n"); finished: iscsi_logout_sync(iscsi); iscsi_destroy_context(iscsi); return ret; }
int T0213_read12_0blocks(const char *initiator, const char *url, int data_loss _U_, int show_info) { struct iscsi_context *iscsi; struct scsi_task *task; struct scsi_readcapacity16 *rc16; int ret = 0, lun; uint32_t block_size; uint64_t num_blocks; printf("0213_read12_0blocks:\n"); printf("====================\n"); if (show_info) { printf("Test that READ12 works correctly when reading 0 number of blocks.\n"); printf("1, Read at 0 should work.\n"); printf("2, Read at end-of-lun should work.\n"); printf("3, Read beyond end-of-lun should fail.\n"); printf("4, Read at LBA:-1 should fail. (only test this if the device is < 2TB)\n"); printf("\n"); return 0; } iscsi = iscsi_context_login(initiator, url, &lun); if (iscsi == NULL) { printf("Failed to login to target\n"); return -1; } /* find the size of the LUN */ task = iscsi_readcapacity16_sync(iscsi, lun); if (task == NULL) { printf("Failed to send READCAPACITY16 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("READCAPACITY16 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto finished; } rc16 = scsi_datain_unmarshall(task); if (rc16 == NULL) { printf("failed to unmarshall READCAPACITY16 data. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto finished; } block_size = rc16->block_length; num_blocks = rc16->returned_lba; scsi_free_scsi_task(task); printf("Read12 0blocks at LBA:0 "); task = iscsi_read12_sync(iscsi, lun, 0, 0, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto finished; } printf("[OK]\n"); printf("Read12 0blocks at LBA:<end-of-disk> "); task = iscsi_read12_sync(iscsi, lun, num_blocks, 0, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto finished; } printf("[OK]\n"); printf("Read12 0blocks at LBA:<beyond end-of-disk> "); task = iscsi_read12_sync(iscsi, lun, num_blocks + 1, 0, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status == SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("Read12 command: Should fail when reading 0blocks beyond end\n"); ret = -1; scsi_free_scsi_task(task); goto finished; } printf("[OK]\n"); /* read12 0 at lba -1, only do this if the device is < 2TB */ if (num_blocks == 0xffffffff) { goto finished; } printf("Reading 0 blocks at lba:-1 ... "); task = iscsi_read12_sync(iscsi, lun, -1, 0, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status == SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("Read12 command: Should fail when reading 0blocks at -1\n"); ret = -1; scsi_free_scsi_task(task); goto finished; } printf("[OK]\n"); finished: iscsi_logout_sync(iscsi); iscsi_destroy_context(iscsi); return ret; }
int T0214_read12_beyondeol(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; int ret, i, lun; printf("0214_read12_beyond_eol:\n"); printf("=======================\n"); if (show_info) { printf("Test that READ12 fails if reading beyond end-of-lun.\n"); printf("This test is skipped for LUNs with more than 2^31 blocks\n"); printf("1, Read 1-256 blocks one block beyond end-of-lun.\n"); printf("2, Read 1-256 blocks at LBA 2^31\n"); printf("2, Read 1-256 blocks at LBA -1\n"); printf("\n"); return 0; } iscsi = iscsi_context_login(initiator, url, &lun); if (iscsi == NULL) { printf("Failed to login to target\n"); return -1; } ret = 0; if (num_blocks >= 0x80000000) { printf("[SKIPPED]\n"); printf("LUN is too big for read-beyond-eol tests with READ12. Skipping test.\n"); ret = -2; goto finished; } /* read 1 - 256 blocks beyond the end of the device */ printf("Reading 1-256 blocks beyond end-of-device ... "); for (i = 2; i <= 257; i++) { task = iscsi_read12_sync(iscsi, lun, num_blocks, i * block_size, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send READ12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status == SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("READ12 command should fail when reading beyond end of device\n"); ret = -1; scsi_free_scsi_task(task); 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("READ12 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 finished; } scsi_free_scsi_task(task); } printf("[OK]\n"); /* read 1 - 256 blocks at LBA 2^31 */ printf("Reading 1-256 blocks at LBA 2^31 ... "); if (num_blocks >= 0xffffffff) { printf("LUN is too big, skipping test\n"); goto finished; } for (i = 2; i <= 257; i++) { task = iscsi_read12_sync(iscsi, lun, 0x80000000U, i * block_size, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send READ12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status == SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("READ12 command should fail when reading from LBA 2^31\n"); ret = -1; scsi_free_scsi_task(task); 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("READ12 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 finished; } scsi_free_scsi_task(task); } printf("[OK]\n"); /* read 1 - 256 blocks at LBA -1 */ printf("Reading 1-256 blocks at LBA -1 ... "); if (num_blocks > 0x80000000) { printf("LUN is too big, skipping test\n"); goto finished; } for (i = 2; i <= 257; i++) { task = iscsi_read12_sync(iscsi, lun, -1, i * block_size, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send READ12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status == SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("READ12 command should fail when reading from LBA -1\n"); ret = -1; scsi_free_scsi_task(task); 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("READ12 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 finished; } scsi_free_scsi_task(task); } printf("[OK]\n"); finished: iscsi_logout_sync(iscsi); iscsi_destroy_context(iscsi); return ret; }
int T0210_read12_simple(const char *initiator, const char *url) { struct iscsi_context *iscsi; struct scsi_task *task; int ret, i, lun; printf("0210_read12_simple:\n"); printf("===================\n"); if (show_info) { printf("Test basic READ12 functionality.\n"); printf("1, Verify we can read the first 1-256 blocks of the LUN.\n"); printf("2, Verify we can read the last 1-256 blocks of the LUN.\n"); printf("\n"); return 0; } iscsi = iscsi_context_login(initiator, url, &lun); if (iscsi == NULL) { printf("Failed to login to target\n"); return -1; } ret = 0; /* read the first 1 - 256 blocks at the start of the LUN */ printf("Reading first 1-256 blocks ... "); for (i=1; i<=256; i++) { task = iscsi_read12_sync(iscsi, lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto finished; } scsi_free_scsi_task(task); } printf("[OK]\n"); /* read the last 1 - 256 blocks at the end of the LUN */ printf("Reading last 1-256 blocks ... "); for (i=1; i<=256; i++) { task = iscsi_read12_sync(iscsi, lun, num_blocks +1 - i, i * block_size, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto finished; } scsi_free_scsi_task(task); } printf("[OK]\n"); finished: iscsi_logout_sync(iscsi); iscsi_destroy_context(iscsi); return ret; }
int T0280_verify12_simple(const char *initiator, const char *url, int data_loss _U_, int show_info) { struct iscsi_context *iscsi; struct scsi_task *task; struct scsi_task *vtask; struct scsi_readcapacity16 *rc16; int ret, i, lun; uint32_t block_size; printf("0280_verify12_simple:\n"); printf("=====================\n"); if (show_info) { printf("Test basic VERIFY12 functionality.\n"); printf("1, Read and verify the first 1-256 blocks of the LUN using READ12/VERIFY12.\n"); printf("\n"); return 0; } iscsi = iscsi_context_login(initiator, url, &lun); if (iscsi == NULL) { printf("Failed to login to target\n"); return -1; } /* find the size of the LUN */ task = iscsi_readcapacity16_sync(iscsi, lun); if (task == NULL) { printf("Failed to send readcapacity16 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("Readcapacity16 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto finished; } rc16 = scsi_datain_unmarshall(task); if (rc16 == NULL) { printf("failed to unmarshall readcapacity16 data. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto finished; } block_size = rc16->block_length; scsi_free_scsi_task(task); ret = 0; /* read and verify the first 1 - 256 blocks at the start of the LUN */ printf("Read+verify first 1-256 blocks ... "); for (i = 1; i <= 256; i++) { unsigned char *buf; task = iscsi_read12_sync(iscsi, lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send read12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; goto finished; } if (task->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("Read12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto test2; } buf = task->datain.data; if (buf == NULL) { printf("[FAILED]\n"); printf("Failed to access DATA-IN buffer %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto test2; } vtask = iscsi_verify12_sync(iscsi, lun, buf, i * block_size, 0, 0, 1, 1, block_size); if (vtask == NULL) { printf("[FAILED]\n"); printf("Failed to send verify12 command: %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); goto test2; } if (vtask->status == SCSI_STATUS_CHECK_CONDITION && vtask->sense.key == SCSI_SENSE_ILLEGAL_REQUEST && vtask->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { printf("[SKIPPED]\n"); printf("Opcode is not implemented on target\n"); scsi_free_scsi_task(task); scsi_free_scsi_task(vtask); ret = -2; goto finished; } if (vtask->status != SCSI_STATUS_GOOD) { printf("[FAILED]\n"); printf("Verify12 command: failed with sense. %s\n", iscsi_get_error(iscsi)); ret = -1; scsi_free_scsi_task(task); scsi_free_scsi_task(vtask); goto test2; } scsi_free_scsi_task(task); scsi_free_scsi_task(vtask); } printf("[OK]\n"); test2: finished: iscsi_logout_sync(iscsi); iscsi_destroy_context(iscsi); return ret; }