From patchwork Sun Jul 15 23:16:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 10525317 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 310B260245 for ; Sun, 15 Jul 2018 23:16:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22AD72654B for ; Sun, 15 Jul 2018 23:16:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16FF928334; Sun, 15 Jul 2018 23:16:51 +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 autolearn=ham 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 B04CB2654B for ; Sun, 15 Jul 2018 23:16:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727402AbeGOXlW (ORCPT ); Sun, 15 Jul 2018 19:41:22 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59992 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727349AbeGOXlV (ORCPT ); Sun, 15 Jul 2018 19:41:21 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A7888402312B; Sun, 15 Jul 2018 23:16:47 +0000 (UTC) Received: from rh2.redhat.com (ovpn-120-206.rdu2.redhat.com [10.10.120.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AB0E76EA; Sun, 15 Jul 2018 23:16:47 +0000 (UTC) From: Mike Christie To: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, nab@linux-iscsi.org Cc: Mike Christie Subject: [PATCH 10/15] target: add lock around session fields exported in configfs Date: Sun, 15 Jul 2018 18:16:26 -0500 Message-Id: <1531696591-8558-11-git-send-email-mchristi@redhat.com> In-Reply-To: <1531696591-8558-1-git-send-email-mchristi@redhat.com> References: <1531696591-8558-1-git-send-email-mchristi@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 15 Jul 2018 23:16:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sun, 15 Jul 2018 23:16:47 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mchristi@redhat.com' RCPT:'' Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The next patches will export the initiator port info and add a file to test a session. This patch adds locking around the fields that will be exported in the session's configfs dir. It also moves the setting of se_tpg/fabric_sess_ptr to the end of registration so we know that when they are set the session has been full registered. Signed-off-by: Mike Christie --- drivers/target/target_core_transport.c | 13 +++++++++++-- include/target/target_core_base.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 0efb3dc..04ef13c 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -238,6 +238,7 @@ void transport_init_session(struct se_session *se_sess) INIT_LIST_HEAD(&se_sess->sess_acl_list); INIT_LIST_HEAD(&se_sess->sess_cmd_list); spin_lock_init(&se_sess->sess_cmd_lock); + spin_lock_init(&se_sess->configfs_lock); init_waitqueue_head(&se_sess->cmd_list_wq); } EXPORT_SYMBOL(transport_init_session); @@ -377,7 +378,6 @@ void __transport_register_session( unsigned char buf[PR_REG_ISID_LEN]; unsigned long flags; - se_sess->se_tpg = se_tpg; se_sess->fabric_sess_ptr = fabric_sess_ptr; /* * Used by struct se_node_acl's under ConfigFS to locate active se_session-t @@ -426,6 +426,10 @@ void __transport_register_session( } list_add_tail(&se_sess->sess_list, &se_tpg->tpg_sess_list); + spin_lock(&se_sess->configfs_lock); + se_sess->se_tpg = se_tpg; + spin_unlock(&se_sess->configfs_lock); + pr_debug("TARGET_CORE[%s]: Registered fabric_sess_ptr: %p\n", se_tpg->se_tpg_tfo->get_fabric_name(), se_sess->fabric_sess_ptr); } @@ -603,7 +607,9 @@ void transport_free_session(struct se_session *se_sess) struct se_portal_group *se_tpg = se_nacl->se_tpg; const struct target_core_fabric_ops *se_tfo = se_tpg->se_tpg_tfo; + spin_lock_irqsave(&se_sess->configfs_lock, flags); se_sess->se_node_acl = NULL; + spin_unlock_irqrestore(&se_sess->configfs_lock, flags); /* * Also determine if we need to drop the extra ->cmd_kref if @@ -647,8 +653,11 @@ void transport_deregister_session(struct se_session *se_sess) spin_lock_irqsave(&se_tpg->session_lock, flags); list_del(&se_sess->sess_list); - se_sess->se_tpg = NULL; se_sess->fabric_sess_ptr = NULL; + + spin_lock(&se_sess->configfs_lock); + se_sess->se_tpg = NULL; + spin_unlock(&se_sess->configfs_lock); spin_unlock_irqrestore(&se_tpg->session_lock, flags); pr_debug("TARGET_CORE[%s]: Deregistered fabric_sess\n", diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 01caaa3..d3bb76c 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -606,6 +606,7 @@ struct se_session { struct list_head sess_acl_list; struct list_head sess_cmd_list; spinlock_t sess_cmd_lock; + spinlock_t configfs_lock; wait_queue_head_t cmd_list_wq; void *sess_cmd_map; struct sbitmap_queue sess_tag_pool;