From patchwork Fri Jun 15 18:23:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhu Lingshan X-Patchwork-Id: 10467237 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 54963601C2 for ; Fri, 15 Jun 2018 18:24:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44FB128E3B for ; Fri, 15 Jun 2018 18:24:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39A1728E40; Fri, 15 Jun 2018 18:24:26 +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 BF5B728E3D for ; Fri, 15 Jun 2018 18:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756422AbeFOSYV (ORCPT ); Fri, 15 Jun 2018 14:24:21 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:54763 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756412AbeFOSYU (ORCPT ); Fri, 15 Jun 2018 14:24:20 -0400 Received: from vstart.localdomain (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Fri, 15 Jun 2018 12:24:16 -0600 From: Zhu Lingshan To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, nab@linux-iscsi.org, mchristi@redhat.com, martin.petersen@oracle.com Cc: hare@suse.de, lduncan@suse.com, ddiss@suse.de, lszhu@suse.de, Zhu Lingshan Subject: [PATCH 05/33] TCMU PR: add a function to get IT_Nexus Date: Sat, 16 Jun 2018 02:23:14 +0800 Message-Id: <20180615182342.6239-5-lszhu@suse.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180615182342.6239-1-lszhu@suse.com> References: <20180615182342.6239-1-lszhu@suse.com> 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 This patch added a function tcmu_gen_it_nexus() which can help generate a string contain IT_Nexus information from a session. Signed-off-by: Zhu Lingshan --- drivers/target/target_core_user.c | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index d368c656ef79..26d8aee40719 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -1769,6 +1769,50 @@ static int tcmu_set_dev_pr_info(struct tcmu_dev *udev, void *val) return tcmu_send_set_pr_info_event(udev, val); } +static int +tcmu_gen_it_nexus(struct se_session *se_sess, + char *nexus_buf, + size_t buflen) +{ + struct se_portal_group *se_tpg; + const struct target_core_fabric_ops *tfo; + u32 tpg_tag = 0; + char *tpg_wwn = ""; + int rc; + + if (!se_sess || !se_sess->se_node_acl || !se_sess->se_tpg + || !se_sess->se_tpg->se_tpg_tfo) { + pr_warn("invalid session for IT nexus generation\n"); + return -EINVAL; + } + + se_tpg = se_sess->se_tpg; + tfo = se_tpg->se_tpg_tfo; + + /* + * nexus generation may be coming from an xcopy, in which case tfo + * refers to xcopy_pt_tfo (tpg_get_wwn and tpg_get_tag are NULL). + */ + if (tfo->tpg_get_tag) + tpg_tag = tfo->tpg_get_tag(se_tpg); + if (tfo->tpg_get_wwn) + tpg_wwn = tfo->tpg_get_wwn(se_tpg); + + rc = snprintf(nexus_buf, buflen, "%s,i,0x%llx,%s,t,0x%x", + se_sess->se_node_acl->initiatorname, + se_sess->sess_bin_isid, + tpg_wwn, + tpg_tag); + if ((rc < 0) || (rc >= buflen)) { + pr_debug("error formatting reserve cookie\n"); + return -EINVAL; + } + + pr_debug("generated nexus: %s\n", nexus_buf); + + return 0; +} + static int tcmu_configure_device(struct se_device *dev) { struct tcmu_dev *udev = TCMU_DEV(dev);