Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp307141ybi; Thu, 1 Aug 2019 19:31:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqyAmliXWc0ABg3bndopHm6ljNoFMeWm2K9+sEF+KNYDngG5Qw9BhQINPGMut6houVo4wjZN X-Received: by 2002:aed:3461:: with SMTP id w88mr93839372qtd.13.1564713080905; Thu, 01 Aug 2019 19:31:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564713080; cv=none; d=google.com; s=arc-20160816; b=f3mSIaHNfSZcLSLCgbgqLhjfbHiUrzSBt4Q62Xl52NHvycv7TAWgpvd2RRRsCFpg4q yA6mmu70K8YR6bcVya+n6rWrGjBmAzrTnDQSNhE5BeXcVOJAv/ilAb95qDrLYh680Qro Uf35Dizzy2Akt6kVHlj75FVHlZsCRz3bna35ZOheovGLKBEwNmkCFxQmcnWFa6ppOJXf cDog2SOOkn/5jlDCQQd4T1tV7sjgsVjvumCU+jcLrInG3+ABNGzalpudKNGz0RZXt46m yRVcFhKZSJ25XTo6N86W7ie3/TsHgAriRA+ufnkFFYR7XL6J0Fxo65Vaok5u64w0lN06 iLRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:cc:to:from; bh=kTR67GBS06bcbx4MvMQk0krwouPx8I8jSsjf1qorn2Y=; b=0G26OX4VKrrSY1Tes6resQia8M0cEkuKyQGVFxarc140UUBLECaJOZPcMJs8NM6RiK T0+Rfr2CI08m+d82+XytykzXweDUMGFcR3D6ss/3X4Wz3suf3yiMJeYF/o5q/6ymmFkD iQzHQDO1frO6fcXQKH2hPS8P3h88G9TeAw8xher89hsehgDFdwOD56sNEGb/dbyEZo4Y Gethhcih1mjzsesu5sBGWZtdwJ0Vy+RNcHgSEuzqLIMF1hYr465NKQUh1k7wOcmi/Gyj vP39nrIF17aGmyC43TcSomkGEwsdymvtO3gArXP3Md7YVA4gUhtoaPre+dJdwrabKn3l xIWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p6si40818520qkj.309.2019.08.01.19.31.07; Thu, 01 Aug 2019 19:31:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403766AbfHAXpb (ORCPT + 99 others); Thu, 1 Aug 2019 19:45:31 -0400 Received: from ale.deltatee.com ([207.54.116.67]:33018 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388733AbfHAXpZ (ORCPT ); Thu, 1 Aug 2019 19:45:25 -0400 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1htKl2-0002MG-On; Thu, 01 Aug 2019 17:45:24 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.89) (envelope-from ) id 1htKl2-00025O-4D; Thu, 01 Aug 2019 17:45:16 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Christoph Hellwig , Sagi Grimberg , Keith Busch , Jens Axboe , Chaitanya Kulkarni , Max Gurtovoy , Stephen Bates , Logan Gunthorpe , Chaitanya Kulkarni Date: Thu, 1 Aug 2019 17:45:07 -0600 Message-Id: <20190801234514.7941-9-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190801234514.7941-1-logang@deltatee.com> References: <20190801234514.7941-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, hch@lst.de, sagi@grimberg.me, kbusch@kernel.org, axboe@fb.com, maxg@mellanox.com, sbates@raithlin.com, logang@deltatee.com, Chaitanya.Kulkarni@wdc.com, chaitanya.kulkarni@wdc.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.5 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,MYRULES_FREE,MYRULES_NO_TEXT autolearn=ham autolearn_force=no version=3.4.2 Subject: [PATCH v7 08/14] nvmet-core: allow one host per passthru-ctrl X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch rejects any new connection to the passthru-ctrl if this controller is already connected to a different host. At the time of allocating the controller we check if the subsys associated with the passthru ctrl is already connected to a host and reject it if the hostnqn differs. Connections from the same host (by hostnqn) are supported to allow for multipath. [chaitanya.kulkarni@wdc.com: based conceptually on a similar patch but different implementation] Signed-off-by: Chaitanya Kulkarni Signed-off-by: Logan Gunthorpe --- drivers/nvme/target/core.c | 4 ++++ drivers/nvme/target/io-cmd-passthru.c | 31 +++++++++++++++++++++++++++ drivers/nvme/target/nvmet.h | 7 ++++++ 3 files changed, 42 insertions(+) diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index 2e75968af7f4..c655f26db3da 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -1278,6 +1278,10 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn, if (!ctrl->sqs) goto out_free_cqs; + ret = nvmet_passthru_alloc_ctrl(subsys, hostnqn); + if (ret) + goto out_free_sqs; + ret = ida_simple_get(&cntlid_ida, NVME_CNTLID_MIN, NVME_CNTLID_MAX, GFP_KERNEL); diff --git a/drivers/nvme/target/io-cmd-passthru.c b/drivers/nvme/target/io-cmd-passthru.c index b199785500ad..06a919283cc5 100644 --- a/drivers/nvme/target/io-cmd-passthru.c +++ b/drivers/nvme/target/io-cmd-passthru.c @@ -104,6 +104,37 @@ void nvmet_passthru_subsys_free(struct nvmet_subsys *subsys) mutex_unlock(&subsys->lock); } +int nvmet_passthru_alloc_ctrl(struct nvmet_subsys *subsys, + const char *hostnqn) +{ + struct nvmet_ctrl *ctrl; + + /* + * Check here if this subsystem is already connected to the passthru + * ctrl. We allow only one host to connect to a given passthru + * subsystem. + */ + int rc = 0; + + mutex_lock(&subsys->lock); + + if (!subsys->passthru_ctrl) + goto out; + + if (list_empty(&subsys->ctrls)) + goto out; + + ctrl = list_first_entry(&subsys->ctrls, struct nvmet_ctrl, + subsys_entry); + + if (strcmp(hostnqn, ctrl->hostnqn)) + rc = -ENODEV; + +out: + mutex_unlock(&subsys->lock); + return rc; +} + static void nvmet_passthru_req_complete(struct nvmet_req *req, struct request *rq, u16 status) { diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index aff4db03269d..6436cb990905 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -513,6 +513,8 @@ void nvmet_passthru_destroy(void); void nvmet_passthru_subsys_free(struct nvmet_subsys *subsys); int nvmet_passthru_ctrl_enable(struct nvmet_subsys *subsys); void nvmet_passthru_ctrl_disable(struct nvmet_subsys *subsys); +int nvmet_passthru_alloc_ctrl(struct nvmet_subsys *subsys, + const char *hostnqn); u16 nvmet_parse_passthru_cmd(struct nvmet_req *req); static inline @@ -536,6 +538,11 @@ static inline void nvmet_passthru_subsys_free(struct nvmet_subsys *subsys) static inline void nvmet_passthru_ctrl_disable(struct nvmet_subsys *subsys) { } +static inline int nvmet_passthru_alloc_ctrl(struct nvmet_subsys *subsys, + const char *hostnqn) +{ + return 0; +} static inline u16 nvmet_parse_passthru_cmd(struct nvmet_req *req) { return 0; -- 2.20.1