Files
libiscsi/test-tool/1130_persistent_reserve_simple.c
Lee Duncan 474cec5556 Added new 1130* test file for PGR simple reserve testing.
Added infrastructure to support reading, setting, and
clearing reservations.
2012-12-22 13:50:55 -08:00

123 lines
3.4 KiB
C

/*
Copyright (C) 2013 by Lee Duncan <leeman.duncan@gmail.com>
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 <string.h>
#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;
}