drivers/target/target_core_fabric_lib.c

Source file repositories/reference/linux-study-clean/drivers/target/target_core_fabric_lib.c

File Facts

System
Linux kernel
Corpus path
drivers/target/target_core_fabric_lib.c
Extension
.c
Size
11764 bytes
Lines
454
Domain
Driver Families
Bucket
drivers/target
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (!strncmp(&ptr[i], ":", 1)) {
			i++;
			continue;
		}
		ret = hex2bin(&buf[off++], &ptr[i], 1);
		if (ret < 0) {
			pr_debug("%s: invalid hex string\n", __func__);
			return ret;
		}
		i += 2;
	}
	/*
	 * The FC Transport ID is a hardcoded 24-byte length
	 */
	return 24;
}

static int sbp_get_pr_transport_id(
	struct se_node_acl *nacl,
	int *format_code,
	unsigned char *buf)
{
	int ret;

	ret = hex2bin(&buf[8], nacl->initiatorname, 8);
	if (ret) {
		pr_debug("%s: invalid hex string\n", __func__);
		return ret;
	}

	return 24;
}

static int srp_get_pr_transport_id(
	struct se_node_acl *nacl,
	int *format_code,
	unsigned char *buf)
{
	const char *p;
	unsigned len, count, leading_zero_bytes;
	int rc;

	p = nacl->initiatorname;
	if (strncasecmp(p, "0x", 2) == 0)
		p += 2;
	len = strlen(p);
	if (len % 2)
		return -EINVAL;

	count = min(len / 2, 16U);
	leading_zero_bytes = 16 - count;
	memset(buf + 8, 0, leading_zero_bytes);
	rc = hex2bin(buf + 8 + leading_zero_bytes, p, count);
	if (rc < 0) {
		pr_debug("hex2bin failed for %s: %d\n", p, rc);
		return rc;
	}

	return 24;
}

static int iscsi_get_pr_transport_id(
	struct se_node_acl *se_nacl,
	struct t10_pr_registration *pr_reg,
	int *format_code,
	unsigned char *buf)
{
	u32 off = 4, padding = 0;
	int isid_len;
	u16 len = 0;

	spin_lock_irq(&se_nacl->nacl_sess_lock);
	/*
	 * Only null terminate the last field.
	 *
	 * From spc4r37 section 7.6.4.6: TransportID for initiator ports using
	 * SCSI over iSCSI.
	 *
	 * Table 507 TPID=0 Initiator device TransportID
	 *
	 * The null-terminated, null-padded (see 4.3.2) ISCSI NAME field shall
	 * contain the iSCSI name of an iSCSI initiator node (see RFC 7143).
	 * The first ISCSI NAME field byte containing an ASCII null character
	 * terminates the ISCSI NAME field without regard for the specified
	 * length of the iSCSI TransportID or the contents of the ADDITIONAL
	 * LENGTH field.
	 */
	len = sprintf(&buf[off], "%s", se_nacl->initiatorname);
	off += len;
	if ((*format_code == 1) && (pr_reg->isid_present_at_reg)) {

Annotation

Implementation Notes