[RFC PATCH 28/48] target: core: add function to compare TransportID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Dmitry Bogdanov <d.bogdanov@xxxxxxxxx>
---
 drivers/target/target_core_fabric_lib.c | 27 +++++++++++++++++++++----
 drivers/target/target_core_internal.h   |  2 ++
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/drivers/target/target_core_fabric_lib.c b/drivers/target/target_core_fabric_lib.c
index 34fdab558e24..0eb03d7b9e78 100644
--- a/drivers/target/target_core_fabric_lib.c
+++ b/drivers/target/target_core_fabric_lib.c
@@ -350,22 +350,27 @@ u32 iscsi_parse_pr_out_transport_id(
 	return out_tid_len;
 }
 
-int target_get_pr_transport_id_len(struct t10_pr_registration *pr_reg)
+static int __target_get_pr_transport_id_len(const char *tid)
 {
-	switch (pr_reg->pr_tid[0] & 0xF) {
+	switch (tid[0] & 0xF) {
 	case SCSI_PROTOCOL_FCP:
 	case SCSI_PROTOCOL_SBP:
 	case SCSI_PROTOCOL_SRP:
 	case SCSI_PROTOCOL_SAS:
 		return 24;
 	case SCSI_PROTOCOL_ISCSI:
-		return get_unaligned_be16(&pr_reg->pr_tid[2]) + 4;
+		return get_unaligned_be16(&tid[2]) + 4;
 	default:
-		WARN(1, "Unknown proto_id: %#x\n", pr_reg->pr_tid[0] & 0xF);
+		WARN(1, "Unknown proto_id: %#x\n", tid[0] & 0xF);
 		return -EINVAL;
 	}
 }
 
+int target_get_pr_transport_id_len(struct t10_pr_registration *pr_reg)
+{
+	return __target_get_pr_transport_id_len(pr_reg->pr_tid);
+}
+
 int target_get_pr_transport_id(
 		struct t10_pr_registration *pr_reg,
 		unsigned char *buf)
@@ -378,6 +383,20 @@ int target_get_pr_transport_id(
 	return  len;
 }
 
+int target_cmp_pr_transport_id(
+		struct t10_pr_registration *pr_reg,
+		unsigned char *tid)
+{
+	int len1 =  __target_get_pr_transport_id_len(pr_reg->pr_tid);
+	int len2 =  __target_get_pr_transport_id_len(tid);
+
+	if (len1 != len2)
+		return 1;
+
+	return memcmp(pr_reg->pr_tid, tid, len1);
+}
+
+
 int target_gen_pr_transport_id(
 	struct t10_pr_registration *pr_reg,
 	int proto_id,
diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h
index bbdddcd83fa4..b0d29c30ab1e 100644
--- a/drivers/target/target_core_internal.h
+++ b/drivers/target/target_core_internal.h
@@ -101,6 +101,8 @@ int	target_fabric_setup_cits(struct target_fabric_configfs *);
 int	target_get_pr_transport_id_len(struct t10_pr_registration *pr_reg);
 int	target_get_pr_transport_id(struct t10_pr_registration *pr_reg,
 				   unsigned char *buf);
+int target_cmp_pr_transport_id(struct t10_pr_registration *pr_reg,
+			       unsigned char *tid);
 int target_gen_pr_transport_id(struct t10_pr_registration *pr_reg,
 			       int proto_id,
 			       const char *initiatorname,
-- 
2.25.1




[Index of Archives]     [Linux SCSI]     [Kernel Newbies]     [Linux SCSI Target Infrastructure]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Device Mapper]

  Powered by Linux