- Made PGR test more verbose (naming initiator).
- Added test for Exclusive Access PGR reservation access testing.
This commit is contained in:
@@ -154,7 +154,8 @@ bin_iscsi_test_SOURCES = test-tool/iscsi-test.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/1130_persistent_reserve_simple.c
|
||||
test-tool/1130_persistent_reserve_simple.c \
|
||||
test-tool/1140_persistent_reserve_access_check_ea.c
|
||||
|
||||
endif
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include "iscsi-test.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,
|
||||
@@ -34,6 +37,7 @@ static enum scsi_persistent_out_type pr_types_to_test[] = {
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
int T1130_persistent_reserve_simple(const char *initiator,
|
||||
const char *url, int data_loss, int show_info)
|
||||
{
|
||||
@@ -54,7 +58,7 @@ int T1130_persistent_reserve_simple(const char *initiator,
|
||||
printf(" and that we can release each type, as well\n");
|
||||
printf("%d, We can register a key\n", idx++);
|
||||
for (i = 0; pr_types_to_test[i] != 0; i++) {
|
||||
printf("%d, Can register %s\n", idx++,
|
||||
printf("%d, Can reserve %s\n", idx++,
|
||||
scsi_pr_type_str(pr_types_to_test[i]));
|
||||
printf("%d, Can read reservation\n", idx++);
|
||||
printf("%d, Can release reservation\n", idx++);
|
||||
|
||||
164
test-tool/1140_persistent_reserve_access_check_ea.c
Normal file
164
test-tool/1140_persistent_reserve_access_check_ea.c
Normal file
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
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"
|
||||
|
||||
|
||||
int T1140_persistent_reserve_access_check_ea(const char *initiator,
|
||||
const char *url, int data_loss, int show_info)
|
||||
{
|
||||
struct iscsi_context *iscsi = NULL, *iscsi2 = NULL;
|
||||
int ret;
|
||||
int lun, lun2;
|
||||
const unsigned long long key = rand_key();
|
||||
const unsigned long long key2 = rand_key();
|
||||
const enum scsi_persistent_out_type pr_type =
|
||||
SCSI_PERSISTENT_RESERVE_TYPE_EXCLUSIVE_ACCESS;
|
||||
const char *pr_type_str = scsi_pr_type_str(pr_type);
|
||||
unsigned char *buf = NULL;
|
||||
|
||||
|
||||
printf("1140_persistent_reserve_access_check_ea:\n");
|
||||
printf("=========================================\n");
|
||||
if (show_info) {
|
||||
int idx = 1;
|
||||
|
||||
printf("Test that access constrols are correct for %s Persistent Reservations\n",
|
||||
pr_type_str);
|
||||
printf("%d, %s Reservation Holder Read Access\n",
|
||||
idx++, pr_type_str);
|
||||
printf("%d, %s Reservation Holder Write Access\n",
|
||||
idx++, pr_type_str);
|
||||
printf("%d, non-%s Reservation Holder does not have read access\n",
|
||||
idx++, pr_type_str);
|
||||
printf("%d, non-%s Reservation Holder does not have write access\n",
|
||||
idx++, pr_type_str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
iscsi = iscsi_context_login(initiator, url, &lun);
|
||||
if (iscsi == NULL) {
|
||||
printf("Failed to login to target\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
iscsi2 = iscsi_context_login(initiatorname2, url, &lun2);
|
||||
if (iscsi2 == NULL) {
|
||||
printf("Failed to login to target (2nd initiator)\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set. Skipping test\n");
|
||||
ret = -2;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* register our reservation key with the target */
|
||||
ret = register_and_ignore(iscsi, lun, key);
|
||||
if (ret != 0)
|
||||
goto finished;
|
||||
ret = register_and_ignore(iscsi2, lun2, key2);
|
||||
if (ret != 0)
|
||||
goto finished;
|
||||
|
||||
/* reserve the target through initiator 1 */
|
||||
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(pr_type) ? 0 : key,
|
||||
pr_type);
|
||||
if (ret != 0)
|
||||
goto finished;
|
||||
|
||||
buf = malloc(512); /* allocate a buffer */
|
||||
if (buf == NULL) {
|
||||
printf("failed to allocate 512 byes of memory\n");
|
||||
ret = -1;
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* make sure init1 can read */
|
||||
ret = verify_read_works(iscsi, lun, buf);
|
||||
if (ret != 0)
|
||||
goto finished;
|
||||
|
||||
/* make sure init1 can write */
|
||||
ret = verify_write_works(iscsi, lun, buf);
|
||||
if (ret != 0)
|
||||
goto finished;
|
||||
|
||||
/* make sure init2 does not have read access */
|
||||
ret = verify_read_fails(iscsi2, lun2, buf);
|
||||
if (ret != 0)
|
||||
goto finished;
|
||||
|
||||
/* make sure init2 does not have write access */
|
||||
ret = verify_write_fails(iscsi2, lun2, buf);
|
||||
if (ret != 0)
|
||||
goto finished;
|
||||
|
||||
/* unregister init2 */
|
||||
ret = register_key(iscsi2, lun2, 0, key);
|
||||
if (ret != 0) {
|
||||
goto finished;
|
||||
}
|
||||
|
||||
/* make sure init2 does not have read access */
|
||||
ret = verify_read_fails(iscsi2, lun2, buf);
|
||||
if (ret != 0)
|
||||
goto finished;
|
||||
|
||||
/* make sure init2 does not have write access */
|
||||
ret = verify_write_fails(iscsi2, lun2, buf);
|
||||
if (ret != 0)
|
||||
goto finished;
|
||||
|
||||
/* release our reservation */
|
||||
ret = release(iscsi, lun, key, pr_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? */
|
||||
if (iscsi) {
|
||||
iscsi_logout_sync(iscsi);
|
||||
iscsi_destroy_context(iscsi);
|
||||
}
|
||||
if (iscsi2) {
|
||||
iscsi_logout_sync(iscsi2);
|
||||
iscsi_destroy_context(iscsi2);
|
||||
}
|
||||
if (buf)
|
||||
free(buf);
|
||||
return ret;
|
||||
}
|
||||
@@ -254,11 +254,12 @@ struct scsi_test tests[] = {
|
||||
{ "T1041_unsolicited_immediate_data", T1041_unsolicited_immediate_data },
|
||||
{ "T1042_unsolicited_nonimmediate_data",T1042_unsolicited_nonimmediate_data },
|
||||
|
||||
/* PERSISTENT_RESERVE_IN */
|
||||
/* PERSISTENT_RESERVE_IN/PERSISTENT_RESERVE_OUT */
|
||||
{ "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 },
|
||||
{ "T1140_persistent_reserve_access_check_ea", T1140_persistent_reserve_access_check_ea },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
@@ -399,7 +400,8 @@ int register_and_ignore(struct iscsi_context *iscsi, int lun,
|
||||
|
||||
|
||||
/* register our reservation key with the target */
|
||||
printf("Send PROUT/REGISTER_AND_IGNORE to register ... ");
|
||||
printf("Send PROUT/REGISTER_AND_IGNORE to register init=%s ... ",
|
||||
iscsi->initiator_name);
|
||||
memset(&poc, 0, sizeof (poc));
|
||||
poc.service_action_reservation_key = sark;
|
||||
task = iscsi_persistent_reserve_out_sync(iscsi, lun,
|
||||
@@ -442,8 +444,9 @@ int register_key(struct iscsi_context *iscsi, int lun,
|
||||
|
||||
|
||||
/* register our reservation key with the target */
|
||||
printf("Send PROUT/REGISTER to %s ... ",
|
||||
sark != 0 ? "register" : "unregister");
|
||||
printf("Send PROUT/REGISTER to %s init=%s... ",
|
||||
sark != 0 ? "register" : "unregister",
|
||||
iscsi->initiator_name);
|
||||
memset(&poc, 0, sizeof (poc));
|
||||
poc.service_action_reservation_key = sark;
|
||||
poc.reservation_key = rk;
|
||||
@@ -481,8 +484,9 @@ int verify_key_presence(struct iscsi_context *iscsi, int lun,
|
||||
struct scsi_persistent_reserve_in_read_keys *rk = NULL;
|
||||
|
||||
|
||||
printf("Send PRIN/READ_KEYS to verify key %s ... ",
|
||||
present ? "present" : "absent");
|
||||
printf("Send PRIN/READ_KEYS to verify key %s init=%s... ",
|
||||
present ? "present" : "absent",
|
||||
iscsi->initiator_name);
|
||||
task = iscsi_persistent_reserve_in_sync(iscsi, lun,
|
||||
SCSI_PERSISTENT_RESERVE_READ_KEYS, buf_sz);
|
||||
if (task == NULL) {
|
||||
@@ -536,7 +540,8 @@ int reregister_key_fails(struct iscsi_context *iscsi, int lun,
|
||||
struct scsi_task *task;
|
||||
|
||||
|
||||
printf("Send PROUT/REGISTER to ensure reregister fails ... ");
|
||||
printf("Send PROUT/REGISTER to ensure reregister fails init=%s... ",
|
||||
iscsi->initiator_name);
|
||||
memset(&poc, 0, sizeof (poc));
|
||||
poc.service_action_reservation_key = sark;
|
||||
task = iscsi_persistent_reserve_out_sync(iscsi, lun,
|
||||
@@ -581,8 +586,9 @@ int reserve(struct iscsi_context *iscsi, int lun,
|
||||
|
||||
|
||||
/* reserve the target using specified reservation type */
|
||||
printf("Send PROUT/RESERVE to reserve, type=%d (%s) ... ",
|
||||
pr_type, scsi_pr_type_str(pr_type));
|
||||
printf("Send PROUT/RESERVE to reserve, type=%d (%s) init=%s ... ",
|
||||
pr_type, scsi_pr_type_str(pr_type),
|
||||
iscsi->initiator_name);
|
||||
|
||||
memset(&poc, 0, sizeof (poc));
|
||||
poc.reservation_key = key;
|
||||
@@ -619,8 +625,8 @@ int release(struct iscsi_context *iscsi, int lun,
|
||||
|
||||
|
||||
/* release the target using specified reservation type */
|
||||
printf("Send PROUT/RELEASE to release reservation, type=%d ... ",
|
||||
pr_type);
|
||||
printf("Send PROUT/RELEASE to release reservation, type=%d init=%s ... ",
|
||||
pr_type, iscsi->initiator_name);
|
||||
|
||||
memset(&poc, 0, sizeof (poc));
|
||||
poc.reservation_key = key;
|
||||
@@ -656,8 +662,8 @@ int verify_reserved_as(struct iscsi_context *iscsi, int lun,
|
||||
struct scsi_persistent_reserve_in_read_reservation *rr = NULL;
|
||||
|
||||
|
||||
printf("Send PRIN/READ_RESERVATION to verify type=%d ... ",
|
||||
pr_type);
|
||||
printf("Send PRIN/READ_RESERVATION to verify type=%d init=%s... ",
|
||||
pr_type, iscsi->initiator_name);
|
||||
task = iscsi_persistent_reserve_in_sync(iscsi, lun,
|
||||
SCSI_PERSISTENT_RESERVE_READ_RESERVATION, buf_sz);
|
||||
if (task == NULL) {
|
||||
@@ -685,15 +691,18 @@ int verify_reserved_as(struct iscsi_context *iscsi, int lun,
|
||||
|
||||
|
||||
if (!rr->reserved) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to find Target reserved as expected.\n");
|
||||
return -1;
|
||||
}
|
||||
if (rr->reservation_key != key) {
|
||||
printf("[FAILED]\n");
|
||||
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]\n");
|
||||
printf("Failed to find reservation type %d: found %d.\n",
|
||||
pr_type, rr->pr_type);
|
||||
return -1;
|
||||
@@ -703,6 +712,154 @@ int verify_reserved_as(struct iscsi_context *iscsi, int lun,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int verify_read_works(struct iscsi_context *iscsi, int lun, unsigned char *buf)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
const uint32_t lba = 1;
|
||||
const int blksize = 512;
|
||||
const uint32_t datalen = 1 * blksize;
|
||||
|
||||
/*
|
||||
* try to read the second 512-byte block
|
||||
*/
|
||||
|
||||
printf("Send READ10 to verify READ works init=%s ... ",
|
||||
iscsi->initiator_name);
|
||||
|
||||
task = iscsi_read10_sync(iscsi, lun, lba, datalen, blksize, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n",
|
||||
iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command: failed with sense: %s\n",
|
||||
iscsi_get_error(iscsi));
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
memcpy(buf, task->datain.data, task->datain.size);
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
printf("[OK]\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int verify_write_works(struct iscsi_context *iscsi, int lun, unsigned char *buf)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
const uint32_t lba = 1;
|
||||
const int blksize = 512;
|
||||
const uint32_t datalen = 1 * blksize;
|
||||
|
||||
/*
|
||||
* try to write the second 512-byte block
|
||||
*/
|
||||
|
||||
printf("Send WRITE10 to verify WRITE works init=%s ... ",
|
||||
iscsi->initiator_name);
|
||||
|
||||
task = iscsi_write10_sync(iscsi, lun, lba, buf, datalen, blksize, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE10 command: %s\n",
|
||||
iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE10 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_read_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
const uint32_t lba = 1;
|
||||
const int blksize = 512;
|
||||
const uint32_t datalen = 1 * blksize;
|
||||
|
||||
/*
|
||||
* try to read the second 512-byte block -- should fail
|
||||
*/
|
||||
|
||||
printf("Send READ10 to verify READ does not work init=%s ... ",
|
||||
iscsi->initiator_name);
|
||||
|
||||
task = iscsi_read10_sync(iscsi, lun, lba, datalen, blksize, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send READ10 command: %s\n",
|
||||
iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
memcpy(buf, task->datain.data, task->datain.size);
|
||||
printf("[FAILED]\n");
|
||||
printf("READ10 command succeeded when expected to fail\n");
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX should we verify sense data?
|
||||
*/
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
printf("[OK]\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int verify_write_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
const uint32_t lba = 1;
|
||||
const int blksize = 512;
|
||||
const uint32_t datalen = 1 * blksize;
|
||||
|
||||
/*
|
||||
* try to write the second 512-byte block
|
||||
*/
|
||||
|
||||
printf("Send WRITE10 to verify WRITE does not work init=%s ... ",
|
||||
iscsi->initiator_name);
|
||||
|
||||
task = iscsi_write10_sync(iscsi, lun, lba, buf, datalen, blksize, 0, 0, 0, 0, 0);
|
||||
if (task == NULL) {
|
||||
printf("[FAILED]\n");
|
||||
printf("Failed to send WRITE10 command: %s\n",
|
||||
iscsi_get_error(iscsi));
|
||||
return -1;
|
||||
}
|
||||
if (task->status == SCSI_STATUS_GOOD) {
|
||||
printf("[FAILED]\n");
|
||||
printf("WRITE10 command: succeeded when exptec to fail\n");
|
||||
scsi_free_scsi_task(task);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX should we verify sense data?
|
||||
*/
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
|
||||
printf("[OK]\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int testunitready(struct iscsi_context *iscsi, int lun)
|
||||
{
|
||||
struct scsi_task *task;
|
||||
|
||||
@@ -198,6 +198,8 @@ int T1110_persistent_reserve_in_serviceaction_range(const char *initiator, const
|
||||
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);
|
||||
int T1140_persistent_reserve_access_check_ea(const char *initiator,
|
||||
const char *url, int data_loss, int show_info);
|
||||
|
||||
|
||||
/*
|
||||
@@ -245,6 +247,10 @@ 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);
|
||||
int verify_read_works(struct iscsi_context *iscsi, int lun, unsigned char *buf);
|
||||
int verify_write_works(struct iscsi_context *iscsi, int lun, unsigned char *buf);
|
||||
int verify_read_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf);
|
||||
int verify_write_fails(struct iscsi_context *iscsi, int lun, unsigned char *buf);
|
||||
int testunitready(struct iscsi_context *iscsi, int lun);
|
||||
int testunitready_nomedium(struct iscsi_context *iscsi, int lun);
|
||||
int testunitready_conflict(struct iscsi_context *iscsi, int lun);
|
||||
|
||||
Reference in New Issue
Block a user