test: add prout_preempt() helper function
Issue a Persistent Reservation Out PREEMPT request, with keys and type provided. PREEMPT allows for the removal of registrations, and replacement of reservations. Signed-off-by: David Disseldorp <ddiss@suse.de>
This commit is contained in:
@@ -1022,6 +1022,58 @@ prout_clear(struct scsi_device *sdev, unsigned long long key)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
prout_preempt(struct scsi_device *sdev,
|
||||
unsigned long long sark, unsigned long long rk,
|
||||
enum scsi_persistent_out_type pr_type)
|
||||
{
|
||||
struct scsi_persistent_reserve_out_basic poc;
|
||||
struct scsi_task *task;
|
||||
int ret = 0;
|
||||
|
||||
/* reserve the target using specified reservation type */
|
||||
logging(LOG_VERBOSE,
|
||||
"Send PROUT/PREEMPT to preempt reservation and/or "
|
||||
"registration");
|
||||
|
||||
if (!data_loss) {
|
||||
printf("--dataloss flag is not set in. Skipping PROUT\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&poc, 0, sizeof (poc));
|
||||
poc.reservation_key = rk;
|
||||
poc.service_action_reservation_key = sark;
|
||||
task = scsi_cdb_persistent_reserve_out(
|
||||
SCSI_PERSISTENT_RESERVE_PREEMPT,
|
||||
SCSI_PERSISTENT_RESERVE_SCOPE_LU,
|
||||
pr_type, &poc);
|
||||
assert(task != NULL);
|
||||
|
||||
task = send_scsi_command(sdev, task, NULL);
|
||||
if (task == NULL) {
|
||||
logging(LOG_NORMAL,
|
||||
"[FAILED] Failed to send PROUT command: %s",
|
||||
iscsi_get_error(sdev->iscsi_ctx));
|
||||
return -1;
|
||||
}
|
||||
if (status_is_invalid_opcode(task)) {
|
||||
scsi_free_scsi_task(task);
|
||||
logging(LOG_NORMAL, "[SKIPPED] PERSISTENT RESERVE OUT is not implemented.");
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (task->status != SCSI_STATUS_GOOD) {
|
||||
logging(LOG_NORMAL,
|
||||
"[FAILED] PROUT command: failed with sense. %s",
|
||||
iscsi_get_error(sdev->iscsi_ctx));
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(task);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
prin_verify_reserved_as(struct scsi_device *sdev,
|
||||
unsigned long long key, enum scsi_persistent_out_type pr_type)
|
||||
|
||||
@@ -274,6 +274,9 @@ int prout_reserve(struct scsi_device *sdev,
|
||||
int prout_release(struct scsi_device *sdev,
|
||||
unsigned long long key, enum scsi_persistent_out_type pr_type);
|
||||
int prout_clear(struct scsi_device *sdev, unsigned long long key);
|
||||
int prout_preempt(struct scsi_device *sdev,
|
||||
unsigned long long sark, unsigned long long rk,
|
||||
enum scsi_persistent_out_type pr_type);
|
||||
int prin_verify_not_reserved(struct scsi_device *sdev);
|
||||
int prin_verify_reserved_as(struct scsi_device *sdev,
|
||||
unsigned long long key, enum scsi_persistent_out_type pr_type);
|
||||
|
||||
Reference in New Issue
Block a user