From patchwork Sun Jul 15 23:16:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 10525327 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 1AB046054B for ; Sun, 15 Jul 2018 23:16:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CBFB27F98 for ; Sun, 15 Jul 2018 23:16:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0093C28385; Sun, 15 Jul 2018 23:16:52 +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=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 A13BC2837E for ; Sun, 15 Jul 2018 23:16:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727411AbeGOXlY (ORCPT ); Sun, 15 Jul 2018 19:41:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49596 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727374AbeGOXlV (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 54FDC7B2B3; Sun, 15 Jul 2018 23:16:48 +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 CB92576EA; 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 11/15] target: export initiator port values for all sessions Date: Sun, 15 Jul 2018 18:16:27 -0500 Message-Id: <1531696591-8558-12-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.1]); Sun, 15 Jul 2018 23:16:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sun, 15 Jul 2018 23:16:48 +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 Export the initiator port info in configfs Signed-off-by: Mike Christie --- drivers/target/target_core_fabric_configfs.c | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/target/target_core_fabric_configfs.c b/drivers/target/target_core_fabric_configfs.c index 497fa01..2deda28 100644 --- a/drivers/target/target_core_fabric_configfs.c +++ b/drivers/target/target_core_fabric_configfs.c @@ -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;