Cleanup to make tests easier to read.
This commit is contained in:
@@ -24,27 +24,6 @@
|
|||||||
#include "iscsi-test.h"
|
#include "iscsi-test.h"
|
||||||
|
|
||||||
|
|
||||||
struct resvn_test_info {
|
|
||||||
const char *resvn_str;
|
|
||||||
enum scsi_persistent_out_type resvn_type;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct resvn_test_info rti[] = {
|
|
||||||
{"Write Exclusive",
|
|
||||||
SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE},
|
|
||||||
{"Exclusive Access",
|
|
||||||
SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS},
|
|
||||||
{"Write Exclusive, Registrants Only",
|
|
||||||
SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_REGISTRANTS_ONLY},
|
|
||||||
{"Exclusive Access, Registrants Only",
|
|
||||||
SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_REGISTRANTS_ONLY},
|
|
||||||
{"Write Exclusive, All Registrants",
|
|
||||||
SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_ALL_REGISTRANTS},
|
|
||||||
{"Exclusive Access, All Registrants",
|
|
||||||
SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_ALL_REGISTRANTS},
|
|
||||||
{NULL, 0}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
int T1130_persistent_reserve_simple(const char *initiator,
|
int T1130_persistent_reserve_simple(const char *initiator,
|
||||||
const char *url, int data_loss, int show_info)
|
const char *url, int data_loss, int show_info)
|
||||||
@@ -53,7 +32,7 @@ int T1130_persistent_reserve_simple(const char *initiator,
|
|||||||
int ret;
|
int ret;
|
||||||
int lun;
|
int lun;
|
||||||
const unsigned long long key = rand_key();
|
const unsigned long long key = rand_key();
|
||||||
struct resvn_test_info *rtip;
|
struct resvn_type_info *rtip;
|
||||||
|
|
||||||
|
|
||||||
printf("1130_persistent_reserve_simple:\n");
|
printf("1130_persistent_reserve_simple:\n");
|
||||||
@@ -64,8 +43,11 @@ int T1130_persistent_reserve_simple(const char *initiator,
|
|||||||
printf("Test that we can using each type of Persistent Reservation,\n");
|
printf("Test that we can using each type of Persistent Reservation,\n");
|
||||||
printf(" and that we can release each type, as well\n");
|
printf(" and that we can release each type, as well\n");
|
||||||
printf("%d, We can register a key\n", idx++);
|
printf("%d, We can register a key\n", idx++);
|
||||||
for (rtip = rti; rtip->resvn_str != NULL; rtip++) {
|
for (rtip = reservation_types;
|
||||||
printf("%d, Can register %s\n", idx++, rtip->resvn_str);
|
rtip->pr_type_str != NULL;
|
||||||
|
rtip++) {
|
||||||
|
printf("%d, Can register %s\n", idx++,
|
||||||
|
rtip->pr_type_str);
|
||||||
printf("%d, Can read reservation\n", idx++);
|
printf("%d, Can read reservation\n", idx++);
|
||||||
printf("%d, Can release reservation\n", idx++);
|
printf("%d, Can release reservation\n", idx++);
|
||||||
}
|
}
|
||||||
@@ -93,18 +75,23 @@ int T1130_persistent_reserve_simple(const char *initiator,
|
|||||||
goto finished;
|
goto finished;
|
||||||
|
|
||||||
/* test each reservatoin type */
|
/* test each reservatoin type */
|
||||||
for (rtip = rti; rtip->resvn_str != NULL; rtip++) {
|
for (rtip = reservation_types;
|
||||||
|
rtip->pr_type_str != NULL;
|
||||||
|
rtip++) {
|
||||||
/* reserve the target */
|
/* reserve the target */
|
||||||
ret = reserve(iscsi, lun, key, rtip->resvn_type);
|
ret = reserve(iscsi, lun, key, rtip);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
goto finished;
|
goto finished;
|
||||||
|
|
||||||
/* verify target reservation */
|
/* verify target reservation */
|
||||||
ret = verify_reserved_as(iscsi, lun,
|
ret = verify_reserved_as(iscsi, lun,
|
||||||
pr_type_is_all_registrants(rtip->resvn_type) ? 0 : key,
|
pr_type_is_all_registrants(rtip->pr_type) ? 0 : key,
|
||||||
rtip->resvn_type);
|
rtip);
|
||||||
|
if (ret != 0)
|
||||||
|
goto finished;
|
||||||
|
|
||||||
/* release our reservation */
|
/* release our reservation */
|
||||||
ret = release(iscsi, lun, key, rtip->resvn_type);
|
ret = release(iscsi, lun, key, rtip);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
goto finished;
|
goto finished;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,6 +262,23 @@ struct scsi_test tests[] = {
|
|||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct resvn_type_info reservation_types[] = {
|
||||||
|
{"Write Exclusive",
|
||||||
|
SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE},
|
||||||
|
{"Exclusive Access",
|
||||||
|
SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS},
|
||||||
|
{"Write Exclusive, Registrants Only",
|
||||||
|
SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_REGISTRANTS_ONLY},
|
||||||
|
{"Exclusive Access, Registrants Only",
|
||||||
|
SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_REGISTRANTS_ONLY},
|
||||||
|
{"Write Exclusive, All Registrants",
|
||||||
|
SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_ALL_REGISTRANTS},
|
||||||
|
{"Exclusive Access, All Registrants",
|
||||||
|
SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_ALL_REGISTRANTS},
|
||||||
|
{NULL, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
void print_usage(void)
|
void print_usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: iscsi-test [-?] [-?|--help] [--usage] [-t|--test=<test>] [-s|--skip=<test>]\n"
|
fprintf(stderr, "Usage: iscsi-test [-?] [-?|--help] [--usage] [-t|--test=<test>] [-s|--skip=<test>]\n"
|
||||||
@@ -440,7 +457,8 @@ int register_key(struct iscsi_context *iscsi, int lun,
|
|||||||
|
|
||||||
|
|
||||||
/* register our reservation key with the target */
|
/* register our reservation key with the target */
|
||||||
printf("Send PROUT/REGISTER to register ... ");
|
printf("Send PROUT/REGISTER to %s ... ",
|
||||||
|
sark != 0 ? "register" : "unregister");
|
||||||
memset(&poc, 0, sizeof (poc));
|
memset(&poc, 0, sizeof (poc));
|
||||||
poc.service_action_reservation_key = sark;
|
poc.service_action_reservation_key = sark;
|
||||||
poc.reservation_key = rk;
|
poc.reservation_key = rk;
|
||||||
@@ -571,21 +589,22 @@ int reregister_key_fails(struct iscsi_context *iscsi, int lun,
|
|||||||
|
|
||||||
|
|
||||||
int reserve(struct iscsi_context *iscsi, int lun,
|
int reserve(struct iscsi_context *iscsi, int lun,
|
||||||
unsigned long long key, enum scsi_persistent_out_type pr_type)
|
unsigned long long key, struct resvn_type_info *rtip)
|
||||||
{
|
{
|
||||||
struct scsi_persistent_reserve_out_basic poc;
|
struct scsi_persistent_reserve_out_basic poc;
|
||||||
struct scsi_task *task;
|
struct scsi_task *task;
|
||||||
|
|
||||||
|
|
||||||
/* reserve the target using specified reservation type */
|
/* reserve the target using specified reservation type */
|
||||||
printf("Send PROUT/RESERVE to reserve, type=%d ... ", pr_type);
|
printf("Send PROUT/RESERVE to reserve, type=%d (%s) ... ",
|
||||||
|
rtip->pr_type, rtip->pr_type_str);
|
||||||
|
|
||||||
memset(&poc, 0, sizeof (poc));
|
memset(&poc, 0, sizeof (poc));
|
||||||
poc.reservation_key = key;
|
poc.reservation_key = key;
|
||||||
task = iscsi_persistent_reserve_out_sync(iscsi, lun,
|
task = iscsi_persistent_reserve_out_sync(iscsi, lun,
|
||||||
SCSI_PERSISTENT_RESERVE_RESERVE,
|
SCSI_PERSISTENT_RESERVE_RESERVE,
|
||||||
SCSI_PERSISTENT_RESERVE_SCOPE_LU,
|
SCSI_PERSISTENT_RESERVE_SCOPE_LU,
|
||||||
pr_type, &poc);
|
rtip->pr_type, &poc);
|
||||||
if (task == NULL) {
|
if (task == NULL) {
|
||||||
printf("[FAILED]\n");
|
printf("[FAILED]\n");
|
||||||
printf("Failed to send PROUT command: %s\n",
|
printf("Failed to send PROUT command: %s\n",
|
||||||
@@ -608,7 +627,7 @@ int reserve(struct iscsi_context *iscsi, int lun,
|
|||||||
|
|
||||||
|
|
||||||
int release(struct iscsi_context *iscsi, int lun,
|
int release(struct iscsi_context *iscsi, int lun,
|
||||||
unsigned long long key, enum scsi_persistent_out_type pr_type)
|
unsigned long long key, struct resvn_type_info *rtip)
|
||||||
{
|
{
|
||||||
struct scsi_persistent_reserve_out_basic poc;
|
struct scsi_persistent_reserve_out_basic poc;
|
||||||
struct scsi_task *task;
|
struct scsi_task *task;
|
||||||
@@ -616,14 +635,14 @@ int release(struct iscsi_context *iscsi, int lun,
|
|||||||
|
|
||||||
/* release the target using specified reservation type */
|
/* release the target using specified reservation type */
|
||||||
printf("Send PROUT/RELEASE to release reservation, type=%d ... ",
|
printf("Send PROUT/RELEASE to release reservation, type=%d ... ",
|
||||||
pr_type);
|
rtip->pr_type);
|
||||||
|
|
||||||
memset(&poc, 0, sizeof (poc));
|
memset(&poc, 0, sizeof (poc));
|
||||||
poc.reservation_key = key;
|
poc.reservation_key = key;
|
||||||
task = iscsi_persistent_reserve_out_sync(iscsi, lun,
|
task = iscsi_persistent_reserve_out_sync(iscsi, lun,
|
||||||
SCSI_PERSISTENT_RESERVE_RELEASE,
|
SCSI_PERSISTENT_RESERVE_RELEASE,
|
||||||
SCSI_PERSISTENT_RESERVE_SCOPE_LU,
|
SCSI_PERSISTENT_RESERVE_SCOPE_LU,
|
||||||
pr_type, &poc);
|
rtip->pr_type, &poc);
|
||||||
if (task == NULL) {
|
if (task == NULL) {
|
||||||
printf("[FAILED]\n");
|
printf("[FAILED]\n");
|
||||||
printf("Failed to send PROUT command: %s\n",
|
printf("Failed to send PROUT command: %s\n",
|
||||||
@@ -645,7 +664,7 @@ int release(struct iscsi_context *iscsi, int lun,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int verify_reserved_as(struct iscsi_context *iscsi, int lun,
|
int verify_reserved_as(struct iscsi_context *iscsi, int lun,
|
||||||
unsigned long long key, enum scsi_persistent_out_type pr_type)
|
unsigned long long key, struct resvn_type_info *rtip)
|
||||||
{
|
{
|
||||||
struct scsi_task *task;
|
struct scsi_task *task;
|
||||||
const int buf_sz = 16384;
|
const int buf_sz = 16384;
|
||||||
@@ -653,7 +672,7 @@ int verify_reserved_as(struct iscsi_context *iscsi, int lun,
|
|||||||
|
|
||||||
|
|
||||||
printf("Send PRIN/READ_RESERVATION to verify type=%d ... ",
|
printf("Send PRIN/READ_RESERVATION to verify type=%d ... ",
|
||||||
pr_type);
|
rtip->pr_type);
|
||||||
task = iscsi_persistent_reserve_in_sync(iscsi, lun,
|
task = iscsi_persistent_reserve_in_sync(iscsi, lun,
|
||||||
SCSI_PERSISTENT_RESERVE_READ_RESERVATION, buf_sz);
|
SCSI_PERSISTENT_RESERVE_READ_RESERVATION, buf_sz);
|
||||||
if (task == NULL) {
|
if (task == NULL) {
|
||||||
@@ -692,9 +711,9 @@ int verify_reserved_as(struct iscsi_context *iscsi, int lun,
|
|||||||
key, rr->reservation_key);
|
key, rr->reservation_key);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (rr->pr_type != pr_type) {
|
if (rr->pr_type != rtip->pr_type) {
|
||||||
printf("Failed to find reservation type %d: found %d.\n",
|
printf("Failed to find reservation type %d: found %d.\n",
|
||||||
pr_type, rr->pr_type);
|
rtip->pr_type, rr->pr_type);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -231,6 +231,13 @@ static inline int pr_type_is_all_registrants(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct resvn_type_info {
|
||||||
|
const char *pr_type_str;
|
||||||
|
enum scsi_persistent_out_type pr_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct resvn_type_info reservation_types[];
|
||||||
|
|
||||||
int register_and_ignore(struct iscsi_context *iscsi, int lun,
|
int register_and_ignore(struct iscsi_context *iscsi, int lun,
|
||||||
unsigned long long key);
|
unsigned long long key);
|
||||||
int register_key(struct iscsi_context *iscsi, int lun,
|
int register_key(struct iscsi_context *iscsi, int lun,
|
||||||
@@ -240,10 +247,10 @@ int verify_key_presence(struct iscsi_context *iscsi, int lun,
|
|||||||
int reregister_key_fails(struct iscsi_context *iscsi, int lun,
|
int reregister_key_fails(struct iscsi_context *iscsi, int lun,
|
||||||
unsigned long long sark);
|
unsigned long long sark);
|
||||||
int reserve(struct iscsi_context *iscsi, int lun,
|
int reserve(struct iscsi_context *iscsi, int lun,
|
||||||
unsigned long long key, enum scsi_persistent_out_type pr_type);
|
unsigned long long key, struct resvn_type_info *rtip);
|
||||||
int release(struct iscsi_context *iscsi, int lun,
|
int release(struct iscsi_context *iscsi, int lun,
|
||||||
unsigned long long key, enum scsi_persistent_out_type pr_type);
|
unsigned long long key, struct resvn_type_info *rtip);
|
||||||
int verify_reserved_as(struct iscsi_context *iscsi, int lun,
|
int verify_reserved_as(struct iscsi_context *iscsi, int lun,
|
||||||
unsigned long long key, enum scsi_persistent_out_type pr_type);
|
unsigned long long key, struct resvn_type_info *rtip);
|
||||||
|
|
||||||
#endif /* _ISCSI_TEST_H_ */
|
#endif /* _ISCSI_TEST_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user