From patchwork Tue Jun 14 04:35:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 9174951 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 0F3116048C for ; Tue, 14 Jun 2016 04:36:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0439F281DB for ; Tue, 14 Jun 2016 04:36:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECDDC2821F; Tue, 14 Jun 2016 04:36:54 +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=-5.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, URIBL_BLACK 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 52817281DB for ; Tue, 14 Jun 2016 04:36:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933208AbcFNEgx (ORCPT ); Tue, 14 Jun 2016 00:36:53 -0400 Received: from mail.linux-iscsi.org ([67.23.28.174]:38475 "EHLO linux-iscsi.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932235AbcFNEgu (ORCPT ); Tue, 14 Jun 2016 00:36:50 -0400 Received: from linux-iscsi.org (localhost [127.0.0.1]) by linux-iscsi.org (Postfix) with ESMTP id 2123722CAAB; Tue, 14 Jun 2016 04:35:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=linux-iscsi.org; s=default.private; t=1465878952; bh=QI6ShyBLdy5fYpiozU/YSCJDQs29H1A ul+MgDe+AAS4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References; b=g/DlBHpDRlB30D8F730ZU7J6N2dIpgzIRSrhbcr/2Z2XrNnwQwKX jUuEmBqZtzjJPngdfbZFXfdl/tB4gGeqm48j9qNAYe85FjCM3DUS4cSO1e5hNRTRiVY 5rL3ssXuO+1RsYSXszhODhbVpHYOwKV0TM2BTI4f7wLLBGaRkVTs= From: "Nicholas A. Bellinger" To: target-devel Cc: linux-scsi , linux-nvme , Jens Axboe , Christoph Hellwig , Keith Busch , Jay Freyensee , Martin Petersen , Sagi Grimberg , Hannes Reinecke , Mike Christie , Dave B Minturn , Nicholas Bellinger Subject: [RFC-v2 01/11] nvme-fabrics: Export nvmf_host_add + generate hostnqn if necessary Date: Tue, 14 Jun 2016 04:35:36 +0000 Message-Id: <1465878946-26556-2-git-send-email-nab@linux-iscsi.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1465878946-26556-1-git-send-email-nab@linux-iscsi.org> References: <1465878946-26556-1-git-send-email-nab@linux-iscsi.org> 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 From: Nicholas Bellinger This patch allows nvmf_host_add() to be used externally, and optionally if no hostnqn is passed will generate a hostnqn based on host->id, following nvmf_host_default(). Note it's required for nvme-loop multi-controller support, in order to drive nvmet_port creation directly via configfs attribute write from in ../nvmet/subsystems/$NQN/ports/$PORT/ group context. Cc: Jens Axboe Cc: Christoph Hellwig Cc: Keith Busch Cc: Jay Freyensee Cc: Martin Petersen Cc: Sagi Grimberg Cc: Hannes Reinecke Cc: Mike Christie Signed-off-by: Nicholas Bellinger --- drivers/nvme/host/fabrics.c | 18 +++++++++++++----- drivers/nvme/host/fabrics.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c index ee4b7f1..2e0086a 100644 --- a/drivers/nvme/host/fabrics.c +++ b/drivers/nvme/host/fabrics.c @@ -41,28 +41,36 @@ static struct nvmf_host *__nvmf_host_find(const char *hostnqn) return NULL; } -static struct nvmf_host *nvmf_host_add(const char *hostnqn) +struct nvmf_host *nvmf_host_add(const char *hostnqn) { struct nvmf_host *host; mutex_lock(&nvmf_hosts_mutex); - host = __nvmf_host_find(hostnqn); - if (host) - goto out_unlock; + if (hostnqn) { + host = __nvmf_host_find(hostnqn); + if (host) + goto out_unlock; + } host = kmalloc(sizeof(*host), GFP_KERNEL); if (!host) goto out_unlock; kref_init(&host->ref); - memcpy(host->nqn, hostnqn, NVMF_NQN_SIZE); uuid_le_gen(&host->id); + if (hostnqn) + memcpy(host->nqn, hostnqn, NVMF_NQN_SIZE); + else + snprintf(host->nqn, NVMF_NQN_SIZE, + "nqn.2014-08.org.nvmexpress:NVMf:uuid:%pUl", &host->id); + list_add_tail(&host->list, &nvmf_hosts); out_unlock: mutex_unlock(&nvmf_hosts_mutex); return host; } +EXPORT_SYMBOL_GPL(nvmf_host_add); static struct nvmf_host *nvmf_host_default(void) { diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h index b540674..956eab4 100644 --- a/drivers/nvme/host/fabrics.h +++ b/drivers/nvme/host/fabrics.h @@ -128,6 +128,7 @@ int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl); int nvmf_connect_io_queue(struct nvme_ctrl *ctrl, u16 qid); void nvmf_register_transport(struct nvmf_transport_ops *ops); void nvmf_unregister_transport(struct nvmf_transport_ops *ops); +struct nvmf_host *nvmf_host_add(const char *hostnqn); void nvmf_free_options(struct nvmf_ctrl_options *opts); const char *nvmf_get_subsysnqn(struct nvme_ctrl *ctrl); int nvmf_get_address(struct nvme_ctrl *ctrl, char *buf, int size);