From: Maurizio Lombardi <mlombard@redhat.com>
To: martin.petersen@oracle.com
Cc: michael.christie@oracle.com, linux-scsi@vger.kernel.org,
target-devel@vger.kernel.org, mlombard@bsdbackstore.eu
Subject: [PATCH] target: generate correct string identifiers for PR OUT transport IDs
Date: Fri, 27 Jun 2025 16:52:29 +0200 [thread overview]
Message-ID: <20250627145229.286252-1-mlombard@redhat.com> (raw)
Fix target_parse_pr_out_transport_id() to
return a dynamically allocated string representing the
transport ID in a standardized, human-readable format
(e.g., naa.xxxxxxxx...) for various SCSI protocol types
(SAS, FCP, SRP, SBP).
Previously, the function returned a pointer to the raw binary buffer.
The caller would then compared it to a human-readable string,
which obviously always failed.
Now, the function constructs a string using kasprintf()
based on the protocol's offset and format:
* SAS, FCP, SBP: 64-bit identifier
* SRP: 128-bit identifier
* iSCSI: duplicates the iqn string to match the new allocation behavior
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
---
drivers/target/target_core_fabric_lib.c | 22 ++++++++++++++++------
drivers/target/target_core_pr.c | 7 ++++++-
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/drivers/target/target_core_fabric_lib.c b/drivers/target/target_core_fabric_lib.c
index 43f47e3aa448..a124cf982a4c 100644
--- a/drivers/target/target_core_fabric_lib.c
+++ b/drivers/target/target_core_fabric_lib.c
@@ -390,7 +390,10 @@ int target_get_pr_transport_id(struct se_node_acl *nacl,
const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg,
char *buf, u32 *out_tid_len, char **port_nexus_ptr)
{
- u32 offset;
+ u32 offset = 8;
+ u32 len = 8;
+ char *prefix;
+ char hex[40];
switch (tpg->proto_id) {
case SCSI_PROTOCOL_SAS:
@@ -399,15 +402,21 @@ const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg,
* for initiator ports using SCSI over SAS Serial SCSI Protocol.
*/
offset = 4;
+ prefix = "naa";
break;
- case SCSI_PROTOCOL_SBP:
case SCSI_PROTOCOL_SRP:
+ prefix = "ib";
+ len = 16;
+ break;
case SCSI_PROTOCOL_FCP:
- offset = 8;
+ prefix = "naa";
+ break;
+ case SCSI_PROTOCOL_SBP:
+ prefix = "eui";
break;
case SCSI_PROTOCOL_ISCSI:
- return iscsi_parse_pr_out_transport_id(tpg, buf, out_tid_len,
- port_nexus_ptr);
+ return kstrdup(iscsi_parse_pr_out_transport_id(tpg, buf,
+ out_tid_len, port_nexus_ptr), GFP_KERNEL);
default:
pr_err("Unknown proto_id: 0x%02x\n", tpg->proto_id);
return NULL;
@@ -415,5 +424,6 @@ const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg,
*port_nexus_ptr = NULL;
*out_tid_len = 24;
- return buf + offset;
+ bin2hex(hex, buf + offset, len);
+ return kasprintf(GFP_KERNEL, "%s.%s", prefix, hex);
}
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 70905805cb17..b9b3adc1657d 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -1571,6 +1571,7 @@ core_scsi3_decode_spec_i_port(
dest_rtpi = tmp_lun->lun_tpg->tpg_rtpi;
iport_ptr = NULL;
+ kfree(i_str);
i_str = target_parse_pr_out_transport_id(tmp_tpg,
ptr, &tid_len, &iport_ptr);
if (!i_str)
@@ -1808,6 +1809,7 @@ core_scsi3_decode_spec_i_port(
core_scsi3_tpg_undepend_item(dest_tpg);
}
+ kfree(i_str);
return 0;
out_unmap:
transport_kunmap_data_sg(cmd);
@@ -1852,6 +1854,7 @@ core_scsi3_decode_spec_i_port(
core_scsi3_nodeacl_undepend_item(dest_node_acl);
core_scsi3_tpg_undepend_item(dest_tpg);
}
+ kfree(i_str);
return ret;
}
@@ -3153,7 +3156,7 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
struct t10_pr_registration *pr_reg, *pr_res_holder, *dest_pr_reg;
struct t10_reservation *pr_tmpl = &dev->t10_pr;
unsigned char *buf;
- const unsigned char *initiator_str;
+ const unsigned char *initiator_str = NULL;
char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN] = { };
u32 tid_len, tmp_tid_len;
int new_reg = 0, type, scope, matching_iname;
@@ -3526,6 +3529,7 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
core_scsi3_update_and_write_aptpl(cmd->se_dev, aptpl);
core_scsi3_put_pr_reg(dest_pr_reg);
+ kfree(initiator_str);
return 0;
out:
if (buf)
@@ -3538,6 +3542,7 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
out_put_pr_reg:
core_scsi3_put_pr_reg(pr_reg);
+ kfree(initiator_str);
return ret;
}
--
2.47.1
next reply other threads:[~2025-06-27 14:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-27 14:52 Maurizio Lombardi [this message]
2025-06-27 17:40 ` [PATCH] target: generate correct string identifiers for PR OUT transport IDs Dmitry Bogdanov
2025-06-29 12:16 ` Maurizio Lombardi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250627145229.286252-1-mlombard@redhat.com \
--to=mlombard@redhat.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=michael.christie@oracle.com \
--cc=mlombard@bsdbackstore.eu \
--cc=target-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox