TESTS: move the default url, lun and iscsi context into a structure
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
This commit is contained in:
+51
-48
@@ -50,6 +50,7 @@
|
||||
#define PROG "iscsi-test-cu"
|
||||
|
||||
int loglevel = LOG_NORMAL;
|
||||
struct scsi_device *sd;
|
||||
|
||||
/*
|
||||
* this allows us to redefine how PDU are queued, at times, for
|
||||
@@ -595,8 +596,6 @@ static struct test_family families[] = {
|
||||
/*
|
||||
* globals for test setup and teardown
|
||||
*/
|
||||
int tgt_lun;
|
||||
struct iscsi_context *iscsic;
|
||||
struct scsi_task *task;
|
||||
int tgt_lun2;
|
||||
struct iscsi_context *iscsic2;
|
||||
@@ -683,8 +682,8 @@ test_teardown(void)
|
||||
int
|
||||
suite_init(void)
|
||||
{
|
||||
iscsic = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun);
|
||||
if (iscsic == NULL) {
|
||||
sd->iscsi_ctx = iscsi_context_login(initiatorname1, sd->iscsi_url, &sd->iscsi_lun);
|
||||
if (sd->iscsi_ctx == NULL) {
|
||||
fprintf(stderr,
|
||||
"error: Failed to login to target for test set-up\n");
|
||||
return 1;
|
||||
@@ -703,10 +702,10 @@ suite_cleanup(void)
|
||||
/* libcunit version 1 */
|
||||
test_teardown();
|
||||
#endif
|
||||
if (iscsic) {
|
||||
iscsi_logout_sync(iscsic);
|
||||
iscsi_destroy_context(iscsic);
|
||||
iscsic = NULL;
|
||||
if (sd->iscsi_ctx) {
|
||||
iscsi_logout_sync(sd->iscsi_ctx);
|
||||
iscsi_destroy_context(sd->iscsi_ctx);
|
||||
sd->iscsi_ctx = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -715,7 +714,7 @@ int
|
||||
suite_init_pgr(void)
|
||||
{
|
||||
suite_init();
|
||||
iscsic2 = iscsi_context_login(initiatorname2, tgt_url, &tgt_lun2);
|
||||
iscsic2 = iscsi_context_login(initiatorname2, sd->iscsi_url, &tgt_lun2);
|
||||
if (iscsic2 == NULL) {
|
||||
fprintf(stderr,
|
||||
"error: Failed to login to target for test set-up\n");
|
||||
@@ -933,6 +932,8 @@ main(int argc, char *argv[])
|
||||
int i, c;
|
||||
int opt_idx = 0;
|
||||
|
||||
sd = malloc(sizeof(struct scsi_device));
|
||||
|
||||
while ((c = getopt_long(argc, argv, "?hli:I:t:sdgfAsSnuvxV", long_opts,
|
||||
&opt_idx)) > 0) {
|
||||
switch (c) {
|
||||
@@ -994,7 +995,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
tgt_url = strdup(argv[optind++]);
|
||||
sd->iscsi_url = strdup(argv[optind++]);
|
||||
}
|
||||
if (optind < argc) {
|
||||
fprintf(stderr, "error: too many arguments\n");
|
||||
@@ -1005,7 +1006,7 @@ main(int argc, char *argv[])
|
||||
/* XXX why is this done? */
|
||||
real_iscsi_queue_pdu = dlsym(RTLD_NEXT, "iscsi_queue_pdu");
|
||||
|
||||
if (tgt_url == NULL) {
|
||||
if (sd->iscsi_url == NULL) {
|
||||
fprintf(stderr, "You must specify the URL\n");
|
||||
print_usage();
|
||||
if (testname_re)
|
||||
@@ -1013,8 +1014,8 @@ main(int argc, char *argv[])
|
||||
return 10;
|
||||
}
|
||||
|
||||
iscsic = iscsi_context_login(initiatorname1, tgt_url, &lun);
|
||||
if (iscsic == NULL) {
|
||||
sd->iscsi_ctx = iscsi_context_login(initiatorname1, sd->iscsi_url, &lun);
|
||||
if (sd->iscsi_ctx == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -1024,46 +1025,46 @@ main(int argc, char *argv[])
|
||||
* All devices support readcapacity10 but only some support
|
||||
* readcapacity16
|
||||
*/
|
||||
task = iscsi_readcapacity10_sync(iscsic, lun, 0, 0);
|
||||
task = iscsi_readcapacity10_sync(sd->iscsi_ctx, lun, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("Failed to send READCAPACITY10 command: %s\n",
|
||||
iscsi_get_error(iscsic));
|
||||
iscsi_destroy_context(iscsic);
|
||||
iscsi_get_error(sd->iscsi_ctx));
|
||||
iscsi_destroy_context(sd->iscsi_ctx);
|
||||
return -1;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("READCAPACITY10 command: failed with sense. %s\n",
|
||||
iscsi_get_error(iscsic));
|
||||
iscsi_get_error(sd->iscsi_ctx));
|
||||
scsi_free_scsi_task(task);
|
||||
iscsi_destroy_context(iscsic);
|
||||
iscsi_destroy_context(sd->iscsi_ctx);
|
||||
return -1;
|
||||
}
|
||||
rc10 = scsi_datain_unmarshall(task);
|
||||
if (rc10 == NULL) {
|
||||
printf("failed to unmarshall READCAPACITY10 data. %s\n",
|
||||
iscsi_get_error(iscsic));
|
||||
iscsi_get_error(sd->iscsi_ctx));
|
||||
scsi_free_scsi_task(task);
|
||||
iscsi_destroy_context(iscsic);
|
||||
iscsi_destroy_context(sd->iscsi_ctx);
|
||||
return -1;
|
||||
}
|
||||
block_size = rc10->block_size;
|
||||
num_blocks = rc10->lba + 1;
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
rc16_task = iscsi_readcapacity16_sync(iscsic, lun);
|
||||
rc16_task = iscsi_readcapacity16_sync(sd->iscsi_ctx, lun);
|
||||
if (rc16_task == NULL) {
|
||||
printf("Failed to send READCAPACITY16 command: %s\n",
|
||||
iscsi_get_error(iscsic));
|
||||
iscsi_destroy_context(iscsic);
|
||||
iscsi_get_error(sd->iscsi_ctx));
|
||||
iscsi_destroy_context(sd->iscsi_ctx);
|
||||
return -1;
|
||||
}
|
||||
if (rc16_task->status == SCSI_STATUS_GOOD) {
|
||||
rc16 = scsi_datain_unmarshall(rc16_task);
|
||||
if (rc16 == NULL) {
|
||||
printf("failed to unmarshall READCAPACITY16 data. %s\n",
|
||||
iscsi_get_error(iscsic));
|
||||
iscsi_get_error(sd->iscsi_ctx));
|
||||
scsi_free_scsi_task(rc16_task);
|
||||
iscsi_destroy_context(iscsic);
|
||||
iscsi_destroy_context(sd->iscsi_ctx);
|
||||
return -1;
|
||||
}
|
||||
block_size = rc16->block_length;
|
||||
@@ -1071,9 +1072,9 @@ main(int argc, char *argv[])
|
||||
lbppb = 1 << rc16->lbppbe;
|
||||
}
|
||||
|
||||
inq_task = iscsi_inquiry_sync(iscsic, lun, 0, 0, 64);
|
||||
inq_task = iscsi_inquiry_sync(sd->iscsi_ctx, lun, 0, 0, 64);
|
||||
if (inq_task == NULL || inq_task->status != SCSI_STATUS_GOOD) {
|
||||
printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic));
|
||||
printf("Inquiry command failed : %s\n", iscsi_get_error(sd->iscsi_ctx));
|
||||
return -1;
|
||||
}
|
||||
full_size = scsi_datain_getfullsize(inq_task);
|
||||
@@ -1081,10 +1082,10 @@ main(int argc, char *argv[])
|
||||
scsi_free_scsi_task(inq_task);
|
||||
|
||||
/* we need more data for the full list */
|
||||
inq_task = iscsi_inquiry_sync(iscsic, lun, 0, 0, full_size);
|
||||
inq_task = iscsi_inquiry_sync(sd->iscsi_ctx, lun, 0, 0, full_size);
|
||||
if (inq_task == NULL) {
|
||||
printf("Inquiry command failed : %s\n",
|
||||
iscsi_get_error(iscsic));
|
||||
iscsi_get_error(sd->iscsi_ctx));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1103,7 +1104,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* try reading block limits vpd */
|
||||
inq_bl_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, 64);
|
||||
inq_bl_task = iscsi_inquiry_sync(sd->iscsi_ctx, lun, 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, 64);
|
||||
if (inq_bl_task && inq_bl_task->status != SCSI_STATUS_GOOD) {
|
||||
scsi_free_scsi_task(inq_bl_task);
|
||||
inq_bl_task = NULL;
|
||||
@@ -1113,8 +1114,8 @@ main(int argc, char *argv[])
|
||||
if (full_size > inq_bl_task->datain.size) {
|
||||
scsi_free_scsi_task(inq_bl_task);
|
||||
|
||||
if ((inq_bl_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, full_size)) == NULL) {
|
||||
printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic));
|
||||
if ((inq_bl_task = iscsi_inquiry_sync(sd->iscsi_ctx, lun, 1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, full_size)) == NULL) {
|
||||
printf("Inquiry command failed : %s\n", iscsi_get_error(sd->iscsi_ctx));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1127,7 +1128,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* try reading block device characteristics vpd */
|
||||
inq_bdc_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_BLOCK_DEVICE_CHARACTERISTICS, 255);
|
||||
inq_bdc_task = iscsi_inquiry_sync(sd->iscsi_ctx, lun, 1, SCSI_INQUIRY_PAGECODE_BLOCK_DEVICE_CHARACTERISTICS, 255);
|
||||
if (inq_bdc_task == NULL) {
|
||||
printf("Failed to read Block Device Characteristics page\n");
|
||||
}
|
||||
@@ -1141,9 +1142,9 @@ main(int argc, char *argv[])
|
||||
|
||||
/* if thin provisioned we also need to read the VPD page for it */
|
||||
if (rc16 && rc16->lbpme != 0){
|
||||
inq_lbp_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, 64);
|
||||
inq_lbp_task = iscsi_inquiry_sync(sd->iscsi_ctx, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, 64);
|
||||
if (inq_lbp_task == NULL || inq_lbp_task->status != SCSI_STATUS_GOOD) {
|
||||
printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic));
|
||||
printf("Inquiry command failed : %s\n", iscsi_get_error(sd->iscsi_ctx));
|
||||
return -1;
|
||||
}
|
||||
full_size = scsi_datain_getfullsize(inq_lbp_task);
|
||||
@@ -1151,8 +1152,8 @@ main(int argc, char *argv[])
|
||||
scsi_free_scsi_task(inq_lbp_task);
|
||||
|
||||
/* we need more data for the full list */
|
||||
if ((inq_lbp_task = iscsi_inquiry_sync(iscsic, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, full_size)) == NULL) {
|
||||
printf("Inquiry command failed : %s\n", iscsi_get_error(iscsic));
|
||||
if ((inq_lbp_task = iscsi_inquiry_sync(sd->iscsi_ctx, lun, 1, SCSI_INQUIRY_PAGECODE_LOGICAL_BLOCK_PROVISIONING, full_size)) == NULL) {
|
||||
printf("Inquiry command failed : %s\n", iscsi_get_error(sd->iscsi_ctx));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1164,12 +1165,12 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
rsop_task = iscsi_report_supported_opcodes_sync(iscsic, lun,
|
||||
rsop_task = iscsi_report_supported_opcodes_sync(sd->iscsi_ctx, lun,
|
||||
1, SCSI_REPORT_SUPPORTING_OPS_ALL, 0, 0, 65535);
|
||||
if (rsop_task == NULL) {
|
||||
printf("Failed to send REPORT_SUPPORTED_OPCODES command: %s\n",
|
||||
iscsi_get_error(iscsic));
|
||||
iscsi_destroy_context(iscsic);
|
||||
iscsi_get_error(sd->iscsi_ctx));
|
||||
iscsi_destroy_context(sd->iscsi_ctx);
|
||||
return -1;
|
||||
}
|
||||
if (rsop_task->status == SCSI_STATUS_GOOD) {
|
||||
@@ -1177,19 +1178,19 @@ main(int argc, char *argv[])
|
||||
if (rsop == NULL) {
|
||||
printf("failed to unmarshall REPORT_SUPPORTED_OPCODES "
|
||||
"data. %s\n",
|
||||
iscsi_get_error(iscsic));
|
||||
iscsi_get_error(sd->iscsi_ctx));
|
||||
scsi_free_scsi_task(rsop_task);
|
||||
}
|
||||
}
|
||||
|
||||
/* check if the device is write protected or not */
|
||||
task = iscsi_modesense6_sync(iscsic, lun, 0, SCSI_MODESENSE_PC_CURRENT,
|
||||
task = iscsi_modesense6_sync(sd->iscsi_ctx, lun, 0, SCSI_MODESENSE_PC_CURRENT,
|
||||
SCSI_MODEPAGE_RETURN_ALL_PAGES,
|
||||
0, 255);
|
||||
if (task == NULL) {
|
||||
printf("Failed to send MODE_SENSE6 command: %s\n",
|
||||
iscsi_get_error(iscsic));
|
||||
iscsi_destroy_context(iscsic);
|
||||
iscsi_get_error(sd->iscsi_ctx));
|
||||
iscsi_destroy_context(sd->iscsi_ctx);
|
||||
return -1;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
@@ -1205,8 +1206,8 @@ main(int argc, char *argv[])
|
||||
}
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
iscsi_logout_sync(iscsic);
|
||||
iscsi_destroy_context(iscsic);
|
||||
iscsi_logout_sync(sd->iscsi_ctx);
|
||||
iscsi_destroy_context(sd->iscsi_ctx);
|
||||
|
||||
if (is_usb) {
|
||||
printf("USB device. Clamping maximum transfer length to 120k\n");
|
||||
@@ -1243,7 +1244,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
CU_cleanup_registry();
|
||||
free(discard_const(tgt_url));
|
||||
free(discard_const(sd->iscsi_url));
|
||||
|
||||
if (inq_task != NULL) {
|
||||
scsi_free_scsi_task(inq_task);
|
||||
@@ -1263,6 +1264,8 @@ main(int argc, char *argv[])
|
||||
if (rsop_task != NULL) {
|
||||
scsi_free_scsi_task(rsop_task);
|
||||
}
|
||||
|
||||
if (sd != NULL) {
|
||||
free(sd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user