1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
/*
Copyright (C) 2013 by Lee Duncan <lee@gonzoleeman.net>
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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <arpa/inet.h>
#include <CUnit/CUnit.h>
#include "iscsi.h"
#include "scsi-lowlevel.h"
#include "iscsi-support.h"
#include "iscsi-test-cu.h"
/*
* list of persistent reservation types to test, in order
*/
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
};
void
test_prout_reserve_simple(void)
{
int ret = 0;
int i;
const unsigned long long key = rand_key();
logging(LOG_VERBOSE, LOG_BLANK_LINE);
logging(LOG_VERBOSE, "Test Persistent Reserve IN RESERVE works.");
/* register our reservation key with the target */
ret = prout_register_and_ignore(iscsic, tgt_lun, key);
if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] PERSISTEN RESERVE OUT is not implemented.");
CU_PASS("PERSISTENT RESERVE OUT is not implemented.");
return;
}
CU_ASSERT_EQUAL(ret, 0);
/* test each reservatoin type */
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 = prout_reserve(iscsic, tgt_lun, key, pr_type);
CU_ASSERT_EQUAL(ret, 0);
/* verify target reservation */
ret = prin_verify_reserved_as(iscsic, tgt_lun,
pr_type_is_all_registrants(pr_type) ? 0 : key,
pr_type);
CU_ASSERT_EQUAL(ret, 0);
/* release our reservation */
ret = prout_release(iscsic, tgt_lun, key, pr_type);
CU_ASSERT_EQUAL(ret, 0);
}
/* remove our key from the target */
ret = prout_register_key(iscsic, tgt_lun, 0, key);
CU_ASSERT_EQUAL(ret, 0);
}
|