diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 54365b3..b90e9d0 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -160,6 +160,7 @@ EXTERN const char *scsi_sense_key_str(int key); EXTERN const char *scsi_sense_ascq_str(int ascq); +EXTERN const char *scsi_pr_type_str(enum scsi_persistent_out_type pr_type); enum scsi_xfer_dir { SCSI_XFER_NONE = 0, diff --git a/lib/libiscsi.syms b/lib/libiscsi.syms index 1a723e1..80673f5 100644 --- a/lib/libiscsi.syms +++ b/lib/libiscsi.syms @@ -181,6 +181,7 @@ scsi_inquiry_pagecode_to_str scsi_protocol_identifier_to_str scsi_reportluns_cdb scsi_sense_ascq_str +scsi_pr_type_str scsi_sense_key_str scsi_set_task_private_ptr scsi_task_add_data_in_buffer diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index b588286..dc3a706 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -163,6 +163,28 @@ scsi_sense_ascq_str(int ascq) return value_string_find(ascqs, ascq); } +const char * +scsi_pr_type_str(enum scsi_persistent_out_type pr_type) +{ + struct value_string pr_type_strings[] = { + {SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE, + "Write Exclusive"}, + {SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS, + "Exclusive Access"}, + {SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_REGISTRANTS_ONLY, + "Write Exclusive, Registrants Only"}, + {SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_REGISTRANTS_ONLY, + "Exclusive Access Registrants Only"}, + {SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_ALL_REGISTRANTS, + "Write Exclusive, All Registrants"}, + {SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_ALL_REGISTRANTS, + "Exclusive Access, All Registrants"}, + {0, NULL} + }; + + return value_string_find(pr_type_strings, pr_type); +} + inline uint64_t scsi_get_uint64(const unsigned char *c) { diff --git a/test-tool/1130_persistent_reserve_simple.c b/test-tool/1130_persistent_reserve_simple.c index d8cf0d7..2d8ec37 100644 --- a/test-tool/1130_persistent_reserve_simple.c +++ b/test-tool/1130_persistent_reserve_simple.c @@ -24,6 +24,15 @@ #include "iscsi-test.h" +static enum scsi_persistent_out_type pr_types_to_test[] = { + SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE, + SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS, + SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_REGISTRANTS_ONLY, + SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_REGISTRANTS_ONLY, + SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_ALL_REGISTRANTS, + SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_ALL_REGISTRANTS, + 0 +}; int T1130_persistent_reserve_simple(const char *initiator, const char *url, int data_loss, int show_info) @@ -32,22 +41,21 @@ int T1130_persistent_reserve_simple(const char *initiator, int ret; int lun; const unsigned long long key = rand_key(); - struct resvn_type_info *rtip; + int i; + printf("1130_persistent_reserve_simple:\n"); printf("=========================================\n"); if (show_info) { - int idx = 1; + int idx = 1; - printf("Test that we can using each type of Persistent Reservation,\n"); + printf("Test that we can use each type of Persistent Reservation,\n"); printf(" and that we can release each type, as well\n"); printf("%d, We can register a key\n", idx++); - for (rtip = reservation_types; - rtip->pr_type_str != NULL; - rtip++) { + for (i = 0; pr_types_to_test[i] != 0; i++) { printf("%d, Can register %s\n", idx++, - rtip->pr_type_str); + scsi_pr_type_str(pr_types_to_test[i])); printf("%d, Can read reservation\n", idx++); printf("%d, Can release reservation\n", idx++); } @@ -75,23 +83,23 @@ int T1130_persistent_reserve_simple(const char *initiator, goto finished; /* test each reservatoin type */ - for (rtip = reservation_types; - rtip->pr_type_str != NULL; - rtip++) { + for (i = 0; pr_types_to_test[i] != 0; i++) { + enum scsi_persistent_out_type pr_type = pr_types_to_test[i]; + /* reserve the target */ - ret = reserve(iscsi, lun, key, rtip); + ret = reserve(iscsi, lun, key, pr_type); if (ret != 0) goto finished; /* verify target reservation */ ret = verify_reserved_as(iscsi, lun, - pr_type_is_all_registrants(rtip->pr_type) ? 0 : key, - rtip); + pr_type_is_all_registrants(pr_type) ? 0 : key, + pr_type); if (ret != 0) goto finished; /* release our reservation */ - ret = release(iscsi, lun, key, rtip); + ret = release(iscsi, lun, key, pr_type); if (ret != 0) goto finished; } diff --git a/test-tool/iscsi-test.c b/test-tool/iscsi-test.c index e95dcb8..95625a6 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -262,22 +262,6 @@ struct scsi_test tests[] = { { 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) { @@ -589,7 +573,7 @@ int reregister_key_fails(struct iscsi_context *iscsi, int lun, int reserve(struct iscsi_context *iscsi, int lun, - unsigned long long key, struct resvn_type_info *rtip) + unsigned long long key, enum scsi_persistent_out_type pr_type) { struct scsi_persistent_reserve_out_basic poc; struct scsi_task *task; @@ -597,14 +581,14 @@ int reserve(struct iscsi_context *iscsi, int lun, /* reserve the target using specified reservation type */ printf("Send PROUT/RESERVE to reserve, type=%d (%s) ... ", - rtip->pr_type, rtip->pr_type_str); + pr_type, scsi_pr_type_str(pr_type)); memset(&poc, 0, sizeof (poc)); poc.reservation_key = key; task = iscsi_persistent_reserve_out_sync(iscsi, lun, SCSI_PERSISTENT_RESERVE_RESERVE, SCSI_PERSISTENT_RESERVE_SCOPE_LU, - rtip->pr_type, &poc); + pr_type, &poc); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send PROUT command: %s\n", @@ -627,7 +611,7 @@ int reserve(struct iscsi_context *iscsi, int lun, int release(struct iscsi_context *iscsi, int lun, - unsigned long long key, struct resvn_type_info *rtip) + unsigned long long key, enum scsi_persistent_out_type pr_type) { struct scsi_persistent_reserve_out_basic poc; struct scsi_task *task; @@ -635,14 +619,14 @@ int release(struct iscsi_context *iscsi, int lun, /* release the target using specified reservation type */ printf("Send PROUT/RELEASE to release reservation, type=%d ... ", - rtip->pr_type); + pr_type); memset(&poc, 0, sizeof (poc)); poc.reservation_key = key; task = iscsi_persistent_reserve_out_sync(iscsi, lun, SCSI_PERSISTENT_RESERVE_RELEASE, SCSI_PERSISTENT_RESERVE_SCOPE_LU, - rtip->pr_type, &poc); + pr_type, &poc); if (task == NULL) { printf("[FAILED]\n"); printf("Failed to send PROUT command: %s\n", @@ -664,7 +648,7 @@ int release(struct iscsi_context *iscsi, int lun, } int verify_reserved_as(struct iscsi_context *iscsi, int lun, - unsigned long long key, struct resvn_type_info *rtip) + unsigned long long key, enum scsi_persistent_out_type pr_type) { struct scsi_task *task; const int buf_sz = 16384; @@ -672,7 +656,7 @@ int verify_reserved_as(struct iscsi_context *iscsi, int lun, printf("Send PRIN/READ_RESERVATION to verify type=%d ... ", - rtip->pr_type); + pr_type); task = iscsi_persistent_reserve_in_sync(iscsi, lun, SCSI_PERSISTENT_RESERVE_READ_RESERVATION, buf_sz); if (task == NULL) { @@ -698,9 +682,6 @@ int verify_reserved_as(struct iscsi_context *iscsi, int lun, scsi_free_scsi_task(task); - /* - * XXX check reservation (in rr) ... - */ if (!rr->reserved) { printf("Failed to find Target reserved as expected.\n"); @@ -711,9 +692,9 @@ int verify_reserved_as(struct iscsi_context *iscsi, int lun, key, rr->reservation_key); return -1; } - if (rr->pr_type != rtip->pr_type) { + if (rr->pr_type != pr_type) { printf("Failed to find reservation type %d: found %d.\n", - rtip->pr_type, rr->pr_type); + pr_type, rr->pr_type); return -1; } diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index b2664d3..f9d42a6 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -231,13 +231,6 @@ 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, unsigned long long key); int register_key(struct iscsi_context *iscsi, int lun, @@ -247,10 +240,10 @@ int verify_key_presence(struct iscsi_context *iscsi, int lun, int reregister_key_fails(struct iscsi_context *iscsi, int lun, unsigned long long sark); int reserve(struct iscsi_context *iscsi, int lun, - unsigned long long key, struct resvn_type_info *rtip); + unsigned long long key, enum scsi_persistent_out_type pr_type); int release(struct iscsi_context *iscsi, int lun, - unsigned long long key, struct resvn_type_info *rtip); + unsigned long long key, enum scsi_persistent_out_type pr_type); int verify_reserved_as(struct iscsi_context *iscsi, int lun, - unsigned long long key, struct resvn_type_info *rtip); + unsigned long long key, enum scsi_persistent_out_type pr_type); #endif /* _ISCSI_TEST_H_ */