diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index daa1443..bfd4356 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -1482,6 +1482,40 @@ int modesense6(struct scsi_device *sdev, struct scsi_task **out_task, int dbd, e return ret; } +int modeselect6(struct scsi_device *sdev, int pf, int sp, struct scsi_mode_page *mp, int status, enum scsi_sense_key key, int *ascq, int num_ascq) +{ + struct scsi_task *task; + int ret; + struct scsi_data *data; + struct iscsi_data d; + + logging(LOG_VERBOSE, "Send MODESELECT6 (Expecting %s) ", + scsi_status_str(status)); + + task = scsi_cdb_modeselect6(pf, sp, 255); + assert(task != NULL); + + data = scsi_modesense_dataout_marshall(task, mp, 1); + if (data == NULL) { + logging(LOG_VERBOSE, "Failed to marshall MODESELECT6 data"); + scsi_free_scsi_task(task); + return -1; + } + + d.data = data->data; + d.size = data->size; + task->cdb[4] = data->size; + task->expxferlen = data->size; + + task = send_scsi_command(sdev, task, &d); + + ret = check_result("MODESELECT6", sdev, task, status, key, ascq, num_ascq); + if (task) { + scsi_free_scsi_task(task); + } + return ret; +} + int compareandwrite(struct scsi_device *sdev, uint64_t lba, unsigned char *data, uint32_t datalen, int blocksize, int wrprotect, int dpo, @@ -2394,29 +2428,21 @@ get_command_descriptor(int opcode, int sa) int set_swp(struct scsi_device *sdev) { - int ret = 0; + int ret; struct scsi_task *sense_task = NULL; - struct scsi_task *select_task = NULL; struct scsi_mode_sense *ms; struct scsi_mode_page *mp; logging(LOG_VERBOSE, "Read CONTROL page"); - sense_task = iscsi_modesense6_sync(sdev->iscsi_ctx, sdev->iscsi_lun, - 1, SCSI_MODESENSE_PC_CURRENT, - SCSI_MODEPAGE_CONTROL, - 0, 255); - if (sense_task == NULL) { - logging(LOG_NORMAL, "Failed to send MODE_SENSE6 command: %s", - iscsi_get_error(sdev->iscsi_ctx)); - ret = -1; - goto finished; - } - if (sense_task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "MODE_SENSE6 failed: %s", - iscsi_get_error(sdev->iscsi_ctx)); - ret = -1; + ret = modesense6(sdev, &sense_task, 1, SCSI_MODESENSE_PC_CURRENT, + SCSI_MODEPAGE_CONTROL, 0, 255, + EXPECT_STATUS_GOOD); + if (ret) { + logging(LOG_NORMAL, "Failed to read CONTROL mode page."); goto finished; } + logging(LOG_VERBOSE, "[SUCCESS] CONTROL page fetched."); + ms = scsi_datain_unmarshall(sense_task); if (ms == NULL) { logging(LOG_NORMAL, "failed to unmarshall mode sense datain " @@ -2434,56 +2460,38 @@ int set_swp(struct scsi_device *sdev) logging(LOG_VERBOSE, "Turn SWP ON"); mp->control.swp = 1; - select_task = iscsi_modeselect6_sync(sdev->iscsi_ctx, sdev->iscsi_lun, - 1, 0, mp); - if (select_task == NULL) { - logging(LOG_NORMAL, "Failed to send MODE_SELECT6 command: %s", - iscsi_get_error(sdev->iscsi_ctx)); - ret = -1; - goto finished; - } - if (select_task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "MODE_SELECT6 failed: %s", - iscsi_get_error(sdev->iscsi_ctx)); - ret = -1; + ret = modeselect6(sdev, 1, 0, mp, + EXPECT_STATUS_GOOD); + if (ret) { + logging(LOG_NORMAL, "Failed to write CONTROL mode page."); goto finished; } + logging(LOG_VERBOSE, "[SUCCESS] CONTROL page written."); finished: if (sense_task != NULL) { scsi_free_scsi_task(sense_task); } - if (select_task != NULL) { - scsi_free_scsi_task(select_task); - } return ret; } int clear_swp(struct scsi_device *sdev) { - int ret = 0; + int ret; struct scsi_task *sense_task = NULL; - struct scsi_task *select_task = NULL; struct scsi_mode_sense *ms; struct scsi_mode_page *mp; logging(LOG_VERBOSE, "Read CONTROL page"); - sense_task = iscsi_modesense6_sync(sdev->iscsi_ctx, sdev->iscsi_lun, - 1, SCSI_MODESENSE_PC_CURRENT, - SCSI_MODEPAGE_CONTROL, - 0, 255); - if (sense_task == NULL) { - logging(LOG_NORMAL, "Failed to send MODE_SENSE6 command: %s", - iscsi_get_error(sdev->iscsi_ctx)); - ret = -1; - goto finished; - } - if (sense_task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "MODE_SENSE6 failed: %s", - iscsi_get_error(sdev->iscsi_ctx)); - ret = -1; + ret = modesense6(sdev, &sense_task, 1, SCSI_MODESENSE_PC_CURRENT, + SCSI_MODEPAGE_CONTROL, 0, 255, + EXPECT_STATUS_GOOD); + if (ret) { + logging(LOG_NORMAL, "Failed to read CONTROL mode page."); goto finished; } + logging(LOG_VERBOSE, "[SUCCESS] CONTROL page fetched."); + ms = scsi_datain_unmarshall(sense_task); if (ms == NULL) { logging(LOG_NORMAL, "failed to unmarshall mode sense datain " @@ -2501,27 +2509,17 @@ int clear_swp(struct scsi_device *sdev) logging(LOG_VERBOSE, "Turn SWP OFF"); mp->control.swp = 0; - select_task = iscsi_modeselect6_sync(sdev->iscsi_ctx, sdev->iscsi_lun, - 1, 0, mp); - if (select_task == NULL) { - logging(LOG_NORMAL, "Failed to send MODE_SELECT6 command: %s", - iscsi_get_error(sdev->iscsi_ctx)); - ret = -1; - goto finished; - } - if (select_task->status != SCSI_STATUS_GOOD) { - logging(LOG_NORMAL, "MODE_SELECT6 failed: %s", - iscsi_get_error(sdev->iscsi_ctx)); - ret = -1; + ret = modeselect6(sdev, 1, 0, mp, + EXPECT_STATUS_GOOD); + if (ret) { + logging(LOG_NORMAL, "Failed to write CONTROL mode page."); goto finished; } + logging(LOG_VERBOSE, "[SUCCESS] CONTROL page written."); finished: if (sense_task != NULL) { scsi_free_scsi_task(sense_task); } - if (select_task != NULL) { - scsi_free_scsi_task(select_task); - } return ret; } diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 0cadb28..8739601 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -272,6 +272,7 @@ int compareandwrite(struct scsi_device *sdev, uint64_t lba, unsigned char *data, int get_lba_status(struct scsi_device *sdev, struct scsi_task **task, uint64_t lba, uint32_t len, int status, enum scsi_sense_key key, int *ascq, int num_ascq); int inquiry(struct scsi_device *sdev, struct scsi_task **task, int evpd, int page_code, int maxsize, int status, enum scsi_sense_key key, int *ascq, int num_ascq); int modesense6(struct scsi_device *sdev, struct scsi_task **task, int dbd, enum scsi_modesense_page_control pc, enum scsi_modesense_page_code page_code, int sub_page_code, unsigned char alloc_len, int status, enum scsi_sense_key key, int *ascq, int num_ascq); +int modeselect6(struct scsi_device *sdev, int pf, int sp, struct scsi_mode_page *mp, int status, enum scsi_sense_key key, int *ascq, int num_ascq); int orwrite(struct scsi_device *sdev, uint64_t lba, uint32_t datalen, int blocksize, int wrprotect, 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 prefetch10(struct scsi_device *sdev, uint32_t lba, int num_blocks, int immed, int group, int status, enum scsi_sense_key key, int *ascq, int num_ascq); int prefetch16(struct scsi_device *sdev, uint64_t lba, int num_blocks, int immed, int group, int status, enum scsi_sense_key key, int *ascq, int num_ascq); diff --git a/test-tool/test_modesense6_all_pages.c b/test-tool/test_modesense6_all_pages.c index 1f0ddc0..9cf9461 100644 --- a/test-tool/test_modesense6_all_pages.c +++ b/test-tool/test_modesense6_all_pages.c @@ -28,39 +28,28 @@ void test_modesense6_all_pages(void) { struct scsi_mode_sense *ms; + struct scsi_task *ms_task = NULL; + int ret; logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test of MODESENSE6 AllPages"); - if (task != NULL) { - scsi_free_scsi_task(task); - task = NULL; - } - logging(LOG_VERBOSE, "Send MODESENSE6 command to fetch AllPages"); - task = iscsi_modesense6_sync(sd->iscsi_ctx, sd->iscsi_lun, 0, - SCSI_MODESENSE_PC_CURRENT, - SCSI_MODEPAGE_RETURN_ALL_PAGES, - 0, 255); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - logging(LOG_VERBOSE, "[FAILED] Failed to send MODE_SENSE6 " - "command:%s", - iscsi_get_error(sd->iscsi_ctx)); - CU_FAIL("[FAILED] Failed to fetch the All Pages page."); - return; - } + ret = modesense6(sd, &ms_task, 0, SCSI_MODESENSE_PC_CURRENT, + SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 255, + EXPECT_STATUS_GOOD); + CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] All Pages fetched."); logging(LOG_VERBOSE, "Try to unmarshall the DATA-IN buffer."); - ms = scsi_datain_unmarshall(task); + ms = scsi_datain_unmarshall(ms_task); if (ms == NULL) { logging(LOG_VERBOSE, "[FAILED] failed to unmarshall mode sense " "datain buffer"); CU_FAIL("[FAILED] Failed to unmarshall the data-in buffer."); - scsi_free_scsi_task(task); - task = NULL; + scsi_free_scsi_task(ms_task); return; } logging(LOG_VERBOSE, "[SUCCESS] Unmarshalling successful."); @@ -75,8 +64,5 @@ test_modesense6_all_pages(void) CU_ASSERT_TRUE(ms->mode_data_length >= 3); - if (task != NULL) { - scsi_free_scsi_task(task); - task = NULL; - } + scsi_free_scsi_task(ms_task); } diff --git a/test-tool/test_modesense6_residuals.c b/test-tool/test_modesense6_residuals.c index ab0eb97..ab0dbbf 100644 --- a/test-tool/test_modesense6_residuals.c +++ b/test-tool/test_modesense6_residuals.c @@ -27,6 +27,9 @@ void test_modesense6_residuals(void) { + struct scsi_task *ms_task = NULL; + int ret; + logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test of MODESENSE6 Residuals"); @@ -36,95 +39,69 @@ test_modesense6_residuals(void) logging(LOG_VERBOSE, "Try a MODESENSE6 command with 4 bytes of " "transfer length and verify that we don't get residuals."); - if (task != NULL) { - scsi_free_scsi_task(task); - task = NULL; - } - task = iscsi_modesense6_sync(sd->iscsi_ctx, sd->iscsi_lun, 0, - SCSI_MODESENSE_PC_CURRENT, - SCSI_MODEPAGE_RETURN_ALL_PAGES, - 0, 4); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - logging(LOG_VERBOSE, "[FAILED] Failed to send MODE_SENSE6 " - "command:%s", - iscsi_get_error(sd->iscsi_ctx)); - CU_FAIL("[FAILED] Failed to fetch the All Pages page."); - return; - } + ret = modesense6(sd, &ms_task, 0, SCSI_MODESENSE_PC_CURRENT, + SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 4, + EXPECT_STATUS_GOOD); + CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] All Pages fetched."); logging(LOG_VERBOSE, "Verify that we got at most 4 bytes of DATA-IN"); - if (task->datain.size > 4) { + if (ms_task->datain.size > 4) { logging(LOG_NORMAL, "[FAILED] got more than 4 bytes of " "DATA-IN."); } else { logging(LOG_VERBOSE, "[SUCCESS] <= 4 bytes of DATA-IN " "received."); } - CU_ASSERT_TRUE(task->datain.size <= 4); + CU_ASSERT_TRUE(ms_task->datain.size <= 4); logging(LOG_VERBOSE, "Verify residual overflow flag not set"); - if (task->residual_status == SCSI_RESIDUAL_OVERFLOW) { + if (ms_task->residual_status == SCSI_RESIDUAL_OVERFLOW) { logging(LOG_VERBOSE, "[FAILED] Target set residual " "overflow flag"); } - CU_ASSERT_NOT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW); + CU_ASSERT_NOT_EQUAL(ms_task->residual_status, SCSI_RESIDUAL_OVERFLOW); logging(LOG_VERBOSE, "Try a MODESENSE6 command with 255 bytes of " "transfer length and verify that we get residuals if the target returns less than the requested amount of data."); - if (task != NULL) { - scsi_free_scsi_task(task); - task = NULL; - } - task = iscsi_modesense6_sync(sd->iscsi_ctx, sd->iscsi_lun, 0, - SCSI_MODESENSE_PC_CURRENT, - SCSI_MODEPAGE_RETURN_ALL_PAGES, - 0, 255); - if (task == NULL || task->status != SCSI_STATUS_GOOD) { - logging(LOG_VERBOSE, "[FAILED] Failed to send MODE_SENSE6 " - "command:%s", - iscsi_get_error(sd->iscsi_ctx)); - CU_FAIL("[FAILED] Failed to fetch the All Pages page."); - return; - } + scsi_free_scsi_task(ms_task); + ret = modesense6(sd, &ms_task, 0, SCSI_MODESENSE_PC_CURRENT, + SCSI_MODEPAGE_RETURN_ALL_PAGES, 0, 255, + EXPECT_STATUS_GOOD); + CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "[SUCCESS] All Pages fetched."); - - if (task->datain.size == 255) { + if (ms_task->datain.size == 255) { logging(LOG_VERBOSE, "We got all 255 bytes of data back " "from the target. Verify that underflow is not set."); - if (task->residual_status == SCSI_RESIDUAL_UNDERFLOW) { + if (ms_task->residual_status == SCSI_RESIDUAL_UNDERFLOW) { logging(LOG_VERBOSE, "[FAILED] Target set residual " "underflow flag"); } else { logging(LOG_VERBOSE, "[SUCCESS] Residual underflow " "is not set"); } - CU_ASSERT_NOT_EQUAL(task->residual_status, + CU_ASSERT_NOT_EQUAL(ms_task->residual_status, SCSI_RESIDUAL_UNDERFLOW); } else { logging(LOG_VERBOSE, "We got less than the requested 255 bytes " "from the target. Verify that underflow is set."); - if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) { + if (ms_task->residual_status != SCSI_RESIDUAL_UNDERFLOW) { logging(LOG_VERBOSE, "[FAILED] Target did not set " "residual underflow flag"); } else { logging(LOG_VERBOSE, "[SUCCESS] Residual underflow " "is set"); } - CU_ASSERT_EQUAL(task->residual_status, + CU_ASSERT_EQUAL(ms_task->residual_status, SCSI_RESIDUAL_UNDERFLOW); } - - if (task != NULL) { - scsi_free_scsi_task(task); - task = NULL; - } + scsi_free_scsi_task(ms_task); } diff --git a/test-tool/test_sanitize_readonly.c b/test-tool/test_sanitize_readonly.c index 7d52ece..f526a26 100644 --- a/test-tool/test_sanitize_readonly.c +++ b/test-tool/test_sanitize_readonly.c @@ -41,7 +41,10 @@ test_sanitize_readonly(void) CHECK_FOR_DATALOSS; logging(LOG_VERBOSE, "Create a second connection to the target"); - sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd->iscsi_url, &sd2.iscsi_lun); + memset(&sd2, 0, sizeof(sd2)); + sd2.iscsi_url = sd->iscsi_url; + sd2.iscsi_lun = sd->iscsi_lun; + sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd2.iscsi_url, &sd2.iscsi_lun); if (sd2.iscsi_ctx == NULL) { logging(LOG_VERBOSE, "Failed to login to target"); return;