Added new 1130* test file for PGR simple reserve testing.
Added infrastructure to support reading, setting, and clearing reservations.
This commit is contained in:
@@ -18,215 +18,15 @@
|
||||
#include <stdio.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user