diff --git a/Makefile.am b/Makefile.am index 623a948..2306eac 100644 --- a/Makefile.am +++ b/Makefile.am @@ -135,6 +135,8 @@ bin_iscsi_test_SOURCES = test-tool/iscsi-test.c \ test-tool/0404_inquiry_all_reported_vpd.c \ test-tool/0410_readtoc_basic.c \ test-tool/0420_reserve6_simple.c \ + test-tool/0421_reserve6_lun_reset.c \ + test-tool/0422_reserve6_logout.c \ \ test-tool/1000_cmdsn_invalid.c \ test-tool/1010_datasn_invalid.c \ diff --git a/test-tool/0421_reserve6_lun_reset.c b/test-tool/0421_reserve6_lun_reset.c new file mode 100644 index 0000000..e956d0e --- /dev/null +++ b/test-tool/0421_reserve6_lun_reset.c @@ -0,0 +1,212 @@ +/* + Copyright (C) 2012 by Ronnie Sahlberg + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#include +#include +#include +#include +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test.h" + +struct mgmt_task { + uint32_t status; + uint32_t finished; +}; + +static void mgmt_cb(struct iscsi_context *iscsi _U_, int status _U_, + void *command_data, void *private_data) +{ + struct mgmt_task *mgmt_task = (struct mgmt_task *)private_data; + + mgmt_task->status = *(uint32_t *)command_data; + mgmt_task->finished = 1; +} + +int T0421_reserve6_lun_reset(const char *initiator, const char *url, int data_loss, int show_info) +{ + struct iscsi_context *iscsi, *iscsi2; + struct scsi_task *task; + int ret, lun; + struct mgmt_task mgmt_task = {0, 0}; + struct pollfd pfd; + + printf("0421_reserve6_lun_reset:\n"); + printf("========================\n"); + if (show_info) { + printf("Test that a RESERVE6 is dropped by a LUN-reset\n"); + printf(" If device does not support RESERVE6, just skip the test.\n"); + printf("1, Reserve the device from the first initiator.\n"); + printf("2, Verify we can access the LUN from the first initiator\n"); + printf("3, Verify we can NOT access the LUN from the second initiator\n"); + printf("4, Send a LUN-reset to the target\n"); + printf("5, Verify we can access the LUN from the second initiator\n"); + printf("\n"); + return 0; + } + + iscsi = iscsi_context_login(initiator, url, &lun); + if (iscsi == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + iscsi2 = iscsi_context_login(initiator2, url, &lun); + if (iscsi2 == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + ret = 0; + + + + + printf("Send RESERVE6 from the first initiator ... "); + task = iscsi_reserve6_sync(iscsi, lun); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send RESERVE6 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_OPERATION_CODE) { + printf("[SKIPPED]\n"); + printf("RESERVE6 Not Supported\n"); + ret = -2; + scsi_free_scsi_task(task); + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("RESERVE6 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: + printf("Verify we can access the LUN from the first initiator ... "); + task = iscsi_testunitready_sync(iscsi, lun); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send TEST UNIT READY command: %s\n", + iscsi_get_error(iscsi)); + ret = -1; + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("TEST UNIT READY 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("Verify we can NOT access the LUN from the second initiator ... "); + task = iscsi_testunitready_sync(iscsi2, lun); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send TEST UNIT READY command: %s\n", + iscsi_get_error(iscsi2)); + ret = -1; + goto finished; + } + if (task->status != SCSI_STATUS_RESERVATION_CONFLICT) { + printf("[FAILED]\n"); + printf("Expected RESERVATION CONFLICT\n"); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } + scsi_free_scsi_task(task); + printf("[OK]\n"); + +test4: + printf("Send a LUN Reset to the target ... "); + iscsi_task_mgmt_lun_reset_async(iscsi, lun, mgmt_cb, &mgmt_task); + while (mgmt_task.finished == 0) { + pfd.fd = iscsi_get_fd(iscsi); + pfd.events = iscsi_which_events(iscsi); + + if (poll(&pfd, 1, -1) < 0) { + printf("Poll failed"); + goto finished; + } + if (iscsi_service(iscsi, pfd.revents) < 0) { + printf("iscsi_service failed with : %s\n", iscsi_get_error(iscsi)); + break; + } + } + if (mgmt_task.status != 0) { + printf("[FAILED]\n"); + printf("Failed to reset the LUN\n"); + goto finished; + } + printf("[OK]\n"); + +test5: + /* We might be getting UNIT_ATTENTION/BUS_RESET after the lun-reset above. + If so just loop and try the TESTUNITREADY again until it clears + */ + printf("Verify we can access the LUN from the second initiator ... "); + task = iscsi_testunitready_sync(iscsi2, lun); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send TEST UNIT READY command: %s\n", + iscsi_get_error(iscsi2)); + ret = -1; + goto finished; + } + if (task->status == SCSI_STATUS_CHECK_CONDITION + && task->sense.key == SCSI_SENSE_UNIT_ATTENTION + && task->sense.ascq == SCSI_SENSE_ASCQ_BUS_RESET) { + printf("Got BUS RESET. Retry accessing the LUN\n"); + goto test5; + + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("TEST UNIT READY command: failed with sense %s\n", + iscsi_get_error(iscsi2)); + ret = -1; + scsi_free_scsi_task(task); + goto test3; + } + scsi_free_scsi_task(task); + printf("[OK]\n"); + + +finished: + iscsi_logout_sync(iscsi); + iscsi_destroy_context(iscsi); + iscsi_logout_sync(iscsi2); + iscsi_destroy_context(iscsi2); + return ret; +} diff --git a/test-tool/0422_reserve6_logout.c b/test-tool/0422_reserve6_logout.c new file mode 100644 index 0000000..e30d597 --- /dev/null +++ b/test-tool/0422_reserve6_logout.c @@ -0,0 +1,166 @@ +/* + Copyright (C) 2012 by Ronnie Sahlberg + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#include +#include +#include +#include "iscsi.h" +#include "scsi-lowlevel.h" +#include "iscsi-test.h" + +int T0422_reserve6_logout(const char *initiator, const char *url, int data_loss, int show_info) +{ + struct iscsi_context *iscsi, *iscsi2; + struct scsi_task *task; + int ret, lun; + + printf("0422_reserve6_logout:\n"); + printf("=====================\n"); + if (show_info) { + printf("Test that a RESERVE6 is dropped when the session is logged out\n"); + printf(" If device does not support RESERVE6, just skip the test.\n"); + printf("1, Reserve the device from the first initiator.\n"); + printf("2, Verify we can access the LUN from the first initiator.\n"); + printf("3, Verify we can NOT access the LUN from the second initiator.\n"); + printf("4, Logout the first initiator.\n"); + printf("5, Verify we can access the LUN from the second initiator.\n"); + printf("\n"); + return 0; + } + + iscsi = iscsi_context_login(initiator, url, &lun); + if (iscsi == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + iscsi2 = iscsi_context_login(initiator2, url, &lun); + if (iscsi2 == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + ret = 0; + + + + + printf("Send RESERVE6 from the first initiator ... "); + task = iscsi_reserve6_sync(iscsi, lun); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send RESERVE6 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_OPERATION_CODE) { + printf("[SKIPPED]\n"); + printf("RESERVE6 Not Supported\n"); + ret = -2; + scsi_free_scsi_task(task); + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("RESERVE6 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: + printf("Verify we can access the LUN from the first initiator ... "); + task = iscsi_testunitready_sync(iscsi, lun); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send TEST UNIT READY command: %s\n", + iscsi_get_error(iscsi)); + ret = -1; + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("TEST UNIT READY 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("Verify we can NOT access the LUN from the second initiator ... "); + task = iscsi_testunitready_sync(iscsi2, lun); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send TEST UNIT READY command: %s\n", + iscsi_get_error(iscsi2)); + ret = -1; + goto finished; + } + if (task->status != SCSI_STATUS_RESERVATION_CONFLICT) { + printf("[FAILED]\n"); + printf("Expected RESERVATION CONFLICT\n"); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } + scsi_free_scsi_task(task); + printf("[OK]\n"); + +test4: + printf("Logout the first initiator ... "); + iscsi_logout_sync(iscsi); + iscsi_destroy_context(iscsi); + printf("[OK]\n"); + +test5: + printf("Verify we can access the LUN from the second initiator ... "); + task = iscsi_testunitready_sync(iscsi2, lun); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send TEST UNIT READY command: %s\n", + iscsi_get_error(iscsi2)); + ret = -1; + goto finished; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("TEST UNIT READY command: failed with sense %s\n", + iscsi_get_error(iscsi2)); + ret = -1; + scsi_free_scsi_task(task); + goto finished; + } + scsi_free_scsi_task(task); + printf("[OK]\n"); + + +finished: + iscsi_logout_sync(iscsi2); + iscsi_destroy_context(iscsi2); + return ret; +} diff --git a/test-tool/iscsi-test.c b/test-tool/iscsi-test.c index fad2af0..1c7c7ea 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -218,6 +218,8 @@ struct scsi_test tests[] = { /* reserve6/release6 */ { "T0420_reserve6_simple", T0420_reserve6_simple }, +{ "T0421_reserve6_lun_reset", T0421_reserve6_lun_reset }, +{ "T0422_reserve6_logout", T0422_reserve6_logout }, /* iSCSI protocol tests */ diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index 2c9e72d..3bd8e1c 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -170,6 +170,8 @@ int T0404_inquiry_all_reported_vpd(const char *initiator, const char *url, int d int T0410_readtoc_basic(const char *initiator, const char *url, int data_loss, int show_info); int T0420_reserve6_simple(const char *initiator, const char *url, int data_loss, int show_info); +int T0421_reserve6_lun_reset(const char *initiator, const char *url, int data_loss, int show_info); +int T0422_reserve6_logout(const char *initiator, const char *url, int data_loss, int show_info); int T1000_cmdsn_invalid(const char *initiator, const char *url, int data_loss, int show_info); int T1010_datasn_invalid(const char *initiator, const char *url, int data_loss, int show_info);