コード例 #1
0
int T0423_reserve6_sessionloss(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("0423_reserve6_sessionloss:\n");
	printf("=====================\n");
	if (show_info) {
		printf("Test that a RESERVE6 is dropped when the session is dropped\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, Drop session for 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("Drop the session to the first initiator ... ");
	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;
}
コード例 #2
0
int T0422_reserve6_logout(const char *initiator, const char *url)
{
	struct iscsi_context *iscsi = NULL, *iscsi2 = NULL;
	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(initiatorname2, 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 finished;
	}
	scsi_free_scsi_task(task);
	printf("[OK]\n");


	printf("Verify we can access the LUN from the first initiator.\n");
	ret = testunitready(iscsi, lun);
	if (ret != 0) {
		goto finished;
	}


	printf("Verify we can NOT access the LUN from the second initiator.\n");
	ret = testunitready_conflict(iscsi2, lun);
	if (ret != 0) {
		goto finished;
	}

	printf("Logout the first initiator ... ");
	iscsi_logout_sync(iscsi);
	iscsi_destroy_context(iscsi);
	iscsi = NULL;
	printf("[OK]\n");

	printf("Verify we can access the LUN from the second initiator.\n");
	ret = testunitready(iscsi2, lun);
	if (ret != 0) {
		goto finished;
	}


finished:
	if (iscsi2 != NULL) {
		iscsi_logout_sync(iscsi2);
		iscsi_destroy_context(iscsi2);
	}
	if (iscsi != NULL) {
		iscsi_logout_sync(iscsi);
		iscsi_destroy_context(iscsi);
	}
	return ret;
}
コード例 #3
0
int T0420_reserve6_simple(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("0420_reserve6_simple:\n");
	printf("===================\n");
	if (show_info) {
		printf("Test RESERVE6/RELEASE6 commands if supported.\n");
		printf("  If device does not support, just verify appropriate error returned\n");
		printf("1. Test simple RESERVE6 followed by RELEASE6\n");
		printf("2. Test Initator 1 can reserve if already reserved by Intiator 1.\n");
		printf("3. Test Initiator 2 can't reserve if already reserved by Initiator 1.\n");
		printf("3a. Test Initiator 2 release when reserved by Initiator 1 returns success, but without releasing.\n");
		printf("4. Test Initiator 1 can testunitready if reserved by Initiator 1.\n");
		printf("5. Test Initiator 2 can't testunitready if reserved by Initiator 1.\n");
		printf("6. Test Initiator 2 can get reservation once Intiator 1 releases reservation.\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");	
		ret = 1;
		goto out_login1;
	}

	ret = 0;

	printf("Send RESERVE6 ... ");
	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 finished1;
	}
	if (task->status != SCSI_STATUS_GOOD) {
		if (task->status == SCSI_STATUS_CHECK_CONDITION
		    && task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST 
		    && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {		
			printf("[OK]\n");
			printf("RESERVE6 Not Supported\n");
			goto finished2;
		} else {
			printf("[FAILED]\n");
			printf("RESERVE6 failed but ascq was wrong. Should "
			       "have failed with ILLEGAL_REQUEST/"
			       "INVALID OPERATOR. Sense:%s\n", 
			       iscsi_get_error(iscsi));
			ret = -1;
			goto finished2;
		}
	}
	scsi_free_scsi_task(task);
	printf("[OK]\n");

	printf("Send RELEASE6 ... ");
	task = iscsi_release6_sync(iscsi, lun);
	if (task == NULL) {
		printf("[FAILED]\n");
		printf("Failed to send RELEASE6 command : %s\n", 
		       iscsi_get_error(iscsi));
		ret = -1;
		goto finished1;
	}
	if (task->status != SCSI_STATUS_GOOD) {
		printf("[FAILED]\n");
		printf("RELEASE6 command failed : %s\n", 
		       iscsi_get_error(iscsi));
		ret = -1;
		goto finished2;
	}
	scsi_free_scsi_task(task);
	printf("[OK]\n");


test2:
	printf("Test that reservation works.\n");
	printf("Send RESERVE6 from Initiator 1. ... ");
	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 finished1;
	}
	if (task->status != SCSI_STATUS_GOOD) {
		printf("[FAILED]\n");
		printf("RESERVE6 command failed : %s\n",
		       iscsi_get_error(iscsi));
		ret = -1;
		goto finished2;
	}
	scsi_free_scsi_task(task);
	printf("[OK]\n");

	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 finished1;
	}
	if (task->status != SCSI_STATUS_GOOD) {
		printf("[FAILED]\n");
		printf("RESERVE6 command failed : %s\n",
		       iscsi_get_error(iscsi));
		ret = -1;
		goto finished2;
	}
	scsi_free_scsi_task(task);
	printf("[OK]\n");

test3:
	printf("Send RESERVE6 from Initiator 2. Expect conflict. ... ");
	task = iscsi_reserve6_sync(iscsi2, lun);
	if (task == NULL) {
		printf("[FAILED]\n");
		printf("Failed to send RESERVE6 command : %s\n",
		       iscsi_get_error(iscsi));
		ret = -1;
		goto finished1;
	} 
	/* We expect this command to fail for the test to pass. */
	if (task->status != SCSI_STATUS_RESERVATION_CONFLICT) {
		printf("[FAILED]\n");
		printf("Expected RESERVATION CONFLICT\n");
		ret = -1;
		goto finished2;
	}
	scsi_free_scsi_task(task);
	printf("[OK]\n");

test3a:
	printf("Send RELEASE6 from Initiator 2..Expect NO-OP. ... ");
	task = iscsi_release6_sync(iscsi2, lun);
	if (task == NULL) {
		printf("[FAILED]\n");
		printf("Failed to send RELEASE6 command : %s\n",
		       iscsi_get_error(iscsi));
		ret = -1;
		goto finished1;
	}
	/* We expect this command to pass. */
	if (task->status != SCSI_STATUS_GOOD) {
		printf("[FAILED]\n");
		printf("RELEASE6 command: failed with sense %s\n",
		       iscsi_get_error(iscsi));
		ret = -1;
		/* Treat as non-fatal failure for now. STGT is broken.*/
		scsi_free_scsi_task(task);
		goto test4;
	}
	scsi_free_scsi_task(task);
	printf("[OK]\n");

test4:
	printf("Send TESTUNITREADY from Initiator 1 ... ");
	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 finished1;
	}
	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;
		goto finished2;
	}
	scsi_free_scsi_task(task);
	printf("[OK]\n");

