Merge pull request #284 from bvanassche/master

Three bug fixes for the libiscsi test tool
This commit is contained in:
Ronnie Sahlberg
2019-02-05 13:08:58 +10:00
committed by GitHub
3 changed files with 48 additions and 42 deletions

View File

@@ -457,7 +457,7 @@ int iscsi_reconnect(struct iscsi_context *iscsi)
} }
tmp_iscsi->old_iscsi = iscsi->old_iscsi; tmp_iscsi->old_iscsi = iscsi->old_iscsi;
} else { } else {
iscsi->old_iscsi = malloc(sizeof(struct iscsi_context)); tmp_iscsi->old_iscsi = malloc(sizeof(struct iscsi_context));
memcpy(tmp_iscsi->old_iscsi, iscsi, sizeof(struct iscsi_context)); memcpy(tmp_iscsi->old_iscsi, iscsi, sizeof(struct iscsi_context));
} }
memcpy(iscsi, tmp_iscsi, sizeof(struct iscsi_context)); memcpy(iscsi, tmp_iscsi, sizeof(struct iscsi_context));

View File

@@ -770,6 +770,37 @@ print_usage(void)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
/* Clear persistent reservations and reservation keys left by a previous run */
static int clear_pr(struct scsi_device *sdev)
{
int i, res;
struct scsi_task *pr_task;
struct scsi_persistent_reserve_in_read_keys *rk;
res = 0;
if (prin_read_keys(sdev, &pr_task, &rk, 16384) != 0)
goto out;
res = -1;
if (rk->num_keys && data_loss == 0)
goto out;
res = 0;
for (i = 0; i < rk->num_keys; i++) {
res = prout_register_and_ignore(sdev, rk->keys[i]);
if (res)
break;
res = prout_register_key(sdev, 0, rk->keys[i]);
if (res)
break;
}
scsi_free_scsi_task(pr_task);
out:
return res;
}
void void
test_setup(void) test_setup(void)
{ {
@@ -830,6 +861,7 @@ suite_cleanup(void)
for (i = 0; i < mp_num_sds; i++) { for (i = 0; i < mp_num_sds; i++) {
if (mp_sds[i]->iscsi_url) { if (mp_sds[i]->iscsi_url) {
if (mp_sds[i]->iscsi_ctx) { if (mp_sds[i]->iscsi_ctx) {
clear_pr(mp_sds[i]);
iscsi_logout_sync(mp_sds[i]->iscsi_ctx); iscsi_logout_sync(mp_sds[i]->iscsi_ctx);
iscsi_destroy_context(mp_sds[i]->iscsi_ctx); iscsi_destroy_context(mp_sds[i]->iscsi_ctx);
mp_sds[i]->iscsi_ctx = NULL; mp_sds[i]->iscsi_ctx = NULL;
@@ -1062,33 +1094,6 @@ static void free_scsi_device(struct scsi_device *sdev)
free(sdev); free(sdev);
} }
/* Clear persistent reservations and reservation keys left by a previous run */
static int clear_pr(struct scsi_device *sdev)
{
int i, res;
struct scsi_task *pr_task;
struct scsi_persistent_reserve_in_read_keys *rk;
res = 0;
if (prin_read_keys(sdev, &pr_task, &rk, 16384) != 0)
goto out;
res = -1;
if (rk->num_keys && data_loss == 0)
goto out;
res = 0;
for (i = 0; i < rk->num_keys; i++) {
prout_register_and_ignore(sdev, rk->keys[i]);
prout_register_key(sdev, 0, rk->keys[i]);
}
scsi_free_scsi_task(pr_task);
out:
return res;
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@@ -1241,6 +1246,10 @@ main(int argc, char *argv[])
"Failed to connect to SCSI device %d\n", i); "Failed to connect to SCSI device %d\n", i);
goto err_sds_free; goto err_sds_free;
} }
if (clear_pr(mp_sds[i]) < 0) {
printf("One or more persistent reservations keys have been registered\n");
return -1;
}
} }
if (mp_num_sds > 1) { if (mp_num_sds > 1) {
@@ -1439,11 +1448,6 @@ main(int argc, char *argv[])
} }
scsi_free_scsi_task(task); scsi_free_scsi_task(task);
if (clear_pr(sd) < 0) {
printf("One or more persistent reservations keys have been registered\n");
return -1;
}
/* BLKSECTGET for /dev/sg* is a shitshow under linux. /* BLKSECTGET for /dev/sg* is a shitshow under linux.
* Even 4.2 kernels return number of bytes instead of number * Even 4.2 kernels return number of bytes instead of number
* of sectors here. Just force it to 120k and let us get on with * of sectors here. Just force it to 120k and let us get on with

View File

@@ -58,15 +58,17 @@ test_prin_read_keys_truncate(void)
} }
CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(ret, 0);
/* if (rk) {
* SPC5r17: 6.16.2 READ KEYS service action /*
* The ADDITIONAL LENGTH field indicates the number of bytes in * SPC5r17: 6.16.2 READ KEYS service action
* the Reservation key list. The contents of the ADDITIONAL * The ADDITIONAL LENGTH field indicates the number of bytes in
* LENGTH field are not altered based on the allocation length. * the Reservation key list. The contents of the ADDITIONAL
*/ * LENGTH field are not altered based on the allocation length.
CU_ASSERT_NOT_EQUAL(rk->additional_length, 0); */
/* key array should have been truncated in the response */ CU_ASSERT_NOT_EQUAL(rk->additional_length, 0);
CU_ASSERT_EQUAL(rk->num_keys, 0); /* key array should have been truncated in the response */
CU_ASSERT_EQUAL(rk->num_keys, 0);
}
/* remove our key from the target */ /* remove our key from the target */
ret = prout_register_key(sd, 0, key); ret = prout_register_key(sd, 0, key);