From: Mike Christie <michael.christie@oracle.com> To: bvanassche@acm.org, bstroesser@ts.fujitsu.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: [PATCH 16/17] iscsi target: export session state and alias in sysfs Date: Sun, 07 Jun 2020 20:36:03 +0000 [thread overview] Message-ID: <1591562164-9766-17-git-send-email-michael.christie@oracle.com> (raw) In-Reply-To: <1591562164-9766-1-git-send-email-michael.christie@oracle.com> Export the session state and alias in sysfs. Note: It does not export the per connection state. In the future we can have the iscsi target add/rm an attribute group directly for each connection when we login and logout/drop a connection. Since those are dynamic and can change while the session exists, we don't need them at device addition so it can be done directly from the module. Signed-off-by: Mike Christie <michael.christie@oracle.com> --- drivers/target/iscsi/iscsi_target_configfs.c | 97 ++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 21 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c index ba608fa..64de2ec 100644 --- a/drivers/target/iscsi/iscsi_target_configfs.c +++ b/drivers/target/iscsi/iscsi_target_configfs.c @@ -28,6 +28,28 @@ #include "iscsi_target.h" #include <target/iscsi/iscsi_target_stat.h> +static const struct { + enum target_sess_state_table value; + char *name; +} session_states[] = { + { TARG_SESS_STATE_FREE, "TARG_SESS_FREE" }, + { TARG_SESS_STATE_ACTIVE, "TARG_SESS_STATE_ACTIVE" }, + { TARG_SESS_STATE_LOGGED_IN, "TARG_SESS_STATE_LOGGED_IN" }, + { TARG_SESS_STATE_FAILED, "TARG_SESS_STATE_FAILED" }, + { TARG_SESS_STATE_IN_CONTINUE, "TARG_SESS_STATE_IN_CONTINUE" }, +}; + +static const char *session_state_name(enum target_sess_state_table state) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(session_states); i++) { + if (session_states[i].value = state) + return session_states[i].name; + } + + return NULL; +} /* Start items for lio_target_portal_cit */ @@ -502,6 +524,7 @@ static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page) struct iscsi_session *sess; struct iscsi_conn *conn; struct se_session *se_sess; + const char *state_name; ssize_t rb = 0; u32 max_cmd_sn; @@ -525,27 +548,12 @@ static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page) (sess->sess_ops->SessionType) ? "Discovery" : "Normal"); rb += sprintf(page+rb, "Session State: "); - switch (sess->session_state) { - case TARG_SESS_STATE_FREE: - rb += sprintf(page+rb, "TARG_SESS_FREE\n"); - break; - case TARG_SESS_STATE_ACTIVE: - rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n"); - break; - case TARG_SESS_STATE_LOGGED_IN: - rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n"); - break; - case TARG_SESS_STATE_FAILED: - rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n"); - break; - case TARG_SESS_STATE_IN_CONTINUE: - rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n"); - break; - default: - rb += sprintf(page+rb, "ERROR: Unknown Session" - " State!\n"); - break; - } + + state_name = session_state_name(sess->session_state); + if (state_name) + rb += sprintf(page+rb, "%s\n", state_name); + else + rb += sprintf(page+rb, "ERROR: Unknown Session State!\n"); rb += sprintf(page+rb, "---------------------[iSCSI Session" " Values]-----------------------\n"); @@ -1333,6 +1341,51 @@ static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item, /* End lio_target_discovery_auth_cit */ +/* session sysfs */ +static ssize_t +lio_show_sess_state(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct se_session *se_sess = container_of(dev, struct se_session, dev); + struct iscsi_session *sess = se_sess->fabric_sess_ptr; + const char *state_name; + + state_name = session_state_name(sess->session_state); + if (!state_name) + return -EINVAL; + + return snprintf(buf, PAGE_SIZE, "%s", state_name); +} + +static ssize_t +lio_show_initiator_alias(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct se_session *se_sess = container_of(dev, struct se_session, dev); + struct iscsi_session *sess = se_sess->fabric_sess_ptr; + + return snprintf(buf, PAGE_SIZE, "%s", sess->sess_ops->InitiatorAlias); +} + +static DEVICE_ATTR(state, S_IRUGO, lio_show_sess_state, NULL); +static DEVICE_ATTR(initiator_alias, S_IRUGO, lio_show_initiator_alias, NULL); + +static struct attribute *lio_sess_attrs[] = { + &dev_attr_state.attr, + &dev_attr_initiator_alias.attr, + NULL, +}; + +static struct attribute_group lio_sess_attr_group = { + .name = "iscsi_session", + .attrs = lio_sess_attrs, +}; + +static const struct attribute_group *lio_sess_attr_groups[] = { + &lio_sess_attr_group, + NULL, +}; + /* Start functions for target_core_fabric_ops */ static int iscsi_get_cmd_state(struct se_cmd *se_cmd) @@ -1556,6 +1609,8 @@ static void lio_release_cmd(struct se_cmd *se_cmd) .fabric_drop_np = lio_target_call_delnpfromtpg, .fabric_init_nodeacl = lio_target_init_nodeacl, + .session_attr_groups = lio_sess_attr_groups, + .tfc_discovery_attrs = lio_target_discovery_auth_attrs, .tfc_wwn_attrs = lio_target_wwn_attrs, .tfc_tpg_base_attrs = lio_target_tpg_attrs, -- 1.8.3.1
WARNING: multiple messages have this Message-ID (diff)
From: Mike Christie <michael.christie@oracle.com> To: bvanassche@acm.org, bstroesser@ts.fujitsu.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: [PATCH 16/17] iscsi target: export session state and alias in sysfs Date: Sun, 7 Jun 2020 15:36:03 -0500 [thread overview] Message-ID: <1591562164-9766-17-git-send-email-michael.christie@oracle.com> (raw) In-Reply-To: <1591562164-9766-1-git-send-email-michael.christie@oracle.com> Export the session state and alias in sysfs. Note: It does not export the per connection state. In the future we can have the iscsi target add/rm an attribute group directly for each connection when we login and logout/drop a connection. Since those are dynamic and can change while the session exists, we don't need them at device addition so it can be done directly from the module. Signed-off-by: Mike Christie <michael.christie@oracle.com> --- drivers/target/iscsi/iscsi_target_configfs.c | 97 ++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 21 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c index ba608fa..64de2ec 100644 --- a/drivers/target/iscsi/iscsi_target_configfs.c +++ b/drivers/target/iscsi/iscsi_target_configfs.c @@ -28,6 +28,28 @@ #include "iscsi_target.h" #include <target/iscsi/iscsi_target_stat.h> +static const struct { + enum target_sess_state_table value; + char *name; +} session_states[] = { + { TARG_SESS_STATE_FREE, "TARG_SESS_FREE" }, + { TARG_SESS_STATE_ACTIVE, "TARG_SESS_STATE_ACTIVE" }, + { TARG_SESS_STATE_LOGGED_IN, "TARG_SESS_STATE_LOGGED_IN" }, + { TARG_SESS_STATE_FAILED, "TARG_SESS_STATE_FAILED" }, + { TARG_SESS_STATE_IN_CONTINUE, "TARG_SESS_STATE_IN_CONTINUE" }, +}; + +static const char *session_state_name(enum target_sess_state_table state) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(session_states); i++) { + if (session_states[i].value == state) + return session_states[i].name; + } + + return NULL; +} /* Start items for lio_target_portal_cit */ @@ -502,6 +524,7 @@ static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page) struct iscsi_session *sess; struct iscsi_conn *conn; struct se_session *se_sess; + const char *state_name; ssize_t rb = 0; u32 max_cmd_sn; @@ -525,27 +548,12 @@ static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page) (sess->sess_ops->SessionType) ? "Discovery" : "Normal"); rb += sprintf(page+rb, "Session State: "); - switch (sess->session_state) { - case TARG_SESS_STATE_FREE: - rb += sprintf(page+rb, "TARG_SESS_FREE\n"); - break; - case TARG_SESS_STATE_ACTIVE: - rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n"); - break; - case TARG_SESS_STATE_LOGGED_IN: - rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n"); - break; - case TARG_SESS_STATE_FAILED: - rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n"); - break; - case TARG_SESS_STATE_IN_CONTINUE: - rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n"); - break; - default: - rb += sprintf(page+rb, "ERROR: Unknown Session" - " State!\n"); - break; - } + + state_name = session_state_name(sess->session_state); + if (state_name) + rb += sprintf(page+rb, "%s\n", state_name); + else + rb += sprintf(page+rb, "ERROR: Unknown Session State!\n"); rb += sprintf(page+rb, "---------------------[iSCSI Session" " Values]-----------------------\n"); @@ -1333,6 +1341,51 @@ static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item, /* End lio_target_discovery_auth_cit */ +/* session sysfs */ +static ssize_t +lio_show_sess_state(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct se_session *se_sess = container_of(dev, struct se_session, dev); + struct iscsi_session *sess = se_sess->fabric_sess_ptr; + const char *state_name; + + state_name = session_state_name(sess->session_state); + if (!state_name) + return -EINVAL; + + return snprintf(buf, PAGE_SIZE, "%s", state_name); +} + +static ssize_t +lio_show_initiator_alias(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct se_session *se_sess = container_of(dev, struct se_session, dev); + struct iscsi_session *sess = se_sess->fabric_sess_ptr; + + return snprintf(buf, PAGE_SIZE, "%s", sess->sess_ops->InitiatorAlias); +} + +static DEVICE_ATTR(state, S_IRUGO, lio_show_sess_state, NULL); +static DEVICE_ATTR(initiator_alias, S_IRUGO, lio_show_initiator_alias, NULL); + +static struct attribute *lio_sess_attrs[] = { + &dev_attr_state.attr, + &dev_attr_initiator_alias.attr, + NULL, +}; + +static struct attribute_group lio_sess_attr_group = { + .name = "iscsi_session", + .attrs = lio_sess_attrs, +}; + +static const struct attribute_group *lio_sess_attr_groups[] = { + &lio_sess_attr_group, + NULL, +}; + /* Start functions for target_core_fabric_ops */ static int iscsi_get_cmd_state(struct se_cmd *se_cmd) @@ -1556,6 +1609,8 @@ static void lio_release_cmd(struct se_cmd *se_cmd) .fabric_drop_np = lio_target_call_delnpfromtpg, .fabric_init_nodeacl = lio_target_init_nodeacl, + .session_attr_groups = lio_sess_attr_groups, + .tfc_discovery_attrs = lio_target_discovery_auth_attrs, .tfc_wwn_attrs = lio_target_wwn_attrs, .tfc_tpg_base_attrs = lio_target_tpg_attrs, -- 1.8.3.1
next prev parent reply other threads:[~2020-06-07 20:36 UTC|newest] Thread overview: 83+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-07 20:35 [PATCH v6 00/17] target: add sysfs support Mike Christie 2020-06-07 20:35 ` Mike Christie 2020-06-07 20:35 ` [PATCH 01/17] target: check enforce_pr_isids during registration Mike Christie 2020-06-07 20:35 ` Mike Christie 2020-06-07 20:35 ` [PATCH 02/17] target: separate acl name from port ids Mike Christie 2020-06-07 20:35 ` Mike Christie 2020-06-09 10:11 ` Stefan Hajnoczi 2020-06-09 10:11 ` Stefan Hajnoczi 2020-06-09 14:13 ` Himanshu Madhani 2020-06-09 14:13 ` Himanshu Madhani 2020-06-07 20:35 ` [PATCH 03/17] target: add helper to parse acl and transport name Mike Christie 2020-06-07 20:35 ` Mike Christie 2020-06-07 20:35 ` [PATCH 04/17] tcm loop: use target_parse_emulated_name Mike Christie 2020-06-07 20:35 ` Mike Christie 2020-06-07 20:35 ` [PATCH 05/17] vhost scsi: " Mike Christie 2020-06-07 20:35 ` Mike Christie 2020-06-09 10:21 ` Stefan Hajnoczi 2020-06-09 10:21 ` Stefan Hajnoczi 2020-06-07 20:35 ` [PATCH 06/17] xen scsiback: " Mike Christie 2020-06-07 20:35 ` Mike Christie 2020-06-07 20:35 ` [PATCH 07/17] iscsi target: setup transport_id Mike Christie 2020-06-07 20:35 ` Mike Christie 2020-06-07 20:35 ` [PATCH 08/17] target: use tpt_id in target_stat_iport_port_ident_show Mike Christie 2020-06-07 20:35 ` Mike Christie 2020-06-07 20:35 ` [PATCH 09/17] target: drop sess_get_initiator_sid from PR code Mike Christie 2020-06-07 20:35 ` Mike Christie 2020-06-07 20:35 ` [PATCH 10/17] target: drop sess_get_initiator_sid Mike Christie 2020-06-07 20:35 ` Mike Christie 2020-06-07 20:35 ` [PATCH 11/17] target: add session sysfs class support Mike Christie 2020-06-07 20:35 ` Mike Christie 2020-06-08 5:32 ` Greg Kroah-Hartman 2020-06-08 5:32 ` Greg Kroah-Hartman 2020-06-08 15:35 ` Mike Christie 2020-06-08 15:35 ` Mike Christie 2020-06-08 16:36 ` Greg Kroah-Hartman 2020-06-08 16:36 ` Greg Kroah-Hartman 2020-06-08 19:02 ` Mike Christie 2020-06-08 19:02 ` Mike Christie 2020-06-09 6:05 ` Greg Kroah-Hartman 2020-06-09 6:05 ` Greg Kroah-Hartman 2020-06-08 6:14 ` Hannes Reinecke 2020-06-08 6:14 ` Hannes Reinecke 2020-06-08 15:21 ` Mike Christie 2020-06-08 15:21 ` Mike Christie 2020-06-08 15:55 ` Michael Christie 2020-06-08 15:55 ` Michael Christie 2020-06-09 3:10 ` Michael Christie 2020-06-09 3:10 ` Michael Christie 2020-06-08 12:06 ` Bodo Stroesser 2020-06-08 12:06 ` Bodo Stroesser 2020-06-08 14:49 ` Mike Christie 2020-06-08 14:49 ` Mike Christie 2020-06-08 12:18 ` Greg Kroah-Hartman 2020-06-08 12:18 ` Greg Kroah-Hartman 2020-06-08 12:18 ` Greg Kroah-Hartman 2020-06-08 12:18 ` Greg Kroah-Hartman 2020-06-07 20:35 ` [PATCH 12/17] target: hook most target users into sysfs API Mike Christie 2020-06-07 20:35 ` Mike Christie 2020-06-08 6:15 ` Hannes Reinecke 2020-06-08 6:15 ` Hannes Reinecke 2020-06-08 10:20 ` kernel test robot 2020-06-08 10:20 ` kernel test robot 2020-06-08 10:20 ` kernel test robot 2020-06-07 20:36 ` [PATCH 13/17] iscsi target: replace module sids with lio's sid Mike Christie 2020-06-07 20:36 ` Mike Christie 2020-06-08 6:16 ` Hannes Reinecke 2020-06-08 6:16 ` Hannes Reinecke 2020-06-07 20:36 ` [PATCH 14/17] target: add free_session callout Mike Christie 2020-06-07 20:36 ` Mike Christie 2020-06-08 6:19 ` Hannes Reinecke 2020-06-08 6:19 ` Hannes Reinecke 2020-06-07 20:36 ` [PATCH 15/17] iscsi target: hook iscsi target into sysfs API Mike Christie 2020-06-07 20:36 ` Mike Christie 2020-06-08 6:20 ` Hannes Reinecke 2020-06-08 6:20 ` Hannes Reinecke 2020-06-07 20:36 ` Mike Christie [this message] 2020-06-07 20:36 ` [PATCH 16/17] iscsi target: export session state and alias in sysfs Mike Christie 2020-06-08 6:21 ` Hannes Reinecke 2020-06-08 6:21 ` Hannes Reinecke 2020-06-07 20:36 ` [PATCH 17/17] target: drop sess_get_index Mike Christie 2020-06-07 20:36 ` Mike Christie 2020-06-08 6:21 ` Hannes Reinecke 2020-06-08 6:21 ` Hannes Reinecke
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=1591562164-9766-17-git-send-email-michael.christie@oracle.com \ --to=michael.christie@oracle.com \ --cc=bstroesser@ts.fujitsu.com \ --cc=bvanassche@acm.org \ --cc=linux-scsi@vger.kernel.org \ --cc=martin.petersen@oracle.com \ --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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.