test5:
	printf("Send TESTUNITREADY from Initiator 2. Expect conflict. ... ");
	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 finished1;
	}
	if (task->status != SCSI_STATUS_RESERVATION_CONFLICT) {
		printf("[FAILED]\n");
		printf("Expected RESERVATION CONFLICT\n");
		ret = -1;
		goto finished2;
	}
	scsi_free_scsi_task(task);
	printf("[OK]\n");

test6:
	printf("Test that release actually works\n");
	printf("Send RELEASE6 from Initiator 1 ... ");
	task = iscsi_release6_sync(iscsi, lun);
	if (task == NULL) {
		printf("[FAILED]\n");
		printf("Failed to send RELEASE6 command : %s\n", 
		       iscsi_get_error(iscsi));
		ret = -1;
		goto finished1;
	}
	if (task->status != SCSI_STATUS_GOOD) {
		printf("[FAILED]\n");
		printf("RELEASE6 command failed : %s\n", 
		       iscsi_get_error(iscsi));
		ret = -1;
		goto finished2;
	}
	scsi_free_scsi_task(task);
	printf("[OK]\n");

	printf("Send RESERVE6 Initiator 2 ... ");
	task = iscsi_reserve6_sync(iscsi2, lun);
	if (task == NULL) {
		printf("[FAILED]\n");
		printf("Failed to send RESERVE6 command : %s\n",
		       iscsi_get_error(iscsi));
		ret = -1;
		goto finished1;
	}
	if (task->status != SCSI_STATUS_GOOD) {
		printf("[FAILED]\n");
		printf("RESERVE6 command failed : %s\n",
		       iscsi_get_error(iscsi));
		ret = -1;
		goto finished2;
	}
	scsi_free_scsi_task(task);
	printf("[OK]\n");

	printf("Send RELEASE6 Initiator 2 ... ");
	task = iscsi_reserve6_sync(iscsi2, lun);
	if (task == NULL) {
		printf("[FAILED]\n");
		printf("Failed to send RELEASE6 command : %s\n",
		       iscsi_get_error(iscsi));
		ret = -1;
		goto finished1;
	}
	if (task->status != SCSI_STATUS_GOOD) {
		printf("[FAILED]\n");
		printf("RELEASE6 command failed : %s\n",
		       iscsi_get_error(iscsi));
		ret = -1;
		goto finished2;
	}
	scsi_free_scsi_task(task);
	printf("[OK]\n");
        goto finished1;


finished2:
	scsi_free_scsi_task(task);
finished1:
	iscsi_logout_sync(iscsi2);
	iscsi_destroy_context(iscsi2);
out_login1:
	iscsi_logout_sync(iscsi);
	iscsi_destroy_context(iscsi);
	return ret;
}