diff --git a/.gitignore b/.gitignore index b3c021b..f465bd5 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ bin /libtool /ltmain.sh libiscsi-*.tar.gz +TAGS diff --git a/Makefile.am b/Makefile.am index 756544d..7d9b69f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -153,7 +153,8 @@ bin_iscsi_test_SOURCES = test-tool/iscsi-test.c \ test-tool/1042_unsolicited_nonimmediate_data.c \ test-tool/1100_persistent_reserve_in_read_keys_simple.c \ test-tool/1110_persistent_reserve_in_serviceaction_range.c \ - test-tool/1120_persistent_register_simple.c + test-tool/1120_persistent_register_simple.c \ + test-tool/1130_persistent_reserve_simple.c endif diff --git a/include/scsi-lowlevel.h b/include/scsi-lowlevel.h index 4f99e07..54365b3 100644 --- a/include/scsi-lowlevel.h +++ b/include/scsi-lowlevel.h @@ -725,6 +725,11 @@ struct scsi_persistent_reserve_in_read_keys { struct scsi_persistent_reserve_in_read_reservation { uint32_t prgeneration; uint32_t additional_length; + + int reserved; + + uint64_t reservation_key; + unsigned char pr_type; }; struct scsi_persistent_reserve_in_report_capabilities { diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c index e95cb3c..b588286 100644 --- a/lib/scsi-lowlevel.c +++ b/lib/scsi-lowlevel.c @@ -666,15 +666,30 @@ scsi_persistentreservein_datain_unmarshall(struct scsi_task *task) rk->keys[i] = scsi_get_uint64(&task->datain.data[8 + i * 8]); } return rk; - case SCSI_PERSISTENT_RESERVE_READ_RESERVATION: - rr = scsi_malloc(task, sizeof(struct scsi_persistent_reserve_in_read_reservation)); + case SCSI_PERSISTENT_RESERVE_READ_RESERVATION: { + size_t alloc_sz; + + i = scsi_get_uint32(&task->datain.data[4]); + alloc_sz = offsetof( + struct scsi_persistent_reserve_in_read_reservation, + reserved) + i; + + rr = scsi_malloc(task, alloc_sz); if (rr == NULL) { return NULL; } - rr->prgeneration = scsi_get_uint32(&task->datain.data[0]); - rr->additional_length = scsi_get_uint32(&task->datain.data[4]); + memset(rr, 0, alloc_sz); + rr->prgeneration = scsi_get_uint32(&task->datain.data[0]); + + if (i > 0) { + rr->reserved = 1; + rr->reservation_key = + scsi_get_uint64(&task->datain.data[8]); + rr->pr_type = task->datain.data[21] & 0xff; + } return rr; + } case SCSI_PERSISTENT_RESERVE_REPORT_CAPABILITIES: rc = scsi_malloc(task, sizeof(struct scsi_persistent_reserve_in_report_capabilities)); if (rc == NULL) { diff --git a/test-tool/1120_persistent_register_simple.c b/test-tool/1120_persistent_register_simple.c index 612a9f7..5d43392 100644 --- a/test-tool/1120_persistent_register_simple.c +++ b/test-tool/1120_persistent_register_simple.c @@ -18,215 +18,15 @@ #include #include #include -#include -#include -#include -#include #include "iscsi.h" #include "scsi-lowlevel.h" #include "iscsi-test.h" -static inline long rand_key(void) -{ - time_t t; - pid_t p; - unsigned int s; - long l; - - (void)time(&t); - p = getpid(); - s = ((int)p * (t & 0xffff)); - srandom(s); - l = random(); - return l; -} - -int register_and_ignore(struct iscsi_context *iscsi, int lun, - unsigned long long sark) -{ - struct scsi_persistent_reserve_out_basic poc; - struct scsi_task *task; - - - /* register our reservation key with the target */ - printf("Send PROUT/REGISTER_AND_IGNORE to register ... "); - memset(&poc, 0, sizeof (poc)); - poc.service_action_reservation_key = sark; - task = iscsi_persistent_reserve_out_sync(iscsi, lun, - SCSI_PERSISTENT_RESERVE_REGISTER_AND_IGNORE_EXISTING_KEY, - SCSI_PERSISTENT_RESERVE_SCOPE_LU, 0, &poc); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send PERSISTENT_RESERVE_OUT command: %s\n", - iscsi_get_error(iscsi)); - return -1; - } - 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("PERSISTENT_RESERVE_OUT Not Supported\n"); - scsi_free_scsi_task(task); - return -2; - } - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("PERSISTENT_RESERVE_OUT command: failed with sense. %s\n", - iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - printf("[OK]\n"); - - return 0; -} - - -int register_key(struct iscsi_context *iscsi, int lun, - unsigned long long sark, unsigned long long rk) -{ - struct scsi_persistent_reserve_out_basic poc; - struct scsi_task *task; - - - /* register our reservation key with the target */ - printf("Send PROUT/REGISTER to register ... "); - memset(&poc, 0, sizeof (poc)); - poc.service_action_reservation_key = sark; - poc.reservation_key = rk; - task = iscsi_persistent_reserve_out_sync(iscsi, lun, - SCSI_PERSISTENT_RESERVE_REGISTER, - SCSI_PERSISTENT_RESERVE_SCOPE_LU, 0, &poc); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send PERSISTENT_RESERVE_OUT command: %s\n", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("PERSISTENT_RESERVE_OUT command: failed with sense. %s\n", - iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - printf("[OK]\n"); - - return 0; -} - -static int verify_key_presence(struct iscsi_context *iscsi, int lun, - unsigned long long key, int present) -{ - struct scsi_task *task; - const int buf_sz = 16384; - int i; - int key_found; - struct scsi_persistent_reserve_in_read_keys *rk = NULL; - - - printf("Send PRIN/READ_KEYS to verify key %s ... ", - present ? "present" : "absent"); - task = iscsi_persistent_reserve_in_sync(iscsi, lun, - SCSI_PERSISTENT_RESERVE_READ_KEYS, buf_sz); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send PERSISTENT_RESERVE_IN command: %s\n", - iscsi_get_error(iscsi)); - return -1; - } - if (task->status != SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("PERSISTENT_RESERVE_IN command: failed with sense. %s\n", - iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - rk = scsi_datain_unmarshall(task); - if (rk == NULL) { - printf("failed to unmarshall PERSISTENT_RESERVE_IN/READ_KEYS data. %s\n", - iscsi_get_error(iscsi)); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - - key_found = 0; - for (i = 0; i < rk->num_keys; i++) { - if (rk->keys[i] == key) { - key_found = 1; - } - } - - if ((present && key_found) || - (!present && !key_found)) { - printf("[OK]\n"); - return 0; - } else { - printf("[FAILED]\n"); - if (present) { - printf("Key found when none expected\n"); - } else { - printf("Key not found when expected\n"); - } - return -1; - } -} - - -int reregister_fails(struct iscsi_context *iscsi, int lun, - unsigned long long sark) -{ - struct scsi_persistent_reserve_out_basic poc; - struct scsi_task *task; - - - printf("Send PROUT/REGISTER to ensure reregister fails ... "); - memset(&poc, 0, sizeof (poc)); - poc.service_action_reservation_key = sark; - task = iscsi_persistent_reserve_out_sync(iscsi, lun, - SCSI_PERSISTENT_RESERVE_REGISTER, - SCSI_PERSISTENT_RESERVE_SCOPE_LU, - SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE, - &poc); - if (task == NULL) { - printf("[FAILED]\n"); - printf("Failed to send PERSISTENT_RESERVE_OUT command: %s\n", - iscsi_get_error(iscsi)); - return -1; - } - - if (task->status != SCSI_STATUS_CHECK_CONDITION || - task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST || - task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { - printf("[FAILED]\n"); - printf("PRIN/REGISTER when already registered should fail\n"); - scsi_free_scsi_task(task); - return -1; - } - if (task->status == SCSI_STATUS_GOOD) { - printf("[FAILED]\n"); - printf("PROUT/REGISTER command: succeeded when it should not have!\n"); - scsi_free_scsi_task(task); - return -1; - } - - scsi_free_scsi_task(task); - printf("[OK]\n"); - - return 0; -} - int T1120_persistent_register_simple(const char *initiator, const char *url, - int data_loss _U_, int show_info) + int data_loss, int show_info) { struct iscsi_context *iscsi; int ret, lun; @@ -273,7 +73,7 @@ int T1120_persistent_register_simple(const char *initiator, const char *url, } /* try to reregister, which should fail */ - ret = reregister_fails(iscsi, lun, key+1); + ret = reregister_key_fails(iscsi, lun, key+1); if (ret != 0) { goto finished; } diff --git a/test-tool/1130_persistent_reserve_simple.c b/test-tool/1130_persistent_reserve_simple.c new file mode 100644 index 0000000..a2430f9 --- /dev/null +++ b/test-tool/1130_persistent_reserve_simple.c @@ -0,0 +1,122 @@ +/* + Copyright (C) 2013 by Lee Duncan + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#include +#include +#include + +#include "iscsi.h" +#include "scsi-lowlevel.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, + const char *url, int data_loss, int show_info) +{ + struct iscsi_context *iscsi; + int ret; + int lun; + const unsigned long long key = rand_key(); + struct resvn_test_info *rtip; + + + printf("1130_persistent_reserve_simple:\n"); + printf("=========================================\n"); + if (show_info) { + int idx = 1; + + printf("Test that we can using 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 = rti; rtip->resvn_str != NULL; rtip++) { + printf("%d, Can register %s\n", idx++, rtip->resvn_str); + printf("%d, Can read reservation\n", idx++); + printf("%d, Can release reservation\n", idx++); + } + printf("%d, Can unregister\n", idx++); + return 0; + } + + iscsi = iscsi_context_login(initiator, url, &lun); + if (iscsi == NULL) { + printf("Failed to login to target\n"); + return -1; + } + + if (!data_loss) { + printf("--dataloss flag is not set. Skipping test\n"); + ret = -2; + goto finished; + } + + ret = 0; + + /* register our reservation key with the target */ + ret = register_and_ignore(iscsi, lun, key); + if (ret != 0) + goto finished; + + /* test each reservatoin type */ + for (rtip = rti; rtip->resvn_str != NULL; rtip++) { + /* reserve the target */ + ret = reserve(iscsi, lun, key, rtip->resvn_type); + if (ret != 0) + goto finished; + /* verify target reservation */ + ret = verify_reserved_as(iscsi, lun, + pr_type_is_all_registrants(rtip->resvn_type) ? 0 : key, + rtip->resvn_type); + + /* release our reservation */ + ret = release(iscsi, lun, key, rtip->resvn_type); + if (ret != 0) + goto finished; + } + + /* remove our key from the target */ + ret = register_key(iscsi, lun, 0, key); + if (ret != 0) + goto finished; + +finished: + /* XXX should we clean up key if needed? */ + iscsi_logout_sync(iscsi); + iscsi_destroy_context(iscsi); + return ret; +} diff --git a/test-tool/iscsi-test.c b/test-tool/iscsi-test.c index fb50bdc..9efcbe9 100644 --- a/test-tool/iscsi-test.c +++ b/test-tool/iscsi-test.c @@ -257,6 +257,7 @@ struct scsi_test tests[] = { { "T1100_persistent_reserve_in_read_keys_simple", T1100_persistent_reserve_in_read_keys_simple }, { "T1110_persistent_reserve_in_serviceaction_range", T1110_persistent_reserve_in_serviceaction_range }, { "T1120_persistent_register_simple", T1120_persistent_register_simple }, +{ "T1130_persistent_reserve_simple", T1130_persistent_reserve_simple }, { NULL, NULL } }; @@ -388,6 +389,320 @@ int iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu) return real_iscsi_queue_pdu(iscsi, pdu); } +int register_and_ignore(struct iscsi_context *iscsi, int lun, + unsigned long long sark) +{ + struct scsi_persistent_reserve_out_basic poc; + struct scsi_task *task; + + + /* register our reservation key with the target */ + printf("Send PROUT/REGISTER_AND_IGNORE to register ... "); + memset(&poc, 0, sizeof (poc)); + poc.service_action_reservation_key = sark; + task = iscsi_persistent_reserve_out_sync(iscsi, lun, + SCSI_PERSISTENT_RESERVE_REGISTER_AND_IGNORE_EXISTING_KEY, + SCSI_PERSISTENT_RESERVE_SCOPE_LU, 0, &poc); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send PROUT command: %s\n", + iscsi_get_error(iscsi)); + return -1; + } + 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("PROUT Not Supported\n"); + scsi_free_scsi_task(task); + return -2; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("PROUT command: failed with sense. %s\n", + iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + + scsi_free_scsi_task(task); + printf("[OK]\n"); + + return 0; +} + + +int register_key(struct iscsi_context *iscsi, int lun, + unsigned long long sark, unsigned long long rk) +{ + struct scsi_persistent_reserve_out_basic poc; + struct scsi_task *task; + + + /* register our reservation key with the target */ + printf("Send PROUT/REGISTER to register ... "); + memset(&poc, 0, sizeof (poc)); + poc.service_action_reservation_key = sark; + poc.reservation_key = rk; + task = iscsi_persistent_reserve_out_sync(iscsi, lun, + SCSI_PERSISTENT_RESERVE_REGISTER, + SCSI_PERSISTENT_RESERVE_SCOPE_LU, 0, &poc); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send PROUT command: %s\n", + iscsi_get_error(iscsi)); + return -1; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("PROUT command: failed with sense. %s\n", + iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + + scsi_free_scsi_task(task); + printf("[OK]\n"); + + return 0; +} + + +int verify_key_presence(struct iscsi_context *iscsi, int lun, + unsigned long long key, int present) +{ + struct scsi_task *task; + const int buf_sz = 16384; + int i; + int key_found; + struct scsi_persistent_reserve_in_read_keys *rk = NULL; + + + printf("Send PRIN/READ_KEYS to verify key %s ... ", + present ? "present" : "absent"); + task = iscsi_persistent_reserve_in_sync(iscsi, lun, + SCSI_PERSISTENT_RESERVE_READ_KEYS, buf_sz); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send PRIN command: %s\n", + iscsi_get_error(iscsi)); + return -1; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("PRIN command: failed with sense. %s\n", + iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + rk = scsi_datain_unmarshall(task); + if (rk == NULL) { + printf("failed to unmarshall PRIN/READ_KEYS data. %s\n", + iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + + scsi_free_scsi_task(task); + + key_found = 0; + for (i = 0; i < rk->num_keys; i++) { + if (rk->keys[i] == key) + key_found = 1; + } + + if ((present && key_found) || + (!present && !key_found)) { + printf("[OK]\n"); + return 0; + } else { + printf("[FAILED]\n"); + if (present) + printf("Key found when none expected\n"); + else + printf("Key not found when expected\n"); + return -1; + } +} + + +int reregister_key_fails(struct iscsi_context *iscsi, int lun, + unsigned long long sark) +{ + struct scsi_persistent_reserve_out_basic poc; + struct scsi_task *task; + + + printf("Send PROUT/REGISTER to ensure reregister fails ... "); + memset(&poc, 0, sizeof (poc)); + poc.service_action_reservation_key = sark; + task = iscsi_persistent_reserve_out_sync(iscsi, lun, + SCSI_PERSISTENT_RESERVE_REGISTER, + SCSI_PERSISTENT_RESERVE_SCOPE_LU, + SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE, + &poc); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send PROUT command: %s\n", + iscsi_get_error(iscsi)); + return -1; + } + + if (task->status != SCSI_STATUS_CHECK_CONDITION || + task->sense.key != SCSI_SENSE_ILLEGAL_REQUEST || + task->sense.ascq != SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { + printf("[FAILED]\n"); + printf("PROUT/REGISTER when already registered should fail\n"); + scsi_free_scsi_task(task); + return -1; + } + if (task->status == SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("PROUT/REGISTER command: succeeded when it should not have!\n"); + scsi_free_scsi_task(task); + return -1; + } + + scsi_free_scsi_task(task); + printf("[OK]\n"); + + return 0; +} + + +int reserve(struct iscsi_context *iscsi, int lun, + unsigned long long key, enum scsi_persistent_out_type pr_type) +{ + struct scsi_persistent_reserve_out_basic poc; + struct scsi_task *task; + + + /* reserve the target using specified reservation type */ + printf("Send PROUT/RESERVE to reserve, type=%d ... ", 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, + pr_type, &poc); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send PROUT command: %s\n", + iscsi_get_error(iscsi)); + return -1; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("PROUT command: failed with sense. %s\n", + iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + + scsi_free_scsi_task(task); + printf("[OK]\n"); + + return 0; +} + + +int release(struct iscsi_context *iscsi, int lun, + unsigned long long key, enum scsi_persistent_out_type pr_type) +{ + struct scsi_persistent_reserve_out_basic poc; + struct scsi_task *task; + + + /* release the target using specified reservation type */ + printf("Send PROUT/RELEASE to release reservation, type=%d ... ", + 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, + pr_type, &poc); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send PROUT command: %s\n", + iscsi_get_error(iscsi)); + return -1; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("PROUT command: failed with sense. %s\n", + iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + + scsi_free_scsi_task(task); + printf("[OK]\n"); + + return 0; +} + +int verify_reserved_as(struct iscsi_context *iscsi, int lun, + unsigned long long key, enum scsi_persistent_out_type pr_type) +{ + struct scsi_task *task; + const int buf_sz = 16384; + struct scsi_persistent_reserve_in_read_reservation *rr = NULL; + + + printf("Send PRIN/READ_RESERVATION to verify type=%d ... ", + pr_type); + task = iscsi_persistent_reserve_in_sync(iscsi, lun, + SCSI_PERSISTENT_RESERVE_READ_RESERVATION, buf_sz); + if (task == NULL) { + printf("[FAILED]\n"); + printf("Failed to send PRIN command: %s\n", + iscsi_get_error(iscsi)); + return -1; + } + if (task->status != SCSI_STATUS_GOOD) { + printf("[FAILED]\n"); + printf("PRIN command: failed with sense. %s\n", + iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + rr = scsi_datain_unmarshall(task); + if (rr == NULL) { + printf("failed to unmarshall PRIN/READ_RESERVATION data. %s\n", + iscsi_get_error(iscsi)); + scsi_free_scsi_task(task); + return -1; + } + + scsi_free_scsi_task(task); + + /* + * XXX check reservation (in rr) ... + */ + + if (!rr->reserved) { + printf("Failed to find Target reserved as expected.\n"); + return -1; + } + if (rr->reservation_key != key) { + printf("Failed to find reservation key 0x%llx: found 0x%lx.\n", + key, rr->reservation_key); + return -1; + } + if (rr->pr_type != pr_type) { + printf("Failed to find reservation type %d: found %d.\n", + pr_type, rr->pr_type); + return -1; + } + + printf("[OK]\n"); + return 0; +} + + int main(int argc, const char *argv[]) { poptContext pc; diff --git a/test-tool/iscsi-test.h b/test-tool/iscsi-test.h index c7d4837..f9d42a6 100644 --- a/test-tool/iscsi-test.h +++ b/test-tool/iscsi-test.h @@ -17,6 +17,14 @@ along with this program; if not, see . */ +#ifndef _ISCSI_TEST_H_ +#define _ISCSI_TEST_H_ + +#include +#include +#include +#include + extern const char *initiatorname1; extern const char *initiatorname2; @@ -188,3 +196,54 @@ int T1042_unsolicited_nonimmediate_data(const char *initiator, const char *url, int T1100_persistent_reserve_in_read_keys_simple(const char *initiator, const char *url, int data_loss, int show_info); int T1110_persistent_reserve_in_serviceaction_range(const char *initiator, const char *url, int data_loss, int show_info); int T1120_persistent_register_simple(const char *initiator, const char *url, int data_loss, int show_info); +int T1130_persistent_reserve_simple(const char *initiator, const char *url, + int data_loss, int show_info); + + +/* + * PGR support + */ + +static inline long rand_key(void) +{ + time_t t; + pid_t p; + unsigned int s; + long l; + + (void)time(&t); + p = getpid(); + s = ((int)p * (t & 0xffff)); + srandom(s); + l = random(); + return l; +} + +static inline int pr_type_is_all_registrants( + enum scsi_persistent_out_type pr_type) +{ + switch (pr_type) { + case SCSI_PERSISTENT_RESERVE_TYPE_WRITE_EXCLUSIVE_ALL_REGISTRANTS: + case SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS_ALL_REGISTRANTS: + return 1; + default: + return 0; + } +} + +int register_and_ignore(struct iscsi_context *iscsi, int lun, + unsigned long long key); +int register_key(struct iscsi_context *iscsi, int lun, + unsigned long long sark, unsigned long long rk); +int verify_key_presence(struct iscsi_context *iscsi, int lun, + unsigned long long key, int present); +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, enum scsi_persistent_out_type pr_type); +int release(struct iscsi_context *iscsi, int lun, + 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, enum scsi_persistent_out_type pr_type); + +#endif /* _ISCSI_TEST_H_ */