Skip to contentSkip to conversation

target: export initiator port values for all sessions

PATCH Applied Mike Christie 3 participants 14 messages Jul 15, 2018 – Aug 1, 2018 SCSI target

lore
Share & tools
lore
#0 lore raw

PATCH 11/15 target: export initiator port values for all sessions

Export the initiator port info in configfs

---
 drivers/target/target_core_fabric_configfs.c | 48 ++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
drivers/target/target_core_fabric_configfs.c +48 -0
index 497fa01..2deda28 100644
@@ -897,6 +897,53 @@ static void target_fabric_drop_tpg(
 	config_item_put(item);
 }
 
+static ssize_t target_fabric_session_initiator_port_show(
+	struct config_item *item, char *page)
+{
+	struct se_session *se_sess = container_of(to_config_group(item),
+						  struct se_session, group);
+	ssize_t len;
+	int isid_len = 0;
+	unsigned long flags;
+
+	spin_lock_irqsave(&se_sess->configfs_lock, flags);
+	if (!se_sess->se_tpg) {
+		len = -ENOTCONN;
+		goto unlock;
+	}
+
+	if (se_sess->se_tpg->se_tpg_tfo->sess_get_initiator_sid)
+		isid_len = 15;
+
+	if (strlen(se_sess->se_node_acl->initiatorname) + isid_len + 1 >
+	    PAGE_SIZE) {
+		len = -EINVAL;
+		goto unlock;
+	}
+
+	if (se_sess->se_tpg->se_tpg_tfo->sess_get_initiator_sid) {
+		len = snprintf(page, PAGE_SIZE, "%s 0x%6phN\n",
+			       se_sess->se_node_acl->initiatorname,
+			       &se_sess->sess_bin_isid);
+	} else {
+		len = snprintf(page, PAGE_SIZE, "%s\n",
+			       se_sess->se_node_acl->initiatorname);
+	}
+	len += 1; /* Include NULL terminator */
+
+unlock:
+	spin_unlock_irqrestore(&se_sess->configfs_lock, flags);
+
+	return len;
+}
+
+CONFIGFS_ATTR_RO(target_fabric_session_, initiator_port);
+
+static struct configfs_attribute *target_fabric_session_attrs[] = {
+	&target_fabric_session_attr_initiator_port,
+	NULL,
+};
+
 static void target_fabric_session_release(struct config_item *item)
 {
 	struct se_session *se_sess = container_of(to_config_group(item),
@@ -918,6 +965,7 @@ int target_fabric_init_session(struct se_session *se_sess)
 
 	se_sess->cit.ct_owner = THIS_MODULE;
 	se_sess->cit.ct_item_ops = &target_session_item_ops;
+	se_sess->cit.ct_attrs = target_fabric_session_attrs;
 	config_group_init_type_name(&se_sess->group, name, &se_sess->cit);
 	kfree(name);
 	return 0;
Signature · 1 line
2.7.2
#1 lore raw

On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
+AD4- Export the initiator port info in configfs

Does configfs support soft links? Can this information be exported as a soft link from the session directory to the struct se+AF8-portal+AF8-group configfs object?

Thanks,

Bart.

#2 lore raw
In reply to Mike Christie
Quoted 7 lines · Bart Van Assche
Quoted 1 line · Mike Christie

Export the initiator port info in configfs

Does configfs support soft links? Can this information be exported as a soft link from the session directory to the struct se_portal_group configfs object?

If you just needed to export the initiator name or if a single session per initiator can be connected to a tpg then it would work ok.

The problem is for iscsi the scsi initiator port / transport id, is the initiator name and isid. The isid is just a 48 bit number and the initiator will allocate a new value for every session. So on the initiator side if there are multiple nics, then it is common to create a session through nic and each session will have the same initiator name but different isids. So at some place you need to put multiple files to export the different isids or indicate to userspace tools that there is more than one session connected to that tpg.

#3 lore raw
In reply to Mike Christie
Quoted 12 lines · Mike Christie
Quoted 7 lines · Bart Van Assche
Quoted 1 line · Mike Christie

Export the initiator port info in configfs

Does configfs support soft links? Can this information be exported as a soft link from the session directory to the struct se_portal_group configfs object?

If you just needed to export the initiator name or if a single session per initiator can be connected to a tpg then it would work ok.

Quoted 9 lines

The problem is for iscsi the scsi initiator port / transport id, is the initiator name and isid. The isid is just a 48 bit number and the initiator will allocate a new value for every session. So on the initiator side if there are multiple nics, then it is common to create a session through nic and each session will have the same initiator name but different isids. So at some place you need to put multiple files to export the different isids or indicate to userspace tools that there is more than one session connected to that tpg.

Oh wait, I think I know what you mean. Did you want something like this where the symlink name is the info in the initiator_port file like this:

[tpgt_1]# tree -L 2
.
`-- sessions

    `-- 1
    |   `-- iqn.2005-03.com.ceph:ini1,i,0x00023d000001 -> ../../tpgt_1
     `--2

. `-- iqn.2005-03.com.ceph:ini1,i,0x00023d000002 -> ../../tpgt_1

If that is what you are asking about, I did not get why we want to link to the tpg object, because we already know the tpg since it is the parent of the session dir.

#4 lore raw
In reply to Mike Christie

On Sun, 2018-07-15 at 18:16 -0500, Mike Christie wrote:
+AD4- +- if (se+AF8-sess-+AD4-se+AF8-tpg-+AD4-se+AF8-tpg+AF8-tfo-+AD4-sess+AF8-get+AF8-initiator+AF8-sid) +AHs-
+AD4- +- len +AD0- snprintf(page, PAGE+AF8-SIZE, +ACIAJQ-s 0x+ACU-6phN+AFw-n+ACI-,
+AD4- +- se+AF8-sess-+AD4-se+AF8-node+AF8-acl-+AD4-initiatorname,
+AD4- +- +ACY-se+AF8-sess-+AD4-sess+AF8-bin+AF8-isid)+ADs-
+AD4- +- +AH0- else +AHs-
+AD4- +- len +AD0- snprintf(page, PAGE+AF8-SIZE, +ACIAJQ-s+AFw-n+ACI-,
+AD4- +- se+AF8-sess-+AD4-se+AF8-node+AF8-acl-+AD4-initiatorname)+ADs-
+AD4- +- +AH0-

Hello Mike,

The general recommendation for configfs is that each attribute contains a single value, just like for sysfs. Patch 11/15 exports two values through a single attribute. Have you considered to split the above into two attributes, namely the initiator name and the ISID? Can the initiator name be changed into a soft link to the se+AF8-node+AF8-acl configfs directory to make it easy for shell scripts to retrieve additional initiator configuration information?

Thanks,

Bart.

#5 lore raw
In reply to Mike Christie

On Wed, 2018-07-18 at 21:15 -0500, Mike Christie wrote:
+AD4- Oh wait, I think I know what you mean.

I should have written +ACI-se+AF8-node+AF8-acl+ACI- instead of +ACI-se+AF8-portal+AF8-group+ACI-.

Bart.

#6 lore raw
In reply to Mike Christie
Quoted 12 lines · Bart Van Assche

drivers/target/target_core_fabric_configfs.c static void target_fabric_drop_tpg( · line 931

Quoted 8 lines · Mike Christie
drivers/target/target_core_fabric_configfs.c +8 -0
+	if (se_sess->se_tpg->se_tpg_tfo->sess_get_initiator_sid) {
+		len = snprintf(page, PAGE_SIZE, "%s 0x%6phN\n",
+			       se_sess->se_node_acl->initiatorname,
+			       &se_sess->sess_bin_isid);
+	} else {
+		len = snprintf(page, PAGE_SIZE, "%s\n",
+			       se_sess->se_node_acl->initiatorname);
+	}

Hello Mike,

Quoted 3 lines

The general recommendation for configfs is that each attribute contains a single value, just like for sysfs. Patch 11/15 exports two values through a single attribute. Have you considered to split the above into two

What about just making it the initiator port transport id so it aligns with the get_initiator_port_transport_id() comment for the other patch. For iscsi it would be 1 value with the format from SPC/SAM "target_name,i,0x,isid"?

Quoted 4 lines

attributes, namely the initiator name and the ISID? Can the initiator name be changed into a soft link to the se_node_acl configfs directory to make it easy for shell scripts to retrieve additional initiator configuration information?

Because the kernel is creating the session instead of it being driven from a mkdir, there are no existing functions for this. I do not know configfs code well, but I think making a function to do this is possible though.

What about the dynamic_acl case? Just make those a normal file?

Just to make sure we are on the same page too. The initiator name is always the name of the acl right? It looked like that from target_fabric_make_nodeacl but I was wondering if you are asking for the symlink because there are some fabric module quirks where that is not the case. If it's the same names, then you know the acl already from the initiator name file.

Quoted 5 lines

Thanks,

Bart.

#7 lore raw
In reply to Mike Christie

On Thu, 2018-07-19 at 11:38 -0500, Mike Christie wrote:
+AD4- On 07/19/2018 10:37 AM, Bart Van Assche wrote:
+AD4- +AD4- The general recommendation for configfs is that each attribute contains a +AD4- +AD4- single value, just like for sysfs. Patch 11/15 exports two values through +AD4- +AD4- a single attribute. Have you considered to split the above into two +AD4-
+AD4- What about just making it the initiator port transport id so it aligns +AD4- with the get+AF8-initiator+AF8-port+AF8-transport+AF8-id() comment for the other patch. +AD4- For iscsi it would be 1 value with the format from SPC/SAM
+AD4- +ACI-target+AF8-name,i,0x,isid+ACI-?

That sounds fine to me.

+AD4- +AD4- attributes, namely the initiator name and the ISID? Can the initiator name +AD4- +AD4- be changed into a soft link to the se+AF8-node+AF8-acl configfs directory to make +AD4- +AD4- it easy for shell scripts to retrieve additional initiator configuration +AD4- +AD4- information?
+AD4-
+AD4- Because the kernel is creating the session instead of it being driven +AD4- from a mkdir, there are no existing functions for this. I do not know +AD4- configfs code well, but I think making a function to do this is possible +AD4- though.

Initially configfs did not support creation of a directory from the kernel side. Last time I brought this up with Christoph he replied that this functionality has been added to configfs (if I understood Christoph correctly).

+AD4- What about the dynamic+AF8-acl case? Just make those a normal file?

I'm not that familiar with dynamic ACLs. Is there a difference between +ACI-dynamic ACL+ACI- generation and +ACI-demo mode+ACI-? How does this interact with the generate+AF8-node+AF8-acls mode?

+AD4- Just to make sure we are on the same page too. The initiator name is +AD4- always the name of the acl right? It looked like that from
+AD4- target+AF8-fabric+AF8-make+AF8-nodeacl but I was wondering if you are asking for the +AD4- symlink because there are some fabric module quirks where that is not +AD4- the case. If it's the same names, then you know the acl already from the +AD4- initiator name file.

It depends on what is called the +ACI-initiator name+ACI-. E.g. the SRP target driver supports multiple formats to refer to a single initiator port. The
first version of the ib+AF8-srpt driver supported only 128-bit GIDs as initiator name. Since the 64-bit prefix of a GID may change due to a reboot, later
on support for 64-bit GUIDs was added. During login three formats for
the initiator name are verified: GID, GUID without +ACI-0x+ACI- prefix and GUID with +ACI-0x+ACI- prefix. In any case, target+AF8-alloc+AF8-session() will store a pointer to the first struct se+AF8-node+AF8-acl that matches in sess-+AD4-se+AF8-node+AF8-acl. I think using the name stored in struct se+AF8-node+AF8-acl is fine in all cases.

Bart.

#8 lore raw
In reply to Mike Christie
Quoted 4 lines · Bart Van Assche

Initially configfs did not support creation of a directory from the kernel side. Last time I brought this up with Christoph he replied that this functionality has been added to configfs (if I understood Christoph correctly).

I don't think the functionality was ever missing, but I might be mistaken. You can always call config_group_init_type_name() + configfs_add_default_group to add a directory. nvmet makes heavy use of that.

#9 lore raw
In reply to Mike Christie
Quoted 10 lines · Christoph Hellwig
Quoted 4 lines · Bart Van Assche

Initially configfs did not support creation of a directory from the kernel side. Last time I brought this up with Christoph he replied that this functionality has been added to configfs (if I understood Christoph correctly).

I don't think the functionality was ever missing, but I might be mistaken. You can always call config_group_init_type_name() + configfs_add_default_group to add a directory. nvmet makes heavy use of that.

Just to clarify. We can create a dir from the kernel already. It is no problem. I am doing that in this patchset with configfs_register_group.

What Bart was requesting originally and what is missing is being able to add a symlink from the kernel.

I have not fully looked into it, but I think it would be something like taking part of configfs_symlink and making it so we can call it with config_items for the 2 items to be symlinked.

#10 lore raw
In reply to Mike Christie
Quoted 9 lines · Mike Christie

Just to clarify. We can create a dir from the kernel already. It is no problem. I am doing that in this patchset with configfs_register_group.

What Bart was requesting originally and what is missing is being able to add a symlink from the kernel.

I have not fully looked into it, but I think it would be something like taking part of configfs_symlink and making it so we can call it with config_items for the 2 items to be symlinked.

Yes, it shouldn't be too hard.

#11 lore raw
In reply to Mike Christie
Quoted 28 lines · Bart Van Assche
Quoted 9 lines · Mike Christie
Quoted 3 lines · Bart Van Assche

The general recommendation for configfs is that each attribute contains a single value, just like for sysfs. Patch 11/15 exports two values through a single attribute. Have you considered to split the above into two

What about just making it the initiator port transport id so it aligns with the get_initiator_port_transport_id() comment for the other patch. For iscsi it would be 1 value with the format from SPC/SAM "target_name,i,0x,isid"?

That sounds fine to me.

Quoted 9 lines
Quoted 4 lines

attributes, namely the initiator name and the ISID? Can the initiator name be changed into a soft link to the se_node_acl configfs directory to make it easy for shell scripts to retrieve additional initiator configuration information?

Because the kernel is creating the session instead of it being driven from a mkdir, there are no existing functions for this. I do not know configfs code well, but I think making a function to do this is possible though.

Initially configfs did not support creation of a directory from the kernel side. Last time I brought this up with Christoph he replied that this functionality has been added to configfs (if I understood Christoph correctly).

Quoted 5 lines
Quoted 1 line

What about the dynamic_acl case? Just make those a normal file?

I'm not that familiar with dynamic ACLs. Is there a difference between "dynamic ACL" generation and "demo mode"? How does this interact with the generate_node_acls mode?

Ah sorry, I think I made up that term. I was referring to when se_node_acl->dynamic_node_acl=1, so generate_node_acls=1 and demo mode and dynamic_node_acl=1 is the same state.

Quoted 8 lines
Quoted 7 lines

Just to make sure we are on the same page too. The initiator name is always the name of the acl right? It looked like that from target_fabric_make_nodeacl but I was wondering if you are asking for the symlink because there are some fabric module quirks where that is not the case. If it's the same names, then you know the acl already from the initiator name file.

Quoted 10 lines

It depends on what is called the "initiator name". E.g. the SRP target driver supports multiple formats to refer to a single initiator port. The first version of the ib_srpt driver supported only 128-bit GIDs as initiator name. Since the 64-bit prefix of a GID may change due to a reboot, later on support for 64-bit GUIDs was added. During login three formats for the initiator name are verified: GID, GUID without "0x" prefix and GUID with "0x" prefix. In any case, target_alloc_session() will store a pointer to the first struct se_node_acl that matches in sess->se_node_acl. I think using the name stored in struct se_node_acl is fine in all cases.

Hey Bart,

I did patches to add symlinks. There is one problem that this will break userspace though.

The userspace tools assume that they can tear down a tpgt while sessions are running because currently a rmdir on the acl will force running sessions to be shutdown. For example, a FC or iscsi initiator can be logged into the target and userspace currently does something like this simplified sequence:

for each object under a tpgt
ulink luns
rmdir luns
rmdir acls
rmdir tpt

The problem is that because the session has a symlink to the acl and configfs has done a config_item_get on the acl config_item to make sure it does not get freed while in use the "rmdir acl" will now fail.

I agree knowing the acl info is useful, so how about the following:

1. Create a file named "acl" in the session's dir.
2. For dynamic_node_acl=0 the acl file will return a empty string or "generate_node_acls=1" or "demo mode enabled".
3. For dynamic_node_acl=1 the acl file will return se_node_acl->initiatorname which is the name of the acl in ..../tpgt_$N/acls/.

#12 lore raw
In reply to Mike Christie
Quoted 2 lines · Mike Christie

1. Create a file named "acl" in the session's dir.
2. For dynamic_node_acl=0 the acl file will return a empty string or

Miswrote this.

Above should be dynamic_node_acl=1

Quoted 2 lines

"generate_node_acls=1" or "demo mode enabled".
3. For dynamic_node_acl=1 the acl file will return

This should be dynamic_node_acl=0

Quoted 3 lines

se_node_acl->initiatorname which is the name of the acl in ..../tpgt_$N/acls/.

#13 lore raw
In reply to Mike Christie

On Wed, 2018-08-01 at 11:44 -0500, Mike Christie wrote:
+AD4- I agree knowing the acl info is useful, so how about the following:
+AD4-
+AD4- 1. Create a file named +ACI-acl+ACI- in the session's dir.
+AD4- 2. For dynamic+AF8-node+AF8-acl+AD0-0 the acl file will return a empty string or +AD4- +ACI-generate+AF8-node+AF8-acls+AD0-1+ACI- or +ACI-demo mode enabled+ACI-. +AD4- 3. For dynamic+AF8-node+AF8-acl+AD0-1 the acl file will return +AD4- se+AF8-node+AF8-acl-+AD4-initiatorname which is the name of the acl in +AD4- ..../tpgt+AF8AJA-N/acls/.

Hello Mike,

That sounds fine to me. My personal preference is that the +ACI-acl+ACI- file is empty if demo mode is enabled.

Thanks,

Bart.