From a90e5a3d4cef44db92760f4d5eff0ccb8a24b561 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Fri, 18 Sep 2015 17:58:42 +0200 Subject: [PATCH] test/iscsi-support: PR Out CLEAR helper function Add a helper function to dispatch Persistent Reserve Out requests with CLEAR service action. Signed-off-by: David Disseldorp --- test-tool/iscsi-support.c | 49 +++++++++++++++++++++++++++++++++++++++ test-tool/iscsi-support.h | 1 + 2 files changed, 50 insertions(+) diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index 42e0e18..ce11612 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -973,6 +973,55 @@ prout_release(struct scsi_device *sdev, return ret; } +int +prout_clear(struct scsi_device *sdev, unsigned long long key) +{ + 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/CLEAR to clear all registrations and any PR " + "reservation"); + + if (!data_loss) { + printf("--dataloss flag is not set in. Skipping PROUT\n"); + return -1; + } + + memset(&poc, 0, sizeof (poc)); + poc.reservation_key = key; + task = scsi_cdb_persistent_reserve_out( + SCSI_PERSISTENT_RESERVE_CLEAR, + SCSI_PERSISTENT_RESERVE_SCOPE_LU, + 0, &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) diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 1e55d70..4c43b14 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -273,6 +273,7 @@ int prout_reserve(struct scsi_device *sdev, unsigned long long key, enum scsi_persistent_out_type pr_type); 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 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);