From patchwork Mon Jul 16 18:47:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 10527589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2B04D6037E for ; Mon, 16 Jul 2018 18:47:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BDE028B59 for ; Mon, 16 Jul 2018 18:47:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F82628DD7; Mon, 16 Jul 2018 18:47:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,T_TVD_MIME_EPI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C22B28B64 for ; Mon, 16 Jul 2018 18:47:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728639AbeGPTPq (ORCPT ); Mon, 16 Jul 2018 15:15:46 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50056 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728202AbeGPTPq (ORCPT ); Mon, 16 Jul 2018 15:15:46 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0E8040AC6DE; Mon, 16 Jul 2018 18:47:02 +0000 (UTC) Received: from [10.10.120.249] (ovpn-120-249.rdu2.redhat.com [10.10.120.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D7932156893; Mon, 16 Jul 2018 18:47:02 +0000 (UTC) Subject: Re: [PATCH 09/15] target: add session dir in configfs To: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, nab@linux-iscsi.org References: <1531696591-8558-1-git-send-email-mchristi@redhat.com> <1531696591-8558-10-git-send-email-mchristi@redhat.com> From: Mike Christie Message-ID: <5B4CE826.8080201@redhat.com> Date: Mon, 16 Jul 2018 13:47:02 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <1531696591-8558-10-git-send-email-mchristi@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 16 Jul 2018 18:47:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 16 Jul 2018 18:47:02 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mchristi@redhat.com' RCPT:'' Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 07/15/2018 06:16 PM, Mike Christie wrote: > TODO: > 1. handle target_fabric_register_session failure in iscsi target. > I fixed this in the updated attached patch. So Bodo and reviewers please use that instead. From 895edd5d20df208c3dfae8d826a3c3fc9999bd68 Mon Sep 17 00:00:00 2001 From: Mike Christie Date: Mon, 16 Jul 2018 13:37:12 -0500 Subject: [PATCH 09/15] target: add session dir in configfs Drivers like iscsi will dump one of the session's info in a info file under the acl. The problem with this is that it only prints one session and only sessions with an acl. Then there is a dynamic_sessions file which dumps the initiator name of each session without an acl. The problem with this is that the info printed is limited to only the node name. For iscsi we do not get the entire initiator port string (name + isid). Also all dynamic sessions are printed in one file so setups that do a target per lun quickly run out of space. To handle all these issues, this patch adds a per session dir under the tpg. We can then export info like initiator name and if needed isid. These patches will then also add some files to test sessions. Signed-off-by: Mike Christie --- drivers/target/iscsi/iscsi_target.c | 3 ++ drivers/target/iscsi/iscsi_target_login.c | 6 ++- drivers/target/iscsi/iscsi_target_nego.c | 24 ++++++++++-- drivers/target/target_core_fabric_configfs.c | 47 +++++++++++++++++++++++ drivers/target/target_core_internal.h | 2 + drivers/target/target_core_transport.c | 57 ++++++++++++++++++++-------- include/target/iscsi/iscsi_target_core.h | 1 + include/target/target_core_base.h | 3 ++ include/target/target_core_fabric.h | 5 ++- 9 files changed, 127 insertions(+), 21 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 6d81a59..f350c68 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -4324,6 +4324,9 @@ int iscsit_close_session(struct iscsi_session *sess) iscsit_stop_time2retain_timer(sess); spin_unlock_bh(&se_tpg->session_lock); + if (sess->fabric_registered) + target_fabric_unregister_session(sess->se_sess); + /* * transport_deregister_session_configfs() will clear the * struct se_node_acl->nacl_sess pointer now as a iscsi_np process context diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c index d6a4b93..4f80965 100644 --- a/drivers/target/iscsi/iscsi_target_login.c +++ b/drivers/target/iscsi/iscsi_target_login.c @@ -1145,8 +1145,12 @@ void iscsi_target_login_sess_out(struct iscsi_conn *conn, ISCSI_LOGIN_STATUS_INIT_ERR); if (!zero_tsih || !conn->sess) goto old_sess_out; - if (conn->sess->se_sess) + if (conn->sess->se_sess) { + if (conn->sess->fabric_registered) + target_fabric_unregister_session(conn->sess->se_sess); + transport_free_session(conn->sess->se_sess); + } kfree(conn->sess->sess_ops); kfree(conn->sess); conn->sess = NULL; diff --git a/drivers/target/iscsi/iscsi_target_nego.c b/drivers/target/iscsi/iscsi_target_nego.c index 8a5e8d1..fe08e40 100644 --- a/drivers/target/iscsi/iscsi_target_nego.c +++ b/drivers/target/iscsi/iscsi_target_nego.c @@ -1279,11 +1279,27 @@ int iscsi_target_locate_portal( tag_size = sizeof(struct iscsi_cmd) + conn->conn_transport->priv_size; ret = transport_alloc_session_tags(sess->se_sess, tag_num, tag_size); - if (ret < 0) { - iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, - ISCSI_LOGIN_STATUS_NO_RESOURCES); - ret = -1; + if (ret < 0) + goto return_oom; + + if (conn->tpg != iscsit_global->discovery_tpg) { + ret = target_fabric_register_session(&conn->tpg->tpg_se_tpg, + sess->se_sess); + if (ret) { + pr_err("Could not register session to configfs. Err %d.\n", + ret); + /* tags and nacl released when session is freed */ + goto return_oom; + } + sess->fabric_registered = true; } + + goto out; + +return_oom: + iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, + ISCSI_LOGIN_STATUS_NO_RESOURCES); + ret = -1; out: kfree(tmpbuf); return ret; diff --git a/drivers/target/target_core_fabric_configfs.c b/drivers/target/target_core_fabric_configfs.c index 1fa436e..497fa01 100644 --- a/drivers/target/target_core_fabric_configfs.c +++ b/drivers/target/target_core_fabric_configfs.c @@ -878,6 +878,11 @@ static struct config_group *target_fabric_make_tpg( configfs_add_default_group(&se_tpg->tpg_param_group, &se_tpg->tpg_group); + config_group_init_type_name(&se_tpg->tpg_session_group, "sessions", + &tf->tf_tpg_session_cit); + configfs_add_default_group(&se_tpg->tpg_session_group, + &se_tpg->tpg_group); + return &se_tpg->tpg_group; } @@ -892,6 +897,48 @@ static void target_fabric_drop_tpg( config_item_put(item); } +static void target_fabric_session_release(struct config_item *item) +{ + struct se_session *se_sess = container_of(to_config_group(item), + struct se_session, group); + target_release_session(se_sess); +} + +static struct configfs_item_operations target_session_item_ops = { + .release = target_fabric_session_release, +}; + +int target_fabric_init_session(struct se_session *se_sess) +{ + char *name; + + name = kasprintf(GFP_KERNEL, "%d", se_sess->sid); + if (!name) + return -ENOMEM; + + se_sess->cit.ct_owner = THIS_MODULE; + se_sess->cit.ct_item_ops = &target_session_item_ops; + config_group_init_type_name(&se_sess->group, name, &se_sess->cit); + kfree(name); + return 0; +} +EXPORT_SYMBOL(target_fabric_init_session); + +int target_fabric_register_session( + struct se_portal_group *se_tpg, + struct se_session *se_sess) +{ + return configfs_register_group(&se_tpg->tpg_session_group, + &se_sess->group); +} +EXPORT_SYMBOL(target_fabric_register_session); + +void target_fabric_unregister_session(struct se_session *se_sess) +{ + configfs_unregister_group(&se_sess->group); +} +EXPORT_SYMBOL(target_fabric_unregister_session); + static void target_fabric_release_wwn(struct config_item *item) { struct se_wwn *wwn = container_of(to_config_group(item), diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h index 0c66355..73c90ae 100644 --- a/drivers/target/target_core_internal.h +++ b/drivers/target/target_core_internal.h @@ -44,6 +44,7 @@ struct target_fabric_configfs { struct config_item_type tf_tpg_attrib_cit; struct config_item_type tf_tpg_auth_cit; struct config_item_type tf_tpg_param_cit; + struct config_item_type tf_tpg_session_cit; struct config_item_type tf_tpg_nacl_cit; struct config_item_type tf_tpg_nacl_base_cit; struct config_item_type tf_tpg_nacl_attrib_cit; @@ -154,6 +155,7 @@ void transport_dump_dev_info(struct se_device *, struct se_lun *, bool target_check_wce(struct se_device *dev); bool target_check_fua(struct se_device *dev); void __target_execute_cmd(struct se_cmd *, bool); +void target_release_session(struct se_session *); /* target_core_stat.c */ void target_stat_setup_dev_default_groups(struct se_device *); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 57279fe..0efb3dc 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -271,11 +271,22 @@ struct se_session *transport_alloc_session(enum target_prot_op sup_prot_ops) if (ret < 0) { pr_err("Unable to allocate session index.\n"); - kmem_cache_free(se_sess_cache, se_sess); - return ERR_PTR(ret); + goto free_sess; } + ret = target_fabric_init_session(se_sess); + if (ret) + goto free_sid; + return se_sess; + +free_sid: + spin_lock_irqsave(&se_sess_idr_lock, flags); + idr_remove(&se_sess_idr, se_sess->sid); + spin_unlock_irqrestore(&se_sess_idr_lock, flags); +free_sess: + kmem_cache_free(se_sess_cache, se_sess); + return ERR_PTR(ret); } EXPORT_SYMBOL(transport_alloc_session); @@ -443,6 +454,7 @@ struct se_session * struct se_session *, void *)) { struct se_session *sess; + int rc; /* * If the fabric driver is using percpu-ida based pre allocation @@ -459,23 +471,32 @@ struct se_session * sess->se_node_acl = core_tpg_check_initiator_node_acl(tpg, (unsigned char *)initiatorname); if (!sess->se_node_acl) { - transport_free_session(sess); - return ERR_PTR(-EACCES); + rc = -EACCES; + goto free_sess; } + + rc = target_fabric_register_session(tpg, sess); + if (rc) + goto free_sess; + /* * Go ahead and perform any remaining fabric setup that is * required before transport_register_session(). */ if (callback != NULL) { - int rc = callback(tpg, sess, private); - if (rc) { - transport_free_session(sess); - return ERR_PTR(rc); - } + rc = callback(tpg, sess, private); + if (rc) + goto unregister_fabric; } transport_register_session(tpg, sess->se_node_acl, sess, private); return sess; + +unregister_fabric: + target_fabric_unregister_session(sess); +free_sess: + transport_free_session(sess); + return ERR_PTR(rc); } EXPORT_SYMBOL(target_setup_session); @@ -558,6 +579,17 @@ void transport_deregister_session_configfs(struct se_session *se_sess) } EXPORT_SYMBOL(transport_deregister_session_configfs); +void target_release_session(struct se_session *se_sess) +{ + unsigned long flags; + + spin_lock_irqsave(&se_sess_idr_lock, flags); + idr_remove(&se_sess_idr, se_sess->sid); + spin_unlock_irqrestore(&se_sess_idr_lock, flags); + + kmem_cache_free(se_sess_cache, se_sess); +} + void transport_free_session(struct se_session *se_sess) { struct se_node_acl *se_nacl = se_sess->se_node_acl; @@ -600,12 +632,6 @@ void transport_free_session(struct se_session *se_sess) sbitmap_queue_free(&se_sess->sess_tag_pool); kvfree(se_sess->sess_cmd_map); } - - spin_lock_irqsave(&se_sess_idr_lock, flags); - idr_remove(&se_sess_idr, se_sess->sid); - spin_unlock_irqrestore(&se_sess_idr_lock, flags); - - kmem_cache_free(se_sess_cache, se_sess); } EXPORT_SYMBOL(transport_free_session); @@ -642,6 +668,7 @@ void transport_deregister_session(struct se_session *se_sess) void target_remove_session(struct se_session *se_sess) { + target_fabric_unregister_session(se_sess); transport_deregister_session_configfs(se_sess); transport_deregister_session(se_sess); } diff --git a/include/target/iscsi/iscsi_target_core.h b/include/target/iscsi/iscsi_target_core.h index 10031dc..e6ff787 100644 --- a/include/target/iscsi/iscsi_target_core.h +++ b/include/target/iscsi/iscsi_target_core.h @@ -688,6 +688,7 @@ struct iscsi_session { struct completion session_waiting_on_uc_comp; struct timer_list time2retain_timer; struct iscsi_sess_ops *sess_ops; + bool fabric_registered; struct se_session *se_sess; struct iscsi_portal_group *tpg; } ____cacheline_aligned; diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index d5efde8..01caaa3 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -610,6 +610,8 @@ struct se_session { void *sess_cmd_map; struct sbitmap_queue sess_tag_pool; int sid; + struct config_group group; + struct config_item_type cit; }; struct se_device; @@ -887,6 +889,7 @@ struct se_portal_group { struct config_group tpg_attrib_group; struct config_group tpg_auth_group; struct config_group tpg_param_group; + struct config_group tpg_session_group; }; static inline struct se_portal_group *to_tpg(struct config_item *item) diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h index aa69b13..36077d6 100644 --- a/include/target/target_core_fabric.h +++ b/include/target/target_core_fabric.h @@ -128,7 +128,10 @@ void transport_register_session(struct se_portal_group *, void target_put_nacl(struct se_node_acl *); void transport_deregister_session_configfs(struct se_session *); void transport_deregister_session(struct se_session *); - +int target_fabric_init_session(struct se_session *); +int target_fabric_register_session(struct se_portal_group *, + struct se_session *); +void target_fabric_unregister_session(struct se_session *); void transport_init_se_cmd(struct se_cmd *, const struct target_core_fabric_ops *, -- 1.8.3.1