From 39fcda0571c0ce3d5a45dcec6eee0c216c847ba3 Mon Sep 17 00:00:00 2001
From: David Disseldorp <ddiss@suse.de>
Date: Thu, 27 Aug 2015 11:12:39 +0200
Subject: [PATCH] target/pr: split out and export
core_scsi3_pr_seq_non_holder()
Patch-mainline: Not yet, SES2 clustered LIO/RBD
References: fate#318836
Move reservation backend specific code out into
target_scsi3_pr_reservation_check(), leaving only logic to determine
whether reservation conflict should be returned given PR/cdb
conditionals.
XXX: target_core_pr.h should be split out into library header?
Signed-off-by: David Disseldorp <ddiss@suse.de>
---
drivers/target/target_core_pr.c | 43 ++++++++++++++++++++--------------------
drivers/target/target_core_pr.h | 1
2 files changed, 23 insertions(+), 21 deletions(-)
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -314,32 +314,17 @@ out:
* This function is called by those initiator ports who are *NOT*
* the active PR reservation holder when a reservation is present.
*/
-static int core_scsi3_pr_seq_non_holder(struct se_cmd *cmd, u32 pr_reg_type,
- bool isid_mismatch)
+int core_scsi3_pr_seq_non_holder(struct se_cmd *cmd, u32 pr_reg_type,
+ char *dbg_nexus, bool registered_nexus)
{
unsigned char *cdb = cmd->t_task_cdb;
- struct se_session *se_sess = cmd->se_sess;
- struct se_node_acl *nacl = se_sess->se_node_acl;
int other_cdb = 0;
- int registered_nexus = 0, ret = 1; /* Conflict by default */
+ int ret = 1; /* Conflict by default */
int all_reg = 0, reg_only = 0; /* ALL_REG, REG_ONLY */
int we = 0; /* Write Exclusive */
int legacy = 0; /* Act like a legacy device and return
* RESERVATION CONFLICT on some CDBs */
- if (isid_mismatch) {
- registered_nexus = 0;
- } else {
- struct se_dev_entry *se_deve;
-
- rcu_read_lock();
- se_deve = target_nacl_find_deve(nacl, cmd->orig_fe_lun);
- if (se_deve)
- registered_nexus = test_bit(DEF_PR_REG_ACTIVE,
- &se_deve->deve_flags);
- rcu_read_unlock();
- }
-
switch (pr_reg_type) {
case PR_TYPE_WRITE_EXCLUSIVE:
we = 1;
@@ -505,7 +490,7 @@ static int core_scsi3_pr_seq_non_holder(
pr_debug("%s Conflict for unregistered nexus"
" %s CDB: 0x%02x to %s reservation\n",
transport_dump_cmd_direction(cmd),
- se_sess->se_node_acl->initiatorname, cdb[0],
+ dbg_nexus, cdb[0],
core_scsi3_pr_dump_type(pr_reg_type));
return 1;
} else {
@@ -557,11 +542,12 @@ static int core_scsi3_pr_seq_non_holder(
pr_debug("%s Conflict for %sregistered nexus %s CDB: 0x%2x"
" for %s reservation\n", transport_dump_cmd_direction(cmd),
(registered_nexus) ? "" : "un",
- se_sess->se_node_acl->initiatorname, cdb[0],
+ dbg_nexus, cdb[0],
core_scsi3_pr_dump_type(pr_reg_type));
return 1; /* Conflict by default */
}
+EXPORT_SYMBOL(core_scsi3_pr_seq_non_holder);
static sense_reason_t
target_scsi3_pr_reservation_check(struct se_cmd *cmd)
@@ -570,6 +556,7 @@ target_scsi3_pr_reservation_check(struct
struct se_session *sess = cmd->se_sess;
u32 pr_reg_type;
bool isid_mismatch = false;
+ bool registered_nexus = false;
if (!dev->dev_pr_res_holder)
return 0;
@@ -590,7 +577,21 @@ target_scsi3_pr_reservation_check(struct
return 0;
check_nonholder:
- if (core_scsi3_pr_seq_non_holder(cmd, pr_reg_type, isid_mismatch))
+ if (!isid_mismatch) {
+ struct se_node_acl *nacl = sess->se_node_acl;
+ struct se_dev_entry *se_deve;
+
+ rcu_read_lock();
+ se_deve = target_nacl_find_deve(nacl, cmd->orig_fe_lun);
+ if (se_deve)
+ registered_nexus = test_bit(DEF_PR_REG_ACTIVE,
+ &se_deve->deve_flags);
+ rcu_read_unlock();
+ }
+
+ if (core_scsi3_pr_seq_non_holder(cmd, pr_reg_type,
+ sess->se_node_acl->initiatorname,
+ registered_nexus));
return TCM_RESERVATION_CONFLICT;
return 0;
}
--- a/drivers/target/target_core_pr.h
+++ b/drivers/target/target_core_pr.h
@@ -70,6 +70,7 @@ extern void core_scsi3_free_pr_reg_from_
struct se_node_acl *);
extern void core_scsi3_free_all_registrations(struct se_device *);
extern unsigned char *core_scsi3_pr_dump_type(int);
+extern int core_scsi3_pr_seq_non_holder(struct se_cmd *, u32, char *, bool);
extern sense_reason_t target_scsi3_emulate_pr_in(struct se_cmd *);
extern sense_reason_t target_scsi3_emulate_pr_out(struct se_cmd *);